From fd3467dd9ea17c4ea25b4b2aa2fc0f3762bd8ec2 Mon Sep 17 00:00:00 2001 From: Piotr Kubowicz Date: Sat, 16 Dec 2023 20:24:14 +0100 Subject: [PATCH] Handle unterminated \verb Closes #82 --- detex.l | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/detex.l b/detex.l index ad07968..86a0138 100644 --- a/detex.l +++ b/detex.l @@ -349,16 +349,28 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ footnoteLevel = currBracesLevel; ++currBracesLevel; } -"\\verb" /* ignore \verb... */ { if (fLatex) { - char verbchar, c; - verbchar = input(); - while ((c = input()) != verbchar) - /*if (c == '\n') - NEWLINE;*/ - putchar(c); - } - IGNORE; - } +"\\verb" /* ignore \verb... */ { + if (fLatex) { + char verbchar, c; + verbchar = input(); + if (verbchar < ' ') { + /* would be nice to include input filenames and line numbers */ + ErrorExit("\\verb not complete before eof"); + } + while ((c = input()) != verbchar && c != '\n' && c != EOF && c != 0) { + putchar(c); + } + if (verbchar == EOF || c == EOF) { + ErrorExit("\\verb not complete before eof"); + } + if (c == '\n') { + char delim[2]; + delim[0] = verbchar; + delim[1] = 0; + Warning("\\verb not terminated before eol, delimiter", delim); + } + } +} "\\newcommand" { LATEX; KILLARGS(2); } "\\renewcommand" { LATEX; KILLARGS(2); }