-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuuconv.c
2098 lines (1836 loc) · 55.5 KB
/
uuconv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* uuconv.c
Convert one type of UUCP configuration file to another.
Copyright (C) 1991, 1992, 1993, 1994, 1995, 2002 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
The author of the program may be contacted at [email protected].
*/
#include "uucnfi.h"
#if USE_RCS_ID
const char uuconv_rcsid[] = "$Id$";
#endif
#include "getopt.h"
/* Local functions. */
static void uvusage P((void));
static void uvhelp P((void));
static void uvwrite_time P((FILE *e, struct uuconf_timespan *qtime));
static void uvwrite_string P((FILE *e, const char *zarg, const char *zcmd));
static void uvwrite_size P((FILE *e, struct uuconf_timespan *qsize,
const char *zcmd));
static void uvwrite_boolean P((FILE *e, int iarg, const char *zcmd));
static void uvwrite_string_array P((FILE *e, char **pz, const char *zcmd));
static void uvwrite_chat_script P((FILE *e, char **pz));
static void uvwrite_chat P((FILE *e, const struct uuconf_chat *qchat,
const struct uuconf_chat *qlast,
const char *zprefix, boolean fforce));
static void uvwrite_proto_params P((FILE *e,
const struct uuconf_proto_param *qparam,
const char *zprefix));
static void uvwrite_taylor_system P((FILE *e,
const struct uuconf_system *qsys));
static void uvwrite_v2_system P((FILE *e,
const struct uuconf_system *qsys));
static void uvwrite_hdb_system P((FILE *e,
const struct uuconf_system *qsys));
static boolean fvperm_string_cmp P((const char *z1, const char *z2));
static boolean fvperm_array_cmp P((const char **pz1, const char **pz2));
static void uvadd_perm P((struct shpermissions *qadd));
static void uvwrite_perms P((void));
static void uvwrite_perm_array P((FILE *e, const char **pz,
const char *zcmd, size_t *pccol));
static void uvwrite_perm_boolean P((FILE *e, int f, const char *zcmd,
size_t *pccol, boolean fsendfiles));
static void uvwrite_perm_rw_array P((FILE *e, const char **pz,
const char *zcmd, size_t *pccol));
static void uvwrite_perm_string P((FILE *e, const char *z, const char *zcmd,
size_t *pccol));
static int ivwrite_taylor_port P((struct uuconf_port *qport,
pointer pinfo));
static int ivwrite_v2_port P((struct uuconf_port *qport, pointer pinfo));
static int ivwrite_hdb_port P((struct uuconf_port *qport, pointer pinfo));
static void uvwrite_taylor_port P((FILE *e, struct uuconf_port *qport,
const char *zprefix));
static void uvwrite_taylor_dialer P((FILE *e, struct uuconf_dialer *qdialer,
const char *zprefix));
static void uvwrite_hdb_dialer P((FILE *e, struct uuconf_dialer *qdialer));
static void uvuuconf_error P((pointer puuconf, int iret));
/* The program name. */
const char *zProgram;
/* A list of Permissions entries built when writing out HDB system
information. */
static struct shpermissions *qVperms;
/* Type of configuration file. */
enum tconfig
{
CONFIG_TAYLOR,
CONFIG_V2,
CONFIG_HDB
};
/* Long getopt options. */
static const struct option asVlongopts[] =
{
{ "input", required_argument, NULL, 'i' },
{ "output", required_argument, NULL, 'o' },
{ "program", required_argument, NULL, 'p' },
{ "config", required_argument, NULL, 'I' },
{ "debug", required_argument, NULL, 'x' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 1 },
{ NULL, 0, NULL, 0 }
};
int
main (argc, argv)
int argc;
char **argv;
{
/* -I: The configuration file name. */
const char *zconfig = NULL;
/* -i: Input type. */
const char *zinput = NULL;
/* -o: Output type. */
const char *zoutput = NULL;
/* -p: Program name. */
const char *zprogram = NULL;
int iopt;
enum tconfig tinput, toutput;
int iret;
pointer pinput;
zProgram = argv[0];
while ((iopt = getopt_long (argc, argv, "i:I:o:p:vx:", asVlongopts,
(int *) NULL)) != EOF)
{
switch (iopt)
{
case 'i':
/* Input type. */
zinput = optarg;
break;
case 'o':
/* Output type. */
zoutput = optarg;
break;
case 'p':
/* Program name. */
zprogram = optarg;
break;
case 'I':
/* Set the configuration file name. */
zconfig = optarg;
break;
case 'x':
/* Set the debugging level. */
break;
case 'v':
/* Print version and exit. */
printf ("uuconv (Taylor UUCP) %s\n", VERSION);
printf ("Copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n");
printf ("This program is free software; you may redistribute it under the terms of\n");
printf ("the GNU General Public LIcense. This program has ABSOLUTELY NO WARRANTY.\n");
exit (EXIT_SUCCESS);
/*NOTREACHED*/
case 1:
/* --help. */
uvhelp ();
exit (EXIT_SUCCESS);
/*NOTREACHED*/
case 0:
/* Long option found, and flag value set. */
break;
default:
uvusage ();
break;
}
}
if (optind != argc
|| zinput == NULL
|| zoutput == NULL)
uvusage ();
if (strcasecmp (zinput, "taylor") == 0)
tinput = CONFIG_TAYLOR;
else if (strcasecmp (zinput, "v2") == 0)
tinput = CONFIG_V2;
else if (strcasecmp (zinput, "hdb") == 0)
tinput = CONFIG_HDB;
else
{
uvusage ();
tinput = CONFIG_TAYLOR;
}
if (strcasecmp (zoutput, "taylor") == 0)
toutput = CONFIG_TAYLOR;
else if (strcasecmp (zoutput, "v2") == 0)
toutput = CONFIG_V2;
else if (strcasecmp (zoutput, "hdb") == 0)
toutput = CONFIG_HDB;
else
{
uvusage ();
toutput = CONFIG_TAYLOR;
}
if (tinput == toutput)
uvusage ();
iret = UUCONF_SUCCESS;
/* Initialize the input. */
pinput = NULL;
switch (tinput)
{
case CONFIG_TAYLOR:
iret = uuconf_taylor_init (&pinput, zprogram, zconfig);
break;
case CONFIG_V2:
iret = uuconf_v2_init (&pinput);
break;
case CONFIG_HDB:
iret = uuconf_hdb_init (&pinput, zprogram);
break;
}
if (iret != UUCONF_SUCCESS)
{
uvuuconf_error (pinput, iret);
exit (EXIT_FAILURE);
}
{
char **pzsystems;
char *zsys;
char abtaylor[sizeof ZCURDIR + sizeof SYSFILE - 1];
char abv2[sizeof ZCURDIR + sizeof V2_SYSTEMS - 1];
char abhdb[sizeof ZCURDIR + sizeof HDB_SYSTEMS - 1];
FILE *esys;
char **pz;
/* Get the list of systems. */
switch (tinput)
{
case CONFIG_TAYLOR:
iret = uuconf_taylor_system_names (pinput, &pzsystems, FALSE);
break;
case CONFIG_V2:
iret = uuconf_v2_system_names (pinput, &pzsystems, FALSE);
break;
case CONFIG_HDB:
iret = uuconf_hdb_system_names (pinput, &pzsystems, FALSE);
break;
}
if (iret != UUCONF_SUCCESS)
uvuuconf_error (pinput, iret);
else
{
/* Open the sys file for the output type. */
switch (toutput)
{
default:
case CONFIG_TAYLOR:
sprintf (abtaylor, "%s%s", ZCURDIR, SYSFILE);
zsys = abtaylor;
break;
case CONFIG_V2:
sprintf (abv2, "%s%s", ZCURDIR, V2_SYSTEMS);
zsys = abv2;
break;
case CONFIG_HDB:
sprintf (abhdb, "%s%s", ZCURDIR, HDB_SYSTEMS);
zsys = abhdb;
break;
}
esys = fopen (zsys, "w");
if (esys == NULL)
{
fprintf (stderr, "uuchk:%s: ", zsys);
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (esys, "# %s file automatically generated by uuconv.\n",
zsys);
/* Read and write each system. We cheat and call the internal
routines, so that we can easily detect default information and
not write it out. This isn't necessary, but it makes the output
smaller and simpler. */
for (pz = pzsystems; *pz != NULL; pz++)
{
struct uuconf_system ssys;
switch (tinput)
{
case CONFIG_TAYLOR:
iret = _uuconf_itaylor_system_internal (pinput, *pz, &ssys);
break;
case CONFIG_V2:
iret = _uuconf_iv2_system_internal (pinput, *pz, &ssys);
break;
case CONFIG_HDB:
iret = _uuconf_ihdb_system_internal (pinput, *pz, &ssys);
break;
}
if (iret != UUCONF_SUCCESS)
uvuuconf_error (pinput, iret);
else
{
switch (toutput)
{
case CONFIG_TAYLOR:
uvwrite_taylor_system (esys, &ssys);
break;
case CONFIG_V2:
uvwrite_v2_system (esys, &ssys);
break;
case CONFIG_HDB:
uvwrite_hdb_system (esys, &ssys);
break;
}
if (toutput != CONFIG_HDB)
(void) uuconf_system_free (pinput, &ssys);
}
}
if (toutput == CONFIG_HDB)
uvwrite_perms ();
if (ferror (esys)
|| fclose (esys) == EOF)
{
fprintf (stderr, "uuchk:%s: error during output\n", zsys);
exit (EXIT_FAILURE);
}
}
}
{
/* Open the port file for the output type. */
char *zport;
char abtaylor[sizeof ZCURDIR + sizeof PORTFILE - 1];
char abv2[sizeof ZCURDIR + sizeof V2_DEVICES - 1];
char abhdb[sizeof ZCURDIR + sizeof HDB_DEVICES - 1];
FILE *eport;
int (*piportfn) P((struct uuconf_port *, pointer));
struct uuconf_port sport;
switch (toutput)
{
default:
case CONFIG_TAYLOR:
sprintf (abtaylor, "%s%s", ZCURDIR, PORTFILE);
zport = abtaylor;
piportfn = ivwrite_taylor_port;
break;
case CONFIG_V2:
sprintf (abv2, "%s%s", ZCURDIR, V2_DEVICES);
zport = abv2;
piportfn = ivwrite_v2_port;
break;
case CONFIG_HDB:
sprintf (abhdb, "%s%s", ZCURDIR, HDB_DEVICES);
zport = abhdb;
piportfn = ivwrite_hdb_port;
break;
}
eport = fopen (zport, "w");
if (eport == NULL)
{
fprintf (stderr, "uuchk:%s: ", zport);
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (eport, "# %s file automatically generated by uuconv.\n", zport);
switch (tinput)
{
case CONFIG_TAYLOR:
iret = uuconf_taylor_find_port (pinput, (const char *) NULL, 0L,
0L, piportfn, (pointer) eport,
&sport);
break;
case CONFIG_V2:
iret = uuconf_v2_find_port (pinput, (const char *) NULL, 0L, 0L,
piportfn, (pointer) eport, &sport);
break;
case CONFIG_HDB:
iret = uuconf_hdb_find_port (pinput, (const char *) NULL, 0L, 0L,
piportfn, (pointer) eport, &sport);
break;
}
if (iret != UUCONF_NOT_FOUND)
uvuuconf_error (pinput, iret);
if (ferror (eport)
|| fclose (eport) == EOF)
{
fprintf (stderr, "uuchk:%s: error during output\n", zport);
exit (EXIT_FAILURE);
}
}
/* V2 configuration files don't support dialers. */
if (tinput != CONFIG_V2 && toutput != CONFIG_V2)
{
char **pzdialers;
char *zdialer;
char abtaylor[sizeof ZCURDIR + sizeof DIALFILE - 1];
char abhdb[sizeof ZCURDIR + sizeof HDB_DIALERS - 1];
FILE *edialer;
char **pz;
/* Get the list of dialers. */
switch (tinput)
{
default:
case CONFIG_TAYLOR:
iret = uuconf_taylor_dialer_names (pinput, &pzdialers);
break;
case CONFIG_HDB:
iret = uuconf_hdb_dialer_names (pinput, &pzdialers);
break;
}
if (iret != UUCONF_SUCCESS)
uvuuconf_error (pinput, iret);
else
{
/* Open the sys file for the output type. */
switch (toutput)
{
default:
case CONFIG_TAYLOR:
sprintf (abtaylor, "%s%s", ZCURDIR, DIALFILE);
zdialer = abtaylor;
break;
case CONFIG_HDB:
sprintf (abhdb, "%s%s", ZCURDIR, HDB_DIALERS);
zdialer = abhdb;
break;
}
edialer = fopen (zdialer, "w");
if (edialer == NULL)
{
fprintf (stderr, "uuchk:%s: ", zdialer);
perror ("fopen");
exit (EXIT_FAILURE);
}
fprintf (edialer, "# %s file automatically generated by uuconv.\n",
zdialer);
/* Read and write each dialer. */
for (pz = pzdialers; *pz != NULL; pz++)
{
struct uuconf_dialer sdialer;
switch (tinput)
{
default:
case CONFIG_TAYLOR:
iret = uuconf_taylor_dialer_info (pinput, *pz, &sdialer);
break;
case CONFIG_HDB:
iret = uuconf_hdb_dialer_info (pinput, *pz, &sdialer);
break;
}
if (iret != UUCONF_SUCCESS)
uvuuconf_error (pinput, iret);
else
{
switch (toutput)
{
default:
case CONFIG_TAYLOR:
fprintf (edialer, "# Start of dialer %s\n",
sdialer.uuconf_zname);
fprintf (edialer, "dialer %s\n", sdialer.uuconf_zname);
uvwrite_taylor_dialer (edialer, &sdialer, "");
break;
case CONFIG_HDB:
uvwrite_hdb_dialer (edialer, &sdialer);
break;
}
(void) uuconf_dialer_free (pinput, &sdialer);
}
}
if (ferror (edialer)
|| fclose (edialer) == EOF)
{
fprintf (stderr, "uuchk:%s: error during output\n", zdialer);
exit (EXIT_FAILURE);
}
}
}
exit (EXIT_SUCCESS);
/* Avoid complaints about not returning. */
return 0;
}
/* Print out a usage message and die. */
static void
uvusage ()
{
fprintf (stderr, "Usage: %s -i input-type -o output-type [-p program]\n",
zProgram);
fprintf (stderr, "Use %s --help for help\n", zProgram);
exit (EXIT_FAILURE);
}
/* Print a help message. */
static void
uvhelp ()
{
printf ("Taylor UUCP %s, copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n",
VERSION);
printf ("Converts UUCP configuration files from one format to another.\n");
printf ("Usage: %s -i input -o output [-p program] [-I file]\n", zProgram);
printf (" -i,--input input: Set input type (one of taylor, v2, hdb)\n");
printf (" -o,--output output: Set output type (one of taylor, v2, hdb)\n");
printf (" -p,--program program: Program to convert (e.g., uucp or cu)\n");
printf (" -I,--config file: Set Taylor UUCP configuration file to use\n");
printf (" -v,--version: Print version and exit\n");
printf (" --help: Print help and exit\n");
printf ("Report bugs to [email protected]\n");
}
/* Write out a timespan. */
static void
uvwrite_time (e, qtime)
FILE *e;
struct uuconf_timespan *qtime;
{
if (qtime == NULL)
{
fprintf (e, "Never");
return;
}
if (qtime->uuconf_istart == 0 && qtime->uuconf_iend == 7 * 24 * 60)
{
fprintf (e, "Any");
return;
}
for (; qtime != NULL; qtime = qtime->uuconf_qnext)
{
int idaystart, idayend;
int ihourstart, ihourend;
int iminutestart, iminuteend;
const char * const zdays = "Su\0Mo\0Tu\0We\0Th\0Fr\0Sa";
idaystart = qtime->uuconf_istart / (24 * 60);
ihourstart = (qtime->uuconf_istart % (24 * 60)) / 60;
iminutestart = qtime->uuconf_istart % 60;
if (qtime->uuconf_iend >= 7 * 24 * 60)
qtime->uuconf_iend = 7 * 24 * 60 - 1;
idayend = qtime->uuconf_iend / (24 * 60);
ihourend = (qtime->uuconf_iend % (24 * 60)) / 60;
iminuteend = qtime->uuconf_iend % 60;
if (ihourend == 0 && iminuteend == 0)
--idayend;
if (idaystart == idayend)
fprintf (e, "%s%02d%02d-%02d%02d", zdays + idaystart * 3,
ihourstart, iminutestart, ihourend, iminuteend);
else
{
int i;
fprintf (e, "%s%02d%02d-0000", zdays + idaystart * 3,
ihourstart, iminutestart);
for (i = idaystart + 1; i < idayend; i++)
fprintf (e, ",%s", zdays + i * 3);
if (ihourend != 0 || iminuteend != 0)
fprintf (e, ",%s0000-%02d%02d", zdays + idayend * 3, ihourend,
iminuteend);
}
if (qtime->uuconf_qnext != NULL)
fprintf (e, ",");
}
}
/* Some subroutines used when writing out Taylor UUCP configuration
files. */
/* Write a command with a string argument. */
static void
uvwrite_string (e, zarg, zcmd)
FILE *e;
const char *zarg;
const char *zcmd;
{
if (zarg != UUCONF_UNSET)
fprintf (e, "%s %s\n", zcmd, zarg == NULL ? (const char *) "" : zarg);
}
/* Write out a size restriction command. */
static void
uvwrite_size (e, qtime, zcmd)
FILE *e;
struct uuconf_timespan *qtime;
const char *zcmd;
{
if (qtime != UUCONF_UNSET)
{
for (; qtime != NULL; qtime = qtime->uuconf_qnext)
{
fprintf (e, "%s %ld", zcmd, qtime->uuconf_ival);
uvwrite_time (e, qtime);
fprintf (e, "\n");
}
}
}
/* Write out a boolean argument with a string command. If the value
is less than zero, than it was uninitialized and we don't write
anything. */
static void
uvwrite_boolean (e, fval, zcmd)
FILE *e;
int fval;
const char *zcmd;
{
if (fval >= 0)
fprintf (e, "%s %s\n", zcmd, fval > 0 ? "true" : "false");
}
/* Write out a string array as a single command. */
static void
uvwrite_string_array (e, pz, zcmd)
FILE *e;
char **pz;
const char *zcmd;
{
if (pz != UUCONF_UNSET)
{
fprintf (e, "%s", zcmd);
if (pz != NULL)
for (; *pz != NULL; pz++)
fprintf (e, " %s", *pz);
fprintf (e, "\n");
}
}
/* Write out a chat script. Don't separate subsend/subexpect strings
by spaces. */
static void
uvwrite_chat_script (e, pzarg)
FILE *e;
char **pzarg;
{
char **pz;
if (pzarg == NULL || pzarg == UUCONF_UNSET)
return;
for (pz = pzarg; *pz != NULL; pz++)
{
if ((*pz)[0] != '-' && pz != pzarg)
fprintf (e, " ");
fprintf (e, *pz);
}
}
/* Write out chat information. If the qlast argument is not NULL,
then only values that are different from qlast should be written.
The fforce argument is used to get around a peculiar problem: if
the ``chat'' command is used with no arguments for a system, then
uuconf_pzchat will be NULL (not &_uuconf_unset) and the default
chat script will not be used. We must distinguish this case from
the ``chat'' command not appearing at all for a port or dialer, in
which case the value will again be NULL. In the former case we
must output a ``chat'' command, in the latter case we would prefer
not to. */
static void
uvwrite_chat (e, q, qlast, zprefix, fforce)
FILE *e;
const struct uuconf_chat *q;
const struct uuconf_chat *qlast;
const char *zprefix;
boolean fforce;
{
char **pz;
char ab[100];
if (q->uuconf_pzchat != UUCONF_UNSET
&& (qlast == NULL
? (fforce || q->uuconf_pzchat != NULL)
: qlast->uuconf_pzchat != q->uuconf_pzchat))
{
fprintf (e, "%schat ", zprefix);
uvwrite_chat_script (e, q->uuconf_pzchat);
fprintf (e, "\n");
}
if (q->uuconf_pzprogram != UUCONF_UNSET
&& (qlast == NULL
? q->uuconf_pzprogram != NULL
: qlast->uuconf_pzprogram != q->uuconf_pzprogram))
{
sprintf (ab, "%schat-program", zprefix);
uvwrite_string_array (e, q->uuconf_pzprogram, ab);
}
if (q->uuconf_ctimeout >= 0
&& (qlast == NULL
|| qlast->uuconf_ctimeout != q->uuconf_ctimeout))
fprintf (e, "%schat-timeout %d\n", zprefix, q->uuconf_ctimeout);
if (q->uuconf_pzfail != NULL
&& q->uuconf_pzfail != UUCONF_UNSET
&& (qlast == NULL
|| qlast->uuconf_pzfail != q->uuconf_pzfail))
for (pz = q->uuconf_pzfail; *pz != NULL; pz++)
fprintf (e, "%schat-fail %s\n", zprefix, *pz);
if (qlast == NULL || qlast->uuconf_fstrip != q->uuconf_fstrip)
{
sprintf (ab, "%schat-strip", zprefix);
uvwrite_boolean (e, q->uuconf_fstrip, ab);
}
}
/* Write out protocol parameters to a Taylor UUCP file. */
static void
uvwrite_proto_params (e, qparams, zprefix)
FILE *e;
const struct uuconf_proto_param *qparams;
const char *zprefix;
{
const struct uuconf_proto_param *qp;
if (qparams == NULL
|| qparams == UUCONF_UNSET)
return;
for (qp = qparams; qp->uuconf_bproto != '\0'; qp++)
{
const struct uuconf_proto_param_entry *qe;
for (qe = qp->uuconf_qentries; qe->uuconf_cargs > 0; qe++)
{
int i;
fprintf (e, "%sprotocol-parameter %c", zprefix, qp->uuconf_bproto);
for (i = 0; i < qe->uuconf_cargs; i++)
fprintf (e, " %s", qe->uuconf_pzargs[i]);
fprintf (e, "\n");
}
}
}
/* Write out Taylor UUCP system information. */
static void
uvwrite_taylor_system (e, q)
FILE *e;
const struct uuconf_system *q;
{
char **pz;
const struct uuconf_system *qlast;
fprintf (e, "# Start of system %s\n", q->uuconf_zname);
fprintf (e, "system %s\n", q->uuconf_zname);
if (q->uuconf_pzalias != NULL
&& q->uuconf_pzalias != UUCONF_UNSET)
for (pz = q->uuconf_pzalias; *pz != NULL; pz++)
uvwrite_string (e, *pz, "alias");
for (qlast = NULL; q != NULL; qlast = q, q = q->uuconf_qalternate)
{
struct uuconf_timespan *qtime;
if (qlast != NULL)
{
fprintf (e, "alternate");
if (q->uuconf_zalternate != UUCONF_UNSET
&& q->uuconf_zalternate != NULL)
fprintf (e, " %s", q->uuconf_zalternate);
fprintf (e, "\n");
}
#define CHANGED(x) (qlast == NULL || qlast->x != q->x)
if (CHANGED (uuconf_qtimegrade)
&& (q->uuconf_qtimegrade
!= UUCONF_UNSET))
{
if (q->uuconf_qtimegrade == NULL)
fprintf (e, "time never\n");
else
{
for (qtime = q->uuconf_qtimegrade;
qtime != NULL;
qtime = qtime->uuconf_qnext)
{
if ((char) qtime->uuconf_ival == UUCONF_GRADE_LOW)
fprintf (e, "time ");
else
fprintf (e, "timegrade %c ", (char) qtime->uuconf_ival);
uvwrite_time (e, qtime);
if (qtime->uuconf_cretry != 0)
fprintf (e, " %d", qtime->uuconf_cretry);
fprintf (e, "\n");
}
}
}
if (CHANGED (uuconf_qcalltimegrade)
&& (q->uuconf_qcalltimegrade
!= UUCONF_UNSET))
{
for (qtime = q->uuconf_qcalltimegrade;
qtime != NULL;
qtime = qtime->uuconf_qnext)
{
fprintf (e, "call-timegrade %c ", (char) qtime->uuconf_ival);
uvwrite_time (e, qtime);
fprintf (e, "\n");
}
}
if (CHANGED (uuconf_qcalledtimegrade)
&& (q->uuconf_qcalledtimegrade
!= UUCONF_UNSET))
{
for (qtime = q->uuconf_qcalledtimegrade;
qtime != NULL;
qtime = qtime->uuconf_qnext)
{
fprintf (e, "called-timegrade %c ", (char) qtime->uuconf_ival);
uvwrite_time (e, qtime);
fprintf (e, "\n");
}
}
if (CHANGED (uuconf_qcall_local_size))
uvwrite_size (e, q->uuconf_qcall_local_size, "call-local-size");
if (CHANGED (uuconf_qcall_remote_size))
uvwrite_size (e, q->uuconf_qcall_remote_size, "call-remote-size");
if (CHANGED (uuconf_qcalled_local_size))
uvwrite_size (e, q->uuconf_qcalled_local_size, "called-local-size");
if (CHANGED (uuconf_qcalled_remote_size))
uvwrite_size (e, q->uuconf_qcalled_remote_size, "called-remote-size");
if (CHANGED (uuconf_ibaud) || CHANGED (uuconf_ihighbaud))
{
if (q->uuconf_ibaud >= 0)
{
if (q->uuconf_ihighbaud > 0)
fprintf (e, "baud-range %ld %ld\n", q->uuconf_ibaud,
q->uuconf_ihighbaud);
else
fprintf (e, "baud %ld\n", q->uuconf_ibaud);
}
}
if (CHANGED (uuconf_zport) || CHANGED (uuconf_qport))
{
if (q->uuconf_zport != NULL
&& q->uuconf_zport != UUCONF_UNSET)
uvwrite_string (e, q->uuconf_zport, "port");
else if (q->uuconf_qport != NULL
&& (q->uuconf_qport
!= UUCONF_UNSET))
uvwrite_taylor_port (e, q->uuconf_qport, "port ");
}
if (CHANGED (uuconf_zphone))
{
const char *zcmd;
if (q->uuconf_qport != NULL
&& q->uuconf_qport != UUCONF_UNSET
&& (q->uuconf_qport->uuconf_ttype == UUCONF_PORTTYPE_TCP
|| q->uuconf_qport->uuconf_ttype == UUCONF_PORTTYPE_TLI))
zcmd = "address";
else
zcmd = "phone";
uvwrite_string (e, q->uuconf_zphone, zcmd);
}
uvwrite_chat (e, &q->uuconf_schat,
(qlast == NULL
? (struct uuconf_chat *) NULL
: &qlast->uuconf_schat),
"", TRUE);
if (CHANGED (uuconf_zcall_login))
uvwrite_string (e, q->uuconf_zcall_login, "call-login");
if (CHANGED (uuconf_zcall_password))
uvwrite_string (e, q->uuconf_zcall_password, "call-password");
if (CHANGED (uuconf_zcalled_login))
uvwrite_string (e, q->uuconf_zcalled_login, "called-login");
if (CHANGED (uuconf_fcallback))
uvwrite_boolean (e, q->uuconf_fcallback, "callback");
if (CHANGED (uuconf_fsequence))
uvwrite_boolean (e, q->uuconf_fsequence, "sequence");
if (CHANGED (uuconf_zprotocols))
uvwrite_string (e, q->uuconf_zprotocols, "protocol");
if (CHANGED (uuconf_qproto_params))
uvwrite_proto_params (e, q->uuconf_qproto_params, "");
uvwrite_chat (e, &q->uuconf_scalled_chat,
(qlast == NULL
? (struct uuconf_chat *) NULL
: &qlast->uuconf_scalled_chat),
"called-", FALSE);
if (CHANGED (uuconf_zdebug))
uvwrite_string (e, q->uuconf_zdebug, "debug");
if (CHANGED (uuconf_zmax_remote_debug))
uvwrite_string (e, q->uuconf_zmax_remote_debug, "max-remote-debug");
if ((CHANGED (uuconf_fsend_request)
|| CHANGED (uuconf_frec_request))
&& (q->uuconf_fsend_request >= 0
|| q->uuconf_frec_request >= 0))
{
if (q->uuconf_fsend_request >= 0
&& (q->uuconf_fsend_request > 0
? q->uuconf_frec_request > 0
: q->uuconf_frec_request == 0))
uvwrite_boolean (e, q->uuconf_fsend_request, "request");
else
{
uvwrite_boolean (e, q->uuconf_fsend_request, "send-request");
uvwrite_boolean (e, q->uuconf_frec_request,
"receive-request");
}
}
if ((CHANGED (uuconf_fcall_transfer)
|| CHANGED (uuconf_fcalled_transfer))
&& (q->uuconf_fcall_transfer >= 0
|| q->uuconf_fcalled_transfer >= 0))
{
if (q->uuconf_fcall_transfer >= 0
&& (q->uuconf_fcall_transfer > 0
? q->uuconf_fcalled_transfer > 0
: q->uuconf_fcalled_transfer == 0))
uvwrite_boolean (e, q->uuconf_fcall_transfer, "transfer");
else
{
uvwrite_boolean (e, q->uuconf_fcall_transfer, "call-transfer");
uvwrite_boolean (e, q->uuconf_fcalled_transfer,
"called-transfer");
}
}
if (CHANGED (uuconf_pzlocal_send))
uvwrite_string_array (e, q->uuconf_pzlocal_send, "local-send");
if (CHANGED (uuconf_pzremote_send))
uvwrite_string_array (e, q->uuconf_pzremote_send, "remote-send");
if (CHANGED (uuconf_pzlocal_receive))
uvwrite_string_array (e, q->uuconf_pzlocal_receive, "local-receive");
if (CHANGED (uuconf_pzremote_receive))
uvwrite_string_array (e, q->uuconf_pzremote_receive,
"remote-receive");
if (CHANGED (uuconf_pzpath))
uvwrite_string_array (e, q->uuconf_pzpath, "command-path");
if (CHANGED (uuconf_pzcmds))
uvwrite_string_array (e, q->uuconf_pzcmds, "commands");