cfitsTK
CLIcore.h
Go to the documentation of this file.
1 
14 #define _GNU_SOURCE
15 
16 
17 #ifndef _CLICORE_H
18 #define _CLICORE_H
19 
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <semaphore.h>
27 #include <fftw3.h>
28 #include <gsl/gsl_rng.h> // for random numbers
29 #include <signal.h>
30 
31 
32 #include "ImageStruct.h"
33 
34 
35 #define PI 3.14159265358979323846264338328
36 
38 #define SZ_CLICOREVARRAY 1000
39 
41 extern pid_t CLIPID;
42 extern char DocDir[200]; // location of documentation
43 extern char SrcDir[200]; // location of source
44 extern char BuildFile[200]; // file name for source
45 extern char BuildDate[200];
46 extern char BuildTime[200];
47 
48 extern int C_ERRNO; // C errno (from errno.h)
49 
50 /* #define DEBUG */
51 #define CFITSEXIT printf("Program abnormally terminated, File \"%s\", line %d\n", __FILE__, __LINE__);exit(0)
52 
53 #ifdef DEBUG
54 #define nmalloc(f,type,n) f = (type*) malloc(sizeof(type)*n);if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}else{printf("\nMALLOC: \""#f "\" allocated\n");}
55 #define nfree(f) free(f);printf("\nMALLOC: \""#f"\" freed\n");
56 #else
57 #define nmalloc(f,type,n) f = (type*) malloc(sizeof(type)*n);if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}
58 #define nfree(f) free(f);
59 #endif
60 
61 #define TEST_ALLOC(f) if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}
62 
63 
64 #define NB_ARG_MAX 20
65 
66 
67 
68 // declare a boolean type "BOOL"
69 // TRUE and FALSE improve code readability
70 //
71 typedef uint_fast8_t BOOL;
72 #define FALSE 0
73 #define TRUE 1
74 
75 
76 
77 
78 //Need to install process with setuid. Then, so you aren't running privileged all the time do this:
79 extern uid_t euid_real;
80 extern uid_t euid_called;
81 extern uid_t suid;
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 /*^-----------------------------------------------------------------------------
92 | commands available through the CLI
93 +-----------------------------------------------------------------------------*/
94 
95 
96 
97 typedef struct {
98  char key[100]; // command keyword
99  char module[50]; // module name
100  int_fast8_t (* fp) (); // command function pointer
101  char info [1000]; // short description/help
102  char syntax [1000]; // command syntax
103  char example[1000]; // command example
104  char Ccall[1000];
105 } CMD;
106 
107 
108 
109 typedef struct {
110  char name[50]; // module name
111  char info[1000]; // short description
112 } MODULE;
113 
114 
115 
116 
117 /* ---------------------------------------------------------- */
118 /* */
119 /* */
120 /* COMMAND LINE ARGs / TOKENS */
121 /* */
122 /* */
123 /* ---------------------------------------------------------- */
124 
125 
126 // The command line is parsed and
127 
128 // cmdargtoken type
129 // 0 : unsolved
130 // 1 : floating point (double precision)
131 // 2 : long
132 // 3 : string
133 // 4 : existing image
134 // 5 : command
135 typedef struct
136 {
137  int type;
138  union
139  {
140  double numf;
141  long numl;
142  char string[200];
143  } val;
144 } CMDARGTOKEN;
145 
146 
147 
148 int CLI_checkarg(int argnum, int argtype);
149 int CLI_checkarg_noerrmsg(int argnum, int argtype);
150 
151 
152 
153 
154 
155 
156 extern uint8_t TYPESIZE[32];
157 
158 
159 
160 
161 typedef struct
162 {
163  int used;
164  char name[80];
165  int type;
166  union
167  {
168  double f;
169  long l;
170  char s[80];
171  } value;
172  char comment[200];
173 } VARIABLE;
174 
175 
176 
177 
178 
179 // THIS IS WHERE EVERYTHING THAT NEEDS TO BE WIDELY ACCESSIBLE GETS STORED
180 typedef struct
181 {
182  struct sigaction sigact;
183  // signals toggle flags
193 
194  int Debug;
195  int quiet;
196  int overwrite; // automatically overwrite FITS files
197  double INVRANDMAX;
198  gsl_rng *rndgen; // random number generator
199  int precision; // default precision: 0 for float, 1 for double
200 
201  // logging
202  int CLIlogON;
203  char CLIlogname[200];
204 
205  // Command Line Interface (CLI) INPUT
206  int fifoON;
207  char processname[100];
208  char fifoname[100];
209  uint_fast16_t NBcmd;
212  int parseerror; // 1 if error, 0 otherwise
213  long cmdNBarg; // number of arguments in last command line
214  CMDARGTOKEN cmdargtoken[NB_ARG_MAX];
215  long cmdindex; // when command is found in command line, holds index of command
216  long calctmp_imindex; // used to create temporary images
217  int CMDexecuted; // 0 if command has not been executed, 1 otherwise
218  long NBmodule;
221 
222 
223  // shared memory default
225 
226  // Number of keyword per iamge default
228 
229  // images, variables
231  IMAGE *image;
232 
235  /*
236  long NB_MAX_VARIABLELONG;
237  VARIABLELONG *variablelong;
238 
239  long NB_MAX_VARIABLESTRING;
240  VARIABLESTRING *variablestring;
241  */
242 
243  float FLOATARRAY[1000]; // array to store temporary variables
244  double DOUBLEARRAY[1000]; // for convenience
245  char SAVEDIR[500];
246 
247  // status counter (used for profiling)
248  int status0;
249  int status1;
250 } DATA;
251 
252 
253 
254 
255 
256 
257 #define MAX_NB_FRAMES 500
258 #define MAX_NB_FRAMENAME_CHAR 500
259 #define MAX_NB_EXCLUSIONS 40
260 
261 
262 void sig_handler(int signo);
263 
264 uint_fast16_t RegisterCLIcommand(char *CLIkey, char *CLImodule, int_fast8_t (*CLIfptr)(), char *CLIinfo, char *CLIsyntax, char *CLIexample, char *CLICcall);
265 
266 
267 
268 #endif
int status0
Definition: CLIcore.h:248
int NBKEWORD_DFT
Definition: CLIcore.h:227
Definition: CLIcore.h:180
long l
Definition: CLIcore.h:169
int precision
Definition: CLIcore.h:199
int CLI_checkarg(int argnum, int argtype)
Definition: CLIcore.c:2011
char SrcDir[200]
Definition: CLIcore.c:135
uint_fast16_t RegisterCLIcommand(char *CLIkey, char *CLImodule, int_fast8_t(*CLIfptr)(), char *CLIinfo, char *CLIsyntax, char *CLIexample, char *CLICcall)
Definition: CLIcore.c:632
MODULE * module
Definition: CLIcore.h:220
long numl
Definition: CLIcore.h:141
int status1
Definition: CLIcore.h:249
long NB_MAX_VARIABLE
Definition: CLIcore.h:233
gsl_rng * rndgen
Definition: CLIcore.h:198
int signal_USR1
Definition: CLIcore.h:184
int C_ERRNO
Definition: CLIcore.c:146
double INVRANDMAX
Definition: CLIcore.h:197
uint_fast8_t BOOL
Definition: CLIcore.h:71
long NB_MAX_MODULE
Definition: CLIcore.h:219
Definition: CLIcore.h:97
int Debug
Definition: CLIcore.h:194
double numf
Definition: CLIcore.h:140
int type
Definition: CLIcore.h:165
long cmdindex
Definition: CLIcore.h:215
int signal_PIPE
Definition: CLIcore.h:192
int type
Definition: CLIcore.h:137
int parseerror
Definition: CLIcore.h:212
int CLIlogON
Definition: CLIcore.h:202
char BuildTime[200]
Definition: CLIcore.c:138
int signal_BUS
Definition: CLIcore.h:190
long calctmp_imindex
Definition: CLIcore.h:216
VARIABLE * variable
Definition: CLIcore.h:234
long NB_MAX_IMAGE
Definition: CLIcore.h:230
int signal_ABRT
Definition: CLIcore.h:189
long cmdNBarg
Definition: CLIcore.h:213
int signal_HUP
Definition: CLIcore.h:191
uint8_t TYPESIZE[32]
Definition: CLIcore.c:144
int CLI_checkarg_noerrmsg(int argnum, int argtype)
Definition: CLIcore.c:2020
Definition: CLIcore.h:161
int CMDexecuted
Definition: CLIcore.h:217
Image structure definition.
uid_t suid
Definition: CLIcore.c:142
uint_fast16_t NBcmd
Definition: CLIcore.h:209
IMAGE * image
Definition: CLIcore.h:231
CMD * cmd
Definition: CLIcore.h:211
int signal_TERM
Definition: CLIcore.h:186
uid_t euid_called
Definition: CLIcore.c:141
int signal_SEGV
Definition: CLIcore.h:188
long NB_MAX_COMMAND
Definition: CLIcore.h:210
Definition: CLIcore.h:109
uid_t euid_real
Definition: CLIcore.c:140
int SHARED_DFT
Definition: CLIcore.h:224
char DocDir[200]
Definition: CLIcore.c:134
int signal_USR2
Definition: CLIcore.h:185
double f
Definition: CLIcore.h:168
int signal_INT
Definition: CLIcore.h:187
void sig_handler(int signo)
signal catching
Definition: CLIcore.c:227
long NBmodule
Definition: CLIcore.h:218
int quiet
Definition: CLIcore.h:195
pid_t CLIPID
important directories and info
Definition: CLIcore.c:133
int used
Definition: CLIcore.h:163
char BuildDate[200]
Definition: CLIcore.c:137
int overwrite
Definition: CLIcore.h:196
char BuildFile[200]
Definition: CLIcore.c:136
Definition: CLIcore.h:135
int fifoON
Definition: CLIcore.h:206