summaryrefslogtreecommitdiffstats
path: root/term_ascii.c
Commit message (Collapse)AuthorAgeFilesLines
* When starting a new input line, even when continuing the same outputIngo Schwarze2022-08-161-1/+1
| | | | | | line, use the current output position as the reference position for tabs on that input line. This brings mandoc in line with the behaviour of GNU, Heirloom, and Plan 9 roff.
* Distinguish between escape sequences that produce no outputIngo Schwarze2022-08-151-1/+1
| | | | | | | | | | | | | | | | | whatsoever (for example \fR) and escape sequences that produce invisible zero-width output (for example \&). No, i'm not joking, groff does make that distinction, and it has consequences in some situations, for example for vertical spacing in no-fill mode. Heirloom and Plan 9 behaviour is subtly different, but in case of doubt, we want to follow groff. While this fixes the behaviour for the majority of escape sequences, in particular for those most likely to occur in practice, it is not perfect yet because some of the more exotic ESCAPE_IGNORE sequences are actually of the "no output whatsoever" type but treated as "invisible zero-width" for now. With the new ASCII_NBRZW mechanism in place, switching them over one by one when the need arises will no longer be very difficult.
* Do not abuse assert(3) to react to absurd input; the purpose of assert(3)Ingo Schwarze2020-09-091-2/+16
| | | | | | | | only is to catch internal inconsistencies in the program itself. Issue found in an afl run performed by Jan Schreiber <jes at posteo dot de>. Instead, just cut down unreasonably wide spacing requested by the document to a narrower width.
* After .ti, there are many reasons why the offset may change, so settingIngo Schwarze2020-09-061-4/+10
| | | | | | it back later requires a guard against underflow, or subsequent assertions may fail. Issue found in an afl run performed by Jan Schreiber <jes at posteo dot de>.
* Bugfix: never set termp->enc to the ambiguous value TERMENC_LOCALE,Ingo Schwarze2018-11-281-3/+3
| | | | | | but instead set it to TERMENC_UTF8 or TERMENC_ASCII. Makes tbl(7) box drawing work under -T locale (that is, by default when LC_CTYPE is defined appropriately).
* Improve the ASCII rendering of \(Po (Pound Sterling)Ingo Schwarze2018-08-211-1/+1
| | | | | and of the playing card suits to match groff, using feedback from Ralph Corderoy <ralph at inputplus dot co dot uk>.
* Unsurprisingly, zero-width non-breaking spaces have... width 0.Ingo Schwarze2018-08-181-2/+1
|
* Protect against malicious manual pages containing .ll requests withIngo Schwarze2018-05-201-0/+6
| | | | | | | | | | | | | | excessive arguments: apply the same cutoff as for the -O width= command line argument. While here, also place some assertions at strategical places to prevent excessive indentations from being printed in case of bugs. In the past, we had more than one bug that caused mandoc to print effectively infinite output, filling up people's /tmp/ file system, which is not funny. We cannot prevent bugs from crashing the program, but we can at least make filling up the disk less likely. Triggered by a remark from sthen@ on source-changes@.
* Make sure that mandoc only goes into UTF-8 mode if the user reallyIngo Schwarze2018-04-131-2/+14
| | | | | | selected UTF-8, not some other multibyte locale. This obviously makes no difference on OpenBSD but improves portability. Issue reported by <Nakayama at NetBSD> via wiz@.
* Switch ASCII rendering of the same mathematical symbols and greekIngo Schwarze2017-08-231-5/+5
| | | | | | | | | | letters as in groff commit babca15f from trying to imitate the characters' graphical shapes, which resulted in unintelligible renderings in many cases, to transliterations conveying the characters' meanings. One benefit is making these characters usable for portable manual pages. Solving a problem pointed out by bentley@.
* harmless, but weird typo; found with afterstep_faq(1)Ingo Schwarze2017-06-141-1/+1
|
* Prepare the terminal driver for filling multiple columns in parallel,Ingo Schwarze2017-06-071-7/+9
| | | | | | first step: split column data out of the terminal state struct into a new column state struct and use an array of such column state structs. No functional change.
* Basic implementation of the roff(7) .ti (temporary indent) request.Ingo Schwarze2017-05-081-1/+5
| | | | Needed by about four dozen ports (thanks to naddy@ for the research).
* Basic implementation of the roff(7) .ta (define tab stops) request.Ingo Schwarze2017-05-071-1/+0
| | | | | | This is the first feature made possible by the parser reorganization. Improves the formatting of the SYNOPSIS in many Xenocara GL manuals. Also important for ports, as reported by many, including naddy@.
* Autodetect a suitable locale for -Tutf8 mode,Ingo Schwarze2016-07-311-1/+1
| | | | | | | and allow overriding it manually. Based on a patch from Svyatoslav Mishyn <juef at openmailbox dot org> tweaked by me. The idea originally came up in a conversation with Markus Waldeck.
* ISO C99 7.19.2.5 doesn't like mixing putchar(3) and putwchar(3) onIngo Schwarze2016-07-081-6/+5
| | | | | | the same stream, and actually, it fails spectacularly on glibc. Portability issue pointed out by Svyatoslav Mishyn <juef at openmailbox dot org> after testing on Void Linux.
* Never use LC_ALL. On the one hand, it can cause misformatting.Ingo Schwarze2015-11-121-1/+9
| | | | | On the other hand, it is a security risk because it might cause buffer overflows. Use LC_CTYPE only, that's all we need.
* Major character table cleanup:Ingo Schwarze2015-10-131-11/+8
| | | | | | | | | | | | | * Use ohash(3) rather than a hand-rolled hash table. * Make the character table static in the chars.c module: There is no need to pass a pointer around, we most certainly never want to use two different character tables concurrently. * No need to keep the characters in a separate file chars.in; that merely encourages downstream porters to mess with them. * Sort the characters to agree with the mandoc_chars(7) manual page. * Specify Unicode codepoints in hex, not decimal (that's the detail that originally triggered this patch). No functional change, minus 100 LOC, and i don't see a performance change.
* To make the code more readable, delete 283 /* FALLTHROUGH */ commentsIngo Schwarze2015-10-121-2/+0
| | | | | | that were right between two adjacent case statement. Keep only those 24 where the first case actually executes some code before falling through to the next case.
* modernize style: "return" is not a functionIngo Schwarze2015-10-061-9/+9
|
* /* NOTREACHED */ after abort() is silly, delete itIngo Schwarze2015-09-261-1/+0
|
* Initial, still somewhat experimental implementation to leverageIngo Schwarze2015-07-171-0/+4
| | | | | | | | | | | | | | | less(1) -T and :t ctags(1)-like functionality to jump to the definitions of various terms inside manual pages. To be polished in the tree, so bear with me and report issues. Technically, if less(1) is used as a pager, information is collected by the mdoc(7) terminal formatter, first stored using the ohash library, then ultimately written to a temporary file which is passed to less via -T. No change intended for other output formatters or when running without a pager. Based on an idea from Kristaps using feedback from many, in particular phessler@ nicm@ millert@ halex@ doug@ kspillner@ deraadt@.
* Avoid warning "unused variable" when compiling without HAVE_WCHAR.Ingo Schwarze2015-06-101-0/+2
| | | | Issue found on Debian by Markus <Waldeck at gmx dot de>.
* Rounding rules for horizontal scaling widths are more complicated.Ingo Schwarze2015-04-041-24/+18
| | | | | | | | | | | | | There is a first rounding to basic units on the input side. After that, rounding rules differ between requests and macros. Requests round to the nearest possible character position. Macros round to the next character position to the left. Implement that by changing the return value of term_hspan() to basic units and leaving the second scaling and rounding stage to the formatters instead of doing it in the terminal handler. Improves for example argtable2(3).
* Actually use the new man.conf(5) "output" directive.Ingo Schwarze2015-03-271-48/+21
| | | | Additional functionality, yet minus 45 lines of code.
* Clamp width and indent settings to sensible values.Ingo Schwarze2015-02-161-2/+8
| | | | | Ignore errors for now. Patch from tedu@.
* When showing more than one formatted manual page, insert horizontal linesIngo Schwarze2014-12-311-0/+14
| | | | | | between pages. Suggested by Theo Buehler <theo at math dot ethz dot ch>. Even in UTF-8 output mode, do not use fancy line drawing characters such that you can easily use /^--- to skip to the next manual in your pager.
* Enforcing an arbitrary, implementation dependent, undocumented limitIngo Schwarze2014-12-191-0/+3
| | | | | | by calling assert() when valid user input exceeds it is a bad idea. Allocate the terminal font stack dynamically instead of crashing above 10 entries. Issue found by jsg@ with afl.
* Prevent negative arguments to the .ll request from causing integerIngo Schwarze2014-11-201-3/+5
| | | | | | | | | underflow. Found while preparing an audit of termp.rmargin. Overflow can also happen, but i see no sane way to deal with it, so just let it happen. It doesn't happen for any sane input anyway, groff behaviour is undefined, and the resulting values are legal, even though they are useless.
* In -Tascii mode, print "<?>" only for Unicode escapes of unknownIngo Schwarze2014-10-281-2/+2
| | | | | | representation, not for character escapes with unknown names. According to groff, the latter produce no output, and we now warn about them.
* Make the character table available to libroff so it can check theIngo Schwarze2014-10-281-8/+10
| | | | | | | | validity of character escape names and warn about unknown ones. This requires mchars_spec2cp() to report unknown names again. Fortunately, that doesn't require changing the calling code because according to groff, invalid character escapes should not produce output anyway, and now that we warn about them, that's fine.
* Refine -Tascii rendering of Unicode characters, mostly to better agreeIngo Schwarze2014-10-281-34/+34
| | | | | | | | | with groff, in particular in cases where groff uses backspace overstrike. In two cases, agreement is impossible because groff clobbers the previous line: \(*G \(*S In a number of cases, groff rendering is so misleading that i chose to render differently: \(Sd \(TP \(Tp \(Po \(ps \(sc \(r! \(r? \(de While here, also correct the \(la and \(ra Unicode code points.
* Grrr, patch(1) merged the new function to the wrong place in this file.Ingo Schwarze2014-10-261-77/+77
| | | | Resync with OpenBSD. No code change.
* In -Tascii mode, provide approximations even for some Unicode escapeIngo Schwarze2014-10-261-2/+4
| | | | | | | | sequences above codepoint 512 by doing a reverse lookup in the existing mandoc_char(7) character table. Again, groff isn't smart enough to do this and silently discards such escape sequences without printing anything.
* Improve -Tascii output for Unicode escape sequences: For the first 512Ingo Schwarze2014-10-261-0/+75
| | | | | | | | | | | | code points, provide ASCII approximations. This is already much better than what groff does, which prints nothing for most code points. A few minor fixes while here: * Handle Unicode escape sequences in the ASCII range. * In case of errors, use the REPLACEMENT CHARACTER U+FFFD for -Tutf8 and the string "<?>" for -Tascii output. * Handle all one-character escape sequences in mchars_spec2{cp,str}() and remove the workarounds on the higher level.
* Implement the traditional -h option for man(1): show the SYNOPSIS only.Ingo Schwarze2014-09-031-2/+6
| | | | | | | As usual, we get mandoc -h and apropos -h for free. Try stuff like "apropos -h In=dirent" or "apropos -h Fa=timespec". Only useful for terminal output, so -Tps, -Tpdf, -Thtml ignore -h for now.
* While all current callers pass valid data to ascii_hspan() only,Ingo Schwarze2014-08-171-1/+1
| | | | | | it's safer to assume incoming enum data might be invalid and catch it instead of happily returning an unitialized int. No functional change right now.
* Improve build system and autodetection.Ingo Schwarze2014-08-161-16/+5
| | | | | | | | | * Make ./configure standalone, that's what people expect. * Let people write a ./configure.local from scratch, not edit existing files. * Autodetect wchar, sqlite3, and manpath and act accordingly. * Autodetect the need for -L/usr/local/lib and -lutil. * Get rid of config.h.p{re,ost}, let ./configure only write what's needed. * Let ./configure write a Makefile.local snippet, that's quite flexible.
* Some compilers apparently worry that abort() might returnIngo Schwarze2014-08-141-1/+2
| | | | | | and then throw a "may be used uninitialized" warning, so sprinkle some /* NOTREACHED */. No functional change. Noticed by Thomas Klausner <wiz at NetBSD dot org>.
* Begin cleaning up scaling units.Kristaps Dzonsons2014-08-131-10/+20
| | | | | | | | | Start with the horizontal terminal specifiers, making sure that they match up with troff. Then move on to PS, PDF, and HTML, noting that we stick to the terminal default width for "u". Lastly, fix some completely-wrong documentation and note that we diverge from troff w/r/t "u".
* Get rid of HAVE_CONFIG_H, it is always defined; idea from libnbcompat.Ingo Schwarze2014-08-101-4/+2
| | | | | | Include <sys/types.h> where needed, it does not belong in config.h. Remove <stdio.h> from config.h; if it is missing somewhere, it should be added, but i cannot find a *.c file where it is missing.
* Clarity with respect to floating point handling:Ingo Schwarze2014-08-011-6/+6
| | | | | | Write double constants as double rather than integer literals. Remove useless explicit (double) cast done at one place and nowhere else. No functional change.
* Even for UTF-8 output, a non-breaking space character has the same widthIngo Schwarze2014-07-271-1/+6
| | | | as a normal space character, and not width 0. Bug reported by bentley@.
* KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze2014-04-201-25/+16
| | | | | remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
* Support relative arguments to .ll (increase or decrease line length).Ingo Schwarze2014-03-301-7/+11
|
* Implement the roff(7) .ll (line length) request.Ingo Schwarze2014-03-301-1/+15
| | | | | Found by naddy@ in the textproc/enchant(1) port. Of course, do not use this in new manuals.
* The files mandoc.c and mandoc.h contained both specialised low-levelIngo Schwarze2014-03-231-1/+1
| | | | | | | functions used for multiple languages (mdoc, man, roff), for example mandoc_escape(), mandoc_getarg(), mandoc_eos(), and generic auxiliary functions. Split the auxiliaries out into their own file and header. While here, do some #include cleanup.
* Use a standard locale name, "UTF-8" is an ugly non-standard aliasIngo Schwarze2013-06-011-2/+1
| | | | | that doesn't work on OpenBSD. OK tedu@ naddy@
* Implement mdoc(7)-like output style variant for man(7) documents:Ingo Schwarze2011-12-041-2/+11
| | | | | | | | | | | * one instead of three blank lines after the page header; * one instead of three blank lines before the page footer; * source instead of title(section) in the lower right corner. Select this style variant with the undocumented command line option -Omdoc. In the long run, we hope to unify the ouput of both languages and to pull this out again, but that requires coordination with groff. Grudgingly ok and, (as usual,-) more comments requested by kristaps@
* Make the default left text margin configurable from the command line,Ingo Schwarze2011-11-131-3/+7
| | | | | | | just like the default right margin already is. This may be useful for people with expensive screen real estate. Besides, it helps automated man(7) to mdoc(7) output comparisons to validate -Tman output. ok kristaps@ on an earlier version