1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/* This file is part of jpegpixi, a program to interpolate pixels in
JFIF image files.
Copyright (C) 2003, 2004 Martin Dickopp
Jpegpixi is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Jpegpixi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegpixi; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "util.h"
#if STDC_HEADERS
# include <ctype.h>
#else
# define isdigit(c) ((c) >= '0' && (c) <= '9')
#endif
#include "jpegpixi.h"
/* Parse a number. Return 1 if it is absolute, 0 if it is relative, -1 in case of an error. */
int
parse_number (const char **const strptr, unsigned int *const numptr)
{
if (!isdigit ((unsigned char)**strptr) && **strptr != '.')
return -1;
*numptr = 0;
while (isdigit ((unsigned char)**strptr))
{
*numptr = *numptr * 10 + (*(*strptr)++ - '0');
if (*numptr >= DENOM)
return -1;
}
if (**strptr == '%' || **strptr == '.')
{
++*strptr;
if (*numptr > 100)
return -1;
*numptr *= (DENOM / 100);
if (*(*strptr - 1) == '.')
{
unsigned int value = DENOM / 1000;
while (isdigit ((unsigned char)**strptr))
{
*numptr += value * (*(*strptr)++ - '0');
value /= 10;
}
if (**strptr == '%')
++*strptr;
else
return -1;
if (*numptr > DENOM)
return -1;
}
return 0;
}
return 1;
}
|