/** * main function of cmml-uri-file-open, which opens the CMML file * given through a file uri, checks any offsets, registers the * callbacks, and then steps through the file in chunks of BUFSIZE * size, during which the callbacks get activated as the relevant * elements get parsed. * * Fragments may be given to the uri in one of two forms: * - #name - name is the value of an clip's id tag * - #clock:YYYYMMDDThhmmss.ffZ - this is a utc time; npt or smpte also possible */ int main(int argc, char *argv[]) { char *uri_string = NULL; URI * uri; CMML * doc; long n = 0; if (argc < 2) { fprintf (stderr, "Usage: %s <file://filename#fragment>\n", argv[0]); exit (1); } uri_string = argv[1]; uri = parse_file_uri(uri_string); doc = cmml_open(uri->path); /* if fragment given, forward to that */ if (uri->fragstr != NULL) cmml_skip_to_offset(doc, uri->fragstr); cmml_set_read_callbacks (doc, NULL, NULL, read_clip, NULL); while (((n = cmml_read (doc, BUFSIZE)) > 0)); cmml_close(doc); exit(0); }
static void parse_args(gint argc, gchar **argv, FileInfo *fi) { EncArray *encarray; gint i; GError *error = NULL; GOptionContext *context; gchar *opt_codeset = NULL; gint opt_tab_width = 0; gboolean opt_jump = 0; gboolean opt_version = FALSE; GOptionEntry entries[] = { { "codeset", 0, 0, G_OPTION_ARG_STRING, &opt_codeset, "Set codeset to open file", "CODESET" }, { "tab-width", 0, 0, G_OPTION_ARG_INT, &opt_tab_width, "Set tab width", "WIDTH" }, { "jump", 0, 0, G_OPTION_ARG_INT, &opt_jump, "Jump to specified line", "LINENUM" }, { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show version number", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; context = g_option_context_new("[filename]"); g_option_context_add_main_entries(context, entries, PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); g_option_context_set_ignore_unknown_options(context, FALSE); g_option_context_parse(context, &argc, &argv, &error); g_option_context_free(context); if (error) { g_print("%s: %s\n", PACKAGE, error->message); g_error_free(error); exit(-1); } if (opt_version) { g_print("%s\n", PACKAGE_STRING); exit(0); } if (opt_codeset) { g_convert("TEST", -1, "UTF-8", opt_codeset, NULL, NULL, &error); if (error) { g_error_free(error); error = NULL; } else { g_free(fi->charset); fi->charset = g_strdup(opt_codeset); } } if (opt_tab_width) indent_set_default_tab_width(opt_tab_width); if (opt_jump) jump_linenum = opt_jump; if (fi->charset && (g_ascii_strcasecmp(fi->charset, get_default_charset()) != 0) && (g_ascii_strcasecmp(fi->charset, "UTF-8") != 0)) { encarray = get_encoding_items(get_encoding_code()); for (i = 0; i < ENCODING_MAX_ITEM_NUM; i++) if (encarray->item[i]) if (g_ascii_strcasecmp(fi->charset, encarray->item[i]) == 0) break; if (i == ENCODING_MAX_ITEM_NUM) fi->charset_flag = TRUE; } if (argc >= 2) fi->filename = parse_file_uri(argv[1]); }
static void parse_args(gint argc, gchar **argv, FileInfo *fi) { EncArray *encarray; gint i; GError *error = NULL; #if GLIB_CHECK_VERSION(2, 6, 0) GOptionContext *context; gchar *opt_codeset = NULL; gint opt_tab_width = 0; gboolean opt_jump = 0; gboolean opt_version = FALSE; GOptionEntry entries[] = { { "codeset", 0, 0, G_OPTION_ARG_STRING, &opt_codeset, "Set codeset to open file", "CODESET" }, { "tab-width", 0, 0, G_OPTION_ARG_INT, &opt_tab_width, "Set tab width", "WIDTH" }, { "jump", 0, 0, G_OPTION_ARG_INT, &opt_jump, "Jump to specified line", "LINENUM" }, { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show version number", NULL }, { NULL } }; //Structure defined in glib for entries and commandline option parser //4th argument is an enum defined in glib context = g_option_context_new("[Filename]"); //Creates new context for option parsing g_option_context_add_main_entries(context, entries, PACKAGE); //PACKAGE == Translation Domain ?? g_option_context_add_group(context, gtk_get_option_group(TRUE)); g_option_context_set_ignore_unknown_options(context, FALSE); //sets error when unknown command g_option_context_parse(context, &argc, &argv, &error); //passes the arguments g_option_context_free(context); //free for gcontext if (error) { g_print("%s: %s\n", PACKAGE, error->message); //things to do for each option g_error_free(error); exit(-1); } if (opt_version) { g_print("%s\n", PACKAGE_STRING); exit(0); } if (opt_codeset) { g_convert("TEST", -1, "UTF-8", opt_codeset, NULL, NULL, &error); if (error) { g_error_free(error); error = NULL; } else { g_free(fi->charset); fi->charset = g_strdup(opt_codeset); } } if (opt_tab_width) indent_set_default_tab_width(opt_tab_width); if (opt_jump) jump_linenum = opt_jump; #else //code for older version of glib gint c; //getopt also parses the command line argument do { c = getopt_long(argc, argv, "", longopts, NULL); switch (c) { case 0: if (optarg) { g_convert("TEST", -1, "UTF-8", optarg, NULL, NULL, &error); if (error) { g_error_free(error); error = NULL; } else { g_free(fi->charset); fi->charset = g_strdup(optarg); } } break; case 't': if (optarg) indent_set_default_tab_width(atoi(optarg)); break; case 'j': if (optarg) jump_linenum = atoi(optarg); break; case 'v': g_print("%s\n", PACKAGE_STRING); exit(0); case '?': print_usage(); exit(0); } } while (c != -1); #endif if (fi->charset //Find fileinfo encarray data structure && (g_strcasecmp(fi->charset, get_default_charset()) != 0) && (g_strcasecmp(fi->charset, "UTF-8") != 0)) { encarray = get_encoding_items(get_encoding_code()); for (i = 0; i < ENCODING_MAX_ITEM_NUM; i++) if (encarray->item[i]) if (g_strcasecmp(fi->charset, encarray->item[i]) == 0) break; if (i == ENCODING_MAX_ITEM_NUM) fi->charset_flag = TRUE; } #if GLIB_CHECK_VERSION(2, 6, 0) if (argc >= 2) fi->filename = parse_file_uri(argv[1]); #else if (optind < argc) fi->filename = parse_file_uri(argv[optind]); #endif }
static void dnd_drag_data_recieved_handler(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { static gboolean flag_called_once = FALSE; gchar **files; gchar *filename; gchar *comline; gint i = 0, j = 0; gchar *filename_sh; gchar **strs; #ifdef ENABLE_CSDI j = 1; #endif DV(g_print("DND start!\n")); #if GTK_CHECK_VERSION(2, 10, 0) if (g_strcasecmp(gdk_atom_name(context->targets->data), "GTK_TEXT_BUFFER_CONTENTS") != 0) { #else if (info != TARGET_SELF) { #endif if (flag_called_once) { flag_called_once = FALSE; g_signal_stop_emission_by_name(widget, "drag_data_received"); DV(g_print("second drop signal killed.\n")); return; } else flag_called_once = TRUE; } DV({ g_print("info = %d\n", info); g_print("time = %d\n", time); g_print("context->protocol = %d\n", context->protocol); g_print("context->is_source = %d\n", context->is_source); g_print("context->targets = %d\n", g_list_length(context->targets)); g_print("context->target = %s\n", gdk_atom_name(context->targets->data)); /* g_print("context->target = %s\n", gdk_atom_name(context->targets->next->data)); g_print("context->target = %s\n", gdk_atom_name(context->targets->next->next->data)); g_print("context->actions = %d\n", context->actions); g_print("context->suggested_action = %d\n", context->suggested_action); g_print("context->action = %d\n", context->action); g_print("selection_data->selection = %s\n", gdk_atom_name(selection_data->selection)); g_print("selection_data->target = %s\n", gdk_atom_name(selection_data->target)); */ g_print("selection_data->type = %s\n", gdk_atom_name(selection_data->type)); g_print("selection_data->format = %d\n", selection_data->format); g_print("selection_data->length = %d\n", selection_data->length); g_print("%s\n", selection_data->data); }); if (selection_data->data && info == TARGET_URI_LIST) { files = g_strsplit((gchar *)selection_data->data, "\n" , -1); while (files[i]) { if (strlen(files[i]) == 0) break; filename = g_strstrip(parse_file_uri(files[i])); if (i + j == 0) dnd_open_first_file(filename); else { if (i + j == 1) save_config_file(); if (strstr(filename, " ")) { strs = g_strsplit(filename, " ", -1); filename_sh = g_strjoinv("\\ ", strs); g_strfreev(strs); } else filename_sh = g_strdup(filename); comline = g_strdup_printf("%s %s", PACKAGE, filename_sh); DV(g_print(">%s\n", comline)); g_free(filename_sh); g_spawn_command_line_async(comline, NULL); g_free(comline); } g_free(filename); i++; } g_strfreev(files); } else { clear_current_keyval(); undo_set_sequency(FALSE); #if GTK_CHECK_VERSION(2, 10, 0) if (info == TARGET_UTF8_STRING) { #else if (info == TARGET_SELF) { #endif undo_set_sequency_reserve(); context->action = GDK_ACTION_MOVE; } else if (info == TARGET_PLAIN && g_utf8_validate((gchar *)selection_data->data, -1, NULL)) { selection_data->type = gdk_atom_intern("UTF8_STRING", FALSE); } } return; } static gboolean dnd_drag_motion_handler(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GList *targets; gchar *name; gboolean flag = FALSE; targets = context->targets; while (targets) { name = gdk_atom_name(targets->data); DV(g_print("%s\n", name)); if (g_ascii_strcasecmp(name, "text/uri-list") == 0) flag = TRUE; g_free(name); targets = targets->next; } /* if (flag) context->action = GDK_ACTION_DEFAULT; else context->action = GDK_ACTION_COPY; // g_signal_stop_emission_by_name(widget, "drag_motion"); */ /* if (!flag) { gint bx, by; GtkTextIter iter; gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_WIDGET, x, y, &bx, &by); gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, bx, by); if (!dnd_mark) { dnd_mark = gtk_text_buffer_create_mark(GTK_TEXT_VIEW(widget)->buffer, NULL, &iter, TRUE); gtk_text_mark_set_visible(dnd_mark, TRUE); } else gtk_text_mark_set_visible(dnd_mark, FALSE); gtk_text_buffer_move_mark(GTK_TEXT_VIEW(widget)->buffer, dnd_mark, &iter); gtk_text_mark_set_visible(dnd_mark, TRUE); } */ return flag; }