diff --git a/include/villas/advio.h b/include/villas/advio.h index f9f2bbaef..c4ca19a25 100644 --- a/include/villas/advio.h +++ b/include/villas/advio.h @@ -25,10 +25,10 @@ struct advio { typedef struct advio AFILE; /* The remaining functions from stdio are just replaced macros */ - #define afeof(af) feof((af)->file) #define aftell(af) ftell((af)->file) #define arewind(af) rewind((af)->file) +#define afileno(af) fileno((af)->file) #define afread(ptr, sz, nitems, af) fread(ptr, sz, nitems, (af)->file) #define afwrite(ptr, sz, nitems, af) fwrite(ptr, sz, nitems, (af)->file) diff --git a/lib/advio.c b/lib/advio.c index 3c5bc526c..f2d942394 100644 --- a/lib/advio.c +++ b/lib/advio.c @@ -40,20 +40,20 @@ static int advio_xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_of int dotz = round(frac * BAR_WIDTH); // create the "meter" - printf("%3.0f%% in %f s (%" CURL_FORMAT_CURL_OFF_T " / %" CURL_FORMAT_CURL_OFF_T ") [", frac * 100, curtime, dlnow, dltotal); + fprintf(stderr, "%3.0f%% in %f s (%" CURL_FORMAT_CURL_OFF_T " / %" CURL_FORMAT_CURL_OFF_T ") [", frac * 100, curtime, dlnow, dltotal); // part that's full already int i = 0; for ( ; i < dotz; i++) - printf("="); + fprintf(stderr, "="); // remaining part (spaces) for ( ; i < BAR_WIDTH; i++) - printf(" "); + fprintf(stderr, " "); // and back to line begin - do not forget the fflush to avoid output buffering problems! - printf("]\r"); - fflush(stdout); + fprintf(stderr, "]\r"); + fflush(stderr); return 0; } @@ -150,8 +150,10 @@ int aupload(AFILE *af) fseek(af->file, 0, SEEK_SET); res = curl_easy_perform(af->curl); - printf("\n"); /* do not continue in the same line as the progress bar */ - + + fprintf(stderr, "\e[2K"); + fflush(stderr); /* do not continue in the same line as the progress bar */ + fseek(af->file, pos, SEEK_SET); /* Restore old stream pointer */ if (res != CURLE_OK) @@ -166,11 +168,15 @@ int adownload(AFILE *af) { CURLcode res; long code; + int ret; - rewind(af->file); + fseek(af->file, 0, SEEK_SET); res = curl_easy_perform(af->curl); - printf("\n"); /* do not continue in the same line as the progress bar */ + + fprintf(stderr, "\e[2K"); + fflush(stderr); /* do not continue in the same line as the progress bar */ + switch (res) { case CURLE_OK: curl_easy_getinfo(af->curl, CURLINFO_RESPONSE_CODE, &code); @@ -210,7 +216,10 @@ notexist: /* File does not exist */ /* If we receive a 404, we discard the already received error page * and start with an empty file. */ - ftruncate(fileno(af->file), 0); + fflush(af->file); + ret = ftruncate(fileno(af->file), 0); + if (ret) + return ret; exist: /* File exists */ if (af->mode[0] == 'a') @@ -219,6 +228,6 @@ exist: /* File exists */ fseek(af->file, 0, SEEK_SET); sha1sum(af->file, af->hash); - + return 0; } diff --git a/lib/fpga/ips/model.c b/lib/fpga/ips/model.c index d97528ae0..4df61acc4 100644 --- a/lib/fpga/ips/model.c +++ b/lib/fpga/ips/model.c @@ -206,7 +206,9 @@ int model_init(struct fpga_ip *c) ret = 0; /* Set default values for parameters */ - list_foreach(struct model_param *p, &m->parameters) { + for (size_t i = 0; i < list_length(&m->parameters); i++) { + struct model_param *p = list_at(&m->parameters, i); + p->ip = c; if (p->direction == MODEL_PARAM_IN) { @@ -243,7 +245,9 @@ void model_dump(struct fpga_ip *c) { INDENT info("Parameters:"); - list_foreach(struct model_param *p, &m->parameters) { INDENT + for (size_t i = 0; i < list_length(&m->parameters); i++) { INDENT + struct model_param *p = list_at(&m->parameters, i); + if (p->direction == MODEL_PARAM_IN) info("%#jx: %s (%s) = %.3f %s %u", p->offset, @@ -262,7 +266,9 @@ void model_dump(struct fpga_ip *c) } info("Infos:"); - list_foreach(struct model_info *i, &m->infos) { INDENT + for (size_t j = 0; j < list_length(&m->infos); j++) { INDENT + struct model_info *i = list_at(&m->infos, j); + info("%s: %s", i->field, i->value); } } diff --git a/lib/fpga/ips/switch.c b/lib/fpga/ips/switch.c index 86964b63b..328b4ed30 100644 --- a/lib/fpga/ips/switch.c +++ b/lib/fpga/ips/switch.c @@ -58,7 +58,8 @@ int switch_init_paths(struct fpga_ip *c) XAxisScr_RegUpdateDisable(xsw); XAxisScr_MiPortDisableAll(xsw); - list_foreach(struct sw_path *p, &sw->paths) { + for (size_t i = 0; i < list_length(&sw->paths); i++) { + struct sw_path *p = list_at(&sw->paths, i); struct fpga_ip *mi, *si; mi = list_lookup(&c->card->ips, p->out);