about summary refs log tree commit diff
path: root/generator/pbmtext.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-02-17 03:12:02 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-02-17 03:12:02 +0000
commit8f5364cc0b1be8b669213d1001f4e1ac9c8f0051 (patch)
treebc3c666e95d6a2f57541abf192308440bebba82d /generator/pbmtext.c
parent4f706b144aa49b1b094a0422c9df628e86341391 (diff)
downloadnetpbm-mirror-8f5364cc0b1be8b669213d1001f4e1ac9c8f0051.tar.gz
netpbm-mirror-8f5364cc0b1be8b669213d1001f4e1ac9c8f0051.tar.xz
netpbm-mirror-8f5364cc0b1be8b669213d1001f4e1ac9c8f0051.zip
Add -text-dump option
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3149 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator/pbmtext.c')
-rw-r--r--generator/pbmtext.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/generator/pbmtext.c b/generator/pbmtext.c
index e25c6bbe..b6ead391 100644
--- a/generator/pbmtext.c
+++ b/generator/pbmtext.c
@@ -41,8 +41,9 @@ struct CmdlineInfo {
     int lspace;           /* -lspace option value or default */
     unsigned int width;   /* -width option value or zero */
     unsigned int nomargins;  /* -nomargins option specified  */
-    unsigned int dryrun;  /* -dry-run option specified */ 
-    unsigned int verbose; /* -verbose option specified */
+    unsigned int dryrun;     /* -dry-run option specified */ 
+    unsigned int textdump;   /* -text-dump option specified */ 
+    unsigned int verbose;    /* -verbose option specified */
         /* undocumented option */
     unsigned int dumpsheet; /* font data sheet in PBM format for -font */   
 };
@@ -74,6 +75,7 @@ parseCommandLine(int argc, const char ** argv,
     OPTENT3(0, "nomargins",  OPT_FLAG,   NULL, &cmdlineP->nomargins, 0);
     OPTENT3(0, "verbose",    OPT_FLAG,   NULL, &cmdlineP->verbose,   0);
     OPTENT3(0, "dry-run",    OPT_FLAG,   NULL, &cmdlineP->dryrun,    0);
+    OPTENT3(0, "text-dump",  OPT_FLAG,   NULL, &cmdlineP->textdump,  0);
     OPTENT3(0, "dump-sheet", OPT_FLAG,   NULL, &cmdlineP->dumpsheet, 0);
 
     /* Set the defaults */
@@ -106,6 +108,16 @@ parseCommandLine(int argc, const char ** argv,
     else if (cmdlineP->lspace < -pbm_maxfontheight())
         pm_error("negative -lspace value too large");
 
+    if (cmdlineP->textdump) {
+        if (cmdlineP->dryrun)
+            pm_error("You cannot specify both -dry-run and -text-dump");
+        else if (cmdlineP->dumpsheet)
+            pm_error("You cannot specify both -dump-sheet and -text-dump");
+    }
+
+    if (cmdlineP->dryrun && cmdlineP->dumpsheet)
+        pm_error("You cannot specify both -dry-run and -dump-sheet");
+
     if (argc-1 == 0)
         cmdlineP->text = NULL;
     else {
@@ -215,6 +227,9 @@ computeFont(struct CmdlineInfo const cmdline,
 
 struct Text {
     char **      textArray;  /* malloc'ed */
+        /* This is strictly characters that are in user's font - no control
+           characters, no undefined code points.
+        */
     unsigned int allocatedLineCount;
     unsigned int lineCount;
 };
@@ -743,7 +758,18 @@ getText(char          const cmdlineText[],
         struct font * const fontP,
         struct Text * const inputTextP,
         enum FixMode  const fixMode) {
+/*----------------------------------------------------------------------------
+   Get as *inputTextP the text to format, given that the text on the
+   command line (one word per command line argument, separated by spaces),
+   is 'cmdlineText'.
 
+   If 'cmdlineText' is null, that means to get the text from Standard Input.
+   Otherwise, 'cmdlineText' is that text.
+
+   But we return text as only renderable characters - characters in *fontP -
+   with control characters interpreted or otherwise fixed, according to
+   'fixMode'.
+-----------------------------------------------------------------------------*/
     struct Text inputText;
 
     if (cmdlineText) {
@@ -1027,6 +1053,22 @@ dryrunOutput(unsigned int const cols,
 
 
 static void
+textDumpOutput(struct Text   const lp,
+               FILE *        const ofP) {
+/*----------------------------------------------------------------------------
+   Output the text 'lp' as characters.  (Do not render.)
+-----------------------------------------------------------------------------*/
+    unsigned int line;  /* Line number in input text */
+
+    for (line = 0; line < lp.lineCount; ++line) {
+        fputs(lp.textArray[line], ofP);
+        fputc('\n', ofP);
+    }
+}
+
+
+
+static void
 pbmtext(struct CmdlineInfo const cmdline,
         struct font *      const fontP,
         FILE *             const ofP) {
@@ -1078,6 +1120,8 @@ pbmtext(struct CmdlineInfo const cmdline,
 
     if (cmdline.dryrun)
         dryrunOutput(cols, rows, ofP);
+    else if (cmdline.textdump)
+        textDumpOutput(formattedText, ofP);
     else 
         renderText(cols, rows, fontP, hmargin, vmargin, formattedText,
                    maxleftb, cmdline.space, cmdline.lspace, FALSE, ofP);