| 1 | /* expect.h - include file for using the expect library, libexpect.a |
| 2 | from C or C++ (i.e., without Tcl) |
| 3 | |
| 4 | Written by: Don Libes, libes@cme.nist.gov, NIST, 12/3/90 |
| 5 | |
| 6 | Design and implementation of this program was paid for by U.S. tax |
| 7 | dollars. Therefore it is public domain. However, the author and NIST |
| 8 | would appreciate credit if this program or parts of it are used. |
| 9 | */ |
| 10 | |
| 11 | #ifndef _EXPECT_H |
| 12 | #define _EXPECT_H |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <setjmp.h> |
| 16 | |
| 17 | /* |
| 18 | * tcl.h -- |
| 19 | * |
| 20 | * This header file describes the externally-visible facilities |
| 21 | * of the Tcl interpreter. |
| 22 | * |
| 23 | * Copyright (c) 1987-1994 The Regents of the University of California. |
| 24 | * Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 25 | * Copyright (c) 1993-1996 Lucent Technologies. |
| 26 | * Copyright (c) 1998-1999 Scriptics Corporation. |
| 27 | * |
| 28 | * See the file "license.terms" for information on usage and redistribution |
| 29 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 30 | * |
| 31 | * RCS: @(#) $Id: expect.h,v 5.30 2001/11/09 19:36:18 andreas_kupries Exp $ |
| 32 | */ |
| 33 | |
| 34 | #ifndef _TCL |
| 35 | #define _TCL |
| 36 | |
| 37 | #ifndef __WIN32__ |
| 38 | # if defined(_WIN32) || defined(WIN32) |
| 39 | # define __WIN32__ |
| 40 | # endif |
| 41 | #endif |
| 42 | |
| 43 | #ifdef __WIN32__ |
| 44 | # ifndef STRICT |
| 45 | # define STRICT |
| 46 | # endif |
| 47 | # ifndef USE_PROTOTYPE |
| 48 | # define USE_PROTOTYPE 1 |
| 49 | # endif |
| 50 | # ifndef HAS_STDARG |
| 51 | # define HAS_STDARG 1 |
| 52 | # endif |
| 53 | # ifndef USE_PROTOTYPE |
| 54 | # define USE_PROTOTYPE 1 |
| 55 | # endif |
| 56 | |
| 57 | /* |
| 58 | * Under Windows we need to call Tcl_Alloc in all cases to avoid competing |
| 59 | * C run-time library issues. |
| 60 | */ |
| 61 | |
| 62 | # ifndef USE_TCLALLOC |
| 63 | # define USE_TCLALLOC 1 |
| 64 | # endif |
| 65 | #endif /* __WIN32__ */ |
| 66 | |
| 67 | /* |
| 68 | * The following definitions set up the proper options for Macintosh |
| 69 | * compilers. We use this method because there is no autoconf equivalent. |
| 70 | */ |
| 71 | |
| 72 | #ifdef MAC_TCL |
| 73 | # ifndef HAS_STDARG |
| 74 | # define HAS_STDARG 1 |
| 75 | # endif |
| 76 | # ifndef USE_TCLALLOC |
| 77 | # define USE_TCLALLOC 1 |
| 78 | # endif |
| 79 | # ifndef NO_STRERROR |
| 80 | # define NO_STRERROR 1 |
| 81 | # endif |
| 82 | #endif |
| 83 | |
| 84 | /* |
| 85 | * Utility macros: STRINGIFY takes an argument and wraps it in "" (double |
| 86 | * quotation marks), JOIN joins two arguments. |
| 87 | */ |
| 88 | |
| 89 | #define VERBATIM(x) x |
| 90 | #ifdef _MSC_VER |
| 91 | # define STRINGIFY(x) STRINGIFY1(x) |
| 92 | # define STRINGIFY1(x) #x |
| 93 | # define JOIN(a,b) JOIN1(a,b) |
| 94 | # define JOIN1(a,b) a##b |
| 95 | #else |
| 96 | # ifdef RESOURCE_INCLUDED |
| 97 | # define STRINGIFY(x) STRINGIFY1(x) |
| 98 | # define STRINGIFY1(x) #x |
| 99 | # define JOIN(a,b) JOIN1(a,b) |
| 100 | # define JOIN1(a,b) a##b |
| 101 | # else |
| 102 | # ifdef __STDC__ |
| 103 | # define STRINGIFY(x) #x |
| 104 | # define JOIN(a,b) a##b |
| 105 | # else |
| 106 | # define STRINGIFY(x) "x" |
| 107 | # define JOIN(a,b) VERBATIM(a)VERBATIM(b) |
| 108 | # endif |
| 109 | # endif |
| 110 | #endif |
| 111 | |
| 112 | /* |
| 113 | * A special definition used to allow this header file to be included |
| 114 | * in resource files so that they can get obtain version information from |
| 115 | * this file. Resource compilers don't like all the C stuff, like typedefs |
| 116 | * and procedure declarations, that occur below. |
| 117 | */ |
| 118 | |
| 119 | #ifndef RESOURCE_INCLUDED |
| 120 | |
| 121 | #ifndef BUFSIZ |
| 122 | #include <stdio.h> |
| 123 | #endif |
| 124 | |
| 125 | /* |
| 126 | * Definitions that allow Tcl functions with variable numbers of |
| 127 | * arguments to be used with either varargs.h or stdarg.h. TCL_VARARGS |
| 128 | * is used in procedure prototypes. TCL_VARARGS_DEF is used to declare |
| 129 | * the arguments in a function definiton: it takes the type and name of |
| 130 | * the first argument and supplies the appropriate argument declaration |
| 131 | * string for use in the function definition. TCL_VARARGS_START |
| 132 | * initializes the va_list data structure and returns the first argument. |
| 133 | */ |
| 134 | |
| 135 | #if defined(__STDC__) || defined(HAS_STDARG) |
| 136 | # include <stdarg.h> |
| 137 | |
| 138 | # define TCL_VARARGS(type, name) (type name, ...) |
| 139 | # define TCL_VARARGS_DEF(type, name) (type name, ...) |
| 140 | # define TCL_VARARGS_START(type, name, list) (va_start(list, name), name) |
| 141 | #else |
| 142 | # include <varargs.h> |
| 143 | |
| 144 | # ifdef __cplusplus |
| 145 | # define TCL_VARARGS(type, name) (type name, ...) |
| 146 | # define TCL_VARARGS_DEF(type, name) (type va_alist, ...) |
| 147 | # else |
| 148 | # define TCL_VARARGS(type, name) () |
| 149 | # define TCL_VARARGS_DEF(type, name) (va_alist) |
| 150 | # endif |
| 151 | # define TCL_VARARGS_START(type, name, list) \ |
| 152 | (va_start(list), va_arg(list, type)) |
| 153 | #endif |
| 154 | |
| 155 | /* |
| 156 | * Macros used to declare a function to be exported by a DLL. |
| 157 | * Used by Windows, maps to no-op declarations on non-Windows systems. |
| 158 | * The default build on windows is for a DLL, which causes the DLLIMPORT |
| 159 | * and DLLEXPORT macros to be nonempty. To build a static library, the |
| 160 | * macro STATIC_BUILD should be defined. |
| 161 | */ |
| 162 | |
| 163 | #ifdef STATIC_BUILD |
| 164 | # define DLLIMPORT |
| 165 | # define DLLEXPORT |
| 166 | #else |
| 167 | # if defined(__WIN32__) && (defined(_MSC_VER) || (defined(__GNUC__) && defined(__declspec))) |
| 168 | # define DLLIMPORT __declspec(dllimport) |
| 169 | # define DLLEXPORT __declspec(dllexport) |
| 170 | # else |
| 171 | # define DLLIMPORT |
| 172 | # define DLLEXPORT |
| 173 | # endif |
| 174 | #endif |
| 175 | |
| 176 | /* |
| 177 | * These macros are used to control whether functions are being declared for |
| 178 | * import or export. If a function is being declared while it is being built |
| 179 | * to be included in a shared library, then it should have the DLLEXPORT |
| 180 | * storage class. If is being declared for use by a module that is going to |
| 181 | * link against the shared library, then it should have the DLLIMPORT storage |
| 182 | * class. If the symbol is beind declared for a static build or for use from a |
| 183 | * stub library, then the storage class should be empty. |
| 184 | * |
| 185 | * The convention is that a macro called BUILD_xxxx, where xxxx is the |
| 186 | * name of a library we are building, is set on the compile line for sources |
| 187 | * that are to be placed in the library. When this macro is set, the |
| 188 | * storage class will be set to DLLEXPORT. At the end of the header file, the |
| 189 | * storage class will be reset to DLLIMPORt. |
| 190 | */ |
| 191 | |
| 192 | #undef TCL_STORAGE_CLASS |
| 193 | #ifdef BUILD_tcl |
| 194 | # define TCL_STORAGE_CLASS DLLEXPORT |
| 195 | #else |
| 196 | # ifdef USE_TCL_STUBS |
| 197 | # define TCL_STORAGE_CLASS |
| 198 | # else |
| 199 | # define TCL_STORAGE_CLASS DLLIMPORT |
| 200 | # endif |
| 201 | #endif |
| 202 | |
| 203 | /* |
| 204 | * Definitions that allow this header file to be used either with or |
| 205 | * without ANSI C features like function prototypes. */ |
| 206 | |
| 207 | #undef _ANSI_ARGS_ |
| 208 | #undef CONST |
| 209 | |
| 210 | #if ((defined(__STDC__) || defined(SABER)) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) || defined(USE_PROTOTYPE) |
| 211 | # define _USING_PROTOTYPES_ 1 |
| 212 | # define _ANSI_ARGS_(x) x |
| 213 | # define CONST const |
| 214 | #else |
| 215 | # define _ANSI_ARGS_(x) () |
| 216 | # define CONST |
| 217 | #endif |
| 218 | |
| 219 | #ifdef __cplusplus |
| 220 | # define EXTERN extern "C" TCL_STORAGE_CLASS |
| 221 | #else |
| 222 | # define EXTERN extern TCL_STORAGE_CLASS |
| 223 | #endif |
| 224 | |
| 225 | /* |
| 226 | * Macro to use instead of "void" for arguments that must have |
| 227 | * type "void *" in ANSI C; maps them to type "char *" in |
| 228 | * non-ANSI systems. |
| 229 | */ |
| 230 | #ifndef __WIN32__ |
| 231 | #ifndef VOID |
| 232 | # ifdef __STDC__ |
| 233 | # define VOID void |
| 234 | # else |
| 235 | # define VOID char |
| 236 | # endif |
| 237 | #endif |
| 238 | #else /* __WIN32__ */ |
| 239 | /* |
| 240 | * The following code is copied from winnt.h |
| 241 | */ |
| 242 | #ifndef VOID |
| 243 | #define VOID void |
| 244 | typedef char CHAR; |
| 245 | typedef short SHORT; |
| 246 | typedef long LONG; |
| 247 | #endif |
| 248 | #endif /* __WIN32__ */ |
| 249 | |
| 250 | /* |
| 251 | * Miscellaneous declarations. |
| 252 | */ |
| 253 | |
| 254 | #ifndef NULL |
| 255 | #define NULL 0 |
| 256 | #endif |
| 257 | |
| 258 | typedef struct Tcl_RegExp_ *Tcl_RegExp; |
| 259 | |
| 260 | /* |
| 261 | * The following declarations either map ckalloc and ckfree to |
| 262 | * malloc and free, or they map them to procedures with all sorts |
| 263 | * of debugging hooks defined in tclCkalloc.c. |
| 264 | */ |
| 265 | |
| 266 | #ifdef TCL_MEM_DEBUG |
| 267 | |
| 268 | # define Tcl_Alloc(x) Tcl_DbCkalloc(x, __FILE__, __LINE__) |
| 269 | # define Tcl_Free(x) Tcl_DbCkfree(x, __FILE__, __LINE__) |
| 270 | # define Tcl_Realloc(x,y) Tcl_DbCkrealloc((x), (y),__FILE__, __LINE__) |
| 271 | # define ckalloc(x) Tcl_DbCkalloc(x, __FILE__, __LINE__) |
| 272 | # define ckfree(x) Tcl_DbCkfree(x, __FILE__, __LINE__) |
| 273 | # define ckrealloc(x,y) Tcl_DbCkrealloc((x), (y),__FILE__, __LINE__) |
| 274 | |
| 275 | #else |
| 276 | |
| 277 | /* |
| 278 | * If USE_TCLALLOC is true, then we need to call Tcl_Alloc instead of |
| 279 | * the native malloc/free. The only time USE_TCLALLOC should not be |
| 280 | * true is when compiling the Tcl/Tk libraries on Unix systems. In this |
| 281 | * case we can safely call the native malloc/free directly as a performance |
| 282 | * optimization. |
| 283 | */ |
| 284 | |
| 285 | # if USE_TCLALLOC |
| 286 | # define ckalloc(x) Tcl_Alloc(x) |
| 287 | # define ckfree(x) Tcl_Free(x) |
| 288 | # define ckrealloc(x,y) Tcl_Realloc(x,y) |
| 289 | # else |
| 290 | # define ckalloc(x) malloc(x) |
| 291 | # define ckfree(x) free(x) |
| 292 | # define ckrealloc(x,y) realloc(x,y) |
| 293 | # endif |
| 294 | # define Tcl_DumpActiveMemory(x) |
| 295 | # define Tcl_ValidateAllMemory(x,y) |
| 296 | |
| 297 | #endif /* !TCL_MEM_DEBUG */ |
| 298 | |
| 299 | |
| 300 | /* |
| 301 | * These function have been renamed. The old names are deprecated, but we |
| 302 | * define these macros for backwards compatibilty. |
| 303 | */ |
| 304 | |
| 305 | #define Tcl_Ckalloc Tcl_Alloc |
| 306 | #define Tcl_Ckfree Tcl_Free |
| 307 | #define Tcl_Ckrealloc Tcl_Realloc |
| 308 | #define Tcl_Return Tcl_SetResult |
| 309 | #define Tcl_TildeSubst Tcl_TranslateFileName |
| 310 | |
| 311 | /* |
| 312 | * In later releases, Tcl_Panic will be the correct name to use. For now |
| 313 | * we leave it as panic to avoid breaking existing binaries. |
| 314 | */ |
| 315 | |
| 316 | #define Tcl_Panic panic |
| 317 | #define Tcl_PanicVA panicVA |
| 318 | |
| 319 | #endif /* RESOURCE_INCLUDED */ |
| 320 | |
| 321 | #undef TCL_STORAGE_CLASS |
| 322 | #define TCL_STORAGE_CLASS DLLIMPORT |
| 323 | |
| 324 | #endif /* _TCL */ |
| 325 | |
| 326 | /* |
| 327 | * end of tcl.h definitions |
| 328 | */ |
| 329 | |
| 330 | |
| 331 | /* |
| 332 | * regexp definitions - from tcl8.0/tclRegexp.h |
| 333 | */ |
| 334 | |
| 335 | /* |
| 336 | * Definitions etc. for regexp(3) routines. |
| 337 | * |
| 338 | * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], |
| 339 | * not the System V one. |
| 340 | * |
| 341 | * RCS: @(#) $Id: expect.h,v 5.30 2001/11/09 19:36:18 andreas_kupries Exp $ |
| 342 | */ |
| 343 | |
| 344 | #ifndef _REGEXP |
| 345 | #define _REGEXP 1 |
| 346 | |
| 347 | #ifdef BUILD_tcl |
| 348 | # undef TCL_STORAGE_CLASS |
| 349 | # define TCL_STORAGE_CLASS DLLEXPORT |
| 350 | #endif |
| 351 | |
| 352 | /* |
| 353 | * NSUBEXP must be at least 10, and no greater than 117 or the parser |
| 354 | * will not work properly. |
| 355 | */ |
| 356 | |
| 357 | #define NSUBEXP 20 |
| 358 | |
| 359 | typedef struct regexp { |
| 360 | char *startp[NSUBEXP]; |
| 361 | char *endp[NSUBEXP]; |
| 362 | char regstart; /* Internal use only. */ |
| 363 | char reganch; /* Internal use only. */ |
| 364 | char *regmust; /* Internal use only. */ |
| 365 | int regmlen; /* Internal use only. */ |
| 366 | char program[1]; /* Unwarranted chumminess with compiler. */ |
| 367 | } regexp; |
| 368 | |
| 369 | EXTERN regexp *TclRegComp _ANSI_ARGS_((char *exp)); |
| 370 | EXTERN int TclRegExec _ANSI_ARGS_((regexp *prog, char *string, char *start)); |
| 371 | EXTERN void TclRegSub _ANSI_ARGS_((regexp *prog, char *source, char *dest)); |
| 372 | EXTERN void exp_TclRegError _ANSI_ARGS_((char *msg)); |
| 373 | EXTERN char *TclGetRegError _ANSI_ARGS_((void)); |
| 374 | |
| 375 | # undef TCL_STORAGE_CLASS |
| 376 | # define TCL_STORAGE_CLASS DLLIMPORT |
| 377 | |
| 378 | #endif /* REGEXP */ |
| 379 | |
| 380 | |
| 381 | /* |
| 382 | * end of regexp definitions |
| 383 | */ |
| 384 | |
| 385 | |
| 386 | /* |
| 387 | * finally - expect-specific definitions |
| 388 | */ |
| 389 | |
| 390 | #include "expect_comm.h" |
| 391 | |
| 392 | enum exp_type { |
| 393 | exp_end = 0, /* placeholder - no more cases */ |
| 394 | exp_glob, /* glob-style */ |
| 395 | exp_exact, /* exact string */ |
| 396 | exp_regexp, /* regexp-style, uncompiled */ |
| 397 | exp_compiled, /* regexp-style, compiled */ |
| 398 | exp_null, /* matches binary 0 */ |
| 399 | exp_bogus /* aid in reporting compatibility problems */ |
| 400 | }; |
| 401 | |
| 402 | struct exp_case { /* case for expect command */ |
| 403 | char *pattern; |
| 404 | regexp *re; |
| 405 | enum exp_type type; |
| 406 | int value; /* value to be returned upon match */ |
| 407 | }; |
| 408 | |
| 409 | EXTERN char *exp_buffer; /* buffer of matchable chars */ |
| 410 | EXTERN char *exp_buffer_end; /* one beyond end of matchable chars */ |
| 411 | EXTERN char *exp_match; /* start of matched string */ |
| 412 | EXTERN char *exp_match_end; /* one beyond end of matched string */ |
| 413 | EXTERN int exp_match_max; /* bytes */ |
| 414 | EXTERN int exp_timeout; /* seconds */ |
| 415 | EXTERN int exp_full_buffer; /* if true, return on full buffer */ |
| 416 | EXTERN int exp_remove_nulls; /* if true, remove nulls */ |
| 417 | |
| 418 | EXTERN int exp_pty_timeout; /* see Cray hooks in source */ |
| 419 | EXTERN int exp_pid; /* process-id of spawned process */ |
| 420 | EXTERN int exp_autoallocpty; /* if TRUE, we do allocation */ |
| 421 | EXTERN int exp_pty[2]; /* master is [0], slave is [1] */ |
| 422 | EXTERN char *exp_pty_slave_name; /* name of pty slave device if we */ |
| 423 | /* do allocation */ |
| 424 | EXTERN char *exp_stty_init; /* initial stty args */ |
| 425 | EXTERN int exp_ttycopy; /* copy tty parms from /dev/tty */ |
| 426 | EXTERN int exp_ttyinit; /* set tty parms to sane state */ |
| 427 | EXTERN int exp_console; /* redirect console */ |
| 428 | |
| 429 | #ifdef HAVE_SIGLONGJMP |
| 430 | EXTERN sigjmp_buf exp_readenv; /* for interruptable read() */ |
| 431 | #else |
| 432 | EXTERN jmp_buf exp_readenv; /* for interruptable read() */ |
| 433 | #endif /* HAVE_SIGLONGJMP */ |
| 434 | |
| 435 | EXTERN int exp_reading; /* whether we can longjmp or not */ |
| 436 | #define EXP_ABORT 1 /* abort read */ |
| 437 | #define EXP_RESTART 2 /* restart read */ |
| 438 | |
| 439 | EXTERN int exp_is_debugging; |
| 440 | EXTERN int exp_loguser; |
| 441 | |
| 442 | EXTERN void (*exp_close_in_child)(); /* procedure to close files in child */ |
| 443 | EXTERN void exp_slave_control _ANSI_ARGS_((int,int)); |
| 444 | EXTERN int exp_logfile_all; |
| 445 | EXTERN FILE *exp_debugfile; |
| 446 | EXTERN FILE *exp_logfile; |
| 447 | extern void exp_debuglog _ANSI_ARGS_(TCL_VARARGS(char *,fmt)); |
| 448 | extern void exp_errorlog _ANSI_ARGS_(TCL_VARARGS(char *,fmt)); |
| 449 | |
| 450 | EXTERN int exp_disconnect _ANSI_ARGS_((void)); |
| 451 | EXTERN FILE *exp_popen _ANSI_ARGS_((char *command)); |
| 452 | EXTERN void (*exp_child_exec_prelude) _ANSI_ARGS_((void)); |
| 453 | |
| 454 | #ifndef EXP_DEFINE_FNS |
| 455 | EXTERN int exp_spawnl _ANSI_ARGS_(TCL_VARARGS(char *,file)); |
| 456 | EXTERN int exp_expectl _ANSI_ARGS_(TCL_VARARGS(int,fd)); |
| 457 | EXTERN int exp_fexpectl _ANSI_ARGS_(TCL_VARARGS(FILE *,fp)); |
| 458 | #endif |
| 459 | |
| 460 | EXTERN int exp_spawnv _ANSI_ARGS_((char *file, char *argv[])); |
| 461 | EXTERN int exp_expectv _ANSI_ARGS_((int fd, struct exp_case *cases)); |
| 462 | EXTERN int exp_fexpectv _ANSI_ARGS_((FILE *fp, struct exp_case *cases)); |
| 463 | |
| 464 | EXTERN int exp_spawnfd _ANSI_ARGS_((int fd)); |
| 465 | |
| 466 | #endif /* _EXPECT_H */ |