Name: Anonymous 2009-12-19 3:12
So I couldn't sleep and out of boredom wrote a brainfuck to C compiler.
http://nopaste.info/73ec0c6fa7_nl.html
http://nopaste.info/73ec0c6fa7_nl.html
getopt isn't ``GPL''. As a concept it's part of POSIX, and there are many different implementations under many licenses.getopt_long and getopt_long_only), and obviously that library is licensed under the GPL. Is that what you were thinking of?getopt() is less than 20 lines of C for the full POSIX implementation, and probably takes a few minutes to write.
getopt is really straightforward, though. Even /prog/ should be able to write an implementation.
/* @getopt.c */
#include <string.h>
#include <stdio.h>
char *optarg;
int optind=1, opterr, optopt;
static int optoptind=1;
int getopt(int argc, char *const argv[], const char *optstring) {
char *s, c;
if(!argv[optind] || *argv[optind]!='-' || !strcmp(argv[optind],"-") || !strcmp(argv[optind++],"--"))
return -1;
if(s=strchr(optstring,c=argv[--optind][optoptind++])) {
if(s[1]==':') {
optarg = argv[optind++][optoptind]? optoptind=0,&argv[optind][optoptind]:argv[optind++];
if(optind>argc)
c= do_opt_err(argv,':',c);
}
} else
c = do_opt_err(argv,'?',c);
optoptind = argv[optind][optoptind]?optoptind:optind++,1;
return c;
}
static int do_opt_err(char **argv, char c, char d) {
fprintf(stderr,"%s: %s %c",c=='?'?"invalid option":"missing argument for option",d);
return optopt=d;
}
opterr though ;P