-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgcodestat.c
706 lines (659 loc) · 21.8 KB
/
gcodestat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*
* File gcodestat.c v0.9
* Author: [email protected]
* Date 20070721
*
* TODO: support marlin
* TODO: support max extruder feed rate
*
*/
#define _CLEANUP_ {if (gcodefile != NULL) free(gcodefile); \
if (gcodeout != NULL) free(gcodeout); \
if (apiurl != NULL) free(apiurl); \
if (apikey!=NULL) free(apikey); \
if (m117format!=NULL) free(m117format); \
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <malloc.h>
#include <sys/time.h>
#ifndef NOCURL
#include <curl/curl.h>
#endif
#ifdef _WIN32
#include <windows.h>
#endif
#include "gcodestat.h"
#include "calcmove.h"
#include "readconfig.h"
#include "readgcode.h"
/*
* print_usage() - print usage info
*/
void print_usage() {
fprintf(stderr, "gcodestat \n");
fprintf(stderr, "\t-h, --help\t\t\t\tshow help\n");
fprintf(stderr, "\t-?, --help\t\t\t\tshow help\n");
fprintf(stderr, "\t-q, --quiet\t\t\t\tsuppress any output\n");
fprintf(stderr, "\t-Q --show-time\t\t\t\toutput result time\n");
#ifdef _WIN32
fprintf(stderr, "\t-w, --alert\t\t\t\tdisplay windows alert with total time\n");
#endif
fprintf(stderr, "\t-g, --gcode samples/test.gcode\t\tFile to analyze\n");
fprintf(stderr, "\t-c, --config samples/config.txt\t\tSmoothieware config file\n");
fprintf(stderr, "\t-o, --output <outputfile.gcode>\t\tWhere to save modified G-Code file\n");
fprintf(stderr, "\t-a, --acceleration %d\t\t\tDefault XY acceleration in mm/sec/sec\n", DEFAULT_ACCELERATION);
fprintf(stderr, "\t-d, --junction_deviation %f\tDefault Junction Deviation\n", DEFAULT_JUNCTION_DEVIATION);
fprintf(stderr, "\t-j, --jerk %f\t\t\tDefault jerk\n", DEFAULT_JERK);
fprintf(stderr, "\t-6, --heatup_time 0\t\t\tConstant time to add to result (seconds)\n");
fprintf(stderr, "\t-f, --max_feed %d\t\t\tMax feed in mm/min\n", DEFAULT_MAX_SPEED);
fprintf(stderr, "\t-x, --max_x_speed %d\t\t\tMax x speed in mm/min\n", DEFAULT_MAX_SPEED);
fprintf(stderr, "\t-y, --max_y_speed %d\t\t\tMax y speed in mm/min\n", DEFAULT_MAX_SPEED);
fprintf(stderr, "\t-z, --max_z_speed %d\t\t\tMax z speed in mm/min\n", DEFAULT_MAX_SPEED);
fprintf(stderr, "\t-r, --retract_time %f\t\tRetraction time in sec\n", DEFAULT_RETRACT_TIME);
fprintf(stderr, "\t-p, --prime_time %f\t\tPrime time in sec\n", DEFAULT_PRIME_TIME);
fprintf(stderr, "\t-s, --percent_step 10\t\t\tChange LCD data every ##%%\n");
fprintf(stderr, "\t-m, --m117_format <format> \t\tformat to write M117 as, e.g.\n\t\t\t\t\t\t\"M117 %%w weeks, %%d days (%%h:%%m:%%s) %%p%%%% remaining\"\n\t\t\t\t\t\t\"M117 %%S seconds to go\"\n");
#ifndef NOCURL
fprintf(stderr, "\nOctoPrint settings\n\t\t(if output file set it will be uploaded to octoprint\n\t\tif not the input file will be uploaded)\n\n");
fprintf(stderr, "\t-k, --api_key \t\t\t\tOctoprint API key\n");
fprintf(stderr, "\t-u, --api_url \t\t\t\tOctoprint API URI (e.g. http://octopi.local/api/files/local )\n");
#endif
fprintf(stderr, "\n\n");
return;
}
/*
* print_config(*print_settings) - print config info
*/
void print_config(print_settings_t * ps) {
fprintf(stderr, "gcodestat v0.9\n");
fprintf(stderr, "Starting with parameters:\n");
fprintf(stderr, "\tacceleration: \t\t%f mm/sec/sec\n", ps->accel);
fprintf(stderr, "\tjunction deviation: \t%f\n", ps->jdev);
fprintf(stderr, "\tx max speed: \t\t%f mm/min\n", ps->x_maxspeed);
fprintf(stderr, "\ty max speed: \t\t%f mm/min\n", ps->y_maxspeed);
fprintf(stderr, "\tz max speed: \t\t%f mm/min\n", ps->z_maxspeed);
fprintf(stderr, "\tretraction time: \t%f sec\n", ps->rtime);
fprintf(stderr, "\tprime time: \t\t%f sec\n", ps->ptime);
fprintf(stderr, "\tspeed override: \t%f\n", ps->speedoverride);
fprintf(stderr, "\tabsolute movement: \t%s\n", ps->abs ? "yes" : "no");
fprintf(stderr, "\tabsolute extrusion: \t%s\n", ps->eabs ? "yes" : "no");
fprintf(stderr, "\tmetering unit: \t\t%s\n", ps->mm ? "mm" : "inch");
fprintf(stderr, "\n");
return;
}
// copied function somewhere from the vast internet
char *str_replace(char *orig, char *rep, char *with) {
char *result, *ins, *tmp;
int len_rep, len_with, len_front, count;
if (!orig || !rep) return NULL;
if ((len_rep = strlen(rep)) == 0) return NULL;
if (!with) with = "";
len_with = strlen(with);
ins = orig;
for (count = 0; (tmp = strstr(ins, rep)); ++count) ins = tmp + len_rep;
tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
if (!result) return NULL;
while (count--) {
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep;
}
strcpy(tmp, orig);
return result;
}
void print_timeleft(FILE* f, long int sec){
fprintf(f, "( ");
if (sec > 60*60*24*7) fprintf(f, "%ld weeks, ", sec / 60 / 60 / 24 / 7);
if (sec > 60*60*24 ) fprintf(f, "%ld days, " , (sec / 60 / 60 / 24) % 7);
if (sec > 60*60 ) fprintf(f, "%02ld:" , (sec / 3600) %24);
fprintf(f, "%02ld:" , (sec / 60) % 60);
fprintf(f, "%02ld )" , sec % 60);
}
void print_timeleft_f(FILE* f, char * sformat, long int sec, int pct){
int week, day, hour, minute, second;
char sweek[4], sday[2], shour[3], sminute[3], ssecond[3], sSec[64], spct[4];
char *stringtowrite = NULL;
char *tmp;
if (sformat == NULL) return;
if (pct == 0) return;
if (sec == 0) return;
week = sec / 60 / 60 / 24 / 7; // %w
day = (sec / 60 / 60 / 24) % 7; // %d
hour = (sec / 3600) %24; // %h
minute = (sec / 60) % 60; // %m
second = sec % 60; // %s
snprintf(sweek, 4, "%i", week);
snprintf(sday, 2, "%i", day );
snprintf(shour, 3, "%02i", hour);
snprintf(sminute, 3, "%02i", minute);
snprintf(ssecond, 3, "%02i", second);
snprintf(sSec, 64, "%lu", sec);
snprintf(spct, 4, "%i", pct);
tmp = str_replace(sformat, "%w", sweek );
if (tmp != NULL) {
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%d", sday );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%h", shour );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%m", sminute );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%s", ssecond );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%S", sSec );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%q", "\"" );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%%", "%" );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
tmp = str_replace(stringtowrite, "%p", spct );
if (tmp != NULL) {
free(stringtowrite);
stringtowrite = strdup (tmp);
free(tmp);
}
if (stringtowrite != NULL) {
fputs(stringtowrite, f);
fputs("\n", f);
free(stringtowrite);
}
}
#ifndef NOCURL
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
return realsize;
}
#endif
/*
* main
*/
int main(int argc, char** argv) {
FILE *f = NULL;
FILE *output_file = NULL;
char *lb = NULL;
char *gcodefile = NULL;
char *gcodeout = NULL;
char *m117format = NULL;
double seconds = 0;
double total_seconds = 0;
print_settings_t print_settings;
bool quiet = false,
show_time = false;
int pass;
double next_pct = 100;
double pct_step = 0.1;
double heatup_time = 0.0;
char *apikey = NULL;
char *apiurl = NULL;
#ifndef NOCURL
CURL *curl = NULL;
CURLcode res;
curl_mime *form = NULL;
curl_mimepart *field = NULL;
struct curl_slist *headerlist = NULL;
void *chunk = NULL;
#endif
#ifdef _WIN32
int alert = 0;
#endif
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"quiet", no_argument, NULL, 'q'},
{"show_time", no_argument, NULL, 'Q'},
{"alert", no_argument, NULL, 'w'},
{"gcode", required_argument, NULL, 'g'},
{"output", required_argument, NULL, 'o'},
{"config", required_argument, NULL, 'c'},
{"acceleration", required_argument, NULL, 'a'},
{"junction_deviation", required_argument, NULL, 'd'},
{"jerk", required_argument, NULL, 'j'},
{"heatup_time", required_argument, NULL, 't'},
{"max_x_speed", required_argument, NULL, 'x'},
{"max_y_speed", required_argument, NULL, 'y'},
{"max_z_speed", required_argument, NULL, 'z'},
{"max_feed", required_argument, NULL, 'f'},
{"retract_time", required_argument, NULL, 'r'},
{"prime_time", required_argument, NULL, 'p'},
{"percent_step", required_argument, NULL, 's'},
{"api_url", required_argument, NULL, 'u'},
{"api_key", required_argument, NULL, 'k'},
{"m117_format", required_argument, NULL, 'm'},
{NULL, 0, NULL, 0}
};
print_settings.accel = DEFAULT_ACCELERATION; // default acceleration mm/sec/sec
print_settings.jdev = DEFAULT_JUNCTION_DEVIATION; // default junction deviation (ex jerk)
print_settings.abs = true; // by default ABS moves
print_settings.eabs = true; // by default extruder movement is absolute
print_settings.mm = true; // by default move in mm
print_settings.x_maxspeed = DEFAULT_MAX_SPEED; // default max speed
print_settings.y_maxspeed = DEFAULT_MAX_SPEED; // default max speed
print_settings.z_maxspeed = DEFAULT_MAX_SPEED; // default max speed
print_settings.rtime = DEFAULT_RETRACT_TIME; // default retract time
print_settings.ptime = DEFAULT_PRIME_TIME; // default prime time
print_settings.jerk = false; // default we use junction deviation
print_settings.speedoverride = 1.0;
quiet = false;
show_time = true;
next_pct = 0.9;
heatup_time = 0.0;
seconds = heatup_time;
apikey = NULL;
apiurl = NULL;
int option_index = 0;
int getopt_result;
if(argc > 1) {
if(argv[1][0] != '-') {
gcodefile = strdup(argv[1]);
}
}
while ((getopt_result = getopt_long(argc, argv, "Qq?hwg:c:a:d:j:x:y:z:r:p:o:s:t:u:k:m:", long_options, &option_index)) != -1) {
switch (getopt_result) {
case 'q':
quiet = true;
show_time = false;
break;
case 'Q':
quiet = true;
show_time = true;
break;
case 'h':
case '?':
print_usage();
return (-1);
break;
case 'w':
#ifdef _WIN32
alert = 1;
#endif
break;
case 'm':
m117format = strdup(optarg);
break;
case 'g':
if (optarg) {
gcodefile = strdup(optarg);
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'o':
if (optarg) {
gcodeout = strdup(optarg);
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'c':
if (optarg) {
if (read_config(optarg, &print_settings)) {
fprintf(stderr, "Error reading config from %s\n", optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'a':
if (optarg) {
print_settings.accel = atof(optarg);
if (print_settings.accel == 0) {
fprintf(stderr, "Invalid acceleration value: %s\n", optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'd':
if (optarg) {
print_settings.jdev = atof(optarg);
if (print_settings.jdev == 0) {
fprintf(stderr, "Invalid junction deviation value: %s\n",
optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'j':
if (optarg) {
//TODO: implement jerk thingy
fprintf(stderr, "TODO: JERK IS NOT YET SUPORTED, SORRY\n");
return (-999);
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 't':
if (optarg) {
heatup_time = atof(optarg);
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'x':
if (optarg) {
print_settings.x_maxspeed = atof(optarg);
if (print_settings.x_maxspeed == 0) {
fprintf(stderr, "Invalid max_x_speed value: %s\n", optarg);
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'y':
if (optarg) {
print_settings.y_maxspeed = atof(optarg);
if (print_settings.y_maxspeed == 0) {
fprintf(stderr, "Invalid max_y_speed value: %s\n", optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'z':
if (optarg) {
print_settings.z_maxspeed = atof(optarg);
if (print_settings.z_maxspeed == 0) {
fprintf(stderr, "Invalid max_z_speed value: %s\n", optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'r':
if (optarg) {
print_settings.rtime = atof(optarg);
if (print_settings.rtime == 0) {
fprintf(stderr, "Invalid retraction time value: %s\n",
optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'p':
if (optarg) {
print_settings.ptime = atof(optarg);
if (print_settings.ptime == 0) {
fprintf(stderr, "Invalid prime time value: %s\n", optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 's':
if (optarg) {
pct_step = atof(optarg)/100.0F;
if (pct_step > 1.0F || pct_step < 0.01F) {
fprintf(stderr, "Invalid percent step value: %s, please use value between 1 and 100\n", optarg);
_CLEANUP_
return (-1);
}
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'u':
if (optarg) {
apiurl = strdup(optarg);
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
case 'k':
if (optarg) {
apikey = strdup(optarg);
} else {
print_usage();
_CLEANUP_
return (-1);
}
break;
}
}
if (m117format == NULL) m117format = strdup("M117 %p%% Remaining %w weeks %d days ( %h:%m:%s )");
if (gcodefile == NULL)
gcodefile = strdup("samples/test.gcode");
if (NULL == (lb = calloc(LINE_BUFFER_LENGTH, 1))) {
fprintf(stderr, "ERROR: Cannot allocate ram for line buffer\n");
_CLEANUP_
return (-3);
}
if (NULL == (f = fopen(gcodefile, "r"))) {
fprintf(stderr, "Cannot open %s for read\n", gcodefile);
print_usage();
_CLEANUP_
return (-2);
}
if (gcodeout != NULL) {
if (NULL == (output_file = fopen(gcodeout, "w"))) {
fprintf(stderr, "Cannot open %s for write\n", gcodeout);
fclose(f);
print_usage();
_CLEANUP_
return (-2);
}
}
if (!quiet)
print_config(&print_settings);
next_pct = 1 - pct_step;
for (pass = 0; pass < (output_file != NULL ? 2 : 1); pass++) {
if (pass == 1) {
rewind(f);
total_seconds = seconds;
seconds = heatup_time;
//fprintf(output_file, "M117 100%% Remaining ");
//print_timeleft(output_file, (long int) floor(total_seconds));
//fprintf(output_file, "\n");
print_timeleft_f(output_file, m117format, (long int) floor(total_seconds), 100);
}
while (fgets(lb, LINE_BUFFER_LENGTH, f)) {
if (pass == 1) {
fputs(lb, output_file);
if (next_pct > 0.01 && (total_seconds - seconds) / total_seconds < next_pct) {
//fprintf(output_file, "M117 %i%% Remaining ", (int) floor(next_pct * 100));
//print_timeleft(output_file, (long int) floor(total_seconds - seconds));
//fprintf(output_file, "\n");
print_timeleft_f(output_file, m117format, (long int) floor(total_seconds - seconds), (int) ceill(next_pct * 100));
next_pct -= pct_step;
}
}
if (comment(lb))
continue;
switch (gcode(lb)) {
case GCODE_MOVE:
seconds += calcmove(lb, &print_settings);
break;
case GCODE_DWELL:
seconds += read_dwell(lb);
break;
case GCODE_RETRACT:
break;
case GCODE_INCH:
print_settings.mm = false;
break;
case GCODE_MM:
print_settings.mm = true;
break;
case GCODE_ABS:
print_settings.abs = true;
break;
case GCODE_REL:
print_settings.abs = false;
break;
case GCODE_EABS:
print_settings.eabs = true;
break;
case GCODE_EREL:
print_settings.eabs = false;
break;
case GCODE_MAXFEED:
read_maxfeed(lb, &print_settings);
break;
case GCODE_ACCEL:
read_accel(lb, &print_settings);
break;
case GCODE_JDEV:
read_jdev(lb, &print_settings);
break;
case GCODE_RLEN:
read_rtime(lb, &print_settings);
break;
case GCODE_PLEN:
read_ptime(lb, &print_settings);
break;
case GCODE_SPEEDOVER:
read_speedover(lb, &print_settings);
break;
}
}
}
fclose(f);
if (!quiet) {
fprintf(stdout, "Total time: ");
print_timeleft(stdout, (long int) floor(seconds));
//print_timeleft_f(stdout, m117format, (long int) floor(total_seconds - seconds), (int) floor(next_pct * 100));
fprintf(stdout, "\n");
} else if (show_time) {
fprintf(stdout, "%lu\n", (long int) floor(seconds));
}
if (output_file != NULL) {
fprintf(output_file, ";\n; gcodestat\n; https://github.com/arhi/gcodestat\n");
fprintf(output_file, "; Total print time ");
print_timeleft(output_file, (long int) floor(seconds));
//print_timeleft_f(output_file, m117format, (long int) floor(total_seconds - seconds), (int) floor(next_pct * 100));
fprintf(output_file, "\n;\n");
fclose(output_file);
}
#ifndef NOCURL
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl && apikey && apiurl) {
char apiheader[128]; // should be 44 but maybe in future api key will be bigger
chunk = malloc(1);
form = curl_mime_init(curl);
field = curl_mime_addpart(form);
curl_mime_name(field, "file");
curl_mime_filedata(field, gcodeout ? gcodeout : gcodefile);
field = curl_mime_addpart(form);
curl_mime_name(field, "filename");
curl_mime_data(field, gcodeout ? gcodeout : gcodefile, CURL_ZERO_TERMINATED);
snprintf(apiheader, 128, "X-Api-Key: %s", apikey);
headerlist = curl_slist_append(headerlist, "Expect:");
headerlist = curl_slist_append(headerlist, apiheader);
curl_easy_setopt(curl, CURLOPT_URL, apiurl);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, form);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "gcodestat/0.x");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, chunk);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
if (!quiet) fprintf(stderr, "Uploading file to %s\n", apiurl);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "Failed uploading file to server. Error: %s\n", curl_easy_strerror(res));
if (!quiet) fprintf(stderr, "Uploading DONE!\n");
free(chunk);
curl_easy_cleanup(curl);
curl_mime_free(form);
curl_slist_free_all(headerlist);
}
#endif
#ifdef _WIN32
if (alert) {
char ttime[128];
snprintf(ttime, 128, "Total Time: ");
if ((long int) floor(seconds) > 60 * 60 * 24 * 7)
snprintf(ttime, 128, "%s%ld weeks, ", ttime, (long int) floor(seconds) / 60 / 60 / 24 / 7);
if ((long int) floor(seconds) > 60 * 60 * 24)
snprintf(ttime, 128, "%s%ld days, ", ttime, ((long int) floor(seconds) / 60 / 60 / 24) % 7);
if ((long int) floor(seconds) > 60 * 60)
snprintf(ttime, 128, "%s%02ld:", ttime, ((long int) floor(seconds) / 3600) % 24);
snprintf(ttime, 128, "%s%02ld:", ttime, ((long int) floor(seconds) / 60) % 60);
snprintf(ttime, 128, "%s%02ld ", ttime, (long int) floor(seconds) % 60);
MessageBox(NULL, ttime, "gcodestat", 0);
}
#endif
_CLEANUP_
return 0;
}