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