File: console_fe.c

package info (click to toggle)
sitecopy 1:0.16.6-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 5,668 kB
  • ctags: 5,783
  • sloc: ansic: 48,856; sh: 3,820; makefile: 774; yacc: 291; awk: 58; sed: 27
file content (1416 lines) | stat: -rw-r--r-- 38,812 bytes parent folder | download | duplicates (2)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
/* 
   sitecopy, for managing remote web sites.
   Copyright (C) 1998-2008, Joe Orton <joe@manyfish.co.uk>
                                                                     
   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., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/* This is the console front end for sitecopy.
 * TODO: Some of the configuration stuff should be moved out of here. */

#include <config.h>

#include <sys/types.h>

#include <sys/param.h>
#include <sys/stat.h>

#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif 
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif

#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif

#include <signal.h>
#include <time.h>
#include <ctype.h>

#include <getopt.h>

#include <ne_string.h> /* for ne_shave */
#include <ne_utils.h> /* for ne_debug_* */
#include <ne_alloc.h>

#include "basename.h"
#include "i18n.h"
#include "frontend.h"
#include "sites.h"
#include "rcfile.h"
#include "common.h"

/* From lib/yesno.c */
int yesno(void);

/* The maximum number of sites which can be specified on the command
 * line */

#define MAXSITES 20

static enum action {
    action_list,
    action_synch,
    action_fetch,
    action_update,
    action_verify,
    action_catchup,
    action_init,
    action_view,
    action_none
} action;

#define A_LOCAL (1 << 2)
#define A_STORED (1 << 3)
#define A_COND_STORED (A_STORED | (1 << 4))

/* TODO: extend this even further, so it includes the site_whatever
 * handler, whether we need to do a post-operation write_stored_state,
 * any preconditions, ...
 * Changes needed for that are that each site_mode() function have
 * consistent parms and return code usage.
 * Does this structure actually make localization harder or easier?
 * .. Unfortunately harder. :-(<prazak@grisoft.cz>
 */
static struct action_info {
    /* The stem verb: used to form phrases like: "Update the site".
     * Should be capitalized, since it will be used at the beginning of
     * sentences. */
    const char *verb; 
    /* The present participle of the verb (I think?), used to form a
     * phrase like: "I am <doing> the site." */
    const char *doing; 
    /* What the action operates on, used to form a phrase like:
     *  "I am <doing> the <subject> site." */
    const char *subject;
    /* Flags;
     *  A_LOCAL -> must read local state before operation.
     *  A_STORED -> must read stored state before operation.
     *  A_COND_STORED -> read stored state if there is any, otherwise ignore it.
     */
    unsigned int flags;
} actions[] = {
    { N_("Show changes to"), N_("showing changes to"), N_("local"), A_LOCAL | A_STORED },
    { N_("Synchronize"), N_("synchronizing"), N_("local"), A_LOCAL | A_STORED },
    /* TODO: fetch really only needs local state if we're using
     * state_timesize, to fudge the modtimes.
     * And we only need A_STORED if we're using state_timesize AND
     * safe mode. */
    { N_("Fetch"), N_("fetching"), N_("remote"), A_LOCAL | A_COND_STORED },
    { N_("Update"), N_("updating"), N_("remote"), A_LOCAL | A_STORED },
    { N_("Verify"), N_("verifying"), N_("remote"), A_STORED },
    { N_("Catch up"), N_("catching up"), N_("stored"), A_LOCAL },
    { N_("Initialize"), N_("initializing"), N_("stored"), 0 },
    { NULL, NULL, NULL, 0 }
};

static const char *contact_mntr = 
N_("You should never see this message.\n"
   "Please contact the maintainer at sitecopy@lyra.org\n");

/* The short program name, basename(argv[0]) */
static const char *progname;

/* the sites specified on the command line */
static const char *sitenames[MAXSITES]; 
static int numsites; /* the number of sites specified */
static struct site *current_site; /* this is used to save the state if we
				   * get signalled mid-update */

static int upload_total, upload_sofar, in_transfer;

/* User-specified options */
static int quiet; /* How quiet do they want us to be? */
static int allsites, /* Do they want all sites to be operated on? */
    listflat, /* Do they want the 'flat' list style */
    show_progress, /* Do they want the %-complete messages */
    prompting, /* Did they say --prompting? */
    keepgoing, /* Did they say --keep-going? */
    dry_run,   /* Did they say --dry-run? */
    createremoteroot=false; /* Did they say --create-remote? */	

/* Functions prototypes */
static void init(int, char **);
static void parse_cmdline(int, char **);
static int act_on_site(struct site *site, enum action act);
static int verify_sites(struct site *sites, enum action act);
int main(int, char **);
static void usage(void);
static void version(void);
static void list_site_changes(struct site *);
static int list_site_definitions(struct site *);
static void init_sites(void);

