Mercurial > hg > early-roguelike
comparison xrogue/daemon.c @ 134:cfa9d1609b78
xrogue: fix definition of struct delayed_action.
Arrays of struct delayed_action were declared before the definition.
Also, daemon.c and state.c defined it differently. The state.c
definition, in which d_arg is a union, is now used everywhere.
This is the least bad option, but fuses and daemons are still a
disheartening morass that undoubtedly shelters more bugs.
| author | John "Elwin" Edwards |
|---|---|
| date | Tue, 21 Apr 2015 10:11:02 -0400 |
| parents | e6179860cb76 |
| children | cadff8f047a1 |
comparison
equal
deleted
inserted
replaced
| 133:e6179860cb76 | 134:cfa9d1609b78 |
|---|---|
| 22 #define EMPTY 0 | 22 #define EMPTY 0 |
| 23 #define DAEMON -1 | 23 #define DAEMON -1 |
| 24 | 24 |
| 25 #define _X_ { EMPTY } | 25 #define _X_ { EMPTY } |
| 26 | 26 |
| 27 struct delayed_action { | |
| 28 int d_type; | |
| 29 int (*d_func)(); | |
| 30 VOID *d_arg; | |
| 31 int d_time; | |
| 32 } ; | |
| 33 struct delayed_action d_list[MAXDAEMONS] = { | 27 struct delayed_action d_list[MAXDAEMONS] = { |
| 34 _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_ | 28 _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_ |
| 35 }; | 29 }; |
| 36 struct delayed_action f_list[MAXFUSES] = { | 30 struct delayed_action f_list[MAXFUSES] = { |
| 37 _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, | 31 _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, _X_, |
| 105 | 99 |
| 106 dev = d_slot(); | 100 dev = d_slot(); |
| 107 if (dev != NULL) { | 101 if (dev != NULL) { |
| 108 dev->d_type = type; | 102 dev->d_type = type; |
| 109 dev->d_func = dfunc; | 103 dev->d_func = dfunc; |
| 110 dev->d_arg = arg; | 104 dev->d_arg.vp = arg; |
| 111 dev->d_time = DAEMON; | 105 dev->d_time = DAEMON; |
| 112 demoncnt += 1; /* update count */ | 106 demoncnt += 1; /* update count */ |
| 113 } | 107 } |
| 114 } | 108 } |
| 115 | 109 |
| 131 if (i >= MAXDAEMONS) return; /* if not found, forget it */ | 125 if (i >= MAXDAEMONS) return; /* if not found, forget it */ |
| 132 /* | 126 /* |
| 133 * Take it out of the list | 127 * Take it out of the list |
| 134 */ | 128 */ |
| 135 dev->d_type = EMPTY; | 129 dev->d_type = EMPTY; |
| 136 dev->d_arg = NULL; | 130 dev->d_arg.vp = NULL; |
| 137 dev->d_func = NULL; | 131 dev->d_func = NULL; |
| 138 dev->d_time = 0; | 132 dev->d_time = 0; |
| 139 | 133 |
| 140 demoncnt -= 1; /* update count */ | 134 demoncnt -= 1; /* update count */ |
| 141 } | 135 } |
| 160 dev = &d_list[i]; | 154 dev = &d_list[i]; |
| 161 /* | 155 /* |
| 162 * Executing each one, giving it the proper arguments | 156 * Executing each one, giving it the proper arguments |
| 163 */ | 157 */ |
| 164 if ((dev->d_type == flag) && (dev->d_time == DAEMON) && (dev->d_func != NULL)) | 158 if ((dev->d_type == flag) && (dev->d_time == DAEMON) && (dev->d_func != NULL)) |
| 165 (*dev->d_func)(dev->d_arg); | 159 (*dev->d_func)(dev->d_arg.vp); |
| 166 } | 160 } |
| 167 } | 161 } |
| 168 | 162 |
| 169 /* | 163 /* |
| 170 * fuse: | 164 * fuse: |
| 179 | 173 |
| 180 wire = f_slot(); | 174 wire = f_slot(); |
| 181 if (wire != NULL) { | 175 if (wire != NULL) { |
| 182 wire->d_type = type; | 176 wire->d_type = type; |
| 183 wire->d_func = dfunc; | 177 wire->d_func = dfunc; |
| 184 wire->d_arg = arg; | 178 wire->d_arg.vp = arg; |
| 185 wire->d_time = time; | 179 wire->d_time = time; |
| 186 fusecnt += 1; /* update count */ | 180 fusecnt += 1; /* update count */ |
| 187 } | 181 } |
| 188 } | 182 } |
| 189 | 183 |
| 214 | 208 |
| 215 if ((wire = find_slot(dfunc)) == NULL) | 209 if ((wire = find_slot(dfunc)) == NULL) |
| 216 return; | 210 return; |
| 217 wire->d_type = EMPTY; | 211 wire->d_type = EMPTY; |
| 218 wire->d_func = NULL; | 212 wire->d_func = NULL; |
| 219 wire->d_arg = NULL; | 213 wire->d_arg.vp = NULL; |
| 220 wire->d_time = 0; | 214 wire->d_time = 0; |
| 221 fusecnt -= 1; | 215 fusecnt -= 1; |
| 222 } | 216 } |
| 223 | 217 |
| 224 /* | 218 /* |
| 243 */ | 237 */ |
| 244 if(flag == wire->d_type && wire->d_time > 0 && | 238 if(flag == wire->d_type && wire->d_time > 0 && |
| 245 --wire->d_time == 0) { | 239 --wire->d_time == 0) { |
| 246 wire->d_type = EMPTY; | 240 wire->d_type = EMPTY; |
| 247 if (wire->d_func != NULL) | 241 if (wire->d_func != NULL) |
| 248 (*wire->d_func)(wire->d_arg); | 242 (*wire->d_func)(wire->d_arg.vp); |
| 249 fusecnt -= 1; | 243 fusecnt -= 1; |
| 250 } | 244 } |
| 251 } | 245 } |
| 252 } | 246 } |
| 253 | 247 |
