Exemplo n.º 1
0
int main() {

	int nl,nc,npares;
	int i,j;
	int cindex, lindex;

	char* readline = NULL;
	char* finalWord = NULL;
	char* strtokRes = NULL;

	BOARD board;

	readline=rl_gets("Numero de Linhas e de Colunas> ");
	sscanf(readline,"%d %d",&nl,&nc);
	board = board_init(nl,nc);


	for(i = 0; i<nl; i++){
		readline=rl_gets("Linha> ");
		add_row(readline,i,board);
	}


	readline=rl_gets("Numero de Pares> ");
	sscanf(readline,"%d",&npares);

	finalWord = (char*) malloc(sizeof(char)*npares+1);

	readline=rl_gets("Coordenadas> ");

	strtokRes = strtok(readline," ");
	lindex = cindex = 0;
	for(i = 0,j=0;strtokRes && i<(npares*2);i++){
		if(i%2==1){
			cindex = atoi(strtokRes);
			finalWord[j]=board->board[lindex-1][cindex-1];
			j++;
		}
		else{
			lindex = atoi(strtokRes);
		}

		strtokRes=strtok(NULL," ");
	}
	finalWord[j]='\0';
	printf("%s\n",finalWord);
	return 0;
}
Exemplo n.º 2
0
static int get_interactive_line (void *p)
{
    ExecState *s = (ExecState *) p;
    const char *prompt = get_prompt(s);
    int err = 0;

#ifdef HAVE_READLINE
    rl_gets(&line_read, prompt);

    if (line_read == NULL) {
	strcpy(s->line, "quit");
    } else if (strlen(line_read) > MAXLINE - 2) {
	err = E_TOOLONG;
    } else {
	*s->line = '\0';
	strncat(s->line, line_read, MAXLINE - 2);
	strcat(s->line, "\n");
    }
#else
    printf("%s", prompt);
    fflush(stdout);
    file_get_line(s); /* note: "file" = stdin here */
#endif

    return err;
}
Exemplo n.º 3
0
void ui_mainloop() {
	while(1) {
		char *str = rl_gets();
		char *str_end = str + strlen(str);

		/* extract the first token as the command */
		char *cmd = strtok(str, " ");
		if(cmd == NULL) { continue; }

		/* treat the remaining string as the arguments,
		 * which may need further parsing
		 */
		char *args = cmd + strlen(cmd) + 1;
		if(args >= str_end) {
			args = NULL;
		}

#ifdef HAS_DEVICE
		extern void sdl_clear_event_queue(void);
		sdl_clear_event_queue();
#endif

		int i;
		for(i = 0; i < NR_CMD; i ++) {
			if(strcmp(cmd, cmd_table[i].name) == 0) {
				if(cmd_table[i].handler(args) < 0) { return; }
				break;
			}
		}

		if(i == NR_CMD) { printf("Unknown command '%s'\n", cmd); }
	}
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
  // Shell read-evaluate loop
  for (;;) {
    // Read user input and evaluate commands
    Command_vec *commands = read_commands(rl_gets());
    eval(commands);
    free_command_vec(commands);
  }
  printf("\n");
  return 0;
}
Exemplo n.º 5
0
/* Simulate a call to ungetc(getc(stdin)), but actually use rl_gets to
   use readline instead.  This is used in peek().  [Ash] */
