Doxygen Source Code Documentation
afni_environ.c File Reference
#include "mrilib.h"Go to the source code of this file.
Defines | |
| #define | ISTARRED(s) ( (s)[0]=='*' && (s)[1]=='*' && (s)[2]=='*' ) |
| #define | EOLSKIP |
| #define | GETSSS |
| #define | GETSTR |
| #define | GETEQN |
| #define | NSBUF 256 |
Functions | |
| char * | AFNI_suck_file (char *fname) |
| void | AFNI_mark_environ_done (void) |
| char * | my_getenv (char *ename) |
| void | AFNI_process_environ (char *fname) |
| int | AFNI_yesenv (char *ename) |
| int | AFNI_noenv (char *ename) |
| double | AFNI_numenv (char *ename) |
| int | AFNI_setenv (char *cmd) |
Variables | |
| int | afni_env_done = 0 |
Define Documentation
|
|
Value: do{ for( ; fptr[0] != '\n' && fptr[0] != '\0' ; fptr++ ) ; \ if( fptr[0] == '\0' ) goto done ; \ fptr++ ; } while(0) Definition at line 44 of file afni_environ.c. |
|
|
Value: do{ GETSTR ; if(ISTARRED(str)) goto SkipSection ; \ strcpy(left,str) ; \ GETSTR ; if(ISTARRED(str)) goto SkipSection ; \ strcpy(middle,str) ; \ GETSTR ; if(ISTARRED(str)) goto SkipSection ; \ strcpy(right,str) ; } while(0) Definition at line 62 of file afni_environ.c. Referenced by AFNI_process_environ(). |
|
|
Value: do{ int nu=0,qq; \ if( fptr-fbuf >= nbuf || fptr[0] == '\0' ) goto done ; \ str[0]='\0'; qq=sscanf(fptr,"%127s%n",str,&nu); nused+=nu;fptr+=nu; \ if( str[0]=='\0' || qq==0 || nu==0 ) goto done ; \ } while(0) Definition at line 49 of file afni_environ.c. |
|
|
Value: do{ GETSSS ; \ while(str[0]=='!' || (str[0]=='/' && str[1]=='/') || \ (str[0]=='#' && str[1]=='\0') ){EOLSKIP; GETSSS;} \ } while(0) Definition at line 56 of file afni_environ.c. Referenced by AFNI_process_environ(). |
|
|
Definition at line 42 of file afni_environ.c. Referenced by AFNI_process_environ(), AFNI_process_setup(), AFNI_startup_layout_CB(), RCREND_read_states(), and REND_read_states(). |
|
|
Definition at line 70 of file afni_environ.c. Referenced by AFNI_process_environ(). |
Function Documentation
|
|
Definition at line 74 of file afni_environ.c. References afni_env_done. Referenced by main().
00074 { afni_env_done = 1 ; return ; }
|
|
|
|
Definition at line 174 of file afni_environ.c. References my_getenv(), and strtod(). Referenced by AFNI_bucket_label_CB(), AFNI_init_niml(), GRA_handle_keypress(), ISQ_drawing_EV(), ISQ_handle_keypress(), ISQ_process_mri(), main(), PLUTO_scatterplot(), refit_MCW_optmenu(), and THD_get_all_timeseries().
00175 {
00176 char *ept,*ccc ; double val ;
00177 if( ename == NULL ) return 0.0l ;
00178 ept = my_getenv(ename) ;
00179 if( ept == NULL ) return 0.0l ;
00180 val = strtod(ept,&ccc) ;
00181 if( *ccc == 'k' || *ccc == 'K' ) val *= 1024.0l ;
00182 else if( *ccc == 'm' || *ccc == 'M' ) val *= 1024.0l*1024.0l ;
00183 else if( *ccc == 'g' || *ccc == 'G' ) val *= 1024.0l*1024.0l*1024.0l ;
00184 return val ;
00185 }
|
|
|
Definition at line 86 of file afni_environ.c. References afni_env_done, AFNI_suck_file(), ENTRY, free, getenv(), GETEQN, GETSTR, ISTARRED, left, malloc, nr, NSBUF, right, and THD_filename_pure(). Referenced by main(), my_getenv(), and SUMA_process_environ().
00087 {
00088 int nbuf , nused , ii ;
00089 char *fbuf , *fptr ;
00090 char str[NSBUF] , left[NSBUF] , middle[NSBUF] , right[NSBUF] ;
00091
00092 ENTRY("AFNI_process_environ") ;
00093 if( fname != NULL ){
00094 strcpy(str,fname) ;
00095 } else {
00096 char *home ;
00097 if( afni_env_done ) EXRETURN ;
00098 home = getenv("HOME") ;
00099 if( home != NULL ){ strcpy(str,home) ; strcat(str,"/.afnirc") ; }
00100 else { strcpy(str,".afnirc") ; }
00101 afni_env_done = 1 ;
00102 }
00103
00104 fbuf = AFNI_suck_file( str ) ; if( fbuf == NULL ) EXRETURN ;
00105 nbuf = strlen(fbuf) ; if( nbuf == 0 ) EXRETURN ;
00106
00107 fptr = fbuf ; nused = 0 ;
00108
00109 /** scan for section strings, which start with "***" **/
00110
00111 str[0] = '\0' ; /* initialize string */
00112
00113 while( nused < nbuf ){
00114
00115 /**----------------------------------------**/
00116 /**-- skip ahead to next section keyword --**/
00117
00118 SkipSection: while( ! ISTARRED(str) ){ GETSTR; }
00119
00120 /*- 04 Jun 1999 -*/
00121
00122 if( strcmp(str,"***END") == 0 ) break ; /* exit main loop */
00123
00124 if( strcmp(str,"***ENVIRONMENT") != 0 ){ GETSTR ; goto SkipSection ; }
00125
00126 /**---------------------------------------**/
00127 /**-- ENVIRONMENT section [04 Jun 1999] --**/
00128
00129 if( strcmp(str,"***ENVIRONMENT") == 0 ){ /* loop, looking for environment settings */
00130 char *enveqn ; int nl , nr ;
00131
00132 while(1){ /* loop, looking for 'name = value' */
00133 GETEQN ;
00134
00135 if( !THD_filename_pure(left) ) continue ;
00136
00137 nl = strlen(left) ; nr = strlen(right) ;
00138 enveqn = (char *) malloc(nl+nr+4) ;
00139 strcpy(enveqn,left) ; strcat(enveqn,"=") ; strcat(enveqn,right) ;
00140 putenv(enveqn) ;
00141 }
00142
00143 continue ; /* to end of outer while */
00144 } /* end of ENVIRONMENT */
00145
00146 } /* end of while loop */
00147
00148 done:
00149 free(fbuf) ; EXRETURN ;
00150 }
|
|
|
Input is "name value". Return is 0 if OK, -1 if not OK. Definition at line 190 of file afni_environ.c. Referenced by AFNI_parse_args(), and main().
00191 {
00192 char nam[256]="\0" , val[1024]="\0" , eqn[1280] , *eee ;
00193
00194 if( cmd == NULL || strlen(cmd) < 3 ) return(-1) ;
00195
00196 sscanf( cmd , "%255s %1023s" , nam , val ) ;
00197 if( nam[0] == '\0' || val[0] == '\0' && strchr(cmd,'=') != NULL ){
00198 char *ccc = strdup(cmd) ;
00199 eee = strchr(ccc,'=') ; *eee = ' ' ;
00200 sscanf( ccc , "%255s %1023s" , nam , val ) ;
00201 free((void *)ccc) ;
00202 }
00203 if( nam[0] == '\0' || val[0] == '\0' ) return(-1) ;
00204
00205 sprintf(eqn,"%s=%s",nam,val) ;
00206 eee = strdup(eqn) ; putenv(eee) ;
00207 return(0) ;
00208 }
|
|
|
Definition at line 15 of file afni_environ.c. References close(), fd, free, malloc, read(), and THD_filesize(). Referenced by AFNI_finalize_read_palette_CB(), AFNI_process_environ(), AFNI_process_setup(), AFNI_startup_layout_CB(), AFNI_startup_script_CB(), DRAW_finalize_dset_CB(), DRAW_label_getfile(), main(), RCREND_read_states(), REND_read_states(), and SUMA_AFNI_Extract_Colors().
00016 {
00017 int len , fd , ii ;
00018 char *buf ;
00019
00020 if( fname == NULL || fname[0] == '\0' ) return NULL ;
00021
00022 len = THD_filesize( fname ) ;
00023 if( len <= 0 ) return NULL ;
00024
00025 fd = open( fname , O_RDONLY ) ;
00026 if( fd < 0 ) return NULL ;
00027
00028 buf = (char *) malloc( sizeof(char) * (len+4) ) ;
00029 ii = read( fd , buf , len ) ;
00030 close( fd ) ;
00031 if( ii <= 0 ){ free(buf) ; return NULL; }
00032
00033 buf[len] = '\0' ; /* 27 July 1998: 'len' used to be 'ii+1', which is bad */
00034 return buf ;
00035 }
|
|
|
Variable Documentation
|
|
Definition at line 72 of file afni_environ.c. Referenced by AFNI_mark_environ_done(), AFNI_process_environ(), and my_getenv(). |