void ProcessLinkfile(char *tzLinkfile) { FILE *pLinkfile; enum eBlockType CurrentBlock = BLOCK_COMMENT; pLinkfile = fopen(tzLinkfile, "rt"); if (!pLinkfile) { sprintf(temptext, "Unable to find linkfile '%s'\n", tzLinkfile); fatalerror(temptext); } while (!feof(pLinkfile)) { char tzLine[256]; fscanf(pLinkfile, "%s\n", tzLine); if (tzLine[0] != '#') { if (tzLine[0] == '[' && tzLine[strlen(tzLine) - 1] == ']') { if (strcmpi("[objects]", tzLine) == 0) CurrentBlock = BLOCK_OBJECTS; else if (strcmpi("[output]", tzLine) == 0) CurrentBlock = BLOCK_OUTPUT; else if (strcmpi("[libraries]", tzLine) == 0) CurrentBlock = BLOCK_LIBRARIES; else if (strcmpi("[comment]", tzLine) == 0) CurrentBlock = BLOCK_COMMENT; else { fclose(pLinkfile); sprintf(temptext, "Unknown block '%s'\n", tzLine); fatalerror(temptext); } } else { switch (CurrentBlock) { case BLOCK_COMMENT: break; case BLOCK_OBJECTS: obj_Readfile(tzLine); break; case BLOCK_LIBRARIES: lib_Readfile(tzLine); break; case BLOCK_OUTPUT: out_Setname(tzLine); break; } } } } fclose(pLinkfile); }
int main(int argc, char *argv[]) { int ch; char *ep; if (argc == 1) usage(); while ((ch = getopt(argc, argv, "l:m:n:o:p:s:t")) != -1) { switch (ch) { case 'l': lib_Readfile(optarg); break; case 'm': SetMapfileName(optarg); break; case 'n': SetSymfileName(optarg); break; case 'o': out_Setname(optarg); break; case 'p': fillchar = strtoul(optarg, &ep, 0); if (optarg[0] == '\0' || *ep != '\0') { fprintf(stderr, "Invalid argument for option 'p'\n"); exit(1); } if (fillchar < 0 || fillchar > 0xFF) { fprintf(stderr, "Argument for option 'p' must be between 0 and 0xFF"); exit(1); } break; case 's': options |= OPT_SMART_C_LINK; strcpy(smartlinkstartsymbol, optarg); break; case 't': options |= OPT_SMALL; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc == 0) usage(); for (int i = 0; i < argc; ++i) obj_Readfile(argv[i]); AddNeededModules(); AssignSections(); CreateSymbolTable(); Patch(); Output(); CloseMapfile(); return (0); }