int main(int argc, char *argv[])
{
    int ret = 0, numgoodsites;
    struct site *current;

#ifdef HAVE_SETLOCALE
    setlocale(LC_ALL, "");
#endif

#ifdef ENABLE_NLS
    bindtextdomain(PACKAGE_NAME, LOCALEDIR);
    textdomain(PACKAGE_NAME);
#endif /* ENABLE_NLS */

    fe_initialize();
    init(argc, argv);

    if (numsites == 0 && action == action_view)
	allsites = 1;

    if (!allsites) {
	/* Mark all the sites we are interested in */
	int num;
	for (num=0; num < numsites; num++) {
	    current = site_find(sitenames[num]);
	    if (current == NULL) {
		printf(
		    _("%s: Error: No site called `%s' found - skipping.\n"), 
		    progname, sitenames[num]);
	    } else {
		current->use_this = true;
	    }
	}
    }    

    /* Count the number of sites that are okay. */
    numgoodsites = verify_sites(all_sites, action);

    /* Handle the dump sites request */
    if (action == action_view) {
	return list_site_definitions(all_sites);
    }
    
    if (numgoodsites==0) {
	if (numsites > 0) {
	    printf(_("%s: No valid sites specified.\n"), progname);
	} else {
	    printf(_("%s: No sites specified.\n"), progname);
	}
	printf(_("Try `%s --help' for more information.\n"), progname);
	exit(-1);
    }

     for (current=all_sites; current!=NULL; current=current->next) {
	
	 if (current->use_this || allsites) {
	    if (!listflat && quiet == 0) {
		/* Display the banner line */
		const char *str_action = _(actions[action].doing);
		printf(_("%s: %c%s site `%s' (on %s in %s)\n"), 
			progname, toupper(*str_action), 
			str_action+1, current->name, 
			current->server.hostname, current->remote_root_user);
	    }
	    ret = act_on_site(current, action);
	}

    }
    
    return ret;
}

/* Produce the normal listing output for the given site.
 */
static void list_site_changes(struct site *the_site)
{
    struct site_file *current;
    int count;

    if (the_site->numnew > 0) {
	printf(_("* These items have been added since the last update:\n"));
	count = 0;
	for (current = the_site->files; current!=NULL; current=current->next) {
	    if (current->diff == file_new) {
		if (count++) printf(", ");
		if (current->type == file_dir) printf(_("dir:"));
		printf("%s", file_name(current));
	    }
	}
	putchar('\n');
    }
    if ((the_site->numchanged > 0) || (the_site->numignored > 0)) {
	printf(_("* These items have been changed since the last update:\n"));
	if (the_site->numignored > 0) {
	    printf(_("  Changes to items in [brackets] are ignored during updates.\n"));
	}    
	count = 0;
	for (current = the_site->files; current!=NULL; current=current->next) {
	    if (current->diff == file_changed) {
		if (count++) printf(", ");
		printf("%s%s%s", current->ignore?"[":"", file_name(current),
			current->ignore?"]":"");
	    }
	}
	putchar('\n');
    }
    if (the_site->numdeleted > 0) {
	if (the_site->nodelete) {
	    printf(_("* These items have been deleted, but will be left on the server:\n"));
	} else {
	    printf(_("* These items have been deleted since the last update:\n"));
	}
	count = 0;
	for (current = the_site->files; current!=NULL; current=current->next) {
	    if (current->diff == file_deleted) {
		if (count++) printf(", ");
		if (current->type == file_dir) printf(_("dir:"));
		printf("%s", file_name(current));
	    }
	}
	putchar('\n');
    }
    if (the_site->nummoved > 0) {
	printf(_("* These items have been moved since the last update:\n"));
	count = 0;
	for (current = the_site->files; current!=NULL; current=current->next) {
	    if (current->diff == file_moved) {
		/* TODO: move to directory */
		if (count++) printf(", ");
		printf("%s->%s", current->stored.filename, 
			current->local.filename);
	    }
	}
	putchar('\n');
    }
}

static const char *get_perms_mode(struct site *site)
{
    switch (site->perms) {
    case sitep_ignore:
	return _("Ignored");
    case sitep_exec:
	return _("Maintained for executables");
    default:
	return _("Always maintained");
    }
}

static const char *get_symlinks_mode(struct site *site)
{
    switch (site->symlinks) {
    case sitesym_ignore:
	return _("Ignored");
    case sitesym_maintain:
	return _("Maintained");
    default:
	return _("Followed");
    }
}

static int list_site_definitions(struct site *sites)
{
    struct site *current;
    for (current=sites; current!=NULL; current=current->next) {
	/* FIXME: Possibly, make sure we have the actual port number first
	 * so we don't have to mess around printing out the port */
	if (!current->use_this && !allsites) continue;
	printf(_("Site: %s\n\tServer: %s"), current->name, 
		current->server.hostname);
	printf(_("  Port: "));
	if (current->server.port == 0) {
	    printf(_("(default)\n"));
	} else {
	    printf(_("%d\n"), current->server.port);
	}
	printf(_("\tProtocol: %s    Username: %s\n"),
		site_get_protoname(current), 
		current->server.username?current->server.username:
		_("(unspecified)"));
	if (! current->ftp_pasv_mode)
	    printf(_("\tPassive mode FTP will not be used.\n"));
	printf(_("\tRemote directory: %s\n\tLocal directory: %s\n"),
		current->remote_root_user, current->local_root_user);
	printf(_("\tPermissions: %s     Symlinks: %s\n"),
		get_perms_mode(current), get_symlinks_mode(current));
	if (current->nodelete) 
	    printf(_("\tRemote files will not be deleted.\n"));
	if (current->checkmoved) 
	    printf(_("\tFiles will be moved remotely if moved locally.\n"));
    }
    return 0;
}

