This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCLIcore.c
3489 lines (2671 loc) · 96.8 KB
/
CLIcore.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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file CLIcore.c
* @brief main C file
*
*/
/*
* Exit code
* - 0: no error
* - 1: error (non-specific)
* - 2: error loading libraries
* - 3: missing file required to proceed
* - 4: system call error
*/
#define _GNU_SOURCE
/* =============================================================================================== */
/* =============================================================================================== */
/* HEADER FILES */
/* =============================================================================================== */
/* =============================================================================================== */
#include <stdint.h>
#include <string.h>
#include "CommandLineInterface/CLIcore.h"
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <dlfcn.h>
#include <unistd.h>
#include <dirent.h>
#include <stddef.h> // offsetof()
#include <sys/resource.h> // getrlimit
#include <termios.h>
//#include <pthread_np.h>
#ifdef __MACH__
#include <mach/mach_time.h>
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 0
static int clock_gettime(int clk_id, struct mach_timespec *t)
{
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
uint64_t time;
time = mach_absolute_time();
double nseconds = ((double)time * (double)timebase.numer) / ((
double)timebase.denom);
double seconds = ((double)time * (double)timebase.numer) / ((
double)timebase.denom * 1e9);
t->tv_sec = seconds;
t->tv_nsec = nseconds;
return 0;
}
#else
#include <sys/time.h>
#endif
#include <math.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <getopt.h>
#include <ncurses.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdbool.h>
#ifndef __MACH__
#include <sys/prctl.h>
#endif
#include <sched.h>
#include <signal.h>
#include <readline/readline.h>
#include <readline/history.h>
# ifdef _OPENMP
# include <omp.h>
#define OMP_NELEMENT_LIMIT 1000000
# endif
#ifdef _OPENACC
#include <openacc.h>
#endif
#include <gsl/gsl_rng.h> // for random numbers
#include <fitsio.h>
//#include "initmodules.h"
#include "ImageStreamIO/ImageStreamIO.h"
#include "COREMOD_memory/COREMOD_memory.h"
#include "COREMOD_iofits/COREMOD_iofits.h"
#include "COREMOD_arith/COREMOD_arith.h"
#include "CommandLineInterface/calc.h"
#include "CommandLineInterface/calc_bison.h"
/* =============================================================================================== */
/* =============================================================================================== */
/* DEFINES, MACROS */
/* =============================================================================================== */
/* =============================================================================================== */
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define KRES "\033[0m"
/* =============================================================================================== */
/* =============================================================================================== */
/* GLOBAL DATA DECLARATION */
/* =============================================================================================== */
/* =============================================================================================== */
int DLib_index;
void *DLib_handle[1000];
extern void yy_scan_string(const char *);
extern int yylex_destroy(void);
/*-----------------------------------------
* Globals exported to all modules
*/
pid_t CLIPID;
uint8_t TYPESIZE[32];
int C_ERRNO;
int Verbose = 0;
int Listimfile = 0;
char line[500];
int rlquit = false;
int CLIexecuteCMDready = 0;
//double CFITSVARRAY[SZ_CFITSVARRAY];
//long CFITSVARRAY_LONG[SZ_CFITSVARRAY];
//int ECHO;
char calctmpimname[200];
char CLIstartupfilename[200] = "CLIstartup.txt";
// fifo input
static int fifofd;
static fd_set cli_fdin_set;
/*-----------------------------------------
* Forward References
*/
int user_function();
void fnExit1(void);
static void runCLI_data_init();
static void runCLI_free();
// readline auto-complete
int CLImatchMode = 0;
static char **CLI_completion(const char *, int, int);
char *CLI_generator(const char *, int);
char *dupstr(char *);
void *xmalloc(int);
static errno_t memory_re_alloc();
static int command_line_process_options(int argc, char **argv);
/// CLI commands
static int exitCLI();
static int help();
static errno_t list_commands();
static errno_t list_commands_module(const char *restrict modulename);
static errno_t load_sharedobj(const char *restrict libname);
static errno_t load_module_shared(const char *restrict modulename);
static errno_t load_module_shared_ALL();
static errno_t help_command(const char *restrict cmdkey);
/* =============================================================================================== */
/* =============================================================================================== */
/* FUNCTIONS SOURCE CODE */
/* =============================================================================================== */
/* =============================================================================================== */
/** @name CLIcore functions */
static void set_terminal_echo_on()
{
// Terminal settings
struct termios termInfo;
if(tcgetattr(0, &termInfo) == -1)
{
perror("tcgetattr");
exit(1);
}
termInfo.c_lflag |= ECHO; /* turn on ECHO */
tcsetattr(0, TCSADRAIN, &termInfo);
}
/// signal catching
errno_t set_signal_catch()
{
// catch signals for clean exit
if(sigaction(SIGTERM, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGTERM\n");
}
if(sigaction(SIGINT, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGINT\n");
}
if(sigaction(SIGABRT, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGABRT\n");
}
if(sigaction(SIGBUS, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGBUS\n");
}
if(sigaction(SIGSEGV, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGSEGV\n");
}
if(sigaction(SIGHUP, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGHUP\n");
}
if(sigaction(SIGPIPE, &data.sigact, NULL) == -1)
{
printf("\ncan't catch SIGPIPE\n");
}
return RETURN_SUCCESS;
}
static void fprintf_stdout(FILE *f, char const *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
}
/**
* @brief Write entry into debug log
*
*
*/
errno_t write_process_log()
{
FILE *fplog;
char fname[STRINGMAXLEN_FILENAME];
pid_t thisPID;
thisPID = getpid();
WRITE_FILENAME(fname, "logreport.%05d.log", thisPID);
struct tm *uttime;
time_t tvsec0;
fplog = fopen(fname, "a");
if(fplog != NULL)
{
struct timespec tnow;
// time_t now;
clock_gettime(CLOCK_REALTIME, &tnow);
tvsec0 = tnow.tv_sec;
uttime = gmtime(&tvsec0);
fprintf(fplog, "%04d%02d%02dT%02d%02d%02d.%09ld ",
1900 + uttime->tm_year, 1 + uttime->tm_mon, uttime->tm_mday, uttime->tm_hour,
uttime->tm_min, uttime->tm_sec, tnow.tv_nsec);
fprintf(fplog, " File : %s\n", data.testpoint_file);
fprintf(fplog, " Function: %s\n", data.testpoint_func);
fprintf(fplog, " Line : %d\n", data.testpoint_line);
fprintf(fplog, " Message : %s\n", data.testpoint_msg);
fprintf(fplog, "\n");
fclose(fplog);
}
return RETURN_SUCCESS;
}
/**
* @brief Write to disk a process report
*
* This function is typically called upon crash to help debugging
*
* errortypestring describes the type of error or reason to issue report
*
*/
errno_t write_process_exit_report(
const char *restrict errortypestring
)
{
FILE *fpexit;
char fname[STRINGMAXLEN_FILENAME];
pid_t thisPID;
long fd_counter = 0;
thisPID = getpid();
WRITE_FILENAME(fname, "exitreport-%s.%05d.log", errortypestring, thisPID);
printf("EXIT CONDITION < %s >: See report in file %s\n", errortypestring,
fname);
printf(" File : %s\n", data.testpoint_file);
printf(" Function: %s\n", data.testpoint_func);
printf(" Line : %d\n", data.testpoint_line);
printf(" Message : %s\n", data.testpoint_msg);
fflush(stdout);
struct tm *uttime;
time_t tvsec0, tvsec1;
fpexit = fopen(fname, "w");
if(fpexit != NULL)
{
fprintf_stdout(fpexit, "PID : %d\n", thisPID);
struct timespec tnow;
// time_t now;
clock_gettime(CLOCK_REALTIME, &tnow);
tvsec0 = tnow.tv_sec;
uttime = gmtime(&tvsec0);
fprintf_stdout(fpexit, "Time: %04d%02d%02dT%02d%02d%02d.%09ld\n\n",
1900 + uttime->tm_year, 1 + uttime->tm_mon, uttime->tm_mday, uttime->tm_hour,
uttime->tm_min, uttime->tm_sec, tnow.tv_nsec);
fprintf_stdout(fpexit, "Last encountered test point\n");
tvsec1 = data.testpoint_time.tv_sec;
uttime = gmtime(&tvsec1);
fprintf_stdout(fpexit, " Time : %04d%02d%02dT%02d%02d%02d.%09ld\n",
1900 + uttime->tm_year, 1 + uttime->tm_mon, uttime->tm_mday, uttime->tm_hour,
uttime->tm_min, uttime->tm_sec, data.testpoint_time.tv_nsec);
double timediff = 1.0 * (tvsec0 - tvsec1) + 1.0e-9 * (tnow.tv_nsec -
data.testpoint_time.tv_nsec);
fprintf_stdout(fpexit, " %.9f sec ago\n", timediff);
fprintf_stdout(fpexit, " File : %s\n", data.testpoint_file);
fprintf_stdout(fpexit, " Function: %s\n", data.testpoint_func);
fprintf_stdout(fpexit, " Line : %d\n", data.testpoint_line);
fprintf_stdout(fpexit, " Message : %s\n", data.testpoint_msg);
fprintf_stdout(fpexit, "\n");
// Check open file descriptors
struct rlimit rlimits;
int max_fd_number;
fprintf_stdout(fpexit, "File descriptors\n");
getrlimit(RLIMIT_NOFILE, &rlimits);
max_fd_number = getdtablesize();
fprintf_stdout(fpexit, " max_fd_number : %d\n", max_fd_number);
fprintf_stdout(fpexit, " rlim_cur : %lu\n", rlimits.rlim_cur);
fprintf_stdout(fpexit, " rlim_max : %lu\n", rlimits.rlim_max);
for(int i = 0; i <= max_fd_number; i++)
{
struct stat stats;
fstat(i, &stats);
if(errno != EBADF)
{
fd_counter++;
}
}
fprintf_stdout(fpexit, " Open files : %ld\n", fd_counter);
fclose(fpexit);
}
return RETURN_SUCCESS;
}
/**
* Signal handler
*
*
*/
void sig_handler(
int signo
)
{
switch(signo)
{
case SIGINT:
printf("sig_handler received SIGINT\n");
data.signal_INT = 1;
break;
case SIGTERM:
printf("sig_handler received SIGTERM\n");
data.signal_TERM = 1;
set_terminal_echo_on();
exit(EXIT_FAILURE);
break;
case SIGUSR1:
printf("sig_handler received SIGUSR1\n");
data.signal_USR1 = 1;
break;
case SIGUSR2:
printf("sig_handler received SIGUSR2\n");
data.signal_USR2 = 1;
break;
case SIGBUS: // exit program after SIGSEGV
printf("sig_handler received SIGBUS \n");
write_process_exit_report("SIGBUS");
data.signal_BUS = 1;
set_terminal_echo_on();
exit(EXIT_FAILURE);
break;
case SIGABRT:
printf("sig_handler received SIGABRT\n");
write_process_exit_report("SIGABRT");
data.signal_ABRT = 1;
set_terminal_echo_on();
exit(EXIT_FAILURE);
break;
case SIGSEGV: // exit program after SIGSEGV
printf("sig_handler received SIGSEGV\n");
write_process_exit_report("SIGSEGV");
data.signal_SEGV = 1;
set_terminal_echo_on();
exit(EXIT_FAILURE);
break;
case SIGHUP:
printf("sig_handler received SIGHUP\n");
data.signal_HUP = 1;
break;
case SIGPIPE:
printf("sig_handler received SIGPIPE\n");
data.signal_PIPE = 1;
break;
}
}
/// CLI functions
errno_t exitCLI()
{
if(data.fifoON == 1)
{
EXECUTE_SYSTEM_COMMAND("rm %s", data.fifoname);
}
if(Listimfile == 1)
{
EXECUTE_SYSTEM_COMMAND("rm imlist.txt");
}
printf("Closing PID %ld (prompt process)\n", (long) getpid());
// exit(0);
data.CLIloopON = 0; // stop CLI loop
return RETURN_SUCCESS;
}
static errno_t printInfo()
{
float f1;
printf("\n");
printf(" PID = %d\n", CLIPID);
printf("--------------- GENERAL ----------------------\n");
printf("%s %s\n", data.package_name, data.package_version);
printf("IMAGESTRUCT_VERSION %s\n", IMAGESTRUCT_VERSION);
printf("%s BUILT %s %s\n", __FILE__, __DATE__, __TIME__);
printf("\n");
printf("--------------- SETTINGS ---------------------\n");
printf("procinfo status = %d\n", data.processinfo);
if(data.precision == 0)
{
printf("Default precision upon startup : float\n");
}
if(data.precision == 1)
{
printf("Default precision upon startup : double\n");
}
printf("sizeof(struct timespec) = %4ld bit\n",
sizeof(struct timespec) * 8);
printf("sizeof(pid_t) = %4ld bit\n", sizeof(pid_t) * 8);
printf("sizeof(short int) = %4ld bit\n", sizeof(short int) * 8);
printf("sizeof(int) = %4ld bit\n", sizeof(int) * 8);
printf("sizeof(long) = %4ld bit\n", sizeof(long) * 8);
printf("sizeof(long long) = %4ld bit\n", sizeof(long long) * 8);
printf("sizeof(int_fast8_t) = %4ld bit\n", sizeof(int_fast8_t) * 8);
printf("sizeof(int_fast16_t) = %4ld bit\n", sizeof(int_fast16_t) * 8);
printf("sizeof(int_fast32_t) = %4ld bit\n", sizeof(int_fast32_t) * 8);
printf("sizeof(int_fast64_t) = %4ld bit\n", sizeof(int_fast64_t) * 8);
printf("sizeof(uint_fast8_t) = %4ld bit\n", sizeof(uint_fast8_t) * 8);
printf("sizeof(uint_fast16_t) = %4ld bit\n",
sizeof(uint_fast16_t) * 8);
printf("sizeof(uint_fast32_t) = %4ld bit\n",
sizeof(uint_fast32_t) * 8);
printf("sizeof(uint_fast64_t) = %4ld bit\n",
sizeof(uint_fast64_t) * 8);
printf("sizeof(IMAGE_KEYWORD) = %4ld bit\n",
sizeof(IMAGE_KEYWORD) * 8);
size_t offsetval = 0;
size_t offsetval0 = 0;
printf("sizeof(IMAGE_METADATA) = %4ld bit = %4zu byte ------------------\n",
sizeof(IMAGE_METADATA) * 8, sizeof(IMAGE_METADATA));
offsetval = offsetof(IMAGE_METADATA, version);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, name);
printf(" version offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, naxis);
printf(" name offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, size);
printf(" naxis offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, nelement);
printf(" size offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, datatype);
printf(" nelement offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, imagetype);
printf(" datatype offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, creationtime);
printf(" imagetype offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, lastaccesstime);
printf(" creationtime offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, atime);
printf(" lastaccesstime offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, writetime);
printf(" atime offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, location);
printf(" writetime offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, location);
printf(" shared offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, status);
printf(" location offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, flag);
printf(" status offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, sem);
printf(" flag offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, sem);
printf(" logflag offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, cnt0);
printf(" sem offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, cnt1);
printf(" cnt0 offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, cnt2);
printf(" cnt1 offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, write);
printf(" cnt2 offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, NBkw);
printf(" write offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval, offsetval - offsetval0);
offsetval0 = offsetval;
offsetval = offsetof(IMAGE_METADATA, cudaMemHandle);
printf(" NBkw offset = %4zu bit = %4zu byte [%4zu byte]\n",
8 * offsetval0, offsetval0, offsetval - offsetval0);
offsetval0 = offsetval;
printf(" cudaMemHandle offset = %4zu bit = %4zu byte\n",
8 * offsetval0, offsetval0);
printf("sizeof(IMAGE) offset = %4zu bit = %4zu byte ------------------\n",
sizeof(IMAGE) * 8, sizeof(IMAGE));
printf(" name offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, name), offsetof(IMAGE, name));
printf(" used offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, used), offsetof(IMAGE, used));
printf(" shmfd offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, shmfd), offsetof(IMAGE, shmfd));
printf(" memsize offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, memsize), offsetof(IMAGE, memsize));
printf(" semlog offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, semlog), offsetof(IMAGE, semlog));
printf(" md offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, md), offsetof(IMAGE, md));
printf(" atimearray offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, atimearray), offsetof(IMAGE, atimearray));
printf(" writetimearray offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, writetimearray), offsetof(IMAGE,
writetimearray));
printf(" flagarray offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, flagarray), offsetof(IMAGE, flagarray));
printf(" cntarray offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, cntarray), offsetof(IMAGE, cntarray));
printf(" array offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, array), offsetof(IMAGE, array));
printf(" semptr offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, semptr), offsetof(IMAGE, semptr));
printf(" kw offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE, kw), offsetof(IMAGE, kw));
printf("sizeof(IMAGE_KEYWORD) offset = %4zu bit = %4zu byte ------------------\n",
sizeof(IMAGE_KEYWORD) * 8, sizeof(IMAGE_KEYWORD));
printf(" name offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE_KEYWORD, name), offsetof(IMAGE_KEYWORD, name));
printf(" type offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE_KEYWORD, type), offsetof(IMAGE_KEYWORD, type));
printf(" value offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE_KEYWORD, value), offsetof(IMAGE_KEYWORD, value));
printf(" comment offset = %4zu bit = %4zu byte\n",
8 * offsetof(IMAGE_KEYWORD, comment), offsetof(IMAGE_KEYWORD, comment));
printf("\n");
printf("--------------- LIBRARIES --------------------\n");
printf("READLINE : version %x\n", RL_READLINE_VERSION);
# ifdef _OPENMP
printf("OPENMP : Compiled by an OpenMP-compliant implementation.\n");
# endif
printf("CFITSIO : version %f\n", fits_get_version(&f1));
printf("\n");
printf("--------------- DIRECTORIES ------------------\n");
printf("CONFIGDIR = %s\n", data.configdir);
printf("SOURCEDIR = %s\n", data.sourcedir);
printf("\n");
printf("--------------- MALLOC INFO ------------------\n");
malloc_stats();
printf("\n");
return RETURN_SUCCESS;
}
static errno_t help()
{
EXECUTE_SYSTEM_COMMAND("more %s/src/CommandLineInterface/doc/help.txt",
data.sourcedir);
return RETURN_SUCCESS;
}
static errno_t helpreadline()
{
EXECUTE_SYSTEM_COMMAND("more %s/src/CommandLineInterface/doc/helpreadline.md",
data.sourcedir);
return RETURN_SUCCESS;
}
static errno_t help_cmd()
{
if((data.cmdargtoken[1].type == 3) || (data.cmdargtoken[1].type == 4)
|| (data.cmdargtoken[1].type == 5))
{
help_command(data.cmdargtoken[1].val.string);
}
else
{
list_commands();
}
return RETURN_SUCCESS;
}
static errno_t help_module()
{
if(data.cmdargtoken[1].type == 3)
{
list_commands_module(data.cmdargtoken[1].val.string);
}
else
{
long i;
printf("\n");
printf("%2s %10s %32s %10s %7s %20s %s\n", "#", "shortname", "Name", "Package", "Version", "last compiled",
"description");
printf("--------------------------------------------------------------------------------------------------------------\n");
for(i = 0; i < data.NBmodule; i++)
{
printf("%2ld %10s \033[1m%32s\033[0m %10s %2d.%02d.%02d %11s %8s %s\n",
i, data.module[i].shortname,
data.module[i].name,
data.module[i].package,
data.module[i].versionmajor, data.module[i].versionminor, data.module[i].versionpatch,
data.module[i].datestring, data.module[i].timestring,
data.module[i].info);
}
printf("-------------------------------------------------------------------------------------------------------\n");
printf("\n");
}
return RETURN_SUCCESS;
}
static errno_t load_so()
{
load_sharedobj(data.cmdargtoken[1].val.string);
return CLICMD_SUCCESS;
}
static errno_t load_module()
{
if(data.cmdargtoken[1].type == 3)
{
load_module_shared(data.cmdargtoken[1].val.string);
return CLICMD_SUCCESS;
}
else
{
return CLICMD_INVALID_ARG;
}
}
static errno_t CLIcore__load_module_as__cli()
{
if(0
+ CLI_checkarg(1, CLIARG_STR)
+ CLI_checkarg(2, CLIARG_STR)
== 0)
{
strcpy(data.moduleshortname, data.cmdargtoken[2].val.string);
load_module_shared(data.cmdargtoken[1].val.string);
return CLICMD_SUCCESS;
}
else
{
return CLICMD_INVALID_ARG;
}
}
errno_t set_processinfoON()
{
data.processinfo = 1;
return RETURN_SUCCESS;
}
errno_t set_processinfoOFF()
{
data.processinfo = 0;
return RETURN_SUCCESS;
}
errno_t set_default_precision_single()
{
data.precision = 0;
return RETURN_SUCCESS;
}
errno_t set_default_precision_double()
{
data.precision = 1;
return RETURN_SUCCESS;
}
errno_t cfits_usleep_cli()
{
if(data.cmdargtoken[1].type == 2)
{
usleep(data.cmdargtoken[1].val.numl);
return RETURN_SUCCESS;
}
else
{
return RETURN_FAILURE;
}
}
errno_t functionparameter_CTRLscreen_cli()
{
if((CLI_checkarg(1, 2) == 0) && (CLI_checkarg(2, 5) == 0)
&& (CLI_checkarg(3, 5) == 0))
{
functionparameter_CTRLscreen((uint32_t) data.cmdargtoken[1].val.numl,
data.cmdargtoken[2].val.string, data.cmdargtoken[3].val.string);
return RETURN_SUCCESS;
}
else
{
printf("Wrong args (%d)\n", data.cmdargtoken[1].type);
}
return RETURN_SUCCESS;
}
errno_t processinfo_CTRLscreen_cli()
{