|
tesseract 3.04.01
|
#include <ctype.h>#include <math.h>#include <stdarg.h>#include <stddef.h>#include <string.h>#include <limits.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "scanutils.h"#include "tprintf.h"Go to the source code of this file.
Typedefs | |
| typedef long | off_t |
Enumerations | |
| enum | Flags { FL_SPLAT = 0x01, FL_INV = 0x02, FL_WIDTH = 0x04, FL_MINUS = 0x08 } |
| enum | Ranks { RANK_CHAR = -2, RANK_SHORT = -1, RANK_INT = 0, RANK_LONG = 1, RANK_LONGLONG = 2, RANK_PTR = INT_MAX } |
| enum | Bail { BAIL_NONE = 0, BAIL_EOF, BAIL_ERR } |
Functions | |
| size_t | LongBit () |
| uintmax_t | streamtoumax (FILE *s, int base) |
| double | streamtofloat (FILE *s) |
| double | strtofloat (const char *s) |
| int | tfscanf (FILE *stream, const char *format,...) |
Variables | |
| enum Ranks | kMinRank = RANK_CHAR |
| enum Ranks | kMaxRank = RANK_LONGLONG |
| enum Ranks | kIntMaxRank = RANK_LONGLONG |
| enum Ranks | kSizeTRank = RANK_LONG |
| enum Ranks | kPtrDiffRank = RANK_LONG |
| typedef long off_t |
Definition at line 42 of file scanutils.cpp.
| enum Bail |
Definition at line 68 of file scanutils.cpp.
| enum Flags |
| enum Ranks |
Definition at line 52 of file scanutils.cpp.
{
RANK_CHAR = -2,
RANK_SHORT = -1,
RANK_INT = 0,
RANK_LONG = 1,
RANK_LONGLONG = 2,
RANK_PTR = INT_MAX // Special value used for pointers
};
| size_t LongBit | ( | ) | [inline] |
Definition at line 75 of file scanutils.cpp.
{
return CHAR_BIT * sizeof(long);
}
| double streamtofloat | ( | FILE * | s | ) |
Definition at line 151 of file scanutils.cpp.
{
int minus = 0;
int v = 0;
int d, c = 0;
int k = 1;
int w = 0;
for (c = fgetc(s);
isspace(static_cast<unsigned char>(c)) && (c != EOF);
c = fgetc(s));
// Single optional + or -
if (c == '-' || c == '+') {
minus = (c == '-');
c = fgetc(s);
}
// Actual number parsing
for (; c != EOF && (d = DigitValue(c, 10)) >= 0; c = fgetc(s))
v = v*10 + d;
if (c == '.') {
for (c = fgetc(s); c != EOF && (d = DigitValue(c, 10)) >= 0; c = fgetc(s)) {
w = w*10 + d;
k *= 10;
}
}
double f = static_cast<double>(v)
+ static_cast<double>(w) / static_cast<double>(k);
if (c == 'e' || c == 'E') {
c = fgetc(s);
int expsign = 1;
if (c == '-' || c == '+') {
expsign = (c == '-') ? -1 : 1;
c = fgetc(s);
}
int exponent = 0;
for (; (c != EOF) && (d = DigitValue(c, 10)) >= 0; c = fgetc(s)) {
exponent = exponent * 10 + d;
}
exponent *= expsign;
f *= pow(10.0, static_cast<double>(exponent));
}
ungetc(c, s);
return minus ? -f : f;
}
| uintmax_t streamtoumax | ( | FILE * | s, |
| int | base | ||
| ) |
Definition at line 110 of file scanutils.cpp.
{
int minus = 0;
uintmax_t v = 0;
int d, c = 0;
for (c = fgetc(s);
isspace(static_cast<unsigned char>(c)) && (c != EOF);
c = fgetc(s)) {}
// Single optional + or -
if (c == '-' || c == '+') {
minus = (c == '-');
c = fgetc(s);
}
// Assign correct base
if (base == 0) {
if (c == '0') {
c = fgetc(s);
if (c == 'x' || c == 'X') {
base = 16;
c = fgetc(s);
} else {
base = 8;
}
}
} else if (base == 16) {
if (c == '0') {
c = fgetc(s);
if (c == 'x' || c == 'X') c = fgetc(s);
}
}
// Actual number parsing
for (; (c != EOF) && (d = DigitValue(c, base)) >= 0; c = fgetc(s))
v = v*base + d;
ungetc(c, s);
return minus ? -v : v;
}
| double strtofloat | ( | const char * | s | ) |
Definition at line 198 of file scanutils.cpp.
{
int minus = 0;
int v = 0;
int d;
int k = 1;
int w = 0;
while(*s && isspace(static_cast<unsigned char>(*s))) s++;
// Single optional + or -
if (*s == '-' || *s == '+') {
minus = (*s == '-');
s++;
}
// Actual number parsing
for (; *s && (d = DigitValue(*s, 10)) >= 0; s++)
v = v*10 + d;
if (*s == '.') {
for (++s; *s && (d = DigitValue(*s, 10)) >= 0; s++) {
w = w*10 + d;
k *= 10;
}
}
if (*s == 'e' || *s == 'E')
tprintf("WARNING: Scientific Notation not supported!");
double f = static_cast<double>(v)
+ static_cast<double>(w) / static_cast<double>(k);
return minus ? -f : f;
}
| int tfscanf | ( | FILE * | stream, |
| const char * | format, | ||
| ... | |||
| ) |
fscanf variant to ensure correct reading regardless of locale.
tfscanf parse a file stream according to the given format. See the fscanf manpage for more information, as this function attempts to mimic its behavior.
Definition at line 233 of file scanutils.cpp.
{
va_list ap;
int rv;
va_start(ap, format);
rv = tvfscanf(stream, format, ap);
va_end(ap);
return rv;
}
| enum Ranks kIntMaxRank = RANK_LONGLONG |
Definition at line 64 of file scanutils.cpp.
Definition at line 62 of file scanutils.cpp.
Definition at line 61 of file scanutils.cpp.
| enum Ranks kPtrDiffRank = RANK_LONG |
Definition at line 66 of file scanutils.cpp.
| enum Ranks kSizeTRank = RANK_LONG |
Definition at line 65 of file scanutils.cpp.