]> git.mdlowis.com Git - proto/aos.git/commitdiff
removed stdc.h
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Dec 2020 17:48:17 +0000 (12:48 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Dec 2020 17:48:17 +0000 (12:48 -0500)
25 files changed:
bin/init.c
bin/listen.c
bin/shell.c
inc/liba.h
inc/stdc.h [deleted file]
lib/a/argv0.c
lib/a/ecalloc.c
lib/a/efopen.c
lib/a/efreadline.c
lib/a/emalloc.c
lib/a/eraise.c
lib/a/erealloc.c
lib/a/esignal.c
lib/a/estrdup.c
lib/a/fatal.c
lib/a/smprintf.c
lib/a/warn.c
lib/ui/font_close.c
lib/ui/font_load.c
lib/ui/ui_begin.c
lib/ui/ui_end.c
lib/ui/window_create.c
lib/ui/window_delete.c
lib/ui/window_hide.c
lib/ui/window_show.c

index 40011ce58ae106f221b0a3c149af7c0081f3e3da..99842e7cb14e0396593f59c7e7a32c817468f828 100644 (file)
@@ -1,7 +1,6 @@
 #define _XOPEN_SOURCE 700
-#include <stdc.h>
+#include <liba.h>
 #include <sys/wait.h>
-#include <unistd.h>
 
 static sigset_t set;
 static char* const rcinitcmd[]     = { "/etc/rc.init", 0 };
index 7ad27ee7a900aabc9690db8d2ceed4fb7aa2043a..be58c80851e702d1a8fbd9ec5d19d82d26b86599 100644 (file)
@@ -1,7 +1,5 @@
 #include <liba.h>
 #include <libnet.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
index 6784262276b444f688a8596a3f091c0c0c4054f5..70021db563ad34fa8dcbe62e227152c15016a1a1 100644 (file)
@@ -1,17 +1,10 @@
-#define _XOPEN_SOURCE 700
+#include <liba.h>
 #include <sys/wait.h>
 #include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 
 #define LSH_TOK_BUFSIZE 64
 #define LSH_TOK_DELIM " \t\r\n\a"
 
-#define nelem(ary) \
-    (sizeof(ary) / sizeof(ary[0]))
-
 int cd(char **args)
 {
     if (args[1] == NULL)
@@ -157,7 +150,7 @@ int main(int argc, char **argv)
         printf("> ");
         char* line = read_line();
         char** args = split_line(line);
-        int status = execute(args);
+        status = execute(args);
         (void)status;
         free(line);
         free(args);
index dcc8583e33b2c75d4bd89840c293ddf399a28ec2..1d72e44e719df4904ec575a70796e93d1d4d4974 100644 (file)
@@ -1,4 +1,146 @@
+/* Standard Macros and Types */
+#include <stddef.h>
+#define _XOPEN_SOURCE 700
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <limits.h>
+#include <assert.h>
+
+/* Useful Standard Functions */
+#include <signal.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+/* we're only targeting unixes */
+#include <unistd.h>
+
+/* This variable contains the value of argv[0] so that it can be referenced
+ * again once the option parsing is done. This variable must be defined by the
+ * program. */
+extern char* ARGV0;
+
+/* Option Parsing
+ *******************************************************************************
+ * This following macros implement a simple POSIX-style option parsing strategy.
+ * They are heavily influenced and inspired by the arg.h file from suckless.org
+ * (http://git.suckless.org/libsl/tree/arg.h). That file is in turn inspired by
+ * the corresponding macros defined in plan9 libc.h.
+ *
+ * The interface assumes that the main function will have the following
+ * prototype:
+ *
+ * int main(int argc, char** argv);
+ *
+ * An example usage of the interface would look something like the follwoing:
+ *
+ * char* ARGV0;
+ * int main(int argc, char** argv) {
+ *     OPTBEGIN {
+ *         case 'a': printf("Simple option\n"); break;
+ *         case 'b': printf("Option with arg: %s\n", OPTARG()); break;
+ *         default:  printf("Unknown option!\n");
+ *     } OPTEND;
+ *     return 0;
+ * }
+ */
+
+/* This is a helper function used by the following macros to parse the next
+ * option from the command line. */
+static inline char* _getopt_(int* p_argc, char*** p_argv) {
+    if (!(*p_argv)[0][1] && !(*p_argv)[1]) {
+        return (char*)0;
+    } else if ((*p_argv)[0][1]) {
+        return &(*p_argv)[0][1];
+    } else {
+        *p_argv = *p_argv + 1;
+        *p_argc = *p_argc - 1;
+        return (*p_argv)[0];
+    }
+}
+
+/* This macro is almost identical to the ARGBEGIN macro from suckless.org. If
+ * it ain't broke, don't fix it. */
+#define OPTBEGIN                                                              \
+    for (                                                                     \
+        ARGV0 = *argv, argc--, argv++;                                        \
+        argv[0] && argv[0][1] && argv[0][0] == '-';                           \
+        argc--, argv++                                                        \
+    ) {                                                                       \
+        int brk_; char argc_ , **argv_, *optarg_;                             \
+        if (argv[0][1] == '-' && !argv[0][2]) {                               \
+            argv++, argc--; break;                                            \
+        }                                                                     \
+        for (brk_=0, argv[0]++, argv_=argv; argv[0][0] && !brk_; argv[0]++) { \
+            if (argv_ != argv) break;                                         \
+            argc_ = argv[0][0];                                               \
+            switch (argc_)
+
+/* Terminate the option parsing. */
+#define OPTEND }}
+
+/* Get the current option character */
+#define OPTC() (argc_)
+
+/* Get an argument from the command line and return it as a string. If no
+ * argument is available, this macro returns NULL */
+#define OPTARG() \
+    (optarg_ = _getopt_(&argc,&argv), brk_ = (optarg_!=0), optarg_)
+
+/* Get an argument from the command line and return it as a string. If no
+ * argument is available, this macro executes the provided code. If that code
+ * returns, then abort is called. */
+#define EOPTARG(code) \
+    (optarg_ = _getopt_(&argc,&argv), \
+    (!optarg_ ? ((code), abort(), (char*)0) : (brk_ = 1, optarg_)))
+
+/* Helper macro to recognize number options */
+#define OPTNUM \
+    case '0':  \
+    case '1':  \
+    case '2':  \
+    case '3':  \
+    case '4':  \
+    case '5':  \
+    case '6':  \
+    case '7':  \
+    case '8':  \
+    case '9'
+
+/* Helper macro to recognize "long" options ala GNU style. */
+#define OPTLONG \
+    case '-'
+
+/* Miscellaneous Macros
+ ******************************************************************************/
+#ifndef nelem
+    #define nelem(x) \
+        (sizeof(x)/sizeof((x)[0]))
+#endif
+
+#ifndef container_of
+    #define container_of(obj, type, member) \
+        (type*)((uintptr_t)obj - offsetof(type, member))
+#endif
+
+#define concat(a,b) \
+    a##b
+
+#define ident(a) \
+    concat(id, a)
+
+#define unique_id \
+    ident(__LINE__)
+
+#ifndef static_assert
+    #define static_assert(expr) \
+        typedef char unique_id[( expr )?1:-1]
+#endif
+
+
 
 void fatal(const char* fmt, ...);
 void warn(const char* fmt, ...);
diff --git a/inc/stdc.h b/inc/stdc.h
deleted file mode 100644 (file)
index aec368d..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
-    Setup common ANSI C environment with common includes, functions, typedefs,
-    and macros.
-
-    Copyright 2017, Michael D. Lowis
-
-    Permission to use, copy, modify, and/or distribute this software
-    for any purpose with or without fee is hereby granted, provided
-    that the above copyright notice and this permission notice appear
-    in all copies.
-
-    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
-    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
-    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
-    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
-    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
-    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-    PERFORMANCE OF THIS SOFTWARE.
-*/
-
-/* Standard Macros and Types */
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <errno.h>
-#include <limits.h>
-#include <assert.h>
-
-/* Useful Standard Functions */
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-
-/* Type and Variable Definitions
- ******************************************************************************/
-typedef unsigned short ushort;
-typedef unsigned char uchar;
-typedef unsigned long ulong;
-typedef unsigned int uint;
-typedef signed char schar;
-typedef long long vlong;
-typedef unsigned long long uvlong;
-
-typedef uint8_t  uint8;
-typedef uint16_t uint16;
-typedef uint32_t uint32;
-typedef uint64_t uint64;
-
-typedef int8_t  int8;
-typedef int16_t int16;
-typedef int32_t int32;
-typedef int64_t int64;
-
-typedef uintptr_t uintptr;
-typedef intptr_t  intptr;
-
-/* This variable contains the value of argv[0] so that it can be referenced
- * again once the option parsing is done. This variable must be defined by the
- * program.
- *
- * NOTE: Ensure that you define this variable with external linkage (i.e. not
- * static) */
-extern char* ARGV0;
-
-/* Option Parsing
- *******************************************************************************
- * This following macros implement a simple POSIX-style option parsing strategy.
- * They are heavily influenced and inspired by the arg.h file from suckless.org
- * (http://git.suckless.org/libsl/tree/arg.h). That file is in turn inspired by
- * the corresponding macros defined in plan9 libc.h.
- *
- * The interface assumes that the main function will have the following
- * prototype:
- *
- * int main(int argc, char** argv);
- *
- * An example usage of the interface would look something like the follwoing:
- *
- * char* ARGV0;
- * int main(int argc, char** argv) {
- *     OPTBEGIN {
- *         case 'a': printf("Simple option\n"); break;
- *         case 'b': printf("Option with arg: %s\n", OPTARG()); break;
- *         default:  printf("Unknown option!\n");
- *     } OPTEND;
- *     return 0;
- * }
- */
-
-/* This is a helper function used by the following macros to parse the next
- * option from the command line. */
-static inline char* _getopt_(int* p_argc, char*** p_argv) {
-    if (!(*p_argv)[0][1] && !(*p_argv)[1]) {
-        return (char*)0;
-    } else if ((*p_argv)[0][1]) {
-        return &(*p_argv)[0][1];
-    } else {
-        *p_argv = *p_argv + 1;
-        *p_argc = *p_argc - 1;
-        return (*p_argv)[0];
-    }
-}
-
-/* This macro is almost identical to the ARGBEGIN macro from suckless.org. If
- * it ain't broke, don't fix it. */
-#define OPTBEGIN                                                              \
-    for (                                                                     \
-        ARGV0 = *argv, argc--, argv++;                                        \
-        argv[0] && argv[0][1] && argv[0][0] == '-';                           \
-        argc--, argv++                                                        \
-    ) {                                                                       \
-        int brk_; char argc_ , **argv_, *optarg_;                             \
-        if (argv[0][1] == '-' && !argv[0][2]) {                               \
-            argv++, argc--; break;                                            \
-        }                                                                     \
-        for (brk_=0, argv[0]++, argv_=argv; argv[0][0] && !brk_; argv[0]++) { \
-            if (argv_ != argv) break;                                         \
-            argc_ = argv[0][0];                                               \
-            switch (argc_)
-
-/* Terminate the option parsing. */
-#define OPTEND }}
-
-/* Get the current option character */
-#define OPTC() (argc_)
-
-/* Get an argument from the command line and return it as a string. If no
- * argument is available, this macro returns NULL */
-#define OPTARG() \
-    (optarg_ = _getopt_(&argc,&argv), brk_ = (optarg_!=0), optarg_)
-
-/* Get an argument from the command line and return it as a string. If no
- * argument is available, this macro executes the provided code. If that code
- * returns, then abort is called. */
-#define EOPTARG(code) \
-    (optarg_ = _getopt_(&argc,&argv), \
-    (!optarg_ ? ((code), abort(), (char*)0) : (brk_ = 1, optarg_)))
-
-/* Helper macro to recognize number options */
-#define OPTNUM \
-    case '0':  \
-    case '1':  \
-    case '2':  \
-    case '3':  \
-    case '4':  \
-    case '5':  \
-    case '6':  \
-    case '7':  \
-    case '8':  \
-    case '9'
-
-/* Helper macro to recognize "long" options ala GNU style. */
-#define OPTLONG \
-    case '-'
-
-/* Error Handling Macros
- ******************************************************************************/
-#ifdef NDEBUG
-    #define debug(msg, ...) \
-        ((void)0)
-#else
-    #define debug(msg, ...) \
-        fprintf(stderr, "DEBUG %s:%d: " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__)
-#endif
-
-#define errnostr() \
-    (errno == 0 ? "None" : strerror(errno))
-
-#define print_error(msg, ...) \
-    fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " msg "\n", __FILE__, __LINE__, errnostr(), ##__VA_ARGS__)
-
-#define check(expr, msg, ...) \
-    if(!(expr)) { print_error(msg, ##__VA_ARGS__); errno=0; goto error; }
-
-#define sentinel(msg, ...) \
-    { print_error(msg, ##__VA_ARGS__); errno=0; goto error; }
-
-/* Miscellaneous Macros
- ******************************************************************************/
-#ifndef nelem
-    #define nelem(x) \
-        (sizeof(x)/sizeof((x)[0]))
-#endif
-
-#ifndef container_of
-    #define container_of(obj, type, member) \
-        (type*)((uintptr_t)obj - offsetof(type, member))
-#endif
-
-#define concat(a,b) \
-    a##b
-
-#define ident(a) \
-    concat(id, a)
-
-#define unique_id \
-    ident(__LINE__)
-
-#ifndef static_assert
-    #define static_assert(expr) \
-        typedef char unique_id[( expr )?1:-1]
-#endif
index 62a3c3539e10d7912d82f0ef6fcd11732ac6650b..015fbeee6ca325455868a40c5b3145733f285501 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 char* ARGV0 = 0;
\ No newline at end of file
index c4b2a31e424240e67c4bce35ce8127c7f8ae93e5..f6ad21cdbc571f8c4eacfe34cb40ee5fdff8980d 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 void* ecalloc(size_t num, size_t size)
index 7b900f31b36011e2bd16be8584e20d10671a3398..aa459f95e59de194d0aa74f0f7b21f61bf938e44 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 FILE* efopen(const char* filename, const char* mode)
index b2069f0981a61977ccbd6dbc204644d4cac657bd..39f180e08e14a99b0d34d18a46c4d222a9f34cf8 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 char* efreadline(FILE* input)
index ea9f6c197c4c8af31debf6bc43431825b18d4a17..9e7470d495bff7505d782ac6b4fc8ea944cbf30c 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 void* emalloc(size_t size)
index 7c45dd44e6e69efc36a5dfa67740b7f2a35730c7..6a3bd50caf6ca7565151fdb62d7ffd90f96e09e8 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 int eraise(int sig)
index cf9af0135a5192513b515dc2ea47ba2ab440ac0f..3d0db4ab00e43576350fdd2bf56316f41a3d3fee 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 void* erealloc(void* ptr, size_t size)
index 7231f514ecbcfb71e587d98494730ca445877be7..f31b0c53f5335181613193034bd8861f8a1955aa 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 void esignal(int sig, void (*func)(int))
index 24a5af57178906fab7da442063d37d2d87bbc994..4945c474361b30e1d537f8ee6128e775292a2802 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 char* estrdup(const char *s)
index 3e5d08e12d9eddf70e38159ebc7ee018c9d7a4a0..384c9811f3f2c3d40eeb8af20bdcf8d86102b02a 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 void fatal(const char* fmt, ...)
index e6ef3027b44ab57d0279b2c6fce900f203fbd558..5ff127a5e43a604c999c6add2723955fad08e4da 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 char* smprintf(const char* fmt, ...)
index 5e82a4be143feb6088ede8e722fe066fe20b32ba..d9011daf73b524a3b84801b7e0f867dc214db9fb 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 
 void warn(const char* fmt, ...)
index 6891a1ed95c203816e6138ceee9c149fcdc9d448..fed619d2ef4826158162366aaae78f21a8b5045e 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index aa469b71042644f68c6739de845e0742c4557d55..45297529c505f5adcdd8f7f47183324a4ad59fd3 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index 0042d31ec49ddcbd943e6a4c1001c98da575dd2a..8d7d5b977e59c7ce6198e9b43c777d2ab82da7e3 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index 11baa5a6be9d9eb42148ed4b40b58a2db5c6cccc..45c0f3a1fe2268187b1270a5eeaaecd77cf4ecc9 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index a321c695e6df05fb60ab77a714f73e6b59259b43..4bf078b6fe9f8a11b03d2844f00a53ea9d39f360 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index 0aa5b5c810a913770fb0fe564da513d26158ce86..45f29eb8edfddf7a936457d74284ca22dbbcd73a 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index f23590124f22dc8424192b1d43ced49584bc8ef8..c4f8ca32da897cb1183b516afc6b799a87b1e63d 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"
index 2a1322a9293f08cbc799a976a0fc90c9f4ef9d93..b2f92f8085674cbb6838e76f0e6273878d7ceede 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdc.h>
 #include <liba.h>
 #include <libui.h>
 #include "libui_impl.h"