path390.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 568 行 · 第 1/2 页

CPP
568
字号
            if (_pathEnd > source) {               // copy everything up to the last /, replacing / with .               while( source < _pathEnd ) {                  switch( *source ) {                      case '/':                         *dest = '.';                         break;                      default:                         *dest = *source;                  }                  dest++; source++;               }               // bump past the last /               source++;            }            // Now we try to locate the extension, and copy that.            filename_start = 0;            if ( _extStart != NULL ) {               tmpPos = _extStart;               if ( (*tmpPos != '\0') && (*tmpPos != ';') && (source != pathstart) )                  *dest++='.';               while ( (*tmpPos != '\0') && (*tmpPos != ';') ) {                  *dest++ = *tmpPos++;               }               // if there is a filename, add a (               if (source < (_extStart-1)) {                 filename_start = tmpPos;                 *dest++ = '(';                 }            }            else if (source != pathstart)               *dest++ = '.';            // Now we copy in the filename.            tmpPos = source;            while( ((*tmpPos != '\0') && (*tmpPos != ';'))  && ((_extStart == NULL) || (tmpPos < (_extStart-1))) ) {               *dest++ = *tmpPos++;            }            // Finally cap off the filename with optional ")"            if ( (_extStart != NULL) && (filename_start) ) *dest++ = ')';            // Add on the ending ' if necessary.            if (_dsnabsolute) *dest++ = '\'';            // make it a null terminated string.            *dest = '\0';            break;         case PATH390_HFS:            // it is in hfs: format. If it is relative, then add on a ./ otherwise            // just copy the string.            if (!_absolute) {               if (_uriabsolute) {                  _error = ERROR_MUST_BE_ABSOLUTE;                  break;               }               *dest++='.';               *dest++='/';            }            strcpy(dest,source);            break;         case PATH390_DD:            // It's in dd: format. This is similar to the dsn: format, just shorter.            // Start it out with dd:            *dest++='D';            *dest++='D';            *dest++=':';            tmpPos = source;            // if there is a / present in the path...            if (_pathEnd > source) {               // copy everything up to the last /, replacing / with .               while( source < _pathEnd ) {                  switch( *source ) {                      case '/':                         *dest = '.';                         break;                      default:                         *dest = *source;                  }                  dest++; source++;               }               // bump past the last /               source++;            }            // Now we try to locate the extension, and copy that.            filename_start = 0;            if ( _extStart != NULL ) {               tmpPos = _extStart;               if ( (*tmpPos != '\0') && (*tmpPos != ';') && (source != _curpos) )                  *dest++='.';               while ( (*tmpPos != '\0') && (*tmpPos != ';') ) {                  *dest++ = *tmpPos++;               }               // if there is a filename, add a (               if (source < (_extStart-1)) {                 filename_start = tmpPos;                 *dest++ = '(';                 }            }            else if (source != _curpos)               *dest++ = '.';            // Now we copy in the filename.            tmpPos = source;            while( ((*tmpPos != '\0') && (*tmpPos != ';'))  && ((_extStart == NULL) || (tmpPos < (_extStart-1))) ) {               *dest++ = *tmpPos++;            }            // Finally cap off the filename with optional ")"            if ( (_extStart != NULL) && (filename_start) ) *dest++ = ')';            *dest = '\0';            break;         case PATH390_DSN2:            // This is in dsn: format with the traditional MVS dataset name. Just fall into            // the default case to copy the path to the destination after making sure that            // there are no extra slashes.            {            int lastslash=5;            if (_uriabsolute)              lastslash=6;            if ( (_lastslash) && ((_lastslash-_orgpath)>lastslash) ) {               _error = ERROR_BAD_DSN2;               break;            }            }         default:            // for all other cases simply copy over the string.            strcpy(dest,source);            break;      }      _parsestate = PARSE_PARSED;   }}// Public methods start here:// This sets a new path into the object. Re-initialize everything and do an initial// parse.void Path390::setPath(char * s) {   if (_orgparms)      XMLPlatformUtils::fgMemoryManager->deallocate(_orgparms);//free (_orgparms);   if (_resultpath)      XMLPlatformUtils::fgMemoryManager->deallocate(_resultpath);//free(_resultpath);   if (_orgpath)      XMLPlatformUtils::fgMemoryManager->deallocate(_orgpath);//free(_orgpath);   _error = 0;   _orgparms = 0;   _resultpath = 0;   _absolute = false;   _dsnabsolute = false;   _orglen = strlen(s);   _orgpath = (char*) XMLPlatformUtils::fgMemoryManager->allocate((_orglen+1) * sizeof(char));//(char *) malloc(_orglen+1);   strcpy(_orgpath,s);   _curpos = _orgpath;   _parsestate=PARSE_NONE;   // Do an initial parse...   _determine_uri_abs();   _determine_type();}// Do the parse to completion and return any errors found.int Path390::fullParse() {   // Do an initial parse...   _determine_uri_abs();   _determine_type();   _determine_punct();   if (_error) {//      printf("found error-%d\n",_error);      return _error;   }   _determine_parms();   _parse_rest();   return _error;}// Get the path in a format which is required by fopen. First make sure that the path is// completely parsedchar * Path390::getfopenPath() {   _determine_uri_abs();   _determine_type();   _determine_punct();   if (_error)  {//      printf("found error-%d\n",_error);      return 0;   }   _determine_parms();   _parse_rest();   if (_error)  {//      printf("found error-%d\n",_error);      return 0;   }   if (_resultpath[0])      return _resultpath;   else      return 0;}// Get the parms in a format which is required by fopen. First make sure that the path is// completely parsedchar * Path390::getfopenParms() {   _determine_uri_abs();   _determine_type();   _determine_punct();   if (_error)  {//      printf("found error-%d\n",_error);      return 0;   }   _determine_parms();   _parse_rest();   if (_error)  {//      printf("found error-%d\n",_error);      return 0;   }   if ( (_orgparms) && (_orgparms[0]) )      return _orgparms;   else      return 0;}// return whether there is type=record parameter in the parameter list.bool Path390::isRecordType() {   _determine_uri_abs();   _determine_type();   _determine_punct();   if (_error)  {//      printf("found error-%d\n",_error);      return false;   }   _determine_parms();   _parse_rest();   if (_error)  {//      printf("found error-%d\n",_error);      return false;   }   if ( (_orgparms) && (_typerecord>=0) )      return true;   else      return false;}// This returns the path typeint Path390::getPathType() {   _determine_uri_abs();   _determine_type();   return _pathtype;}// This returns the error code which was found when the path was parsedint Path390::getError() {   _determine_uri_abs();   _determine_type();   _determine_punct();   if (_error)  { //     return _error;   }   _determine_parms();   _parse_rest();   if (_error)  { //     return _error;   }   return _error;}// returns whether the path is relative or absolute.bool Path390::isRelative() {   _determine_uri_abs();   _determine_type();return !(_absolute|_uriabsolute);}XERCES_CPP_NAMESPACE_END

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?