Exemple #1
0
void git_upgrade ()
// Upgrades the git system.
{
  // Go through the projects that have their git repository enabled.
  extern Settings * settings;
  vector <ustring> projects = projects_get_all ();
  for (unsigned int i = 0; i < projects.size(); i++) {
    ProjectConfiguration * projectconfig = settings->projectconfig (projects[i]);
    ustring git_directory = gw_build_filename (project_data_directory_project (projects[i]), ".git");
    if (projectconfig->git_use_remote_repository_get()) {
      // At times there's a stale index.lock file that prevents any collaboration.
      // This is to be removed.
      ustring index_lock = gw_build_filename (git_directory, "index.lock");
      if (g_file_test (index_lock.c_str(), G_FILE_TEST_IS_REGULAR)) {
        gw_message (_("Cleaning out index lock ") + index_lock);
        unix_unlink (index_lock.c_str());
      }
      // Get the data directory for the project
      ustring datadirectory = tiny_project_data_directory_project(projects[i]);
      // On most machines git can determine the user's name from the system services. 
      // On the XO machine, it can't. It is set here manually. 
      // On more recent versions of git, like version 1.8.3 and younger,
      // although git may determine the user's name from the system, 
      // it still requires it to be set manually.
      ustring command;
      command = "git config user.email \"";
      command.append(g_get_user_name());
      command.append("@");
      command.append(g_get_host_name());
      command.append("\"");
      maintenance_register_shell_command (datadirectory, command);
      command = "git config user.name \"";
      command.append(g_get_real_name());
      command.append("\"");
      maintenance_register_shell_command (datadirectory, command);
      // (Re)initialize the repository. This can be done repeatedly without harm.
      // Note that this is done on shutdown.
      maintenance_register_shell_command (datadirectory, "git init");
    } else {
      if (g_file_test (git_directory.c_str(), G_FILE_TEST_IS_DIR)) {
        gw_message (_("Cleaning out folder ") + git_directory);
        ProgressWindow progresswindow (_("Tidying up project ") + projects[i], false);
        progresswindow.set_fraction (0.5);
        unix_rmdir (git_directory);
      }
    }
  }
}
void stylesheets_upgrade()
// Upgrade older stylesheets to the currently used format.
{
  // Make the \r marker a section heading instead of a normal paragraph.
  {
    ReadFiles rf(Directories->get_stylesheets(), "", ".xml1");
    for (unsigned int i = 0; i < rf.files.size(); i++) {
      ustring filename = gw_build_filename(Directories->get_stylesheets(), rf.files[i]);
      gw_message(_("Updating stylesheet: ") + filename);
      ReadText rt (filename, true, false);
      stylesheet_upgrade_value (rt.lines, "r", "subtype", "2");
      unix_unlink (filename.c_str());
      ustring newfilename(filename);
      newfilename.replace(newfilename.length() - 1, 1, "2");
      write_lines (newfilename, rt.lines);
    }
  }

  // Note: The stylesheet.xml template has been updated thus far.
  // Every update listed below still needs to be entered into the template.

  // At the end of everything, check that we have at least one stylesheet.  
  {
    vector < ustring > stylesheets;
    stylesheet_get_ones_available(stylesheets);
    if (stylesheets.size() == 0) {
      stylesheet_create_new(STANDARDSHEET, stFull);
    }
  }
}
bool RemoteRepositoryAssistant::check_git_version ()
// Checks the git version.
{
  bool okay = false;
  GwSpawn spawn("git");
  spawn.arg("--version");
  spawn.read();
  spawn.run();
  ustring versiontext;
  if (!spawn.standardout.empty())
    versiontext = spawn.standardout[0];
  gw_message (versiontext);
  Parse parse1(versiontext, false);
  if (parse1.words.size() >= 3) {
    Parse parse2(parse1.words[2], false, ".");
    if (parse2.words.size() >= 3) {
      unsigned int version = 100 * convert_to_int(parse2.words[0]) + 10 * convert_to_int(parse2.words[1]) + convert_to_int(parse2.words[2]);
      if (version >= 150)
        okay = true;
    }
  }
  if (!okay) {
    versiontext.append(_(", but should be 1.5.0 or higher"));
    gtk_label_set_text(GTK_LABEL(label_try_git), versiontext.c_str());
  }
  if (!spawn.result) {
    gtk_label_set_text(GTK_LABEL(label_try_git), _("Program git failed to run. Has git been installed?"));
  }
  return okay;
}
int main(int argc, char *argv[])
{
  // g_type_init has been deprecated since version 2.36.
  // The type system is now initialised automatically.
  // g_type_init();

  // Settings object. 
  Settings mysettings(true);
  settings = &mysettings;

  // Create a new directories 'factory' and initialize it with argv[0]
  Directories = new directories(argv[0]);
  books_init(); // TEMP - MAP
  Directories->init(); // important step

  // Bibledit can read from or write to Bible data.
  // Syntax: bibledit-rdwrt -r|-w ...
  bool readdata = false;
  bool writedata = false;
  if (argc > 2) {
    readdata = (strcmp(argv[1], "-r") == 0);
    writedata = (strcmp(argv[1], "-w") == 0);
  }
  if (readdata ^ writedata) {
    // Do the reading or the writing.
    read_write_data (argc, argv, readdata, writedata);
  } else {
    // Nothing to do.
    gw_message (_("Nothing was done"));
  }

  // Quit.
  return 0;
}
Exemple #5
0
void WindowsOutpost::log(const ustring & message)
// Logs messages. 
// It does not output the same message repeatedly.
{
  if (message != last_message) {
    gw_message("Windows Outpost: " + message);
    last_message = message;
  }
}
Exemple #6
0
bool uncompress(const ustring & archive, const ustring & directory)
// Uncompresses "archive" into "directory".
// Returns whether this was successful.
{
  // Bail out if the archive was not recognized.
  if (!compressed_archive_recognized(archive)) {
    gw_critical(_("cannot uncompress unrecognized archive"));
    return false;
  }
  // Ensure that the output directory is there.
  gw_mkdir_with_parents (directory);

  // Get the uncompression identifier.
  int uncompression_identifier = uncompression_identifier_get (archive);

  // Do the uncompression.
  int result = -1;
  switch (uncompression_identifier) {
  case 0:
    {
		gw_message("I'm not yet smart enough to handle the " + archive + " file type");
		break;
    }
  case 1:
    { // If you have a zip utility installed in Windows, etc.
      GwSpawn spawn (Directories->get_unzip());
      spawn.arg ("-o"); // overwrite without prompting
      if (!directory.empty ()) {
        spawn.arg ("-d"); // extract files into exdir
        spawn.arg (directory);
      }
      spawn.arg (archive);
      spawn.progress (_("Unpacking"), false);
      spawn.run ();
      result = 0;
      break;
    }
  case 2:
    {
      GwSpawn spawn(Directories->get_tar());
	  spawn.arg ("--force-local"); // to permit : in filename (like C:\Users\...)
      spawn.arg("-xvzf"); // x=eXtract, z=gunZip, f=Filename to extract
      if (!directory.empty()) {
        spawn.workingdirectory(directory);
      }
      spawn.arg(archive);
      spawn.progress(_("Unpacking"), false);
      spawn.run();
      result = spawn.exitstatus;
	  DEBUG("tar return code="+std::to_string(result));
      break;
    }
  }

  // Return whether things were ok.  
  return (result == 0);
}
void notes_handle_vcs_feedback (const ustring& directory, const ustring& feedback)
// This handles the feedback that comes from the version control system.
{
    if (directory == notes_shared_storage_folder ()) {

        unsigned int note_id = 0;

        // The following feedback indicates that somebody created a new note:
        // create mode 100644 27185458
        if (feedback.find ("create mode") != string::npos) {
            ustring s (feedback);
            s.erase (12);
            Parse parse (s);
            if (parse.words.size () == 2) {
                note_id = convert_to_int (parse.words[1]);
            }
        }

        // The following feedback indicates that somebody modified a note:
        // #	modified:   27185458
        if (feedback.find ("modified:") != string::npos) {
            ustring s (feedback);
            s.erase (12);
            note_id = convert_to_int (number_in_string (feedback));
        }

        // The following feedback indicates that somebody deleted a note:
        // #	deleted:    46473236
        if (feedback.find ("deleted:") != string::npos) {
            ustring s (feedback);
            s.erase (11);
            note_id = convert_to_int (number_in_string (feedback));
        }

        // See the following:
        // 95935882 |    9 +++++++++
        // It means that this note was edited.
        if (feedback.find (" |  ") != string::npos) {
            note_id = convert_to_int (number_in_string (feedback));
        }

        if (note_id != 0) {
            gw_message (_("Change detected for note ") + convert_to_string (note_id));
            // Update the index.
            sqlite3 *db;
            sqlite3_open(notes_index_filename ().c_str(), &db);
            sqlite3_busy_timeout(db, 1000);
            notes_store_index_entry (db, note_id);
            sqlite3_close(db);
        }
    }
}
Exemple #8
0
ustring XeTeX::run ()
{
  write_document_tex_file ();
  ustring pdf_file;
  if (runtime_check (rtXeTeX)) {
    pdf_file = gw_build_filename (working_directory, "document.pdf");
    bool re_run = false;
    unsigned int run_count = 0;
    do {
      run_count++;
      GwSpawn spawn (runtime_program (rtXeTeX));
      spawn.workingdirectory (working_directory);
      spawn.arg ("document.tex");
      spawn.read ();
      spawn.progress ("Formatting run " + convert_to_string (run_count), true);
      spawn.run ();
      re_run = false;
      for (unsigned int i = 0; i < spawn.standardout.size(); i++) {
        gw_message (spawn.standardout[i]);
        if (spawn.standardout[i].find ("re-run") != string::npos) 
        re_run = true;
      }
      for (unsigned int i = 0; i < spawn.standarderr.size(); i++) {
        gw_critical (spawn.standarderr[i]);
        if (spawn.standarderr[i].find ("re-run") != string::npos) 
          re_run = true;
      }
      // If the formatting process was cancelled, bail out, with no pdf file.
      if (spawn.cancelled) {
        return "";
      }
    } while (re_run && (run_count < 10));
  }
  // Info for user in logfile.
  gw_message (_("All the data for this document is available in temporal folder ") + working_directory + ".");
  gw_message (_("You can tune the files by hand, then run \"xetex document.tex\" in this folder to convert it into a PDF file."));
  return pdf_file;
}
Exemple #9
0
void GwSpawn::describe ()
// Describes the command if it would run from a shell.
{
  ustring description;
  if (!myworkingdirectory.empty()) {
    description.append ("cd ");
    description.append (myworkingdirectory);
    description.append ("; ");
  }
  description.append (myprogram);
  
  for (unsigned int i = 0; i < myarguments.size(); i++) {
    description.append (" ");
    description.append (myarguments[i]);
  }
  gw_message ("Shell command: " + description);
}
void view_parallel_references_pdf(ProjectMemory & main_project, vector < ustring > *extra_projects, vector < Reference > references, bool keep_verses_together_within_page, vector < ustring > *remarks, bool highlight)
/*
 Formats the references in "references", and highlights all words in
 "session->highlights*" and shows them in a pdf viewer.
 There is a pointer to a list of "remarks". Any remarks will be printed first.
 */
{
  // Log.
  gw_message(_("Printing parallel references"));

  // Progress system.
  ProgressWindow progresswindow(_("Printing Parallel References"), false);
  progresswindow.set_iterate(0, 1, references.size());

  // Configuration
  extern Settings *settings;
  ProjectConfiguration *projectconfig = settings->projectconfig(main_project.name);
  ustring stylesheet = stylesheet_get_actual ();

  // Store the additional projects to print.
  vector < ustring > additional_projects;
  if (extra_projects)
    additional_projects = *extra_projects;
  settings->session.additional_printing_projects = additional_projects;

  // Prepare for mapping.
  Mapping mapping(projectconfig->versification_get(), 0);

  // The converter.
  Text2Pdf text2pdf(gw_build_filename(Directories->get_temp(), "document.pdf"), settings->genconfig.print_engine_use_intermediate_text_get());

  // Page.
  text2pdf.page_size_set(settings->genconfig.paper_width_get(), settings->genconfig.paper_height_get());
  text2pdf.page_margins_set(settings->genconfig.paper_inside_margin_get(), settings->genconfig.paper_outside_margin_get(), settings->genconfig.paper_top_margin_get(), settings->genconfig.paper_bottom_margin_get());
  text2pdf.page_one_column_only();

  // Headers.
  if (settings->genconfig.printdate_get()) {
    text2pdf.print_date_in_header();
  }
  // Font, etc., of main project.
  ustring main_font = projectconfig->editor_font_name_get();
  unsigned int main_line_spacing = projectconfig->text_line_height_get();
  if (projectconfig->editor_font_default_get()) {
    main_font.clear();
    main_line_spacing = 100;
  }
  text2pdf.set_font(main_font);
  text2pdf.set_line_spacing(main_line_spacing);
  bool main_right_to_left = projectconfig->right_to_left_get();
  text2pdf.set_right_to_left(main_right_to_left);

  // Start off with inserting any remarks.
  if (remarks) {
    for (unsigned int r = 0; r < remarks->size(); r++) {
      text2pdf.open_paragraph();
      text2pdf.paragraph_set_column_count(1);
      text2pdf.add_text(remarks->at(r));
      text2pdf.close_paragraph();
    }
  }
  // Some variables to avoid excessive session access during highlighting.
  vector < bool > highlight_casesensitives;
  vector < ustring > highlight_words;
  if (highlight) {
    for (unsigned int hl = 0; hl < settings->session.highlights.size(); hl++) {
      highlight_casesensitives.push_back(settings->session.highlights[hl].casesensitive);
      highlight_words.push_back(settings->session.highlights[hl].word);
    }
  }
  // All the projects to be put in this parallel Bible, together with
  // their related information, like mapping, fonts.
  vector < ustring > project_names;
  vector < ProjectMemory > project_memories;
  vector < Mapping > mapping_s;
  vector < ustring > fonts;
  vector < unsigned int >line_spacings;
  vector < bool > right_to_lefts;
  if (extra_projects) {
    vector < ustring > project_s_raw = *extra_projects;
    for (unsigned int i = 0; i < project_s_raw.size(); i++) {
      ProjectMemory projectmemory(project_s_raw[i], true);
      project_memories.push_back(projectmemory);
      ProjectConfiguration *projectconfig = settings->projectconfig(project_s_raw[i]);
      project_names.push_back(project_s_raw[i]);
      Mapping mapping(projectconfig->versification_get(), 0);
      mapping_s.push_back(mapping);
      ustring font = projectconfig->editor_font_name_get();
      unsigned int line_spacing = projectconfig->text_line_height_get();
      if (projectconfig->editor_font_default_get()) {
        font.clear();
        line_spacing = 100;
      }
      fonts.push_back(font);
      line_spacings.push_back(line_spacing);
      right_to_lefts.push_back(projectconfig->right_to_left_get());
    }
  }
  // Produce chunks for all references.
  for (unsigned int rf = 0; rf < references.size(); rf++) {

    // Update progress bar.
    progresswindow.iterate();

    // Whether to keep things on one page.    
    if (keep_verses_together_within_page) {
      text2pdf.open_keep_together();
    }
    // Set main font, etc.
    text2pdf.set_font(main_font);
    text2pdf.set_line_spacing(main_line_spacing);
    text2pdf.set_right_to_left(main_right_to_left);

    // Add the reference to the text.
    text2pdf.add_text(references[rf].human_readable(""));

    // Map this verse to the original, that is, to Hebrew or Greek.
    vector <int> hebrew_greek_chapters;
    vector <int> hebrew_greek_verses;
    mapping.book_change(references[rf].book);
    mapping.me_to_original(references[rf].chapter, references[rf].verse, hebrew_greek_chapters, hebrew_greek_verses);
    // Get verse text for each version.
    for (unsigned int vsn = 0; vsn <= project_names.size(); vsn++) {

      // Add the font, etc., for each project.
      ustring font(main_font);
      unsigned int line_spacing = main_line_spacing;
      bool right_to_left = main_right_to_left;
      if (vsn > 0) {
        font = fonts[vsn - 1];
        line_spacing = line_spacings[vsn - 1];
        right_to_left = right_to_lefts[vsn - 1];
      }
      text2pdf.set_font(font);
      text2pdf.set_line_spacing(line_spacing);
      text2pdf.set_right_to_left(right_to_left);

      // Get the verse text.
      ustring line;
      if (vsn == 0) {
        // First version.
        ProjectBook *projectbook = main_project.get_book_pointer(references[rf].book);
        if (projectbook) {
          ProjectChapter *projectchapter = projectbook->get_chapter_pointer(references[rf].chapter);
          if (projectchapter) {
            ProjectVerse *projectverse = projectchapter->get_verse_pointer(references[rf].verse);
            if (projectverse) {
              line = projectverse->data;
            }
          }
        }
      } else {
        // Other versions. 
        // Get mapped chapters / verses.
        line.clear();
        vector <int> mychapters;
        vector <int> myverses;
        mapping_s[vsn - 1].book_change(references[rf].book);
        mapping_s[vsn - 1].original_to_me(hebrew_greek_chapters, hebrew_greek_verses, mychapters, myverses);
        // Get text of any of the mapped verses.
        for (unsigned int mp = 0; mp < mychapters.size(); mp++) {
          // Get the verse and add it to the usfm code.
          ProjectBook *projectbook = project_memories[vsn - 1].get_book_pointer(references[rf].book);
          if (projectbook) {
            ProjectChapter *projectchapter = projectbook->get_chapter_pointer(mychapters[mp]);
            if (projectchapter) {
              ProjectVerse *projectverse = projectchapter->get_verse_pointer(convert_to_string(myverses[mp]));
              if (projectverse) {
                if (!line.empty()) 
                  line.append (" ");
                line.append (projectverse->data);
              }
            }
          }
        }
      }

      // Add the project name if there are more than one.
      if (!project_names.empty()) {
        ustring project;
        if (vsn == 0)
          project = main_project.name;
        else
          project = project_names[vsn - 1];
        text2pdf.open_paragraph();
        text2pdf.inline_set_font_size_percentage(65);
        text2pdf.add_text(project);
        text2pdf.inline_clear_font_size_percentage();
        text2pdf.add_text(" ");
      } else {
        text2pdf.open_paragraph();
      }

      // Do text replacement.
      text_replacement(line);

      // Positions in the line, and lengths to highlight.
      vector < size_t > highlight_positions;
      vector < size_t > highlight_lengths;

      // Go through all the words to highlight.
      for (unsigned int i2 = 0; i2 < highlight_casesensitives.size(); i2++) {
        // Word to highlight
        ustring highlightword;
        if (highlight_casesensitives[i2])
          highlightword = highlight_words[i2];
        else
          highlightword = highlight_words[i2].casefold();
        // Variabele s holds a shadow string.
        ustring s;
        if (highlight_casesensitives[i2])
          s = line;
        else
          s = line.casefold();
        // Find positions for highlighting.
        size_t offposition = s.find(highlightword);
        while (offposition != string::npos) {
          // Store position and length.
          highlight_positions.push_back(offposition);
          highlight_lengths.push_back(highlightword.length());
          // Look for possible next word to highlight.
          offposition = offposition + highlightword.length() + 1;
          // There is something like a bug in s.find. If the offposition
          // is greater than the length of s, then s.find will return
          // a value below offposition, instead of string::npos as is
          // expected. Workaround.
          if (offposition > s.length())
            break;
          offposition = s.find(highlightword, offposition);
        }
      }
      // Sort the positions from small to bigger.
      xml_sort_positions(highlight_positions, highlight_lengths);
      // Combine overlapping positions.
      xml_combine_overlaps(highlight_positions, highlight_lengths);

      // Insert the code for highlighting.
      for (int i = highlight_positions.size () - 1; i >= 0; i--) {
        for (int i2 = highlight_lengths.size() - 1; i2 >= 0; i2--) {
          line.insert (highlight_positions[i] + i2, INSERTION_FLAG);
        }
      }

      // Add usfm converter to the layout engine, and set various things.
      Usfm2Text usfm2text(&text2pdf, false);
      usfm2text.add_styles(usfm2xslfo_read_stylesheet(stylesheet));

      usfm2text.no_bold();
      usfm2text.no_space_before_or_after();
      usfm2text.no_new_page();
      usfm2text.add_usfm_code(line);
      usfm2text.process();
    }

    // Add a bit of space.
    text2pdf.close_paragraph();
    text2pdf.add_text(" ");
    text2pdf.close_paragraph();

    // Whether to close code keeping things on one page.    
    if (keep_verses_together_within_page) {
      text2pdf.close_keep_together();
    }
  }

  // Hide progeressbar.
  progresswindow.hide();

  // Process the data.
  text2pdf.run();

  // Display the pdf file.
  text2pdf.view();

  // Log: ready.
  gw_message(_("Ready printing the parallel references"));
}
Exemple #11
0
void git_resolve_conflict_chapter(const ustring & project, unsigned int book, unsigned int chapter)
// This solves a conflicting chapter.
{
  // Log message
  gw_message(_("Resolving conflict for project ") + project + _(" book ") + books_id_to_english(book) + " " + convert_to_string(chapter));

  // Directory of the chapter in the data.
  ustring directory = project_data_directory_chapter(project, book, chapter);

  // Data filename.
  ustring datafile = project_data_filename_chapter(project, book, chapter, false);

  /* Read the datafile. If there is a conflict it will look like the example below:

     \c 1
     <<<<<<< HEAD:3 John/1/data
     \v 1 my text.
     =======
     \v 1 server's text.
     >>>>>>> a62f843ce41ed2d0325c8a2767993df6acdbc933:3 John/1/data
     \v 2

   */
  ReadText rt(datafile, true);

  // Set about to resolve the conflict.
  vector < ustring > newdata;
  bool withinmine = false;
  bool withinserver = false;
  for (unsigned int i = 0; i < rt.lines.size(); i++) {
    // Find out when we've a marker, no actual data.    
    bool minemarker = rt.lines[i].find(git_mine_conflict_marker()) != string::npos;
    bool separatormarker = rt.lines[i] == "=======";
    bool servermarker = rt.lines[i].find(">>>>>>> ") == 0;
    // Do conflict management only if we've actual data.
    bool takeit = false;
    if (!minemarker && !separatormarker && !servermarker) {
      if (withinmine) {
      } else if (withinserver) {
        takeit = true;
      } else {
        takeit = true;
      }
    }
    if (takeit) {
      newdata.push_back(rt.lines[i]);
    } else {
    }
    // Set whether we're within a conflict, my data, or the server's data.
    // This setting applies to the next line of data.
    if (minemarker) {
      withinmine = true;
      withinserver = false;
    }
    if (separatormarker) {
      withinmine = false;
      withinserver = true;
    }
    if (servermarker) {
      withinmine = false;
      withinserver = false;
    }
  }
  write_lines(datafile, newdata);
  // Next time that a timed pull and push is done, the conflict will show up as resolved.
}
void view_parallel_bible_pdf()
{
  // Log.
  gw_message(_("Printing Parallel Bible"));

  // Configuration
  extern Settings *settings;

  // Get the chapters and check them.
  vector < unsigned int >chapters = project_get_chapters(settings->genconfig.project_get(), settings->genconfig.book_get());
  if (chapters.empty()) {
    gtkw_dialog_info(NULL, books_id_to_english(settings->genconfig.book_get()) + _("does not exist in this project"));
    return;
  }
  // Progress system.
  ProgressWindow progresswindow(_("Parallel Bible"), true);
  progresswindow.set_text(_("Collecting verses"));
  progresswindow.set_iterate(0, 1, chapters.size());

  // Messages to be printed first.
  vector < ustring > messages;

  // All the projects to be put in this parallel Bible.
  // If the book exists in the project, add it, else give message.
  vector <ustring> project_s_raw;
  {
    vector <ustring> bibles = settings->genconfig.parallel_bible_projects_get();
    vector <bool> enabled = settings->genconfig.parallel_bible_enabled_get();
    if (bibles.size () == enabled.size()) {
      for (unsigned int i = 0; i < enabled.size(); i++) {
        if (enabled[i]) {
          project_s_raw.push_back (bibles[i]);
        }
      }
    }
  }
  vector < ustring > project_names;
  for (unsigned int i = 0; i < project_s_raw.size(); i++) {
    if (project_book_exists(project_s_raw[i], settings->genconfig.book_get())) {
      project_names.push_back(project_s_raw[i]);
    } else {
      messages.push_back(_("Project ") + project_s_raw[i] + _(" was requested to be included, but it does not contain ") + books_id_to_english(settings->genconfig.book_get()) + _(". It was left out."));
    }
  }

  // References to print.
  vector < Reference > references;

  // Portion selection.
  WithinReferencesRange inrange;
  {
    vector < unsigned int >portions_chapter_from, portions_chapter_to;
    vector < ustring > portions_verse_from, portions_verse_to;
    select_portion_get_values(settings->genconfig.project_get(), settings->genconfig.book_get(), settings->genconfig.parallel_bible_chapters_verses_get(), portions_chapter_from, portions_verse_from, portions_chapter_to, portions_verse_to);
    inrange.add_portion(settings->genconfig.book_get(), portions_chapter_from, portions_verse_from, portions_chapter_to, portions_verse_to);
    inrange.set_book(settings->genconfig.book_get());
  }

  // Go through the chapters.
  for (unsigned int ch = 0; ch < chapters.size(); ch++) {

    progresswindow.iterate();

    inrange.set_chapter(chapters[ch]);

    // Go through the verse numbers in this chapter.
    vector < ustring > verses = project_get_verses(settings->genconfig.project_get(), settings->genconfig.book_get(), chapters[ch]);
    for (unsigned int vs = 0; vs < verses.size(); vs++) {

      inrange.set_verse(verses[vs]);
      if (!inrange.in_range())
        continue;

      // See whether to print verses zero.
      if (!settings->genconfig.parallel_bible_include_verse_zero_get())
        if (verses[vs] == "0")
          continue;

      // Store the reference.
      Reference reference(settings->genconfig.book_get(), chapters[ch], verses[vs]);
      references.push_back(reference);
    }
  }

  // Hide progeressbar.
  progresswindow.hide();

  // Do the printing.
  ProjectMemory projectmemory(settings->genconfig.project_get(), true);
  view_parallel_references_pdf(projectmemory, &project_names, references, settings->genconfig.parallel_bible_keep_verses_together_get(), &messages, false);

  // Log: ready.
  gw_message(_("Ready printing the Parallel Bible"));
}
Exemple #13
0
void directories::find_utilities(void)
{
  // Find some utilities that we need to use (cp, rm, tar, zip, etc.)

  //---------------------------------------------
  // Copy
  //---------------------------------------------
  {
  // Check for cp (Unix)
  GwSpawn spawn("cp");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a cp command. Use it.
	copy = "cp";
  }
  else {
	// Check for copy (Windows/DOS through cmd.exe)
	GwSpawn spawn("copy");
    spawn.arg("/?");
	if (spawn.exitstatus == 0) { copy = "copy"; }
	else {
		// Check for cp.exe in the rundir (Windows directly through msys2/mingw binary)
		GwSpawn spawn(rundir + "\\cp.exe");
		spawn.arg("--version");
		if (spawn.exitstatus == 0) { copy = rundir + "\\cp.exe"; }
		else { gw_message("Cannot find a suitable copy utility"); }
	}
  }
  }
  
  //---------------------------------------------
  // Copy recursive
  //---------------------------------------------
  {
  // Check for cp (Unix)
  GwSpawn spawn("cp");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a cp command. Use it.
	copy_recursive = "cp";
	copy_recursive_args = "-r";
  }
  else {
	// Check for copy (Windows/DOS through cmd.exe)
	GwSpawn spawn("xcopy");
    spawn.arg("/?");
	if (spawn.exitstatus == 0) { copy_recursive = "xcopy"; copy_recursive_args = "/E/I/Y"; }
	else {
		// Check for cp.exe in the rundir (Windows directly through msys2/mingw binary)
		GwSpawn spawn(rundir + "\\cp.exe");
		spawn.arg("--version");
		if (spawn.exitstatus == 0) { copy_recursive = rundir + "\\cp.exe"; copy_recursive_args = "-r"; }
		else { gw_message("Cannot find a suitable recursive copy utility"); }
	}
  }
  }
  
  //---------------------------------------------
  // Move
  //---------------------------------------------
  {
  // Check for mv (Unix)
  GwSpawn spawn("mv");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a mv command. Use it.
	move = "mv";
	move_args = "-f";
  }
  else {
	// Check for move (Windows/DOS through cmd.exe)
	GwSpawn spawn("move");
    spawn.arg("/?");
	if (spawn.exitstatus == 0) { move = "move"; move_args = "/Y"; }
	else {
		// Check for mv.exe in the rundir (Windows directly through msys2/mingw binary)
		GwSpawn spawn(rundir + "\\mv.exe");
		spawn.arg("--version");
		if (spawn.exitstatus == 0) { move = rundir + "\\mv.exe"; move_args = "-f"; }
		else { gw_message(_("Cannot find a suitable move utility")); }
	}
  }
  }
  
  //---------------------------------------------
  // Zip
  //---------------------------------------------
  {
  // Check for gzip (Unix)
  GwSpawn spawn("gzip");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a gzip command. Use it.
	zip = "gzip";
  }
  else {
	// Check for gzip.exe in the rundir (Windows directly through msys2/mingw binary)
	GwSpawn spawn(rundir + "\\gzip.exe");
	spawn.arg("--version");
	if (spawn.exitstatus == 0) { zip = rundir + "\\gzip.exe"; }
	else { gw_message(_("Cannot find a suitable zip utility")); }
  }
  }
  
  //---------------------------------------------
  // Tar
  //---------------------------------------------
  {
  // Check for tar (Unix)
  GwSpawn spawn("tar");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a tar command. Use it.
	tar = "tar";
  }
  else {
	// Check for tar.exe in the rundir (Windows directly through msys2/mingw binary)
	GwSpawn spawn(rundir + "\\tar.exe");
    spawn.arg("--version");
	if (spawn.exitstatus == 0) { tar = rundir + "\\tar.exe"; }
	else { gw_message(_("Cannot find a suitable tar utility")); }
  }
  }
  
  //---------------------------------------------
  // Rm
  //---------------------------------------------
  {
  // Check for rm (Unix)
  GwSpawn spawn("rm");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a rm command. Use it.
	rm = "rm";
  }
  else {
	// Check for del (Windows/DOS through cmd.exe)
	GwSpawn spawn("del");
    spawn.arg("/?");
	if (spawn.exitstatus == 0) { rm = "del"; }
	else {
		// Check for rm.exe in the rundir (Windows directly through msys2/mingw binary)
		GwSpawn spawn(rundir + "\\rm.exe");
		spawn.arg("--version");
		if (spawn.exitstatus == 0) { rm = rundir + "\\rm.exe"; }
		else { gw_message(_("Cannot find a suitable rm/del utility")); }
	}
  }
  }
  
  //---------------------------------------------
  // Rmdir
  //---------------------------------------------
  {
  // Check for rm (Unix)
  GwSpawn spawn("rm");
  spawn.arg("--version");
  spawn.run();
  if (spawn.exitstatus == 0) { 
	// We have a rm command. Use it.
	rmdir = "rm";
	rmdir_args = "-rf";
  }
  else {
	// Check for rmdir (Windows/DOS through cmd.exe)
	GwSpawn spawn("rmdir");
    spawn.arg("/?");
	if (spawn.exitstatus == 0) { rmdir = "rmdir"; rmdir_args = "/s/q"; }
	else {
		// Check for rm.exe in the rundir (Windows directly through msys2/mingw binary)
		GwSpawn spawn(rundir + "\\rm.exe");
		spawn.arg("--version");
		if (spawn.exitstatus == 0) { rmdir = rundir + "\\rm.exe"; rmdir_args = "-rf"; }
		// We have rmdir.exe, but it only works if the directories are empty
		else { gw_message(_("Cannot find a suitable rmdir utility")); }
	}
  }
  }
  
  //---------------------------------------------
  // mkdir
  //---------------------------------------------
  {
#ifdef WIN32
    // mkdir (md) does not play nice. If you run it with /?, it returns code 1, not 0. So
	// I rely on the #ifdef to just "know" that we have compiled on Windows and can assume
	// that mkdir is available.
    mkdir = "mkdir"; // no mkdir_args
#else
	// Check for mkdir (Unix)
	GwSpawn spawn("mkdir");
	spawn.arg("--help");  // TODO: Something is messed up here. It creates Bibledit-x.y.z\--help as a directory!!!
	spawn.run();
	if (spawn.exitstatus == 0) { 
		// We have a mkdir command. Use it.
		mkdir = "mkdir"; mkdir_args = "-p";
	}
	else {
		// Check for mkdir.exe in the rundir (Windows directly through msys2/mingw binary)
		GwSpawn spawn(rundir + "\\mkdir.exe");
		spawn.arg("--help");
		if (spawn.exitstatus == 0) { mkdir = rundir + "\\mkdir.exe"; mkdir_args = "-p"; }
		else { gw_message(_("Cannot find a suitable mkdir utility")); }
	}
	}
