Esempio n. 1
0
void __attribute__((noreturn)) kernel_main(unsigned int _memory_size)
{
    struct vm_translation_map *init_map;
    struct process *init_proc;

    vm_page_init(_memory_size);
    init_map = vm_translation_map_init();
    boot_init_heap((char*) KERNEL_HEAP_BASE + PAGE_STRUCTURES_SIZE(_memory_size));
    vm_address_space_init(init_map);
    bootstrap_vm_cache();
    bool_init_kernel_process();
    boot_init_thread();

    // Start other threads
    REGISTERS[REG_THREAD_RESUME] = 0xffffffff;

    spawn_kernel_thread("Grim Reaper", grim_reaper, 0);

    init_proc = exec_program("program.elf");

    // Idle task
    for (;;)
    {
        if (list_is_empty(&init_proc->thread_list))
        {
            kprintf("init process has exited, shutting down\n");
            REGISTERS[REG_THREAD_HALT] = 0xffffffff;
        }

        reschedule();
    }
}
Esempio n. 2
0
UINT cheetah_menu_mask(struct git_data *this_)
{
	BOOL is_directory;
	char *wd = wd_from_path(this_->name, &is_directory);
	UINT selection = is_directory ? MENU_ITEM_DIR : MENU_ITEM_FILE;
	int status;
	char *prefix = get_git_prefix(wd, &status);

	if (status < 0) /* something went terribly wrong */
		selection = MENU_ITEM_LAST;
	else if (status)
		selection |= MENU_ITEM_NOREPO;
	else {
		char head_path[MAX_PATH] = "HEAD";
		if (!is_directory)
			sprintf(head_path, "HEAD:%s%s",
				prefix,
				this_->name + strlen(wd) + 1);

		status = exec_program(wd, NULL, NULL, WAITMODE,
			"git", "rev-parse", "--verify", head_path, NULL);
		if (status < 0) /* something went terribly wrong */
			selection = MENU_ITEM_LAST;
		else
			selection |= MENU_ITEM_REPO |
				(status ?
					MENU_ITEM_NOTRACK : MENU_ITEM_TRACK);
	}

	free(prefix);
	free(wd);
	return selection;
}
Esempio n. 3
0
int true_main(int argc, char *argv[])
{
    if (lisp_prompt) {
        jl_lisp_prompt();
        return 0;
    }

    jl_array_t *args = jl_alloc_cell_1d(argc);
    jl_set_global(jl_current_module, jl_symbol("ARGS"), (jl_value_t*)args);
    int i;
    for (i=0; i < argc; i++) {
        jl_arrayset(args, i, (jl_value_t*)jl_cstr_to_string(argv[i]));
    }
    jl_set_const(jl_current_module, jl_symbol("JULIA_HOME"),
                 jl_cstr_to_string(julia_home));

    // run program if specified, otherwise enter REPL
    if (program) {
        return exec_program();
    }

    init_repl_environment();

    jl_function_t *start_client =
        (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start"));

    if (start_client) {
        jl_apply(start_client, NULL, 0);
        return 0;
    }

    // client event loop not available; use fallback blocking version
    int iserr = 0;
 again:
    ;
    JL_TRY {
        if (iserr) {
            jl_show(jl_exception_in_transit);
            ios_printf(ios_stdout, "\n\n");
            iserr = 0;
        }
        while (1) {
            char *input = read_expr("julia> ");
            if (!input || ios_eof(ios_stdin)) {
                ios_printf(ios_stdout, "\n");
                break;
            }
            jl_value_t *ast = jl_parse_input_line(input);
            jl_value_t *value = jl_toplevel_eval(ast);
            jl_show(value);
            ios_printf(ios_stdout, "\n\n");
        }
    }
    JL_CATCH {
        iserr = 1;
        goto again;
    }

    return 0;
}
Esempio n. 4
0
int true_main(int argc, char *argv[])
{
    if (jl_base_module != NULL) {
        jl_array_t *args = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("ARGS"));
        assert(jl_array_len(args) == 0);
        jl_array_grow_end(args, argc);
        int i;
        for (i=0; i < argc; i++) {
            jl_value_t *s = (jl_value_t*)jl_cstr_to_string(argv[i]);
            s->type = (jl_value_t*)jl_utf8_string_type;
            jl_arrayset(args, s, i);
        }
    }
    
    // run program if specified, otherwise enter REPL
    if (program) {
        int ret = exec_program();
        uv_tty_reset_mode();
        return ret;
    }

    jl_function_t *start_client =
        (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start"));

    //uv_read_start(jl_stdin_tty,jl_alloc_read_buffer,&read_buffer);

    if (start_client) {
        jl_apply(start_client, NULL, 0);
        //rl_cleanup_after_signal();
        return 0;
    }

    // client event loop not available; use fallback blocking version
    //install_read_event_handler(&echoBack);
    int iserr = 0;

 again:
    ;
    JL_TRY {
        if (iserr) {
            //jl_show(jl_exception_in_transit);# What if the error was in show?
            jl_printf(JL_STDERR, "\n\n");
            iserr = 0;
        }
        uv_run(jl_global_event_loop(),UV_RUN_DEFAULT);
    }
    JL_CATCH {
        iserr = 1;
        JL_PUTS("error during run:\n",JL_STDERR);
        jl_show(jl_stderr_obj(),jl_exception_in_transit);
        JL_PUTS("\n",JL_STDOUT);
        goto again;
    }
    uv_tty_reset_mode();
    return iserr;
}
Esempio n. 5
0
File: repl.c Progetto: julienr/julia
int true_main(int argc, char *argv[])
{
    if (lisp_prompt) {
        jl_lisp_prompt();
        return 0;
    }

    jl_array_t *args = jl_alloc_cell_1d(argc);
    jl_set_global(jl_system_module, jl_symbol("ARGS"), (jl_value_t*)args);
    int i;
    for (i=0; i < argc; i++) {
        jl_arrayset(args, i, (jl_value_t*)jl_cstr_to_string(argv[i]));
    }
    jl_set_const(jl_system_module, jl_symbol("JULIA_HOME"),
                 jl_cstr_to_string(julia_home));

    // run program if specified, otherwise enter REPL
    if (program) {
        return exec_program();
    }

    init_repl_environment();

    have_color = detect_color();
    char *prompt = have_color ? jl_prompt_color : jl_prompt_plain;
    prompt_length = strlen(jl_prompt_plain);
    prompt_string = prompt;

    jl_function_t *start_client =
        (jl_function_t*)
        jl_get_global(jl_system_module, jl_symbol("_start"));

    if (start_client == NULL) {
        repl_print_prompt();
        // client event loop not available; use fallback blocking version
        int iserr = 0;
    again:
        ;
        JL_TRY {
            if (iserr) {
                if (have_color) {
                    ios_printf(ios_stdout, jl_color_normal);
                }
                jl_show(jl_exception_in_transit);
                ios_printf(ios_stdout, "\n\n");
                iserr = 0;
            }
            while (1) {
                read_expr(prompt);
            }
        }
        JL_CATCH {
            iserr = 1;
            goto again;
        }
    }
Esempio n. 6
0
File: repl.c Progetto: CBaader/julia
int true_main(int argc, char *argv[])
{
    if (jl_base_module != NULL) {
        jl_array_t *args = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("ARGS"));
        if (args == NULL) {
            args = jl_alloc_cell_1d(0);
            jl_set_const(jl_base_module, jl_symbol("ARGS"), (jl_value_t*)args);
        }
        assert(jl_array_len(args) == 0);
        jl_array_grow_end(args, argc);
        int i;
        for (i=0; i < argc; i++) {
            jl_value_t *s = (jl_value_t*)jl_cstr_to_string(argv[i]);
            s->type = (jl_value_t*)jl_utf8_string_type;
            jl_arrayset(args, s, i);
        }
    }

    // run program if specified, otherwise enter REPL
    if (program) {
        int ret = exec_program();
        uv_tty_reset_mode();
        return ret;
    }

    jl_function_t *start_client =
        (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start"));

    if (start_client) {
        jl_apply(start_client, NULL, 0);
        return 0;
    }

    int iserr = 0;

 again:
    ;
    JL_TRY {
        if (iserr) {
            //jl_show(jl_exception_in_transit);# What if the error was in show?
            jl_printf(JL_STDERR, "\n\n");
            iserr = 0;
        }
        uv_run(jl_global_event_loop(),UV_RUN_DEFAULT);
    }
    JL_CATCH {
        iserr = 1;
        JL_PUTS("error during run:\n",JL_STDERR);
        jl_show(jl_stderr_obj(),jl_exception_in_transit);
        JL_PUTS("\n",JL_STDOUT);
        goto again;
    }
    uv_tty_reset_mode();
    return iserr;
}
Esempio n. 7
0
int main( int argc, char ** argv) {
    int     status;

    if (argc - 1 >= ARG_LIM) {
        fprintf( stderr, "Too many arguments.\n");
        return  1;
    }
    status = exec_program( argc, argv);
                    /* MinGW does not have fork() nor wait().   */
    return  status;
}
Esempio n. 8
0
static BOOL build_branch_menu(struct git_data *data,
			      const struct menu_item *item,
			      void *platform)
{
	void *submenu;

	int status;
	char *wd = wd_from_path(data->name, NULL);

	struct strbuf output;
	struct strbuf **lines, **it;
	strbuf_init(&output, 0);

	status = exec_program(wd, &output, NULL, WAITMODE,
		"git", "branch", NULL);
	free(wd);
	if (status)
		return FALSE;

	submenu = start_submenu(data, item, platform);

	lines = strbuf_split(&output, '\n');
	for (it = lines; *it; it++) {
		struct menu_item item = {
			MENU_ITEM_CLEANUP, 0,
			NULL, NULL,
			NULL, menu_branch
		};

		strbuf_rtrim(*it);
		item.string = strdup((*it)->buf + 2);
		item.helptext = strdup((*it)->buf + 2);
		item.flags = '*' == (*it)->buf[0] ?
			MI_CHECKED | MI_DISABLED : 0;
		if (build_item(data, &item, submenu))
			append_active_menu(&item);
		else
			/*
			 * if the platform failed to create an item
			 * there is no point to try other items
			 */
			break;
	}

	end_submenu(platform, submenu);

	/* technically, there is nothing to track for the menu engine */
	return FALSE;
}
Esempio n. 9
0
/**
 * Tests 'exec_program()'.
 */
void test_exec_program()
{
    allocate();
    uint32_t test_instructions[2] = {
            create_instruction(INSTR_NOOP, EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE),
            create_instruction(INSTR_EXIT, EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE)};
    load_program(test_instructions,
                 sizeof(test_instructions) / sizeof(test_instructions[0]),
                 flash);
    exec_program();
    // TODO: Maybe there is a better way to test this
    // This is a very trivial test just to check that the pc was incremented
    // after executing a no op
    CU_ASSERT(0 != pc);
    deallocate();
}
Esempio n. 10
0
void			exec_cmd(s_cmd_node *cmd)
{
  assert(cmd);
  if (DEBUG_EXEC)
    cmd_debugger(cmd);
  //FIXME: expansions here
  if (!cmd->argv) {
    if (cmd->prefix) exec_prefix(cmd->prefix, 0);
    return;
  }
  if (func_exist(shell->func, cmd->argv[0]))
    exec_function(cmd->argv);
  else if (is_a_builtin(cmd->argv[0]))
    shell->status = get_builtin(cmd->argv[0])(cmd->argv);
  else
    shell->status = exec_program(cmd);
}
Esempio n. 11
0
static char *get_git_prefix(const char *wd, int *out_status)
{
	char *eol;
	int status;
	struct strbuf output = STRBUF_INIT;

	status = exec_program(wd, &output, NULL, WAITMODE,
		"git", "rev-parse", "--show-prefix", NULL);
	if (out_status)
		*out_status = status;
	if (status) {
		strbuf_release(&output);
		return NULL;
	}
	
	eol = strchr(output.buf, '\n');
	if (eol)
		*eol = 0;

	return strbuf_detach(&output, NULL);
}
Esempio n. 12
0
File: repl.c Progetto: Blisse/julia
static NOINLINE int true_main(int argc, char *argv[])
{
    if (jl_core_module != NULL) {
        jl_array_t *args = (jl_array_t*)jl_get_global(jl_core_module, jl_symbol("ARGS"));
        if (args == NULL) {
            args = jl_alloc_cell_1d(0);
            JL_GC_PUSH1(&args);
            jl_set_const(jl_core_module, jl_symbol("ARGS"), (jl_value_t*)args);
            JL_GC_POP();
        }
        assert(jl_array_len(args) == 0);
        jl_array_grow_end(args, argc);
        int i;
        for (i=0; i < argc; i++) {
            jl_value_t *s = (jl_value_t*)jl_cstr_to_string(argv[i]);
            jl_set_typeof(s,jl_utf8_string_type);
            jl_arrayset(args, s, i);
        }
    }

    jl_function_t *start_client = jl_base_module ?
        (jl_function_t*)jl_get_global(jl_base_module, jl_symbol("_start")) : NULL;

    if (start_client) {
        jl_apply(&start_client, 1);
        return 0;
    }

    // run program if specified, otherwise enter REPL
    if (argc > 0) {
        if (strcmp(argv[0], "-")) {
            return exec_program(argv[0]);
        }
    }

    ios_puts("WARNING: Base._start not defined, falling back to economy mode repl.\n", ios_stdout);
    if (!jl_errorexception_type)
        ios_puts("WARNING: jl_errorexception_type not defined; any errors will be fatal.\n", ios_stdout);

    while (!ios_eof(ios_stdin)) {
        char *volatile line = NULL;
        JL_TRY {
            ios_puts("\njulia> ", ios_stdout);
            ios_flush(ios_stdout);
            line = ios_readline(ios_stdin);
            jl_value_t *val = (jl_value_t*)jl_eval_string(line);
            if (jl_exception_occurred()) {
                jl_printf(JL_STDERR, "error during run:\n");
                jl_static_show(JL_STDERR, jl_exception_in_transit);
                jl_exception_clear();
            }
            else if (val) {
                jl_static_show(JL_STDOUT, val);
            }
            jl_printf(JL_STDOUT, "\n");
            free(line);
            line = NULL;
            uv_run(jl_global_event_loop(),UV_RUN_NOWAIT);
        }
        JL_CATCH {
            if (line) {
                free(line);
                line = NULL;
            }
            jl_printf(JL_STDERR, "\nparser error:\n");
            jl_static_show(JL_STDERR, jl_exception_in_transit);
            jl_printf(JL_STDERR, "\n");
            jlbacktrace();
        }
    }
    return 0;
}
Esempio n. 13
0
/************************************************************************
*                                                                       *
*  Process the Image Math string "cmd".
*  (STATIC)								*
*									*/
void
Win_math::exec_string(char *cmd)
{
    int i;
    int n;
    int err = FALSE;
    char *pc;

    // The following get pointed to mallocated memory
    ParmList dst_frames = NULL;
    ParmList dst_ddls = NULL;
    ParmList src_ddls = NULL;
    ParmList src_ddl_vecs = NULL;
    ParmList src_strings = NULL;
    ParmList src_constants = NULL;
    ParmList parmtree = NULL;
    char *exec_path = NULL;

    win_print_msg("Math: Parsing...");

    /* Change New-Lines to Spaces */
    while (pc=strchr(cmd, '\n')){
	*pc = ' ';
    }

    /* Parse the left hand side */
    int nout = parse_lhs(cmd, &dst_frames);
    if (!nout){
	err = TRUE;
    }
    /*printParm(dst_frames);/*CMP*/

    /* Parse images on right hand side */
    int nin = parse_rhs(cmd, &src_ddls, &src_ddl_vecs,
			&src_strings, &src_constants);
    if (!nin){
	err = TRUE;
    }
    /*printParm(src_ddls);/*CMP*/
    /*printParm(src_strings);/*CMP*/

    /* Get the executable, compiling if necessary */
    if (!err){
	win_print_msg("Math: Compiling program...");
	if (!(exec_path = get_program(cmd))){
	    err = TRUE;
	}
    }
    /*fprintf(stderr,"exec_path=%s\n", exec_path);/*CMP*/

    /* Execute the program */
    parmtree = allocParm("parmtree", PL_PARM, 5);
    setParmParm(parmtree, src_ddls, 0);
    setParmParm(parmtree, dst_frames, 1);
    setParmParm(parmtree, src_strings, 2);
    setParmParm(parmtree, src_constants, 3);
    setParmParm(parmtree, src_ddl_vecs, 4);
    /*printParm(parmtree);/*CMP*/
    if (!err){
	win_print_msg("Math: Executing program...");
	if (!exec_program(exec_path, parmtree, &dst_ddls)){
	    err = TRUE;
	}
    }

    /* Display the results */
    /*printParm(dst_ddls);/*CMP*/
    void *vst;
    int frame;
    Gframe *gf;
    n = countParm(dst_ddls);
    for (i=0; i<n; i++){
	getPtrParm(dst_ddls, &vst, i);
	DDLSymbolTable *st = (DDLSymbolTable *)vst;
	getIntParm(dst_frames, &frame, i);
	/*fprintf(stderr,"st=0x%x, frame=%d\n", st, frame);/*CMP*/
	if (st && frame){
	    char *fname;
	    st->GetValue("filename", fname);
	    char *newname = (char *)malloc(strlen(fname) + 20);
	    sprintf(newname,"%s-mathout#%d", fname, i+1);
	    st->SetValue("filename", newname);
	    free(newname);
	    gf = Gframe::get_frame_by_number(frame);
	    int display_data = TRUE;
	    int math_result = TRUE;
	    Frame_data::load_ddl_data(gf, NULL, NULL, &display_data, TRUE,
				      (DDLSymbolTable *)st, math_result);
	}
    }

    /* Free memory */
    free(parmtree);		// Also frees params under it
    free(dst_ddls);

    win_print_msg("Math: Done.");
}
Esempio n. 14
0
int main (int argc, char *argv[])
{
  int use_stdin = 0;
  FILE *newsfile;
  FILE *newsfile_copy;
  char *bodyfile_name = NULL;
  FILE *bodyfile_r;
  FILE *bodyfile_w;
  char *mergefile_name = NULL;
  FILE *mergefile;

#if defined(MAINLOOP)
  volatile int w = 1;
  while (w);
#endif

  parse_commandline (argc, argv);

  if (printversion)
  {
    printf ("%s (" PACKAGE ") " VERSION "\n", Name);
    return 0;
  }

  if (!strcmp (newsfile_name, "-"))
  {
    use_stdin = 1;
    newsfile_name = nb_tmpnam ();
    newsfile_copy = open_write (newsfile_name);
    newsfile = stdin;

    mergefile = stdout;
  }
  else
  {
    newsfile_copy = NULL;
    newsfile = open_read (newsfile_name);

    mergefile_name = nb_tmpnam ();
    mergefile = open_write (mergefile_name);
  }

  if (filter)
  {
    expand_argv (new_argv, "-");
    exec_filter (new_argv, &bodyfile_w, &bodyfile_r);
    writebody (newsfile, newsfile_copy, bodyfile_w,
	       remove_header, remove_quote, remove_sig, keep);

    newsfile = open_read (newsfile_name);
    readbody (newsfile, bodyfile_r, mergefile,
	      remove_header, remove_quote, remove_sig, keep);
    check_child ();
  }
  else
  {
    bodyfile_name = nb_tmpnam ();
    bodyfile_w = open_write (bodyfile_name);
    expand_argv (new_argv, bodyfile_name);
    writebody (newsfile, newsfile_copy, bodyfile_w,
	       remove_header, remove_quote, remove_sig, keep);

    exec_program (new_argv);
    check_child ();

    newsfile = open_read (newsfile_name);
    bodyfile_r = open_read (bodyfile_name);
    readbody (newsfile, bodyfile_r, mergefile,
	      remove_header, remove_quote, remove_sig, keep);
  }

  if (use_stdin)
    nb_unlink (newsfile_name);
  else
    nb_rename (mergefile_name, newsfile_name);

  if (!filter)
    nb_unlink (bodyfile_name);

  return 0;
}
Esempio n. 15
0
/**
 * Run a command without using the shell.
 *
 * return 0 if the command run and exited with 0 status; Otherwise
 * return -1
 *
 */
int run_program(struct netcf *ncf, const char *const *argv, char **output)
{

    pid_t childpid = -1;
    int exitstatus, waitret;
    char *argv_str;
    int ret = -1;
    char errbuf[128];
    char *outtext = NULL;
    int outfd = -1;
    FILE *outfile = NULL;
    size_t outlen;

    if (!output)
        output = &outtext;

    argv_str = argv_to_string(argv);
    ERR_NOMEM(argv_str == NULL, ncf);

    exec_program(ncf, argv, argv_str, &childpid, &outfd);
    ERR_BAIL(ncf);

    printf("Attempting to execute %s\n", argv_str);
    outfile = fdopen(outfd, "r");
    ERR_THROW_STRERROR(outfile == NULL,ncf, EEXEC,
                       "Failed to create file stream for output while executing '%s': %s",
                       argv_str, errbuf);

    *output = fread_file(outfile, &outlen);
    ERR_THROW_STRERROR(*output == NULL, ncf, EEXEC,
                       "Error while reading output from execution of '%s': %s",
                       argv_str, errbuf);

    /* finished with the stream. Close it so the child can exit. */
    fclose(outfile);
    outfile = NULL;

    while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
            errno == EINTR) {
        /* empty loop */
    }

    ERR_THROW_STRERROR(waitret == -1, ncf, EEXEC,
                       "Failed waiting for completion of '%s': %s",
                       argv_str, errbuf);
    ERR_THROW(!WIFEXITED(exitstatus) && WIFSIGNALED(exitstatus), ncf, EEXEC,
              "'%s' terminated by signal: %d",
              argv_str, WTERMSIG(exitstatus));
    ERR_THROW(!WIFEXITED(exitstatus), ncf, EEXEC,
              "'%s' terminated improperly", argv_str);
    ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_ENOENT, ncf, EEXEC,
              "Running '%s' program not found", argv_str);
    ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_CANNOT_INVOKE, ncf, EEXEC,
              "Running '%s' program located but not usable", argv_str);
    ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_SIGMASK, ncf, EEXEC,
              "Running '%s' failed to reset child process signal mask",
              argv_str);
    ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_DUP2, ncf, EEXEC,
              "Running '%s' failed to dup2 child process stdout/stderr",
              argv_str);
    ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_INVALID_IN_THIS_STATE, ncf, EINVALIDOP,
              "Running '%s' operation is invalid in this state",
              argv_str);
    ERR_THROW(WEXITSTATUS(exitstatus) != 0, ncf, EEXEC,
              "Running '%s' failed with exit code %d: %s",
              argv_str, WEXITSTATUS(exitstatus), *output);
    ret = 0;

