changeset 493:b2c332ae4df4

Rename tcclib.h to tinyinc.h and update examples.
author Rob Landley <rob@landley.net>
date Tue, 30 Oct 2007 20:18:33 -0500
parents aa482214f9c0
children 803a46d4a4c9
files examples/ex1.c examples/ex2.c examples/ex3.c examples/ex4.c examples/ex5.c include/tcclib.h include/tinyinc.h
diffstat 7 files changed, 96 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/examples/ex1.c	Mon Oct 29 03:21:30 2007 -0500
+++ b/examples/ex1.c	Tue Oct 30 20:18:33 2007 -0500
@@ -1,5 +1,8 @@
 #! /usr/bin/tcc -run
-#include <tcclib.h>
+
+/* A small program to print "hello world", using tinyinc.h */
+
+#include <tinyinc.h>
 
 int main() 
 {
--- a/examples/ex2.c	Mon Oct 29 03:21:30 2007 -0500
+++ b/examples/ex2.c	Tue Oct 30 20:18:33 2007 -0500
@@ -1,4 +1,8 @@
-#include "tcclib.h"
+#include "tinyinc.h"
+
+/* Benchmark: given a result and a list of numbers, try to add, subtract,
+   multiply, and divide the list of numbers to get the result.  For example,
+   "./ex2 42 7 1 5" should find that 5+1 is 6, and 6*7 is 42. */
 
 #define N 20
 
--- a/examples/ex3.c	Mon Oct 29 03:21:30 2007 -0500
+++ b/examples/ex3.c	Tue Oct 30 20:18:33 2007 -0500
@@ -1,4 +1,7 @@
-#include <tcclib.h>
+#include <tinyinc.h>
+
+/* Benchmark: compute the nth Fibonacci number.  No, this is not optimal, it's
+   just for performance comparison purposes. */
 
 int fib(n)
 {
--- a/examples/ex4.c	Mon Oct 29 03:21:30 2007 -0500
+++ b/examples/ex4.c	Tue Oct 30 20:18:33 2007 -0500
@@ -1,9 +1,10 @@
 #!/usr/bin/tcc -run -L/usr/X11R6/lib -lX11
 #include <stdlib.h>
-/* Yes, TCC can use X11 too ! */
 #include <stdio.h>
 #include <X11/Xlib.h>
 
+/* Demonstrate that tinycc can use X11, even via -run */
+
 int main(int argc, char **argv)
 {
     Display *display;
--- a/examples/ex5.c	Mon Oct 29 03:21:30 2007 -0500
+++ b/examples/ex5.c	Tue Oct 30 20:18:33 2007 -0500
@@ -1,5 +1,7 @@
 #include <stdio.h>
 
+/* The traditional hello world program, using stdio.h insead of tinyinc.h */
+
 int main() 
 {
     printf("Hello World\n");
--- a/include/tcclib.h	Mon Oct 29 03:21:30 2007 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/* Simple libc header for TCC 
- * 
- * Add any function you want from the libc there. This file is here
- * only for your convenience so that you do not need to put the whole
- * /usr/include directory on your target system.
- */
-#ifndef _TCCLIB_H
-#define _TCCLIB_H
-
-#include <stddef.h>
-#include <stdarg.h>
-
-/* stdlib.h */
-void *calloc(size_t nmemb, size_t size);
-void *malloc(size_t size);
-void free(void *ptr);
-void *realloc(void *ptr, size_t size);
-int atoi(const char *nptr);
-long int strtol(const char *nptr, char **endptr, int base);
-unsigned long int strtoul(const char *nptr, char **endptr, int base);
-
-/* stdio.h */
-typedef struct __FILE FILE;
-#define EOF (-1)
-extern FILE *stdin;
-extern FILE *stdout;
-extern FILE *stderr;
-FILE *fopen(const char *path, const char *mode);
-FILE *fdopen(int fildes, const char *mode);
-FILE *freopen(const  char *path, const char *mode, FILE *stream);
-int fclose(FILE *stream);
-size_t  fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
-size_t  fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
-int fgetc(FILE *stream);
-char *fgets(char *s, int size, FILE *stream);
-int getc(FILE *stream);
-int getchar(void);
-char *gets(char *s);
-int ungetc(int c, FILE *stream);
-int fflush(FILE *stream);
-
-int printf(const char *format, ...);
-int fprintf(FILE *stream, const char *format, ...);
-int sprintf(char *str, const char *format, ...);
-int snprintf(char *str, size_t size, const  char  *format, ...);
-int asprintf(char **strp, const char *format, ...);
-int dprintf(int fd, const char *format, ...);
-int vprintf(const char *format, va_list ap);
-int vfprintf(FILE  *stream,  const  char *format, va_list ap);
-int vsprintf(char *str, const char *format, va_list ap);
-int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
-int vasprintf(char  **strp,  const  char *format, va_list ap);
-int vdprintf(int fd, const char *format, va_list ap);
-
-void perror(const char *s);
-
-/* string.h */
-char *strcat(char *dest, const char *src);
-char *strchr(const char *s, int c);
-char *strrchr(const char *s, int c);
-char *strcpy(char *dest, const char *src);
-void *memcpy(void *dest, const void *src, size_t n);
-void *memmove(void *dest, const void *src, size_t n);
-void *memset(void *s, int c, size_t n);
-char *strdup(const char *s);
-
-/* dlfcn.h */
-#define RTLD_LAZY       0x001
-#define RTLD_NOW        0x002
-#define RTLD_GLOBAL     0x100
-
-void *dlopen(const char *filename, int flag);
-const char *dlerror(void);
-void *dlsym(void *handle, char *symbol);
-int dlclose(void *handle);
-
-#endif /* _TCCLIB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/tinyinc.h	Tue Oct 30 20:18:33 2007 -0500
@@ -0,0 +1,79 @@
+/* Simple libc header for tinycc, containing the many common symbols.
+ * 
+ * Add any function you want below.  This file is here only for your
+ * convenience, so that you do not need to put the whole /usr/include directory
+ * on your target system.
+ */
+#ifndef _TINYINC_H
+#define _TINYINC_H
+
+/* These are installed by tinycc, not libc. */
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/* stdlib.h */
+void *calloc(size_t nmemb, size_t size);
+void *malloc(size_t size);
+void free(void *ptr);
+void *realloc(void *ptr, size_t size);
+int atoi(const char *nptr);
+long int strtol(const char *nptr, char **endptr, int base);
+unsigned long int strtoul(const char *nptr, char **endptr, int base);
+
+/* stdio.h */
+typedef struct __FILE FILE;
+#define EOF (-1)
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+FILE *fopen(const char *path, const char *mode);
+FILE *fdopen(int fildes, const char *mode);
+FILE *freopen(const  char *path, const char *mode, FILE *stream);
+int fclose(FILE *stream);
+size_t  fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+size_t  fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
+int fgetc(FILE *stream);
+char *fgets(char *s, int size, FILE *stream);
+int getc(FILE *stream);
+int getchar(void);
+char *gets(char *s);
+int ungetc(int c, FILE *stream);
+int fflush(FILE *stream);
+
+int printf(const char *format, ...);
+int fprintf(FILE *stream, const char *format, ...);
+int sprintf(char *str, const char *format, ...);
+int snprintf(char *str, size_t size, const  char  *format, ...);
+int asprintf(char **strp, const char *format, ...);
+int dprintf(int fd, const char *format, ...);
+int vprintf(const char *format, va_list ap);
+int vfprintf(FILE  *stream,  const  char *format, va_list ap);
+int vsprintf(char *str, const char *format, va_list ap);
+int vsnprintf(char *str, size_t size, const char  *format, va_list ap);
+int vasprintf(char  **strp,  const  char *format, va_list ap);
+int vdprintf(int fd, const char *format, va_list ap);
+
+void perror(const char *s);
+
+/* string.h */
+char *strcat(char *dest, const char *src);
+char *strchr(const char *s, int c);
+char *strrchr(const char *s, int c);
+char *strcpy(char *dest, const char *src);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memmove(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+char *strdup(const char *s);
+
+/* dlfcn.h */
+#define RTLD_LAZY       0x001
+#define RTLD_NOW        0x002
+#define RTLD_GLOBAL     0x100
+
+void *dlopen(const char *filename, int flag);
+const char *dlerror(void);
+void *dlsym(void *handle, char *symbol);
+int dlclose(void *handle);
+
+#endif /* _TCCLIB_H */