1 /******************************************************************************
2 * FIDOCONFIG --- library for fidonet configs
3 ******************************************************************************
4 * Copyright (C) 1998
5 *
6 * Matthias Tichy
7 *
8 * Fido: 2:2433/1245 2:2433/1247 2:2432/605.14
9 * Internet: mtt@tichy.de
10 *
11 * Grimmestr. 12 Buchholzer Weg 4
12 * 33098 Paderborn 40472 Duesseldorf
13 * Germany Germany
14 *
15 * This file is part of FIDOCONFIG.
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Library General Public
19 * License as published by the Free Software Foundation; either
20 * version 2 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Library General Public License for more details.
26 *
27 * You should have received a copy of the GNU Library General Public
28 * License along with this library; see file COPYING. If not, write to the Free
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 *
31 * See also http://www.gnu.org
32 *****************************************************************************/
33
34 /* adapted from fconf2golded by Alex Bronin, 2:5049/36 */
35
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "fidoconf.h"
40 #include "common.h"
41
42 #ifndef VERSION_H
43 #define VERSION_H
44
45 #include "version.h"
46 #include "../cvsdate.h"
47
48 #endif
49
50 #include <huskylib/unused.h>
51
writeArea(FILE * f,s_area * area,char type)52 int writeArea(FILE *f, s_area *area, char type) {
53 unsigned int i;
54
55 switch (type) {
56 case 0: fprintf(f, "EchoArea ");
57 break;
58 case 1: fprintf(f, "NetArea ");
59 break;
60 case 2: fprintf(f, "LocalArea ");
61 break;
62 case 3: fprintf(f, "DupeArea ");
63 break;
64 case 4: fprintf(f, "BadArea ");
65 }
66
67 fprintf(f, "%s", area->areaName);
68
69 if (area->msgbType != MSGTYPE_PASSTHROUGH) fprintf(f, " %s", area->fileName);
70 else fprintf(f, " passthrough");
71
72 if (area->msgbType == MSGTYPE_SQUISH) fprintf(f, " -$");
73 if (area->msgbType == MSGTYPE_PASSTHROUGH) fprintf(f, " -0");
74
75 if (area->description!=NULL) fprintf(f, " -$n\"%s\"", area->description);
76
77 if (area->group && strcmp(area->group,"0")) fprintf(f, " -$g%s",area->group);
78
79 if (area->purge) fprintf(f, " -$d%u", area->purge);
80
81 if (area->max) fprintf(f, " -$m%u", area->max);
82
83 fprintf(f, " -p%s", aka2str(*area->useAka));
84
85 for (i=0; i<area->downlinkCount; i++)
86 fprintf(f, " %s", aka2str(area->downlinks[i]->link->hisAka));
87
88 fprintf(f, "\n");
89
90 return 0;
91 }
92
readDefaultConfig(char * cfg_file,char * def_file)93 int readDefaultConfig(char *cfg_file, char *def_file) {
94 FILE *f1,*f2;
95 char buffer[2048];
96
97 if ((f1=fopen(def_file,"rt"))==NULL) {
98 perror("Orig. file not found!");
99 return -1;
100 }
101 else {
102 if ((f2=fopen (cfg_file,"wt"))==NULL) {
103 perror("Can't create dest. file!");
104 return -2;
105 }
106 else {
107 while (fgets(buffer,sizeof(buffer),f1))
108 fputs (buffer,f2);
109 }
110 fclose(f1);
111 fclose(f2);
112 }
113 return 0;
114 }
115
generateMsgEdConfig(s_fidoconfig * config,char * fileName,int areasOnly)116 int generateMsgEdConfig(s_fidoconfig *config, char *fileName, int areasOnly) {
117 FILE *f;
118 unsigned int i;
119 s_area *area;
120
121 unused(areasOnly);
122
123 if (strcmp(fileName,"-") == 0)
124 f = stdout;
125 else
126 f = fopen(fileName, "a+");
127 if (f!= NULL) {
128
129 for (i=0; i<config->netMailAreaCount; i++) {
130 writeArea(f, &(config->netMailAreas[i]), 1);
131 }
132 writeArea(f, &(config->dupeArea), 3);
133 writeArea(f, &(config->badArea), 4);
134
135 for (i=0; i<config->echoAreaCount; i++) {
136 area = &(config->echoAreas[i]);
137 /* if (area->msgbType != MSGTYPE_PASSTHROUGH) */
138 writeArea(f, area, 0);
139 }
140
141 for (i=0; i<config->localAreaCount; i++) {
142 area = &(config->localAreas[i]);
143 writeArea(f, area, 2);
144 }
145
146 return 0;
147 } else printf("Could not write %s\n", fileName);
148
149 return 1;
150 }
151
main(int argc,char * argv[])152 int main (int argc, char *argv[]) {
153 s_fidoconfig *config;
154
155 { char *temp;
156 printf("%s\n", temp=GenVersionStr( "fconf2squish", FC_VER_MAJOR,
157 FC_VER_MINOR, FC_VER_PATCH, FC_VER_BRANCH, cvs_date ));
158 nfree(temp);
159 }
160
161 if (argc < 2) {
162 fprintf(stderr,"\nUsage:\n");
163 fprintf(stderr," fconf2squish <squish.cfg>|- [<default.cfg>]\n");
164 fprintf(stderr," (- as squish.cfg means stdout)\n");
165 fprintf(stderr," (you may read config defaults from default.cfg)\n");
166 fprintf(stderr,"\nExample:\n");
167 fprintf(stderr," fconf2squish ~/squish/squish.cfg\n");
168 fprintf(stderr," fconf2squish - | sed \"\\/var\\/fido\\//u:\\\\\\/gi\" > /etc/fido/squish.cfg\n\n");
169 return 1;
170 }
171
172 fprintf(stderr,"Generating Config-file %s\n", argv[1]);
173
174 config = readConfig(NULL);
175 if (config!= NULL) {
176
177 if (argv[2]!=NULL) readDefaultConfig (argv[1], argv[2]);
178 else
179 remove (argv[1]);
180
181 generateMsgEdConfig(config, argv[1], 0);
182 disposeConfig(config);
183 return 0;
184 }
185
186 return 1;
187 }
188