A large commit.
[pdp8.git] / sw / dumprest / original / config.c
1 /* Config file format
2 Config file dumprest.cfg or $HOME/.dumprest.cfg
3
4 baud rate
5 0 if 1 stop bit or 1 if two stop bits
6 serial device to use
7
8 example:
9 9600
10 0
11 /dev/ttyS1
12
13 PC example
14 9600
15 0
16 com1
17
18 Or
19 PC example
20 9600
21 0
22 2f8,3
23
24 The 2f8 is base address of port and 3 is the irq
25 */
26
27 #ifndef PC
28
29 struct {
30 char *baud_str;
31 long bits_per_sec;
32 long baud_val;
33 } baud_lookup[] =
34 {
35 { "50",50,B50},
36 { "75",75,B75},
37 { "110",110,B110},
38 { "134",134,B134},
39 { "150",150,B150},
40 { "200",200,B200},
41 { "300",300,B300},
42 { "600",600,B600},
43 { "1200",1200,B1200},
44 { "1800",1800,B1800},
45 { "2400",2400,B2400},
46 { "4800",4800,B4800},
47 { "9600",9600,B9600},
48 { "19200",19200,B19200}
49 #ifdef B38400
50 ,{ "38400",38400,B38400}
51 #endif
52 #ifdef B57600
53 ,{ "57600",57600,B57600}
54 #endif
55 #ifdef B115200
56 ,{ "115200",115200,B115200}
57 #endif
58 #ifdef B230400
59 ,{ "230400",230400,B230400}
60 #endif
61 #ifdef B460800
62 ,{ "460800",460800,B460800}
63 #endif
64 };
65
66 #endif
67
68 #if defined(_STDC_) || defined(PC)
69 void setup_config(long *,int *,char *);
70 #endif
71
72 void setup_config(baud,two_stop,serial_dev)
73 long *baud;
74 int *two_stop;
75 char *serial_dev;
76 {
77 FILE *config;
78 char homeloc[256];
79 char *home;
80 #ifndef PC
81 char baud_rate[32];
82 int cntr;
83 #endif
84
85 config = fopen("dumprest.cfg","r");
86 if (config == NULL) {
87 home = getenv("HOME");
88 if (home != NULL) {
89 strcpy(homeloc,home);
90 strcat(homeloc,"/");
91 strcat(homeloc,".dumprest.cfg");
92 config = fopen(homeloc,"r");
93 }
94 if (config == NULL) {
95 printf("Unable to open dumprest.cfg or $HOME/.dumprest.cfg\n");
96 exit(1);
97 }
98 }
99 #ifdef PC
100 fscanf(config,"%ld",baud);
101 #else
102 fscanf(config,"%s",baud_rate);
103 *baud = B0;
104 for (cntr = 0; cntr < ARRAYSIZE(baud_lookup) && *baud == B0; cntr++) {
105 if (strcmp(baud_lookup[cntr].baud_str,baud_rate) == 0) {
106 *baud = baud_lookup[cntr].baud_val;
107 }
108 }
109 if (*baud == B0) {
110 printf("Unknown baud rate %s\n",baud_rate);
111 exit(1);
112 }
113 #endif
114 fscanf(config,"%d",two_stop);
115 fscanf(config,"%s",serial_dev);
116 fclose(config);
117 }