#endif
}
Exemple #14
0
Stylesheet::Stylesheet(const ustring & name_in)
{
  gw_message("Creating Stylesheet called '" + name_in + "'");
  
  // Save the sheet's name.
  name = name_in;

  // If the name is empty, read from the template.
  ustring filename = stylesheet_xml_filename(name);
  if (name.empty())
    filename = stylesheet_xml_template_filename();

  // Read the xml data, bail out on failure.
  gchar *contents;
  g_file_get_contents(filename.c_str(), &contents, NULL, NULL);
  if (contents == NULL) {
    gw_critical(_("Failure reading stylesheet ") + filename);
		return;
  }

  // Parse the stylesheet.  
  xmlParserInputBufferPtr inputbuffer;
  inputbuffer = xmlParserInputBufferCreateMem(contents, strlen(contents), XML_CHAR_ENCODING_NONE);
  ustring value;
  xmlTextReaderPtr reader = xmlNewTextReader(inputbuffer, NULL);
  if (reader) {
    StyleV2 * style = NULL;
    while ((xmlTextReaderRead(reader) == 1)) {
      switch (xmlTextReaderNodeType(reader)) {
      case XML_READER_TYPE_ELEMENT:
	{
	  xmlChar *element_name = xmlTextReaderName(reader);
	  if (!xmlStrcmp(element_name, BAD_CAST "style")) {
	    char *attribute = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "marker");
	    if (attribute) {
	      style = new StyleV2 (0);
	      style->marker = attribute;
	      free(attribute);
	    }
	  }
	  free(element_name); element_name = NULL;
	  break;
	}
      case XML_READER_TYPE_TEXT:
	{
	  xmlChar *text = xmlTextReaderValue(reader);
	  if (text) {
	    value = (gchar *) text;
	    xmlFree(text);
	  }	
	  break;
	}
      case XML_READER_TYPE_END_ELEMENT:
	{
	  xmlChar *element_name = xmlTextReaderName(reader);
	  if (style) {
	    if (!xmlStrcmp(element_name, BAD_CAST "marker"))
	      style->marker = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "name"))
	      style->name = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "info"))
	      style->info = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "type"))
	      style->type = (StyleType) convert_to_int(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "subtype"))
	      style->subtype = convert_to_int(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "fontsize"))
	      style->fontsize = convert_to_double(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "italic"))
	      style->italic = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "bold"))
	      style->bold = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "underline"))
	      style->underline = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "smallcaps"))
	      style->smallcaps = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "superscript"))
	      style->superscript = convert_to_bool(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "justification"))
	      style->justification = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "spacebefore"))
	      style->spacebefore = convert_to_double(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "spaceafter"))
	      style->spaceafter = convert_to_double(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "leftmargin"))
	      style->leftmargin = convert_to_double(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "rightmargin"))
	      style->rightmargin = convert_to_double(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "firstlineindent"))
	      style->firstlineindent = convert_to_double(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "spancolumns"))
	      style->spancolumns = convert_to_bool(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "color"))
	      style->color = convert_to_int(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "print"))
	      style->print = convert_to_bool(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userbool1"))
	      style->userbool1 = convert_to_bool(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userbool2"))
	      style->userbool2 = convert_to_bool(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userbool3"))
	      style->userbool3 = convert_to_bool(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userint1"))
	      style->userint1 = convert_to_int(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userint2"))
	      style->userint2 = convert_to_int(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userint3"))
	      style->userint3 = convert_to_int(value);
	    if (!xmlStrcmp(element_name, BAD_CAST "userstring1"))
	      style->userstring1 = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "userstring2"))
	      style->userstring2 = value;
	    if (!xmlStrcmp(element_name, BAD_CAST "userstring3"))
	      style->userstring3 = value;
	  }
	  value.clear();
	  if (!xmlStrcmp(element_name, BAD_CAST "style")) {
	    if (style) {
	      insert (style);
	      style = NULL;
	    }
	  }
	  free(element_name); element_name = NULL;
	  break;
	}
      }
    }
  }

  // Free memory.
	if (reader)
		xmlFreeTextReader(reader);
	if (inputbuffer)
		xmlFreeParserInputBuffer(inputbuffer);
	if (contents)
		g_free(contents);
}
Exemple #15
0
void gw_debug(int msgno, const ustring & message, const char *file, int lineno, const char *func)
{
  gint64 milliseconds = (g_get_monotonic_time() / 1000);
  gw_message("DEBUG:"+std::to_string(msgno)+":"+std::to_string(milliseconds)+"ms: " + message + " " + func + ":" + file + ":" + std::to_string(lineno));
  //fsync(1); // flush data to disk
}
Exemple #16
0
void gw_warning(const ustring & warning)
{
  gw_message("WARNING:  " + warning);
  g_warning("%s", warning.c_str());
}
bool RemoteRepositoryAssistant::try_git ()
// Tries git and returns true if everything's fine.
{
  // Progress.
  ProgressWindow progresswindow (_("Trying the contents tracker"), false);
  
  // Whether git is okay.
  bool okay = true;
  
  if (okay) {
    progresswindow.set_fraction (0.05);
    gw_message (_("Check git version number"));
    okay = check_git_version ();
  }
  
  // Clean the directory to work in.
  {
    ustring directory = git_testing_directory ("");
    unix_rmdir (directory);
    gw_mkdir_with_parents (directory);
  }
  
  if (okay) {
    progresswindow.set_fraction (0.11);
    gw_message (_("Create first local repository"));
    okay = try_git_create_repository ("local1", false);
  }

  if (okay) {
    progresswindow.set_fraction (0.17);
    gw_message (_("Store data into first local repository"));
    okay = try_git_store_data_in_repository ("local1", "--test--");
  }

  if (okay) {
    progresswindow.set_fraction (0.23);
    gw_message (_("Create remote repository"));
    okay = try_git_create_repository ("remote", true);
  }

  if (okay) {
    progresswindow.set_fraction (0.29);
    gw_message (_("Fetch data from the first local repository into the remote one"));
    okay = try_git_fetch_repository ("remote", "local1");
  }

  if (okay) {
    progresswindow.set_fraction (0.35);
    gw_message (_("Checkout the first local repository"));
    okay = try_git_checkout_repository ("local1", "remote");
  }

  if (okay) {
    progresswindow.set_fraction (0.41);
    gw_message (_("Check data of first local repository"));
    okay = try_git_check_data_in_repository ("local1", "--test--");
  }

  if (okay) {
    progresswindow.set_fraction (0.47);
    gw_message (_("Checkout the second local repository"));
    okay = try_git_checkout_repository ("local2", "remote");
  }

  if (okay) {
    progresswindow.set_fraction (0.52);
    gw_message (_("Check data of second local repository"));
    okay = try_git_check_data_in_repository ("local2", "--test--");
  }

  if (okay) {
    progresswindow.set_fraction (0.58);
    gw_message (_("Store different data into first repository"));
    okay = try_git_store_data_in_repository ("local1", "---test---");
  }

  if (okay) {
    progresswindow.set_fraction (0.64);
    gw_message (_("Push first repository"));
    okay = try_git_push_repository ("local1");
  }

  if (okay) {
    progresswindow.set_fraction (0.70);
    gw_message (_("Pull second repository"));
    okay = try_git_pull_repository ("local2");
  }

  if (okay) {
    progresswindow.set_fraction (0.76);
    gw_message ("Check data in second repository");
    okay = try_git_check_data_in_repository ("local2", "---test---");
  }

  if (okay) {
    progresswindow.set_fraction (0.82);
    gw_message (_("Store different data into second repository"));
    okay = try_git_store_data_in_repository ("local2", "----test----");
  }

  if (okay) {
    progresswindow.set_fraction (0.88);
    gw_message (_("Push second repository"));
    okay = try_git_push_repository ("local2");
  }

  if (okay) {
    progresswindow.set_fraction (0.94);
    gw_message (_("Pull first repository"));
    okay = try_git_pull_repository ("local1");
  }

  if (okay) {
    progresswindow.set_fraction (1);
    gw_message (_("Check data in first repository"));
    okay = try_git_check_data_in_repository ("local1", "----test----");
  }

  // Return whether git is ok.
  return okay;
}
Exemple #18
0
void gw_critical(const ustring & critical)
{
  gw_message("CRITICAL: " + critical);
  g_critical("%s", critical.c_str());
}
Exemple #19
0
void gw_error(const ustring & error)
{
  gw_message("ERROR:    " + error);
  g_error("%s", error.c_str());
}