Example #1
0
int				main(int argc, char **argv, char **env_table)
{
	t_env		*env;
	char		*line;

	if (!(env = (t_env *)malloc(sizeof(t_env))))
		return (-1);
	init_env(env, env_table);
	write(1, PROMPT, sizeof(PROMPT) - 1);
	while (get_next_line(1, &env->line) > 0)
	{
		if (*env->line)
		{
			env->command = get_called_command(env->line);
			if (!strcmp(env->command, "env"))
				builtin_env(env);
			else if (!strcmp(env->command, "setenv"))
				builtin_setenv(env);
			else if (!strcmp(env->command, "unsetenv"))
				builtin_unsetenv(env);
			else if (!strcmp(env->command, "exit"))
				builtin_exit(env);
			else
				unknown_command(env->command);
		}
		write(1, PROMPT, sizeof(PROMPT) - 1);
	}
	return (0);
}
Example #2
0
File: shell.c Project: nysan/alpine
int
bktoshell(int f, int n)
{
    UCS z = CTRL | 'Z';

    if(!(gmode&MDSSPD)){
	unknown_command(z);
	return(FALSE);
    }
    if(Pmaster){
        if(!Pmaster->suspend){
	    unknown_command(z);
	    return(FALSE);
	}
	(*Pmaster->suspend)();
	return(TRUE);
    }
			 
    mswin_minimize();
    return(TRUE);
}
Example #3
0
/*
 * Check to see if we have a complete command ready..
 */
