📄 dialog.c
字号:
#ifndef lintstatic const char rcsid[] = "$Id: dialog.c,v 1.1.1.1 2001/03/08 00:01:47 efalk Exp $" ;#endif/* * Copyright (c) 1995 by Edward A. Falk *//********** * * * @@@@ @@@ @@@ @ @@@ @@@@ * @ @ @ @ @ @ @ @ @ * @ @ @ @@@@@ @ @ @ @ @@@ * @ @ @ @ @ @ @ @ @ @ * @@@@ @@@ @ @ @@@@@ @@@ @@@@ * * DIALOG - Manage interactive dialogs. * * Note: this code is non-reentrant. That is, only one dialog can * be managed at any time. * * Routines provided here: * * * void * DialogStart( pats, npats, timeout, callback ) * Pattern *pats ; * int npats ; * int timeout ; (seconds) * void (*callback)() ; * * Start dialog. Callback function is called when any pattern is * matched or timeout occurs. Callback is called with -1 for * timeout, or index of pattern that matched (0-based) * * void * callback(int which) * * void * DialogChars() * Called when inputBuf has data. * * void * DialogTimeout() * Called when timeout occurs. * * * TODO: Convert to use standard regex() functions. * TODO: Throw this away entirely and use expect. * * * Edward A. Falk * Sun Microsystems * * January, 1995 * * * **********/#include <stdio.h>#include <sys/types.h>#include "gcomm.h"#include "buffers.h"#include "pattern.h"#include "dialog.h"/**** * * Constants, typedefs, externals, globals, statics, macros, block data * ****/static Pattern *patterns ;static int npats ;static void (*callback)() ;static bool DialogTimeout() ;voidDialogStart(Pattern *pats, int np, int timeout, void (*cb)(int)){ dialogActive = 1 ; dialogTimeout = timeout ; InstallDialogTimeout(timeout*1000, DialogTimeout) ; patterns = pats ; npats = np ; callback = cb ; while( --np >= 0 ) PatInit(pats++) ; SelectTermBuf() ;}voidDialogChars(){ int j ; int c ; while( (c = get_buffer(&inputBuf)) != -1 ) { if( debugEcho ) PutTerm1(c) ; for(j=0; j<npats; ++j) { if( PatChar(&patterns[j], c) ) { dialogActive = 0 ; RemoveDialogTimeout() ; SelectTermBuf() ; callback(j) ; return ; } } }}static boolDialogTimeout(){ dialogActive = 0 ; SelectTermBuf() ; callback(-1) ; return False ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -