• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ parseline函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中parseline函数的典型用法代码示例。如果您正苦于以下问题:C++ parseline函数的具体用法?C++ parseline怎么用?C++ parseline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parseline函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: config_loadfile

Config* config_loadfile(const char* path) {
	FILE* fp = fopen(path, "r");
	if (fp == NULL) {
		return NULL;
	}

	Config* conf = malloc(sizeof(Config));
	if (conf == NULL) {
		//TODO will currently give a ERR_CONFIG error, should give ERR_OOM
		fclose(fp);
		return NULL;
	}

	char line[256];
	Pair* current = NULL;
	while (fgets(line, sizeof(line), fp) != NULL) {
		Pair* p = parseline(line);
		if (p != NULL) {
			if (current == NULL) {
				current = p;
				conf->first = current;
			} else {
				current->next = p;
			}
		}
	}

	fclose(fp);
	return conf;
}
开发者ID:Hamcha,项目名称:iotaid,代码行数:30,代码来源:config.c


示例2: main

main(int argc, char *argv[])
{
   float themeans[MAXREADBACKS];
   float thessds[MAXREADBACKS];
   float thecounts[MAXREADBACKS];

   int x;

   char theline[512];

   for(x=0;x<MAXREADBACKS; x++)
      themeans[x] = thessds[x] = thecounts[x] = 0.0;


   mkdir(argv[1],0755);

   while(gets(theline) != NULL)
   {
      if(
          (strncmp(theline,"_SCAN",5) == 0) &&     /* ONLY DO SCAN LINES  */
          ( isdigit(theline[strlen(theline)-2]) )  /* WITH NUMBERS...     */
        )                                          /* -2 for ^M or "3.23" */
        {                                          /* so is ok either way */
           parseline(theline,themeans,thessds,thecounts, argv[1]);
        }
   }
   printstats(themeans, thessds, thecounts, argv[1]);
}
开发者ID:AlexandreBurel,项目名称:pwiz-mzdb,代码行数:28,代码来源:procraw.c


示例3: eval

/* 
 * eval - Evaluate the command line that the user has just typed in
 * 
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.  
*/
void eval(char *cmdline) 
{
    char *argv[MAXARGS];
    int isBG = parseline(cmdline, argv);
    if (argv[0] == NULL) return;
    if (builtin_cmd(argv)) return;

    sigset_t allset;
    sigfillset(&allset);

    sigprocmask(SIG_BLOCK, &allset, NULL);
    pid_t childpid = fork();
    if (childpid == -1) unix_error("fork failed");
    if (childpid == 0) {
        sigprocmask(SIG_UNBLOCK, &allset, NULL);
        if (setpgid(0, 0) == -1)  unix_error("setpgrp failed");
        if (execv(argv[0], argv) == -1) unix_error("execv failed");
    } 

    if (isBG) {
        addjob(jobs, childpid, BG, cmdline);
        printjob(jobs, childpid);
        sigprocmask(SIG_UNBLOCK, &allset, NULL);
    } else {
        addjob(jobs, childpid, FG, cmdline);
        sigprocmask(SIG_UNBLOCK, &allset, NULL);
        waitfg(childpid);
    }

    return;
}
开发者ID:GHScan,项目名称:DailyProjects,代码行数:42,代码来源:tsh.c


示例4: processline

void processline(bc *bc, char *line)
{
char token[64], *lp;
struct cmd *cmd;

	lp=line;
	gettoken(token, sizeof(token), &lp);
	skipwhite(&lp);

	cmd=commandlist;
	while(cmd->name)
	{
		if(!strncmp(token, cmd->name, strlen(token)))
		{
			cmd->func(bc, lp);
			return;
		}
		++cmd;
	}
	if(line[0]>='0' && line[0]<='9') // line number
	{
		bc->flags |= BF_NOPROMPT;
		lp=line;
		while(*lp>='0' && *lp<='9') ++lp;
		if(*lp)
			addline(bc, line);
		else
			deleteline(bc, atoi(line));
	} else if(*line)
	{
		parseline(bc, line);
	} else
		bc->flags |= BF_NOPROMPT;
}
开发者ID:nssilva,项目名称:SDL,代码行数:34,代码来源:basic.c


