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
  
1417
  
1418
  
1419
  
1420
  
1421
  
1422
  
1423
  
1424
  
1425
  
1426
  
1427
  
1428
  
1429
  
1430
  
1431
  
1432
  
1433
  
1434
  
1435
  
1436
  
1437
  
1438
  
1439
  
1440
  
1441
  
1442
  
1443
  
1444
  
1445
  
1446
  
1447
  
1448
  
1449
  
1450
  
1451
  
1452
  
1453
  
1454
  
1455
  
1456
  
1457
  
1458
  
1459
  
1460
  
1461
  
1462
  
1463
  
1464
  
1465
  
1466
  
1467
  
1468
  
1469
  
1470
  
1471
  
1472
  
1473
  
1474
  
1475
  
1476
  
1477
  
1478
  
1479
  
1480
  
1481
  
1482
  
1483
  
1484
  
1485
  
1486
  
1487
  
1488
  
1489
  
1490
  
1491
  
1492
  
1493
  
1494
  
1495
  
1496
  
1497
  
1498
  
1499
  
1500
  
1501
  
1502
  
1503
  
1504
  
1505
  
1506
  
1507
  
1508
  
1509
  
1510
  
1511
  
1512
  
1513
  
1514
  
1515
  
1516
  
1517
  
1518
  
1519
  
1520
  
1521
  
1522
  
1523
  
1524
  
1525
  
1526
  
1527
  
1528
  
1529
  
1530
  
1531
  
1532
  
1533
  
1534
  
1535
  
// cmdline.cpp: implementation of the CCmdLine class. 
// 
// $Id: cmdline.cpp,v 1.24 2002/10/24 00:22:46 nilsson Exp $ 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "startdll.h" 
#include "cmdline.h" 
#include "roxen.h" 
#include "enumproc.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
//#define new DEBUG_NEW 
#endif 
 
static char *defPikeArgs[] = { 
 
  // List terminator 
  NULL 
}; 
 
static char *defPikeDefines[] = { 
  "-DRAM_CACHE", 
  "-DENABLE_THREADS", 
 
  // List terminator 
  NULL 
}; 
 
static char *defRoxenArgs[] = { 
 
  // List terminator 
  NULL 
}; 
 
 
//////////////////////// 
// 
// CArgList class 
// 
#define ARG_ALLOC 1 
#define ARG_THRESH 1 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CArgList::CArgList() 
{ 
  m_Count = 0; 
  m_Size = 0; 
  m_pData = NULL; 
 
  // Allocate an empty array 
  ReSize(1); 
} 
 
CArgList::~CArgList() 
{ 
  if (m_pData == NULL) 
    return; 
 
  for (int i=0; i<m_Count; i++) 
  { 
    delete (m_pData)[i]; 
  } 
 
  delete [] m_pData; 
} 
 
BOOL CArgList::CopyData(tData *p, int size) 
{ 
  int i; 
  int copySize = min(m_Size, size); 
 
  // copy 
  for (i=0; i<copySize; i++) 
    p[i] = m_pData[i]; 
 
  // clear 
  if (copySize < size) 
    for (i=copySize; i<size; i++) 
      p[i] = 0; 
 
  return TRUE; 
} 
 
BOOL CArgList::ReSize(int diff) 
{ 
  if (diff > 0) 
  { 
    int need = m_Count + diff; 
    // Grow the data array if necessary 
    if (need > m_Size) 
    { 
      // Allocate new array and make sure that an extra NULL entry always exists 
      tData *p = new tData[need + ARG_ALLOC + 1]; 
      CopyData(p, need+ARG_ALLOC+1); 
      if (m_pData) 
        delete m_pData; 
      m_pData = p; 
      m_Size = need + ARG_ALLOC; 
    } 
  } 
  else 
  { 
    // Trim the size of the data array 
    // if diff is 0 shrink the array if there is more than 
    // ARG_THRESH entries free 
    // if diff is negative use the absolute value as the thresh hold value 
    int thresh = ARG_THRESH; 
    if (diff < 0) 
      thresh = -diff; 
    if (m_Count + thresh < m_Size) 
    { 
      // Allocate new array and make sure that an extra NULL entry always exists 
      tData *p = new tData[m_Count + thresh + 1]; 
      CopyData(p, m_Count + thresh + 1); 
      if (m_pData) 
        delete m_pData; 
      m_pData = p; 
      m_Size = m_Count + thresh; 
    } 
  } 
 
  return TRUE; 
} 
 
 
BOOL CArgList::Exists(const char *item) 
{ 
  int ret = FALSE; 
  int i; 
 
  for (i=0; i<m_Count; i++) 
  { 
    if (strcmp(m_pData[i], item) == 0) 
    { 
      ret = TRUE; 
      break; 
    } 
  } 
 
  return ret; 
} 
 
 
BOOL CArgList::Add(const char *item) 
{ 
  ReSize(1); 
 
  int len = strlen(item); 
  char *p = new char[len+1]; 
 
  strcpy(p, item); 
  m_pData[m_Count++] = p; 
 
  return TRUE; 
} 
 
 
BOOL CArgList::AddIfNew(const char *item) 
{ 
  if (Exists(item)) 
    return TRUE; 
 
  return Add(item); 
} 
 
 
BOOL CArgList::Remove(const char *item) 
{ 
  int ret = FALSE; 
  int i; 
 
  for (i=0; i<m_Count; i++) 
  { 
    if (strcmp(m_pData[i], item) == 0) 
    { 
      delete m_pData[i]; 
 
      // Move the extra NULL entry also 
      for (int j=i+1; j<=m_Count; j++) 
        m_pData[j-1] = m_pData[j]; 
 
      m_Count--; 
       
      ret = TRUE; 
      break; 
    } 
  } 
 
  ReSize(0); 
 
  return ret; 
} 
 
 
//////////////////////// 
// 
// CCmdLine class 
// 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CCmdLine::CCmdLine() 
: m_SelfTestDir("data\\test"), m_LogDir("..\\logs"), 
  m_ConfigDir("..\\configurations") 
{ 
  m_bPreloaded      = FALSE; 
  m_bParseFinished  = FALSE; 
 
  m_bInstall    = FALSE; 
  m_bRemove     = FALSE; 
  m_bOnce       = FALSE; 
  m_bHelp       = FALSE; 
  m_bVersion    = FALSE; 
  m_bPassHelp   = FALSE; 
  m_bKeepMysql  = FALSE; 
  m_bMsdev      = FALSE; 
  m_bCheckVersion = TRUE; 
 
  m_iVerbose    = 1; 
 
  m_iDebug      = -1; 
 
} 
 
