PageRenderTime 65ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/gsoc2008-cherylfoil/Source/Swig/misc.c

#
C | 1092 lines | 1028 code | 20 blank | 44 comment | 32 complexity | 373b4d150565e7225d75b630ac0d5c31 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * This file is part of SWIG, which is licensed as a whole under version 3
  3. * (or any later version) of the GNU General Public License. Some additional
  4. * terms also apply to certain portions of SWIG. The full details of the SWIG
  5. * license and copyrights can be found in the LICENSE and COPYRIGHT files
  6. * included with the SWIG source code as distributed by the SWIG developers
  7. * and at http://www.swig.org/legal.html.
  8. *
  9. * misc.c
  10. *
  11. * Miscellaneous functions that don't really fit anywhere else.
  12. * ----------------------------------------------------------------------------- */
  13. char cvsroot_misc_c[] = "$Id: misc.c 11900 2010-03-05 23:43:39Z wsfulton $";
  14. #include "swig.h"
  15. #include <errno.h>
  16. #include <ctype.h>
  17. #include <limits.h>
  18. static char *fake_version = 0;
  19. /* -----------------------------------------------------------------------------
  20. * Swig_copy_string()
  21. *
  22. * Duplicate a NULL-terminate string given as a char *.
  23. * ----------------------------------------------------------------------------- */
  24. char *Swig_copy_string(const char *s) {
  25. char *c = 0;
  26. if (s) {
  27. c = (char *) malloc(strlen(s) + 1);
  28. strcpy(c, s);
  29. }
  30. return c;
  31. }
  32. /* -----------------------------------------------------------------------------
  33. * Swig_set_fakeversion()
  34. *
  35. * Version string override
  36. * ----------------------------------------------------------------------------- */
  37. void Swig_set_fakeversion(const char *version) {
  38. fake_version = Swig_copy_string(version);
  39. }
  40. /* -----------------------------------------------------------------------------
  41. * Swig_package_version()
  42. *
  43. * Return the package string containing the version number
  44. * ----------------------------------------------------------------------------- */
  45. const char *Swig_package_version(void) {
  46. return fake_version ? fake_version : PACKAGE_VERSION;
  47. }
  48. /* -----------------------------------------------------------------------------
  49. * Swig_banner()
  50. *
  51. * Emits the SWIG identifying banner.
  52. * ----------------------------------------------------------------------------- */
  53. void Swig_banner(File *f) {
  54. Printf(f, "/* ----------------------------------------------------------------------------\n\
  55. * This file was automatically generated by SWIG (http://www.swig.org).\n\
  56. * Version %s\n\
  57. * \n\
  58. * This file is not intended to be easily readable and contains a number of \n\
  59. * coding conventions designed to improve portability and efficiency. Do not make\n\
  60. * changes to this file unless you know what you are doing--modify the SWIG \n\
  61. * interface file instead. \n", Swig_package_version());
  62. /* String too long for ISO compliance */
  63. Printf(f, " * ----------------------------------------------------------------------------- */\n\n");
  64. }
  65. /* -----------------------------------------------------------------------------
  66. * Swig_strip_c_comments()
  67. *
  68. * Return a new string with C comments stripped from the input string. Null is
  69. * returned if there aren't any.
  70. * ----------------------------------------------------------------------------- */
  71. String *Swig_strip_c_comments(const String *s) {
  72. const char *c = Char(s);
  73. const char *comment_begin = 0;
  74. const char *comment_end = 0;
  75. String *stripped = 0;
  76. while (*c) {
  77. if (!comment_begin && *c == '/') {
  78. ++c;
  79. if (!*c)
  80. break;
  81. if (*c == '*')
  82. comment_begin = c-1;
  83. } else if (comment_begin && !comment_end && *c == '*') {
  84. ++c;
  85. if (*c == '/')
  86. comment_end = c;
  87. break;
  88. }
  89. ++c;
  90. }
  91. if (comment_begin && comment_end) {
  92. int size = comment_begin - Char(s);
  93. String *stripmore = 0;
  94. stripped = NewStringWithSize(s, size);
  95. Printv(stripped, comment_end + 1, NIL);
  96. do {
  97. stripmore = Swig_strip_c_comments(stripped);
  98. if (stripmore) {
  99. Delete(stripped);
  100. stripped = stripmore;
  101. }
  102. } while (stripmore);
  103. }
  104. return stripped;
  105. }
  106. /* -----------------------------------------------------------------------------
  107. * Swig_string_escape()
  108. *
  109. * Takes a string object and produces a string with escape codes added to it.
  110. * ----------------------------------------------------------------------------- */
  111. String *Swig_string_escape(String *s) {
  112. String *ns;
  113. int c;
  114. ns = NewStringEmpty();
  115. while ((c = Getc(s)) != EOF) {
  116. if (c == '\n') {
  117. Printf(ns, "\\n");
  118. } else if (c == '\r') {
  119. Printf(ns, "\\r");
  120. } else if (c == '\t') {
  121. Printf(ns, "\\t");
  122. } else if (c == '\\') {
  123. Printf(ns, "\\\\");
  124. } else if (c == '\'') {
  125. Printf(ns, "\\'");
  126. } else if (c == '\"') {
  127. Printf(ns, "\\\"");
  128. } else if (c == ' ') {
  129. Putc(c, ns);
  130. } else if (!isgraph(c)) {
  131. if (c < 0)
  132. c += UCHAR_MAX + 1;
  133. Printf(ns, "\\%o", c);
  134. } else {
  135. Putc(c, ns);
  136. }
  137. }
  138. return ns;
  139. }
  140. /* -----------------------------------------------------------------------------
  141. * Swig_string_upper()
  142. *
  143. * Takes a string object and returns a copy that is uppercase
  144. * ----------------------------------------------------------------------------- */
  145. String *Swig_string_upper(String *s) {
  146. String *ns;
  147. int c;
  148. ns = NewStringEmpty();
  149. Seek(s, 0, SEEK_SET);
  150. while ((c = Getc(s)) != EOF) {
  151. Putc(toupper(c), ns);
  152. }
  153. return ns;
  154. }
  155. /* -----------------------------------------------------------------------------
  156. * Swig_string_lower()
  157. *
  158. * Takes a string object and returns a copy that is lowercase
  159. * ----------------------------------------------------------------------------- */
  160. String *Swig_string_lower(String *s) {
  161. String *ns;
  162. int c;
  163. ns = NewStringEmpty();
  164. Seek(s, 0, SEEK_SET);
  165. while ((c = Getc(s)) != EOF) {
  166. Putc(tolower(c), ns);
  167. }
  168. return ns;
  169. }
  170. /* -----------------------------------------------------------------------------
  171. * Swig_string_title()
  172. *
  173. * Takes a string object and returns a copy that is lowercase with first letter
  174. * capitalized
  175. * ----------------------------------------------------------------------------- */
  176. String *Swig_string_title(String *s) {
  177. String *ns;
  178. int first = 1;
  179. int c;
  180. ns = NewStringEmpty();
  181. Seek(s, 0, SEEK_SET);
  182. while ((c = Getc(s)) != EOF) {
  183. Putc(first ? toupper(c) : tolower(c), ns);
  184. first = 0;
  185. }
  186. return ns;
  187. }
  188. /* -----------------------------------------------------------------------------
  189. * Swig_string_ccase()
  190. *
  191. * Takes a string object and returns a copy that is lowercase with the first
  192. * letter capitalized and the one following '_', which are removed.
  193. *
  194. * camel_case -> CamelCase
  195. * camelCase -> CamelCase
  196. * ----------------------------------------------------------------------------- */
  197. String *Swig_string_ccase(String *s) {
  198. String *ns;
  199. int first = 1;
  200. int c;
  201. ns = NewStringEmpty();
  202. Seek(s, 0, SEEK_SET);
  203. while ((c = Getc(s)) != EOF) {
  204. if (c == '_') {
  205. first = 1;
  206. continue;
  207. }
  208. Putc(first ? toupper(c) : c, ns);
  209. first = 0;
  210. }
  211. return ns;
  212. }
  213. /* -----------------------------------------------------------------------------
  214. * Swig_string_lccase()
  215. *
  216. * Takes a string object and returns a copy with the character after
  217. * each '_' capitalised, and the '_' removed. The first character is
  218. * also forced to lowercase.
  219. *
  220. * camel_case -> camelCase
  221. * CamelCase -> camelCase
  222. * ----------------------------------------------------------------------------- */
  223. String *Swig_string_lccase(String *s) {
  224. String *ns;
  225. int first = 1;
  226. int after_underscore = 0;
  227. int c;
  228. ns = NewStringEmpty();
  229. Seek(s, 0, SEEK_SET);
  230. while ((c = Getc(s)) != EOF) {
  231. if (c == '_') {
  232. after_underscore = 1;
  233. continue;
  234. }
  235. if (first) {
  236. Putc(tolower(c), ns);
  237. first = 0;
  238. } else {
  239. Putc(after_underscore ? toupper(c) : c, ns);
  240. }
  241. after_underscore = 0;
  242. }
  243. return ns;
  244. }
  245. /* -----------------------------------------------------------------------------
  246. * Swig_string_ucase()
  247. *
  248. * This is the reverse case of ccase, ie
  249. *
  250. * CamelCase -> camel_case
  251. * get2D -> get_2d
  252. * asFloat2 -> as_float2
  253. * ----------------------------------------------------------------------------- */
  254. String *Swig_string_ucase(String *s) {
  255. String *ns;
  256. int c;
  257. int lastC = 0;
  258. int nextC = 0;
  259. int underscore = 0;
  260. ns = NewStringEmpty();
  261. /* We insert a underscore when:
  262. 1. Lower case char followed by upper case char
  263. getFoo > get_foo; getFOo > get_foo; GETFOO > getfoo
  264. 2. Number proceded by char and not end of string
  265. get2D > get_2d; get22D > get_22d; GET2D > get_2d
  266. but:
  267. asFloat2 > as_float2
  268. */
  269. Seek(s, 0, SEEK_SET);
  270. while ((c = Getc(s)) != EOF) {
  271. nextC = Getc(s); Ungetc(nextC, s);
  272. if (isdigit(c) && isalpha(lastC) && nextC != EOF)
  273. underscore = 1;
  274. else if (isupper(c) && isalpha(lastC) && !isupper(lastC))
  275. underscore = 1;
  276. lastC = c;
  277. if (underscore) {
  278. Putc('_', ns);
  279. underscore = 0;
  280. }
  281. Putc(tolower(c), ns);
  282. }
  283. return ns;
  284. }
  285. /* -----------------------------------------------------------------------------
  286. * Swig_string_first_upper()
  287. *
  288. * Make the first character in the string uppercase, leave all the
  289. * rest the same. This is used by the Ruby module to provide backwards
  290. * compatibility with the old way of naming classes and constants. For
  291. * more info see the Ruby documentation.
  292. *
  293. * firstUpper -> FirstUpper
  294. * ----------------------------------------------------------------------------- */
  295. String *Swig_string_first_upper(String *s) {
  296. String *ns = NewStringEmpty();
  297. char *cs = Char(s);
  298. if (cs && cs[0] != 0) {
  299. Putc(toupper((int)cs[0]), ns);
  300. Append(ns, cs + 1);
  301. }
  302. return ns;
  303. }
  304. /* -----------------------------------------------------------------------------
  305. * Swig_string_first_lower()
  306. *
  307. * Make the first character in the string lowercase, leave all the
  308. * rest the same. This is used by the Ruby module to provide backwards
  309. * compatibility with the old way of naming classes and constants. For
  310. * more info see the Ruby documentation.
  311. *
  312. * firstLower -> FirstLower
  313. * ----------------------------------------------------------------------------- */
  314. String *Swig_string_first_lower(String *s) {
  315. String *ns = NewStringEmpty();
  316. char *cs = Char(s);
  317. if (cs && cs[0] != 0) {
  318. Putc(tolower((int)cs[0]), ns);
  319. Append(ns, cs + 1);
  320. }
  321. return ns;
  322. }
  323. /* -----------------------------------------------------------------------------
  324. * Swig_string_schemify()
  325. *
  326. * Replace underscores with dashes, to make identifiers look nice to Schemers.
  327. *
  328. * under_scores -> under-scores
  329. * ----------------------------------------------------------------------------- */
  330. String *Swig_string_schemify(String *s) {
  331. String *ns = NewString(s);
  332. Replaceall(ns, "_", "-");
  333. return ns;
  334. }
  335. /* -----------------------------------------------------------------------------
  336. * Swig_string_typecode()
  337. *
  338. * Takes a string with possible type-escapes in it and replaces them with
  339. * real C datatypes.
  340. * ----------------------------------------------------------------------------- */
  341. String *Swig_string_typecode(String *s) {
  342. String *ns;
  343. int c;
  344. String *tc;
  345. ns = NewStringEmpty();
  346. while ((c = Getc(s)) != EOF) {
  347. if (c == '`') {
  348. String *str = 0;
  349. tc = NewStringEmpty();
  350. while ((c = Getc(s)) != EOF) {
  351. if (c == '`')
  352. break;
  353. Putc(c, tc);
  354. }
  355. str = SwigType_str(tc, 0);
  356. Append(ns, str);
  357. Delete(str);
  358. } else {
  359. Putc(c, ns);
  360. if (c == '\'') {
  361. while ((c = Getc(s)) != EOF) {
  362. Putc(c, ns);
  363. if (c == '\'')
  364. break;
  365. if (c == '\\') {
  366. c = Getc(s);
  367. Putc(c, ns);
  368. }
  369. }
  370. } else if (c == '\"') {
  371. while ((c = Getc(s)) != EOF) {
  372. Putc(c, ns);
  373. if (c == '\"')
  374. break;
  375. if (c == '\\') {
  376. c = Getc(s);
  377. Putc(c, ns);
  378. }
  379. }
  380. }
  381. }
  382. }
  383. return ns;
  384. }
  385. /* -----------------------------------------------------------------------------
  386. * Swig_string_mangle()
  387. *
  388. * Take a string and mangle it by stripping all non-valid C identifier
  389. * characters.
  390. *
  391. * This routine skips unnecessary blank spaces, therefore mangling
  392. * 'char *' and 'char*', 'std::pair<int, int >' and
  393. * 'std::pair<int,int>', produce the same result.
  394. *
  395. * However, note that 'long long' and 'long_long' produce different
  396. * mangled strings.
  397. *
  398. * The mangling method still is not 'perfect', for example std::pair and
  399. * std_pair return the same mangling. This is just a little better
  400. * than before, but it seems to be enough for most of the purposes.
  401. *
  402. * Having a perfect mangling will break some examples and code which
  403. * assume, for example, that A::get_value will be mangled as
  404. * A_get_value.
  405. * ----------------------------------------------------------------------------- */
  406. String *Swig_string_mangle(const String *s) {
  407. #if 0
  408. /* old mangling, not suitable for using in macros */
  409. String *t = Copy(s);
  410. char *c = Char(t);
  411. while (*c) {
  412. if (!isalnum(*c))
  413. *c = '_';
  414. c++;
  415. }
  416. return t;
  417. #else
  418. String *result = NewStringEmpty();
  419. int space = 0;
  420. int state = 0;
  421. char *pc, *cb;
  422. String *b = Copy(s);
  423. if (SwigType_istemplate(b)) {
  424. String *st = Swig_symbol_template_deftype(b, 0);
  425. String *sq = Swig_symbol_type_qualify(st, 0);
  426. String *t = SwigType_namestr(sq);
  427. Delete(st);
  428. Delete(sq);
  429. Delete(b);
  430. b = t;
  431. }
  432. pc = cb = Char(b);
  433. while (*pc) {
  434. char c = *pc;
  435. if (isalnum((int) c) || (c == '_')) {
  436. state = 1;
  437. if (space && (space == state)) {
  438. Append(result, "_SS_");
  439. }
  440. space = 0;
  441. Printf(result, "%c", (int) c);
  442. } else {
  443. if (isspace((int) c)) {
  444. space = state;
  445. ++pc;
  446. continue;
  447. } else {
  448. state = 3;
  449. space = 0;
  450. }
  451. switch (c) {
  452. case '.':
  453. if ((cb != pc) && (*(pc - 1) == 'p')) {
  454. Append(result, "_");
  455. ++pc;
  456. continue;
  457. } else {
  458. c = 'f';
  459. }
  460. break;
  461. case ':':
  462. if (*(pc + 1) == ':') {
  463. Append(result, "_");
  464. ++pc;
  465. ++pc;
  466. continue;
  467. }
  468. break;
  469. case '*':
  470. c = 'm';
  471. break;
  472. case '&':
  473. c = 'A';
  474. break;
  475. case '<':
  476. c = 'l';
  477. break;
  478. case '>':
  479. c = 'g';
  480. break;
  481. case '=':
  482. c = 'e';
  483. break;
  484. case ',':
  485. c = 'c';
  486. break;
  487. case '(':
  488. c = 'p';
  489. break;
  490. case ')':
  491. c = 'P';
  492. break;
  493. case '[':
  494. c = 'b';
  495. break;
  496. case ']':
  497. c = 'B';
  498. break;
  499. case '^':
  500. c = 'x';
  501. break;
  502. case '|':
  503. c = 'o';
  504. break;
  505. case '~':
  506. c = 'n';
  507. break;
  508. case '!':
  509. c = 'N';
  510. break;
  511. case '%':
  512. c = 'M';
  513. break;
  514. case '?':
  515. c = 'q';
  516. break;
  517. case '+':
  518. c = 'a';
  519. break;
  520. case '-':
  521. c = 's';
  522. break;
  523. case '/':
  524. c = 'd';
  525. break;
  526. default:
  527. break;
  528. }
  529. if (isalpha((int) c)) {
  530. Printf(result, "_S%c_", (int) c);
  531. } else {
  532. Printf(result, "_S%02X_", (int) c);
  533. }
  534. }
  535. ++pc;
  536. }
  537. Delete(b);
  538. return result;
  539. #endif
  540. }
  541. String *Swig_string_emangle(String *s) {
  542. return Swig_string_mangle(s);
  543. }
  544. /* -----------------------------------------------------------------------------
  545. * Swig_scopename_prefix()
  546. *
  547. * Take a qualified name like "A::B::C" and return the scope name.
  548. * In this case, "A::B". Returns NULL if there is no base.
  549. * ----------------------------------------------------------------------------- */
  550. void Swig_scopename_split(String *s, String **rprefix, String **rlast) {
  551. char *tmp = Char(s);
  552. char *c = tmp;
  553. char *cc = c;
  554. char *co = 0;
  555. if (!strstr(c, "::")) {
  556. *rprefix = 0;
  557. *rlast = Copy(s);
  558. }
  559. co = strstr(cc, "operator ");
  560. if (co) {
  561. if (co == cc) {
  562. *rprefix = 0;
  563. *rlast = Copy(s);
  564. return;
  565. } else {
  566. *rprefix = NewStringWithSize(cc, co - cc - 2);
  567. *rlast = NewString(co);
  568. return;
  569. }
  570. }
  571. while (*c) {
  572. if ((*c == ':') && (*(c + 1) == ':')) {
  573. cc = c;
  574. c += 2;
  575. } else {
  576. if (*c == '<') {
  577. int level = 1;
  578. c++;
  579. while (*c && level) {
  580. if (*c == '<')
  581. level++;
  582. if (*c == '>')
  583. level--;
  584. c++;
  585. }
  586. } else {
  587. c++;
  588. }
  589. }
  590. }
  591. if (cc != tmp) {
  592. *rprefix = NewStringWithSize(tmp, cc - tmp);
  593. *rlast = NewString(cc + 2);
  594. return;
  595. } else {
  596. *rprefix = 0;
  597. *rlast = Copy(s);
  598. }
  599. }
  600. String *Swig_scopename_prefix(String *s) {
  601. char *tmp = Char(s);
  602. char *c = tmp;
  603. char *cc = c;
  604. char *co = 0;
  605. if (!strstr(c, "::"))
  606. return 0;
  607. co = strstr(cc, "operator ");
  608. if (co) {
  609. if (co == cc) {
  610. return 0;
  611. } else {
  612. String *prefix = NewStringWithSize(cc, co - cc - 2);
  613. return prefix;
  614. }
  615. }
  616. while (*c) {
  617. if ((*c == ':') && (*(c + 1) == ':')) {
  618. cc = c;
  619. c += 2;
  620. } else {
  621. if (*c == '<') {
  622. int level = 1;
  623. c++;
  624. while (*c && level) {
  625. if (*c == '<')
  626. level++;
  627. if (*c == '>')
  628. level--;
  629. c++;
  630. }
  631. } else {
  632. c++;
  633. }
  634. }
  635. }
  636. if (cc != tmp) {
  637. return NewStringWithSize(tmp, cc - tmp);
  638. } else {
  639. return 0;
  640. }
  641. }
  642. /* -----------------------------------------------------------------------------
  643. * Swig_scopename_last()
  644. *
  645. * Take a qualified name like "A::B::C" and returns the last. In this
  646. * case, "C".
  647. * ----------------------------------------------------------------------------- */
  648. String *Swig_scopename_last(String *s) {
  649. char *tmp = Char(s);
  650. char *c = tmp;
  651. char *cc = c;
  652. char *co = 0;
  653. if (!strstr(c, "::"))
  654. return NewString(s);
  655. co = strstr(cc, "operator ");
  656. if (co) {
  657. return NewString(co);
  658. }
  659. while (*c) {
  660. if ((*c == ':') && (*(c + 1) == ':')) {
  661. cc = c;
  662. c += 2;
  663. } else {
  664. if (*c == '<') {
  665. int level = 1;
  666. c++;
  667. while (*c && level) {
  668. if (*c == '<')
  669. level++;
  670. if (*c == '>')
  671. level--;
  672. c++;
  673. }
  674. } else {
  675. c++;
  676. }
  677. }
  678. }
  679. return NewString(cc + 2);
  680. }
  681. /* -----------------------------------------------------------------------------
  682. * Swig_scopename_first()
  683. *
  684. * Take a qualified name like "A::B::C" and returns the first scope name.
  685. * In this case, "A". Returns NULL if there is no base.
  686. * ----------------------------------------------------------------------------- */
  687. String *Swig_scopename_first(String *s) {
  688. char *tmp = Char(s);
  689. char *c = tmp;
  690. char *co = 0;
  691. if (!strstr(c, "::"))
  692. return 0;
  693. co = strstr(c, "operator ");
  694. if (co) {
  695. if (co == c) {
  696. return 0;
  697. }
  698. } else {
  699. co = c + Len(s);
  700. }
  701. while (*c && (c != co)) {
  702. if ((*c == ':') && (*(c + 1) == ':')) {
  703. break;
  704. } else {
  705. if (*c == '<') {
  706. int level = 1;
  707. c++;
  708. while (*c && level) {
  709. if (*c == '<')
  710. level++;
  711. if (*c == '>')
  712. level--;
  713. c++;
  714. }
  715. } else {
  716. c++;
  717. }
  718. }
  719. }
  720. if (*c && (c != tmp)) {
  721. return NewStringWithSize(tmp, c - tmp);
  722. } else {
  723. return 0;
  724. }
  725. }
  726. /* -----------------------------------------------------------------------------
  727. * Swig_scopename_suffix()
  728. *
  729. * Take a qualified name like "A::B::C" and returns the suffix.
  730. * In this case, "B::C". Returns NULL if there is no suffix.
  731. * ----------------------------------------------------------------------------- */
  732. String *Swig_scopename_suffix(String *s) {
  733. char *tmp = Char(s);
  734. char *c = tmp;
  735. char *co = 0;
  736. if (!strstr(c, "::"))
  737. return 0;
  738. co = strstr(c, "operator ");
  739. if (co) {
  740. if (co == c)
  741. return 0;
  742. }
  743. while (*c) {
  744. if ((*c == ':') && (*(c + 1) == ':')) {
  745. break;
  746. } else {
  747. if (*c == '<') {
  748. int level = 1;
  749. c++;
  750. while (*c && level) {
  751. if (*c == '<')
  752. level++;
  753. if (*c == '>')
  754. level--;
  755. c++;
  756. }
  757. } else {
  758. c++;
  759. }
  760. }
  761. }
  762. if (*c && (c != tmp)) {
  763. return NewString(c + 2);
  764. } else {
  765. return 0;
  766. }
  767. }
  768. /* -----------------------------------------------------------------------------
  769. * Swig_scopename_check()
  770. *
  771. * Checks to see if a name is qualified with a scope name
  772. * ----------------------------------------------------------------------------- */
  773. int Swig_scopename_check(String *s) {
  774. char *c = Char(s);
  775. char *co = strstr(c, "operator ");
  776. if (co) {
  777. if (co == c)
  778. return 0;
  779. }
  780. if (!strstr(c, "::"))
  781. return 0;
  782. while (*c) {
  783. if ((*c == ':') && (*(c + 1) == ':')) {
  784. return 1;
  785. } else {
  786. if (*c == '<') {
  787. int level = 1;
  788. c++;
  789. while (*c && level) {
  790. if (*c == '<')
  791. level++;
  792. if (*c == '>')
  793. level--;
  794. c++;
  795. }
  796. } else {
  797. c++;
  798. }
  799. }
  800. }
  801. return 0;
  802. }
  803. /* -----------------------------------------------------------------------------
  804. * Swig_string_command()
  805. *
  806. * Executes a external command via popen with the string as a command
  807. * line parameter. For example:
  808. *
  809. * Printf(stderr,"%(command:sed 's/[a-z]/\U\\1/' <<<)s","hello") -> Hello
  810. * ----------------------------------------------------------------------------- */
  811. #if defined(HAVE_POPEN)
  812. # if defined(_MSC_VER)
  813. # define popen _popen
  814. # define pclose _pclose
  815. # else
  816. extern FILE *popen(const char *command, const char *type);
  817. extern int pclose(FILE *stream);
  818. # endif
  819. #else
  820. # if defined(_MSC_VER)
  821. # define HAVE_POPEN 1
  822. # define popen _popen
  823. # define pclose _pclose
  824. # endif
  825. #endif
  826. String *Swig_string_command(String *s) {
  827. String *res = NewStringEmpty();
  828. #if defined(HAVE_POPEN)
  829. if (Len(s)) {
  830. char *command = Char(s);
  831. FILE *fp = popen(command, "r");
  832. if (fp) {
  833. char buffer[1025];
  834. while (fscanf(fp, "%1024s", buffer) != EOF) {
  835. Append(res, buffer);
  836. }
  837. pclose(fp);
  838. } else {
  839. Swig_error("SWIG", Getline(s), "Command encoder fails attempting '%s'.\n", s);
  840. exit(1);
  841. }
  842. }
  843. #endif
  844. return res;
  845. }
  846. /* -----------------------------------------------------------------------------
  847. * Swig_string_rxspencer()
  848. *
  849. * Executes a regexp substitution via the RxSpencer library. For example:
  850. *
  851. * Printf(stderr,"gsl%(rxspencer:[GSL_.*_][@1])s","GSL_Hello_") -> gslHello
  852. * ----------------------------------------------------------------------------- */
  853. #if defined(HAVE_RXSPENCER)
  854. #include <sys/types.h>
  855. #include <rxspencer/regex.h>
  856. #define USE_RXSPENCER
  857. #endif
  858. const char *skip_delim(char pb, char pe, const char *ce) {
  859. int end = 0;
  860. int lb = 0;
  861. while (!end && *ce != '\0') {
  862. if (*ce == pb) {
  863. ++lb;
  864. }
  865. if (*ce == pe) {
  866. if (!lb) {
  867. end = 1;
  868. --ce;
  869. } else {
  870. --lb;
  871. }
  872. }
  873. ++ce;
  874. }
  875. return end ? ce : 0;
  876. }
  877. #if defined(USE_RXSPENCER)
  878. String *Swig_string_rxspencer(String *s) {
  879. String *res = 0;
  880. if (Len(s)) {
  881. const char *cs = Char(s);
  882. const char *cb;
  883. const char *ce;
  884. if (*cs == '[') {
  885. int retval;
  886. regex_t compiled;
  887. cb = ++cs;
  888. ce = skip_delim('[', ']', cb);
  889. if (ce) {
  890. char bregexp[512];
  891. strncpy(bregexp, cb, ce - cb);
  892. bregexp[ce - cb] = '\0';
  893. ++ce;
  894. retval = regcomp(&compiled, bregexp, REG_EXTENDED);
  895. if (retval == 0) {
  896. cs = ce;
  897. if (*cs == '[') {
  898. cb = ++cs;
  899. ce = skip_delim('[', ']', cb);
  900. if (ce) {
  901. const char *cvalue = ce + 1;
  902. int nsub = (int) compiled.re_nsub + 1;
  903. regmatch_t *pmatch = (regmatch_t *) malloc(sizeof(regmatch_t) * (nsub));
  904. retval = regexec(&compiled, cvalue, nsub, pmatch, 0);
  905. if (retval != REG_NOMATCH) {
  906. char *spos = 0;
  907. res = NewStringWithSize(cb, ce - cb);
  908. spos = Strchr(res, '@');
  909. while (spos) {
  910. char cd = *(++spos);
  911. if (isdigit(cd)) {
  912. char arg[8];
  913. size_t len;
  914. int i = cd - '0';
  915. sprintf(arg, "@%d", i);
  916. if (i < nsub && (len = pmatch[i].rm_eo - pmatch[i].rm_so)) {
  917. char value[256];
  918. strncpy(value, cvalue + pmatch[i].rm_so, len);
  919. value[len] = 0;
  920. Replaceall(res, arg, value);
  921. } else {
  922. Replaceall(res, arg, "");
  923. }
  924. spos = Strchr(res, '@');
  925. } else if (cd == '@') {
  926. spos = strchr(spos + 1, '@');
  927. }
  928. }
  929. }
  930. free(pmatch);
  931. }
  932. }
  933. }
  934. regfree(&compiled);
  935. }
  936. }
  937. }
  938. if (!res)
  939. res = NewStringEmpty();
  940. return res;
  941. }
  942. #else
  943. String *Swig_string_rxspencer(String *s) {
  944. (void) s;
  945. return NewStringEmpty();
  946. }
  947. #endif
  948. /* ------------------------------------------------------------
  949. * is_generated_overload()
  950. * Check if the function is an automatically generated
  951. * overload created because a method has default parameters.
  952. * ------------------------------------------------------------ */
  953. int Swig_is_generated_overload(Node *n)
  954. {
  955. Node *base_method = Getattr(n, "sym:overloaded");
  956. Node *default_args = Getattr(n, "defaultargs");
  957. return ((base_method != NULL) && (default_args != NULL) && (base_method == default_args));
  958. }
  959. /* -----------------------------------------------------------------------------
  960. * Swig_init()
  961. *
  962. * Initialize the SWIG core
  963. * ----------------------------------------------------------------------------- */
  964. void Swig_init() {
  965. /* Set some useful string encoding methods */
  966. DohEncoding("escape", Swig_string_escape);
  967. DohEncoding("upper", Swig_string_upper);
  968. DohEncoding("lower", Swig_string_lower);
  969. DohEncoding("title", Swig_string_title);
  970. DohEncoding("ctitle", Swig_string_ccase);
  971. DohEncoding("lctitle", Swig_string_lccase);
  972. DohEncoding("utitle", Swig_string_ucase);
  973. DohEncoding("typecode", Swig_string_typecode);
  974. DohEncoding("mangle", Swig_string_emangle);
  975. DohEncoding("command", Swig_string_command);
  976. DohEncoding("rxspencer", Swig_string_rxspencer);
  977. DohEncoding("schemify", Swig_string_schemify);
  978. /* aliases for the case encoders */
  979. DohEncoding("uppercase", Swig_string_upper);
  980. DohEncoding("lowercase", Swig_string_lower);
  981. DohEncoding("camelcase", Swig_string_ccase);
  982. DohEncoding("lowercamelcase", Swig_string_lccase);
  983. DohEncoding("undercase", Swig_string_ucase);
  984. DohEncoding("firstuppercase", Swig_string_first_upper);
  985. DohEncoding("firstlowercase", Swig_string_first_lower);
  986. /* Initialize typemaps */
  987. Swig_typemap_init();
  988. /* Initialize symbol table */
  989. Swig_symbol_init();
  990. /* Initialize type system */
  991. SwigType_typesystem_init();
  992. /* Initialize template system */
  993. SwigType_template_init();
  994. }