File: cmdline.cpp

package info (click to toggle)
objconv 2.56%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,300 kB
  • sloc: cpp: 27,039; makefile: 4; sh: 2
file content (1239 lines) | stat: -rw-r--r-- 47,381 bytes parent folder | download
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
/****************************  cmdline.cpp  **********************************
* Author:        Agner Fog
* Date created:  2006-07-25
* Last modified: 2023-03-29
* Project:       objconv
* Module:        cmdline.cpp
* Description:
* This module is for interpretation of command line options
* Also contains symbol change function
*
* Copyright 2006-2023 GNU General Public License http://www.gnu.org/licenses
*****************************************************************************/

#include "stdafx.h"

// List of recognized output file type options
static SIntTxt TypeOptionNames[] = {
    {CMDL_OUTPUT_ELF,   "elf"},
    {CMDL_OUTPUT_ELF,   "ELF"},
    {CMDL_OUTPUT_PE,    "pe"},
    {CMDL_OUTPUT_PE,    "PE"},
    {CMDL_OUTPUT_PE,    "coff"},
    {CMDL_OUTPUT_PE,    "COFF"},
    {CMDL_OUTPUT_PE,    "cof"},
    {CMDL_OUTPUT_PE,    "win"},
    {CMDL_OUTPUT_OMF,   "omf"},
    {CMDL_OUTPUT_MACHO, "mac"},
    {CMDL_OUTPUT_MACHO, "macho"},
    {CMDL_OUTPUT_MACHO, "mach-o"},
    {CMDL_OUTPUT_MACHO, "mach"},
    {CMDL_OUTPUT_MASM,  "asm"},
    {CMDL_OUTPUT_MASM,  "masm"},
    {CMDL_OUTPUT_MASM,  "tasm"},
    {CMDL_OUTPUT_MASM,  "nasm"},
    {CMDL_OUTPUT_MASM,  "yasm"},
    {CMDL_OUTPUT_MASM,  "gasm"},
    {CMDL_OUTPUT_MASM,  "gas"}
};

// List of subtype names
static SIntTxt SubtypeNames[] = {
    {SUBTYPE_MASM,  "asm"},
    {SUBTYPE_MASM,  "masm"},
    {SUBTYPE_MASM,  "tasm"},
    {SUBTYPE_NASM,  "nasm"},
    {SUBTYPE_NASM,  "yasm"},
    {SUBTYPE_GASM,  "gasm"},
    {SUBTYPE_GASM,  "gas"}
};

// List of standard names that are always translated
const uint32_t MaxType = FILETYPE_MACHO_LE;

// Standard names in 32-bit mode
const char * StandardNames32[][MaxType+1] = {
    //  0,    COFF,          OMF,           ELF,                MACHO
    {0,"___ImageBase","___ImageBase","__executable_start","__mh_execute_header"}
};

// Standard names in 64-bit mode
// COFF removes an underscore in 32-bit. There is no 64-bit OMF 
const char * StandardNames64[][MaxType+1] = {
    //  0,    COFF,       OMF,         ELF,                MACHO
    {0,"__ImageBase",  "",    "__executable_start","__mh_execute_header"}
};

const int NumStandardNames = sizeof(StandardNames32) / sizeof(StandardNames32[0]);


// Command line interpreter
CCommandLineInterpreter cmd;                  // Instantiate command line interpreter

CCommandLineInterpreter::CCommandLineInterpreter() {
    // Default constructor
    memset(this, 0, sizeof(*this));            // Set all to zero
    Verbose        = CMDL_VERBOSE_YES;         // How much diagnostics to print on screen
    DumpOptions    = DUMP_NONE;                // Dump options
    DebugInfo      = CMDL_DEBUG_DEFAULT;       // Strip or convert debug info
    ExeptionInfo   = CMDL_EXCEPTION_DEFAULT;   // Strip or preserve exception handling info
    SegmentDot     = CMDL_SECTIONDOT_NOCHANGE; // Change underscore/dot in beginning of segment names
    Underscore     = CMDL_UNDERSCORE_NOCHANGE; // Add/remove underscores in symbol names
    LibraryOptions = CMDL_LIBRARY_DEFAULT;     // Library options
}


CCommandLineInterpreter::~CCommandLineInterpreter() { // Destructor
}


void CCommandLineInterpreter::ReadCommandLine(int argc, char * argv[]) {

    // Read command line
    for (int i = 1; i < argc; i++) {
        ReadCommandItem(argv[i]);
    }
    if (ShowHelp || (InputFile == 0 && OutputFile == 0) /* || !OutputType */) {
        // No useful command found. Print help
        Help();  ShowHelp = 1;
        return;
    }
    // Check file options
    FileOptions = CMDL_FILE_INPUT;
    if (LibraryOptions == CMDL_LIBRARY_ADDMEMBER) {
        // Adding object files to library. Library may not exist
        FileOptions = CMDL_FILE_IN_IF_EXISTS;
    }
    if (DumpOptions || ((LibraryOptions & CMDL_LIBRARY_EXTRACTMEM) && !(LibraryOptions & CMDL_LIBRARY_ADDMEMBER))) {
        // Dumping or extracting. Output file not used
        if (OutputFile) err.submit(1103); // Output file name ignored
        OutputFile = 0;
    }
    else {
        // Output file required
        FileOptions |= CMDL_FILE_OUTPUT;
    }
    if ((LibraryOptions & CMDL_LIBRARY_ADDMEMBER) && !(LibraryOptions & CMDL_LIBRARY_CONVERT)) {
        // Adding library members only. Output file may have same name as input file
        FileOptions |= CMDL_FILE_IN_OUT_SAME;
    }
    // Check output type
    if (!OutputType) {
        // Output type not defined yet
        if (LibraryOptions & (CMDL_LIBRARY_CONVERT | CMDL_LIBRARY_ADDMEMBER)) {
            OutputType = FILETYPE_LIBRARY;
        }
    }
}


void CCommandLineInterpreter::ReadCommandItem(char * string) {
    // Read one option from command line
    // Skip leading whitespace
    while (*string != 0 && *string <= ' ') string++;
    if (*string == 0) return;  // Empty string

    // Look for option prefix and response file prefix
    const char OptionPrefix1 = '-';  // Option must begin with '-'
#if defined (_WIN32) || defined (__WINDOWS__)
    const char OptionPrefix2 = '/';  // '/' allowed instead of '-' in Windows only
#else
    const char OptionPrefix2 = '-';
#endif
    const char ResponseFilePrefix = '@';  // Response file name prefixed by '@'
    if (*string == OptionPrefix1 || *string == OptionPrefix2) {
        // Option prefix found. This is a command line option
        InterpretCommandOption(string+1);
    }
    else if (*string == ResponseFilePrefix) {
        // Response file prefix found. Read more options from response file
        ReadCommandFile(string+1);
    }
    else {
        // No prefix found. This is an input or output file name
        InterpretFileName(string);
    }
}


void CCommandLineInterpreter::ReadCommandFile(char * filename) {
    // Read commands from file
    if (*filename <= ' ') {
        err.submit(1001); return;    // Warning: empty filename
    }

    // Check if too many response file buffers (possibly because file includes itself)
    if (++NumBuffers > MAX_COMMAND_FILES) {err.submit(2107); return;}

    // Allocate buffer for response files.
    if (ResponseFiles.GetNumEntries() == 0) {
        ResponseFiles.SetNum(MAX_COMMAND_FILES);
        ResponseFiles.SetZero();
    }

    // Read response file into new buffer
    ResponseFiles[NumBuffers-1].FileName = filename;
    ResponseFiles[NumBuffers-1].Read();

    // Get buffer with file contents
    char * buffer = (char*)ResponseFiles[NumBuffers-1].Buf();
    char * ItemBegin, * ItemEnd;  // Mark begin and end of token in buffer

    // Check if buffer is allocated
    if (buffer) {

        // Parse contents of response file for tokens
        while (*buffer) {

            // Skip whitespace
            while (*buffer != 0 && uint8_t(*buffer) <= uint8_t(' ')) buffer++;
            if (*buffer == 0) break; // End of buffer found
            ItemBegin = buffer;

            // Find end of token
            ItemEnd = buffer+1;
            while (uint8_t(*ItemEnd) > uint8_t(' ')) ItemEnd++;
            if (*ItemEnd == 0) {
                buffer = ItemEnd;
            }
            else {
                buffer = ItemEnd + 1;
                *ItemEnd = 0;    // Mark end of token
            }
            // Found token. 
            // Check if it is a comment beginning with '#' or '//'
            if (ItemBegin[0] == '#' || (ItemBegin[0] == '/' && ItemBegin[1] == '/' )) {
                // This is a comment. Skip to end of line
                ItemEnd = buffer;
                while (*ItemEnd != 0 && *ItemEnd != '\n') {
                    ItemEnd++;
                }
                if (*ItemEnd == 0) {
                    buffer = ItemEnd;
                }
                else {
                    buffer = ItemEnd + 1;
                }
                continue;
            }
            // Not a comment. Interpret token
            ReadCommandItem(ItemBegin);
        }
    }
}


void CCommandLineInterpreter::InterpretFileName(char * string) {
    // Interpret input or output filename from command line

    switch (libmode) {
    case 1:            // First filename after -lib = inputfile and outputfile
        InputFile = string;
        libmode = 2;
        return;

    case 2:            // Second or later filename after -lib = object file to add to library
        AddObjectToLibrary(string, string);
        return;
    }
    // libmode = 0: Ordinary input or output file

    if (!InputFile) {
        // Input file not specified yet
        InputFile = string;
    }
    else if (!OutputFile) {
        // Output file not specified yet
        OutputFile = string;
    }
    else {
        // Both input and output files already specified
        err.submit(2001);
    }
}


void CCommandLineInterpreter::InterpretCommandOption(char * string) {
    // Interpret one option from command line
    if (*string <= ' ') {
        err.submit(1001); return;    // Warning: empty option
    }

    // Detect option type
    switch(string[0]) {
    case 'f': case 'F':   // output file format
        if (string[1] == 'd') {
            // -fd == deprecated dump option
            InterpretDumpOption(string+2);  break;
        }
        InterpretOutputTypeOption(string+1);  break;

    case 'v': case 'V':   // verbose/silent
        InterpretVerboseOption(string+1);  break;

    case 'd': case 'D':   // dump option
        InterpretDumpOption(string+1);  break;
        // Debug info option
        //InterpretDebugInfoOption(string+1);  break;

    case 'x': case 'X':   // Exception handler info option
        InterpretExceptionInfoOption(string+1);  break;

    case 'h': case 'H': case '?':  // Help
        ShowHelp = 1;  break;

    case 'e': case 'E':   // Error option
    case 'w': case 'W':   // Warning option
        InterpretErrorOption(string);  break;

    case 'n': case 'N':   // Symbol name change option
    case 'a': case 'A':   // Symbol name alias option
        InterpretSymbolNameChangeOption(string);  break;

    case 'i': case 'I':   // Imagebase
        if ((string[1] | 0x20) == 'm') {
            InterpretImagebaseOption(string);
        }
        break;

    case 'l': case 'L':   // Library option
        InterpretLibraryOption(string);  break;

    case 'c':  // Count instruction codes supported
        // This is an easter egg: You can only get it if you know it's there
        if (strncmp(string,"countinstructions", 17) == 0) {
            CDisassembler::CountInstructions();
            exit(0);
        }

    default:    // Unknown option
        err.submit(1002, string);
    }
}


void CCommandLineInterpreter::InterpretLibraryOption(char * string) {
    // Interpret options for manipulating library/archive files

    // Check for -lib command
    if (stricmp(string, "lib") == 0) {  // Found -lib command
        if (InputFile) {
            libmode = 2;                  // Input file already specified. Remaining file names are object files to add
        }
        else {
            libmode = 1;                  // The rest of the command line must be interpreted as library name and object file names
        }
        return;
    }

    SSymbolChange sym = {0,0,0,0};      // Symbol change record
    int i;                              // Loop counter

    // Check for member name and optional new name in this command
    char * name1 = 0, * name2 = 0, separator;
    if ((string[2] == ':' || string[2] == '|') && string[3]) {
        // name1 found
        separator = string[2];
        name1 = string+3;
        // Search for second separator or end
        name2 = name1 + 1;
        while (name2[0] != 0) {
            if (name2[0] == separator) {
                *name2 = 0;  // Mark end of name1
                if (name2[1]) {
                    // name2 found
                    name2++;     // Name2 starts here
                    break;
                }
            }
            name2++;
        }
        if (name2 == 0 || name2[0] == 0 || name2[0] == separator) {
            // name 2 is blank
            //name2 = name1;
            name2 = 0;
        }
        else {
            // Check if name2 ends with separator
            for (i = 0; i < (int)strlen(name2); i++) {
                if (name2[i] == separator) name2[i] = 0;
            }
        }
    }
    // Check for duplicate name
    if (SymbolIsInList(name1)) {
        // This symbol is already in list
        err.submit(2017, name1);
        return;
    }

    sym.Name1 = name1;     // Store names in symbol change record
    sym.Name2 = name2;     

    switch (string[1]) {
    case 'a': case 'A':      // Add input file to library
        if (name1) {
            AddObjectToLibrary(name1, name2);
        }
        else err.submit(2004, string);
        break;

    case 'x': case 'X':      // Extract member(s) from library
        if (name1) {
            // Extract specified member
            cmd.LibraryOptions = CMDL_LIBRARY_EXTRACTMEM;
            sym.Action  = SYMA_EXTRACT_MEMBER;
            SymbolList.Push(&sym, sizeof(sym));
        }
        else {
            // Extract all members
            cmd.LibraryOptions = CMDL_LIBRARY_EXTRACTALL;
        }
        break;

    case 'd': case 'D':  // Delete member from library
        if (name1) {
            // Delete specified member
            cmd.LibraryOptions = CMDL_LIBRARY_CONVERT;
            sym.Action  = SYMA_DELETE_MEMBER;
            SymbolList.Push(&sym, sizeof(sym));
        }
        else err.submit(2004, string);
        break;

    case 's': case 'S':  // Use short member names for compatibility
        cmd.LibrarySubtype = LIBTYPE_SHORTNAMES;
        break;

    default:
        err.submit(2004, string);  // Unknown option
    }
}


void CCommandLineInterpreter::AddObjectToLibrary(char * filename, char * membername) {
    // Add object file to library 
    if (!filename || !*filename) {          
        err.submit(2004, filename-1);  return;     // Empty string
    }

    if (!membername || !*membername) membername = filename;

    SSymbolChange Sym = {0,0,0,0};                // Symbol change record

    Sym.Name2 = filename;                         // Object file name

    if (!MemberNamesAllocated) {
        // Allocate space for truncated member names
        const int SafetySpace = 1024;

        // Get size of response files
        if (ResponseFiles.GetNumEntries()) {
            MemberNamesAllocated = ResponseFiles[0].GetDataSize() + ResponseFiles[1].GetDataSize();
        }
        // Allocate this size + SafetySpace
        MemberNames.SetSize(MemberNamesAllocated + SafetySpace);

        // Remember allocated buffer size
        MemberNamesAllocated = MemberNames.GetBufferSize();
    }

    // Truncate name and store it in MemberNames
    //uint32_t Name1Offset = MemberNames.PushString(CLibrary::TruncateMemberName(membername));
    uint32_t Name1Offset = MemberNames.PushString(membername);   
    Sym.Name1 = (char*)(MemberNames.Buf() + Name1Offset);
    CLibrary::StripMemberName(Sym.Name1);

    // Note: Sym.Name1 points to allocated memory in violation of good programming practice.
    // Check that it is not reallocated:
    if (MemberNames.GetBufferSize() != MemberNamesAllocated) {
        err.submit(2506); // Cannot reallocate MemberNames because we have pointers to in in SymbolList
        return;
    }

    // Check for duplicate name
    if (SymbolIsInList(Sym.Name1)) {
        // This symbol is already in list
        err.submit(2017, Sym.Name1);
        return;
    }

    // Store options
    cmd.LibraryOptions |= CMDL_LIBRARY_ADDMEMBER;
    Sym.Action  = SYMA_ADD_MEMBER;

    // Store SYMA_ADD_MEMBER record in symbol list
    SymbolList.Push(&Sym, sizeof(Sym));
}


void CCommandLineInterpreter::InterpretOutputTypeOption(char * string) {
    // Interpret output file format option from command line

    int opt;
    for (opt = 0; opt < TableSize(TypeOptionNames); opt++) {
        int len = (int)strlen(TypeOptionNames[opt].b);
        if (strncmp(string, TypeOptionNames[opt].b, len) == 0) {
            // Match found
            if (OutputType)  err.submit(2003, string);  // More than one output type specified
            if (DumpOptions) err.submit(2007);          // Both dump and convert specified

            // Save desired output type
            OutputType = TypeOptionNames[opt].a;

            // Check if name is followed by a word size
            int wordsize = 0;
            if (string[len]) wordsize = atoi(string+len);
            switch (wordsize) {
            case 0:  // No word size specified
                break;

            case 32: case 64:  // Valid word size
                DesiredWordSize = wordsize;
                break;

            default:  // Illegal word size
                err.submit(2002, wordsize);
            }
            break;   // Finished searching
        }
    }

    // Check if found
    if (opt >= TableSize(TypeOptionNames)) err.submit(2004, string-1);

    if (OutputType == CMDL_OUTPUT_MASM) {
        // Get subtype
        for (opt = 0; opt < TableSize(SubtypeNames); opt++) {
            int len = (int)strlen(SubtypeNames[opt].b);
            if (strncmp(string, SubtypeNames[opt].b, len) == 0) {
                // Match found
                SubType = SubtypeNames[opt].a;  break;
            }
        }
    }
}


