Пример #1
0
/*
 * running the shell mode
 */
void run_shell_mode(void)
{
	char * p;
	char cwd[256];
	char prompt[256];

	/*
	 * clear the screen
	 */
	console_cls(get_console_stdout());

	do {
		getcwd(cwd, sizeof(cwd));
		sprintf(prompt, "%s: %s$ ", getenv("prompt"), cwd);

		p = readline(prompt);

		exec_cmdline(p);
		free(p);
	} while(xboot_get_mode() == MODE_SHELL);
}
Пример #2
0
int main() {

    /*DECLARATIONS*/
    struct command *L[100];
    char *cmdLine = calloc(100,sizeof(char)); //command line
    int *groupD;                              //keep track of directives
    char c;
    int numLists = 0;                         //number of lists created
    int listNum=0;                            //specific list to deal with
    int i;

    signal(SIGCHLD, bg_handler);    //allow children to die
    signal(SIGALRM, alarm_handler); //check efficiency

    L[numLists] = (struct command *)calloc(1, sizeof(struct command));
    initialize_list(L[numLists]);
    
    printf("My Shell > ");
    fflush(stdout);
    
    while(1) {
        c = getchar();
        
        switch(c) {
            case'\n':
                if (cmdLine[0] == '\0') {
                    printf("My Shell > ");
                }
                else { /*execute command line*/
                    
                    groupD = parse_cmdline(L[numLists], cmdLine);
                    if (groupD[0] == 0){
                        exec_cmdline(L[numLists]);
                    }
                    else {
                        /*directives*/
                        for (i=0; i<numLists+1; i++){
                            if (L[i]->group == groupD[1]){
                                directive(L[i], groupD[0]);
                            }
                        }
                    }
                    printf("My Shell > ");
                    
                    numLists++;
                    L[numLists] = (struct command *)calloc(1, sizeof(struct command));
                    initialize_list(L[numLists]);
                    reset_cmdline(cmdLine);
                }
            break;
            
            default:
                strncat(cmdLine, &c, 1);
                break;
        }
    }
    for (i=0; i<numLists+1; i++)
        free_proclist(L[i]);
    free_listofproclist(L);
    free(cmdLine);
return -1;
}