Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

uncomment.c File Reference

#include "mrilib.h"

Go to the source code of this file.


Defines

#define putchar(x)   fputc((x),stdout)
#define NEX   4

Functions

char * suck_file (char *fname)
int main (int argc, char *argv[])

Define Documentation

#define NEX   4
 

#define putchar      fputc((x),stdout)
 

Definition at line 12 of file uncomment.c.

Referenced by estimate_gfw(), main(), PERMTEST_compute(), ps_label(), and show_run_stats().


Function Documentation

int main int    argc,
char *    argv[]
 

Definition at line 42 of file uncomment.c.

References argc, putchar, and suck_file().

00043 {
00044    char * infile ;
00045    int nin , comm , ii , quote ;
00046 
00047    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00048       printf("Usage: uncomment infile.c > outfile.c\n") ;
00049       exit(0) ;
00050    }
00051 
00052    infile = suck_file( argv[1] ) ;
00053    if( infile == NULL || strlen(infile) == 0 ){
00054       fprintf(stderr,"*** Can't read from file %s\n",argv[1]) ;
00055       exit(1) ;
00056    }
00057 
00058    nin   = strlen(infile) ;
00059    comm  = 0 ;
00060    quote = 0 ;
00061    ii    = 0 ;
00062 
00063    while( ii < nin ){
00064 
00065       /* if inside a quote, and see an end quote: */
00066 
00067       if( quote && infile[ii] == '"' && infile[ii-1] != '\\' ){
00068          putchar(infile[ii++]) ; quote = 0 ; continue ;
00069       }
00070 
00071       /* if not inside a quote or comment, and see a start quote: */
00072 
00073       if( !quote && !comm && infile[ii] == '"' && infile[ii-1] != '\\' ){
00074          putchar(infile[ii++]) ; quote = 1 ; continue ;
00075       }
00076 
00077       /* if inside a comment and see an end comment: */
00078 
00079       if( comm && infile[ii] == '*' && infile[ii+1] == '/' ){
00080          ii += 2 ; comm = 0 ; continue ;
00081       }
00082 
00083       /* if not inside a quote or comment, and see a start comment: */
00084 
00085       if( !quote && !comm && infile[ii] == '/' && infile[ii+1] == '*' ){
00086          putchar(' ') ; ii += 2 ; comm = 1 ; continue ;
00087       }
00088 
00089       /* normal case: output character if not inside a comment: */
00090 
00091 #if 0
00092 fprintf(stderr,"at %d/%d: comm=%d char=%d\n",ii,nin,comm,infile[ii]) ;
00093 #endif
00094 
00095       if( !comm ) putchar(infile[ii]) ;
00096       ii++ ;
00097    }
00098    putchar('\n') ;
00099 
00100         if( comm  ) fprintf(stderr,"*** Warning: ended inside a comment!\n") ;
00101    else if( quote ) fprintf(stderr,"*** Warning: ended inside a quote!\n") ;
00102    exit(0) ;
00103 }

char* suck_file char *    fname
 

Definition at line 14 of file uncomment.c.

References close(), fd, free, malloc, read(), and THD_filesize().

Referenced by main().

00015 {
00016    int len , fd , ii ;
00017    char * buf ;
00018 
00019    if( fname == NULL || fname[0] == '\0' ) return NULL ;
00020 
00021    len = THD_filesize( fname ) ;
00022    if( len <= 0 ) return NULL ;
00023 
00024    fd = open( fname , O_RDONLY ) ;
00025    if( fd < 0 ) return NULL ;
00026 
00027 #if 0
00028 fprintf(stderr,"THD_filesize = %d\n",len) ;
00029 #endif
00030 
00031 #define NEX 4
00032 
00033    buf = (char *) malloc( sizeof(char) * (len+NEX) ) ;
00034    ii  = read( fd , buf , len ) ;
00035    close( fd ) ;
00036    if( ii <= 0 ){ free(buf) ; return NULL; }
00037 
00038    for( ii=0 ; ii < NEX ; ii++ ) buf[len+ii] = '\0' ;
00039    return buf ;
00040 }
 

Powered by Plone

This site conforms to the following standards: