Exemple #1
0
int main (int argc, char *argv[])
{
	char	*line;
	char	*s;
	int	c;

	while ((c = getopt(argc, argv, "dv?")) != -1) {
		switch (c) {
		case 'd':
			Debug = TRUE;
			break;
		case 'v':
			Zerofill = TRUE;
			break;
		case '?':
		default:
			usage();
			exit(1);
			break;
		}
	}
	initsyms();
	initkmem();

	initeval();

	setjmp(Err_jmp);
	for (;;) {
#if READLINE IS_ENABLED
		line = readline("> ");	/* use getline on OS-X */
		if (!line) {
			break;
		}
		s = stripwhite(line);
		if (*s) {
			add_history(s);
		}
#else
		ssize_t	rc;
		size_t	n;
		printf("? ");
		fflush(stdin);
		line = NULL;
		rc = getline( &line, &n, stdin);
		s = stripwhite(line);
#endif
		parse_line(s);
		if (Debug) dump_args();
		invokeCmd(Argc, Argv);
		free(line);
	}
	printf("\n");
	return 0;
}
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);
    }
}
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);
    }
}
Exemple #4
0
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;
}
Exemple #5
0
int main()
{
    char prompt[ 16 ];
    char *line;
    char *s = NULL;
    struct termios term;

    memset( prompt, 0, 16 );
    sprintf( prompt, "CLI>" );
    //printf("cli>");
    tcgetattr(fileno(stdin), &term);
    tcsetattr(fileno(stdin), TCSAFLUSH, &term);
    fflush(stdin);
    /* receive command line input. */
    //hy_switch_to_buffer(stdin);

    while ( 1 ) {
        line = readline( prompt );
        if ( !line ) {
            break;
        }
        s = stripwhite( line );
        if (strcmp(s, "exit") == 0)
            break;
        if ( *s ) {
            add_history ( s );
            printf("Input is %s.\n", s);
        }
        //printf("cli>");
        free( line );
    }
    return 0;
}
Exemple #6
0
static
int handle_cmd(CONN_TYPE * conn, char *line, cmd_params_st *params)
{
	char *cline;
	unsigned int i;
	int status = 0;

	cline = stripwhite(line);

	if (strlen(cline) == 0)
		return 1;

	for (i = 0;; i++) {
		if (commands[i].name == NULL)
			goto error;

		if (check_cmd
		    (commands[i].name, cline, conn,
		     commands[i].need_preconn,
		     commands[i].func,
		     &status, params) != 0)
			break;
	}

	return status;

 error:
	if (check_cmd_help(line) == 0) {
		fprintf(stderr, "unknown command: %s\n", line);
		fprintf(stderr,
			"use help or '?' to get a list of the available commands\n");
	}
	return 1;
}
Exemple #7
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;
}
Exemple #8
0
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);
}
Exemple #9
0
int
main( int argc, char *argv[] )
{
//BOOL		bUseStartup, bGotCmd;
BOOL		bGotCmd;
BLOCK		bCmd;
//char		c;
RESULTt		rResult;


    setbuf(stdout,NULL);
    
    strcpy( GsProgramName, argv[0] );

    BasicsInitialize();

    GbGraphicalEnvironment = FALSE;

    ParseArguments( argc, argv );

    ParseInit( &rResult );

    bGotCmd = FALSE;
    bCmd = bBlockCreate();

    while ( rResult.iCommand != CQUIT ) {
      char *line=NULL;
      char *cp;

      line = tl_getline("> ");
      cp = stripwhite (line);


      if (*cp){
	gl_histadd(cp);
	
	for(; *cp; cp++) 
	  (void) bBlockAddChar( bCmd, *cp );
	
	if ( bBlockAddChar( bCmd, '\n' ) ) {
	  ParseBlock( bCmd, &rResult );
	  BlockEmpty( bCmd );
	}
      }
      
    } while ( rResult.iCommand != CQUIT );

    ParseShutdown();

    LISTUNFREEDMEMORYTOLOGFILE();

    exit(0);
}
Exemple #10
0
static void command_loop()
{
#if HAVE_READLINE
	char *line, *cmd;
	char prompt[32];

	snprintf(prompt, sizeof(prompt), "%s> ", package);

	/* Allow conditional parsing of the ~/.inputrc file. */
	rl_readline_name = package;

	/* Define a custom completion function. */
	rl_completion_entry_function = command_generator;
#else
	char line[64] = {0,};
	char *cmd = NULL;
#endif

	/* Read and execute commands until the user quits. */
	while (!done) {

#if HAVE_READLINE
		line = readline(prompt);

		if (line == NULL) {	/* EOF? */
			printf("\n");	/* close out prompt */
			done = 1;
			break;
		}
#else
		printf("%s> ", package);
		fgets(line, sizeof(line), stdin);
		line[strlen(line)-1] = '\0';
#endif

		/* Remove leading and trailing whitespace from the line. */
		cmd = stripwhite(line);

		/* If anything left, add to history and execute it. */
		if (*cmd)
		{
#if HAVE_READLINE
			add_history(cmd);
#endif
			execute_command(cmd);
		}

#if HAVE_READLINE
		free(line);		/* realine() called malloc() */
#endif
	}
}
Exemple #11
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		getword
//Author		Jim Taylor
//Date			Mon 27 Nov 1995
//
//Description	Gets 1 symbol... either a word or punctuation.
//				I think this routine can error if it runs out of data,
//				because the caller should know when to expect EOF,
//				but not yet!
//				
//Inputs		
//
//Returns	
//
//------------------------------------------------------------------------------
static	string	TokenSpell::getword(file	ifile)
{
	//2 stages to getting a word:
	//	1) leading white removal
	//	2) copy to terminator
	//1) leading white removal

	char 	c;
	string	myword = NULL;

	if (!stripwhite(ifile))
		return(NULL);
	elser
	{
	 	c=(char) fgetc(ifile);
string 	outbuf=wordbuff;
		myword=outbuf;
		//test for punctuation (ok... spc/tab in there as well!)
string	p1=endchars;

		while ((c!=*p1) && *p1)
			p1++;

		if (*p1)
		{	//punctuation only 1 char long...
			*(outbuf++)=c;
			*outbuf=0;
			return (myword);
		}
		elser
		{	
			for(;;)
			{	//build string up to next punctuation or white
				*(outbuf++)=c;
				*outbuf=0;		//handle early return for eof
				c=(char) fgetc(ifile);
				//EOF during a word read is not an error, really
				if (feof(ifile))
					return (myword);

string			p1=endchars;

				while ((c!=*p1) && *p1)
					p1++;

			breakif (*p1);
			}
			ungetc(c,ifile);
			return (myword);
		}
	}
}
Exemple #12
0
/*----------------------------------------------------------------------
  Break a string of the type <Name>=<Value> into Name and Value.
----------------------------------------------------------------------*/
int BreakStr(char *str, char **Name, char **val)
{
  char *t,*off;

  if ((off = strchr(str,'='))) off++;
  
  if ((t=strtok(str,"="))!=NULL)
    {
      stripwhite(t);
      *Name = (char *)getmem(strlen(t)+1,"BreakStr");
      strcpy(*Name,t);
    }
  else *Name = NULL;
  if (off)
    {
      stripwhite(off);
      *val = (char *)getmem(strlen(off)+1,"BreakStr");
      strcpy(*val,off);
    }
  else *val = NULL;
  return 1;
}
Exemple #13
0
/*
 * Name: main
 *
 * Description: Gets the ball rolling...
 *
 */
