char * GetAfniWebDownloader(void) { static char *ate=NULL; ate = getenv("AFNI_WEB_DOWNLOADER"); if( ate ) return ate; /* else, hunt */ if( ate == NULL ) if (THD_find_executable( "curl" )) ate = "curl -O -f" ; if( ate == NULL ) ate = THD_find_executable( "wget" ) ; return(ate); }
char * GetAfniImageViewer(void) { static char *ate=NULL; ate = getenv("AFNI_IMAGE_VIEWER"); if( ate ) return ate; /* else, hunt */ if( ate == NULL ) ate = THD_find_executable( "Preview" ) ; if( ate == NULL ) ate = THD_find_executable( "aiv" ) ; return(ate); }
char * GetAfniWebBrowser(void) { static char *awb=NULL; awb = getenv("AFNI_WEB_BROWSER") ; #ifdef DARWIN if( awb == NULL ) awb = "open" ; /* for Mac OS X */ #endif if( awb == NULL ) awb = THD_find_executable( "chrome" ) ; if( awb == NULL ) awb = THD_find_executable( "firefox" ) ; if( awb == NULL ) awb = THD_find_executable( "mozilla" ) ; if( awb == NULL ) awb = THD_find_executable( "netscape" ) ; if( awb == NULL ) awb = THD_find_executable( "opera" ) ; return(awb); }
char * GetAfniTextEditor(void) { char *ate=NULL; ate = getenv("AFNI_GUI_EDITOR"); if( ate == NULL ) ate = THD_find_executable( "nedit" ) ; if( ate == NULL ) ate = THD_find_executable( "kedit" ) ; if( ate == NULL ) ate = THD_find_executable( "gedit" ) ; if( ate == NULL ) ate = THD_find_executable( "kwrite" ) ; #ifdef DARWIN if( ate == NULL ) ate = "open -t" ; /* for Mac OS X */ #endif return(ate); }
char * GetAfniPDFViewer(void) { static char *ate=NULL; ate = getenv("AFNI_PDF_VIEWER"); if( ate ) return ate; /* else, hunt */ if( ate == NULL ) ate = THD_find_executable( "Preview" ) ; if( ate == NULL ) ate = THD_find_executable( "evince" ) ; if( ate == NULL ) ate = THD_find_executable( "acroread" ) ; if( ate == NULL ) ate = GetAfniWebBrowser() ; /* last resort? */ return(ate); }
int mri_write_png( char *fname , MRI_IMAGE *im ) /* 11 Dec 2006 */ { char *pg , *pgfilt ; FILE *fp ; if( fname == NULL || *fname == '\0' || im == NULL ) return 0 ; if( im->kind != MRI_rgb && im->kind != MRI_byte ) return 0 ; if( STRING_HAS_SUFFIX_CASE(fname,".jpg") ){ /* 07 Dec 2007 */ RETURN( mri_write_jpg(fname,im) ) ; } pg = THD_find_executable( "pnmtopng" ) ; if( pg == NULL ) return 0 ; pgfilt = (char *)malloc( sizeof(char)*(strlen(pg)+strlen(fname)+32) ) ; sprintf( pgfilt , "%s -compression 9 > %s" , pg , fname ) ; #ifndef CYGWIN signal( SIGPIPE , SIG_IGN ) ; #endif fp = popen( pgfilt , "w" ) ; if( fp == NULL ){ free((void *)pgfilt); return 0; } if( im->kind == MRI_rgb ){ fprintf(fp,"P6\n%d %d\n255\n" , im->nx,im->ny ) ; fwrite( MRI_RGB_PTR(im), sizeof(byte), 3*im->nvox, fp ) ; } else if( im->kind == MRI_byte ){ fprintf(fp,"P5\n%d %d\n255\n" , im->nx,im->ny ) ; fwrite( MRI_BYTE_PTR(im), sizeof(byte), im->nvox, fp ) ; } (void) pclose(fp) ; free((void *)pgfilt) ; return 1 ; }
/*! Find afni's bin directory if it exists. If not, NULL is returned. If it exists, a pointer to the path is returned. Do free it with free() ------------------------------------------------------------------------------*/ char * THD_abindir (byte withslash) { char *afr = NULL, *af=NULL; int nn = 0, N_afni=strlen("afni"); THD_string_array *elist=NULL; if (!(elist = get_elist()) || !(af = THD_find_executable("afni"))) { ERROR_message("Could not find afni, we're doomed daddy!"); RETURN(NULL); } /* remove afni from the end to get the path */ nn = strlen(af); if (strcmp(af+nn-N_afni,"afni")) { ERROR_message("This should not be (%s)!", af+nn-N_afni); RETURN(NULL); } afr = strdup(af); afr[strlen(af)-N_afni]='\0'; /* remove slash */ while ( (nn=strlen(afr)-1) && afr[nn] == '/') afr[nn] = '\0'; if (withslash) { nn=strlen(afr); afr[nn] = '/'; afr[nn+1]='\0'; } return(afr); }
void view_prog_help(char *prog) { char *viewer=NULL, *hname=NULL; char *progname=NULL; if (!prog) return; if (!(progname = THD_find_executable(prog))) { ERROR_message("Could not find executable %s.\n", prog); return; } if (!(viewer = GetAfniTextEditor())) { ERROR_message("No GUI editor defined, and guessing game failed.\n" "Set AFNI_GUI_EDITOR in your .afnirc for this option to work.\n"); return; } hname = get_updated_help_file(0, 0, progname, -1); if (hname[0]=='\0') { /* failed, no help file ... */ ERROR_message("No help file for %s\n", progname); return; } if (!(view_text_file(hname))) { ERROR_message("Failed to view %s\n", hname); } return; }
char *web_prog_help_link(char *prog, int style) { char *progname=NULL; static char weblinka[10][1024]={""}, *weblink; static int n; ++n; if (n>9) n = 0; weblink = (char *)weblinka[n]; weblink[0]='\0'; if (!prog) return(weblink); if (!strcmp(prog,"ALL")) { if (style == 0) { snprintf(weblink,1020*sizeof(char), "https://afni.nimh.nih.gov/pub/dist/doc/program_help/%s.html", "all-of-them"); } else { /* Nothing yet, return old */ snprintf(weblink,1020*sizeof(char), "https://afni.nimh.nih.gov/pub/dist/doc/program_help/%s.html", "all-of-them"); } } else { if (!(progname = THD_find_executable(prog))) { ERROR_message("Could not find executable %s.\n", prog); return(weblink); } if (style == 0) { snprintf(weblink,1020*sizeof(char), "https://afni.nimh.nih.gov/pub/dist/doc/program_help/%s.html", THD_trailname(progname,0)); } else { /* Nothing yet, return old */ snprintf(weblink,1020*sizeof(char), "https://afni.nimh.nih.gov/pub/dist/doc/program_help/%s.html", THD_trailname(progname,0)); } } return(weblink); }
int mri_write_jpg( char *fname , MRI_IMAGE *im ) /* 15 Apr 2005 */ { char *pg , *jpfilt, *eee ; FILE *fp ; int jpeg_compress; if( fname == NULL || *fname == '\0' || im == NULL ) return 0 ; if( im->kind != MRI_rgb && im->kind != MRI_byte ) return 0 ; if( STRING_HAS_SUFFIX_CASE(fname,".png") ){ /* 07 Dec 2007 */ RETURN( mri_write_png(fname,im) ) ; } pg = THD_find_executable( "cjpeg" ) ; if( pg == NULL ) return 0 ; /* user environment variable compression quality - mod 5/10/2006 drg */ eee = my_getenv("AFNI_JPEG_COMPRESS"); if(eee!=NULL){ jpeg_compress = strtod(eee, NULL); if((jpeg_compress<=0) || (jpeg_compress>100)) jpeg_compress = 95; } else jpeg_compress = 95; jpfilt = (char *)malloc( sizeof(char)*(strlen(pg)+strlen(fname)+32) ) ; sprintf( jpfilt , "%s -quality %d > %s" , pg , jpeg_compress, fname ) ; #ifndef CYGWIN signal( SIGPIPE , SIG_IGN ) ; #endif fp = popen( jpfilt , "w" ) ; if( fp == NULL ){ free((void *)jpfilt); return 0; } if( im->kind == MRI_rgb ){ fprintf(fp,"P6\n%d %d\n255\n" , im->nx,im->ny ) ; fwrite( MRI_RGB_PTR(im), sizeof(byte), 3*im->nvox, fp ) ; } else if( im->kind == MRI_byte ){ fprintf(fp,"P5\n%d %d\n255\n" , im->nx,im->ny ) ; fwrite( MRI_BYTE_PTR(im), sizeof(byte), im->nvox, fp ) ; } (void) pclose(fp) ; free((void *)jpfilt) ; return 1 ; }
void AFNI_display_hist( Widget w ) { #define NBUF 1024 static char *cmd=NULL ; char buf[NBUF+1] , *all=NULL ; int nbuf , nall=0 ; FILE *fp ; /*-- get the path to the command to run --*/ if( cmd == NULL ){ char *pg = THD_find_executable("afni_history") ; if( pg == NULL || *pg == '\0' ){ (void)MCW_popup_message( w , " \n" " Can't find afni_history \n" " program in your PATH!!! \n" , MCW_USER_KILL | MCW_TIMER_KILL ) ; XtSetSensitive(w,False) ; return ; } cmd = (char *)calloc( sizeof(char) , (64+strlen(pg)) ) ; sprintf(cmd,"%s -reverse",pg) ; } /*-- open a pipe to read from the command --*/ fp = popen( cmd , "r" ); if( fp == NULL ){ (void)MCW_popup_message( w , " \n" " Can't run afni_history\n" " program for some reason!\n" , MCW_USER_KILL | MCW_TIMER_KILL ) ; return ; } /*-- read the first bunch of data fromt the pipe --*/ nbuf = fread( buf , 1 , NBUF , fp ) ; if( nbuf < 16 || *buf == '\0' ){ (void)MCW_popup_message( w , " \n" " afni_history program\n" " fails to give output!\n" , MCW_USER_KILL | MCW_TIMER_KILL ) ; return ; } /*-- store this initial string in 'all' --*/ buf[nbuf] = '\0' ; all = strdup(buf) ; nall = strlen(all) ; /*-- loop: read buffer, copy into 'all', until nothing left to read --*/ do{ nbuf = fread( buf , 1 , NBUF , fp ) ; if( nbuf <= 0 ){ pclose(fp); break; } /* read failed ==> done */ buf[nbuf] = '\0' ; all = realloc( all , nall+nbuf+2 ) ; strcat(all,buf) ; nall = strlen(all) ; } while(1) ; /*-- display results in a window, and exeunt omnes --*/ (void)new_MCW_textwin( w , all , 1 ) ; free(all) ; return ; }
char * AFNI_make_update_script(void) { char *pg_ftp , *pg_afni , *pg_gzip , *pg_tar ; char hbuf[4096], fname[128], adir[4096], *cpt, cwd[4096] ; FILE *fp ; static char sname[4096] ; pg_ftp = THD_find_executable("ftp" ); if( pg_ftp == NULL ) return NULL; pg_afni = THD_find_executable("afni"); if( pg_afni == NULL ) return NULL; pg_gzip = THD_find_executable("gzip"); if( pg_gzip == NULL ) pg_gzip = THD_find_executable("pigz") ; if( pg_gzip == NULL ) return NULL; pg_tar = THD_find_executable("tar" ); if( pg_tar == NULL ) return NULL; strcpy(adir,pg_afni) ; /* extract name of AFNI directory */ cpt = THD_trailname(adir,0) ; *cpt = '\0' ; if( strlen(adir) <= 0 ) return NULL ; /* no AFNI directory? */ strcpy( cwd , adir ) ; /* try to write a test file there */ strcat( cwd , "afni_qadgop" ) ; fp = fopen( cwd , "a" ) ; if( fp == NULL ) return NULL ; /* can't write to AFNI directory? */ fclose(fp) ; remove(cwd) ; getcwd( cwd , 4096 ) ; /* get current directory for later use */ chdir( adir ) ; /* switch to AFNI directory for this work */ /* write a script to get and install the binary archive via FTP */ gethostname( hbuf , 4096 ) ; strcpy( fname , SHSHSH(SHOWOFF) ) ; strcat( fname , ".tgz" ) ; fp = fopen( SNAME , "w" ) ; if( fp == NULL ){ chdir(cwd); return NULL; } fprintf( fp , "#!/bin/sh\n" "echo '++ FTP-ing %s from afni.nimh.nih.gov'\n" "%s -n afni.nimh.nih.gov << EEEEE\n" /* FTP to get file */ "user anonymous AFNI_UPDATER@%s\n" "binary\n" "passive\n" "cd tgz\n" "get %s\n" "bye\n" "EEEEE\n" "echo '++ Unpacking %s'\n" "%s -dc %s | %s xf -\n" /* uncompress and untar .tgz file */ "/bin/rm -f %s\n" /* delete .tgz file */ "echo '++ Moving files'\n" "/bin/mv -f %s/* .\n" /* move untar-ed files up to here */ "/bin/rm -rf %s\n" /* remove any directory leftovers */ "echo '++ Finished'\n" , fname , /* filename to get (for 'FTP-ing' echo) */ pg_ftp , /* FTP program */ hbuf , /* hostname, for FTP password */ fname , /* filename to get (for FTP) */ fname , /* ditto (for 'Unpacking' echo) */ pg_gzip, fname, pg_tar, /* GZIP program, filename, TAR program */ fname , /* filename to delete */ SHSHSH(SHOWOFF) , /* directory to copy up */ SHSHSH(SHOWOFF) /* directory to delete */ ) ; fclose( fp ) ; chmod( SNAME , S_IRUSR | S_IWUSR | S_IXUSR ) ; /* mark as executable */ /* get back to current working directory, then leave */ chdir(cwd) ; sprintf(sname,"%s%s",adir,SNAME) ; return sname ; }