File Coverage

lib/PDL/IO/Pnm/get.c
Criterion Covered Total %
statement 17 20 85.0
branch 16 40 40.0
condition n/a
subroutine n/a
pod n/a
total 33 60 55.0


line stmt bran cond sub pod time code
1             #include "get.h"
2              
3             /* process one input line from an ascii pnm file
4             * and store data into a pdl data component
5             * returns number of elements read
6             * returns -1 if garbage was encountered
7             */
8              
9             /* get the next number from the input string
10             * return values: len : number of characters read
11             * 0 : end of string or skip rest of string because comment
12             * -1 : found garbage
13             */
14             #define TRAILING_WHITESPACE_CHECK(s) \
15             if (s!=' ' && s!='\t' && s!='\r' && s!='\n' && s!=',') return -1
16 90           int getint(PerlIO *fp, PDL_Long *ip)
17             {
18 90           PDL_Long i = 0;
19 90           int nread = 0;
20 90           int s = PerlIO_getc(fp);
21              
22 90 50         if (s == EOF) return 0;
23             while (1) {
24 198 50         if (s == EOF)
25 0           return 0; /* signal end of line */
26 198 50         if (s == '#')
27 0 0         SWALLOWLINE(fp);
    0          
28 198 100         if (s >='0' && s <='9') break;
    50          
29 108 100         if (s!=' ' && s!='\t' && s!='\r' && s!='\n' && s!=',')
    50          
    50          
    50          
    0          
30 0           return -1; /* garbage */
31 108           s = PerlIO_getc(fp); /* else skip whitespace */
32             }
33             /* parse number */
34             while (1) {
35 206           i = (i*10) + (s - '0');
36 206           nread++;
37 206 50         if ((s = PerlIO_getc(fp)) == EOF) break; /* we could loose that */
38 206 100         if (s<'0' || s>'9') break;
    50          
39             }
40 90           *ip = i;
41 90 50         TRAILING_WHITESPACE_CHECK(s);
    0          
    0          
    0          
    0          
42 90           return nread;
43             }