Beispiel #1
0
int texlive_init (void) {
    int texversion = 0;

    if (external_exists (C_LATEX)) {
        texversion = external_version2 (EX_TEXLIVE);
        slog (L_INFO, "Texlive %d was found installed..\n", texversion);
    }

    if (external_exists (C_PDFLATEX)) {
        slog (L_INFO, "Typesetter detected: %s\n",
              external_version (C_PDFLATEX));
        pdf_detected = TRUE;
    }

    if (external_exists (C_XELATEX)) {
        slog (L_INFO, "Typesetter detected: %s\n",
              external_version (C_XELATEX));
        xel_detected = TRUE;
    }
    return texversion;
}
Beispiel #2
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;
}
Beispiel #3
0
int main (int argc, char *argv[]) {
    /* set up i18n */
    bindtextdomain (PACKAGE, LOCALEDIR);
    setlocale (LC_ALL, "");
    textdomain (PACKAGE);

    GError* error = NULL;
    GOptionContext* context = g_option_context_new ("files");
    g_option_context_add_main_entries (context, entries, PACKAGE);
    g_option_context_parse (context, &argc, &argv, &error);
    if (error) g_error("%s\n", error->message);

    /* initialize GTK */
    g_thread_init (NULL);
    gdk_threads_init ();
    gtk_init (&argc, &argv);
    GError* ui_error = NULL;
    GtkBuilder* builder = gtk_builder_new ();
    gchar* ui = g_build_filename (DATADIR, "ui", "gummi.glade", NULL);
    
    // exit program when gummi.glade can not be located:
    if (!g_file_test (ui, G_FILE_TEST_EXISTS)) {
        printf("Could not locate Glade interface file at:\n%s\n", ui);
        return 0;
    }
    
    gtk_builder_add_from_file (builder, ui, &ui_error);
    if (ui_error) {
        g_error ("%s\n", ui_error->message);
    }
    gtk_builder_set_translation_domain (builder, PACKAGE);
    g_free (ui);

    /* Initialize logging */
    slog_init (debug);
    slog (L_INFO, PACKAGE_NAME" version: "PACKAGE_VERSION"\n");

    /* Initialize configuration */
    gchar* configname = g_build_filename (g_get_user_config_dir (), "gummi",
                                  "gummi.cfg", NULL);
    config_init (configname);
    config_load ();
    g_free (configname);

    /* Initialize signals */
    gummi_signals_register ();

    /* Initialize Classes */
    gchar* snippetsname = g_build_filename (g_get_user_config_dir (), "gummi",
            "snippets.cfg", NULL);

    // why do we not load this from environment, like gui-main does? -A
    GuMotion* motion = motion_init ();
    GuIOFunc* io = iofunctions_init();
    GuLatex* latex = latex_init (); 
    GuBiblio* biblio = biblio_init (builder);
    GuTemplate* templ = template_init (builder);
    GuTabmanager* tabm = tabmanager_init ();
    GuProject* proj = project_init ();

    GuSnippets* snippets = snippets_init (snippetsname);
    gummi = gummi_init (motion, io, latex, biblio, templ, snippets, tabm, proj);
    slog (L_DEBUG, "Gummi created!\n");
    g_free (snippetsname);

    /* Initialize GUI */
    gui = gui_init (builder);
    
    slog_set_gui_parent (gui->mainwindow);
    slog (L_DEBUG, "GummiGui created!\n");

    /* Start compile thread */
    if (external_exists (config_get_value("typesetter"))) {
        typesetter_setup ();
        motion_start_compile_thread (motion);
    }
    else {
        infoscreengui_enable (gui->infoscreengui, "program_error");
        slog (L_ERROR, "Could not locate the typesetter program\n");
    }

    /* Install acceleration group to mainwindow */
    gtk_window_add_accel_group (gui->mainwindow, snippets->accel_group);

    if (argc != 2)
        tabmanager_create_tab (A_DEFAULT, NULL, NULL);
    else {
        if (!g_file_test(argv[1], G_FILE_TEST_EXISTS)) {
            slog(L_ERROR, "Failed to open file '%s': No such file or "
                    "directory\n", argv[1]);
            exit(1);
        }
        tabmanager_create_tab (A_LOAD, argv[1], NULL);
    }
        
    if (config_get_value ("autosaving")) iofunctions_start_autosave ();

    gui_main (builder);
    config_save ();
    config_clean_up ();
    return 0;
}
Beispiel #4
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);
}