#include "copyright.h"
#include "config.h"
#include "macro.h"
#include "commac.h"
#include "flags.h"
#include "powers.h"
#include "db.h"
#include "alloc.h"
Include dependency graph for macro.c:
Go to the source code of this file.
Defines | |
#define | TST(cmd, msg) if (cmd) { fprintf(stderr, msg); exit(1); } |
Functions | |
dbref | match_thing (dbref player, char *name) |
void | init_mactab (void) |
int | do_macro (dbref player, char *in, char **out) |
void | do_list_macro (dbref player, char *s) |
void | do_add_macro (dbref player, char *s) |
void | do_del_macro (dbref player, char *s) |
void | do_desc_macro (dbref player, char *s) |
void | do_chmod_macro (dbref player, char *s) |
void | do_gex_macro (dbref player, char *s) |
void | do_edit_macro (dbref player, char *s) |
void | do_status_macro (dbref player, char *s) |
void | do_ex_macro (dbref player, char *s) |
void | do_chown_macro (dbref player, char *cmd) |
void | clear_macro_set (int set) |
void | do_clear_macro (dbref player, char *s) |
void | do_def_macro (dbref player, char *cmd) |
void | do_undef_macro (dbref player, char *cmd) |
char * | do_process_macro (dbref player, char *in, char *s) |
macros * | get_macro_set (dbref player, int which) |
void | do_sort_macro_set (struct macros *m) |
void | do_create_macro (dbref player, char *s) |
int | can_write_macros (dbref player, struct macros *m) |
int | can_read_macros (dbref player, struct macros *m) |
void | load_macros (FILE *fp) |
void | save_macros (FILE *fp) |
Variables | |
MACENT | macro_table [] |
#define TST | ( | cmd, | |||
msg | ) | if (cmd) { fprintf(stderr, msg); exit(1); } |
Definition at line 763 of file macro.c.
References MACRO_R, macros::player, macros::status, and Wizard.
Referenced by do_gex_macro(), and do_list_macro().
00764 { 00765 if(Wizard(player)) 00766 return 1; 00767 00768 if(!m) 00769 return 0; 00770 00771 if(m->player == player) 00772 return 1; 00773 else 00774 return m->status & MACRO_R; 00775 }
Definition at line 752 of file macro.c.
References MACRO_L, MACRO_W, macros::player, and macros::status.
Referenced by do_chown_macro(), do_def_macro(), and do_undef_macro().
00753 { 00754 if(m->status & MACRO_L) 00755 return 0; 00756 00757 if(m->player == player) 00758 return 1; 00759 else 00760 return m->status & MACRO_W; 00761 }
void clear_macro_set | ( | int | set | ) |
Definition at line 398 of file macro.c.
References macros::alias, c, commac_table, GMac, commac::macros, coolmenu_type::next, NUM_COMMAC, nummacros, macros::nummacros, and macros::string.
Referenced by do_clear_macro(), load_macros(), and mmdb_db_read().
00399 { 00400 struct macros *m; 00401 struct commac *c; 00402 int i, j; 00403 00404 if(GMac(set)) { 00405 m = macros[set]; 00406 for(i = 0; i < m->nummacros; i++) { 00407 free(m->string[i]); 00408 } 00409 free(m->alias); 00410 free(m->string); 00411 free(m); 00412 00413 nummacros--; 00414 for(i = set; i < nummacros; i++) 00415 macros[i] = macros[i + 1]; 00416 macros[i] = NULL; 00417 00418 } 00419 for(i = 0; i < NUM_COMMAC; i++) { 00420 c = commac_table[i]; 00421 while (c) { 00422 for(j = 0; j < 5; j++) { 00423 if(c->macros[j] == set) { 00424 c->macros[j] = -1; 00425 if(c->curmac == j) 00426 c->curmac = -1; 00427 } else if(c->macros[j] > set) { 00428 c->macros[j]--; 00429 } 00430 } 00431 c = c->next; 00432 } 00433 } 00434 }
void do_add_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 117 of file macro.c.
References c, get_commac(), and notify.
00118 { 00119 int first; 00120 int set; 00121 struct macros *m; 00122 struct commac *c; 00123 int i; 00124 00125 c = get_commac(player); 00126 00127 first = -1; 00128 for(i = 0; i < 5 && first < 0; i++) 00129 if(c->macros[i] == -1) 00130 first = i; 00131 00132 if(first < 0) { 00133 notify(player, 00134 "MACRO: Sorry, you already have 5 sets defined on you."); 00135 } else if(is_number(s)) { 00136 set = atoi(s); 00137 if(set >= 0 && set < nummacros) { 00138 m = macros[set]; 00139 if(can_read_macros(player, m)) { 00140 c->macros[first] = set; 00141 notify_printf(player, 00142 "MACRO: Macro set %d added in the %d slot.", 00143 set, first); 00144 } else { 00145 notify(player, "MACRO: Permission denied."); 00146 } 00147 } else { 00148 notify(player, "MACRO: That macro set does not exist."); 00149 return; 00150 } 00151 } else { 00152 notify(player, 00153 "MACRO: What set do you want to add to your macro system?"); 00154 } 00155 }
void do_chmod_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 195 of file macro.c.
References get_macro_set(), MACRO_L, MACRO_R, MACRO_W, notify, macros::player, sign(), macros::status, and Wizard.
00196 { 00197 struct macros *m; 00198 int sign; 00199 00200 m = get_macro_set(player, -1); 00201 00202 if(m) { 00203 if((m->player != player) && !Wizard(player)) { 00204 notify(player, "MACRO: Permission denied."); 00205 return; 00206 } 00207 if(*s == '!') { 00208 sign = 0; 00209 s++; 00210 } else 00211 sign = 1; 00212 00213 switch (*s) { 00214 case 'L': 00215 case 'l': 00216 if(sign) { 00217 m->status |= MACRO_L; 00218 notify(player, 00219 "MACRO: Default Macro Slot is now locked and unwritable."); 00220 } else { 00221 m->status &= ~MACRO_L; 00222 notify(player, "MACRO: Default Macro Slot is now unlocked."); 00223 } 00224 break; 00225 case 'R': 00226 case 'r': 00227 if(sign) { 00228 m->status |= MACRO_R; 00229 notify(player, 00230 "MACRO: Default Macro Slot set to be readable by others"); 00231 } else { 00232 m->status &= ~MACRO_R; 00233 notify(player, 00234 "MACRO: Default Macro Slot set to be not readable by others"); 00235 } 00236 break; 00237 case 'W': 00238 case 'w': 00239 if(sign) { 00240 m->status |= MACRO_W; 00241 notify(player, 00242 "MACRO: Default Macro Slot set to be writable by others"); 00243 } else { 00244 m->status &= ~MACRO_W; 00245 notify(player, 00246 "MACRO: Default Macro Slot set to be not writable by others"); 00247 } 00248 break; 00249 default: 00250 notify(player, 00251 "MACRO: Sorry, unknown mode. Legal modes are: L R W"); 00252 } 00253 } else 00254 notify(player, "MACRO: You have no current slot set."); 00255 }
void do_chown_macro | ( | dbref | player, | |
char * | cmd | |||
) |
Definition at line 366 of file macro.c.
References can_write_macros(), macros::desc, free_lbuf, get_macro_set(), match_thing(), NOTHING, notify, notify_printf(), macros::player, unparse_object(), and Wizard.
00367 { 00368 struct macros *m; 00369 dbref thing; 00370 char *unparse; 00371 00372 m = get_macro_set(player, -1); 00373 thing = match_thing(player, cmd); 00374 00375 if(thing == NOTHING) { 00376 notify(player, "MACRO: I do not see that here."); 00377 return; 00378 } 00379 #if 0 00380 if(!m || !can_write_macros(player, m)) { 00381 notify(player, "MACRO: Permission denied."); 00382 } 00383 #endif 00384 if(!m) { 00385 notify(player, "MACRO: No current active macro."); 00386 return; 00387 } 00388 if(!Wizard(player)) { 00389 notify(player, "MACRO: Sorry, command limited to Wizards."); 00390 return; 00391 } 00392 m->player = thing; 00393 unparse = unparse_object(player, thing, 0); 00394 notify_printf(player, "MACRO: Macro %s chowned to %s.", m->desc, unparse); 00395 free_lbuf(unparse); 00396 }
void do_clear_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 436 of file macro.c.
References c, clear_macro_set(), macros::desc, get_commac(), GMac, MACRO_L, notify, notify_printf(), macros::player, macros::status, and Wizard.
00437 { 00438 int set; 00439 struct macros *m; 00440 struct commac *c; 00441 00442 c = get_commac(player); 00443 00444 if(c->curmac == -1) { 00445 notify(player, "MACRO: You are not currently editing a macro set."); 00446 return; 00447 } else if(c->macros[c->curmac] == -1) { 00448 notify(player, "MACRO: That is not a valid macro set."); 00449 return; 00450 } 00451 set = c->macros[c->curmac]; 00452 m = macros[set]; 00453 00454 if(GMac(set)) { 00455 if((player != m->player) && !Wizard(player)) { 00456 notify(player, "MACRO: You may only CLEAR your own macro sets."); 00457 return; 00458 } else if((player == m->player) && (m->status & MACRO_L)) { 00459 notify(player, "MACRO: Sorry, that macro set is locked."); 00460 return; 00461 } 00462 } 00463 notify_printf(player, "MACRO: Clearing macro set %d: %s.", set, 00464 GMac(set) ? m->desc : "Nonexistent"); 00465 clear_macro_set(set); 00466 }
void do_create_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 707 of file macro.c.
References c, get_commac(), and notify.
00708 { 00709 int first; 00710 int i; 00711 struct commac *c; 00712 struct macros **nm; 00713 int set; 00714 00715 c = get_commac(player); 00716 first = -1; 00717 for(i = 0; i < 5 && first < 0; i++) 00718 if(c->macros[i] == -1) 00719 first = i; 00720 if(first < 0) { 00721 notify(player, 00722 "MACRO: Sorry, you already have 5 sets defined on you."); 00723 return; 00724 } 00725 if(nummacros >= maxmacros) { 00726 maxmacros += 10; 00727 nm = (struct macros **) malloc(sizeof(struct macros *) * maxmacros); 00728 00729 for(i = 0; i < nummacros; i++) 00730 nm[i] = macros[i]; 00731 free(macros); 00732 macros = nm; 00733 } 00734 set = nummacros++; 00735 macros[set] = (struct macros *) malloc(sizeof(struct macros)); 00736 00737 macros[set]->player = player; 00738 macros[set]->status = 0; 00739 macros[set]->nummacros = 0; 00740 macros[set]->maxmacros = 0; 00741 macros[set]->alias = NULL; 00742 macros[set]->string = NULL; 00743 macros[set]->desc = (char *) malloc(strlen(s) + 1); 00744 StringCopy(macros[set]->desc, s); 00745 c->curmac = first; 00746 c->macros[first] = set; 00747 00748 notify_printf(player, 00749 "MACRO: Macro set %d created with description %s.", set, s); 00750 }
void do_def_macro | ( | dbref | player, | |
char * | cmd | |||
) |
Definition at line 468 of file macro.c.
References macros::alias, can_write_macros(), get_macro_set(), LBUF_SIZE, macros::maxmacros, notify, nummacros, macros::nummacros, macros::string, and StringCopy.
00469 { 00470 int i, j, where; 00471 struct macros *m; 00472 char *alias; 00473 char *s; 00474 char buffer[LBUF_SIZE]; 00475 char **ns; 00476 char *na; 00477 00478 m = get_macro_set(player, -1); 00479 00480 if(!m) { 00481 notify(player, "MACRO: No current set."); 00482 return; 00483 } 00484 if(!can_write_macros(player, m)) { 00485 notify(player, "MACRO: Permission denied."); 00486 return; 00487 } 00488 for(alias = cmd; *alias && *alias == ' '; alias++) 00489 *alias = 0; 00490 00491 cmd = alias; 00492 for(; *cmd && *cmd != ' ' && *cmd != '='; cmd++); 00493 while (*cmd && *cmd == ' ') 00494 *cmd++ = '\0'; 00495 if(*cmd != '=') { 00496 notify(player, 00497 "MACRO: You must specify an = in your macro definition"); 00498 return; 00499 } 00500 *cmd++ = 0; 00501 while (*cmd && *cmd == ' ') 00502 *cmd++ = 0; 00503 00504 s = cmd; 00505 00506 if(!*s) { 00507 notify(player, "MACRO: You must specify a string to substitute for."); 00508 return; 00509 } else if(strlen(alias) > 4) { 00510 notify(player, "MACRO: Please limit aliases to 4 chars or less."); 00511 return; 00512 } 00513 for(j = 0; 00514 j < m->nummacros && (strcasecmp(alias, m->alias + j * 5) > 0); j++); 00515 if(j < m->nummacros && !strcasecmp(alias, m->alias + j * 5)) { 00516 notify(player, "MACRO: That alias is already defined in this set."); 00517 sprintf(buffer, "%-4.4s:%s", m->alias + j * 5, m->string[j]); 00518 notify(player, buffer); 00519 return; 00520 } 00521 if(m->nummacros >= m->maxmacros) { 00522 m->maxmacros += 10; 00523 na = (char *) malloc(5 * m->maxmacros); 00524 ns = (char **) malloc(sizeof(char *) * m->maxmacros); 00525 00526 for(i = 0; i < m->nummacros; i++) { 00527 StringCopy(na + i * 5, m->alias + i * 5); 00528 ns[i] = m->string[i]; 00529 } 00530 free(m->alias); 00531 free(m->string); 00532 m->alias = na; 00533 m->string = ns; 00534 } 00535 where = m->nummacros++; 00536 for(i = where; i > j; i--) { 00537 StringCopy(m->alias + i * 5, m->alias + (i - 1) * 5); 00538 m->string[i] = m->string[i - 1]; 00539 } 00540 00541 where = j; 00542 StringCopy(m->alias + where * 5, alias); 00543 m->string[where] = (char *) malloc(strlen(s) + 1); 00544 StringCopy(m->string[where], s); 00545 sprintf(buffer, "MACRO: Macro %s:%s defined.", alias, s); 00546 notify(player, buffer); 00547 }
void do_del_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 157 of file macro.c.
References c, get_commac(), is_number(), notify, and notify_printf().
00158 { 00159 struct commac *c; 00160 int set; 00161 00162 c = get_commac(player); 00163 00164 if(is_number(s)) { 00165 set = atoi(s); 00166 if(set >= 0 && set < 5 && c->macros[set] >= 0) { 00167 c->macros[set] = -1; 00168 notify_printf(player, "MACRO: Macro slot %d cleared.", set); 00169 if(set == c->curmac) { 00170 c->curmac = -1; 00171 notify(player, 00172 "MACRO: Deleted current slot, resetting to none."); 00173 } 00174 } else 00175 notify(player, "MACRO: That is not a legal macro slot."); 00176 } else 00177 notify(player, 00178 "MACRO: What set did you want to delete from your macro system?"); 00179 }
void do_desc_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 181 of file macro.c.
References macros::desc, get_macro_set(), notify, notify_printf(), and StringCopy.
00182 { 00183 struct macros *m; 00184 00185 m = get_macro_set(player, -1); 00186 if(m) { 00187 free(m->desc); 00188 m->desc = (char *) malloc(strlen(s) + 1); 00189 StringCopy(m->desc, s); 00190 notify_printf(player, "MACRO: Current slot description to %s.", s); 00191 } else 00192 notify(player, "MACRO: You have no current slot set."); 00193 }
void do_edit_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 293 of file macro.c.
References c, get_commac(), GMac, is_number(), notify, and notify_printf().
00294 { 00295 struct commac *c; 00296 int set; 00297 00298 c = get_commac(player); 00299 00300 if(is_number(s)) { 00301 set = atoi(s); 00302 if(set >= 0 && set < 5 && GMac(c->macros[set])) { 00303 c->curmac = set; 00304 notify_printf(player, "MACRO: Current slot set to %d.", set); 00305 } else 00306 notify(player, "MACRO: That is not a legal macro slot."); 00307 } else 00308 notify(player, "MACRO: What slot did you want to make current?"); 00309 }
void do_ex_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 342 of file macro.c.
References macros::alias, macros::desc, get_macro_set(), is_number(), LBUF_SIZE, notify, notify_printf(), macros::nummacros, and macros::string.
00343 { 00344 struct macros *m; 00345 int which; 00346 int i; 00347 char buffer[LBUF_SIZE]; 00348 00349 if(is_number(s)) { 00350 which = atoi(s); 00351 m = get_macro_set(player, which); 00352 } else 00353 m = get_macro_set(player, -1); 00354 00355 if(m) { 00356 notify_printf(player, "Macro Definitions for %s", m->desc); 00357 for(i = 0; i < m->nummacros; i++) { 00358 sprintf(buffer, " %-5.5s: %s", m->alias + i * 5, m->string[i]); 00359 notify(player, buffer); 00360 } 00361 } else 00362 notify(player, "MACRO: Illegal macro set to examine."); 00363 00364 }
void do_gex_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 257 of file macro.c.
References macros::alias, can_read_macros(), macros::desc, is_number(), LBUF_SIZE, notify, notify_printf(), macros::nummacros, nummacros, and macros::string.
00258 { 00259 struct macros *m; 00260 int which; 00261 int i; 00262 char buffer[LBUF_SIZE]; 00263 00264 if(!s || !*s) { 00265 notify(player, "MACRO: You need to specify a macro set."); 00266 return; 00267 } 00268 if(is_number(s)) { 00269 which = atoi(s); 00270 if((which >= nummacros) || (which < 0) || (nummacros == 0)) { 00271 notify_printf(player, 00272 "MACRO: Illegal Macro Set. Macros go from 0 to %d.", 00273 nummacros - 1); 00274 return; 00275 } else 00276 m = macros[which]; 00277 } else { 00278 notify(player, "MACRO: I do not see that set here."); 00279 return; 00280 } 00281 00282 if(m && can_read_macros(player, m)) { 00283 notify_printf(player, "Macro Definitions for %s", m->desc); 00284 for(i = 0; i < m->nummacros; i++) { 00285 sprintf(buffer, " %-5.5s: %s", m->alias + i * 5, m->string[i]); 00286 notify(player, buffer); 00287 } 00288 } else 00289 notify(player, "MACRO: Permission denied."); 00290 00291 }
void do_list_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 88 of file macro.c.
References can_read_macros(), macros::desc, free_lbuf, MACRO_L, MACRO_R, MACRO_W, notify, notify_printf(), nummacros, macros::player, macros::status, and unparse_object().
00089 { 00090 int i; 00091 int notified = 0; 00092 struct macros *m; 00093 char *unparse; 00094 00095 for(i = 0; i < nummacros; i++) { 00096 m = macros[i]; 00097 00098 if(can_read_macros(player, m)) { 00099 if(!notified) { 00100 notify(player, 00101 "Num Description Owner LRW"); 00102 notified = 1; 00103 } 00104 unparse = unparse_object(player, m->player, 0); 00105 notify_printf(player, "%-4d %-35.35s %-24.24s %c%c%c", i, 00106 m->desc, unparse, m->status & MACRO_L ? 'L' : '-', 00107 m->status & MACRO_R ? 'R' : '-', 00108 m->status & MACRO_W ? 'W' : '-'); 00109 free_lbuf(unparse); 00110 } 00111 } 00112 00113 if(!notified) 00114 notify(player, "MACRO: There are no macro sets you can read."); 00115 }
int do_macro | ( | dbref | player, | |
char * | in, | |||
char ** | out | |||
) |
Definition at line 46 of file macro.c.
References alloc_lbuf, free_lbuf, macroentry::handler, hashfind(), isPlayer, statedata::macro_htab, mudstate, notify, and StringCopy.
Referenced by process_command().
00047 { 00048 char *s; 00049 char *cmd; 00050 MACENT *mp; 00051 char *old; 00052 00053 cmd = in + 1; 00054 00055 if(!isPlayer(player)) { 00056 notify(player, "MACRO: Only players may use macros."); 00057 return 0; 00058 } 00059 old = alloc_lbuf("do_macro"); 00060 00061 StringCopy(old, in); 00062 00063 for(s = cmd; *s && *s != ' '; s++); 00064 if(*s == ' ') 00065 *s++ = 0; 00066 00067 mp = (MACENT *) hashfind(cmd, &mudstate.macro_htab); 00068 if(mp != NULL) { 00069 (*(mp->handler)) (player, s); 00070 free_lbuf(old); 00071 return 0; 00072 } 00073 if((*out = do_process_macro(player, in, s)) != NULL) { 00074 free_lbuf(old); 00075 return 1; 00076 } else { 00077 StringCopy(in, old); 00078 free_lbuf(old); 00079 return 2; /* 00080 * return any value > 1, and command * * * 00081 * processing will 00082 */ 00083 } /* 00084 * continue 00085 */ 00086 }
char* do_process_macro | ( | dbref | player, | |
char * | in, | |||
char * | s | |||
) |
Definition at line 575 of file macro.c.
References macros::alias, alloc_lbuf, c, dir, get_commac(), GMac, macros::nummacros, macros::string, and StringCopy.
00576 { 00577 char *cmd; 00578 char *tar; 00579 char *next; 00580 struct macros *m; 00581 int first, last, current = 0; 00582 int dir; 00583 int i; 00584 struct commac *c; 00585 char *buff; 00586 00587 c = get_commac(player); 00588 buff = alloc_lbuf("do_process_macro"); 00589 cmd = in + 1; 00590 buff[0] = '\0'; /* 00591 * End the string 00592 */ 00593 for(i = 0; i < 5; i++) { 00594 if(GMac(c->macros[i])) { 00595 m = macros[c->macros[i]]; 00596 if(m->nummacros > 0) { 00597 first = 0; 00598 last = m->nummacros - 1; 00599 dir = 1; 00600 next = in + 1; 00601 while (dir && (first <= last)) { 00602 current = (first + last) / 2; 00603 dir = strcmp(next, m->alias + 5 * current); 00604 if(dir < 0) 00605 last = current - 1; 00606 else 00607 first = current + 1; 00608 } 00609 00610 if(!dir) { 00611 tar = m->string[current]; 00612 #if 1 /* Original MUSE code */ 00613 next = buff; 00614 while (*tar) { 00615 if(*tar == '%' && *(tar + 1) == '*') { 00616 *next++ = '*'; 00617 tar += 2; 00618 } else if(*tar == '*') { 00619 *next = 0; 00620 strcat(next, s); 00621 tar++; 00622 next += strlen(next); 00623 } else 00624 *next++ = *tar++; 00625 } 00626 *next = 0; 00627 #else 00628 while (*tar) { 00629 switch (*tar) { 00630 case '*': 00631 if(!buff) 00632 StringCopy(buff, s); 00633 else 00634 strcat(buff, s); 00635 break; 00636 case '%': 00637 if(!buff) 00638 StringCopy(buff, tar + 1); 00639 else 00640 sprintf(buff, "%s%c", buff, tar + 1); 00641 *tar++; 00642 break; 00643 default: 00644 if(!buff) 00645 StringCopy(buff, tar); 00646 else 00647 sprintf(buff, "%s%c", buff, *tar); 00648 break; 00649 } 00650 *tar++; 00651 } 00652 #endif 00653 return buff; 00654 } 00655 } 00656 } 00657 } 00658 free_lbuf(buff); 00659 return NULL; 00660 }
void do_sort_macro_set | ( | struct macros * | m | ) |
Definition at line 684 of file macro.c.
References macros::alias, macros::nummacros, macros::string, and StringCopy.
Referenced by load_macros(), and mmdb_db_read().
00685 { 00686 int i; 00687 int cont; 00688 char buffer[10]; 00689 char *s; 00690 00691 cont = 1; 00692 while (cont) { 00693 cont = 0; 00694 for(i = 0; i < m->nummacros - 1; i++) 00695 if(strcasecmp(m->alias + i * 5, m->alias + (i + 1) * 5) > 0) { 00696 StringCopy(buffer, m->alias + i * 5); 00697 StringCopy(m->alias + i * 5, m->alias + (i + 1) * 5); 00698 StringCopy(m->alias + (i + 1) * 5, buffer); 00699 s = m->string[i]; 00700 m->string[i] = m->string[i + 1]; 00701 m->string[i + 1] = s; 00702 cont = 1; 00703 } 00704 } 00705 }
void do_status_macro | ( | dbref | player, | |
char * | s | |||
) |
Definition at line 311 of file macro.c.
References c, macros::desc, free_lbuf, get_commac(), GMac, MACRO_L, MACRO_R, MACRO_W, notify, notify_printf(), macros::player, macros::status, and unparse_object().
00312 { 00313 int i; 00314 struct commac *c; 00315 struct macros *m; 00316 char *unparse; 00317 00318 c = get_commac(player); 00319 00320 notify(player, 00321 "#: Num Description Owner LRW"); 00322 for(i = 0; i < 5; i++) { 00323 if(c->macros[i] >= 0) 00324 if(!(GMac(c->macros[i]))) 00325 notify_printf(player, "%d: INVALID MACRO SET!", i); 00326 else { 00327 m = macros[c->macros[i]]; 00328 unparse = unparse_object(player, m->player, 0); 00329 notify_printf(player, 00330 "%d: %-4d %-35.35s %-24.24s %c%c%c", i, 00331 c->macros[i], m->desc, unparse, 00332 m->status & MACRO_L ? 'L' : '-', 00333 m->status & MACRO_R ? 'R' : '-', 00334 m->status & MACRO_W ? 'W' : '-'); 00335 free_lbuf(unparse); 00336 } else 00337 notify_printf(player, "%d:", i); 00338 } 00339 notify_printf(player, "Current Macro Slot: %d", c->curmac); 00340 }
void do_undef_macro | ( | dbref | player, | |
char * | cmd | |||
) |
Definition at line 549 of file macro.c.
References macros::alias, can_write_macros(), get_macro_set(), notify, nummacros, macros::nummacros, macros::string, and StringCopy.
00550 { 00551 int i; 00552 struct macros *m; 00553 00554 m = get_macro_set(player, -1); 00555 00556 if(!m || !can_write_macros(player, m)) { 00557 notify(player, "MACRO: Permission denied."); 00558 return; 00559 } 00560 for(i = 0; i < m->nummacros; i++) { 00561 if(!strcmp(m->alias + i * 5, cmd)) { 00562 free(m->string[i]); 00563 m->nummacros--; 00564 for(; i < m->nummacros; i++) { 00565 StringCopy(m->alias + i * 5, m->alias + i * 5 + 5); 00566 m->string[i] = m->string[i + 1]; 00567 } 00568 notify(player, "MACRO: Macro deleted from set."); 00569 return; 00570 } 00571 } 00572 notify(player, "MACRO: That macro is not in this set."); 00573 }
Definition at line 662 of file macro.c.
References c, and get_commac().
Referenced by do_chmod_macro(), do_chown_macro(), do_def_macro(), do_desc_macro(), do_ex_macro(), and do_undef_macro().
00663 { 00664 int set; 00665 struct commac *c; 00666 00667 c = get_commac(player); 00668 00669 if(c) { 00670 set = -1; 00671 if(which >= 0 && which < 5) 00672 set = c->macros[which]; 00673 else if(c->curmac >= 0) 00674 set = c->macros[c->curmac]; 00675 00676 if(set == -1) 00677 return NULL; 00678 else 00679 return macros[set]; 00680 } else 00681 return NULL; 00682 }
void init_mactab | ( | void | ) |
Definition at line 36 of file macro.c.
References macroentry::cmdname, HASH_FACTOR, hashadd(), hashinit(), statedata::macro_htab, macro_table, and mudstate.
Referenced by main().
00037 { 00038 MACENT *mp; 00039 00040 hashinit(&mudstate.macro_htab, 5 * HASH_FACTOR); 00041 00042 for(mp = macro_table; mp->cmdname; mp++) 00043 hashadd(mp->cmdname, (int *) mp, &mudstate.macro_htab); 00044 }
void load_macros | ( | FILE * | fp | ) |
Definition at line 779 of file macro.c.
References macros::alias, c, clear_macro_set(), macros::desc, do_sort_macro_set(), isPlayer, LBUF_SIZE, macros::maxmacros, macros::nummacros, nummacros, macros::player, macros::status, macros::string, StringCopy, tprintf(), and TST.
00780 { 00781 int i, j; 00782 char *c; 00783 char *t; 00784 char buffer[LBUF_SIZE]; 00785 struct macros *m; 00786 00787 TST(fscanf(fp, "%d\n", &nummacros) != 1, "Error: Loading #macros\n"); 00788 maxmacros = nummacros; 00789 00790 if(maxmacros > 0) 00791 macros = 00792 (struct macros **) malloc(sizeof(struct macros *) * nummacros); 00793 else 00794 macros = NULL; 00795 00796 for(i = 0; i < nummacros; i++) { 00797 macros[i] = (struct macros *) malloc(sizeof(struct macros)); 00798 00799 m = macros[i]; 00800 00801 fgets(buffer, LBUF_SIZE, fp); 00802 TST(sscanf(buffer, "%d %d %d\n", &(m->player), &(m->nummacros), &j) 00803 != 3, tprintf("Reading macro set #%d\n", i)); 00804 m->status = j; 00805 00806 fgets(buffer, LBUF_SIZE, fp); 00807 if(*buffer) 00808 if(buffer[strlen(buffer) - 1] == '\n') 00809 buffer[strlen(buffer) - 1] = 0; 00810 00811 m->desc = (char *) malloc(strlen(buffer) - 1); 00812 StringCopy(m->desc, buffer + 2); 00813 00814 m->maxmacros = m->nummacros; 00815 if(m->nummacros > 0) { 00816 m->alias = (char *) malloc(5 * m->maxmacros); 00817 m->string = (char **) malloc(sizeof(char *) * m->nummacros); 00818 00819 for(j = 0; j < m->nummacros; j++) { 00820 t = m->alias + j * 5; 00821 fgets(buffer, LBUF_SIZE, fp); 00822 if(buffer[strlen(buffer) - 1] == '\n') 00823 buffer[strlen(buffer) - 1] = 0; 00824 for(c = buffer; *c && *c != ' '; c++); 00825 *c = 0; 00826 if(strlen(buffer) > 4) { 00827 fprintf(stderr, "Error reading macro set #%d!\n", i); 00828 exit(1); 00829 } 00830 if(!*buffer) { 00831 00832 /* fprintf(stderr, "Error in macro set #%d (macro %d) : Invalid macro name.\n", i, j); */ 00833 t[0] = 0; 00834 } else 00835 strcpy(t, buffer); 00836 c++; 00837 m->string[j] = (char *) malloc(strlen(c) + 1); 00838 StringCopy(m->string[j], c); 00839 } 00840 do_sort_macro_set(m); 00841 } else { 00842 m->alias = NULL; 00843 m->string = NULL; 00844 } 00845 } 00846 while (1) { 00847 for(i = 0; i < nummacros; i++) 00848 if(!isPlayer(macros[i]->player)) 00849 break; 00850 if(i >= nummacros) 00851 break; 00852 clear_macro_set(i); 00853 } 00854 }
Definition at line 289 of file functions.c.
00290 { 00291 init_match(player, name, NOTYPE); 00292 match_everything(MAT_EXIT_PARENTS); 00293 return (noisy_match_result()); 00294 }
void save_macros | ( | FILE * | fp | ) |
Definition at line 856 of file macro.c.
References macros::alias, macros::desc, macros::nummacros, nummacros, macros::player, macros::status, and macros::string.
00857 { 00858 int i, j; 00859 struct macros *m; 00860 00861 fprintf(fp, "%d\n", nummacros); 00862 00863 for(i = 0; i < nummacros; i++) { 00864 m = macros[i]; 00865 fprintf(fp, "%d %d %d\n", m->player, m->nummacros, (int) m->status); 00866 fprintf(fp, "D:%s\n", m->desc); 00867 for(j = 0; j < m->nummacros; j++) 00868 fprintf(fp, "%s %s\n", m->alias + j * 5, m->string[j]); 00869 } 00870 }
Initial value:
{ {(char *) "add", do_add_macro}, {(char *) "clear", do_clear_macro}, {(char *) "chmod", do_chmod_macro}, {(char *) "chown", do_chown_macro}, {(char *) "create", do_create_macro}, {(char *) "def", do_def_macro}, {(char *) "del", do_del_macro}, {(char *) "name", do_desc_macro}, {(char *) "chslot", do_edit_macro}, {(char *) "ex", do_ex_macro}, {(char *) "gex", do_gex_macro}, {(char *) "glist", do_list_macro}, {(char *) "list", do_status_macro}, {(char *) "undef", do_undef_macro}, {(char *) NULL, NULL} }
Definition at line 18 of file macro.c.
Referenced by init_mactab().