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.32 2010/07/01 00:53:49 eee 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 * These function have been renamed. The old names are deprecated, but we 262 * define these macros for backwards compatibilty. 263 */ 264 265 #define Tcl_Ckalloc Tcl_Alloc 266 #define Tcl_Ckfree Tcl_Free 267 #define Tcl_Ckrealloc Tcl_Realloc 268 #define Tcl_Return Tcl_SetResult 269 #define Tcl_TildeSubst Tcl_TranslateFileName 270 271 #endif /* RESOURCE_INCLUDED */ 272 273 #undef TCL_STORAGE_CLASS 274 #define TCL_STORAGE_CLASS DLLIMPORT 275 276 #endif /* _TCL */ 277 278 /* 279 * end of tcl.h definitions 280 */ 281 282 283 /* 284 * regexp definitions - from tcl8.0/tclRegexp.h 285 */ 286 287 /* 288 * Definitions etc. for regexp(3) routines. 289 * 290 * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], 291 * not the System V one. 292 * 293 * RCS: @(#) $Id: expect.h,v 5.32 2010/07/01 00:53:49 eee Exp $ 294 */ 295 296 #ifndef _REGEXP 297 #define _REGEXP 1 298 299 #ifdef BUILD_tcl 300 # undef TCL_STORAGE_CLASS 301 # define TCL_STORAGE_CLASS DLLEXPORT 302 #endif 303 304 /* 305 * NSUBEXP must be at least 10, and no greater than 117 or the parser 306 * will not work properly. 307 */ 308 309 #define NSUBEXP 20 310 311 typedef struct regexp { 312 char *startp[NSUBEXP]; 313 char *endp[NSUBEXP]; 314 char regstart; /* Internal use only. */ 315 char reganch; /* Internal use only. */ 316 char *regmust; /* Internal use only. */ 317 int regmlen; /* Internal use only. */ 318 char program[1]; /* Unwarranted chumminess with compiler. */ 319 } regexp; 320 321 EXTERN regexp *TclRegComp _ANSI_ARGS_((char *exp)); 322 EXTERN int TclRegExec _ANSI_ARGS_((regexp *prog, char *string, char *start)); 323 EXTERN void TclRegSub _ANSI_ARGS_((regexp *prog, char *source, char *dest)); 324 EXTERN void exp_TclRegError _ANSI_ARGS_((char *msg)); 325 EXTERN char *TclGetRegError _ANSI_ARGS_((void)); 326 327 # undef TCL_STORAGE_CLASS 328 # define TCL_STORAGE_CLASS DLLIMPORT 329 330 #endif /* REGEXP */ 331 332 333 /* 334 * end of regexp definitions 335 */ 336 337 338 /* 339 * finally - expect-specific definitions 340 */ 341 342 #include "expect_comm.h" 343 344 enum exp_type { 345 exp_end = 0, /* placeholder - no more cases */ 346 exp_glob, /* glob-style */ 347 exp_exact, /* exact string */ 348 exp_regexp, /* regexp-style, uncompiled */ 349 exp_compiled, /* regexp-style, compiled */ 350 exp_null, /* matches binary 0 */ 351 exp_bogus /* aid in reporting compatibility problems */ 352 }; 353 354 struct exp_case { /* case for expect command */ 355 char *pattern; 356 regexp *re; 357 enum exp_type type; 358 int value; /* value to be returned upon match */ 359 }; 360 361 EXTERN char *exp_buffer; /* buffer of matchable chars */ 362 EXTERN char *exp_buffer_end; /* one beyond end of matchable chars */ 363 EXTERN char *exp_match; /* start of matched string */ 364 EXTERN char *exp_match_end; /* one beyond end of matched string */ 365 EXTERN int exp_match_max; /* bytes */ 366 EXTERN int exp_timeout; /* seconds */ 367 EXTERN int exp_full_buffer; /* if true, return on full buffer */ 368 EXTERN int exp_remove_nulls; /* if true, remove nulls */ 369 370 EXTERN int exp_pty_timeout; /* see Cray hooks in source */ 371 EXTERN int exp_pid; /* process-id of spawned process */ 372 EXTERN int exp_autoallocpty; /* if TRUE, we do allocation */ 373 EXTERN int exp_pty[2]; /* master is [0], slave is [1] */ 374 EXTERN char *exp_pty_slave_name; /* name of pty slave device if we */ 375 /* do allocation */ 376 EXTERN char *exp_stty_init; /* initial stty args */ 377 EXTERN int exp_ttycopy; /* copy tty parms from /dev/tty */ 378 EXTERN int exp_ttyinit; /* set tty parms to sane state */ 379 EXTERN int exp_console; /* redirect console */ 380 381 #ifdef HAVE_SIGLONGJMP 382 EXTERN sigjmp_buf exp_readenv; /* for interruptable read() */ 383 #else 384 EXTERN jmp_buf exp_readenv; /* for interruptable read() */ 385 #endif /* HAVE_SIGLONGJMP */ 386 387 EXTERN int exp_reading; /* whether we can longjmp or not */ 388 #define EXP_ABORT 1 /* abort read */ 389 #define EXP_RESTART 2 /* restart read */ 390 391 EXTERN int exp_is_debugging; 392 EXTERN int exp_loguser; 393 394 EXTERN void (*exp_close_in_child)(); /* procedure to close files in child */ 395 EXTERN void exp_slave_control _ANSI_ARGS_((int,int)); 396 EXTERN int exp_logfile_all; 397 EXTERN FILE *exp_debugfile; 398 EXTERN FILE *exp_logfile; 399 extern void exp_debuglog _ANSI_ARGS_(TCL_VARARGS(char *,fmt)); 400 extern void exp_errorlog _ANSI_ARGS_(TCL_VARARGS(char *,fmt)); 401 402 EXTERN int exp_disconnect _ANSI_ARGS_((void)); 403 EXTERN FILE *exp_popen _ANSI_ARGS_((char *command)); 404 EXTERN void (*exp_child_exec_prelude) _ANSI_ARGS_((void)); 405 406 #ifndef EXP_DEFINE_FNS 407 EXTERN int exp_spawnl _ANSI_ARGS_(TCL_VARARGS(char *,file)); 408 EXTERN int exp_expectl _ANSI_ARGS_(TCL_VARARGS(int,fd)); 409 EXTERN int exp_fexpectl _ANSI_ARGS_(TCL_VARARGS(FILE *,fp)); 410 #endif 411 412 EXTERN int exp_spawnv _ANSI_ARGS_((char *file, char *argv[])); 413 EXTERN int exp_expectv _ANSI_ARGS_((int fd, struct exp_case *cases)); 414 EXTERN int exp_fexpectv _ANSI_ARGS_((FILE *fp, struct exp_case *cases)); 415 416 EXTERN int exp_spawnfd _ANSI_ARGS_((int fd)); 417 418 #endif /* _EXPECT_H */ 419