Ejemplo n.º 1
0
Archivo: rash.c Proyecto: Razbit/razos
/* Launch a program and wait for it to terminate. */
static int rash_launch(char **args)
{
    int pipes = 0;
    int cmd_buf = 8;
    int *commandStarts = malloc(cmd_buf * sizeof(int));
    char *input_name = NULL;
    char *output_name = NULL;
     
    int i;
    int s = 1;
    commandStarts[0] = 0;
    /* Counts the pipes, sets them to NULL and sets the command boundaries. */
    for (i = 0; args[i] != NULL; i++)
    {
        if (strchr(args[i], PIPE))
        {
            free(args[i]);
            args[i] = NULL;
            commandStarts[s++] = i+1;
            ++pipes;
        }
        else if (strchr(args[i], IN))
        {
            free(args[i]);
            args[i++] = NULL;
            input_name = malloc(strlen(args[i]) + 1);
            strcpy(input_name, args[i]);
        }
        else if (strchr(args[i], OUT))
        {
            free(args[i]);
            args[i++] = NULL;
            output_name = malloc(strlen(args[i]) + 1);
            strcpy(output_name, args[i]);
        }
        
        if (s >= cmd_buf)
        {
            cmd_buf *= 2;
            commandStarts = realloc(commandStarts, cmd_buf * sizeof(int));
            if (commandStarts == NULL)
            {
                dprintf(STDERR_FILENO, "%s", alloc_error);
                exit(EXIT_FAILURE);
            }
        }
    }
    
    s = do_commands(args, pipes, commandStarts, input_name, output_name);
    
    free(input_name);
    free(output_name);
    free(commandStarts);
    
    if (s != 0) /* Error in the do_commands function */
        exit(EXIT_FAILURE);

    return 1;
}
Ejemplo n.º 2
0
int
main(int argc, char **argv) {
	int fd, d, j, k;
	char *p;

	/* egcs-2.91.66 is buggy and says:
	   blockdev.c:93: warning: `d' might be used uninitialized */
	d = 0;

	progname = argv[0];
	if ((p = strrchr(progname, '/')) != NULL)
		progname = p+1;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	if (argc < 2)
		usage();

	/* -V not together with commands */
	if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
		printf("%s from %s\n", progname, util_linux_version);
		exit(0);
	}

	/* do each of the commands on each of the devices */
	/* devices start after last command */
	for (d = 1; d < argc; d++) {
		j = find_cmd(argv[d]);
		if (j >= 0) {
			if (bdcms[j].argtype == ARGINTA)
				d++;
			continue;
		}
		if (!strcmp(argv[d], "--")) {
			d++;
			break;
		}
		if (argv[d][0] != '-')
			break;
	}

	if (d >= argc)
		usage();

	for (k = d; k < argc; k++) {
		fd = open(argv[k], O_RDONLY, 0);
		if (fd < 0) {
			perror(argv[k]);
			exit(1);
		}
		do_commands(fd, argv, d);
	}
	return 0;
}
Ejemplo n.º 3
0
bool frame_func() {
    float px, py;
    const auto dt = hge->Timer_GetDelta();

    // Update

    hge->Input_GetMousePos(&state.mx, &state.my);
    if (hge->Input_GetKeyState(HGEK_RBUTTON)) {
        psx = state.mx;
        psy = state.my;
    }
    else {
        psx = 400;
        psy = 300;
    }

    if (state.bIFace) {
        if (psx > 631) {
            psx = 631;
        }
        if (psx < 168) {
            psx = 168;
        }
    }

    state.ps->GetPosition(&px, &py);
    state.ps->MoveTo(px + (psx - px) * 10 * dt, py + (psy - py) * 10 * dt);
    state.ps->Update(dt);

    if (handle_keys(hge->Input_GetKey())) {
        return true;
    }

    if (state.bIFace) {
        if (do_commands(gui->Update(dt))) {
            return true;
        }
    }

    GET_TEXT_CTRL(CMD_NPARTICLES)->printf("%d", state.ps->GetParticlesAlive());
    GET_TEXT_CTRL(CMD_FPS)->printf("%d", hge->Timer_GetFPS());

    return false;
}