void CCommandLineInterpreter::InterpretVerboseOption(char * string) {
    // Interpret silent/verbose option from command line
    Verbose = atoi(string);
}


void CCommandLineInterpreter::InterpretDumpOption(char * string) {
    // Interpret dump option from command line
    if (OutputType || DumpOptions) err.submit(2007);          // Both dump and convert specified

    char * s1 = string;
    while (*s1) {
        switch (*(s1++)) {
        case 'f': case 'F':  // dump file header
            DumpOptions |= DUMP_FILEHDR;  break;
        case 'h': case 'H':  // dump section headers
            DumpOptions |= DUMP_SECTHDR;  break;
        case 's': case 'S':  // dump symbol table
            DumpOptions |= DUMP_SYMTAB;  break;
        case 'r': case 'R':  // dump relocations
            DumpOptions |= DUMP_RELTAB;  break;
        case 'n': case 'N':  // dump string table
            DumpOptions |= DUMP_STRINGTB;  break;
        case 'c': case 'C':  // dump comment records (currently only for OMF)
            DumpOptions |= DUMP_COMMENT;  break;         
        default:
            err.submit(2004, string-1);  // Unknown option
        }
    }
    if (DumpOptions == 0) DumpOptions = DUMP_FILEHDR;
    OutputType = CMDL_OUTPUT_DUMP;
    if (OutputType && OutputType != CMDL_OUTPUT_DUMP) err.submit(2007); // Both dump and convert specified
    OutputType = CMDL_OUTPUT_DUMP;
}


void CCommandLineInterpreter::InterpretDebugInfoOption(char * string) {
    // Interpret debug info option from command line
    if (strlen(string) > 1) err.submit(2004, string-1);  // Unknown option
    switch (*string) {
    case 's': case 'S': case 'r': case 'R':  // Strip (remove)
        DebugInfo = CMDL_DEBUG_STRIP;  break;
    case 'p': case 'P':                      // Preserve
        DebugInfo = CMDL_DEBUG_PRESERVE;  break;
    case 'l': case 'L':                      // (Not supported)
        DebugInfo = CMDL_DEBUG_LINNUM;  break;
    case 'c': case 'C':                      // (Not supported)
        DebugInfo = CMDL_DEBUG_SYMBOLS;  break;
    default:
        err.submit(2004, string-1);  // Unknown option
    }
}


void CCommandLineInterpreter::InterpretExceptionInfoOption(char * string) {
    // Interpret exception handler info option from command line
    if (strlen(string) > 1) err.submit(2004, string-1);  // Unknown option
    switch (*string) {
    case 's': case 'S': case 'r': case 'R':  // Strip (remove)
        ExeptionInfo = CMDL_EXCEPTION_STRIP;  break;
    case 'p': case 'P':                      // Preserve
        ExeptionInfo = CMDL_EXCEPTION_PRESERVE;  break;
    default:
        err.submit(2004, string-1);  // Unknown option
    }
}


void CCommandLineInterpreter::InterpretErrorOption(char * string) {
    // Interpret warning/error option from command line
    if (strlen(string) < 3) {
        err.submit(2004, string); return; // Unknown option
    } 
    int newstatus;   // New status for this error number

    switch (string[1]) {
    case 'd': case 'D':  // Disable
        newstatus = 0;  break;

    case 'w': case 'W':  // Treat as warning
        newstatus = 1;  break;

    case 'e': case 'E':  // Treat as error
        newstatus = 2;  break;

    default:
        err.submit(2004, string);  // Unknown option
        return;
    }
    if (string[2] == 'x' || string[2] == 'X') {
        // Apply new status to all non-fatal messages
        for (SErrorText * ep = ErrorTexts; ep->Status < 9; ep++) {
            ep->Status = newstatus;  // Change status of all errors
        }
    }
    else {
        int ErrNum = atoi(string+2);
        if (ErrNum == 0 && string[2] != '0') {
            err.submit(2004, string);  return; // Unknown option
        }
        // Search for this error number
        SErrorText * ep = err.FindError(ErrNum);
        if (ep->Status & 0x100) {
            // Error number not found
            err.submit(1003, ErrNum);  return; // Unknown error number
        }
        // Change status of this error
        ep->Status = newstatus;
    }
}