示例5: aiccu_LoadConfig

/* configure this client */
bool aiccu_LoadConfig(const char *filename)
{
	FILE			*f;
	char			buf[1000];
	char			filenames[256];
	unsigned int		line = 0;

	if (!filename)
	{
		aiccu_LocateFile(AICCU_CONFIG, filenames, sizeof(filenames));
		filename = filenames;
	}

	f = fopen(filename, "r");
	if (!f)
	{
		dolog(LOG_ERR, "Could not open config file \"%s\"\n", filename);
		return false;
	}

	while (fgets(buf, sizeof(buf), f))
	{
		line++;
		if (parseline(buf, " ", aiccu_conf_rules, g_aiccu)) continue;

		dolog(LOG_WARNING, "Unknown configuration statement on line %u of %s: \"%s\"\n", line, filename, buf);
	}
	fclose(f);

	return true;
}
开发者ID:twikz,项目名称:maiccu,代码行数:32,代码来源:aiccu.c


示例6: main

int main(int argc, char **argv) {
	int i;
	FILE *fd;
	char *file, buf[1024];
	if (argc==1 || !strcmp (argv[1], "-h")) {
		fprintf (stderr, "Usage: rarun2 [''|script.rr2] [options ...]\n"
			"> options are file directives:\n");
		printf (
			"program=/bin/ls\n"
			"arg1=/bin\n"
			"# arg#=...\n"
			"setenv=FOO=BAR\n"
			"timeout=3\n"
			"# connect=localhost:8080\n"
			"# listen=8080\n"
			"# stdout=foo.txt\n"
			"# stdin=input.txt\n"
			"# input=input.txt\n"
			"# chdir=/\n"
			"# chroot=/mnt/chroot\n"
			"# preload=/lib/libfoo.so\n"
			"# setuid=2000\n"
			"# seteuid=2000\n"
			"# setgid=2001\n"
			"# setegid=2001\n");
		return 1;
	}
	file = argv[1];
	if (*file) {
		fd = fopen (file, "r");
		if (!fd) {
			fprintf (stderr, "Cannot open %s\n", file);
			return 1;
		}
		for (;;) {
			fgets (buf, sizeof (buf)-1, fd);
			if (feof (fd)) break;
			buf[strlen (buf)-1] = 0;
			parseline (buf);
		}
		fclose (fd);
	} else {
		for (i=2; i<argc; i++)
			parseline (argv[i]);
	}
	return runfile ();
}
开发者ID:ericfode,项目名称:radare2,代码行数:47,代码来源:rarun2.c


示例7: eval

/* 
 * eval - Evaluate the command line that the user has just typed in.
 * 
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately.  Otherwise, fork a child process and
 * run the job in the context of the child.  If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.  
 *
 * Requires:
 *   "cmdline" is a NUL ('\0') terminated string with a trailing
 *   '\n' character.  "cmdline" must contain less than MAXARGS
 *   arguments.
 *
 * Effects:
 *   A built-in command is executed immediately. Otherwise, it attempts 
 *   to fork a child process and execute the job. If necessary, the 
 *   executable program is searched through the directories of the 
 *   search path. If not found, an error is thrown. If the job is
 *   running as a foreground job, it waits until completion.  
 */
static void
eval(const char *cmdline) 
{
	char *argv[MAXARGS];
	int bg = parseline(cmdline, argv);
	pid_t pid;
	sigset_t mask;
	
	// Checks command line is not empty.
	if (!argv[0]) {
		return;
	}

	// Checks that the command is not a built-in command.
	if(!builtin_cmd(argv)){
		sigemptyset(&mask);
		sigaddset(&mask, SIGCHLD);
		sigprocmask(SIG_BLOCK, &mask, NULL);

		// A child is forked. 
		pid = fork();
		if (pid == 0) {
			// Put child in new group whose ID is identical to child’s PID.
			setpgid(0, 0);
			sigprocmask(SIG_UNBLOCK, &mask, NULL);

			if (execve(argv[0], argv, environ) == -1) {
				int index = 0;
				// Run through directories in search path to execute program.
				while (argv[0][0] != '.' && index < directoryCount) {
					if (execve(strcat(directories[index],argv[0]), argv, environ) != -1) {
						break;
					}
					index++;
				}
				// Command not found.
				char *print;
				asprintf(&print, "%s: Command not found\n", argv[0]);
				sio_error(print);
			} 
		}
	

		if (bg == 0) {
			addjob(jobs,pid,FG,cmdline);
			sigprocmask(SIG_UNBLOCK, &mask, NULL);
			// Wait for foreground jobs to complete.
			waitfg(pid);
		}
		else {
			addjob(jobs,pid,BG,cmdline);
			sigprocmask(SIG_UNBLOCK, &mask, NULL);
			printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline); 
		}
	}
 
	return;
}
开发者ID:yejinalicekim,项目名称:shell,代码行数:81,代码来源:tsh.c


