コード例 #1
0
ファイル: helper.c プロジェクト: kitinfo/garfield-shell
bool begins(char* longer, char* shorter) {

        int len = strlen(shorter);
        char dest[len +1];

        strncpy(dest, &longer[0], len);
        dest[len] = '\0';

        return sequals(dest, shorter);
}
コード例 #2
0
/**
 * shell function
 */
int shell() {

    debug("shell init");
    checkLogin();

    char input[MAXLENGTH];
    for (;;) {
        printf("%s>", getUser());

        read_line(input);

        if (sequals(input, "exit")) {
            debug("shut down");
            shellExit();
        } else if (begins(input, "set ")) {
            debug("exec set cmd");
            parseSet(input + 4);
        } else if (begins(input, "list ")) {
            debug("exec list cmd");
            parseList(input + 5);
        } else if (begins(input, "search ")) {
            debug("exec find cmd from search");
            find(input + 7);
        } else if (begins(input, "find ")) {
            debug("exec find cmd");
            find(input + 5);
        } else if (begins(input, "buy ")) {
            debug("exec buy cmd");
            buy(input + 4);
        } else if (begins(input, "help")) {
            debug("exec help cmd");
            printInternHelp();
        } else if (begins(input, "balance")) {
            debug("exec balance cmd");
            balanceUser();
        } else {
            debug("no match found in shell");
            printf("Don't know what you mean...\n");
        }
    }
    return 0;
}