/* Called to ensure only one action is specified at once */
static void set_action(enum action newact)
{
    if (action != action_none) {
	printf(_("%s: Error: Only specify ONE operation mode at a time.\n"),
		progname);
	printf(_("Try `%s --help' for more information.\n"), progname);
	exit(-1);
    } else {
	action = newact;
    }
}

static void parse_cmdline(int argc, char *argv[])
{
    int optc;
    int firstlist = false;
    extern char *optarg;
    extern int optind;
    const static char *shortopts = 
#ifdef NE_DEBUGGING
	"d:g:"
#endif
	"acefhiklonp:qr:suvVyZ"; /* available: bgjmntwx */
    const static struct option longopts[] = {
	/* Operation modes */
	{ "update", no_argument, NULL, 'u' },
	{ "verify", no_argument, NULL, 'e' },
	{ "initialize", no_argument, NULL, 'i' },
	{ "fetch", no_argument, NULL, 'f' },
	{ "synchronize", no_argument, NULL, 's' },
	{ "list", no_argument, NULL, 'l' },
	{ "flatlist", no_argument, NULL, 'Z' },
	{ "keep-going", no_argument, NULL, 'k' },
        { "dry-run", no_argument, NULL, 'n' },
	{ "show-progress", no_argument, NULL, 'o' },
/*	{ "force-overwrite", no_argument, NULL, 't' }, */
	{ "help", no_argument, NULL, 'h' },
	{ "catchup", no_argument, NULL, 'c' },
	{ "view", no_argument, NULL, 'v' },
	/* Options */
	{ "quiet", no_argument, &quiet, 1 },
	{ "silent", no_argument, &quiet, 2 },
	{ "rcfile", required_argument, NULL, 'r' },
	{ "storepath", required_argument, NULL, 'p' },
#ifdef NE_DEBUGGING
	{ "debug", required_argument, NULL, 'd' },
	{ "logfile", required_argument, NULL, 'g' },
#endif
	{ "prompting", no_argument, NULL, 'y' },
	{ "allsites", no_argument, NULL, 'a' },
	{ "version", no_argument, NULL, 'V' },
	{ 0, 0, 0, 0 }
    };
	
#ifdef NE_DEBUGGING
    /* Debugging defaults to off and stderr */
    int use_debug_mask = 0;
    FILE *use_debug_stream = stderr;
#endif
    
    /* Defaults */
    allsites = prompting = false;
    show_progress = false;
    action = action_none;
    progname = base_name(argv[0]);

    /* Read the cmdline args */
    while ((optc = getopt_long(argc, argv, 
			       shortopts, longopts, NULL)) != -1) {
	switch (optc) {
	case 0:
	    /* Make the action list mode if they gave --flatlist */
	    if (listflat == true)
		action = action_list;
	    break;
	case 'Z':
	    listflat = true;
	    set_action(action_list);
	    break;
	case 'l':
	    if (firstlist == false) {
		set_action(action_list);
		firstlist = true;
	    } else {
		listflat = true;
	    }
	    break;
	case 's': set_action(action_synch); break;
	case 'e': set_action(action_verify); break;
	case 'f': set_action(action_fetch); break;
	case 'i': set_action(action_init); break;
	case 'c': set_action(action_catchup); break;
	case 'u': set_action(action_update); break;
	case 'v': 
	    set_action(action_view);
	    break;
	case 'q': quiet++; break;
	case 'r': 
	    if (strlen(optarg) != 0) {
		rcfile = ne_strdup(optarg);
	    } else {
		usage();
		exit(-1);
	    }
	    break;
	case 'p':
	    if (strlen(optarg) != 0) {
		if (optarg[strlen(optarg)] != '/') {
		    copypath = ne_malloc(strlen(optarg) + 2);
		    strcpy(copypath, optarg);
		    strcat(copypath, "/");
		} else {
		    copypath = ne_strdup(optarg);
		}
	    } else {
		usage();
		exit(-1);
	    }
	    break;
#ifdef NE_DEBUGGING
	case 'd': {
	    char errbuf[20];
	    /* set debugging level */
	    
	    if (map_debug_options(optarg, &use_debug_mask, errbuf)) {
		printf(_("%s: Error: Debug channel %s not known.\n"),
		       progname, errbuf );
		exit(-1);
	    }
	} break;
	case 'g': {
	    FILE *f = fopen(optarg, "a+");
	    if (f == NULL) {
		printf(_("%s: Warning: Could not open `%s' to use as logfile.\n"),
		       progname, optarg);
		f = stderr;
	    } else {
		use_debug_stream = f;
		/* TODO: Close this stream when we exit?... welll...
		 * we *could* do. */
	    }
	} break;
#endif
	case 'x':
	    createremoteroot = true;
	    break;
	case 'y':
	    prompting = true;
	    break;
	case 'k':
	    keepgoing = true;
	    break;
	case 'a':
	    allsites = true;
	    break;
        case 'n':
            dry_run = true;
            break;
	case 'o':
	    show_progress = true;
	    break;
	case 'V': 
	    version();
	    puts(ne_version_string());
	    exit(-1);
	case 'h': usage(); exit(-1);
	case '?': 
	default:
	    printf(_("Try `%s --help' for more information.\n"), progname);
	    exit(1);
	}
    }

    /* Set the default action mode */
    if (action == action_none)
	action = action_list;

    /* Dry-run mode is only currently supported for --update */
    if (dry_run && action != action_update) {
        printf(_("%s: Error: Dry run mode is currently only supported "
                 "for updates.\n"),
               progname);
        exit(1);
    }

#ifdef NE_DEBUGGING
    ne_debug_init(use_debug_stream, use_debug_mask);
#else
    ne_debug_init(stderr, 0);
#endif

    /* Get those site names off the end of the cmdline */
    for (numsites = 0 ; optind < argc; optind++) {
	sitenames[numsites++] = argv[optind];
	if (numsites == MAXSITES) {
	    printf(_("%s: Warning: Only %d sites can be specified on the command line!\nExtra entries are being skipped.\n"), progname, MAXSITES);
	    break;
	}
    }

}

