int main(int argc, char **argv) { Optctx ctx; size_t i; FILE *f; localincpath = "."; optinit(&ctx, "sd:hmo:p:l:", argv, argc); while (!optdone(&ctx)) { switch (optnext(&ctx)) { case 'h': usage(argv[0]); exit(0); break; case 'p': pkgname = ctx.optarg; break; case 'o': outfile = ctx.optarg; break; case 'd': while (ctx.optarg && *ctx.optarg) debugopt[*ctx.optarg++ & 0x7f] = 1; break; case 'l': lappend(&extralibs, &nextralibs, ctx.optarg); break; default: usage(argv[0]); exit(0); break; } } if (!outfile && !show) { fprintf(stderr, "output file needed when merging usefiles.\n"); exit(1); } if (!pkgname) { fprintf(stderr, "package needed when merging usefiles.\n"); exit(1); } /* read and parse the file */ initfile(&file, outfile); updatens(file.globls, pkgname); for (i = 0; i < ctx.nargs; i++) mergeuse(ctx.args[i]); loaduses(); infer(); tagexports(1); addextlibs(extralibs, nextralibs); /* generate the usefile */ f = fopen(outfile, "w"); writeuse(f); fclose(f); return 0; }
static void genuse(char *path) { FILE *f; char buf[1024]; char *psuffix; if (outfile != NULL) swapout(buf, 1024, ".use"); else { psuffix = strrchr(path, '+'); if (psuffix != NULL) swapsuffix(buf, 1024, path, psuffix, ".use"); else swapsuffix(buf, 1024, path, ".myr", ".use"); } f = fopen(buf, "w"); if (!f) { fprintf(stderr, "Could not open path %s\n", buf); exit(1); } writeuse(f, file); fclose(f); }