void CCommandLineInterpreter::InterpretSymbolNameChangeOption(char * string) {
    // Interpret various options for changing symbol names
    SSymbolChange sym = {0,0,0,0};   // Symbol change record
    string[0] |= 0x20;  // change first letter to lower case

    // Check for symbol names in this command
    char * name1 = 0, * name2 = 0;
    if (string[2] == ':' && string[3]) {
        // name1 found
        name1 = string+3;
        // Search for second ':' or end
        name2 = name1 + 1;
        while (name2[0] != 0) {
            if (name2[0] == ':') {
                *name2 = 0;  // Mark end of name1
                if (name2[1]) {
                    // name2 found
                    name2++;     // Name2 starts here
                    break;
                }
            }
            name2++;
        }
        if (name2 && name2[0]) {
            // name2 found. check if it ends with ':'
            for (uint32_t i = 0; i < (uint32_t)strlen(name2); i++) {
                if (name2[i] == ':') name2[i] = 0;
            }
        }
        if (name2[0] == 0) name2 = 0;
    }
    // Check for duplicate name
    if (name1 && SymbolIsInList(name1)) {
        // This symbol is already in list
        err.submit(2015, name1);
        return;
    }

    switch (string[1]) {
    case 'u': case 'U':  // underscore option
        switch (string[2]) {
        case 0:
            Underscore = CMDL_UNDERSCORE_CHANGE; 
            if (string[0] == 'a') Underscore |= CMDL_KEEP_ALIAS;
            break;
        case '+': case 'a': case 'A': 
            Underscore = CMDL_UNDERSCORE_ADD; 
            if (string[0] == 'a') Underscore |= CMDL_KEEP_ALIAS;
            break;
        case '-': case 'r': case 'R': 
            Underscore = CMDL_UNDERSCORE_REMOVE; 
            if (string[0] == 'a') Underscore |= CMDL_KEEP_ALIAS;
            break;
        default:
            err.submit(2004, string);  // Unknown option
        }
        break;

    case 'd': case 'D':  // section name dot option
        SegmentDot = CMDL_SECTIONDOT_CHANGE; 
        break;

    case 'r': case 'R':  // name replace option
        if (name1 == 0 || name2 == 0 || *name1 == 0 || *name2 == 0) {
            err.submit(2008, string); return;
        }
        sym.Name1 = name1;
        sym.Name2 = name2;
        sym.Action  = SYMA_CHANGE_NAME;
        if (string[0] == 'a') sym.Action |= SYMA_ALIAS;
        SymbolList.Push(&sym, sizeof(sym));  SymbolChangeEntries++;
        break;

    case 'p': case 'P':  // prefix replace option
        if (name1 == 0 || *name1 == 0) {
            err.submit(2008, string); return;
        }
        if (name2 == 0) name2 = (char*)"";
        sym.Name1 = name1;
        sym.Name2 = name2;
        sym.Action  = SYMA_CHANGE_PREFIX;
        if (string[0] == 'a') sym.Action |= SYMA_ALIAS;
        SymbolList.Push(&sym, sizeof(sym));  SymbolChangeEntries++;
        break;

    case 's': case 'S':  // suffix replace option
        if (name1 == 0 || *name1 == 0) {
            err.submit(2008, string); return;
        }
        if (name2 == 0) name2 = (char*)"";
        sym.Name1 = name1;
        sym.Name2 = name2;
        sym.Action  = SYMA_CHANGE_SUFFIX;
        if (string[0] == 'a') sym.Action |= SYMA_ALIAS;
        SymbolList.Push(&sym, sizeof(sym));  SymbolChangeEntries++;
        break;

    case 'w': case 'W':  // Weaken symbol
        if (name1 == 0 || *name1 == 0 || name2) {
            err.submit(2009, string); return;
        }
        sym.Name1 = name1;
        sym.Action  = SYMA_MAKE_WEAK;
        SymbolList.Push(&sym, sizeof(sym));  SymbolChangeEntries++;
        break;

    case 'l': case 'L':  // Make symbol local or hidden
        if (name1 == 0 || *name1 == 0 || name2) {
            err.submit(2009, string); return;
        }
        sym.Name1 = name1;
        sym.Action  = SYMA_MAKE_LOCAL;
        SymbolList.Push(&sym, sizeof(sym));  SymbolChangeEntries++;
        break;

    default:
        err.submit(2004, string);  // Unknown option
    }
}

void CCommandLineInterpreter::InterpretImagebaseOption(char * string) {
    // Interpret image base option
    char * p = strchr(string, '=');
    if ((strnicmp(string, "imagebase", 9) && strnicmp(string, "image_base", 10)) || !p) {
        // Unknown option
        err.submit(1002, string);
        return;
    }
    if (ImageBase) err.submit(2330); // Imagebase specified more than once

    p++;  // point to number following '='
    // Loop through string to interpret hexadecimal number
    while (*p) {
        char letter = *p | 0x20; // lower case letter
        if (*p >= '0' && *p <= '9') {
            // 0 - 9 hexadecimal digit
            ImageBase = (ImageBase << 4) + *p - '0';
        }
        else if (letter >= 'a' && letter <= 'f') {
            // A - F hexadecimal digit
            ImageBase = (ImageBase << 4) + letter - 'a' + 10;
        }
        else if (letter == 'h') {
            // Hexadecimal number may end with 'H'
            break;
        }
        else if (letter == 'x' || letter == ' ') {
            // Hexadecimal number may begin with 0x
            if (ImageBase) {
                // 'x' preceded by number other than 0
                err.submit(1002, string); break;
            }
        }
        else {
            // Any other character not allowed
            err.submit(1002, string); break;
        }
        // next character
        p++;
    }
    if (ImageBase & 0xFFF) {
        // Must be divisible by page size
        err.submit(2331, string);
    }
    if ((int32_t)ImageBase <= 0) {
        // Cannot be zero or > 2^31
        err.submit(2332, string);
    }
}


SSymbolChange const * CCommandLineInterpreter::GetMemberToAdd() {
    // Get names of object files to add to library
    // replaced will be set to 1 if a member with the same name is replaced

    // Search through SymbolList, continuing from last CurrentSymbol
    while (CurrentSymbol < SymbolList.GetDataSize()) {
        // Get pointer to current symbol record
        SSymbolChange * Sym = (SSymbolChange *)(SymbolList.Buf() + CurrentSymbol);
        // Increment pointer
        CurrentSymbol += sizeof(SSymbolChange);
        // Check record type
        if (Sym->Action == SYMA_ADD_MEMBER) {
            // Name found
            return Sym;
        }
    }
    // No more names found
    return 0;
}


void CCommandLineInterpreter::CheckExtractSuccess() {
    // Check if library members to extract were found

    // Search through SymbolList for extract records
    for (uint32_t i = 0; i < SymbolList.GetDataSize(); i += sizeof(SSymbolChange)) {
        SSymbolChange * Sym = (SSymbolChange *)(SymbolList.Buf() + i);
        if (Sym->Action == SYMA_EXTRACT_MEMBER && Sym->Done == 0) {
            // Member has not been extracted
            err.submit(1104, Sym->Name1);
        }
    }
}


void CCommandLineInterpreter::CheckSymbolModifySuccess() {
    // Check if symbols to modify were found

    // Search through SymbolList for symbol change records
    for (uint32_t i = 0; i < SymbolList.GetDataSize(); i += sizeof(SSymbolChange)) {
        SSymbolChange * Sym = (SSymbolChange *)(SymbolList.Buf() + i);
        if (Sym->Action >= SYMA_MAKE_WEAK && Sym->Action < SYMA_ADD_MEMBER && Sym->Done == 0) {
            // Member has not been extracted
            err.submit(1106, Sym->Name1);
        }
        if (Sym->Action == SYMA_DELETE_MEMBER && Sym->Done == 0) {
            // Member has not been extracted
            err.submit(1105, Sym->Name1);
        }
    }
}


int CCommandLineInterpreter::SymbolIsInList(char const * name) {
    // Check if name is already in symbol list
    int isym, nsym = SymbolList.GetNumEntries();
    SSymbolChange * List = (SSymbolChange *)SymbolList.Buf(), * psym;

    // Search for name in list of names specified by user on command line
    for (isym = 0, psym = List; isym < nsym; isym++, psym++) {
        if (strcmp(name, psym->Name1) == 0) return 1;  // Matching name found
    }
    return 0;
}


int CCommandLineInterpreter::SymbolChange(char const * oldname, char const ** newname, int symtype) {
    // Check if symbol has to be changed
    int action = 0, i, isym;
    int nsym = SymbolList.GetNumEntries();
    if (oldname == 0) return SYMA_NOCHANGE;
    if (newname) *newname = 0;

    // Convert standard names if type conversion
    if (cmd.InputType != cmd.OutputType 
        && uint32_t(cmd.InputType) <= MaxType && uint32_t(cmd.OutputType) <= MaxType) {
            if (DesiredWordSize == 32) {
                // Look for standard names to translate, 32-bit
                for (i = 0; i < NumStandardNames; i++) {
                    if (strcmp(oldname, StandardNames32[i][cmd.InputType]) == 0) {
                        // Match found
                        *newname = StandardNames32[i][cmd.OutputType];
                        CountSymbolNameChanges++;
                        return SYMA_CHANGE_NAME; // Change name of symbol
                    }
                }
            }
            else {
                // Look for standard names to translate, 64-bit
                for (i = 0; i < NumStandardNames; i++) {
                    if (strcmp(oldname, StandardNames64[i][cmd.InputType]) == 0) {
                        // Match found
                        *newname = StandardNames64[i][cmd.OutputType];
                        CountSymbolNameChanges++;
                        return SYMA_CHANGE_NAME; // Change name of symbol
                    }
                }
            }
    }

    // See if there are other conversions to do
    if (Underscore == 0 && SegmentDot == 0 && nsym == 0) return SYMA_NOCHANGE;  // Nothing to do
    if (oldname == 0 || *oldname == 0) return SYMA_NOCHANGE;                    // No name

    static char NameBuffer[MAXSYMBOLLENGTH];

    SSymbolChange * List = (SSymbolChange *)SymbolList.Buf(), * psym;
    // search for name in list of names specified by user on command line
    for (isym = 0, psym = List; isym < nsym; isym++, psym++) {
        if (strcmp(oldname, psym->Name1) == 0) break;  // Matching name found
        int n1len = (int)strlen(psym->Name1); // Length of string to search for
        int onlen = (int)strlen(oldname);     // Length of string to match
        if ((psym->Action&~SYMA_ALIAS) == SYMA_CHANGE_PREFIX && strncmp(oldname, psym->Name1, n1len)==0) break; // matching prefix found
        if ((psym->Action&~SYMA_ALIAS) == SYMA_CHANGE_SUFFIX && strcmp(oldname+onlen-n1len, psym->Name1)==0) break; // matching suffix found
    }
    if (isym < nsym) {
        // A matching name was found.
        action = psym->Action;
        // Whatever action is specified here is overriding any general option
        // Statistics counting
        switch (action & ~SYMA_ALIAS) {

        case SYMA_MAKE_WEAK: // Make public symbol weak
            if (symtype == SYMT_PUBLIC) {
                CountSymbolsWeakened++;  psym->Done++;
            }
            else { // only public symbols can be weakened
                err.submit(1020, oldname); // cannot make weak
                action = SYMA_NOCHANGE;
            }
            break;

        case SYMA_MAKE_LOCAL: // Hide public or external symbol
            if (symtype == SYMT_PUBLIC || symtype == SYMT_EXTERNAL) {
                CountSymbolsMadeLocal++;  psym->Done++;
                if (symtype == SYMT_EXTERNAL) err.submit(1023, oldname);
            }
            else { // only public and external symbols can be made local
                err.submit(1021, oldname); // cannot make local
                action = SYMA_NOCHANGE;
            }
            break;

        case SYMA_CHANGE_NAME: // Change name of symbol or segment or library member
            CountSymbolNameChanges++;  psym->Done++;  
            *newname = psym->Name2;
            break;

        case SYMA_CHANGE_PREFIX: // Change beginning of symbol name
            if (symtype == SYMT_PUBLIC || symtype == SYMT_EXTERNAL || symtype == SYMT_LOCAL || symtype == SYMT_SECTION) {
                if (strlen(oldname) - strlen(psym->Name1) + strlen(psym->Name2) >= MAXSYMBOLLENGTH) {
                    err.submit(2202, oldname);  // Name too long
                    action = SYMA_NOCHANGE;  break;
                }
                strcpy(NameBuffer, psym->Name2);
                strcpy(NameBuffer + strlen(psym->Name2), oldname + strlen(psym->Name1));
                action = SYMA_CHANGE_NAME;
                *newname = NameBuffer;
                CountSymbolNameChanges++;  psym->Done++;
            }
            else { // only symbols and segments can change prefix
                err.submit(1024, oldname);
                action = SYMA_NOCHANGE;
            }
            break;

        case SYMA_CHANGE_SUFFIX: // Change end of symbol name
            if (symtype == SYMT_PUBLIC || symtype == SYMT_EXTERNAL || symtype == SYMT_LOCAL || symtype == SYMT_SECTION) {
                if (strlen(oldname) - strlen(psym->Name1) + strlen(psym->Name2) >= MAXSYMBOLLENGTH) {
                    err.submit(2202, oldname);  // Name too long
                    action = SYMA_NOCHANGE;  break;
                }
                strcpy(NameBuffer, oldname);
                strcpy(NameBuffer + strlen(oldname) - strlen(psym->Name1), psym->Name2);
                action = SYMA_CHANGE_NAME;
                *newname = NameBuffer;
                CountSymbolNameChanges++;  psym->Done++;
            }
            else { // only symbols and segments can change prefix
                err.submit(1024, oldname);
                action = SYMA_NOCHANGE;
            }
            break;

        case SYMA_EXTRACT_MEMBER:
            *newname = psym->Name2;
            // continue in next case
        case SYMA_DELETE_MEMBER: case SYMA_ADD_MEMBER:
            if (symtype == SYMT_LIBRARYMEMBER) {
                // Change to library member
                psym->Done++;
            }
            else {
                // Ignore action for symbols that have the same name as a library member
                action = SYMA_NOCHANGE;
            }
        }

        if (action && (psym->Action & SYMA_ALIAS)) {
            // Keep old name as alias
            if (symtype == SYMT_PUBLIC) {
                CountSymbolNameAliases++;  psym->Done++;
                action = SYMA_ALIAS;
            }
            else { // only public symbols can have aliases
                CountSymbolNameChanges--;
                err.submit(1022, oldname); // cannot make alias
                action = SYMA_NOCHANGE;
            }
        }

        // Action to take
        return action;
    }

    // Not found in list. Check for section options
    if (symtype == SYMT_SECTION) {
        if (!strncmp(oldname, ".rela", 5)) {
            // ELF relocation section must have same name change as mother section
            const char * name2;
            int action2 = SymbolChange(oldname+5, &name2, symtype);
            if (action2 == SYMA_CHANGE_NAME && strlen(name2) + 6 < MAXSYMBOLLENGTH) {
                sprintf(NameBuffer, ".rela%s", name2);
                *newname = NameBuffer;
                return action2;
            }
        }
        if (!strncmp(oldname, ".rel", 4)) {
            // ELF relocation section must have same name change as mother section
            const char * name2;
            int action2 = SymbolChange(oldname+4, &name2, symtype);
            if (action2 == SYMA_CHANGE_NAME && strlen(name2) + 5 < MAXSYMBOLLENGTH) {
                sprintf(NameBuffer, ".rel%s", name2);
                *newname = NameBuffer;
                return action2;
            }
        }
        if (SegmentDot) {
            // Change section name

            if (SegmentDot == CMDL_SECTIONDOT_U2DOT && oldname[0] == '_') {
                // replace '_' by '.'
                strncpy(NameBuffer, oldname, MAXSYMBOLLENGTH-1);
                NameBuffer[MAXSYMBOLLENGTH-1] = 0;  // Terminate string
                NameBuffer[0] = '.';
                *newname = NameBuffer;
                CountSectionDotConversions++;
                return SYMA_CHANGE_NAME;
            }
            if (SegmentDot == CMDL_SECTIONDOT_DOT2U && oldname[0] == '.') {
                // replace '.' by '_'
                // Note: Microsoft and Intel compilers have . on standard names
                // and _ on nonstandard names in COFF files
                // Borland requires _ on all segment names in OMF files
                /* 
                // Standard section names that should not be changed
                static char const * StandardSectionNames[] = {
                ".text", ".data", ".bss", ".comment", ".lib"
                };
                for (uint32_t i = 0; i < sizeof(StandardSectionNames)/sizeof(StandardSectionNames[0]); i++) {
                if (stricmp(oldname,StandardSectionNames[i]) == 0) {
                // Standard name. Don't change
                return SYMA_NOCHANGE;
                }
                }*/
                strncpy(NameBuffer, oldname, MAXSYMBOLLENGTH-1);
                NameBuffer[MAXSYMBOLLENGTH-1] = 0;  // Terminate string
                NameBuffer[0] = '_';
                *newname = NameBuffer;
                CountSectionDotConversions++;
                return SYMA_CHANGE_NAME;
            }
        }
    }

    // Check for underscore options
    if ((Underscore & 0x0F) == CMDL_UNDERSCORE_REMOVE && oldname[0] == '_') {
        // Remove underscore
        if ((Underscore & CMDL_KEEP_ALIAS) && symtype == SYMT_PUBLIC) {
            // Alias only applicable to public symbols
            // Make alias without underscore
            *newname = oldname + 1;
            CountUnderscoreConversions++;  CountSymbolNameAliases++;
            return SYMA_ALIAS;
        }
        // Change name applicable to public and external symbols
        if (symtype == SYMT_PUBLIC || symtype == SYMT_EXTERNAL) {
            // Make new name without underscore
            *newname = oldname + 1;
            CountUnderscoreConversions++;
            return SYMA_CHANGE_NAME;
        }
    }
    if ((Underscore & 0x0F) == CMDL_UNDERSCORE_ADD) {
        // Add underscore even if it already has one
        if ((Underscore & CMDL_KEEP_ALIAS) && symtype == SYMT_PUBLIC) {
            // Alias only applicable to public symbols
            // Make alias with underscore
            strncpy(NameBuffer+1, oldname, MAXSYMBOLLENGTH-2);
            NameBuffer[MAXSYMBOLLENGTH-1] = 0;  // Terminate string
            NameBuffer[0] = '_';
            *newname = NameBuffer;
            CountUnderscoreConversions++;  CountSymbolNameAliases++;
            return SYMA_ALIAS;
        }
        // Change name applicable to public and external symbols
        if (symtype == SYMT_PUBLIC || symtype == SYMT_EXTERNAL) {
            // Make new name with underscore
            strncpy(NameBuffer+1, oldname, MAXSYMBOLLENGTH-2);
            NameBuffer[MAXSYMBOLLENGTH-1] = 0;  // Terminate string
            NameBuffer[0] = '_';
            *newname = NameBuffer;
            CountUnderscoreConversions++;
            return SYMA_CHANGE_NAME;
        }
    }
    return SYMA_NOCHANGE;
}


int CCommandLineInterpreter::SymbolChangesRequested() {
    // Any kind of symbol change requested on command line
    return (Underscore != 0) 
        | (SegmentDot != 0) << 1 
        | (SymbolChangeEntries != 0) << 2;
}


void CCommandLineInterpreter::CountDebugRemoved() {
    // Count debug sections removed
    CountDebugSectionsRemoved++;
}


void CCommandLineInterpreter::CountExceptionRemoved() {
    // Count exception handler sections removed
    CountExceptionSectionsRemoved++;
}


void CCommandLineInterpreter::CountSymbolsHidden() {
    // Count unused external references hidden
    CountUnusedSymbolsHidden++;
}


void CCommandLineInterpreter::ReportStatistics() {
    // Report statistics about name changes etc.
    if (DebugInfo == CMDL_DEBUG_STRIP || ExeptionInfo == CMDL_EXCEPTION_STRIP 
        || Underscore || SegmentDot || SymbolList.GetNumEntries()) {
            printf ("\n");
    }
    if (DebugInfo == CMDL_DEBUG_STRIP) {
        printf ("\n%3i Debug sections removed", CountDebugSectionsRemoved);
    }
    if (ExeptionInfo == CMDL_EXCEPTION_STRIP) {
        printf ("\n%3i Exception sections removed", CountExceptionSectionsRemoved);
    }
    if ((DebugInfo == CMDL_DEBUG_STRIP || ExeptionInfo == CMDL_EXCEPTION_STRIP) 
        && CountUnusedSymbolsHidden) {
            printf ("\n%3i Unused external symbol references hidden", CountUnusedSymbolsHidden);
    }

    if (Underscore || SegmentDot || SymbolList.GetNumEntries()) {
        if (CountUnderscoreConversions || Underscore) {
            printf ("\n%3i Changes in leading underscores on symbol names", CountUnderscoreConversions);
        }
        if (CountSectionDotConversions || SegmentDot) {
            printf ("\n%3i Changes in leading characters on section names", CountSectionDotConversions);
        }
        if (CountSymbolNameChanges) {
            printf ("\n%3i Symbol names changed", CountSymbolNameChanges);
        }
        if (CountSymbolNameAliases) {
            printf ("\n%3i Public symbol names aliased", CountSymbolNameAliases);
        }
        if (CountSymbolsWeakened) {
            printf ("\n%3i Public symbol names made weak", CountSymbolsWeakened);
        }
        if (CountSymbolsMadeLocal) {
            printf ("\n%3i Public or external symbol names made local", CountSymbolsMadeLocal);
        }
        if (SymbolChangeEntries && !CountSymbolNameChanges && !CountSymbolNameAliases && !CountSymbolsWeakened && !CountSymbolsMadeLocal) {
            printf ("\n    No symbols to change were found");
        }
    }
}