CCmdLine::~CCmdLine() 
{ 
} 
 
 
/* Check if the string s[0..len[ matches the glob m[0..mlen[ */ 
static BOOL does_match(char *s, char *p) 
{ 
  for (; *p; p++) 
  { 
    switch (*p) 
    { 
    case '?': 
      if(!*s++) return 0; 
      break; 
       
    case '*':  
      p++; 
      if (!*p) return 1;        //* slut / 
       
      for (; *s; s++) 
        if (does_match(s, p)) 
          return 1; 
         
        return 0; 
         
    default:  
      if(!*s || 
        *p != *s) return 0; 
      s++; 
    } 
  } 
 
  return *s==0; 
} 
 
//////////////////////// 
// 
// Match the first string against the pattern in the second 
// and optionally splitting the string on a character and 
// returning a pointer to the character after the first delim. 
// 
// The only wildcard character supported in the second string 
// is a trailing * which means match all characters to the end 
// of the string. 
// 
BOOL CCmdLine::Match(char *s, char *pattern, char *delim, char **value) 
{ 
  BOOL ret = FALSE; 
  if (does_match(s, pattern)) 
  { 
    if (delim && value) 
    { 
      *value = strpbrk(s, delim); 
      if (*value != NULL) 
      { 
        (*value)++; 
        ret = TRUE; 
      } 
    } 
    else 
      ret = TRUE; 
  } 
 
  return ret; 
} 
 
 
void CCmdLine::OutputLineFmt(HANDLE out, char *pFormat, ...) 
{ 
  TCHAR    chMsg[1024]; 
  va_list pArg; 
   
  va_start(pArg, pFormat); 
  _vstprintf(chMsg, pFormat, pArg); 
  va_end(pArg); 
   
  OutputLine(out, chMsg); 
} 
 
 
void CCmdLine::OutputLine(HANDLE out, char *line) 
{ 
  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;  
  WORD wOldColorAttrs;  
  DWORD cWritten; 
   
  if (GetConsoleScreenBufferInfo(out, &csbiInfo))  
    wOldColorAttrs = csbiInfo.wAttributes;  
  else 
    wOldColorAttrs = 0;  
   
  while (line && *line) 
  { 
    if (*line == '.' && line[1] && line[1] == 'B') 
    { 
      SetConsoleTextAttribute(out, wOldColorAttrs | FOREGROUND_INTENSITY); 
//      SetConsoleTextAttribute(out, FOREGROUND_RED); 
      line += 2; 
      continue; 
    } 
    if (*line == 'B' && line[1] && line[1] == '.') 
    { 
      SetConsoleTextAttribute(out, wOldColorAttrs); 
      line += 2; 
      continue; 
    } 
 
    WriteFile(out, line, 1, &cWritten, NULL); 
    line++; 
  } 
 
  SetConsoleTextAttribute(out, wOldColorAttrs); 
  WriteFile(out, "\r\n", 2, &cWritten, NULL); 
} 
 
 
void CCmdLine::PrintHelp() 
{ 
  char * helptext[] = 
  { 
    "", 
    "", 
    ".BThis command will start Roxen CMSB..", 
    "", 
    "The environment variable .BROXEN_ARGSB. can be used to specify", 
    "the default arguments.", 
    "", 
    "   .BArguments:B.", 
    "", 
    "      .B--versionB.:                  Output version information.", 
    "", 
    "      .B--help -?B.:                  This information.", 
    "", 
    "      .B--installB.:                  Register application and install as", 
    "                                  an NT service.", 
    "", 
    "      .B--registerB.:                 Register application.", 
    "", 
    "      .B--removeB.:                   Remove all registry setting and uninstall", 
    "                                  the NT service.", 
    "", 
    "      .B--offlineB.:                  Indicate that there is no network", 
    "                                  connection available. Disables DNS and some", 
    "                                  other similar things.", 
    "", 
    "      .B--remove-dumpedB.:            Remove all dumped code, thus forcing", 
    "                                  a recompile.", 
    "", 
    "      .B--verbose -vB.:               Enable more verbose messages.", 
    "", 
    "      .B--quiet -qB.:                 Disable most of the messages.", 
    "", 
/* 
    "      .B--log-dir=DIRB.:              Set the log directory. Defaults to .B../logsB..", 
    "", 
    "      .B--config-dir=DIRB.:           Use an alternate configuration directory.", 
    "                                  Defaults to .B../configurationsB..", 
    "", 
    "      .B--debug-log=FILEB.:           Use an alternate debuglog file.", 
    "                                  Defaults to .B../logs/debug/B.configdirname.B.1B..", 
    "", 
    "      .B--pid-file=FILEB.:            Store the roxen and startscript pids in this", 
    "                                  file. Defaults to .B../configurations/_roxen_pidB..", 
    "", 
    "      .B--silent-startB.:             Inhibits output to stdout. If used,", 
    "                                  this argument must be the first one.", 
*/ 
    "", 
    "      .B--without-ram-cacheB.:        Do not use an in-RAM cache to speed", 
    "                                  things up. Saves RAM at the cost of speed.", 
    "", 
    "      .B--without-ram-cache-statB.:   Disable the stat that is usually done", 
    "                                  for files in the ram cache to ensure that", 
    "                                  they are not changed before they are sent.", 
    "                                  Improves performance at the cost of constant", 
    "                                  aggravation if the site is edited. Useful for", 
    "                                  truly static sites.", 
    "", 
    "      .B--with-threadsB.:             If threads are available, use them.", 
    "", 
    "      .B--without-threadsB.:          Even if threads are enabled by default,", 
    "                                  disable them.", 
    "", 
    "      .B--with-profileB.:             Store runtime profiling information on", 
    "                                  a directory basis. This information is", 
    "                                  not saved on permanent storage, it is only", 
    "                                  available until the next server restart", 
    "                                  This will enable a new 'action' in the", 
    "                                  administration interface", 
    "", 
    "      .B--with-file-profileB.:        Like .B--with-profileB., but save information", 
    "                                  for each and every file.", 
    "", 
    "      .B--self-testB.:                Runs a testsuite.", 
    "      .B--self-test-verboseB.:        Runs a testsuite, report all tests.", 
//    "      .B--self-test-quietB.:          Runs a testsuite, only report errors.", 
    "      .B--self-test-dir=DIRB.:        Use this self test directory instead of", 
    "                                  the default .Bdata/testB. directory.", 
    "", 
    "      .B--onceB.:                     Run the server only once, in the foreground.", 
    "                                  This is very useful when debugging.", 
    "                                  Implies --module-debug.", 
    "", 
    "      .B--keep-mysqlB.:               Don't shut down MySQL process when exiting", 
    "                                  the start script. Useful during development", 
    "                                  or any other scenario where the start script", 
    "                                  is frequently terminated.", 
    "", 
/* 
    "      .B--gdbB.:                      Run the server in gdb. Implies .B--onceB..", 
    "", 
*/ 
/* 
    "      .B--msdevB.:                    Run the server in Microsoft Developer Studio.", 
    "                                  Implies .B--onceB..", 
*/ 
    "", 
    "      .B--programB.:                  Start a different program with the roxen", 
    "                                  Pike.", 
    "", 
    "      .B--with-debugB.:               Enable debug", 
    "", 
    "      .B--without-debugB.:            Disable all debug. This is the default.", 
    "", 
    "      .B--module-debugB.:             Enable more internal debug checks to", 
    "                                  simplify debugging of Roxen modules.", 
    "", 
    "      .B--fd-debugB.:                 Enable FD debug.", 
    "", 
    "      .B--dump-debugB.:               Enable dump debug.", 
    "", 
/* 
    "      .B--trussB.:                    (Solaris only). Run the server under", 
    "                                  truss, shows .BallB. system calls. This is", 
    "                                  extremely noisy, and is not intented for", 
    "                                  anything but debug.", 
    "", 
    "      .B--truss-cB.:                  (Solaris only). Run the server under", 
    "                                  truss -c, shows times for all system calls", 
    "                                  on exit. This is not intented for anything", 
    "                                  but debug. Slows the server down.", 
    "", 
*/ 
    "      .B--with-snmp-agentB.:          Enable internal SNMP agent code.", 
    "", 
    "  .BArguments passed to pike:B.", 
    "", 
    "       .B-DDEFINEB.:                  Define the symbol .BDEFINEB..", 
    "", 
    "       .B-d<level>B.:                 Set the runtime Pike debug to level.", 
    "                                  This only works if Pike is compiled", 
    "                                  with debug (i.e. with --rtl-debug to", 
    "                                  configure).", 
    "", 
    "       .B-rtB.:                       Enable runtime typechecking.", 
    "                                  Things will run more slowly, but it is very", 
    "                                  useful while developing code.", 
    "", 
    "                                  Enabled when starting roxen with --debug", 
    "", 
    "       .B-rTB.:                       Enable strict types.", 
    "                                  Same as adding #pragma strict-types", 
    "                                  to all files.", 
    "", 
    "                                  This enables more strict", 
    "                                  type-checking, things that are", 
    "                                  normally permitted (such as calling", 
    "                                  a mixed value, or assigning a typed", 
    "                                  object variable with an untyped", 
    "                                  object) will generate warnings.", 
    "", 
    "                                  Useful for module and roxen core", 
    "                                  developers, but not so useful for", 
    "                                  the occasional pike-script-writer.", 
    "", 
    "                                  Enabled when starting roxen with --debug", 
    "", 
    "       .B-s<size>B.:                  Set the stack size.", 
    "", 
    "       .B-M<path>B.:                  Add the path to the Pike module path.", 
    "", 
    "       .B-I<path>B.:                  Add the path to the Pike include path.", 
    "", 
    "       .B-P<path>B.:                  Add the path to the Pike program path.", 
    "", 
    "       .B-dtB.:                       Turn off tail recursion optimization.", 
    "", 
    "       .B-tB.:                        Turn on Pike level tracing.", 
    "", 
    "       .B-t<level>B.:                 Turn on more Pike tracing. This only", 
    "                                  works if Pike is compiled with debug", 
    "                                  (i.e. with --rtl-debug to configure).", 
    "", 
    "       .B-a<level>B.:                 Turn on Pike assembler debug. This only", 
    "                                  works if Pike is compiled with debug", 
    "                                  (i.e. with --rtl-debug to configure).", 
    "", 
    "       .B-wB.:                        Turn on Pike warnings.", 
    "", 
    "  .BEnvironment variables:B.", 
    "", 
    "     .BLANGB.:                        Used to determine the default locale", 
    "                                  in the administration interface and logs.", 
/* 
    "     .BROXEN_CONFIGDIRB.:             Same as .B--config-dir=... B.", 
    "     .BROXEN_PID_FILEB.:              Same as .B--pid-file=... B.", 
*/ 
    "     .BROXEN_LANGB.:                  The default language for all language", 
    "                                  related tags. Defaults to 'en' for english.", 
 
    // Must be last entry 
    NULL 
  }; 
 
  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 
  int i = 0; 
  while (helptext[i] != NULL) 
  { 
    OutputLine(hOut, helptext[i]); 
    i++; 
  } 
 
} 
 
 
 
