Exemple #1
0
void cmdTerp() {
	UART_Handle uart;
	UART_Params uartParams;

	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = 9600;
	uart = UART_open(Board_UART1, &uartParams);
	globalUART = &uart;

	if (uart == NULL) {
	        System_abort("Error opening the UART");
	}

	char input[2];
	uint8_t duty;

	while(1) {
		UART_write(uart,">",1);
		UART_read(uart,input,1);
		UART_write(uart,input,1);

		cmdExecute(input,duty);
	}
}
Exemple #2
0
void conInput(SDLKey c) {

    if (c >= 32 && c < 127) {

        if (c == SDLK_SPACE && conCommandPos == 0)
            return;

        if (conCommandPos < CONSOLE_LENGTH) {
            int i,l;
            l = strlen(conCommand);
            for (i = strlen(conCommand); i > conCommandPos-1; i--)
                conCommand[i+1]=conCommand[i];

            conCommand[conCommandPos] = c;
            conCommandPos++;
            conCompWord[0] = 0;

        }
        return;

    }

    if (c == SDLK_BACKSPACE || c == SDLK_DELETE) {

        if (conCommandPos > 0) {

            strcpy(&conCommand[conCommandPos-1], &conCommand[conCommandPos]);
            conCommandPos--;

        }
        conCompWord[0] = 0;
        return;

    }

    if (c == SDLK_RETURN || c == 10) {

        printf("\n\r");

        if (conCommandPos == 0) {
            view.consoleMode = 0;
            return;
        }

        // add command to typed history
        conTypedHistoryAdd(conCommand);

        view.consoleMode = 0;

        cmdExecute(conCommand);

        conCommand[0] = 0;
        conCommandPos = 0;
        conCompWord[0] = 0;

        return;

    }

    if (c == SDLK_BACKQUOTE || c == SDLK_ESCAPE) {

        view.consoleMode = 0;
        conCommandPos = 0;
        conCommand[0] = 0;
        conCompWord[0] = 0;
        return;

    }

    if (c == SDLK_TAB) {
        conAutoComplete();
        return;
    }

    if (c == SDLK_UP) {
        conTypedHistoryChange(-1);
        return;
    }

    if (c == SDLK_DOWN) {
        conTypedHistoryChange(1);
        return;
    }

    if (c == SDLK_LEFT) {
        if (conCommandPos > 0) {
            conCommandPos--;
        }
        return;
    }

    if (c == SDLK_RIGHT) {
        if (conCommandPos < (signed)strlen(conCommand)) {
            conCommandPos++;
        }
        return;
    }

    conAdd(LLOW, "unknown key: %u", c);

}
Exemple #3
0
int commandLineRead(int argc, char *argv[]) {

    int i;
//	char *parm;
//	char *argvptr;

#define CheckCommand(x) !strncmp(argv[i], x, strlen(x))

    for (i = 1; i < argc; i++) {

        // version, quit
        if (CheckCommand("--version") || CheckCommand("-v")) {
            conAdd(LLOW, GRAVIT_VERSION);
            conAdd(LLOW, GRAVIT_COPYRIGHT);
            cmdQuit(0);
            return 0;
        }

        // --help or -h
        if (CheckCommand("--help") || CheckCommand("-h")) {

            usage();
            return 0;

        }

        // -n or --noscript
        if (CheckCommand("--noscript") || CheckCommand("-n")) {
            state.dontExecuteDefaultScript = 1;
            continue;
        }

#ifdef WIN32SCREENSAVER

        if (CheckCommand("/S") || CheckCommand("/s")/* || CheckCommand("/P") || CheckCommand("/p")*/) {

            char *path;
            path = getRegistryString(REGISTRY_NAME_PATH);
            if (!path || strlen(path) == 0) {
                MessageBox(NULL, "Can't work out where Gravit lives!\nTry running Gravit by itself first", "Gravit Screensaver Error", MB_OK);
                cmdQuit(0);
                return 0;
            }
            SetCurrentDirectory(path);

            configRead(findFile(SCREENSAVER_FILE), 0);
            state.dontExecuteDefaultScript = 1;
            view.screenSaver = 1;

            continue;
        }

        // just ignore preview mode, configure dialog and change password
        if (CheckCommand("/P") || CheckCommand("/p") || CheckCommand("/C") || CheckCommand("/c") || CheckCommand("/A") || CheckCommand("/a")) {
            cmdQuit(0);
            return 0;
        }

#endif

        cmdExecute(argv[i]);

    }

    return 1;

}
Exemple #4
0
int main()
{
  signal(SIGINT, &prohandler);
  signal(SIGTERM, &prohandler);
  /** Allocation of the arguments' array */
  char** argumentArray = (char**) malloc(sizeof(char*) * NUM_OF_ARGS);
  
  int i=0;
  for(i=0;i<NUM_OF_ARGS;i++)
  {
    argumentArray[i] = (char*) malloc(sizeof(char) * MAX_ARG_SIZE);
  }
  /** Allocation of the input command array */
  char* command = malloc(MAX_COMMAND_SIZE);
  if (command == NULL)
  {
      printf("No memory \n");
      return 1;
  }
  /** Allocation of the home path array */
  char* home = malloc(1024);
  if (home == NULL)
  {
      printf("No memory \n");
      return 1;
  }
  /** End of allocations */
  /****************************************** MAIN LOOP  ********************************************************************/
  /**************************************************************************************************************************/
  
  //Like a normal shell - user@hostname
  struct passwd *p = getpwuid(getuid());  // Check for NULL!
  char hostname[HOST_NAME_MAX+1];
  
  while(1)
  {
    /**
     * Shell waiting for input. If you just press enter, or enter something starting with a whitespace, the shell will ask for 
     * new entry. If Ctrl-C is pressed while in the loop, the loop breaks.
     */
    
    do
    {
      //printf("User name: %s\n", p->pw_name);
      gethostname(hostname, sizeof(hostname));  // Check the return value!
      //printf("Host name: %s\n", hostname);
      
      //fprintf(stdout, KRED "SuperHackingShell:" RESET);
      fprintf(stdout, KCYN "%s" RESET "@" KGRN "%s:" RESET,p->pw_name,hostname);
      printDir();
      fprintf(stdout, KNRM "$ " RESET);
      fgets(command, MAX_COMMAND_SIZE, stdin);
            
    }while(strFilter(command)==0 );

    /** Check for exit command */
    if (stringCompare(command,"exit"))
      break;
    
    
    /**  Parsing  */
    int args = cmdParser(command, argumentArray, NUM_OF_ARGS);  //args contains the number of arguments the command contained.
    
    /** Executing programs and commands - if no cd command given */
    if(cd(argumentArray) != 0)
    {  
      /** Check for background execution */
      if( *argumentArray[args-1] == 38)  //if last argument of command is "&"(38), execute in background
      {  
        *argumentArray[args-1] = 0; //doesn't appear to create problems NOPE: me ls -l & peos
        //prepei na kopsw to teleutaio argument
        //printf("%s %s",argumentArray[0],argumentArray[1]);//tsekarei an to ekopse
        cmdExecBack(argumentArray);
      }
      /** Normal execution */
      else
        cmdExecute(argumentArray);
    }
  }
  fprintf(stdout, KRED"<1337>...SuperHackingShell...exiting... <1337> \n" RESET);
  free(command);
  free(argumentArray);
  exit(0);
}