示例#1
0
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);
    }
  }
}
void ResourceConverterDialog::on_write_anchors_button()
{
    // Remove old anchors.
    resource_conversion_remove_anchors(lines);

    // Flags.
    anchors_written = true;

    // Do the conversion.
    switch (resource_conversion_type) {
    case rctChapterStartsAtPatternVerseOneStartsAtChapterVerseStartsAtPattern:
    {
        resource_conversion_insert_anchors(lines, chapter_pattern_prefix, chapter_pattern_index, chapter_pattern_suffix, verse_pattern_prefix, verse_pattern_index, verse_pattern_suffix);
        break;
    }
    case rctEnd:
    {
        break;
    }
    }

    // Write text to file.
    write_lines(gw_build_filename(workingdirectory, filename), lines);

    // Update gui.
    if (write_anchors_gui()) {
        gui();
    }
}
示例#3
0
int fs_printf(fs_file fh, const char *fmt, ...)
{
    char *buff;
    int len;

    va_list ap;

    va_start(ap, fmt);
    len = 1 + vsnprintf(NULL, 0, fmt, ap);
    va_end(ap);

    if ((buff = malloc(len)))
    {
        int written;

        va_start(ap, fmt);
        vsnprintf(buff, len, fmt, ap);
        va_end(ap);

        /*
         * HACK.  This assumes fs_printf is always called with the
         * intention of writing text, and not arbitrary data.
         */

        written = write_lines(buff, strlen(buff), fh);

        free(buff);

        return written;
    }

    return 0;
}
示例#4
0
void WindowMerge::approval_approve(GtkButton * button)
// Handles the user's approval of a change.
{
  // Go through the approval buttons to find the one clicked.
  for (unsigned int i = 0; i < approve_buttons.size(); i++) {
    if (button == approve_buttons[i].button) {

      // Write a new patch file to disk.
      vector < ustring > lines;
      ustring s;
      s = convert_to_string(approve_buttons[i].patch.linenumber);
      if (approve_buttons[i].patch.addition)
        s.append("a");
      else
        s.append("d");
      s.append("0");
      lines.push_back(s);
      if (approve_buttons[i].patch.addition)
        s = ">";
      else
        s = "<";
      lines.push_back(s + " " + approve_buttons[i].patch.change);
      write_lines(approve_patch_file, lines);

      // Apply the patch to master.
      ustring command = "patch" + shell_quote_space(approve_master_file) + shell_quote_space(approve_patch_file);
      if (system(command.c_str())) ; // This one could use GwSpawn, but it was not tested.

      // Show the new differences after the change has been accepted.
      approval_show_diff();

    }
  }
}
示例#5
0
void ExportParatextStylesheet::save (ustring filename)
{
  // Write the stylesheet to file.
  if (!g_str_has_suffix (filename.c_str(), ".sty")) {
    filename.append (".sty");
  }
  write_lines (filename, stylesheet_lines);
}
示例#6
0
void odt_set_font(const ustring & directory, const ustring & fontname)
// Writes the font to the right files in the directory given.
{
  // Save the font in the content file.
  ReadText rt2(odt_content_xml_filename(directory), true, false);
  for (unsigned int i = 0; i < rt2.lines.size(); i++) {
    replace_text(rt2.lines[i], "Bitstream", fontname);
  }
  write_lines(odt_content_xml_filename(directory), rt2.lines);
}
示例#7
0
int main()
{
        int line_count;
        char storage[MAXLINELENGTH * MAXLINECOUNT];
        char* lines[MAXLINECOUNT]; /* a list of pointers to locations in storage[] */

        line_count = read_lines(storage, lines);
        qsort(lines, 0, line_count);
        write_lines(lines, line_count);
        return 0;
}
int main(int argc, char* argv[])
{
    int num_lines;
    char* lines[MAX_NUM_LINES];

    bool sort_numerically = false;

    if (argc > 1)
    {
        for (int i = 1; i < argc; ++i)
        {
            if (strcmp(argv[i], SORT_NUMERICALLY) == 0)
            {
                sort_numerically = true;
            }
            else if (strcmp(argv[i], SORT_REVERSE) == 0)
            {
                sort_reverse = true;
            }
            else if (strcmp(argv[i], FOLD_CASE) == 0)
            {
                fold_case = true;
            }
            else if (strcmp(argv[i], SORT_BY_FIELD) == 0)
            {
                if (i == argc - 1)
                {
                    printf("error: when sorting by field, you must specify the field to sort by\n"
                           "example: ./exercise_5-16 -e 2\n");
                }
                else
                {
                    sort_by_field = true;
                    field = atoi(argv[++i]);
                }
            }
        }
    }

    if ((num_lines = read_lines(lines)) >= 0)
    {
        quick_sort((void**) lines, 0, num_lines - 1,
            (int(*)(void*, void*))(sort_numerically ? numeric_cmp : lexicographic_cmp));
        write_lines(lines, num_lines);
        return 0;
    }
    else
    {
        printf("error: input too large to sort\n");
        return 1;
    }
}
示例#9
0
void odt_insert_content(const ustring & directory, const vector < ustring > &text)
{
  vector < ustring > odtlines;
  ReadText rt(odt_content_xml_filename(directory), true, false);
  for (unsigned int i = 0; i < rt.lines.size(); i++) {
    if (rt.lines[i].find("</office:text>") == 0) {
      for (unsigned int i2 = 0; i2 < text.size(); i2++) {
        odtlines.push_back(text[i2]);
      }
    }
    odtlines.push_back(rt.lines[i]);
  }
  write_lines(odt_content_xml_filename(directory), odtlines);
}
示例#10
0
int main()
{
	int nlines; /* Number of lines */
	char * plines[MAX_LINES]; /* Pointers to lines */
	
	if ((nlines = read_lines(plines, MAX_LINES)) < 0)
	{
		fprintf(stderr, "Error: Lack of memory. Input is too large.\n");
		return 1;
	}

	my_qsort(plines, 0, nlines-1);
	write_lines(plines, nlines);

	return 0;
}
示例#11
0
void notes_categories_check()
// Check categories are there - if not, create default set.
{
    if (!g_file_test(notes_categories_filename().c_str(), G_FILE_TEST_IS_REGULAR)) {
        vector < ustring > categories;
        categories.push_back(_("No issue"));
        categories.push_back(_("For myself"));
        categories.push_back(_("For subteam"));
        categories.push_back(_("For team"));
        categories.push_back(_("For scholar"));
        categories.push_back(_("For panel"));
        categories.push_back(_("For church"));
        categories.push_back(_("For consultant"));
        categories.push_back(_("For Bible society"));
        write_lines(notes_categories_filename(), categories);
    }
}
示例#12
0
bool resource_add_name_to_deleted_ones_if_standard_template(const ustring & filename)
/*
 If the filename given is a standard template, it adds the name of the resource
 to the list of deleted ones and then returns true.
 */
{
  ustring directory = gw_path_get_dirname(filename);
  if (directory == Directories->get_package_data()) {
    ustring deleted_filename = gw_build_filename(Directories->get_resources(), "deleted");
    ReadText rt(deleted_filename, true, true);
    ustring title = resource_get_title(filename);
    rt.lines.push_back(title);
    write_lines(deleted_filename, rt.lines);
    return true;
  }
  return false;
}
示例#13
0
void notes_store_one_in_file(int id, ustring & note, const ustring & project, const ustring& references, const ustring & category, int date_created, const ustring & user_created, int date_modified, ustring & logbook)
// Stores a note in a file.
// It should be flat files, not xml, because of the merging done by git.
{
    // Store the note.
    vector <ustring> lines;

    // Store date created.
    lines.push_back (convert_to_string (date_created));
    // Store user who created it.
    lines.push_back (user_created);
    // Store references.
    lines.push_back (references);
    // Store category.
    lines.push_back (category);
    // Store project.
    lines.push_back (project);
    // Store date modified.
    lines.push_back (convert_to_string (date_modified));
    // Store note.
    lines.push_back (note);
    // Store logbook separator.
    lines.push_back (notes_logbook_line ());
    // Store logbook.
    lines.push_back (logbook);

    // Write the note. The filename is the note id.
    ustring note_filename = notes_file_name (id);
    write_lines (note_filename, lines);

    // Update the index.
    sqlite3 *db;
    sqlite3_open(notes_index_filename ().c_str(), &db);
    sqlite3_busy_timeout(db, 1000);
    notes_store_index_entry (db, id);
    sqlite3_close(db);
}
示例#14
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.
}
示例#15
0
void XeTeX::write_document_tex_file ()
{
  // Settings.
  extern Settings * settings;
  ProjectConfiguration *projectconfig = settings->projectconfig(settings->genconfig.project_get());
  
  // Style sheet.
  extern Styles * styles;
  Stylesheet * sheet = styles->stylesheet (stylesheet_get_actual ());
  
  document_tex.push_back (_("% Configuration file created by Bibledit-Gtk"));
  document_tex.push_back (_("% You can modify it to suit your needs"));
  document_tex.push_back (_("% After modification, run the following command in this directory:"));
  document_tex.push_back (_("%   xetex document.tex"));
  document_tex.push_back (_("% After that look carefully at the output"));
  document_tex.push_back (_("% If it says that a re-run is required, repeat this command"));

  document_tex.push_back ("");
  document_tex.push_back (_("% Include the ptx2pdf macros"));
  document_tex.push_back ("\\input paratext2.tex");

  document_tex.push_back ("");
  document_tex.push_back (_("% Paper size"));
  document_tex.push_back ("\\PaperWidth=" + convert_to_string (settings->genconfig.paper_width_get()) + "cm");
  document_tex.push_back ("\\PaperHeight=" + convert_to_string (settings->genconfig.paper_height_get()) + "cm");

  if (settings->session.print_crop_marks){
    document_tex.push_back ("");
    document_tex.push_back (_("% Crop marks"));
    document_tex.push_back ("\\CropMarkstrue");
  }

  document_tex.push_back ("");
  document_tex.push_back (_("% The basic unit for the margins; changing this will alter them all"));
  document_tex.push_back ("\\MarginUnit=1cm");

  document_tex.push_back ("");
  document_tex.push_back (_("% Relative sizes of margins, based on the unit above"));
  document_tex.push_back ("\\def\\TopMarginFactor{" + convert_to_string (settings->genconfig.paper_top_margin_get()) + "}");
  document_tex.push_back ("\\def\\BottomMarginFactor{" + convert_to_string (settings->genconfig.paper_bottom_margin_get()) + "}");
  document_tex.push_back ("\\def\\SideMarginFactor{" + convert_to_string (settings->genconfig.paper_outside_margin_get()) + "}");

  if (settings->genconfig.paper_inside_margin_get() != settings->genconfig.paper_outside_margin_get()) {
    document_tex.push_back ("");
    document_tex.push_back (_("% Extra margin for the gutter on the binding side"));
    document_tex.push_back ("\\BindingGuttertrue");
    document_tex.push_back ("\\BindingGutter=" + convert_to_string (settings->genconfig.paper_inside_margin_get() - settings->genconfig.paper_outside_margin_get()) + "cm");
    document_tex.push_back ("");
    document_tex.push_back (_("% Double sided printing"));
    document_tex.push_back ("\\DoubleSidedtrue");
  }

  if (!projectconfig->editor_font_default_get()) {
    PangoFontDescription *font_desc = pango_font_description_from_string(projectconfig->editor_font_name_get().c_str());
    if (font_desc){
      
      // Assemble the string for the font mapping.
      ustring font_mapping = projectconfig->xetex_font_mapping_file_get();
      if (!font_mapping.empty()) {
        if (g_str_has_suffix (font_mapping.c_str(), ".tec")) {
          font_mapping = gw_path_get_basename (font_mapping);
          // Remove the .tec suffix.
          font_mapping.erase (font_mapping.length() - 4, 4);
          // Insert the mapping command.
          font_mapping.insert (0, "mapping=");
        } else {
          gw_warning (_("Font mapping file ") + font_mapping +  _(" should have the .tec suffix - ignoring this file"));
          font_mapping.clear();
        }
      }

      // Assemble the string for the shaping engine.
      ustring shaping_engine;
      switch (XeTeXScriptingEngineType (projectconfig->xetex_shaping_engine_get())) {
        case xtxsetGeneric:                                 break;
        case xtxsetArab:    shaping_engine = "script=arab"; break;
      }

      // Assemble the addition to the font.
      ustring font_addition;
      if (!font_mapping.empty()) {
        if (font_addition.empty())
          font_addition.append (":");
        else 
          font_addition.append (";");
        font_addition.append (font_mapping);
      }
      if (!shaping_engine.empty()) {
        if (font_addition.empty())
          font_addition.append (":");
        else 
          font_addition.append (";");
        font_addition.append (shaping_engine);
      }

      ustring font_family = pango_font_description_get_family (font_desc);
      document_tex.push_back ("");
      document_tex.push_back (_("% Fonts to use for \"plain\", \"bold\", \"italic\", and \"bold italic\" from the stylesheet"));
      document_tex.push_back (_("% (they need not really be italic, etc.)"));
      document_tex.push_back (_("% Add e.g. \":mapping=farsidigits\" to get digits in Farsi, provided the farsidigits.tec TECkit mapping is available"));
      document_tex.push_back (_("% Add e.g. \":script=arab\" to use the arab shaping engine instead of the generic one"));
      document_tex.push_back ("\\def\\regular{\"" + font_family + font_addition + "\"}");
      document_tex.push_back ("\\def\\bold{\"" + font_family + "/B" + font_addition + "\"}");
      document_tex.push_back ("\\def\\italic{\"" + font_family + "/I" + font_addition +  "\"}");
      document_tex.push_back ("\\def\\bolditalic{\"" + font_family + "/BI" + font_addition +  + "\"}");
      pango_font_description_free(font_desc);
    }
  }

  if (projectconfig->right_to_left_get()) {
    document_tex.push_back ("");
    document_tex.push_back (_("% Right-to-left layout mode"));
    document_tex.push_back ("\\RTLtrue");
  }

  document_tex.push_back ("");
  document_tex.push_back (_("% The unit for font sizes in the stylesheet; changing this will scale all text proportionately"));
  document_tex.push_back ("\\FontSizeUnit=1pt");

  document_tex.push_back ("");
  document_tex.push_back (_("% Scaling factor used to adjust line spacing, relative to font size"));
  double line_spacing_factor = 1.0;
  double vertical_space_factor = 1.0;
  if (!projectconfig->editor_font_default_get()){
    line_spacing_factor = projectconfig->text_line_height_get() / 100;
    vertical_space_factor = projectconfig->text_line_height_get() / 100;
  }
  document_tex.push_back ("\\def\\LineSpacingFactor{" + convert_to_string (line_spacing_factor) + "}");
  document_tex.push_back ("\\def\\VerticalSpaceFactor{" + convert_to_string (vertical_space_factor) + "}");

  document_tex.push_back ("");
  document_tex.push_back (_("% Information to include in the running header (at top of pages, except first)"));
  document_tex.push_back (_("% We set the items to print at left/center/right of odd and even pages separately"));
  document_tex.push_back (_("% Possible contents:"));
  document_tex.push_back (_("%   \\rangeref = Scripture reference of the range of text on the page;"));
  document_tex.push_back (_("%   \\firstref = reference of the first verse on the page)"));
  document_tex.push_back (_("%   \\lastref = reference of the last verse on the page)"));
  document_tex.push_back (_("%   \\pagenumber = the page number"));
  document_tex.push_back (_("%   \\empty = print nothing in this position"));
  document_tex.push_back ("\\def\\RHoddleft{\\empty}");
  document_tex.push_back ("\\def\\RHoddcenter{\\empty}");
  document_tex.push_back ("\\def\\RHoddright{\\rangeref}");
  document_tex.push_back ("");
  document_tex.push_back ("\\def\\RHevenleft{\\rangeref}");
  document_tex.push_back ("\\def\\RHevencenter{\\empty}");
  document_tex.push_back ("\\def\\RHevenright{\\empty}");
  document_tex.push_back ("");
  document_tex.push_back ("\\def\\RHtitleleft{\\empty}");
  document_tex.push_back ("\\def\\RHtitlecenter{\\empty}");
  document_tex.push_back ("\\def\\RHtitleright{\\empty}");
  document_tex.push_back ("");
  document_tex.push_back ("\\def\\RFoddcenter{\\pagenumber}");
  document_tex.push_back ("\\def\\RFevencenter{\\pagenumber}");
  document_tex.push_back ("\\def\\RFtitlecenter{\\pagenumber}");

  document_tex.push_back ("");
  document_tex.push_back (_("% Whether to include verse number in running head, or only chapter"));
  document_tex.push_back ("\\VerseRefstrue");

  document_tex.push_back ("");
  document_tex.push_back (_("% Whether to skip printing verse number 1 at start of chapter"));
  document_tex.push_back ("\\OmitVerseNumberOnetrue");

  document_tex.push_back ("");
  document_tex.push_back (_("% Whether to use paragraph indent at drop-cap chapter numbers"));
  document_tex.push_back (_("% \\IndentAtChaptertrue"));

  // Go through the stylesheet looking for note markers.
  for (unsigned int i = 0; i < sheet->styles.size(); i++) {
    bool retrieve_note_data = false;
    StyleV2 * style = sheet->styles[i];
    if (style->type == stFootEndNote) {
      if ((style->subtype == fentFootnote) || (style->subtype == fentEndnote)) {
        retrieve_note_data = true;
      }
    }
    if ((style->type == stFootEndNote) || (style->type == stCrossreference)) {
      if (style->subtype == ctCrossreference) {
        retrieve_note_data = true;
      }
    }
    if (retrieve_note_data) {

      ustring marker = style->marker;
      document_tex.push_back ("");
      document_tex.push_back (_("% Reformat \\") + marker + " notes as a single paragraph");
      document_tex.push_back ("\\ParagraphedNotes{" + marker + "}");

      document_tex.push_back ("");
      NoteNumberingType note_numbering = NoteNumberingType (style->userint1);
      switch (note_numbering) {
        case nntNumerical:
          document_tex.push_back (_("% Numerical callers for \\") + marker + _(" notes"));
          document_tex.push_back ("\\NumericCallers{" + marker + "}");
          break;
        case nntAlphabetical:
          document_tex.push_back (_("% Alphabetical callers for \\") + marker + _(" notes"));
          document_tex.push_back ("\\AutoCallers{" + marker+ "}{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}");
          break;
        case nntUserDefined:
          ustring autocallers;
          for (unsigned int i = 0; i < style->userstring1.size(); i++) {
            if (i)
              autocallers.append (",");
            autocallers.append (style->userstring1.substr (i, 1));
          }
          if (!autocallers.empty()) {
            document_tex.push_back (_("% Special caller sequence for \\") + marker + " notes");
            document_tex.push_back ("\\AutoCallers{" + marker+ "}{" + autocallers + "}");
          }
          break;
      }

      document_tex.push_back ("");
      NoteNumberingRestartType note_restart = NoteNumberingRestartType (style->userint2);
      switch (note_restart) {
        case nnrtNever:
          break;
        case nnrtBook:
          break;
        case nnrtChapter:
          break;
      }
      document_tex.push_back (_("% Reset callers every page for \\") + marker + _(" notes"));
      document_tex.push_back ("\\PageResetCallers{" + marker + "}");

      document_tex.push_back ("");
      document_tex.push_back (_("% Omit callers in the note for \\") + marker + _(" notes"));
      document_tex.push_back (_("% \\OmitCallerInNote{") + marker + "}");

    }
  }

  document_tex.push_back ("");
  document_tex.push_back (_("% The number of columns"));
  document_tex.push_back ("\\TitleColumns=1");
  document_tex.push_back ("\\IntroColumns=1");
  document_tex.push_back ("\\BodyColumns=2");

  document_tex.push_back ("");
  document_tex.push_back (_("% The gutter between double cols, relative to font size"));
  document_tex.push_back ("\\def\\ColumnGutterFactor{15}");

  // Define the Paratext stylesheet to be used as a basis for formatting
  write_stylesheet ();

  // Write the data and add their filenames.
  for (unsigned int i = 0; i < book_ids.size(); i++) {
    ustring filename = convert_to_string (book_ids[i]) + " " + books_id_to_english(book_ids[i]) + ".usfm";
    replace_text (filename, " ", "_");
    write_lines (gw_build_filename (working_directory, filename), book_data[i]);
    document_tex.push_back ("\\ptxfile{" + filename + "}");
  }

  // End of document input.
  document_tex.push_back ("\\end");

  // Write document.text to file.
  write_lines (gw_build_filename (working_directory, "document.tex"), document_tex);
}
void ResourceConverterDialog::on_view_file_button()
{
    ustring tempfile = gw_build_filename(Directories->get_temp(), "resource-converter-view-file");
    write_lines(tempfile, lines);
    gtkw_show_uri (tempfile, false);
}