int main(void) {
  signal(SIGINT, SIG_IGN);
  signal(SIGTSTP, SIG_IGN);
  signal(SIGCHLD, SIG_IGN);

  Command cmd;
  int n;
  while (!done) {

    char *line;
    line = readline("> ");

    if (!line) {
      /* Encountered EOF at top level *///
      done = 1;
    }
    else {
        stripwhite(line);
        if(*line) {
            add_history(line);
            /* execute it */
            n = parse(line, &cmd);
            PrintCommand(n, &cmd);
            if (! Builtexec(&cmd)) {

            /* If not a builtin cmd, fork */
                pid_t child_pid;
                int child_status;
                child_pid = fork();

                if(child_pid == 0){
                    Startexec(&cmd); // Child code, recursive helper function
                    exit(0);
                }else{
                  pid_t tpid;       // Parent code, to wait or not to wait for child
                  if(!cmd.bakground){ 
                      tpid = waitpid(child_pid, &child_status, 0);
                  }
                
                }
            }
        }
        /* Check for builtin command and execute it */
    }
    if(line) {
      free(line);
    }
  }
  return 0;
}
Exemple #14
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;
}
Exemple #15
0
/* Prend une ligne, entrée par l'utilisateur, se composant d'une
   commande et de ses éventuels arguments, et l'exécute */