int
check_command(char *command)  {
    register int i;
    char *sep = " ";
    char *cmd_name;
    char cmd_copy[MAX_SOCK_COMMAND_LEN];


    if (command[0] == '\r')  {
        unknown_command();
        return 0;
    }


      /* Commands to use are terminated via \r\n, if it exists we have
         a command so we can strip them */
    if (strstr(command, "\r\n") != NULL)  {
        command[strlen(command)-2] = '\0';

        for (i = 0; ; ++i)  {
            if (commands[i].function == NULL)  {
                break;
            }  else  {
                strncpy(cmd_copy, command, MAX_SOCK_COMMAND_LEN);
                cmd_name = strtok(cmd_copy, sep);

                  /* That command exists and can be executed (everything up to
                     first " " in char *command) */
                if (strncmp(cmd_name, commands[i].command, MAX_SOCK_COMMAND_LEN) == 0)  {
                    return 1;
                }
            }
        }
    }

    unknown_command();
    return 0;
}
void IOSCfgParser::ip_commands() {
	
	try {      // for error handling
		match(IP);
		{
		switch ( LA(1)) {
		case ACCESS_LIST:
		{
			ip_access_list_ext();
			break;
		}
		case ACCESS_GROUP:
		case ADDRESS:
		{
			interface_known_ip_commands();
			break;
		}
		case COMMUNITY_LIST:
		{
			community_list_command();
			break;
		}
		case ICMP:
		case TCP:
		case HOST:
		{
			ip_unused_command();
			break;
		}
		case WORD:
		{
			unknown_command();
			break;
		}
		default:
		{
			throw ANTLR_USE_NAMESPACE(antlr)NoViableAltException(LT(1), getFilename());
		}
		}
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}
Example #5
0
void run_js(void *jsargs) {
  js_call *call_data = (js_call *) jsargs;
  spidermonkey_drv_t *dd = call_data->driver_data;
  ErlDrvBinary *args = call_data->args;
  driver_free(call_data);
  char *data = args->orig_bytes;
  char *command = read_command(&data);
  char *call_id = read_string(&data);
  char *result = NULL;
  if (strncmp(command, "ej", 2) == 0) {
    char *filename = read_string(&data);
    char *code = read_string(&data);
    result = sm_eval(dd->vm, filename, code, 1);
    if (strstr(result, "{\"error\"") != NULL) {
      send_error_string_response(dd, call_id, result);
    }
    else {
      send_string_response(dd, call_id, result);
    }
    driver_free(filename);
    driver_free(code);
    driver_free(result);
  }
  else if (strncmp(command, "dj", 2) == 0) {
    char *filename = read_string(&data);
    char *code = read_string(&data);
    result = sm_eval(dd->vm, filename, code, 0);
    if (result == NULL) {
      send_ok_response(dd, call_id);
    }
    else {
      send_error_string_response(dd, call_id, result);
      driver_free(result);
    }
    driver_free(filename);
    driver_free(code);
  }
  else if (strncmp(command, "sd", 2) == 0) {
    dd->shutdown = 1;
    send_ok_response(dd, call_id);
  }
  else {
    unknown_command(dd, call_id);
  }
  driver_free(command);
  driver_free(call_id);
  driver_binary_dec_refc(args);
}
Example #6
0
File: shell.c Project: nysan/alpine
/*
 *  bktoshell - suspend and wait to be woken up
 */
int
bktoshell(int f, int n)
{
    UCS z = CTRL | 'Z';

    if(!(gmode&MDSSPD)){
	unknown_command(z);
	return(FALSE);
    }

    if(Pmaster){
	if(!Pmaster->suspend){
	    unknown_command(z);
	    return(FALSE);
	}

	if((*Pmaster->suspend)() == NO_OP_COMMAND){
	    int rv;
	
	    if(km_popped){
		term.t_mrow = 2;
		curwp->w_ntrows -= 2;
	    }

	    clearcursor();
	    mlerase();
	    rv = (*Pmaster->showmsg)('x');
	    ttresize();
	    picosigs();
	    if(rv)		/* Did showmsg corrupt the display? */
	      pico_refresh(0, 1);	/* Yes, repaint */

	    mpresf = 1;
	    if(km_popped){
		term.t_mrow = 0;
		curwp->w_ntrows += 2;
	    }
	}
	else{
	    ttresize();
	    pclear(0, term.t_nrow);
	    pico_refresh(0, 1);
	}

	return(TRUE);
    }

    if(gmode&MDSPWN){
	char *shell;
	int   dummy;

	vttidy();
	movecursor(0, 0);
	(*term.t_eeop)();
	printf("\n\n\nUse \"exit\" to return to Pi%s\n",
	       (gmode & MDBRONLY) ? "lot" : "co");
	system((shell = (char *)getenv("SHELL")) ? shell : "/bin/csh");
	rtfrmshell(dummy);	/* fixup tty */
    }
    else {
	movecursor(term.t_nrow-1, 0);
	peeol();
	movecursor(term.t_nrow, 0);
	peeol();
	movecursor(term.t_nrow, 0);
	printf("\n\n\nUse \"fg\" to return to Pi%s\n",
	       (gmode & MDBRONLY) ? "lot" : "co");
	ttclose();
	movecursor(term.t_nrow, 0);
	peeol();
	(*term.t_flush)();

	signal(SIGCONT, rtfrmshell);	/* prepare to restart */
	signal(SIGTSTP, SIG_DFL);			/* prepare to stop */
	kill(0, SIGTSTP);
    }

    return(TRUE);
}
Example #7
0
static int run_action_server_do(struct async *as, struct sdirs *sdirs,
	const char *incexc, int srestore, int *timer_ret, struct conf **cconfs)
{
	int ret;
	int resume=0;
	char msg[256]="";
	struct iobuf *rbuf=as->asfd->rbuf;

	// Make sure some directories exist.
	if(mkpath(&sdirs->current, sdirs->dedup))
	{
		snprintf(msg, sizeof(msg),
			"could not mkpath %s", sdirs->current);
		log_and_send(as->asfd, msg);
		return -1;
	}

	if(rbuf->cmd!=CMD_GEN) return unknown_command(as->asfd);

	// List and diff should work even while backups are running.
	if(!strncmp_w(rbuf->buf, "list ")
	  || !strncmp_w(rbuf->buf, "listb "))
		return run_list(as->asfd, sdirs, cconfs);

	if(!strncmp_w(rbuf->buf, "diff "))
		return run_diff(as->asfd, sdirs, cconfs);

	switch((ret=get_lock_sdirs(as->asfd, sdirs)))
	{
		case 0: break; // OK.
		case 1: return 1; // Locked out.
		default: // Error.
			maybe_do_notification(as->asfd, ret,
				"", "error in get_lock_sdirs()",
				"", buf_to_notify_str(rbuf), cconfs);
			return -1;
	}

	switch((ret=check_for_rubble(as, sdirs, incexc, &resume, cconfs)))
	{
		case 0: break; // OK.
		case 1: return 1; // Now finalising.
		default: // Error.
			maybe_do_notification(as->asfd, ret,
				"", "error in check_for_rubble()",
				"", buf_to_notify_str(rbuf), cconfs);
			return -1;
	}

	if(!strncmp_w(rbuf->buf, "backup"))
	{
		ret=run_backup(as, sdirs, cconfs, incexc, timer_ret, resume);
		if(*timer_ret<0)
			maybe_do_notification(as->asfd, ret, "",
				"error running timer script",
				"", "backup", cconfs);
		else if(!*timer_ret)
			maybe_do_notification(as->asfd, ret, sdirs->client,
				sdirs->current, "log", "backup", cconfs);
		return ret;
	}

	if(!strncmp_w(rbuf->buf, "restore ")
	  || !strncmp_w(rbuf->buf, "verify "))
		return run_restore(as->asfd, sdirs, cconfs, srestore);

	if(!strncmp_w(rbuf->buf, "Delete "))
		return run_delete(as->asfd, sdirs, cconfs);

	// Old clients will send 'delete', possibly accidentally due to the
	// user trying to use the new diff/long diff options.
	// Stop them from working, just to be safe.
	if(!strncmp_w(rbuf->buf, "delete "))
	{
		logp("old style delete from %s denied\n",
			get_string(cconfs[OPT_CNAME]));
		as->asfd->write_str(as->asfd, CMD_ERROR,
			"old style delete is not supported on this server");
		return -1;
	}

	return unknown_command(as->asfd);
}
void IOSCfgParser::cfgfile() {
	
	try {      // for error handling
		{ // ( ... )+
		int _cnt3=0;
		for (;;) {
			switch ( LA(1)) {
			case LINE_COMMENT:
			{
				comment();
				break;
			}
			case IOSVERSION:
			{
				version();
				break;
			}
			case HOSTNAME:
			{
				hostname();
				break;
			}
			case IP:
			{
				ip_commands();
				break;
			}
			case INTRFACE:
			{
				intrface();
				break;
			}
			case CONTROLLER:
			{
				controller();
				break;
			}
			case VLAN:
			{
				vlan();
				break;
			}
			case ACCESS_LIST:
			{
				access_list_commands();
				break;
			}
			case EXIT:
			{
				exit();
				break;
			}
			case DESCRIPTION:
			{
				description();
				break;
			}
			case SHUTDOWN:
			{
				shutdown();
				break;
			}
			case CERTIFICATE:
			{
				certificate();
				break;
			}
			case QUIT:
			{
				quit();
				break;
			}
			case WORD:
			{
				unknown_command();
				break;
			}
			case NEWLINE:
			{
				match(NEWLINE);
				break;
			}
			default:
			{
				if ( _cnt3>=1 ) { goto _loop3; } else {throw ANTLR_USE_NAMESPACE(antlr)NoViableAltException(LT(1), getFilename());}
			}
			}
			_cnt3++;
		}
		_loop3:;
		}  // ( ... )+
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		} else {
			throw;
		}
	}
}
Example #9
0
File: pico.c Project: ctubio/alpine
/*
 * This is the general command execution routine. It handles the fake binding
 * of all the keys to "self-insert". It also clears out the "thisflag" word,
 * and arranges to move it to the "lastflag", so that the next command can
 * look at it. Return the status of command.
 */
int
execute(UCS c, int f, int n)
{
    KEYTAB *ktp;
    int     status, ww;

    ktp = (Pmaster) ? &keytab[0] : &pkeytab[0];

    while (ktp->k_fp != NULL) {
	if (ktp->k_code == c) {

	    if(lastflag&CFFILL){
		curwp->w_flag |= WFMODE;
		if(Pmaster == NULL)
		  sgarbk = TRUE;
	    }

	    thisflag = 0;
	    status   = (*ktp->k_fp)(f, n);
	    if((lastflag & CFFILL) && !(thisflag & CFFILL))
	      fdelete();
	    if((lastflag & CFFLBF) && !(thisflag & CFFLBF))
	      kdelete();

	    lastflag = thisflag;

	    /*
	     * Reset flag saying wrap should open a new line whenever
	     * we execute a command (as opposed to just typing in text).
	     * However, if that command leaves us in the same line on the
	     * screen, then don't reset.
	     */
	    if(curwp->w_flag & (WFMOVE | WFHARD))
	      curbp->b_flag |= BFWRAPOPEN;    /* wrap should open new line */

	    return (status);
	}
	++ktp;
    }

    if(lastflag & CFFILL)		/* blat unusable fill data */
      fdelete();
    if(lastflag & CFFLBF)
      kdelete();

    if (VALID_KEY(c)) {			/* Self inserting.      */

	if (n <= 0) {                   /* Fenceposts.          */
	    lastflag = 0;
	    return (n<0 ? FALSE : TRUE);
	}
	thisflag = 0;                   /* For the future.      */

	/* do the appropriate insertion */
	/* pico never does C mode, this is simple */
	status = linsert(n, c);

	/*
	 * Check to make sure we didn't go off of the screen
	 * with that character.  Take into account tab expansion.
	 * If so wrap the line...
	 */
	if(curwp->w_bufp->b_mode & MDWRAP){
	    int j, wid;

	    wid = 0;
	    for(j = 0; j < llength(curwp->w_dotp); j++)
	      if(ucs4_isspace(lgetc(curwp->w_dotp, j).c)){
		  if(lgetc(curwp->w_dotp, j).c == TAB){
		    ++wid;
		    while(wid & 0x07)
		      ++wid;
		  }
		  else
		    ++wid;
	      }
	      else{
		  ww = wcellwidth((UCS) lgetc(curwp->w_dotp, j).c);
		  wid += (ww >= 0 ? ww : 1);
		  if(wid > fillcol){
		      wrapword();
		      break;
		  }
	      }
	}

	lastflag = thisflag;
	return (status);
    }
    
    unknown_command(c);

    lastflag = 0;                           /* Fake last flags.     */
    return (FALSE);
}
Example #10
0
void request_check(int index, char* buf){
    char tokens[MAX_MSG_TOKENS][MAX_MSG_LEN+1];
    int arg_num = tokenize(buf,tokens);
    int type,connfd;

    connfd = p.clientfd[index];

    if (!strcmp(tokens[0],"USER"))
        type = USER_CMD;
    else if(!strcmp(tokens[0],"NICK"))
        type = NICK_CMD;
    else if(!strcmp(tokens[0],"JOIN"))
        type = JOIN_CMD;
    else if(!strcmp(tokens[0],"QUIT"))
        type = QUIT_CMD;
    else if(!strcmp(tokens[0],"PART"))
        type = PART_CMD;
    else if(!strcmp(tokens[0],"LIST"))
        type = LIST_CMD;
    else if(!strcmp(tokens[0],"WHO"))
        type = WHO_CMD;
    else if(!strcmp(tokens[0],"PRIVMSG"))
        type = PRIVMSG_CMD;
    else
        type = UNKONWN_CMD;

    //DEBUG
    int i;
    printf(" # CMD:%s\t ARG_NUM:%d\t",tokens[0],arg_num);
    for(i=0;i<4;i++)
        printf(" ARG%d:%s\t",i,tokens[i+1]);
    printf("\n");

    if(type == UNKONWN_CMD)
        unknown_command(connfd,tokens[0]);
    else if(arg_num < ARG_NUM[type]){
        char msg[MAX_MSG_LEN];
        if(type == NICK_CMD)
            /* NICK ERRRO TYPE: ERR_NOERR_NONICKNAMEGIVEN */
            snprintf(msg,MAX_MSG_LEN,":No nickname given\n");
        else if(type == PRIVMSG_CMD){
            /* PRIVMSG ERRRO TYPE: ERR_NORECIPIENT */
            if(!arg_num)
                snprintf(msg,MAX_MSG_LEN,":No recipient given PRIVMSG\n");
            /* PRIVMSG ERRRO TYPE: ERR_NOTEXTTOSEND */
            else
                snprintf(msg,MAX_MSG_LEN,":No text to send\n");
        }else
            snprintf(msg,MAX_MSG_LEN,"%s:Not enough parameters\n", tokens[0]);
        send_msg_back(connfd,msg);
    }
    else
        switch(type){
            case QUIT_CMD:
                quit_command(index);
                break;
            case USER_CMD:
                user_command(connfd,tokens[1],tokens[4]);               
                break;
            case NICK_CMD:
                nick_command(connfd,tokens[1]);
                break;
            default:
                if(check_register(connfd)){
                    switch(type){
                        case JOIN_CMD:
                            join_command(connfd,tokens[1]);
                            break;
                        case PART_CMD:
                            part_command(connfd,tokens[1],1);
                            break;
                        case LIST_CMD:
                            list_command(connfd);
                            break;
                        case WHO_CMD:
                            who_command(connfd,tokens[1]);
                            break;
                        case PRIVMSG_CMD:
                            privmsg_command(connfd,tokens[1],tokens[2]);
                    }
                }else
                    send_msg_back(connfd,":You have not registered\n");
        }
}
Example #11
0
File: bind.c Project: ctubio/alpine
/*
 * scrollw - takes beginning row and ending row to diplay an array
 *           of text lines.  returns either 0 if scrolling terminated
 *           normally or the value of a ctrl character typed to end it.
 *
 * updates - 
 *     01/11/89 - added stripe call if 1st char is tilde - '~'
 *
 */
int
wscrollw(int begrow, int endrow, char *utf8textp[], int textlen)
{
    register int	loffset = 0; 
    register int	prevoffset = -1; 
    register int	dlines;
    register int	i;
    register int	cont;
    register int	done = 0;
    register char	*buf;
    UCS	 c;
     
    dlines = endrow - begrow - 1;
    while(!done) {
        /*
         * diplay a page loop ...
         */
	if(prevoffset != loffset){
       	    for(i = 0; i < dlines; i++){
                movecursor(i + begrow, 0);
                peeol();
                if((loffset+i) < textlen){
		    buf = _(&(utf8textp[loffset+i][0]));
		    if(*buf == '~'){
			buf++;
			wstripe(begrow+i, 0, buf, '~');
		    }
		    else{
			pputs_utf8(buf, 0);
		    }
                }
            }
	    /*
	     * put up the options prompt
	     */
            movecursor(begrow + dlines, 0);
            cont = (loffset+dlines < textlen);
            if(cont){                               /* continue ? */
		menu_scroll[NEXT_KEY].name  = "^V";
		/* TRANSLATORS: Next Page, a command key label */
		menu_scroll[NEXT_KEY].label = N_("Next Pg");
	    }
	    else
	      menu_scroll[NEXT_KEY].name = NULL;

	    if(loffset){
		menu_scroll[PREV_KEY].name  = "^Y";
		/* TRANSLATORS: Previous Page */
		menu_scroll[PREV_KEY].label = N_("Prev Pg");
	    }
	    else
	      menu_scroll[PREV_KEY].name = NULL;

	    wkeyhelp(menu_scroll);
	}

	(*term.t_flush)();

        c = GetKey();

	prevoffset = loffset;
	switch(c){
	    case  (CTRL|'X') :		/* quit */
 	    case  F2  :
		done = 1;
		break;
	    case  (CTRL|'Y') :		/* prev page */
	    case  F7  :			/* prev page */
		if((loffset-dlines-OVERLAP) > 0){
               	    loffset -= (dlines-OVERLAP);
		}
	        else{
		    if(loffset != 0){
			prevoffset = -1;
		    }
		    else{
		    	(*term.t_beep)();
		    }
		    loffset = 0;
	        }
		break;
	    case  (CTRL|'V') :			/* next page */
 	    case  F8  :
		if(cont){
               	   loffset += (dlines-OVERLAP);
		}
		else{
		   (*term.t_beep)();
		}
		break;
	    case  '\016' :		/* prev-line */
	    case  (CTRL|'N') :
	      if(cont)
		loffset++;
	      else
		(*term.t_beep)();
	      break;
	    case  '\020' :		/* prev-line */
	    case  (CTRL|'P') :
	      if(loffset > 0)
		loffset--;
	      else
		(*term.t_beep)();
	      break;
	    case  '\014' :		/* refresh */
	    case  (CTRL|'L') :		/* refresh */
	        modeline(curwp);
		update();
		prevoffset = -1;
		break;
	    case  NODATA :
	        break;
#ifdef notdef
    /*
     * We don't handle window resize events correctly when in pico help.
     * resize_pico() redraws the edit window instead of the help window.
     * A ^L will redraw the help text. What we'd like is something like
     * a KEY_RESIZE return from GetKey. If we had that we could exit
     * wscrollw with a FALSE return value and have that cause us to loop
     * back into wscrollw with the adjusted size. That would still mean
     * the edit text would be redrawn first...
     */
#endif /* notdef */
	    default :
		unknown_command(c);
		break;
	}
    }

    return(TRUE);
}