File: repeat.c

package info (click to toggle)
fvwm 1%3A2.6.7-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 16,752 kB
  • ctags: 14,275
  • sloc: ansic: 145,770; xml: 17,086; perl: 7,302; sh: 4,885; makefile: 1,055; yacc: 688; python: 629; lex: 188; sed: 11
file content (171 lines) | stat: -rw-r--r-- 4,196 bytes parent folder | download | duplicates (6)
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
/* -*-c-*- */
/* Copyright (C) 1999  Dominik Vogt */
/* 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 of the License, 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 program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdio.h>

#include "libs/fvwmlib.h"
#include "fvwm.h"
#include "externs.h"
#include "cursor.h"
#include "functions.h"
#include "repeat.h"
#include "libs/Parse.h"


/* If non-zero we are already repeating a function, so don't record the
 * command again. */
static int repeat_depth = 0;

#if 0
typedef struct
{
	char *start;
	char *end;
} double_ended_string;

static struct
{
	double_ended_string string;
	double_ended_string old;
	double_ended_string builtin;
	double_ended_string function;
	double_ended_string top_function;
	double_ended_string module;
	double_ended_string menu;
	double_ended_string popup;
	double_ended_string menu_or_popup;
	int page_x;
	int page_y;
	int desk;
	FvwmWindow *fvwm_window;
} last;
#endif

static struct
{
	char *command_line;
	char *menu_name;
} last = {
	NULL,
	NULL
};

#if 0
char *repeat_last_function = NULL;
char *repeat_last_complex_function = NULL;
char *repeat_last_builtin_function = NULL;
char *repeat_last_module = NULL;
char *repeat_last_top_function = NULL;
char *repeat_last_menu = NULL;
FvwmWindow *repeat_last_fvwm_window = NULL;
#endif

/* Stores the contents of the data pointer internally for the repeat command.
 * The type of data is determined by the 'type' parameter. If this function is
 * called to set a string value representing an fvwm builtin function the
 * 'builtin' can be set to the F_... value in the function table in
 * functions.c. If this value is set certain functions are not recorded.
 * The 'depth' parameter indicates the recursion depth of the current data
 * pointer (i.e. the first function call has a depth of one, functions called
 * from within this function have depth 2 and higher, this may be applicable
 * to future enhancements like menus).
 *
 * TODO: [finish and update description]
 */
Bool set_repeat_data(void *data, repeat_t type, const func_t *builtin)
{
	/* No history recording during startup. */
	if (fFvwmInStartup)
	{
		return True;
	}

	switch(type)
	{
	case REPEAT_COMMAND:
		if (last.command_line == (char *)data)
		{
			/* Already stored, no need to free the data pointer. */
			return False;
		}
		if (data == NULL || repeat_depth != 0)
		{
			/* Ignoring the data, must free it outside of this
			 * call. */
			return True;
		}
		if (builtin && (builtin->flags & FUNC_DONT_REPEAT))
		{
			/* Dont' record functions that have the
			 * FUNC_DONT_REPEAT flag set. */
			return True;
		}
		if (last.command_line)
		{
			free(last.command_line);
		}
		/* Store a backup. */
		last.command_line = (char *)data;
		/* Since we stored the pointer the caller must not free it. */
		return False;
	case REPEAT_MENU:
	case REPEAT_POPUP:
		if (last.menu_name)
		{
			free(last.menu_name);
		}
		last.menu_name = (char *)data;
		/* Since we stored the pointer the caller must not free it. */
		return False;
	case REPEAT_PAGE:
	case REPEAT_DESK:
	case REPEAT_DESK_AND_PAGE:
		return True;
	case REPEAT_FVWM_WINDOW:
		return True;
	case REPEAT_NONE:
	default:
		return True;
	}
}

void CMD_Repeat(F_CMD_ARGS)
{
	int index;
	char *optlist[] = {
		"command",
		NULL
	};

	repeat_depth++;
	/* Replay the backup, we don't want the repeat command recorded. */
	GetNextTokenIndex(action, optlist, 0, &index);
	switch (index)
	{
	case 0: /* command */
	default:
		action = last.command_line;
		execute_function(
			cond_rc, exc, action, FUNC_DONT_EXPAND_COMMAND);
		break;
	}
	repeat_depth--;

	return;
}