Skip to content

Commit 020df16

Browse files
author
Wayne Davison
committed
Make case_N.h more generic.
1 parent 2624e00 commit 020df16

File tree

2 files changed

+49
-44
lines changed

2 files changed

+49
-44
lines changed

case_N.h

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* End-of-run cleanup helper code used by cleanup.c.
2+
* Allow an arbitrary sequence of case labels.
33
*
4-
* Copyright (C) 2006-2008 Wayne Davison
4+
* Copyright (C) 2006-2010 Wayne Davison
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -17,63 +17,60 @@
1717
* with this program; if not, visit the http://fsf.org website.
1818
*/
1919

20-
/* This is included by cleanup.c multiple times, once for every segement in
21-
* the _exit_cleanup() code. This produces the next "case N:" statement in
22-
* sequence and increments the cleanup_step variable by 1. This ensures that
23-
* our case statements never get out of whack due to added/removed steps. */
20+
/* This is included multiple times, once for every segement in a switch statement.
21+
* This produces the next "case N:" statement in sequence. */
2422

25-
#if !defined EXIT_CLEANUP_CASE_0
26-
#define EXIT_CLEANUP_CASE_0
23+
#if !defined CASE_N_STATE_0
24+
#define CASE_N_STATE_0
2725
case 0:
28-
#elif !defined EXIT_CLEANUP_CASE_1
29-
#define EXIT_CLEANUP_CASE_1
26+
#elif !defined CASE_N_STATE_1
27+
#define CASE_N_STATE_1
3028
case 1:
31-
#elif !defined EXIT_CLEANUP_CASE_2
32-
#define EXIT_CLEANUP_CASE_2
29+
#elif !defined CASE_N_STATE_2
30+
#define CASE_N_STATE_2
3331
case 2:
34-
#elif !defined EXIT_CLEANUP_CASE_3
35-
#define EXIT_CLEANUP_CASE_3
32+
#elif !defined CASE_N_STATE_3
33+
#define CASE_N_STATE_3
3634
case 3:
37-
#elif !defined EXIT_CLEANUP_CASE_4
38-
#define EXIT_CLEANUP_CASE_4
35+
#elif !defined CASE_N_STATE_4
36+
#define CASE_N_STATE_4
3937
case 4:
40-
#elif !defined EXIT_CLEANUP_CASE_5
41-
#define EXIT_CLEANUP_CASE_5
38+
#elif !defined CASE_N_STATE_5
39+
#define CASE_N_STATE_5
4240
case 5:
43-
#elif !defined EXIT_CLEANUP_CASE_6
44-
#define EXIT_CLEANUP_CASE_6
41+
#elif !defined CASE_N_STATE_6
42+
#define CASE_N_STATE_6
4543
case 6:
46-
#elif !defined EXIT_CLEANUP_CASE_7
47-
#define EXIT_CLEANUP_CASE_7
44+
#elif !defined CASE_N_STATE_7
45+
#define CASE_N_STATE_7
4846
case 7:
49-
#elif !defined EXIT_CLEANUP_CASE_8
50-
#define EXIT_CLEANUP_CASE_8
47+
#elif !defined CASE_N_STATE_8
48+
#define CASE_N_STATE_8
5149
case 8:
52-
#elif !defined EXIT_CLEANUP_CASE_9
53-
#define EXIT_CLEANUP_CASE_9
50+
#elif !defined CASE_N_STATE_9
51+
#define CASE_N_STATE_9
5452
case 9:
55-
#elif !defined EXIT_CLEANUP_CASE_10
56-
#define EXIT_CLEANUP_CASE_10
53+
#elif !defined CASE_N_STATE_10
54+
#define CASE_N_STATE_10
5755
case 10:
58-
#elif !defined EXIT_CLEANUP_CASE_11
59-
#define EXIT_CLEANUP_CASE_11
56+
#elif !defined CASE_N_STATE_11
57+
#define CASE_N_STATE_11
6058
case 11:
61-
#elif !defined EXIT_CLEANUP_CASE_12
62-
#define EXIT_CLEANUP_CASE_12
59+
#elif !defined CASE_N_STATE_12
60+
#define CASE_N_STATE_12
6361
case 12:
64-
#elif !defined EXIT_CLEANUP_CASE_13
65-
#define EXIT_CLEANUP_CASE_13
62+
#elif !defined CASE_N_STATE_13
63+
#define CASE_N_STATE_13
6664
case 13:
67-
#elif !defined EXIT_CLEANUP_CASE_14
68-
#define EXIT_CLEANUP_CASE_14
65+
#elif !defined CASE_N_STATE_14
66+
#define CASE_N_STATE_14
6967
case 14:
70-
#elif !defined EXIT_CLEANUP_CASE_15
71-
#define EXIT_CLEANUP_CASE_15
68+
#elif !defined CASE_N_STATE_15
69+
#define CASE_N_STATE_15
7270
case 15:
73-
#elif !defined EXIT_CLEANUP_CASE_16
74-
#define EXIT_CLEANUP_CASE_16
71+
#elif !defined CASE_N_STATE_16
72+
#define CASE_N_STATE_16
7573
case 16:
7674
#else
7775
#error Need to add more case statements!
7876
#endif
79-
cleanup_step++;

cleanup.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pid_t cleanup_child_pid = -1;
9898
**/
9999
NORETURN void _exit_cleanup(int code, const char *file, int line)
100100
{
101-
static int cleanup_step = 0;
101+
static int switch_step = 0;
102102
static int exit_code = 0, exit_line = 0;
103103
static const char *exit_file = NULL;
104104
static int unmodified_code = 0;
@@ -119,8 +119,9 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
119119

120120
/* Some of our actions might cause a recursive call back here, so we
121121
* keep track of where we are in the cleanup and never repeat a step. */
122-
switch (cleanup_step) {
123-
#include "case_N.h" /* case 0: cleanup_step++; */
122+
switch (switch_step) {
123+
#include "case_N.h" /* case 0: */
124+
switch_step++;
124125

125126
exit_code = unmodified_code = code;
126127
exit_file = file;
@@ -139,6 +140,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
139140

140141
/* FALLTHROUGH */
141142
#include "case_N.h"
143+
switch_step++;
142144

143145
if (cleanup_child_pid != -1) {
144146
int status;
@@ -152,6 +154,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
152154

153155
/* FALLTHROUGH */
154156
#include "case_N.h"
157+
switch_step++;
155158

156159
if (cleanup_got_literal && cleanup_fname && cleanup_new_fname
157160
&& keep_partial && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
@@ -169,12 +172,14 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
169172

170173
/* FALLTHROUGH */
171174
#include "case_N.h"
175+
switch_step++;
172176

173177
if (!code || am_server || am_receiver)
174178
io_flush(FULL_FLUSH);
175179

176180
/* FALLTHROUGH */
177181
#include "case_N.h"
182+
switch_step++;
178183

179184
if (cleanup_fname)
180185
do_unlink(cleanup_fname);
@@ -203,6 +208,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
203208

204209
/* FALLTHROUGH */
205210
#include "case_N.h"
211+
switch_step++;
206212

207213
if (DEBUG_GTE(EXIT, 1)) {
208214
rprintf(FINFO,
@@ -213,6 +219,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
213219

214220
/* FALLTHROUGH */
215221
#include "case_N.h"
222+
switch_step++;
216223

217224
if (exit_code && exit_code != RERR_SOCKETIO && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
218225
&& exit_code != RERR_TIMEOUT && !shutting_down && (protocol_version >= 31 || am_receiver)) {
@@ -228,6 +235,7 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
228235

229236
/* FALLTHROUGH */
230237
#include "case_N.h"
238+
switch_step++;
231239

232240
if (am_server && code)
233241
msleep(100);

0 commit comments

Comments
 (0)