Beispiel #1
0
void dumpInputs(Network::TrainingData const& datas)
{
    for (size_t i = 0; i < datas.size(); ++i) {
        std::cout << "INPUT #" << i << ": " << datas[i].y << ":" << std::endl;
        dumpInput(datas[i].x, 50, 50);
    }
}
Beispiel #2
0
int main(int argc, char * argv[], char * envp[]) {

    char s[100]; //Maximum assumed length of any command word
    int ch;
    char * temp;
    char * hostName;
    hostName = (char *) malloc(sizeof(char) * HOST_NAME_MAX);
    gethostname(hostName, HOST_NAME_MAX);
    char result[ PATH_MAX ];
    ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
    setenv("SHELL",result,1);
    ifp = stdin;
    if(argc > 1) {
        ifp = fopen(argv[1], "r");
        if(ifp == NULL) {
            printf("Unable to open file. User can enter commands manually.\n");
            ifp = stdin;
        }
    }

    while(!feof(ifp)) {
        if(argc <= 1) {
            printf("|%s@%s:%s$| ", getenv("USER"), hostName, getcwd(temp,PATH_MAX));
        }
        fscanf(ifp, "%s", s); //Read next command

        if(strcmp(s, "clr") == 0) {
            clear();
            printf("\033[2J\033[1;1H");
            /* The first one (\033[2J) clears the entire screen (J) from top to bottom (2). The second code (\033[1;1H) positions 				the cursor at row 1, column 1.*/
        }
        // Home command
        else if(strcmp(s, "HOME") == 0) {
            printf("%s\n", getenv(s));
        }
        // ls or dir command
        else if(strcmp(s, "dir") == 0) {
            clearSpace();
            if((ch = getchar()) == '\n')
                listDir(getcwd(temp, PATH_MAX));
            else {
                ungetc(ch, ifp);
                fscanf(ifp, "%s", s);
                listDir(s);
            }
        }
        // environ command
        else if(strcmp(s, "environ") == 0 ) {
            printEnvList(envp);
        }
        // echo command
        else if(strcmp(s, "echo") == 0) {
            dumpInput();
        }
        // quit command
        else if(strcmp(s, "quit") == 0) {
            exit(0);
        }
        // pwd command
        else if(strcmp(s, "pwd") == 0) {
            printf("%s\n", getenv("PWD"));
        }
        // pause command
        else if(strcmp(s, "pause") == 0) {
            while((ch = getc(ifp)) != '\n'); //For clearing input buffer from the same line of pause
            printf("Press enter or return key to resume.\n");
            while((ch = getc(ifp)) != '\n');
            //pause();
        }
        // help command
        else if(strcmp(s, "help") == 0) {
            clearSpace();
            if((ch = getc(ifp)) == '\n') {
                help();
            }
            else {
                ungetc(ch, ifp);
                fscanf(ifp, "%s", s);
                ind_help(s);
            }
        }
        // change directory command
        else if(strcmp(s, "cd") == 0) {
            clearSpace();
            if((ch = getc(ifp)) == '\n')
                printf("%s\n", getcwd(temp, PATH_MAX));
            else {
                ungetc(ch, ifp);
                fscanf(ifp, "%s", s);
                if(chdir(s) != 0)
                    printf("Error changing directory.\n");
                else setenv("PWD", getcwd(temp, PATH_MAX), 1);
            }
        }
    }//End of while(1)
    return 0;
}