示例8: execute

/**
Funkcja wykonuje komendę w procesie potomnym.
*/
void execute()
{
    line* ln = NULL;
    command* com = NULL;
    int i;
    /**printf("STRLEN %d\n", strlen(buffer_to_parse));*/
   /// for(i=0;i<strlen(buffer_to_parse);++i)
       /// printf("%c", buffer_to_parse[i]);
    ///printf("\n");
    ln = parseline(buffer_to_parse);
    if((ln == NULL) || (*(ln->pipelines) == NULL) || (**(ln->pipelines) == NULL))
    {
        ///printf("LN NULL\n");
        printf("%s\n", SYNTAX_ERROR_STR);
        fflush(stdout);
        return ;
    }

    com = pickfirstcommand(ln);
    if((com == NULL) || (com->argv == NULL) || (com->argv[0] == NULL))
    {
        ///printf("COM NULL\n");
        if(buffer_to_parse[0] != '#') /** jeśli linia nie jest komentarzem */
        {
            ///printf("COM NULL\n");
            ///printf("%s\n", buffer_to_parse);
            printf("%s\n", SYNTAX_ERROR_STR);
        }
        fflush(stdout);
        return ;
    }

    int child_pid = fork();
    if(child_pid == -1)
        exit(1);

    if(child_pid > 0) /// parent
    {
        int wait_status = waitpid(child_pid, NULL, 0);
        if(wait_status == -1)
            exit(1);
    }
    else /// child
    {
        int exec_status = execvp(com->argv[0], com->argv);
        if(exec_status == -1)
        {
            if(errno == ENOENT) /** 2 */
                fprintf(stderr, "%s: no such file or directory\n", com->argv[0]);
            else if(errno == EACCES) /** 13 */
                fprintf(stderr, "%s: permission denied\n", com->argv[0]);
            else
                fprintf(stderr, "%s: exec error\n", com->argv[0]);
            fflush(stdout);
            exit(EXEC_FAILURE);
        }
    }
}
开发者ID:MacWoz,项目名称:minixShell,代码行数:61,代码来源:2014-10-26.c


示例9: eval

/* 
 * eval - Evaluate the command line that the user has just typed in
 * 
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.  
*/
void eval(char *cmdline) 
{
    char *argv[MAXARGS];
	char buf[MAXLINE];
	int bg;
	sigset_t mask;
	pid_t pid;
	
	strcpy(buf, cmdline);
	bg = parseline(buf, argv);
	if(argv[0] == NULL)
		return;

	if(!builtin_cmd(argv)){
		
		//block signal
		if(sigemptyset(&mask) < 0)
			unix_error("sigemptyset error");
		if(sigaddset(&mask, SIGCHLD) < 0)
			unix_error("sigaddset error");
		if(sigprocmask(SIG_BLOCK, &mask, NULL) < 0)
			unix_error("sigprocmask error");

		if((pid = fork()) == 0){

			//set pid group to be the same as the current pid
			if(setpgid(0,0) < 0)
				unix_error("eval: set pid group error");

			//unblock siganl
			if(sigprocmask(SIG_UNBLOCK, &mask, NULL) < 0)
				unix_error("sigprocmask error");

			//execute program
			if(execve(argv[0], argv, environ)<0){
				printf("%s: Command not found.\n", argv[0]);
				exit(1);
			}
		}
		
		if(!bg){
			addjob(jobs, pid, FG, cmdline);

			//unblock siganl
			if(sigprocmask(SIG_UNBLOCK, &mask, NULL) < 0)
				unix_error("sigprocmask error");
			waitfg(pid);
		}else{
			addjob(jobs, pid, BG, cmdline);

			//unblock siganl
			if(sigprocmask(SIG_UNBLOCK, &mask, NULL) < 0)
				unix_error("sigprocmask error");
			printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline);
		}
	}
    return;
}
开发者ID:vvv214,项目名称:icsLab,代码行数:69,代码来源:tsh.c