static int get_username(const char *prompt, char *buffer)
{
    printf("%s", prompt);
    if (fgets(buffer, FE_LBUFSIZ, stdin)) {
	ne_shave(buffer, "\r\n ");
	return 0;
    } else {
	return -1;
    }
}

int fe_accept_cert(const ne_ssl_certificate *cert, int failures)
{
    const char *id = ne_ssl_cert_identity(cert);
    char *dn, fprint[61];

    ne_ssl_cert_digest(cert, fprint);

    puts(_("WARNING: Server certificate is not trusted."));
    
    if (id)
        printf(_("Certificate was issued for server `%s'.\n"), id);
    else
        puts(_("WARNING: Certificate does not specify a server"));
    
    printf(_("Fingerprint: %s\n"), fprint);

    dn = ne_ssl_readable_dname(ne_ssl_cert_subject(cert));
    printf(_("Issued to: %s\n"), dn);
    free(dn);

    dn = ne_ssl_readable_dname(ne_ssl_cert_issuer(cert));
    printf(_("Issued by: %s\n"), dn);
    free(dn);

    printf(_("Do you wish to accept this certificate? (y/n) "));

    return !yesno();
}

int fe_login(fe_login_context ctx, const char *realm, const char *hostname,
	     char *username, char *password) 
{
    const char *server = 
	(ctx==fe_login_server)?N_("server"):N_("proxy server");
    char *tmp;
    if (in_transfer) {
	printf("]");
    }
    if (realm) {
	printf(_("Authentication required for %s on %s `%s':\n"), 
	       realm, server, hostname);
    } else {
	printf(_("Authentication required on %s `%s':\n"), server, hostname);
    }
    if (username[0] == '\0') {
	if (get_username(_("Username: "), username)) {
	    printf("\nAuthentication aborted!\n");
	    return -1;
	}
    } else {
	printf(_("Username: %s\n"), username);
    }    
    tmp = getpass(_("Password: "));
    if (tmp == NULL) {
	/* joe: my Linux getpass doesn't say it will ever return NULL, 
	 * but, just to be sure... */
	return -1;
    }

    ne_strnzcpy(password, tmp, FE_LBUFSIZ);

    if (in_transfer) {
	printf(_("Retrying: ["));
	upload_sofar = 0;
    }
    return 0;
}

int fe_decrypt_clicert(const ne_ssl_client_cert *cert, char *password)
{
    const char *name = ne_ssl_clicert_name(cert);
    char *tmp;

    printf(_("%s: Encrypted client certificate configured%s%s.\n"),
           progname, name ? ": " : "", name ? name : "");

    tmp = getpass(_("Password: "));
    if (tmp == NULL) {
        return -1;
    }

    ne_strnzcpy(password, tmp, FE_LBUFSIZ);
    return 0;
}

void fe_warning(const char *descr, const char *reason, const char *err)
{
    printf("%s: Warning", progname);
    if (reason != NULL) {
	printf(" on `%s':\n", reason);
    } else {
	printf(":\n");
    }
    printf("%s", descr);
    if (err != NULL) 
	printf(" - %s\n", err);
    else
	printf("\n");
}

int fe_can_update(const struct site_file *file)
{
    char tmp[256];

    if (!prompting) return true;
    switch (file->type) {
    case file_dir:
	if (file->diff == file_new) {
	    printf(_("Create %s/"), file_name(file));
	} else {
	    printf(_("Delete %s/"), file_name(file));
	}
	break;
    case file_file:
	switch (file->diff) {
	case file_changed:
	case file_new: 
            ne_snprintf(tmp, sizeof tmp, "%" NE_FMT_OFF_T, file->local.size);
	    printf(_("Upload %s (%s bytes)"), file_name(file), tmp);
            break;
	case file_deleted: printf(_("Delete %s"), file_name(file)); break;
	case file_moved: printf(_("Move %s->%s"), file->stored.filename,
				 file_name(file)); break;
	default: 
	    /* Shouldn't happen */
	    printf(_("%s: in fe_can_update/file_file\n%s"), progname, 
		    contact_mntr);
	    break;
	}
	break;
    case file_link:
	switch (file->diff) {
	case file_changed: printf(_("Change %s"), file_name(file)); break;
	case file_new: printf(_("Create %s"), file_name(file)); break;
	case file_deleted: printf(_("Remove %s"), file_name(file)); break;
	default:
	    /* Shouldn't happen */
	    printf(_("%s: in fe_can_update/file_link\n%s"), progname,
		    contact_mntr);
	    break;
	}
	break;
    }
    printf(_("? (y/n) "));
    return yesno();
}

void fe_checksumming(const char *filename)
{
    switch (quiet) {
    case 0:
	in_transfer = 0;
	printf(_("Checksumming %s: ["), filename);
	fflush(stdout);
	break;
    case 1:
	printf("%s\n", filename);
    default:
	break;
    }
}

void fe_checksummed(const char *file, int success, const char *err)
{
    switch (quiet) {
    case 0:
	if (success) {
	    printf(_("] done.\n"));
	} else {
	    printf(_("] failed:\n%s\n"), err);
	}
    default:
	break;
    }
}

void fe_setting_perms(const struct site_file *file)
{
    if (quiet == 0) {
	printf(_("Setting permissions on %s%s: "), file_name(file),
               file->type == file_dir ? "/" : "");
	fflush(stdout);
    }
}

void fe_set_perms(const struct site_file *file, int success, const char *error)
{
    if (quiet == 0) {
	if (success) {
	    printf(_("done.\n"));
	} else {
	    printf(_("failed:\n%s\n"), error);
	}
    }
}

/* Called when the given files is about to be updated */
void fe_updating(const struct site_file *file)
{
    if (quiet) {
	if (quiet == 1) {
	    printf("%s\n", file_name(file));
	}
	return;
    }

    in_transfer = 0;
    switch (file->type) {
    case file_dir:
	if (file->diff == file_new) {
	    printf(_("Creating %s/: "), file_name(file));
	} else {
	    printf(_("Deleting %s/: "), file_name(file));
	}
	break;
    case file_file:
	switch (file->diff) {
	case file_changed:
	case file_new: 
	    printf(_("Uploading %s: ["), file_name(file)); 
	    break;
	case file_deleted: 
	    printf(_("Deleting %s: "), file_name(file));
	    break;
	case file_moved: 
	    printf(_("Moving %s->%s: "), file->stored.filename,
		   file->local.filename); 
	    break;
	default: 
	    printf(_("%s: in fe_updating/file_file\n%s"), progname,
		   contact_mntr); 
	    break;
	}
	break;
    case file_link:
	switch (file->diff) {
	case file_changed:
	    printf(_("Changing %s: "), file_name(file)); break;
	case file_new:
	    printf(_("Creating %s: "), file_name(file)); break;
	case file_deleted:
	    printf(_("Deleting %s: "), file_name(file)); break;
	default:
	    printf(_("%s: in fe_updating/file_link\n%s"), progname,
		   contact_mntr); 
	}
	break;
    }

    fflush(stdout);
}

void fe_updated(const struct site_file *file, int success, const char *error)
{
    char wrap = error && strlen(error) < 30 ? ' ' : '\n';

    upload_sofar += file->local.size;

    if (quiet > 0) {
	if (! success) {
	    printf(_("Failed to update %s:%c%s\n"), file_name(file), wrap, error);
	}
	return;
    }
    if ((file->type == file_dir) || 
	(file->diff!=file_changed && file->diff!=file_new)) {
	if (success) {
	    printf(_("done.\n"));
	} else {
	    printf(_("failed:%c%s\n"), wrap, error);
	}
    } else {
	if (success) {
	    if (show_progress) {
		float prog = (100 * (float)upload_sofar) / (float)upload_total;
		if (upload_total == 0) prog = 0;
		printf(("] done. (%.0f%% finished)\n"), prog);
	    } else {
		printf(_("] done.\n"));
	    }
	} else {
	    printf(_("] failed:%c%s\n"), wrap, error);
	}
    }
}

void fe_synching(const struct site_file *file)
{
    if (quiet) {
	printf("%s\n", file_name(file));
	return;
    }

    in_transfer = 0;
    switch (file->type) {
    case file_dir:
	if (file->diff != file_new) {
	    printf(_("Creating %s/: "), file_name(file));
	} else {
	    printf(_("Deleting %s/: "), file_name(file));
	}
	break;
    case file_file:
	switch (file->diff) {
	case file_changed:
	case file_deleted: 
	    printf(_("Downloading %s: ["), file_name(file)); 
	    break;
	case file_new: 
	    printf(_("Deleting %s: "), file_name(file)); 
	    break;
	case file_moved: 
	    printf(_("Moving %s->%s: "), file->local.filename,
		   file->stored.filename); 
	    break;
	default: 
	    break;
	    }
    case file_link:
	/* TODO-ng */
	break;
    }
    fflush(stdout);

}

void fe_synched(const struct site_file *file, int success, const char *error) 
{
    if (quiet)
	return;
    if ((file->type == file_dir) || 
	(file->diff!=file_changed && file->diff!=file_deleted)) {
	if (success) {
	    printf(_("done.\n"));
	} else {
	    printf(_("failed:\n%s\n"), error);
	}
    } else {
	if (success) {
	    printf(_("] done.\n"));
	} else {
	    printf(_("] failed:\n%s\n"), error);
	}
    }
}

void fe_verified(const char *name, enum file_diff match)
{
    const char *state = "huh?";
    switch (match) {
    case file_changed:
	state = _("Changed on server");
	break;
    case file_new:
	state = _("Added on server");
	break;
    case file_unchanged:
    case file_deleted:
    case file_moved:
	return;
	break;
    }
    printf(_("%s: %s\n"), state, name);
}