int rl_getungetc() {
  int c;

  if (getc_require_new_readline) {
    getc_ptr = rl_gets();
    getc_require_new_readline = 0;
  }

  if (getc_ptr == (char *)NULL)
    return EOF;

  if (*getc_ptr == '\0')
    return '\n';

  return *getc_ptr;
}
Exemplo n.º 6
0
int
rl_getc_wrapper() {
  if (getc_require_new_readline)
    getc_ptr = rl_gets();

  if (getc_ptr == (char *)NULL)
    return EOF;

  if (*getc_ptr == '\0') {
    getc_require_new_readline = 1;
    *getc_ptr = '\n';
  } else
    getc_require_new_readline = 0;

  return *getc_ptr++;
}
Exemplo n.º 7
0
static int maybe_get_input_line_continuation (char *line)
{
    char tmp[MAXLINE];
    int contd, err = 0;

    if (!strncmp(line, "quit", 4)) {
	return 0;
    }

    contd = top_n_tail(line, MAXLINE, &err);

    while (contd && !err) {
	*tmp = '\0';

	if (batch || runit) {
	    char *test = fgets(tmp, MAXLINE, fb);

	    if (test == NULL) {
		break;
	    }
	} else {
#ifdef HAVE_READLINE
	    rl_gets(&line_read, "> ");
	    strcpy(tmp, line_read);
#else
	    fgets(tmp, MAXLINE, stdin); 
#endif
	}

	if (*tmp != '\0') {
	    if (strlen(line) + strlen(tmp) > MAXLINE - 1) {
		err = E_TOOLONG;
		break;
	    } else {
		strcat(line, tmp);
		compress_spaces(line);
	    }
	}
	contd = top_n_tail(line, MAXLINE, &err);
    }

    return err;
}
Exemplo n.º 8
0
int main(int argc, char **argv) {
	char *line = (char *)NULL;
	
	while (1) {
		line = rl_gets();
		
		// show help text
		if (strcmp(line, "help") == 0) {
			cmd_help(line);
			continue;
		}
		
		// quit
		if (strcmp(line, "exit") == 0)
			return 0;
	}
	
	return 0;
}
Exemplo n.º 9
0
static void * nbfgetsThreadFunction (void *Arg)
{
  nbfgetsBuffer[MAX_NBFGETS - 1] = 0;
  while (1)
  {
      // Wait for an input string, presumably sleeping.
#ifdef USE_READLINE
      if (rl_gets() == NULL)
#else
      if (nbfgetsBuffer != fgets (nbfgetsBuffer, MAX_NBFGETS - 1, stdin))
#endif

      {
#ifdef WIN32	    
	  Sleep (10);
#else
	  struct timespec req, rem;
	  req.tv_sec = 0;
	  req.tv_nsec = 10000000;
	  nanosleep (&req, &rem);
#endif // WIN32
           continue;
       }
		
      nbfgetsReady = 1;
      
      // Go to sleep until the string has been processed.
      pthread_mutex_lock(&nbfgetsMutex);
      if (pthread_cond_wait (&nbfgetsCond, &nbfgetsMutex) != 0)
      {
      	fputs("pthread error\n",stderr);
      }
      pthread_mutex_unlock(&nbfgetsMutex);     
    }
  // This function doesn't actually return, but I've
  // put in the following line to avoid a compiler
  // warning in some compiler versions.
#ifndef SOLARIS
  return (NULL);
#endif
}
Exemplo n.º 10
0
/*
 * start_cmd_processing - main command processing loop.
 *
 */
void pagentd_cli_start ( void ) {
  char *cmdline;
  COMMAND *theCmd;
  BOOL retb;
  char cmdl[100];
  
  puts(menuMsg);

  /*
   * the main command loop.
   */
  while (1) {
    cmdline = rl_gets();
    strcpy(cmdl, cmdline);
    theCmd = find_command(cmdline);
    if (!theCmd) 
      printf("%s: No such command!\n", cmdline);
    else {
      retb = theCmd->cmdHandler(cmdl);
    }
  }
}
Exemplo n.º 11
0
/**
  * A função main é um ciclo que apenas termina quando o utilizador insere o comando "q".
  * Esta função vai então ser responsável iniciar o programa e receber os comandos que o utilizador lhe introduz.
  * Vai imprimir os resultados do jogo enquanto este decorrer. 
  */