示例10: iniFile

void iniLoader::loadIniDoc(const string& filename, iniDoc& doc){
	loadingDoc = &doc;
	ifstream iniFile(filename, ifstream::in);
	string line;
	int i = 1;
	while(getline(iniFile,line)){
		parseline(line, i++);
	}
}
开发者ID:nodj,项目名称:omg,代码行数:9,代码来源:ini.cpp


示例11: eval

/* 
 * eval - Evaluate the command line that the user has just typed in
 * 
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.  
*/
void eval(char *cmdline) 
{
    char * argv[MAXARGS];
    int bg = parseline(cmdline, argv);
    int rbic = builtin_cmd(argv);

    if (!rbic)
    {
        pid_t child = fork();
        //printf("forked\n");
        
        if (child)
        {      
            //PARENT    
            if (bg)
            {
                int ret = addjob(jobs, child, BG, cmdline); //returns an int
                if (ret)
                {
                    int jid = pid2jid(child);
                    printf("[%d] (%d) %s", jobs[jid-1].jid, jobs[jid-1].pid, jobs[jid-1].cmdline);
                }
                else
                {
                    printf("addjobfailed\n");
                }
            }
            else
            {
                int ret = addjob(jobs, child, FG, cmdline); //returns an int
                if (!ret)
                {
                    printf("addjobfailed\n");
                }
                waitfg(child);
            }
        }
        else if( child < 0 )
        {
            //ERROR
            exit(1); 
        }
        else
        {
            //CHILDS
            setpgid( 0, 0 );
            int rc = execv( argv[0], argv );
            if (rc == -1)
            {
                printf( "execv error %d\n", errno);
                exit(1);
            }
        }
    }
    return;
    
}
开发者ID:nmank,项目名称:comp-organization,代码行数:68,代码来源:tsh.c


示例12: parse

void parse(FILE *source_file, char *filename, LIST *mapping)
{
    int linenum = 0;
    char line[LINE_LENGTH + 1];
    while(fgets(line, LINE_LENGTH, source_file) != NULL)
    {
        parseline(line, ++linenum, filename, mapping);
    }
}
开发者ID:alon7786,项目名称:mmn14,代码行数:9,代码来源:parse.c


示例13: eval

/* eval - Evaluate a command line */
void eval(char *cmdline) 
{

    char *argv[MAXARGS]; /* Argument list execve() */
    char buf[MAXLINE];   /* Holds modified command line */
    int bg;              /* Should the job run in bg or fg? */
    pid_t pid;           /* Process id */

    signal(SIGCHLD, reaperthegrim);
    strcpy(buf, cmdline);
        bg = parseline(buf, argv);  
    //bg = p3parseline(buf, argv); /* call new parseline function for cs485 project 3 */
    if (argv[0] == NULL)  
	return;   /* Ignore empty lines */
    
    if (!builtin_command(argv)) { 
	if ((pid = fork()) == 0) {   /* Child runs user job */
	    if (execve(argv[0], argv, environ) < 0) {
		printf("%s: Command not found.\n", argv[0]);
		exit(0);
	    }
	}

	/* Parent waits for foreground job to terminate */
	if (!bg) {
	    int status;
	    if (waitpid(pid, &status, 0) < 0)
		unix_error("waitfg: waitpid error");
	}
	else{
	    printf("%d %s", pid, cmdline);
	    int i =0;
	    int ctr = 1;
	    while(ctr==1)
                {
			//puts the pid into the PIDS array so we can keep track of all pids
                        if(PIDS[i]==0)
                        {
                                PIDS[i]=pid;
                                ctr=0;
			}
                        else
                        {
                                i++;
                        }
                }
	   }
         }

    in = 0;
    out = 0;
    inpos = 0;
    outpos = 0;
    
    return;
}
开发者ID:kevinlogan94,项目名称:CS_Projects,代码行数:57,代码来源:upsh.c


