1 /* expect.h - include file for using the expect library, libexpect.a
2 from C or C++ (i.e., without Tcl)
4 Written by: Don Libes, libes@cme.nist.gov, NIST, 12/3/90
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.
20 * This header file describes the externally-visible facilities
21 * of the Tcl interpreter.
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.
28 * See the file "license.terms" for information on usage and redistribution
29 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
31 * RCS: @(#) $Id: expect.h,v 5.33 2010/08/31 22:20:27 andreas_kupries Exp $
38 # if defined(_WIN32) || defined(WIN32)
47 # ifndef USE_PROTOTYPE
48 # define USE_PROTOTYPE 1
53 # ifndef USE_PROTOTYPE
54 # define USE_PROTOTYPE 1
58 * Under Windows we need to call Tcl_Alloc in all cases to avoid competing
59 * C run-time library issues.
63 # define USE_TCLALLOC 1
65 #endif /* __WIN32__ */
68 * The following definitions set up the proper options for Macintosh
69 * compilers. We use this method because there is no autoconf equivalent.
77 # define USE_TCLALLOC 1
80 # define NO_STRERROR 1
85 * Utility macros: STRINGIFY takes an argument and wraps it in "" (double
86 * quotation marks), JOIN joins two arguments.
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
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
103 # define STRINGIFY(x) #x
104 # define JOIN(a,b) a##b
106 # define STRINGIFY(x) "x"
107 # define JOIN(a,b) VERBATIM(a)VERBATIM(b)
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.
119 #ifndef RESOURCE_INCLUDED
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.
135 #if defined(__STDC__) || defined(HAS_STDARG)
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)
142 # include <varargs.h>
145 # define TCL_VARARGS(type, name) (type name, ...)
146 # define TCL_VARARGS_DEF(type, name) (type va_alist, ...)
148 # define TCL_VARARGS(type, name) ()
149 # define TCL_VARARGS_DEF(type, name) (va_alist)
151 # define TCL_VARARGS_START(type, name, list) \
152 (va_start(list), va_arg(list, type))
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.
167 # if defined(__WIN32__) && (defined(_MSC_VER) || (defined(__GNUC__) && defined(__declspec)))
168 # define DLLIMPORT __declspec(dllimport)
169 # define DLLEXPORT __declspec(dllexport)
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.
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.
192 #undef TCL_STORAGE_CLASS
194 # define TCL_STORAGE_CLASS DLLEXPORT
196 # ifdef USE_TCL_STUBS
197 # define TCL_STORAGE_CLASS
199 # define TCL_STORAGE_CLASS DLLIMPORT
204 * Definitions that allow this header file to be used either with or
205 * without ANSI C features like function prototypes. */
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
215 # define _ANSI_ARGS_(x) ()
220 # define EXTERN extern "C" TCL_STORAGE_CLASS
222 # define EXTERN extern TCL_STORAGE_CLASS
226 * Macro to use instead of "void" for arguments that must have
227 * type "void *" in ANSI C; maps them to type "char *" in
238 #else /* __WIN32__ */
240 * The following code is copied from winnt.h
248 #endif /* __WIN32__ */
251 * Miscellaneous declarations.
258 typedef struct Tcl_RegExp_ *Tcl_RegExp;
261 * These function have been renamed. The old names are deprecated, but we
262 * define these macros for backwards compatibilty.
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
271 #endif /* RESOURCE_INCLUDED */
273 #undef TCL_STORAGE_CLASS
274 #define TCL_STORAGE_CLASS DLLIMPORT
279 * end of tcl.h definitions
284 * regexp definitions - from tcl8.0/tclRegexp.h
288 * Definitions etc. for regexp(3) routines.
290 * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
291 * not the System V one.
293 * RCS: @(#) $Id: expect.h,v 5.33 2010/08/31 22:20:27 andreas_kupries Exp $
300 # undef TCL_STORAGE_CLASS
301 # define TCL_STORAGE_CLASS DLLEXPORT
305 * NSUBEXP must be at least 10, and no greater than 117 or the parser
306 * will not work properly.
311 typedef struct regexp {
312 char *startp[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. */
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));
327 # undef TCL_STORAGE_CLASS
328 # define TCL_STORAGE_CLASS DLLIMPORT
334 * end of regexp definitions
339 * finally - expect-specific definitions
342 #include "expect_comm.h"
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 */
354 struct exp_case { /* case for expect command */
358 int value; /* value to be returned upon match */
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 */
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 */
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 */
381 #ifdef HAVE_SIGLONGJMP
382 EXTERN sigjmp_buf exp_readenv; /* for interruptable read() */
384 EXTERN jmp_buf exp_readenv; /* for interruptable read() */
385 #endif /* HAVE_SIGLONGJMP */
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 */
391 EXTERN int exp_is_debugging;
392 EXTERN int exp_loguser;
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));
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));
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));
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));
416 EXTERN int exp_spawnfd _ANSI_ARGS_((int fd));
418 #endif /* _EXPECT_H */