From 7058c14b1e8ae4184d8bbbd29df725abf38371b9 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 7 Oct 2018 19:40:20 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3394 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/ppm/xvminitoppm.c | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/converter/ppm/xvminitoppm.c b/converter/ppm/xvminitoppm.c index 0da1515e..34a0f9b5 100644 --- a/converter/ppm/xvminitoppm.c +++ b/converter/ppm/xvminitoppm.c @@ -13,12 +13,13 @@ #include #include #include +#include #include "pm_c_util.h" #include "nstring.h" +#include "pm.h" #include "ppm.h" -#define BUFSIZE 256 typedef struct xvPalette { @@ -52,25 +53,6 @@ parseCommandLine(int const argc, -static void -getLine(FILE * const ifP, - char * const buf, - size_t const size) { - - char * rc; - - rc = fgets(buf, size, ifP); - if (rc == NULL) { - if (ferror(ifP)) - pm_error("read error. fgets() failed, errno=%d (%s)", - errno, strerror(errno)); - else - pm_error("unexpected EOF"); - } -} - - - static void makeXvPalette(xvPalette * const xvPaletteP) { @@ -102,36 +84,54 @@ readXvHeader(FILE * const ifP, unsigned int * const rowsP, unsigned int * const maxvalP) { - char buf[256]; + char * buf; + size_t bufferSz; + int eof; + size_t lineLen; unsigned int cols, rows, maxval; int rc; bool endOfComments; - getLine(ifP, buf, sizeof(buf)); + buf = NULL; /* initial value */ + bufferSz = 0; /* initial value */ + + pm_getline(ifP, &buf, &bufferSz, &eof, &lineLen); + if (eof) + pm_error("Unexpected EOF"); if (!strneq(buf, "P7 332", 6)) pm_error("Input is not a XV thumbnail picture. It does not " "begin with the characters 'P7 332'."); - endOfComments = FALSE; - while (!endOfComments) { - getLine(ifP, buf, sizeof(buf)); + for (endOfComments = false; !endOfComments; ) { + int eof; + size_t lineLen; + pm_getline(ifP, &buf, &bufferSz, &eof, &lineLen); + if (eof) + pm_error("Unexpected EOF"); if (strneq(buf, "#END_OF_COMMENTS", 16)) - endOfComments = TRUE; + endOfComments = true; else if (strneq(buf, "#BUILTIN", 8)) pm_error("This program does not know how to " "convert builtin XV thumbnail pictures"); } - getLine(ifP, buf, sizeof(buf)); + pm_getline(ifP, &buf, &bufferSz, &eof, &lineLen); + if (eof) + pm_error("Unexpected EOF"); + rc = sscanf(buf, "%u %u %u", &cols, &rows, &maxval); if (rc != 3) pm_error("error parsing dimension info '%s'. " "It does not consist of 3 decimal numbers.", buf); if (maxval != 255) pm_error("bogus XV thumbnail maxval %u. Should be 255", maxval); + *colsP = cols; *rowsP = rows; *maxvalP = maxval; + + if (buf) + free(buf); } -- cgit 1.4.1