/*** 
*static void parse_cmdline(cmdstart, argv, args, numargs, numchars) 
* 
*Purpose: 
*       Parses the command line and sets up the argv[] array. 
*       On entry, cmdstart should point to the command line, 
*       argv should point to memory for the argv array, args 
*       points to memory to place the text of the arguments. 
*       If these are NULL, then no storing (only coujting) 
*       is done.  On exit, *numargs has the number of 
*       arguments (plus one for a final NULL argument), 
*       and *numchars has the number of bytes used in the buffer 
*       pointed to by args. 
* 
*Entry: 
*       _TSCHAR *cmdstart - pointer to command line of the form 
*           <progname><nul><args><nul> 
*       _TSCHAR **argv - where to build argv array; NULL means don't 
*                       build array 
*       _TSCHAR *args - where to place argument text; NULL means don't 
*                       store text 
* 
*Exit: 
*       no return value 
*       int *numargs - returns number of argv entries created 
*       int *numchars - number of characters used in args buffer 
* 
*Exceptions: 
* 
*******************************************************************************/ 
 
#define NULCHAR    _T('\0') 
#define SPACECHAR  _T(' ') 
#define TABCHAR    _T('\t') 
#define DQUOTECHAR _T('\"') 
#define SLASHCHAR  _T('\\') 
 