void fe_transfer_progress(ne_off_t num, ne_off_t total) 
{
    if (quiet == 0) {
	putchar('.');
	fflush(stdout);
	in_transfer = 1;
    }
}

void fe_connection(fe_status status, const char *info) {}

void fe_fetch_found(const struct site_file *file) 
{
    char tmp[80];

    switch (file->type)  {
    case file_dir:
	printf(_("Directory: %s/\n"), file->stored.filename);
	break;
    case file_file:
	/* TODO: could put checksum or modtime in here as appropriate */
        ne_snprintf(tmp, sizeof tmp, "%" NE_FMT_OFF_T, file->stored.size);
	printf(_("File: %s - size %s%s\n"), 
	       file->stored.filename, tmp, 
	       file->stored.ascii?_(" (ASCII)"):"");
	break;
    case file_link:
	printf(_("Link: %s - target %s\n"), file->stored.filename,
	       file->stored.linktarget);
	break;
    }
}

static void init_sites(void)
{
    int ret;
    
    /* Read the rcfile */
    ret = rcfile_read(&all_sites);
    if (ret == RC_OPENFILE) {
	printf(_("%s: Error: Could not open rcfile: %s.\n"),
		progname, rcfile);
	exit(-1);
    } else if (ret == RC_CORRUPT) {
	printf(_("%s: rcfile corrupt at line %d:\n%s\n"),
		progname, rcfile_linenum, rcfile_err);
	exit(-1);
    }
}

/* Verify sites list. */
static int verify_sites(struct site *sites, enum action act) 
{
    int count = 0, ret;
    struct site *current;
    int isokay;

    for (current = sites; current!=NULL; current=current->next) {
	if (!current->use_this && !allsites) continue;
	/* Check the site rcfile entry is okay */
	ret = rcfile_verify(current);
	switch (ret) {
	case SITE_ACCESSLOCALDIR:
	    printf(_("%s: Could not read directory for `%s':\n\t%s\n"), 
		    progname, current->name, current->local_root);
	    break;
	case SITE_NOSERVER:
	    printf(_("%s: Server not specified in site `%s'.\n"), 
		    progname, current->name);
	    break;
	case SITE_NOREMOTEDIR:
	    printf(_("%s: Remote directory not specified in site `%s'.\n"), 
		    progname, current->name);
	    break;
	case SITE_NOLOCALDIR:
	    printf(_("%s: Local directory not specified in site `%s'.\n"), 
		    progname, current->name);
	    break;
	case SITE_INVALIDPORT:
	    printf(_("%s: Invalid port used in site `%s'.\n"),
		    progname, current->name);
	    break;
	case SITE_NOMAINTAIN:
	    printf(_("%s: %s cannot maintain symbolic links (site `%s').\n"),
		    progname, site_get_protoname(current), current->name);
	    break;
	case SITE_NOREMOTEREL:
	    printf(_("%s: Cannot use a relative remote directory in %s (site `%s').\n"), progname, site_get_protoname(current), current->name);
	    break;
	case SITE_NOPERMS:
	    printf(_("%s: File permissions are not supported in %s (site `%s').\n"), progname, site_get_protoname(current), current->name);
	    break;
	case SITE_NOSAFEOVER:
	    printf(_("%s: Safe mode cannot be used in conjunction with nooverwrite (site `%s').\n"), progname, current->name);
	    break;
	case SITE_NOSAFETEMPUP:
	    printf(_("%s: Safe mode cannot be used in conjunction with tempupload (site `%s').\n"), progname, current->name);
	    break;
	case SITE_NORENAMES:
	    printf(_("%s: Can only check for renamed files when checksumming (site `%s').\n"), progname, current->name);
	    break;
	case SITE_UNSUPPORTED:
	    printf(_("%s: The protocol `%s' is unsupported (site `%s').\n"),
		    progname, current->proto_string, current->name);
	    break;
	case 0:
	    /* Success */
	    break;
	default:
	    printf(_("%s: Unhandled error %d in site `%s' - please contact the maintainer.\n"), progname, ret, current->name);
	    break;
	}

	if (ret != 0) { 
	    isokay = false;
	} else {
	    isokay = true;
	}

	if (isokay && (actions[act].flags & A_LOCAL)) {
	    site_read_local_state(current);
	}

	if (isokay && (actions[act].flags & A_STORED)) {
	    ret = site_read_stored_state(current);
	    switch (ret) {
	    case SITE_ERRORS: 
		printf(_("%s: Error: Corrupt site storage file for `%s':\n%s: %s\n"),
			progname, current->name, progname, current->last_error);
		isokay = false;
		break;
	    case SITE_FAILED:
		if ((actions[act].flags & A_COND_STORED) == A_COND_STORED) {
		    break;
		} else {
		    printf(_(
			"%s: Error: No storage file for `%s'.\n"
			"%s: Use --init, --catchup or --fetch to create a storage file.\n"),
			   progname, current->name, progname);
		}
		isokay = false;
	    default:
		break;
	    }
	}

	if (isokay) {
	    count++;
	} else {
	    printf(_("%s: Skipping site `%s'.\n"), progname, current->name);
	    current->use_this = false;
	}

    }
    return count;
}

