xDataMisc.cc File Reference

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include "xData.h"

Go to the source code of this file.

Functions

void * xData_malloc (statusMessageReporting *smr, size_t size, int zero, const char *forItem, const char *file, int line)
void * xData_realloc (statusMessageReporting *smr, void *pOld, size_t size, const char *forItem, const char *file, int line)
void * xData_free (statusMessageReporting *, void *p)
char * xDataMisc_allocateCopyString (statusMessageReporting *smr, const char *s, const char *forItem, const char *file, int line)
char * xDataMisc_getAbsPath (statusMessageReporting *smr, const char *fileName)
int xData_setMessageError_ReturnInt (int value, statusMessageReporting *smr, void *userInterface, const char *packageName, int lineNumber, int code, const char *fmt,...)


Function Documentation

void* xData_free ( statusMessageReporting *  ,
void *  p 
)

Definition at line 89 of file xDataMisc.cc.

Referenced by G4GIDI::freeTarget(), G4GIDI_Z_AMass(), G4GIDI::getAlreadyReadTarget(), G4GIDI::getNamesOfAvailableLibraries(), tpi_channelID_free(), tpi_spectralID_free(), tpi_spectralID_release(), tpia_angular_release(), tpia_angularEnergy_release(), tpia_channel_free(), tpia_channel_release(), tpia_depot_free(), tpia_depot_release(), tpia_Legendre_release(), tpia_map_free(), tpia_map_release(), tpia_misc_getEqualProbableBins(), tpia_multiplicity_free(), tpia_multiplicity_release(), tpia_particle_free(), tpia_particle_freeInternalList(), tpia_product_free(), tpia_product_release(), tpia_target_createRead(), tpia_target_createReadFromMap(), tpia_target_free(), tpia_target_heated_create(), tpia_target_heated_createRead(), tpia_target_heated_free(), tpia_target_heated_release(), tpia_target_release(), xData_1d_x_free_copyData(), xData_2d_xindex_y_free_rawIndices(), xData_2d_xindex_y_free_toFilledYs(), xData_2d_xShared_yHistogram_free_copyData(), xData_2d_xy_free_copyData(), xData_freeElementList(), xData_matrix_free_copyData(), xData_parseFree(), xData_releaseAttributionList(), xData_setFileName(), and G4GIDI_target::~G4GIDI_target().

00089                                                       {
00090 
00091     if( p != NULL ) free( p );
00092     return( NULL );
00093 }

void* xData_malloc ( statusMessageReporting *  smr,
size_t  size,
int  zero,
const char *  forItem,
const char *  file,
int  line 
)

Definition at line 56 of file xDataMisc.cc.

References xData_realloc().

Referenced by xDataMisc_allocateCopyString().

00056                                                                                                                           {
00057 
00058     void *p = xData_realloc( smr, NULL, size, forItem, file, line );
00059     int i;
00060     char *c;
00061     long long *l;
00062 
00063     if( ( p != NULL ) && zero ) {
00064         //for( i = 0, l = (long long *) p; i < size / sizeof( long long ); i++, l++ ) *l = 0;
00065         for( i = 0, l = (long long *) p; i < (int)( size / sizeof( long long ) ); i++, l++ ) *l = 0;
00066         //for( i = sizeof( long long ) * i, c = (char *) l; i < size; i++, c++ ) *c = 0;
00067         for( i = sizeof( long long ) * i, c = (char *) l; i < (int) size; i++, c++ ) *c = 0;
00068     }
00069 
00070     return( p );
00071 }

void* xData_realloc ( statusMessageReporting *  smr,
void *  pOld,
size_t  size,
const char *  forItem,
const char *  file,
int  line 
)

Definition at line 75 of file xDataMisc.cc.

References smr_setMessageError().

Referenced by xData_malloc().

00075                                                                                                                              {
00076 
00077     void *p = realloc( pOld, size );
00078 
00079     if( ( p == NULL ) && ( smr != NULL ) ) {
00080         smr_setMessageError( smr, NULL, file, line, -1, " xData_realloc: failed to realloc size = %llu for variable %s\n", 
00081             (unsigned long long) size, forItem );
00082     }
00083     return( p );
00084 }

