static GHashTable * dictionary_from_vorbis_comment (vorbis_comment * vc) { gint i; GHashTable * dict = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) str_unref, (GDestroyNotify) str_unref); for (i = 0; i < vc->comments; i++) { gchar **frags; AUDDBG("%s\n", vc->user_comments[i]); frags = g_strsplit(vc->user_comments[i], "=", 2); if (frags[0] && frags[1]) { gchar * key = g_ascii_strdown (frags[0], -1); g_hash_table_insert (dict, str_get (key), str_get (frags[1])); g_free (key); } g_strfreev(frags); /* Don't use g_free() for string lists! --eugene */ } return dict; }
static void tr_co(char **args) { char *src = args[1]; char *dst = args[2]; if (src && dst && str_get(map(src))) str_set(map(dst), str_get(map(src))); }
EXPORT char * str_nget (const char * str, int len) { if (strlen (str) <= len) return str_get (str); char buf[len + 1]; memcpy (buf, str, len); buf[len] = 0; return str_get (buf); }
static bool_t audpl_load (const char * path, VFSFile * file, char * * title, Index * filenames, Index * tuples) { ReadState * state = malloc (sizeof (ReadState)); state->file = file; state->cur = state->buf; state->len = 0; char * key, * val; if (! read_key (state, & key, & val) || strcmp (key, "title")) { free (state); return FALSE; } * title = str_get (val); bool_t readed = read_key (state, & key, & val); while (readed && ! strcmp (key, "uri")) { char * uri = str_get (val); Tuple * tuple = NULL; while ((readed = read_key (state, & key, & val)) && strcmp (key, "uri")) { if (! tuple) tuple = tuple_new_from_filename (uri); if (! strcmp (key, "empty")) continue; int field = tuple_field_by_name (key); TupleValueType type = tuple_field_get_type (field); if (field < 0) break; if (type == TUPLE_STRING) tuple_set_str (tuple, field, NULL, val); else if (type == TUPLE_INT) tuple_set_int (tuple, field, NULL, atoi (val)); } index_append (filenames, uri); index_append (tuples, tuple); } free (state); return TRUE; }
static void tr_coo(char **args) { char *reg = args[1]; char *path = args[2]; FILE *fp; if (!reg || !reg[0] || !path || !path[0]) return; if ((fp = fopen(path, "w"))) { if (str_get(map(reg))) fputs(str_get(map(reg)), fp); fclose(fp); } }
static void tr_as(char **args) { int reg; char *s1, *s2, *s; reg = map(args[1]); s1 = str_get(reg) ? str_get(reg) : ""; s2 = args[2] ? args[2] : ""; s = xmalloc(strlen(s1) + strlen(s2) + 1); strcpy(s, s1); strcat(s, s2); str_set(reg, s); free(s); }
static void tr_coa(char **args) { char *src = args[1]; char *dst = args[2]; if (src && dst && str_get(map(src))) { struct sbuf sb; sbuf_init(&sb); if (str_get(map(dst))) sbuf_append(&sb, str_get(map(dst))); sbuf_append(&sb, str_get(map(src))); str_set(map(dst), sbuf_buf(&sb)); sbuf_done(&sb); } }
char * get_path_to_self (void) { #if defined _WIN32 || defined HAVE_PROC_SELF_EXE int size = 256; while (1) { char buf[size]; int len; #ifdef _WIN32 if (! (len = GetModuleFileName (NULL, buf, size))) { fprintf (stderr, "GetModuleFileName failed.\n"); return NULL; } #else if ((len = readlink ("/proc/self/exe", buf, size)) < 0) { fprintf (stderr, "Cannot access /proc/self/exe: %s.\n", strerror (errno)); return NULL; } #endif if (len < size) { buf[len] = 0; return str_get (buf); } size += size; } #elif defined __APPLE__ unsigned int size = 256; while (1) { char buf[size]; int res; if (! (res = _NSGetExecutablePath (buf, &size))) return str_get (buf); if (res != -1) return NULL; } #else return NULL; #endif }
static void tr_chop(char **args) { struct sbuf sbuf; int id; id = map(args[1]); if (str_get(id)) { sbuf_init(&sbuf); sbuf_append(&sbuf, str_get(id)); if (!sbuf_empty(&sbuf)) { sbuf_cut(&sbuf, sbuf_len(&sbuf) - 1); str_set(id, sbuf_buf(&sbuf)); } sbuf_done(&sbuf); } }
static void tr_de(char **args) { struct sbuf sbuf; int id; if (!args[1]) return; id = map(args[1]); sbuf_init(&sbuf); if (args[0][1] == 'a' && args[0][2] == 'm' && str_get(id)) sbuf_append(&sbuf, str_get(id)); macrobody(&sbuf, args[2] ? args[2] : "."); str_set(id, sbuf_buf(&sbuf)); sbuf_done(&sbuf); if (!n_cp && args[3]) /* parse the arguments as request argv[3] */ str_dset(id, str_dget(map(args[3]))); }
void config_set_defaults (const char * section, const char * const * entries) { g_return_if_fail (defaults && keyfile); pthread_mutex_lock (& mutex); if (! section) section = DEFAULT_SECTION; GHashTable * table = g_hash_table_lookup (defaults, section); if (! table) { table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, str_unref_cb); g_hash_table_replace (defaults, g_strdup (section), table); } while (1) { const char * name = * entries ++; const char * value = * entries ++; if (! name || ! value) break; g_hash_table_replace (table, g_strdup (name), str_get (value)); } pthread_mutex_unlock (& mutex); }
static void search_conf(void) { struct symbol **sym_arr; struct gstr res; char *dialog_input; int dres; again: dialog_clear(); dres = dialog_inputbox(_("Search Configuration Parameter"), _("Enter CONFIG_ (sub)string to search for " "(with or without \"CONFIG\")"), 10, 75, ""); switch (dres) { case 0: break; case 1: show_helptext(_("Search Configuration"), search_help); goto again; default: return; } /* strip CONFIG_ if necessary */ dialog_input = dialog_input_result; if (strncasecmp(dialog_input_result, "CONFIG_", 7) == 0) dialog_input += 7; sym_arr = sym_re_search(dialog_input); res = get_relations_str(sym_arr); free(sym_arr); show_textbox(_("Search Results"), str_get(&res), 0, 0); str_free(&res); }
char * write_temp_file (void * data, int64_t len) { char * temp = filename_build (g_get_tmp_dir (), "audacious-temp-XXXXXX"); SCOPY (name, temp); str_unref (temp); int handle = g_mkstemp (name); if (handle < 0) { fprintf (stderr, "Error creating temporary file: %s\n", strerror (errno)); return NULL; } while (len) { int64_t written = write (handle, data, len); if (written < 0) { fprintf (stderr, "Error writing %s: %s\n", name, strerror (errno)); close (handle); return NULL; } data = (char *) data + written; len -= written; } if (close (handle) < 0) { fprintf (stderr, "Error closing %s: %s\n", name, strerror (errno)); return NULL; } return str_get (name); }
static void read_all_frames (VFSFile * handle, int version, bool_t syncsafe, int data_size, GHashTable * dict) { int pos; for (pos = 0; pos < data_size; ) { int frame_size, size; char key[5]; char * data; GenericFrame * frame; if (! read_frame (handle, data_size - pos, version, syncsafe, & frame_size, key, & data, & size)) break; pos += frame_size; frame = g_slice_new (GenericFrame); strcpy (frame->key, key); frame->data = data; frame->size = size; void * key2, * list = NULL; if (g_hash_table_lookup_extended (dict, key, & key2, & list)) g_hash_table_steal (dict, key); else key2 = str_get (key); list = g_list_append (list, frame); g_hash_table_insert (dict, key2, list); } }
static void search_conf(void) { struct symbol **sym_arr; struct gstr res; int dres; again: dialog_clear(); dres = dialog_inputbox(_("Search Configuration Parameter"), _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"), 10, 75, ""); switch (dres) { case 0: break; case 1: show_helptext(_("Search Configuration"), search_help); goto again; default: return; } sym_arr = sym_re_search(dialog_input_result); res = get_relations_str(sym_arr); free(sym_arr); show_textbox(_("Search Results"), str_get(&res), 0, 0); str_free(&res); }
static GHashTable * create_extension_dict (void) { GHashTable * dict = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) str_unref, NULL); AVInputFormat * f; for (f = av_iformat_next (NULL); f; f = av_iformat_next (f)) { if (! f->extensions) continue; gchar * exts = g_ascii_strdown (f->extensions, -1); gchar * parse, * next; for (parse = exts; parse; parse = next) { next = strchr (parse, ','); if (next) { * next = 0; next ++; } g_hash_table_insert (dict, str_get(parse), f); } g_free (exts); } return dict; }
static void search_conf(void) { struct symbol **sym_arr; int stat; struct gstr res; again: cprint_init(); cprint("--title"); cprint(_("Search Configuration Parameter")); cprint("--inputbox"); cprint(_("Enter CONFIG_ (sub)string to search for (omit CONFIG_)")); cprint("10"); cprint("75"); cprint(""); stat = exec_conf(); if (stat < 0) goto again; switch (stat) { case 0: break; case 1: show_helptext(_("Search Configuration"), search_help); goto again; default: return; } sym_arr = sym_re_search(input_buf); res = get_relations_str(sym_arr); free(sym_arr); show_textbox(_("Search Results"), str_get(&res), 0, 0); str_free(&res); }
static char * file_str_entry_get(FILE *f, const char *entry) { char buf[4096]; char *tmp; tmp = fgets(buf, sizeof(buf), f); if (!tmp) { EINA_LOG_ERR("unexpected end of file, expected: '%s'", entry); return NULL; } if (strcmp(tmp, entry) != 0) { EINA_LOG_ERR("unexpected file entry, expected: '%s'", entry); return NULL; } tmp = str_get(tmp); if (!tmp) { EINA_LOG_ERR("unexpected file entry, missing value for '%s'", entry); return NULL; } return tmp; }
static char * str_get_decoded (char * str) { if (! str) return NULL; str_decode_percent (str, -1, str); return str_get (str); }
static void save_and_close(gchar * cmd, gchar * cmd_after, gchar * cmd_end, gchar * cmd_ttc) { aud_set_str("song_change", "cmd_line", cmd); aud_set_str("song_change", "cmd_line_after", cmd_after); aud_set_str("song_change", "cmd_line_end", cmd_end); aud_set_str("song_change", "cmd_line_ttc", cmd_ttc); str_unref(cmd_line); str_unref(cmd_line_after); str_unref(cmd_line_end); str_unref(cmd_line_ttc); cmd_line = str_get(cmd); cmd_line_after = str_get(cmd_after); cmd_line_end = str_get(cmd_end); cmd_line_ttc = str_get(cmd_ttc); }
static void show_help(struct menu *menu) { struct gstr help = str_new(); menu_get_ext_help(menu, &help); show_helptext(_(menu_get_prompt(menu)), str_get(&help)); str_free(&help); }
static void print_help(struct menu *menu) { struct gstr help = str_new(); menu_get_ext_help(menu, &help); printf("\n%s\n", str_get(&help)); str_free(&help); }
static void show_help(struct menu *menu) { struct gstr help = str_new(); help.max_width = getmaxx(stdscr) - 10; menu_get_ext_help(menu, &help); show_helptext(_(menu_get_prompt(menu)), str_get(&help)); str_free(&help); }
static void insert_int_tuple_field_to_dictionary (const Tuple * tuple, int fieldn, GHashTable * dict, const char * key) { int val = tuple_get_int (tuple, fieldn); if (val > 0) g_hash_table_insert (dict, str_get (key), int_to_str (val)); else g_hash_table_remove (dict, key); }
static void insert_str_tuple_field_to_dictionary (const Tuple * tuple, int fieldn, GHashTable * dict, const char * key) { char * val = tuple_get_str (tuple, fieldn); if (val && val[0]) g_hash_table_insert (dict, str_get (key), str_ref (val)); else g_hash_table_remove (dict, key); str_unref(val); }
char * construct_uri (const char * path, const char * reference) { /* URI */ if (strstr (path, "://")) return str_get (path); /* absolute filename */ #ifdef _WIN32 if (path[0] && path[1] == ':' && path[2] == '\\') #else if (path[0] == '/') #endif return filename_to_uri (path); /* relative path */ const char * slash = strrchr (reference, '/'); if (! slash) return NULL; char * utf8 = str_to_utf8 (path, -1); if (! utf8) return NULL; int pathlen = slash + 1 - reference; char buf[pathlen + 3 * strlen (utf8) + 1]; memcpy (buf, reference, pathlen); if (get_bool (NULL, "convert_backslash")) { SCOPY (tmp, utf8); str_replace_char (tmp, '\\', '/'); str_encode_percent (tmp, -1, buf + pathlen); } else str_encode_percent (utf8, -1, buf + pathlen); str_unref (utf8); return str_get (buf); }
static void begin_add (const char * path) { int list = get_playlist (FALSE, FALSE); if (list < 0) list = create_playlist (); aud_set_str ("search-tool", "path", path); char * uri = filename_to_uri (path); g_return_if_fail (uri); if (! g_str_has_suffix (uri, "/")) { SCONCAT2 (temp, uri, "/"); str_unref (uri); uri = str_get (temp); } destroy_added_table (); added_table = g_hash_table_new_full ((GHashFunc) str_hash, (GEqualFunc) str_equal, (GDestroyNotify) str_unref, NULL); int entries = aud_playlist_entry_count (list); for (int entry = 0; entry < entries; entry ++) { char * filename = aud_playlist_entry_get_filename (list, entry); if (g_str_has_prefix (filename, uri) && ! g_hash_table_contains (added_table, filename)) { aud_playlist_entry_set_selected (list, entry, FALSE); g_hash_table_insert (added_table, filename, NULL); } else { aud_playlist_entry_set_selected (list, entry, TRUE); str_unref (filename); } } aud_playlist_delete_selected (list); aud_playlist_remove_failed (list); Index * add = index_new (); index_insert (add, -1, uri); aud_playlist_entry_insert_filtered (list, -1, add, NULL, filter_cb, NULL, FALSE); adding = TRUE; }
EXPORT void event_queue_full (int time, const char * name, void * data, void (* destroy) (void *)) { Event * event = g_slice_new (Event); event->name = str_get (name); event->data = data; event->destroy = destroy; pthread_mutex_lock (& mutex); event->source = g_timeout_add (time, (GSourceFunc) event_execute, event); events = g_list_prepend (events, event); pthread_mutex_unlock (& mutex); }
static GenericFrame * add_generic_frame (int id, int size, GHashTable * dict) { GenericFrame * frame = g_slice_new (GenericFrame); strcpy (frame->key, id3_frames[id]); frame->data = g_malloc (size); frame->size = size; GList * list = g_list_append (NULL, frame); g_hash_table_insert (dict, str_get (id3_frames[id]), list); return frame; }
static int verify_tool (const Str* tool) { /* verify name */ if ( (str_compare_cstr (tool, "brot")) &&(str_compare_cstr (tool, "fold")) &&(str_compare_cstr (tool, "er2de"))) { THROW_ERROR_MSG ("Unknown application: \"%s\", try `%s --help` for more " "information.",str_get (tool), get_progname()); return 1; } return 0; }