コード例 #1
0
ファイル: game.c プロジェクト: devmabbott/Invaders
int main(int argc, char *argv[]) {
    /* Signal handlers */
    sigaction_wrapper(SIGINT, sigint_handler);

    /* Start the game */
    g = game_init();
    game_run(g);
    game_free(g);

    return 0;
}
コード例 #2
0
ファイル: mshell.c プロジェクト: CharlesVaneenoo/TP_L3S5
/*
 * main - The shell's main routine
 */
int main(int argc, char **argv) {
    char c;
    char cmdline[MAXLINE];

    verbose = 0;

    /* Redirect stderr to stdout (so that driver will get all output
     * on the pipe connected to stdout) */
    dup2(1, 2);

    /* Parse the command line */
    while ((c = getopt(argc, argv, "hv")) != EOF) {
        switch (c) {
        case 'h':              /* print help message */
            usage();
            break;
        case 'v':              /* emit additional diagnostic info */
            verbose = 1;
            break;
        default:
            usage();
        }
    }

    /* Install the signal handlers */

    /* These are the ones you will need to implement */
    sigaction_wrapper(SIGINT, sigint_handler);  /* ctrl-c */
    sigaction_wrapper(SIGTSTP, sigtstp_handler);        /* ctrl-z */
    sigaction_wrapper(SIGCHLD, sigchld_handler);        /* Terminated or stopped child */

    /* Initialize the job list */
    jobs_initjobs();

    printf("\nType help to find out all the available commands in mshell\n\n");

    /* Execute the shell's read/eval loop */
    while (1) {
        /* Read command line */
        printf("%s", prompt);

        if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin)) {
            fprintf(stdout, "fgets error\n");
            exit(EXIT_FAILURE);
        }
        if (feof(stdin)) {      /* End of file (ctrl-d) */
            fflush(stdout);
            exit(EXIT_SUCCESS);
        }

        /* Evaluate the command line */
        if (cmdline[0] != '\n') {   /* evaluate the command line only when not empty */
            cmdline[strlen(cmdline) - 1] = '\0';       /* remove the '\n' at the end */
            eval(cmdline);
            fflush(stdout);
            fflush(stdout);
        }
    }

    exit(EXIT_SUCCESS);         /* control never reaches here */
}