From bda0c167e13282185609619c63dd0b12164ae3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 15 Jun 2022 18:29:41 +0200 Subject: Rename to lightroff. --- lightroff.lex | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lightroff.lex (limited to 'lightroff.lex') diff --git a/lightroff.lex b/lightroff.lex new file mode 100644 index 0000000..9326415 --- /dev/null +++ b/lightroff.lex @@ -0,0 +1,72 @@ +%option noyywrap +%x NEW +%x REQ +%x RAW +%x ESC +%x RES + +%% + +\\ BEGIN(ESC); +^\n* /* Ignore newlines at beginning of file. */ +\n BEGIN(NEW); +\\n* /* Ignore comment. */ +^< printf("."); BEGIN(REQ); /* Beginning of file. */ +\< printf("\\c\n."); BEGIN(REQ); +. ECHO; + + /* Handle text following newlines. */ + +\n /* Ignore consecutive newlines. */ +\\ printf("\n"); BEGIN(ESC); + /* Ignore comment. */ +< printf("\n."); BEGIN(REQ); +\. printf("\n\\&."); BEGIN(0); +. printf("\n"); BEGIN(0); REJECT; + + /* Translate request. */ + +\\ BEGIN(RES); +> BEGIN(NEW); + + /* Pass through raw troff code. */ + +\n\]> BEGIN(NEW); +\]> BEGIN(0); +. ECHO; + + /* Escape next character. */ + +\\ printf("\\\\"); BEGIN(0); +< ECHO; BEGIN(0); +. printf("\\"); ECHO; BEGIN(0); + + /* Escape next character within request. */ + +\\ printf("\\\\"); BEGIN(REQ); +> ECHO; BEGIN(REQ); +. printf("\\"); ECHO; BEGIN(REQ); + +%% + +int +main() +{ + char *st; + + yylex(); + + switch (YYSTATE) { + case 0: return 0; + case NEW: printf("\n"); return 0; + case REQ: st = "request"; break; + case RAW: st = "raw section"; break; + case ESC: st = "escape"; break; + case RES: st = "escape (within request)"; break; + } + + fprintf(stderr, "%s unfinished\n", st); + return 1; +} -- cgit v1.2.3