示例14: main

/* ----------------------------------------------------------------- */
int main(void)
{
 char cmdline[MAXLINE];
 char *argv[MAXARGS];
 int argc;
 int status;
 pid_t pid;

 /* Loop forever to wait and process commands */
 while (1)
 {
  /* Step 1: Name your shell: csc60mshell - m for mini shell */ 
  printf("miniShell> ");
  fgets(cmdline, MAXLINE, stdin);
  argc = parseline(cmdline, argv); // call parseline to parse commands and options
  if (argv[0] == NULL)
	continue;  // blank entry just gets ignored
  else if (strcmp("exit", argv[0] ) == 0)
	exit(0); // exits the mini shell built in commands
  else if (strcmp("cd", argv[0] ) == 0)
  {
	if (argv[1] == NULL)
	{
		chdir(getenv("HOME")); // cd chdir with no arguments defaults to home
		setenv("PWD", getenv("HOME"), 1);  // updates the PWD directory variable too
	}
	else if (argv[1]!= NULL)
	{
		if (chdir(argv[1]) != 0) // cd dir to desired path
			perror(argv[1]); // if not sucessful print error

		setenv("PWD", argv[1], 1); // updates the PWD directory variable too
	}
  }
  else if (strcmp("pwd", argv[0] ) == 0)
	printf("%s\n", getenv("PWD")); // print current working directory
  else
  {
 	pid = fork();
  	if (pid == -1) 
    	perror("Shell Program fork error");
  	else if (pid == 0) 
		/* I am child process. I will execute the command, call: execvp */
    	process_input(argc, argv);
  	else
   { 
		/* I am parent process */
    	if (wait(&status) == -1)
			perror("Shell Program error");
    	else
      	    printf("Child returned status: %d\n",status);
	}
  }
 } // end while
 return 0;  
} // end main
开发者ID:portillo09,项目名称:miniUnixShell,代码行数:57,代码来源:csc60mshell.c


示例15: project_get_books

CheckValidateUsfm::CheckValidateUsfm(const ustring & project, const vector < unsigned int >&books, bool gui, bool checksheet)
/*
It performs checks related to the USFM standard.
project: project to check.
books: books to check; if empty it checks them all.
gui: whether to show graphical progressbar.
checksheet: check whether markers are in the stylesheet of the project.
*/
{
  // Init variables.
  cancelled = false;
  mychecksheet = checksheet;
  // Get a list of the books to check. If no books were given, take them all.
  vector < unsigned int >mybooks(books.begin(), books.end());
  if (mybooks.empty())
    mybooks = project_get_books(project);
  // Get all styles in the attached stylesheet.
  vector <ustring> styless = stylesheet_get_markers(stylesheet_get_actual (), NULL);
  for (unsigned int i = 0; i < styless.size(); i++)
    styles.insert(styless[i]);
  // GUI.
  progresswindow = NULL;
  if (gui) {
    progresswindow = new ProgressWindow(_("Validating markers"), true);
    progresswindow->set_iterate(0, 1, mybooks.size());
  }
  // Check each book.
  for (unsigned int bk = 0; bk < mybooks.size(); bk++) {
    if (gui) {
      progresswindow->iterate();
      progresswindow->set_text(books_id_to_english(book));
      if (progresswindow->cancel) {
        cancelled = true;
        return;
      }
    }
    book = mybooks[bk];
    // Check each chapter.
    vector <unsigned int> chapters = project_get_chapters(project, book);
    for (unsigned int ch = 0; ch < chapters.size(); ch++) {
      chapter = chapters[ch];
      vector <ustring> verses = project_get_verses(project, book, chapter);
      // Check each verse.
      for (unsigned int vs = 0; vs < verses.size(); vs++) {
        verse = verses[vs];
        ustring line = project_retrieve_verse(project, book, chapter, verse);
        // Check each line.
        ParseLine parseline(line);
        for (unsigned int ln = 0; ln < parseline.lines.size(); ln++) {
          check(parseline.lines[ln]);
        }
      }
    }
  }
}
开发者ID:alerque,项目名称:bibledit,代码行数:55,代码来源:check_validate_usfm.cpp


