Beispiel #1
0
static void execute_word(void) {
  DICTIONARY_ENTRY *e;

  // find it
  e=find(FIND_FORTH);
  // do it if its there
  if(e) {
    // handle execute-forth word specially
    if(counted_string_equal(e->name, e->name_len,
                            WORD_EXECUTE_FORTH_RAW, -1)) {
      // check dstack
      dstack_check();
      // jump directly to forth word address
      ((EXECUTE_FORTH_FUNC)e->code_addr)(&ctx);
      // check dstack
      dstack_check();
    } else {
      // call special execute-forth word
      dstack_push((CELL)e->code_addr);
      execute_cstr(WORD_EXECUTE_FORTH);
    }
  } else if(execute_built_in(ctx.current_word, ctx.current_word_len)) {
    // the above function does what's needed
  } else {
    dstack_push(parse_number());
  }
}
Beispiel #2
0
void execute(char **cmd)
{
	int status;
	int i = 0;
	pid_t pid;
	

	if(is_built_in(cmd[0]))
	{
		execute_built_in(cmd);
	}
	else if (is_external(cmd[0]))
	{
		pid = fork();

		/* error */
		if (pid == -1)
			exit(1);

		/* child */
		else if (pid == 0) 
		{
			execv(cmd[0], cmd);
			exit(0);
		}
	
		/* parent */
		else
			waitpid(pid, &status, 0);
	}
	else
		printf("%s: Command not found.\n", cmd[0]);
}
Beispiel #3
0
int check_for_builtins(char *input[]){
  register int i;
  char *string;
  if(!string)
    string = malloc(sizeof(input[0]));
  memset(string, 0, sizeof(string));
  strcpy(string, input[0]);  
  for(i = 0; i < 6; i++){
    if(strncmp(__built_ins[i], string, sizeof(__built_ins[i])) == 0){
      execute_built_in(i, input);
      free(string);
      return 1;
    }
    else{
      continue;
    }
  }
  free(string);
  return 0;
}