Lines 123-129
Link Here
|
123 |
|
123 |
|
124 |
|
124 |
|
125 |
static void |
125 |
static void |
126 |
getline(char * const line, |
126 |
xpmtoppm_getline(char * const line, |
127 |
size_t const size, |
127 |
size_t const size, |
128 |
FILE * const stream) { |
128 |
FILE * const stream) { |
129 |
/*---------------------------------------------------------------------------- |
129 |
/*---------------------------------------------------------------------------- |
Lines 141-147
Link Here
|
141 |
Exit program if the line doesn't fit in the buffer. |
141 |
Exit program if the line doesn't fit in the buffer. |
142 |
-----------------------------------------------------------------------------*/ |
142 |
-----------------------------------------------------------------------------*/ |
143 |
if (size > sizeof(lastInputLine)) |
143 |
if (size > sizeof(lastInputLine)) |
144 |
pm_error("INTERNAL ERROR: getline() received 'size' parameter " |
144 |
pm_error("INTERNAL ERROR: xpmtoppm_getline() received 'size' parameter " |
145 |
"which is out of bounds"); |
145 |
"which is out of bounds"); |
146 |
|
146 |
|
147 |
if (backup) { |
147 |
if (backup) { |
Lines 387-393
Link Here
|
387 |
int * const transparentP) { |
387 |
int * const transparentP) { |
388 |
/*---------------------------------------------------------------------------- |
388 |
/*---------------------------------------------------------------------------- |
389 |
Read the header of the XPM file on stream 'stream'. Assume the |
389 |
Read the header of the XPM file on stream 'stream'. Assume the |
390 |
getline() stream is presently positioned to the beginning of the |
390 |
xpmtoppm_getline() stream is presently positioned to the beginning of the |
391 |
file and it is a Version 3 XPM file. Leave the stream positioned |
391 |
file and it is a Version 3 XPM file. Leave the stream positioned |
392 |
after the header. |
392 |
after the header. |
393 |
|
393 |
|
Lines 423-447
Link Here
|
423 |
unsigned int * ptab; |
423 |
unsigned int * ptab; |
424 |
|
424 |
|
425 |
/* Read the XPM signature comment */ |
425 |
/* Read the XPM signature comment */ |
426 |
getline(line, sizeof(line), stream); |
426 |
xpmtoppm_getline(line, sizeof(line), stream); |
427 |
if (strncmp(line, xpm3_signature, strlen(xpm3_signature)) != 0) |
427 |
if (strncmp(line, xpm3_signature, strlen(xpm3_signature)) != 0) |
428 |
pm_error("Apparent XPM 3 file does not start with '/* XPM */'. " |
428 |
pm_error("Apparent XPM 3 file does not start with '/* XPM */'. " |
429 |
"First line is '%s'", xpm3_signature); |
429 |
"First line is '%s'", xpm3_signature); |
430 |
|
430 |
|
431 |
/* Read the assignment line */ |
431 |
/* Read the assignment line */ |
432 |
getline(line, sizeof(line), stream); |
432 |
xpmtoppm_getline(line, sizeof(line), stream); |
433 |
if (strncmp(line, "static char", 11) != 0) |
433 |
if (strncmp(line, "static char", 11) != 0) |
434 |
pm_error("Cannot find data structure declaration. Expected a " |
434 |
pm_error("Cannot find data structure declaration. Expected a " |
435 |
"line starting with 'static char', but found the line " |
435 |
"line starting with 'static char', but found the line " |
436 |
"'%s'.", line); |
436 |
"'%s'.", line); |
437 |
|
437 |
|
438 |
/* Read the hints line */ |
438 |
/* Read the hints line */ |
439 |
getline(line, sizeof(line), stream); |
439 |
xpmtoppm_getline(line, sizeof(line), stream); |
440 |
/* skip the comment line if any */ |
440 |
/* skip the comment line if any */ |
441 |
if (!strncmp(line, "/*", 2)) { |
441 |
if (!strncmp(line, "/*", 2)) { |
442 |
while (!strstr(line, "*/")) |
442 |
while (!strstr(line, "*/")) |
443 |
getline(line, sizeof(line), stream); |
443 |
xpmtoppm_getline(line, sizeof(line), stream); |
444 |
getline(line, sizeof(line), stream); |
444 |
xpmtoppm_getline(line, sizeof(line), stream); |
445 |
} |
445 |
} |
446 |
if (sscanf(line, "\"%u %u %u %u\",", &width, &height, |
446 |
if (sscanf(line, "\"%u %u %u %u\",", &width, &height, |
447 |
&nColors, &charsPerPixel) != 4) |
447 |
&nColors, &charsPerPixel) != 4) |
Lines 475-484
Link Here
|
475 |
*transparentP = -1; /* initial value */ |
475 |
*transparentP = -1; /* initial value */ |
476 |
|
476 |
|
477 |
for (seqNum = 0; seqNum < nColors; ++seqNum) { |
477 |
for (seqNum = 0; seqNum < nColors; ++seqNum) { |
478 |
getline(line, sizeof(line), stream); |
478 |
xpmtoppm_getline(line, sizeof(line), stream); |
479 |
/* skip the comment line if any */ |
479 |
/* skip the comment line if any */ |
480 |
if (!strncmp(line, "/*", 2)) |
480 |
if (!strncmp(line, "/*", 2)) |
481 |
getline(line, sizeof(line), stream); |
481 |
xpmtoppm_getline(line, sizeof(line), stream); |
482 |
|
482 |
|
483 |
interpretXpm3ColorTableLine(line, seqNum, charsPerPixel, |
483 |
interpretXpm3ColorTableLine(line, seqNum, charsPerPixel, |
484 |
colors, ptab, nColors, transparentP); |
484 |
colors, ptab, nColors, transparentP); |
Lines 504-510
Link Here
|
504 |
unsigned int ** const ptabP) { |
504 |
unsigned int ** const ptabP) { |
505 |
/*---------------------------------------------------------------------------- |
505 |
/*---------------------------------------------------------------------------- |
506 |
Read the header of the XPM file on stream 'stream'. Assume the |
506 |
Read the header of the XPM file on stream 'stream'. Assume the |
507 |
getline() stream is presently positioned to the beginning of the |
507 |
xpmtoppm_getline() stream is presently positioned to the beginning of the |
508 |
file and it is a Version 1 XPM file. Leave the stream positioned |
508 |
file and it is a Version 1 XPM file. Leave the stream positioned |
509 |
after the header. |
509 |
after the header. |
510 |
|
510 |
|
Lines 525-531
Link Here
|
525 |
/* Read the initial defines. */ |
525 |
/* Read the initial defines. */ |
526 |
processedStaticChar = FALSE; |
526 |
processedStaticChar = FALSE; |
527 |
while (!processedStaticChar) { |
527 |
while (!processedStaticChar) { |
528 |
getline(line, sizeof(line), stream); |
528 |
xpmtoppm_getline(line, sizeof(line), stream); |
529 |
|
529 |
|
530 |
if (sscanf(line, "#define %s %d", str1, &v) == 2) { |
530 |
if (sscanf(line, "#define %s %d", str1, &v) == 2) { |
531 |
char *t1; |
531 |
char *t1; |
Lines 576-582
Link Here
|
576 |
/* If there's a monochrome color table, skip it. */ |
576 |
/* If there's a monochrome color table, skip it. */ |
577 |
if (!strncmp(t1, "mono", 4)) { |
577 |
if (!strncmp(t1, "mono", 4)) { |
578 |
for (;;) { |
578 |
for (;;) { |
579 |
getline(line, sizeof(line), stream); |
579 |
xpmtoppm_getline(line, sizeof(line), stream); |
580 |
if (!strncmp(line, "static char", 11)) |
580 |
if (!strncmp(line, "static char", 11)) |
581 |
break; |
581 |
break; |
582 |
} |
582 |
} |
Lines 599-605
Link Here
|
599 |
|
599 |
|
600 |
/* Read color table. */ |
600 |
/* Read color table. */ |
601 |
for (i = 0; i < *ncolorsP; ++i) { |
601 |
for (i = 0; i < *ncolorsP; ++i) { |
602 |
getline(line, sizeof(line), stream); |
602 |
xpmtoppm_getline(line, sizeof(line), stream); |
603 |
|
603 |
|
604 |
if ((t1 = strchr(line, '"')) == NULL) |
604 |
if ((t1 = strchr(line, '"')) == NULL) |
605 |
pm_error("D error scanning color table"); |
605 |
pm_error("D error scanning color table"); |
Lines 635-641
Link Here
|
635 |
"static char ..."). |
635 |
"static char ..."). |
636 |
*/ |
636 |
*/ |
637 |
for (;;) { |
637 |
for (;;) { |
638 |
getline(line, sizeof(line), stream); |
638 |
xpmtoppm_getline(line, sizeof(line), stream); |
639 |
if (strncmp(line, "static char", 11) == 0) |
639 |
if (strncmp(line, "static char", 11) == 0) |
640 |
break; |
640 |
break; |
641 |
} |
641 |
} |
Lines 741-747
Link Here
|
741 |
backup = FALSE; |
741 |
backup = FALSE; |
742 |
|
742 |
|
743 |
/* Read the header line */ |
743 |
/* Read the header line */ |
744 |
getline(line, sizeof(line), stream); |
744 |
xpmtoppm_getline(line, sizeof(line), stream); |
745 |
backup = TRUE; /* back up so next read reads this line again */ |
745 |
backup = TRUE; /* back up so next read reads this line again */ |
746 |
|
746 |
|
747 |
rc = sscanf(line, "/* %s */", str1); |
747 |
rc = sscanf(line, "/* %s */", str1); |
Lines 761-767
Link Here
|
761 |
pm_error("Could not get %d bytes of memory for image", totalpixels); |
761 |
pm_error("Could not get %d bytes of memory for image", totalpixels); |
762 |
cursor = *dataP; |
762 |
cursor = *dataP; |
763 |
maxcursor = *dataP + totalpixels - 1; |
763 |
maxcursor = *dataP + totalpixels - 1; |
764 |
getline(line, sizeof(line), stream); |
764 |
xpmtoppm_getline(line, sizeof(line), stream); |
765 |
/* read next line (first line may not always start with comment) */ |
765 |
/* read next line (first line may not always start with comment) */ |
766 |
while (cursor <= maxcursor) { |
766 |
while (cursor <= maxcursor) { |
767 |
if (strncmp(line, "/*", 2) == 0) { |
767 |
if (strncmp(line, "/*", 2) == 0) { |
Lines 771-777
Link Here
|
771 |
ncolors, ptab, &cursor, maxcursor); |
771 |
ncolors, ptab, &cursor, maxcursor); |
772 |
} |
772 |
} |
773 |
if (cursor <= maxcursor) |
773 |
if (cursor <= maxcursor) |
774 |
getline(line, sizeof(line), stream); |
774 |
xpmtoppm_getline(line, sizeof(line), stream); |
775 |
} |
775 |
} |
776 |
if (ptab) free(ptab); |
776 |
if (ptab) free(ptab); |
777 |
} |
777 |
} |