Exemplo n.º 1
0
int initialize(void)
{
  //int rc;
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
#ifndef INCLUDE_CMD_FDDEBUG
  FILE *f;
#endif
#endif

/* Set up the host environment of COMMAND.COM */

	/* Install the dummy handlers for Criter and ^Break */
	initCBreak();
	setvect(0x23, cbreak_handler);
	setvect(0x24, dummy_criter_handler);

  /* DOS shells patch the PPID to the own PID, how stupid this is, however,
    because then DOS won't terminate them, e.g. when a Critical Error
    occurs that is not detected by COMMAND.COM */

  oldPSP = OwnerPSP;
  atexit(exitfct);
  OwnerPSP = _psp;

	dbg_printmem();
#ifdef DEBUG
	{ void* p;
		if((p = malloc(5*1024)) == 0)
			dprintf(("[MEM: Out of memory allocating test block during INIT]"));
		else free(p);
	}
#endif

#ifdef FEATURE_KERNEL_SWAP_SHELL
	if(kswapInit()) {		/* re-invoked */
		if(kswapLoadStruc()) {
			/* OK, on success we need not really keep the shell trick
				(pretend we are our own parent), which might cause
				problems with beta-software-bugs ;-)
				In fact, KSSF will catch up our crashes and re-invoke
				FreeCOM, probably with the loss of any internal
				settings. */
			  OwnerPSP = oldPSP;
			return E_None;
		}
	}
#endif

  /* Some elder DOSs may not pass an initializied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = 0;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));
  /* After that argv[0] is no longer used and maybe zapped.
  	This also will help, as most programs altering the environment
  	segment externally don't expect a string area. */
  env_nullStrings(0);

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'
    	&& peekb(ENV, 1) == '='

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == 0) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
#ifndef INCLUDE_CMD_FDDEBUG
  if((f = fopen(logFilename, "at")) == 0) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
  } else {

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
  }
#else
	cmd_fddebug(logFilename);

	dbg_outc('"');
	dbg_outs(ComPath);
	dbg_outc('"');
	dbg_outc(':');
	dbg_outsn(cmdline);
#endif
#endif

  canexit = 1;
  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, 0);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = 0;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = 0;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = 0;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = 0;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {      /* change TTY as early as possible so the caller gets
                          the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
#undef TEXT_MSG_FREECOM_NOT_FOUND
	puts(TEXT_MSG_FREECOM_NOT_FOUND);
    return E_Useage;
  }

  /* First of all, set up the environment */
    /* If a new valid size is specified, use that */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if(newEnvSize > 16 && newEnvSize < 32767)
    env_setsize(0, newEnvSize);

  /* Otherwise the path is placed into the environment */
    /* Set the COMSPEC variable. */
  if(chgEnv("COMSPEC", ComPath)) {		/* keep it silent */
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if(chgEnv("COMSPEC", ComPath))
    	chgEnv("COMSPEC",  NULL);	/* Cannot set -> zap an old one */
  }
  	inInit = 0;

	/* Install INT 24 Critical error handler */
	/* Needs the ComPath variable, eventually */
	if(!kswapContext) {
		/* Load the module/context into memory */
		if((kswapContext = modContext()) == 0) {
			error_loading_context();
			return E_NoMem;
		}
#ifdef FEATURE_KERNEL_SWAP_SHELL
		if(swapOnExec != ERROR)
			kswapRegister(kswapContext);
#endif
	}

	ctxtCreate();

	/* re-use the already loaded Module */
	setvect(0x24, (void interrupt(*)())
	 MK_FP(FP_SEG(kswapContext->cbreak_hdlr), kswapContext->ofs_criter));

  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
	if(!canexit) {
		char *autoexec;

		autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

		showinfo = 0;
		short_version();

		if(skipAUTOEXEC) {		/* /D option */
			showinfo = 0;
			displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec);
		} else {
			if(exist(autoexec)) {
#ifdef FEATURE_BOOT_KEYS
				struct REGPACK r;
				int key;

				r.r_ax = 0x3000;	/* Get DOS version & OEM ID */
				intr(0x21, &r);
				if(!tracemode	/* /Y --> F8 on CONFIG.SYS */
				 || ((r.r_bx & 0xff00) == 0xfd00	/* FreeDOS >= build 2025 */
				      && !(r.r_cx > 0x101 || (r.r_bx & 0xff) > 24))) {
					displayString(TEXT_MSG_INIT_BYPASS_AUTOEXEC, autoexec);
					key = cgetchar_timed(3);
					putchar('\n');
				} else key = 0;

				if(key == KEY_F8)
					tracemode = 1;

				if(key == KEY_F5)
					displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec);
				else
#endif
					process_input(1, autoexec);
			} else {
				if(user_autoexec)
					error_sfile_not_found(user_autoexec);
#ifdef INCLUDE_CMD_DATE
					cmd_date(0);
#endif
#ifdef INCLUDE_CMD_TIME
					cmd_time(0);
#endif
			}
		}

		free(user_autoexec);
	} else {
		assert(user_autoexec == 0);
	}

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
#ifndef DEBUG
    putchar('\n');
    showcmds(0);
    putchar('\n');
#endif
  }

  return E_None;
}
Exemplo n.º 2
0
void dispCopy(const char src[], const char dst[], int append)
{ displayString(TEXT_MSG_COPYING, src, append? "=>>": "=>", dst);
}
Exemplo n.º 3
0
/*
 * process the command line and execute the appropriate functions
 * full input/output redirection and piping are supported
 *
 */
