Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xDataTOM_Misc.cc File Reference
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include "xDataTOM_private.h"
Include dependency graph for xDataTOM_Misc.cc:

Go to the source code of this file.

Macros

#define nameValueLength   1024
 

Functions

static xDataTOM_elementxDataTOM_getLinksElement2 (statusMessageReporting *smr, xDataTOM_element *element, char const *link, char const *fullLink)
 
static int xDataTOM_getLinksElement3 (statusMessageReporting *smr, char const *nameValue, char *name, char *value, char const *fullLink)
 
char * xDataTOMMisc_getAbsPath (statusMessageReporting *smr, const char *fileName)
 
int xDataTOM_setMessageError_ReturnInt (int value, statusMessageReporting *smr, void *userInterface, const char *packageName, int lineNumber, int code, const char *fmt,...)
 
xDataTOM_elementxDataTOM_getLinksElement (statusMessageReporting *smr, xDataTOM_element *element, char const *link)
 

Macro Definition Documentation

#define nameValueLength   1024

Definition at line 22 of file xDataTOM_Misc.cc.

Function Documentation

xDataTOM_element* xDataTOM_getLinksElement ( statusMessageReporting smr,
xDataTOM_element element,
char const *  link 
)

Definition at line 89 of file xDataTOM_Misc.cc.

89  {
90 
91  xDataTOM_element *linkedElement = NULL;
92 
93  if( link[0] == '/' ) {
94  for( linkedElement = element; linkedElement->parent != NULL; ) linkedElement = linkedElement->parent;
95  linkedElement = xDataTOM_getLinksElement2( smr, linkedElement, &(link[1]), link ); }
96  else {
97  smr_setReportError2( smr, smr_unknownID, 1, "Only absolute link currently supported: requested link = '%s'", link );
98  }
99  return( linkedElement );
100 }
static xDataTOM_element * xDataTOM_getLinksElement2(statusMessageReporting *smr, xDataTOM_element *element, char const *link, char const *fullLink)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
#define smr_unknownID
xDataTOM_element * parent
Definition: xDataTOM.h:181

Here is the call graph for this function:

Here is the caller graph for this function:

static xDataTOM_element * xDataTOM_getLinksElement2 ( statusMessageReporting smr,
xDataTOM_element element,
char const *  link,
char const *  fullLink 
)
static

Definition at line 104 of file xDataTOM_Misc.cc.

104  {
105 
106  int n = (int) strlen( link );
107  char const *slash = strchr( link, '/' ), *bracket = strchr( link, '[' ), *attributesValue;
109  xDataTOM_element *child;
110 
111  if( bracket != NULL ) n = (int) ( bracket - link );
112  if( slash != NULL ) {
113  if( (int) ( slash - link ) < n ) {
114  n = (int) ( slash - link );
115  bracket = NULL;
116  }
117  }
118  for( child = element->children; child != NULL; child = child->next ) {
119  if( strncmp( link, child->name, n ) == 0 ) {
120  if( bracket != NULL ) {
121  if( bracket[1] != '@' ) {
122  smr_setReportError2( smr, smr_unknownID, 1, "bad link info at '%s' of '%s'", bracket, fullLink );
123  return( NULL );
124  }
125  if( xDataTOM_getLinksElement3( smr, &(bracket[2]), name, value, fullLink ) ) return( NULL );
126  if( ( attributesValue = xDataTOM_getAttributesValueInElement( child, name ) ) == NULL ) continue;
127  if( strcmp( value, attributesValue ) ) continue;
128  }
129  if( slash == NULL ) return( child );
130  return( xDataTOM_getLinksElement2( smr, child, &(slash[1]), fullLink ) );
131  }
132  }
133  return( NULL );
134 }
const XML_Char * name
Definition: expat.h:151
xDataTOM_element * next
Definition: xDataTOM.h:182
static xDataTOM_element * xDataTOM_getLinksElement2(statusMessageReporting *smr, xDataTOM_element *element, char const *link, char const *fullLink)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
const XML_Char int const XML_Char * value
Definition: expat.h:331
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define smr_unknownID
static int xDataTOM_getLinksElement3(statusMessageReporting *smr, char const *nameValue, char *name, char *value, char const *fullLink)
xDataTOM_element * children
Definition: xDataTOM.h:186
#define nameValueLength
char const * xDataTOM_getAttributesValueInElement(xDataTOM_element *element, char const *name)
Definition: xDataTOM.cc:286

Here is the call graph for this function:

Here is the caller graph for this function:

static int xDataTOM_getLinksElement3 ( statusMessageReporting smr,
char const *  nameValue,
char *  name,
char *  value,
char const *  fullLink 
)
static

Definition at line 138 of file xDataTOM_Misc.cc.

