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 <string.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
usage()51 void usage(){
52 printf("\nUsage:\n");
53 printf(" fconf2msged [-a][-sn][-se][-sl][-sb][-sd] <msgedConfigFileName>\n");
54 printf(" (-a exports areas only)\n");
55 printf(" (-sn skip netmail areas)\n");
56 printf(" (-se skip echomail areas)\n");
57 printf(" (-sl skip local areas, and so on...)\n");
58 printf(" (-h print this message and exit)\n");
59 printf("\nExample:\n");
60 printf(" fconf2msged ~/.msged\n\n");
61 }
62
writeArea(FILE * f,s_area * area,char netMail)63 int writeArea(FILE *f, s_area *area, char netMail) {
64 switch (area->msgbType) {
65
66 case (MSGTYPE_SQUISH): fprintf(f, "Squish ");
67 break;
68
69 case (MSGTYPE_SDM): fprintf(f, "Fido ");
70 break;
71
72 case (MSGTYPE_JAM): fprintf(f, "Jam ");
73 break;
74 }
75
76 if (netMail == 1) fprintf(f, "mp");
77 else fprintf(f, "e");
78 fprintf(f, "8u ");
79
80 fprintf(f, "\"%s\" %s %s ", area->areaName, area->fileName, (netMail!=1) ? area->areaName : "");
81
82 fprintf(f, "%u:%u/%u.%u", area->useAka->zone, area->useAka->net, area->useAka->node, area->useAka->point);
83
84 fprintf(f, "\n");
85
86 return 0;
87 }
88
generateMsgEdConfig(s_fidoconfig * config,char * fileName,int options)89 int generateMsgEdConfig(s_fidoconfig *config, char *fileName, int options) {
90 FILE *f;
91 unsigned int i;
92 s_area *area;
93
94 f = fopen(fileName, "w");
95 if (f!= NULL) {
96 if (!(options & AREASONLY)) {
97
98 fprintf(f, "Name \"%s\"\n\n", config->sysop);
99
100 for (i=0; i<config->addrCount; i++)
101 fprintf(f, "Address %u:%u/%u.%u\n", config->addr[i].zone, config->addr[i].net, config->addr[i].node, config->addr[i].point);
102
103 if (config->echotosslog != NULL) fprintf(f, "tossLog %s\n", config->echotosslog);
104 if (config->nodelistDir != NULL && config->fidoUserList != NULL)
105 {
106 fprintf(f, "Userlist %s%s\n",
107 config->nodelistDir, config->fidoUserList);
108 }
109
110 fprintf(f, "\n");
111 }
112 if (!(options & NETMAIL)) {
113 for (i=0; i<config->netMailAreaCount; i++) {
114 writeArea(f, &(config->netMailAreas[i]), 1);
115 }
116 }
117 if (!(options & DUPE)) {
118 writeArea(f, &(config->dupeArea), 0);
119 }
120 if (!(options & BAD)) {
121 writeArea(f, &(config->badArea), 0);
122 }
123 if (!(options & LOCAL)) {
124 for (i=0; i<config->localAreaCount; i++) {
125 area = &(config->localAreas[i]);
126 if (area->msgbType != MSGTYPE_PASSTHROUGH)
127 writeArea(f, area, 0);
128 }
129 }
130 if (!(options & ECHOMAIL)) {
131 for (i=0; i<config->echoAreaCount; i++) {
132 area = &(config->echoAreas[i]);
133 if (area->msgbType != MSGTYPE_PASSTHROUGH)
134 writeArea(f, area, 0);
135 }
136 }
137 return 0;
138 } else printf("Could not write %s\n", fileName);
139
140 return 1;
141 }
142
parseOptions(char * line)143 int parseOptions(char *line){
144 int options=0;
145 char chr=0;
146
147 if(line[0]!='-'){
148 fprintf(stderr,"This is not option: \"%s\", exit\n",line);
149 exit(1);
150 }
151 if (line[2]==0) chr=line[1];
152 else if (line[1]=='s' && line[3]=='\0') chr=line[2];
153 else chr=' '; /* unknown option indication */
154
155 switch (chr){
156
157 case 'a': {
158 options^=AREASONLY;
159 break;
160 }
161 case 'n': {
162 options^=NETMAIL;
163 break;
164 }
165 case 'e': {
166 options^=ECHOMAIL;
167 break;
168 }
169
170 case 'l': {
171 options^=LOCAL;
172 break;
173 }
174 case 'd': {
175 options^=DUPE;
176 break;
177 }
178 case 'b': {
179 options^=BAD;
180 break;
181 }
182 case 'H':
183 case 'h': usage();
184 exit(0);
185 default:
186 fprintf(stderr,"Unknown option \"%s\", exit\n",line);
187 exit(1);
188
189 }
190 return options;
191 }
192
193
main(int argc,char * argv[])194 int main (int argc, char *argv[]) {
195 s_fidoconfig *config;
196 int options=0;
197 int cont=1;
198
199 { char *temp;
200 printf("%s\n", temp=GenVersionStr( "fconf2msged", FC_VER_MAJOR,
201 FC_VER_MINOR, FC_VER_PATCH, FC_VER_BRANCH, cvs_date ));
202 nfree(temp);
203 }
204
205 while ((cont<argc)&&(*argv[cont]=='-')){
206 options|=parseOptions(argv[cont]);
207 cont++;
208 }
209 if (!(cont<argc)){
210 usage();
211 return 1;
212 }
213
214 printf("Generating Config-file %s\n", argv[cont]);
215
216 config = readConfig(cont+1<argc?argv[cont+1]:NULL);
217 if (config!= NULL) {
218 generateMsgEdConfig(config, argv[cont], options);
219 disposeConfig(config);
220 return 0;
221 }
222
223 return 1;
224 }
225