Revision 12350,
1.2 KB
checked in by ghudson, 26 years ago
(diff) |
Some RCS ID cleanup: delete $Log$ and replace other RCS keywords with $Id$.
|
Rev | Line | |
---|
[4] | 1 | /* |
---|
[12350] | 2 | * $Id: dent.c,v 1.3 1999-01-22 23:09:17 ghudson Exp $ |
---|
[4] | 3 | */ |
---|
| 4 | |
---|
| 5 | #ifndef lint |
---|
[12350] | 6 | static char *rcsid_dent_c = "$Id: dent.c,v 1.3 1999-01-22 23:09:17 ghudson Exp $"; |
---|
[12145] | 7 | #endif /* lint */ |
---|
[4] | 8 | |
---|
| 9 | #include <stdio.h> |
---|
| 10 | |
---|
| 11 | #define MAXCHARS 1024 /* maximum length of a single line */ |
---|
| 12 | |
---|
| 13 | /* |
---|
| 14 | This routine indents the standard input. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | main(argc,argv) |
---|
| 18 | int argc; |
---|
| 19 | char *argv[]; |
---|
| 20 | { |
---|
| 21 | FILE *fptr = stdin; /* initially read standard input file */ |
---|
| 22 | register int i,j; |
---|
| 23 | int nspaces = 8; |
---|
| 24 | for(i = 1; i < argc; i++) { |
---|
| 25 | if(argv[i][0] == '-') { |
---|
| 26 | if(sscanf(&argv[i][1],"%d",&nspaces) == 0) { |
---|
| 27 | fprintf(stderr, |
---|
| 28 | "%s: argument must be integer.\n", |
---|
| 29 | argv[0]); |
---|
| 30 | exit(1); |
---|
| 31 | } |
---|
| 32 | continue; |
---|
| 33 | } |
---|
| 34 | if((fptr = fopen(argv[i],"r")) == NULL) { |
---|
| 35 | fprintf(stderr,"%s: no such file %s.\n", |
---|
| 36 | argv[0],argv[i]); |
---|
| 37 | exit(1); |
---|
| 38 | } |
---|
| 39 | indent(fptr,nspaces); |
---|
| 40 | fclose(fptr); |
---|
| 41 | } |
---|
| 42 | if(fptr == stdin) indent(fptr,nspaces); |
---|
| 43 | exit(0); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | int indent(fptr,nspaces) |
---|
| 47 | FILE *fptr; |
---|
| 48 | int nspaces; |
---|
| 49 | { |
---|
| 50 | register int i,j; |
---|
| 51 | char line[MAXCHARS]; |
---|
| 52 | while(fgets(line,MAXCHARS,fptr) != NULL) { |
---|
| 53 | if(strlen(line) >= 1) { |
---|
| 54 | spaceout(nspaces); |
---|
| 55 | for (j = 0; j < strlen(line); j++) { |
---|
| 56 | putchar(line[j]); |
---|
| 57 | if(line[j] == '\r') spaceout(nspaces); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | spaceout(spaces) |
---|
| 63 | register int spaces; |
---|
| 64 | { |
---|
| 65 | while(spaces-- > 0) putchar(' '); |
---|
| 66 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.