void CCommandLineInterpreter::Help() {
    // Print help message
    printf("\nObject file converter version %.2f for x86 and x86-64 platforms.", OBJCONV_VERSION);
    printf("\nCopyright (c) 2025 by Agner Fog. Gnu General Public License.");
    printf("\n\nUsage: objconv options inputfile [outputfile]");
    printf("\n\nOptions:");
    printf("\n-fXXX[SS]  Output file format XXX, word size SS. Supported formats:");
    printf("\n           PE, COFF, ELF, OMF, MACHO\n");
    printf("\n-fasm      Disassemble file (-fmasm, -fnasm, -fyasm, -fgasm)\n");
    printf("\n-dXXX      Dump file contents to console.");
    printf("\n           Values of XXX (can be combined):");
    printf("\n           f: File header, h: section Headers, s: Symbol table,");
    printf("\n           r: Relocation table, n: string table.\n");

    printf("\n-nu        change symbol Name Underscores to the default for the target format.");
    printf("\n-nu-       remove Underscores from symbol Names.");
    printf("\n-nu+       add Underscores to symbol Names.");
    printf("\n-nd        replace Dot/underscore in section names.");
    printf("\n-nr:N1:N2  Replace symbol Name N1 with N2.");
    printf("\n-np:N1:N2  Replace symbol Prefix N1 with N2.");
    printf("\n-ns:N1:N2  Replace symbol Suffix N1 with N2.");
    printf("\n-ar:N1:N2  make Alias N2 for existing public name N1.");
    printf("\n-ap:N1:N2  Replace symbol Prefix and keep old name as alias.");
    printf("\n-as:N1:N2  Replace symbol Suffix and keep old name as alias.");
    printf("\n-nw:N1     make public symbol Name N1 Weak (ELF and MAC64 only).");
    printf("\n-nl:N1     make public symbol Name N1 Local (invisible).\n");
    //printf("\n-ds        Strip Debug info.");    // default if input and output are different formats
    //printf("\n-dp        Preserve Debug info, even if it is incompatible.");
    printf("\n-xs        Strip exception handling info and other incompatible info.");  // default if input and output are different formats. Hides unused symbols
    printf("\n-xp        Preserve exception handling info and other incompatible info.\n");

    printf("\n-lx        eXtract all members from Library.");
    printf("\n-lx:N1:N2  eXtract member N1 from Library to file N2.");
    printf("\n-ld:N1     Delete member N1 from Library.");
    printf("\n-la:N1:N2  Add object file N1 to Library as member N2.");
    printf("\n           Alternative: -lib LIBRARYNAME OBJECTFILENAMES.\n");

    printf("\n-vN        Verbose options. Values of N:");
    printf("\n           0: Silent, 1: Print file names and types, 2: Tell about conversions.");

    printf("\n-wdNNN     Disable Warning NNN.");
    printf("\n-weNNN     treat Warning NNN as Error. -wex: treat all warnings as errors.");
    printf("\n-edNNN     Disable Error number NNN.");
    printf("\n-ewNNN     treat Error number NNN as Warning.\n");

    printf("\n-h         Print this help screen.\n");

    printf("\n@RFILE     Read additional options from response file RFILE.\n");
    printf("\n\nExample:");
    printf("\nobjconv -felf32 -nu filename.obj filename.o\n\n");
}