home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
mag&info
/
cujmay93.zip
/
1105108B
< prev
next >
Wrap
Text File
|
1993-03-09
|
2KB
|
67 lines
/* pr.c: Skeleton of a file printer program */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
static int
Copies = 1, /* Default to one copy */
Number = 0; /* Don't print with line numbers */
static char
Queue = 'S'; /* Default to standard printer */
static void process(char *);
main(int argc, char *argv[])
{
int i;
char *s;
/* Process each argument immediately */
for (i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
for (s = argv[i]+1; *s; ++s)
switch(toupper(*s))
{
case 'C': /* Build number for copies */
if (isdigit(s[1]))
for (Copies = 0; isdigit(s[1]); ++s)
Copies = Copies*10 + (s[1] - '0');
break;
case 'N': /* Toggle line numbering */
Number = !Number;
break;
case 'Q': /* Select print queue */
++s;
Queue = toupper(*s);
break;
default:
fprintf(stderr,"pr: Bad option: -%c\n",*s);
return EXIT_FAILURE;
}
else
process(argv[i]);
}
return EXIT_SUCCESS;
}
static void process(char *s)
{
printf("Processing %s...\n",s);
printf("\tCopies: %d, Number: %d, Queue: %c\n",
Copies,Number,Queue);
}
/* The output after executing the command line above is
Processing file1.c...
Copies: 10, Number: 1, Queue: S
Processing file2.c...
Copies: 1, Number: 0, Queue: L
Processing file3.c...
Copies: 1, Number: 0, Queue: L
*/