Description: Configure Debian-specific installation paths
  This allows for splitting libraries, plugins and pure data into /usr/lib
  and /usr/share, instead of having to dump everything into a single directory.
Author: Michael Hanke <michael.hanke@gmail.com>
Last-Update: 2010-09-29
--- a/afni_func.c
+++ b/afni_func.c
@@ -5783,7 +5783,7 @@ ENTRY("AFNI_tips_CB") ;
      XMapRaised( XtDisplay(tips_hw->wshell) , XtWindow(tips_hw->wshell) ) ;
      EXRETURN ;
    } else if( !AFNI_noenv("AFNI_DONT_USE_HTMLWIN") ){
-     fpt = THD_find_regular_file("afnigui.html", NULL) ;
+     fpt = THD_find_regular_file("afnigui.html", "/usr/share/afni/html") ;
      if( fpt != NULL && *fpt != '\0' ){
        inf = (char *)malloc(sizeof(char)*(strlen(fpt)+16)) ;
        strcpy(inf,"file:") ; strcat(inf,fpt) ; free(fpt) ;
@@ -6641,6 +6641,8 @@ ENTRY("AFNI_find_poem_files") ;
    /*----- get path to search -----*/
 
                        epath = getenv("AFNI_PLUGINPATH") ;
+   /* Debian puts them into a separate dir */
+   epath = "/usr/share/afni/poems";
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath == NULL ) epath = getenv("PATH") ;
    if( epath == NULL ){ num_poem=-1; EXRETURN ; }
--- a/afni_splash.c
+++ b/afni_splash.c
@@ -666,6 +666,8 @@ ENTRY("AFNI_find_jpegs") ;
    /*----- get path to search -----*/
 
                        epath = getenv("AFNI_PLUGINPATH") ;
+   /* Debian puts them into a separate dir */
+   epath = "/usr/share/afni/pics";
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath == NULL ) epath = getenv("PATH") ;
    if( epath == NULL ) epath = getenv("HOME") ;
--- a/thd_ttatlas_query.c
+++ b/thd_ttatlas_query.c
@@ -596,6 +596,8 @@ char * get_atlas_dirname(void)  /* 31 Ja
    if( !first ) return adnam ;
    first = 0 ;
                        epath = getenv("AFNI_PLUGINPATH") ;
+   /* Debian puts them into a separate dir */
+   epath = "/usr/share/afni/atlases";
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath == NULL ) epath = getenv("PATH") ;
    if( epath == NULL ) return NULL ;  /* this is bad */
@@ -680,6 +682,8 @@ THD_3dim_dataset * get_atlas(char *epath
       /*----- get path to search -----*/
 
                           epath = getenv("AFNI_PLUGINPATH") ;
+      /* Debian puts them into a separate dir */
+      epath = "/usr/share/afni/atlases";
       if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
       if( epath == NULL ) epath = getenv("PATH") ;
       if( epath == NULL ) RETURN(dset) ;
@@ -2131,8 +2135,11 @@ char *find_atlas_niml_file(char * nimlna
    }
      
    /* okay that didn't work, try the AFNI plugin directory */
-   namebuf[0]='\0';
-                       epath = getenv("AFNI_PLUGINPATH") ;
+   /* In Debian distribution most logical location is actually
+      atlas path, so let's use that one instead of PLUGINPATH
+      if it was defined and only use plugins path if not */
+   namebuf[0]='\0';    epath = getenv("AFNI_TTATLAS_DATASET");
+   if( epath == NULL ) epath = getenv("AFNI_PLUGINPATH") ;
    if( epath == NULL ) epath = getenv("AFNI_PLUGIN_PATH") ;
    if( epath != NULL ) {
       if(wami_verb() > 1) 
--- a/afni.c
+++ b/afni.c
@@ -4922,12 +4922,31 @@ ENTRY("AFNI_read_inputs") ;
       /*-- 20 Dec 2001: Try to read a "global" session --*/
       /*-- 11 May 2002: Move read global session up here --*/
 
+      char debian_atlases[30] = "/usr/share/afni/atlases";
       eee = getenv( "AFNI_GLOBAL_SESSION" ) ;   /* where it's supposed to be */
+      /* Debian: if there is now global session, use the atlases */
+      if( eee == NULL ){
+         eee = debian_atlases ;
+         REPORT_PROGRESS("ONLY ATLASES");
+      }
       if( eee != NULL ){
          THD_3dim_dataset *dset ;
          STATUS("reading global session") ;
          gss =
           GLOBAL_library.session = THD_init_session( eee ); /* try to read datasets */
+         /* Debian: always add the global atlas dir, if not the only global
+          * session */
+         if( gss != NULL ){
+             /* do not add twice */
+             if ( eee != debian_atlases ){
+                 REPORT_PROGRESS("PLUS ATLASES");
+                 AFNI_append_sessions(gss, THD_init_session( debian_atlases));
+             }
+         } else {
+            /* try reading the atlases (again) in case failure on custom
+             * session dir caused nothing to be loaded */
+            gss = GLOBAL_library.session = THD_init_session( debian_atlases );
+         }
 
          if( gss != NULL ){                               /* got at least one */
             gss->parent = NULL ;                          /* parentize them */