void CCmdLine::SplitCmdline( 
  _TSCHAR *cmdstart, 
  _TSCHAR **argv, 
  _TSCHAR *args, 
  int *numargs, 
  int *numchars 
  ) 
{ 
  _TSCHAR *p; 
  _TUCHAR c; 
  int inquote;                    /* 1 = inside quotes */ 
  int copychar;                   /* 1 = copy char to *args */ 
  unsigned numslash;              /* num of backslashes seen */ 
   
  *numchars = 0; 
  *numargs = 1;                   /* the program name at least */ 
   
  /* first scan the program name, copy it, and count the bytes */ 
  p = cmdstart; 
  if (argv) 
    *argv++ = args; 
   
#ifdef WILDCARD 
    /* To handle later wild card expansion, we prefix each entry by 
    it's first character before quote handling.  This is done 
  so _[w]cwild() knows whether to expand an entry or not. */ 
  if (args) 
    *args++ = *p; 
  ++*numchars; 
   
#endif  /* WILDCARD */ 
   
  /* A quoted program name is handled here. The handling is much 
  simpler than for other arguments. Basically, whatever lies 
  between the leading double-quote and next one, or a terminal null 
  character is simply accepted. Fancier handling is not required 
  because the program name must be a legal NTFS/HPFS file name. 
  Note that the double-quote characters are not copied, nor do they 
  contribute to numchars. */ 
  if ( *p == DQUOTECHAR ) { 
  /* scan from just past the first double-quote through the next 
    double-quote, or up to a null, whichever comes first */ 
    while ( (*(++p) != DQUOTECHAR) && (*p != NULCHAR) ) { 
       
#ifdef _MBCS 
      if (_ismbblead(*p)) { 
        ++*numchars; 
        if ( args ) 
          *args++ = *p++; 
      } 
#endif  /* _MBCS */ 
      ++*numchars; 
      if ( args ) 
        *args++ = *p; 
    } 
    /* append the terminating null */ 
    ++*numchars; 
    if ( args ) 
      *args++ = NULCHAR; 
     
    /* if we stopped on a double-quote (usual case), skip over it */ 
    if ( *p == DQUOTECHAR ) 
      p++; 
  } 
  else { 
    /* Not a quoted program name */ 
    do { 
      ++*numchars; 
      if (args) 
        *args++ = *p; 
       
      c = (_TUCHAR) *p++; 
#ifdef _MBCS 
      if (_ismbblead(c)) { 
        ++*numchars; 
        if (args) 
          *args++ = *p;   /* copy 2nd byte too */ 
        p++;  /* skip over trail byte */ 
      } 
#endif  /* _MBCS */ 
       
    } while ( c != SPACECHAR && c != NULCHAR && c != TABCHAR ); 
     
    if ( c == NULCHAR ) { 
      p--; 
    } else { 
      if (args) 
        *(args-1) = NULCHAR; 
    } 
  } 
   
  inquote = 0; 
   
  /* loop on each argument */ 
  for(;;) { 
     
    if ( *p ) { 
      while (*p == SPACECHAR || *p == TABCHAR) 
        ++p; 
    } 
     
    if (*p == NULCHAR) 
      break;              /* end of args */ 
     
    /* scan an argument */ 
    if (argv) 
      *argv++ = args;     /* store ptr to arg */ 
    ++*numargs; 
     
#ifdef WILDCARD 
    /* To handle later wild card expansion, we prefix each entry by 
    it's first character before quote handling.  This is done 
    so _[w]cwild() knows whether to expand an entry or not. */ 
    if (args) 
      *args++ = *p; 
    ++*numchars; 
     
#endif  /* WILDCARD */ 
     
    /* loop through scanning one argument */ 
    for (;;) { 
      copychar = 1; 
      /* Rules: 2N backslashes + " ==> N backslashes and begin/end quote 
      2N+1 backslashes + " ==> N backslashes + literal " 
      N backslashes ==> N backslashes */ 
      numslash = 0; 
      while (*p == SLASHCHAR) { 
        /* count number of backslashes for use below */ 
        ++p; 
        ++numslash; 
      } 
      if (*p == DQUOTECHAR) { 
      /* if 2N backslashes before, start/end quote, otherwise 
        copy literally */ 
        if (numslash % 2 == 0) { 
          if (inquote) { 
            if (p[1] == DQUOTECHAR) 
              p++;    /* Double quote inside quoted string */ 
            else        /* skip first quote char and copy second */ 
              copychar = 0; 
          } else 
            copychar = 0;       /* don't copy quote */ 
           
          inquote = !inquote; 
        } 
        numslash /= 2;          /* divide numslash by two */ 
      } 
       
      /* copy slashes */ 
      while (numslash--) { 
        if (args) 
          *args++ = SLASHCHAR; 
        ++*numchars; 
      } 
       
      /* if at end of arg, break loop */ 
      if (*p == NULCHAR || (!inquote && (*p == SPACECHAR || *p == TABCHAR))) 
        break; 
       
      /* copy character into argument */ 
#ifdef _MBCS 
      if (copychar) { 
        if (args) { 
          if (_ismbblead(*p)) { 
            *args++ = *p++; 
            ++*numchars; 
          } 
          *args++ = *p; 
        } else { 
          if (_ismbblead(*p)) { 
            ++p; 
            ++*numchars; 
          } 
        } 
        ++*numchars; 
      } 
      ++p; 
#else  /* _MBCS */ 
      if (copychar) { 
        if (args) 
          *args++ = *p; 
        ++*numchars; 
      } 
      ++p; 
#endif  /* _MBCS */ 
    } 
     
    /* null-terminate the argument */ 
     
    if (args) 
      *args++ = NULCHAR;          /* terminate string */ 
    ++*numchars; 
  } 
   
  /* We put one last argument in -- a null ptr */ 
  if (argv) 
    *argv++ = NULL; 
  ++*numargs; 
} 
 
 
//////////////////////// 
// 
// Parse current argument (always argv[0]) and 
// return the number of parameters used 
// 
int CCmdLine::ParseArg(int argc, char *argv[], CCmdLine::tArgType & type) 
{ 
  char *value; 
   
 
  /* 
  -DRAM_CACHE 
  -DENABLE_THREADS 
   
  -DRUN_SELF_TEST 
  ## 
  --remove-dumped 
  ## 
  */ 
 
 
  //'-install'|'--install') 
  // 
  if (Match(*argv, "-install", NULL, NULL) || 
      Match(*argv, "--install", NULL, NULL) ) 
  { 
    m_bInstall = TRUE; 
    m_bCheckVersion = FALSE; 
    type = eArgStart; 
    return 1; 
  } 
 
  //'-register'|'--register') 
  // 
  if (Match(*argv, "-register", NULL, NULL) || 
      Match(*argv, "--register", NULL, NULL) ) 
  { 
    m_bRegister = TRUE; 
    m_bCheckVersion = FALSE; 
    type = eArgStart; 
    return 1; 
  } 
 
  //'-remove'|'--remove') 
  // 
  if (Match(*argv, "-remove", NULL, NULL) || 
      Match(*argv, "--remove", NULL, NULL) ) 
  { 
    m_bRemove = TRUE; 
    m_bCheckVersion = FALSE; 
    type = eArgStart; 
    return 1; 
  } 
 
  //-D*) 
  //DEFINES="$DEFINES $1" 
  if (Match(*argv, "-D*", NULL, NULL)) 
  { 
    m_saPikeDefines.Add(*argv); 
    type = eArgPike; 
    return 1; 
  } 
 
  //-l*) 
  // ARGS="$ARGS $1" 
  if (Match(*argv, "-l*", NULL, NULL)) 
  { 
    m_saPikeArgs.Add(*argv); 
    type = eArgPike; 
    return 1; 
  } 
 
  //--log-dir=*) 
  // LOGDIR=`echo $1 | sed -e 's/--log-dir=//'` 
  if (Match(*argv, "--log-dir=*", "=", &value)) 
  { 
    //strcpy(logdir, value); 
    type = eArgUnsupported; 
    return 1; 
  } 
 
  //--debug-log=*) 
  // DEBUGLOG=`echo $1 | sed -e's/--debug-log=//'` 
  if (Match(*argv, "--debug-log=*", "=", &value)) 
  { 
    //strcpy(debuglog, value); 
    type = eArgUnsupported; 
    return 1; 
  } 
 
  //--config-dir=*) 
  // DIR=`echo $1 | sed -e 's/--config-dir=//'` 
  // FILES=`echo $1 | sed -e's/--config-dir=//' -e's/\.//g' -e's./..g' -e 's.-..g'` 
  if (Match(*argv, "--config-dir=*", "=", &value)) 
  { 
    //strcpy(configdir, value); 
    type = eArgUnsupported; 
    return 1; 
  } 
 
  //--pid-file=*) 
  // pidfile=`echo $1 | sed -e 's/--pid-file=//'` 
 
   
  //'--with-security'|'--enable-security') 
  //  DEFINES="$DEFINES -DSECURITY" 
  if (Match(*argv, "--with-security", NULL, NULL) || 
      Match(*argv, "--enable-security", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DSECURITY"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--with-snmp-agent'|'--enable-snmp-agent') 
  //  DEFINES="$DEFINES -DSNMP_AGENT" 
  if (Match(*argv, "--with-snmp-agent", NULL, NULL) || 
      Match(*argv, "--enable-snmp-agent", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DSNMP_AGENT"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--debug'|'--with-debug'|'--enable-debug') 
  //  debug=1 
  if (Match(*argv, "--debug", NULL, NULL) || 
    Match(*argv, "--with-debug", NULL, NULL) || 
    Match(*argv, "--enable-debug", NULL, NULL) ) 
  { 
    m_iDebug = 1; 
    type = eArgDebug; 
    return 1; 
  } 
 
  //'--without-debug') 
  //  debug=-1 
  if (Match(*argv, "--without-debug", NULL, NULL)) 
  { 
    m_iDebug = -1; 
    type = eArgNoDebug; 
    return 1; 
  } 
 
  //'--module-debug') 
  //  debug=0 
  if (Match(*argv, "--module-debug", NULL, NULL) || 
    Match(*argv, "--with-module-debug", NULL, NULL) || 
    Match(*argv, "--enable-module-debug", NULL, NULL) ) 
  { 
    m_iDebug = 0; 
    type = eArgDebug; 
    return 1; 
  } 
 
  //'--fd-debug'|'--with-fd-debug'|'--enable-fd-debug') 
  //  DEFINES="-DFD_DEBUG $DEFINES" 
  if (Match(*argv, "--fd-debug", NULL, NULL) || 
    Match(*argv, "--with-fd-debug", NULL, NULL) || 
    Match(*argv, "--enable-fd-debug", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DFD_DEBUG"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--offline') 
  //  DEFINES="-DNO_DNS -DOFFLINE $DEFINES" 
  if (Match(*argv, "--offline", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DNO_DNS"); 
    m_saPikeDefines.Add("-DOFFLINE"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--without-ram-cache'|'--disable-ram-cache') 
  //  DEFINES="`echo $DEFINES | sed -e 's/-DRAM_CACHE//g'`" 
  if (Match(*argv, "--without-ram-cache", NULL, NULL) || 
    Match(*argv, "--disable-ram-cache", NULL, NULL) ) 
  { 
    m_saPikeDefines.Remove("-DRAM_CACHE"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--without-ram-cache-stat'|'--disable-ram-cache-stat') 
  //  DEFINES="`-DRAM_CACHE_ASUME_STATIC_CONTENT`" 
  if (Match(*argv, "--without-ram-cache-stat", NULL, NULL) || 
    Match(*argv, "--disable-ram-cache-stat", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DRAM_CACHE_ASUME_STATIC_CONTENT"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--dump-debug'|'--with-dump-debug'|'--enable-dump-debug') 
  //  DEFINES="-DDUMP_DEBUG $DEFINES" 
  if (Match(*argv, "--dump-debug", NULL, NULL) || 
    Match(*argv, "--with-dump-debug", NULL, NULL) || 
    Match(*argv, "--enable-dump-debug", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DDUMP_DEBUG"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--threads'|'--with-threads'|'--enable-threads') 
  //  DEFINES="-DENABLE_THREADS $DEFINES" 
  if (Match(*argv, "--threads", NULL, NULL) || 
    Match(*argv, "--with-threads", NULL, NULL) || 
    Match(*argv, "--enable-threads", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DENABLE_THREADS"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--no-threads'|'--without-threads'|'--disable-threads') 
  //  DEFINES="`echo $DEFINES | sed -e 's/-DENABLE_THREADS//g'`" 
  if (Match(*argv, "--no-threads", NULL, NULL) || 
    Match(*argv, "--without-threads", NULL, NULL) || 
    Match(*argv, "--disable-threads", NULL, NULL) ) 
  { 
    m_saPikeDefines.Remove("-DENABLE_THREADS"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--with-profile'|'--profile') 
  //  DEFINES="-DPROFILE $DEFINES" 
  if (Match(*argv, "--profile", NULL, NULL) || 
    Match(*argv, "--with-profile", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DPROFILE"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--with-file-profile'|'--file-profile') 
  //  DEFINES="-DPROFILE -DFILE_PROFILE $DEFINES" 
  if (Match(*argv, "--file-profile", NULL, NULL) || 
    Match(*argv, "--with-file-profile", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add("-DFILE_PROFILE"); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--quiet'|'-q') 
  //  verbose=0 
  if (Match(*argv, "-q", NULL, NULL) || 
      Match(*argv, "--quiet", NULL, NULL) ) 
  { 
    m_iVerbose = 0; 
    m_saRoxenArgs.Add("--quiet"); 
    type = eArgStart; 
    return 1; 
  } 
 
  //'--verbose'|'-v') 
  //  verbose=2 
  //  debug=1 
  if (Match(*argv, "-v", NULL, NULL) || 
      Match(*argv, "--verbose", NULL, NULL) ) 
  { 
    m_iVerbose = 2; 
    m_iDebug = 1; 
    type = eArgStart; 
    return 1; 
  } 
 
  //'--remove-dumped') 
  //   remove_dumped=1; 
  if (Match(*argv, "--remove-dumped", NULL, NULL) ) 
  { 
    m_saRoxenArgs.Add(*argv); 
    type = eArgRoxen; 
    return 1; 
  } 
 
  //'--once') 
  //  once=1 
  if (Match(*argv, "--once", NULL, NULL) ) 
  { 
    m_bOnce = TRUE; 
    m_iDebug = max(m_iDebug, 0); 
    type = eArgStart; 
    return 1; 
  } 
 
//# Misspelling --once might give undesirable results, so let's accept 
//# some "creative" spellings...  :-) 
  //'--onve'|'--onec'|'--onev') 
  //  once=1 
  if (Match(*argv, "--onve", NULL, NULL) || 
      Match(*argv, "--onec", NULL, NULL) || 
      Match(*argv, "--onev", NULL, NULL) ) 
  { 
    m_bOnce = TRUE; 
    m_iDebug = max(m_iDebug, 0); 
    type = eArgStart; 
    return 1; 
  } 
 
  //'--keep-mysql') 
  //  keep_mysql=1 
  if (Match(*argv, "--keep-mysql", NULL, NULL) ) 
  { 
    m_bKeepMysql = TRUE; 
    type = eArgStart; 
    return 1; 
  } 
 
  //'--gdb') 
  //  gdb=gdb 
  //  once=1 
/* 
  if (Match(*argv, "--msdev", NULL, NULL) ) 
  { 
    m_bOnce = TRUE; 
    m_bMsdev = TRUE; 
    type = eArgStart; 
    return 1; 
  } 
*/ 
 
  //'--program') 
  //  program="$2" 
  //  once=1 
  //  passhelp=1 
  if (Match(*argv, "--program", NULL, NULL) ) 
  { 
    if (argc > 1) 
    { 
      int count; 
      for (count=0; count<argc; count++) 
        m_saRoxenArgs.Add(argv[count]); 
      m_bOnce = TRUE; 
      m_bPassHelp = TRUE; 
      m_bKeepMysql = TRUE; 
      m_bCheckVersion = FALSE; 
      type = eArgNtLoader; 
      return count; 
    } 
    else 
    { 
      type = eArgMoreData; 
      return 1; 
    } 
  } 
 
  //'--cd') 
  //  cd_to="$2" 
  //  # Use the absolute path... 
  //  roxendir="`pwd`" 
  //  once=1 
  //  shift 
  if (Match(*argv, "--cd", NULL, NULL) ) 
  { 
    if (argc > 1) 
    { 
      m_saRoxenArgs.Add(*argv); 
      m_saRoxenArgs.Add(argv[1]); 
      m_bOnce = TRUE; 
      type = eArgNtLoader; 
      return 2; 
    } 
    else 
    { 
      type = eArgMoreData; 
      return 1; 
    } 
  } 
 
  //--debug-without=*|-r*|-d*|-t*|-l*|-w*|-a*|-p*|--*-debug*) 
  //  # Argument passed along to Pike. 
  //  ARGS="$ARGS $1" 
  if (Match(*argv, "--debug-without=*", NULL, NULL) || 
      Match(*argv, "-r*", NULL, NULL) || 
      Match(*argv, "-d*", NULL, NULL) || 
      Match(*argv, "-t*", NULL, NULL) || 
      Match(*argv, "-l*", NULL, NULL) || 
      Match(*argv, "-w*", NULL, NULL) || 
      Match(*argv, "-p*", NULL, NULL) || 
      Match(*argv, "-a*", NULL, NULL) || 
      Match(*argv, "--*-debug*", NULL, NULL) ) 
  { 
    m_saPikeArgs.Add(*argv); 
    type = eArgPike; 
    return 1; 
  } 
 
  //-D*|-M*|-I*|-P*) 
  //  # Argument passed along to Pike. 
  //  DEFINES="$DEFINES $1" 
  if (Match(*argv, "-D*", NULL, NULL) || 
      Match(*argv, "-M*", NULL, NULL) || 
      Match(*argv, "-I*", NULL, NULL) || 
      Match(*argv, "-P*", NULL, NULL) ) 
  { 
    m_saPikeDefines.Add(*argv); 
    type = eArgPike; 
    return 1; 
  } 
 
  //'--version') 
  // if [ "x$passhelp" = "x1" ] ; then 
  //   pass="$pass --version" 
  // else 
  //  if [ -f server_core/core.pike ]; then 
  //    echo "ChiliMoon `roxen_version`" 
  //    exit 0 
  //  else 
  //    echo 'server_core/core.pike not found!' 
  //    exit 1 
  //  fi 
  // fi 
  if (Match(*argv, "--version", NULL, NULL)) 
  { 
    if (m_bPassHelp) 
    { 
      m_saRoxenArgs.Add(*argv); 
      type = eArgRoxen; 
    } 
    else 
    { 
      m_bCheckVersion = FALSE; 
      m_bVersion = TRUE; 
      type = eArgVersion; 
    } 
    return 1; 
  } 
 
  //'--self-test') 
  //  setup_for_tests 
  if (Match(*argv, "--self-test", NULL, NULL)) 
  { 
    type = eArgSelfTest; 
    return 1; 
  } 
 
  //'--self-test-quiet') 
  //  debug=-1 
  //  SILENT_START=y 
  //  do_pipe="| grep '  |'" 
  //  setup_for_tests 
  if (Match(*argv, "--self-test-quiet", NULL, NULL)) 
  { 
    // setup 
    //type = eArgSelfTest; 
    type = eArgUnsupported; 
    return 1; 
  } 
 
  //'--self-test-verbose') 
  //  pass="$pass --tests-verbose=1" 
  //  setup_for_tests 
  if (Match(*argv, "--self-test-verbose", NULL, NULL)) 
  { 
    m_saRoxenArgs.Add("--tests-verbose=1"); 
    type = eArgSelfTest; 
    return 1; 
  } 
 
  //--self-test-dir=*) 
  //  SELF_TEST_DIR=`echo $1 | sed -e's/--self-test-dir=//'` 
  if (Match(*argv, "--self-test-dir=*", "=", &value)) 
  { 
    m_SelfTestDir.resize(strlen(value)); 
    for (int i=0; i<strlen(value); i++) 
    { 
      if (value[i] == '/') 
        m_SelfTestDir[i] = '\\'; 
      else 
        m_SelfTestDir[i] = value[i]; 
    } 
    type = eArgStart; 
    return 1; 
  } 
 
  //'--help'|'-?') 
  if (Match(*argv, "--help", NULL, NULL) || 
      Match(*argv, "-?", NULL, NULL) ) 
  { 
    if (m_bPassHelp) 
    { 
      m_saRoxenArgs.Add(*argv); 
      type = eArgRoxen; 
    } 
    else 
    { 
      m_bCheckVersion = FALSE; 
      m_bHelp = TRUE; 
      type = eArgHelp; 
    } 
    return 1; 
  } 
 
 
  // Unknown option give it to roxen 
  m_saRoxenArgs.Add(*argv); 
  type = eArgRoxen; 
  return 1; 
} 
 
 
 
void CCmdLine::ParseFinish() 
{ 
  // Take care of some special argument handling 
 
  //case "x$debug" in 
  //  "x") 
  //    DEBUG="-DMODULE_DEBUG " 
  //    ARGS="$ARGS -w" 
  //    ;; 
  //  "x-1") 
  //    DEBUG="" 
  //    ;; 
  //  "x1") 
  //    DEBUG="-DDEBUG -DMODULE_DEBUG" 
  //    ARGS="$ARGS -w" 
  //    ;; 
  //esac 
 
  if (m_bParseFinished) 
    return; 
 
  // This must be before CheckVersionChange 
  m_bParseFinished = TRUE; 
 
  if (m_iDebug == 0) 
  { 
    m_saPikeDefines.AddIfNew("-DMODULE_DEBUG"); 
    m_saPikeArgs.AddIfNew("-w"); 
  } 
  else if (m_iDebug == -1) 
  { 
  } 
  else if (m_iDebug == 1) 
  { 
    m_saPikeDefines.AddIfNew("-DDEBUG"); 
    m_saPikeDefines.AddIfNew("-DMODULE_DEBUG"); 
    m_saPikeArgs.AddIfNew("-w"); 
  } 
 
  // This must be after anything that changes the PikeDefines 
  if (m_bCheckVersion) 
  { 
    if (CRoxen::CheckVersionChange()) 
    { 
      m_saRoxenArgs.AddIfNew("--remove-dumped"); 
      HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 
      if (m_iVerbose >= 1) 
        OutputLine(hOut, "          : Removing old precompiled files (defines or pike version changed)"); 
    } 
  } 
} 
 
 
BOOL CCmdLine::Parse(char * cmdline) 
{ 
  int numargs; 
  int numchars; 
 
  SplitCmdline((_TSCHAR *)cmdline, NULL, NULL, &numargs, &numchars); 
 
  _TSCHAR *p = new _TSCHAR[numargs * sizeof(_TSCHAR *) + numchars * sizeof(_TSCHAR)]; 
 
  SplitCmdline((_TSCHAR *)cmdline, (_TSCHAR **)p, p + numargs * sizeof(char *), &numargs, &numchars); 
 
  int ret = Parse(numargs-1, (char **)p); 
 
  delete p; 
 
  return ret; 
} 
 
 
BOOL CCmdLine::Parse(int argc, char *argv[]) 
{ 
  BOOL ret = TRUE; 
  tArgType type; 
  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 
  int i; 
 
  if (!m_bPreloaded) 
  { 
    // Preload the argument lists with default values 
    i = 0; 
    while (defPikeArgs[i] != NULL) 
    { 
      m_saPikeArgs.Add(defPikeArgs[i]); 
      i++; 
    } 
     
    i = 0; 
    while (defPikeDefines[i] != NULL) 
    { 
      m_saPikeDefines.Add(defPikeDefines[i]); 
      i++; 
    } 
     
    i = 0; 
    while (defRoxenArgs[i] != NULL) 
    { 
      m_saRoxenArgs.Add(defRoxenArgs[i]); 
      i++; 
    } 
    m_bPreloaded = TRUE; 
  } 
 
  // Walk through the argument list 
  i = 1; // skip argv[0] 
  while (i < argc && ret) 
  { 
    int numParsed = ParseArg(argc-i, &argv[i], type); 
 
    switch (type) 
    { 
    case eArgStart: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BNtStart argument: %sB.", argv[i]); 
      break; 
 
    case eArgNtLoader: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BNtRoxenLoader argument: %sB.", argv[i]); 
      break; 
 
    case eArgPike: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BPike argument: %sB.", argv[i]); 
      break; 
 
    case eArgRoxen: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BRoxen argument: %sB.", argv[i]); 
      break; 
 
    case eArgDebug: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BDebug argument: %sB.", argv[i]); 
      break; 
 
    case eArgNoDebug: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BNoDebug argument: %sB.", argv[i]); 
      break; 
 
    case eArgVersion: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BVersion argument: %sB.", argv[i]); 
      break; 
 
    case eArgSelfTest: 
      { 
        // Make sure the var directory exists 
        CreateDirectory("..\\var", NULL); 
 
        std::string selfTestDirUnx; 
        selfTestDirUnx.resize(m_SelfTestDir.length()); 
        for (int i=0; i<m_SelfTestDir.length(); i++) 
        { 
          if (m_SelfTestDir[i] == '\\') 
            selfTestDirUnx[i] = '/'; 
          else 
            selfTestDirUnx[i] = m_SelfTestDir[i]; 
        } 
         
        //DEFINES="-DRUN_SELF_TEST -DSELF_TEST_DIR=\"$SELF_TEST_DIR\" $DEFINES" 
        //rm -rf $VARDIR/test_config* 
        //cp -R data/test/config $VARDIR/test_config 
        //cp data/test/filesystem/test_rxml_package rxml_packages/test_rxml_package 
        //DIR=$VARDIR/test_config 
        //once=1 
        //remove_dumped=1 
        m_saPikeArgs.Add("-DRUN_SELF_TEST"); 
        m_saPikeArgs.Add(("-DSELF_TEST_DIR=\\\"" + selfTestDirUnx + "\\\"").c_str()); 
 
        m_bOnce = TRUE; 
        m_iDebug = max(m_iDebug, 1); 
        m_ConfigDir = "../var/test_config"; 
        m_saRoxenArgs.Add(("--config-dir=" + m_ConfigDir).c_str()); 
        m_saRoxenArgs.Add("--remove-dumped"); 
         
        // Make sure that mysql is not running 
        KillMySql(m_ConfigDir.c_str()); 
 
        SetEnvironmentVariable("COPYCMD", "/Y"); 
        system("rmdir /Q /S ..\\var\\test_config >NUL:"); 
 
        std::string setupCmd = m_SelfTestDir + "\\scripts\\setup.pike"; 
        DWORD attr = GetFileAttributes(setupCmd.c_str()); 
        if (attr != -1 && !(attr & FILE_ATTRIBUTE_DIRECTORY)) 
        { 
          setupCmd += " " + selfTestDirUnx + " ../var"; 
          CRoxen::RunPike(setupCmd.c_str()); 
        } 
         
      } 
      //OutputLineFmt(hOut, ".BSelfTest argument: %sB.", argv[i]); 
      break; 
 
    case eArgHelp: 
      // No extra handling here 
      //OutputLineFmt(hOut, ".BHelp argument: %sB.", argv[i]); 
      break; 
 
 
    case eArgMoreData: 
      ret = FALSE; 
      OutputLineFmt(hOut, ".BArgument requires more data: %sB.", argv[i]); 
      break; 
       
 
    case eArgUnsupported: 
      OutputLineFmt(hOut, ".BArgument not supported: %sB.", argv[i]); 
      break; 
       
 
    default: 
      OutputLineFmt(hOut, ".BInternal Error: default case hit with: %sB.", argv[i]); 
      break; 
       
    } 
 
    i += numParsed; 
  } 
 
 
  return ret; 
}