grep.c 22 KB

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