int main() {
	char *cmd = NULL;
	FUNCTION *fun = NULL;
	BOARD * brd = NULL;

	srand(time(NULL));
	brd = initialize_state();

	while(rl_gets() != NULL) {
		int i, j;

		/* Ignorar os espacos no inicio do comando */
		for(i = 0; line_read[i] && whitespace(line_read[i]); i++);

		/* Saltar a primeira palavra da linha */
		for(j = i; line_read[j] && !whitespace(line_read[j]); j++);

		/* Delimitar o nome do comando */
		if(line_read[j])
			line_read[j++] = 0;

		 /* Saltar os espacos mais uma vez */
		for(; line_read[j] && whitespace(line_read[j]); j++);

		cmd = line_read + i;

		fun = find_command(cmd);
		if(fun != NULL) {
			brd = fun(line_read + j, brd);
			print_state(brd);
		} else {
			mensagem_de_erro(E_COMMAND);
		}
	}

	return 0;
}
Exemplo n.º 12
0
int main(int argc, char** argv)
{
	extern char *optarg;
	char command[200];
	char* res;
	int ret=0;
	int sysret=0;
	int i=0;

	if (sem_init(&Write_sem, 0, 0) == -1)
        handle_error("Writesem_init");
	if (sem_init(&Read_sem, 0, 0) == -1)
        handle_error("Readsem_init");	
	/* Defaults */
	strcpy(LibraryPath,"/usr/lib/libcanfestival_can_peak_linux.so");
	strcpy(BoardBusName,"0");
	strcpy(BoardBaudRate,"1M");

	/* Init stack timer */
	TimerInit();
        
	if (argc > 1){
        printf("ok\n");
		/* Strip command-line*/
		for(i=1 ; i<argc ; i++)
		{
			if(ProcessCommand(argv[i]) == INIT_ERR) goto init_fail;
		}
	}
    NodeInit(0,1);

    RegisterSetODentryCallBack(CANOpenShellOD_Data, 0x2003, 0, &OnStatus3Update);


	help_menu();
	CurrentNode = 3;
    sleep(1);
    //setState(CANOpenShellOD_Data, Operational);     // Put the master in operational mode
    stopSYNC(CANOpenShellOD_Data);

	/* Enter in a loop to read stdin command until "quit" is called */
	while(ret != QUIT)
	{
		// wait on stdin for string command
		rl_on_new_line ();
		res = rl_gets();
		//sysret = system(CLEARSCREEN);
		if(res[0]=='.'){
		ret = ProcessCommand(res+1);
		}
		else if(res[0]==','){
		ret = ProcessFocusedCommand(res+1);
		}
        else if (res[0]=='\n'){

        }
		else {
			
			EnterMutex();
			SDO_write(CANOpenShellOD_Data,CurrentNode,0x1023,0x01,strlen(res),visible_string, res, 0);

			EnterMutex();
			SDO_read(CANOpenShellOD_Data,CurrentNode,0x1023,0x03,visible_string,0);
			
			printf("%s\n",SDO_read_data);
		}
		fflush(stdout);
        usleep(500000);
	}

	printf("Finishing.\n");

	// Stop timer thread
	StopTimerLoop(&Exit);

	/* Close CAN board */
	canClose(CANOpenShellOD_Data);

init_fail:
	TimerCleanup();
	return 0;
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: lrtfm/math
int main(int argc, char*argv[])
{
    int number;
    char formula_string[10][MAX_FORUMLA_LEN] ; //= "sin("STR(PI)"/2)*cos(0)";
    SYM_PAIR sym_value_map[MAX_SYM_NUM];
    int sym_num = 0;
    real ret = 0;
    int i;
    int len;
    int j = 0;
    int save_str_num = 0;
    char * newline = NULL;

    while (1)
    {
        newline = rl_gets();
        if (newline == NULL) {
            continue;
        }
        else {
            if (!strcmp(newline, "exit")) {
                break;
            }
            else {

                if(issym(newline))
                {
                    if (sym_num < MAX_SYM_NUM) {
                        get_sym_name_value(newline, &sym_value_map[sym_num]);
                        sym_num++;
                    }
                }
                else {
                    F_NODE *formula = NULL;
                    formula = parse(newline);
                    ret = compute(formula, sym_value_map, sym_num);
                    printf("result: %s = %lf\n", newline, ret);
                }
            }
        }
        
        
    }

    /*
    for (i = 0; i < 10; ++i) {
        printf("Please input the symbol and value:\n");
        scanf("%s %lf", sym_value_map[0].sym_name, &sym_value_map[0].sym_value);
        sym_num = 1;
        getchar();
        printf("Please input the formula (without space!!!):\n");
        // scanf("%s", formula_string);
        // TODO input data.
        // gets(formula_string);

        fgets(formula_string[j], MAX_FORUMLA_LEN, stdin);
        len = strlen(formula_string[j]);
        if (formula_string[j][len - 1] == '\n') {
            formula_string[j][len - 1] = '\0';
        }
        

        F_NODE *formula = NULL;
        formula = parse(formula_string[j]);
        ret = compute(formula, sym_value_map, sym_num);
        printf("%s = %lf\n", formula_string[j], ret);
        free_node(formula);

        j = (j + 1) % 10;
        save_str_num++;
        if (save_str_num > 10 ) {
            save_str_num = 10;
        }
    }*/
    
    return 0;
}
Exemplo n.º 14
0
int main (int argc, char **argv) {
  toptions   *opt;
  tsequence  *seq;
  treadseq   *rs        = NULL;
  ttokenizer *tokenizer = NULL;
  char       *command;



  opt = (toptions *) calloc(1,sizeof(toptions));

  init_defaults(opt);
  process_args(opt, 0, argc, argv);

  if (!opt->terminate) {
    if (optind < argc)               rs = readseq_open(READSEQ_STRING, argv[optind]);
    else if (opt->inputfile)         rs = readseq_open(READSEQ_FILE,   opt->inputfile);
    else if (!isatty(fileno(stdin))) rs = readseq_open(READSEQ_STDIN,  NULL);
    else {
      printf("Interactive mode. Try `./RNAfold -h` for more information.\n", argv[0]);
      rl_init();
      opt->interactive = 1;
      opt->colored_output = 1 - opt->colored_output;
      tokenizer = tokenizer_new();
      rs = readseq_open(READSEQ_STRING, "");
    }

    while (1) {
      if (opt->interactive) {
        if (opt->colored_output)
          printf("%s\nInput sequence (upper or lower case); :q to quit, -h for help.\n....,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....8\n%s",COLOR_RED,COLOR_DEFAULT);
        else
	  printf("\nInput sequence (upper or lower case); :q to quit, -h for help.\n....,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....8\n");
        command = rl_gets();

        if (!command || (command[0] == '@') || ((command[0] == ':') && (command[1] == 'q'))) {
          pcolor(opt->colored_output,COLOR_BLUE);
          printf("Leaving RNAfold.");
          pcolor(opt->colored_output,COLOR_DEFAULT);
          printf("\n");
          exit(0);
        }
        else if (command[0] == ':') {
          pcolor(opt->colored_output,COLOR_BLUE);
          if (command[1] == 's') print_settings(opt);
          if (command[1] == 'd') {
            init_defaults(opt);
            opt->colored_output = 1;
            opt->interactive = 1;
            printf("Activated default configuration.\n");
            pcolor(opt->colored_output,COLOR_DEFAULT);
          }
          if (command[1] == 'e') {
            system(command + 2);
          }
          if (command[1] == 'r') {
            system("make update");
            system("./RNAfold");
            exit(0);
          }
        }
        else if (command[0] == '-') {
          tokenizer_exec(tokenizer, argv[0], command);
          process_args(opt, 1, tokenizer->count, tokenizer->token);
          if (opt->inputfile) {
            rs = readseq_free(rs);
            rs = readseq_open(READSEQ_FILE, opt->inputfile);
          }
          free(opt->inputfile);
          opt->inputfile = NULL;
        }
        else {
          rs = readseq_free(rs);
          rs = readseq_open(READSEQ_STRING, command);
        }
      }

      while (1) {
        seq = readseq_next_fasta(rs);
        if (!(seq->success)) break;
        if (1) {
          main_rnafold_mfe(opt, seq);
        }

        sequence_free(seq);
      }

      if (!opt->interactive) break;
    }
  }
  exit(0);
}
Exemplo n.º 15
0
char * read_line(){
  return rl_gets();
}
Exemplo n.º 16
0
int main(int argc, char **argv)
{
	char *line = NULL;
	CONN_TYPE *conn;
	const char *file = NULL;
	void *gl_pool;
	cmd_params_st params;

	memset(&params, 0, sizeof(params));

	gl_pool = talloc_init("occtl");
	if (gl_pool == NULL) {
		fprintf(stderr, "talloc init error\n");
		exit(1);
	}

	ocsignal(SIGPIPE, SIG_IGN);

	if (argc > 1) {
		while (argc > 1 && argv[1][0] == '-') {
			if (argv[1][1] == 'j'
			    || (argv[1][1] == '-' && argv[1][2] == 'j')) {
				params.json = 1;

				argv += 1;
				argc -= 1;

			} else if (argv[1][1] == 'n'
			    || (argv[1][1] == '-' && argv[1][2] == 'n')) {
				params.no_pager = 1;

				argv += 1;
				argc -= 1;

			} else if (argv[1][1] == 'v'
			    || (argv[1][1] == '-' && argv[1][2] == 'v')) {
				version();
				exit(0);
			} else if (argc > 2 && (argv[1][1] == 's'
			    || (argv[1][1] == '-' && argv[1][2] == 's'))) {
				file = talloc_strdup(gl_pool, argv[2]);

				if (argc == 3) {
					goto interactive;
				}

				argv += 2;
				argc -= 2;
			} else {
				usage();
				exit(0);
			}
  		}

  		/* handle all arguments as a command */
		exit(single_cmd(argc, argv, gl_pool, file, &params));
	}

 interactive:
	conn = conn_init(gl_pool, file);

	initialize_readline();

	version();
	for (;;) {
		line = rl_gets(line);
		if (line == NULL)
			return 0;

		handle_cmd(conn, line, 0);
	}

	conn_close(conn);

	return 0;
}
Exemplo n.º 17
0
int main(int argc, char *argv[]) {
    int opt;

    char *scriptfile, prompt[50];
    extern void my_interfaceparse(char *my_string);
    /*  YY_BUFFER_STATE flex_command; */
    stack_init();
    srand ((unsigned int)time(NULL));
    while ((opt = getopt(argc, argv, "e:f:hl:pqrsv")) != -1) {
        switch(opt) {
        case 'e':
            my_interfaceparse(optarg);
            break;
        case 'f':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != NULL) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
            }
            exit(0);
        case 'h':
            print_help();
            exit(0);
        case 'l':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != NULL) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
		xxfree(scriptfile);
            }
            break;
        case 'p':
            pipe_mode = 1;
            break;
        case 'q':
            quiet_mode = 1;
            break;
        case 'r':
            use_readline = 0;
            break;
        case 's':
	  exit(0);
        case 'v':
            printf("%s %i.%i.%i%s\n",argv[0],MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,STATUS_VERSION);
            exit(0);
        default:
            fprintf(stderr, "%s", usagestring);
            exit(EXIT_FAILURE);
        }
    }

    if (!pipe_mode && !quiet_mode) 
        printf("%s",disclaimer);
    rl_basic_word_break_characters = " >";

    rl_attempted_completion_function = my_completion;
    for(;;) {
        if (promptmode == PROMPT_MAIN)
            sprintf(prompt, "foma[%i]: ",stack_size());
        if (promptmode == PROMPT_A && apply_direction == AP_D)
            sprintf(prompt, "apply down> ");
        if (promptmode == PROMPT_A && apply_direction == AP_U)
            sprintf(prompt, "apply up> ");
        if (promptmode == PROMPT_A && apply_direction == AP_M)
            sprintf(prompt, "apply med> ");
        if (pipe_mode || quiet_mode)
            prompt[0] = '\0';

        command = rl_gets(prompt);

        if (command == NULL && promptmode == PROMPT_MAIN) {
            printf("\n");
            exit(0);
        }
        if (command == NULL && promptmode == PROMPT_A) {
            /* apply_clear(); */
            promptmode = PROMPT_MAIN;
            printf("\n");
            continue;
        }
        input_is_file = 0;
        my_interfaceparse(command);
    }
}
Exemplo n.º 18
0
int main(int nargs, char *args[])
{
  char *line, *words[MAX_WORDS];
  char string[1024],combined[1024],line_s[MAX_LINE];
  char c, *dir=NULL,*cwd, pwd[PATH_MAX];
  char username[128],password[128],viFile[256],viTemp[256];
  char comname[128],authkey[80],authkeyword[64],key[64];
  int  gotauthkey=0,gotusername=0,gotvi=0,gotnew=0;
  int  res, i, n, status, nwords=0;
  FILE *auth_fp = (FILE *)0;
  FILE *key_fp = (FILE *)0;
  pid_t wpid, pid;
  char mode[] = "0755";
  struct stat stbuf;

  // get server login user and password
  while ((c = getopt(nargs, args, "dhu:l:")) != -1)
    switch (c) {

    case 'h':             // help
      printf("Usage: %s {-d} {-h} {-u <username>}\n\n",args[0]);
      printf("-d : don't delete /tmp files\n");
      printf("-h : help\n");
      printf("-u : commands.com username\n");
      exit(0);

    case 'u':             // username
      strcpy(username,optarg);
      gotusername = 1;
      strcpy(password,getpass("Password: "******"Usage: %s {-d} {-h} {-u <username>}\n\n",args[0]);
      printf("-d : don't delete /tmp files\n");
      printf("-h : help\n");
      printf("-u : commands.com username\n");
      exit(0);
      break;
    }

  // if we have both the username and password, login and
  // get the authkey

  // get the authorization key for the username
  if (gotusername) {
    if ((res = getAuthKey(username, password, authkey, key)) != 0) {
      printf("Unable to get authkey from server (%d)\n",res);
      exit(1);
    }
  } else {
    getKeyVal(key);
  }

  // create the authkey.json file only if we have -u
  sprintf (comname,"/tmp/.%s.commands.com",getenv("USER"));
  if (gotusername) {
    sscanf (authkey,"{\"%[^\"]\":\"%[^\"]",authkeyword,authKeyVal);
    if (!strcmp(authkeyword,"error")) {
      printf("Invalid Login.. Exiting.\n");
      exit(1);
      // do not save error as authkey
    } else {
      auth_fp = fopen(comname,"w");
      if (auth_fp == NULL) {
        printf("unable to create %s\n",comname);
        exit(1);
      }
      fputs(authkey,auth_fp);
      fputs("\n",auth_fp);
      fclose(auth_fp);
    }
  } else {
    auth_fp = fopen(comname, "r");
    if (auth_fp != NULL) {
      if(fgets(authkey, 64, auth_fp) == NULL) {
        printf("Unable to read authkey from %s\n",comname);
        exit(1);
      }
      // remove trailing \n
      n = strlen(authkey);
      if (authkey[n-1] == '\n') authkey[n-1] = '\0';
      gotauthkey = 1;
    }
  }

  // create the key.json file
  key_fp = fopen(fName(KEY_NAME),"w");
  if (key_fp == NULL) {
    printf("unable to create %s\n",fName(KEY_NAME));
    exit(1);
  }
  fputs(key,key_fp);
  fputs("\n",key_fp);
  fclose(key_fp);

  // save off the key url to display to the user when we are done
  sscanf (key,"{\"key\":\"%[^\"]",keyVal);
  sprintf (displayUrl,"%s/%s",gotoKeyUrl,keyVal);

  // save off the authkey value
  if (gotusername || gotauthkey) {
    sscanf (authkey,"{\"%[^\"]\":\"%[^\"]",authkeyword,authKeyVal);
    if (!strcmp(authkeyword,"error")) {
      printf("\nError: %s\n\n",authKeyVal);
      exit(1);
    } else {
      printf("\nSuccessfully logged in...");
      if (gotusername) {
        printf("\nAuthKey saved to %s.  Delete file to return to Anonymous posting.\n",comname);
      } else {
        printf("\nAuthKey retrieved from %s.  Delete file to return to Anonymous posting.\n",comname);
      }
    }
  } else {
    strcpy(authKeyVal,"");
  }


  // set up termination function
  atexit((void *)terminate);

  // catch abort signals
  signal(SIGINT,(void *)terminate2);	// trap ctl-c
  signal(SIGTERM,(void *)terminate2);	// trap kill -15

  // create the post.txt file
  post_fp = fopen(fName(POST_NAME),"w");
  if (post_fp == NULL) {
    printf("unable to create post file %s\n",fName(POST_NAME));
    exit(1);
  }

  // record all input from the user
  while(1)
    {
      if (!gotdebug)
        unlink(fName(SHELL_NAME));

	line = rl_gets();
        if (line == NULL) {		// trap ctl-d
          exit(1);
        } else {
	  strcpy(line_s, line);
        }
      line = rl_gets();
      strcpy(line_s, line);
      if (line == NULL) {		// trap ctl-d
        exit(1);
      }

      // break the line up into words
      tokenize(line, words, &nwords);

      // just a blank line?
      if (words[0] == NULL) {
        continue;
      }

      // are we done ?
      if (!strcasecmp(words[0], "exit")) {
        exit(1);
      }

      fputs("monitor$ ",post_fp);
      fflush(post_fp);
      fputs(line_s,post_fp);
      fflush(post_fp);
      fputs("\n",post_fp);
      fflush(post_fp);



      // toss out any commands that cannot be handled such
      // as those that use libcurses.so

      if (!strcasecmp(words[0], "top")) {
        printf("Unable to capture output from %s\n",words[0]);
        sprintf(string,"Unable to capture output from %s\n",words[0]);
        fputs(string,post_fp);
        fflush(post_fp);
        continue;
      }


      // builtin command
      if (!strcasecmp(words[0], "cd")) {
        if (nwords == 1)                     dir = getenv("HOME");
        if (nwords == 2 && *words[1] == '~') dir = getenv("HOME");
        if (nwords == 2 && *words[1] != '~') dir = words[1];
        if (chdir(dir) == -1) {
          perror("chdir");
          fputs(strerror(errno),post_fp);
          fflush(post_fp);
          fputs("\n",post_fp);
          fflush(post_fp);
          continue;
        }
        continue;
      }

      // builtin command
      if (!strcasecmp(words[0], "pwd")) {
        if(NULL == (cwd = getcwd(pwd, PATH_MAX))) {
          strcpy(pwd,"Unable to get current working directory\n");
        }
        printf("%s\n",pwd);
        fputs(pwd,post_fp);
        fflush(post_fp);
        fputs("\n",post_fp);
        fflush(post_fp);
        continue;
      }

      // builtin command
      if (!strcasecmp(words[0], "export")) {
        if (nwords > 1) {
          putenv(words[1]);
          continue;
        }
      }

      // look for "ls" by itself and add -C to make it tabbed format
      // because when piped through tee, it thinks it is not connected
      // to a terminal.
      if (!strcasecmp(words[0], "ls")) {
        if (nwords == 1) {
          words[1] = "-C";
          nwords = 2;
        }
      }

      // look for "man" and add | col -b
      if (!strcasecmp(words[0], "man")) {
        if (nwords == 2) {
          words[2] = "|";
          words[3] = "col";
          words[4] = "-b";
          nwords = 5;
        }
        // for when there is a "man 3 foo"
        if (nwords == 3) {
          words[3] = "|";
          words[4] = "col";
          words[5] = "-b";
          nwords = 6;
        }
      }

      // process special "vi" command
      if (!strcasecmp(words[0], "vi")) {
        if (nwords == 1) {
          printf("Please specify the new file you wish to create.\n");
          printf("It is required to correctly log the new file.\n");
          continue;
        }
        gotvi = 1;
        if (stat(words[1],&stbuf) != 0) {
          // new file
          gotnew=1;
          strcpy(viFile,words[1]);
        } else {
          // make copy of existing file
          strcpy(viFile,words[1]);
          strcpy(viTemp,fName(TEMP_NAME));
          my_cp(viFile,viTemp);
          gotnew=0;
        }
      } else {
        gotvi = 0;
      }

      // close the post.txt before forking
      fclose(post_fp);

      // OK, lets process the external command using fork/execvp
      if ((pid = fork ()) < 0) {
        perror ("fork");
        exit(0);
      }

      // this will split output between the terminal and post.txt
      //  <command> 2>&1 | tee -ai <file>
      if (pid == 0) {		// if child then exec the command
        if (!gotvi) {
          // create the bash script
          tmp_fp = fopen(fName(SHELL_NAME),"w");
          if (tmp_fp == NULL) {
            printf("unable to create %s file\n",fName(SHELL_NAME));
            exit(1);
          }
          // set file permission to 755
          i = strtol(mode, 0, 8);
          chmod (fName(SHELL_NAME),i);
          memset(combined,0,sizeof(combined));
          for(i=0;i<nwords;i++) {
            strcat(combined,words[i]);
            strcat(combined," ");
          }

          sprintf(string,"#!/bin/bash -l\n%s 2>&1 | tee -ai %s\n",combined,fName(POST_NAME));
          fputs(string,tmp_fp);
          fclose(tmp_fp);

          execlp ("/bin/bash","bash","-c",fName(SHELL_NAME),(char *)0);
          perror ("execlp");
          exit(0);
        } else {

          execlp ("vi","vi",viFile,(char *)0);
          perror ("execlp");
          exit(0);
        }
      }

      if (pid > 0)            // parent waits for child process to terminate
        {
          do {
            wpid = waitpid(pid, &status, WUNTRACED);
            if (wpid == -1) {
              perror("waitpid");
              return(0);
            }


            if (WIFEXITED(status)) {
              //printf("child exited, status=%d\n", WEXITSTATUS(status));


            } else if (WIFSIGNALED(status)) {
              printf("process killed (signal %d)\n", WTERMSIG(status));


            } else if (WIFSTOPPED(status)) {
              printf("process stopped (signal %d)\n", WSTOPSIG(status));


            } else {    // Non-standard case -- may never happen
              printf("Unexpected status (0x%x)\n", status);
            }
          } while (!WIFEXITED(status) && !WIFSIGNALED(status));

          // existing file
          if (gotvi && !gotnew) {
            my_diff(viTemp,viFile,fName(POST_NAME));
            unlink(viTemp);
          }

          // new file
          if (gotvi && gotnew) {
            my_append(viFile,fName(POST_NAME));
          }

          // re-open the post.txt file
          post_fp = fopen(fName(POST_NAME),"a");
          if (post_fp == NULL) {
            printf("unable to re-open post file %s\n",fName(POST_NAME));
            exit(2);
          }

        }



    }

  exit(0);
}