summaryrefslogtreecommitdiff
path: root/src/roff/troff/node.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [troff]: Trivially refactor ("constant_int_reg").G. Branden Robinson2022-12-071-2/+2
| | | | | | | | | | | | Rename class `constant_int_reg` to `readonly_register`. Say "readonly" instead of "const" to try to avoid confusion with C++ constness. Drop "int" because integer-valued registers are the norm, not the exception. * src/roff/troff/column.cpp (init_column_requests): * src/roff/troff/div.cpp (init_div_requests): * src/roff/troff/input.cpp (top level, init_input_requests): * src/roff/troff/node.cpp (init_node_requests): * src/roff/troff/reg.h: Do it.
* [troff]: Trivially refactor ("number_reg_dic...").G. Branden Robinson2022-12-071-6/+6
| | | | | | | | | | | | | | | | | | Rename `number_reg_dictionary` to `register_dictionary`. It's shorter _and_ non-abbreviated _and_ matches our documentation. * src/roff/troff/column.cpp (init_column_requests): * src/roff/troff/div.cpp (page_number, init_div_requests): * src/roff/troff/env.cpp (print_env, init_env_requests) (init_hyphen_requests): * src/roff/troff/input.cpp (length_request, interpolate_number_format) (do_register, do_if_request, main, init_registers) (init_input_requests): * src/roff/troff/node.cpp (get_register, init_node_requests): * src/roff/troff/reg.cpp (top level, define_number_reg (inline_define_reg, alter_format, remove_reg, alias_reg, rename_reg) (print_number_regs): * src/roff/troff/reg.h: Do it.
* [troff]: Boolify `character_exists()`.G. Branden Robinson2022-11-251-5/+5
| | | | | * src/roff/troff/node.h (character_exists): * src/roff/troff/node.cpp (character_exists): Boolify.
* src/roff/troff/node.cpp: Fix code style nit.G. Branden Robinson2022-08-231-1/+1
| | | | | | * src/roff/troff/node.cpp: Fix code style nit. Put space around binary arithmetic operators. Put a space after `sizeof` because it is an operator, not a function.
* src/roff/troff/node.cpp: Refactor make_definite().G. Branden Robinson2022-08-231-45/+43
| | | | | | | | | | | * src/roff/troff/node.cpp (font_family::make_definite): Refactor. Rename parameter from inscrutable `i` to `mounting_position`. Add `assert()` to enforce invariant: we're passed a mounting position that is nonnegative. Use `pos` as short alias of parameter once we're into the function body. Relocate conditional branches to front-load early returns as well as those requiring little code to handle. This reduces the average indentation level of the function, a readability win.
* [troff]: Add source file line # to grohtml-info.G. Branden Robinson2022-07-141-2/+3
| | | | | * src/roff/troff/node.cpp (suppress_node::tprint): Add source file line number after its name when emitting "grohtml-info", to aid debugging.
* [troff]: Refactor.G. Branden Robinson2022-07-141-9/+10
| | | | | | | | | * src/roff/troff/node.cpp (get_register, get_string): Reorder null pointer inequality comparisons; they don't need to be in a funny order because it's pretty hard to mistype `!=` as an assignment operator. Annotate them as null pointers to ease any future migration to ISO C++11. Use primitive type constructor instead of C-style cast operator; this seems more idiomatic.
* [troff]: Trivially refactor.G. Branden Robinson2022-06-231-5/+6
| | | | | | | | | | | | | | | | | * src/roff/troff/input.cpp (token::next): Rename statement label to use documentary terminology. * src/roff/troff/node.cpp (make_composite_node, make_glyph_node): Make functions static since nothing outside this translation unit calls them. * src/roff/troff/node.cpp (make_glyph_node): Refactor optional argument and its usage. Put it down, flip it, and reverse it. That is, demote its type from `int` to `bool`, invert its sense, and rename it since it affects warning, not error, diagnostics. (character_exists): Update only call site of `make_glyph_node()` that uses non-default argument value.
* [troff]: Adjust diagnostic message text.G. Branden Robinson2022-06-231-13/+14
| | | | | | | | | | | | | | | | | | | [troff]: Adjust diagnostic message text to clarify and better match terminology used in documentation. * src/roff/troff/input.cpp (set_escape_char, do_overstrike, do_bracket, do_name_test, do_width, do_special): * src/roff/troff/node.cpp (suppress_node::tprint): Migrate from "escape" to "escape sequence". * src/roff/troff/node.cpp (make_composite_node, make_glyph_node): Clarify what went wrong. * src/roff/troff/input.cpp (token::get_char, check_missing_character): Migrate from "normal character" to "ordinary character" (see groff_char(7)). Also add comment near possibly unreachable code.
* src/roff/troff/node.cpp: Fix code style nit.G. Branden Robinson2022-06-211-5/+5
| | | | | | * src/roff/troff/node.cpp (mount_font_no_translate): Annotate null pointers with `nullptr` comment to ease any future transition to C++11, which defines it as a keyword.
* src/roff/troff/node.cpp: Improve diagnostic msg.G. Branden Robinson2022-05-311-3/+9
| | | | | | | * src/roff/troff/node.cpp (font_position): If mounting a font fails and a third argument was given (to the `fp` request), report its value in the diagnostic message. This could reveal a prohibited attempt at directory traversal. See commit a891161bc9, 7 November.
* [libgroff, troff]: Slightly refactor.G. Branden Robinson2021-09-171-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [libgroff, troff]: Slightly refactor device and font description file loading. Remove dead code. * src/include/font.h (font::load_font): Drop second parameter. It was never used for its intended purpose. (load): Drop first parameter; likewise. * src/libs/libgroff/font.cpp (font::load) (load): As above. * src/libs/libgroff/font.cpp (struct text_file): Rename `skip_comments` to `recognize_comments`. Demote that and `silent` from `int` to `bool`. (text_file::text_file): Use Boolean rather than integer literals in constructor. (text_file::next_line, font::load): Apply above renaming. * src/libs/libgroff/font.cpp (font::load): Rename parameter from `head_only` to `load_header_only` to be more communicative. Drop test of font description file name being `DESC`; this code was not being reached. Stop throwing errors from this function on failure to open the file; the caller will handle this when it sees our false return value. Rename local variable `command` to `directive` for alignment with our documentation. Replace "I dont think this should happen" test and comment with `assert()`. (struct table): Rename member from `command` to `numeric_directive` to indicate its specificity, tracking only a subset of valid `DESC` file directives. * src/libs/libgroff/font.cpp (font::load, font::load_desc): Remove redundant assignments to the member variable formerly known as `skip_comments`. * src/libs/libgroff/font.cpp (font::load_desc): Rename local variable `directive_found` to `numeric_directive_found` to clarify logic. * src/roff/troff/node.cpp (mount_font_no_translate): Simplify call of `font::load_font`. The `not_found` in-out parameter which was so agonizingly passed up through layers of library calls was never actually read. Drop code that has been `#if 0`-ed out since 1993. Before and after of goofing up by trying to mount a font called "DESC". The former is groff 1.22.4. $ groff .fp 5 DESC troff: <standard input>:1: warning: can't find font 'DESC' $ ./build/test-groff .fp 5 DESC troff: .../build/font/devps/DESC:15: error: unrecognized directive 'lpr' after 'kernpairs' or 'charset' directive troff: <standard input>:1: error: cannot load font 'DESC' for mounting
* [troff]: Give font diagnostics more context.G. Branden Robinson2021-09-161-59/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [troff]: Lift font mounting diagnostic messages to be closer to their user-controlled contexts to provide more information. In many cases no diagnostic was being thrown at all when an unavailable font was requested by name, which is the method most users prefer, and which meant that failures resulting from typos in font names for many requests (`uf`, `fschar`, `rfschar`, `special`, `fspecial`, `fzoom`, `bd`, `tkf`, `cs`) were going unreported. Also, these font warnings are promoted to errors because the request will utterly fail to do what was requested with no reasonable fallback. Possibly, they were warnings in the first place because they could also be thrown regarding unavailable fonts encountered in device description files, and while that's bad news, it results in no formatting problems if it doesn't affect fonts that an input document actually uses; thus, a mere warning is appropriate. * src/roff/troff/node.cpp (struct font_lookup_info): New struct keeps the font name or position requested, and the position of successful font lookup. (font_lookup_info::font_lookup_info): Add constructor. (font_lookup_error): New function builds error message using a `font_lookup_info` struct and a message argument. (get_fontno): Rename to... (has_font): ...this. Add argument to take a pointer to a `font_lookup_info` struct. Return a `bool` indicating whether the lookup succeeded. Place former `int` return value into the struct instead. Populate the other struct members with the requested font name or position, as appropriate. (mount_font_no_translate): Stop throwing warning diagnostic here if a font cannot be loaded. Instead, throw them... (font_position): ...here, and... (underline_font, define_font_special_character, remove_font_special_character, read_special_fonts, font_special_request, font_zoom_request, bold_font, track_kern, constant_space): ...here, using `font_lookup_info` structs and `has_font()`. (remove_font_special_character): Stop returning early if font lookup fails; it's gratuitously inconsistent with other similar functions (save one, which has a reason to be different). (define_font_special_character): Return early if font lookup fails and say why in a comment (we can't `skip_line()`). Input: .uf Z .uf 99 .fschar Z \[co] COPYRIGHT .fschar 99 \[co] COPYRIGHT .rfschar Z \[co] .rfschar 99 \[co] .special Y .special 98 .fspecial Z Y .fspecial 99 Y .fzoom Z .fzoom 99 .bd Z 3 .bd 99 3 .bd S Z 3 .bd S 99 3 .bd 98 Z 3 .bd 98 99 3 .tkf Z .tkf 99 .cs Z .cs 99 groff 1.22.4 diagnostics: troff: ...:1: warning: can't find font 'Z' troff: ...:2: bad font number troff: ...:4: bad font number troff: ...:6: bad font number troff: ...:7: warning: can't find font 'Y' troff: ...:8: bad font number troff: ...:10: bad font number troff: ...:12: bad font number troff: ...:14: bad font number troff: ...:17: bad font number troff: ...:18: bad font number troff: ...:20: bad font number troff: ...:22: bad font number groff 1.23.0 diagnostics: troff: ...:1: error: cannot load font 'Z' to make it the underline font troff: ...:2: error: cannot load font at position 99 to make it the underline font troff: ...:3: error: cannot load font 'Z' to define font-specific fallback glyph troff: ...:4: error: cannot load font at position 99 to define font-specific fallback glyph troff: ...:5: error: cannot load font 'Z' to remove font-specific fallback glyph troff: ...:6: error: cannot load font at position 99 to remove font-specific fallback glyph troff: ...:7: error: cannot load font 'Y' to mark it as special troff: ...:8: error: cannot load font at position 98 to mark it as special troff: ...:9: error: cannot load font 'Z' to mark other fonts as special contingently upon it troff: ...:10: error: cannot load font at position 99 to mark other fonts as special contingently upon it troff: ...:11: error: cannot load font 'Z' to set a zoom factor for it troff: ...:12: error: cannot load font at position 99 to set a zoom factor for it troff: ...:13: error: cannot load font 'Z' for emboldening troff: ...:14: error: cannot load font at position 99 for emboldening troff: ...:15: error: cannot load font 'Z' for conditional emboldening troff: ...:16: error: cannot load font at position 99 for conditional emboldening troff: ...:17: error: cannot load font at position 98 for emboldening troff: ...:18: error: cannot load font at position 98 for emboldening troff: ...:19: error: cannot load font 'Z' for track kerning troff: ...:20: error: cannot load font at position 99 for track kerning troff: ...:21: error: cannot load font 'Z' for constant spacing troff: ...:22: error: cannot load font at position 99 for constant spacing
* [libgroff, troff]: Further boolify.G. Branden Robinson2021-09-161-16/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/include/font.h (load_font, font): Demote parameters from {pointer to} `int` to `bool` and update default literal from integer to Boolean (except for the pointer). Update comment. * src/libs/libgroff/font.cpp (load_font, load): Similarly. * src/roff/troff/node.h (mount_font): * src/roff/troff/node.cpp (mount_font): Demote return type from `int` to `bool`. * src/roff/troff/node.h (mount_style): * src/roff/troff/node.cpp (mount_style): Promote return type from `void` to `bool`. * src/roff/troff/node.cpp (mount_font_no_translate): Demote return type and `check_only` parameter from `int` to `bool` and use Boolean rather than integer literals with them. (check_font): Update call site of `mount_font_no_translate` to use Boolean literal. (font_position): Indicate that "error" is ignored by casting return value of `mount_font` to void instead of using a comment. (style): Cast return value of `mount_style` to `void`. The return value of `mount_style` will be used elsewhere in a forthcoming commit.
* [troff]: Boolify members of `token` class.G. Branden Robinson2021-09-061-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/roff/troff/token.h (class token): Demote return type of several member functions from `int` to `bool` and rename them. - `backspace` -> `is_backspace` - `delimiter` -> `usable_as_delimiter` - `dummy` -> `is_dummy` - `eof` -> `is_eof` - `horizontal_space` -> `is_horizontal_space` - `hyphen_indicator` -> `is_hyphen_indicator` - `leader` -> `is_leader` - `left_brace` -> `is_left_brace` - `newline` -> `is_newline` - `page_ejector` -> `is_page_ejector` - `right_brace` -> `is_right_brace` - `space` -> `is_space` - `special` -> `is_special` - `stretchable_space` -> `is_stretchable_space` - `tab` -> `is_tab` - `transparent_dummy` -> `is_transparent_dummy` - `transparent` -> `is_transparent` - `unstretchable_space` -> `is_unstretchable_space` - `white_space` -> `is_white_space` - `zero_width_break` -> `is_zero_width_break` (class token): Drop 1991 comment anticipating that member function `nspaces` could return "2" for a "double space"; this was apparently never implemented. (class token): Drop parameter names from declarations; the prevailing style (familiar from Stroustrup) is not to use them. (token::is_special): Simplify implementation. * src/roff/troff/input.cpp (has_arg, token::usable_as_delimiter): Update definitions of above member functions not defined in token.h. * src/roff/troff/div.cpp (begin_page, space_request, need_space, output_saved_vertical_space, flush_output): * src/roff/troff/env.cpp (fill, no_fill, center, right_justify, indent, temporary_indent, margin_character, number_lines, do_break_request, hyphen_word): * src/roff/troff/input.cpp (next_file, do_overstrike, do_bracket, do_name_test, do_expr_test, do_zero_width, token::skip, has_arg, skip_line, empty_name_warning, non_empty_name_warning, do_get_long_name, process_input_stack, flush_pending_lines, decode_args, read_request, do_define_string, do_define_character, remove_character, do_define_macro, length_request, get_delim_number, get_line_arg, read_size, get_delim_name, do_register, do_width, read_title_parts, encode_char, do_special, device_request, output_request, skip_alternative, begin_alternative, nop_request, do_if_request, do_source, pipe_source, ps_bbox_request, tag, taga, do_terminal, do_translate, hyphenation_code, hyphenation_patterns_file_code, define_class, get_optional_char, check_missing_character, abort_request, copy_file, transparent_file, do_macro_source, charinfo_to_node_list, read_draw_node, read_color_draw_node): * src/roff/troff/node.cpp (get_fontno, remove_font_special_character, bold_font): * src/roff/troff/number.cpp (start_number, parse_term): * src/roff/troff/reg.cpp (define_number_reg, alter_format): Update call sites to use new names. * src/roff/troff/input.cpp (token::usable_as_delimiter, read_draw_node): Return Boolean, not integer, literals. Also add editor aid comments to ends of files lacking them. Remove old-style Emacs file-local local variable at file beginnings. Also fix white space nits.
* [libgroff]: Drop `a_delete` preprocessor wrapper.G. Branden Robinson2021-08-281-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... for the `delete` operator. It has been rendered unnecessary by the removal of support for ancient C++ compilers. * src/include/lib.h (a_delete): Drop symbol definition. * src/devices/grohtml/output.cpp (word::~word): * src/devices/grohtml/post-html.cpp (char_block::char_block, assert_state::~assert_state, assert_state::add, assert_state::close, replace_negate_str): * src/devices/grops/ps.cpp (ps_font::ps_font, subencoding::subencoding, ps_printer::define_encoding, ps_printer::encode_fonts): * src/devices/grops/psrm.cpp (resource_manager::document_setup, resource_manager::supply_resource): * src/devices/grotty/tty.cpp (tty_printer::tty_color, tty_printer::tty_printer, tty_printer::color_to_idx, tty_printer::add_char): * src/include/itable.h (ITABLE(T)::~ITABLE(T), ITABLE(T)::define): * src/include/ptable.h (PTABLE(T)::~PTABLE(T), PTABLE(T)::define): * src/libs/libbib/index.cpp (index_search_item::~index_search_item, make_index_search_item, index_search_item_iterator::index_search_item_iterator, index_search_item::get_tag, index_search_item::munge_filename, index_search_item::search): * src/libs/libbib/linear.cpp (bmpattern::~bmpattern, file_buffer::file_buffer, file_buffer::load, linear_searcher::linear_searcher, linear_searcher::~linear_searcher): * src/libs/libbib/search.cpp (search_list_iterator::search_list_iterator, search_item::search_item): * src/libs/libdriver/input.cpp (IntArray::~IntArray, IntArray::append, StringBuf::~StringBuf, StringBuf::append, get_integer_arg, parse_x_command, do_file): * src/libs/libdriver/printer.cpp (printer::printer, printer::load_font, text_file::~text_file, text_file::next, font::~font, font_widths_cache::~font_widths_cache, font:alloc_ch_index, font::extend_ch, font::compact, font::load_desc): * src/libs/libgroff/fontfile.cpp (font::open_file): * src/libs/libgroff/relocate.cpp (searchpath, searchpathext, set_current_prefix): * src/libs/libgroff/searchpath.cpp (search_path::search_path, search_path::command_line_dir, search_path::open_file, search_path::open_file_cautious): * src/libs/libgroff/string.cpp (sfree, srealloc, string::remove_spaces): * src/libs/libgroff/symbol.cpp (symbol::symbol, concat): * src/libs/libgroff/tmpfile.cpp (temp_init::temp_init, xtmpfile_list_init::~xtmpfile_list_init, xtmpfile): * src/preproc/eqn/box.cpp (set_gfont, set_grfont, set_gbfont, box_list::append, box_list::~box_list): * src/preproc/eqn/delim.cpp (make_delim_box, delim_box::~delim_box): * src/preproc/eqn/eqn.ypp (number): * src/preproc/eqn/lex.ypp (file_input::~file_input, argument_macro_input::~argument_macro_input): * src/preproc/eqn/pile.ypp (matrix_box::~matrix_box, matrix_box::append): * src/preproc/eqn/special.cpp (special_box::~special_box): * src/preproc/eqn/text.ypp (set_char_type): * src/preproc/html/pre-html.cpp (get_line, scanArguments): * src/preproc/pic/object.cpp (output::~output, output::set_args, text_item::~text_item, object_spec::~object_spec, command_object::~command_object, line_object::~line_object): * src/preproc/pic/pic.ypp (placeless_element, reset_variables, print_args, text_expr, object_spec, text, sprintf_args, path): * src/preproc/refer/command.cpp (input_item::~input_item, input_item::peek_char): * src/preproc/refer/label.ypp (lookup_label): * src/preproc/refer/refer.cpp (store_citation, store_reference): * src/preproc/tbl/main.cpp (format::add_rows, format::~format): * src/preproc/tbl/table.cpp (block_entry::~block_entry, table::~table, table::allocate): * src/roff/groff/groff.cpp (possible_command::~possible_command, possible_command::clear_name): * src/roff/troff/column.cpp (justification_spec::~justification_spec, justification_spec::append): * src/roff/troff/dictionary.cpp (dictionary::lookup): * src/roff/troff/env.cpp (override_sizes, tab_stops::to_string, hyphen_word, hyphen_trie::insert_hyphenation): * src/roff/troff/input.cpp (read_long_escape_name, token::next, do_get_long_name, temp_iterator::~temp_iterator, get_delim_name, pipe_source, read_string, pipe_output, system_request, open_mac_file, do_macro_source, do_register_assignment, do_string_assignment, read_draw_node, copy_mode_error): * src/roff/troff/node.cpp (troff_output_file::set_font, troff_output_file::~troff_output_file, draw_node::is_tag, grow_font_table, font_family::~font_family, font_family::make_definite): * src/utils/hpftodit/hpftodit.cpp (name_list::~name_list, read_map): * src/utils/indxbib/indxbib.cpp (main, get_cwd): * src/utils/tfmtodit/tfmtodit.cpp (tfm::~tfm, tfm::load): Port uses of `a_delete(xxx)` to `delete[]`.
* Convert some font class `int` members to `bool`.G. Branden Robinson2021-08-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/include/font.h (font class): Demote integers to Booleans and use Boolean literals where possible. Rename some member variables to look like logical predicates. - contains() - is_special() - has_ligature() - tcommand -> has_tcommand - unscaled_charwidths - pass_filenames - use_charnames_in_special - is_unicode - special (private) * src/libs/libgroff/font.cpp (font::font): Construct object using Boolean literal. (font::contains): (font::is_special): (font::has_ligature): Convert return type to `bool`. (font::load): (font::load_desc): Assign to member variables using Boolean literals. * src/libs/libgroff/fontfile.cpp: Initialize appropriate globals using `bool` type and Boolean literals. * src/roff/troff/troff.h: * src/roff/troff/input.cpp (main): * src/roff/troff/node.cpp (troff_output_file::put_char_width): Rename `tcommand_flag` to `device_has_command` to suggest a logical predicate, and to emphasize the formatter's concern with what the output device can accept in the intermediate output language. * src/roff/troff/input.cpp: Initialize `device_has_tcommand` global using `bool` type and Boolean literal.
* src/roff/troff/node.cpp: Update comments.G. Branden Robinson2021-07-301-8/+8
| | | | ...since this stuff confused me so badly, it might befuddle others.
* [troff]: Slightly refactor.G. Branden Robinson2021-07-301-8/+4
| | | | | | | | | | | | * src/roff/troff/node.cpp: Add static `image_filename_len` to store length of cached image file name, so we don't wastefully recompute its length every time one is re-used. (suppress_node::tprint): Compute image file name length only when saving a new image file name. Use saved length in later expressions. (min): Drop unused inline function.
* [troff]: Fix regression in \O2 escape handling.G. Branden Robinson2021-07-301-1/+1
| | | | | | | | | | Fix regression (breaking important pdfmark/pdfroff features) caused by my commit e876d4bfd193abb9a7d1fb6e76519349bded482a, 27 July. An empty image file name is in fact semantically valid when writing a bounding box; pdfmark uses such boxes to frame hyperlinks. Avoid null pointer dereference by initializing `image_filename` to an empty string literal. Thanks to Tadziu Hoffman and Keith Marshall for their patient explanations.
* Revert "[troff]: Add sanity check to prevent SEGV."G. Branden Robinson2021-07-301-5/+0
| | | | | | | | | | | | | | | | | | | | | This reverts commit 01a65469b56f7284041365b0b179b6b4b9153b9c. The image file name string can indeed validly be a null pointer; this can happen with the \O2 escape as used by pdfmark to write bounding box information with no associated image. Tadziu Hoffman explains[1]: pdfmark uses the suppression mechanism bounding box output to find the anchor positions, but no images are involved. The Postscript branch in suppress_node::tprint should be perfectly okay with an empty image_filename. [In the change being reverted], the entire "is_html / else postscript (or other device)" switch is being skipped if we have no image_filename, resulting in no output of the link anchor information for pdfmark. [1] https://lists.gnu.org/archive/html/groff/2021-07/msg00123.html
* [troff]: Add sanity check to prevent SEGV.G. Branden Robinson2021-07-291-0/+5
| | | | | | | | | | | | | | | | | | | * src/roff/troff/node.cpp (suppress_node::tprint): If emitting bounding box limits for an image filename, ensure that `image_filename` is not a null pointer (and furthermore that it's not a zero-length string even if the pointer is valid). Emit an error diagnostic and skip further processing of the node if they are. This problem implies nonsensical input (so we should guard against it), but I cannot reproduce the problem _except_ with pdfroff during a build of the groff tree, which has been reliably failing to relocate the table of contents in pdfmark.pdf since commit e876d4bfd193abb9a7d1fb6e76519349bded482a, 27 July. If I extract the groff and troff commands that pdfroff is running and execute them in the build directory, they complete successfully, which suggests to me an environment problems or a race condition. This commit produces nonstandard indentation in the `else` brace block; I did that to keep the logic and scope of the change clear.
* src/roff/troff/node.cpp: Wrap long source lines.G. Branden Robinson2021-07-291-3/+6
| | | | | This is in preparation for changes that will add a brace scope and thus change indentation.
* [troff]: Refactor some internal functions.G. Branden Robinson2021-07-291-17/+16
| | | | | | | | | | | | | | | | | | | | * src/roff/troff/node.cpp: Rename two functions that have only one caller. - get_reg_int -> get_register - get_reg_str -> get_string We now have: (get_register, get_string): Use `assert()` aggressively because these are deeply internal and validation is imperative. Get rid of diagnostic messages (one of which perpetuated the dubious "number register" nomenclature) accordingly. (fetch_register): Also rename `prev_value`, misleadingly specific and semmingly copy-and-pasted out of a context where an auto-increment or -decrement might have been applied. It's just the `value`. (suppress_node::tprint): Update call site.
* [troff]: Recast some diagnostic messages.G. Branden Robinson2021-07-281-2/+2
| | | | | | | | | | | | | * src/roff/troff/input.cpp (do_suppress): Recast diagnostic messages for clarity, to communicate in terms of what the escape sequence _is_, and to quote literals expected as input. * src/roff/troff/node.cpp (suppress_node::tprint): Recast diagnostic to prevent misinterpretation of image "description" as being HTML IMG tag alt text or something like that. Unfortunately, the new language speaks in terms of internal implementation details ("grohtml-info"), but at least that way it's easier for a user to decide if they care about it.
* [troff]: Fix Savannah #60977.G. Branden Robinson2021-07-281-16/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [troff]: Avoid using sprintf() with user-controlled format string. * src/preproc/html/pre-html.cpp (makeFileName): Add comment noting need for implementation synchrony between this function, which generates \O5 escape sequences, and troff's suppress_node::tprint member function, which interprets them. * src/roff/troff/node.cpp: Rename 2 static globals for clarity. - `last_image_filename` -> `image_filename` - `last_image_id` -> `subimage_counter` (suppress_node::tprint): Set up the buffer for image file name to be written using a constant rather than an embedded literal. Unconditionally initialize the buffer with a string terminator, so there is no chance of a read from uninitialized storage. Drop unused code involving `tem`. Drop stale comments. Clarify comment: an `image_filename` doesn't _always_ contain a format string, only sometimes. Replace use of `sprintf` with manual construction of a new image filename string. There are two cases, one where a format string {presently "%d"} is present, and one where it is not. If it is present, locate it {`percent`}. This means a limited/bounded image ("subimage") is being processed; increment the subimage counter. Write a new image file name preserving the parts before and after "%d" (the "prefix" and "suffix", and replacing only the middle, using `sprintf` with the subimage counter and the (string literal) format. Be mindful of string bounds and memory allocation, issuing diagnostics or aborting as necessary. If the image file name does _not_ contain a format string, but needs only to be copied, do that (`strcpy`), again instead of using `sprintf`. Fixes <https://savannah.gnu.org/bugs/?60977>. Implementation note: * Why all these standard C library string manipulations? (1) I'm more familiar with C than C++. (2) The inbound type I'm dealing with, {last,}image_filename, is a char*, not a C++ string type. (3) groff does not use a standard C++ library string type, but its own implementation[1]; groff is _old_). (4) That custom string class does not have any `printf`-style format methods that I can see. Incidentally, groff's own `i_to_a` library function[2] doesn't handle long ints, which `size_t` is, so you can't put longs into diagnostic messages among other places. (It looks easy to change `i_to_a` and `ui_to_a` to support longs. You can then watch the build explode into a thousand pieces with numeric overflows in troff.) (5) I did attempt to handle the strings efficiently, never calling strcat() since I always knew where the end of a string I wanted to append to was[3]. [1] src/include/stringclass.h [2] src/libs/libgroff/itoa.c [3] https://symas.com/the-sad-state-of-c-strings/
* [troff]: Slightly refactor.G. Branden Robinson2021-07-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make the source code slightly more accessible by using a `bool` type for a function's default parameter used as a Boolean, and comment it at call sites where the default is overridden. See also commit d56e0f1d, 25 June. * src/roff/troff/token.h (get_name, get_long_name): Change type of parameter from `int` to `bool` and default from 0 to `false`. * src/roff/troff/input.cpp (do_get_long_name, empty_name_warning, get_name, get_long_name): Change type of parameter from `int` to `bool` in declarations and definitions. * src/roff/troff/column.cpp (column_justify): * src/roff/troff/div.cpp (diversion_trap): * src/roff/troff/env.cpp (environment_switch, environment_copy, do_input_trap, set_hyphenation_language, do_hyphenation_patterns_file): * src/roff/troff/input.cpp (define_color, composite_request, do_define_string, do_define_macro, rename_macro, alias_macro, chop_macro, do_string_case_transform, substring_request, length_request, asciify_macro, unformat_macro, do_register, device_macro_request, do_if_request, do_source, ps_bbox_request, do_open, close_request, do_write_request, write_macro_request, define_class, copy_file, vjustify, transparent_file, do_macro_source): * src/roff/troff/node.cpp (font_translate, font_position, style, get_fontno): * src/roff/troff/reg.cpp (define_number_reg, inline_define_reg, alter_format, alias_reg, rename_reg): Update call sites. Add comment indicating meaning of parameter.
* [troff]: Slightly refactor token::get_char().G. Branden Robinson2021-06-251-1/+1
| | | | | | | | | | | | | | | | | | [troff]: Slightly refactor. Make the source code slightly more accessible by using a `bool` type for a member function's default parameter used as a Boolean, and comment it at call sites where the default is overridden. * src/roff/troff/token.h (token::get_char): Change type of parameter from `int` to `bool` and default from 0 to `false`. * src/roff/troff/input.cpp (token::get_char): Update definition. * src/roff/troff/env.cpp (hyphen_word): * src/roff/troff/node.cpp (remove_font_special_character): * src/roff/troff/input.cpp (do_overstrike, do_bracket, next, do_define_character, remove_character, get_line_arg, encode_char, do_if_request, do_translate, char_flags, hyphenation_code, define_class): Update call sites. Add comment indicating meaning of parameter.
* Update copyright1.23.0.rc1Bertrand Garrigues2020-11-111-1/+1
| | | | | | | | * update-copyright.sh: use gnulib's 'update-copyright' script. Pass this script in directories 'arch', 'contrib', 'font', 'man', 'tmac', 'src' and on a list of extra files. * FOR-RELEASE: mention this point.
* Revert "Update copyright"Bertrand Garrigues2020-10-251-1/+1
| | | | | | This reverts commit a2e955e07354c83939fabffebcf720d3333d1f6b. Some files (COPYING, FDL, bootstrap) should not have been updated
* Update copyrightBertrand Garrigues2020-10-251-1/+1
| | | | | | | | Use gnulib's update-copyright script. * src/roff/groff/groff.cpp: update the printf displayed when 'groff -v' is invoked. * FOR-RELEASE: mention this point.
* node.h: do not rely on C++11 features, fixes build with gcc 4.2.1Ingo Schwarze2020-10-151-0/+1
| | | | | fixes https://savannah.gnu.org/bugs/?59270 OK gbranden@
* src/roff/troff/node.cpp: Expand diagnostics.G. Branden Robinson2020-10-081-6/+13
| | | | | | | | | | | | | | | | | | | | | * src/roff/troff/node.cpp: Make diagnostics slightly more informative in unusual error cases. (real_output_file::~real_output_file): If ferror() reports error status on a stream say that, instead of "error writing". If it does not, but fflush() fails on the stream, describe the flush as failing, and use strerror() since fflush() sets errno. If pclose() fails, say that we were unable to close a pipe instead of repeating the name of the C library function to the user, who might not be a C programmer. Report sterror() in this case and for a failing fclose(). (real_output_file::flush): Repeat updated fflush() logic from previous function. Also copy a cautionary comment preceding the fflush() failure logic between the functions. The changes arose while I was investigating Savannah #59202.
* Update editor aids in some C++ source files.G. Branden Robinson2020-10-081-1/+6
| | | | | | | | Assist Vim as well as Emacs, and set fill-column/textwidth to 72, like other groff source files. Use Vim settings that work well with GNU indentation style. Drop short-form Emacs Local Variable setting.
* Fix SEGV arising from recursing destructor.G. Branden Robinson2020-09-291-0/+2
| | | | | | | | | | | | | | | | * src/roff/troff/node.h (output_file): Add class member `is_dying` to track whether destructor has already been entered; initialize false. * src/roff/troff/node.cpp (real_output_file::~real_output_file): Set `is_dying` true when destructor entered. * src/roff/troff/div.cpp (cleanup_and_exit): Only delete `the_output` object if it is not already being destroyed. Thanks to "hackerb9" for reporting the problem. Problem appears to date back to groff 1.02 (June 1991) or earlier. Fixes <https://savannah.gnu.org/bugs/index.php?59202>.
* Remove embedded newlines from diagnostic messages.G. Branden Robinson2020-09-191-2/+2
| | | | | | | | | | | | | | | | * src/preproc/grn/main.cpp (conv): * src/roff/troff/node.cpp (suppress_node::tprint): Remove embedded newlines from diagnostic messages. Also rephrase grn diagnostic to more closely resemble its others: error("no picture filename at line %1", baseline); error("bad font size value at line %1", linenum); error("no fontname specified in line %1", linenum); error("bad stipple number %1 at line %2", idx, linenum); error("bad stipple index value at line %1", linenum); error("bad adjust command at line %1", linenum); error("invalid scale value on line %1", linenum); error("unknown command '%1' on line %2", str1, linenum);
* Update copyright (use gnulib's update-copyright script)Bertrand Garrigues2018-07-031-1/+1
|
* src: Fix `quote style' in comments and plaintext.G. Branden Robinson2017-11-091-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/include/include.am: * src/libs/libbib/libbib.am: * src/libs/libdriver/libdriver.am: * src/libs/libgroff/libgroff.am: * src/libs/libxutil/libxutil.am: * src/roff/groff/groff.am: * src/roff/grog/grog.am: * src/roff/troff/troff.am: * src/utils/addftinfo/addftinfo.am: * src/utils/afmtodit/afmtodit.am: * src/utils/hpftodit/hpftodit.am: + Update and parallelize editor aid comments. * src/include/font.h: * src/libs/libdriver/input.cpp: * src/libs/libgroff/glyphuni.cpp * src/libs/libgroff/quotearg.c: * src/libs/libgroff/spawnvp.c: * src/preproc/grn/main.cpp: * src/preproc/pic/object.cpp: * src/roff/troff/dictionary.cpp: * src/roff/troff/div.cpp: * src/roff/troff/token.h: * src/roff/troff/troff.am: + Remove trailing whitespace from lines near other changes. Signed-off-by: G. Branden Robinson <g.branden.robinson@gmail.com>
* src: Migrate diagnostics away from `these quotes'.G. Branden Robinson2017-11-091-9/+9
| | | | | | Fix bug https://savannah.gnu.org/bugs/?52374. Signed-off-by: G. Branden Robinson <g.branden.robinson@gmail.com>
* Put two spaces between sentences in GPL notice.G. Branden Robinson2017-10-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | Fixes half of Savannah #51609 but applies it much more generally. This is a wide-ranging change, but it makes these notices consistent with modern copies of the GPLv3 text. (Some of these files are not GPLv3, but that's where the boilerplate comes from; GPLv2 and LGPLv2.x used semicolons to separate these clauses instead.) If the next resync with Autotools regresses some of these, well, that's a bug in Autotools. I checked with wc -L, and no file grew its longest line to 81 characters due to this change. contrib/hdtbl/hdmisc.tmac-u only: Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is> Blame me for the rest. Signed-off-by: G. Branden Robinson <g.branden.robinson@gmail.com>
* Fix many malloc/new vs. free/delete/delete[] mismatches (#47164)Bálint Réczey2016-02-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/devices/grops/ps.cpp (ps_font::~ps_font, ps_printer::define_encoding): Use `free'. * src/devices/grops/psrm.cpp (resource::~resource, resource_manager::output_prolog, resource_manager::supply_resource, resource_manager::read_download_file): Ditto. * src/include/ptable.h (PTABLE::~PTABLE, PTABLE::define): Ditto. * src/libs/libgroff/searchpath.cpp (search_path::open_file_cautious): Ditto. * src/libs/libgroff/string.cpp: Include `stdlib.h'. (string::extract): Use `malloc'. * src/preproc/eqn/box.cpp (quoted_text_box::~quoted_text_box): Use `free'. * src/preproc/eqn/lex.cpp (definition::~definition, macro_input::~macro_input, top_input::~top_input, do_definition): Ditto. * src/preproc/eqn/main.cpp (main): Ditto. * src/preproc/eqn/other.cpp: Include `stdlib.h'. (size_box::~size_box, font_box::~font_box): Use `free'. * src/preproc/eqn/text.cpp: Include `stdlib.h'. (box::set_spacing_type, special_char_box::~special_char_box, split_text): Use `free'. * src/preproc/grn/main.cpp (conv): Use `free'. * src/preproc/html/pre-html.cpp (get_resolution): Ditto. * src/preproc/pic/lex.cpp (macro_input::~macro_input, argument_macro_input::~argument_macro_input, for_input::~for_input): Ditto. * src/preproc/pic/main.cpp (do_picture): Ditto. * src/preproc/pic/object.cpp: Include `stdlib.h'. (text_piece::~text_piece, string_list::~string_list): Use `free'. * src/preproc/pic/pic.ypp (placeless_element, element, text, label, expr_not_lower_than): Ditto. * src/preproc/pic/troff.cpp (troff_output::reset_color): Ditto. * src/preproc/preconv/preconv.cpp (check_coding_tag): Ditto. * src/preproc/soelim/soelim.cpp (do_file): Ditto. * src/preproc/tbl/table.cpp (text_entry::~text_entry): Ditto. * src/roff/groff/groff.cpp (possible_command::~possible_command, possible_command::set_name): Ditto. * src/roff/troff/env.cpp (hyphen_trie::read_patterns_file): Ditto. * src/roff/troff/node.cpp (suppress_node::tprint): Ditto.
* Simplify memory allocation (#47162).Bálint Réczey2016-02-161-55/+0
| | | | | | | | | | | | | | | | | | | | | | Many invalid memory accesses were caught by UBSAN (e.g., invalid memory access in `small_temp_iterator::operator new') while bootstrapping hardened1-linux-amd64 Debian port in the `free_list' handling because it doesn't properly handle the padding between array elements. Some places were already #if 0-d out anyway. * src/roff/troff/input.cpp (small_temp_iterator): Remove class. (make_temp_iterator): Use `temp_iterator' only. * src/devices/grotty/tty.cpp (tty_glyph): Remove `free_list', `new', and `delete'. * src/include/color.h, src/include/color.cpp (color): Ditto. * src/roff/troff/env.cpp (tab): Ditto. * src/roff/troff/node.cpp (glyph_node): Ditto.
* src/roff/troff/*: Improve the license information.Bernd Warken2014-09-181-3/+1
|
* Replace patch from 2010-12-18 with a much faster implementation.Werner LEMBERG2010-12-201-262/+53
| | | | | | | | | | | | | | | | | | | * src/roff/troff/node.h (node): Add virtual function `get_break_code'. * src/roff/troff/node.cpp (inter_char_space_node): Remove class completely. (glyph_node::merge_glyph_node): Restore previous version. (break_char_node): Add `prev_break_code' field and update constructors. (node::get_break_code, break_char_node::get_break_code): Implement. (node::add_char): Pass remaining cflags values. (break_char_node::add_self): Use the logic of the now deleted `inter_char_space_node::add_self' function to insert a space node if necessary.
* Improve CJK support with new values for `.cflags'.Werner LEMBERG2010-12-181-6/+252
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces three new values to `.cflags': don't break before character: 128 don't break after character: 256 allow inter-character break: 512 They are handled differently if compared to other cflags values: (1) hcode values are completely ignored (2) similar to kern values, and contrary to the other cflags values, troff looks at pairs of characters to decide whether a break gets inserted A yet-to-be-written patch should add inter-character spacing if those flags are active; currently, only zero-width breakpoints are inserted. * src/roff/troff/charinfo.h (charinfo): Change type of `flags' to `int'. Update callers accordingly. New enum values `DONT_BREAK_BEFORE', `DONT_BREAK_AFTER', and `INTER_CHAR_SPACE'. New member functions `prohibit_break_before', `prohibit_break_after', and `inter_char_space'. * src/roff/troff/input.cpp: Updated. * src/roff/troff/node.cpp (inter_char_space_node): New class similar to kern_pair_node, collecting charinfo entities with the abovementioned cflags values. (break_char_type): Add new enum values. (glyph_node::merge_glyph_node): Handle abovementioned cflags values and emit an `inter_char_space_node' if necessary. * tmac/ja.tmac: Use new cflags values. * doc/groff.texinfo, NEWS, man/groff_diff.man: Document new values.
* Fix compilation problem.Werner LEMBERG2010-12-151-8/+0
| | | | | | | | This issue happens with gcc 4.2.4. * src/roff/troff/node.cpp (node::~node): Move to... * src/roff/troff/node.h: Here. This ensures that the inline member function is publicly visible.
* Remove unused code.Werner LEMBERG2010-12-151-5/+0
| | | | | * src/roff/troff/node.cpp, src/roff/troff/node.h (space_node::space_node): Remove unused constructor.
* Use enum to increase readability.Werner LEMBERG2010-12-151-7/+13
| | | | | * src/roff/troff/node.cpp (break_char_type): New enum. (break_char_node::add_self, node::add_char): Use it.
* * src/roff/troff/node.cpp (make_node): Adding missing `%'.Werner LEMBERG2010-06-281-1/+1
| | | | | Reported in http://lists.gnu.org/archive/html/bug-groff/2010-06/msg00022.html
* Don't use obsolete intermediate output command `F'.Werner LEMBERG2010-05-281-2/+2
| | | | | | | Reported by Krzysztof Zelechowski <giecrilj@stegny.2a.pl> * src/roff/troff/nodes.cpp (troff_output_file::really_put_filename): Replace `F' command with `x F'.