void execute_line(char* line) {
  line = stripwhite(line);

  char** args;
  int args_nb = 0;
  unsigned int i, toggle;
  size_t len = strlen(line);
  for(i=0, toggle=0; line[i] != '\0'; i++) {
    if(is_white(line[i])) {
      if(toggle) toggle = 0;
      line[i] = '\0';
    } else {
      if(!toggle) toggle = 1;
      args_nb++;
    }
  }
  
  args = malloc((args_nb+1) * sizeof(char*));
  
  int a = 0;
  for(i=0, toggle=0; i < len; i++) {
    if(line[i] == '\0') {
      if(toggle) toggle = 0;
    } else {
      if(!toggle) {
	toggle = 1;
	args[a++] = &line[i];
      }
    }
  }
  args[a] = NULL;

  /* Comparaisons pour trouver de quelle commande il s'agit */

  for(i=0; env.commands[i].name != NULL; i++) {
    if(!strcmp(args[0], env.commands[i].name)) {
      env.commands[i].f(args, &env);
      free(args);
      return;
    }
  }

  printf("Command not found : %s\n", args[0]);
  free(args);
}
Exemple #16
0
/*
 * Name: main
 *
 * Description: Gets the ball rolling...
 *
 */
int main(void) {
    Command cmd;
    int n;

    while (!done) {

        char *line;
        line = readline("> ");

        if (!line) {
            /* Encountered EOF at top level */
            done = 1;
        } else {
            /*
             * Remove leading and trailing whitespace from the line
             * Then, if there is anything left, add it to the history list
             * and execute it.
             */
            stripwhite(line);

            if (*line) {
                add_history(line);
                /* execute it */
                n = parse(line, &cmd);
                PrintCommand(n, &cmd);
            }
        }

        /* Own stuff testing */


        /*
         * Traverse through linked list, and fork process child per program
         * Sets up pipeline between child processes.
         */
        runCommand(0, cmd.pgm);


        /* Own stuff testing - END*/
        if (line) {
            free(line);
        }
    }
    return 0;
}
Exemple #17
0
char* getl()
{
    char* ret;
    int len;

    ret = readline("sh-0.0.1$ ");

    if (ret == NULL) {// exit
	puts("");
	exit(0);
    }

    if (ret && *ret)
	add_history(ret);

    stripwhite(ret);
   
    return ret;
}
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;
}
Exemple #19
0
void
lsh_exec(lsh_t *lsh)
{
#ifdef WITH_READLINE
	int ret;
	char *line, *s;
#endif

	RiBegin(RI_NULL);

#ifdef WITH_READLINE
	while (1) {
		printf("Example usage:\n");
		printf("lsh: file RIBFILE  -> specify RIB file to render\n");
		printf("lsh: render        -> start rendering\n");
		printf("\n");

		line = readline("lsh: ");

		if (!line) break;

		s = stripwhite(line);

		if (*s) {
			add_history(s);
			ret = exec_line(s);
			if (ret < 0) break;
		}

		free(line);
	}
#endif

	RiEnd();

	(void)lsh;		/* for gcc */
}
Exemple #20
0
static void command_loop()
{
	char *line, *cmd;
	char prompt[32];

	snprintf(prompt, sizeof(prompt), "%s> ", package);

	/* Allow conditional parsing of the ~/.inputrc file. */
	rl_readline_name = package;
     
	/* Define a custom completion function. */
	rl_completion_entry_function = command_generator;

	/* Read and execute commands until the user quits. */
	while (!done) {

		line = readline(prompt);
     
		if (line == NULL) {	/* EOF? */
			printf("\n");	/* close out prompt */
			done = 1;
			break;
		}
     
		/* Remove leading and trailing whitespace from the line. */
		cmd = stripwhite(line);

		/* If anything left, add to history and execute it. */
		if (*cmd)
		{
			add_history(cmd);
			execute_command(cmd);
		}
     
		free(line);		/* realine() called malloc() */
	}
}
Exemple #21
0
/*
 * Name: main
 *
 * Description: Gets the ball rolling...
 *
 */
