1 /******************************************************************************
2 * FIDOCONFIG --- library for fidonet configs
3 ******************************************************************************
4 * Copyright (C) 1998-1999
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 #define AREASONLY 0x1
32 #define NETMAIL 0x2
33 #define ECHOMAIL 0x4
34 #define LOCAL 0x8
35 #define DUPE 0x10
36 #define BAD 0x20
37
38 #include <stdlib.h>
39
40 #include "fidoconf.h"
41 #include "common.h"
42
43 #ifndef VERSION_H
44 #define VERSION_H
45
46 #include "version.h"
47 #include "../cvsdate.h"
48
49 #endif
50
writeArea(FILE * f,s_area * area,char type)51 int writeArea(FILE *f, s_area *area, char type) {
52
53 if (area->group == NULL) area->group = "0";
54
55 fprintf(f, "areadef %s \"%s\" %s ", area->areaName, area->areaName, area->group);
56
57 switch (type) {
58 case 0: fprintf(f, "local ");
59 break;
60 case 1: fprintf(f, "net ");
61 break;
62 case 2: fprintf(f, "local ");
63 break;
64 }
65
66 if (area->msgbType == MSGTYPE_SQUISH) fprintf(f, "Squish ");
67 else fprintf(f, "Opus ");
68
69 fprintf(f, "%s ", area->fileName);
70
71 fprintf(f, "%u:%u/%u.%u", area->useAka->zone, area->useAka->net, area->useAka->node, area->useAka->point);
72
73 fprintf(f, "\n");
74
75 return 0;
76 }
77
generateAquaedConfig(s_fidoconfig * config,char * fileName,char * includeFile,int options)78 int generateAquaedConfig(s_fidoconfig *config, char *fileName, char *includeFile,int options) {
79 FILE *f;
80 unsigned int i;
81 s_area *area;
82
83 f = fopen(fileName, "w");
84 if (f!= NULL) {
85
86 if (includeFile != NULL) fprintf(f, "include %s\n\n", includeFile);
87
88 if (!(options & AREASONLY)) {
89 fprintf(f, "username %s\n\n", config->sysop);
90 if (config->echotosslog != NULL) fprintf(f, "squishechotoss %s\n", config->echotosslog);
91
92 for (i=0; i<config->addrCount; i++)
93 fprintf(f, "Address %u:%u/%u.%u\n", config->addr[i].zone, config->addr[i].net, config->addr[i].node, config->addr[i].point);
94 fprintf(f, "\n");
95 }
96 if (!(options & NETMAIL)) {
97 for (i=0; i<config->netMailAreaCount; i++) {
98 writeArea(f, &(config->netMailAreas[i]), 1);
99 }
100 }
101 if (!(options & DUPE)){
102 writeArea(f, &(config->dupeArea), 1);
103 }
104 if (!(options & BAD)) {
105 writeArea(f, &(config->badArea), 1);
106 }
107 if (!(options & ECHOMAIL)) {
108 for (i=0; i<config->echoAreaCount; i++) {
109 area = &(config->echoAreas[i]);
110 if (area->msgbType != MSGTYPE_PASSTHROUGH)
111 writeArea(f, area, 0);
112 }
113 }
114 if (!(options & LOCAL)) {
115 for (i=0; i<config->localAreaCount; i++) {
116 area = &(config->localAreas[i]);
117 if (area->msgbType != MSGTYPE_PASSTHROUGH)
118 writeArea(f, area, 2);
119 }
120 }
121 return 0;
122 } else printf("Could not write %s\n", fileName);
123
124 return 1;
125 }
126
parseOptions(char * line)127 int parseOptions(char *line){
128 int options=0;
129 char chr=0;
130
131 if (sstrcmp(line,"-a")==0) chr='a';
132 else (chr=line[2]);
133
134 switch (chr){
135
136 case 'a': {
137 options^=AREASONLY;
138 break;
139 }
140 case 'n': {
141 options^=NETMAIL;
142 break;
143 }
144 case 'e': {
145 options^=ECHOMAIL;
146 break;
147 }
148
149 case 'l': {
150 options^=LOCAL;
151 break;
152 }
153 case 'd': {
154 options^=DUPE;
155 break;
156 }
157 case 'b': {
158 options^=BAD;
159 break;
160 }
161
162 }
163 return options;
164 }
165
main(int argc,char * argv[])166 int main (int argc, char *argv[]) {
167 s_fidoconfig *config;
168 int options=0;
169 int cont=1;
170
171 { char *temp;
172 printf("%s\n", temp=GenVersionStr( "fconf2aquaed", FC_VER_MAJOR,
173 FC_VER_MINOR, FC_VER_PATCH, FC_VER_BRANCH, cvs_date ));
174 nfree(temp);
175 }
176
177 while ((cont<argc)&&(*argv[cont]=='-')){
178 options|=parseOptions(argv[cont]);
179 cont++;
180 }
181 if (!(cont<argc)){
182 printf("\nUsage:\n");
183 printf("fconf2aquaed [-a][-sn][-se][-sl][-sb][-sd] <aqauedConfigFileName> [<default.cfg>]\n");
184 printf(" (you may include config defaults from default.cfg)\n");
185 printf(" (-a exports areas only)\n");
186 printf(" (-sn skip netmail areas)\n");
187 printf(" (-se skip echomail areas)\n");
188 printf(" (-sl skip local areas, and so on...)\n");
189 printf("\nExample:\n");
190 printf(" fconf2aquaed ~/aquaed/aquaed.cfg\n\n");
191 return 1;
192 }
193
194 printf("Generating Config-file %s\n", argv[cont]);
195
196 config = readConfig(NULL);
197 if (config!= NULL) {
198 generateAquaedConfig(config, argv[cont], argv[cont+1],options);
199 disposeConfig(config);
200 return 0;
201 }
202
203 return 1;
204 }
205