static int issue_error(struct site *site, enum action actno, int error) 
{
    struct action_info *act = &actions[actno];
    int ret;
    switch (error) {
    case SITE_OK:
	if (quiet == 0) {
	    printf(_("%s: %s completed successfully.\n"), progname, 
		   _(act->verb));
	}
	ret = 0;
	break;
    case SITE_UNSUPPORTED:
	printf(_("%s: %s unsupported for %s.\n"), progname, _(act->verb), 
		site_get_protoname(site));
	ret = 4;
	break;
    case SITE_ERRORS:
	printf(_("%s: Errors occurred while %s the %s site.\n"), progname,
		_(act->doing), _(act->subject));
	ret = 1;
	break;
    case SITE_LOOKUP:
	printf(_("%s: Error: Could not resolve remote hostname (%s).\n"),
		progname, site->server.hostname);
	ret = 2;
	break;
    case SITE_PROXYLOOKUP:
	printf(
	    _("%s: Error: Could not resolve hostname of proxy server (%s).\n"),
	    progname, site->proxy.hostname);
	ret = 2;
	break;
    case SITE_CONNECT:
	if (site->proxy.hostname) {
	    printf(_("%s: Error: Could not connect to proxy server (%s port %d).\n"),
		   progname, site->proxy.hostname, site->proxy.port);
	} else {
	    printf(_("%s: Error: Could not connect to server (%s port %d).\n"),
		   progname, site->server.hostname, site->server.port);
	}
	ret = 2;
	break;
    case SITE_AUTH:
	printf(_("%s: Error: Could not authorise user on server.\n"),
		progname);
	ret = 2;
	break;
    case SITE_FAILED:
	printf(_("%s: Error: %s\n"), progname, site->last_error);
	ret = 2;
	break;
    case SITE_PROXYAUTH:
	printf(_("%s: Error: Could not authorise user on proxy server (%s).\n"),
		progname, site->proxy.hostname);
	ret = 2;
	break;
    default:
	printf(_("%s: in issue_error\n%s"), progname, contact_mntr);
	ret = 5;
	break;
    }
    return ret;
}

static void init(int argc, char **argv) 
{
    int ret;

    parse_cmdline(argc, argv);

    if (init_env() == 1) {
	printf(_("%s: Error: Environment variable HOME not set.\n"),
		progname);
	exit(-1);
    }

    ret = init_paths();
    switch (ret) {
    case RC_OPENFILE:
	printf(_("%s: Error: Could not open rcfile: %s\n"), progname, rcfile);
	break;
    case RC_PERMS:
	printf(_("%s: Error: rcfile permissions allow other users to read your rcfile.\n"), progname);
	printf(_("%s: Set the permissions to 0600.\n"), progname);
	break;
    case RC_DIROPEN:
	printf(_("%s: Error: Could not open storage directory: %s\n"), progname, copypath);
	printf(_("%s: You need to create this directory and set the permissions to 0700.\n"), progname);
	break;
    case RC_DIRPERMS:
	printf(_("%s: Error: storage directory permissions incorrect.\n"), progname);
	printf(_("%s: Set the permissions to 0700.\n"), progname);
	break;
    case RC_NETRCPERMS:
	printf(_("%s: Error: ~/.netrc permissions incorrect.\n"), progname);
	printf(_("%s: Set the permissions to 0600.\n"), progname);
	break;
    case 0:
	break;
    default:
	printf(_("%s: init_paths gave %d\n%s"), progname, ret,
		contact_mntr);
	break;
    }
    if (ret != 0) exit(-1);

    if (init_netrc() == 1) {
	printf(_("%s: Error: Could not parse ~/.netrc.\n"), progname);
	exit(-1);
    }

    init_sites();
}