int main(void)
{
  Command cmd;
  int n;

  while (!done) {

    char *line;
    line = readline("> ");

    if (!line) {
      /* Encountered EOF at top level */
      done = 1;
    }
    else {
      /*
       * Remove leading and trailing whitespace from the line
       * Then, if there is anything left, add it to the history list
       * and execute it.
       */
      stripwhite(line);

      if(*line) {
        add_history(line);
        /* execute it */
        n = parse(line, &cmd);
        PrintCommand(n, &cmd);
      }
    }
    
    if(line) {
      free(line);
    }
  }
  return 0;
}
Exemple #22
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);
}
Exemple #23
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);
}
Exemple #24
0
void read_config(void)
{
	static char key[MAXPATHLEN];
	static char value[MAXPATHLEN];
	static char line[MAXPATHLEN];
	char *ptr = value;
	FILE *fd;
	if(get_home(line)) 
	{
		read_pair(line, key, value);
	} 
	else 
	{
		strcpy(value, "./");
	}

	strcat(value, "/.ps4shrc");
	if ( (fd = fopen(value, "rb")) == NULL ) 
	{
		perror(value);
		return;
	}

	while((read_line(fd, line)) != -1) 
	{
		if (line[0] == '#') 
		{
			continue;
		}
		read_pair(line, key, value);
		trim(key);
		ptr = stripwhite(value);
		if (strcmp(key, "ip") == 0) 
		{
			strcpy(dst_ip, ptr);
		} 
		else if (strcmp(key, "log") == 0) 
		{
			if (strcmp(ptr, "") == 0) 
			{
				cli_log(stdout);
			} 
			else {
				cli_log(ptr);
			}
		} 
	/*	else if (strcmp(key, "exception") == 0) 
		{
			if (strcmp(ptr, "screen") == 0) 
			{
				DUMPSCREEN = 1;
			} 
			else 
			{
				DUMPSCREEN = 0;
			}
		} */
		else if (strcmp(key, "verbose") == 0) 
		{
			if (strcmp(ptr, "yes") == 0) 
			{
				printf(" Verbose mode on\n");
				VERBOSE = 1;
			}
		} 
		else if (strcmp(key, "debug") == 0) 
		{
			if (strcmp(ptr, "yes") == 0) 
			{
				ps4link_set_debug(1);
			}
		}
		else if (strcmp(key, "histfile") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				strcpy(ps4sh_history, ptr);
			}
		} 
		else if (strcmp(key, "bind") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				strcpy(src_ip, ptr);
			}
		} 
		else if (strcmp(key, "path") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				ps4link_set_path(path_split(ptr));
			}
		} 
		else if (strcmp(key, "suffix") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				common_set_suffix(path_split(ptr));
			}
		} 
		else if (strcmp(key, "setroot") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				ps4link_set_root(ptr);
			}
		} 
		else if (strcmp(key, "logprompt") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				/* pko_set_root(ptr); */
			}
		} 
		else if (strcmp(key, "home") == 0) 
		{
			if (strcmp(ptr, "") != 0) 
			{
				if (chdir(ptr) == -1) 
				{
					perror(ptr);
				}
			}
		}
	}
    return;
}
// simple version without readline...
void ServerConsole::MainLoop()
{
    char line[321];
    line[0] = '\0';

    CPrompt (COL_BLUE "%s: " COL_NORMAL, prompt);

    // This important flag allows clean shutdown outside the console
    // since stdin is polled asynchronously
    while (!stop)
    {

        // Make sure that if we don't type anything the loop is continued
        // so that the running flag will be checked.

#ifdef WIN32
        // Windows only allows select to be used on sockets so we have to use this
        // roundabout method. Note: the running flag won't be checked when the
        // user is in the middle of typing something.
        HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
        DWORD records_read = 0;
        INPUT_RECORD irec[1];

        // Wait until the console receives input
        if(WaitForSingleObject(hInput, 1000) == WAIT_TIMEOUT)
            continue;

        // Check if the record is for a keypress
        PeekConsoleInput(hInput, irec, 1, (LPDWORD)(&records_read));

        if(irec[0].EventType != KEY_EVENT)
        {
            // Read and discard this event
            ReadConsoleInput(hInput, irec, 1, (LPDWORD)(&records_read));
            continue;
        }
#else
        struct timeval tv;
        fd_set readfds;

        tv.tv_sec = 1;
        tv.tv_usec = 0;

        FD_ZERO(&readfds);
        FD_SET(STDIN_FILENO, &readfds);

        // This allows the running flag to be checked every second but only works on Unix.
        int retval = select(STDIN_FILENO+1, &readfds, NULL, NULL, &tv);
        if(retval == 0)
        {
            continue;
        }
#endif

        if (fgets(line,319,stdin) == NULL)
        {
            // TODO: Yield timeslice here maybe?
			continue;
        }

        ConsoleOut::atStartOfLine = true;

        char* s;
        s = stripwhite(line);

        // Strip trailing newline
        if (s[strlen(s)-1]=='\n')
            s[strlen(s)-1]='\0';

        if (*s)
        {
#ifdef USE_HISTORY
            add_history(s);
#endif
            if (*s != '/')  // commands starting with slash are remote commands from npcclient to server
            {
                if(!strcmp("quit", s))
                    execute_line(s, NULL);
                else
                    EventManager::GetSingleton().Push(new psServerConsoleCommand(s));
            }
            else if (cmdcatcher)
            {
                // Give something else access to the command
                cmdcatcher->CatchCommand(s);
                CPrompt (COL_BLUE "%s: " COL_NORMAL, prompt);
            }
        }
        else
        {
            CPrompt (COL_BLUE "%s: " COL_NORMAL, prompt);
        }
    }
}
Exemple #26
0
debug_return_t enter_debugger (target_stack_node_t *p, 
			       file_t *p_target, int errcode,
			       debug_enter_reason_t reason)
{
  debug_return_t debug_return = debug_readloop;
  static bool b_init = false;
  static bool b_readline_init = false;
  char open_depth[MAX_NEST_DEPTH];
  char close_depth[MAX_NEST_DEPTH];
  unsigned int i = 0;

  last_stop_reason = reason;
  
  if ( in_debugger == DEBUGGER_QUIT_RC ) {
    return continue_execution;
  }
  
  if ( i_debugger_stepping > 1 || i_debugger_nexting > 1 ) {
    /* Don't stop unless we are here from a breakpoint. But
       do decrement the step count. */
    if (i_debugger_stepping)  i_debugger_stepping--;
    if (i_debugger_nexting)   i_debugger_nexting--;
    if (!p_target->tracing) return continue_execution;
  } else if ( !debugger_on_error 
	      && !(i_debugger_stepping || i_debugger_nexting) 
	      && p_target && !p_target->tracing && -2 != errcode )
    return continue_execution;
  
  /* Clear temporary breakpoints. */
  if (p_target && p_target->tracing & BRK_TEMP)
    switch(last_stop_reason) 
      {
      case DEBUG_BRKPT_AFTER_CMD:
      case DEBUG_BRKPT_BEFORE_PREREQ:
      case DEBUG_BRKPT_AFTER_PREREQ:
        p_target->tracing = BRK_NONE;
      default:
        ;
      }

#ifdef HAVE_LIBREADLINE
  if (use_readline_flag && !b_readline_init) {
      rl_initialize ();
      using_history ();
      add_history ("");
      b_readline_init = true;
  }
#endif
  if (!b_init) {
    cmd_initialize();
    file2lines.ht_size = 0;
    b_init = true;
  }


  /* Set initial frame position reporting area: 0 is bottom. */
  p_target_loc    = NULL;
  psz_target_name = "";
  i_stack_pos      = 0;

  p_stack = p_stack_top = p;
  p_floc_stack = p_stack_floc_top;

  /* Get the target name either from the stack top (preferred) or
     the passed in target.
   */
  if (p && p->p_target) {
    p_target_loc    = &(p->p_target->floc);  
    psz_target_name = (char *) p->p_target->name;
  } else if (p_target) {
    p_target_loc    = &(p_target->floc);
    psz_target_name = (char *) p_target->name;
  }

  for (i=0; i<=makelevel && i < MAX_NEST_DEPTH-5; i++) {
    open_depth[i]  = '<';
    close_depth[i] = '>';
  }

  if ( MAX_NEST_DEPTH - 5 == i ) {
    close_depth[i] = open_depth[i]  = '.'; i++;
    close_depth[i] = open_depth[i]  = '.'; i++;
    close_depth[i] = open_depth[i]  = '.'; i++;
  }
  
  open_depth[i] = close_depth[i] = '\0';

  in_debugger = true;

  if (errcode) {
    if (-1 == errcode) {
      printf("\n***Entering debugger because we encountered an error.\n");
    } else if (-2 == errcode) {
      if (0 == makelevel) {
	printf("\nMakefile terminated.\n");
	dbg_msg("Use q to quit or R to restart");
      } else {
	printf("\nMakefile finished at level %d. Use R to restart\n", 
	       makelevel);
	dbg_msg("the makefile at this level or 's', 'n', or 'F' to continue "
	       "in parent");
	in_debugger = DEBUGGER_QUIT_RC;
      }
    } else {
      printf("\n***Entering debugger because we encountered a fatal error.\n");
      dbg_errmsg("Exiting the debugger will exit make with exit code %d.", 
                 errcode);
    }
  }

  print_debugger_location(p_target, reason, NULL);

  /* Loop reading and executing lines until the user quits. */
  for ( debug_return = debug_readloop; 
	debug_return == debug_readloop || debug_return == debug_cmd_error; ) {
    char prompt[PROMPT_LENGTH];
    char *line=NULL;
    char *s;

    if (setjmp(debugger_loop))
      dbg_errmsg("Internal error jumped back to debugger loop");
    else {
    
#ifdef HAVE_LIBREADLINE
      if (use_readline_flag) {
        snprintf(prompt, PROMPT_LENGTH, "remake%s%d%s ", 
                 open_depth, where_history(), close_depth);
        
        line = readline (prompt);
      } else 
#endif
        {
          snprintf(prompt, PROMPT_LENGTH, "remake%s0%s ", open_depth, 
                   close_depth);
          printf("%s", prompt);
          if (line == NULL) line = calloc(1, 2048);
          line = fgets(line, 2048, stdin);
          if (NULL != line) chomp(line);
        }
      
      if ( line ) {
        if ( *(s=stripwhite(line)) ) {
          add_history (s);
          debug_return=execute_line(s);
        } else {
          add_history ("step");
          debug_return=dbg_cmd_step("");
        }
        free (line);
      } else {
        dbg_cmd_quit(NULL);
      }
    }
  }

  if (in_debugger != DEBUGGER_QUIT_RC)
    in_debugger=false;
  
  return debug_return;
}