Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | ANSIfication changes. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7261e7297093534891e838369de10550 |
User & Date: | eee 2010-03-15 23:17:39.000 |
Context
2010-03-17
| ||
23:47 | ANSIfication changes check-in: e785babaae user: eee tags: trunk | |
2010-03-15
| ||
23:17 | ANSIfication changes. check-in: 7261e72970 user: eee tags: trunk | |
2010-03-11
| ||
21:55 | WHITESPACE CHANGES ONLY. I removed a number of form-feed characters that had been littered about the source code. check-in: 427e90617d user: eee tags: trunk | |
Changes
Changes to exp_clib.c.
︙ | ︙ | |||
47 48 49 50 51 52 53 | #include <sys/strredir.h> # ifdef SRIOCSREDIR # undef TIOCCONS # endif #endif #include <signal.h> | < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <sys/strredir.h> # ifdef SRIOCSREDIR # undef TIOCCONS # endif #endif #include <signal.h> #include <string.h> #include <errno.h> #include "expect.h" #define TclRegError exp_TclRegError /* * regexp code - from tcl8.0.4/generic/regexp.c */ |
︙ | ︙ | |||
162 163 164 165 166 167 168 | * * *** NOTE: This code has been altered for use in MT-Sturdy Tcl *** * *** 1. All use of static variables has been changed to access *** * *** fields of a structure. *** * *** 2. This in addition to changes to TclRegError makes the *** * *** code multi-thread safe. *** * | | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | * * *** NOTE: This code has been altered for use in MT-Sturdy Tcl *** * *** 1. All use of static variables has been changed to access *** * *** fields of a structure. *** * *** 2. This in addition to changes to TclRegError makes the *** * *** code multi-thread safe. *** * * RCS: @(#) $Id: exp_clib.c,v 5.34 2010/03/11 21:55:19 eee Exp $ */ #if 0 #include "tclInt.h" #include "tclPort.h" #endif |
︙ | ︙ | |||
320 321 322 323 324 325 326 | #define MAGIC 0234 /* * Forward declarations for TclRegComp()'s friends. */ | < | < | < | < | < | < | | | < | | | | < | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | #define MAGIC 0234 /* * Forward declarations for TclRegComp()'s friends. */ static char * reg(int paren, int *flagp, struct regcomp_state *rcstate); static char * regatom(int *flagp, struct regcomp_state *rcstate); static char * regbranch(int *flagp, struct regcomp_state *rcstate); static void regc(int b, struct regcomp_state *rcstate); static void reginsert(int op, char *opnd, struct regcomp_state *rcstate); static char * regnext(char *p); static char * regnode(int op, struct regcomp_state *rcstate); static void regoptail(char *p, char *val); static char * regpiece(int *flagp, struct regcomp_state *rcstate); static void regtail(char *p, char *val); #ifdef STRCSPN static int strcspn (char *s1, char *s2); #endif /* - TclRegComp - compile a regular expression into internal code * * We can't allocate space until we know how big the compiled form will be, * but we can't compile it (and thus know how big it is) until we've got a * place to put the code. So we cheat: we compile it twice, once with code * generation turned off and size counting turned on, and once "for real". * This also means that we don't allocate space until we are sure that the * thing really will compile successfully, and we never have to move the * code and thus invalidate pointers into it. (Note that it has to be in * one piece because free() must be able to free it all.) * * Beware that the optimization-preparation code in here knows about some * of the structure of the compiled regexp. */ regexp * TclRegComp(char *exp) { register regexp *r; register char *scan; register char *longest; register int len; int flags; struct regcomp_state state; |
︙ | ︙ | |||
449 450 451 452 453 454 455 | * Caller must absorb opening parenthesis. * * Combining parenthesis handling with the base level of regular expression * is a trifle forced, but the need to tie the tails of the branches to what * follows makes it hard to avoid. */ static char * | < < < | | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | * Caller must absorb opening parenthesis. * * Combining parenthesis handling with the base level of regular expression * is a trifle forced, but the need to tie the tails of the branches to what * follows makes it hard to avoid. */ static char * reg(int paren, int *flagp, struct regcomp_state *rcstate) { register char *ret; register char *br; register char *ender; register int parno = 0; int flags; |
︙ | ︙ | |||
522 523 524 525 526 527 528 | /* - regbranch - one alternative of an | operator * * Implements the concatenation operator. */ static char * | < < | | 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | /* - regbranch - one alternative of an | operator * * Implements the concatenation operator. */ static char * regbranch(int *flagp, struct regcomp_state *rcstate) { register char *ret; register char *chain; register char *latest; int flags; *flagp = WORST; /* Tentatively. */ |
︙ | ︙ | |||
563 564 565 566 567 568 569 | * Note that the branching code sequences used for ? and the general cases * of * and + are somewhat optimized: they use the same NOTHING node as * both the endmarker for their branch list and the body of the last branch. * It might seem that this node could be dispensed with entirely, but the * endmarker role is not redundant. */ static char * | < < | | 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | * Note that the branching code sequences used for ? and the general cases * of * and + are somewhat optimized: they use the same NOTHING node as * both the endmarker for their branch list and the body of the last branch. * It might seem that this node could be dispensed with entirely, but the * endmarker role is not redundant. */ static char * regpiece(int *flagp, struct regcomp_state *rcstate) { register char *ret; register char op; register char *next; int flags; ret = regatom(&flags,rcstate); |
︙ | ︙ | |||
628 629 630 631 632 633 634 | * * Optimization: gobbles an entire sequence of ordinary characters so that * it can turn them into a single node, which is smaller to store and * faster to run. Backslashed characters are exceptions, each becoming a * separate node; the code is simpler that way and it's not worth fixing. */ static char * | < < | | 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | * * Optimization: gobbles an entire sequence of ordinary characters so that * it can turn them into a single node, which is smaller to store and * faster to run. Backslashed characters are exceptions, each becoming a * separate node; the code is simpler that way and it's not worth fixing. */ static char * regatom(int *flagp, struct regcomp_state *rcstate) { register char *ret; int flags; *flagp = WORST; /* Tentatively. */ switch (*rcstate->regparse++) { |
︙ | ︙ | |||
738 739 740 741 742 743 744 | return(ret); } /* - regnode - emit a node */ static char * /* Location. */ | < < | | 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | return(ret); } /* - regnode - emit a node */ static char * /* Location. */ regnode(int op, struct regcomp_state *rcstate) { register char *ret; register char *ptr; ret = rcstate->regcode; if (ret == ®dummy) { rcstate->regsize += 3; |
︙ | ︙ | |||
764 765 766 767 768 769 770 | return(ret); } /* - regc - emit (if appropriate) a byte of code */ static void | < < | < < < | | 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | return(ret); } /* - regc - emit (if appropriate) a byte of code */ static void regc(int b; struct regcomp_state *rcstate) { if (rcstate->regcode != ®dummy) *rcstate->regcode++ = (char)b; else rcstate->regsize++; } /* - reginsert - insert an operator in front of already-emitted operand * * Means relocating the operand. */ static void reginsert(int op, char *opnd, struct regcomp_state *rcstate) { register char *src; register char *dst; register char *place; if (rcstate->regcode == ®dummy) { rcstate->regsize += 3; |
︙ | ︙ | |||
810 811 812 813 814 815 816 | *place = '\0'; } /* - regtail - set the next-pointer at the end of a node chain */ static void | | < < | 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | *place = '\0'; } /* - regtail - set the next-pointer at the end of a node chain */ static void regtail(char *p, char *val) { register char *scan; register char *temp; register int offset; if (p == ®dummy) return; |
︙ | ︙ | |||
842 843 844 845 846 847 848 | *(scan+2) = (char)(offset&0377); } /* - regoptail - regtail on operand of first argument; nop if operandless */ static void | | < < | 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | *(scan+2) = (char)(offset&0377); } /* - regoptail - regtail on operand of first argument; nop if operandless */ static void regoptail(char *p, char *val) { /* "Operandless" and "op != BRANCH" are synonymous in practice. */ if (p == NULL || p == ®dummy || OP(p) != BRANCH) return; regtail(OPERAND(p), val); } |
︙ | ︙ | |||
869 870 871 872 873 874 875 | char **regstartp; /* Pointer to startp array. */ char **regendp; /* Ditto for endp. */ }; /* * Forwards. */ | < | < | < | | | < | < < | 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | char **regstartp; /* Pointer to startp array. */ char **regendp; /* Ditto for endp. */ }; /* * Forwards. */ static int regtry (regexp *prog, char *string, struct regexec_state *restate); static int regmatch (char *prog, struct regexec_state *restate); static int regrepeat (char *p, struct regexec_state *restate); #ifdef DEBUG int regnarrate = 0; void regdump (regexp *r); static char *regprop (char *op); #endif /* - TclRegExec - match a regexp against a string */ int TclRegExec(register regexp *prog, register char *string, char *start) { register char *s; struct regexec_state state; struct regexec_state *restate= &state; /* Be paranoid... */ if (prog == NULL || string == NULL) { |
︙ | ︙ | |||
951 952 953 954 955 956 957 | return(0); } /* - regtry - try match at specific point */ static int /* 0 failure, 1 success */ | < < < | | 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | return(0); } /* - regtry - try match at specific point */ static int /* 0 failure, 1 success */ regtry(regexp *prog, char *string, struct regexec_state *restate) { register int i; register char **sp; register char **ep; restate->reginput = string; restate->regstartp = prog->startp; |
︙ | ︙ | |||
989 990 991 992 993 994 995 | * node matches, call self recursively to see whether the rest matches, * and then act accordingly. In practice we make some effort to avoid * recursion, in particular by going through "ordinary" nodes (that don't * need to know whether the rest of the match failed) by a loop instead of * by recursion. */ static int /* 0 failure, 1 success */ | < < | | 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | * node matches, call self recursively to see whether the rest matches, * and then act accordingly. In practice we make some effort to avoid * recursion, in particular by going through "ordinary" nodes (that don't * need to know whether the rest of the match failed) by a loop instead of * by recursion. */ static int /* 0 failure, 1 success */ regmatch(char *prog, struct regexec_state *restate) { register char *scan; /* Current node. */ char *next; /* Next node. */ scan = prog; #ifdef DEBUG if (scan != NULL && regnarrate) |
︙ | ︙ | |||
1190 1191 1192 1193 1194 1195 1196 | return(0); } /* - regrepeat - repeatedly match something simple, report how many */ static int | < < | | 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 | return(0); } /* - regrepeat - repeatedly match something simple, report how many */ static int regrepeat(char *p, struct regexec_state *restate) { register int count = 0; register char *scan; register char *opnd; scan = restate->reginput; opnd = OPERAND(p); |
︙ | ︙ | |||
1237 1238 1239 1240 1241 1242 1243 | return(count); } /* - regnext - dig the "next" pointer out of a node */ static char * | < | | | < | 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | return(count); } /* - regnext - dig the "next" pointer out of a node */ static char * regnext(register char *p) { register int offset; if (p == ®dummy) return(NULL); offset = NEXT(p); if (offset == 0) return(NULL); if (OP(p) == BACK) return(p-offset); else return(p+offset); } #ifdef DEBUG static char *regprop(char *); /* - regdump - dump a regexp onto stdout in vaguely comprehensible form */ void regdump(regexp *r) { register char *s; register char op = EXACTLY; /* Arbitrary non-END op. */ register char *next; s = r->program + 1; |
︙ | ︙ | |||
1306 1307 1308 1309 1310 1311 1312 | printf("\n"); } /* - regprop - printable representation of opcode */ static char * | | < | 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 | printf("\n"); } /* - regprop - printable representation of opcode */ static char * regprop(char *op) { register char *p; static char buf[50]; (void) strcpy(buf, ":"); switch (OP(op)) { |
︙ | ︙ | |||
1407 1408 1409 1410 1411 1412 1413 | #ifdef STRCSPN /* * strcspn - find length of initial segment of s1 consisting entirely * of characters not from s2 */ static int | | < < | 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 | #ifdef STRCSPN /* * strcspn - find length of initial segment of s1 consisting entirely * of characters not from s2 */ static int strcspn(char *s1, char *s2) { register char *scan1; register char *scan2; register int count; count = 0; for (scan1 = s1; *scan1 != '\0'; scan1++) { |
︙ | ︙ | |||
1445 1446 1447 1448 1449 1450 1451 | * Side effects: * The value of "string" is saved in "errMsg". * *---------------------------------------------------------------------- */ void | | < | | 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 | * Side effects: * The value of "string" is saved in "errMsg". * *---------------------------------------------------------------------- */ void exp_TclRegError(char *string) { errMsg = string; } char * TclGetRegError(void) { return errMsg; } /* * end of regexp definitions and code */ |
︙ | ︙ | |||
1490 1491 1492 1493 1494 1495 1496 | * None. * *---------------------------------------------------------------------- */ static char * | | < | 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 | * None. * *---------------------------------------------------------------------- */ static char * Tcl_ErrnoMsg(int err) { switch (err) { #ifdef E2BIG case E2BIG: return "argument list too long"; #endif #ifdef EACCES case EACCES: return "permission denied"; |
︙ | ︙ | |||
1928 1929 1930 1931 1932 1933 1934 | /* * stolen from exp_log.c - this function is called from the Expect library * but the one that the library supplies calls Tcl functions. So we supply * our own. */ | | < | < | 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 | /* * stolen from exp_log.c - this function is called from the Expect library * but the one that the library supplies calls Tcl functions. So we supply * our own. */ static void expDiagLogU(char *str) { if (exp_is_debugging) { fprintf(stderr,str); if (exp_logfile) fprintf(exp_logfile,str); } } |
︙ | ︙ | |||
1969 1970 1971 1972 1973 1974 1975 | * Like Tcl_StringMatch except that * 1) returns number of characters matched, -1 if failed. * (Can return 0 on patterns like "" or "$") * 2) does not require pattern to match to end of string * 3) much of code is stolen from Tcl_StringMatch * 4) front-anchor is assumed (Tcl_StringMatch retries for non-front-anchor) */ | | < | < < < | 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 | * Like Tcl_StringMatch except that * 1) returns number of characters matched, -1 if failed. * (Can return 0 on patterns like "" or "$") * 2) does not require pattern to match to end of string * 3) much of code is stolen from Tcl_StringMatch * 4) front-anchor is assumed (Tcl_StringMatch retries for non-front-anchor) */ static int Exp_StringMatch2(register char *string, register char *pattern) { char c2; int match = 0; /* # of chars matched */ while (1) { /* If at end of pattern, success! */ if (*pattern == 0) { |
︙ | ︙ | |||
2102 2103 2104 2105 2106 2107 2108 | thisCharOK: pattern += 1; string += 1; match++; } } | < | < < | < | 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 | thisCharOK: pattern += 1; string += 1; match++; } } static int /* returns # of chars that matched */ Exp_StringMatch(char *string, char *pattern, int *offset) { char *s; int sm; /* count of chars matched or -1 */ int caret = FALSE; int star = FALSE; *offset = 0; |
︙ | ︙ | |||
2150 2151 2152 2153 2154 2155 2156 | } return -1; } #define EXP_MATCH_MAX 2000 /* public */ | | | | | | | | | | | | | | | 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 | } return -1; } #define EXP_MATCH_MAX 2000 /* public */ char *exp_buffer = NULL; char *exp_buffer_end = NULL; char *exp_match = NULL; char *exp_match_end = NULL; int exp_match_max = EXP_MATCH_MAX; /* bytes */ int exp_full_buffer = FALSE; /* don't return on full buffer */ int exp_remove_nulls = TRUE; int exp_timeout = 10; /* seconds */ int exp_pty_timeout = 5; /* seconds - see CRAY below */ int exp_autoallocpty = TRUE; /* if TRUE, we do allocation */ int exp_pty[2]; /* master is [0], slave is [1] */ int exp_pid; char *exp_stty_init = NULL; /* initial stty args */ int exp_ttycopy = TRUE; /* copy tty parms from /dev/tty */ int exp_ttyinit = TRUE; /* set tty parms to sane state */ int exp_console = FALSE; /* redirect console */ void (*exp_child_exec_prelude)() = NULL; void (*exp_close_in_child)() = NULL; #ifdef HAVE_SIGLONGJMP sigjmp_buf exp_readenv; /* for interruptable read() */ #else jmp_buf exp_readenv; /* for interruptable read() */ #endif /* HAVE_SIGLONGJMP */ int exp_reading = FALSE; /* whether we can longjmp or not */ int exp_is_debugging = FALSE; FILE *exp_debugfile = NULL; FILE *exp_logfile = NULL; int exp_logfile_all = FALSE; /* if TRUE, write log of all interactions */ int exp_loguser = TRUE; /* if TRUE, user sees interactions on stdout */ char *exp_printify(char *); int exp_getptymaster(void); int exp_getptyslave(int, int, CONST char *); #define sysreturn(x) return(errno = x, -1) void exp_init_pty(void); /* The following functions are linked from the Tcl library. They don't cause anything else in the library to be dragged in, so it shouldn't cause any problems (e.g., bloat). The functions are relatively small but painful enough that I don't care |
︙ | ︙ | |||
2219 2220 2221 2222 2223 2224 2225 | /* actual size is one larger for null */ } *fs = 0; static int fd_alloc_max = -1; /* max fd allocated */ /* translate fd or fp to fd */ static struct f * | | < < | < | 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 | /* actual size is one larger for null */ } *fs = 0; static int fd_alloc_max = -1; /* max fd allocated */ /* translate fd or fp to fd */ static struct f * fdfp2f(int fd, FILE *fp) { if (fd == -1) return(fs + fileno(fp)); else return(fs + fd); } static struct f * fd_new(int fd) { int i, low; struct f *fp; struct f *newfs; /* temporary, so we don't lose old fs */ if (fd > fd_alloc_max) { if (!fs) { /* no fd's yet allocated */ |
︙ | ︙ | |||
2265 2266 2267 2268 2269 2270 2271 | } fp->buffer_end = fp->buffer; fp->match_end = fp->buffer; return fp; } | | < | | < < | 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 | } fp->buffer_end = fp->buffer; fp->match_end = fp->buffer; return fp; } static void exp_setpgrp(void) { #ifdef MIPS_BSD /* required on BSD side of MIPS OS <[email protected]> */ # include <sysv/sys.s> syscall(SYS_setpgrp); #endif #ifdef SETPGRP_VOID (void) setpgrp(); #else (void) setpgrp(0,0); #endif } /* returns fd of master side of pty */ int exp_spawnv(char *file, char *argv[]) { int cc; int errorfd; /* place to stash fileno(stderr) in child */ /* while we're setting up new stderr */ int ttyfd; int sync_fds[2]; int sync2_fds[2]; |
︙ | ︙ | |||
2718 2719 2720 2721 2722 2723 2724 | i = exp_spawnv(argv[0],argv+1); free((char *)argv); return(i); } /* allow user-provided fd to be passed to expect funcs */ int | | < | < < | 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 | i = exp_spawnv(argv[0],argv+1); free((char *)argv); return(i); } /* allow user-provided fd to be passed to expect funcs */ int exp_spawnfd(int fd) { if (!fd_new(fd)) { errno = ENOMEM; return -1; } return fd; } /* remove nulls from s. Initially, the number of chars in s is c, */ /* not strlen(s). This count does not include the trailing null. */ /* returns number of nulls removed. */ static int rm_nulls(char *s, int c) { char *s2 = s; /* points to place in original string to put */ /* next non-null character */ int count = 0; int i; for (i=0;i<c;i++,s++) { |
︙ | ︙ | |||
2757 2758 2759 2760 2761 2762 2763 | } static int i_read_errno;/* place to save errno, if i_read() == -1, so it doesn't get overwritten before we get to read it */ /*ARGSUSED*/ static void | | < < < < | < < | 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 | } static int i_read_errno;/* place to save errno, if i_read() == -1, so it doesn't get overwritten before we get to read it */ /*ARGSUSED*/ static void sigalarm_handler(int n) { #ifdef REARM_SIG signal(SIGALRM,sigalarm_handler); #endif #ifdef HAVE_SIGLONGJMP siglongjmp(exp_readenv,1); #else longjmp(exp_readenv,1); #endif /* HAVE_SIGLONGJMP */ } /* interruptable read */ static int i_read(int fd, FILE *fp, char *buffer, int length, int timeout) { int cc = -2; /* since setjmp insists on returning 1 upon longjmp(,0), */ /* longjmp(,2 (EXP_RESTART)) instead. */ /* no need to set alarm if -1 (infinite) or 0 (poll with */ |
︙ | ︙ | |||
2880 2881 2882 2883 2884 2885 2886 | /* the key internal variables that this function depends on are: exp_buffer exp_buffer_end exp_match_end */ static int | < < < | | 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 | /* the key internal variables that this function depends on are: exp_buffer exp_buffer_end exp_match_end */ static int expectv(int fd, FILE *fp, struct exp_case *ecases) { int cc = 0; /* number of chars returned in a single read */ int buf_length; /* numbers of chars in exp_buffer */ int old_length; /* old buf_length */ int first_time = TRUE; /* force old buffer to be tested before */ /* additional reads */ int polled = 0; /* true if poll has caused read() to occur */ |
︙ | ︙ | |||
3146 3147 3148 3149 3150 3151 3152 | errno = sys_error; return -1; } return return_val; } int | < < | < < | | 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 | errno = sys_error; return -1; } return return_val; } int exp_fexpectv(FILE *fp, struct exp_case *ecases) { return(expectv(-1,fp,ecases)); } int exp_expectv(int fd, struct exp_case *ecases) { return(expectv(fd,(FILE *)0,ecases)); } /*VARARGS*/ int exp_expectl TCL_VARARGS_DEF(int,arg1) |
︙ | ︙ | |||
3296 3297 3298 3299 3300 3301 3302 | } free((char *)ecases); return(i); } /* like popen(3) but works in both directions */ FILE * | | < | | 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 | } free((char *)ecases); return(i); } /* like popen(3) but works in both directions */ FILE * exp_popen(char *program) { FILE *fp; int ec; if (0 > (ec = exp_spawnl("sh","sh","-c",program,(char *)0))) return(0); if (!(fp = fdopen(ec,"r+"))) return(0); setbuf(fp,(char *)0); return(fp); } int exp_disconnect(void) { int ttyfd; #ifndef EALREADY #define EALREADY 37 #endif |
︙ | ︙ | |||
3392 3393 3394 3395 3396 3397 3398 | if (exp_logfile) vfprintf(exp_logfile,fmt,args); va_end(args); } #include <ctype.h> char * | | < | 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 | if (exp_logfile) vfprintf(exp_logfile,fmt,args); va_end(args); } #include <ctype.h> char * exp_printify(char *s) { static int destlen = 0; static char *dest = 0; char *d; /* ptr into dest */ unsigned int need; if (s == 0) return("<null>"); |
︙ | ︙ |
Changes to exp_command.c.
︙ | ︙ | |||
302 303 304 305 306 307 308 | return esPtr->fdin; #else return name[0]; /* pacify lint, use arg and return something */ #endif } | | < | 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | return esPtr->fdin; #else return name[0]; /* pacify lint, use arg and return something */ #endif } static void expBusy(ExpState *esPtr) { int x = open("/dev/null",0); if (x != esPtr->fdin) { fcntl(x,F_DUPFD,esPtr->fdin); close(x); } |
︙ | ︙ | |||
421 422 423 424 425 426 427 | { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); return (tsdPtr->stdinout == esPtr); } ExpState * | | | | 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); return (tsdPtr->stdinout == esPtr); } ExpState * expStdinoutGet(void) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); return tsdPtr->stdinout; } ExpState * expDevttyGet(void) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); return tsdPtr->devtty; } void |
︙ | ︙ | |||
528 529 530 531 532 533 534 | int pgrp = getpgrp(0); if (-1 == ioctl(fd,TIOCSETPGRP,&pgrp)) perror("TIOCSETPGRP"); if (-1 == ioctl(fd,TIOCSPGRP,&pgrp)) perror("TIOCSPGRP"); if (-1 == tcsetpgrp(fd,pgrp)) perror("tcsetpgrp"); } #endif | | < | | 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | int pgrp = getpgrp(0); if (-1 == ioctl(fd,TIOCSETPGRP,&pgrp)) perror("TIOCSETPGRP"); if (-1 == ioctl(fd,TIOCSPGRP,&pgrp)) perror("TIOCSPGRP"); if (-1 == tcsetpgrp(fd,pgrp)) perror("tcsetpgrp"); } #endif static void expSetpgrp(void) { #ifdef MIPS_BSD /* required on BSD side of MIPS OS <[email protected]> */ # include <sysv/sys.s> syscall(SYS_setpgrp); #endif |
︙ | ︙ | |||
1581 1582 1583 1584 1585 1586 1587 | { /* current implementation is pathetic but works */ /* 99991 is largest prime in my CRC - can't hurt, eh? */ return((float)(1+(rand()%99991))/99991.0); } void | | | 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 | { /* current implementation is pathetic but works */ /* 99991 is largest prime in my CRC - can't hurt, eh? */ return((float)(1+(rand()%99991))/99991.0); } void exp_init_unit_random(void) { srand(getpid()); } /* This function is my implementation of the Weibull distribution. */ /* I've added a max time and an "alpha_eow" that captures the slight */ /* but noticable change in human typists when hitting end-of-word */ |
︙ | ︙ | |||
1642 1643 1644 1645 1646 1647 1648 | struct exp_i *exp_i_pool = 0; struct exp_state_list *exp_state_list_pool = 0; #define EXP_I_INIT_COUNT 10 #define EXP_FD_INIT_COUNT 10 struct exp_i * | | | 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 | struct exp_i *exp_i_pool = 0; struct exp_state_list *exp_state_list_pool = 0; #define EXP_I_INIT_COUNT 10 #define EXP_FD_INIT_COUNT 10 struct exp_i * exp_new_i(void) { int n; struct exp_i *i; if (!exp_i_pool) { /* none avail, generate some new ones */ exp_i_pool = i = (struct exp_i *)ckalloc( |
︙ | ︙ | |||
2802 2803 2804 2805 2806 2807 2808 | int pid; WAIT_STATUS_TYPE wait_status; enum {not_in_use, wait_done, wait_not_done} link_status; struct forked_proc *next; } *forked_proc_base = 0; void | | | 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 | int pid; WAIT_STATUS_TYPE wait_status; enum {not_in_use, wait_done, wait_not_done} link_status; struct forked_proc *next; } *forked_proc_base = 0; void fork_clear_all(void) { struct forked_proc *f; for (f=forked_proc_base;f;f=f->next) { f->link_status = not_in_use; } } |
︙ | ︙ | |||
2861 2862 2863 2864 2865 2866 2867 | static int Exp_WaitObjCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) /* Argument objects. */ { | | | | | 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 | static int Exp_WaitObjCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) /* Argument objects. */ { char *chanName = NULL; struct ExpState *esPtr; struct forked_proc *fp = NULL; /* handle to a pure forked proc */ struct ExpState esTmp; /* temporary memory for either f or fp */ char spawn_id[20]; int nowait = FALSE; int result = 0; /* 0 means child was successfully waited on */ /* -1 means an error occurred */ /* -2 means no eligible children to wait on */ |
︙ | ︙ | |||
3499 3500 3501 3502 3503 3504 3505 | if (*string != *flag) return 0; } if (*string == '\0' && minlen <= 0) return 1; return 0; } void | | < < | 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 | if (*string != *flag) return 0; } if (*string == '\0' && minlen <= 0) return 1; return 0; } void exp_create_commands(Tcl_Interp *interp, struct exp_cmd_data *c) { Namespace *globalNsPtr = (Namespace *) Tcl_GetGlobalNamespace(interp); Namespace *currNsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp); char cmdnamebuf[80]; for (;c->name;c++) { /* if already defined, don't redefine */ |
︙ | ︙ |
Changes to exp_command.h.
︙ | ︙ | |||
23 24 25 26 27 28 29 | # undef panic #endif #include <tclPort.h> #define EXP_CHANNELNAMELEN (16 + TCL_INTEGER_SPACE) | | | | < | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # undef panic #endif #include <tclPort.h> #define EXP_CHANNELNAMELEN (16 + TCL_INTEGER_SPACE) EXTERN char * exp_get_var (Tcl_Interp *,char *); EXTERN int exp_default_match_max; EXTERN int exp_default_parity; EXTERN int exp_default_rm_nulls; EXTERN int exp_default_close_on_eof; EXTERN int exp_one_arg_braced (Tcl_Obj *); EXTERN Tcl_Obj* exp_eval_with_one_arg (ClientData, Tcl_Interp *, struct Tcl_Obj * CONST objv[]); EXTERN void exp_lowmemcpy (char *,char *,int); EXTERN int exp_flageq_code (char *,char *,int); #define exp_flageq(flag,string,minlen) \ (((string)[0] == (flag)[0]) && (exp_flageq_code(((flag)+1),((string)+1),((minlen)-1)))) /* exp_flageq for single char flags */ #define exp_flageq1(flag,string) \ ((string[0] == flag) && (string[1] == '\0')) |
︙ | ︙ | |||
205 206 207 208 209 210 211 | #define EXP_TEMPORARY 1 /* expect */ #define EXP_PERMANENT 2 /* expect_after, expect_before, expect_bg */ #define EXP_DIRECT 1 #define EXP_INDIRECT 2 | | | | | | | | < | | | | | | | | | | | | | | | | | | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | #define EXP_TEMPORARY 1 /* expect */ #define EXP_PERMANENT 2 /* expect_after, expect_before, expect_bg */ #define EXP_DIRECT 1 #define EXP_INDIRECT 2 EXTERN void expAdjust (ExpState *); EXTERN int expWriteChars (ExpState *,char *,int); EXTERN int expWriteCharsUni (ExpState *,Tcl_UniChar *,int); EXTERN void exp_buffer_shuffle (Tcl_Interp *,ExpState *,int,char *,char *); EXTERN int exp_close (Tcl_Interp *,ExpState *); EXTERN void exp_close_all (Tcl_Interp *); EXTERN void exp_ecmd_remove_fd_direct_and_indirect (Tcl_Interp *,int); EXTERN void exp_trap_on (int); EXTERN int exp_trap_off (char *); EXTERN void exp_strftime(char *format, const struct tm *timeptr,Tcl_DString *dstring); #define exp_deleteProc (void (*)())0 #define exp_deleteObjProc (void (*)())0 EXTERN int expect_key; EXTERN int exp_configure_count; /* # of times descriptors have been closed */ /* or indirect lists have been changed */ EXTERN int exp_nostack_dump; /* TRUE if user has requested unrolling of */ /* stack with no trace */ EXTERN void exp_init_pty (void); EXTERN void exp_pty_exit (void); EXTERN void exp_init_tty (void); EXTERN void exp_init_stdio (void); /*EXTERN void exp_init_expect (Tcl_Interp *);*/ EXTERN void exp_init_spawn_ids (Tcl_Interp *); EXTERN void exp_init_spawn_id_vars (Tcl_Interp *); EXTERN void exp_init_trap (void); EXTERN void exp_init_send (void); EXTERN void exp_init_unit_random (void); EXTERN void exp_init_sig (void); EXTERN void expChannelInit (void); EXTERN int expChannelCountGet (void); EXTERN int exp_tcl2_returnvalue (int); EXTERN int exp_2tcl_returnvalue (int); EXTERN void exp_rearm_sigchld (Tcl_Interp *); EXTERN int exp_string_to_signal (Tcl_Interp *,char *); EXTERN char *exp_onexit_action; #define exp_new(x) (x *)malloc(sizeof(x)) struct exp_state_list { ExpState *esPtr; |
︙ | ︙ | |||
281 282 283 284 285 286 287 | int ecount; /* # of ecases this is used by */ struct exp_state_list *state_list; struct exp_i *next; }; | | < | | | < | | | < | < | | | | | | | | | | | | | | | | | | | | | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | int ecount; /* # of ecases this is used by */ struct exp_state_list *state_list; struct exp_i *next; }; EXTERN struct exp_i * exp_new_i_complex (Tcl_Interp *, char *, int, Tcl_VarTraceProc *); EXTERN struct exp_i * exp_new_i_simple (ExpState *,int); EXTERN struct exp_state_list *exp_new_state (ExpState *); EXTERN void exp_free_i (Tcl_Interp *,struct exp_i *, Tcl_VarTraceProc *); EXTERN void exp_free_state (struct exp_state_list *); EXTERN void exp_free_state_single (struct exp_state_list *); EXTERN int exp_i_update (Tcl_Interp *, struct exp_i *); /* * definitions for creating commands */ #define EXP_NOPREFIX 1 /* don't define with "exp_" prefix */ #define EXP_REDEFINE 2 /* stomp on old commands with same name */ #define exp_proc(cmdproc) 0, cmdproc struct exp_cmd_data { char *name; Tcl_ObjCmdProc *objproc; Tcl_CmdProc *proc; ClientData data; int flags; }; EXTERN void exp_create_commands (Tcl_Interp *, struct exp_cmd_data *); EXTERN void exp_init_main_cmds (Tcl_Interp *); EXTERN void exp_init_expect_cmds (Tcl_Interp *); EXTERN void exp_init_most_cmds (Tcl_Interp *); EXTERN void exp_init_trap_cmds (Tcl_Interp *); EXTERN void exp_init_interact_cmds (Tcl_Interp *); EXTERN void exp_init_tty_cmds(); EXTERN ExpState * expStateCheck (Tcl_Interp *,ExpState *,int,int,char *); EXTERN ExpState * expStateCurrent (Tcl_Interp *,int,int,int); EXTERN ExpState * expStateFromChannelName (Tcl_Interp *,char *,int,int,int,char *); EXTERN void expStateFree (ExpState *); EXTERN ExpState * expCreateChannel (Tcl_Interp *,int,int,int); EXTERN ExpState * expWaitOnAny (void); EXTERN ExpState * expWaitOnOne (void); EXTERN void expExpectVarsInit (void); EXTERN int expStateAnyIs (ExpState *); EXTERN int expDevttyIs (ExpState *); EXTERN int expStdinoutIs (ExpState *); EXTERN ExpState * expStdinoutGet (void); EXTERN ExpState * expDevttyGet (void); /* generic functions that really should be provided by Tcl */ #if 0 /* Redefined as macros. */ EXTERN int expSizeGet (ExpState *); EXTERN int expSizeZero (ExpState *); #else #define expSizeGet(esPtr) ((esPtr)->input.use) #define expSizeZero(esPtr) (((esPtr)->input.use) == 0) #endif #define EXP_CMDINFO_CLOSE "expect/cmdinfo/close" #define EXP_CMDINFO_RETURN "expect/cmdinfo/return" |
︙ | ︙ |
Changes to exp_console.c.
︙ | ︙ | |||
34 35 36 37 38 39 40 | #include "tcl.h" #include "exp_rename.h" #include "exp_prog.h" #include "exp_command.h" #include "exp_log.h" static void | | < | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include "tcl.h" #include "exp_rename.h" #include "exp_prog.h" #include "exp_command.h" #include "exp_log.h" static void exp_console_manipulation_failed(char *s) { expErrorLog("expect: spawn: cannot %s console, check permissions of /dev/console\n",s); exit(-1); } void exp_console_set(void) { #ifdef SRIOCSREDIR int fd; if ((fd = open("/dev/console", O_RDONLY)) == -1) { exp_console_manipulation_failed("open"); } |
︙ | ︙ |
Changes to exp_event.c.
︙ | ︙ | |||
28 29 30 31 32 33 34 | typedef struct ThreadSpecificData { int rr; /* round robin ptr */ } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; void | | < | < | < | < | < | < | < | < | < < | < | | | | | | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | typedef struct ThreadSpecificData { int rr; /* round robin ptr */ } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; void exp_event_disarm_bg(ExpState *esPtr) { Tcl_DeleteChannelHandler(esPtr->channel,exp_background_channelhandler,(ClientData)esPtr); } static void exp_arm_background_channelhandler_force(ExpState *esPtr) { Tcl_CreateChannelHandler(esPtr->channel, TCL_READABLE|TCL_EXCEPTION, exp_background_channelhandler, (ClientData)esPtr); esPtr->bg_status = armed; } void exp_arm_background_channelhandler( ExpState *esPtr) { switch (esPtr->bg_status) { case unarmed: exp_arm_background_channelhandler_force(esPtr); break; case disarm_req_while_blocked: esPtr->bg_status = blocked; /* forget request */ break; case armed: case blocked: /* do nothing */ break; } } void exp_disarm_background_channelhandler( ExpState *esPtr) { switch (esPtr->bg_status) { case blocked: esPtr->bg_status = disarm_req_while_blocked; break; case armed: esPtr->bg_status = unarmed; exp_event_disarm_bg(esPtr); break; case disarm_req_while_blocked: case unarmed: /* do nothing */ break; } } /* ignore block status and forcibly disarm handler - called from exp_close. */ /* After exp_close returns, we will not have an opportunity to disarm */ /* because the fd will be invalid, so we force it here. */ void exp_disarm_background_channelhandler_force( ExpState *esPtr) { switch (esPtr->bg_status) { case blocked: case disarm_req_while_blocked: case armed: esPtr->bg_status = unarmed; exp_event_disarm_bg(esPtr); break; case unarmed: /* do nothing */ break; } } /* this can only be called at the end of the bg handler in which */ /* case we know the status is some kind of "blocked" */ void exp_unblock_background_channelhandler( ExpState *esPtr) { switch (esPtr->bg_status) { case blocked: exp_arm_background_channelhandler_force(esPtr); break; case disarm_req_while_blocked: exp_disarm_background_channelhandler_force(esPtr); break; } } /* this can only be called at the beginning of the bg handler in which */ /* case we know the status must be "armed" */ void exp_block_background_channelhandler( ExpState *esPtr) { esPtr->bg_status = blocked; exp_event_disarm_bg(esPtr); } /*ARGSUSED*/ static void exp_timehandler( ClientData clientData) { *(int *)clientData = TRUE; } static void exp_channelhandler( ClientData clientData, int mask) { ExpState *esPtr = (ExpState *)clientData; esPtr->notified = TRUE; esPtr->notifiedMask = mask; exp_event_disarm_fg(esPtr); } void exp_event_disarm_fg( ExpState *esPtr) { /*printf("DeleteChannelHandler: %s\r\n",esPtr->name);*/ Tcl_DeleteChannelHandler(esPtr->channel,exp_channelhandler,(ClientData)esPtr); /* remember that ChannelHandler has been disabled so that */ /* it can be turned on for fg expect's as well as bg */ esPtr->fg_armed = FALSE; } /* returns status, one of EOF, TIMEOUT, ERROR or DATA */ /* can now return RECONFIGURE, too */ /*ARGSUSED*/ int exp_get_next_event( Tcl_Interp *interp, ExpState *(esPtrs[]), int n, /* # of esPtrs */ ExpState **esPtrOut, /* 1st ready esPtr, not set if none */ int timeout, /* seconds */ int key) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); ExpState *esPtr; int i; /* index into in-array */ #ifdef HAVE_PTYTRAP struct request_info ioctl_info; |
︙ | ︙ | |||
277 278 279 280 281 282 283 | } } /* Having been told there was an event for a specific ExpState, get it */ /* This returns status, one of EOF, TIMEOUT, ERROR or DATA */ /*ARGSUSED*/ int | | < < | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | } } /* Having been told there was an event for a specific ExpState, get it */ /* This returns status, one of EOF, TIMEOUT, ERROR or DATA */ /*ARGSUSED*/ int exp_get_next_event_info( Tcl_Interp *interp, ExpState *esPtr) { #ifdef HAVE_PTYTRAP struct request_info ioctl_info; #endif if (esPtr->notifiedMask & TCL_READABLE) return EXP_DATA_NEW; |
︙ | ︙ | |||
311 312 313 314 315 316 317 | /* it will be thrown away by caller anyway */ return EXP_TCLERROR; #endif } /*ARGSUSED*/ int /* returns TCL_XXX */ | < | < | < | | 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | /* it will be thrown away by caller anyway */ return EXP_TCLERROR; #endif } /*ARGSUSED*/ int /* returns TCL_XXX */ exp_dsleep( Tcl_Interp *interp, double sec) { int timerFired = FALSE; Tcl_CreateTimerHandler((int)(sec*1000),exp_timehandler,(ClientData)&timerFired); while (!timerFired) { Tcl_DoOneEvent(0); } return TCL_OK; } static char destroy_cmd[] = "destroy ."; static void exp_event_exit_real( Tcl_Interp *interp) { Tcl_Eval(interp,destroy_cmd); } /* set things up for later calls to event handler */ void exp_init_event(void) { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); tsdPtr->rr = 0; exp_event_exit = exp_event_exit_real; } |