Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Brainfuck

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

Name: Anonymous 2009-12-23 1:00

>>30

/* @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;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List