Уклоњена потреба за регекс библиотеком, умањен захтев за Посикс стандард окружења у времену компајлирања.
This commit is contained in:
parent
a617c96eaf
commit
bea145baec
7
Makefile
7
Makefile
|
@ -8,10 +8,9 @@ PREFIX = /usr/local
|
||||||
LIBPREFIX = $(PREFIX)/lib
|
LIBPREFIX = $(PREFIX)/lib
|
||||||
|
|
||||||
# флегови за C компајлер и линкер
|
# флегови за C компајлер и линкер
|
||||||
CPPFLAGS = -D_POSIX_C_SOURCE=200200L -DDESTDIR=\"$(DESTDIR)\" \
|
CPPFLAGS = -D_POSIX_C_SOURCE=2 -DDESTDIR=\"$(DESTDIR)\" -DVERSION=\"$(VERSION)\"
|
||||||
-DVERSION=\"$(VERSION)\"
|
# CFLAGS = -g -std=c99 -pedantic -Wall -O0
|
||||||
CFLAGS = -g -std=c99 -pedantic -Wall -O0
|
CFLAGS = -std=c99 -pedantic -Wall -O3
|
||||||
# CFLAGS = -std=c99 -pedantic -Wall -O3
|
|
||||||
LDFLAGS = -lm -lc
|
LDFLAGS = -lm -lc
|
||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
66
read.c
66
read.c
|
@ -4,7 +4,6 @@
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <regex.h>
|
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "read.h"
|
#include "read.h"
|
||||||
|
@ -138,12 +137,45 @@ wint_t unscanwc(wint_t c, FILE *stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int lengthDigitArray(char *s)
|
int validFracNum(char *s)
|
||||||
{
|
{
|
||||||
int i;
|
char *endptr;
|
||||||
for (i = 0; isdigit(s[i]); ++i)
|
strtoll(s, &endptr, 10);
|
||||||
;
|
if (*endptr == '\0' && endptr != s)
|
||||||
return i;
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (*endptr == '/' && endptr != s)
|
||||||
|
{
|
||||||
|
char *denom = endptr + 1;
|
||||||
|
strtoll(denom, &endptr, 10);
|
||||||
|
if (*endptr == '\0' && endptr != denom)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int validRealNum(char *s)
|
||||||
|
{
|
||||||
|
char *endptr;
|
||||||
|
strtold(s, &endptr);
|
||||||
|
if (*endptr == '\0')
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object getToken(FILE *stream)
|
object getToken(FILE *stream)
|
||||||
|
@ -190,25 +222,17 @@ object getToken(FILE *stream)
|
||||||
char *s = malloc(n * sizeof(char));
|
char *s = malloc(n * sizeof(char));
|
||||||
wcstombs(s, buffer, n);
|
wcstombs(s, buffer, n);
|
||||||
|
|
||||||
regex_t regNumberFrac, regNumberReal;
|
char *endptr;
|
||||||
regcomp(®NumberFrac, "^[-+]?[[:digit:]]+(/[[:digit:]]+)?$",
|
if (validFracNum(s))
|
||||||
REG_EXTENDED);
|
|
||||||
regcomp(®NumberReal, "^[-+]?[[:digit:]]*,[[:digit:]]+$",
|
|
||||||
REG_EXTENDED);
|
|
||||||
const int nmatches = 1;
|
|
||||||
regmatch_t a[nmatches];
|
|
||||||
|
|
||||||
if (!regexec(®NumberFrac, s, nmatches, a, 0))
|
|
||||||
{
|
{
|
||||||
TYPE(result) = numberObject;
|
TYPE(result) = numberObject;
|
||||||
NUM_TYPE(result) = fractionNum;
|
NUM_TYPE(result) = fractionNum;
|
||||||
NUM_NUMER(result) = atoll(s);
|
NUM_NUMER(result) = strtoll(s, &endptr, 10);
|
||||||
char *tmp;
|
NUM_DENOM(result) = *endptr == '/' ?
|
||||||
NUM_DENOM(result) = (tmp = strchr(s, '/')) == NULL ?
|
strtoll(endptr + 1, &endptr, 10) : 1;
|
||||||
1 : atoll(tmp + 1);
|
|
||||||
result = shortenFractionNum(result);
|
result = shortenFractionNum(result);
|
||||||
}
|
}
|
||||||
else if (!regexec(®NumberReal, s, nmatches, a, 0))
|
else if (validRealNum(s))
|
||||||
{
|
{
|
||||||
TYPE(result) = numberObject;
|
TYPE(result) = numberObject;
|
||||||
NUM_TYPE(result) = realNum;
|
NUM_TYPE(result) = realNum;
|
||||||
|
@ -220,8 +244,6 @@ object getToken(FILE *stream)
|
||||||
SYM(result) = malloc((strlen(s) + 1) * sizeof(char));
|
SYM(result) = malloc((strlen(s) + 1) * sizeof(char));
|
||||||
strcpy(SYM(result), s);
|
strcpy(SYM(result), s);
|
||||||
}
|
}
|
||||||
regfree(®NumberFrac);
|
|
||||||
regfree(®NumberReal);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue