예제 #1
0
파일: main.c 프로젝트: BigEd/unix-jun72
int main(int argc, char *argv[])
{
    struct exec E;
    int ch, err;

    /* Get any arguments */
    while ((ch = getopt(argc, argv, "1a")) != -1) {
        switch (ch) {
        case '1':
            onepass = 1;
            break;
        case 'a':
            printaddrs = 1;
            break;
        case '?':
        default:
            usage();
        }
    }
    argc -= optind;
    argv += optind;


    /* Check we have an file to open */
    if (argc != 1)
        usage();

    /* Get the header details for the a.out file */
    err = load_a_out(argv[0], &E);

    if (err == -1) {
        fprintf(stderr, "%s does not appear to be a PDP-11 a.out file\n", argv[0]);
        exit(1);
    }

    printf("/ text at 0%o, len 0%o, end 0%o\n",
           E.a_entry, E.a_text, E.a_entry + E.a_text);

    if (onepass == 0) {
        doprint = 0;
        dopass(&E);			/* Do pass 1 to infer symbols */
        patch_symbols();
        /* print_symtables(); */
    }
    doprint = 1;
    dopass(&E);			/* Do pass 2 to print it out */

    exit(0);
}
예제 #2
0
파일: main.c 프로젝트: AntiTyping/unix
int
main(int argc, char **argv)
{
    int i;

    /* Ensure, before we start, that certain types are right */
    assert(sizeof(int8_t)==1);  assert(sizeof(u_int8_t)==1);
    assert(sizeof(int16_t)==2); assert(sizeof(u_int16_t)==2);
    assert(sizeof(int32_t)==4); assert(sizeof(u_int32_t)==4);

    if (argc < 2) usage();
    if (!strcmp(argv[1], "-help")) usage();
    if (!strcmp(argv[1], "--help")) usage();

#ifdef DEBUG
    while (1) {
      if (!strcmp(argv[1], "-inst"))
		{ inst_debug = 1; argc--; argv++; continue; }
      if (!strcmp(argv[1], "-trap"))
		{ trap_debug = 1; argc--; argv++; continue; }
      if (!strcmp(argv[1], "-jsr"))
		{ jsr_debug = 1; argc--; argv++; continue; }
      if (!strcmp(argv[1], "-fp"))
		{ fp_debug = 1; argc--; argv++; continue; }
      break;
    }
    if (inst_debug|trap_debug|jsr_debug|fp_debug)
				dbg_file = fopen("apout.dbg", "w");
#endif

				/* Prepare arg list for emulated environment */
    argc--; argv++;
    Argc= argc; Envp[0]=NULL;
    for (i=0; i<argc; i++) Argv[i]= argv[i];

				/* Initialise the stream pointers */
    for (i=3; i<NFILE; i++) { stream[i]=NULL; streammode[i]=NULL; }
    stream[0]=stdin;  streammode[0]="r";
    stream[1]=stdout; streammode[1]="w";
    stream[2]=stderr; streammode[2]="w";

                                /* Set the translation to a fictitious */
                                /* root filesystem */
    if ((apout_root = getenv("APOUT_ROOT"))) {  
	set_apout_root(apout_root);
    } else {
        fprintf(stderr,                 
                "APOUT_ROOT env variable not set before running apout\n");
        exit(1);
    }   

				/* Try to load the binary as an a.out */
    if (load_a_out(argv[0],NULL,1) == -1) {
	fprintf(stderr, "Apout - couldn't load %s\n", argv[0]);
	exit(1);
    }

				/* Other emulated systems (RT-11) can go here */

    run();			/* Now run the binary */
    exit(0);
}
예제 #3
0
파일: aout.c 프로젝트: tsupplis/apout
/* Read in the executable name and its arguments from the shell script,
 * and the re-call load_a_out to load in that binary. Returns 0 on
 * success, -1 on error. Input file is always closed by this routine.
 */
int load_script(const char *file, const char *origpath, FILE * zin,
                int want_env)
{
#define SCRIPT_LINESIZE 512	/* Max size of 1st line in script */
    char *script_line;
    char *script_arg[MAX_ARGS];
    int i, script_cnt = 0;
    char **ap;

    for (i = 0; i < Argc; i++)
        TrapDebug((dbg_file, "In load_script Argv[%d] is %s\n", i,
                   Argv[i]));
    /* Get the first line of the file */
    if (((script_line = (char *) malloc(SCRIPT_LINESIZE)) == NULL) ||
            (fgets(script_line, SCRIPT_LINESIZE, zin) == NULL)) {
        (void) fprintf(stderr,
                       "Apout - could not read 1st line of script\n");
        (void) fclose(zin);
        return (-1);
    }
    /* Now break into separate words */
    for (ap = script_arg; (*ap = strsep(&script_line, " \t\n")) != NULL;)
        if (**ap != '\0') {
            ap++;
            script_cnt++;
            if (script_cnt >= MAX_ARGS)
                break;
        }
    if (fclose(zin) != 0) {
        free(script_line);
        return (-1);
    }
#ifdef DEBUG
    TrapDebug((dbg_file, "Script: extra args are is %d\n", script_cnt));
    if (trap_debug) {
        for (i = 0; i < script_cnt; i++)
            fprintf(dbg_file, " script_arg[%d] is %s\n", i, script_arg[i]);
    }
#endif

    /* Ensure we have room to shift the args */
    if ((Argc + script_cnt) > MAX_ARGS) {
        (void) fprintf(stderr, "Apout - out of argv space in script\n");
        free(script_line);
        return (-1);
    }
    /* Now shift the args up and insert new ones */
    for (i = Argc - 1; i != 0; i--)
        Argv[i + script_cnt] = Argv[i];
    for (i = 0; i < Argc; i++)
        TrapDebug((dbg_file, "Part A load_script Argv[%d] is %s\n", i,
                   Argv[i]));
    for (i = 0; i < script_cnt; i++)
        Argv[i] = script_arg[i];
    if (origpath != NULL)
        Argv[i] = strdup(origpath);
    else
        Argv[i] = strdup(file);
    Argc += script_cnt;
    for (i = 0; i < Argc; i++)
        TrapDebug((dbg_file, "Part B load_script Argv[%d] is %s\n", i,
                   Argv[i]));

    file = xlate_filename(script_arg[0]);
    free(script_line);
    for (i = 0; i < Argc; i++)
        TrapDebug((dbg_file, "Leaving load_script Argv[%d] is %s\n", i,
                   Argv[i]));
    return (load_a_out(file, origpath, want_env));
}