Example #1
0
static void del_command(client_t *c, int ntoken, char **tokens)
{
    char command[1024];
    int  i;

    if (c->registered) {
        print(c, "You need to unregister first to modify commands.");
        return;
    }

    if (concat_tokens(command, sizeof(command), ntoken, tokens) == NULL) {
        print(c, "Command too long.");
        return;
    }

    for (i = 0; i < c->ncommand; i++) {
        if (!strcmp(c->commands[i], command)) {
            if (i < c->ncommand - 1)
                memmove(c->commands + i + 1, c->commands + i,
                        (c->ncommand - 1 - i) * sizeof(*c->commands));

            c->ncommand--;
            mrp_realloc(c->commands, sizeof(*c->commands) * c->ncommand);

            print(c, "Command '%s' deleted.", command);
        }
    }
}
static int add_decoder(int ncfg,
                       srs_cfg_t *cfgs,
                       const char *name,
                       size_t *pndec,
                       options_decoder_t **pdecs)
{
    int i;
    srs_cfg_t *cfg;
    const char *key;
    const char *value;
    size_t pfxlen;
    char pfx[1024];
    options_decoder_t *decs, *dec;
    size_t ndec, size;
    const char *hmm = NULL;
    const char *lm = NULL;
    const char *dict = NULL;
    const char *fsg = NULL;

    pfxlen = snprintf(pfx, sizeof(pfx), SPHINX_PREFIX "%s.", name);

    for (i = 0;  i < ncfg;  i++) {
        cfg = cfgs + i;
        key = cfg->key + pfxlen;
        value = cfg->value;

        if (!strncmp(cfg->key, pfx, pfxlen)) {

            switch (key[0]) {

            case 'd':
                if (!strcmp(key, "dict"))
                    dict = value;
                break;

            case 'f':
                if (!strcmp(key, "fsg"))
                    fsg = value;
                break;

            case 'h':
                if (!strcmp(key, "hmm"))
                    hmm = value;
                break;

            case 'l':
                if (!strcmp(key, "lm"))
                    lm = value;
                break;
            }
        }
    }

    ndec = *pndec;
    size = sizeof(options_decoder_t) * (ndec + 1);

    if (lm && dict && (decs = mrp_realloc(*pdecs, size))) {
        dec = decs + ndec++;

        dec->name = mrp_strdup(name);
        dec->hmm  = hmm ? mrp_strdup(hmm) : NULL;
        dec->lm   = mrp_strdup(lm);
        dec->dict = mrp_strdup(dict);
        dec->fsg  = fsg ? mrp_strdup(fsg) : NULL;

        *pndec = ndec;
        *pdecs = decs;

        return 0;
    }

    return -1;
}