示例16: eval

/*
 * eval - Evaluate the command line that the user has just typed in
 *
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.
 */
void
eval(char *cmdline)
{
    int bg;              /* should the job run in bg or fg? */
    struct cmdline_tokens tok;
    sigset_t prev, mask_all;
    int state;
    pid_t pid;
    struct job_t *job_ins;

    /* Parse command line */
    bg = parseline(cmdline, &tok);

    if (bg == -1) /* parsing error */
        return;
    if (tok.argv[0] == NULL) /* ignore empty lines */
        return;

    /* Fig. 8.40 */
    if (!builtin_command(&tok)) {
        Sigemptyset(&mask_all);
        Sigaddset(&mask_all, SIGCHLD);
        Sigaddset(&mask_all, SIGINT);
        Sigaddset(&mask_all, SIGTSTP);
        Sigprocmask(SIG_BLOCK, &mask_all, &prev); /* Block at beginning */

        if ((pid = Fork()) == 0) { /* Child process */
            Sigprocmask(SIG_SETMASK, &prev, NULL); /* Unblock inside child */
	    Setpgid(0, 0); /* one proc and shell in pgrp */

	    open_dup2_in(tok.infile);
	    open_dup2_out(tok.outfile);
	    if (execve(tok.argv[0], tok.argv, environ) < 0) {
	        printf("%s: Command not found.\n", tok.argv[0]);
	        exit(0);
	    }
	}

        /* Parent process */

        state = bg ? BG : FG;
        addjob(job_list, pid, state, cmdline);
        job_ins = getjobpid(job_list, pid);

        Sigprocmask(SIG_SETMASK, &prev, NULL); /* Unblock 3 signals */

        if (bg) {
            printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline);
        } else {
            wait_fg_job(job_ins -> state);
        }
    }

    return;
}
开发者ID:Canon15214,项目名称:15213-ICS-Fall15,代码行数:66,代码来源:tsh.c


示例17: eval

void eval(char *cmdline) {
    char *argv[MAXARGS]; // argv pour execve()
    char buf[MAXLINE]; // contient ligne commande modifiee
    int bg; // arriere-plan ou premier plan ?
    pid_t pid; // process id

    int indexJobLibre;

    strcpy(buf, cmdline);
    bg = parseline(buf, argv);
    if (argv[0] == NULL)
        return; // ignorer lignes vides

    if (!builtin_command(argv)) { // commande integree ?
        // si oui, executee directement
        if ((pid = Fork()) == 0) { // si non, executee par un fils
            setpgid(0, 0);

            if (execvp(argv[0], argv) < 0) {
                printf("%s: Command not found.\n", argv[0]);
                exit(0);
            }
        }

        indexJobLibre = getIndexLibre();
        tabJobs[indexJobLibre] = malloc(sizeof (job));
        tabJobs[indexJobLibre]->pid = pid;
        strcpy(tabJobs[indexJobLibre]->commande, argv[0]);


        if (!bg) { // le pere attend fin du travail de premier plan

            tabJobs[indexJobLibre]->etat = FG;
            printf("dans !bg: commande = %s\n", tabJobs[indexJobLibre]->commande);
            printf("getIndexFG() = %d --\n", getIndexFG());


        } else { // travail d'arriere-plan, on imprime le pid
            tabJobs[indexJobLibre]->etat = BG;
            printf("%d %s", pid, cmdline);


        }

    }

    while (getIndexFG() != -1) {
        printf("verif FG = %d\n", getIndexFG());
        afficheJobs();
        sleep(1);
    }


    return;
}
开发者ID:Schwingg,项目名称:shell,代码行数:55,代码来源:eval.c


示例18: main

int
main(int argc, char **argv)
{
	int line, tokens;
	char buffer[BUFSIZ], *inputline, *token[GV_MAXARGS];

	/* Load the module if necessary. */
	if (modfind(GVINUMMOD) < 0) {
		if (kldload(GVINUMKLD) < 0 && modfind(GVINUMMOD) < 0)
			err(1, GVINUMKLD ": Kernel module not available");
	}

	/* Arguments given on the command line. */
	if (argc > 1) {
		argc--;
		argv++;
		parseline(argc, argv);

	/* Interactive mode. */
	} else {
		for (;;) {
			inputline = readline("gvinum -> ");
			if (inputline == NULL) {
				if (ferror(stdin)) {
					err(1, "can't read input");
				} else {
					printf("\n");
					exit(0);
				}
			} else if (*inputline) {
				add_history(inputline);
				strcpy(buffer, inputline);
				free(inputline);
				line++;		    /* count the lines */
				tokens = gv_tokenize(buffer, token, GV_MAXARGS);
				if (tokens)
					parseline(tokens, token);
			}
		}
	}
	exit(0);
}
开发者ID:2asoft,项目名称:freebsd,代码行数:42,代码来源:gvinum.c


示例19: eval

/*
 * eval - Evaluate the command line that the user has just typed in
 *
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.
 */
void eval(char *cmdline)
{
    // Get memory for our parsed input
    char temp[MAXLINE];
    char** argv = (char**)temp;
    // Return if only newline
    if (strcmp(cmdline, "\n") == 0) {
        return;
    }
    // Parse the input
    int background = parseline(cmdline, argv);
    // Check if built in command
    if (builtin_cmd(argv) == 0) {
        // Not a built in command
        char* programName = argv[0];

        // Block sigchild signal
        sigset_t mask;
        Sigemptyset(&mask);
        Sigaddset(&mask, SIGCHLD);
        Sigprocmask(SIG_BLOCK, &mask, NULL);

        // Create a child process
        pid_t pid = Fork();

        // Unblock sichild signal
        Sigprocmask(SIG_UNBLOCK, &mask, NULL);
        if (pid == 0) {
            // Child
            // Assign it a new process group id
            setpgid(0,0);
            // Run the external program
            Execve(programName, argv, environ);
        }
        else {
            // Parent
            if (background == 0) {
                // Add it to the list
                addjob(jobs, pid, FG, cmdline);
                // Make the shell wait for the process in the fg
                waitfg(pid);
            }
            else {
                // Add it to the list
                addjob(jobs, pid, BG, cmdline);
                // Get the job id
                int jid = pid2jid(pid);
                // Print info on background job
                printf("[%d] (%d) %s", jid, pid, cmdline);
            }
        }
    }
    return;
}
开发者ID:athorhallsson,项目名称:tinyshell,代码行数:65,代码来源:tsh.c


示例20: eval

void eval(char *cmdline,task_struct* head)
{
    pid_t pid;
    task_struct* node;
    int bg;
    char *arg[MAXARGC];
    char buf[MAXBUF];

    strcpy(buf,cmdline);
    bg = parseline(buf,arg);

    if(!quit(arg))
    {
        if(fgbg(head,arg) != 0)
        {
            return ;
        }
        if(printPid(arg) != 0)
        {
            return;
        }
        pid = Fork();
        if(pid != 0)
        {
            node = (task_struct*)Malloc(sizeof(task_struct));
            taskop(arg[0],pid,bg,node);
            add_tail_to_task(head,node);
        }
        if(pid == 0)
        {
            if(execve(arg[0],arg,environ) < 0)
            {
                printf("%s: command not found\n",arg[0]);
                exit(8);
            }
        }
        if(!bg)
        {
            int status;
            if(waitpid(pid,&status,0) < 0) unix_error("waitpid error");
            if(WIFEXITED(status))
            {
                printf("%d is removed\n",node->pid);
                delete_node(node);
            }
        }
        else
        {
            printf("%d %s\n",pid,cmdline);
        }

    }
    return ;
}
开发者ID:Sevendeadlys,项目名称:myshell,代码行数:54,代码来源:mysh.c



注:本文中的parseline函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ parser函数代码示例发布时间:2022-05-30
下一篇:
C++ parseip函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap