diff options
Diffstat (limited to 'other/ppmsvgalib.c')
-rw-r--r-- | other/ppmsvgalib.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/other/ppmsvgalib.c b/other/ppmsvgalib.c index c5700992..e106280b 100644 --- a/other/ppmsvgalib.c +++ b/other/ppmsvgalib.c @@ -6,7 +6,7 @@ By Bryan Henderson, San Jose CA 2002.01.06. Contributed to the public domain. - + ******************************************************************************/ #define _XOPEN_SOURCE /* Make sure modern signal stuff is in signal.h */ @@ -20,6 +20,7 @@ #include "pm_c_util.h" #include "ppm.h" #include "shhopt.h" +#include "mallocvar.h" struct cmdlineInfo { /* All the information the user supplied in the command line, @@ -37,7 +38,7 @@ parseCommandLine (int argc, char ** argv, struct cmdlineInfo *cmdlineP) { /*---------------------------------------------------------------------------- parse program command line described in Unix standard form by argc - and argv. Return the information in the options as *cmdlineP. + and argv. Return the information in the options as *cmdlineP. If command line is internally inconsistent (invalid options, etc.), issue error message to stderr and abort program. @@ -45,15 +46,15 @@ parseCommandLine (int argc, char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def = malloc( 100*sizeof( optEntry ) ); - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; unsigned int option_def_index; unsigned int modeSpec; + MALLOCARRAY(option_def, 100); + option_def_index = 0; /* incremented by OPTENT3 */ OPTENT3(0, "mode", OPT_UINT, &cmdlineP->mode, &modeSpec, 0); @@ -83,10 +84,10 @@ parseCommandLine (int argc, char ** argv, static void -displayImage(FILE * const ifP, - int const cols, +displayImage(FILE * const ifP, + int const cols, int const rows, - pixval const maxval, + pixval const maxval, int const format, int const originCol, int const originRow) { @@ -107,7 +108,7 @@ displayImage(FILE * const ifP, pixelrow = ppm_allocrow(cols); - /* Implementation note: It might be faster to use + /* Implementation note: It might be faster to use vga_drawscansegment() instead of vga_drawpixel() */ @@ -143,13 +144,13 @@ sigintHandler(int const signal) { -static void +static void waitforSigint(void) { struct sigaction oldsigaction; struct sigaction newsigaction; int rc; - + newsigaction.sa_handler = &sigintHandler; sigemptyset(&newsigaction.sa_mask); newsigaction.sa_flags = 0; @@ -166,19 +167,19 @@ waitforSigint(void) { static void -display(FILE * const ifP, - int const cols, - int const rows, - pixval const maxval, - int const format, - int const videoMode, +display(FILE * const ifP, + int const cols, + int const rows, + pixval const maxval, + int const format, + int const videoMode, bool const verbose) { int xmax, ymax; vga_modeinfo *modeinfo; modeinfo = vga_getmodeinfo(videoMode); - + if (verbose) { pm_message("Screen Width: %d Height: %d Colors: %d", modeinfo->width, @@ -193,18 +194,18 @@ display(FILE * const ifP, if (modeinfo->colors <= 256) pm_error("This video mode has %d or fewer colors, which means " "it is colormapped (aka paletted, aka pseudocolor). " - "This program cannot drive colormapped modes.", + "This program cannot drive colormapped modes.", modeinfo->colors); if (cols > modeinfo->width) pm_error("Image is too wide (%d columns) for screen (%d columns). " - "Use Pamcut to select part to display.", + "Use Pamcut to select part to display.", cols, modeinfo->width); if (rows > modeinfo->height) pm_error("Image is too tall (%d rows) for screen (%d rows). " "Use Pamcut to select part to display.", rows, modeinfo->height); - + /* The program must not terminate after we set the video mode and before we reset it to text mode. Note that vga_setmode() sets up handlers for signals such as SIGINT that attempt to restore modes and then exit @@ -241,7 +242,7 @@ display(FILE * const ifP, -int +int main(int argc, char *argv[]) { FILE * ifP; @@ -261,7 +262,7 @@ main(int argc, char *argv[]) { { enum pm_check_code checkResult; - ppm_check(ifP, PM_CHECK_BASIC, format, cols, rows, maxval, + ppm_check(ifP, PM_CHECK_BASIC, format, cols, rows, maxval, &checkResult); } @@ -274,7 +275,7 @@ main(int argc, char *argv[]) { pm_error("Svgalib unable to allocate a virtual console."); if (vga_hasmode(cmdline.mode)) - display(ifP, cols, rows, maxval, format, + display(ifP, cols, rows, maxval, format, cmdline.mode, cmdline.verbose); else { pm_error("Svgalib video mode #%d not available. Either the " |