int main() { char *cmdline, *prompt, **arglist, **cmdlist; char rfileName[32]; int result, fd_out, i, fno, cmdNum, rioFlag; int sfd = dup(STDOUT_FILENO); void setup(); prompt = DFL_PROMPT; setup(); cmdlist = emalloc(BUFSIZ); while ((cmdline = next_cmd(prompt, stdin)) != NULL) { /* io redirection */ rioFlag = getRFileName(cmdline, rfileName); if (rioFlag > 0) fd_out = r_open(rfileName); /* pipe test*/ cmdNum = pipeTest(cmdline, cmdlist); if (cmdNum == 1) { if ((arglist = splitline(cmdline)) != NULL) { if (buildIn(arglist)) { ; } else { result = execute(arglist); freelist(arglist); } } } else if (cmdNum == 2) { pipeCommand(cmdlist); } //freelist(cmdlist); free(cmdline); if (rioFlag > 0) r_close(sfd); } return 0; }
int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; atexit(safeExit); // init log system gp_log_init(APP_LOGFILE); // Get some application/host data appInfo(); /* if (isAppRunning()) { printf("Application is already running\n"); exit(0); g_critical("Application is already running"); } */ // parse command line arguments context = g_option_context_new (APP_DESCRIPTION); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } // enable verbose mode if (opt_verbose) { gp_log_set_verbose(TRUE); } g_message("Program start\n"); // print version information if (opt_version) { printf("Program version %s\nBuild ("__DATE__" "__TIME__")\n", APP_VERSION); exit(0); } // Error Test if (opt_errorTest) { errorTest(); exit(0); } // thread test if (opt_threadTest) { threadTest(); exit(0); } // info test if (opt_info) { infoTest(); exit(0); } // daemon test if (opt_daemonTest) { daemonTest(); exit(0); } // queue test if (opt_queueTest) { queueTest(); exit(0); } // pipe test if (opt_pipeTest) { pipeTest(); exit(0); } // domain socket test if (opt_domainTest) { domainTest(); exit(0); } return 0; }