示例#1
0
int executeCommand(programOptions po)
{
	switch (programOptionsGetMode(po))
	{
	case MODE_ADD:
		return commandAdd(po);
		break;
	case MODE_DELETE:
		return commandDelete(po);
		break;
	case MODE_EXTRACT:
		return commandExtract(po);
		break;
	case MODE_UPDATE:
		return commandUpdate(po);
		break;
	case MODE_CREATE:
		return commandCreate(po);
		break;
	case MODE_LIST:
		return commandList(po);
		break;
	case MODE_DIFF:
		return commandDiff(po);
		break;
	case MODE_HELP:
		return commandHelp(po);
		break;
	default:
		break;
	}
	return 0;
}
void commandDefault(const char * line)
{
	Serial.print("Syntax Error '");
	Serial.print(line);
	Serial.print("'");

	commandHelp();
}
示例#3
0
static int
getCommands(void) {
	paramLetters();
	do {
		printf("Command: ");
		getInput();
		switch (inputBuffer[0]) {
		case 0:
			break;
		case 'h':
			commandHelp();
			break;
		case 'C':
			show_charMap(-1);
			break;
		case 'D':
			show_dotsMap(-1);
			break;
		case 'z':
			show_compDots(-1);
			break;
		case 'c':
			show_characters(-1);
			break;
		case 'd':
			show_dots(-1);
			break;
		case 'f':
			show_forRules(-1);
			break;
		case 'b':
			show_backRules(-1);
			break;
		case 'i':
			show_brailleIndicators();
			break;
		case 'm':
			show_misc();
			break;
		case 'p':
			particular();
			break;
		case 'q':
			return 1;
		default:
			printf("Bad choice.\n");
			break;
		}
	} while (inputBuffer[0] != 'q');
	return 1;
}
示例#4
0
文件: HelpCmd.cpp 项目: xaizek/dit
boost::optional<int>
HelpCmd::run(Dit &, const std::vector<std::string> &args)
{
    if (args.size() > 1U) {
        err() << "Expected at most one argument.\n";
        return EXIT_FAILURE;
    }

    if (args.empty()) {
        return listCommands();
    }

    const std::string &cmdName = args[0];
    return commandHelp(cmdName);
}
示例#5
0
bool executeCommand(sqlite3 *db, const char *command)
{
    char **params;
    int paramsCount;
    int i;

    int from, to;
    double sum;

    (void)db;   // unused


    // parse command
    paramsCount = countWords(command);
    params = malloc(sizeof(char*) * paramsCount);
    for (i=0; i<paramsCount; i++)
        params[i] = getWord(command, i);            

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_HELP)))
        commandHelp();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_1)))
        command1();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_2)))
        command2();

    if ((paramsCount >= 4) && (!strcmp(params[0], COMMAND_TRANSF)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[3], "%lf", &sum);
        sscanf(params[2], "%i", &to);
        //transfer(db, from, to, sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
        credit(db, to, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_DEB)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_CRED)))
    {
        sscanf(params[1], "%i", &to);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0) return false;
        credit(db, to, sum);
    }

    if ((paramsCount >= 2) && (!strcmp(params[0], COMMAND_CHCK)))
    {
        sscanf(params[1], "%i", &to);
        checkAccount(db, to);
    }

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_UNDO)))
        undo(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADD)))
        createNewCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DEL)))
        deleteCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DELACC)))
        deleteAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADDACC)))
        addAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_COMMIT)))
        commit(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_SHOW)))
        showAll(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_LOGGER)))
        logger(db);

    for (i=0; i<paramsCount; i++)
        free(params[i]);
    free(params);

    return true;
}