aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorJ08nY2018-02-27 16:47:27 +0100
committerJ08nY2018-02-27 16:47:27 +0100
commitb86ede073f78121f58cbad9a56f55041191a150b (patch)
tree67b548d8540f57968d342499d9c68e42327b96a2 /src/io
parent76b8866222b9abd5f25a795ff719914e852e14ab (diff)
downloadecgen-b86ede073f78121f58cbad9a56f55041191a150b.tar.gz
ecgen-b86ede073f78121f58cbad9a56f55041191a150b.tar.zst
ecgen-b86ede073f78121f58cbad9a56f55041191a150b.zip
Drop CSV support.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/cli.c13
-rw-r--r--src/io/output.c117
-rw-r--r--src/io/output.h25
3 files changed, 10 insertions, 145 deletions
diff --git a/src/io/cli.c b/src/io/cli.c
index 2ea14f8..c192021 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -72,7 +72,6 @@ struct argp_option cli_options[] = {
{"count", OPT_COUNT, "COUNT", 0, "Generate multiple curves.", 3},
{0, 0, 0, 0, "Input/Output options:", 4},
- {"format", OPT_FORMAT, "FORMAT", 0, "Format to output in. One of {csv, json}, default is json.", 4},
{"input", OPT_INPUT, "FILE", 0, "Input from file.", 4},
{"output", OPT_OUTPUT, "FILE", 0, "Output into file. Overwrites any existing file!", 4},
{"append", OPT_APPEND, 0, 0, "Append to output file (don't overwrite).", 4},
@@ -198,6 +197,7 @@ static void cli_end(struct argp_state *state) {
if (!cfg->points.type) {
cfg->points.type = POINTS_PRIME;
}
+ cfg->format = FORMAT_JSON;
}
error_t cli_parse(int key, char *arg, struct argp_state *state) {
@@ -335,17 +335,6 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
break;
}
/* IO options */
- case OPT_FORMAT:
- if (!strcmp(arg, "csv")) {
- cfg->format = FORMAT_CSV;
- } else if (!strcmp(arg, "json")) {
- cfg->format = FORMAT_JSON;
- } else {
- argp_failure(state, 1, 0,
- "Invalid format specified. One of [csv, json] "
- "is valid.");
- }
- break;
case OPT_INPUT:
cfg->input = arg;
break;
diff --git a/src/io/output.c b/src/io/output.c
index df3d6a4..4d8fca0 100644
--- a/src/io/output.c
+++ b/src/io/output.c
@@ -19,105 +19,6 @@ char *output_malloc(const char *what) {
return s;
}
-char *output_scsv(curve_t *curve) {
- pari_sp ltop = avma;
- char *params[OFFSET_END] = {NULL};
-
- switch (cfg->field) {
- case FIELD_PRIME:
- params[OFFSET_FIELD] =
- pari_sprintf("%P0#*x", cfg->hex_digits, curve->field);
- break;
- case FIELD_BINARY: {
- GEN field = field_params(curve->field);
- params[OFFSET_FIELD] =
- pari_sprintf("%P#x,%P#x,%P#x,%P#x", gel(field, 1),
- gel(field, 2), gel(field, 3), gel(field, 4));
- break;
- }
- }
-
- if (curve->a)
- params[OFFSET_A] =
- pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->a));
- if (curve->b)
- params[OFFSET_B] =
- pari_sprintf("%P0#*x", cfg->hex_digits, field_elementi(curve->b));
-
- if (curve->generators) {
- char *gens[curve->ngens];
- size_t len = 0;
- for (size_t i = 0; i < curve->ngens; ++i) {
- point_t *generator = curve->generators[i];
- GEN x = field_elementi(gel(generator->point, 1));
- GEN y = field_elementi(gel(generator->point, 2));
- gens[i] = pari_sprintf("%P0#*x,%P0#*x,%P#x,%P#x", cfg->hex_digits,
- x, cfg->hex_digits, y, generator->order,
- generator->cofactor);
- len += strlen(gens[i]);
- }
- size_t lenn = sizeof(char) * (len + curve->ngens);
- params[OFFSET_GENERATORS] = pari_calloc(lenn);
- for (size_t i = 0; i < curve->ngens; ++i) {
- if (i > 0) strncat(params[OFFSET_GENERATORS], ",", lenn - 1);
- strncat(params[OFFSET_GENERATORS], gens[i], lenn - 1);
- pari_free(gens[i]);
- }
- }
-
- if (curve->order)
- params[OFFSET_ORDER] =
- pari_sprintf("%P0#*x", cfg->hex_digits, curve->order);
-
- if (curve->points) {
- char *points[curve->npoints];
- size_t len = 0;
- for (size_t i = 0; i < curve->npoints; ++i) {
- point_t *point = curve->points[i];
- GEN x = field_elementi(gel(point->point, 1));
- GEN y = field_elementi(gel(point->point, 2));
- points[i] = pari_sprintf("%P0#*x,%P0#*x,%P#x", cfg->hex_digits, x,
- cfg->hex_digits, y, point->order);
- len += strlen(points[i]);
- }
- size_t lenn = sizeof(char) * (len + curve->npoints);
- params[OFFSET_POINTS] = pari_calloc(lenn);
- for (size_t i = 0; i < curve->npoints; ++i) {
- if (i > 0) strncat(params[OFFSET_POINTS], ",", lenn - 1);
- strncat(params[OFFSET_POINTS], points[i], lenn - 1);
- pari_free(points[i]);
- }
- }
-
- size_t len = 0;
- size_t count = 0;
- for (int i = OFFSET_FIELD; i < OFFSET_END; ++i) {
- if (params[i]) {
- len += strlen(params[i]);
- ++count;
- }
- }
- size_t lenn = sizeof(char) * (len + count);
- char *result = try_calloc(lenn);
-
- for (int i = OFFSET_FIELD; i < OFFSET_END; ++i) {
- if (params[i]) {
- if (i > OFFSET_FIELD) strncat(result, ",", lenn - 1);
- strncat(result, params[i], lenn - 1);
- pari_free(params[i]);
- }
- }
-
- avma = ltop;
- return result;
-}
-
-char *output_scsv_separator() { return output_malloc("\n"); }
-
-char *output_scsv_begin() { return NULL; }
-
-char *output_scsv_end() { return output_malloc("\n"); }
-
static JSON_Value *output_jjson(curve_t *curve) {
pari_sp ltop = avma;
// root object/value is curve
@@ -333,22 +234,22 @@ bool output_init() {
output_s_end = &output_sjson_end;
break;
}
- case FORMAT_CSV: {
- output_s = &output_scsv;
- output_s_separator = &output_scsv_separator;
- output_s_begin = &output_scsv_begin;
- output_s_end = &output_scsv_end;
- break;
- }
}
return true;
}
+static bool output_is_std(FILE *stream) {
+ return (stream == stdout || stream == stderr || stream == stdin);
+}
+
void output_quit(void) {
- if (out != NULL && out != stdout) {
+ if (!output_is_std(out)) {
fclose(out);
}
- if (err != NULL && err != stdout) {
+ if (!output_is_std(err)) {
fclose(err);
}
+ if (!output_is_std(verbose)) {
+ fclose(verbose); // My name is fClose Verbose!
+ }
}
diff --git a/src/io/output.h b/src/io/output.h
index 1037c00..6c048d9 100644
--- a/src/io/output.h
+++ b/src/io/output.h
@@ -78,31 +78,6 @@
#define output_log(...) pari_fprintf(out, __VA_ARGS__)
/**
- * @brief Output curve to a malloc'ed string in CSV format.
- * @param curve
- * @return
- */
-char *output_scsv(curve_t *curve);
-
-/**
- * @brief Output CSV separator(newline) to a malloc'ed string in CSV format.
- * @return
- */
-char *output_scsv_separator();
-
-/**
- * @brief Output CSV output header to a malloc'ed string in CSV format.
- * @return
- */
-char *output_scsv_begin();
-
-/**
- * @brief Output CSV output footer to a malloc'ed string in CSV format.
- * @return
- */
-char *output_scsv_end();
-
-/**
* @brief Output curve to a malloc'ed string in JSON format.
* @param curve
* @return