Synopsis - Cross-Reference
File: /Synopsis/Parsers/IDL/idlutil.cc1// -*- c++ -*- 2// Package : omniidl 3// idlutil.cc Created on: 1999/10/11 4// Author : Duncan Grisby (dpg1) 5// 6// Copyright (C) 1999 AT&T Laboratories Cambridge 7// 8// This file is part of omniidl. 9// 10// omniidl is free software; you can redistribute it and/or modify it 11// under the terms of the GNU General Public License as published by 12// the Free Software Foundation; either version 2 of the License, or 13// (at your option) any later version. 14// 15// This program is distributed in the hope that it will be useful, 16// but WITHOUT ANY WARRANTY; without even the implied warranty of 17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18// General Public License for more details. 19// 20// You should have received a copy of the GNU General Public License 21// along with this program; if not, write to the Free Software 22// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 23// 02111-1307, USA. 24// 25// Description: 26// 27// Utility functions 28 29// $Id: idlutil.cc,v 1.11.2.1 2003/03/23 21:01:43 dgrisby Exp $ 30// $Log: idlutil.cc,v $ 31// Revision 1.11.2.1 2003/03/23 21:01:43 dgrisby 32// Start of omniORB 4.1.x development branch. 33// 34// Revision 1.5.2.7 2003/01/16 11:08:27 dgrisby 35// Patches to support Digital Mars C++. Thanks Christof Meerwald. 36// 37// Revision 1.5.2.6 2002/01/15 16:38:14 dpg1 38// On the road to autoconf. Dependencies refactored, configure.ac 39// written. No makefiles yet. 40// 41// Revision 1.5.2.5 2001/06/21 11:17:15 sll 42// Added darwin port. 43// 44// Revision 1.5.2.4 2001/06/08 17:12:24 dpg1 45// Merge all the bug fixes from omni3_develop. 46// 47// Revision 1.5.2.3 2000/10/27 16:31:10 dpg1 48// Clean up of omniidl dependencies and types, from omni3_develop. 49// 50// Revision 1.5.2.2 2000/10/10 10:18:51 dpg1 51// Update omniidl front-end from omni3_develop. 52// 53// Revision 1.3.2.2 2000/09/22 10:50:21 dpg1 54// Digital Unix uses strtoul, not strtoull 55// 56// Revision 1.3.2.1 2000/08/07 15:34:36 dpg1 57// Partial back-port of long long from omni3_1_develop. 58// 59// Revision 1.3 1999/11/04 17:16:54 dpg1 60// Changes for NT. 61// 62// Revision 1.2 1999/11/02 17:07:24 dpg1 63// Changes to compile on Solaris. 64// 65// Revision 1.1 1999/10/27 14:05:54 dpg1 66// *** empty log message *** 67// 68 69#include <string.h> 70#include <stdlib.h> 71#include <stdio.h> 72#include <idlutil.h> 73 74char* idl_strdup(const char* s) 75{ 76 if (s) { 77 char* ret = new char[strlen(s)+1]; 78 strcpy(ret, s); 79 return ret; 80 } 81 else 82 return 0; 83} 84 85IDL_WChar* idl_wstrdup(const IDL_WChar* s) 86{ 87 if (s) { 88 int i, len; 89 for (len=0; s[len]; len++); 90 IDL_WChar* ret = new IDL_WChar[len+1]; 91 for (i=0; i<len; i++) 92 ret[i] = s[i]; 93 ret[i] = 0; 94 return ret; 95 } 96 else 97 return 0; 98} 99 100int idl_wstrlen(const IDL_WChar* s) 101{ 102 int l; 103 for (l=0; *s; ++s, ++l); 104 return l; 105} 106 107IDL_WChar* idl_wstrcpy(IDL_WChar* a, const IDL_WChar* b) 108{ 109 IDL_WChar* r = a; 110 for (; *b; ++a, ++b) *a = *b; 111 *a = 0; 112 return r; 113} 114 115 116IDL_WChar* idl_wstrcat(IDL_WChar* a, const IDL_WChar* b) 117{ 118 IDL_WChar* r = a; 119 for (; *a; ++a); 120 for (; *b; ++a, ++b) *a = *b; 121 *a = 0; 122 return r; 123} 124 125#ifndef HAVE_STRCASECMP 126#include <ctype.h> 127 128int strcasecmp(const char* s1, const char* s2) 129{ 130 for (; *s1 && *s2; ++s1, ++s2) 131 if (toupper(*s1) != toupper(*s2)) 132 break; 133 134 if (!*s1 && !*s2) return 0; 135 else if (toupper(*s1) < toupper(*s2)) return -1; 136 else return 1; 137} 138#endif 139 140 141#ifdef HAS_LongLong 142 143# if defined(_MSC_VER) 144 145IdlIntLiteral 146idl_strtoul(const char* text, int base) 147{ 148 IdlIntLiteral ull; 149 switch (base) { 150 case 8: 151 sscanf(text, "%I64o", &ull); 152 break; 153 case 10: 154 sscanf(text, "%I64d", &ull); 155 break; 156 case 16: 157 sscanf(text, "%I64x", &ull); 158 break; 159 default: 160 abort(); 161 } 162 return ull; 163} 164 165# elif defined(__hpux__) 166 167IdlIntLiteral 168idl_strtoul(const char* text, int base) 169{ 170 IdlIntLiteral ull; 171 switch (base) { 172 case 8: 173 sscanf(text, "%llo", &ull); 174 break; 175 case 10: 176 sscanf(text, "%lld", &ull); 177 break; 178 case 16: 179 sscanf(text, "%llx", &ull); 180 break; 181 default: 182 abort(); 183 } 184 return ull; 185} 186 187# elif defined(HAVE_STRTOUL) && SIZEOF_LONG == 8 188 189IdlIntLiteral 190idl_strtoul(const char* text, int base) 191{ 192 return strtoul(text, 0, base); 193} 194 195# elif defined(HAVE_STRTOUQ) 196 197IdlIntLiteral 198idl_strtoul(const char* text, int base) 199{ 200 return strtouq(text, 0, base); 201} 202 203# elif defined(HAVE_STRTOULL) 204 205IdlIntLiteral 206idl_strtoul(const char* text, int base) 207{ 208 return strtoull(text, 0, base); 209} 210 211# else 212 213IdlIntLiteral 214idl_strtoul(const char* text, int base) 215{ 216 return strtoul(text, 0, base); 217} 218 219# endif 220 221#else 222 223// No long long support 224 225IdlIntLiteral 226idl_strtoul(const char* text, int base) 227{ 228 return strtoul(text, 0, base); 229} 230 231#endif 232 233 234IdlFloatLiteral 235idl_strtod(const char* text) 236{ 237 // *** Should cope with long double 238 return strtod(text,0); 239}