Convert over to use GetOpt::Long and introduce -f and -h.
[fvwm.git] / fvwm / repeat.c
blob5b4d690d170d7a393a1cf6b2a0f3574961375863
1 /* -*-c-*- */
2 /* 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 int repeat_depth = 0;
35 #if 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;
58 #endif
60 static struct
62 char *command_line;
63 char *menu_name;
64 } last = {
65 NULL,
66 NULL
69 #if 0
70 char *repeat_last_function = NULL;
71 char *repeat_last_complex_function = NULL;
72 char *repeat_last_builtin_function = NULL;
73 char *repeat_last_module = NULL;
74 char *repeat_last_top_function = NULL;
75 char *repeat_last_menu = NULL;
76 FvwmWindow *repeat_last_fvwm_window = NULL;
77 #endif
79 /* Stores the contents of the data pointer internally for the repeat command.
80 * The type of data is determined by the 'type' parameter. If this function is
81 * called to set a string value representing an fvwm builtin function the
82 * 'builtin' can be set to the F_... value in the function table in
83 * functions.c. If this value is set certain functions are not recorded.
84 * The 'depth' parameter indicates the recursion depth of the current data
85 * pointer (i.e. the first function call has a depth of one, functions called
86 * from within this function have depth 2 and higher, this may be applicable
87 * to future enhancements like menus).
89 * TODO: [finish and update description]
91 Bool set_repeat_data(void *data, repeat_t type, const func_t *builtin)
93 /* No history recording during startup. */
94 if (fFvwmInStartup)
96 return True;
99 switch(type)
101 case REPEAT_COMMAND:
102 if (last.command_line == (char *)data)
104 /* Already stored, no need to free the data pointer. */
105 return False;
107 if (data == NULL || repeat_depth != 0)
109 /* Ignoring the data, must free it outside of this
110 * call. */
111 return True;
113 if (builtin && (builtin->flags & FUNC_DONT_REPEAT))
115 /* Dont' record functions that have the
116 * FUNC_DONT_REPEAT flag set. */
117 return True;
119 if (last.command_line)
121 free(last.command_line);
123 /* Store a backup. */
124 last.command_line = (char *)data;
125 /* Since we stored the pointer the caller must not free it. */
126 return False;
127 case REPEAT_MENU:
128 case REPEAT_POPUP:
129 if (last.menu_name)
131 free(last.menu_name);
133 last.menu_name = (char *)data;
134 /* Since we stored the pointer the caller must not free it. */
135 return False;
136 case REPEAT_PAGE:
137 case REPEAT_DESK:
138 case REPEAT_DESK_AND_PAGE:
139 return True;
140 case REPEAT_FVWM_WINDOW:
141 return True;
142 case REPEAT_NONE:
143 default:
144 return True;
148 void CMD_Repeat(F_CMD_ARGS)
150 int index;
151 char *optlist[] = {
152 "command",
153 NULL
156 repeat_depth++;
157 /* Replay the backup, we don't want the repeat command recorded. */
158 GetNextTokenIndex(action, optlist, 0, &index);
159 switch (index)
161 case 0: /* command */
162 default:
163 action = last.command_line;
164 execute_function(
165 cond_rc, exc, action, FUNC_DONT_EXPAND_COMMAND);
166 break;
168 repeat_depth--;
170 return;