Added a skeleton of generic C program.

This commit is contained in:
Serge Vakulenko
2014-05-05 11:19:42 -07:00
parent a433085324
commit ed92365a4c
2 changed files with 85 additions and 1 deletions

View File

@@ -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?/*)

83
share/example/skeleton.c Normal file
View File

@@ -0,0 +1,83 @@
/*
* Sample program.
*
* Copyright (C) 1993-2004 Serge Vakulenko, <vak@cronyx.ru>
*
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
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<argc; ++i)
printf ("%s ", argv[i]);
printf ("\n");
}
return (0);
}