| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | #include <cstdlib> |
| 38 | #include <ctype.h> |
| 39 | #include "Man.h"cxx . . $ `<file>/doc/man/ivman/Man.h`/ |
| 40 | |
| 41 | ///////////////////////////////////////////////////////////////////////////// |
| 42 | // |
| 43 | // Class: Reader |
| 44 | // |
| 45 | ///////////////////////////////////////////////////////////////////////////// |
| 46 | |
| 47 | FILE *Readercxx . . $ Reader#::fpcxx . . $ Reader#fp.; |
| 48 | int Readercxx . . $ Reader#::lineNumcxx . . $ Reader#lineNum.; |
| 49 | char *Readercxx . . $ Reader#::fullNamecxx . . $ Reader#fullName. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 50 | |
| 51 | #define BUFSIZEcxx . . $ `doc/man/ivman/Reader.c++:51:9`! 1024 |
| 52 | |
| 53 | SbBoolcxx . . $ SbBool# |
| 54 | Readercxx . . $ Reader#::opencxx . . $ Reader#open(5c4306d8553b3696).(const char *pathName) |
| 55 | { |
| 56 | if (fullNamecxx . . $ Reader#fullName. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) |
| 57 | free(fullNamecxx . . $ Reader#fullName.); |
| 58 | |
| 59 | fullNamecxx . . $ Reader#fullName. = strdup(pathName); |
| 60 | |
| 61 | fpcxx . . $ Reader#fp. = fopen(fullNamecxx . . $ Reader#fullName., "r"); |
| 62 | |
| 63 | if (fpcxx . . $ Reader#fp. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) { |
| 64 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Couldn't open file \"%s\"\n", fullNamecxx . . $ Reader#fullName.); |
| 65 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 66 | } |
| 67 | |
| 68 | lineNumcxx . . $ Reader#lineNum. = 1; |
| 69 | |
| 70 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 71 | } |
| 72 | |
| 73 | SbBoolcxx . . $ SbBool# |
| 74 | Readercxx . . $ Reader#::opencxx . . $ Reader#open(5ae29d726ae57f88).(const char *dirName, const char *fileName) |
| 75 | { |
| 76 | SbStringcxx . . $ SbString# namecxx . . $ SbString#SbString(40cb438959dbb26f). = dirNamecxx . . $ SbString#SbString(85c52e162fed56f9).; |
| 77 | |
| 78 | name +=cxx . . $ SbString#`operator+=`(90e156a883234106). "/"; |
| 79 | name +=cxx . . $ SbString#`operator+=`(90e156a883234106). fileName; |
| 80 | |
| 81 | return opencxx . . $ Reader#open(5c4306d8553b3696).(name.getStringcxx . . $ SbString#getString(a9f41ea0e82d88cf).()); |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | Readercxx . . $ Reader#::errorcxx . . $ Reader#error(85c52e162fed56f9).(const char *what) |
| 86 | { |
| 87 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error reading %s on line %d of \"%s\"\n", |
| 88 | what, lineNumcxx . . $ Reader#lineNum., fullNamecxx . . $ Reader#fullName.); |
| 89 | } |
| 90 | |
| 91 | SbBoolcxx . . $ SbBool# |
| 92 | Readercxx . . $ Reader#::readNamecxx . . $ Reader#readName(5a5be675804373ca).(SbNamecxx . . $ SbName# &name) |
| 93 | { |
| 94 | char buf[132]; |
| 95 | |
| 96 | if (! readBufcxx . . $ Reader#readBuf(6abd07ddb1a912f0).(buf, TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!)) |
| 97 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 98 | |
| 99 | name =cxx . . $ SbName#`operator=`(8da52b6fc1e0f7c6). bufcxx . . $ SbName#SbName(85c52e162fed56f9).; |
| 100 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 101 | } |
| 102 | |
| 103 | SbBoolcxx . . $ SbBool# |
| 104 | Readercxx . . $ Reader#::readStringcxx . . $ Reader#readString(279155daee2f202d).(SbStringcxx . . $ SbString# &string) |
| 105 | { |
| 106 | char buf[2048]; |
| 107 | |
| 108 | if (! readBufcxx . . $ Reader#readBuf(6abd07ddb1a912f0).(buf, FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!)) |
| 109 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 110 | |
| 111 | string =cxx . . $ SbString#`operator=`(90e156a883234106). buf; |
| 112 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 113 | } |
| 114 | |
| 115 | SbBoolcxx . . $ SbBool# |
| 116 | Readercxx . . $ Reader#::readBracketedcxx . . $ Reader#readBracketed(279155daee2f202d).(SbStringcxx . . $ SbString# &string) |
| 117 | { |
| 118 | char buf[BUFSIZEcxx . . $ `doc/man/ivman/Reader.c++:51:9`!]; |
| 119 | int c, c2, i = 0; |
| 120 | |
| 121 | string.makeEmptycxx . . $ SbString#makeEmpty(d4f767463ce0a6b3).(); |
| 122 | |
| 123 | skipWhiteSpacecxx . . $ Reader#skipWhiteSpace(49f6e7a06ebc5aa8).(); |
| 124 | |
| 125 | // Read open brace character |
| 126 | if (getcxx . . $ Reader#get(b126dc7c1de90089).() != OPEN_CHARcxx . . $ `doc/man/ivman/Man.h:434:9`!) |
| 127 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 128 | |
| 129 | skipWhiteSpacecxx . . $ Reader#skipWhiteSpace(49f6e7a06ebc5aa8).(); |
| 130 | |
| 131 | // Read characters into buffer until close brace or EOF |
| 132 | while ((c = getcxx . . $ Reader#get(b126dc7c1de90089).()) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! && c != CLOSE_CHARcxx . . $ `doc/man/ivman/Man.h:435:9`!) { |
| 133 | |
| 134 | // Check for backslash-open/close sequence |
| 135 | if (c == '\\') { |
| 136 | if ((c2 = getcxx . . $ Reader#get(b126dc7c1de90089).()) == OPEN_CHARcxx . . $ `doc/man/ivman/Man.h:434:9`! || c2 == CLOSE_CHARcxx . . $ `doc/man/ivman/Man.h:435:9`!) |
| 137 | c = c2; |
| 138 | else |
| 139 | putBackcxx . . $ Reader#putBack(d4f767463ce0a6b3).(c2); |
| 140 | } |
| 141 | |
| 142 | buf[i++] = c; |
| 143 | |
| 144 | // If the buffer is full, add it to the string and get ready |
| 145 | // for more |
| 146 | if (i == BUFSIZEcxx . . $ `doc/man/ivman/Reader.c++:51:9`! - 1) { |
| 147 | buf[i] = '\0'; |
| 148 | string +=cxx . . $ SbString#`operator+=`(90e156a883234106). buf; |
| 149 | i = 0; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if (c != CLOSE_CHARcxx . . $ `doc/man/ivman/Man.h:435:9`!) |
| 154 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 155 | |
| 156 | // Add rest of buffer to string |
| 157 | if (i > 0) { |
| 158 | buf[i] = '\0'; |
| 159 | string +=cxx . . $ SbString#`operator+=`(90e156a883234106). buf; |
| 160 | } |
| 161 | |
| 162 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 163 | } |
| 164 | |
| 165 | SbBoolcxx . . $ SbBool# |
| 166 | Readercxx . . $ Reader#::readUpTocxx . . $ Reader#readUpTo(f3c82169505fa0ac).(int endChar, SbStringcxx . . $ SbString# &string) |
| 167 | { |
| 168 | char buf[BUFSIZEcxx . . $ `doc/man/ivman/Reader.c++:51:9`!]; |
| 169 | int c, i = 0; |
| 170 | |
| 171 | string.makeEmptycxx . . $ SbString#makeEmpty(d4f767463ce0a6b3).(); |
| 172 | |
| 173 | skipWhiteSpacecxx . . $ Reader#skipWhiteSpace(49f6e7a06ebc5aa8).(); |
| 174 | |
| 175 | // Read characters into buffer until given char or EOF |
| 176 | while ((c = getcxx . . $ Reader#get(b126dc7c1de90089).()) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! && c != endChar) { |
| 177 | |
| 178 | buf[i++] = c; |
| 179 | |
| 180 | // If the buffer is full, add it to the string and get ready |
| 181 | // for more |
| 182 | if (i == BUFSIZEcxx . . $ `doc/man/ivman/Reader.c++:51:9`! - 1) { |
| 183 | buf[i] = '\0'; |
| 184 | string +=cxx . . $ SbString#`operator+=`(90e156a883234106). buf; |
| 185 | i = 0; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if (c != endChar) |
| 190 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 191 | |
| 192 | putBackcxx . . $ Reader#putBack(d4f767463ce0a6b3).(c); |
| 193 | |
| 194 | // Add rest of buffer to string |
| 195 | if (i > 0) { |
| 196 | buf[i] = '\0'; |
| 197 | string +=cxx . . $ SbString#`operator+=`(90e156a883234106). buf; |
| 198 | } |
| 199 | |
| 200 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 201 | } |
| 202 | |
| 203 | SbBoolcxx . . $ SbBool# |
| 204 | Readercxx . . $ Reader#::readBufcxx . . $ Reader#readBuf(6abd07ddb1a912f0).(char *buf, SbBoolcxx . . $ SbBool# isName) |
| 205 | { |
| 206 | int c; |
| 207 | |
| 208 | skipWhiteSpacecxx . . $ Reader#skipWhiteSpace(49f6e7a06ebc5aa8).(); |
| 209 | |
| 210 | // See if stuff is quoted |
| 211 | if ((c = getcxx . . $ Reader#get(b126dc7c1de90089).()) == QUOTE_CHARcxx . . $ `doc/man/ivman/Man.h:433:9`!) { |
| 212 | char *b = buf; |
| 213 | |
| 214 | c = getcxx . . $ Reader#get(b126dc7c1de90089).(); |
| 215 | |
| 216 | while (c != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! && c != QUOTE_CHARcxx . . $ `doc/man/ivman/Man.h:433:9`!) { |
| 217 | *b++ = c; |
| 218 | c = getcxx . . $ Reader#get(b126dc7c1de90089).(); |
| 219 | } |
| 220 | *b = '\0'; |
| 221 | |
| 222 | if (c != QUOTE_CHARcxx . . $ `doc/man/ivman/Man.h:433:9`!) |
| 223 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 224 | } |
| 225 | |
| 226 | else { |
| 227 | char *b = buf; |
| 228 | |
| 229 | putBackcxx . . $ Reader#putBack(d4f767463ce0a6b3).(c); |
| 230 | |
| 231 | // If reading a name, stop at a separator character |
| 232 | while ((c = getcxx . . $ Reader#get(b126dc7c1de90089).()) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! && ! isspace(c)) { |
| 233 | if (isName && c == SEP_CHARcxx . . $ `doc/man/ivman/Man.h:437:9`!) |
| 234 | break; |
| 235 | *b++ = c; |
| 236 | } |
| 237 | *b = '\0'; |
| 238 | |
| 239 | if (b == buf) |
| 240 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 241 | |
| 242 | if (c != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!) |
| 243 | putBackcxx . . $ Reader#putBack(d4f767463ce0a6b3).(c); |
| 244 | } |
| 245 | |
| 246 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 247 | } |
| 248 | |
| 249 | void |
| 250 | Readercxx . . $ Reader#::skipWhiteSpacecxx . . $ Reader#skipWhiteSpace(49f6e7a06ebc5aa8).() |
| 251 | { |
| 252 | int c; |
| 253 | |
| 254 | while (1) { |
| 255 | |
| 256 | // Skip over space characters |
| 257 | while ((c = getcxx . . $ Reader#get(b126dc7c1de90089).()) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! && isspace(c)) |
| 258 | ; |
| 259 | |
| 260 | // Check for comment just after the space |
| 261 | if (c == COMMENT_CHARcxx . . $ `doc/man/ivman/Man.h:436:9`!) { |
| 262 | |
| 263 | // Skip all characters up to next newline |
| 264 | while ((c = getcxx . . $ Reader#get(b126dc7c1de90089).()) != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! && c != '\n') |
| 265 | ; |
| 266 | } |
| 267 | |
| 268 | // No comment? Stop! |
| 269 | else |
| 270 | break; |
| 271 | } |
| 272 | |
| 273 | // Put the last character (if any) back |
| 274 | if (c != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!) |
| 275 | putBackcxx . . $ Reader#putBack(d4f767463ce0a6b3).(c); |
| 276 | } |
| 277 | |
| 278 | int |
| 279 | Readercxx . . $ Reader#::getcxx . . $ Reader#get(b126dc7c1de90089).() |
| 280 | { |
| 281 | int c = getc(fpcxx . . $ Reader#fp.); |
| 282 | |
| 283 | if (c == '\n') |
| 284 | lineNumcxx . . $ Reader#lineNum.++; |
| 285 | |
| 286 | return c; |
| 287 | } |
| 288 | |
| 289 | void |
| 290 | Readercxx . . $ Reader#::putBackcxx . . $ Reader#putBack(d4f767463ce0a6b3).(int c) |
| 291 | { |
| 292 | if (c == '\n') |
| 293 | lineNumcxx . . $ Reader#lineNum.--; |
| 294 | |
| 295 | ungetc(c, fpcxx . . $ Reader#fp.); |
| 296 | } |
| 297 | |
| 298 | void |
| 299 | Readercxx . . $ Reader#::cleanStringcxx . . $ Reader#cleanString(2b29f0bee232e7a6).(SbStringcxx . . $ SbString# &string, SbBoolcxx . . $ SbBool# inCode, SbBoolcxx . . $ SbBool# changeSbName) |
| 300 | { |
| 301 | const char *s = string.getStringcxx . . $ SbString#getString(a9f41ea0e82d88cf).(); |
| 302 | int len = string.getLengthcxx . . $ SbString#getLength(455f465bc33b4cdf).(); |
| 303 | char realbuf[2048], *buf, *b; |
| 304 | SbStringcxx . . $ SbString# cleanStringcxx . . $ SbString#SbString(49f6e7a06ebc5aa8).; |
| 305 | |
| 306 | |
| 307 | if (len >= 2048) |
| 308 | buf = new char[len + 1]; |
| 309 | else |
| 310 | buf = realbuf; |
| 311 | |
| 312 | // Remove leading spaces |
| 313 | while (isspace(*s)) |
| 314 | s++; |
| 315 | |
| 316 | b = buf; |
| 317 | |
| 318 | while (*s != '\0') { |
| 319 | |
| 320 | // Copy non-space stuff |
| 321 | while (*s != '\0' && ! isspace(*s)) |
| 322 | *b++ = *s++; |
| 323 | |
| 324 | // Condense spaces |
| 325 | if (isspace(*s)) { |
| 326 | // Don't allow spaces after open parens in code |
| 327 | if (inCode && b > buf && *(b-1) == '(') |
| 328 | ; |
| 329 | else |
| 330 | *b++ = ' '; |
| 331 | s++; |
| 332 | while (isspace(*s)) |
| 333 | s++; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Remove trailing space, if any |
| 338 | if (b > buf && *(b - 1) == ' ') |
| 339 | b--; |
| 340 | |
| 341 | // Terminate string |
| 342 | *b = '\0'; |
| 343 | |
| 344 | // Replace "const SbName &" with "const char *" in the C version |
| 345 | // but only if the class name is not SbName. |
| 346 | if ((Writercxx . . $ Writer#::getLanguagecxx . . $ Writer#getLanguage(b9e98e30316a2b42).() == Ccxx . . $ C.) && changeSbName && |
| 347 | (ClassDefcxx . . $ ClassDef#::getCurClasscxx . . $ ClassDef#getCurClass(5a8991f52c1dc640).()->getNamecxx . . $ ClassDef#getName(96f83ea34e3884f5).() !=cxx . . $ `operator!=`(1deca42c6f82b65f). "SbName")) { |
| 348 | for (b = buf; *b != '\0'; b++) |
| 349 | if ( !strncmp(b,"const SbName &", 14) ) { |
| 350 | b[0] = 'c'; |
| 351 | b[1] = 'o'; |
| 352 | b[2] = 'n'; |
| 353 | b[3] = 's'; |
| 354 | b[4] = 't'; |
| 355 | b[5] = ' '; |
| 356 | b[6] = 'c'; |
| 357 | b[7] = 'h'; |
| 358 | b[8] = 'a'; |
| 359 | b[9] = 'r'; |
| 360 | b[10]= ' '; |
| 361 | b[11]= '*'; |
| 362 | b[12]= ' '; |
| 363 | b[13]= ' '; |
| 364 | // We just created two extra spaces at the end. So we |
| 365 | // need to move everything over. |
| 366 | char *q = b+12; |
| 367 | while (*q != '\0') { |
| 368 | *q = q[2]; |
| 369 | q++; |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // Replace references (&) with pointers (*) in the C version |
| 375 | if (Writercxx . . $ Writer#::getLanguagecxx . . $ Writer#getLanguage(b9e98e30316a2b42).() == Ccxx . . $ C.) |
| 376 | for (b = buf; *b != '\0'; b++) |
| 377 | if (*b == '&') |
| 378 | *b = '*'; |
| 379 | |
| 380 | string =cxx . . $ SbString#`operator=`(90e156a883234106). buf; |
| 381 | |
| 382 | if (len >= 2048) |
| 383 | delete [] buf; |
| 384 | } |