Ejemplo n.º 1
0
Archivo: use.c Proyecto: 8l/myrddin
void readuse(Node *use, Stab *st, Vis vis)
{
    size_t i;
    FILE *fd;
    char *t, *p;

    /* local (quoted) uses are always relative to the cwd */
    fd = NULL;
    p = NULL;
    if (use->use.islocal) {
        p = strdup(use->use.name);
        fd = fopen(p, "r");
    /* nonlocal (barename) uses are always searched on the include path */
    } else {
        for (i = 0; i < nincpaths; i++) {
            t = strjoin(incpaths[i], "/");
            p = strjoin(t, use->use.name);
            fd = fopen(p, "r");
            if (fd) {
                free(t);
                break;
            }
        }
    }
    if (!fd)
        fatal(use, "Could not open %s", use->use.name);

    if (!loaduse(p, fd, st, vis))
        die("Could not load usefile %s from %s", use->use.name, p);
    free(p);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    FILE *f;
    int opt;
    int i;

    while ((opt = getopt(argc, argv, "hud:I:")) != -1) {
        switch (opt) {
            case 'h':
                usage(argv[0]);
                exit(0);
                break;
            case 'u':
                fromuse = 1;
                break;
            case 'd':
                debug = 1;
                while (optarg && *optarg)
                    debugopt[*optarg++ & 0x7f] = 1;
                break;
            case 'I':
                lappend(&incpaths, &nincpaths, optarg);
                break;
            default:
                usage(argv[0]);
                exit(0);
                break;
        }
    }

    for (i = optind; i < argc; i++) {
        lappend(&incpaths, &nincpaths, Instroot "/lib/myr");
        file = mkfile(argv[i]);
        file->file.exports = mkstab();
        file->file.globls = mkstab();
        tyinit(file->file.globls);
        printf("%s:\n", argv[i]);
        if (fromuse) {
            f = fopen(argv[i], "r");
            if (!f)
                die("Unable to open usefile %s\n", argv[i]);
            loaduse(f, file->file.globls);
            dumpsyms(file->file.globls, 1);
        } else {
            tokinit(argv[i]);
            yyparse();
            infer(file);
            dumpsyms(file->file.globls, 1);
        }
    }

    return 0;
}
Ejemplo n.º 3
0
Archivo: muse.c Proyecto: oridb/mc
static void
mergeuse(char *path)
{
	FILE *f;
	Stab *st;

	st = file.globls;
	f = fopen(path, "r");
	if (!f) {
		fprintf(stderr, "couldn't open %s\n", path);
		exit(1);
	}
	loaduse(path, f, st, Visexport);
	fclose(f);
}