aboutsummaryrefslogtreecommitdiff
path: root/pathologist/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'pathologist/src/include')
-rw-r--r--pathologist/src/include/Makefile.am9
-rw-r--r--pathologist/src/include/gdbmi.h730
-rw-r--r--pathologist/src/include/monkey_common.h443
-rw-r--r--pathologist/src/include/monkey_getopt_lib.h367
-rw-r--r--pathologist/src/include/mxml.h329
-rw-r--r--pathologist/src/include/platform.h266
-rw-r--r--pathologist/src/include/plibc.h810
7 files changed, 2954 insertions, 0 deletions
diff --git a/pathologist/src/include/Makefile.am b/pathologist/src/include/Makefile.am
new file mode 100644
index 0000000..b301e48
--- /dev/null
+++ b/pathologist/src/include/Makefile.am
@@ -0,0 +1,9 @@
1SUBDIRS = .
2
3monkeyincludedir = $(includedir)/monkey
4
5monkeyinclude_HEADERS = \
6 monkey_common.h \
7 plibc.h \
8 gdbmi.h \
9 mxml.h
diff --git a/pathologist/src/include/gdbmi.h b/pathologist/src/include/gdbmi.h
new file mode 100644
index 0000000..588c50b
--- /dev/null
+++ b/pathologist/src/include/gdbmi.h
@@ -0,0 +1,730 @@
1/**[txh]********************************************************************
2
3 Copyright (c) 2004-2009 by Salvador E. Tropea.
4 Covered by the GPL license.
5
6 Comments:
7 Main header for libmigdb.
8
9***************************************************************************/
10
11#ifndef GDBMI_H
12#define GDBMI_H
13
14#ifdef __cplusplus
15extern "C"
16{
17#if 0 /* keep Emacsens' auto-indent happy */
18}
19#endif
20#endif
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <unistd.h> /* pid_t */
25
26#define MI_OK 0
27#define MI_OUT_OF_MEMORY 1
28#define MI_PIPE_CREATE 2
29#define MI_FORK 3
30#define MI_DEBUGGER_RUN 4
31#define MI_PARSER 5
32#define MI_UNKNOWN_ASYNC 6
33#define MI_UNKNOWN_RESULT 7
34#define MI_FROM_GDB 8
35#define MI_GDB_TIME_OUT 9
36#define MI_GDB_DIED 10
37#define MI_MISSING_XTERM 11
38#define MI_CREATE_TEMPORAL 12
39#define MI_MISSING_GDB 13
40#define MI_LAST_ERROR 13
41
42#define MI_R_NONE 0 /* We are no waiting any response. */
43#define MI_R_SKIP 1 /* We want to discard it. */
44#define MI_R_FE_AND_S 2 /* Wait for done. */
45#define MI_R_E_ARGS 3
46
47enum mi_val_type { t_const, t_tuple, t_list };
48
49/* Types and subtypes. */
50/* Type. */
51#define MI_T_OUT_OF_BAND 0
52#define MI_T_RESULT_RECORD 1
53/* Out of band subtypes. */
54#define MI_ST_ASYNC 0
55#define MI_ST_STREAM 1
56/* Async sub-subtypes. */
57#define MI_SST_EXEC 0
58#define MI_SST_STATUS 1
59#define MI_SST_NOTIFY 2
60/* Stream sub-subtypes. */
61#define MI_SST_CONSOLE 3
62#define MI_SST_TARGET 4
63#define MI_SST_LOG 5
64/* Classes. */
65/* Async classes. */
66#define MI_CL_UNKNOWN 0
67#define MI_CL_STOPPED 1
68#define MI_CL_DOWNLOAD 2
69/* Result classes. */
70#define MI_CL_DONE 2
71#define MI_CL_RUNNING 3
72#define MI_CL_CONNECTED 4
73#define MI_CL_ERROR 5
74#define MI_CL_EXIT 6
75
76#define MI_DEFAULT_TIME_OUT 10
77
78#define MI_DIS_ASM 0
79#define MI_DIS_SRC_ASM 1
80
81/* Implemented workaround for gdb bugs that we can dis/enable. */
82/* At least gdb<=6.1.1 fails to find a source file with absolute path if the
83 name is for a psym instead of a sym. psym==partially loaded symbol table. */
84#define MI_PSYM_SEARCH 0
85
86#define MI_VERSION_STR "0.8.12"
87#define MI_VERSION_MAJOR 0
88#define MI_VERSION_MIDDLE 8
89#define MI_VERSION_MINOR 12
90
91struct mi_results_struct
92{
93 char *var; /* Result name or NULL if just a value. */
94 enum mi_val_type type;
95 union
96 {
97 char *cstr;
98 struct mi_results_struct *rs;
99 } v;
100 struct mi_results_struct *next;
101};
102typedef struct mi_results_struct mi_results;
103
104struct mi_output_struct
105{
106 /* Type of output. */
107 char type;
108 char stype;
109 char sstype;
110 char tclass;
111 /* Content. */
112 mi_results *c;
113 /* Always modeled as a list. */
114 struct mi_output_struct *next;
115};
116typedef struct mi_output_struct mi_output;
117
118typedef void (*stream_cb)(const char *, void *);
119typedef void (*async_cb)(mi_output *o, void *);
120typedef int (*tm_cb)(void *);
121
122/* Values of this structure shouldn't be manipulated by the user. */
123struct mi_h_struct
124{
125 /* Pipes connected to gdb. */
126 int to_gdb[2];
127 int from_gdb[2];
128 /* Streams for the pipes. */
129 FILE *to, *from;
130 /* PID of child gdb. */
131 pid_t pid;
132 char died;
133 /* Which rensponse we are waiting for. */
134 /*int response;*/
135 /* The line we are reading. */
136 char *line;
137 int llen, lread;
138 /* Parsed output. */
139 mi_output *po, *last;
140 /* Tunneled streams callbacks. */
141 stream_cb console;
142 void *console_data;
143 stream_cb target;
144 void *target_data;
145 stream_cb log;
146 void *log_data;
147 /* Async responses callback. */
148 async_cb async;
149 void *async_data;
150 /* Callbacks to get echo of gdb dialog. */
151 stream_cb to_gdb_echo;
152 void *to_gdb_echo_data;
153 stream_cb from_gdb_echo;
154 void *from_gdb_echo_data;
155 /* Time out */
156 tm_cb time_out_cb;
157 void *time_out_cb_data;
158 int time_out;
159 /* Ugly workaround for some of the show responses :-( */
160 int catch_console;
161 char *catched_console;
162 /* MI version, currently unknown but the user can force v2 */
163 unsigned version;
164};
165typedef struct mi_h_struct mi_h;
166
167#define MI_TO(a) ((a)->to_gdb[1])
168
169enum mi_bkp_type { t_unknown=0, t_breakpoint=1, t_hw=2 };
170enum mi_bkp_disp { d_unknown=0, d_keep=1, d_del=2 };
171enum mi_bkp_mode { m_file_line=0, m_function=1, m_file_function=2, m_address=3 };
172
173struct mi_bkpt_struct
174{
175 int number;
176 enum mi_bkp_type type;
177 enum mi_bkp_disp disp; /* keep or del if temporal */
178 char enabled;
179 void *addr;
180 char *func;
181 char *file;
182 int line;
183 int ignore;
184 int times;
185
186 /* For the user: */
187 char *cond;
188 char *file_abs;
189 int thread;
190 enum mi_bkp_mode mode;
191 struct mi_bkpt_struct *next;
192};
193typedef struct mi_bkpt_struct mi_bkpt;
194
195enum mi_wp_mode { wm_unknown=0, wm_write=1, wm_read=2, wm_rw=3 };
196
197struct mi_wp_struct
198{
199 int number;
200 char *exp;
201 enum mi_wp_mode mode;
202
203 /* For the user: */
204 struct mi_wp_struct *next;
205 char enabled;
206};
207typedef struct mi_wp_struct mi_wp;
208
209struct mi_frames_struct
210{
211 int level; /* The frame number, 0 being the topmost frame, i.e. the innermost
212 function. */
213 void *addr; /* The `$pc' value for that frame. */
214 char *func; /* Function name. */
215 char *file; /* File name of the source file where the function lives. */
216 char *from;
217 int line; /* Line number corresponding to the `$pc'. */
218 /* When arguments are available: */
219 mi_results *args;
220 int thread_id;
221 /* When more than one is provided: */
222 struct mi_frames_struct *next;
223};
224typedef struct mi_frames_struct mi_frames;
225
226struct mi_aux_term_struct
227{
228 pid_t pid;
229 char *tty;
230};
231typedef struct mi_aux_term_struct mi_aux_term;
232
233struct mi_pty_struct
234{
235 char *slave;
236 int master;
237};
238typedef struct mi_pty_struct mi_pty;
239
240enum mi_gvar_fmt { fm_natural=0, fm_binary=1, fm_decimal=2, fm_hexadecimal=3,
241 fm_octal=4,
242 /* Only for registers format: */
243 fm_raw=5 };
244enum mi_gvar_lang { lg_unknown=0, lg_c, lg_cpp, lg_java };
245
246#define MI_ATTR_DONT_KNOW 0
247#define MI_ATTR_NONEDITABLE 1
248#define MI_ATTR_EDITABLE 2
249
250struct mi_gvar_struct
251{
252 char *name;
253 int numchild;
254 char *type;
255 enum mi_gvar_fmt format;
256 enum mi_gvar_lang lang;
257 char *exp;
258 int attr;
259
260 /* MI v2 fills it, not yet implemented here. */
261 /* Use gmi_var_evaluate_expression. */
262 char *value;
263
264 /* Pointer to the parent. NULL if none. */
265 struct mi_gvar_struct *parent;
266 /* List containing the children.
267 Filled by gmi_var_list_children.
268 NULL if numchild==0 or not yet filled. */
269 struct mi_gvar_struct *child;
270 /* Next var in the list. */
271 struct mi_gvar_struct *next;
272
273 /* For the user: */
274 char opened; /* We will show its children. 1 when we fill "child" */
275 char changed; /* Needs to be updated. 0 when created. */
276 int vischild; /* How many items visible. numchild when we fill "child" */
277 int depth; /* How deep is this var. */
278 char ispointer;
279};
280typedef struct mi_gvar_struct mi_gvar;
281
282struct mi_gvar_chg_struct
283{
284 char *name;
285 int in_scope; /* if true the other fields apply. */
286 char *new_type; /* NULL if type_changed==false */
287 int new_num_children; /* only when new_type!=NULL */
288
289 struct mi_gvar_chg_struct *next;
290};
291typedef struct mi_gvar_chg_struct mi_gvar_chg;
292
293
294/* A list of assembler instructions. */
295struct mi_asm_insn_struct
296{
297 void *addr;
298 char *func;
299 unsigned offset;
300 char *inst;
301
302 struct mi_asm_insn_struct *next;
303};
304typedef struct mi_asm_insn_struct mi_asm_insn;
305
306/* A list of source lines containing assembler instructions. */
307struct mi_asm_insns_struct
308{
309 char *file;
310 int line;
311 mi_asm_insn *ins;
312
313 struct mi_asm_insns_struct *next;
314};
315typedef struct mi_asm_insns_struct mi_asm_insns;
316
317/* Changed register. */
318struct mi_chg_reg_struct
319{
320 int reg;
321 char *val;
322 char *name;
323 char updated;
324
325 struct mi_chg_reg_struct *next;
326};
327typedef struct mi_chg_reg_struct mi_chg_reg;
328
329/*
330 Examining gdb sources and looking at docs I can see the following "stop"
331reasons:
332
333Breakpoints:
334a) breakpoint-hit (bkptno) + frame
335Also: without reason for temporal breakpoints.
336
337Watchpoints:
338b) watchpoint-trigger (wpt={number,exp};value={old,new}) + frame
339c) read-watchpoint-trigger (hw-rwpt{number,exp};value={value}) + frame
340d) access-watchpoint-trigger (hw-awpt{number,exp};value={[old,]new}) + frame
341e) watchpoint-scope (wpnum) + frame
342
343Movement:
344f) function-finished ([gdb-result-var,return-value]) + frame
345g) location-reached + frame
346h) end-stepping-range + frame
347
348Exit:
349i) exited-signalled (signal-name,signal-meaning)
350j) exited (exit-code)
351k) exited-normally
352
353Signal:
354l) signal-received (signal-name,signal-meaning) + frame
355
356Plus: thread-id
357*/
358enum mi_stop_reason
359{
360 sr_unknown=0,
361 sr_bkpt_hit,
362 sr_wp_trigger, sr_read_wp_trigger, sr_access_wp_trigger, sr_wp_scope,
363 sr_function_finished, sr_location_reached, sr_end_stepping_range,
364 sr_exited_signalled, sr_exited, sr_exited_normally,
365 sr_signal_received
366};
367
368struct mi_stop_struct
369{
370 enum mi_stop_reason reason; /* If more than one reason just the last. */
371 /* Flags indicating if non-pointer fields are filled. */
372 char have_thread_id;
373 char have_bkptno;
374 char have_exit_code;
375 char have_wpno;
376 /* Where stopped. Doesn't exist for sr_exited*. */
377 int thread_id;
378 mi_frames *frame;
379 /* sr_bkpt_hit */
380 int bkptno;
381 /* sr_*wp_* no scope */
382 mi_wp *wp;
383 char *wp_old;
384 char *wp_val;
385 /* sr_wp_scope */
386 int wpno;
387 /* sr_function_finished. Not for void func. */
388 char *gdb_result_var;
389 char *return_value;
390 /* sr_exited_signalled, sr_signal_received */
391 char *signal_name;
392 char *signal_meaning;
393 /* sr_exited */
394 int exit_code;
395};
396typedef struct mi_stop_struct mi_stop;
397
398/* Variable containing the last error. */
399extern int mi_error;
400extern char *mi_error_from_gdb;
401const char *mi_get_error_str();
402
403/* Indicate the name of gdb exe. Default is /usr/bin/gdb */
404void mi_set_gdb_exe(const char *name);
405const char *mi_get_gdb_exe();
406/* Indicate the name of a file containing commands to send at start-up */
407void mi_set_gdb_start(const char *name);
408const char *mi_get_gdb_start();
409/* Indicate the name of a file containing commands to send after connection */
410void mi_set_gdb_conn(const char *name);
411const char *mi_get_gdb_conn();
412void mi_send_target_commands(mi_h *h);
413/* Connect to a local copy of gdb. */
414mi_h *mi_connect_local();
415/* Close connection. You should ask gdb to quit first. */
416void mi_disconnect(mi_h *h);
417/* Force MI version. */
418#define MI_VERSION2U(maj,mid,min) (maj*0x1000000+mid*0x10000+min)
419void mi_force_version(mi_h *h, unsigned vMajor, unsigned vMiddle,
420 unsigned vMinor);
421void mi_set_workaround(unsigned wa, int enable);
422int mi_get_workaround(unsigned wa);
423/* Parse gdb output. */
424mi_output *mi_parse_gdb_output(const char *str);
425/* Functions to set/get the tunneled streams callbacks. */
426void mi_set_console_cb(mi_h *h, stream_cb cb, void *data);
427void mi_set_target_cb(mi_h *h, stream_cb cb, void *data);
428void mi_set_log_cb(mi_h *h, stream_cb cb, void *data);
429stream_cb mi_get_console_cb(mi_h *h, void **data);
430stream_cb mi_get_target_cb(mi_h *h, void **data);
431stream_cb mi_get_log_cb(mi_h *h, void **data);
432/* The callback to deal with async events. */
433void mi_set_async_cb(mi_h *h, async_cb cb, void *data);
434async_cb mi_get_async_cb(mi_h *h, void **data);
435/* Time out in gdb responses. */
436void mi_set_time_out_cb(mi_h *h, tm_cb cb, void *data);
437tm_cb mi_get_time_out_cb(mi_h *h, void **data);
438void mi_set_time_out(mi_h *h, int to);
439int mi_get_time_out(mi_h *h);
440/* Callbacks to "see" the dialog with gdb. */
441void mi_set_to_gdb_cb(mi_h *h, stream_cb cb, void *data);
442void mi_set_from_gdb_cb(mi_h *h, stream_cb cb, void *data);
443stream_cb mi_get_to_gdb_cb(mi_h *h, void **data);
444stream_cb mi_get_from_gdb_cb(mi_h *h, void **data);
445/* Sends a message to gdb. */
446int mi_send(mi_h *h, const char *format, ...);
447/* Wait until gdb sends a response. */
448mi_output *mi_get_response_blk(mi_h *h);
449/* Check if gdb sent a complete response. Use with mi_retire_response. */
450int mi_get_response(mi_h *h);
451/* Get the last response. Use with mi_get_response. */
452mi_output *mi_retire_response(mi_h *h);
453/* Look for a result record in gdb output. */
454mi_output *mi_get_rrecord(mi_output *r);
455/* Look if the output contains an async stop.
456 If that's the case return the reason for the stop.
457 If the output contains an error the description is returned in reason. */
458int mi_get_async_stop_reason(mi_output *r, char **reason);
459mi_stop *mi_get_stopped(mi_results *r);
460mi_frames *mi_get_async_frame(mi_output *r);
461/* Wait until gdb sends a response.
462 Then check if the response is of the desired type. */
463int mi_res_simple_exit(mi_h *h);
464int mi_res_simple_done(mi_h *h);
465int mi_res_simple_running(mi_h *h);
466int mi_res_simple_connected(mi_h *h);
467/* It additionally extracts an specified variable. */
468mi_results *mi_res_done_var(mi_h *h, const char *var);
469/* Extract a frames list from the response. */
470mi_frames *mi_res_frames_array(mi_h *h, const char *var);
471mi_frames *mi_res_frames_list(mi_h *h);
472mi_frames *mi_parse_frame(mi_results *c);
473mi_frames *mi_res_frame(mi_h *h);
474/* Create an auxiliar terminal using xterm. */
475mi_aux_term *gmi_start_xterm();
476/* Indicate the name of xterm exe. Default is /usr/bin/X11/xterm */
477void mi_set_xterm_exe(const char *name);
478const char *mi_get_xterm_exe();
479/* Kill the auxiliar terminal and release the structure. */
480void gmi_end_aux_term(mi_aux_term *t);
481/* Look for a free Linux VT for the child. */
482mi_aux_term *gmi_look_for_free_vt();
483/* Look for a free and usable Linux VT. */
484int mi_look_for_free_vt();
485/* Close master and release the structure. */
486void gmi_end_pty(mi_pty *p);
487/* Look for a free pseudo terminal. */
488mi_pty *gmi_look_for_free_pty();
489/* Extract a list of thread IDs from response. */
490int mi_res_thread_ids(mi_h *h, int **list);
491int mi_get_thread_ids(mi_output *res, int **list);
492/* A variable response. */
493mi_gvar *mi_res_gvar(mi_h *h, mi_gvar *cur, const char *expression);
494enum mi_gvar_fmt mi_format_str_to_enum(const char *format);
495const char *mi_format_enum_to_str(enum mi_gvar_fmt format);
496char mi_format_enum_to_char(enum mi_gvar_fmt format);
497enum mi_gvar_lang mi_lang_str_to_enum(const char *lang);
498const char *mi_lang_enum_to_str(enum mi_gvar_lang lang);
499int mi_res_changelist(mi_h *h, mi_gvar_chg **changed);
500int mi_res_children(mi_h *h, mi_gvar *v);
501mi_bkpt *mi_res_bkpt(mi_h *h);
502mi_wp *mi_res_wp(mi_h *h);
503char *mi_res_value(mi_h *h);
504mi_stop *mi_res_stop(mi_h *h);
505enum mi_stop_reason mi_reason_str_to_enum(const char *s);
506const char *mi_reason_enum_to_str(enum mi_stop_reason r);
507int mi_get_read_memory(mi_h *h, unsigned char *dest, unsigned ws, int *na,
508 unsigned long *addr);
509mi_asm_insns *mi_get_asm_insns(mi_h *h);
510/* Starting point of the program. */
511void mi_set_main_func(const char *name);
512const char *mi_get_main_func();
513mi_chg_reg *mi_get_list_registers(mi_h *h, int *how_many);
514int mi_get_list_registers_l(mi_h *h, mi_chg_reg *l);
515mi_chg_reg *mi_get_list_changed_regs(mi_h *h);
516int mi_get_reg_values(mi_h *h, mi_chg_reg *l);
517mi_chg_reg *mi_get_reg_values_l(mi_h *h, int *how_many);
518int gmi_target_download(mi_h *h);
519
520/* Allocation functions: */
521void *mi_calloc(size_t count, size_t sz);
522void *mi_calloc1(size_t sz);
523char *mi_malloc(size_t sz);
524mi_results *mi_alloc_results(void);
525mi_output *mi_alloc_output(void);
526mi_frames *mi_alloc_frames(void);
527mi_gvar *mi_alloc_gvar(void);
528mi_gvar_chg *mi_alloc_gvar_chg(void);
529mi_bkpt *mi_alloc_bkpt(void);
530mi_wp *mi_alloc_wp(void);
531mi_stop *mi_alloc_stop(void);
532mi_asm_insns *mi_alloc_asm_insns(void);
533mi_asm_insn *mi_alloc_asm_insn(void);
534mi_chg_reg *mi_alloc_chg_reg(void);
535void mi_free_output(mi_output *r);
536void mi_free_output_but(mi_output *r, mi_output *no, mi_results *no_r);
537void mi_free_frames(mi_frames *f);
538void mi_free_aux_term(mi_aux_term *t);
539void mi_free_results(mi_results *r);
540void mi_free_results_but(mi_results *r, mi_results *no);
541void mi_free_gvar(mi_gvar *v);
542void mi_free_gvar_chg(mi_gvar_chg *p);
543void mi_free_wp(mi_wp *wp);
544void mi_free_stop(mi_stop *s);
545void mi_free_asm_insns(mi_asm_insns *i);
546void mi_free_asm_insn(mi_asm_insn *i);
547void mi_free_charp_list(char **l);
548void mi_free_chg_reg(mi_chg_reg *r);
549
550/* Porgram control: */
551/* Specify the executable and arguments for local debug. */
552int gmi_set_unwind_on_signal_on(mi_h * h);
553int gmi_set_exec(mi_h *h, const char *file, const char *args);
554/* Start running the executable. Remote sessions starts running. */
555int gmi_exec_run(mi_h *h);
556/* Continue the execution after a "stop". */
557int gmi_exec_continue(mi_h *h);
558/* Continue the execution in reverse order after a "stop". */
559int gmi_exec_continue_reverse(mi_h *h);
560/* Indicate which terminal will use the target program. For local sessions. */
561int gmi_target_terminal(mi_h *h, const char *tty_name);
562/* Specify what's the local copy that have debug info. For remote sessions. */
563int gmi_file_symbol_file(mi_h *h, const char *file);
564/* Continue until function return, the return value is included in the async
565 response. */
566int gmi_exec_finish(mi_h *h);
567/* Continue backwardly until function return, the return value is included in
568 the async response.*/
569int gmi_exec_finish_reverse(mi_h *h);
570/* Stop the program using SIGINT. */
571int gmi_exec_interrupt(mi_h *h);
572/* Next line of code. */
573int gmi_exec_next(mi_h *h);
574/* Start recording a process */
575int gmi_exec_record_process(mi_h *h);
576/* Stop recording a process */
577int gmi_exec_record_stop(mi_h *h);
578/* Next count lines of code. */
579int gmi_exec_next_cnt(mi_h *h, int count);
580/* Next line of assembler code. */
581int gmi_exec_next_instruction(mi_h *h);
582/* Next line of code. Get inside functions. */
583int gmi_exec_step(mi_h *h);
584/* Previous line of code. Get inside functions. */
585int gmi_exec_step_back(mi_h *h);
586/* Previous line of code (do not step into).*/
587int gmi_exec_next_reverse(mi_h *h);
588/* Next count lines of code. Get inside functions. */
589int gmi_exec_step_cnt(mi_h *h, int count);
590/* Next line of assembler code. Get inside calls. */
591int gmi_exec_step_instruction(mi_h *h);
592/* Execute until location is reached. If file is NULL then is until next line. */
593int gmi_exec_until(mi_h *h, const char *file, int line);
594int gmi_exec_until_addr(mi_h *h, void *addr);
595/* Return to previous frame inmediatly. */
596mi_frames *gmi_exec_return(mi_h *h);
597/* Just kill the program. Please read the notes in prg_control.c. */
598int gmi_exec_kill(mi_h *h);
599
600/* Target manipulation: */
601/* Connect to a remote gdbserver using the specified methode. */
602int gmi_target_select(mi_h *h, const char *type, const char *params);
603/* Attach to an already running process. */
604mi_frames *gmi_target_attach(mi_h *h, pid_t pid);
605/* Detach from an attached process. */
606int gmi_target_detach(mi_h *h);
607
608/* Miscellaneous commands: */
609/* Exit gdb killing the child is it is running. */
610void gmi_gdb_exit(mi_h *h);
611/* Send the version to the console. */
612int gmi_gdb_version(mi_h *h);
613/* Set a gdb variable. */
614int gmi_gdb_set(mi_h *h, const char *var, const char *val);
615/* Get a gdb variable. */
616char *gmi_gdb_show(mi_h *h, const char *var);
617
618/* Breakpoints manipulation: */
619/* Insert a breakpoint at file:line. */
620mi_bkpt *gmi_break_insert(mi_h *h, const char *file, int line);
621/* Insert a breakpoint, all available options. */
622mi_bkpt *gmi_break_insert_full(mi_h *h, int temporary, int hard_assist,
623 const char *cond, int count, int thread,
624 const char *where);
625mi_bkpt *gmi_break_insert_full_fl(mi_h *h, const char *file, int line,
626 int temporary, int hard_assist,
627 const char *cond, int count, int thread);
628/* Remove a breakpoint. */
629int gmi_break_delete(mi_h *h, int number);
630/* Free the memory used for a breakpoint description. */
631void mi_free_bkpt(mi_bkpt *b);
632/* Modify the "ignore" count for a breakpoint. */
633int gmi_break_set_times(mi_h *h, int number, int count);
634/* Associate a condition with the breakpoint. */
635int gmi_break_set_condition(mi_h *h, int number, const char *condition);
636/* Enable or disable a breakpoint. */
637int gmi_break_state(mi_h *h, int number, int enable);
638/* Set a watchpoint. It doesn't work for remote targets! */
639mi_wp *gmi_break_watch(mi_h *h, enum mi_wp_mode mode, const char *exp);
640
641/* Data Manipulation. */
642/* Evaluate an expression. Returns a parsed tree. */
643char *gmi_data_evaluate_expression(mi_h *h, const char *expression);
644/* Path for sources. */
645int gmi_dir(mi_h *h, const char *path);
646/* A very limited "data read memory" implementation. */
647int gmi_read_memory(mi_h *h, const char *exp, unsigned size,
648 unsigned char *dest, int *na, int convAddr,
649 unsigned long *addr);
650mi_asm_insns *gmi_data_disassemble_se(mi_h *h, const char *start,
651 const char *end, int mode);
652mi_asm_insns *gmi_data_disassemble_fl(mi_h *h, const char *file, int line,
653 int lines, int mode);
654mi_chg_reg *gmi_data_list_register_names(mi_h *h, int *how_many);
655int gmi_data_list_register_names_l(mi_h *h, mi_chg_reg *l);
656mi_chg_reg *gmi_data_list_changed_registers(mi_h *h);
657int gmi_data_list_register_values(mi_h *h, enum mi_gvar_fmt fmt, mi_chg_reg *l);
658mi_chg_reg *gmi_data_list_all_register_values(mi_h *h, enum mi_gvar_fmt fmt, int *how_many);
659
660/* Stack manipulation. */
661/* List of frames. Arguments aren't filled. */
662mi_frames *gmi_stack_list_frames(mi_h *h);
663/* List of frames. Indicating a range. */
664mi_frames *gmi_stack_list_frames_r(mi_h *h, int from, int to);
665/* List arguments. Only level and args filled. */
666mi_frames *gmi_stack_list_arguments(mi_h *h, int show);
667/* List arguments. Indicating a range. Only level and args filled. */
668mi_frames *gmi_stack_list_arguments_r(mi_h *h, int show, int from, int to);
669/* Information about the current frame, including args. */
670mi_frames *gmi_stack_info_frame(mi_h *h);
671/* Stack info depth. error => -1 */
672int gmi_stack_info_depth_get(mi_h *h);
673/* Set stack info depth. error => -1 */
674int gmi_stack_info_depth(mi_h *h, int max_depth);
675/* Change current frame. */
676int gmi_stack_select_frame(mi_h *h, int framenum);
677/* List of local vars. */
678mi_results *gmi_stack_list_locals(mi_h *h, int show);
679
680/* Thread. */
681/* List available thread ids. */
682int gmi_thread_list_ids(mi_h *h, int **list);
683/* Select a thread. */
684mi_frames *gmi_thread_select(mi_h *h, int id);
685/* List available threads. */
686mi_frames *gmi_thread_list_all_threads(mi_h *h);
687
688/* Variable objects. */
689/* Create a variable object. */
690mi_gvar *gmi_var_create_nm(mi_h *h, const char *name, int frame, const char *exp);
691mi_gvar *gmi_var_create(mi_h *h, int frame, const char *exp);
692/* Create the variable and also fill the lang and attr fields. */
693mi_gvar *gmi_full_var_create(mi_h *h, int frame, const char *exp);
694/* Delete a variable object. Doesn't free the mi_gvar data. */
695int gmi_var_delete(mi_h *h, mi_gvar *var);
696/* Set the format used to represent the result. */
697int gmi_var_set_format(mi_h *h, mi_gvar *var, enum mi_gvar_fmt format);
698/* Fill the format field with info from gdb. */
699int gmi_var_show_format(mi_h *h, mi_gvar *var);
700/* Fill the numchild field with info from gdb. */
701int gmi_var_info_num_children(mi_h *h, mi_gvar *var);
702/* Fill the type field with info from gdb. */
703int gmi_var_info_type(mi_h *h, mi_gvar *var);
704/* Fill the expression and lang fields with info from gdb.
705 Note that lang isn't filled during creation. */
706int gmi_var_info_expression(mi_h *h, mi_gvar *var);
707/* Fill the attr field with info from gdb.
708 Note that attr isn't filled during creation. */
709int gmi_var_show_attributes(mi_h *h, mi_gvar *var);
710/* Update variable. Use NULL for all.
711 Note that *changed can be NULL if none updated. */
712int gmi_var_update(mi_h *h, mi_gvar *var, mi_gvar_chg **changed);
713/* Change variable. Fills the value field. */
714int gmi_var_assign(mi_h *h, mi_gvar *var, const char *expression);
715/* Get current value for a variable. */
716int gmi_var_evaluate_expression(mi_h *h, mi_gvar *var);
717/* List children. It ONLY returns the first level information. :-( */
718int gmi_var_list_children(mi_h *h, mi_gvar *var);
719
720
721
722
723#if 0 /* keep Emacsens' auto-indent happy */
724{
725#endif
726#ifdef __cplusplus
727}
728#endif
729
730#endif
diff --git a/pathologist/src/include/monkey_common.h b/pathologist/src/include/monkey_common.h
new file mode 100644
index 0000000..4973ac5
--- /dev/null
+++ b/pathologist/src/include/monkey_common.h
@@ -0,0 +1,443 @@
1/**
2 * @file monkey_common.h
3 * @brief commonly used definitions
4 * @author Safey A.Halim
5 */
6
7#ifndef MONKEY_COMMON_H
8#define MONKEY_COMMON_H
9
10#include <stdio.h>
11/**
12 * Named constants for return values.
13 */
14#define MONKEY_OK 1
15#define MONKEY_SYSERR -1
16#define MONKEY_YES 1
17#define MONKEY_NO 0
18
19/**
20 * Use this for fatal errors that cannot be handled
21 */
22#define MONKEY_assert(cond) do { if (! (cond)) { fprintf(stderr, "Assertion failed at %s:%d.\n", __FILE__, __LINE__); abort(); } } while(0)
23
24/**
25 * Use this for fatal errors that cannot be handled
26 */
27#define MONKEY_assert_at(cond, f, l) do { if (! (cond)) { fprintf(stderr, "Assertion failed at %s:%d.\n", f, l); abort(); } } while(0)
28
29/**
30 * Use this for internal assertion violations that are
31 * not fatal (can be handled) but should not occur.
32 */
33#define MONKEY_break(cond) do { if (! (cond)) { fprintf(stderr, "Assertion failed at %s:%d.\n", __FILE__, __LINE__); } } while(0)
34
35
36/* ******************** doubly-linked list *************** */
37/* To avoid mistakes: head->prev == tail->next == NULL */
38
39/**
40 * Insert an element at the head of a DLL. Assumes that head, tail and
41 * element are structs with prev and next fields.
42 *
43 * @param head pointer to the head of the DLL
44 * @param tail pointer to the tail of the DLL
45 * @param element element to insert
46 */
47#define MONKEY_CONTAINER_DLL_insert(head,tail,element) do { \
48 MONKEY_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
49 MONKEY_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
50 (element)->next = (head); \
51 (element)->prev = NULL; \
52 if ((tail) == NULL) \
53 (tail) = element; \
54 else \
55 (head)->prev = element; \
56 (head) = (element); } while (0)
57
58
59/**
60 * Insert an element at the tail of a DLL. Assumes that head, tail and
61 * element are structs with prev and next fields.
62 *
63 * @param head pointer to the head of the DLL
64 * @param tail pointer to the tail of the DLL
65 * @param element element to insert
66 */
67#define MONKEY_CONTAINER_DLL_insert_tail(head,tail,element) do { \
68 MONKEY_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
69 MONKEY_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
70 (element)->prev = (tail); \
71 (element)->next = NULL; \
72 if ((head) == NULL) \
73 (head) = element; \
74 else \
75 (tail)->next = element; \
76 (tail) = (element); } while (0)
77
78
79/**
80 * Insert an element into a DLL after the given other element. Insert
81 * at the head if the other element is NULL.
82 *
83 * @param head pointer to the head of the DLL
84 * @param tail pointer to the tail of the DLL
85 * @param other prior element, NULL for insertion at head of DLL
86 * @param element element to insert
87 */
88#define MONKEY_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
89 MONKEY_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
90 MONKEY_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
91 (element)->prev = (other); \
92 if (NULL == other) \
93 { \
94 (element)->next = (head); \
95 (head) = (element); \
96 } \
97 else \
98 { \
99 (element)->next = (other)->next; \
100 (other)->next = (element); \
101 } \
102 if (NULL == (element)->next) \
103 (tail) = (element); \
104 else \
105 (element)->next->prev = (element); } while (0)
106
107
108/**
109 * Insert an element into a DLL before the given other element. Insert
110 * at the tail if the other element is NULL.
111 *
112 * @param head pointer to the head of the DLL
113 * @param tail pointer to the tail of the DLL
114 * @param other prior element, NULL for insertion at head of DLL
115 * @param element element to insert
116 */
117#define MONKEY_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
118 MONKEY_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
119 MONKEY_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
120 (element)->next = (other); \
121 if (NULL == other) \
122 { \
123 (element)->prev = (tail); \
124 (tail) = (element); \
125 } \
126 else \
127 { \
128 (element)->prev = (other)->prev; \
129 (other)->prev = (element); \
130 } \
131 if (NULL == (element)->prev) \
132 (head) = (element); \
133 else \
134 (element)->prev->next = (element); } while (0)
135
136
137/**
138 * Remove an element from a DLL. Assumes
139 * that head, tail and element are structs
140 * with prev and next fields.
141 *
142 * @param head pointer to the head of the DLL
143 * @param tail pointer to the tail of the DLL
144 * @param element element to remove
145 */
146#define MONKEY_CONTAINER_DLL_remove(head,tail,element) do { \
147 MONKEY_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
148 MONKEY_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
149 if ((element)->prev == NULL) \
150 (head) = (element)->next; \
151 else \
152 (element)->prev->next = (element)->next; \
153 if ((element)->next == NULL) \
154 (tail) = (element)->prev; \
155 else \
156 (element)->next->prev = (element)->prev; \
157 (element)->next = NULL; \
158 (element)->prev = NULL; } while (0)
159
160
161#define MONKEY_MIN(a,b) (((a) < (b)) ? (a) : (b))
162
163#define MONKEY_MAX(a,b) (((a) > (b)) ? (a) : (b))
164
165/* ************************* allocation functions ****************** */
166
167/**
168 * Maximum allocation with MONKEY_malloc macro.
169 */
170#define MONKEY_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
171
172/**
173 * Wrapper around malloc. Allocates size bytes of memory.
174 * The memory will be zero'ed out.
175 *
176 * @param size the number of bytes to allocate, must be
177 * smaller than 40 MB.
178 * @return pointer to size bytes of memory, never NULL (!)
179 */
180#define MONKEY_malloc(size) MONKEY_xmalloc_(size, __FILE__, __LINE__)
181
182/**
183 * Allocate and initialize a block of memory.
184 *
185 * @param buf data to initalize the block with
186 * @param size the number of bytes in buf (and size of the allocation)
187 * @return pointer to size bytes of memory, never NULL (!)
188 */
189#define MONKEY_memdup(buf,size) MONKEY_xmemdup_(buf, size, __FILE__, __LINE__)
190
191/**
192 * Wrapper around malloc. Allocates size bytes of memory.
193 * The memory will be zero'ed out.
194 *
195 * @param size the number of bytes to allocate
196 * @return pointer to size bytes of memory, NULL if we do not have enough memory
197 */
198#define MONKEY_malloc_large(size) MONKEY_xmalloc_unchecked_(size, __FILE__, __LINE__)
199
200/**
201 * Wrapper around realloc. Rellocates size bytes of memory.
202 *
203 * @param ptr the pointer to reallocate
204 * @param size the number of bytes to reallocate
205 * @return pointer to size bytes of memory
206 */
207#define MONKEY_realloc(ptr, size) MONKEY_xrealloc_(ptr, size, __FILE__, __LINE__)
208
209/**
210 * Wrapper around free. Frees the memory referred to by ptr.
211 * Note that is is generally better to free memory that was
212 * allocated with MONKEY_array_grow using MONKEY_array_grow(mem, size, 0) instead of MONKEY_free.
213 *
214 * @param ptr location where to free the memory. ptr must have
215 * been returned by MONKEY_strdup, MONKEY_strndup, MONKEY_malloc or MONKEY_array_grow earlier.
216 */
217#define MONKEY_free(ptr) MONKEY_xfree_(ptr, __FILE__, __LINE__)
218
219/**
220 * Free the memory pointed to by ptr if ptr is not NULL.
221 * Equivalent to if (ptr!=null)MONKEY_free(ptr).
222 *
223 * @param ptr the location in memory to free
224 */
225#define MONKEY_free_non_null(ptr) do { void * __x__ = ptr; if (__x__ != NULL) { MONKEY_free(__x__); } } while(0)
226
227/**
228 * Wrapper around MONKEY_strdup. Makes a copy of the zero-terminated string
229 * pointed to by a.
230 *
231 * @param a pointer to a zero-terminated string
232 * @return a copy of the string including zero-termination
233 */
234#define MONKEY_strdup(a) MONKEY_xstrdup_(a,__FILE__,__LINE__)
235
236/**
237 * Wrapper around MONKEY_strndup. Makes a partial copy of the string
238 * pointed to by a.
239 *
240 * @param a pointer to a string
241 * @param length of the string to duplicate
242 * @return a partial copy of the string including zero-termination
243 */
244#define MONKEY_strndup(a,length) MONKEY_xstrndup_(a,length,__FILE__,__LINE__)
245
246/**
247 * Grow a well-typed (!) array. This is a convenience
248 * method to grow a vector <tt>arr</tt> of size <tt>size</tt>
249 * to the new (target) size <tt>tsize</tt>.
250 * <p>
251 *
252 * Example (simple, well-typed stack):
253 *
254 * <pre>
255 * static struct foo * myVector = NULL;
256 * static int myVecLen = 0;
257 *
258 * static void push(struct foo * elem) {
259 * MONKEY_array_grow(myVector, myVecLen, myVecLen+1);
260 * memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo));
261 * }
262 *
263 * static void pop(struct foo * elem) {
264 * if (myVecLen == 0) die();
265 * memcpy(elem, myVector[myVecLen-1], sizeof(struct foo));
266 * MONKEY_array_grow(myVector, myVecLen, myVecLen-1);
267 * }
268 * </pre>
269 *
270 * @param arr base-pointer of the vector, may be NULL if size is 0;
271 * will be updated to reflect the new address. The TYPE of
272 * arr is important since size is the number of elements and
273 * not the size in bytes
274 * @param size the number of elements in the existing vector (number
275 * of elements to copy over)
276 * @param tsize the target size for the resulting vector, use 0 to
277 * free the vector (then, arr will be NULL afterwards).
278 */
279#define MONKEY_array_grow(arr,size,tsize) MONKEY_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__)
280
281/**
282 * Append an element to a list (growing the
283 * list by one).
284 */
285#define MONKEY_array_append(arr,size,element) do { MONKEY_array_grow(arr,size,size+1); arr[size-1] = element; } while(0)
286
287/**
288 * Like snprintf, just aborts if the buffer is of insufficient size.
289 *
290 * @param buf pointer to buffer that is written to
291 * @param size number of bytes in buf
292 * @param format format strings
293 * @param ... data for format string
294 * @return number of bytes written to buf or negative value on error
295 */
296int
297MONKEY_snprintf (char *buf, size_t size, const char *format, ...);
298
299
300/**
301 * Like asprintf, just portable.
302 *
303 * @param buf set to a buffer of sufficient size (allocated, caller must free)
304 * @param format format string (see printf, fprintf, etc.)
305 * @param ... data for format string
306 * @return number of bytes in "*buf" excluding 0-termination
307 */
308int
309MONKEY_asprintf (char **buf, const char *format, ...);
310
311
312/**
313 * Replace all occurrences of a substring in a string
314 * @param string target string
315 * @param substr substring to replace
316 * @param replacement substitution of the substring
317 */
318char *
319MONKEY_str_replace_all ( const char *string, const char *substr, const char *replacement );
320
321/* ************** internal implementations, use macros above! ************** */
322
323/**
324 * Allocate memory. Checks the return value, aborts if no more
325 * memory is available. Don't use MONKEY_xmalloc_ directly. Use the
326 * MONKEY_malloc macro.
327 * The memory will be zero'ed out.
328 *
329 * @param size number of bytes to allocate
330 * @param filename where is this call being made (for debugging)
331 * @param linenumber line where this call is being made (for debugging)
332 * @return allocated memory, never NULL
333 */
334void *
335MONKEY_xmalloc_ (size_t size, const char *filename, int linenumber);
336
337
338
339/**
340 * Allocate and initialize memory. Checks the return value, aborts if no more
341 * memory is available. Don't use MONKEY_xmemdup_ directly. Use the
342 * MONKEY_memdup macro.
343 *
344 * @param buf buffer to initialize from (must contain size bytes)
345 * @param size number of bytes to allocate
346 * @param filename where is this call being made (for debugging)
347 * @param linenumber line where this call is being made (for debugging)
348 * @return allocated memory, never NULL
349 */
350void *
351MONKEY_xmemdup_ (const void *buf, size_t size, const char *filename,
352 int linenumber);
353
354
355/**
356 * Allocate memory. This function does not check if the allocation
357 * request is within reasonable bounds, allowing allocations larger
358 * than 40 MB. If you don't expect the possibility of very large
359 * allocations, use MONKEY_malloc instead. The memory will be zero'ed
360 * out.
361 *
362 * @param size number of bytes to allocate
363 * @param filename where is this call being made (for debugging)
364 * @param linenumber line where this call is being made (for debugging)
365 * @return pointer to size bytes of memory, NULL if we do not have enough memory
366 */
367void *
368MONKEY_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
369
370/**
371 * Reallocate memory. Checks the return value, aborts if no more
372 * memory is available.
373 */
374void *
375MONKEY_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
376
377/**
378 * Free memory. Merely a wrapper for the case that we
379 * want to keep track of allocations. Don't use MONKEY_xfree_
380 * directly. Use the MONKEY_free macro.
381 *
382 * @param ptr pointer to memory to free
383 * @param filename where is this call being made (for debugging)
384 * @param linenumber line where this call is being made (for debugging)
385 */
386void
387MONKEY_xfree_ (void *ptr, const char *filename, int linenumber);
388
389
390/**
391 * Dup a string. Don't call MONKEY_xstrdup_ directly. Use the MONKEY_strdup macro.
392 * @param str string to duplicate
393 * @param filename where is this call being made (for debugging)
394 * @param linenumber line where this call is being made (for debugging)
395 * @return the duplicated string
396 */
397char *
398MONKEY_xstrdup_ (const char *str, const char *filename, int linenumber);
399
400/**
401 * Dup partially a string. Don't call MONKEY_xstrndup_ directly. Use the MONKEY_strndup macro.
402 *
403 * @param str string to duplicate
404 * @param len length of the string to duplicate
405 * @param filename where is this call being made (for debugging)
406 * @param linenumber line where this call is being made (for debugging)
407 * @return the duplicated string
408 */
409char *
410MONKEY_xstrndup_ (const char *str, size_t len, const char *filename,
411 int linenumber);
412
413/**
414 * Grow an array, the new elements are zeroed out.
415 * Grows old by (*oldCount-newCount)*elementSize
416 * bytes and sets *oldCount to newCount.
417 *
418 * Don't call MONKEY_xgrow_ directly. Use the MONKEY_array_grow macro.
419 *
420 * @param old address of the pointer to the array
421 * *old may be NULL
422 * @param elementSize the size of the elements of the array
423 * @param oldCount address of the number of elements in the *old array
424 * @param newCount number of elements in the new array, may be 0 (then *old will be NULL afterwards)
425 * @param filename where is this call being made (for debugging)
426 * @param linenumber line where this call is being made (for debugging)
427 */
428void
429MONKEY_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount,
430 unsigned int newCount, const char *filename, int linenumber);
431
432
433
434
435#if __STDC_VERSION__ < 199901L
436#if __GNUC__ >= 2
437#define __func__ __FUNCTION__
438#else
439#define __func__ "<unknown>"
440#endif
441#endif
442
443#endif /* MONKEY_COMMON_H */
diff --git a/pathologist/src/include/monkey_getopt_lib.h b/pathologist/src/include/monkey_getopt_lib.h
new file mode 100644
index 0000000..50d9cc1
--- /dev/null
+++ b/pathologist/src/include/monkey_getopt_lib.h
@@ -0,0 +1,367 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file include/gnunet_getopt_lib.h
23 * @brief command line parsing and --help formatting
24 *
25 * @author Christian Grothoff
26 */
27
28#ifndef MONKEY_GETOPT_LIB_H
29#define MONKEY_GETOPT_LIB_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39//#include "gnunet_configuration_lib.h"
40
41/**
42 * @brief General context for command line processors.
43 */
44struct MONKEY_GETOPT_CommandLineProcessorContext
45{
46
47 /**
48 * Name of the application
49 */
50 const char *binaryName;
51
52 /**
53 * Name of application with option summary
54 */
55 const char *binaryOptions;
56
57 /**
58 * Array with all command line options.
59 */
60 const struct MONKEY_GETOPT_CommandLineOption *allOptions;
61
62 /**
63 * Original command line
64 */
65 char *const *argv;
66
67 /**
68 * Total number of argv's.
69 */
70 unsigned int argc;
71
72 /**
73 * Current argument.
74 */
75 unsigned int currentArgument;
76
77};
78
79/**
80 * @brief Process a command line option
81 *
82 * @param ctx context for all options
83 * @param scls specific closure (for this processor)
84 * @param option long name of the option (i.e. "config" for --config)
85 * @param value argument, NULL if none was given
86 * @return MONKEY_OK to continue processing other options, MONKEY_SYSERR to abort
87 */
88typedef int (*MONKEY_GETOPT_CommandLineOptionProcessor) (struct
89 MONKEY_GETOPT_CommandLineProcessorContext
90 * ctx, void *scls,
91 const char *option,
92 const char *value);
93
94/**
95 * @brief Definition of a command line option.
96 */
97struct MONKEY_GETOPT_CommandLineOption
98{
99
100 /**
101 * Short name of the option (use '\\0' for none).
102 */
103 const char shortName;
104
105 /**
106 * Long name of the option (may not be NULL)
107 */
108 const char *name;
109
110 /**
111 * Name of the argument for the user in help text
112 */
113 const char *argumentHelp;
114
115 /**
116 * Help text for the option (description)
117 */
118 const char *description;
119
120 /**
121 * Is an argument required? 0: MONKEY_NO (includes optional), 1: MONKEY_YES.
122 */
123 int require_argument;
124
125 /**
126 * Handler for the option.
127 */
128 MONKEY_GETOPT_CommandLineOptionProcessor processor;
129
130 /**
131 * Specific closure to pass to the processor.
132 */
133 void *scls;
134
135};
136
137/**
138 * Macro defining the option to print the command line
139 * help text (-h option).
140 *
141 * @param about string with brief description of the application
142 */
143#define MONKEY_GETOPT_OPTION_HELP(about) \
144 { 'h', "help", (const char *) NULL, gettext_noop("print this help"), 0, &MONKEY_GETOPT_format_help_, (void *) about }
145
146
147/**
148 * Macro defining the option to print the version of
149 * the application (-v option)
150 *
151 * @param version string with the version number
152 */
153#define MONKEY_GETOPT_OPTION_VERSION(version) \
154 { 'v', "version", (const char *) NULL, gettext_noop("print the version number"), 0, &MONKEY_GETOPT_print_version_, (void *) version }
155
156
157/**
158 * Allow user to specify log file name (-l option)
159 *
160 * @param logfn set to the name of the logfile
161 */
162#define MONKEY_GETOPT_OPTION_LOGFILE(logfn) \
163 { 'l', "logfile", "LOGFILE", gettext_noop("configure logging to write logs to LOGFILE"), 1, &MONKEY_GETOPT_set_string, (void *) logfn }
164
165
166/**
167 * Allow user to specify log level (-L option)
168 *
169 * @param loglev set to the log level
170 */
171#define MONKEY_GETOPT_OPTION_LOGLEVEL(loglev) \
172 { 'L', "log", "LOGLEVEL", gettext_noop("configure logging to use LOGLEVEL"), 1, &MONKEY_GETOPT_set_string, (void *) loglev }
173
174
175/**
176 * Get number of verbose (-V) flags
177 *
178 * @param level where to store the verbosity level (should be an 'int')
179 */
180#define MONKEY_GETOPT_OPTION_VERBOSE(level) \
181 { 'V', "verbose", (const char *) NULL, gettext_noop("be verbose"), 0, &MONKEY_GETOPT_increment_value, (void *) level }
182
183
184/**
185 * Get configuration file name (-c option)
186 *
187 * @param fn set to the configuration file name
188 */
189#define MONKEY_GETOPT_OPTION_CFG_FILE(fn) \
190 { 'c', "config", "FILENAME", gettext_noop("use configuration file FILENAME"), 1, &MONKEY_GETOPT_set_string, (void *) fn }
191
192
193/**
194 * Marker for the end of the list of options.
195 */
196#define MONKEY_GETOPT_OPTION_END \
197 { '\0', NULL, NULL, NULL, 0, NULL, NULL }
198
199
200/**
201 * Parse the command line.
202 *
203 * @param binaryOptions Name of application with option summary
204 * @param allOptions defined options and handlers
205 * @param argc number of arguments
206 * @param argv actual arguments
207 * @return index into argv with first non-option
208 * argument, or MONKEY_SYSERR on error
209 */
210int
211MONKEY_GETOPT_run (const char *binaryOptions,
212 const struct MONKEY_GETOPT_CommandLineOption *allOptions,
213 unsigned int argc, char *const *argv);
214
215
216/**
217 * Set an option of type 'unsigned long long' from the command line.
218 * A pointer to this function should be passed as part of the
219 * 'struct MONKEY_GETOPT_CommandLineOption' array to initialize options
220 * of this type. It should be followed by a pointer to a value of
221 * type 'unsigned long long'.
222 *
223 * @param ctx command line processing context
224 * @param scls additional closure (will point to the 'unsigned long long')
225 * @param option name of the option
226 * @param value actual value of the option as a string.
227 * @return MONKEY_OK if parsing the value worked
228 */
229int
230MONKEY_GETOPT_set_ulong (struct MONKEY_GETOPT_CommandLineProcessorContext *ctx,
231 void *scls, const char *option, const char *value);
232
233
234/**
235 * Set an option of type 'struct MONKEY_TIME_Relative' from the command line.
236 * A pointer to this function should be passed as part of the
237 * 'struct MONKEY_GETOPT_CommandLineOption' array to initialize options
238 * of this type. It should be followed by a pointer to a value of
239 * type 'struct MONKEY_TIME_Relative'.
240 *
241 * @param ctx command line processing context
242 * @param scls additional closure (will point to the 'struct MONKEY_TIME_Relative')
243 * @param option name of the option
244 * @param value actual value of the option as a string.
245 * @return MONKEY_OK if parsing the value worked
246 */
247int
248MONKEY_GETOPT_set_relative_time (struct MONKEY_GETOPT_CommandLineProcessorContext *ctx,
249 void *scls, const char *option, const char *value);
250
251
252/**
253 * Set an option of type 'unsigned int' from the command line.
254 * A pointer to this function should be passed as part of the
255 * 'struct MONKEY_GETOPT_CommandLineOption' array to initialize options
256 * of this type. It should be followed by a pointer to a value of
257 * type 'unsigned int'.
258 *
259 * @param ctx command line processing context
260 * @param scls additional closure (will point to the 'unsigned int')
261 * @param option name of the option
262 * @param value actual value of the option as a string.
263 * @return MONKEY_OK if parsing the value worked
264 */
265int
266MONKEY_GETOPT_set_uint (struct MONKEY_GETOPT_CommandLineProcessorContext *ctx,
267 void *scls, const char *option, const char *value);
268
269
270/**
271 * Set an option of type 'int' from the command line to 1 if the
272 * given option is present.
273 * A pointer to this function should be passed as part of the
274 * 'struct MONKEY_GETOPT_CommandLineOption' array to initialize options
275 * of this type. It should be followed by a pointer to a value of
276 * type 'int'.
277 *
278 * @param ctx command line processing context
279 * @param scls additional closure (will point to the 'int')
280 * @param option name of the option
281 * @param value not used (NULL)
282 * @return MONKEY_OK
283 */
284int
285MONKEY_GETOPT_set_one (struct MONKEY_GETOPT_CommandLineProcessorContext *ctx,
286 void *scls, const char *option, const char *value);
287
288
289/**
290 * Set an option of type 'char *' from the command line.
291 * A pointer to this function should be passed as part of the
292 * 'struct MONKEY_GETOPT_CommandLineOption' array to initialize options
293 * of this type. It should be followed by a pointer to a value of
294 * type 'char *'.
295 *
296 * @param ctx command line processing context
297 * @param scls additional closure (will point to the 'char *',
298 * which will be allocated)
299 * @param option name of the option
300 * @param value actual value of the option (a string)
301 * @return MONKEY_OK
302 */
303int
304MONKEY_GETOPT_set_string (struct MONKEY_GETOPT_CommandLineProcessorContext *ctx,
305 void *scls, const char *option, const char *value);
306
307/**
308 * Set an option of type 'unsigned int' from the command line. Each
309 * time the option flag is given, the value is incremented by one.
310 * A pointer to this function should be passed as part of the
311 * 'struct MONKEY_GETOPT_CommandLineOption' array to initialize options
312 * of this type. It should be followed by a pointer to a value of
313 * type 'int'.
314 *
315 * @param ctx command line processing context
316 * @param scls additional closure (will point to the 'int')
317 * @param option name of the option
318 * @param value not used (NULL)
319 * @return MONKEY_OK
320 */
321int
322MONKEY_GETOPT_increment_value (struct MONKEY_GETOPT_CommandLineProcessorContext
323 *ctx, void *scls, const char *option,
324 const char *value);
325
326
327/* *************** internal prototypes - use macros above! ************* */
328
329/**
330 * Print out details on command line options (implements --help).
331 *
332 * @param ctx command line processing context
333 * @param scls additional closure (points to about text)
334 * @param option name of the option
335 * @param value not used (NULL)
336 * @return MONKEY_SYSERR (do not continue)
337 */
338int
339MONKEY_GETOPT_format_help_ (struct MONKEY_GETOPT_CommandLineProcessorContext
340 *ctx, void *scls, const char *option,
341 const char *value);
342
343/**
344 * Print out program version (implements --version).
345 *
346 * @param ctx command line processing context
347 * @param scls additional closure (points to version string)
348 * @param option name of the option
349 * @param value not used (NULL)
350 * @return MONKEY_SYSERR (do not continue)
351 */
352int
353MONKEY_GETOPT_print_version_ (struct MONKEY_GETOPT_CommandLineProcessorContext
354 *ctx, void *scls, const char *option,
355 const char *value);
356
357#if 0 /* keep Emacsens' auto-indent happy */
358{
359#endif
360#ifdef __cplusplus
361}
362#endif
363
364
365/* ifndef MONKEY_GETOPT_LIB_H */
366#endif
367/* end of gnunet_getopt_lib.h */
diff --git a/pathologist/src/include/mxml.h b/pathologist/src/include/mxml.h
new file mode 100644
index 0000000..79c711f
--- /dev/null
+++ b/pathologist/src/include/mxml.h
@@ -0,0 +1,329 @@
1/*
2 * "$Id: mxml.h 427 2011-01-03 02:03:29Z mike $"
3 *
4 * Header file for Mini-XML, a small XML-like file parsing library.
5 *
6 * Copyright 2003-2011 by Michael R Sweet.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Michael R Sweet and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "COPYING"
11 * which should have been included with this file. If this file is
12 * missing or damaged, see the license at:
13 *
14 * http://www.minixml.org/
15 */
16
17/*
18 * Prevent multiple inclusion...
19 */
20
21#ifndef _mxml_h_
22# define _mxml_h_
23
24/*
25 * Include necessary headers...
26 */
27
28# include <stdio.h>
29# include <stdlib.h>
30# include <string.h>
31# include <ctype.h>
32# include <errno.h>
33
34
35/*
36 * Constants...
37 */
38
39# define MXML_TAB 8 /* Tabs every N columns */
40
41# define MXML_NO_CALLBACK 0 /* Don't use a type callback */
42# define MXML_INTEGER_CALLBACK mxml_integer_cb
43 /* Treat all data as integers */
44# define MXML_OPAQUE_CALLBACK mxml_opaque_cb
45 /* Treat all data as opaque */
46# define MXML_REAL_CALLBACK mxml_real_cb
47 /* Treat all data as real numbers */
48# define MXML_TEXT_CALLBACK 0 /* Treat all data as text */
49# define MXML_IGNORE_CALLBACK mxml_ignore_cb
50 /* Ignore all non-element content */
51
52# define MXML_NO_PARENT 0 /* No parent for the node */
53
54# define MXML_DESCEND 1 /* Descend when finding/walking */
55# define MXML_NO_DESCEND 0 /* Don't descend when finding/walking */
56# define MXML_DESCEND_FIRST -1 /* Descend for first find */
57
58# define MXML_WS_BEFORE_OPEN 0 /* Callback for before open tag */
59# define MXML_WS_AFTER_OPEN 1 /* Callback for after open tag */
60# define MXML_WS_BEFORE_CLOSE 2 /* Callback for before close tag */
61# define MXML_WS_AFTER_CLOSE 3 /* Callback for after close tag */
62
63# define MXML_ADD_BEFORE 0 /* Add node before specified node */
64# define MXML_ADD_AFTER 1 /* Add node after specified node */
65# define MXML_ADD_TO_PARENT NULL /* Add node relative to parent */
66
67
68/*
69 * Data types...
70 */
71
72typedef enum mxml_sax_event_e /**** SAX event type. ****/
73{
74 MXML_SAX_CDATA, /* CDATA node */
75 MXML_SAX_COMMENT, /* Comment node */
76 MXML_SAX_DATA, /* Data node */
77 MXML_SAX_DIRECTIVE, /* Processing directive node */
78 MXML_SAX_ELEMENT_CLOSE, /* Element closed */
79 MXML_SAX_ELEMENT_OPEN /* Element opened */
80} mxml_sax_event_t;
81
82typedef enum mxml_type_e /**** The XML node type. ****/
83{
84 MXML_IGNORE = -1, /* Ignore/throw away node @since Mini-XML 2.3@ */
85 MXML_ELEMENT, /* XML element with attributes */
86 MXML_INTEGER, /* Integer value */
87 MXML_OPAQUE, /* Opaque string */
88 MXML_REAL, /* Real value */
89 MXML_TEXT, /* Text fragment */
90 MXML_CUSTOM /* Custom data @since Mini-XML 2.1@ */
91} mxml_type_t;
92
93typedef void (*mxml_custom_destroy_cb_t)(void *);
94 /**** Custom data destructor ****/
95
96typedef void (*mxml_error_cb_t)(const char *);
97 /**** Error callback function ****/
98
99typedef struct mxml_attr_s /**** An XML element attribute value. @private@ ****/
100{
101 char *name; /* Attribute name */
102 char *value; /* Attribute value */
103} mxml_attr_t;
104
105typedef struct mxml_element_s /**** An XML element value. @private@ ****/
106{
107 char *name; /* Name of element */
108 int num_attrs; /* Number of attributes */
109 mxml_attr_t *attrs; /* Attributes */
110} mxml_element_t;
111
112typedef struct mxml_text_s /**** An XML text value. @private@ ****/
113{
114 int whitespace; /* Leading whitespace? */
115 char *string; /* Fragment string */
116} mxml_text_t;
117
118typedef struct mxml_custom_s /**** An XML custom value. @private@ ****/
119{
120 void *data; /* Pointer to (allocated) custom data */
121 mxml_custom_destroy_cb_t destroy; /* Pointer to destructor function */
122} mxml_custom_t;
123
124typedef union mxml_value_u /**** An XML node value. @private@ ****/
125{
126 mxml_element_t element; /* Element */
127 int integer; /* Integer number */
128 char *opaque; /* Opaque string */
129 double real; /* Real number */
130 mxml_text_t text; /* Text fragment */
131 mxml_custom_t custom; /* Custom data @since Mini-XML 2.1@ */
132} mxml_value_t;
133
134struct mxml_node_s /**** An XML node. @private@ ****/
135{
136 mxml_type_t type; /* Node type */
137 struct mxml_node_s *next; /* Next node under same parent */
138 struct mxml_node_s *prev; /* Previous node under same parent */
139 struct mxml_node_s *parent; /* Parent node */
140 struct mxml_node_s *child; /* First child node */
141 struct mxml_node_s *last_child; /* Last child node */
142 mxml_value_t value; /* Node value */
143 int ref_count; /* Use count */
144 void *user_data; /* User data */
145};
146
147typedef struct mxml_node_s mxml_node_t; /**** An XML node. ****/
148
149struct mxml_index_s /**** An XML node index. @private@ ****/
150{
151 char *attr; /* Attribute used for indexing or NULL */
152 int num_nodes; /* Number of nodes in index */
153 int alloc_nodes; /* Allocated nodes in index */
154 int cur_node; /* Current node */
155 mxml_node_t **nodes; /* Node array */
156};
157
158typedef struct mxml_index_s mxml_index_t;
159 /**** An XML node index. ****/
160
161typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
162 /**** Custom data load callback function ****/
163
164typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);
165 /**** Custom data save callback function ****/
166
167typedef int (*mxml_entity_cb_t)(const char *);
168 /**** Entity callback function */
169
170typedef mxml_type_t (*mxml_load_cb_t)(mxml_node_t *);
171 /**** Load callback function ****/
172
173typedef const char *(*mxml_save_cb_t)(mxml_node_t *, int);
174 /**** Save callback function ****/
175
176typedef void (*mxml_sax_cb_t)(mxml_node_t *, mxml_sax_event_t, void *);
177 /**** SAX callback function ****/
178
179
180/*
181 * C++ support...
182 */
183
184# ifdef __cplusplus
185extern "C" {
186# endif /* __cplusplus */
187
188/*
189 * Prototypes...
190 */
191
192extern void mxmlAdd(mxml_node_t *parent, int where,
193 mxml_node_t *child, mxml_node_t *node);
194extern void mxmlDelete(mxml_node_t *node);
195extern void mxmlElementDeleteAttr(mxml_node_t *node,
196 const char *name);
197extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
198extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
199 const char *value);
200extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name,
201 const char *format, ...)
202# ifdef __GNUC__
203__attribute__ ((__format__ (__printf__, 3, 4)))
204# endif /* __GNUC__ */
205;
206extern int mxmlEntityAddCallback(mxml_entity_cb_t cb);
207extern const char *mxmlEntityGetName(int val);
208extern int mxmlEntityGetValue(const char *name);
209extern void mxmlEntityRemoveCallback(mxml_entity_cb_t cb);
210extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
211 const char *name, const char *attr,
212 const char *value, int descend);
213extern mxml_node_t *mxmlFindPath(mxml_node_t *node, const char *path);
214extern const char *mxmlGetCDATA(mxml_node_t *node);
215extern const void *mxmlGetCustom(mxml_node_t *node);
216extern const char *mxmlGetElement(mxml_node_t *node);
217extern mxml_node_t *mxmlGetFirstChild(mxml_node_t *node);
218extern int mxmlGetInteger(mxml_node_t *node);
219extern mxml_node_t *mxmlGetLastChild(mxml_node_t *node);
220extern mxml_node_t *mxmlGetNextSibling(mxml_node_t *node);
221extern const char *mxmlGetOpaque(mxml_node_t *node);
222extern mxml_node_t *mxmlGetParent(mxml_node_t *node);
223extern mxml_node_t *mxmlGetPrevSibling(mxml_node_t *node);
224extern double mxmlGetReal(mxml_node_t *node);
225extern int mxmlGetRefCount(mxml_node_t *node);
226extern const char *mxmlGetText(mxml_node_t *node, int *whitespace);
227extern mxml_type_t mxmlGetType(mxml_node_t *node);
228extern void *mxmlGetUserData(mxml_node_t *node);
229extern void mxmlIndexDelete(mxml_index_t *ind);
230extern mxml_node_t *mxmlIndexEnum(mxml_index_t *ind);
231extern mxml_node_t *mxmlIndexFind(mxml_index_t *ind,
232 const char *element,
233 const char *value);
234extern int mxmlIndexGetCount(mxml_index_t *ind);
235extern mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element,
236 const char *attr);
237extern mxml_node_t *mxmlIndexReset(mxml_index_t *ind);
238extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd,
239 mxml_type_t (*cb)(mxml_node_t *));
240extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
241 mxml_type_t (*cb)(mxml_node_t *));
242extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
243 mxml_type_t (*cb)(mxml_node_t *));
244extern mxml_node_t *mxmlNewCDATA(mxml_node_t *parent, const char *string);
245extern mxml_node_t *mxmlNewCustom(mxml_node_t *parent, void *data,
246 mxml_custom_destroy_cb_t destroy);
247extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
248extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
249extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
250extern mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
251extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
252 const char *string);
253extern mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace,
254 const char *format, ...)
255# ifdef __GNUC__
256__attribute__ ((__format__ (__printf__, 3, 4)))
257# endif /* __GNUC__ */
258;
259extern mxml_node_t *mxmlNewXML(const char *version);
260extern int mxmlRelease(mxml_node_t *node);
261extern void mxmlRemove(mxml_node_t *node);
262extern int mxmlRetain(mxml_node_t *node);
263extern char *mxmlSaveAllocString(mxml_node_t *node,
264 mxml_save_cb_t cb);
265extern int mxmlSaveFd(mxml_node_t *node, int fd,
266 mxml_save_cb_t cb);
267extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
268 mxml_save_cb_t cb);
269extern int mxmlSaveString(mxml_node_t *node, char *buffer,
270 int bufsize, mxml_save_cb_t cb);
271extern mxml_node_t *mxmlSAXLoadFd(mxml_node_t *top, int fd,
272 mxml_type_t (*cb)(mxml_node_t *),
273 mxml_sax_cb_t sax, void *sax_data);
274extern mxml_node_t *mxmlSAXLoadFile(mxml_node_t *top, FILE *fp,
275 mxml_type_t (*cb)(mxml_node_t *),
276 mxml_sax_cb_t sax, void *sax_data);
277extern mxml_node_t *mxmlSAXLoadString(mxml_node_t *top, const char *s,
278 mxml_type_t (*cb)(mxml_node_t *),
279 mxml_sax_cb_t sax, void *sax_data);
280extern int mxmlSetCDATA(mxml_node_t *node, const char *data);
281extern int mxmlSetCustom(mxml_node_t *node, void *data,
282 mxml_custom_destroy_cb_t destroy);
283extern void mxmlSetCustomHandlers(mxml_custom_load_cb_t load,
284 mxml_custom_save_cb_t save);
285extern int mxmlSetElement(mxml_node_t *node, const char *name);
286extern void mxmlSetErrorCallback(mxml_error_cb_t cb);
287extern int mxmlSetInteger(mxml_node_t *node, int integer);
288extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
289extern int mxmlSetReal(mxml_node_t *node, double real);
290extern int mxmlSetText(mxml_node_t *node, int whitespace,
291 const char *string);
292extern int mxmlSetTextf(mxml_node_t *node, int whitespace,
293 const char *format, ...)
294# ifdef __GNUC__
295__attribute__ ((__format__ (__printf__, 3, 4)))
296# endif /* __GNUC__ */
297;
298extern int mxmlSetUserData(mxml_node_t *node, void *data);
299extern void mxmlSetWrapMargin(int column);
300extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
301 int descend);
302extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
303 int descend);
304
305
306/*
307 * Semi-private functions...
308 */
309
310extern void mxml_error(const char *format, ...);
311extern mxml_type_t mxml_ignore_cb(mxml_node_t *node);
312extern mxml_type_t mxml_integer_cb(mxml_node_t *node);
313extern mxml_type_t mxml_opaque_cb(mxml_node_t *node);
314extern mxml_type_t mxml_real_cb(mxml_node_t *node);
315
316
317/*
318 * C++ support...
319 */
320
321# ifdef __cplusplus
322}
323# endif /* __cplusplus */
324#endif /* !_mxml_h_ */
325
326
327/*
328 * End of "$Id: mxml.h 427 2011-01-03 02:03:29Z mike $".
329 */
diff --git a/pathologist/src/include/platform.h b/pathologist/src/include/platform.h
new file mode 100644
index 0000000..994a5b6
--- /dev/null
+++ b/pathologist/src/include/platform.h
@@ -0,0 +1,266 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file include/platform.h
23 * @brief plaform specifics
24 *
25 * @author Nils Durner
26 *
27 * This file should never be included by installed
28 * header files (thos starting with "gnunet_").
29 */
30
31#ifndef PLATFORM_H
32#define PLATFORM_H
33
34#ifndef HAVE_USED_CONFIG_H
35#define HAVE_USED_CONFIG_H
36#if HAVE_CONFIG_H
37//#include "gnunet_config.h"
38#endif
39#endif
40
41#ifdef WINDOWS
42#define BREAKPOINT asm("int $3;");
43#define GNUNET_SIGCHLD 17
44#else
45#define BREAKPOINT
46#define GNUNET_SIGCHLD SIGCHLD
47#endif
48
49#ifdef HAVE_SYS_TYPES_H
50#include <sys/types.h>
51#endif
52
53#define ALLOW_EXTRA_CHECKS GNUNET_NO
54
55/**
56 * For strptime (glibc2 needs this).
57 */
58#ifndef _XOPEN_SOURCE
59#define _XOPEN_SOURCE
60#endif
61
62#ifndef _REENTRANT
63#define _REENTRANT
64#endif
65
66/* configuration options */
67
68#define VERBOSE_STATS 0
69
70#ifdef CYGWIN
71#include <sys/reent.h>
72#endif
73
74#ifdef _MSC_VER
75#ifndef FD_SETSIZE
76#define FD_SETSIZE 1024
77#endif
78#include <Winsock2.h>
79#include <ws2tcpip.h>
80#else
81#ifndef MINGW
82#include <netdb.h>
83#include <sys/socket.h>
84#include <sys/un.h>
85#if HAVE_NETINET_IN_H
86#include <netinet/in.h>
87#endif
88#if HAVE_NETINET_IN_SYSTM_H
89#include <netinet/in_systm.h>
90#endif
91#include <netinet/ip.h> /* superset of previous */
92#include <arpa/inet.h>
93#include <netinet/tcp.h>
94#include <pwd.h>
95#include <sys/ioctl.h>
96#include <sys/wait.h>
97#include <grp.h>
98#else
99#include "winproc.h"
100#endif
101#endif
102
103#include <string.h>
104#include <stdio.h>
105#include <stdlib.h>
106#include <stdint.h>
107#include <stdarg.h>
108#include <errno.h>
109#include <signal.h>
110#include <libgen.h>
111#ifdef WINDOWS
112#include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
113#endif
114#ifndef _MSC_VER
115#include <unistd.h> /* KLB_FIX */
116#endif
117#include <sys/stat.h>
118#include <sys/types.h>
119#ifndef _MSC_VER
120#include <dirent.h> /* KLB_FIX */
121#endif
122#include <fcntl.h>
123#include <math.h>
124#if HAVE_SYS_PARAM_H
125#include <sys/param.h>
126#endif
127#if TIME_WITH_SYS_TIME
128#include <sys/time.h>
129#include <time.h>
130#else
131#if HAVE_SYS_TIME_H
132#include <sys/time.h>
133#else
134#include <time.h>
135#endif
136#endif
137
138#ifdef SOMEBSD
139#include <net/if.h>
140#endif
141#ifdef GNUNET_freeBSD
142#include <semaphore.h>
143#endif
144#ifdef DARWIN
145#include <dlfcn.h>
146#include <semaphore.h>
147#include <net/if.h>
148#endif
149#if defined(LINUX) || defined(GNU)
150#include <net/if.h>
151#endif
152#ifdef SOLARIS
153#include <sys/sockio.h>
154#include <sys/filio.h>
155#include <sys/loadavg.h>
156#include <semaphore.h>
157#endif
158#if HAVE_UCRED_H
159#include <ucred.h>
160#endif
161#ifdef CYGWIN
162#include <windows.h>
163#include <cygwin/if.h>
164#endif
165#if HAVE_IFADDRS_H
166#include <ifaddrs.h>
167#endif
168#include <errno.h>
169#include <limits.h>
170
171#if HAVE_VFORK_H
172#include <vfork.h>
173#endif
174
175#include <ctype.h>
176#if HAVE_SYS_RESOURCE_H
177#include <sys/resource.h>
178#endif
179
180#if HAVE_ENDIAN_H
181#include <endian.h>
182#endif
183#if HAVE_SYS_ENDIAN_H
184#include <sys/endian.h>
185#endif
186
187#include "plibc.h"
188
189//#include <locale.h>
190//#ifndef FRAMEWORK_BUILD
191//#include "gettext.h"
192///**
193// * GNU gettext support macro.
194// */
195//#define _(String) dgettext("gnunet",String)
196//#define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
197//#else
198//#include "libintlemu.h"
199//#define _(String) dgettext("org.gnunet.gnunet",String)
200//#define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
201//#endif
202
203#ifdef CYGWIN
204#define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */
205#define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */
206#define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */
207#endif
208
209#ifndef MINGW
210#include <sys/mman.h>
211#endif
212
213#ifdef FREEBSD
214#define __BYTE_ORDER BYTE_ORDER
215#define __BIG_ENDIAN BIG_ENDIAN
216#endif
217
218#ifdef DARWIN
219#define __BYTE_ORDER BYTE_ORDER
220#define __BIG_ENDIAN BIG_ENDIAN
221 /* not available on darwin, override configure */
222#undef HAVE_STAT64
223#undef HAVE_MREMAP
224#endif
225
226
227#if !HAVE_ATOLL
228long long
229atoll (const char *nptr);
230#endif
231
232#if ENABLE_NLS
233#include "langinfo.h"
234#endif
235
236#ifndef SIZE_MAX
237#define SIZE_MAX ((size_t)(-1))
238#endif
239
240#ifndef O_LARGEFILE
241#define O_LARGEFILE 0
242#endif
243
244/**
245 * AI_NUMERICSERV not defined in windows. Then we just do without.
246 */
247#ifndef AI_NUMERICSERV
248#define AI_NUMERICSERV 0
249#endif
250
251
252#if defined(__sparc__)
253#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
254#else
255#define MAKE_UNALIGNED(val) val
256#endif
257
258#if WINDOWS
259#define FDTYPE HANDLE
260#define SOCKTYPE SOCKET
261#else
262#define FDTYPE int
263#define SOCKTYPE int
264#endif
265
266#endif
diff --git a/pathologist/src/include/plibc.h b/pathologist/src/include/plibc.h
new file mode 100644
index 0000000..8314f21
--- /dev/null
+++ b/pathologist/src/include/plibc.h
@@ -0,0 +1,810 @@
1/*
2 This file is part of PlibC.
3 (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20/**
21 * @file include/plibc.h
22 * @brief PlibC header
23 * @attention This file is usually not installed under Unix,
24 * so ship it with your application
25 * @version $Revision: 69 $
26 */
27
28#ifndef _PLIBC_H_
29#define _PLIBC_H_
30
31#ifndef SIGALRM
32#define SIGALRM 14
33#endif
34
35#ifdef __cplusplus
36extern "C"
37{
38#endif
39
40#include <stddef.h>
41
42#ifdef Q_OS_WIN32
43#define WINDOWS 1
44#endif
45
46#define HAVE_PLIBC_FD 0
47
48#ifdef WINDOWS
49
50#if ENABLE_NLS
51#include "langinfo.h"
52#endif
53
54#include <winsock2.h>
55#include <ws2tcpip.h>
56#include <windows.h>
57#include <sys/types.h>
58#include <time.h>
59#include <stdio.h>
60#include <sys/types.h>
61#include <sys/stat.h>
62#include <dirent.h>
63#include <errno.h>
64#include <stdarg.h>
65
66#define __BYTE_ORDER BYTE_ORDER
67#define __BIG_ENDIAN BIG_ENDIAN
68
69/* Conflicts with our definitions */
70#define __G_WIN32_H__
71
72/* Convert LARGE_INTEGER to double */
73#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
74 (double)((x).LowPart))
75
76 struct stat64
77 {
78 _dev_t st_dev;
79 _ino_t st_ino;
80 _mode_t st_mode;
81 short st_nlink;
82 short st_uid;
83 short st_gid;
84 _dev_t st_rdev;
85 __int64 st_size;
86 __time64_t st_atime;
87 __time64_t st_mtime;
88 __time64_t st_ctime;
89 };
90
91 typedef unsigned int sa_family_t;
92
93 struct sockaddr_un
94 {
95 short sun_family; /*AF_UNIX */
96 char sun_path[108]; /*path name */
97 };
98
99#ifndef pid_t
100#define pid_t DWORD
101#endif
102
103#ifndef error_t
104#define error_t int
105#endif
106
107#ifndef WEXITSTATUS
108#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
109#endif
110
111#ifndef MSG_DONTWAIT
112#define MSG_DONTWAIT 0
113#endif
114
115 enum
116 {
117 _SC_PAGESIZE = 30,
118 _SC_PAGE_SIZE = 30
119 };
120
121/* Thanks to the Cygwin project */
122#define ENOCSI 43 /* No CSI structure available */
123#define EL2HLT 44 /* Level 2 halted */
124#ifndef EDEADLK
125#define EDEADLK 45 /* Deadlock condition */
126#endif
127#ifndef ENOLCK
128#define ENOLCK 46 /* No record locks available */
129#endif
130#define EBADE 50 /* Invalid exchange */
131#define EBADR 51 /* Invalid request descriptor */
132#define EXFULL 52 /* Exchange full */
133#define ENOANO 53 /* No anode */
134#define EBADRQC 54 /* Invalid request code */
135#define EBADSLT 55 /* Invalid slot */
136#ifndef EDEADLOCK
137#define EDEADLOCK EDEADLK /* File locking deadlock error */
138#endif
139#define EBFONT 57 /* Bad font file fmt */
140#define ENOSTR 60 /* Device not a stream */
141#define ENODATA 61 /* No data (for no delay io) */
142#define ETIME 62 /* Timer expired */
143#define ENOSR 63 /* Out of streams resources */
144#define ENONET 64 /* Machine is not on the network */
145#define ENOPKG 65 /* Package not installed */
146#define EREMOTE 66 /* The object is remote */
147#define ENOLINK 67 /* The link has been severed */
148#define EADV 68 /* Advertise error */
149#define ESRMNT 69 /* Srmount error */
150#define ECOMM 70 /* Communication error on send */
151#define EPROTO 71 /* Protocol error */
152#define EMULTIHOP 74 /* Multihop attempted */
153#define ELBIN 75 /* Inode is remote (not really error) */
154#define EDOTDOT 76 /* Cross mount point (not really error) */
155#define EBADMSG 77 /* Trying to read unreadable message */
156#define ENOTUNIQ 80 /* Given log. name not unique */
157#define EBADFD 81 /* f.d. invalid for this operation */
158#define EREMCHG 82 /* Remote address changed */
159#define ELIBACC 83 /* Can't access a needed shared lib */
160#define ELIBBAD 84 /* Accessing a corrupted shared lib */
161#define ELIBSCN 85 /* .lib section in a.out corrupted */
162#define ELIBMAX 86 /* Attempting to link in too many libs */
163#define ELIBEXEC 87 /* Attempting to exec a shared library */
164#ifndef ENOSYS
165#define ENOSYS 88 /* Function not implemented */
166#endif
167#define ENMFILE 89 /* No more files */
168#ifndef ENOTEMPTY
169#define ENOTEMPTY 90 /* Directory not empty */
170#endif
171#ifndef ENAMETOOLONG
172#define ENAMETOOLONG 91 /* File or path name too long */
173#endif
174#define ELOOP 92 /* Too many symbolic links */
175#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
176#define EPFNOSUPPORT 96 /* Protocol family not supported */
177#define ECONNRESET 104 /* Connection reset by peer */
178#define ENOBUFS 105 /* No buffer space available */
179#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
180#define EPROTOTYPE 107 /* Protocol wrong type for socket */
181#define ENOTSOCK 108 /* Socket operation on non-socket */
182#define ENOPROTOOPT 109 /* Protocol not available */
183#define ESHUTDOWN 110 /* Can't send after socket shutdown */
184#define ECONNREFUSED 111 /* Connection refused */
185#define EADDRINUSE 112 /* Address already in use */
186#define ECONNABORTED 113 /* Connection aborted */
187#define ENETUNREACH 114 /* Network is unreachable */
188#define ENETDOWN 115 /* Network interface is not configured */
189#ifndef ETIMEDOUT
190#define ETIMEDOUT 116 /* Connection timed out */
191#endif
192#define EHOSTDOWN 117 /* Host is down */
193#define EHOSTUNREACH 118 /* Host is unreachable */
194#define EINPROGRESS 119 /* Connection already in progress */
195#define EALREADY 120 /* Socket already connected */
196#define EDESTADDRREQ 121 /* Destination address required */
197#define EMSGSIZE 122 /* Message too long */
198#define EPROTONOSUPPORT 123 /* Unknown protocol */
199#define ESOCKTNOSUPPORT 124 /* Socket type not supported */
200#define EADDRNOTAVAIL 125 /* Address not available */
201#define ENETRESET 126 /* Connection aborted by network */
202#define EISCONN 127 /* Socket is already connected */
203#define ENOTCONN 128 /* Socket is not connected */
204#define ETOOMANYREFS 129 /* Too many references: cannot splice */
205#define EPROCLIM 130 /* Too many processes */
206#define EUSERS 131 /* Too many users */
207#define EDQUOT 132 /* Disk quota exceeded */
208#define ESTALE 133 /* Unknown error */
209#ifndef ENOTSUP
210#define ENOTSUP 134 /* Not supported */
211#endif
212#define ENOMEDIUM 135 /* No medium (in tape drive) */
213#define ENOSHARE 136 /* No such host or network path */
214#define ECASECLASH 137 /* Filename exists with different case */
215#define EWOULDBLOCK EAGAIN /* Operation would block */
216#define EOVERFLOW 139 /* Value too large for defined data type */
217
218#undef HOST_NOT_FOUND
219#define HOST_NOT_FOUND 1
220#undef TRY_AGAIN
221#define TRY_AGAIN 2
222#undef NO_RECOVERY
223#define NO_RECOVERY 3
224#undef NO_ADDRESS
225#define NO_ADDRESS 4
226
227#define PROT_READ 0x1
228#define PROT_WRITE 0x2
229#define MAP_SHARED 0x1
230#define MAP_PRIVATE 0x2 /* unsupported */
231#define MAP_FIXED 0x10
232#define MAP_FAILED ((void *)-1)
233
234 struct statfs
235 {
236 long f_type; /* type of filesystem (see below) */
237 long f_bsize; /* optimal transfer block size */
238 long f_blocks; /* total data blocks in file system */
239 long f_bfree; /* free blocks in fs */
240 long f_bavail; /* free blocks avail to non-superuser */
241 long f_files; /* total file nodes in file system */
242 long f_ffree; /* free file nodes in fs */
243 long f_fsid; /* file system id */
244 long f_namelen; /* maximum length of filenames */
245 long f_spare[6]; /* spare for later */
246 };
247
248 extern const struct in6_addr in6addr_any; /* :: */
249 extern const struct in6_addr in6addr_loopback; /* ::1 */
250
251/* Taken from the Wine project <http://www.winehq.org>
252 /wine/include/winternl.h */
253 enum SYSTEM_INFORMATION_CLASS
254 {
255 SystemBasicInformation = 0,
256 Unknown1,
257 SystemPerformanceInformation = 2,
258 SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */
259 Unknown4,
260 SystemProcessInformation = 5,
261 Unknown6,
262 Unknown7,
263 SystemProcessorPerformanceInformation = 8,
264 Unknown9,
265 Unknown10,
266 SystemDriverInformation,
267 Unknown12,
268 Unknown13,
269 Unknown14,
270 Unknown15,
271 SystemHandleList,
272 Unknown17,
273 Unknown18,
274 Unknown19,
275 Unknown20,
276 SystemCacheInformation,
277 Unknown22,
278 SystemInterruptInformation = 23,
279 SystemExceptionInformation = 33,
280 SystemRegistryQuotaInformation = 37,
281 SystemLookasideInformation = 45
282 };
283
284 typedef struct
285 {
286 LARGE_INTEGER IdleTime;
287 LARGE_INTEGER KernelTime;
288 LARGE_INTEGER UserTime;
289 LARGE_INTEGER Reserved1[2];
290 ULONG Reserved2;
291 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
292
293#define sleep(secs) (Sleep(secs * 1000))
294
295/*********************** statfs *****************************/
296/* fake block size */
297#define FAKED_BLOCK_SIZE 512
298
299/* linux-compatible values for fs type */
300#define MSDOS_SUPER_MAGIC 0x4d44
301#define NTFS_SUPER_MAGIC 0x5346544E
302
303/*********************** End of statfs ***********************/
304
305#define SHUT_RDWR SD_BOTH
306
307/* Operations for flock() */
308#define LOCK_SH 1 /* shared lock */
309#define LOCK_EX 2 /* exclusive lock */
310#define LOCK_NB 4 /* or'd with one of the above to prevent
311 * blocking */
312#define LOCK_UN 8 /* remove lock */
313
314/* Not supported under MinGW */
315#define S_IRGRP 0
316#define S_IWGRP 0
317#define S_IROTH 0
318#define S_IXGRP 0
319#define S_IWOTH 0
320#define S_IXOTH 0
321#define S_ISUID 0
322#define S_ISGID 0
323#define S_ISVTX 0
324#define S_IRWXG 0
325#define S_IRWXO 0
326
327#define SHUT_WR SD_SEND
328#define SHUT_RD SD_RECEIVE
329#define SHUT_RDWR SD_BOTH
330
331#define SIGKILL 9
332#define SIGTERM 15
333
334#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
335
336 BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest);
337 BOOL _plibc_DereferenceShortcut (char *pszShortcut);
338 char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags);
339 char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags);
340 long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey,
341 char *pszBuffer, long *pdLength);
342
343 BOOL __win_IsHandleMarkedAsBlocking (int hHandle);
344 void __win_SetHandleBlockingMode (int s, BOOL bBlocking);
345 void __win_DiscardHandleBlockingMode (int s);
346 int _win_isSocketValid (int s);
347 int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows);
348 unsigned plibc_get_handle_count ();
349
350 typedef void (*TPanicProc) (int, char *);
351 void plibc_set_panic_proc (TPanicProc proc);
352
353 int flock (int fd, int operation);
354 int fsync (int fildes);
355 int inet_pton (int af, const char *src, void *dst);
356 int inet_pton4 (const char *src, u_char * dst, int pton);
357#if USE_IPV6
358 int inet_pton6 (const char *src, u_char * dst);
359#endif
360 int truncate (const char *fname, int distance);
361 int statfs (const char *path, struct statfs *buf);
362 const char *hstrerror (int err);
363 int mkstemp (char *tmplate);
364 char *strptime (const char *buf, const char *format, struct tm *tm);
365 const char *inet_ntop (int af, const void *src, char *dst, size_t size);
366
367 int plibc_init (char *pszOrg, char *pszApp);
368 void plibc_shutdown ();
369 int plibc_initialized ();
370 int plibc_conv_to_win_path_ex (const char *pszUnix, char *pszWindows,
371 int derefLinks);
372 void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine);
373 void SetErrnoFromWinsockError (long lWinError);
374 void SetHErrnoFromWinError (long lWinError);
375 void SetErrnoFromHRESULT (HRESULT hRes);
376 int GetErrnoFromWinsockError (long lWinError);
377 FILE *_win_fopen (const char *filename, const char *mode);
378 DIR *_win_opendir (const char *dirname);
379 int _win_open (const char *filename, int oflag, ...);
380#ifdef ENABLE_NLS
381 char *_win_bindtextdomain (const char *domainname, const char *dirname);
382#endif
383 int _win_chdir (const char *path);
384 int _win_close (int fd);
385 int _win_creat (const char *path, mode_t mode);
386 char *_win_ctime (const time_t * clock);
387 char *_win_ctime_r (const time_t * clock, char *buf);
388 int _win_fstat (int handle, struct stat *buffer);
389 int _win_ftruncate (int fildes, off_t length);
390 void _win_gettimeofday (struct timeval *tp, void *tzp);
391 int _win_kill (pid_t pid, int sig);
392 int _win_pipe (int *phandles);
393 int _win_rmdir (const char *path);
394 int _win_access (const char *path, int mode);
395 int _win_chmod (const char *filename, int pmode);
396 char *realpath (const char *file_name, char *resolved_name);
397 long _win_random (void);
398 void _win_srandom (unsigned int seed);
399 int _win_remove (const char *path);
400 int _win_rename (const char *oldname, const char *newname);
401 int _win_stat (const char *path, struct stat *buffer);
402 int _win_stat64 (const char *path, struct stat64 *buffer);
403 long _win_sysconf (int name);
404 int _win_unlink (const char *filename);
405 int _win_write (int fildes, const void *buf, size_t nbyte);
406 int _win_read (int fildes, void *buf, size_t nbyte);
407 size_t _win_fwrite (const void *buffer, size_t size, size_t count,
408 FILE * stream);
409 size_t _win_fread (void *buffer, size_t size, size_t count, FILE * stream);
410 int _win_symlink (const char *path1, const char *path2);
411 void *_win_mmap (void *start, size_t len, int access, int flags, int fd,
412 unsigned long long offset);
413 int _win_munmap (void *start, size_t length);
414 int _win_lstat (const char *path, struct stat *buf);
415 int _win_lstat64 (const char *path, struct stat64 *buf);
416 int _win_readlink (const char *path, char *buf, size_t bufsize);
417 int _win_accept (int s, struct sockaddr *addr, int *addrlen);
418 int _win_printf (const char *format, ...);
419 int _win_fprintf (FILE * f, const char *format, ...);
420 int _win_vprintf (const char *format, va_list ap);
421 int _win_vfprintf (FILE * stream, const char *format, va_list arg_ptr);
422 int _win_vsprintf (char *dest, const char *format, va_list arg_ptr);
423 int _win_vsnprintf (char *str, size_t size, const char *format,
424 va_list arg_ptr);
425 int _win_snprintf (char *str, size_t size, const char *format, ...);
426 int _win_sprintf (char *dest, const char *format, ...);
427 int _win_vsscanf (const char *str, const char *format, va_list arg_ptr);
428 int _win_sscanf (const char *str, const char *format, ...);
429 int _win_vfscanf (FILE * stream, const char *format, va_list arg_ptr);
430 int _win_vscanf (const char *format, va_list arg_ptr);
431 int _win_scanf (const char *format, ...);
432 int _win_fscanf (FILE * stream, const char *format, ...);
433 pid_t _win_waitpid (pid_t pid, int *stat_loc, int options);
434 int _win_bind (int s, const struct sockaddr *name, int namelen);
435 int _win_connect (int s, const struct sockaddr *name, int namelen);
436 int _win_getpeername (int s, struct sockaddr *name, int *namelen);
437 int _win_getsockname (int s, struct sockaddr *name, int *namelen);
438 int _win_getsockopt (int s, int level, int optname, char *optval,
439 int *optlen);
440 int _win_listen (int s, int backlog);
441 int _win_recv (int s, char *buf, int len, int flags);
442 int _win_recvfrom (int s, void *buf, int len, int flags,
443 struct sockaddr *from, int *fromlen);
444 int _win_select (int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
445 const struct timeval *tv);
446 int _win_send (int s, const char *buf, int len, int flags);
447 int _win_sendto (int s, const char *buf, int len, int flags,
448 const struct sockaddr *to, int tolen);
449 int _win_setsockopt (int s, int level, int optname, const void *optval,
450 int optlen);
451 int _win_shutdown (int s, int how);
452 int _win_socket (int af, int type, int protocol);
453 struct hostent *_win_gethostbyaddr (const char *addr, int len, int type);
454 struct hostent *_win_gethostbyname (const char *name);
455 struct hostent *gethostbyname2 (const char *name, int af);
456 char *_win_strerror (int errnum);
457 int IsWinNT ();
458 char *index (const char *s, int c);
459
460#if !HAVE_STRNDUP
461 char *strndup (const char *s, size_t n);
462#endif
463#if !HAVE_STRNLEN
464 size_t strnlen (const char *str, size_t maxlen);
465#endif
466 char *stpcpy (char *dest, const char *src);
467 char *strcasestr (const char *haystack_start, const char *needle_start);
468
469#define strcasecmp(a, b) stricmp(a, b)
470#define strncasecmp(a, b, c) strnicmp(a, b, c)
471
472#endif /* WINDOWS */
473
474#ifndef WINDOWS
475#define DIR_SEPARATOR '/'
476#define DIR_SEPARATOR_STR "/"
477#define PATH_SEPARATOR ':'
478#define PATH_SEPARATOR_STR ":"
479#define NEWLINE "\n"
480
481#ifdef ENABLE_NLS
482#define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
483#endif
484#define CREAT(p, m) creat(p, m)
485#define PLIBC_CTIME(c) ctime(c)
486#define CTIME_R(c, b) ctime_r(c, b)
487#undef FOPEN
488#define FOPEN(f, m) fopen(f, m)
489#define FTRUNCATE(f, l) ftruncate(f, l)
490#define OPENDIR(d) opendir(d)
491#define OPEN open
492#define CHDIR(d) chdir(d)
493#define CLOSE(f) close(f)
494#define LSEEK(f, o, w) lseek(f, o, w)
495#define RMDIR(f) rmdir(f)
496#define ACCESS(p, m) access(p, m)
497#define CHMOD(f, p) chmod(f, p)
498#define FSTAT(h, b) fstat(h, b)
499#define PLIBC_KILL(p, s) kill(p, s)
500#define PIPE(h) pipe(h)
501#define REMOVE(p) remove(p)
502#define RENAME(o, n) rename(o, n)
503#define STAT(p, b) stat(p, b)
504#define STAT64(p, b) stat64(p, b)
505#define SYSCONF(n) sysconf(n)
506#define UNLINK(f) unlink(f)
507#define WRITE(f, b, n) write(f, b, n)
508#define READ(f, b, n) read(f, b, n)
509#define GN_FREAD(b, s, c, f) fread(b, s, c, f)
510#define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
511#define SYMLINK(a, b) symlink(a, b)
512#define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
513#define MUNMAP(s, l) munmap(s, l)
514#define STRERROR(i) strerror(i)
515#define RANDOM() random()
516#define SRANDOM(s) srandom(s)
517#define READLINK(p, b, s) readlink(p, b, s)
518#define LSTAT(p, b) lstat(p, b)
519#define LSTAT64(p, b) lstat64(p, b)
520#define PRINTF printf
521#define FPRINTF fprintf
522#define VPRINTF(f, a) vprintf(f, a)
523#define VFPRINTF(s, f, a) vfprintf(s, f, a)
524#define VSPRINTF(d, f, a) vsprintf(d, f, a)
525#define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
526#define _REAL_SNPRINTF snprintf
527#define SPRINTF sprintf
528#define VSSCANF(s, f, a) vsscanf(s, f, a)
529#define SSCANF sscanf
530#define VFSCANF(s, f, a) vfscanf(s, f, a)
531#define VSCANF(f, a) vscanf(f, a)
532#define SCANF scanf
533#define FSCANF fscanf
534#define WAITPID(p, s, o) waitpid(p, s, o)
535#define ACCEPT(s, a, l) accept(s, a, l)
536#define BIND(s, n, l) bind(s, n, l)
537#define CONNECT(s, n, l) connect(s, n, l)
538#define GETPEERNAME(s, n, l) getpeername(s, n, l)
539#define GETSOCKNAME(s, n, l) getsockname(s, n, l)
540#define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
541#define LISTEN(s, b) listen(s, b)
542#define RECV(s, b, l, f) recv(s, b, l, f)
543#define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
544#define SELECT(n, r, w, e, t) select(n, r, w, e, t)
545#define SEND(s, b, l, f) send(s, b, l, f)
546#define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
547#define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
548#define SHUTDOWN(s, h) shutdown(s, h)
549#define SOCKET(a, t, p) socket(a, t, p)
550#define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t)
551#define GETHOSTBYNAME(n) gethostbyname(n)
552#define GETTIMEOFDAY(t, n) gettimeofday(t, n)
553#define INSQUE(e, p) insque(e, p)
554#define REMQUE(e) remque(e)
555#define HSEARCH(i, a) hsearch(i, a)
556#define HCREATE(n) hcreate(n)
557#define HDESTROY() hdestroy()
558#define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
559#define HCREATE_R(n, h) hcreate_r(n, h)
560#define HDESTROY_R(h) hdestroy_r(h)
561#define TSEARCH(k, r, c) tsearch(k, r, c)
562#define TFIND(k, r, c) tfind(k, r, c)
563#define TDELETE(k, r, c) tdelete(k, r, c)
564#define TWALK(r, a) twalk(r, a)
565#define TDESTROY(r, f) tdestroy(r, f)
566#define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
567#define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
568#else
569#define DIR_SEPARATOR '\\'
570#define DIR_SEPARATOR_STR "\\"
571#define PATH_SEPARATOR ';'
572#define PATH_SEPARATOR_STR ";"
573#define NEWLINE "\r\n"
574
575#ifdef ENABLE_NLS
576#define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
577#endif
578#define CREAT(p, m) _win_creat(p, m)
579#define PLIBC_CTIME(c) _win_ctime(c)
580#define CTIME_R(c, b) _win_ctime_r(c, b)
581#define FOPEN(f, m) _win_fopen(f, m)
582#define FTRUNCATE(f, l) _win_ftruncate(f, l)
583#define OPENDIR(d) _win_opendir(d)
584#define OPEN _win_open
585#define CHDIR(d) _win_chdir(d)
586#define CLOSE(f) _win_close(f)
587#define PLIBC_KILL(p, s) _win_kill(p, s)
588#define LSEEK(f, o, w) _win_lseek(f, o, w)
589#define FSTAT(h, b) _win_fstat(h, b)
590#define RMDIR(f) _win_rmdir(f)
591#define ACCESS(p, m) _win_access(p, m)
592#define CHMOD(f, p) _win_chmod(f, p)
593#define PIPE(h) _win_pipe(h)
594#define RANDOM() _win_random()
595#define SRANDOM(s) _win_srandom(s)
596#define REMOVE(p) _win_remove(p)
597#define RENAME(o, n) _win_rename(o, n)
598#define STAT(p, b) _win_stat(p, b)
599#define STAT64(p, b) _win_stat64(p, b)
600#define SYSCONF(n) _win_sysconf(n)
601#define UNLINK(f) _win_unlink(f)
602#define WRITE(f, b, n) _win_write(f, b, n)
603#define READ(f, b, n) _win_read(f, b, n)
604#define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
605#define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
606#define SYMLINK(a, b) _win_symlink(a, b)
607#define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
608#define MUNMAP(s, l) _win_munmap(s, l)
609#define STRERROR(i) _win_strerror(i)
610#define READLINK(p, b, s) _win_readlink(p, b, s)
611#define LSTAT(p, b) _win_lstat(p, b)
612#define LSTAT64(p, b) _win_lstat64(p, b)
613#define PRINTF(f, ...) _win_printf(f , __VA_ARGS__)
614#define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__)
615#define VPRINTF(f, a) _win_vprintf(f, a)
616#define VFPRINTF(s, f, a) _win_vfprintf(s, f, a)
617#define VSPRINTF(d, f, a) _win_vsprintf(d, f, a)
618#define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a)
619#define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__)
620#define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__)
621#define VSSCANF(s, f, a) _win_vsscanf(s, f, a)
622#define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__)
623#define VFSCANF(s, f, a) _win_vfscanf(s, f, a)
624#define VSCANF(f, a) _win_vscanf(f, a)
625#define SCANF(f, ...) _win_scanf(f, __VA_ARGS__)
626#define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__)
627#define WAITPID(p, s, o) _win_waitpid(p, s, o)
628#define ACCEPT(s, a, l) _win_accept(s, a, l)
629#define BIND(s, n, l) _win_bind(s, n, l)
630#define CONNECT(s, n, l) _win_connect(s, n, l)
631#define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
632#define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
633#define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
634#define LISTEN(s, b) _win_listen(s, b)
635#define RECV(s, b, l, f) _win_recv(s, b, l, f)
636#define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
637#define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
638#define SEND(s, b, l, f) _win_send(s, b, l, f)
639#define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
640#define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
641#define SHUTDOWN(s, h) _win_shutdown(s, h)
642#define SOCKET(a, t, p) _win_socket(a, t, p)
643#define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t)
644#define GETHOSTBYNAME(n) _win_gethostbyname(n)
645#define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n)
646#define INSQUE(e, p) _win_insque(e, p)
647#define REMQUE(e) _win_remque(e)
648#define HSEARCH(i, a) _win_hsearch(i, a)
649#define HCREATE(n) _win_hcreate(n)
650#define HDESTROY() _win_hdestroy()
651#define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
652#define HCREATE_R(n, h) _win_hcreate_r(n, h)
653#define HDESTROY_R(h) _win_hdestroy_r(h)
654#define TSEARCH(k, r, c) _win_tsearch(k, r, c)
655#define TFIND(k, r, c) _win_tfind(k, r, c)
656#define TDELETE(k, r, c) _win_tdelete(k, r, c)
657#define TWALK(r, a) _win_twalk(r, a)
658#define TDESTROY(r, f) _win_tdestroy(r, f)
659#define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
660#define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
661#endif
662
663/* search.h */
664
665/* Prototype structure for a linked-list data structure.
666 This is the type used by the `insque' and `remque' functions. */
667
668 struct PLIBC_SEARCH_QELEM
669 {
670 struct qelem *q_forw;
671 struct qelem *q_back;
672 char q_data[1];
673 };
674
675
676/* Insert ELEM into a doubly-linked list, after PREV. */
677 void _win_insque (void *__elem, void *__prev);
678
679/* Unlink ELEM from the doubly-linked list that it is in. */
680 void _win_remque (void *__elem);
681
682
683/* For use with hsearch(3). */
684 typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
685
686 typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
687
688/* Action which shall be performed in the call the hsearch. */
689 typedef enum
690 {
691 PLIBC_SEARCH_FIND,
692 PLIBC_SEARCH_ENTER
693 }
694 PLIBC_SEARCH_ACTION;
695
696 typedef struct PLIBC_SEARCH_entry
697 {
698 char *key;
699 void *data;
700 }
701 PLIBC_SEARCH_ENTRY;
702
703/* The reentrant version has no static variables to maintain the state.
704 Instead the interface of all functions is extended to take an argument
705 which describes the current status. */
706 typedef struct _PLIBC_SEARCH_ENTRY
707 {
708 unsigned int used;
709 PLIBC_SEARCH_ENTRY entry;
710 }
711 _PLIBC_SEARCH_ENTRY;
712
713
714/* Family of hash table handling functions. The functions also
715 have reentrant counterparts ending with _r. The non-reentrant
716 functions all work on a signle internal hashing table. */
717
718/* Search for entry matching ITEM.key in internal hash table. If
719 ACTION is `FIND' return found entry or signal error by returning
720 NULL. If ACTION is `ENTER' replace existing data (if any) with
721 ITEM.data. */
722 PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item,
723 PLIBC_SEARCH_ACTION __action);
724
725/* Create a new hashing table which will at most contain NEL elements. */
726 int _win_hcreate (size_t __nel);
727
728/* Destroy current internal hashing table. */
729 void _win_hdestroy (void);
730
731/* Data type for reentrant functions. */
732 struct PLIBC_SEARCH_hsearch_data
733 {
734 struct _PLIBC_SEARCH_ENTRY *table;
735 unsigned int size;
736 unsigned int filled;
737 };
738
739/* Reentrant versions which can handle multiple hashing tables at the
740 same time. */
741 int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action,
742 PLIBC_SEARCH_ENTRY ** __retval,
743 struct PLIBC_SEARCH_hsearch_data *__htab);
744 int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
745 void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
746
747
748/* The tsearch routines are very interesting. They make many
749 assumptions about the compiler. It assumes that the first field
750 in node must be the "key" field, which points to the datum.
751 Everything depends on that. */
752/* For tsearch */
753 typedef enum
754 {
755 PLIBC_SEARCH_preorder,
756 PLIBC_SEARCH_postorder,
757 PLIBC_SEARCH_endorder,
758 PLIBC_SEARCH_leaf
759 }
760 PLIBC_SEARCH_VISIT;
761
762/* Search for an entry matching the given KEY in the tree pointed to
763 by *ROOTP and insert a new element if not found. */
764 void *_win_tsearch (__const void *__key, void **__rootp,
765 PLIBC_SEARCH__compar_fn_t __compar);
766
767/* Search for an entry matching the given KEY in the tree pointed to
768 by *ROOTP. If no matching entry is available return NULL. */
769 void *_win_tfind (__const void *__key, void *__const * __rootp,
770 PLIBC_SEARCH__compar_fn_t __compar);
771
772/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
773 void *_win_tdelete (__const void *__restrict __key, void **__restrict __rootp,
774 PLIBC_SEARCH__compar_fn_t __compar);
775
776 typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep,
777 PLIBC_SEARCH_VISIT __value,
778 int __level);
779
780/* Walk through the whole tree and call the ACTION callback for every node
781 or leaf. */
782 void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
783
784/* Callback type for function to free a tree node. If the keys are atomic
785 data this function should do nothing. */
786 typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
787
788/* Destroy the whole tree, call FREEFCT for each node or leaf. */
789 void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
790
791
792/* Perform linear search for KEY by comparing by COMPAR in an array
793 [BASE,BASE+NMEMB*SIZE). */
794 void *_win_lfind (__const void *__key, __const void *__base, size_t * __nmemb,
795 size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
796
797/* Perform linear search for KEY by comparing by COMPAR function in
798 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
799 void *_win_lsearch (__const void *__key, void *__base, size_t * __nmemb,
800 size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
801
802
803#ifdef __cplusplus
804}
805#endif
806
807
808#endif //_PLIBC_H_
809
810/* end of plibc.h */