static void
jsgf_set_search_path(jsgf_t * jsgf, const char *filename)
{
    char *jsgf_path;

#if !defined(_WIN32_WCE)
    if ((jsgf_path = getenv("JSGF_PATH")) != NULL) {
        char *word, *c;
        /* FIXME: This should be a function in libsphinxbase. */
        word = jsgf_path = ckd_salloc(jsgf_path);
        while ((c = strchr(word, ':'))) {
            *c = '\0';
            jsgf->searchpath = glist_add_ptr(jsgf->searchpath, word);
            word = c + 1;
        }
        jsgf->searchpath = glist_add_ptr(jsgf->searchpath, word);
        jsgf->searchpath = glist_reverse(jsgf->searchpath);
        return;
    }
#endif

    if (!filename) {
        jsgf->searchpath =
            glist_add_ptr(jsgf->searchpath, ckd_salloc("."));
        return;
    }

    jsgf_path = ckd_salloc(filename);
    path2dirname(filename, jsgf_path);
    jsgf->searchpath = glist_add_ptr(jsgf->searchpath, jsgf_path);
}
Beispiel #2
0
void
build_filenames(cmd_ln_t *config, char const *basename,
                char **out_infile, char **out_outfile)
{
    char const *di, *do_, *ei, *eo;

    di = cmd_ln_str_r(config, "-di");
    do_ = cmd_ln_str_r(config, "-do");
    ei = cmd_ln_str_r(config, "-ei");
    eo = cmd_ln_str_r(config, "-eo");

    *out_infile = string_join(di ? di : "",
                              di ? "/" : "",
                              basename,
                              ei ? "." : "",
                              ei ? ei : "",
                              NULL);
    *out_outfile = string_join(do_ ? do_ : "",
                               do_ ? "/" : "",
                               basename,
                               eo ? "." : "",
                               eo ? eo : "",
                              NULL);
    /* Build output directory structure if possible/requested (it is
     * by default). */
    if (cmd_ln_boolean_r(config, "-build_outdirs")) {
        char *dirname = ckd_salloc(*out_outfile);
        path2dirname(*out_outfile, dirname);
        build_directory(dirname);
        ckd_free(dirname);
    }
}
Beispiel #3
0
/*
 * Build a filename int buf as follows (without file extension):
 *     if dir ends with ,CTLand ctlspec does not begin with /, filename is dir/ctlspec
 *     if dir ends with ,CTL and ctlspec DOES begin with /, filename is ctlspec
 *     if dir does not end with ,CTL, filename is dir/uttid,
 * where ctlspec is the complete utterance spec in the input control file, and
 * uttid is the last component of ctlspec.
 */
static void
build_output_uttfile(char *buf, char *dir, char *uttid, char *ctlspec)
{
    int32 k;

    k = strlen(dir);
    if ((k > 4) && (strcmp(dir + k - 4, ",CTL") == 0)) {        /* HACK!! Hardwired ,CTL */
        if (ctlspec[0] != '/') {
            strcpy(buf, dir);
            buf[k - 4] = '/';
            strcpy(buf + k - 3, ctlspec);
        }
        else
            strcpy(buf, ctlspec);
    }
    else {
        strcpy(buf, dir);
        buf[k] = '/';
        strcpy(buf + k + 1, uttid);
    }
    /* Build output directory structure if possible/requested (it is
     * by default). */
    if (cmd_ln_boolean("-build_outdirs")) {
        char *dirname = ckd_salloc(buf);
        path2dirname(buf, dirname);
        build_directory(dirname);
        ckd_free(dirname);
    }
}
int
main(int argc, char *argv[])
{
    char const testname[] = "/foo/bar/baz/quux.argh";
    char const testname2[] = "foo/bar/baz";
    char const testname3[] = "/foo";
    char testout[32];

    TEST_EQUAL(0, strcmp("quux.argh", path2basename(testname)));

    path2dirname(testname, testout);
    TEST_EQUAL(0, strcmp("/foo/bar/baz", testout));

    path2dirname(testname2, testout);
    TEST_EQUAL(0, strcmp("foo/bar", testout));

    path2dirname(testname3, testout);
    TEST_EQUAL(0, strcmp("", testout));

    return 0;
}
Beispiel #5
0
static int
build_outdirs(cmd_ln_t *config, char const *uttid)
{
    char *uttpath = ckd_salloc(uttid);

    path2dirname(uttid, uttpath);
    build_outdir_one(config, "-outlatdir", uttpath);
    build_outdir_one(config, "-mfclogdir", uttpath);
    build_outdir_one(config, "-rawlogdir", uttpath);
    build_outdir_one(config, "-senlogdir", uttpath);
    build_outdir_one(config, "-nbestdir", uttpath);
    ckd_free(uttpath);

    return 0;
}
Beispiel #6
0
void
ctl_outfile(char *file, const char *dir, const char *ext,
	    const char *utt, const char *uttid, int build_dirs)
{
    int32 k;

    k = strlen(dir);

    if ((k > 4) && (strcmp(dir + k - 4, ",CTL") == 0)) {        /* HACK!! Hardwired ,CTL */
        if (utt[0] != '/') {
            strcpy(file, dir);
            file[k - 4] = '/';
            strcpy(file + k - 3, utt);
        }
        else
            strcpy(file, utt);
    }
    else {
        strcpy(file, dir);
        file[k] = '/';
        strcpy(file + k + 1, uttid);
    }

    if (ext && (ext[0] != '\0')) {
        strcat(file, ".");
        strcat(file, ext);
    }

    /* Build output directory structure if possible/requested */
    if (build_dirs) {
        char *dirname = ckd_salloc(file);
        path2dirname(file, dirname);
        build_directory(dirname);
        ckd_free(dirname);
    }
}