Skip to content

Commit

Permalink
Merge pull request #3 from rick/fix-pictures
Browse files Browse the repository at this point in the history
Fix "pictures"
  • Loading branch information
rick committed Dec 31, 2015
2 parents 229f0be + 5d40f4d commit f01af6a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ csa/round_costs/csa_s_tpo_pu
dimacs/dcube
dimacs/universal
dimacs/assign
pictures/p5pgmtoasn
13 changes: 13 additions & 0 deletions pictures/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Makefile to build and clean up DIMACS sources

BASEFILES=p5pgmtoasn.c
CFLAGS=-O4
TARGETS=p5pgmtoasn

all: $(TARGETS)

clean: $(BASEFILES)
rm -f $(TARGETS)

p5pgmtoasn: p5pgmtoasn.c
cc $(CFLAGS) -o $@ p5pgmtoasn.c
38 changes: 22 additions & 16 deletions pictures/p5pgmtoasn.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ long val;
main()

{
char line[70], file_type[2];
char line[70], file_type[2], *result;
long pv;
int ch;
unsigned long r, c;
Expand All @@ -67,21 +67,27 @@ unsigned long i;
unsigned max;
unsigned long numgreys;

(void) gets(line);
if ((sscanf(line, "%2s", file_type) == 0) ||
(file_type[0] != 'P') ||
(file_type[1] != '5'))
errmsg(FILE_FORMAT);
do
(void) gets(line);
while (line[0] == '#');
if (sscanf(line, "%lu%lu", &wid, &len) != 2)
errmsg(FILE_FORMAT);
do
(void) gets(line);
while (line[0] == '#');
if (sscanf(line, "%u", &max) != 1)
errmsg(FILE_FORMAT);
if (fgets(line, sizeof(line), stdin) != NULL) {
if ((sscanf(line, "%2s", file_type) == 0) ||
(file_type[0] != 'P') ||
(file_type[1] != '5'))
errmsg(FILE_FORMAT);

do
result = fgets(line, sizeof(line), stdin);
while ((result != NULL) && (line[0] == '#'));

if (sscanf(line, "%lu%lu", &wid, &len) != 2)
errmsg(FILE_FORMAT);

do
result = fgets(line, sizeof(line), stdin);
while ((result != NULL) && (line[0] == '#'));

if (sscanf(line, "%u", &max) != 1)
errmsg(FILE_FORMAT);
}

/*
Now read greyscale information.
*/
Expand Down

0 comments on commit f01af6a

Please sign in to comment.