Commit | Line | Data |
---|---|---|
3b600ead TL |
1 | main(argc,argv) |
2 | char *argv[]; | |
3 | { | |
4 | /* program to convert tables to new format */ | |
5 | char *col[20], *len[20]; | |
6 | char s[200], *p; | |
7 | char stt[30]; | |
8 | int i,j,k,m, first; | |
9 | extern int cin, cout; | |
10 | for(i=0;i<20;i++) | |
11 | col[i]=len[i]=0; | |
12 | first=1; | |
13 | while (argc>1 || first) | |
14 | { | |
15 | first=0; | |
16 | if (argc>1) | |
17 | { | |
18 | cin = copen(argv[1], 'r'); | |
19 | cout = copen(tmpnam(stt), 'w'); | |
20 | } | |
21 | if (cin<0) | |
22 | { | |
23 | printf("can't open file %s\n",argv[1]); | |
24 | cexit(1); | |
25 | } | |
26 | while (gets(s)) | |
27 | { | |
28 | puts(s); | |
29 | if (!prefix(".TS", s)) | |
30 | continue; | |
31 | gets(s); | |
32 | k=0; | |
33 | for(p=s; *p; p++) | |
34 | { | |
35 | if (letter(*p)) | |
36 | { | |
37 | col[k++]=p; | |
38 | while (letter(*p)) | |
39 | p++; | |
40 | if (digit(*p)) | |
41 | len[k-1]=p; | |
42 | while (digit(*p)) | |
43 | p++; | |
44 | } | |
45 | if (*p==0)break; | |
46 | } | |
47 | for(i=m=0; i<k; i++) | |
48 | m=max(length(col[i]),m); | |
49 | for(i=0; i<m; i++) | |
50 | { | |
51 | for(j=0; j<k; j++) | |
52 | { | |
53 | printf("%c ", *(col[j])++); | |
54 | if (!letter(*(col[j]))) col[j]--; | |
55 | if (i==0 && len[i]) | |
56 | { | |
57 | p=len[j]; | |
58 | while (digit(*p)) | |
59 | putchar(*p++); | |
60 | } | |
61 | } | |
62 | if (i+1==m) | |
63 | printf("."); | |
64 | printf("\n"); | |
65 | } | |
66 | for(i=0;i<20; i++) | |
67 | col[i]=len[i]=0; | |
68 | } | |
69 | if (argc>1) | |
70 | { | |
71 | printf(-1, s, "mv %s %s", stt, argv[1]); | |
72 | system(s); | |
73 | argc--; | |
74 | argv++; | |
75 | } | |
76 | } | |
77 | } | |
78 | length(s) | |
79 | char *s; | |
80 | { | |
81 | int k; | |
82 | for(k=0; s[k]; k++) | |
83 | if (!letter(s[k])) break; | |
84 | return(k); | |
85 | } | |
86 | digit(c) | |
87 | { | |
88 | return(c>='0' && c<= '9'); | |
89 | } | |
90 | letter(c) | |
91 | { | |
92 | return((c>='a' && c<= 'z') || (c>= 'A' && c<='Z')); | |
93 | } | |
94 | prefix(small, big) | |
95 | char *small, *big; | |
96 | { | |
97 | int c; | |
98 | while ((c= *small++) == *big++) | |
99 | if (c==0) return(1); | |
100 | return(c==0); | |
101 | } | |
102 | max(a,b) | |
103 | { | |
104 | return(a>b? a : b); | |
105 | } |