|
|
1.1 root 1: /* cvldev.c: COnvert a Coherent L-devices file into a Taylor UUCP
2: * port file.
3: */
4:
5: #include <stdio.h>
6: #include <string.h>
7:
8: #define LDEV "/usr/lib/uucp/L-devices"
9: #define PORT "/usr/lib/uucp/port"
10:
11: int readfile(); /* read L-devices file */
12: int convert_line(); /* convert line from L-devices into port entries */
13: int write_entry(); /* add the entry to the port file */
14:
15: /* stuff to be used to build port entry */
16: char port_type[4]; /* from ldev, either DIR pr ACU */
17: char dev_use[15]; /* 'line' from ldev, device call made on */
18: char dialer[15]; /* 'brand' from ldev, which should match a
19: * 'dial' file entry from converted modemcap.
20: */
21: char baud[6]; /* baud rate from ldev entry */
22:
23: main()
24: {
25:
26: FILE *infp; /* our input file L-devices */
27:
28: umask(0177);
29:
30: /* open file, abort on error */
31: if( (infp = fopen(LDEV,"r")) == NULL){
32: printf("Failed to open %s.\n",LDEV);
33: exit(1);
34: }
35:
36:
37: while (readfile(infp)){
38: /* do nothing */
39: ;
40: }
41:
42: fclose(infp);
43: }
44:
45:
46: /* readfile: read a line from L-devices. Skip blank and comment lines. */
47:
48: readfile(infile)
49: FILE *infile;
50: {
51:
52: char ldevline[75]; /* line read from L-devices file */
53:
54: if(fgets(ldevline,sizeof(ldevline),infile) == NULL){
55: /* we hit EOF or some error occured */
56: return(0);
57: }
58:
59: if( (ldevline[0] == '#') || (ldevline[0] == '\n')){
60: /* skip comment or blank line */
61: return(1);
62: }
63: #ifdef DEBUG
64: printf("want to parse: %s",ldevline);
65: #endif
66: return(convert_line(ldevline));
67: }
68:
69:
70: /* convert_line() will walk down the string passed to it, extracting the
71: * three fields (type, line and brand) needed to build a port entry.
72: */
73:
74: convert_line(ldevline)
75: char *ldevline;
76: {
77: char *ptrldev; /* pointer to Ldev line passed to us */
78: char *ptrport; /* pointer to port field we will fill */
79:
80: /* initialize our stuff */
81:
82: strcpy(port_type,"");
83: strcpy(dev_use,"");
84: strcpy(dialer,"");
85:
86: ptrldev = ldevline;
87:
88: /* now we parse out the port type from L-devices entry, which
89: * is either ACU or DIR. We only really need to look at the
90: * first character to know what the port type will be.
91: */
92:
93: if(*ptrldev == 'D'){
94: strcpy(port_type,"direct ");
95: }
96:
97: if(*ptrldev == 'A'){
98: strcpy(port_type,"modem ");
99: }
100:
101: /* if port_type is still NULL at this point, then there is
102: * something wrong with this line. We will print the line
103: * and abort.
104: */
105:
106: if(strlen(port_type) == 0){
107: printf("Error parsing L-devices entry.\n");
108: printf("An 'A' or 'D' was expected in the 1st field:\n");
109: printf("Line read was: %s\n",ldevline);
110: return(0);
111: }
112:
113: #ifdef DEBUG
114: printf("parsed [%s] from 1st field\n",port_type);
115: #endif
116:
117: /* now we walk down our string past the first field, which will be
118: * terminated by either a space or a tab. When we hit the space or
119: * tab, we keep going until we don't hit a space or tab, which should
120: * be the begining of the next field we want to parse.
121: */
122:
123: ptrport = dev_use; /* we are filling in our 'line' field */
124:
125: ptrldev+=3; /* skip first field of 3 chars */
126:
127: while(isspace(*ptrldev)){
128: /* do nothing, keep on skipping */
129: #ifdef DEBUG
130: printf("skipping [%d]\n", *ptrldev);
131: #endif
132: ptrldev++;
133: }
134:
135: /* no we fill in out field until we hit a space or tab */
136: while(0 == isspace(*ptrldev)){
137:
138: #ifdef DEBUG
139: printf("%c [%d]",*ptrldev, *ptrldev);
140: #endif
141: *ptrport++ = *ptrldev++;
142: }
143:
144: *ptrport = '\0'; /* terminate our string */
145:
146: #ifdef DEBUG
147: printf("field is {%s}\n",dev_use);
148: #endif
149:
150: /* we will now skip the remote field to get to the
151: * baud field.
152: */
153:
154:
155: while(isspace(*ptrldev++)) /* skip remote */
156: ;
157: while(!isspace(*ptrldev++))
158: ;
159:
160: ptrport = baud;
161: while(isspace(*ptrldev)) /* get baud */
162: ptrldev++;
163: while(!isspace(*ptrldev))
164: *ptrport++ = *ptrldev++;
165:
166: *ptrport = '\0';
167:
168: while(isspace(*ptrldev++))
169: ;
170:
171: ptrport = dialer; /* point to the dialer field to use */
172:
173: ptrldev--;
174: while(!isspace(*ptrldev))
175: *ptrport++ = *ptrldev++;
176:
177: *ptrport = '\0';
178:
179:
180: #ifdef DEBUG
181: printf("Parsed: type %s line %s dialer %s\n",
182: port_type, dev_use, dialer);
183: #endif
184:
185: return(write_entry());
186: }
187:
188:
189: /* write_entry() will open the port file and write an appropriate
190: * entry into it.
191: */
192:
193:
194: write_entry()
195: {
196: FILE *outfp;
197:
198: if((outfp = fopen(PORT,"a")) == NULL){
199: printf("Error opening %s to write entry.\n",PORT);
200: return(0);
201: }
202:
203:
204: #ifdef DEBUG
205: printf("write %s %s %s \n",dev_use, port_type, dev_use);
206: #endif
207: fprintf(outfp,"port %s\n",dev_use);
208: fprintf(outfp,"type %s\n",port_type[0] == 'm'? "modem" : "direct");
209: fprintf(outfp,"device /dev/%s\n",dev_use);
210: fprintf(outfp,"baud %s\n",baud);
211:
212: if(port_type[0] == 'm'){
213: fprintf(outfp,"dialer %s\n\n",dialer);
214: }else{
215: fprintf(outfp,"\n");
216: }
217:
218: fflush(outfp);
219: fclose(outfp);
220: return(1);
221: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.