const char * UsageLines [] = {
"Usage: p4show",
"Reads P4 PBM image from standard input.",
"Writes text representation to standard output.",
"For an input pixel of '1', writes '*'.",
"For an input pixel of '0', writes '-', '+', or '|' along outside",
"edges, and (space) otherwise.",
"May 20, 2020. Newest is at gopher -p users/julianbr sdf.org",
"(Use 'p4paint' with a key of \"*\" for the opposite of 'p4show'.)",
};
const int NumUsageLines = sizeof (UsageLines)/sizeof (UsageLines [0] );
#include <stdio.h>
void Show (int width, int height)
{
int across, down, InputValue, InputWeight;
for (down = 0; down < height; down++) {
InputWeight = 128;
InputValue = 0; /* Just to make it != EOF */
for (across = 0; across < width; across++) {
if (InputWeight == 128 && InputValue != EOF)
InputValue = getchar ();
if (InputValue != EOF && InputValue >= InputWeight)
putchar ('*');
else if (down > 0 && down + 1 < height
&& (across == 0 || across + 1 == width) )
putchar ('|');
else if (across > 0 && across + 1 < width
&& (down == 0 || down + 1 == height) )
putchar ('-');
else if ((down == 0 || down + 1 == height)
&& (across == 0 || across + 1 == width) )
putchar ('+');
else
putchar (' ');
if (InputValue != EOF && InputValue >= InputWeight)
InputValue -= InputWeight;
InputWeight /= 2;
if (InputWeight == 0)
InputWeight = 128;
}
putchar ('\n');
}
if (InputValue == EOF) {
fprintf (stderr, "***p4show: Premature end of");
fprintf (stderr, " input image data.\n");
}
else if (getchar () != EOF) {
fprintf (stderr, "***p4show: Extra image data");
fprintf (stderr, " in input PBM.\n");
}
}
int main (int argc, char * argv [] )
{
int i, width, height;