aboutsummaryrefslogtreecommitdiff
path: root/src/io/input.c
diff options
context:
space:
mode:
authorJ08nY2017-02-14 03:14:57 +0100
committerJ08nY2017-02-14 03:14:57 +0100
commit0c5ff628d52678bb44b9c595daf1289833d0e532 (patch)
tree913d36f318b30e7984aced1a654d00656d117eb3 /src/io/input.c
parent4230a5eb009c92cf7ffe83658e6bf926bccb1400 (diff)
downloadecgen-0c5ff628d52678bb44b9c595daf1289833d0e532.tar.gz
ecgen-0c5ff628d52678bb44b9c595daf1289833d0e532.tar.zst
ecgen-0c5ff628d52678bb44b9c595daf1289833d0e532.zip
Diffstat (limited to 'src/io/input.c')
-rw-r--r--src/io/input.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/io/input.c b/src/io/input.c
index 7d6b614..184924f 100644
--- a/src/io/input.c
+++ b/src/io/input.c
@@ -6,8 +6,9 @@
#include <parson/parson.h>
FILE *in;
+int delim;
-GEN fread_i(FILE *stream, const char *prompt, long bits, int delim) {
+GEN fread_i(FILE *stream, const char *prompt, long bits) {
if (prompt) {
printf("%s ", prompt);
}
@@ -25,7 +26,7 @@ GEN fread_i(FILE *stream, const char *prompt, long bits, int delim) {
// check bitsize here
GEN size = int2n(bits);
- if (cmpii(in, size)) {
+ if (cmpii(in, size) <= 0) {
return gerepileupto(ltop, in);
} else {
fprintf(stderr, "Number too big(> %ld bits).\n", bits);
@@ -33,8 +34,8 @@ GEN fread_i(FILE *stream, const char *prompt, long bits, int delim) {
}
}
-GEN fread_prime(FILE *stream, const char *prompt, long bits, int delim) {
- GEN read = fread_i(stream, prompt, bits, delim);
+GEN fread_prime(FILE *stream, const char *prompt, long bits) {
+ GEN read = fread_i(stream, prompt, bits);
if (equalii(read, gen_m1)) {
return read;
} else {
@@ -47,15 +48,15 @@ GEN fread_prime(FILE *stream, const char *prompt, long bits, int delim) {
}
}
-GEN fread_int(FILE *stream, const char *prompt, long bits, int delim) {
- return fread_i(stream, prompt, bits, delim);
+GEN fread_int(FILE *stream, const char *prompt, long bits) {
+ return fread_i(stream, prompt, bits);
}
-GEN fread_short(FILE *stream, const char *prompt, int delim) {
- return fread_i(stream, prompt, 16, delim);
+GEN fread_short(FILE *stream, const char *prompt) {
+ return fread_i(stream, prompt, 16);
}
-GEN fread_string(FILE *stream, const char *prompt, int delim) {
+GEN fread_string(FILE *stream, const char *prompt) {
if (prompt) {
printf("%s ", prompt);
}
@@ -74,41 +75,43 @@ GEN fread_string(FILE *stream, const char *prompt, int delim) {
return result;
}
-GEN fread_param(param_t param, FILE *stream, const char *prompt, long bits,
- int delim) {
+GEN fread_param(param_t param, FILE *stream, const char *prompt, long bits) {
switch (param) {
case PARAM_PRIME:
- return fread_prime(stream, prompt, bits, delim);
+ return fread_prime(stream, prompt, bits);
case PARAM_INT:
- return fread_int(stream, prompt, bits, delim);
+ return fread_int(stream, prompt, bits);
case PARAM_SHORT:
- return fread_short(stream, prompt, delim);
+ return fread_short(stream, prompt);
case PARAM_STRING:
- return fread_string(stream, prompt, delim);
+ return fread_string(stream, prompt);
}
return gen_m1;
}
-GEN read_param(param_t param, const char *prompt, long bits, int delim) {
- return fread_param(param, stdin, prompt, bits, delim);
+GEN read_param(param_t param, const char *prompt, long bits) {
+ return fread_param(param, stdin, prompt, bits);
}
-FILE *input_open(const char *input) {
+void input_init(const char *input) {
json_set_allocation_functions(pari_malloc, pari_free);
+
if (input) {
- FILE *in = fopen(input, "r");
+ in = fopen(input, "r");
+ delim = ',';
if (!in) {
// fallback to stdin or quit?
in = stdin;
+ delim = '\n';
perror("Failed to open input file.");
}
- return in;
} else {
- return stdin;
+ in = stdin;
+ delim = '\n';
}
}
-void input_close(FILE *in) {
+void input_quit() {
if (in != NULL && in != stdout) {
fclose(in);
}