int xData_setMessageError_ReturnInt ( int  value,
statusMessageReporting *  smr,
void *  userInterface,
const char *  packageName,
int  lineNumber,
int  code,
const char *  fmt,
  ... 
)

Definition at line 160 of file xDataMisc.cc.

References smr_setMessageError().

00161                            {
00162 
00163     va_list args;
00164 
00165     va_start( args, fmt );
00166     smr_setMessageError( smr, userInterface, packageName, lineNumber, code, fmt, args );
00167     va_end( args );
00168     return( value );
00169 }

char* xDataMisc_allocateCopyString ( statusMessageReporting *  smr,
const char *  s,
const char *  forItem,
const char *  file,
int  line 
)

Definition at line 97 of file xDataMisc.cc.

References xData_malloc().

00097                                                                                                                                   {
00098 /*
00099 *   User must free returned string.
00100 */
00101     char *c;
00102 
00103     //if( ( c = xData_malloc( smr, strlen( s ) + 1, 0, forItem, file, line ) ) != NULL ) {
00104     if( ( c = (char*) xData_malloc( smr, strlen( s ) + 1, 0, forItem, file, line ) ) != NULL ) {
00105         strcpy( c, s );
00106     }
00107     return( c );
00108 }

char* xDataMisc_getAbsPath ( statusMessageReporting *  smr,
const char *  fileName 
)

Definition at line 112 of file xDataMisc.cc.

References CLHEP::detail::n, and smr_setMessageError().

Referenced by tpia_target_heated_read(), and tpia_target_read().

00112                                                                                 {
00113 /*
00114 *   User must free returned string.
00115 */
00116     int n = strlen( fileName ) + 1, nCwd = 0;
00117     //char *absPath, cwd[4 * 1024] = "", *p, *needle;
00118     char *absPath, cwd[4 * 1024 + 1] = "", *p, *needle;
00119 
00120     if( fileName[0] != '/' ) {
00121         //if( getcwd( cwd, sizeof( cwd ) + 1 ) == NULL ) {
00122         if( getcwd( cwd, sizeof( cwd ) ) == NULL ) {
00123             smr_setMessageError( smr, NULL, __FILE__, __LINE__, -1, "hardwired cwd too small" );
00124             return( NULL );
00125         }
00126         nCwd = strlen( cwd );
00127         n += nCwd + 1;                                  /* cwd + '/'. */
00128     }
00129     //if( ( absPath = xData_malloc2( smr, n, 0, "absPath" ) ) == NULL ) return( NULL );
00130     if( ( absPath = (char*) xData_malloc2( smr, n, 0, "absPath" ) ) == NULL ) return( NULL );
00131     if( fileName[0] != '/' ) {
00132         strcpy( absPath, cwd );
00133         strcat( absPath, "/" );
00134         strcat( absPath, fileName ); }
00135     else {
00136         strcpy( absPath, fileName );
00137     }
00138 
00139     while( 1 ) {                                        /* Remove all ./ from path. */
00140         if( ( needle = strstr( absPath, "/./" ) ) == NULL ) break;
00141         p = needle;
00142         for( needle += 2; *needle; p++, needle++ ) *p = *needle;
00143         *p = 0;
00144     }
00145 
00146     while( 1 ) {                                        /* Remove all ../ from path. */
00147         if( ( needle = strstr( absPath, "/../" ) ) == NULL ) break;
00148         p = needle - 1;
00149         while( ( p > absPath ) && ( *p != '/' ) ) p--;
00150         if( *p != '/' ) break;                           /* This should not happen if path is legit, I think, and I do not know what to do so will leave it. */
00151         if( p == absPath ) break;                       /* Ditto. */
00152         for( needle += 3; *needle; p++, needle++ ) *p = *needle;
00153         *p = 0;
00154     }
00155     return( absPath );
00156 }


Generated on Mon May 27 17:51:17 2013 for Geant4 by  doxygen 1.4.7