Beispiel #1
0
static void parse_mp3_comments(const char *file) {
	AVFormatContext *fmt = NULL;
	int i;

	for (i = 0; i < COMMENT_ID_NUM; i++)
		comment[i][0] = 0;
	
	if (av_open_input_file(&fmt, file, NULL, 0, NULL))
		return;

	snprintf(comment[COMMENT_ID_ARTIST], MAX_COMMENT_LEN, "%s",
	         fmt->author);
	
	snprintf(comment[COMMENT_ID_TITLE], MAX_COMMENT_LEN, "%s",
	         fmt->title);
	
	snprintf(comment[COMMENT_ID_ALBUM], MAX_COMMENT_LEN, "%s",
	         fmt->album);

	for (i = 0; i < COMMENT_ID_NUM; i++)
		if (comment[i][0])
			strchomp(comment[i]);

	return;
}
Beispiel #2
0
static int olsrd_read_table (FILE *fh, /* {{{ */
    int (*callback) (int lineno, size_t fields_num, char **fields))
{
  char buffer[1024];
  size_t buffer_len;

  char *fields[32];
  size_t fields_num;

  int lineno;

  lineno = 0;
  while (fgets (buffer, sizeof (buffer), fh) != NULL)
  {
    /* An empty line ends the table. */
    buffer_len = strchomp (buffer);
    if (buffer_len == 0)
    {
      (*callback) (lineno, /* fields_num = */ 0, /* fields = */ NULL);
      break;
    }

    fields_num = strtabsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));

    (*callback) (lineno, fields_num, fields);
    lineno++;
  } /* while (fgets) */

  return (0);
} /* }}} int olsrd_read_table */
Beispiel #3
0
static inline void
tls_log_function(int level, const char *text)
{
    if (GNET_PROPERTY(tls_debug) > UNSIGNED(level)) {
        char *str = h_strdup(text);
        strchomp(str, 0);
        g_debug("TLS(%d): %s", level, str);
        hfree(str);
    }
}
/*----------------------------------------------------------------------
|   PLT_MicroMediaController::ProcessCommandLoop
+---------------------------------------------------------------------*/
void
PLT_MicroMediaController::ProcessCommandLoop()
{
    char command[2048];
    bool abort = false;

    command[0] = '\0';
    while (!abort) {
        printf("command> ");
        fflush(stdout);
        fgets(command, 2048, stdin);
        strchomp(command);

        if (0 == strcmp(command, "quit") || 0 == strcmp(command, "exit")) {
            abort = true;
        } else if (0 == strcmp(command, "setms")) {
            HandleCmd_setms();
        } else if (0 == strcmp(command, "getms")) {
            HandleCmd_getms();
        } else if (0 == strncmp(command, "ls", 2)) {
            HandleCmd_ls();
        } else if (0 == strcmp(command, "info")) {
            HandleCmd_info();
        } else if (0 == strcmp(command, "cd")) {
            HandleCmd_cd(command);
        } else if (0 == strcmp(command, "cd ..")) {
            HandleCmd_cdup();
        } else if (0 == strcmp(command, "pwd")) {
            HandleCmd_pwd();
        } else if (0 == strcmp(command, "setmr")) {
            HandleCmd_setmr();
        } else if (0 == strcmp(command, "getmr")) {
            HandleCmd_getmr();
        } else if (0 == strcmp(command, "open")) {
            HandleCmd_open();
        } else if (0 == strcmp(command, "play")) {
            HandleCmd_play();
        } else if (0 == strcmp(command, "stop")) {
            HandleCmd_stop();
        } else if (0 == strncmp(command, "seek", 4)) {
            HandleCmd_seek(command);
        } else if (0 == strcmp(command, "mute")) {
            HandleCmd_mute();
        } else if (0 == strcmp(command, "unmute")) {
            HandleCmd_mute();
        } else if (0 == strcmp(command, "help")) {
            HandleCmd_help();
        } else if (0 == strcmp(command, "")) {
            // just prompt again
        } else {
            printf("Unrecognized command: %s\n", command);
            HandleCmd_help();
        }
    }
}
Beispiel #5
0
/* Voice editor command */
int cmd_ve(char *input)
{
    // Help text
    if (input == NULL)
    {
        fprintf(stderr,
                "ve [voice]\n"
                "\t\tLaunches the voice editor, taking a voice name as an optional argument.\n"
                "\t\tIf [voice] has been specified, the corresponding voice is selected for editing.\n"
                "\t\tIf [voice] does not correspond to an existing voice, a new one is created by that name.\n"
                "\t\tIf no voice is specified, a new voice is created by the name \"New Voice\"\n");
        return FAIL;
    }

    strtok(input, " ");
    char *name = strtok(NULL, " ");

    // Banner
    putchar('\n');
    printf("------------------\n");
    printf("-- Voice editor --\n");
    printf("------------------\n\n");

    VoiceDef voice = {};
    if (name == NULL || read_voice(name, &voice) == FAIL)
        init_voice(&voice, name);

    // Input loop 
    bool running = true;
    char ve_input[512];
    while (running)
    { 
        printf("%s> ", voice.name);
        fgets(ve_input, 512, stdin);

        strchomp(ve_input);

        if (strncmp(ve_input, "quit", strlen("quit")) == 0)
            running = false;
        else
            for (int i = 0; i < num_voice_cmds; i++)
            {
                const char *name = VoiceCommands[i].name;
                if (strncmp(ve_input, name, strlen(name)) == 0)
                    VoiceCommands[i].callback(ve_input, &voice);
            }
    }

    return SUCCESS;
}
Beispiel #6
0
static int olsrd_read (void) /* {{{ */
{
  FILE *fh;
  char buffer[1024];
  size_t buffer_len;

  fh = olsrd_connect ();
  if (fh == NULL)
    return (-1);

  fputs ("\r\n", fh);
  fflush (fh);

  while (fgets (buffer, sizeof (buffer), fh) != NULL)
  {
    buffer_len = strchomp (buffer);
    if (buffer_len == 0)
      continue;

    if (strcmp ("Table: Links", buffer) == 0)
      olsrd_read_table (fh, olsrd_cb_links);
    else if (strcmp ("Table: Neighbors", buffer) == 0)
      olsrd_read_table (fh, olsrd_cb_ignore);
    else if (strcmp ("Table: Topology", buffer) == 0)
      olsrd_read_table (fh, olsrd_cb_topology);
    else if (strcmp ("Table: HNA", buffer) == 0)
      olsrd_read_table (fh, olsrd_cb_ignore);
    else if (strcmp ("Table: MID", buffer) == 0)
      olsrd_read_table (fh, olsrd_cb_ignore);
    else if (strcmp ("Table: Routes", buffer) == 0)
      olsrd_read_table (fh, olsrd_cb_routes);
    else if ((strcmp ("HTTP/1.0 200 OK", buffer) == 0)
        || (strcmp ("Content-type: text/plain", buffer) == 0))
    {
      /* ignore */
    }
    else
    {
      DEBUG ("olsrd plugin: Unable to handle line: %s", buffer);
    }
  } /* while (fgets) */

  fclose (fh);

  return (0);
} /* }}} int olsrd_read */
Beispiel #7
0
/* Initialize CMU dictionary */
int cmu_init(const char *filename, CMUDict *dictionary)
{
    FILE *fh = fopen(filename, "r");
    if (fh == NULL)
        return error(FAIL, "Unable to open file '%s' for reading\n", filename);

    char linebuf[CMU_LINE_MAX];

    // Count lines
    int lines = 0;
    while(fgets(linebuf, CMU_LINE_MAX, fh) != NULL)
    {
        // Skip comments, special characters and [multiple-definitions]
        if (isalnum(linebuf[0]) && /*||*/ strchr(linebuf, '(') == NULL)
            lines++;
    }
    fseek(fh, 0, SEEK_SET);

    // Allocate definitions array
    dictionary->def = malloc((lines + 1) * sizeof(CMUDef));
    dictionary->size = lines;

    // Read dictionary
    int i = 0;
    for (; fgets(linebuf, CMU_LINE_MAX, fh) != NULL && i < lines; /*i++*/)
    {
        // Skip comments and special characters
        if (!isalnum(linebuf[0]))
            continue;

        // Ignore multiple definitions (for now)
        if (strstr(linebuf, "(") != NULL)
            continue;

        // Separate word from definition
        char *word = strtok(linebuf, "  ");
        if (word == NULL)
            continue;
        else
            strncpy(dictionary->def[i].word, word, CMU_WORD_MAX);

        // Collect phonemes
        char *ARPAsym = strtok(NULL, " ");
        int j = 0;
        for (; ARPAsym != NULL; ARPAsym = strtok(NULL, " "), j++)
        {
            strchomp(ARPAsym);

            // Extract vowel stress
            dictionary->def[i].stress[j] = 0;
            for (int k = strlen(ARPAsym); k > 0; k--)
            {
                if (isdigit(ARPAsym[k]))
                {
                    dictionary->def[i].stress[j] = ARPAsym[k] - '0';
                    ARPAsym[k] = '\0';
                    break;
                }
            }

            // Get phoneme ID from symbol
            uint8_t phonID = get_phoneme_ID(ARPAsym);
            if (phonID >= NUM_PHONEMES)
            {
                fclose(fh);
                free(dictionary->def);
                return error(FAIL, "Discovered invalid phoneme '%s' in definition of '%s'\n",
                        ARPAsym, dictionary->def[i].word);
            }

            dictionary->def[i].phonIDs[j] = phonID;
        }

        // Record phoneme count
        dictionary->def[i].num_phonemes = j;

        // Linked list stuff
        dictionary->def[i].next = &dictionary->def[i + 1];
        i++;
    }

    dictionary->def[i].next = NULL;

    return SUCCESS;
}
Beispiel #8
0
/**
 * Analyze the data we have received, and give each line to the supplied
 * dispatcher callback `cb', after having chomped it.  On EOF, call `eof'
 * to finalize parsing.
 */
static void
parse_dispatch_lines(void *handle, const char *buf, size_t len,
		parse_dispatch_t cb, parse_eof_t eofile)
{
	struct parse_context *ctx;
	const char *p = buf;
	size_t remain = len;

	/*
	 * Retrieve parsing context, stored as an opaque attribute in the
	 * asynchronous HTTP request handle.
	 */

	ctx = http_async_get_opaque(handle);

	g_assert(ctx->handle == handle);	/* Make sure it's the right context */

	if (len == 0) {						/* Nothing to parse, got EOF */
		if (eofile != NULL)
			(*eofile)(ctx);
		return;
	}

	/*
	 * Read a line at a time.
	 */

	for (;;) {
		char *line;
		bool error;
		size_t line_len;
		size_t parsed;

		switch (getline_read(ctx->getline, p, remain, &parsed)) {
		case READ_OVERFLOW:
			http_async_cancel(handle);
			ghc_connecting = FALSE;
			return;
		case READ_DONE:
			p += parsed;
			remain -= parsed;
			break;
		case READ_MORE:			/* ok, but needs more data */
			g_assert(parsed == remain);
			return;
		}

		/*
		 * We come here everytime we get a full line.
		 */

		line = h_strdup(getline_str(ctx->getline));
		line_len = getline_length(ctx->getline);
		line_len = strchomp(line, line_len);

		error = !(*cb)(ctx, line, line_len); /* An ERROR was reported */
		HFREE_NULL(line);

		if (error) {
			ghc_ctx.ha = NULL;
			ghc_connecting = FALSE;
			return;
		}

		/*
		 * Make sure we don't process lines ad infinitum.
		 */

		ctx->lines++;
		if (ctx->lines >= ctx->maxlines) {
			const char *req;
			const char *url = http_async_info(handle, &req, NULL, NULL, NULL);
			if (GNET_PROPERTY(bootstrap_debug))
				g_warning("BOOT GHC got %u+ lines from \"%s %s\", stopping",
					ctx->lines, req, url);
			http_async_close(handle);
			ghc_connecting = FALSE;
			return;
		}

		getline_reset(ctx->getline);
	}
}
Beispiel #9
0
/**
 * Retrieve known GWC URLs.
 * They are normally saved in ~/.gtk-gnutella/gwcache.
 */
static void
gwc_retrieve(void)
{
    file_path_t fp[4], *fpv;
    uint len, added;
    int line, idx;
    FILE *in;
    char tmp[1024];

    len = settings_file_path_load(fp, gwc_file, SFP_ALL);

    g_assert(len <= N_ITEMS(fp));

    fpv = &fp[0];

retry:
    g_assert(ptr_cmp(fpv, &fp[N_ITEMS(fp)]) < 0);

    if (&fp[0] == fpv)
        in = file_config_open_read_chosen(gwc_what, fpv, len, &idx);
    else
        in = file_config_open_read_norename_chosen(gwc_what, fpv, len, &idx);

    if (NULL == in)
        return;

    /*
     * Retrieve each line, counting the amount of entries added.
     */

    line = 0;
    added = 0;

    while (fgets(tmp, sizeof(tmp), in)) {
        line++;

        if (tmp[0] == '#')		/* Skip comments */
            continue;

        if (tmp[0] == '\n')		/* Allow empty lines */
            continue;

        (void) strchomp(tmp, 0);
        if (gwc_add(tmp))
            added++;
    }

    fclose(in);

    /*
     * Now check whether we added anything from that file, and if we have not
     * and there are more backup files to open, retry with these fallbacks
     * instead.
     */

    if (0 == added && UNSIGNED(idx) < len - 1) {
        g_warning("%s(): nothing loaded from \"%s/%s\", trying fallbacks",
                  G_STRFUNC, fpv[idx].dir, fpv[idx].name);
        fpv += idx + 1;
        len -= idx + 1;
        g_assert(size_is_positive(len));
        goto retry;
    } else {
        if (GNET_PROPERTY(bootstrap_debug)) {
            g_debug("%s(): loaded %u URL%s from \"%s/%s\"",
                    G_STRFUNC, added, plural(added), fpv[idx].dir, fpv[idx].name);
        }
    }
}
Beispiel #10
0
int main (int argc, char *argv[])
{
    // Program banner
    printf(
            "----------------------------------\n"
            "---  Vocli Speech Synthesizer  ---\n"
            "----------------------------------\n"
            "- Version: %s%*c\n"
            "- Email: [email protected]   -\n"
            "----------------------------------\n\n",
            VOCLI_VERSION,
            abs(23 - strlen(VOCLI_VERSION)), '-');

    // Initialize resources
    printf("Initializing CMU dictionary...\n");
    CMUDict dictionary;
    cmu_init(CMU_PATH, &dictionary);

    printf("Creating Csound instance...\n");
    CSOUND *csound = csoundCreate(NULL);
    csoundSetOption(csound, "-odac");    // Real time output
    if (csound == NULL)
    {
        cmu_destroy(&dictionary);
        return error(FAIL, "Unable to create Csound");
    }

    printf("Initializing Vocli orchestra...\n");
    int res = orc_init(csound, ORC_PATH);
    if (res != SUCCESS)
    {
        csoundDestroy(csound);
        cmu_destroy(&dictionary);
        return error(FAIL, "FATAL: Unable to initialize Vocli orchestra\n");
    }

    // Special character whitelist
    char ok[] = "'_-";
    size_t oklen = strlen(ok);

    // Input loop
    bool running = true;
    char input[512];
    printf("\nType '!help' for a list of commands.\n\n");
    while (running)
    {
        // Prompt string
        printf("Enter some text> ");

        // Read text from input
        fgets(input, 512, stdin);
        strchomp(input);

        // Handle commands
        if (input[0] == '!')
        {
            if (strncmp(&input[1], "quit", strlen("quit")) == 0)
            {
                putchar('\n');
                running = false;
            }
            else
                for (int i = 0; i < num_cmds; i++)
                {
                    const char *name = Commands[i].name;
                    if (strncmp(&input[1], name, strlen(name)) == 0)
                        Commands[i].callback(&input[1]);
                }

            // Skip further input processing
            continue; 
        }

        // Reformat string to match the dictionary
        for (int i = 0, len = strlen(input); i < len; i++)
        {
            if (isalnum(input[i]))
                input[i] = toupper(input[i]);
            else
                for (int j = 0; j < oklen; j++)
                    if (input[i] == ok[j])
                        break;
                    else if (j == oklen - 1)
                        input[i] = ' ';
        }

        // Look up and print each word
        int i;
        char *word = strtok(input, " ");
        for (i = 0; word != NULL; i++)
        {
            CMUDef *def = cmu_find_word(word, &dictionary);
            if (def != NULL)
            {
                for (int j = 0; j < def->num_phonemes; j++)
                {
                    // Pass score event
                    char start = i ? '0' : '+';

                    const ARPAsym *sym = &ARPAbet[def->phonIDs[j]];
                    printf("%s", sym->name);

                    // Vowel stress
                    if (sym->type == PHON_MONO || sym->type == PHON_DIPTHO)
                        putchar(def->stress[j] + '0');

                    putchar(' ');
                }
            }

            // Separate each word
            if ((word = strtok(NULL, " ")) != NULL)
                printf(" - ");
        }

        putchar('\n');
    }

    // Clean up
    csoundDestroy(csound);       // Destroy Csound
    cmu_destroy(&dictionary);    // Destroy CMU dictionary

    return SUCCESS;
}