grep.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. /* regex.f -- translated by f2c (version of 17 January 1992 0:17:58).
  2. You must link the resulting object file with the libraries:
  3. -lF77 -lI77 -lm -lc (in that order)
  4. */
  5. /* Signature: 7628c6a0 08-Apr-2002 */
  6. /* #include "f2c.h" */
  7. typedef long int integer;
  8. typedef long int logical;
  9. typedef long ftnlen;
  10. #define TRUE_ (1)
  11. #define FALSE_ (0)
  12. #define max(a,b) ((a) >= (b) ? (a) : (b))
  13. #ifdef BSD
  14. #include <strings.h>
  15. #else
  16. #include <string.h>
  17. #endif
  18. #include <ctype.h>
  19. #include <stdarg.h>
  20. #include "machine.h"
  21. #include "tags.h"
  22. #include "cslerror.h"
  23. #include "externs.h"
  24. /* Added by Mike Dewar to provide Lisp Interface */
  25. #include <stdio.h>
  26. void remark_(char *s,int length)
  27. {
  28. fprintf(stderr,"error: %s\n",s);
  29. }
  30. void zlowc_(char *retval, int retlen,char *ch, int chlen)
  31. {
  32. if (retlen!=1 || chlen!=1) remark_("zlowc: Calling sequence error",0);
  33. *retval = isupper(*ch) ? tolower(*ch) : *ch;
  34. }
  35. void error_(char *s,int length)
  36. {
  37. fprintf(stderr,"error: %s\n",s);
  38. my_exit(42);
  39. }
  40. /* Common Block Declarations */
  41. struct {
  42. integer smode, mode2;
  43. } xcsmod_;
  44. #define xcsmod_1 xcsmod_
  45. struct {
  46. logical isanum[256];
  47. } xcscas_;
  48. #define xcscas_1 xcscas_
  49. /* opyright 1991 Numerical Algorithms Group */
  50. /* Match any single character */
  51. /* $pp$ANYCHR='.' */
  52. /* $pp$ANYAPO='?' */
  53. /* Begin character class */
  54. /* $pp$BCLCHR='[' */
  55. /* Beginning of line (string) */
  56. /* $pp$BOLAPO='%' */
  57. /* $pp$BOLCHR='^' */
  58. /* Closure */
  59. /* $pp$CL0CHR='*' */
  60. /* Positive Closure */
  61. /* $pp$CL1CHR='+' */
  62. /* Close tag field (group) */
  63. /* $pp$CTGAPO='}' */
  64. /* $pp$CTGTP1='>' */
  65. /* End character class */
  66. /* $pp$ECLCHR=']' */
  67. /* End of line (string) */
  68. /* $pp$EOLCHR='$' */
  69. /* APOLLO and TPACK1: Escape a character anywhere, @n & @t are special */
  70. /* $pp$ESCAPO='@' */
  71. /* EMACS and EGREP: Escape a character inside a character class, plus */
  72. /* various special functions outside. */
  73. /* $pp$ESCCHR='\\' */
  74. /* Invert character class */
  75. /* $pp$NOTAPO='~' */
  76. /* $pp$NOTCHR='^' */
  77. /* EMACS and EGREP: Optional item (i.e. 0 or 1 repeats) */
  78. /* $pp$OPTCHR='?' */
  79. /* Open tag field (group) */
  80. /* $pp$OTGAPO='{' */
  81. /* $pp$OTGTP1='<' */
  82. /* Recall tag field (group) */
  83. /* $pp$TAGAPO='@' */
  84. /* $pp$TAGTP1='&' */
  85. /* $pp$TAGCHR='\\' */
  86. /* Transition between alphanumerics and non-alphanumerics */
  87. /* $pp$TRNTP1=':' */
  88. /* Modes of operation */
  89. /* $pp$EMACS=0 */
  90. /* $pp$APOLLO=1 */
  91. /* $pp$EGREP=2 */
  92. /* $pp$TPACK1=3 */
  93. /* Internal Pattern Symbols */
  94. /* $pp$TAGSYM=-101 */
  95. /* $pp$CL1SYM=-102 */
  96. /* $pp$TRNSYM=-103 */
  97. /* $pp$EOLSYM=-104 */
  98. /* $pp$CTGSYM=-105 */
  99. /* $pp$CCESYM=-106 */
  100. /* $pp$CL0SYM=-107 */
  101. /* $pp$ANYSYM=-108 */
  102. /* $pp$BOLSYM=-109 */
  103. /* $pp$OTGSYM=-110 */
  104. /* $pp$CCLSYM=-111 */
  105. /* -112 now unused */
  106. /* $pp$EOSSYM=-113 */
  107. /* $pp$DASSYM=-114 */
  108. /* $pp$ERRSYM=-115 */
  109. /* $pp$OPTSYM=-116 */
  110. /* PATTERN MATCHING AND REPLACEMENT ROUTINES */
  111. /* CHARACTER STRING BASED */
  112. /* RMJI - FRIDAY 13 JANUARY 1989 */
  113. /* Substantially revised and enhanced by Malcolm Cohen, October 1989. */
  114. /* ---------------------------------------------------------------------- */
  115. /* Z S I N I T - Initialise String module (regular expressions) */
  116. /* Subroutine */ void zsinit_(mode) /* used to have return type int */
  117. integer *mode;
  118. {
  119. /* Initialized data */
  120. static char digits[10+1] = "0123456789";
  121. static char lolett[26+1] = "abcdefghijklmnopqrstuvwxyz";
  122. static char uplett[26+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  123. static integer i;
  124. if (*mode == 3) {
  125. xcsmod_1.smode = 1;
  126. xcsmod_1.mode2 = 3;
  127. } else {
  128. xcsmod_1.smode = *mode;
  129. xcsmod_1.mode2 = *mode;
  130. }
  131. for (i = 0; i <= 255; ++i) {
  132. xcscas_1.isanum[i] = FALSE_;
  133. /* L100: */
  134. }
  135. for (i = 1; i <= 26; ++i) {
  136. xcscas_1.isanum[uplett[i - 1]] = TRUE_;
  137. xcscas_1.isanum[lolett[i - 1]] = TRUE_;
  138. /* L200: */
  139. }
  140. for (i = 1; i <= 10; ++i) {
  141. xcscas_1.isanum[digits[i - 1]] = TRUE_;
  142. /* L300: */
  143. }
  144. } /* zsinit_ */
  145. /* ---------------------------------------------------------------------- */
  146. /* Z S C P A T - Compile pattern specification from STRING to */
  147. /* PATSTR, FLAG indicates case sensitivity (.TRUE. */
  148. /* means case sensitive)... */
  149. /* Subroutine */ void zscpat_(string, flag_, patstr, maxpsz, ifail, string_len)
  150. char *string;
  151. logical *flag_;
  152. integer *patstr, *maxpsz, *ifail;
  153. ftnlen string_len;
  154. {
  155. /* System generated locals */
  156. integer i__1;
  157. /* Builtin functions */
  158. integer i_len();
  159. /* Local variables */
  160. static integer i, j, lastj, limit, itemp, lj, lastcl;
  161. extern logical xlssgc_();
  162. extern integer xissex_(), xisspr_(), xissnx_();
  163. /* Parameter adjustments */
  164. --patstr;
  165. /* Function Body */
  166. limit = (integer) string_len;
  167. if (*maxpsz <= max(limit,13)) {
  168. *ifail = 1;
  169. return;
  170. }
  171. *ifail = 2;
  172. /* Save case flag */
  173. if (*flag_) {
  174. patstr[1] = 0;
  175. } else {
  176. patstr[1] = 1;
  177. }
  178. /* Clear the tag fields and set the pointer to miss it */
  179. for (i = 2; i <= 11; ++i) {
  180. patstr[i] = 0;
  181. /* L10: */
  182. }
  183. patstr[12] = 1;
  184. j = 13;
  185. lastj = j;
  186. lastcl = 0;
  187. i = 1;
  188. L20:
  189. lj = j;
  190. if (j + 1 > *maxpsz) {
  191. goto L666;
  192. }
  193. if (string[i - 1] == '.' && xcsmod_1.smode != 1 || string[i - 1] == '?' &&
  194. xcsmod_1.smode == 1) {
  195. patstr[j] = -108;
  196. ++j;
  197. } else if (string[i - 1] == ':' && xcsmod_1.mode2 == 3) {
  198. patstr[j] = -103;
  199. ++j;
  200. } else if (xcsmod_1.smode != 1 && string[i - 1] == '^' && i == 1 ||
  201. xcsmod_1.smode == 1 && string[i - 1] == '%' && i == 1) {
  202. patstr[j] = -109;
  203. ++j;
  204. } else if (string[i - 1] == '$' && i == limit) {
  205. patstr[j] = -104;
  206. ++j;
  207. } else if (string[i - 1] == '[') {
  208. if (! xlssgc_(string, &i, &patstr[1], &j, maxpsz, string_len)) {
  209. return;
  210. }
  211. } else if ((string[i - 1] == '*' || string[i - 1] == '+' || string[i - 1]
  212. == '?' && xcsmod_1.smode != 1) && i > 1) {
  213. lj = lastj;
  214. if (patstr[lj] == -109 || patstr[lj] == -107 || patstr[lj] == -102) {
  215. goto L50;
  216. }
  217. if (string[i - 1] == '+') {
  218. lastj = j;
  219. L30:
  220. if (lj < lastj) {
  221. if (j + 1 > *maxpsz) {
  222. goto L666;
  223. }
  224. patstr[j] = patstr[lj];
  225. ++j;
  226. ++lj;
  227. goto L30;
  228. }
  229. }
  230. if (j + 4 > *maxpsz) {
  231. goto L666;
  232. }
  233. i__1 = lastj;
  234. for (itemp = j - 1; itemp >= i__1; --itemp) {
  235. patstr[itemp + 4] = patstr[itemp];
  236. /* L31: */
  237. }
  238. j += 4;
  239. if (string[i - 1] == '?') {
  240. patstr[lastj] = -116;
  241. } else {
  242. patstr[lastj] = -107;
  243. }
  244. patstr[lastj + 1] = 0;
  245. patstr[lastj + 2] = lastcl;
  246. patstr[lastj + 3] = 0;
  247. lastcl = lastj;
  248. lastj += 4;
  249. } else if (string[i - 1] == '{' && xcsmod_1.mode2 == 1 || string[i - 1] ==
  250. '<' && xcsmod_1.mode2 == 3) {
  251. itemp = xissnx_(&patstr[1]);
  252. if (itemp <= 0) {
  253. *ifail = 4;
  254. goto L666;
  255. }
  256. if (j + 2 > *maxpsz) {
  257. goto L666;
  258. }
  259. patstr[j] = -110;
  260. patstr[j + 1] = itemp;
  261. j += 2;
  262. } else if (string[i - 1] == '}' && xcsmod_1.mode2 == 1 || string[i - 1] ==
  263. '>' && xcsmod_1.mode2 == 3) {
  264. if (j + 2 > *maxpsz) {
  265. goto L666;
  266. }
  267. patstr[j] = -105;
  268. patstr[j + 1] = xisspr_(&patstr[1]);
  269. if (patstr[j + 1] <= 0) {
  270. *ifail = 4;
  271. return;
  272. }
  273. j += 2;
  274. } else if (string[i - 1] == '\\' && xcsmod_1.smode != 1 && i < limit) {
  275. ++i;
  276. if (j + 2 > *maxpsz) {
  277. goto L666;
  278. }
  279. if (string[i - 1] == '(') {
  280. if (string[i] == '+' || string[i] == '*' ||
  281. string[i] == '?')
  282. {
  283. /* Report error if open tag field followed by +*? */
  284. *ifail = 4;
  285. goto L666;
  286. }
  287. patstr[j] = -110;
  288. patstr[j + 1] = xissnx_(&patstr[1]);
  289. } else if (string[i - 1] == ')') {
  290. patstr[j] = -105;
  291. patstr[j + 1] = xisspr_(&patstr[1]);
  292. } else if (string[i - 1] == 'b') {
  293. patstr[j] = -103;
  294. --j;
  295. } else {
  296. integer tmp=i-1;
  297. patstr[j] = xissex_(string, &tmp, string_len);
  298. --j;
  299. }
  300. if (patstr[j + 1] <= 0 && patstr[j + 1] != -103) {
  301. *ifail = 4;
  302. goto L666;
  303. }
  304. j += 2;
  305. } else {
  306. patstr[j] = xissex_(string, &i, string_len);
  307. ++j;
  308. }
  309. lastj = lj;
  310. ++i;
  311. if (i <= limit) {
  312. goto L20;
  313. }
  314. L50:
  315. if (j <= *maxpsz) {
  316. patstr[j] = -113;
  317. for (i = 2; i <= 11; ++i) {
  318. patstr[i] = 0;
  319. /* L60: */
  320. }
  321. patstr[12] = 1;
  322. j = 13;
  323. *ifail = 0;
  324. return;
  325. }
  326. /* Some sort of error found - mark the pattern as invalid */
  327. L666:
  328. remark_("Invalid pattern",15L);
  329. patstr[13] = -115;
  330. } /* zscpat_ */
  331. /* ---------------------------------------------------------------------- */
  332. /* Z S F I N D - Match the string against the compiled pattern */
  333. logical zsfind_(string, start, finish, patstr, string_len)
  334. char *string;
  335. integer *start, *finish, *patstr;
  336. ftnlen string_len;
  337. {
  338. /* System generated locals */
  339. integer i__1;
  340. logical ret_val;
  341. /* Builtin functions */
  342. integer i_len();
  343. /* Local variables */
  344. static integer i, n;
  345. extern integer xissam_();
  346. /* Parameter adjustments */
  347. --patstr;
  348. /* Function Body */
  349. if (patstr[13] == -115) {
  350. remark_("Pattern is in error", 19L);
  351. } else {
  352. /* Loop along the line until a match is found */
  353. i__1 = (integer) string_len;
  354. for (i = 1; i <= i__1; ++i) {
  355. n = xissam_(string, &i, &patstr[1], string_len);
  356. if (n > 0) {
  357. ret_val = TRUE_;
  358. *start = i;
  359. *finish = n - 1;
  360. return ret_val;
  361. }
  362. /* L10: */
  363. }
  364. }
  365. ret_val = FALSE_;
  366. return ret_val;
  367. } /* zsfind_ */
  368. /* ---------------------------------------------------------------------- */
  369. /* X I S S A M - Function to look for a pattern match */
  370. integer xissam_(lin, from, patstr, lin_len)
  371. char *lin;
  372. integer *from, *patstr;
  373. ftnlen lin_len;
  374. {
  375. /* System generated locals */
  376. integer ret_val;
  377. /* Builtin functions */
  378. integer i_len();
  379. /* Local variables */
  380. static integer i, j, stack, offset;
  381. extern logical xlssom_();
  382. extern integer xissps_();
  383. /* Parameter adjustments */
  384. --patstr;
  385. /* Function Body */
  386. stack = 0;
  387. offset = *from;
  388. j = 13;
  389. L10:
  390. if (patstr[j] != -113) {
  391. if (patstr[j] == -107 || patstr[j] == -116) {
  392. stack = j;
  393. j += 4;
  394. i = offset;
  395. L20:
  396. if (i <= (integer) lin_len) {
  397. if (xlssom_(lin, &i, &j, &patstr[1], lin_len)) {
  398. if (patstr[stack] != -116) {
  399. goto L20;
  400. }
  401. }
  402. }
  403. patstr[stack + 1] = i - offset;
  404. patstr[stack + 3] = offset;
  405. offset = i;
  406. } else if (! xlssom_(lin, &offset, &j, &patstr[1], lin_len)) {
  407. L40:
  408. if (stack > 0) {
  409. if (patstr[stack + 1] <= 0) {
  410. stack = patstr[stack + 2];
  411. goto L40;
  412. }
  413. }
  414. if (stack <= 0) {
  415. ret_val = 0;
  416. return ret_val;
  417. }
  418. --patstr[stack + 1];
  419. j = stack + 4;
  420. offset = patstr[stack + 3] + patstr[stack + 1];
  421. }
  422. j += xissps_(&j, &patstr[1]);
  423. goto L10;
  424. }
  425. /* Match found, return pointer to end of match */
  426. ret_val = offset;
  427. return ret_val;
  428. } /* xissam_ */
  429. /* ---------------------------------------------------------------------- */
  430. /* X S S S C T - Function to close a tag field and save the */
  431. /* current pointer value. */
  432. /* Subroutine */ void xsssct_(point, n, string)
  433. integer *point, *n, *string;
  434. {
  435. static integer temp;
  436. /* Parameter adjustments */
  437. --string;
  438. /* Function Body */
  439. if (*n >= 1 && *n <= 9) {
  440. temp = string[*n + 2] / 256;
  441. string[*n + 2] = *point + (temp << 8);
  442. }
  443. } /* xsssct_ */
  444. /* ---------------------------------------------------------------------- */
  445. /* X I S S N X - Function to return an index to the next free tag */
  446. /* field identifier. */
  447. integer xissnx_(string)
  448. integer *string;
  449. {
  450. /* System generated locals */
  451. integer ret_val;
  452. /* Parameter adjustments */
  453. --string;
  454. /* Function Body */
  455. if (string[12] > 9) {
  456. ret_val = -1;
  457. } else {
  458. ret_val = string[12];
  459. ++string[12];
  460. }
  461. return ret_val;
  462. } /* xissnx_ */
  463. /* ---------------------------------------------------------------------- */
  464. /* X S S S O P - Function to open a tag field and save the start */
  465. /* position. */
  466. /* Subroutine */ void xsssop_(point, n, string)
  467. integer *point, *n, *string;
  468. {
  469. /* Parameter adjustments */
  470. --string;
  471. /* Function Body */
  472. if (*n >= 1 && *n <= 9) {
  473. /* Save current pointer in tag field array */
  474. string[*n + 2] = *point << 8;
  475. }
  476. } /* xsssop_ */
  477. /* ---------------------------------------------------------------------- */
  478. /* X I S S P R - Function to return the value of the current tag */
  479. /* field to be closed. The storage location in */
  480. /* PATSTR is used to hold markers to indicate which */
  481. /* tag fields have been closed already, these */
  482. /* markers are cleared on exit from ZCOMPP. */
  483. integer xisspr_(patstr)
  484. integer *patstr;
  485. {
  486. /* System generated locals */
  487. integer ret_val;
  488. /* Parameter adjustments */
  489. --patstr;
  490. /* Function Body */
  491. ret_val = patstr[12] - 1;
  492. L10:
  493. if (ret_val > 0) {
  494. if (patstr[ret_val + 2] != 0) {
  495. --ret_val;
  496. goto L10;
  497. } else {
  498. patstr[ret_val + 2] = 1;
  499. }
  500. }
  501. return ret_val;
  502. } /* xisspr_ */
  503. /* ---------------------------------------------------------------------- */
  504. /* X S S S D O - Expand pattern class range */
  505. logical xsssdo_(valid, array, i, set, j, maxset, valid_len, array_len)
  506. char *valid, *array;
  507. integer *i, *set, *j, *maxset;
  508. ftnlen valid_len;
  509. ftnlen array_len;
  510. {
  511. /* System generated locals */
  512. integer i__1;
  513. logical ret_val;
  514. char ch__1[1];
  515. /* Builtin functions */
  516. integer i_indx();
  517. /* Local variables */
  518. static integer k, limit;
  519. extern integer xissex_();
  520. /* Added by ICH */
  521. char *valid_null_term;
  522. /* Parameter adjustments */
  523. --set;
  524. /* Function Body */
  525. ++(*i);
  526. --(*j);
  527. ch__1[0] = xissex_(array, i, array_len);
  528. /* limit = i_indx(valid, ch__1, valid_len, 1L); */
  529. valid_null_term = (char *) malloc(valid_len+1);
  530. strncpy(valid_null_term,valid,(int) valid_len);
  531. valid_null_term[valid_len]='\0';
  532. limit = (integer) ((strchr(valid_null_term,ch__1[0]) - valid_null_term) + 1);
  533. if (limit<0)
  534. limit=0;
  535. ch__1[0] = set[*j];
  536. if (*j + limit - (integer) (strchr(valid_null_term,ch__1[0])
  537. - valid_null_term + 1) + 1 <= *maxset) {
  538. ch__1[0] = set[*j];
  539. i__1 = limit;
  540. for (k = (integer) (strchr(valid_null_term,ch__1[0])
  541. - valid_null_term + 1); k <= i__1; ++k) {
  542. set[*j] = valid[k - 1];
  543. ++(*j);
  544. /* L10: */
  545. }
  546. ret_val = TRUE_;
  547. } else {
  548. ret_val = FALSE_;
  549. }
  550. free((void *)valid_null_term);
  551. return ret_val;
  552. } /* xsssdo_ */
  553. /* ---------------------------------------------------------------------- */
  554. /* X I S S E X - Un-escape a single character */
  555. integer xissex_(array, i, array_len)
  556. char *array;
  557. integer *i;
  558. ftnlen array_len;
  559. {
  560. /* System generated locals */
  561. integer ret_val;
  562. if (array[*i - 1] == '@' && xcsmod_1.smode == 1 || array[*i - 1] == '\\'
  563. && xcsmod_1.smode != 1) {
  564. ++(*i);
  565. if (array[*i - 1] == 'n') {
  566. ret_val = 10;
  567. } else if (array[*i - 1] == 't') {
  568. ret_val = 9;
  569. } else {
  570. ret_val = array[*i - 1];
  571. }
  572. } else {
  573. ret_val = array[*i - 1];
  574. }
  575. return ret_val;
  576. } /* xissex_ */
  577. /* ---------------------------------------------------------------------- */
  578. /* X S S S F I - Fill a character class set for pattern matching */
  579. /* Subroutine */ void xsssfi_(array, i, set, j, maxset, array_len)
  580. char *array;
  581. integer *i, *set, *j, *maxset;
  582. ftnlen array_len;
  583. {
  584. /* System generated locals */
  585. char ch__1[1];
  586. /* Builtin functions */
  587. integer i_len(), i_indx();
  588. /* Local variables */
  589. static logical ok;
  590. extern integer xissex_();
  591. extern logical xsssdo_();
  592. /* Parameter adjustments */
  593. --set;
  594. /* Function Body */
  595. L10:
  596. ok = *j + 1 < *maxset;
  597. if (ok && array[*i - 1] != ']') {
  598. if (array[*i - 1] == '\\' && xcsmod_1.smode != 1 || array[*i - 1] ==
  599. '@' && xcsmod_1.smode == 1) {
  600. /* Character has been escaped */
  601. set[*j] = xissex_(array, i, array_len);
  602. ++(*j);
  603. } else if (array[*i - 1] != '-') {
  604. set[*j] = array[*i - 1];
  605. ++(*j);
  606. } else if (*j <= 1 || *i == (integer) array_len) {
  607. set[*j] = -114;
  608. ++(*j);
  609. } else /* if(complicated condition) */ {
  610. ch__1[0] = set[*j - 1];
  611. if (*ch__1>='0' && *ch__1<='9') {
  612. ok = xsssdo_("0123456789", array, i, &set[1], j, maxset, 10L,
  613. array_len);
  614. } else /* if(complicated condition) */ {
  615. ch__1[0] = set[*j - 1];
  616. if (*ch__1>='a' && *ch__1<='z' )
  617. {
  618. ok = xsssdo_("abcdefghijklmnopqrstuvwxyz", array, i, &set[
  619. 1], j, maxset, 26L, array_len);
  620. } else /* if(complicated condition) */ {
  621. ch__1[0] = set[*j - 1];
  622. if ( *ch__1>='A' && *ch__1<='Z') {
  623. ok = xsssdo_("ABCDEFGHIJKLMNOPQRSTUVWXYZ", array, i, &
  624. set[1], j, maxset, 26L, array_len);
  625. } else {
  626. set[*j] = -114;
  627. ++(*j);
  628. }
  629. }
  630. }
  631. }
  632. ++(*i);
  633. if (*i <= (integer) array_len) {
  634. goto L10;
  635. }
  636. }
  637. } /* xsssfi_ */
  638. /* ---------------------------------------------------------------------- */
  639. /* X L S S G C - Get character class */
  640. logical xlssgc_(arg, i, pat, j, maxpsz, arg_len)
  641. char *arg;
  642. integer *i, *pat, *j, *maxpsz;
  643. ftnlen arg_len;
  644. {
  645. /* System generated locals */
  646. logical ret_val;
  647. /* Local variables */
  648. static integer jstart;
  649. extern /* Subroutine */ void xsssfi_();
  650. static integer sym;
  651. /* Parameter adjustments */
  652. --pat;
  653. /* Function Body */
  654. ++(*i);
  655. /* Check if an inclusive or exclusive set is being requested */
  656. if (arg[*i - 1] == '^' && xcsmod_1.smode != 1 || arg[*i - 1] == '~' &&
  657. xcsmod_1.smode == 1) {
  658. ++(*i);
  659. sym = -106;
  660. } else {
  661. sym = -111;
  662. }
  663. if (*j + 2 <= *maxpsz) {
  664. pat[*j] = sym;
  665. pat[*j + 1] = 0;
  666. jstart = *j + 1;
  667. *j += 2;
  668. xsssfi_(arg, i, &pat[1], j, maxpsz, arg_len);
  669. pat[jstart] = *j - jstart - 1;
  670. /* Check to see if pattern filled in ok */
  671. ret_val = arg[*i - 1] == ']';
  672. } else {
  673. ret_val = FALSE_;
  674. }
  675. return ret_val;
  676. } /* xlssgc_ */
  677. /* ---------------------------------------------------------------------- */
  678. /* X L S S L O - Match a single character against a char set */
  679. logical xlsslo_(c, pat, offset, c_len)
  680. char *c;
  681. integer *pat, *offset;
  682. ftnlen c_len;
  683. {
  684. /* System generated locals */
  685. logical ret_val;
  686. /* Local variables */
  687. static integer i;
  688. /* Parameter adjustments */
  689. --pat;
  690. /* Function Body */
  691. i = *offset + pat[*offset];
  692. L10:
  693. if (i > *offset) {
  694. if (*c == pat[i]) {
  695. ret_val = TRUE_;
  696. return ret_val;
  697. }
  698. --i;
  699. goto L10;
  700. }
  701. ret_val = FALSE_;
  702. return ret_val;
  703. } /* xlsslo_ */
  704. /* ---------------------------------------------------------------------- */
  705. /* X L S S O M - Match a single pattern */
  706. logical xlssom_(lin, i, j, patstr, lin_len)
  707. char *lin;
  708. integer *i, *j, *patstr;
  709. ftnlen lin_len;
  710. {
  711. /* System generated locals */
  712. integer i__1;
  713. logical ret_val;
  714. char ch__1[1], ch__2[1], ch__3[1];
  715. /* Builtin functions */
  716. integer i_len();
  717. /* Local variables */
  718. static integer bump;
  719. extern logical xlsslo_();
  720. extern /* Subroutine */ void xsssct_(), xsssop_();
  721. /* Set initial (invalid) value for pointer update */
  722. /* Parameter adjustments */
  723. --patstr;
  724. /* Function Body */
  725. bump = -1;
  726. /* Open tag field */
  727. if (patstr[*j] == -110) {
  728. bump = 0;
  729. xsssop_(i, &patstr[*j + 1], &patstr[1]);
  730. /* Close tag field */
  731. } else if (patstr[*j] == -105) {
  732. bump = 0;
  733. xsssct_(i, &patstr[*j + 1], &patstr[1]);
  734. /* Transition (or end or line or beginning of line) */
  735. } else if (patstr[*j] == -103) {
  736. if (*i > (integer) lin_len || *i == 1) {
  737. bump = 0;
  738. } else {
  739. i__1 = *i - 2;
  740. if (xcscas_1.isanum[lin[*i - 1]] != xcscas_1.isanum[lin[i__1]]) {
  741. bump = 0;
  742. /* ELSE IF (I.GT.1) THEN */
  743. /* IF (ICHAR(LIN(I:I)).EQ.10) BUMP = 0 */
  744. }
  745. }
  746. /* End of the line */
  747. } else if (*i > (integer) lin_len) {
  748. if (patstr[*j] == -104) {
  749. bump = 0;
  750. }
  751. } else if (patstr[*j] == -104) {
  752. if (lin[*i - 1] == 10) {
  753. bump = 0;
  754. }
  755. /* Ordinary character */
  756. } else if (patstr[*j] > 0) {
  757. if (patstr[1] == 1) {
  758. zlowc_(ch__1, 1L, lin + (*i - 1), 1L);
  759. ch__3[0] = patstr[*j];
  760. zlowc_(ch__2, 1L, ch__3, 1L);
  761. if (ch__1[0] == ch__2[0]) {
  762. bump = 1;
  763. }
  764. } else {
  765. if (lin[*i - 1] == patstr[*j]) {
  766. bump = 1;
  767. }
  768. }
  769. /* Beginning of the line */
  770. } else if (patstr[*j] == -109) {
  771. if (*i == 1) {
  772. bump = 0;
  773. }
  774. /* Free match (any character) */
  775. } else if (patstr[*j] == -108) {
  776. if (lin[*i - 1] != 10 && *i <= (integer) lin_len) {
  777. bump = 1;
  778. }
  779. /* Character class */
  780. } else if (patstr[*j] == -111) {
  781. i__1 = *j + 1;
  782. if (xlsslo_(lin + (*i - 1), &patstr[1], &i__1, 1L)) {
  783. bump = 1;
  784. }
  785. /* Negated character class */
  786. } else if (patstr[*j] == -106) {
  787. i__1 = *j + 1;
  788. if (lin[*i - 1] != 10 && *i <= (integer) lin_len && ! xlsslo_(lin +
  789. (*i - 1), &patstr[1], &i__1, 1L)) {
  790. bump = 1;
  791. }
  792. /* Otherwise */
  793. } else {
  794. error_("Invalid compiled pattern", 24L);
  795. }
  796. /* If bump is no longer -1 then a match has been found */
  797. if (bump >= 0) {
  798. *i += bump;
  799. }
  800. ret_val = bump >= 0;
  801. return ret_val;
  802. } /* xlssom_ */
  803. /* ---------------------------------------------------------------------- */
  804. /* X I S S P S - Return size of pattern entry */
  805. integer xissps_(n, patstr)
  806. integer *n, *patstr;
  807. {
  808. /* System generated locals */
  809. integer ret_val;
  810. /* Parameter adjustments */
  811. --patstr;
  812. /* Function Body */
  813. if (patstr[*n] > 0) {
  814. ret_val = 1;
  815. } else if (patstr[*n] == -109 || patstr[*n] == -104 || patstr[*n] == -108
  816. || patstr[*n] == -103) {
  817. ret_val = 1;
  818. } else if (patstr[*n] == -111 || patstr[*n] == -106) {
  819. ret_val = patstr[*n + 1] + 2;
  820. } else if (patstr[*n] == -107) {
  821. ret_val = 4;
  822. } else if (patstr[*n] == -110 || patstr[*n] == -105) {
  823. ret_val = 2;
  824. } else {
  825. error_("XISSPS: Invalid pattern entry found", 35L);
  826. }
  827. return ret_val;
  828. } /* xissps_ */