- display_version();
- display_help();
- return 1;
- case 'a':
- case 'A': // Set absolute linking on
- if (aflag)
- warn('a', 1);
-
- if (i + 2 >= argc)
- {
- printf("Not enough arguments to -a\n");
- return 1;
- }
-
- aflag = 1; // Set abs link flag
- // Segment order is TEXT, DATA, BSS
- // Text segment can be 'r', 'x' or a value
- ttype = 0;
-
- if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
- {
- ttype = -1; // TEXT segment is relocatable
- }
- else if ((*argv[i] == 'x' || *argv[i] == 'X'))
- {
- printf("Error in text-segment address: cannot be contiguous\n");
- return 1;
- }
- else if ((ttype = 0), getval(argv[i], &tval))
- {
- printf("Error in text-segment address: %s is not 'r', 'x' or an address.", argv[i]);
- return 1;
- }
-
- i++;
- // Data segment can be 'r', 'x' or a value
- dtype = 0;
-
- if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
- {
- dtype = -1; // DATA segment is relocatable
- }
- else if ((*argv[i] == 'x' || *argv[i] == 'X'))
- {
- dtype = -2; // DATA follows TEXT
- }
- else if ((dtype = 0), getval(argv[i],&dval))
- {
- printf("Error in data-segment address: %s is not 'r', 'x' or an address.", argv[i]);
- return 1;
- }
-
- i++;
- btype = 0;
-
- // BSS segment can be 'r', 'x' or a value
- if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
- {
- btype = -1; // BSS segment is relocatable
- }
- else if ((*argv[i] == 'x' || *argv[i] == 'X'))
- {
- btype = -3; // BSS follows DATA
- }
- else if ((btype = 0), getval(argv[i],&bval))
- {
- printf("Error in bss-segment address: %s is not 'r', 'x[td]', or an address.", argv[i]);
- return 1;
- }
-
- i++;
- break;
- case 'b':
- case 'B': // Don't remove muliply defined locals
- if (bflag)
- warn('b', 1);
-
- bflag = 1;
- break;
- case 'c':
- case 'C': // Process a command file
- if (i == argc)
- {
- printf("Not enough arguments to -c\n");
- return 1;
- }
-
- if (docmdfile(argv[i++]))
- {
- return 1;
- }
-
- break;
- case 'd':
- case 'D': // Wait for "return" before exiting
- if (dflag)
- warn('d', 0);
-
- dflag = 1;
- waitflag = 1;
- break;
- case 'e':
- case 'E': // Output COFF (absolute only)
- cflag = 1;
- break;
- case 'g':
- case 'G': // Output source level debugging
- printf("\'g\' flag not currently implemented\n");
- gflag = 0;
- /*
- if (gflag) warn('g', 1);
- gflag = 1;
- */
- break;
- case 'i':
- case 'I': // Include binary file
- if (i + 2 > argc)
- {
- printf("Not enough arguments to -i\n");
- return 1;
- }
-
- ifile = argv[i++];
- isym = argv[i++];
-
- if ((argv[i-3][2] == 'i') || (argv[i-3][2] == 'I'))
- { // handle -ii (No truncation)
- if (!cflag)
- printf("warning: (-ii) COFF format output not specified\n");
- }
- else
- { // handle -i (Truncation)
- if (strlen(isym) > 7)
- isym[7] = '\0';
- }
-
- // Place include files in the DATA segment only
- if (dofile(ifile, DSTSEG_D, isym))
- return 1;
-
- break;
- case 'l':
- case 'L': // Add local symbols
- if (lflag)
- warn('l', 1);
-
- lflag = 1;
- break;
- case 'm':
- case 'M': // Produce load symbol map
- if (mflag)
- warn('m', 1);
-
- mflag = 1;
- break;
- case 'n':
- case 'N': // Output no header to .abs file
- if (noheaderflag)
- warn('n', 1);
-
- noheaderflag = 1;
- break;
- case 'o':
- case 'O': // Specify an output file
- if (oflag)
- warn('o', 1);
-
- oflag = 1;
-
- if (i >= argc)
- {
- printf("No output filename following -o switch\n");
- return 1;
- }
-
- if (strlen(argv[i]) > FARGSIZE - 5)
- {
- printf("Output file name too long (sorry!)\n");
- return 1;
- }
-
- strcpy(ofile, argv[i++]);
- break;
- case 'r':
- case 'R': // Section alignment size
- if (rflag)
- warn('r', 1);
-
- rflag = 1;
-
- switch (argv[i-1][2])
- {
- case 'w': case 'W': secalign = 1; break; // Word alignment
- case 'l': case 'L': secalign = 3; break; // Long alignment
- case 'p': case 'P': secalign = 7; break; // Phrase alignment
- case 'd': case 'D': secalign = 15; break; // Double phrase alignment
- case 'q': case 'Q': secalign = 31; break; // Quad phrase alignment
- default: secalign = 7; break; // Default phrase alignment
- }
-
- break;
- case 's':
- case 'S': // Output only global symbols
- if (sflag)
- warn('s', 1);
-
- sflag = 1;
- break;
- case 'v':
- case 'V': // Verbose information
- if (!vflag && !versflag)
- {
- display_version();
- }
-
- vflag++;
- break;
- case 'z':
- case 'Z': // Suppress banner flag
- if (zflag)
- warn('z', 1);
-
- zflag = 1;
- break;
- default:
- printf("unknown option argument `%c'\n", c);
- return 1;
- }
- }
- else
- { // Not a switch, then process as a file
- if (dofile(argv[i++], 0, NULL))
- return 1;
- }
-
- }
-
- if (!oflag && vflag)
- {
- strcpy(ofile, "output");
- printf("Output file is %s[.ext]\n", ofile);
- }
-
- if (oflag && vflag)
- printf("Output file is %s\n", ofile);
-
- if (sflag)
- lflag = 0;
-
- return 0; // No problems encountered
+ ShowVersion();
+ ShowHelp();
+ return 1;
+ case 'a':
+ case 'A': // Set absolute linking on
+ if (aflag)
+ warn('a', 1);
+
+ if (i + 2 >= argc)
+ {
+ printf("Not enough arguments to -a\n");
+ return 1;
+ }
+
+ aflag = 1; // Set abs link flag
+
+ // Segment order is TEXT, DATA, BSS
+ // Text segment can be 'r' or a value
+ if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
+ {
+ ttype = -1; // TEXT segment is relocatable
+ }
+ else if ((*argv[i] == 'x' || *argv[i] == 'X'))
+ {
+ printf("Error in text-segment address: cannot be contiguous\n");
+ return 1;
+ }
+ else if (GetHexValue(argv[i], &tval))
+ {
+ printf("Error in text-segment address: %s is not 'r' or an address.", argv[i]);
+ return 1;
+ }
+
+ i++;
+
+ // Data segment can be 'r', 'x' or a value
+ if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
+ {
+ dtype = -1; // DATA segment is relocatable
+ }
+ else if ((*argv[i] == 'x' || *argv[i] == 'X'))
+ {
+ dtype = -2; // DATA follows TEXT
+ }
+ else if (GetHexValue(argv[i], &dval))
+ {
+ printf("Error in data-segment address: %s is not 'r', 'x' or an address.", argv[i]);
+ return 1;
+ }
+
+ i++;
+
+ // BSS segment can be 'r', 'x' or a value
+ if ((*argv[i] == 'r' || *argv[i] == 'R') && !argv[i][1])
+ {
+ btype = -1; // BSS segment is relocatable
+ }
+ else if ((*argv[i] == 'x' || *argv[i] == 'X'))
+ {
+ switch (argv[i][1])
+ {
+ case 'd': case 'D': case '\0':
+ btype = -3; // BSS follows DATA
+ break;
+
+ case 't': case 'T':
+ btype = -2; // BSS follows TEXT
+ if (btype == dtype)
+ {
+ printf("Error in bss-segment address: data-segment also follows text\n");
+ return 1;
+ }
+ break;
+
+ default:
+ btype = -4; // Error
+ break;
+ }
+ }
+ else if (GetHexValue(argv[i], &bval))
+ {
+ btype = -4;
+ return 1;
+ }
+
+ if (btype == -4)
+ {
+ printf("Error in bss-segment address: %s is not 'r', 'x[td]', or an address.", argv[i]);
+ return 1;
+ }
+
+ i++;
+ break;
+ case 'b':
+ case 'B': // Don't remove muliply defined locals
+ if (bflag)
+ warn('b', 1);
+
+ bflag = 1;
+ break;
+ case 'c':
+ case 'C': // Process a command file
+ if (i == argc)
+ {
+ printf("Not enough arguments to -c\n");
+ return 1;
+ }
+
+ if (docmdfile(argv[i++]))
+ {
+ return 1;
+ }
+
+ break;
+ case 'd':
+ case 'D': // Wait for "return" before exiting
+ if (dflag)
+ warn('d', 0);
+
+ dflag = 1;
+ waitflag = 1;
+ break;
+ case 'e':
+ case 'E': // Output COFF (absolute only)
+ cflag = 1;
+
+ if (noheaderflag)
+ printf("Warning: -e overridden by -n, output will be headerless\n");
+
+ break;
+ case 'g':
+ case 'G': // Output source level debugging
+ if (gflag) warn('g', 1);
+ gflag = 1;
+ break;
+ case 'i':
+ case 'I': // Include binary file
+ if (i + 2 > argc)
+ {
+ printf("Not enough arguments to -i\n");
+ return 1;
+ }
+
+ ifile = argv[i++];
+ isym = argv[i++];
+
+ // handle -ii (No truncation)
+ if ((argv[i-3][2] == 'i') || (argv[i-3][2] == 'I'))
+ {
+ if (!cflag)
+ printf("warning: (-ii) COFF format output not specified\n");
+ }
+ // handle -i (Truncation)
+ else
+ {
+ if (strlen(isym) > 8)
+ isym[8] = '\0';
+ }
+
+ // Place include files in the DATA segment only
+ if (DoFile(ifile, DSTSEG_D, isym))
+ return 1;
+
+ break;
+ case 'l':
+ case 'L': // Add local symbols
+ if (lflag)
+ warn('l', 1);
+
+ lflag = 1;
+ break;
+ case 'm':
+ case 'M': // Produce load symbol map
+ if (mflag)
+ warn('m', 1);
+
+ mflag = 1;
+ break;
+ case 'n':
+ case 'N': // Output no header to .abs file
+ if (noheaderflag)
+ warn('n', 1);
+
+ if (cflag)
+ printf("Warning: -e overridden by -n, output will be headerless\n");
+
+ noheaderflag = 1;
+ break;
+ case 'o':
+ case 'O': // Specify an output file
+ if (oflag)
+ warn('o', 1);
+
+ oflag = 1;
+
+ if (i >= argc)
+ {
+ printf("No output filename following -o switch\n");
+ return 1;
+ }
+
+ if (strlen(argv[i]) > FARGSIZE - 5)
+ {
+ printf("Output file name too long (sorry!)\n");
+ return 1;
+ }
+
+ strcpy(ofile, argv[i++]);
+ break;
+ case 'r':
+ case 'R': // Section alignment size
+ if (rflag)
+ warn('r', 1);
+
+ rflag = 1;
+
+ switch (argv[i-1][2])
+ {
+ case 'w': case 'W': secalign = 1; break; // Word alignment
+ case 'l': case 'L': secalign = 3; break; // Long alignment
+ case 'p': case 'P': secalign = 7; break; // Phrase alignment
+ case 'd': case 'D': secalign = 15; break; // Double phrase alignment
+ case 'q': case 'Q': secalign = 31; break; // Quad phrase alignment
+ default: secalign = 7; break; // Default phrase alignment
+ }
+
+ break;
+ case 's':
+ case 'S': // Output only global symbols
+ if (sflag)
+ warn('s', 1);
+
+ sflag = 1;
+ break;
+ case 'u':
+ case 'U': // Undefined symbols
+ uflag++;
+ break;
+ case 'v':
+ case 'V': // Verbose information
+ if (!vflag && !versflag)
+ {
+ ShowVersion();
+ }
+
+ vflag++;
+ break;
+ case 'w':
+ case 'W': // Show warnings flag
+ if (wflag)
+ warn('w', 1);
+
+ wflag = 1;
+ break;
+ case 'y':
+ case 'Y':
+ if (i >= argc)
+ {
+ printf("No directory filename following -y switch\n");
+ return 1;
+ }
+
+ if (strlen(argv[i]) > FARGSIZE * 3)
+ {
+ printf("Directory file name too long (sorry!)\n");
+ return 1;
+ }
+
+ strcpy(libdir, argv[i++]);
+ break;
+ case 'z':
+ case 'Z': // Suppress banner flag
+ if (zflag)
+ warn('z', 1);
+
+ zflag = 1;
+ break;
+ default:
+ printf("unknown option argument `%c'\n", c);
+ return 1;
+ }
+ }
+ else
+ {
+ // Not a switch, then process as a file
+ if (DoFile(argv[i++], 0, NULL))
+ return 1;
+ }
+ }
+
+ if (!oflag && vflag)
+ {
+ strcpy(ofile, "output");
+ printf("Output file is %s[.ext]\n", ofile);
+ }
+
+ if (oflag && vflag)
+ printf("Output file is %s\n", ofile);
+
+ if (sflag)
+ lflag = 0;
+
+ // No problems encountered
+ return 0;