static int act_on_site(struct site *site, enum action act) 
{
    int ret = 0, verify_removed;

    /* Set the options */
     site->keep_going = keepgoing;
     site->create_remote_root = createremoteroot;	

    switch (act) {
    case action_update:
	if (!site->remote_is_different) {
	    if (quiet == 0) {
		printf(_("%s: Nothing to do - no changes found.\n"), 
		       progname);
	    }
	} else if (dry_run) {
            extern const struct proto_driver null_driver;
            site->driver = &null_driver;
            ret = issue_error(site, act, site_update(site));
        } else {
	    if (site_open_storage_file(site) == NULL) {
		printf(_("%s: Error: Could not open storage file for writing (%s)\n"
			  "%s: Error: %s\n"
			  "%s: Will not update site `%s'.\n"), 
			progname, site->infofile,
			progname, strerror(errno),
			progname, site->name);
		ret = -1;
	    } else {
		current_site = site;
		upload_total = site->totalchanged + site->totalnew;
		upload_sofar = 0;
		ret = issue_error(site, act, site_update(site));
		/* hope we don't get signalled here */
		current_site = NULL;
		site_write_stored_state(site);
	    }
	}
	break;
    case action_list:
	if (listflat) {
	    site_flatlist(stdout, site);
	} else {
	    list_site_changes(site);
	    if (site->state_method != site->stored_state_method) {
		printf(_("%s: Warning: Current state method differs from stored in site `%s'.\n%s: All existing files will appear changed (use catchup?).\n"), progname, site->name, progname);
	    }
	    if (site->remote_is_different) {
		int count = site->numchanged + site->numdeleted + 
		    site->nummoved + site->numnew;
		if (count > 1) {
		    printf(_("%s: The remote site needs updating (%d items to update).\n"), progname, count);
		} else {
		    printf(_("%s: The remote site needs updating (1 item to update).\n"), progname);
		}
	    } else {
		printf(_("%s: The remote site does not need updating.\n"), progname);
	    }
	}
	ret = site->remote_is_different?1:0;
	break;
    case action_init:
	site_initialize(site);
	site_write_stored_state(site);
	printf(_("%s: All the files and directories are marked as NOT updated remotely.\n"), progname);
	break;
    case action_catchup:
	site_catchup(site);
	site_write_stored_state(site);
	printf(_("%s: All the files and and directories are marked as updated remotely.\n"), progname);
	break;
    case action_fetch:
	ret = site_fetch(site);
	if (ret == SITE_OK) {
	    site_write_stored_state(site);
	}	    
	switch (ret) {
	case SITE_FAILED:
	    printf(_("%s: Failed to fetch file listing for site `%s':\n"
		     "%s: %s\n"), progname, site->name,
		   progname, site->last_error);
	    ret = -1;
	    break;
	default:
	    ret = issue_error(site, act, ret);
	    break;
	} 
	break;
    case action_verify:
	ret = site_verify(site, &verify_removed);
	switch (ret) {
	case SITE_FAILED:
	    printf(_("%s: Failed to fetch file listing to verify site `%s':\n"
		     "%s: %s\n"), progname, site->name, 
		   progname, site->last_error);
	    ret = -1;
	    break;
	case SITE_ERRORS:
	    if (verify_removed > 0) {
		printf(_("%s: Verify found %d files missing from server.\n"),
		       progname, verify_removed);
	    }
	    printf(_("%s: Remote site not synchronized with stored state.\n"), progname);
	    break;
	default:
	    ret = issue_error(site, act, ret);
	    break;
	} 
	break;
    case action_synch:
	if (!site->local_is_different) {
	    printf(_("%s: Nothing to do - no changes found.\n"), progname);
	} else if (site->numunchanged == 0 && site->numdeleted == 0 &&
		   site->nummoved == 0 && site->numchanged == 0 && 
		   site->numignored == 0) {
	    printf(_("%s: Refusing to delete all local files with a synchronize operation.\n"
		      "%s: Use --update to update the remote site.\n"),
		    progname, progname);
	} else {
	    ret = issue_error(site, act, site_synch(site));
	}
	break;
    default:
	printf(_("%s: in act_on_site\n%s"), progname, contact_mntr);
	ret = -1;
	break;
    }
    return ret;
}


static void usage(void) 
{
    version();
    printf(_("Usage: %s [OPTIONS] [MODE] [sitename]...\n"),
	     progname);
    printf(_("Options: \n"));
#ifdef NE_DEBUGGING
    printf(_(
"  -d, --debug=KEY[,KEY] Turn debugging on for each KEY, which may be:\n"
"     socket, files, rcfile, ftp, http, httpbody, rsh, sftp, xml, xmlparse, cleartext\n"
"     Warning: cleartext displays (normally hidden) passwords in plain text\n"
"  -g, --logfile=FILE    Append debugging messages to FILE (else use stderr)\n"
));
#endif
    printf(_(
"  -r, --rcfile=FILE     Use alternate run control file\n"
"  -p, --storepath=PATH  Use alternate site storage directory\n"
"  -y, --prompting       Request confirmation before making each update\n"
"  -a, --allsites        Perform the operation on ALL defined sites\n"
"  -x, --create-remote   Create root for remote site\n"
"  -k, --keep-going      Carry on an update regardless of errors\n"
"  -o, --show-progress   Display total percentage file transfer complete\n"
"  -q, --quiet           Be quiet while performing the operation\n"
"  -qq, --silent         Be silent while perforing the operation\n"
"  -n, --dry-run         Display but do not carry out the operation\n"
"Operation modes:\n"
"  -l, --list            List changes between remote and local sites (default)\n"
"  -ll, --flatlist       Flat list of changes between remote and local sites\n"
"  -v, --view            Display a list of the site definitions\n"
"  -i, --initialize      Mark all files and directories as not updated\n"
"  -f, --fetch           Find out what files are on the remote site\n"
"  -e, --verify          Verify stored state of site matches real remote state\n"
"  -c, --catchup         Mark all files and directories as updated\n"
"  -s, --synchronize     Update the local site from the remote site\n"
"  -u, --update          Update the remote site\n"
"  -h, --help            Display this help message\n"
"  -V, --version         Display version information\n"
"Please send feature requests and bug reports to sitecopy@lyra.org\n"));
}


/* Two-liner version information. */
static void version(void) 
{
    printf(PACKAGE_NAME " " PACKAGE_VERSION ":");
#ifdef USE_FTP
    printf(" FTP");
#endif /* FTP */
#ifdef USE_DAV
    printf(" WebDAV");
#endif /* USE_DAV */
#ifdef USE_RSH
    printf(" rsh/rcp");
#endif /* USE_RSH */
#ifdef USE_SFTP
    printf(" sftp/ssh");
#endif /* USE_SFTP */
#ifdef NE_DEBUGGING
    printf(", debugging");
#endif
#ifdef __EMX__
    printf(", EMX/RSX");
#else
#ifdef __CYGWIN__
    printf(", cygwin");
#else
    printf(", Unix");
#endif /* __CYGWIN__ */
#endif /* __EMX__ */
    printf(" platform.\n");
}