Minor config file fixes (example, conversion, and error reporting).
[ircu2.10.12-pk.git] / ircd / convert-conf.c
1 /* convert-conf.c - Convert ircu2.10.11 ircd.conf to ircu2.10.12 format.
2  * Copyright 2005 Michael Poole
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  */
19
20 #include <ctype.h> /* tolower(), toupper(), isdigit() */
21 #include <stdio.h> /* *printf(), fgets() */
22 #include <stdlib.h> /* free(), strtol() */
23 #include <string.h> /* strlen(), memcpy(), strchr(), strspn() */
24
25 #define MAX_FIELDS 5
26
27 const char *admin_names[] = { "location", "contact", "contact", 0 },
28     *connect_names[] = { "host", "password", "name", "#port", "class", 0 },
29     *crule_names[] = { "server", "",  "rule", 0 },
30     *general_names[] = { "name", "vhost", "description", "", "#numeric", 0 },
31     *motd_names[] = { "host", "file", 0 },
32     *class_names[] = { "name", "#pingfreq", "#connectfreq", "#maxlinks", "#sendq", 0 },
33     *removed_features[] = { "VIRTUAL_HOST", "OPERS_SEE_IN_SECRET_CHANNELS", "LOCOP_SEE_IN_SECRET_CHANNELS", 0 };
34 char orig_line[512], line[512], dbuf[512];
35 char *fields[MAX_FIELDS + 1];
36 unsigned int nfields;
37 unsigned int lineno;
38
39 /*** GENERIC SUPPORT CODE ***/
40
41 static int split_line(char *input, char **output)
42 {
43     size_t quoted = 0, jj;
44     char *dest = dbuf, ch;
45
46     nfields = 1;
47     output[0] = dest;
48     while (*input != '\0' && *input != '#') switch (ch = *input++) {
49     case ':':
50         if (quoted)
51             *dest++ = ch;
52         else {
53             *dest++ = '\0';
54             if (nfields >= MAX_FIELDS)
55                 return nfields;
56             output[nfields++] = dest;
57         }
58         break;
59     case '\\':
60         switch (ch = *input++) {
61         case 'b': *dest++ = '\b'; break;
62         case 'f': *dest++ = '\f'; break;
63         case 'n': *dest++ = '\n'; break;
64         case 'r': *dest++ = '\r'; break;
65         case 't': *dest++ = '\t'; break;
66         case 'v': *dest++ = '\v'; break;
67         default: *dest++ = ch; break;
68         }
69         break;
70     case '"': quoted = !quoted; break;
71     default: *dest++ = ch;  break;
72     }
73
74     *dest = '\0';
75     for (jj = nfields; jj < MAX_FIELDS; ++jj)
76         output[jj] = dest;
77     return nfields;
78 }
79
80 static void simple_line(const char *block, const char **names, const char *extra)
81 {
82     size_t ii;
83
84     /* Print the current line and start the new block. */
85     fprintf(stdout, "# %s\n%s {\n", orig_line, block);
86
87     /* Iterate over fields in input line, formatting each. */
88     for (ii = 0; ii < nfields && names[ii]; ++ii) {
89         if (!fields[ii][0] || !names[ii][0])
90             continue;
91         else if (names[ii][0] == '#')
92             fprintf(stdout, "\t%s = %s;\n", names[ii] + 1, fields[ii]);
93         else
94             fprintf(stdout, "\t%s = \"%s\";\n", names[ii], fields[ii]);
95     }
96
97     /* Close the new block (including any fixed-form text). */
98     if (extra)
99         fprintf(stdout, "\t%s\n", extra);
100     fputs("};\n", stdout);
101 }
102
103 #define dupstring(TARGET, SOURCE) do { free(TARGET); if (SOURCE) { size_t len = strlen(SOURCE); (TARGET) = malloc(len+1); memcpy((TARGET), (SOURCE), len); } else (TARGET) = 0; } while(0)
104
105 /*** MANAGING LISTS OF STRINGS ***/
106
107 struct string_list {
108     struct string_list *next;
109     char *origin;
110     char *extra;
111     char value[1];
112 };
113
114 /** Find or insert the element from \a list that contains \a value.
115  * If an element of \a list already contains \a value, return it.
116  * Otherwise, append a new element to \a list containing \a value and
117  * return it.
118  * @param[in,out] list A list of strings.
119  * @param[in] value A string to search for.
120  * @return A string list element from \a list containing \a value.
121  */
122 static struct string_list *string_get(struct string_list **list, const char *value)
123 {
124     struct string_list *curr;
125     size_t len = strlen(value), ii;
126
127     while ((curr = *list)) {
128         for (ii = 0; tolower(curr->value[ii]) == tolower(value[ii]) && ii < len; ++ii) ;
129         if (curr->value[ii] == '\0' && value[ii] == '\0')
130             return curr;
131         list = &curr->next;
132     }
133
134     *list = calloc(1, sizeof(**list) + len);
135     memcpy((*list)->value, value, len);
136     return *list;
137 }
138
139 /*** SERVER CONNECTION RELATED CODE ***/
140
141 struct connect {
142     char *host;
143     char *password;
144     char *port;
145     char *class;
146     char *hub;
147     char *maximum;
148     struct connect *next;
149     struct string_list *origins;
150     char name[1];
151 } *connects;
152
153 static struct connect *get_connect(const char *name)
154 {
155     struct connect *conn;
156     size_t ii, nlen;
157
158     /* Look for a pre-existing connection with the same name. */
159     nlen = strlen(name);
160     for (conn = connects; conn; conn = conn->next)
161     {
162         for (ii = 0; tolower(name[ii]) == conn->name[ii] && ii < nlen; ++ii) ;
163         if (conn->name[ii] == '\0' && name[ii] == '\0')
164             break;
165     }
166
167     /* If none was found, create a new one. */
168     if (!conn)
169     {
170         conn = calloc(1, sizeof(*conn) + nlen);
171         for (ii = 0; ii < nlen; ++ii)
172             conn->name[ii] = tolower(name[ii]);
173         conn->next = connects;
174         connects = conn;
175     }
176
177     /* Return the connection. */
178     return conn;
179 }
180
181 static void do_connect(void)
182 {
183     struct connect *conn = get_connect(fields[2]);
184     dupstring(conn->host, fields[0]);
185     dupstring(conn->password, fields[1]);
186     dupstring(conn->port, fields[3]);
187     dupstring(conn->class, fields[4]);
188     string_get(&conn->origins, orig_line);
189 }
190
191 static void do_hub(void)
192 {
193     struct connect *conn = get_connect(fields[2]);
194     dupstring(conn->hub, fields[0]);
195     dupstring(conn->maximum, fields[3]);
196     string_get(&conn->origins, orig_line);
197 }
198
199 static void do_leaf(void)
200 {
201     struct connect *conn = get_connect(fields[2]);
202     free(conn->hub);
203     conn->hub = 0;
204     string_get(&conn->origins, orig_line);
205 }
206
207 static void finish_connects(void)
208 {
209     struct connect *conn;
210     struct string_list *sl;
211
212     for (conn = connects; conn; conn = conn->next)
213     {
214         for (sl = conn->origins; sl; sl = sl->next)
215             fprintf(stdout, "# %s\n", sl->value);
216         fprintf(stdout,
217                 "Connect {\n\tname =\"%s\";\n\thost = \"%s\";\n"
218                 "\tpassword = \"%s\";\n\tclass = \"%s\";\n",
219                 conn->name, conn->host, conn->password, conn->class);
220         if (conn->port && conn->port[0] != '\0')
221             fprintf(stdout, "\tport = %s;\n", conn->port);
222         else
223             fprintf(stdout,
224                     "# Every Connect block should have a port number.\n"
225                     "# To prevent autoconnects, set autoconnect = no.\n"
226                     "#\tport = 4400;\n"
227                     "\tautoconnect = no;\n");
228         if (conn->maximum && conn->maximum[0] != '\0')
229             fprintf(stdout, "\tmaxhops = %s;\n", conn->maximum);
230         if (conn->hub && conn->hub[0] != '\0')
231             fprintf(stdout, "\thub = \"%s\";\n", conn->hub);
232         fprintf(stdout, "};\n\n");
233
234     }
235 }
236
237 /*** FEATURE MANAGEMENT CODE ***/
238
239 struct feature {
240     struct string_list *values;
241     struct string_list *origins;
242     struct feature *next;
243     char name[1];
244 } *features;
245
246 struct remapped_feature {
247     const char *name;
248     const char *privilege;
249     int flags; /* 2 = global, 1 = local */
250     struct feature *feature;
251 } remapped_features[] = {
252     /* Specially handled privileges: If you change the index of
253      * anything with NULL privilege, change the code in
254      * finish_operators() to match!
255      */
256     { "CRYPT_OPER_PASSWORD", NULL, 0, 0 }, /* default: true */
257     { "OPER_KILL", NULL, 2, 0 }, /* default: true */
258     { "LOCAL_KILL_ONLY", NULL, 2, 0 }, /* default: false */
259     /* remapped features that affect all opers  */
260     { "OPER_NO_CHAN_LIMIT", "chan_limit", 3, 0 },
261     { "OPER_MODE_LCHAN", "mode_lchan", 3, 0 },
262     { "OPER_WALK_THROUGH_LMODES", "walk_lchan", 3, 0 },
263     { "NO_OPER_DEOP_LCHAN", "deop_lchan", 3, 0 },
264     { "SHOW_INVISIBLE_USERS", "show_invis", 3, 0 },
265     { "SHOW_ALL_INVISIBLE_USERS", "show_all_invis", 3, 0 },
266     { "UNLIMIT_OPER_QUERY", "unlimit_query", 3, 0 },
267     /* remapped features affecting only global opers */
268     { "OPER_REHASH", "rehash", 2, 0 },
269     { "OPER_RESTART", "restart", 2, 0 },
270     { "OPER_DIE", "die", 2, 0 },
271     { "OPER_GLINE", "gline", 2, 0 },
272     { "OPER_LGLINE", "local_gline", 2, 0 },
273     { "OPER_JUPE", "jupe", 2, 0 },
274     { "OPER_LJUPE", "local_jupe", 2, 0 },
275     { "OPER_OPMODE", "opmode", 2, 0 },
276     { "OPER_LOPMODE", "local_opmode", 2, 0 },
277     { "OPER_FORCE_OPMODE", "force_opmode", 2, 0 },
278     { "OPER_FORCE_LOPMODE", "force_local_opmode", 2, 0 },
279     { "OPER_BADCHAN", "badchan", 2, 0 },
280     { "OPER_LBADCHAN", "local_badchan", 2, 0 },
281     { "OPER_SET", "set", 2, 0 },
282     { "OPER_WIDE_GLINE", "wide_gline", 2, 0 },
283     /* remapped features affecting only local opers */
284     { "LOCOP_KILL", "kill", 1, 0 },
285     { "LOCOP_REHASH", "rehash", 1, 0 },
286     { "LOCOP_RESTART", "restart", 1, 0 },
287     { "LOCOP_DIE", "die", 1, 0 },
288     { "LOCOP_LGLINE", "local_gline", 1, 0 },
289     { "LOCOP_LJUPE", "local_jupe", 1, 0 },
290     { "LOCOP_LOPMODE", "local_opmode", 1, 0 },
291     { "LOCOP_FORCE_LOPMODE", "force_local_opmode", 1, 0 },
292     { "LOCOP_LBADCHAN", "local_badchan", 1, 0 },
293     { "LOCOP_WIDE_GLINE", "wide_gline", 1, 0 },
294     { 0, 0, 0, 0 }
295 };
296
297 static void do_feature(void)
298 {
299     struct feature *feat;
300     size_t ii;
301
302     ii = strlen(fields[0]);
303     feat = calloc(1, sizeof(*feat) + ii);
304     while (ii-- > 0)
305         feat->name[ii] = toupper(fields[0][ii]);
306     feat->next = features;
307     features = feat;
308     string_get(&feat->origins, orig_line);
309     for (ii = 1; fields[ii] && fields[ii][0]; ++ii)
310         string_get(&feat->values, fields[ii]);
311 }
312
313 static void finish_features(void)
314 {
315     struct remapped_feature *rmf;
316     struct string_list *sl;
317     struct feature *feat;
318     size_t ii;
319
320     fputs("Features {\n", stdout);
321     fputs("\t\"OPLEVELS\" = \"FALSE\";\n", stdout);
322     fputs("\t\"ZANNELS\" = \"FALSE\";\n", stdout);
323
324     for (feat = features; feat; feat = feat->next) {
325         /* Display the original feature line we are talking about. */
326         for (sl = feat->origins; sl; sl = sl->next)
327             fprintf(stdout, "# %s\n", sl->value);
328
329         /* See if the feature was remapped to an oper privilege. */
330         for (rmf = remapped_features; rmf->name; rmf++)
331             if (0 == strcmp(feat->name, rmf->name))
332                 break;
333         if (rmf->name) {
334             rmf->feature = feat;
335             fprintf(stdout, "# Above feature mapped to an oper privilege.\n");
336             continue;
337         }
338
339         /* Was it removed? */
340         for (ii = 0; removed_features[ii]; ++ii)
341             if (0 == strcmp(feat->name, removed_features[ii]))
342                 break;
343         if (removed_features[ii]) {
344             fprintf(stdout, "# Above feature no longer exists.\n");
345             continue;
346         }
347
348         /* Wasn't remapped, wasn't removed: print it out. */
349         fprintf(stdout, "\t\"%s\" =", feat->name);
350         for (sl = feat->values; sl; sl = sl->next)
351             fprintf(stdout, " \"%s\"", sl->value);
352         fprintf(stdout, ";\n");
353     }
354     fputs("};\n\n", stdout);
355
356 }
357
358 /*** OPERATOR BLOCKS ***/
359
360 struct operator {
361     char *name;
362     char *host;
363     char *password;
364     char *class;
365     char *origin;
366     int is_local;
367     struct operator *next;
368 } *operators;
369
370 static void do_operator(int is_local)
371 {
372     struct operator *oper;
373
374     oper = calloc(1, sizeof(*oper));
375     dupstring(oper->host, fields[0]);
376     dupstring(oper->password, fields[1]);
377     dupstring(oper->name, fields[2]);
378     dupstring(oper->class, fields[4]);
379     dupstring(oper->origin, orig_line);
380     oper->is_local = is_local;
381     oper->next = operators;
382     operators = oper;
383 }
384
385 static void finish_operators(void)
386 {
387     struct remapped_feature *remap;
388     struct operator *oper;
389     struct feature *feat;
390     char *pw_salt = "";
391     int global_kill = 0, mask = 0;
392     size_t ii;
393
394     if ((feat = remapped_features[0].feature) && feat->values
395         && 0 == strcmp(feat->values->value, "FALSE"))
396         pw_salt = "$PLAIN$";
397
398     if ((feat = remapped_features[1].feature) && feat->values
399         && 0 == strcmp(feat->values->value, "FALSE"))
400         global_kill = 1;
401     else if ((feat = remapped_features[2].feature) && feat->values
402         && 0 == strcmp(feat->values->value, "FALSE"))
403         global_kill = 2;
404
405     for (oper = operators; oper; oper = oper->next) {
406         fprintf(stdout, "# %s\nOperator {\n\tname = \"%s\";\n"
407                 "\thost = \"%s\";\n\tpassword = \"%s%s\";\n"
408                 "\tclass = \"%s\";\n",
409                 oper->origin, oper->name, oper->host, pw_salt,
410                 oper->password, oper->class);
411         if (oper->is_local) {
412             fputs("\tlocal = yes;\n", stdout);
413             mask = 1;
414         } else {
415             fputs("\tlocal = no;\n", stdout);
416             if (global_kill == 1)
417                 fputs("\tkill = no;\n\tlocal_kill = no;\n", stdout);
418             else if (global_kill == 2)
419                 fputs("\tkill = no;\n\tlocal_kill = yes;\n", stdout);
420             mask = 2;
421         }
422         for (ii = 0; (remap = &remapped_features[ii++])->name; ) {
423             if (!remap->feature || !remap->privilege
424                 || !remap->feature->values || !(remap->flags & mask))
425                 continue;
426             fprintf(stdout, "\t%s = %s;\n", remap->privilege,
427                     strcmp(remap->feature->values->value, "TRUE") ? "no" : "yes");
428         }
429         fputs("};\n\n", stdout);
430     }
431 }
432
433 /*** OTHER CONFIG TRANSFORMS ***/
434
435 static void do_kill(void)
436 {
437     const char *host = fields[0], *reason = fields[1], *user = fields[2];
438
439     if (!memcmp(host, "$R", 3)) {
440         fprintf(stderr, "Empty realname K: line at line %u.\n", lineno);
441         return;
442     }
443
444     /* Print the current line and start the new block. */
445     fprintf(stdout, "# %s\nKill {\n", orig_line);
446
447     /* Translate the user-matching portions. */
448     if (host[0] == '$' && host[1] == 'R') {
449         /* Realname kill, possibly with a username */
450         fprintf(stdout, "\trealname = \"%s\";\n", host + 2);
451         if (user[0] != '\0' && (user[0] != '*' || user[1] != '\0'))
452             fprintf(stdout, "\thost = \"%s@*\";\n", user);
453     } else {
454         /* Normal host or IP-based kill */
455         if (user[0] != '\0' && (user[0] != '*' || user[1] != '\0'))
456             fprintf(stdout, "\thost = \"%s@%s\";\n", user, host);
457         else
458             fprintf(stdout, "\thost = \"%s\";\n", host);
459     }
460
461     /* Translate the reason section. */
462     if (reason[0] == '!')
463         fprintf(stdout, "\tfile = \"%s\";\n", reason + 1);
464     else
465         fprintf(stdout, "\treason = \"%s\";\n", reason);
466
467     /* Close the block. */
468     fprintf(stdout, "};\n");
469 }
470
471 static void do_port(void)
472 {
473     const char *ipmask = fields[0], *iface = fields[1], *flags = fields[2], *port = fields[3];
474
475     /* Print the current line and start the new block. */
476     fprintf(stdout, "# %s\nPort {\n", orig_line);
477
478     /* Print the easy fields. */
479     fprintf(stdout, "\tport = %s;\n", port);
480     if (iface && iface[0] != '\0')
481         fprintf(stdout, "\tvhost = \"%s\";\n", iface);
482     if (ipmask && ipmask[0] != '\0')
483         fprintf(stdout, "\tmask = \"%s\";\n", ipmask);
484
485     /* Translate flag field. */
486     while (*flags) switch (*flags++) {
487     case 'C': case 'c': /* client port is default state */; break;
488     case 'S': case 's': fprintf(stdout, "\tserver = yes;\n"); break;
489     case 'H': case 'h': fprintf(stdout, "\thidden = yes;\n"); break;
490     }
491
492     /* Close the block. */
493     fprintf(stdout, "};\n");
494 }
495
496 struct string_list *quarantines;
497
498 static void do_quarantine(void)
499 {
500     struct string_list *q;
501     q = string_get(&quarantines, fields[0]);
502     dupstring(q->origin, orig_line);
503     dupstring(q->extra, fields[1]);
504 }
505
506 static void finish_quarantines(void)
507 {
508     struct string_list *sl;
509
510     if (quarantines)
511     {
512         fputs("Quarantine {\n", stdout);
513         for (sl = quarantines; sl; sl = sl->next)
514             fprintf(stdout, "# %s\n\t\"%s\" = \"%s\";\n", sl->origin, sl->value, sl->extra);
515         fputs("};\n\n", stdout);
516     }
517 }
518
519 static void do_uworld(void)
520 {
521     fprintf(stdout, "# %s\n", orig_line);
522     if (fields[0] && fields[0][0])
523         fprintf(stdout, "Uworld { name = \"%s\"; };\n", fields[0]);
524     if (fields[1] && fields[1][0])
525         fprintf(stdout, "Jupe { nick = \"%s\"; };\n", fields[1]);
526 }
527
528 static void emit_client(const char *mask, const char *passwd, const char *class, long maxlinks, int is_ip)
529 {
530     char *delim;
531     size_t len;
532
533     delim = strchr(mask, '@');
534     if (delim) {
535         *delim++ = '\0';
536         if (is_ip) {
537             len = strspn(delim, "0123456789.*");
538             if (delim[len]) {
539                 fprintf(stderr, "Invalid IP mask on line %u.\n", lineno);
540                 return;
541             }
542             fprintf(stdout, "Client {\n\tusername = \"%s\";\n\tip = \"%s\";\n", mask, delim);
543         } else {
544             fprintf(stdout, "Client {\n\tusername =\"%s\";\n\thost = \"%s\";\n", mask, delim);
545         }
546     } else if (is_ip) {
547         len = strspn(mask, "0123456789.*");
548         if (mask[len])
549             return;
550         fprintf(stdout, "Client {\n\tip = \"%s\";\n", mask);
551     } else {
552         if (!strchr(mask, '.') && !strchr(mask, '*'))
553             return;
554         fprintf(stdout, "Client {\n\thost = \"%s\";\n", mask);
555     }
556
557     if (passwd)
558         fprintf(stdout, "\tpassword = \"%s\";\n", passwd);
559
560     if (maxlinks >= 0)
561         fprintf(stdout, "\tmaxlinks = %ld;\n", maxlinks);
562
563     fprintf(stdout, "\tclass = \"%s\";\n};\n", class);
564 }
565
566 static void do_client(void)
567 {
568     char *passwd = NULL, *delim;
569     long maxlinks;
570
571     /* Print the current line. */
572     fprintf(stdout, "# %s\n", orig_line);
573
574     /* See if the password is really a maxlinks count. */
575     maxlinks = strtol(fields[1], &delim, 10);
576     if (fields[1][0] == '\0')
577         maxlinks = -1;
578     else if (maxlinks < 0 || maxlinks > 99 || *delim != '\0')
579         passwd = fields[1];
580
581     /* Translate the IP and host mask fields into blocks. */
582     emit_client(fields[0], passwd, fields[4], maxlinks, 1);
583     emit_client(fields[2], passwd, fields[4], maxlinks, 0);
584 }
585
586 int main(int argc, char *argv[])
587 {
588     FILE *ifile;
589
590     if (argc < 2)
591         ifile = stdin;
592     else if (!(ifile = fopen(argv[1], "rt"))) {
593         fprintf(stderr, "Unable to open file %s for input.\n", argv[1]);
594         return 1;
595     }
596
597     for (lineno = 1; fgets(line, sizeof(line), ifile); ++lineno) {
598         /* Read line and pass comments through. */
599         size_t len = strlen(line);
600         if (line[0] == '#') {
601             fputs(line, stdout);
602             continue;
603         }
604         /* Strip EOL character(s) and pass blank lines through. */
605         while (len > 0 && (line[len-1] == '\n' || line[len-1] == '\r'))
606             line[--len] = '\0';
607         if (len == 0) {
608             fputc('\n', stdout);
609             continue;
610         }
611         /* Skip but report invalid lines. */
612         if (line[1] != ':') {
613             fprintf(stdout, "# %s\n", line);
614             fprintf(stderr, "Invalid input line %d.\n", lineno);
615             continue;
616         }
617         /* Copy the original line into a reusable variable. */
618         strcpy(orig_line, line);
619         /* Split line into fields. */
620         nfields = split_line(line + 2, fields);
621
622         /* Process the input line. */
623         switch (line[0]) {
624         case 'A': case 'a': simple_line("Admin", admin_names, NULL); break;
625         case 'C': case 'c': do_connect(); break;
626         case 'D':           simple_line("CRule", crule_names, "all = yes;"); break;
627                   case 'd': simple_line("CRule", crule_names, NULL); break;
628         case 'F': case 'f': do_feature(); break;
629         case 'H': case 'h': do_hub(); break;
630         case 'I': case 'i': do_client(); break;
631         case 'K': case 'k': do_kill(); break;
632         case 'L': case 'l': do_leaf(); break;
633         case 'M': case 'm': simple_line("General", general_names, NULL); break;
634         case 'O':           do_operator(0); break;
635                   case 'o': do_operator(1); break;
636         case 'P': case 'p': do_port(); break;
637         case 'Q': case 'q': do_quarantine(); break;
638         case 'T': case 't': simple_line("Motd", motd_names, NULL); break;
639         case 'U': case 'u': do_uworld(); break;
640         case 'Y': case 'y': simple_line("Class", class_names, NULL); break;
641         default:
642             fprintf(stderr, "Unknown line %u with leading character '%c'.\n", lineno, line[0]);
643             break;
644         }
645     }
646
647     fclose(ifile);
648
649     fputs("\n# The following lines were intentionally moved and rearranged."
650           "\n# Our apologies for any inconvenience this may cause."
651           "\n\n", stdout);
652     finish_connects();
653     finish_quarantines();
654     finish_features();
655     finish_operators();
656
657     return 0;
658 }