⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 types.cpp

📁 linux下简单对象应用协议的开发库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*types.cppWSDL parser and converter to gSOAP header file format--------------------------------------------------------------------------------gSOAP XML Web services toolsCopyright (C) 2001-2007, Robert van Engelen, Genivia Inc. All Rights Reserved.This software is released under one of the following two licenses:GPL or Genivia's license for commercial use.--------------------------------------------------------------------------------GPL license.This program is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any laterversion.This program is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along withthis program; if not, write to the Free Software Foundation, Inc., 59 TemplePlace, Suite 330, Boston, MA 02111-1307 USAAuthor contact information:engelen@genivia.com / engelen@acm.org--------------------------------------------------------------------------------A commercial use license is available from Genivia, Inc., contact@genivia.com--------------------------------------------------------------------------------*/#include "types.h"static char *getline(char *s, size_t n, FILE *fd);static const char *nonblank(const char *s);static const char *fill(char *t, int n, const char *s, int e);static const char *utf8(char *t, const char *s);static const char *cstring(const char *s);static const char *xstring(const char *s);static bool is_integer(const char *s);static void documentation(const char *text);////////////////////////////////////////////////////////////////////////////////////	Keywords and reserved words//////////////////////////////////////////////////////////////////////////////////static const char *keywords[] ={ "and",  "asm",  "auto",  "bool",  "break",  "case",  "catch",  "char",  "class",  "const",  "const_cast",  "continue",  "default",  "delete",  "do",  "double",  "dynamic_cast",  "else",	  "enum",  "errno",  "explicit",  "export",  "extern",  "false",  "FILE",  "float",  "for",  "friend",  "goto",  "if",  "inline",  "int",  "long",  "LONG64",  "max",  "min",  "mustUnderstand",  "mutable",  "namespace",  "new",  "not",  "NULL",  "operator",  "or",  "private",  "protected",  "public",  "_QName",  "register",  "reinterpret_cast",  "restrict",  "return",  "short",  "signed",  "size_t",  "sizeof",  "static",  "static_cast",  "struct",  "switch",  "template",  "this",  "throw",  "time_t",  "true",  "typedef",  "typeid",  "typename",  "ULONG64",  "union",  "unsigned",  "using",  "virtual",  "void",  "volatile",  "wchar_t",  "while",  "XML",  "_XML",  "xor",};////////////////////////////////////////////////////////////////////////////////////	Types methods//////////////////////////////////////////////////////////////////////////////////Types::Types(){ init();}int Types::read(const char *file){ FILE *fd = fopen(file, "r");  char buf[1024], xsd[1024], def[1024], use[1024], ptr[1024], uri[1024];  const char *s;  short copy = 0;  if (!fd)  { fprintf(stderr, "Cannot open file '%s'\n", file);    return SOAP_EOF;  }  fprintf(stderr, "Reading type map file '%s'\n\n", file);  while (getline(buf, sizeof(buf), fd))  { s = buf;    if (copy)    { if (*s == ']')        copy = 0;      else        fprintf(stream, "%s\n", buf);    }    else if (*s == '[')      copy = 1;    else if (*s == '<')    { s = fill(uri, sizeof(uri), s+1, -1);      infile[infiles++] = estrdup(uri);      if (infiles >= MAXINFILES)      { fprintf(stderr, "wsdl2h: too many files\n");        exit(1);      }    }    else if (*s == '>')    { s = fill(uri, sizeof(uri), s+1, -1);      if (!outfile)      { outfile = estrdup(uri);        stream = fopen(outfile, "w");        if (!stream)        { fprintf(stderr, "Cannot write to %s\n", outfile);          exit(1);        }        if (cppnamespace)          fprintf(stream, "namespace %s {\n", cppnamespace);        fprintf(stderr, "Saving %s\n\n", outfile);      }    }    else if (*s && *s != '#')    { s = fill(xsd, sizeof(xsd), s, '=');      if (strstr(xsd, "__"))      { s = fill(def, sizeof(def), s, '|');        s = fill(use, sizeof(use), s, '|');        s = fill(ptr, sizeof(ptr), s, '|');        if (*xsd)        { s = estrdup(xsd);          if (*def == '$')          { const char *t = modtypemap[s];            if (t)            { char *r = (char*)emalloc(strlen(t) + strlen(def) + 1);              strcpy(r, t);              strcat(r, def);              free((void*)modtypemap[s]);              modtypemap[s] = r;            }            else              modtypemap[s] = estrdup(def);          }          else          { if (*def)              deftypemap[s] = estrdup(def);            else              deftypemap[s] = "";            if (*use)              usetypemap[s] = estrdup(use);            else              usetypemap[s] = estrdup(xsd);            if (*ptr)              ptrtypemap[s] = estrdup(ptr);          }        }      }      else if (*xsd)      { s = fill(uri, sizeof(uri), s, 0);        if (uri[0] == '"')        { uri[strlen(uri) - 1] = '\0';          nsprefix(xsd, estrdup(uri + 1));        }        else if (uri[0] == '<')        { uri[strlen(uri) - 1] = '\0';          char *s = estrdup(uri + 1);          nsprefix(xsd, s);          exturis.insert(s);        }        else          nsprefix(xsd, estrdup(uri));      }    }  }  fclose(fd);  return SOAP_OK;}void Types::init(){ snum = 1;  unum = 1;  gnum = 1;  with_union = false;  fake_union = false;  knames.insert(keywords, keywords + sizeof(keywords)/sizeof(char*));  if (cflag)  { deftypemap["xsd__ur_type"] = "";    if (dflag)    { usetypemap["xsd__ur_type"] = "xsd__anyType";      ptrtypemap["xsd__ur_type"] = "xsd__anyType*";    }    else    { usetypemap["xsd__ur_type"] = "_XML";      ptrtypemap["xsd__ur_type"] = "_XML";    }  }  else  { deftypemap["xsd__ur_type"] = "class xsd__ur_type { _XML __item; struct soap *soap; };";    usetypemap["xsd__ur_type"] = "xsd__ur_type";  }  if (cflag)  { deftypemap["xsd__anyType"] = "";    if (dflag)    { usetypemap["xsd__anyType"] = "xsd__anyType";      ptrtypemap["xsd__anyType"] = "xsd__anyType*";    }    else    { usetypemap["xsd__anyType"] = "_XML";      ptrtypemap["xsd__anyType"] = "_XML";    }  }  else  { if (dflag)    { deftypemap["xsd__anyType"] = "";      usetypemap["xsd__anyType"] = "xsd__anyType";      ptrtypemap["xsd__anyType"] = "xsd__anyType*";    }    else    { deftypemap["xsd__anyType"] = "class xsd__anyType { _XML __item; struct soap *soap; };";      usetypemap["xsd__anyType"] = "xsd__anyType*";    }  }  if (cflag)  { deftypemap["xsd__base64Binary"] = "struct xsd__base64Binary\n{\tunsigned char *__ptr;\n\tint __size;\n\tchar *id, *type, *options; // NOTE: for DIME and MTOM XOP attachments only\n};";    usetypemap["xsd__base64Binary"] = "struct xsd__base64Binary";  }  else  { deftypemap["xsd__base64Binary"] = "class xsd__base64Binary\n{\tunsigned char *__ptr;\n\tint __size;\n\tchar *id, *type, *options; // NOTE: for DIME and MTOM XOP attachments only\n\tstruct soap *soap;\n};";    usetypemap["xsd__base64Binary"] = "xsd__base64Binary";  }  if (cflag)  { if (eflag)      deftypemap["xsd__boolean"] = "enum xsd__boolean { false_, true_ };";    else      deftypemap["xsd__boolean"] = "enum xsd__boolean { xsd__boolean__false_, xsd__boolean__true_ };";    usetypemap["xsd__boolean"] = "enum xsd__boolean";  }  else  { deftypemap["xsd__boolean"] = "";    usetypemap["xsd__boolean"] = "bool";  }  deftypemap["xsd__byte"] = "";  usetypemap["xsd__byte"] = "char";  ptrtypemap["xsd__byte"] = "short*"; // avoid char*  deftypemap["xsd__dateTime"] = "";  usetypemap["xsd__dateTime"] = "time_t";  deftypemap["xsd__double"] = "";  usetypemap["xsd__double"] = "double";  deftypemap["xsd__float"] = "";  usetypemap["xsd__float"] = "float";  if (cflag)  { deftypemap["xsd__hexBinary"] = "struct xsd__hexBinary { unsigned char *__ptr; int __size; };";    usetypemap["xsd__hexBinary"] = "struct xsd__hexBinary";  }  else  { deftypemap["xsd__hexBinary"] = "class xsd__hexBinary { unsigned char *__ptr; int __size; };";    usetypemap["xsd__hexBinary"] = "xsd__hexBinary";  }  deftypemap["xsd__int"] = "";  usetypemap["xsd__int"] = "int";  deftypemap["xsd__long"] = "";  usetypemap["xsd__long"] = "LONG64";  deftypemap["xsd__short"] = "";  usetypemap["xsd__short"] = "short";  if (cflag || sflag)  { deftypemap["xsd__string"] = "";    usetypemap["xsd__string"] = "char*";    deftypemap["xsd__QName"] = "";    usetypemap["xsd__QName"] = "_QName";    ptrtypemap["xsd__QName"] = "_QName";  }  else  { deftypemap["xsd__string"] = "";    usetypemap["xsd__string"] = "std::string";  }  deftypemap["xsd__unsignedByte"] = "";  usetypemap["xsd__unsignedByte"] = "unsigned char";  ptrtypemap["xsd__unsignedByte"] = "unsigned short*"; // avoid unsigned char*  deftypemap["xsd__unsignedInt"] = "";  usetypemap["xsd__unsignedInt"] = "unsigned int";  deftypemap["xsd__unsignedLong"] = "";  usetypemap["xsd__unsignedLong"] = "ULONG64";  deftypemap["xsd__unsignedShort"] = "";  usetypemap["xsd__unsignedShort"] = "unsigned short";  if (cflag)  { deftypemap["SOAP_ENC__base64Binary"] = "struct SOAP_ENC__base64Binary { unsigned char *__ptr; int __size; };";    usetypemap["SOAP_ENC__base64Binary"] = "struct SOAP_ENC__base64Binary";    deftypemap["SOAP_ENC__base64"] = "struct SOAP_ENC__base64 { unsigned char *__ptr; int __size; };";    usetypemap["SOAP_ENC__base64"] = "struct SOAP_ENC__base64";  }  else  { deftypemap["SOAP_ENC__base64Binary"] = "class SOAP_ENC__base64Binary { unsigned char *__ptr; int __size; };";

⌨️ 快捷键说明

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