void ServerConsole::ExecuteScript(const char* script) { const char* bufptr = script; while ( *bufptr != 0) { // skip empty lines while (*bufptr == '\n') bufptr++; char line[1000]; size_t len = strcspn(bufptr, "\n"); memcpy (line, bufptr, len); line[len] = '\0'; bufptr += len; char* strippedline = stripwhite(line); if ((strippedline[0] == '#') || (strippedline[0] == '\0')) continue; char actualcommand[1000]; strcpy(actualcommand, strippedline); size_t commentbegin = strcspn(actualcommand, "#"); actualcommand[commentbegin] = '\0'; if (actualcommand[0] == '\0') continue; CPrintf (CON_CMDOUTPUT, COL_BLUE "%s: " COL_NORMAL, prompt); CPrintf (CON_CMDOUTPUT, "%s\n", actualcommand); execute_line(actualcommand,NULL); } }
void ServerConsole::MainLoop() { while (!stop) { char *s; char cmdprompt[80]; char *line; cs_snprintf (cmdprompt,80, COL_BLUE "%s: " COL_NORMAL, prompt); line = NULL; while (line == NULL) { line = readline(cmdprompt); /* TODO: Yield timeslice here maybe? */ } s=stripwhite(line); if (*s) { #ifdef USE_HISTORY add_history(s); #endif execute_line(s,NULL); } free(line); } }
/* this is the command execution machine */ void Parser_commands(void) { char *line, *s; using_history(); stifle_history(HISTORY); rl_attempted_completion_function = command_completion; rl_completion_entry_function = &command_generator; while(!done) { line = readline(parser_prompt); if (!line) break; s = skipwhitespace(line); if (*s) { add_history(s); execute_line(s); } free(line); } }
int parse(char* line) { int bg = 0; int argc = 0; int exit_status = EXIT_SUCCESS; char* argv[MAXARGS]; char* buffer; buffer = strtok(line, " \t\n"); while ( buffer != NULL ) { argv[ argc++ ] = buffer; buffer = strtok( NULL, " \t\n" ); } argv[argc] = NULL; count = argc; /* check if the last character is an ampersand */ if( strcmp(argv[argc-1], "&") == 0 ) { argv[ --argc ] = '\0'; /* remove the ampersand */ bg = 1; if( pr_debug) printf("%s Message: Background enabled for %s\n", __func__, argv[0]); } if(pr_debug || verbose)printf("%s Message: Argument = %s\n", __func__, argv[0]); if(pr_debug)printf("%s Message: Arg Count= %d\n", __func__, argc); if( (exit_status = builtin( argv, argc )) != 0 ) { exit_status = execute_line(argv, bg); } return exit_status; }
int main(int argc, char *argv[]) { char *line; printf("COMMAND_SIZE: %d\n", COMMAND_SIZE); #if 0 char entity[MAX_LEN]; int instance; char para[MAX_LEN]; char value[MAX_LEN]; #endif // rl_bind_key ('\t', rl_insert); rl_attempted_completion_function = (CPPFunction *)cmd_completion; while(run_cmd) { line = readline("AMIT> "); if (!line) break; char *s = stripwhite(line); if (*s) { add_history(s); execute_line(s); } free(line); // lookup table // send csid/value/rw/type request to server } return 0; }
int main() { char *s, *line; printf(MESSAGE); env_resetTowns(&env); initialize_readline(); while(env.done == 0) { char prompt[40]; if(env.cur_towns->nb) { snprintf(prompt, 40, "(%d towns) %s>%s ", env.cur_towns->nb, ANSI_GREEN, ANSI_NORMAL); } else { snprintf(prompt, 40, "%s>%s ", ANSI_GREEN, ANSI_NORMAL); } line = readline(prompt); if(line) { s = stripwhite(line); if(s[0] != '\0') { add_history(s); execute_line(s); } free(line); } } return 0; }
/* this is the command execution machine */ int Parser_commands(void) { char *line, *s; int rc = 0, save_error = 0; int interactive; interactive = init_input(); while(!done) { line = readline(interactive ? parser_prompt : NULL); if (!line) break; s = skipwhitespace(line); if (*s) { add_history(s); rc = execute_line(s); } /* stop on error if not-interactive */ if (rc != 0 && !interactive) { if (save_error == 0) save_error = rc; if (!ignore_errors) done = 1; } free(line); } if (save_error) rc = save_error; return rc; }
void UserInterface::exec_string_as_script(const char* s) { const char* start = s; for (;;) { const char* end = start; while (*end != '\0' && *end != '\n') ++end; while (isspace(*(end-1)) && end > start) --end; if (end > start) { // skip blank lines string line(start, end); if (!ctx_->get_settings()->logfile.empty()) { FILE* f = fopen(ctx_->get_settings()->logfile.c_str(), "a"); if (f) { fprintf(f, " %s\n", line.c_str()); fclose(f); } } if (ctx_->get_verbosity() >= 0) show_message(kQuoted, "> " + line); Status r = execute_line(line); if (r != kStatusOk) break; } if (*end == '\0') break; start = end + 1; } }
int execute_script_line(void) { char line[1024]; if(g_context.args.exec[0]) { int ret = execute_line(g_context.args.exec); g_context.args.exec[0] = ' '; g_context.args.exec[1] = 0; if(ret < 0) { return -1; } if(ret > 0) { return 1; } /* Only way we get here is if there were no lines to execute */ close_script(); } else if(g_context.fscript) { while(fgets(line, sizeof(line), g_context.fscript)) { int ret = execute_line(line); if(ret < 0) { return -1; } /* Only return if we have sent a line to the PSP */ if(ret > 0) { return 1; } } /* Only way we get here is if there were no lines to execute */ close_script(); } return 0; }
/* * Called with a complete line of input by the readline library. */ static void handle_stdin(char *line) { if (line == NULL || *line == '\0') return; execute_line(line); add_history(line); free(line); }
int main (int argc, char **argv) { extern int sockfd; char *line, *s; struct sigaction sig; memset(&sig,'\0',sizeof(sig)); /* Use the sa_sigaction field because the handles has two additional parameters */ sig.sa_sigaction = &handle_signal; /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */ sig.sa_flags = SA_SIGINFO; if (sigaction(SIGPIPE, &sig, NULL) < 0) { fprintf (stderr,"SIGPIPE sigaction failure"); return 1; } if (sigaction(SIGINT, &sig, NULL) < 0) { fprintf (stderr,"SIGINT sigaction failure"); return 1; } progname = argv[0]; initialize_readline ();/* Bind our completer. */ char *lineptr = NULL; /* Loop reading and executing lines until the user quits. */ for ( ; done == 0; ) { if (!lineptr) { if (!(line = readline("sysrepo> "))) break; lineptr = strtok(line, ";"); } printf("line is %s\n",line); /* Remove leading and trailing whitespace from the line. Then, if there is anything left, add it to the history list and execute it. */ s = stripwhite (lineptr); if (*s) { add_history (s); execute_line (s); } lineptr = strtok(NULL,";"); if(!lineptr) free (line); } close(sockfd); exit (0); }
int asm_cmd(int argc, char **argv) { char cmd[1024]; if(argc > 1) { int i; char *curr; curr = cmd; snprintf(cmd, sizeof(cmd), "pokew '%s' ", argv[0]); curr += strlen(cmd); for(i = 1; i < argc; i++) { unsigned int opcode; if(asmAssemble(argv[i], 0, &opcode) == 0) { sprintf(curr, "0x%08X ", opcode); curr += strlen(curr); } else { break; } } if(i == argc) { execute_line(cmd); } } else { snprintf(cmd, sizeof(cmd), "calc '%s'", argv[0]); execute_line(cmd); g_context.asmmode = 1; g_context.asmaddr = 0; } return 0; }
int run_program(int lines) { int error = 0; int current_line = 1; while (current_line >= 1 && current_line <= lines) current_line = execute_line (current_line); error = 0; return error; }
int execute_state_machine() { int execution_state = 0; void * instruction_line = NULL; while(actual_kernel_data->Q > 0) { switch (execution_state) { case S0_CHECK_EXECUTION_STATE: switch (check_execution_state()) { case SUCCESS: execution_state = S1_GET_EXECUTION_LINE; break; case EXIT: return SUCCESS; default: execution_state = ERROR; break; } break; case S1_GET_EXECUTION_LINE: if (get_execution_line(&instruction_line) == SUCCESS) { execution_state = S2_EXECUTE_LINE; } else { execution_state = S0_CHECK_EXECUTION_STATE; } break; case S2_EXECUTE_LINE: switch(execute_line(instruction_line)) { case SUCCESS: execution_state = S3_POSTPROCESS; break; case BROKEN: case EXIT: execution_state = S0_CHECK_EXECUTION_STATE; break; default: execution_state = ERROR; } break; case S3_POSTPROCESS: if(post_process_operations() == SUCCESS) { execution_state = S0_CHECK_EXECUTION_STATE; } else { execution_state = ERROR; } break; default: case ERROR: return ERROR; } } finished_quantum_post_process(); return SUCCESS; }
static int execute_file(const char *fn,stralloc *file) { unsigned int start; unsigned int end; unsigned int len; int code; for (start = 0; start < file->len; start = end + 1) { len = byte_chr(file->s+start,file->len-start,'\n'); end = start + len; file->s[end] = 0; if ((code = execute_line(fn,file->s+start)) != 0) return code; } return 0; }
int main(int argc, char **argv) { char **zeroth = argv; ungetch('\n'); argv += argc - 1; while (argv != zeroth) { ungetch(' '); unget_string(*argv); argv--; } execute_line(); return 0; }
void tool_source(int argc, char *argv[]) { char line[1024]; char *nl; FILE *file = fopen(argv[1], "r"); if (!file) { perror(""); return; } while (fgets(line, 1024, file)) { if ((nl = strchr(line, '\n'))) *nl = '\0'; execute_line(line); } }
int main(int argc, char **argv) { char cmdbuf[BUFSIZ]; int c; whoami = argv[0]; interactive = (isatty(0) && isatty(1)); while ((c = getopt(argc, argv, "q")) != -1) { switch (c) { case 'q': quote_output = 1; break; default: fprintf(stderr, "Usage: mrtest [-q]\n"); exit (1); } } #if defined(__APPLE__) && defined(__MACH__) add_error_table(&et_sms_error_table); add_error_table(&et_krb_error_table); #else initialize_sms_error_table(); initialize_krb_error_table(); #endif #ifdef HAVE_READLINE /* we don't want filename completion */ rl_bind_key('\t', rl_insert); #endif set_signal_handler(SIGINT, discard_input); sigsetjmp(jb, 1); while (!quit) { if (!mr_gets("moira: ", cmdbuf, BUFSIZ)) break; execute_line(cmdbuf); } mr_disconnect(); exit(0); }
int main (int argc, char **argv) { char *line, *s; progname = argv[0]; initialize_readline(); /* Bind our completer. */ stifle_history(7); /* Loop reading and executing lines until the user quits. */ for ( ; done == 0; ) { line = readline ("FileMan: "); if (!line) break; /* Remove leading and trailing whitespace from the line. Then, if there is anything left, add it to the history list and execute it. */ s = stripwhite(line); if (*s) { char* expansion; int result; result = history_expand(s, &expansion); if (result < 0 || result == 2) { fprintf(stderr, "%s\n", expansion); } else { add_history(expansion); execute_line(expansion); } free(expansion); } free(line); } exit (0); return 0; }
void UserInterface::exec_fityk_script(const string& filename) { user_interrupt = false; boost::scoped_ptr<FileOpener> opener; if (endswith(filename, ".gz")) opener.reset(new GzipFileOpener); else opener.reset(new NormalFileOpener); if (!opener->open(filename.c_str())) { warn("Can't open file: " + filename); return; } int line_index = 0; char *line; string s; while ((line = opener->read_line()) != NULL) { ++line_index; if (line[0] == '\0') continue; if (ctx_->get_verbosity() >= 0) show_message (kQuoted, S(line_index) + "> " + line); s += line; if (*(s.end() - 1) == '\\') { s.resize(s.size()-1); continue; } if (s.find("_SCRIPT_DIR_/") != string::npos) { string dir = get_directory(filename); replace_all(s, "_EXECUTED_SCRIPT_DIR_/", dir); // old magic string replace_all(s, "_SCRIPT_DIR_/", dir); // new magic string } Status r = execute_line(s); if (r != kStatusOk && ctx_->get_settings()->on_error[0] != 'n' /*nothing*/) break; if (user_interrupt) { mesg("Script stopped by signal INT."); break; } s.clear(); } if (line == NULL && !s.empty()) throw SyntaxError("unfinished line"); }
void NerveTool::execute_data( StringList& data , FILE *sout ) { ClassList<Nerve> nn; // parse for( int k = 0; k < data.count(); k++ ) { String so = data.get( k ); if( so.isEmpty() ) continue; String s = so; int res = execute_line( s , sout , nn ); if( res != 0 ) fprintf( sout , "invalid string (%d): error=%s, full=%s\n" , res , ( const char * )s , ( const char * )so ); } // output output_data( sout , nn ); }
int cli_loop(char * msg) { char *s; /* Remove leading and trailing whitespace from the line. Then, if there is anything left, add it to the history list and execute it. */ s = stripwhite(msg); if (*s) { //add_history(s); execute_line(s); } send(cli_cfg->cfd, cli_cfg->prompt, strlen(cli_cfg->prompt), 0); return 0; }
int main(int argc, char *argv[]) { char* s, *line; readline_init(); printf("enter `?' for help.\n"); while (!done) { line = readline(prompt()); if (!line) break; s = strtrim(line); if (*s) { add_history(s); execute_line(s); } free(line); } return 0; }
int interact(const struct command *cmds, char *prompt){ char *line; char *s; commands = cmds; rl_attempted_completion_function = cmd_completion; while(!interact_done){ line = readline(prompt); if(!line){ break; } s = skipwhite(line); add_history(s); execute_line(cmds, s); free(line); } return 0; }
void UserInterface::exec_stream(FILE *fp) { LineReader reader; char *line; string s; while ((line = reader.next(fp)) != NULL) { if (ctx_->get_verbosity() >= 0) show_message(kQuoted, string("> ") + line); s += line; if (*(s.end() - 1) == '\\') { s.resize(s.size()-1); continue; } Status r = execute_line(s); if (r != kStatusOk) break; s.clear(); } if (line == NULL && !s.empty()) throw SyntaxError("unfinished line"); }
//==========================================================| MAIN int main( int argc, char *argv[] ) { DEBUG_LEVEL = 0; logger log = { debug_function }; log.debug( INFO(1), "SHELL START" ); int status; char* new_line; line* parsed_line; shell_init(); while( ! is_end_of_file() ) { print_prompt(); new_line = get_line(); if( !new_line ) continue; parsed_line = parseline( new_line ); execute_line( parsed_line ); } log.debug( INFO(1), "SHELL STOP" ); exit( EXIT_SUCCESS ); }
int main() { printf("***************************************************************\n"); printf(" CONSOLE \n"); printf("***************************************************************\n"); printf("To get help, please type \"help\"\n"); char *line, *s; initialize_readline(); while (1) { line = readline("> "); if (!line) break; s = g_strstrip(line); if (*s) { add_history(s); execute_line(s); } } return 0; }
int main(int argc, char **argv) { int i; coda_assert_action = CODA_ASSERT_EXIT; ReadConfigFile(); PDB_setupdb(); Parser_init("pdbtool> ", pdbcmds); if (argc == 1) Parser_commands(); else { char line[1024]; strcpy(line, argv[1]); for (i = 2; i < argc; i++) { strcat(line, " "); strcat(line, argv[i]); } execute_line(line); } PDB_db_release(); return 0; }
void *Command(void *argument) { // int recID, varID, levelID; // int nmiss; double s_utime, s_stime; double e_utime, e_stime; double c_cputime = 0, c_usertime = 0, c_systime = 0; char line[MAX_LINE]; char *s; cdoInitialize(argument); processStartTime(&s_utime, &s_stime); gl_streamID = streamOpenRead(cdoStreamName(0)->args); command_init(); /* Loop reading and executing lines until the user quits. */ while ( !Done ) { readcmd("cdo cmd> ", line, MAX_LINE); /* Remove leading and trailing whitespace from the line. Then, if there is anything left, add it to the history list and execute it. */ s = stripwhite(line); if ( *s ) execute_line(s); } /* while ( readline(stdin, line, MAX_LINE) ) { linep = line; if ( strcmp(linep, "exit") == 0 ) break; else if ( strcmp(linep, "vars") == 0 ) { int varID; int nvars = vlistNvars(gl_vlistID); for ( varID = 0; varID < nvars; ++nvars ) { fprintf(stdout,"varID %d\n", varID); } } } */ streamClose(gl_streamID); if ( gl_data ) free(gl_data); if ( all_vars ) free(all_vars); cdoProcessTime(&e_utime, &e_stime); c_usertime = e_utime - s_utime; c_systime = e_stime - s_stime; c_cputime = c_usertime + c_systime; s_utime = e_utime; s_stime = e_stime; cdoPrint("%.2fs %.2fs %.2fs", c_usertime, c_systime, c_cputime); cdoFinish(); return (0); }
/* main */ int main (int argc, char **argv) { char *s, *prompt; int exec, ret, i; progname = argv[0]; /* Loop reading and executing lines until the user quits. */ /* ifeffit_("") ;*/ ret = 1; exec = 1; /* initialize ifeffit */ ret = iff_exec(" set &screen_echo=1"); if (ret != 0) { printf(" fatal error loading ifeffit library\n") ; exit(ret); } s = iff_strval("&build"); printf(" Ifeffit %s\n", s); printf(" command-line shell version %s for Win32\n", Version); /* handle command line switches */ for (i=1;i<argc; i++) { if ( ((strncmp(argv[i], "-q", 2)) == 0) ) { /* -q means execute script with no screen echo */ ret = iff_exec(" set &screen_echo=0"); } else if ((strncmp(argv[i], "-x", 2)) == 0) { /* -x means execute script without pausing and exit */ ret = iff_exec(" set &pause_ignore=1"); exec = 0; } } /* load all script files given on command line */ for (i=1;i<argc; i++) { if ( ((strncmp(argv[i], "-x", 2)) != 0) && ((strncmp(argv[i], "-q", 2)) != 0) ) { ret = iff_load_file(argv[i]); if (ret == 1) {exec = 0;} } } ret = 0; /* execution loop */ while (exec) { prompt = "Ifeffit> "; if (ret == -1) { prompt = " ... > ";} ret = promptline(prompt); s = stripwhite(line); if (( strncmp(s , "exit",4) == 0) || ( strncmp(s , "quit",4) == 0)) { /* ret = iff_exec(" exit ") ; */ ret = 0; exec = 0; } else if (*s) { ret = execute_line(s); /* special case :: ret=1 means 'good exit', so set return stat to 0 and exit while(exec) loop */ if (ret == 1) { exec = 0; ret = 0; } /* a truly bad exit status */ if (ret > 1) { exec = 0;} } /* free(line);*/ } exit(ret); }