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  

thd_notes.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006    
00007 #include "mrilib.h"
00008                          /**************************
00009                           * 3dNotes - T. Ross 8/99 *
00010                           * adapted by RWCox  9/99 *
00011                           **************************/
00012 
00013 #include <sys/utsname.h>
00014 #include <sys/time.h>
00015 #include <time.h>
00016 #include <unistd.h>
00017 #include <stdlib.h>
00018 #include <ctype.h>
00019 
00020 /*---------------------------------------------------------------------------*/
00021 /*!  Assemble a sort-of command line string from the arguments;
00022      free() this when done.
00023 -----------------------------------------------------------------------------*/
00024 
00025 char * tross_commandline( char * pname , int argc , char ** argv )
00026 {
00027    char * ch ;
00028    int ii , ll ;
00029 
00030    if( argc < 2 || argv == NULL ) return NULL ;
00031 
00032    if( pname == NULL ) pname = argv[0] ;
00033 
00034    ii = strlen(pname) ; ch = AFMALL(char, ii+4) ; strcpy(ch,pname) ;
00035 
00036    for( ii=1 ; ii < argc ; ii++ ){
00037       if( argv[ii] == NULL || argv[ii][0] == '\0' ) continue ; /* skip */
00038 
00039       ll = strlen(argv[ii]) ;
00040       ch = AFREALL(ch ,char, strlen(ch)+ll+4 ) ;  /* expand output array */
00041 
00042       if( !THD_filename_ok(argv[ii]) ){       /* bad characters? */
00043          int jj ; char * aa = AFMALL(char, ll+1) ;
00044 
00045          strcpy(aa,argv[ii]) ;        /* edit out bad characters */
00046          for( jj=0 ; jj < ll ; jj++ )
00047             if( iscntrl(aa[jj]) ||
00048                 isspace(aa[jj]) || (aa[jj] & 128) != 0 ) aa[jj] = ' ' ;
00049 
00050          strcat(ch," '") ; strcat(ch,aa) ; strcat(ch,"'") ; free(aa) ;
00051 
00052       } else {
00053          strcat(ch," ")  ; strcat(ch,argv[ii]) ;   /* just copy it */
00054       }
00055    }
00056 
00057    return ch ;
00058 }
00059 
00060 /*---------------------------------------------------------------------------*/
00061 /*!  Get the current date/time string;  free() this when done.
00062 -----------------------------------------------------------------------------*/
00063 
00064 char * tross_datetime(void)
00065 {
00066    time_t tnow = time(NULL) ; int i ; char * qh , * ch ;
00067 
00068    ch=ctime(&tnow); i=strlen(ch); qh=AFMALL(char, i+2); 
00069    strcpy(qh,ch); qh[i-1]='\0';
00070    return qh ;
00071 }
00072 
00073 /*---------------------------------------------------------------------------*/
00074 
00075 #undef  NNAME
00076 #define NNAME 1025
00077 char * tross_hostname(void)  /* 19 Sep 1999 */
00078 {
00079    char * cn = AFMALL(char, NNAME) ;
00080    gethostname( cn , NNAME ) ;
00081    return cn ;
00082 }
00083 
00084 /*---------------------------------------------------------------------------*/
00085 
00086 #include <pwd.h>
00087 
00088 char * tross_username(void)  /* 20 Sep 1999 */
00089 {
00090    uid_t uu = getuid() ;
00091    struct passwd * pwd = getpwuid(uu) ;
00092    char * cn = AFMALL(char, NNAME) ;
00093 
00094    if( pwd == NULL ) strcpy(cn,"nobody") ;
00095    else              strcpy(cn,pwd->pw_name) ;
00096    return cn ;
00097 }
00098 
00099 /*---------------------------------------------------------------------------*/
00100 /*!   Add a note after the last current note
00101 -----------------------------------------------------------------------------*/
00102 
00103 void tross_Add_Note( THD_3dim_dataset *dset, char *cn )
00104 {
00105    ATR_int *notecount;
00106    int num_notes;
00107    char note_name[20], *ch ;
00108 
00109    if( !ISVALID_DSET(dset) || cn == NULL || cn[0] == '\0' ) return ;
00110 
00111    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00112    if (notecount == NULL) {
00113       num_notes = 1;
00114       THD_set_int_atr(dset->dblk, "NOTES_COUNT", 1, &num_notes);
00115    } else {
00116       num_notes = notecount->in[0] + 1;
00117       if( num_notes > MAX_DSET_NOTES ){
00118          fprintf(stderr,"*** attempt to add too many notes to dataset!\n") ;
00119          return ;
00120       }
00121       notecount->in[0]++;
00122    }
00123 
00124    sprintf(note_name, "NOTE_NUMBER_%03d", num_notes);
00125    ch = tross_Encode_String(cn) ; if( ch == NULL ) return ;
00126    THD_set_string_atr(dset->dblk, note_name, ch);
00127    free(ch) ;
00128 
00129    ch = tross_datetime() ;
00130    sprintf(note_name, "NOTE_DATE_%03d", num_notes) ;
00131    THD_set_string_atr(dset->dblk, note_name, ch);
00132    free(ch);
00133 
00134    return ;
00135 }
00136 
00137 /*---------------------------------------------------------------------------*/
00138 /*!   Delete a particular note
00139 -----------------------------------------------------------------------------*/
00140 
00141 void tross_Delete_Note(THD_3dim_dataset *dset, int inote)
00142 {
00143    ATR_int *notecount;
00144    int num_notes;
00145    ATR_string *note_text;
00146    char note_name[20];
00147 
00148    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ) return ;
00149 
00150    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00151    if (notecount == NULL) return ;
00152 
00153    num_notes = notecount->in[0];
00154    if (inote > num_notes) return ;
00155 
00156    sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00157    note_text = THD_find_string_atr(dset->dblk, note_name);
00158    if( note_text == NULL ) return ;
00159    THD_erase_one_atr( dset->dblk , note_name );
00160 
00161    sprintf(note_name, "NOTE_DATE_%03d", inote);
00162    note_text = THD_find_string_atr(dset->dblk, note_name);
00163    if( note_text != NULL ) THD_erase_one_atr( dset->dblk , note_name );
00164 
00165    notecount->in[0]-- ;  /* where the note count is reduced */
00166 
00167    /* Slide the higher numbered notes down */
00168 
00169    while (inote < num_notes) {
00170       /* find the next note */
00171       sprintf(note_name, "NOTE_NUMBER_%03d", inote+1);
00172       note_text=THD_find_string_atr(dset->dblk, note_name);
00173       if (note_text != NULL){
00174          /* rename to the previous name */
00175          sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00176          strcpy(note_text->name, note_name);
00177       }
00178 
00179       sprintf(note_name,"NOTE_DATE_%03d",inote+1) ;
00180       note_text = THD_find_string_atr(dset->dblk, note_name);
00181       if (note_text != NULL){
00182          /* rename to the previous name */
00183          sprintf(note_name, "NOTE_DATE_%03d", inote);
00184          strcpy(note_text->name, note_name);
00185       }
00186 
00187       inote++ ;
00188    }
00189 
00190    /* No notes left, so remove count attribute */
00191    if (num_notes == 1)
00192       THD_erase_one_atr( dset->dblk, "NOTES_COUNT");
00193    return ;
00194 }
00195 
00196 /*---------------------------------------------------------------------------*/
00197 /*! Get the number of Notes currently attached to the dataset.
00198     Doesn't include the History note.
00199 -----------------------------------------------------------------------------*/
00200 
00201 int tross_Get_Notecount( THD_3dim_dataset * dset )
00202 {
00203    ATR_int *notecount;
00204 
00205    if( !ISVALID_DSET(dset) ) return -1 ;
00206 
00207    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00208    if (notecount == NULL) return 0 ;
00209    return notecount->in[0];
00210 }
00211 
00212 /*---------------------------------------------------------------------------*/
00213 /*! Get the inote-th Note attached to the dataset.
00214     free() this string when done with it - it is a copy
00215 -----------------------------------------------------------------------------*/
00216 
00217 char * tross_Get_Note( THD_3dim_dataset * dset , int inote )
00218 {
00219    ATR_int *notecount;
00220    int num_notes;
00221    ATR_string *note ;
00222    char note_name[20], * ch ;
00223 
00224    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ) return NULL ;
00225 
00226    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00227    if (notecount == NULL) return NULL ;
00228    num_notes = notecount->in[0];
00229    if( inote > num_notes ) return NULL ;
00230 
00231    sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00232    note = THD_find_string_atr(dset->dblk, note_name);
00233    if (note == NULL ) return NULL ;
00234    ch = tross_Expand_String( note->ch ) ;
00235    return ch ;
00236 }
00237 
00238 /*------------------------------------------------------------------------------*/
00239 
00240 char * tross_Get_Notedate( THD_3dim_dataset * dset , int inote )
00241 {
00242    ATR_int *notecount;
00243    int num_notes;
00244    ATR_string *note ;
00245    char note_name[20];
00246 
00247    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ) return NULL ;
00248 
00249    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00250    if (notecount == NULL) return NULL ;
00251    num_notes = notecount->in[0];
00252    if( inote > num_notes ) return NULL ;
00253 
00254    sprintf(note_name, "NOTE_DATE_%03d", inote);
00255    note = THD_find_string_atr(dset->dblk, note_name);
00256    if (note == NULL ) return NULL ;
00257    return tross_Expand_String( note->ch ) ;
00258 }
00259 
00260 /*---------------------------------------------------------------------------*/
00261 /*! Add the history from the command line to the dataset.
00262 -----------------------------------------------------------------------------*/
00263 
00264 void tross_Make_History( char *pname, int argc, char **argv, THD_3dim_dataset *dset )
00265 {
00266    char *ch ;
00267 
00268    if( argc < 2 || argv == NULL || !ISVALID_DSET(dset) ) return ;
00269 
00270    ch = tross_commandline( pname , argc , argv ) ; if( ch == NULL ) return ;
00271    tross_Append_History( dset , ch ) ;
00272    free(ch) ; return ;
00273 }
00274 
00275 /*---------------------------------------------------------------------------*/
00276 /*!  Replace the History in new_dset with that from old_dset
00277 -----------------------------------------------------------------------------*/
00278 
00279 void tross_Copy_History( THD_3dim_dataset * old_dset , THD_3dim_dataset * new_dset )
00280 {
00281    char * ch , * cn ;
00282 
00283    if( !ISVALID_DSET(old_dset) || !ISVALID_DSET(new_dset) ) return ;
00284 
00285    ch = tross_Get_History( old_dset ) ;      if( ch == NULL ) return ;
00286    cn = tross_Encode_String(ch) ; free(ch) ; if( cn == NULL ) return;
00287    THD_set_string_atr(new_dset->dblk, "HISTORY_NOTE", cn);
00288    free(cn) ; return ;
00289 }
00290 
00291 /*---------------------------------------------------------------------------*/
00292 /*! Add the History in old_dset to that in new_dset [27 Feb 2003]
00293 -----------------------------------------------------------------------------*/
00294 
00295 void tross_Addto_History( THD_3dim_dataset *old_dset , THD_3dim_dataset *new_dset )
00296 {
00297    char *ch ;
00298 
00299    if( !ISVALID_DSET(old_dset) || !ISVALID_DSET(new_dset) ) return ;
00300 
00301    ch = tross_Get_History( old_dset ) ; if( ch == NULL ) return ;
00302    tross_Append_History( new_dset , ch ) ; free(ch) ; return ;
00303 }
00304 
00305 /*---------------------------------------------------------------------------*/
00306 /*! Erase the old History and replace it with this one.
00307    09 Dec 2000 - use this wisely.
00308 -----------------------------------------------------------------------------*/
00309 
00310 void tross_Replace_History( THD_3dim_dataset * dset , char * ch )
00311 {
00312    char * cn ;
00313 
00314    if( !ISVALID_DSET(dset) || ch == NULL ) return ;
00315 
00316    cn = tross_Encode_String(ch) ; if( cn == NULL ) return ;
00317    THD_set_string_atr(dset->dblk, "HISTORY_NOTE", cn);
00318    free(cn) ; return ;
00319 }
00320 
00321 /*---------------------------------------------------------------------------*/
00322 /*!  Append a string to the dataset history (create the history if need be).
00323 -----------------------------------------------------------------------------*/
00324 
00325 void tross_Append_History( THD_3dim_dataset *dset, char *cn )
00326 {
00327    ATR_string * hist ;
00328    char * ch , * chold , * cdate , * cname , * cuser ;
00329    int idate , iname , iuser ;
00330 
00331    if( !ISVALID_DSET(dset) || cn == NULL || cn[0] == '\0' ) return ;
00332 
00333    hist = THD_find_string_atr(dset->dblk,"HISTORY_NOTE") ;
00334    cdate = tross_datetime() ; idate = strlen(cdate) ;
00335    cname = tross_hostname() ; iname = strlen(cname) ;  /* 19 Sep 1999 */
00336    cuser = tross_username() ; iuser = strlen(cuser) ;  /* 19 Sep 1999 */
00337 
00338    /*- add to the history -*/
00339 
00340    if( hist != NULL ){
00341 
00342       chold = tross_Expand_String(hist->ch) ; if( chold == NULL ) return ;
00343       chold = AFREALL( chold, char, 
00344                        strlen(chold)+idate+iuser+iname+strlen(cn)+12 ) ;
00345 
00346       strcat(chold,"\n") ;
00347       strcat(chold,"[") ; strcat(chold,cuser) ; strcat(chold,"@") ;
00348                           strcat(chold,cname) ; strcat(chold,": ") ;
00349                           strcat(chold,cdate) ;
00350       strcat(chold,"] ") ;
00351       strcat(chold,cn) ;
00352       ch = tross_Encode_String(chold) ; if( ch == NULL ){ free(chold); return; }
00353       THD_set_string_atr(dset->dblk, "HISTORY_NOTE", ch);
00354       free(ch) ; free(chold) ;
00355 
00356    /*- create the history -*/
00357 
00358    } else {
00359       chold = AFMALL(char, idate+iuser+iname+strlen(cn)+12 ) ;
00360       sprintf(chold,"[%s@%s: %s] %s",cuser,cname,cdate,cn) ;
00361       ch = tross_Encode_String(chold) ; if( ch == NULL ){ free(chold); return; }
00362       THD_set_string_atr(dset->dblk, "HISTORY_NOTE", ch);
00363       free(ch) ; free(chold) ;
00364    }
00365 
00366    free(cdate) ; free(cname) ; free(cuser) ; return ;
00367 }
00368 
00369 /*----------------------------------------------------------------------------*/
00370 /*! Append multiple strings to the History, all on one line.  Usage:
00371       - tross_multi_Append_History(dset,str1,str2,str3,NULL) ;
00372       - As many str variables as desired (at least 1), of type char *, can be
00373         passed in.
00374       - The last one must be NULL.
00375 ------------------------------------------------------------------------------*/
00376 
00377 #include <stdarg.h>
00378 
00379 void tross_multi_Append_History( THD_3dim_dataset *dset, ... )
00380 {
00381    va_list vararg_ptr ;
00382    int nstr=0 , nc , first=1 , ii ;
00383    char * str , * cpt ;
00384 
00385    va_start( vararg_ptr , dset ) ;
00386 
00387    str = AFMALL(char, 4) ; nstr = 0 ; str[0] = '\0' ;
00388    while(1){
00389       cpt = va_arg( vararg_ptr , char * ) ; if( cpt == NULL ) break ;
00390       nc = strlen(cpt) ;                    if( nc  == 0    ) continue ;
00391       nstr += nc ; str = AFREALL(str, char, nstr+8 ) ;
00392       if( !first ) strcat(str," ; ") ;
00393       strcat(str,cpt) ; first = 0 ;
00394    }
00395 
00396    va_end( vararg_ptr ) ;
00397 
00398    nstr = strlen(str) ;
00399    if( nstr > 0 ){
00400       for( ii=0 ; ii < nstr ; ii++ )
00401          if( str[ii]=='\n' || str[ii]=='\f' || str[ii]=='\r' || str[ii]=='\v' )
00402             str[ii] = ' ' ;
00403 
00404       tross_Append_History( dset , str ) ;
00405    }
00406 
00407    free(str) ; return ;
00408 }
00409 
00410 /*----------------------------------------------------------------------------*/
00411 /*!  Get the history string; free() this when done.  If NULL is returned,
00412   there is no history (cf. Santayana).
00413 ------------------------------------------------------------------------------*/
00414 
00415 char * tross_Get_History( THD_3dim_dataset *dset )
00416 {
00417    ATR_string * hist ;
00418    char * ch ;
00419 
00420    if( !ISVALID_DSET(dset) ) return NULL ;
00421 
00422    hist = THD_find_string_atr(dset->dblk,"HISTORY_NOTE") ;
00423    if( hist == NULL ) return NULL ;
00424 
00425    ch = tross_Expand_String(hist->ch) ; return ch ;
00426 }
00427 
00428 /*-----------------------------------------------------------------------------*/
00429 /*!  Store string at location inote;
00430    if inote > number of notes now present, gets added at the end of the list;
00431    otherwise, replaces existing note
00432 -------------------------------------------------------------------------------*/
00433 
00434 void tross_Store_Note( THD_3dim_dataset * dset , int inote , char * cn )
00435 {
00436    ATR_int *notecount;
00437    int num_notes;
00438    ATR_string *note ;
00439    char note_name[20], *ch ;
00440 
00441    if( !ISVALID_DSET(dset) || inote <= 0 || inote > MAX_DSET_NOTES ||
00442                               cn == NULL || cn[0] == '\0'            ) return ;
00443 
00444    notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT");
00445    if (notecount == NULL){ tross_Add_Note( dset , cn ) ; return ; }
00446    num_notes = notecount->in[0];
00447    if( inote > num_notes ){ tross_Add_Note( dset , cn ) ; return ; }
00448 
00449    sprintf(note_name, "NOTE_NUMBER_%03d", inote);
00450    ch = tross_Encode_String(cn) ; if( ch == NULL ) return ;
00451    THD_set_string_atr(dset->dblk, note_name, ch);
00452    free(ch) ;
00453 
00454    ch = tross_datetime() ;
00455    sprintf(note_name, "NOTE_DATE_%03d", inote) ;
00456    THD_set_string_atr(dset->dblk, note_name, ch);
00457    free(ch);
00458 
00459    return ;
00460 }
00461 
00462 /*-----------------------------------------------------------------------*/
00463 /*!  Break a string up into lines of length between lbot and ltop bytes;
00464   free() the result when done with it.
00465   NULL return means illegal input was found.
00466 -------------------------------------------------------------------------*/
00467 
00468 char * tross_breakup_string( char * str , int lbot , int ltop )
00469 {
00470    char * sout ;
00471    int slen , ii , ibot,itop , ldif ;
00472 
00473    if( str == NULL || str[0] == '\0' || lbot > ltop || lbot < 4 ) return NULL ;
00474 
00475    slen = strlen(str) ; sout = AFMALL(char, slen+4) ;
00476 
00477    while( slen > lbot && isspace(str[slen-1]) ) slen-- ;  /* trim blanks off end */
00478 
00479    ibot = 0 ; ldif = ltop-lbot ;
00480    while(1){
00481       itop = ibot + ltop-1 ;    /* want to output str[ibot..itop] */
00482 
00483       /* if past end of str, then just output the rest and exit */
00484 
00485       if( itop >= slen ){
00486          memcpy( sout+ibot , str+ibot , slen-ibot ) ;
00487          sout[slen] = '\0' ;
00488          return sout ;
00489       }
00490 
00491       /* scan forwards to find a newline character before itop; */
00492       /* if one is present, output the string up to there,     */
00493       /* and continue again starting after the newline        */
00494 
00495       for( ii=ibot ; ii <= itop ; ii++ )
00496          if( str[ii] == '\n' ) break ;
00497 
00498       if( ii <= itop ){  /* found it! */
00499          memcpy( sout+ibot , str+ibot , ii-ibot+1 ) ;
00500          ibot = ii+1 ;
00501          if( ibot >= slen ){ sout[slen] = '\0'; return sout; }
00502          continue ;
00503       }
00504 
00505       /* scan backwards to find a whitespace character */
00506 
00507       for( ii=itop ; ii > itop-ldif ; ii-- )
00508          if( isspace(str[ii]) ) break ;
00509 
00510       /* found one before the minimum location      */
00511       /* copy up to the previous char into output, */
00512       /* then put a newline in for the whitespace */
00513 
00514       if( ii > itop-ldif ){
00515          memcpy( sout+ibot , str+ibot , ii-ibot ) ;
00516          sout[ii] = '\n' ;
00517          ibot = ii+1 ;
00518          continue ;         /* try to do next line */
00519       }
00520 
00521       /* scan ahead to next whitespace instead */
00522 
00523       for( ii=itop ; ii < slen ; ii++ )
00524          if( isspace(str[ii]) ) break ;
00525 
00526       /* found one */
00527 
00528       if( ii < slen ){
00529          memcpy( sout+ibot , str+ibot , ii-ibot ) ;
00530          sout[ii] = '\n' ;
00531          ibot = ii+1 ;
00532          continue ;
00533       }
00534 
00535       /* copy rest of input and exit */
00536 
00537       memcpy( sout+ibot , str+ibot , slen-ibot ) ;
00538       sout[slen] = '\0' ;
00539       return sout ;
00540    }
00541 }
00542 
00543 /*-----------------------------------------------------------------------*/
00544 /*!  Return a printable version of a note string; free() this when done
00545 -------------------------------------------------------------------------*/
00546 
00547 char * tross_Expand_String( char * ch )
00548 {
00549    char * cn = NULL ;
00550    int i, j, num_char;
00551 
00552    if( ch == NULL || ch[0] == '\0' ) return NULL ;
00553 
00554    num_char = strlen(ch) ;
00555    cn = (char *) malloc( sizeof(char) * (num_char+4) ) ;
00556    for( i=j=0 ; j < num_char ; j++ ){
00557       if( ch[j] != '\\' ){
00558          cn[i++] = ch[j] ;
00559       } else {
00560          switch (ch[++j] ){
00561             case 'r'  : cn[i++] = '\r' ; break;
00562             case 'n'  : cn[i++] = '\n' ; break;
00563             case '\\' : cn[i++] = '\\' ; break;
00564             case '"'  : cn[i++] = '\"' ; break;
00565             case 't'  : cn[i++] = '\t' ; break;
00566             case 'a'  : cn[i++] = '\a' ; break;
00567             case 'v'  : cn[i++] = '\v' ; break;
00568             case 'b'  : cn[i++] = '\b' ; break;
00569             default:    cn[i++] = '\\' ;         /* 13 Mar 2003 */
00570                         cn[i++] = ch[j]; break;
00571          }
00572       }
00573    }
00574    cn[i] = '\0' ; return cn ;
00575 }
00576 
00577 /*--------------------------------------------------------------------------*/
00578 
00579 static int Dont_Encode_Slash = 0 ;
00580 
00581 void tross_Dont_Encode_Slash( int q ){ Dont_Encode_Slash = q ; return ; }
00582 
00583 /*--------------------------------------------------------------------------*/
00584 /*!  Reverse of tross_Expand_String
00585 ----------------------------------------------------------------------------*/
00586 
00587 char * tross_Encode_String( char * cn )
00588 {
00589    char * ch = NULL ;
00590    int i , j , num_char ;
00591 
00592    if( cn == NULL || cn[0] == '\0' ) return NULL ;
00593 
00594    num_char = strlen(cn) ;
00595    ch = (char *) malloc( sizeof(char) * (2*num_char+4) ) ;
00596    for( i=j=0 ; j < num_char ; j++ ){
00597       switch( cn[j] ){
00598          default:   ch[i++] = cn[j]                ; break ;
00599          case '\r': ch[i++] = '\\' ; ch[i++] = 'r' ; break ;
00600          case '\n': ch[i++] = '\\' ; ch[i++] = 'n' ; break ;
00601          case '\"': ch[i++] = '\\' ; ch[i++] = '\"'; break ;
00602          case '\t': ch[i++] = '\\' ; ch[i++] = 't' ; break ;
00603          case '\a': ch[i++] = '\\' ; ch[i++] = 'a' ; break ;
00604          case '\v': ch[i++] = '\\' ; ch[i++] = 'v' ; break ;
00605          case '\b': ch[i++] = '\\' ; ch[i++] = 'b' ; break ;
00606 
00607          case '\\':                          ch[i++] = '\\';
00608                     if( !Dont_Encode_Slash ) ch[i++] = '\\';
00609          break ;
00610       }
00611    }
00612    ch[i] = '\0' ;
00613    for( i-- ; i > 0 ; i-- ) if( isspace(ch[i]) ) ch[i] = '\0' ; else break ;
00614    return ch ;
00615 }
 

Powered by Plone

This site conforms to the following standards: