File: cmd.h

package info (click to toggle)
oleo 1.6-16
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,640 kB
  • ctags: 3,139
  • sloc: ansic: 39,221; yacc: 1,737; sh: 362; makefile: 88
file content (393 lines) | stat: -rw-r--r-- 11,340 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
258
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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#ifndef CMDH
#define CMDH

/*	Copyright (C) 1992, 1993 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this software; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
/*  t. lord	Wed Oct 14 12:01:37 1992	*/

/*
 * This file explains the generic interface to interactive functions.
 * This covers how C functions are made available to the user, how
 * keymaps are structured.  This also describes the variables that
 * hold the user's interaction state .
 */
#include "global.h"
#include "obstack.h"
#include "line.h"
#include "key.h"
#include "args.h"
#include "funcs.h"
#include "info.h"



typedef void (*alarm_fn)(void);

struct alarm_entry
{
  alarm_fn fn;
  int freq;			/* in seconds. */
  time_t last_time;
};


extern struct alarm_entry alarm_table[];

#define cell_timer_seconds  (alarm_table[0].freq)




/* Fields prefixed by _ should normally be accessed via the macros
 * defined further on. 
 */

struct command_frame;
struct macro;

struct input_stream
{
  /* The currently executing macro. */
  struct macro *_rmac;

  unsigned char * _last_macro;		/* The last anonymous macro. */

  /* If a macro is being exectuted, arguments to a command
   * are read from this string.
   */
  char *_func_arg;

  /* Call stack for macros. */
  struct obstack _macro_stack;

  /* The macro being recorded, if any. */
  unsigned char *_macro;
  unsigned char *_macro_start;
  unsigned int _macro_size;

  /* If this input stream was created only to execute a macro, 
   * this will point to the input_stream it suspended.
   * The purpose of this stack is to give command_loop the ability to
   * execute exactly one macro and then return.
   *
   * Note that within an input stream there is another macro stack. 
   * That stack is used internally to command_loop.
   */
  struct input_stream * prev_stream;

  int _pushed_back_char;
};


struct macro
{
  struct macro *mac_prev;
  unsigned char *mac_exe;
  CELLREF mac_row, mac_col;
  struct rng mac_rng;

  int count;			/* Repeat count for this macro. */
  unsigned char * mac_start;	/* Beginning the current cell's string (as */
				/* copied to the macro stack). */
};

/* When a key is bound to a range, that range is stored here and 
 * the CODE field of the binding is an index.  This is bogus.
 * Variables should be used.
 */
extern int n_bound_macros;
extern struct rng *bound_macros;
extern int bound_macro_vec;



/* The pattern of interaction is:
 *   the user selects an interactive function
 *   a list of arguments to that function are assembled
 *   the function is called
 *
 * This type is a union of the types that arguments to interactive
 * functions can have.
 */ 
union command_arg_val
{
  char character;
  FILE * fp;
  int integer;
  double floating;
  struct key_sequence key;	/* Passed as (struct keyseq *). */
  struct rng range;		/* Passed as (struct rng *). */
  char * string;
};


typedef void (*direction_function) (int magic, int repeat);


struct command_arg
{
  int do_prompt;		/* If true, the user gets to edit this. */
  int is_set;			/* If true, a valid value is stored here. */
  struct prompt_style * style;	/* The editting mode for this argument. */
  char * arg_desc;		/* Pointer into FUNC_ARGS of CUR_CMD. */
  char * prompt;		/* Unexpanded prompt */
  char * expanded_prompt;

  struct info_buffer * prompt_info;/* Info that should be displayed while */
				/* prompting for this argument. */
  int info_line;		/* First line visible in prompt_info */

  struct line text;		/* A buffer for the user to edit this value. */
  int cursor;			/* cursor position of this buffer. */
  int overwrite;		/* Is overwrite mode on? */

  /* For incremental commands. */
  direction_function inc_cmd;

  /* For reading a character with timeout. */
  int timeout_seconds;

  /* The value as it will be passed to the cmd function. */
  union command_arg_val val;
};

#define MAX_COMMAND_ARGS	10

/* These declarations make up the state of the command interpreter. */

struct command_frame 
{
  /* If `recursive' edits are enabled, there can be more than one of these. */
  struct command_frame * next;
  struct command_frame * prev;

  struct input_stream * input;
  
  /* The cell being editted (if any). */
  CELLREF _setrow;
  CELLREF _setcol;
  
  /* The current cell and the mark. */
  CELLREF _curow;
  CELLREF _cucol;
  CELLREF _mkrow;
  CELLREF _mkcol;

  /* What passes for a window configuration, for now. */
  /* 
   * When the input area is active, it appears to be just another window,
   * reachable by other-window.  These values must be maintained by any
   * implementation of io_get_line.
   */
  int _window_after_input;	/* Id of the window prior to the input area. */
  int _input_active;	/* Bool: is the input area selected? */

  
  /* The current top level keymap. */
  int top_keymap;
  
  /* Current position in the keymaps. */
  int _cur_keymap;

  int saved_cur_keymap;		/* used when building a prefix arg */
  
  /* The about-to-begin executing command (if any). */
  struct cmd_func *_cur_cmd;
  short _cur_vector;

  /* The last character processed .*/
  int _cur_chr;

  /* The prefix argument */
  int _how_many;
  struct line _raw_prefix;

  /* This becomes true if the user is ever prompted for arguments
   * for this frame.
   */
  int complex_to_user; 

  int _cmd_argc;
  int _cur_arg;
  struct cmd_func * cmd;

  /* The arguments to the current function. 
   * This is used only if the current function prompts for arguments.
   */
  struct command_arg argv[MAX_COMMAND_ARGS];
};

/* When a command is executing, this points to the frame it should operate
 * on:
 */

extern struct command_frame * the_cmd_frame;
extern struct command_frame * running_frames;


/* For most code, the structure of command loops and input streams
 * is unimportant.  To that code, we make it appear that there is just
 * a set of global variables.
 */

#define setrow			the_cmd_frame->_setrow
#define setcol			the_cmd_frame->_setcol
#define curow			the_cmd_frame->_curow
#define cucol			the_cmd_frame->_cucol
#define mkrow			the_cmd_frame->_mkrow
#define mkcol			the_cmd_frame->_mkcol

#define window_after_input	the_cmd_frame->_window_after_input
#define input_active		the_cmd_frame->_input_active

#define cur_keymap		the_cmd_frame->_cur_keymap
#define cur_cmd			the_cmd_frame->_cur_cmd
#define cur_vector		the_cmd_frame->_cur_vector
#define cur_chr			the_cmd_frame->_cur_chr
#define cur_arg			the_cmd_frame->_cur_arg
#define cmd_argc		the_cmd_frame->_cmd_argc

#define how_many		the_cmd_frame->_how_many
#define raw_prefix		the_cmd_frame->_raw_prefix

#define cur_input		the_cmd_frame->input
#define rmac			cur_input->_rmac
#define pushed_back_char	cur_input->_pushed_back_char
#define last_macro		cur_input->_last_macro
#define macro_func_arg		cur_input->_func_arg
#define macro_stack		cur_input->_macro_stack
#define making_macro		cur_input->_macro
#define making_macro_start	cur_input->_macro_start
#define making_macro_size	cur_input->_macro_size

#define the_cmd_arg  		the_cmd_frame->argv[cur_arg]



#ifdef FD_SET

#define SELECT_TYPE fd_set
#define SELECT_SET_SIZE FD_SETSIZE

#else /* no FD_SET */

/* Define the macros to access a single-int bitmap of descriptors.  */
#define SELECT_SET_SIZE 32
#define SELECT_TYPE int
#define FD_SET(n, p) (*(p) |= (1 << (n)))
#define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
#define FD_ISSET(n, p) (*(p) & (1 << (n)))
#define FD_ZERO(p) (*(p) = 0)

#endif /* no FD_SET */

/* The fd's that are selected on in the interact loop. */
extern SELECT_TYPE read_fd_set;
extern SELECT_TYPE exception_fd_set;
extern SELECT_TYPE write_fd_set;
extern SELECT_TYPE read_pending_fd_set; /* These are the output of select. */
extern SELECT_TYPE exception_pending_fd_set;
extern SELECT_TYPE write_pending_fd_set;

#if PROTOTYPES
typedef void (*select_hook_fn) ();
#else
typedef void (*select_hook_fn) (int fd);
#endif

struct select_hook
{
  select_hook_fn hook_fn;
  void * jrandom;
};

extern struct select_hook file_read_hooks[SELECT_SET_SIZE];
extern struct select_hook file_exception_hooks[SELECT_SET_SIZE];
extern struct select_hook file_write_hooks[SELECT_SET_SIZE];



#if PROTOTYPES
extern void free_input_stream (struct input_stream * stream);
extern void pop_input_stream (void);
extern void start_entering_macro (void);
extern void bound_macro (int num);
extern void run_string_as_macro (char * macro);
extern void call_last_kbd_macro (int count);
extern void end_macro (void);
extern void stop_entering_macro (void);
extern void store_last_macro (struct rng * rng);
extern int real_get_chr (void);
extern void push_command_frame (struct rng * rng, char * first_line, int len);
extern void remove_cmd_frame (struct command_frame * frame);
extern void free_cmd_frame (struct command_frame * frame);
extern void pop_unfinished_command (void);
extern void recover_from_error (void);
extern void exit_minibuffer (void);
extern void setn_arg_text (struct command_arg * arg, char * text, int len);
extern void init_arg_text (struct command_arg * arg, char * text);
extern void set_default_arg (struct command_arg * arg, char * text, int len);
extern void command_loop (int prefix);
extern void execute_command (char *str);
extern int get_chr (void);
extern void display_error_msg (char * msg, int c);
extern void pushback_keystroke (int c);
extern void io_error_msg (char *str,...);
extern void io_info_msg (char *str,...);
extern char * expand_prompt (char * str);
extern void set_info (char * name);
extern void page_info_backwards (int rep);
extern void page_info (int rep);
extern void view_info (char * name, int ignore);
extern void with_keymap (char * mapname);
extern void one_cmd_with_keymap (char * mapname, struct key_sequence * keyseq);
#else
extern void free_input_stream ();
extern void pop_input_stream ();
extern void start_entering_macro ();
extern void bound_macro ();
extern void run_string_as_macro ();
extern void call_last_kbd_macro ();
extern void end_macro ();
extern void stop_entering_macro ();
extern void store_last_macro ();
extern int real_get_chr ();
extern void push_command_frame ();
extern void remove_cmd_frame ();
extern void free_cmd_frame ();
extern void pop_unfinished_command ();
extern void recover_from_error ();
extern void exit_minibuffer ();
extern void setn_arg_text ();
extern void init_arg_text ();
extern void set_default_arg ();
extern void command_loop ();
extern void execute_command ();
extern int get_chr ();
extern void display_error_msg ();
extern void pushback_keystroke ();
extern void io_error_msg ();
extern void io_info_msg ();
extern char * expand_prompt ();
extern void set_info ();
extern void page_info_backwards ();
extern void page_info ();
extern void view_info ();
extern void with_keymap ();
extern void one_cmd_with_keymap ();
#endif

#endif