error:
    if (outfile)
        fclose(outfile);
    else if (outfd >= 0)
        close(outfd);
    FREE(outtext);
    FREE(argv_str);
    return ret;
}
Esempio n. 16
0
// -17 pipe not created
// -21 multiple in redirects
// -22 multiple out redirects
int exec_command(char **tokens) {
    char **curr_ptr = tokens;
    bool end = 0;
    
    int next_istream = STDIN_FILENO;
    
    char *progv[64];
    int progc = 0;
    
    while(!end) {
        char *program = *curr_ptr;
        progv[progc] = program;
        progc++;
        curr_ptr++;
        char **arg_start = curr_ptr;
        int argc = 0;
        
        int istream = next_istream;
        int ostream = STDOUT_FILENO;
        int errstream = STDERR_FILENO;
        next_istream = STDIN_FILENO;

        bool in_change = 0; //have these streams been redirected
        bool out_change = 0;
        
        // check for and process command symbols
        while(1) {
            if(istream != 0) {
                in_change = 1;
            }
            
            if(*curr_ptr == 0) {
                argc--;
                end = 1;
                break;
            } else if(strcmp(*curr_ptr, "<") == 0) {
                if(!in_change) {
                    return -21;
                }
                int file_desc = open(*(curr_ptr + 1), O_RDONLY);
                if(file_desc == -1) {
                    return -11;
                } else {
                    istream = file_desc;
                    in_change = 1;
                }
            } else if(strcmp(*curr_ptr, ">") == 0) {
                if(!out_change) {
                    return -22;
                }
                int file_desc = open(*(curr_ptr + 1), O_WRONLY);
                if(file_desc == -1) {
                    return -13;
                } else {
                    ostream = file_desc;
                    out_change = 1;
                }
            } else if(strcmp(*curr_ptr, "|") == 0) {
                if(!out_change) {
                    return -22;
                }
                int fd[2];
                int err = pipe(fd);
                if(err == -1) {
                    return -17;
                }
                
                ostream = fd[1];
                next_istream = fd[0];
                
                out_change = 1;
                break;
            }
            
            curr_ptr++;
            argc++;
        }
        
        // now execute
        char *argv[argc + 1];
        int j;
        for(j = 0; j < argc; j++) {
            argv[j] = *(arg_start + j);
        }
        argv[argc] = 0;
        exec_program(program, argc, argv, istream, ostream, errstream);
    }
    
    int j;
    for(j = 0; j < progc; j++) {
        int prog_err_code;
        int err = waitpid(getgrp(), &prog_err_code);
        if(err == -1) { // child process didn't finish
            return -2;
        } else if(prog_err_code > 0) { // program failed
            errno = prog_err_code;
            return -1;
        } else if(prog_err_code < 0) { // redirection failed
            return prog_err_code;
        }
    }
}