1 /*****************************************************************************
2    Major portions of this software are copyrighted by the Medical College
3    of Wisconsin, 1994-2000, and are released under the Gnu General Public
4    License, Version 2.  See the file README.Copyright for details.
5 ******************************************************************************/
6 
7 #ifndef _AFNI_PLUGIN_HEADER_
8 #define _AFNI_PLUGIN_HEADER_
9 
10 /*-----------------------------------------------------------------
11   Most of this file is included only if ALLOW_PLUGINS is defined,
12   but a little at the end is always used.
13 -------------------------------------------------------------------*/
14 
15 #define PLUTO_X11_display   (GLOBAL_library.dc->display)
16 #define PLUTO_Xt_appcontext (GLOBAL_library.dc->appcontext)
17 
18 #ifdef ALLOW_PLUGINS
19 
20 #if defined(__cplusplus) || defined(c_plusplus)
21 # define DEFINE_PLUGIN_PROTOTYPE \
22   extern "C" { PLUGIN_interface * PLUGIN_init( int ncall ) ; }
23 #else
24 # define DEFINE_PLUGIN_PROTOTYPE
25 #endif
26 
27 extern int first_plugin_check ;       /* cf afni.h */
28 #undef  CHECK_IF_ALLOWED              /* 30 Sep 2016 */
29 #define CHECK_IF_ALLOWED(nam1,nam2)                                                            \
30  do{ if( !AFNI_yesenv("AFNI_ALLOW_ALL_PLUGINS")    &&                                          \
31          !AFNI_yesenv("AFNI_ALLOW_" nam1 "_PLUGIN")   ){                                       \
32        if( first_plugin_check >  0 ){ fprintf(stderr,"\n"); first_plugin_check=0; }            \
33        if( first_plugin_check >= 0 )                                                           \
34          ININFO_message("plugin %17s: set AFNI_ALLOW_%s_PLUGIN to YES to allow it",nam2,nam1); \
35        return NULL ;                                                                           \
36      } } while(0)
37 
38 #include <sys/types.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <math.h>
43 #include <sys/time.h>
44 #include <sys/errno.h>
45 #include <sys/times.h>
46 #include <limits.h>
47 
48 struct AFNI_plugin_array ; /* incomplete definition */
49 
50 #include "afni.h"
51 
52 #include <Xm/XmAll.h>
53 
54 /*******************************************************************
55    Define macros and typedefs for opening, closing, and finding
56    symbols from dynamic libraries.  This is not done the same
57    way on all Unixoid systems, unfortunately (that is to say,
58    HP-UX is different).
59 *******************************************************************/
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 typedef int int_func() ;     /* generic function returning integer */
66 typedef void * vptr_func() ; /* generic function returning void *  */
67 typedef char * cptr_func() ; /* generic function returning char *  */
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 /***************** The dlfcn.h and dl library ****************/
74 
75 #ifdef DYNAMIC_LOADING_VIA_DL
76 
77 #ifndef DARWIN
78 #  include <dlfcn.h>
79 #else
80 #  include "dlcompat/dlfcn.h"
81 #endif
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87    typedef void * DYNAMIC_handle ;
88 
89 #  define ISVALID_DYNAMIC_handle(handle) ((handle) != (DYNAMIC_handle) 0)
90 
91 #  define DYNAMIC_OPEN(libname,handle) \
92       (handle) = dlopen( (libname) , RTLD_LAZY )
93 
94 #  define DYNAMIC_ERROR_STRING  dlerror()  /* 18 May 2001 */
95 
96 #  define DYNAMIC_CLOSE(handle) \
97       (void) dlclose( (handle) )
98 
99 #  define DYNAMIC_SYMBOL(handle,symbol,address) \
100       (address) = dlsym( (handle) , (symbol) )
101 
102 #ifndef DYNAMIC_suffix
103 #   define DYNAMIC_suffix ".so"
104 #endif
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif
111 
112 /****************** The dl.h and dld library ******************/
113 
114 #ifdef DYNAMIC_LOADING_VIA_SHL
115 #  include <dl.h>
116 #  include <errno.h>  /* 18 May 2001 */
117 
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121    typedef shl_t DYNAMIC_handle ;
122 
123 #  define ISVALID_DYNAMIC_handle(handle) ((handle) != (DYNAMIC_handle) 0)
124 
125 #  define DYNAMIC_OPEN(libname,handle) \
126       (handle) = shl_load( (libname) , BIND_DEFERRED , 0L )
127 
128 #  define DYNAMIC_ERROR_STRING strerror(errno) /* 18 May 2001 */
129 
130 #  define DYNAMIC_CLOSE(handle) \
131       (void) shl_unload( (handle) )
132 
133 #  define DYNAMIC_SYMBOL(handle,symbol,address)      \
134       do{ (address) = NULL ;                         \
135           (void) shl_findsym( &(handle) , (symbol) , \
136                               TYPE_UNDEFINED , &(address) ) ; } while(0)
137 
138 #  define DYNAMIC_suffix ".sl"
139 #ifdef __cplusplus
140 }
141 #endif
142 #endif
143 
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147 
148 #ifdef NO_DYNAMIC_LOADING             /* this stuff is not actually used,  */
149 #  define DYNAMIC_suffix ".fixed"     /* but is needed to make things cool */
150    typedef int DYNAMIC_handle ;       /* with the C compiler               */
151 #endif
152 
153 #ifndef DYNAMIC_suffix
154 #  error "Plugins not properly set up -- see machdep.h"
155 #endif
156 
157 /*****************************************************************
158    Data to define the interface between a plugin and AFNI
159 ******************************************************************/
160 
161 /* dimensions of various arrays */
162 
163 #define PLUGIN_LABEL_SIZE           32  /* for buttons and menus */
164 #define PLUGIN_STRING_SIZE         333  /* longer things [shorter than THD_MAX_NAME] */
165 
166 #define PLUGIN_MAX_STRING_RANGE    199  /* isn't this enough? */
167 
168 #define PLUGIN_MAX_SUBVALUES         9  /* isn't this enough? */
169                                         /*  -- Nope --  03 May 2002 [BDWard] */
170 
171 /* data type codes (not all are implemented yet!) */
172 
173 #define PLUGIN_NOTHING_TYPE          0
174 #define PLUGIN_NUMBER_TYPE           1  /* implemented */
175 #define PLUGIN_STRING_TYPE           2  /* implemented */
176 #define PLUGIN_DATASET_TYPE          3  /* implemented */
177 #define PLUGIN_DATASET_LIST_TYPE     4
178 #define PLUGIN_TIMESERIES_TYPE       5  /* implemented */
179 #define PLUGIN_TIMESERIES_LIST_TYPE  6
180 #define PLUGIN_2DIMAGE_TYPE          7
181 #define PLUGIN_2DIMAGE_LIST_TYPE     8
182 #define PLUGIN_3DIMAGE_TYPE          9
183 #define PLUGIN_3DIMAGE_LIST_TYPE    10
184 #define PLUGIN_4DIMAGE_TYPE         11
185 #define PLUGIN_4DIMAGE_LIST_TYPE    12
186 #define PLUGIN_OVERLAY_COLOR_TYPE   13
187 #define PLUGIN_TCSV_TYPE            14
188 
189 /** macro to copy string into plugin label array,
190     filling with blanks or truncating length, as needed **/
191 
192 #define PLUGIN_LABEL_strcpy(plab,str)                                \
193    do{ int ll=strlen((str)) , ii ;                                   \
194        if( ll >= PLUGIN_LABEL_SIZE ) ll = PLUGIN_LABEL_SIZE - 1 ;    \
195        for( ii=0 ; ii < ll ; ii++ ) (plab)[ii] = (str)[ii] ;         \
196        for( ; ii < PLUGIN_LABEL_SIZE - 1 ; ii++ ) (plab)[ii] = ' ' ; \
197        plab[PLUGIN_LABEL_SIZE - 1] = '\0' ; } while(0)
198 
199 /** prototype of routine to compute length
200     of string, not counting blanks at the end **/
201 
202 extern int PLUG_nonblank_len(char *) ;
203 
204 /******* typedef to hold data describing
205          each subvalue that an option requires *******/
206 
207 typedef struct {
208    int data_type ;  /* one of the PLUGIN_*_TYPE codes above */
209 
210    char label[PLUGIN_LABEL_SIZE] ;  /* label for AFNI to display */
211    char *hint ;
212 
213    /** values describing the range of acceptable inputs **/
214 
215    int int_range_bot , int_range_top , int_range_decim ; /* for NUMBER */
216 
217    int   string_range_count ;                           /* for STRING */
218    char *string_range[PLUGIN_MAX_STRING_RANGE] ;
219 
220    int dset_anat_mask , dset_func_mask , dset_ctrl_mask ; /* for DATASET */
221 
222    /** the default value to set up the interface with **/
223 
224    int value_default ;  /* for NUMBER or STRING */
225 
226    /** values describing other properties of the input **/
227 
228    int editable ;  /* can the user type into this? */
229 
230 } PLUGIN_subvalue ;
231 
232 /****** typedef to hold data describing
233         each option input line to a plugin ******/
234 
235 typedef struct {
236    char label[PLUGIN_LABEL_SIZE] ;  /* label for AFNI to display */
237    char tag[PLUGIN_STRING_SIZE] ;   /* passed to plugin */
238    char * hint ;
239 
240    int subvalue_count ;                              /* number of subvalues */
241    PLUGIN_subvalue subvalue[PLUGIN_MAX_SUBVALUES] ;  /* subvalue descriptors */
242 
243    int mandatory ;  /* required by law? */
244 
245    int    chosen ;
246    void * callvalue[PLUGIN_MAX_SUBVALUES] ; /* actual values given to plugin */
247 } PLUGIN_option ;
248 
249 /******* typedef to describe the option-level
250          widgets for the interface to a plugin *******/
251 
252 #define OP_CHOOSER_NONE       0   /* nothing                      */
253 #define OP_CHOOSER_DSET       1   /* PushButton                   */
254 #define OP_CHOOSER_OPTMENU    2   /* optmenu type of MCW_arrowval */
255 #define OP_CHOOSER_STRING     3   /* string type of MCW_arrowval  */
256 #define OP_CHOOSER_NUMBER     4   /* number type of MCW_arrowval  */
257 #define OP_CHOOSER_TEXTFIELD  5   /* TextField                    */
258 #define OP_CHOOSER_TIMESERIES 6   /* PushButton                   */
259 #define OP_CHOOSER_COLORMENU  7   /* optmenu for overlay colors   */
260 #define OP_CHOOSER_TCSV       8   /* PushButton                   */
261 
262 #define OP_OPTMENU_LIMIT     99
263 #define OP_OPTMENU_COLSIZE   20
264 
265 typedef struct {
266    Widget rowcol , label , textf ;
267 } PLUGIN_strval ;
268 
269 typedef struct {
270    char       title[THD_MAX_NAME] ;
271    MCW_idcode idcode ;
272 } PLUGIN_dataset_link ;
273 
274 extern void make_PLUGIN_dataset_link( THD_3dim_dataset *, PLUGIN_dataset_link * ) ;
275 extern void patch_PLUGIN_dataset_links( int , PLUGIN_dataset_link * ) ;
276 
277 typedef struct {
278    Widget rowcol , label , pb ;
279 
280    int                   dset_count ;  /* number of datasets to display */
281    PLUGIN_dataset_link * dset_link ;   /* info about them */
282    PLUGIN_subvalue     * sv ;          /* my good friend */
283 
284    int dset_choice ;                   /* the chosen index */
285 
286    int multi , nchosen , * chosen ;    /* 24 Nov 1996: for dataset lists */
287    int current ;
288    MCW_idcode * idclist ;
289 } PLUGIN_dsetval ;
290 
291 typedef PLUGIN_dsetval MCW_idclist ;
292 
293 typedef struct {
294    Widget rowcol , label , pb ;
295 
296    MRI_IMARR       * tsimar ;    /* array of time series to choose from */
297    PLUGIN_subvalue * sv ;        /* my good friend */
298 
299    MRI_IMAGE * tsim ;            /* the chosen timeseries */
300    int         ts_choice ;       /* the chosen index */
301 } PLUGIN_tsval ;
302 
303 typedef struct {
304    Widget rowcol , label , pb ;
305 
306    NI_ELARR        * elarr ;    /* array of data elements to choose from */
307    PLUGIN_subvalue * sv ;       /* my good friend */
308 
309    NI_element * tcsv_el ;        /* the chosen data element  */
310    int          tcsv_choice ;    /* the chosen index */
311 } PLUGIN_tcsvval ;
312 
313 typedef struct {
314    Widget toggle , label ;
315    void * chooser[PLUGIN_MAX_SUBVALUES] ;
316    Widget chtop[PLUGIN_MAX_SUBVALUES] ;
317    int    chooser_type[PLUGIN_MAX_SUBVALUES] ;
318 } PLUGIN_option_widgets ;
319 
320 /******* typedef to describe the top-level
321          widgets for the interface to a plugin *******/
322 
323 typedef struct {
324    Widget shell , form , label , scrollw , workwin ;
325    PLUGIN_option_widgets ** opwid ;
326    Widget meter ;
327 } PLUGIN_widgets ;
328 
329 /******* typedef to describe
330          the interface to a plugin *******/
331 
332 #define PLUGIN_CALL_IMMEDIATELY  77
333 #define PLUGIN_CALL_VIA_MENU     88
334 #define PLUGIN_CALL_VIA_CUSTOM   99
335 
336 typedef struct PLUGIN_interface {
337    char label[PLUGIN_LABEL_SIZE] ;         /* for a button */
338    char description[PLUGIN_STRING_SIZE] ;  /* for the interface panel */
339    char * helpstring ;                     /* from the user? */
340    char * hint ;
341 
342    int         call_method ;  /* one of the PLUGIN_CALL_* codes above */
343    cptr_func * call_func ;    /* function to call */
344 
345    int option_count ;         /* number of option lines */
346    PLUGIN_option ** option ;  /* array of option line descriptors */
347    PLUGIN_widgets * wid ;     /* toplevel widgets for this interface */
348 
349    Three_D_View * im3d ;      /* who called me up? */
350 
351    int opnum , svnum ;        /* used during get_*_from readout */
352 
353    char seqcode[PLUGIN_STRING_SIZE] ;  /* 06 Aug 1999 */
354    char butcolor[PLUGIN_STRING_SIZE] ; /* 01 Nov 1999 */
355 
356    int  flags ;                        /* 29 Mar 2002 */
357 
358    char run_label [PLUGIN_LABEL_SIZE] ; /* 04 Nov 2003 */
359    char doit_label[PLUGIN_LABEL_SIZE] ;
360    char toplabel  [PLUGIN_STRING_SIZE]; /* 13 May 2010 */
361 } PLUGIN_interface ;
362 
363 #define SHORT_CHOOSE_FLAG 1
364 #define SHORT_NUMBER_FLAG 2
365 
366 #define PLUTO_short_choose(pl) (pl->flags |= SHORT_CHOOSE_FLAG)
367 #define PLUTO_short_number(pl) (pl->flags |= SHORT_NUMBER_FLAG)
368 
369 /*************** Prototypes for creation of the above structures ***************/
370 
371 #define SESSION_ALL_MASK      (1<<0)
372 
373 #define ANAT_NONE_MASK        0
374 #define FUNC_NONE_MASK        0
375 
376 #define DIMEN_3D_MASK         (1<<1)
377 #define DIMEN_4D_MASK         (1<<2)
378 #define DIMEN_ALL_MASK        (DIMEN_3D_MASK | DIMEN_4D_MASK)
379 
380 #define WARP_ON_DEMAND_MASK   (1<<3)
381 
382 #define BRICK_BYTE_MASK       (1<<8)
383 #define BRICK_SHORT_MASK      (1<<9)
384 #define BRICK_FLOAT_MASK      (1<<10)
385 #define BRICK_COMPLEX_MASK    (1<<11)
386 #define BRICK_RGB_MASK        (1<<12)
387 #define BRICK_ALLTYPE_MASK    ( BRICK_BYTE_MASK  | BRICK_SHORT_MASK   |  \
388                                 BRICK_FLOAT_MASK | BRICK_COMPLEX_MASK |  \
389                                 BRICK_RGB_MASK                         )
390 
391 #define BRICK_ALLREAL_MASK    ( BRICK_BYTE_MASK  | BRICK_SHORT_MASK |    \
392                                 BRICK_FLOAT_MASK )
393 
394 extern int PLUGIN_dset_check( int,int    , THD_3dim_dataset * ) ;
395 extern int PLUTO_dset_check ( int,int,int, THD_3dim_dataset * ) ;
396 
397 #define PLUTO_add_option         add_option_to_PLUGIN_interface
398 #define PLUTO_add_number         add_number_to_PLUGIN_interface
399 #define PLUTO_add_string         add_string_to_PLUGIN_interface
400 #define PLUTO_add_dataset        add_dataset_to_PLUGIN_interface
401 #define PLUTO_add_timeseries     add_timeseries_to_PLUGIN_interface
402 #define PLUTO_add_tcsv           add_tcsv_to_PLUGIN_interface
403 #define PLUTO_add_dataset_list   add_dataset_list_to_PLUGIN_interface
404 #define PLUTO_add_overlaycolor   add_overlaycolor_to_PLUGIN_interface
405 
406 #define PLUTO_register_environment_numeric ENV_add_numeric     /* 20 Jun 2000 */
407 #define PLUTO_register_environment_string  ENV_add_string
408 #define PLUTO_register_environment_yesno   ENV_add_yesno       /* 08 Aug 2001 */
409 
410 extern void PLUTO_add_hint( PLUGIN_interface * , char * ) ;
411 
412 extern void PLUTO_set_sequence( PLUGIN_interface *, char * ) ; /* 06 Aug 1999 */
413 extern void PLUTO_set_butcolor( PLUGIN_interface *, char * ) ; /* 01 Nov 1999 */
414 extern void PLUTO_set_toplabel( PLUGIN_interface *, char * ) ; /* 13 May 2010 */
415 
416 /* 15 Jun 1999: redo PLUTO_new_interface */
417 
418 #define PLUTO_new_interface(a,b,c,d,e) new_PLUGIN_interface_1999(a,b,c,d,e,__DATE__)
419 
420 extern PLUGIN_interface * new_PLUGIN_interface( char *, char *, char *,
421                                                 int, cptr_func * ) ;
422 
423 extern PLUGIN_interface * new_PLUGIN_interface_1999( char *, char *, char *,
424                                                      int, cptr_func * , char * ) ;
425 
426 void PLUTO_set_runlabels( PLUGIN_interface *, char *, char * ) ; /* 04 Nov 2003 */
427 
428 extern void add_option_to_PLUGIN_interface( PLUGIN_interface *,
429                                             char *, char *, int ) ;
430 
431 extern void add_number_to_PLUGIN_interface( PLUGIN_interface *, char *,
432                                             int, int, int, int, int ) ;
433 
434 extern void add_string_to_PLUGIN_interface( PLUGIN_interface *,
435                                             char *, int, char **, int) ;
436 
437 extern void add_dataset_to_PLUGIN_interface( PLUGIN_interface *,
438                                              char *, int,int,int ) ;
439 
440 extern void add_dataset_list_to_PLUGIN_interface( PLUGIN_interface *,
441                                                   char *, int,int,int ) ;
442 
443 extern void add_timeseries_to_PLUGIN_interface( PLUGIN_interface *, char * ) ;
444 extern void add_tcsv_to_PLUGIN_interface      ( PLUGIN_interface *, char * ) ;
445 
446 extern void add_overlaycolor_to_PLUGIN_interface( PLUGIN_interface *, char * );
447 
448 extern void PLUTO_set_initcolorindex(int) ; /* 10 Oct 2007 */
449 
450 extern void PLUG_fillin_values( PLUGIN_interface * plint ) ;
451 extern void PLUG_freeup_values( PLUGIN_interface * plint ) ;
452 
453 extern char * PLUTO_commandstring( PLUGIN_interface * plint ) ;
454 
455 #define PLUTO_get_label        get_label_from_PLUGIN_interface
456 #define PLUTO_get_descripton   get_description_from_PLUGIN_interface
457 #define PLUTO_get_optiontag    get_optiontag_from_PLUGIN_interface
458 #define PLUTO_get_callvalue    get_callvalue_from_PLUGIN_interface
459 #define PLUTO_get_number       get_number_from_PLUGIN_interface
460 #define PLUTO_get_string       get_string_from_PLUGIN_interface
461 #define PLUTO_get_idcode       get_idcode_from_PLUGIN_interface
462 #define PLUTO_get_timeseries   get_timeseries_from_PLUGIN_interface
463 #define PLUTO_get_tcsv         get_tcsv_from_PLUGIN_interface
464 #define PLUTO_peek_callvalue   peek_callvalue_type_from_PLUGIN_interface
465 #define PLUTO_peek_optiontag   peek_optiontag_from_PLUGIN_interface
466 #define PLUTO_get_idclist      get_idclist_from_PLUGIN_interface
467 #define PLUTO_get_overlaycolor get_overlaycolor_from_PLUGIN_interface
468 
469 #define PLUTO_idclist_count(ll) ( ((ll) != NULL) ? (ll)->nchosen : 0 )
470 #define PLUTO_idclist_reset(ll) ((ll)->current = 0)
471 #define PLUTO_idclist_next(ll)  (((ll)->current < (ll)->nchosen)     \
472                                  ? ((ll)->idclist+((ll)->current)++) : NULL)
473 
474 extern char * get_label_from_PLUGIN_interface       ( PLUGIN_interface * ) ;
475 extern char * get_description_from_PLUGIN_interface ( PLUGIN_interface * ) ;
476 extern char * get_optiontag_from_PLUGIN_interface   ( PLUGIN_interface * ) ;
477 extern void * get_callvalue_from_PLUGIN_interface   ( PLUGIN_interface * , int ) ;
478 extern float  get_number_from_PLUGIN_interface      ( PLUGIN_interface * ) ;
479 extern char * get_string_from_PLUGIN_interface      ( PLUGIN_interface * ) ;
480 extern int    get_overlaycolor_from_PLUGIN_interface( PLUGIN_interface * ) ;
481 
482 extern MCW_idcode * get_idcode_from_PLUGIN_interface( PLUGIN_interface * ) ;
483 extern MRI_IMAGE *  get_timeseries_from_PLUGIN_interface( PLUGIN_interface * ) ;
484 extern NI_element * get_tcsv_from_PLUGIN_interface( PLUGIN_interface * ) ;
485 extern MCW_idclist * get_idclist_from_PLUGIN_interface( PLUGIN_interface * ) ;
486 
487 extern int    peek_callvalue_type_from_PLUGIN_interface( PLUGIN_interface * ) ;
488 extern char * peek_optiontag_from_PLUGIN_interface     ( PLUGIN_interface * ) ;
489 
490 #define NEXT_PLUGIN_OPTION(pl) (void)get_optiontag_from_PLUGIN_interface((pl))
491 #define NEXT_OPTION            NEXT_PLUGIN_OPTION
492 #define PLUTO_next_option      NEXT_PLUGIN_OPTION
493 
494 #define BAD_NUMBER        (-31416.666)
495 #define PLUTO_BAD_NUMBER  BAD_NUMBER
496 
497 /**************************************************************************/
498 /***** Define data structures to hold control information for plugins *****/
499 
500 #define AFNI_PLUGIN_TYPE        9754
501 #define ISVALID_AFNI_PLUGIN(pl) ((pl)!=NULL && (pl)->type==AFNI_PLUGIN_TYPE)
502 
503 #define MAX_PLUGIN_NAME 128
504 
505 /*** one plugin ***/
506 
507 typedef struct {
508    int type ;     /* identifier */
509 
510    char           libname[MAX_PLUGIN_NAME] ;
511    DYNAMIC_handle libhandle ;
512    vptr_func    * libinit_func ;
513 
514    int                 interface_count ;
515    PLUGIN_interface ** interface ;
516 
517    char seqcode[PLUGIN_STRING_SIZE] ;  /* 06 Aug 1999 */
518 } AFNI_plugin ;
519 
520 /*** dynamic array of many plugins ***/
521 
522 typedef struct AFNI_plugin_array {
523    int num , nall ;
524    AFNI_plugin ** plar ;
525 } AFNI_plugin_array ;
526 
527 /*** macros to create, add to, destroy, and free an array of plugins ***/
528 
529 #define INC_PLUGIN_ARRAY 8
530 
531 /** "name" is a variable of type (AFNI_plugin_array *) **/
532 
533 #define INIT_PLUGIN_ARRAY(name)                                                     \
534    do{ int iq ;                                                                     \
535        (name)       = (AFNI_plugin_array *) malloc(sizeof(AFNI_plugin_array)) ;     \
536        memset((name), 0, sizeof(AFNI_plugin_array)) ;                               \
537        (name)->num  = 0 ;                                                           \
538        (name)->nall = INC_PLUGIN_ARRAY ;                                            \
539        (name)->plar = (AFNI_plugin **)malloc(sizeof(AFNI_plugin*)*(name)->nall) ;   \
540        for( iq=(name)->num ; iq < (name)->nall ; iq++ ) (name)->plar[iq] = NULL ;   \
541      } while(0)
542 
543 /** "plug" is a variable of type (AFNI_plugin *) **/
544 
545 #define ADDTO_PLUGIN_ARRAY(name,plug)                                                 \
546    do{ int nn , iq ;                                                                  \
547        if( (name)->num == (name)->nall ){                                             \
548           nn = (name)->nall = 1.1*(name)->nall + INC_PLUGIN_ARRAY ;                   \
549           (name)->plar      = (AFNI_plugin **)                                        \
550                                realloc( (name)->plar,sizeof(AFNI_plugin *)*nn ) ;     \
551           for( iq=(name)->num ; iq < (name)->nall ; iq++ ) (name)->plar[iq] = NULL ;} \
552        nn = (name)->num ; ((name)->num)++ ;                                           \
553        (name)->plar[nn] = (plug) ;                                                    \
554      } while(0)
555 
556 /** this frees all the memory associated with this array **/
557 
558 #define DESTROY_PLUGIN_ARRAY(name)                                      \
559    do{ int nn ;                                                         \
560        if( (name) != NULL ){                                            \
561           for( nn=0 ; nn < (name)->num ; nn++ )                         \
562              if( (name)->plar[nn] != NULL ) free( (name)->plar[nn] ) ;  \
563           free( (name)->plar ) ; free((name)) ; (name) = NULL ;         \
564        } } while(0)
565 
566 /** this just frees the control data associated
567     with this array -- the actual plugins are not freed. **/
568 
569 #define FREE_PLUGIN_ARRAY(name)                                         \
570    do{ int nn ;                                                         \
571        if( (name) != NULL ){                                            \
572           free( (name)->plar ) ; free((name)) ; (name) = NULL ;         \
573        } } while(0)
574 
575 /*********************************************************************************/
576 
577 /***** Other prototypes *****/
578 
579 extern AFNI_plugin_array * PLUG_get_all_plugins( char * dname ) ;
580 extern AFNI_plugin *       PLUG_read_plugin( char * fname ) ;
581 extern AFNI_plugin_array * PLUG_get_many_plugins(char *) ;
582 
583 extern void PLUG_setup_widgets( PLUGIN_interface *, MCW_DC * ) ;
584 
585 extern void PLUG_action_CB           ( Widget , XtPointer , XtPointer ) ;
586 extern void PLUG_delete_window_CB    ( Widget , XtPointer , XtPointer ) ;
587 extern void PLUG_optional_toggle_CB  ( Widget , XtPointer , XtPointer ) ;
588 extern void PLUG_choose_dataset_CB   ( Widget , XtPointer , XtPointer ) ;
589 extern void PLUG_startup_plugin_CB   ( Widget , XtPointer , XtPointer ) ;
590 extern void PLUG_choose_timeseries_CB( Widget , XtPointer , XtPointer ) ;
591 extern void PLUG_choose_tcsv_CB      ( Widget , XtPointer , XtPointer ) ;
592 
593 extern void PLUTO_turnoff_options( PLUGIN_interface * ) ; /* 21 Feb 2001 */
594 
595 extern void PLUG_finalize_dataset_CB   (Widget, XtPointer, MCW_choose_cbs *);
596 extern void PLUG_finalize_timeseries_CB(Widget, XtPointer, MCW_choose_cbs *);
597 extern void PLUG_finalize_tcsv_CB      (Widget, XtPointer, MCW_choose_cbs *);
598 
599 extern void PLUTO_popup_dset_chooser( Widget, int, int,
600                                       int_func *, void_func *, void * ) ;
601 
602 extern void PLUG_finalize_user_dset_CB( Widget, XtPointer, MCW_choose_cbs * ) ;
603 
604 extern void AFNI_plugin_button( Three_D_View * ) ;
605 
606 #define DSET_ACTION_NONE           0
607 #define DSET_ACTION_MAKE_CURRENT   1
608 
609 extern int PLUTO_add_dset( PLUGIN_interface *, THD_3dim_dataset *, int ) ;
610 
611 extern THD_3dim_dataset * PLUTO_copy_dset( THD_3dim_dataset *, char * ) ;
612 
613 extern void PLUTO_dset_redisplay_mode( THD_3dim_dataset * , int ) ;
614 extern void PLUTO_dset_redisplay( THD_3dim_dataset * ) ;
615 
616 extern int PLUTO_prefix_ok( char * ) ;
617 extern int PLUTO_string_index( char * , int , char ** ) ;
618 
619 #define PLUTO_popup_message(pl,ch)   \
620    PLUTO_popup_worker((pl),(ch),MCW_USER_KILL)
621 
622 #define PLUTO_popup_transient(pl,ch) \
623    PLUTO_popup_worker((pl),(ch),MCW_USER_KILL|MCW_TIMER_KILL);
624 
625 #define PLUTO_popup_textwin(pl,ch)   \
626    PLUTO_popup_worker((pl),(ch),-1)
627 
628 extern void PLUTO_fixup_names(void) ;
629 extern void PLUTO_popup_worker( PLUGIN_interface * , char * , int ) ;
630 extern void PLUTO_beep(void) ;
631 
632 extern void PLUTO_popup_meter( PLUGIN_interface * ) ;
633 extern void PLUTO_popdown_meter( PLUGIN_interface * ) ;
634 extern void PLUTO_set_meter( PLUGIN_interface * , int ) ;
635 
636 extern void PLUTO_set_topshell( PLUGIN_interface *, Widget ) ; /* 22 Sep 2000 */
637 
638 /*------------------------------------------------------------------------*/
639 
640 typedef struct {
641    MCW_imseq * seq ;
642    MRI_IMAGE * im ;
643 } PLUGIN_impopper ;
644 
645 extern void *    PLUTO_popup_image( void * , MRI_IMAGE * ) ;
646 extern XtPointer PLUGIN_imseq_getim( int , int , XtPointer ) ;
647 extern void      PLUGIN_seq_send_CB( MCW_imseq * , XtPointer , ISQ_cbs * ) ;
648 
649 #define PLUTO_popdown_image(hh) (void)PLUTO_popup_image((hh),NULL)
650 
651 #define PLUTO_popup_open(hh) \
652    ( (hh) != NULL && ISQ_REALZ(((PLUGIN_impopper *)(hh))->seq) )
653 
654 #define PLUTO_popkill_image(hh) \
655    ( PLUTO_popdown_image(hh) , XtFree((char *)(hh)) , (hh)=NULL )
656 
657 /*------------------------------------------------------------------------*/
658 
659 typedef struct {
660    MCW_imseq * seq ;
661    MRI_IMARR * imar ;
662    int rgb_count ;
663    generic_func * kill_func ;
664    void * kill_data ;
665 } PLUGIN_imseq ;
666 
667 extern void * PLUTO_imseq_popup( MRI_IMARR *, generic_func *, void * ) ;
668 extern void * PLUTO_imseq_popim( MRI_IMAGE *, generic_func *, void * ) ;
669 
670 extern void   PLUTO_imseq_addto( void * , MRI_IMAGE * ) ;
671 extern void   PLUTO_imseq_destroy( void * ) ;
672 extern void   PLUTO_imseq_retitle( void * , char * ) ;
673 extern void   PLUTO_imseq_rekill( void *, generic_func *, void * ) ;
674 extern void   PLUTO_imseq_setim( void * , int ) ;  /* 17 Dec 2004 */
675 
676 extern XtPointer PLUTO_imseq_getim( int , int , XtPointer ) ;
677 extern void PLUTO_imseq_send_CB( MCW_imseq * , XtPointer , ISQ_cbs * ) ;
678 
679 /*------------------------------------------------------------------------*/
680 
681 extern THD_3dim_dataset * PLUTO_4D_to_typed_fim( THD_3dim_dataset * old_dset ,
682                                                  char * new_prefix , int new_datum ,
683                                                  int ignore , int detrend ,
684                                                  generic_func * user_func ,
685                                                  void * user_data ) ;
686 
687 #define PLUTO_4D_to_fim(ds,np,ig,dtr,uf,ud) \
688   PLUTO_4D_to_typed_fim( (ds),(np), MRI_short , (ig),(dtr),(uf),(ud) )
689 
690 /* BDW, 24 Feb 1997 */
691 extern THD_3dim_dataset * PLUTO_4D_to_typed_fith( THD_3dim_dataset * old_dset ,
692 						  char * new_prefix , int new_datum ,
693 						  int ignore , int detrend ,
694 						  generic_func * user_func ,
695 						  void * user_data ) ;
696 
697 #define PLUTO_4D_to_fith(ds,np,ig,dtr,uf,ud) \
698   PLUTO_4D_to_typed_fith( (ds),(np), MRI_short , (ig),(dtr),(uf),(ud) )
699 
700 /* RWC, 13 Dec 1997 */
701 
702 extern THD_3dim_dataset * PLUTO_4D_to_typed_fbuc( THD_3dim_dataset * old_dset ,
703                                                   char * new_prefix , int new_datum ,
704                                                   int ignore , int detrend ,
705                                                   int nbrik ,
706                                                   generic_func * user_func ,
707                                                   void * user_data ) ;
708 
709 extern void PLUTO_report( PLUGIN_interface * , char * ) ;
710 
711 #define PLUTO_output_header(ds) THD_write_3dim_dataset(NULL,NULL,(ds),False)
712 
713 extern PLUGIN_strval * new_PLUGIN_strval( Widget , char * ) ;
714 extern void destroy_PLUGIN_strval( PLUGIN_strval * ) ;
715 extern void alter_PLUGIN_strval_width( PLUGIN_strval * , int ) ;
716 extern void set_PLUGIN_strval( PLUGIN_strval * , char * ) ;
717 extern char * get_PLUGIN_strval( PLUGIN_strval * ) ;
718 
719 /* for vol2surf plugin                                09 Sep 2004 [rickr] */
720 extern int PLUTO_set_v2s_addrs(void ** vopt, char *** maps, char ** hist);
721 
722 
723 #endif /* ALLOW_PLUGINS */
724 
725 /*--------------------------------------------------------------------
726   Stuff that is always defined
727 ----------------------------------------------------------------------*/
728 
729 #define PLUTO_extract_series(ijk,ds)     THD_extract_series((ijk),(ds),0)
730 #define PLUTO_extract_series_raw(ijk,ds) THD_extract_series((ijk),(ds),1)
731 
732 #define PLUTO_register_0D_function  AFNI_register_0D_function
733 #define PLUTO_register_1D_function  AFNI_register_1D_function
734 #define PLUTO_register_2D_function  AFNI_register_2D_function
735 
736 #define PLUTO_register_1D_funcstr   AFNI_register_1D_funcstr
737 
738 #define PLUTO_cursorize(w)  NORMAL_cursorize(w)
739 
740 extern void PLUTO_register_timeseries( char * , MRI_IMAGE * ) ;
741 #if 0
742 extern void PLUTO_register_tcsv      ( char * , NI_element * ) ;
743 #endif
744 
745 extern THD_3dim_dataset * PLUTO_find_dset( MCW_idcode * ) ;
746 extern THD_3dim_dataset * PLUTO_find_dset_idc( char * ) ;
747 extern THD_slist_find     PLUTO_dset_finder( char * ) ;
748 
749 extern void PLUTO_histoplot( int, float, float, int *,
750                              char *, char *, char * , int,int ** ) ;
751 extern void PLUTO_histoplot_f( int, float, float, float *,
752                              char *, char *, char * , int,float ** ) ;
753 
754 extern void PLUTO_scatterplot( int , float *, float *,
755                                char *, char *, char * , float,float ) ;
756 extern void PLUTO_scatterplot_NEW( int , float *, float *,
757                                    char *, char *, char * ,
758                                    int , float *, float *, float_triple * ) ;
759 
760 extern void PLUTO_set_xypush( int a, int b ) ;
761 
762 extern void PLUTO_force_redisplay( void ) ;
763 extern void PLUTO_force_rebar( void ) ;
764 extern void PLUTO_force_opacity_change( void ) ; /* 06 Jun 2019 */
765 
766 extern void PLUTO_register_workproc( XtWorkProc , XtPointer ) ;
767 extern void PLUTO_remove_workproc  ( XtWorkProc ) ;
768 extern RwcBoolean PLUG_workprocess( XtPointer ) ;
769 extern void PLUTO_register_timeout( int, generic_func *, XtPointer ) ;
770 extern double PLUTO_cpu_time(void) ;
771 extern double PLUTO_elapsed_time(void) ;
772 
773 #ifdef __cplusplus
774 }
775 #endif
776 
777 #endif /* _AFNI_PLUGIN_HEADER_ */
778