From ce7b0e6e919cb9fa1499837881c6e5b206a1c2ba Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 10 Dec 2020 12:48:17 -0500 Subject: [PATCH] removed stdc.h --- bin/init.c | 3 +- bin/listen.c | 2 - bin/shell.c | 11 +-- inc/liba.h | 142 ++++++++++++++++++++++++++++ inc/stdc.h | 205 ----------------------------------------- lib/a/argv0.c | 1 - lib/a/ecalloc.c | 1 - lib/a/efopen.c | 1 - lib/a/efreadline.c | 1 - lib/a/emalloc.c | 1 - lib/a/eraise.c | 1 - lib/a/erealloc.c | 1 - lib/a/esignal.c | 1 - lib/a/estrdup.c | 1 - lib/a/fatal.c | 1 - lib/a/smprintf.c | 1 - lib/a/warn.c | 1 - lib/ui/font_close.c | 1 - lib/ui/font_load.c | 1 - lib/ui/ui_begin.c | 1 - lib/ui/ui_end.c | 1 - lib/ui/window_create.c | 1 - lib/ui/window_delete.c | 1 - lib/ui/window_hide.c | 1 - lib/ui/window_show.c | 1 - 25 files changed, 145 insertions(+), 238 deletions(-) delete mode 100644 inc/stdc.h diff --git a/bin/init.c b/bin/init.c index 40011ce..99842e7 100644 --- a/bin/init.c +++ b/bin/init.c @@ -1,7 +1,6 @@ #define _XOPEN_SOURCE 700 -#include +#include #include -#include static sigset_t set; static char* const rcinitcmd[] = { "/etc/rc.init", 0 }; diff --git a/bin/listen.c b/bin/listen.c index 7ad27ee..be58c80 100644 --- a/bin/listen.c +++ b/bin/listen.c @@ -1,7 +1,5 @@ #include #include -#include -#include #include #include diff --git a/bin/shell.c b/bin/shell.c index 6784262..70021db 100644 --- a/bin/shell.c +++ b/bin/shell.c @@ -1,17 +1,10 @@ -#define _XOPEN_SOURCE 700 +#include #include #include -#include -#include -#include -#include #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); diff --git a/inc/liba.h b/inc/liba.h index dcc8583..1d72e44 100644 --- a/inc/liba.h +++ b/inc/liba.h @@ -1,4 +1,146 @@ +/* Standard Macros and Types */ +#include +#define _XOPEN_SOURCE 700 + +#include +#include +#include +#include +#include + +/* Useful Standard Functions */ +#include #include +#include +#include +#include + +/* we're only targeting unixes */ +#include + +/* 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 index aec368d..0000000 --- a/inc/stdc.h +++ /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 -#include -#include -#include -#include -#include - -/* Useful Standard Functions */ -#include -#include -#include -#include -#include - -/* 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 diff --git a/lib/a/argv0.c b/lib/a/argv0.c index 62a3c35..015fbee 100644 --- a/lib/a/argv0.c +++ b/lib/a/argv0.c @@ -1,4 +1,3 @@ -#include #include char* ARGV0 = 0; \ No newline at end of file diff --git a/lib/a/ecalloc.c b/lib/a/ecalloc.c index c4b2a31..f6ad21c 100644 --- a/lib/a/ecalloc.c +++ b/lib/a/ecalloc.c @@ -1,4 +1,3 @@ -#include #include void* ecalloc(size_t num, size_t size) diff --git a/lib/a/efopen.c b/lib/a/efopen.c index 7b900f3..aa459f9 100644 --- a/lib/a/efopen.c +++ b/lib/a/efopen.c @@ -1,4 +1,3 @@ -#include #include FILE* efopen(const char* filename, const char* mode) diff --git a/lib/a/efreadline.c b/lib/a/efreadline.c index b2069f0..39f180e 100644 --- a/lib/a/efreadline.c +++ b/lib/a/efreadline.c @@ -1,4 +1,3 @@ -#include #include char* efreadline(FILE* input) diff --git a/lib/a/emalloc.c b/lib/a/emalloc.c index ea9f6c1..9e7470d 100644 --- a/lib/a/emalloc.c +++ b/lib/a/emalloc.c @@ -1,4 +1,3 @@ -#include #include void* emalloc(size_t size) diff --git a/lib/a/eraise.c b/lib/a/eraise.c index 7c45dd4..6a3bd50 100644 --- a/lib/a/eraise.c +++ b/lib/a/eraise.c @@ -1,4 +1,3 @@ -#include #include int eraise(int sig) diff --git a/lib/a/erealloc.c b/lib/a/erealloc.c index cf9af01..3d0db4a 100644 --- a/lib/a/erealloc.c +++ b/lib/a/erealloc.c @@ -1,4 +1,3 @@ -#include #include void* erealloc(void* ptr, size_t size) diff --git a/lib/a/esignal.c b/lib/a/esignal.c index 7231f51..f31b0c5 100644 --- a/lib/a/esignal.c +++ b/lib/a/esignal.c @@ -1,4 +1,3 @@ -#include #include void esignal(int sig, void (*func)(int)) diff --git a/lib/a/estrdup.c b/lib/a/estrdup.c index 24a5af5..4945c47 100644 --- a/lib/a/estrdup.c +++ b/lib/a/estrdup.c @@ -1,4 +1,3 @@ -#include #include char* estrdup(const char *s) diff --git a/lib/a/fatal.c b/lib/a/fatal.c index 3e5d08e..384c981 100644 --- a/lib/a/fatal.c +++ b/lib/a/fatal.c @@ -1,4 +1,3 @@ -#include #include void fatal(const char* fmt, ...) diff --git a/lib/a/smprintf.c b/lib/a/smprintf.c index e6ef302..5ff127a 100644 --- a/lib/a/smprintf.c +++ b/lib/a/smprintf.c @@ -1,4 +1,3 @@ -#include #include char* smprintf(const char* fmt, ...) diff --git a/lib/a/warn.c b/lib/a/warn.c index 5e82a4b..d9011da 100644 --- a/lib/a/warn.c +++ b/lib/a/warn.c @@ -1,4 +1,3 @@ -#include #include void warn(const char* fmt, ...) diff --git a/lib/ui/font_close.c b/lib/ui/font_close.c index 6891a1e..fed619d 100644 --- a/lib/ui/font_close.c +++ b/lib/ui/font_close.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/font_load.c b/lib/ui/font_load.c index aa469b7..4529752 100644 --- a/lib/ui/font_load.c +++ b/lib/ui/font_load.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/ui_begin.c b/lib/ui/ui_begin.c index 0042d31..8d7d5b9 100644 --- a/lib/ui/ui_begin.c +++ b/lib/ui/ui_begin.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/ui_end.c b/lib/ui/ui_end.c index 11baa5a..45c0f3a 100644 --- a/lib/ui/ui_end.c +++ b/lib/ui/ui_end.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/window_create.c b/lib/ui/window_create.c index a321c69..4bf078b 100644 --- a/lib/ui/window_create.c +++ b/lib/ui/window_create.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/window_delete.c b/lib/ui/window_delete.c index 0aa5b5c..45f29eb 100644 --- a/lib/ui/window_delete.c +++ b/lib/ui/window_delete.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/window_hide.c b/lib/ui/window_hide.c index f235901..c4f8ca3 100644 --- a/lib/ui/window_hide.c +++ b/lib/ui/window_hide.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" diff --git a/lib/ui/window_show.c b/lib/ui/window_show.c index 2a1322a..b2f92f8 100644 --- a/lib/ui/window_show.c +++ b/lib/ui/window_show.c @@ -1,4 +1,3 @@ -#include #include #include #include "libui_impl.h" -- 2.52.0