Пример #1
0
gboolean biblio_compile_bibliography (GuBiblio* bc, GuEditor* ec, GuLatex* lc) {
    gchar* dirname = g_path_get_dirname (ec->workfile);
    gchar* auxname = NULL;

    if (ec->filename) {
        auxname = g_strdup (ec->pdffile);
        auxname[strlen (auxname) -4] = 0;
    } else
        auxname = g_strdup (ec->fdname);

    if (g_find_program_in_path ("bibtex")) {
        gboolean success = FALSE;
        char* command = g_strdup_printf ("%s bibtex \"%s\"",
                                         C_TEXSEC, auxname);

        g_free (auxname);
        latex_update_workfile (lc, ec);
        latex_update_auxfile (lc, ec);
        Tuple2 res = utils_popen_r (command, dirname);
        gtk_widget_set_tooltip_text (GTK_WIDGET (bc->progressbar),
                (gchar*)res.second);
        g_free (command);
        g_free (dirname);
        success = ! (strstr ((gchar*)res.second, "Database file #1") == NULL);
        g_free (res.second);
        return success;
    }
    slog (L_WARNING, "bibtex command is not present or executable.\n");
    g_free (auxname);
    g_free (dirname);
    return FALSE;
}
Пример #2
0
void latex_update_auxfile(GuLatex* lc, GuEditor* ec)
{
  gchar* dirname = g_path_get_dirname(ec->targetfile);
  gchar* command = g_strdup_printf("%s %s "
                                   "--draftmode "
                                   "-interaction=nonstopmode "
                                   "--output-directory=\"%s\" \"%s\"",
                                   C_TEXSEC,
                                   config_get_value("typesetter"),
                                   C_TMPDIR,
                                   ec->targetfile);
  Tuple2 res = utils_popen_r(command, dirname);
  g_free(dirname);
  g_free(res.second);
  g_free(command);
}
Пример #3
0
gboolean latex_run_makeindex(GuEditor* ec)
{
  int retcode;

  if (g_find_program_in_path("makeindex")) {

    gchar* command = g_strdup_printf("%s makeindex \"%s.idx\"",
                                     C_TEXSEC,
                                     g_path_get_basename(ec->basename));

    Tuple2 res = utils_popen_r(command, C_TMPDIR);
    retcode = (glong)res.first;
    g_free(command);
  }
  if (retcode == 0) return TRUE;
  return FALSE;
}
Пример #4
0
void latex_update_pdffile(GuLatex* lc, GuEditor* ec)
{
  static glong cerrors = 0;
  gchar* basename = ec->basename;
  gchar* filename = ec->filename;

  if (!lc->modified_since_compile) {
    lc->compile_status = cerrors == 0;

  }

  const gchar* typesetter = config_get_value("typesetter");
  if (!external_exists(typesetter)) {
    /* Set to default first detected typesetter */
    config_set_value("typesetter", "pdflatex");
  }

  /* create compile command */
  gchar* curdir = g_path_get_dirname(ec->targetfile);
  gchar *command = latex_set_compile_cmd(ec);

  slog(L_DEBUG, "Command: %s\n", command);

  g_free(lc->compilelog);
  memset(lc->errorlines, 0, BUFSIZ);

  /* run pdf compilation */
  Tuple2 cresult = utils_popen_r(command, curdir);
  cerrors = (glong)cresult.first;
  gchar* coutput = (gchar*)cresult.second;

  lc->compilelog = latex_analyse_log(coutput, filename, basename);
  lc->modified_since_compile = FALSE;

  /* find error line */
  if (cerrors && (g_utf8_strlen(lc->compilelog, -1) != 0)) {
    latex_analyse_errors(lc);
  }

  g_free(command);
  g_free(curdir);

  lc->compile_status = cerrors == 0;
}
Пример #5
0
GuPrefsGui* prefsgui_init(GtkWindow* mainwindow)
{
  GuPrefsGui* p = g_new0(GuPrefsGui, 1);
  GtkBuilder* builder = gtk_builder_new();
  gchar* ui = g_build_filename(GUMMI_DATA, "ui", "prefs.glade", NULL);
  gtk_builder_add_from_file(builder, ui, NULL);
  gtk_builder_set_translation_domain(builder, PACKAGE);
  g_free(ui);

  p->prefwindow =
    GTK_WIDGET(gtk_builder_get_object(builder, "prefwindow"));
  p->notebook =
    GTK_NOTEBOOK(gtk_builder_get_object(builder, "notebook1"));
  p->textwrap_button =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "textwrapping"));
  p->wordwrap_button =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "wordwrapping"));
  p->line_numbers =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "line_numbers"));
  p->highlighting =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "highlighting"));
  p->tabwidth =
    GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "tabwidth"));
  p->spaces_instof_tabs =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "spaces_instof_tabs"));
  p->autoindentation =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "autoindentation"));
  p->autosaving =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "autosaving"));
  p->compile_status =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "compile_status"));
  p->autosave_timer =
    GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "autosave_timer"));
  p->combo_languages =
    GTK_COMBO_BOX_TEXT(gtk_builder_get_object(builder, "combo_languages"));
  p->styleschemes_treeview =
    GTK_TREE_VIEW(gtk_builder_get_object(builder, "styleschemes_treeview"));
  p->list_styleschemes =
    GTK_LIST_STORE(gtk_builder_get_object(builder, "list_styleschemes"));
  p->default_textview =
    GTK_TEXT_VIEW(gtk_builder_get_object(builder, "default_textview"));
  p->default_buffer =
    gtk_text_view_get_buffer(p->default_textview);
  p->editor_font =
    GTK_FONT_BUTTON(gtk_builder_get_object(builder, "editor_font"));
  p->compile_scheme =
    GTK_COMBO_BOX(gtk_builder_get_object(builder, "combo_compilescheme"));
  p->compile_timer =
    GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "compile_timer"));
  p->autoexport =
    GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "auto_export"));

  p->typ_pdflatex =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "typ_pdflatex"));
  p->typ_xelatex =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "typ_xelatex"));
  p->typ_rubber =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "typ_rubber"));
  p->typ_latexmk =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "typ_latexmk"));

  p->method_texpdf =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "method_texpdf"));
  p->method_texdvipdf =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "method_texdvipdf"));
  p->method_texdvipspdf =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "method_texdvipspdf"));

  p->opt_shellescape =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "opt_shellescape"));
  p->opt_synctex =
    GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "opt_synctex"));

  p->combo_animated_scroll =
    GTK_COMBO_BOX(gtk_builder_get_object(builder, "combo_animated_scroll"));
  p->spin_cache_size =
    GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "spin_cache_size"));

  p->view_box = GTK_BOX(gtk_builder_get_object(builder, "view_box"));
  p->editor_box = GTK_BOX(gtk_builder_get_object(builder, "editor_box"));
  p->compile_box = GTK_BOX(gtk_builder_get_object(builder, "compile_box"));

  gtk_window_set_transient_for(GTK_WINDOW(p->prefwindow), mainwindow);

#ifdef USE_GTKSPELL
  /* list available languages */
  if (g_file_test(
        g_find_program_in_path("enchant-lsmod"), G_FILE_TEST_EXISTS)) {

    Tuple2 pret = utils_popen_r("enchant-lsmod -list-dicts", NULL);
    if (pret.second != NULL) {
      gchar** output = g_strsplit((gchar*)pret.second, "\n", BUFSIZ);
      gchar** elems = NULL;
      int i;

      for (i = 0; output[i] != NULL; i++) {
        elems = g_strsplit(output[i], " ", BUFSIZ);
        if (elems[0] != NULL) {
          gtk_combo_box_text_append_text(p->combo_languages, elems[0]);
        }
      }
      g_strfreev(output);
      g_strfreev(elems);
    }
    gtk_combo_box_set_active(GTK_COMBO_BOX(p->combo_languages), 0);
    g_free((gchar*)pret.second);
  }
#else
  /* desensitise gtkspell related GUI elements if not used */
  GtkWidget* box = GTK_WIDGET(
                     gtk_builder_get_object(builder, "box_spellcheck"));
  gtk_widget_set_sensitive(box, FALSE);
#endif
  GList* schemes = editor_list_style_scheme_sorted();
  GList* schemes_iter = schemes;
  gchar* desc = NULL;
  GtkTreeIter iter;
  while (schemes_iter) {
    desc = g_markup_printf_escaped("<b>%s</b> - %s",
                                   gtk_source_style_scheme_get_name(schemes_iter->data),
                                   gtk_source_style_scheme_get_description(schemes_iter->data));
    gtk_list_store_append(p->list_styleschemes, &iter);
    gtk_list_store_set(p->list_styleschemes, &iter,
                       0, desc,
                       1, gtk_source_style_scheme_get_id(schemes_iter->data), -1);
    schemes_iter = g_list_next(schemes_iter);
    g_free(desc);
  }
  g_list_free(schemes);

  gtk_builder_connect_signals(builder, NULL);

  return p;
}
Пример #6
0
G_MODULE_EXPORT
void on_menu_docstat_activate(GtkWidget *widget, void *user)
{
  gint i = 0;
  gchar* output = 0;
  gchar* cmd = 0;
  gchar** matched = NULL;
  GError* err = NULL;
  GMatchInfo* match_info;
  GRegex* regexs[TEXCOUNT_OUTPUT_LINES];
  gchar* res[TEXCOUNT_OUTPUT_LINES] = { 0 };


  /* TODO: can we deprecate this? */
  const gchar* terms[] = {
    _("Words in text"),
    _("Words in headers"),
    _("Words in float captions"),
    _("Number of headers"),
    _("Number of floats"),
    _("Number of math inlines"),
    _("Number of math displayed")
  };

  const gchar* terms_regex[] = {
    "Words in text: ([0-9]*)",
    "Words in headers: ([0-9]*)",
    "Words in float captions: ([0-9]*)",
    "Number of headers: ([0-9]*)",
    "Number of floats: ([0-9]*)",
    "Number of math inlines: ([0-9]*)",
    "Number of math displayed: ([0-9]*)"
  };


  /* TODO: move to non gui class (latex perhaps) */
  if (external_exists("texcount")) {
    /* Copy workfile to /tmp to remove any spaces in filename to avoid
     * segfaults */
    gchar* tmpfile = g_strdup_printf("%s.state", g_active_editor->fdname);
    if (!utils_copy_file(g_active_editor->workfile, tmpfile, &err)) {
      slog(L_G_ERROR, "utils_copy_file (): %s\n", err->message);
      g_free(tmpfile);
      g_error_free(err);
      goto cleanup;
    }

    cmd = g_strdup_printf("texcount '%s'", tmpfile);
    Tuple2 result = utils_popen_r(cmd, NULL);

    for (i = 0; i < TEXCOUNT_OUTPUT_LINES; ++i)
      if (!(regexs[i] = g_regex_new(terms_regex[i], 0, 0, &err))) {
        slog(L_G_ERROR, "utils_copy_file (): %s\n", err->message);
        g_free(tmpfile);
        g_error_free(err);
        goto cleanup;
      }

    for (i = 0; i < TEXCOUNT_OUTPUT_LINES; ++i) {
      if (g_regex_match(regexs[i], result.second, 0, &match_info)) {
        matched = g_match_info_fetch_all(match_info);
        if (NULL == matched[1]) {
          slog(L_WARNING, "can't extract info: %s\n", terms[i]);
          res[i] = g_strdup("N/A");
        } else {
          res[i] = g_strdup(matched[1]);
        }
        g_strfreev(matched);
        g_match_info_free(match_info);
      }
    }
    g_free(result.second);
    g_free(tmpfile);
  } else {
    cmd = NULL;
    slog(L_G_ERROR, "The 'texcount' utility could not be found.\n");
    return;
  }

  gchararray items[6] = {"stats_words", "stats_head", "stats_float",
                         "stats_nrhead", "stats_nrfloat", "stats_nrmath"
                        };
  int j = 0;
  GtkLabel *tmp;

  for (j = 0; j < 6; j++) {
    gchar *value = items[j];
    tmp = GTK_LABEL(gtk_builder_get_object(gui->builder, value));
    gtk_label_set_text(tmp, res[j]);
  }


  gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gui->builder,
                               "stats_filename")), tabmanagergui_get_labeltext(g_active_tab->page));
  gtk_widget_show(gui->docstatswindow);
  return;

cleanup:
  for (i = 0; i < TEXCOUNT_OUTPUT_LINES; ++i) {
    g_regex_unref(regexs[i]);
    g_free(res[i]);
  }
  g_free(cmd);
  g_free(output);
}