コード例 #1
0
ファイル: genheader.C プロジェクト: gildafnai82/craq
static void
dump_tmpl_class (const str &arg, const str &res, const str &c, const str &spc)
{
  aout << spc << "template<class S>\n"
       << spc << "class " << c << " {\n"
       << spc << "public:\n"
       << spc << "  " << c << "(S *s) : _replied (false), _sbp (s) {}\n";
  if (arg) {
    str dcol = is_builtin (arg) ? "" : "::";
    aout << spc << "  " << "const " << dcol << arg << "* getarg() const { "
	 << " return static_cast<" << arg << "*> (_sbp->getvoidarg ()); }\n";
    aout << spc << "  " << dcol << arg << "* getarg() { "
	 << " return static_cast<" << arg << "*> (_sbp->getvoidarg ()); }\n";
  }
  if (res) {
    str dcol = is_builtin (res) ? "" : "::";
    aout << spc << "  " << "void reply (const " << dcol << res << " *r) "
	 << "{ check_reply (); _sbp->reply (r); }\n";
    aout << spc << "  " << "void reply (const " << dcol << res << " &r) "
	 << "{ check_reply (); _sbp->replyref (r); }\n";
    aout << spc << "  " << "void reply (ptr< " << dcol << res << "> r) "
	 << "{ check_reply (); _sbp->reply (r); }\n";

    aout << spc << "  " 
	 << "ptr<" << res << "> alloc_res () "
	 << " { return New refcounted<" << res << "> (); }\n";
    aout << spc << "  template<class T> " 
	 << "ptr<" << res << ">\n"
	 << spc << "  alloc_res (const T &t) "
	 << " { return New refcounted<" << res << "> (t); }\n";

  } else {
    aout << spc << "  " << "void reply () "
	 << "{ check_reply (); _sbp->reply (NULL); }\n";
  }
  aout << spc << "  " << "S *sbp () { return _sbp; }\n";
  aout << spc << "  " << "const S *sbp () const { return _sbp; }\n";

  aout << spc << "  " << "void reject (auth_stat s) "
       << "{ check_reply (); _sbp->reject (s); }\n"
       << spc << "  " << "void reject (accept_stat s) "
       << "{ check_reply (); _sbp->reject (s); }\n"
       << spc << "  " << "void reject () "
       << "{ check_reply (); _sbp->reject (); }\n\n";


  aout << spc << "private:\n"
       << spc << "  void check_reply () "
       << "{ assert (!_replied); _replied = true; }\n"
       << spc << "  bool _replied;\n"
       << spc << "  S *_sbp;\n"
       << spc << "};\n\n";
}
コード例 #2
0
ファイル: hw2.c プロジェクト: mixmash11/CSCI_340_OS
int main( int argc, char** argv ) {
  command_t cmd;
  char line[MAXSTRLEN];
  char fullpath[MAXSTRLEN];
  int done = FALSE;

  while (!done) {
    printf(">> ");
    fgets(line, MAXSTRLEN, stdin);
    line[my_strlen(line)-1] = '\0'; // get rid of newline
    parse(line, &cmd);

    if (my_strequal(cmd.name, "exit")) {
      done = TRUE;
    }
    else if (is_builtin(&cmd)) {
      do_builtin(&cmd);
    }
    else if (find_fullpath(fullpath, &cmd)) {
      // NOTE: find_fullpath() is called again in execute
      execute(&cmd);
    }
    else if (line[0] != '\0') {   // non-blank line entered
      printf("invalid command\n");
    }
    
    cleanup(&cmd);
  }
  
  return 0;
} // end main function
コード例 #3
0
int	exec_course_branch_execute(t_node *root, t_global *global)
{
  int	pid;
  int	signal;
  int	status;

  if (is_builtin(root->content) != -1)
    {
      if ((exec_builtin(root, global)) == EXIT_FAILURE)
	return (EXIT_FAILURE);
      return (EXIT_SUCCESS);
    }
  if ((pid = fork()) == -1)
    return (EXIT_FAILURE);
  if (pid == 0)
    {
      start_signal();
      if ((status = exec_course_branch_select(root, global)) >= EXIT_FAILURE)
	return (status);
    }
  else
    {
      wait(&signal);
      exec_signal(WTERMSIG(signal));
      return((WEXITSTATUS(signal) == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
    }
  return (EXIT_SUCCESS);
}
コード例 #4
0
ファイル: pars.c プロジェクト: person-m/couver-shell
int	is_valide(char **tab, t_shell *sh)
{
  char	**path;
  char	*tmp;
  int	i;

  if (is_builtin(tab[0]) || (slash_in_str(tab[0]) && !access(tab[0], X_OK)))
    return (1);
  path = my_path_tab(sh);
  i = -1;
  while (path[++i])
    {
      tmp = my_malloc(sizeof(char) * (strlen(tab[0]) + strlen(path[i]) + 2));
      tmp = strcpy(tmp, path[i]);
      tmp = strcat(tmp, "/");
      tmp = strcat(tmp, tab[0]);
      if (!access(tmp, X_OK))
	{
	  free(tmp);
	  return (1);
	}
      free(tmp);
    }
  return (0);
}
コード例 #5
0
ファイル: execute.c プロジェクト: argrieve/shell
/*
 * Executes a shell command entered by the user
 * 
 * Parameters:
 *   argc - number of arguments in the command
 *   argv - the user's command
 *   mods - special modifiers for the command
 *
 * Returns:
 *   0 on success, -1 otherwise
 */
int execute_cmd(size_t argc, char *const argv[], const mods_t *const mods)
{
  // Builtin command received
  if (is_builtin(argv[0]))
    return execute_builtin(argc, argv, mods);

  // Non builtin command received
  int ret = fork();
  if (ret == -1)
  {
    // fork() failed in the parent
    perror("ERROR: fork():");
  }
  else if (ret == 0)
  {
    // Child code
    printf("[%d] %s\n", getpid(), argv[0]);
    if (mods->out_file != NULL && redirect_stdout(mods->out_file) == -1)
      return -1;
    execvp(argv[0], argv);
    printf("ERROR: Cannot exec '%s'\n", argv[0]);
    return -1;
  } 
  else 
  {
    // Parent code
    if (mods->bg == 0)
      check_child_status(ret, 0);
  }

  return 0;
}
コード例 #6
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /** The 'kind' of the dtype (int, uint, float, etc) */
 dtype_kind_t get_kind() const {
     if (is_builtin()) {
         return static_cast<dtype_kind_t>(dtype::builtin_kinds[reinterpret_cast<intptr_t>(m_extended)]);
     } else {
         return m_extended->get_kind();
     }
 }
コード例 #7
0
int	exec_select_execution_other(t_node *node, t_global *global)
{
  int	status;
  t_node *tmp;

  if (is_builtin(node->content) != -1)
    {
      if ((exec_builtin(node, global)) == EXIT_FAILURE)
	{
	  global->exit = EXIT_FAILURE;
	  return (EXIT_FAILURE);
	}
      return (EXIT_CHILD);
    }
  else if (my_strsearch(node->content, '$') == 1)
    {
      if ((tmp = parsing_func(node->content, global, 1)) == NULL)
	return (EXIT_CHILD);
      if ((status = exec_course_tree(tmp, global->env, \
				     global)) >= EXIT_FAILURE)
	return (status);
      return (EXIT_CHILD);
    }
  return (EXIT_SUCCESS);
}
コード例 #8
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 inline bool operator==(const dtype& rhs) const {
     if (is_builtin() || rhs.is_builtin()) {
         return m_extended == rhs.m_extended;
     } else {
         return *m_extended == *rhs.m_extended;
     }
 }
コード例 #9
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * The 'at_single' function is used for indexing by a single dimension, without
  * touching any leading dimensions after the first, in contrast to the 'at'
  * function. Overloading operator[] isn't
  * practical for multidimensional objects. Indexing one dimension with
  * an integer index is special-cased, both for higher performance and
  * to provide a way to get a metadata pointer for the result dtype.
  *
  * \param i0  The index to apply.
  * \param inout_metadata  If non-NULL, points to a metadata pointer for
  *                        this dtype that is modified to point to the
  *                        result's metadata.
  * \param inout_data  If non-NULL, points to a data pointer that is modified
  *                    to point to the result's data. If `inout_data` is non-NULL,
  *                    `inout_metadata` must also be non-NULL.
  *
  * \returns  The dtype that results from the indexing operation.
  */
 inline dtype at_single(intptr_t i0, const char **inout_metadata = NULL, const char **inout_data = NULL) const {
     if (!is_builtin()) {
         return m_extended->at_single(i0, inout_metadata, inout_data);
     } else {
         throw too_many_indices(*this, 1, 0);
     }
 }
コード例 #10
0
ファイル: git.c プロジェクト: ovmine/git
static void execv_dashed_external(const char **argv)
{
	struct child_process cmd = CHILD_PROCESS_INIT;
	int status;

	if (get_super_prefix())
		die("%s doesn't support --super-prefix", argv[0]);

	if (use_pager == -1 && !is_builtin(argv[0]))
		use_pager = check_pager_config(argv[0]);
	commit_pager_choice();

	argv_array_pushf(&cmd.args, "git-%s", argv[0]);
	argv_array_pushv(&cmd.args, argv + 1);
	cmd.clean_on_exit = 1;
	cmd.wait_after_clean = 1;
	cmd.silent_exec_failure = 1;

	trace_argv_printf(cmd.args.argv, "trace: exec:");

	/*
	 * If we fail because the command is not found, it is
	 * OK to return. Otherwise, we just pass along the status code,
	 * or our usual generic code if we were not even able to exec
	 * the program.
	 */
	status = run_command(&cmd);
	if (status >= 0)
		exit(status);
	else if (errno != ENOENT)
		exit(128);
}
コード例 #11
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 inline size_t get_metadata_size() const {
     if (is_builtin()) {
         return 0;
     } else {
         return m_extended->get_metadata_size();
     }
 }
コード例 #12
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 inline size_t get_broadcasted_iterdata_size(size_t ndim) const {
     if (is_builtin()) {
         return sizeof(iterdata_broadcasting_terminator);
     } else {
         return m_extended->get_iterdata_size(ndim) + sizeof(iterdata_broadcasting_terminator);
     }
 }
コード例 #13
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /** The size of the data required for uniform iteration */
 inline size_t get_iterdata_size(size_t ndim) const {
     if (is_builtin()) {
         return 0;
     } else {
         return m_extended->get_iterdata_size(ndim);
     }
 }
コード例 #14
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * \brief Constructs the iterdata for processing iteration of the specified shape.
  *
  * \param iterdata  The allocated iterdata to construct.
  * \param inout_metadata  The metadata corresponding to the dtype for the iterdata construction.
  *                        This is modified in place to become the metadata for the uniform dtype.
  * \param ndim      Number of iteration dimensions.
  * \param shape     The iteration shape.
  * \param out_uniform_dtype  This is populated with the dtype of each iterated element
  */
 inline void iterdata_construct(iterdata_common *iterdata, const char **inout_metadata,
                 size_t ndim, const intptr_t* shape, dtype& out_uniform_dtype) const
 {
     if (!is_builtin()) {
         m_extended->iterdata_construct(iterdata, inout_metadata, ndim, shape, out_uniform_dtype);
     }
 }
コード例 #15
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * Gets the number of uniform dimensions in the dtype.
  */
 inline size_t get_undim() const {
     if (is_builtin()) {
         return 0;
     } else {
         return m_extended->get_undim();
     }
 }
コード例 #16
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * Returns a modified dtype with all expression dtypes replaced with
  * their value dtypes, and dtypes replaced with "standard versions"
  * whereever appropriate. For example, an offset-based uniform array
  * would be replaced by a strided uniform array.
  */
 inline dtype get_canonical_dtype() const {
     if (is_builtin()) {
         return *this;
     } else {
         return m_extended->get_canonical_dtype();
     }
 }
コード例 #17
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 inline base_dtype::flags_type get_flags() const {
     if (is_builtin()) {
         return dtype_flag_scalar;
     } else {
         return m_extended->get_flags();
     }
 }
コード例 #18
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 inline bool is_scalar() const {
     if (is_builtin()) {
         return true;
     } else {
         return m_extended->is_scalar();
     }
 }
コード例 #19
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * Returns true if the dtype contains any expression
  * dtype within it somewhere.
  */
 inline bool is_expression() const {
     if (is_builtin()) {
         return false;
     } else {
         return m_extended->is_expression();
     }
 }
コード例 #20
0
ファイル: main.c プロジェクト: plisieck/Minishell
int		exec_env(t_struc *s, char **env2)
{
	int		i;
	int		j;
	int		option_i;
	char	**new_env;

	i = 1;
	j = 1;
	option_i = 0;
	new_env = env2 ? copy_env(env2) : (char **)malloc(sizeof(char *) * 1);
	if (s->argc == 1)
		print_env(new_env);
	else
	{
		if (get_env_options(s, &i, &option_i) == -1)
			return (-1);
		if (option_i)
			new_env = (char **)malloc(sizeof(char *) * 1);
		s->cmd = NULL;
		new_env = exec_env2(s, i, j, new_env);
		if (s->cmd)
			!is_builtin(s) ? exec_cmd(s, new_env) : exec_builtin(s, new_env);
		else
			print_env(new_env);
	}
	return (0);
}
コード例 #21
0
ファイル: ft_sh1.c プロジェクト: WTSC/42_projects
void display_prompt(t_env *env)
{
	char *line;
	pid_t papa;

	ft_putstr("\033[1;1H\033[2J");
	ft_prompt(env);
	while (42)
	{
		if (get_next_line(0, &line) > 0)
		{

			line = ft_strtrim(line);
			line = ft_supertrim(line);
			if (is_multi(line, &env) == 0 && is_builtin(line, &env) == 0)
			{
				papa = sh_fork();
				if (papa == 0)
					ft_parse(env, &line);
				else
					wait(0);
			}
			free(line);
			line = NULL;
			ft_prompt(env);
		}
	}
}
コード例 #22
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /** The element size of the dtype */
 inline size_t get_data_size() const {
     if (is_builtin()) {
         return static_cast<size_t>(dtype::builtin_data_sizes[reinterpret_cast<intptr_t>(m_extended)]);
     } else {
         return m_extended->get_data_size();
     }
 }
コード例 #23
0
ファイル: xcommand.c プロジェクト: NegMozzie/42
int				execute_simple_command(t_tree *tree, t_shell **shell)
{
	int			flag;
	int			statut;
	pid_t		pid;

	statut = 0;
	if (is_builtin(tree->argv[0]))
		return (builtins_center(shell, tree));
	if (tree && (flag = prepare_command(tree, *shell)) != EXIT_SUCCESS)
		return (flag);
	if ((pid = fork()) == 0)
	{
		dup2(tree->fd[0], STDIN_FILENO);
		dup2(tree->fd[1], STDOUT_FILENO);
		if ((execve(tree->argv[0], tree->argv, (*shell)->envc)) == -1)
			perror(strerror(errno));
		exit(0);
	}
	else if (pid > 0)
	{
		if (waitpid(pid, &statut, 0) == -1)
			perror("Waitpid");
		return (write_statut(statut));
	}
	return (FATAL_ERROR);
}
コード例 #24
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * The type number is an enumeration of data types, starting
  * at 0, with one value for each unique data type. This is
  * inspired by the approach in NumPy, and the intention is
  * to have the default
  */
 type_id_t get_type_id() const {
     if (is_builtin()) {
         return static_cast<type_id_t>(reinterpret_cast<intptr_t>(m_extended));
     } else {
         return m_extended->get_type_id();
     }
 }
コード例 #25
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * For expression dtypes, returns the operand dtype,
  * which is the source dtype of this dtype's expression.
  * This is one link down the expression chain.
  */
 const dtype& operand_dtype() const {
     // Only expression_kind dtypes have different operand_dtype
     if (is_builtin() || m_extended->get_kind() != expression_kind) {
         return *this;
     } else {
         return static_cast<const base_expression_dtype *>(m_extended)->get_operand_dtype();
     }
 }
コード例 #26
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * Returns true if the dtype represents a chunk of
  * consecutive memory of raw data.
  */
 inline bool is_pod() const {
     if (is_builtin()) {
         return true;
     } else {
         return m_extended->get_data_size() > 0 &&
                         (m_extended->get_flags() & (dtype_flag_blockref|
                                         dtype_flag_destructor)) == 0;
     }
 }
コード例 #27
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 inline dtype get_dtype_at_dimension(char **inout_metadata, size_t i, size_t total_ndim = 0) const {
     if (!is_builtin()) {
         return m_extended->get_dtype_at_dimension(inout_metadata, i, total_ndim);
     } else if (i == 0) {
         return *this;
     } else {
         throw too_many_indices(*this, total_ndim + i, total_ndim);
     }
 }
コード例 #28
0
ファイル: dtype.hpp プロジェクト: jieah/dynd
 /**
  * Returns the non-expression dtype that this
  * dtype looks like for the purposes of calculation,
  * printing, etc.
  */
 const dtype& value_dtype() const {
     // Only expression_kind dtypes have different value_dtype
     if (is_builtin() || m_extended->get_kind() != expression_kind) {
         return *this;
     } else {
         // All chaining happens in the operand_dtype
         return static_cast<const base_expression_dtype *>(m_extended)->get_value_dtype();
     }
 }
コード例 #29
0
ファイル: shell.c プロジェクト: dklambauer/shell
/**
 * Executes a simple command (no pipes).
 */
int execute_simple_command(simple_command *cmd) {

    /**
     * Check if the command is builtin.
     * 1. If it is, then handle BUILTIN_CD (see execute_cd function provided) 
     *    and BUILTIN_EXIT (simply exit with an appropriate exit status).
     * 2. If it isn't, then you must execute the non-builtin command. 
     * - Fork a process to execute the nonbuiltin command 
     *   (see execute_nonbuiltin function above).
     * - The parent should wait for the child.
     *   (see wait man pages).
     */
    int command_number;
    /* Handle builtin commands. */
    if((command_number = is_builtin(*(cmd->tokens)))) {
        switch(command_number) {
            case(BUILTIN_CD):
                if(execute_cd(cmd->tokens) != EXIT_SUCCESS) {
                    printf("No such file or directory.\n");
                }
                return 0;
                break;
            case(BUILTIN_EXIT):
                return -1;
                break;
        }
    /* Handle nonbuiltin commands.
     * Fork a process and use execute_nonbuiltin to execute the command.
     */
    } else {
        int pid;
        if((pid = fork()) < 0) {
            perror("fork");
            return EXIT_FAILURE;
        } else if (pid == 0) { //child
            /* The exit status of the child process will be the return value
             * of execute_nonbuiltin (if there is an error), or the exit
             * status of the command exec'd.
             */
            exit(execute_nonbuiltin(cmd));
        } else { //parent
            int status;
            /* Wait for the command to return, then return its exit status*/
            if(wait(&status) != -1) {
                if(WIFEXITED(status)) {
                    return WEXITSTATUS(status);
                } else {
                    return EXIT_FAILURE;
                }
            } else {
                perror("wait");
                return EXIT_FAILURE;
            }
        }
    }
    return EXIT_FAILURE;
}
コード例 #30
0
ファイル: shell.c プロジェクト: imnxllet/CSC209
/**
 * Executes a simple command (no pipes).
 */
int execute_simple_command(simple_command *cmd) {

	/**
	 * TODO: 
	 * Check if the command is builtin.
	 * 1. If it is, then handle BUILTIN_CD (see execute_cd function provided) 
	 *    and BUILTIN_EXIT (simply exit with an appropriate exit status).
	 * 2. If it isn't, then you must execute the non-builtin command. 
	 * - Fork a process to execute the nonbuiltin command 
	 *   (see execute_nonbuiltin function above).
	 * - The parent should wait for the child.
	 *   (see wait man pages).
	 */
	if(cmd->builtin != 0){
	    if(is_builtin(cmd->tokens[0]) == BUILTIN_CD){
		 execute_cd(cmd->tokens);
		 

	    }else if(is_builtin(cmd->tokens[0]) == BUILTIN_EXIT){
		 return -1;
	    }    

	}else{
             int r,status; 
	     if ((r = fork()) == -1){ // fork failed 
                 perror("fork"); 
	         exit(-1); 
	       
	    } 
	     else if (r > 1){ // parent process 
                 wait(&status); 
	       
	    } else if (r == 0){ // child process 
                 execute_nonbuiltin(cmd);
		 exit(1);
	      
	    }
	}
	return 0;
	
}