예제 #1
0
void gameTick(Game *g, Task* t) {

    unsigned int x, y;
    
    for (y = 0; y < g->rows; y++)
        for(x = t->min; x <= t->max; x++)
            g->next_board[POS(x, y, g)] = __process(x, y, g);

    DEBUG_MSG("Game tick finish");
}
예제 #2
0
파일: logger.c 프로젝트: koura-h/compostela
int
main(int argc, char** argv)
{
    int fd, ch;
    char* msg = NULL, *path = NULL, *tag = NULL, *dir = NULL, *ftemp = NULL;
    FILE* f = NULL;

    struct option long_opts[] = {
        { "tag", 2, NULL, 0 },
        { "unix-socket", 2, NULL, 0 },
        { "help", 2, NULL, 0 },
    };

    while ((ch = getopt_long(argc, argv, "t:u:h", long_opts, NULL)) != -1) {
        switch (ch) {
        case 't':
            tag = strdup(optarg);
            break;
        case 'u':
            path = strdup(optarg);
            break;
        case 'h':
        default:
            usage();
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    if (!path || !tag) {
        usage();
        exit(-1);
    }

    // from here

    dir = __setup_tempdir(RUNDIR, tag);
    if (!dir) {
        perror("comlogger: __setup_temp");
        exit(-1);
    }

    if (argc > 0) {
        int n = strlen(argv[0]);
        msg = malloc(n + 3);
        snprintf(msg, n + 3, "%s\r\n", argv[0]);
    }

    if (!msg) {
        f = stdin;
    }

    fd = __make_local_socket(path);
    if (fd == -1) {
        perror("comlogger: socket");
        exit(-1);
    }

    if (msg) {
        // send(fd, msg, strlen(msg), 0);
        ftemp = __setup_tempfile(dir);
        if (!ftemp) {
            perror("comlogger: __setup_tempfile");
            exit(-1);
        }

        __process(fd, tag, ftemp, msg, strlen(msg));
        free(ftemp);
    } else {
        char buf[8192];

	while (fgets(buf, sizeof(buf), stdin) != NULL) {
            // send(fd, buf, strlen(buf), 0);
            ftemp = __setup_tempfile(dir);
            if (!ftemp) {
                perror("comlogger: __setup_tempfile");
                exit(-1);
            }

            __process(fd, tag, ftemp, buf, strlen(buf));
            free(ftemp);
        }
    }

    free(dir);
    close(fd);
    return 0;
}