add tests for menu and menustyle commands.
[fvwm.git] / fvwm / repeat.c
blob441c48b35c18823bd496aae236afcf7b28443b33
1 /* Copyright (C) 1999 Dominik Vogt
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "config.h"
20 #include <stdio.h>
22 #include "libs/fvwmlib.h"
23 #include "fvwm.h"
24 #include "externs.h"
25 #include "cursor.h"
26 #include "functions.h"
27 #include "repeat.h"
28 #include "libs/Parse.h"
31 /* If non-zero we are already repeating a function, so don't record the
32 * command again. */
33 static unsigned int repeat_depth = 0;
36 typedef struct
38 char *start;
39 char *end;
40 } double_ended_string;
42 static struct
44 double_ended_string string;
45 double_ended_string old;
46 double_ended_string builtin;
47 double_ended_string function;
48 double_ended_string top_function;
49 double_ended_string module;
50 double_ended_string menu;
51 double_ended_string popup;
52 double_ended_string menu_or_popup;
53 int page_x;
54 int page_y;
55 int desk;
56 FvwmWindow *fvwm_window;
57 } last;
60 static struct
62 char *command_line;
63 char *menu_name;
64 } last = { NULL, NULL };
67 char *repeat_last_function = NULL;
68 char *repeat_last_complex_function = NULL;
69 char *repeat_last_builtin_function = NULL;
70 char *repeat_last_module = NULL;
71 char *repeat_last_top_function = NULL;
72 char *repeat_last_menu = NULL;
73 FvwmWindow *repeat_last_fvwm_window = NULL;
76 /* Prcedure: set_repeat_data
78 * Stores the contents of the data pointer internally for the repeat command.
79 * The sype of data is determined by the 'type' parameter. If this function is
80 * called to set a string value representing a fvwm builtin function the
81 * 'func_typetion' can be set to the F_<func_type> value in the function table
82 * in functions.c. If this value is set certain functions are not recorded.
83 * The 'depth' parameter indicates the recursion depth of the current data
84 * pointer (i.e. the first function call has a depth of one, functions called
85 * from within this function have depth 2 and higher, this may be applicable
86 * to future enhancements like menus).
88 * TODO: [finish and update description]
90 Bool set_repeat_data(void *data, repeat_type type, const func_type *builtin)
92 /* No history recording during startup. */
93 if (fFvwmInStartup)
94 return True;
96 switch(type)
98 case REPEAT_COMMAND:
99 if (last.command_line == (char *)data)
100 /* Already stored, no need to free the data pointer. */
101 return False;
102 if (data == NULL || repeat_depth != 0)
103 /* Ignoring the data, must free it outside of this call. */
104 return True;
105 if (builtin && (builtin->flags & FUNC_DONT_REPEAT))
106 /* Dont' record functions that have the FUNC_DONT_REPEAT flag set. */
107 return True;
108 if (last.command_line)
109 free(last.command_line);
110 /* Store a backup. */
111 last.command_line = (char *)data;
112 /* Since we stored the pointer the caller must not free it. */
113 return False;
114 case REPEAT_MENU:
115 case REPEAT_POPUP:
116 if (last.menu_name)
117 free(last.menu_name);
118 last.menu_name = (char *)data;
119 /* Since we stored the pointer the caller must not free it. */
120 return False;
121 case REPEAT_PAGE:
122 case REPEAT_DESK:
123 case REPEAT_DESK_AND_PAGE:
124 return True;
125 case REPEAT_FVWM_WINDOW:
126 return True;
127 case REPEAT_NONE:
128 default:
129 return True;
133 void repeat_function(F_CMD_ARGS)
135 int index;
136 char *optlist[] = {
137 "command",
138 NULL
141 repeat_depth++;
142 /* Replay the backup, we don't want the repeat command recorded. */
143 GetNextTokenIndex(action, optlist, 0, &index);
144 switch (index)
146 case 0: /* command */
147 default:
148 #if 0
149 fprintf( stderr, "repeating 0x%lx, %s\n",
150 (unsigned long) last.command_line, last.command_line);
151 #endif
152 action = last.command_line;
153 ExecuteFunction(F_PASS_EXEC_ARGS, FUNC_DONT_EXPAND_COMMAND, NULL);
154 break;
156 repeat_depth--;