diff --git a/Makefile b/Makefile index a95e0be..125ec2d 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,8 @@ SHARE_FILES = share/re.help share/example/Makefile \ share/example/blkjack.bas share/example/hilow.bas \ share/example/stars.bas share/example/prime.scm \ share/example/fact.fth share/example/echo.S \ - share/example/stdarg.c $(wildcard share/smallc/*) + share/example/stdarg.c share/example/skeleton.c \ + $(wildcard share/smallc/*) MANFILES = share/man/ share/man/cat1/ share/man/cat2/ share/man/cat3/ \ share/man/cat4/ share/man/cat5/ share/man/cat6/ share/man/cat7/ \ share/man/cat8/ $(wildcard share/man/cat?/*) diff --git a/share/example/skeleton.c b/share/example/skeleton.c new file mode 100644 index 0000000..cbdae85 --- /dev/null +++ b/share/example/skeleton.c @@ -0,0 +1,83 @@ +/* + * Sample program. + * + * Copyright (C) 1993-2004 Serge Vakulenko, + * + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You can redistribute this file and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software Foundation; + * either version 2 of the License, or (at your discretion) any later version. + * See the accompanying file "COPYING.txt" for more details. + */ +#include +#include +#include + +const char version[] = "1.0"; +const char copyright[] = "Copyright (C) 1993 Serge Vakulenko"; + +char *progname; +int verbose; +int trace; +int debug; + +extern char *optarg; +extern int optind; + +void usage () +{ + fprintf (stderr, "Skeleton of generic C program, Version %s, %s\n", version, copyright); + fprintf (stderr, "Usage:\n\t%s [-vtd] [-r count] file...\n", progname); + fprintf (stderr, "Options:\n"); + fprintf (stderr, "\t-v\tverbose mode\n"); + fprintf (stderr, "\t-t\ttrace mode\n"); + fprintf (stderr, "\t-d\tdebug\n"); + fprintf (stderr, "\t-r #\trepeat count\n"); + exit (-1); +} + +int main (int argc, char **argv) +{ + int count = 1; + + progname = *argv; + for (;;) { + switch (getopt (argc, argv, "vtdr:")) { + case EOF: + break; + case 'v': + ++verbose; + continue; + case 't': + ++trace; + continue; + case 'd': + ++debug; + continue; + case 'r': + count = strtol (optarg, 0, 0); + continue; + default: + usage (); + } + break; + } + argc -= optind; + argv += optind; + + if (argc < 1) + usage (); + + while (count-- > 0) { + int i; + + for (i=0; i