void parsecommandline(char *s)
{
  char *in = NULL;
  char *out = NULL;
  char *fname0 = NULL;
  char *fname1 = NULL;
  char *nextcmd;

  int of_attrib = O_CREAT | O_TRUNC | O_TEXT | O_WRONLY;
  int num;

  dprintf(("[parsecommandline (%s)]\n", s));

  /* first thing we do is alias expansion */
  assert(s);
  assert(oldinfd == -1);  /* if fails something is wrong; should NEVER */
  assert(oldoutfd == -1); /* happen! -- 2000/01/13 ska*/

#ifdef FEATURE_ALIASES
  aliasexpand(s, MAX_INTERNAL_COMMAND_SIZE);
  dprintf(("[alias expanded to (%s)]\n", s));
#endif

  if (tracemode)
  {                             /* Question after the variables expansion
                                   and make sure _all_ executed commands will
                                   honor the trace mode */
    printf("%s [Enter=Yes, ESC=No] ", s);
    /* If the user hits ^Break, it has the same effect as
       usually: If he is in a batch file, he is asked if
       to abort all the batchfiles or just the current one */
    if (!strchr("Y\r\n", vcgetcstr("\x1bYN\r\n")))
      /* Pressed either "No" or ^Break */
      return;
  }

  num = get_redirection(s, &in, &out, &of_attrib);
  if (num < 0)                  /* error */
    goto abort;

  /* Set up the initial conditions ... */

  if (in || (num > 1))          /* Need to preserve stdin */
    oldinfd = dup(0);

  if (in)                       /* redirect input from this file name */
  {
    close(0);
    if (0 != devopen(in, O_TEXT | O_RDONLY, S_IREAD))
    {
      displayString(TEXT_ERROR_REDIRECT_FROM_FILE, in);
      goto abort;
    }
  }

  if (out || (num > 1))         /* Need to preserve stdout */
    oldoutfd = dup(1);

  /* Now do all but the last pipe command */
  while (num-- > 1)
  {
    close(1);                   /* Close current output file */
    if ((fname0 = tmpfn()) == NULL)
      goto abort;
    open(fname0, O_CREAT | O_TRUNC | O_TEXT | O_WRONLY, S_IREAD | S_IWRITE);

    nextcmd = s + strlen(s) + 1;
    docommand(s);

    close(0);
    killtmpfn(fname1);          /* fname1 can by NULL */
    fname1 = fname0;
    fname0 = NULL;
    open(fname1, O_TEXT | O_RDONLY, S_IREAD);

    s = nextcmd;
  }

  /* Now set up the end conditions... */

  if (out)                      /* Final output to here */
  {
    close(1);
    if (1 != devopen(out, of_attrib, S_IREAD | S_IWRITE))
    {
      displayString(TEXT_ERROR_REDIRECT_TO_FILE, out);
      goto abort;
    }

    if (of_attrib & O_APPEND)
      lseek(1, 0, SEEK_END);

  }
  else if (oldoutfd != -1)      /* Restore original stdout */
  {
    close(1);
    dup2(oldoutfd, 1);
    close(oldoutfd);
    oldoutfd = -1;
  }

  docommand(s);                 /* process final command */

abort:
  if (oldinfd != -1)            /* Restore original STDIN */
  {
    close(0);
    dup2(oldinfd, 0);
    close(oldinfd);
    oldinfd = -1;
  }

  if (oldoutfd != -1)           /* Restore original STDOUT */
  {
    close(1);
    dup2(oldoutfd, 1);
    close(oldoutfd);
    oldoutfd = -1;
  }

  killtmpfn(fname1);
  killtmpfn(fname0);

  if (out)
    free(out);

  if (in)
    free(in);
}
Exemplo n.º 4
0
int cmd_doskey(char *rest)
{
  displayString(TEXT_MSG_DOSKEY);
  return 0;
}
Exemplo n.º 5
0
task main() {

	int leftMotorSpeed, rightMotorSpeed, wristMotorSpeed, armMotorSpeed, stickAValue, stickBValue, stickCValue, stickDValue;

	resetMotorEncoder(armMotor);
	resetMotorEncoder(clawMotor);
	resetMotorEncoder(leftMotor);
	resetMotorEncoder(rightMotor);
	resetMotorEncoder(wristMotor);

	resetGyro(gyro);
	startGyroCalibration(gyro, gyroCalibrateSamples2048);
	eraseDisplay();
	getGyroCalibrationFlag(gyro);
	displayString(3, "calibrating gyro");
	wait1Msec(500);
	eraseDisplay();

	startTask(displayMyMotorPositions);


	while (true ){


		/***************************************************************************************************************/
		//Joystick Control:

		/***************************************************************************************************************/
		//Driving:

		if(getJoystickValue(BtnEUp) > 0)   {  //Drive Straight Forward
			driveStraightForward();
		}
		else if(getJoystickValue(BtnEDown) > 0)   {  //Drive Straight Backward
			driveStraightBackward();
		}
		else {
			driveForwardPressed = false;
			driveBackwardPressed = false;

			stickAValue  = getJoystickValue(ChA);
			if ((stickAValue <= 15) && (stickAValue >= -15) ) stickAValue = 0;

			stickBValue  = getJoystickValue(ChB);
			if ((stickBValue <= 15) && (stickBValue >= -15) ) stickBValue = 0;

			if (stickBValue >=0 ) 	 	stickBValue = (stickBValue / 10) * (stickBValue / 10) * 2;
			else stickBValue = 		- (stickBValue / 10) * (stickBValue / 10) * 2;



			leftMotorSpeed = stickAValue - stickBValue;
			rightMotorSpeed = stickAValue + stickBValue;

			if ( leftMotorSpeed > 100) leftMotorSpeed = 100;
			if ( leftMotorSpeed < -100) leftMotorSpeed = -100;

			if ( rightMotorSpeed > 100) rightMotorSpeed = 100;
			if ( rightMotorSpeed < -100) rightMotorSpeed = -100;

			if (leftMotorSpeed >=0 ) 	 	leftMotorSpeed = (leftMotorSpeed / 10) * (leftMotorSpeed / 10);
			else leftMotorSpeed = 		- (leftMotorSpeed / 10) * (leftMotorSpeed / 10);
			if (rightMotorSpeed >=0 ) 	rightMotorSpeed = (rightMotorSpeed / 10) * (rightMotorSpeed / 10);
			else rightMotorSpeed = 		- (rightMotorSpeed / 10) * (rightMotorSpeed / 10);

			setMotorSpeed(leftMotor, leftMotorSpeed);
			setMotorSpeed(rightMotor, rightMotorSpeed);
		}

		/***************************************************************************************************************/
		//WRIST MOTOR
		stickDValue		= getJoystickValue(ChD);
		if ((stickDValue <= 15) && (stickDValue >= -15) ) stickDValue = 0;

		wristMotorSpeed = stickDValue;

		if (wristMotorSpeed >=0 ) 	 	wristMotorSpeed = (wristMotorSpeed / 10) * (wristMotorSpeed / 10);
		else wristMotorSpeed = 		- (wristMotorSpeed / 10) * (wristMotorSpeed / 10);

		globalWristPosition = getMotorEncoder(wristMotor);

		if ((wristMotorSpeed > 0) && (globalWristPosition >= WRIST_UPPER_LIMIT)){
			setMotorTarget(wristMotor, WRIST_UPPER_LIMIT, 70);
		}
		else if ((wristMotorSpeed < 0) && (globalWristPosition <= WRIST_LOWER_LIMIT)) {
			setMotorTarget(wristMotor, WRIST_LOWER_LIMIT, 70);
		}
		else {
			//slow things down if we are near the limit of wrist movement
			if ( abs(globalWristPosition - WRIST_LOWER_LIMIT) < 10) {
				wristMotorSpeed = wristMotorSpeed / 4;
			}
			if ( abs(globalWristPosition - WRIST_UPPER_LIMIT) < 10) {
				wristMotorSpeed = wristMotorSpeed / 4;
			}
			setMotorSpeed(wristMotor, wristMotorSpeed );
		}

		/***************************************************************************************************************/
		//ARM MOTOR
		stickCValue		= getJoystickValue(ChC);
		if ((stickCValue <= 15) && (stickCValue >= -15) ) stickCValue = 0;

		armMotorSpeed = stickCValue;

		if (armMotorSpeed >=0 ) 	 	armMotorSpeed = (armMotorSpeed / 10) * (armMotorSpeed / 10);
		else armMotorSpeed = 		- (armMotorSpeed / 10) * (armMotorSpeed / 10);

		globalArmPosition = getMotorEncoder(armMotor);

		if ((armMotorSpeed > 0) && (globalArmPosition >= ARM_UPPER_LIMIT)){
			setMotorTarget(armMotor, ARM_UPPER_LIMIT, 70);
		}
		else if ((armMotorSpeed < 0) && (globalArmPosition <= ARM_LOWER_LIMIT)) {
			setMotorTarget(armMotor, ARM_LOWER_LIMIT, 70);
		}
		else {
			//slow things down if we are near the limit of arm movement
			if ( abs(globalArmPosition - ARM_LOWER_LIMIT) < 10){
				armMotorSpeed= armMotorSpeed/ 4;
			}
			if ( abs(globalArmPosition - ARM_UPPER_LIMIT) < 10){
				armMotorSpeed= armMotorSpeed/ 4;
			}
			setMotorSpeed(armMotor, armMotorSpeed);
		}


		/***************************************************************************************************************/
		//CLAW MOTOR
		if(getJoystickValue(BtnLUp) > 0)   {  //CLOSE
			setMotorSpeed(clawMotor, 70);
		}
		else if(getJoystickValue(BtnLDown) > 0)   {  //OPEN
			globalClawPosition = getMotorEncoder(clawMotor);
			if (globalClawPosition <= -87) {
				setMotorTarget(clawMotor, -87, 70);
			}
			else {
				setMotorSpeed(clawMotor, -70);
			}
		}
		else {
			globalClawPosition = getMotorEncoder(clawMotor);
			setMotorTarget(clawMotor, globalClawPosition, 90);
		}


		/***************************************************************************************************************/
		//Buttons to move our Arm for Us quickly to other positions
		if(getJoystickValue(BtnFUp) > 0)   {  //UP
			moveToAimingPosition();
		}
		if(getJoystickValue(BtnFDown) > 0)   {  //GRAB a Block
			moveToNeutralPosition();
		}

		/***************************************************************************************************************/
		//Block Stacking Positions
		//Buttons to move our Arm for Us quickly to other positions
		if(getJoystickValue(BtnRUp) > 0)   {  //Upper Stacking Position
			moveToUpperStackingPosition();
		}
		if(getJoystickValue(BtnRDown) > 0)   {  //Lower Stacking Position
			moveToLowerStackingPosition();
		}
		wait1Msec(50);   // Give actions time to make progress and prevent over-control from taking inputs too fast

	}

}
Exemplo n.º 6
0
bool checkPin(Account * accountList)
{
        char pin[4] = {'0','0','0','0'};
        int i = 0;

        while (!getButtonPress(buttonEnter))
        {
                char pointer[4] = {' ',' ',' ',' '};
                pointer[i] = '^';
                displayString(1, "Enter PIN: %c%c%c%c",pin[0],pin[1],pin[2],pin[3]);
                displayString(2, "           %c%c%c%c",pointer[0],pointer[1],pointer[2],pointer[3]);

                while (getButtonPress(buttonAny) == 0)
              	{}

                //React to button Presses
               	while (getButtonPress(buttonAny) == 1)
                {
                        if (getButtonPress(buttonLeft) == 1)
                        {
                                i--;
                        }
                        else if (getButtonPress(buttonRight) ==1 )
                        {
                                i++;
                        }
                        else if (getButtonPress(buttonUp) ==1)
                        {
                                pin[i]++;
                        }
                        else if (getButtonPress(buttonDown) ==1)
                        {
                                pin[i]--;
                        }
                        else
                        {
                                break;
                        }

                        if (i<0)
                                i++;
                        else if (i>3)
                                i--;

                        if (pin[i] >= ':')
                        		pin[i]--;
                        else if (pin[i] <= '/')
                        		pin[i]++;

                        wait1Msec(250);
                        eraseDisplay();


                }


        }
        eraseDisplay();
        string pinvalue = "";
        for (int i = 0; i<4; i++)
        {
        	pinvalue+=pin[i];
        }

        return comparePin(pinvalue, accountList);
}
Exemplo n.º 7
0
void error_restore_session(void)
{ displayString(TEXT_ERROR_RESTORE_SESSION);
}
Exemplo n.º 8
0
void error_kswap_alias_size(void)
{	displayString(TEXT_ERROR_KSWAP_ALIAS_SIZE);
}
Exemplo n.º 9
0
int cmd_for(char *param)
{
	/*
	 * Perform FOR command.
	 *
	 * First check syntax is correct : FOR %v IN ( <list> ) DO <command>
	 *   v must be alphabetic, <command> must not be empty.
	 *
	 * If all is correct build a new bcontext structure which preserves
	 *   the necessary information so that readbatchline can expand
	 *   each the command prototype for each list element.
	 *
	 * You might look on a FOR as being a called batch file with one line
	 *   per list element.
	 */

	char *pp;
	char var;

	assert(param);

	/* Check that first element is % then an alpha char followed by space */

	if(*param != '%' || !isalpha(param[1]) || !isspace(param[2])) {
		displayString(TEXT_ERROR_BAD_VERABLE);
		return 1;
	}

	var = param[1];               /* Save FOR var name */
	param = ltrim(param + 2);   /* skip whitespaces */

	/* Check next element is 'IN' */

	if(!matchtok(param, "in")) {
		displayString(TEXT_ERROR_IN_MISSING);
		return 1;
	}

	/* Folowed by a '(', find also matching ')' */

	if(*param != '(' || 0 == (pp = strchr(param, ')'))) {
		displayString(TEXT_ERROR_MISSING_PARENTHESES);
		return 1;
	}

	*pp = '\0';
	param++;                      /* param now points at null terminated list */

	pp = ltrim(pp + 1);

	/* Check DO follows */

	if(!matchtok(pp, "do")) {
		displayString(TEXT_ERROR_DO_MISSING);
		return 1;
	}

	/* Check that command tail is not empty */

	if(*pp == '\0') {
		displayString(TEXT_ERROR_NO_COMMAND_AFTER_DO);
		return 1;
	}

	/* OK all is correct, build a bcontext.... */

	{
		struct bcontext *new = newBatchContext();

		if(!new)
			return 1;

		if((bc->forproto = strdup(pp)) == 0) {
			error_out_of_memory();
			exit_batch();   /* remove the newly created batch context */
			return 1;
		}

		if(!setBatchParams(param)) { /* Split out list */
			exit_batch();
			return 1;
		}

		bc->forvar = var;
		bc->shiftlevel = 1;     /* skip %0 <=> filename */
	}

	return 0;
}
Exemplo n.º 10
0
int parseArgs(char *cmdline, char **fnam, char **rest)
{
  char *c;

  assert(fnam);
  assert(rest);

  /* initialize options */
  optS = 0;
  optL = NULL;

  if(leadOptions(&cmdline, loadfix_flag? NULL: opt_lh, NULL) != E_None)
      return err_silent;

  if((c = optL) != NULL) {
    int i, r;

    /* Disable access to all UMB regions not listed here */
    for (i = 1; i < umbRegions; i++)
    umbRegion[i].access = 0;

    r = 0;

    do
    {
    DWORD region_minSize = 0xffff;  /* flag value, indicating no minsize was specified */

    int region_number = (int)strtol(c, &c, 10);

    if (*c == ',')
    {
    long larg;
      c++;
      if ((larg = strtol(c, &c, 10)) != -1L)
      region_minSize = topara(larg);
    }

    if (region_number >= umbRegions)
      displayString(TEXT_ERROR_REGION_WARNING, region_number);
    else
    {
      if (!r && !region_number)
      upper_flag = 0;

      r++;
      assert(region_minSize < 0x10000ul);
      umbRegion[region_number].minSize = (unsigned)region_minSize;
      umbRegion[region_number].access = 1;
    }
    }
    while (*c++ == ';');
    if(c[-1])
            cmdline = ""; /* to cause an error later */
  }

  /* does a file name follow? */
  if (!*cmdline)
    return err_invalid_parms;

  if (optS && !optL)
    return err_invalid_parms;

  /* The next argument is the file name. The rest of the command line
   * are passed as parameters to the new program. */

  if((*fnam = unquote(cmdline, c = skipwd(cmdline))) == NULL)
    return err_out_of_memory;

  *rest = skipdm(c);

  return OK;
}
Exemplo n.º 11
0
int cmd_del(char *param)
{
	int ec = E_None;    /* exit code */
	int i;
	unsigned count = 0;

	struct ffblk f;

	/* Make fullname somewhat larger to ensure that appending
		a matched name, one backslash and one hope. */
	char fullname[MAXPATH + sizeof(f.ff_name) + 2],
	*p, *q;
	int len;

	char **arg;
	int argc, optc;

	/* initialize options */
	verbose = optP = 0;

	if((arg = scanCmdline(param, opt_del, 0, &argc, &optc)) == 0)
		return E_Other;

	if(!argc) {
		error_req_param_missing();
		ec = E_Useage;
	} else {
		i = 0;
		do {
			assert(arg[i]);

		/* Get the pattern fully-qualified */
			/* Note: An absolute path always contains:
				A:\\
				--> It's always three bytes long at minimum
				and always contains a backslash */
			p = dfnexpand(arg[i], 0);
			if(!p) {
				error_out_of_memory();
				return E_NoMem;
			}
			assert(strlen(p) >= 3);

			if((len = strlen(p)) >= MAXPATH) {
				error_filename_too_long(p);
				free(p);
				ec = E_Other;
				goto errRet;
			}
			strcpy(fullname, p);  /* Operating over a local buffer simplifies
					 the process; rather than keep the pattern
					 within dynamic memory */
			free(p);
			p = fullname + len;

			/* check if it is a directory */
			if(dfnstat(fullname) & DFN_DIRECTORY) {
				if (p[-1] != '\\')
					*p++ = '\\';
			}

			if(p[-1] == '\\')    /* delete a whole directory */
				p = stpcpy(p, "*.*");

			/* p := address to copy the filename to to form the fully-qualified
				filename */
			/* There is at least one backslash within fullname,
				because of dfnexpand() */
			while(*--p != '\\') ;
			++p;

			/* make sure user is sure if all files are to be
			 * deleted */
			if(!optP && *p == '*'
			 && ((q = strchr(p, '.')) == 0 || q[1] == '*')) {
				if(userprompt(PROMPT_DELETE_ALL, p) != 1) {
					ec = E_Other;
					goto errRet;
				}
			}

			if (FINDFIRST(fullname, &f, FA_ARCH)) {
				error_sfile_not_found(fullname);
			} else do {
				strcpy(p, f.ff_name);       /* Make the full path */

				if(optP) {
					switch(userprompt(PROMPT_DELETE_FILE, fullname)) {
					case 4:             /* Quit/^Break pressed */
						ec = E_CBreak;
						goto errRet;
					case 3:				/* all */
						optP = 0;
					case 1:
						break;                /* yes, delete */
					default:
					case 2:
						continue;             /* no, don't delete */
					}
				}
				else if(cbreak) {  /* is also probed for in vcgetstr() */
					ec = E_CBreak;
					goto errRet;
				}

#ifdef NODEL
				/* define NODEL if you want to debug */
				puts(fullname);
#else
				if(verbose && !optP)
					displayString(TEXT_DELETE_FILE, fullname);
				if(unlink(fullname) != 0) {
					perror(fullname);   /* notify the user */
				} else
					++count;
#endif

			} while (FINDNEXT(&f) == 0);
		} while(++i < argc);
	}

errRet:

	if(echo)
		dispCount(count, TEXT_MSG_DEL_CNT_FILES);

	freep(arg);
	return ec;
}
Exemplo n.º 12
0
task main()
{
		struct Account accountList[NUMACCOUNTS];
		initAccounts(accountList, NUMACCOUNTS);

		string account;
		string cardnum;
		string pin;
		int accountindex;
		bool pinCorrect;

		while (getBatteryCurrent() > 0.02)
		{
			/*
			displayString(0,"Swipe card to Begin");
			do
			{
				cardnum = getCardSwipe();
				accountindex = doesExist(cardnum, accountList);
				displayString(0,"ERROR Card Not Found!!");
			}while (accountindex == -1);
			eraseDisplay();
			do
			{
				pinCorrect = checkPin(accountList);
				displayString(0,"ERROR Incorrect PIN");
			}while (pinCorrect == false);
			wait1Msec(100);
			eraseDisplay();
			wait1Msec(500);*/

			//Selection Menu
			while (getButtonPress(buttonEnter) != 1)
			{
					eraseDisplay();
					displayString(1,"Press center button to close transaction");
					displayString(2,"<----                   ---->");
					displayString(3,"Deposit             Withdraw");
					displayString(4,"     Balance: %f", accountList[accountindex].balance);

					waitForButtonPress();

			    if (getButtonPress(buttonLeft) == 1)
			    {
			    		int amount = doDeposit();
			        accountList[accountindex].balance += amount;
							eraseDisplay();
			        displayString(0,"%d", amount);
			    }
			    else if (getButtonPress(buttonRight) ==1)
			    {
			            int amount = doWithdraw(accountList[accountindex]);
			            if (amount != -1)
			            {
			            	accountList[accountindex].balance -= amount;
			            }
			    }
		  }

	    wait1Msec(5000);


		}
}
Exemplo n.º 13
0
//Joel Ruhland
//Fully Tested
int getAmount()
{
        char amount[3] = {'0','0','0'};
        int i = 0;

        while (!getButtonPress(buttonEnter))
        {
                char pointer[3] = {' ',' ',' '};
                pointer[i] = '^';
                displayString(0, "Enter Amount: %c%c%c",amount[0],amount[1],amount[2]);
                displayString(1, "              %c%c%c",pointer[0],pointer[1],pointer[2]);

                while (getButtonPress(buttonAny) == 0)
              	{}
                //React to button Presses
               	while (getButtonPress(buttonAny) == 1)
                {
                        if (getButtonPress(buttonLeft) == 1)
                        {
                                i--;
                        }
                        else if (getButtonPress(buttonRight) ==1)
                        {
                                i++;
                        }
                        else if (getButtonPress(buttonUp) ==1)
                        {
                                amount[i]++;
                        }
                        else if (getButtonPress(buttonDown) ==1)
                        {
                                amount[i]--;
                        }
                        else
                        {
                                break;
                        }

                        if (i<0)
                                i++;
                        else if (i>2)
                                i--;

                        if (amount[i] >= ':')
                        		amount[i]--;
                        else if (amount[i] <= '/')
                        		amount[i]++;

                        wait1Msec(250);
                        eraseDisplay();


                }


        }
        int a0 = amount[0] - '0';
        int a1 = amount[1] - '0';
        int a2 = amount[2] - '0';
        eraseDisplay();
        return (a0*100+a1*10+a2);
}
Exemplo n.º 14
0
void error_invalid_number(const char * const s)
{ displayString(TEXT_INVALID_NUMBER, s);
}
Exemplo n.º 15
0
int showcmds (char * rest) {
  struct CMD *cmdptr;
  int y;

  (void)rest;
  displayString(TEXT_MSG_SHOWCMD_INTERNAL_COMMANDS);
  y = 0;
  cmdptr = internalCommands;
  while (cmdptr->name)
  {
    if (++y == 8)
    {
      puts(cmdptr->name);
      y = 0;
    }
    else
      printf("%-10s", cmdptr->name);

    cmdptr++;
  }
  if (y != 0)
    outc('\n');

  displayString(TEXT_MSG_SHOWCMD_FEATURES);
#ifdef FEATURE_ALIASES
	displayString(TEXT_SHOWCMD_FEATURE_ALIASES);
#endif
#ifdef FEATURE_ENHANCED_INPUT
	displayString(TEXT_SHOWCMD_FEATURE_ENHANCED_INPUT);
#endif
#ifdef FEATURE_HISTORY
	displayString(TEXT_SHOWCMD_FEATURE_HISTORY);
#endif
#ifdef FEATURE_FILENAME_COMPLETION
	displayString(TEXT_SHOWCMD_FEATURE_FILENAME_COMPLETION);
#endif
#ifdef FEATURE_SWAP_EXEC
	displayString(TEXT_SHOWCMD_FEATURE_SWAP_EXEC);
#endif
#ifdef FEATURE_CALL_LOGGING
	displayString(TEXT_SHOWCMD_FEATURE_CALL_LOGGING);
#endif
#ifdef FEATURE_LAST_DIR
	displayString(TEXT_SHOWCMD_FEATURE_LAST_DIR);
#endif
#ifdef FEATURE_LONG_FILENAMES
    displayString(TEXT_SHOWCMD_FEATURE_LONG_FILENAMES);
#endif
#ifdef FEATURE_KERNEL_SWAP_SHELL
	displayString(TEXT_SHOWCMD_FEATURE_KERNEL_SWAP_SHELL);
#define INIT_DISPLAY_DEFAULT_SWAP_VALUE
#endif
#ifdef FEATURE_XMS_SWAP
	displayString(TEXT_SHOWCMD_FEATURE_XMS_SWAP);
#define INIT_DISPLAY_DEFAULT_SWAP_VALUE
#endif
#ifdef INIT_DISPLAY_DEFAULT_SWAP_VALUE
	if(swapOnExec != ERROR && defaultToSwap == TRUE)
		displayString(TEXT_SHOWCMD_DEFAULT_TO_SWAP);
#endif
#ifdef FEATURE_INSTALLABLE_COMMANDS
	displayString(TEXT_SHOWCMD_FEATURE_INSTALLABLE_COMMANDS);
#endif
#ifdef FEATURE_NLS
	displayString(TEXT_SHOWCMD_FEATURE_NLS);
#endif
#ifdef FEATURE_DIRSTACK
	displayString(TEXT_SHOWCMD_FEATURE_DIRSTACK);
#endif
#ifdef DEBUG
	displayString(TEXT_SHOWCMD_FEATURE_DEBUG);
#endif
  outc('\n');

  return 0;
}
Exemplo n.º 16
0
int initialize(void)
{
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */
  int key;

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
  FILE *f;
#endif

/* Set up the host environment of COMMAND.COM */
	atexit(exitfct);

	if(modAttach()) {		/* Attach to any already loaded module */
		/* successfully attached --> no further processing of
			command line required as this instance was respawned by
			Stub module --> restore session */
		sessionLoad();
		return E_None;
	}

	/* Prepare creating a new instance of FreeCOM */
	/* Install the dummy handlers of CRITER and ^Break Catcher */
	/* Though if the modules are already loaded, they are used right now */
	modPreload();		/* activate dummies unless already attached */

  /* Some elder DOSs may not pass an initialzied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = NULL;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));

		/* Maybe an anchessor has an absolute path */
	sessionInherit();

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == NULL) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
  if((f = fopen(logFilename, "at")) == NULL) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
    exit(125);
  }

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
#endif

  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, NULL);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = NULL;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = NULL;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = NULL;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = NULL;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {                   /* change TTY as early as possible so the caller gets
                                   the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
    puts("You must specify the complete path to " COM_NAME);
    puts("as the first argument of COMMAND,");
    puts("for instance: C:\\FDOS");
    return E_Useage;
  }

  /* First of all, set up the environment */
    /* If a new valid size is specified, use that */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if(newEnvSize > 16 && newEnvSize < 32767)
    env_setsize(0, newEnvSize);

  /* Otherwise the path is placed into the environment */
  if (chgEnv("COMSPEC", ComPath)) {
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if (chgEnv("COMSPEC", ComPath))
    error_env_var("COMSPEC");
  }

  /* Install the resident portion(s)
  	Now that the name of the executeable is known, they can be found
  	definitely */
 	modLoad(); 		/* Load any module unless already attached to */
 	if(!modAttach()) {	/* Attach to the loaded modules */
 		error_missing_modules();
 		return E_Exit;
 	}


  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
  if (!canexit)
  {
    char *autoexec;

    autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

    showinfo = 0;
    short_version();

    /* JP: changed so that if autoexec does not exist, then don't ask
       to trace or bypass.
     */
    if (exist(autoexec))
    {
      printf("\nPress F8 for trace mode, or F5 to bypass %s... ", autoexec);
      key = WaitForFkeys();
      putchar('\n');

      if (key == KEY_F8)
      {
        tracemode = 1;
      }

      if (key == KEY_F5)
      {
        printf("Bypassing %s\n", autoexec);
      }
      else
        process_input(1, autoexec);
    }
    else
    {
      if(user_autoexec)
        printf("%s not found.\n", autoexec);
#ifdef INCLUDE_CMD_DATE
      cmd_date(NULL);
#endif
#ifdef INCLUDE_CMD_TIME
      cmd_time(NULL);
#endif
    }

    free(user_autoexec);
  }
  else
  {
    assert(user_autoexec == NULL);
  }

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
    putchar('\n');
    showcmds(NULL);
    putchar('\n');
  }

  return E_None;
}
Exemplo n.º 17
0
static void docommand(char *line)
{
  /*
   * look through the internal commands and determine whether or not this
   * command is one of them.  If it is, call the command.  If not, call
   * execute to run it as an external program.
   *
   * line - the command line of the program to run
   */

#ifdef FEATURE_INSTALLABLE_COMMANDS
	/* Duplicate the command line into such buffer in order to
		allow Installable Commands to alter the command line.
		*line cannot be modified as pipes would be destroyed. */
	/* Place both buffers immediately following each other in
		order to make sure the contents of args can be appended
		to com without any buffer overflow checks.
		*2 -> one buffer for com and one for args
		+2 -> max length byte of com + cur length of com
		+3 -> max length byte of args + cur length of args + additional '\0'
	*/
	char buf[2+2*BUFFER_SIZE_MUX_AE+2+1];
#define com  (buf + 2)
#define args (buf + 2 + BUFFER_SIZE_MUX_AE + 2)
#define BUFFER_SIZE BUFFER_SIZE_MUX_AE
#else
	char com[MAX_INTERNAL_COMMAND_SIZE];
#define BUFFER_SIZE MAX_INTERNAL_COMMAND_SIZE
#endif
  char *cp;
  char *rest;            /* pointer to the rest of the command line */

  struct CMD *cmdptr;

  assert(line);

  /* delete leading spaces, but keep trailing whitespaces */
  line = ltrimcl(line);

#ifdef FEATURE_INSTALLABLE_COMMANDS
#if BUFFER_SIZE < MAX_INTERNAL_COMMAND_SIZE
	if(strlen(line) > BUFFER_SIZE) {
		error_line_too_long();
		return;
	}
#endif
	line = strcpy(args, line);
#endif

  if (*(rest = line))                    /* Anything to do ? */
  {
    cp = com;

  /* Copy over 1st word as lower case */
  /* Internal commands are constructed out of non-delimiter
  	characters; ? had been parsed already */
    while(*rest && is_fnchar(*rest) && !strchr(QUOTE_STR, *rest))
      *cp++ = toupper(*rest++);

    if(*rest && strchr(QUOTE_STR, *rest))
      /* If the first word is quoted, it is no internal command */
      cp = com;   /* invalidate it */
    *cp = '\0';                 /* Terminate first word */

	if(*com) {
#ifdef FEATURE_INSTALLABLE_COMMANDS
		/* Check for installed COMMAND extension */
		if(runExtension(com, args))
			return;		/* OK, executed! */

		dprintf( ("[Command on return of Installable Commands check: >%s<]\n", com) );
#endif

		/* Scan internal command table */
		for (cmdptr = internalCommands
		 ; cmdptr->name && strcmp(com, cmdptr->name) != 0
		 ; cmdptr++);

	}

    if(*com && cmdptr->name) {    /* internal command found */
      switch(cmdptr->flags & (CMD_SPECIAL_ALL | CMD_SPECIAL_DIR)) {
      case CMD_SPECIAL_ALL: /* pass everything into command */
        break;
      case CMD_SPECIAL_DIR: /* pass '\\' & '.' too */
        if(*rest == '\\' || *rest == '.' || *rest == ':') break;
      default:        /* pass '/', ignore ',', ';' & '=' */
        if(!*rest || *rest == '/') break;
        if(isargdelim(*rest)) {
			rest = ltrimcl(rest);
			break;
		}

        /* else syntax error */
        error_syntax(0);
        return;
      }

        /* JPP this will print help for any command */
        if (strstr(rest, "/?"))
        {
          displayString(cmdptr->help_id);
        }
        else
        {
          dprintf(("CMD '%s' : '%s'\n", com, rest));
          cmdptr->func(rest);
        }
      } else {
#ifdef FEATURE_INSTALLABLE_COMMANDS
		if(*com) {		/* external command */
			/* Installable Commands are allowed to change both:
				"com" and "args". Therefore, we may need to
				reconstruct the external command line */
			/* Because com and *rest are located within the very same
				buffer and rest is definitely terminated with '\0',
				the followinf memmove() operation is fully robust
				against buffer overflows */
			memmove(com + strlen(com), rest, strlen(rest) + 1);
			/* Unsave, but probably more efficient operation:
				strcat(com, rest);
					-- 2000/12/10 ska*/
			line = com;
		}
#endif
        /* no internal command --> spawn an external one */
        cp = unquote(line, rest = skip_word(line));
        if(!cp) {
          error_out_of_memory();
          return;
        }
		execute(cp, ltrimsp(rest));
		free(cp);
      }
  }
#undef line
#undef com
#undef args
#undef BUFFER_SIZE
}
Exemplo n.º 18
0
void error_bfile_vanished(const char * const fnam)
{
    displayString(TEXT_ERROR_BFILE_VANISHED, fnam);
}
Exemplo n.º 19
0
static void docommand(char *line)
{
  /*
   * look through the internal commands and determine whether or not this
   * command is one of them.  If it is, call the command.  If not, call
   * execute to run it as an external program.
   *
   * line - the command line of the program to run
   */

  char *com;                    /* the first word in the command */
  char *cp;
  char *rest;            /* pointer to the rest of the command line */

  struct CMD *cmdptr;

  assert(line);

  /* delete leading & trailing whitespaces */
  line = rest = trim(line);

  if (*rest)                    /* Anything to do ? */
  {
    if ((cp = com = malloc(strlen(line) + 1)) == NULL)
    {
    error_out_of_memory();
    return;
    }

  /* Copy over 1st word as lower case */
  /* Internal commands are constructed out of alphabetic
  	characters; ? had been parsed already */
    while (isalpha(*rest))
      *cp++ = tolower(*rest++);

    if(*rest && (!is_delim(*rest) || strchr(QUOTE_STR, *rest)))
      /* If the first word is quoted, it is no internal command */
      cp = com;   /* invalidate it */
    *cp = '\0';                 /* Terminate first word */

  /* Scan internal command table */
  if(*com)
    for (cmdptr = cmds; cmdptr->name && strcmp(com, cmdptr->name) != 0
     ; cmdptr++);

    if(*com && cmdptr->name) {    /* internal command found */
    free(com);          /* free()'ed during call */
      switch(cmdptr->flags & (CMD_SPECIAL_ALL | CMD_SPECIAL_DIR)) {
      case CMD_SPECIAL_ALL: /* pass everything into command */
        break;
      case CMD_SPECIAL_DIR: /* pass '\\' too */
        if(*rest == '\\') break;
      default:        /* pass '/', ignore ',', ';' & '=' */
        if(*rest == '/') break;
        if(!*rest || isspace(*rest)) {  /* normal delimiter */
          rest = ltrim(rest);
          break;
        }
        if(strchr(",;=", *rest)) {
          rest = ltrim(rest + 1);
          break;
        }

        /* else syntax error */
        error_syntax(NULL);
        return;
      }

        /* JPP this will print help for any command */
        if (strstr(rest, "/?"))
        {
          displayString(cmdptr->help_id);
        }
        else
        {
          dprintf(("CMD '%s' : '%s'\n", com, rest));
          cmdptr->func(rest);
        }
      } else {
        /* no internal command --> spawn an external one */
        free(com);
        com = unquote(line, rest = skip_word(line));
        if(!com) {
          error_out_of_memory();
          return;
        }
    execute(com, ltrim(rest));
      free(com);
      }
  }
}
Exemplo n.º 20
0
void error_env_var(const char * const var)
{
  displayString(TEXT_ERROR_SET_ENV_VAR, var);
}
Exemplo n.º 21
0
int showcmds(char *rest)
{
  struct CMD *cmdptr;
  unsigned char y;
  extern struct CMD cmds[];     /* The internal command table */

  displayString(TEXT_MSG_SHOWCMD_INTERNAL_COMMANDS);
  y = 0;
  cmdptr = cmds;
  while (cmdptr->name)
  {
    if (++y == 8)
    {
      puts(cmdptr->name);
      y = 0;
    }
    else
      printf("%-10s", cmdptr->name);

    cmdptr++;
  }
  if (y != 0)
    putchar('\n');
  displayString(TEXT_MSG_SHOWCMD_FEATURES);
	displayString(TEXT_SHOWCMD_FEATURE_ALIASES);
	displayString(TEXT_SHOWCMD_FEATURE_ENHANCED_INPUT);
	displayString(TEXT_SHOWCMD_FEATURE_HISTORY);
	displayString(TEXT_SHOWCMD_FEATURE_FILENAME_COMPLETION);
	displayString(TEXT_SHOWCMD_FEATURE_SWAP_EXEC);
	displayString(TEXT_SHOWCMD_FEATURE_CALL_LOGGING);
	displayString(TEXT_SHOWCMD_FEATURE_LAST_DIR);
	displayString(TEXT_SHOWCMD_FEATURE_KERNEL_SWAP_SHELL);
	displayString(TEXT_SHOWCMD_FEATURE_INSTALLABLE_COMMANDS);
	displayString(TEXT_SHOWCMD_FEATURE_NLS);
  putchar('\n');

  return 0;
}