Browse Source

portable getline replacement (closes #182)

pull/183/head
Steven G. Johnson 5 years ago
parent
commit
d588d7097c
  1. 5
      test/graphemetest.c
  2. 6
      test/normtest.c
  3. 11
      test/simple_getline.h

5
test/graphemetest.c

@ -1,15 +1,16 @@
#include "tests.h"
#include "simple_getline.h"
int main(int argc, char **argv)
{
char *buf = NULL;
char buf[8192];
size_t bufsize = 0;
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
utf8proc_uint8_t src[1024];
int len;
check(f != NULL, "error opening GraphemeBreakTest.txt");
while (getline(&buf, &bufsize, f) > 0) {
while (simple_getline(buf, f) > 0) {
size_t bi = 0, si = 0;
lineno += 1;

6
test/normtest.c

@ -1,4 +1,5 @@
#include "tests.h"
#include "simple_getline.h"
#define CHECK_NORM(NRM, norm, src) { \
char *src_norm = (char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \
@ -9,13 +10,12 @@
int main(int argc, char **argv)
{
char *buf = NULL;
size_t bufsize = 0;
char buf[8192];
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
char source[1024], NFC[1024], NFD[1024], NFKC[1024], NFKD[1024];
check(f != NULL, "error opening NormalizationTest.txt");
while (getline(&buf, &bufsize, f) > 0) {
while (simple_getline(buf, f) > 0) {
size_t offset;
lineno += 1;

11
test/simple_getline.h

@ -0,0 +1,11 @@
/* simplistic, portable replacement for getline, sufficient for our tests */
static size_t simple_getline(char buf[8192], FILE *f) {
size_t i = 0;
while (i < 1023) {
int c = getc(f);
if (c == EOF || c == '\n') break;
buf[i++] = (char) c;
}
buf[i] = 0;
return i;
}
Loading…
Cancel
Save