author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 30 Apr 2009 23:38:48 +0200 | |
changeset 88 | 91fbc3ea240b |
parent 85 | 9568a180fc43 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
77 | 2 |
* numerierung.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <errno.h> |
|
9 |
#include <getopt.h> |
|
10 |
||
11 |
void usage (char *cmd) |
|
12 |
{ |
|
85
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
13 |
printf ("Usage: %s [-h|-p] [<file>]\n", cmd); |
0 | 14 |
exit (0); |
15 |
} |
|
16 |
||
17 |
int main (int argc, char **argv) |
|
18 |
{ |
|
85
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
19 |
char buffer[240]; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
20 |
|
0 | 21 |
int counter = 0; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
22 |
|
0 | 23 |
FILE *f; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
24 |
|
0 | 25 |
int c, pure = 0; |
26 |
||
85
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
27 |
struct option options[] = { |
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
28 |
{"help", 0, 0, 'h'}, |
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
29 |
{"pure", 0, 0, 'p'}, |
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
30 |
}; |
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
31 |
|
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
32 |
while ((c = getopt_long_only (argc, argv, "hp", options, NULL)) != -1) { |
0 | 33 |
switch (c) { |
34 |
case 'h': |
|
35 |
usage (argv[0]); |
|
36 |
break; |
|
37 |
case 'p': |
|
38 |
pure = 1; |
|
39 |
break; |
|
40 |
default: |
|
41 |
printf ("Unknown Parameter: %s\n", argv[optind]); |
|
42 |
} |
|
43 |
} |
|
44 |
||
45 |
if (optind == argc) |
|
46 |
f = stdin; |
|
47 |
else |
|
48 |
f = fopen (argv[optind], "r"); |
|
49 |
||
50 |
if (!f) { |
|
51 |
perror ("Error opening file"); |
|
52 |
return EXIT_FAILURE; |
|
53 |
} |
|
54 |
||
55 |
*buffer = 0; |
|
56 |
||
85
9568a180fc43
[getopt]: support for long options
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
57 |
while (fgets (buffer, sizeof (buffer), f) != NULL) { |
0 | 58 |
if (!pure) |
59 |
printf ("%4.4d: %s", counter++, buffer); |
|
60 |
else |
|
61 |
printf ("%s", buffer); |
|
62 |
*buffer = 0; |
|
63 |
} |
|
64 |
||
65 |
fclose (f); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
66 |
|
0 | 67 |
return EXIT_SUCCESS; |
68 |
} |