138  {
139 
140  int n;
141  char const *equal = strchr( nameValue, '=' ), *p;
142  char quote = '\'';
143 
144  if( equal == NULL ) {
145  smr_setReportError2( smr, smr_unknownID, 1, "link qualifier missing '=' character at '%s' of '%s'", nameValue, fullLink );
146  return( 1 );
147  }
148  n = (int) ( equal - nameValue );
149  if( n >= ( nameValueLength - 1 ) ) {
150  smr_setReportError2( smr, smr_unknownID, 1, "link's name qualifier too long at '%s' of '%s'", nameValue, fullLink );
151  return( 1 );
152  }
153  strncpy( name, nameValue, n );
154  name[n] = 0;
155 
156  equal++;
157  if( *equal != quote ) quote = '"';
158  if( *equal != quote ) {
159  smr_setReportError2( smr, smr_unknownID, 1, "link's name qualifier missing quote at '%s' of '%s'", nameValue, fullLink );
160  return( 1 );
161  }
162 
163  equal++;
164  p = strchr( equal, quote );
165  if( p == NULL ) {
166  smr_setReportError2( smr, smr_unknownID, 1, "link's name qualifier missing end quote at '%s' of '%s'", nameValue, fullLink );
167  return( 1 );
168  }
169 
170  n = (int) ( p - equal );
171  if( n >= ( nameValueLength - 1 ) ) {
172  smr_setReportError2( smr, smr_unknownID, 1, "link's value qualifier too long at '%s' of '%s'", nameValue, fullLink );
173  return( 1 );
174  }
175  strncpy( value, equal, n );
176  value[n] = 0;
177 
178  return( 0 );
179 }
const XML_Char * name
Definition: expat.h:151
const char * p
Definition: xmltok.h:285
#define smr_setReportError2(smr, libraryID, code, fmt,...)
const XML_Char int const XML_Char * value
Definition: expat.h:331
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define smr_unknownID
#define nameValueLength

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 76 of file xDataTOM_Misc.cc.

77  {
78 
79  va_list args;
80 
81  va_start( args, fmt );
82  smr_setReportError( smr, userInterface, packageName, lineNumber, __func__, xDataTOM_smrLibraryID, code, fmt, args );
83  va_end( args );
84  return( value );
85 }
int xDataTOM_smrLibraryID
Definition: xDataTOM.cc:34
const XML_Char int const XML_Char * value
Definition: expat.h:331
Definition: inftrees.h:24
int smr_setReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)

Here is the call graph for this function:

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

Definition at line 29 of file xDataTOM_Misc.cc.

29  {
30 /*
31 * User must free returned string.
32 */
33  int n = (int) strlen( fileName ) + 1, nCwd = 0;
34  char *absPath, cwd[4 * 1024] = "", *p, *needle;
35 
36  if( fileName[0] != '/' ) {
37  //if( getcwd( cwd, sizeof( cwd ) + 1 ) == NULL ) {
38  //TK modified above line for compiler(gcc.4.8) warning message
39  if( getcwd( cwd, sizeof( cwd ) ) == NULL ) {
40  smr_setReportError2p( smr, xDataTOM_smrLibraryID, -1, "hardwired cwd too small" );
41  return( NULL );
42  }
43  nCwd = (int) strlen( cwd );
44  n += nCwd + 1; /* cwd + '/'. */
45  }
46  if( ( absPath = (char *) smr_malloc2( smr, n, 0, "absPath" ) ) == NULL ) return( NULL );
47  if( fileName[0] != '/' ) {
48  strcpy( absPath, cwd );
49  strcat( absPath, "/" );
50  strcat( absPath, fileName ); }
51  else {
52  strcpy( absPath, fileName );
53  }
54 
55  while( 1 ) { /* Remove all ./ from path. */
56  if( ( needle = strstr( absPath, "/./" ) ) == NULL ) break;
57  p = needle;
58  for( needle += 2; *needle; p++, needle++ ) *p = *needle;
59  *p = 0;
60  } // Loop checking, 11.06.2015, T. Koi
61 
62  while( 1 ) { /* Remove all ../ from path. */
63  if( ( needle = strstr( absPath, "/../" ) ) == NULL ) break;
64  p = needle - 1;
65  while( ( p > absPath ) && ( *p != '/' ) ) p--; // Loop checking, 11.06.2015, T. Koi
66  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. */
67  if( p == absPath ) break; /* Ditto. */
68  for( needle += 3; *needle; p++, needle++ ) *p = *needle;
69  *p = 0;
70  } // Loop checking, 11.06.2015, T. Koi
71  return( absPath );
72 }
int xDataTOM_smrLibraryID
Definition: xDataTOM.cc:34
const char * p
Definition: xmltok.h:285
#define smr_setReportError2p(smr, libraryID, code, fmt)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
#define smr_malloc2(smr, size, zero, forItem)

Here is the call graph for this function:

Here is the caller graph for this function: