Пример #1
0
void string_to_window(Char *messagegroup, Char *mess)
{
    EDITINFO *edata;
    edata=message_window(messagegroup);
    if (!edata) {
	fprintf(stderr, (char*)UstrtoLocale(translate("No window named '%s'.\n%s\n")),
		UstrtoLocale(messagegroup), UstrtoLocale(mess));
	return;
    }
    append_editwindow(edata->info, mess, Ustrlen(mess));
}
Пример #2
0
void structure_to_window(Char *messagegroup)
{
    EDITINFO *edata;
    edata=message_window(messagegroup);
    if (!edata) {
	fprintf(stderr, "No window named '%s'.\n", UstrtoLocale(messagegroup));
	include_selection();
	return;
    }
    append_structure(edata->info);
}
Пример #3
0
void read_custom_files(void)
{
    gint i, n = 0;
    gchar *fullname;

    if (custom_directory == NULL)
        return;

    struct custom_data *d = g_malloc0(sizeof(struct custom_data));
    GDir *dir = g_dir_open(custom_directory, 0, NULL);

    GtkTextBuffer *msgbuf = message_window();
    show_msg(msgbuf, NULL, "Reading directory %s\n", custom_directory);

    if (dir) {
        db_create_blob_table();
        const gchar *fname = g_dir_read_name(dir);
        while (fname) {
            char *p = strstr(fname, ".txt");
            fullname = g_build_filename(custom_directory, fname, NULL);
            if (p && p[4] == 0) {
                LOG("\n---------- %s ------------", fname);
                show_msg(msgbuf, "bold", "Reading file %s\n", fname);

                char *msg = read_custom_category(fullname, d);
                if (msg) {
                    g_free(fullname);
                    fname = g_dir_read_name(dir);
                    show_msg(msgbuf, "red", "  %s\n", msg);
                    //show_message(msg);
                    continue;
                }
                guint hash = g_str_hash(d->name_short) << 5;
                db_delete_blob_line(hash);
                gint length;
                gchar *encoded = encode_custom_data(d, &length);
		if (length == 0)
		    show_msg(msgbuf, "red", "  Problem with encoding!\n");
                db_write_blob(hash, (void *)encoded, length);

                gchar buf[64];
                snprintf(buf, sizeof(buf) - 8, "%s", fname);
                p = strstr(buf, ".txt");
                if (p) *p = 0;
                else p = buf + strlen(buf);
                i = 1;
                while (1) {
                    sprintf(p, "-%d.svg", i);
                    gchar *svgname = g_build_filename(custom_directory, buf, NULL);
                    void *data = NULL;
                    gsize datalen;
                    GError *error = NULL;
                    gboolean ok = g_file_get_contents(svgname, (gchar **)&data, &datalen, &error);
                    if (!ok) {
                        if (i == 1) {
                            show_msg(msgbuf, "red", "  %s\n", error->message);
                            show_msg(msgbuf, NULL, "  Trying to read an example file\n");
                            sprintf(p, ".svg");
                            g_free(svgname);
                            svgname = g_build_filename(custom_directory, buf, NULL);
                            g_error_free(error);
                            error = NULL;
                            ok = g_file_get_contents(svgname, (gchar **)&data, &datalen, &error);
                            if (!ok) {
                                show_msg(msgbuf, "red", "  %s\n", error->message);
                                show_msg(msgbuf, NULL, "  Creating example file\n");
                                char *args[2] = {"", fullname};

                                // obtain the existing locale name for numbers    
                                char *old_locale = setlocale(LC_NUMERIC, NULL);
                                // set locale that uses points as decimal separator
                                setlocale(LC_NUMERIC, "en_US.UTF-8");
                                make_svg_file(2, args);
                                // set the locale back
                                setlocale(LC_NUMERIC, old_locale);

                                g_error_free(error);
                                error = NULL;
                                ok = g_file_get_contents(svgname, (gchar **)&data, &datalen, &error);
                                if (!ok) show_msg(msgbuf, "red", "  %s: %s\n", error->message);
                            }
                        }
                        if (error) g_error_free(error);
                        g_free(svgname);
                        svgname = NULL;
                        if (!ok) 
                            break;
                    }
                    g_free(svgname);
                    db_delete_blob_line(hash | i);
                    db_write_blob(hash | i, data, datalen);
                    g_free(data);
                    data = NULL;
                    i++;
                }
                show_msg(msgbuf, NULL, "  %d SVG pages found\n", i-1);
                n++;
            } // if
            g_free(fullname);
            fname = g_dir_read_name(dir);
        } // while fname

        g_dir_close(dir);
    } // if dir

    g_free(d);

    read_custom_from_db();
}
Пример #4
0
void open_message_window(Char *messagetitle)
{
    message_window(messagetitle);
}