From 947236907cd7f65fbff28aa311d8e3af3465a616 Mon Sep 17 00:00:00 2001 From: Rick Bird Date: Sun, 27 Mar 2011 00:47:14 -0400 Subject: [PATCH] PennIncorp 182p6 LOTS OF INDENTION CHANGES Minor changes: * Removed the gmalloc malloc option. (For real this time!) [SW] * KEEPALIVE flag makes the server send a telnet NOP after a short period of inactivity; helps prevent timeouts from NAT/router devices with a short timeout. [MUX] Fixes: * Fixed assorted small memory leaks. [SW] * Fixed handling of telnet NOPs sent by clients. [SW] * The OpenSSL random number pool wasn't getting adequately initialized on systems without /dev/urandom [SW] * Infinite loop in math code. Reported by Ashen-Sugar. [GM] * mkvershlp.pl skips over emacs backup files. --- INSTALL | 63 +- MANIFEST | 1 - UPGRADING | 9 +- game/mushcnf.dst | 7 +- game/txt/hlp/cobra_cmd.hlp | 2 +- game/txt/hlp/cobra_code.hlp | 14 +- game/txt/hlp/cobra_flag.hlp | 13 + hdrs/access.h | 8 +- hdrs/ansi.h | 2 +- hdrs/atr_tab.h | 2 +- hdrs/attrib.h | 6 +- hdrs/boolexp.h | 4 +- hdrs/bufferq.h | 16 +- hdrs/case.h | 2 +- hdrs/chunk.h | 6 +- hdrs/command.h | 14 +- hdrs/compile.h | 2 +- hdrs/conf.h | 6 +- hdrs/csrimalloc.h | 92 +- hdrs/dbdefs.h | 42 +- hdrs/dbio.h | 4 +- hdrs/extchat.h | 28 +- hdrs/externs.h | 69 +- hdrs/extmail.h | 14 +- hdrs/flags.h | 28 +- hdrs/function.h | 32 +- hdrs/game.h | 36 +- hdrs/getpgsiz.h | 22 +- hdrs/help.h | 16 +- hdrs/htab.h | 16 +- hdrs/ident.h | 10 +- hdrs/lock.h | 18 +- hdrs/log.h | 6 +- hdrs/malias.h | 24 +- hdrs/match.h | 2 +- hdrs/mushdb.h | 2 +- hdrs/mushtype.h | 32 +- hdrs/mymalloc.h | 16 +- hdrs/mysocket.h | 90 +- hdrs/myssl.h | 8 +- hdrs/oldflags.h | 62 +- hdrs/parse.h | 30 +- hdrs/pcre.h | 56 +- hdrs/privtab.h | 12 +- hdrs/ptab.h | 12 +- hdrs/pueblo.h | 2 +- hdrs/shs.h | 10 +- hdrs/strtree.h | 14 +- src/access.c | 204 +- src/atr_tab.c | 20 +- src/attrib.c | 14 +- src/bsd.c | 371 +- src/bufferq.c | 4 +- src/chunk.c | 442 +-- src/cmds.c | 62 +- src/command.c | 60 +- src/comp_h.c | 54 +- src/comp_w.c | 68 +- src/comp_w8.c | 72 +- src/compress.c | 4 +- src/conf.c | 214 +- src/cque.c | 218 +- src/create.c | 62 +- src/csrimalloc.c | 632 ++- src/db.c | 196 +- src/destroy.c | 362 +- src/extchat.c | 242 +- src/extmail.c | 812 ++-- src/filecopy.c | 2 +- src/flags.c | 264 +- src/funcrypt.c | 4 +- src/function.c | 76 +- src/fundb.c | 154 +- src/funlist.c | 452 +-- src/funmath.c | 22 +- src/funmisc.c | 54 +- src/funstr.c | 304 +- src/funtime.c | 284 +- src/funufun.c | 40 +- src/game.c | 468 +-- src/gmalloc.c | 1295 ------- src/help.c | 132 +- src/htab.c | 46 +- src/ident.c | 42 +- src/info_slave.c | 24 +- src/local.dst | 24 +- src/lock.c | 78 +- src/log.c | 66 +- src/look.c | 324 +- src/malias.c | 132 +- src/match.c | 72 +- src/memcheck.c | 20 +- src/move.c | 104 +- src/mymalloc.c | 2 - src/mysocket.c | 338 +- src/myssl.c | 104 +- src/notify.c | 308 +- src/parse.c | 173 +- src/pcre.c | 7278 +++++++++++++++++------------------ src/player.c | 55 +- src/plyrlist.c | 2 +- src/portmsg.c | 2 +- src/predicat.c | 124 +- src/privtab.c | 66 +- src/ptab.c | 104 +- src/rob.c | 150 +- src/services.c | 175 +- src/set.c | 142 +- src/shs.c | 20 +- src/sig.c | 6 +- src/speech.c | 84 +- src/sql.c | 26 +- src/strtree.c | 234 +- src/strutil.c | 422 +- src/timer.c | 32 +- src/unparse.c | 8 +- src/utils.c | 69 +- src/warnings.c | 104 +- src/wild.c | 113 +- src/wiz.c | 86 +- utils/mkvershlp.pl | 1 + 121 files changed, 9311 insertions(+), 10495 deletions(-) diff --git a/INSTALL b/INSTALL index 89c2f32..54e32a6 100644 --- a/INSTALL +++ b/INSTALL @@ -7,33 +7,35 @@ This file explains how to install PennMUSH. It comes in three parts: C. Installation of precompiled binaries (only for Windows platforms) If you are upgrading from a previous PennMUSH release, this is -probably not the file you want to start with. Read the UPGRADING -file first. - -DISCLAIMER: Before attempting to run a MUD of any sort, you should have -some reasonable knowledge of UNIX and C. If you do not, it is _strongly_ -suggested that you learn UNIX and C to some reasonable level of competency -before attempting to set up a MUSH. (Note that even people using the -Windows ports are encouraged to know UNIX, because that's the paradigm -that PennMUSH was built with, and most resources will be written with -UNIX is mind.) - -You may also want to take a look at Javelin's Guide for PennMUSH Gods, -at http://pennmush.org/~alansz/guide.html -or by ftp from pennmush.org, /pub/PennMUSH/Guide +probably not the file you want to start with. Read the UPGRADING file +first. + +DISCLAIMER: Before attempting to run a MUD of any sort, you should +have some reasonable knowledge of UNIX and C. If you do not, it is +_strongly_ suggested that you learn UNIX and C to some reasonable +level of competency before attempting to set up a MUSH. (Note that +even people using the Windows ports are encouraged to know UNIX, +because that's the paradigm that PennMUSH was built with, and most +resources will be written with UNIX is mind.) + +You may also want to take a look at the Managing PennMUSH book at +http://community.pennmush.org and at Javelin's Guide for PennMUSH +Gods, at http://javelin.pennmush.org/~alansz/guide.html or by ftp from +pennmush.org, /pub/PennMUSH/Guide ============================================================================ A. Important background Here's a quick picture of the organization of the MUSH directory tree. The "src" directory contains C source code. The "hdrs" directory -contains header files for the source code. The files used by a running -MUSH are in the "game" directory, which includes subdirectories "data" -(current databases), "txt" (text files and directories for building them), -"log" (log files), and "save" (backup databases). Finally, the "hints" -directory is used during the installation process, the "po" directory -holds translation message files, and the "os2" directory contains files -of using in building for OS/2. +contains header files for the source code. The files used by a +running MUSH are in the "game" directory, which includes +subdirectories "data" (current databases), "txt" (text files and +directories for building them), "log" (log files), and "save" (backup +databases). Finally, the "hints" directory is used during the +installation process, the "po" directory holds translation message +files, and the "os2" directory contains files of using in building for +OS/2. pennmush--+-> src +-> hdrs @@ -71,14 +73,14 @@ operating systems including at least: Windows 95/NT cygwin and MSVC++ OS/2 -There's no real reason why PennMUSH shouldn't compile on any 32-bit -or better BSD, System V, or POSIX operating system. Javelin does his +There's no real reason why PennMUSH shouldn't compile on any 32-bit or +better BSD, System V, or POSIX operating system. Javelin does his development on a Linux PC these days. If you have serious problems, contact Javelin and he will try to help -you. Email is the best way to get a fast response; in an emergency, you -can bother him on a MUD, but for code problems, email will probably get -you a better response. +you. Email is the best way to get a fast response; in an emergency, +you can bother him on a MUD, but for code problems, email will +probably get you a better response. ============================================================================ @@ -184,13 +186,14 @@ themselves. This binary distribution may not contain the src, hdrs, hints, or os2 directories and may be missing several key files (like Configure) from the pennmush directory. It does include the options.h that it was built with, as an aid to those who decide later that they -want to customize the server; they are useful as a baseline to work from. +want to customize the server; they are useful as a baseline to work +from. Using the pre-built binary is fairly simple; adjust your configuration file as in game/README, then go to the game directory and run PennMUSH.exe (you may need to use PennMUSH /run or PennMUSH /start). Alternately, if you want the MUSH to automatically start each time you -turn on your machine, you can install it as a system service by running -'PennMUSH /install'. PennMUSH can be removed from service status via -'PennMUSH /remove'. +turn on your machine, you can install it as a system service by +running 'PennMUSH /install'. PennMUSH can be removed from service +status via 'PennMUSH /remove'. diff --git a/MANIFEST b/MANIFEST index 2aa9e44..8450458 100644 --- a/MANIFEST +++ b/MANIFEST @@ -172,7 +172,6 @@ src/funstr.c src/funtime.c src/funufun.c src/game.c -src/gmalloc.c src/help.c src/htab.c src/ident.c diff --git a/UPGRADING b/UPGRADING index 45c402c..749955c 100644 --- a/UPGRADING +++ b/UPGRADING @@ -123,10 +123,11 @@ changes. One small exception is upgrading from a version that used the old flag system to one that uses the new flag system (post-1.7.7p5), if you've added flags or toggles. You probably had an #define in hdrs/flags.h -for your flag's bit value. This now should be moved to hdrs/oldflags.h; -you should leave in the table entry in src/flags.c. If you set up a macro -for testing your flag in hdrs/mushdb.h, you'll need to change it to use -the has_flag_by_name() function - see the many examples in that file. +for your flag's bit value. This now should be moved to +hdrs/oldflags.h; you should leave in the table entry in +src/flags.c. If you set up a macro for testing your flag in +hdrs/mushdb.h, you'll need to change it to use the has_flag_by_name() +function - see the many examples in that file. If this isn't suitable (you're crossing releases or your hacks are too many for this to work cleanly), see below. diff --git a/game/mushcnf.dst b/game/mushcnf.dst index 39801bb..57e0b92 100644 --- a/game/mushcnf.dst +++ b/game/mushcnf.dst @@ -224,10 +224,11 @@ idle_time 30m # been no activity for a few minutes; they tend to assume the web is # the internet, and don't deal well with persistant connections like # mushes use. This option will make the server automatically send a -# 'Are you still there?' query every few minutes to keep the +# TCP-level 'Are you still there?' query every few minutes to keep the # connection active. -# NOTE: This doesn't work on all OSes, but does on the most popular -# ones for mush hosting such as linux. +# NOTE: This doesn't work on all OSes, but does some of the most popular +# ones for mush hosting such as linux. Other options include the KEEPALIVE +# flag and the IDLE command. keepalive_timeout 5m # Should there be a limit on the number of logins the MUSH diff --git a/game/txt/hlp/cobra_cmd.hlp b/game/txt/hlp/cobra_cmd.hlp index e48e69b..53c95a5 100644 --- a/game/txt/hlp/cobra_cmd.hlp +++ b/game/txt/hlp/cobra_cmd.hlp @@ -1564,7 +1564,7 @@ See also: help flags. See help @flag2 for information on @flag/add For example: @function/delete ansi - &ansi_fun #1234=%0 + &ansi_fun #1234=%1 @function ansi=#1234, ansi_fun, 2, 2, noguest will create a new version of ansi() that doesn't do any diff --git a/game/txt/hlp/cobra_code.hlp b/game/txt/hlp/cobra_code.hlp index 1b0d543..9607240 100644 --- a/game/txt/hlp/cobra_code.hlp +++ b/game/txt/hlp/cobra_code.hlp @@ -2,14 +2,16 @@ & contact PennMUSH is developed by a team of developers whose names are listed in 'help changes'. Suggestions, comments, and bug reports are -welcome: +welcome. -Report bugs at: pennmush-bugs@pennmush.org -Comments/suggestions to: pennmush-developers@pennmush.org +The main PennMUSH web page is at http://www.pennmush.org + +Report bugs and make suggestions at: http://dev.pennmush.org + +The PennMUSH community page is at http://community.pennmush.org For information about downloading PennMUSH, see 'help download'. For information about changes in versions of the code, see 'help changes'. - & download The latest version of this MUSH code is available at http://download.pennmush.org/Source. It will be called something like @@ -22,7 +24,7 @@ Also on that site is the MUSH manual, in /Manuals. It should be called mushman.2.008.tar.Z or something similar; you should attempt to get at least version 2.007. Also on that site is Javelin's Guide for PennMUSH Gods, in /pub/PennMUSH/Guide. A better way to read it is on the Web at -http://www.pennmush.org/~alansz/guide.html +http://javelin.pennmush.org/~alansz/guide.html & i18n & internationalization @@ -45,6 +47,8 @@ Internationalization support in PennMUSH includes: Most of these features get enabled by setting an appropriate environment variable in the PennMUSH restart script. +Unicode is not currently supported. + & copyright & copyrite & license diff --git a/game/txt/hlp/cobra_flag.hlp b/game/txt/hlp/cobra_flag.hlp index 9d21e42..d0a2f43 100644 --- a/game/txt/hlp/cobra_flag.hlp +++ b/game/txt/hlp/cobra_flag.hlp @@ -373,6 +373,19 @@ See also: @halt, @restart When a room is set JUMP_OK, then that room can be teleported into by anyone. See @teleport. +& KEEPALIVE + Flag: KEEPALIVE (players) + + When this flag is set on a player with a telnet-capable connection, + a telnet NOP (no-operation) is sent after there's been no activity + on the connection for a minute, to generate socket activity without + generating any output. In a way, it's the opposite of the IDLE + command. IDLE is sent by clients to keep a connection open, while + KEEPALIVE tells the server to send a message. Both are intended for + use by people going through home router/NAT appliances with short + inactivity timeouts. + +See also: IDLE, terminfo() & LIGHT Flag: LIGHT (all types) diff --git a/hdrs/access.h b/hdrs/access.h index 11637ec..051fd56 100644 --- a/hdrs/access.h +++ b/hdrs/access.h @@ -49,13 +49,13 @@ void write_access_file(void); int site_can_access(const char *hname, int flag, dbref who); struct access *site_check_access(const char *hname, dbref who, int *rulenum); int format_access(struct access *ap, int rulenum, - dbref who - __attribute__ ((__unused__)), char *buff, char **bp); + dbref who + __attribute__ ((__unused__)), char *buff, char **bp); int add_access_sitelock(dbref player, const char *host, dbref who, int can, - int cant); + int cant); int remove_access_sitelock(const char *pattern); void do_list_access(dbref player); int parse_access_options (const char *opts, dbref *who, int *can, int *cant, dbref player); -#endif /* __ACCESS_H */ +#endif /* __ACCESS_H */ diff --git a/hdrs/ansi.h b/hdrs/ansi.h index 848e859..b09b297 100644 --- a/hdrs/ansi.h +++ b/hdrs/ansi.h @@ -66,4 +66,4 @@ #define ANSI_END "m" -#endif /* __ANSI_H */ +#endif /* __ANSI_H */ diff --git a/hdrs/atr_tab.h b/hdrs/atr_tab.h index 02e3d6c..d32c0d4 100644 --- a/hdrs/atr_tab.h +++ b/hdrs/atr_tab.h @@ -258,4 +258,4 @@ ATTR attr[] = { {NULL, 0, NULL_CHUNK_REFERENCE, 0, TRUE_BOOLEXP, TRUE_BOOLEXP, 0, NULL} }; -#endif /* __ATR_TAB_H */ +#endif /* __ATR_TAB_H */ diff --git a/hdrs/attrib.h b/hdrs/attrib.h index a76bb83..6c00b33 100644 --- a/hdrs/attrib.h +++ b/hdrs/attrib.h @@ -53,10 +53,10 @@ extern void do_attribute_lock(dbref player, char *name, char *lock, switch_mask typedef enum { AE_OKAY = 0, /**< Success */ AE_ERROR = -1, /**< general failure */ - AE_SAFE = -2, /**< attempt to overwrite a safe attribute */ + AE_SAFE = -2, /**< attempt to overwrite a safe attribute */ AE_BADNAME = -3, /**< invalid name */ AE_TOOMANY = -4, /**< too many attribs */ - AE_TREE = -5, /**< unable to delete/create entire tree */ + AE_TREE = -5, /**< unable to delete/create entire tree */ AE_NOTFOUND = -6 /** No such attribute */ } atr_err; @@ -173,4 +173,4 @@ safe_atr_value(ATTR *atr) /** Null alias */ #define OPAE_NULL -3 -#endif /* __ATTRIB_H */ +#endif /* __ATTRIB_H */ diff --git a/hdrs/boolexp.h b/hdrs/boolexp.h index 8eb32de..e0ec958 100644 --- a/hdrs/boolexp.h +++ b/hdrs/boolexp.h @@ -22,7 +22,7 @@ extern int sizeof_boolexp(boolexp b); extern int eval_boolexp(dbref player, boolexp b, dbref target, unsigned char *switches); extern boolexp parse_boolexp(dbref player, const char *buf, lock_type ltype); extern boolexp parse_boolexp_d(dbref player, const char *buf, lock_type ltype, - int derefs); + int derefs); extern void free_boolexp(boolexp b); boolexp getboolexp(FILE * f, const char *ltype); void putboolexp(FILE * f, boolexp b); @@ -33,4 +33,4 @@ enum u_b_f { from unparse_boolexp.() For @decompile. */ }; extern char *unparse_boolexp(dbref player, boolexp b, enum u_b_f flag); -#endif /* BOOLEXP_H */ +#endif /* BOOLEXP_H */ diff --git a/hdrs/bufferq.h b/hdrs/bufferq.h index 7c1e6ce..ef77331 100644 --- a/hdrs/bufferq.h +++ b/hdrs/bufferq.h @@ -14,12 +14,12 @@ typedef struct bufferq BUFFERQ; struct bufferq { - char *buffer; /**< Pointer to start of buffer */ - char *buffer_end; /**< Pointer to insertion point in buffer */ - int buffer_size; /**< Size allocated to buffer, in bytes */ - int num_buffered; /**< Number of strings in the buffer */ - char last_string[BUFFER_LEN]; /**< Cache of last string inserted */ - char last_type; /**< Cache of type of last string inserted */ + char *buffer; /**< Pointer to start of buffer */ + char *buffer_end; /**< Pointer to insertion point in buffer */ + int buffer_size; /**< Size allocated to buffer, in bytes */ + int num_buffered; /**< Number of strings in the buffer */ + char last_string[BUFFER_LEN]; /**< Cache of last string inserted */ + char last_type; /**< Cache of type of last string inserted */ }; #define BufferQSize(b) ((b)->buffer_size) @@ -31,9 +31,9 @@ extern BUFFERQ *allocate_bufferq(int lines); extern BUFFERQ *reallocate_bufferq(BUFFERQ * bq, int lines); extern void free_bufferq(BUFFERQ * bq); extern void add_to_bufferq(BUFFERQ * bq, int type, dbref player, - const char *msg); + const char *msg); extern char *iter_bufferq(BUFFERQ * bq, char **p, dbref *player, int *type, - time_t * timestamp); + time_t * timestamp); extern int bufferq_lines(BUFFERQ * bq); extern int isempty_bufferq(BUFFERQ * bq); #endif diff --git a/hdrs/case.h b/hdrs/case.h index e995c2c..ae1912d 100644 --- a/hdrs/case.h +++ b/hdrs/case.h @@ -10,4 +10,4 @@ #define DOWNCASE(x) (isupper((unsigned char)x) ? tolower((unsigned char)x) : (x)) #define UPCASE(x) (islower((unsigned char)x) ? toupper((unsigned char)x) : (x)) #endif -#endif /* CASE_H */ +#endif /* CASE_H */ diff --git a/hdrs/chunk.h b/hdrs/chunk.h index 9eb38e8..e06ab04 100644 --- a/hdrs/chunk.h +++ b/hdrs/chunk.h @@ -11,10 +11,10 @@ typedef u_int_32 chunk_reference_t; #define NULL_CHUNK_REFERENCE 0 chunk_reference_t chunk_create(unsigned char const *data, u_int_16 len, - unsigned char derefs); + unsigned char derefs); void chunk_delete(chunk_reference_t reference); u_int_16 chunk_fetch(chunk_reference_t reference, - unsigned char *buffer, u_int_16 buffer_len); + unsigned char *buffer, u_int_16 buffer_len); u_int_16 chunk_len(chunk_reference_t reference); unsigned char chunk_derefs(chunk_reference_t reference); void chunk_migration(int count, chunk_reference_t ** references); @@ -31,4 +31,4 @@ void chunk_fork_parent(void); void chunk_fork_child(void); void chunk_fork_done(void); -#endif /* _CHUNK_H_ */ +#endif /* _CHUNK_H_ */ diff --git a/hdrs/command.h b/hdrs/command.h index 643a205..ff8e738 100644 --- a/hdrs/command.h +++ b/hdrs/command.h @@ -166,8 +166,8 @@ typedef struct switch_value SWITCH_VALUE; * associates switch names with switch numbers */ struct switch_value { - const char *name; /**< Name of the switch */ - int value; /**< Number of the switch */ + const char *name; /**< Name of the switch */ + int value; /**< Number of the switch */ }; typedef struct com_sort_struc COMSORTSTRUC; @@ -177,8 +177,8 @@ typedef struct com_sort_struc COMSORTSTRUC; * to command data. */ struct com_sort_struc { - struct com_sort_struc *next; /**< Pointer to next in list */ - COMMAND_INFO *cmd; /**< Command data */ + struct com_sort_struc *next; /**< Pointer to next in list */ + COMMAND_INFO *cmd; /**< Command data */ }; /** Permissions for commands. @@ -186,8 +186,8 @@ struct com_sort_struc { * (e.g. "player") with the appropriate bitmask */ struct command_perms_t { - const char *name; /**< Permission name */ - unsigned int type; /**< Bitmask for this permission */ + const char *name; /**< Permission name */ + unsigned int type; /**< Bitmask for this permission */ }; #define SWITCH_NONE 0 @@ -226,4 +226,4 @@ extern void do_command_delete(dbref player, char *name); extern void generic_command_failure(dbref player, dbref cause, char *string, int fromport); extern int command_lock(const char *command, const char *lock); -#endif /* __COMMAND_H */ +#endif /* __COMMAND_H */ diff --git a/hdrs/compile.h b/hdrs/compile.h index b7f4b59..ac7f435 100644 --- a/hdrs/compile.h +++ b/hdrs/compile.h @@ -69,4 +69,4 @@ void NORETURN WIN32_CDECL Win32_Exit(int exit_code); #endif -#endif /* __COMPILE_H */ +#endif /* __COMPILE_H */ diff --git a/hdrs/conf.h b/hdrs/conf.h index 8408190..cfe050d 100644 --- a/hdrs/conf.h +++ b/hdrs/conf.h @@ -88,9 +88,9 @@ */ #define SPILLOVER_THRESHOLD 0 /* #define SPILLOVER_THRESHOLD (MAX_OUTPUT / 2) */ -#define COMMAND_TIME_MSEC 1000 /* time slice length in milliseconds */ -#define COMMAND_BURST_SIZE 100 /* commands allowed per user in a burst */ -#define COMMANDS_PER_TIME 1 /* commands per time slice after burst */ +#define COMMAND_TIME_MSEC 1000 /* time slice length in milliseconds */ +#define COMMAND_BURST_SIZE 100 /* commands allowed per user in a burst */ +#define COMMANDS_PER_TIME 1 /* commands per time slice after burst */ /* Set this somewhere near the recursion limit */ diff --git a/hdrs/csrimalloc.h b/hdrs/csrimalloc.h index 19be689..36b9544 100644 --- a/hdrs/csrimalloc.h +++ b/hdrs/csrimalloc.h @@ -21,25 +21,23 @@ #ifdef CSRI_TRACE /* Tracing malloc definitions - helps find leaks */ -extern univptr_t trace__malloc -_((size_t nbytes, const char *fname, int linenum)); -extern univptr_t trace__calloc -_((size_t nelem, size_t elsize, const char *fname, int linenum)); -extern univptr_t trace__realloc -_((univptr_t cp, size_t nbytes, const char *fname, int linenum)); -extern univptr_t trace__valloc _((size_t size, const char *fname, int linenum)); -extern univptr_t trace__memalign -_((size_t alignment, size_t size, const char *fname, int linenum)); -extern univptr_t trace__emalloc -_((size_t nbytes, const char *fname, int linenum)); -extern univptr_t trace__ecalloc -_((size_t nelem, size_t sz, const char *fname, int linenum)); -extern univptr_t trace__erealloc -_((univptr_t ptr, size_t nbytes, const char *fname, int linenum)); -extern char *trace__strdup _((const char *s, const char *fname, int linenum)); -extern char *trace__strsave _((const char *s, const char *fname, int linenum)); -extern void trace__free _((univptr_t cp, const char *fname, int linenum)); -extern void trace__cfree _((univptr_t cp, const char *fname, int linenum)); +univptr_t trace__malloc(size_t nbytes, const char *fname, int linenum); +univptr_t trace__calloc + (size_t nelem, size_t elsize, const char *fname, int linenum); +univptr_t trace__realloc + (univptr_t cp, size_t nbytes, const char *fname, int linenum); +univptr_t trace__valloc(size_t size, const char *fname, int linenum); +univptr_t trace__memalign + (size_t alignment, size_t size, const char *fname, int linenum); +univptr_t trace__emalloc(size_t nbytes, const char *fname, int linenum); +univptr_t trace__ecalloc + (size_t nelem, size_t sz, const char *fname, int linenum); +univptr_t trace__erealloc + (univptr_t ptr, size_t nbytes, const char *fname, int linenum); +char *trace__strdup(const char *s, const char *fname, int linenum); +char *trace__strsave(const char *s, const char *fname, int linenum); +void trace__free(univptr_t cp, const char *fname, int linenum); +void trace__cfree(univptr_t cp, const char *fname, int linenum); #define malloc(x) trace__malloc((x), __FILE__, __LINE__) #define calloc(x, n) trace__calloc((x), (n), __FILE__, __LINE__) @@ -55,34 +53,34 @@ extern void trace__cfree _((univptr_t cp, const char *fname, int linenum)); #define cfree(p) trace__free((p), __FILE__, __LINE__) #define free(p) trace__free((p), __FILE__, __LINE__) -#else /* CSRI_TRACE */ +#else /* CSRI_TRACE */ -extern univptr_t malloc _((size_t nbytes)); -extern univptr_t calloc _((size_t nelem, size_t elsize)); -extern univptr_t realloc _((univptr_t cp, size_t nbytes)); -extern univptr_t valloc _((size_t size)); -extern univptr_t memalign _((size_t alignment, size_t size)); -extern univptr_t emalloc _((size_t nbytes)); -extern univptr_t ecalloc _((size_t nelem, size_t sz)); -extern univptr_t erealloc _((univptr_t ptr, size_t nbytes)); -extern char *strdup _((const char *s)); -extern char *strsave _((const char *s)); -extern Free_t free _((univptr_t cp)); -extern Free_t cfree _((univptr_t cp)); +univptr_t malloc(size_t nbytes); +univptr_t calloc(size_t nelem, size_t elsize); +univptr_t realloc(univptr_t cp, size_t nbytes); +univptr_t valloc(size_t size); +univptr_t memalign(size_t alignment, size_t size); +univptr_t emalloc(size_t nbytes); +univptr_t ecalloc(size_t nelem, size_t sz); +univptr_t erealloc(univptr_t ptr, size_t nbytes); +char *strdup(const char *s); +char *strsave(const char *s); +void free(univptr_t cp); +void cfree(univptr_t cp); -#endif /* CSRI_TRACE */ +#endif /* CSRI_TRACE */ -extern void mal_debug _((int level)); -extern void mal_dumpleaktrace _((FILE * fp)); -extern void mal_heapdump _((FILE * fp)); -extern void mal_leaktrace _((int value)); -extern void mal_sbrkset _((int n)); -extern void mal_slopset _((int n)); -extern void mal_statsdump _((FILE * fp)); -extern void mal_setstatsfile _((FILE * fp)); -extern void mal_trace _((int value)); -extern int mal_verify _((int fullcheck)); -extern void mal_mmap _((char *fname)); +void mal_debug(int level); +void mal_dumpleaktrace(FILE * fp); +void mal_heapdump(FILE * fp); +void mal_leaktrace(int value); +void mal_sbrkset(int n); +void mal_slopset(int n); +void mal_statsdump(FILE * fp); +void mal_setstatsfile(FILE * fp); +void mal_trace(int value); +int mal_verify(int fullcheck); +void mal_mmap(char *fname); /* @@ -93,10 +91,10 @@ extern void mal_mmap _((char *fname)); #ifndef alloca #define alloca(n) __builtin_alloca(n) #endif -#endif /* __GNUC__ */ +#endif /* __GNUC__ */ #ifdef sparc #define alloca(n) __builtin_alloca(n) -#endif /* sparc */ +#endif /* sparc */ -#endif /* __CSRIMALLOC_H__ */ /* Do not add anything after this line */ +#endif /* __CSRIMALLOC_H__ */ /* Do not add anything after this line */ diff --git a/hdrs/dbdefs.h b/hdrs/dbdefs.h index cfd6a94..523c3ca 100644 --- a/hdrs/dbdefs.h +++ b/hdrs/dbdefs.h @@ -17,7 +17,7 @@ extern int depth; -extern dbref first_free; /* pointer to free list */ +extern dbref first_free; /* pointer to free list */ /*------------------------------------------------------------------------- * Database access macros @@ -122,24 +122,24 @@ extern dbref first_free; /* pointer to free list */ #define NoLeave(x) (IS(x, TYPE_THING, "NOLEAVE")) #define ThingListen(x) (IS(x, TYPE_THING, "MONITOR")) #define ThingInhearit(x) \ - (IS(x, TYPE_THING, "LISTEN_PARENT")) /* 0x80 */ + (IS(x, TYPE_THING, "LISTEN_PARENT")) /* 0x80 */ #define ThingZTel(x) (IS(x, TYPE_THING, "Z_TEL")) /******* Room toggles */ -#define Floating(x) (IS(x, TYPE_ROOM, "FLOATING")) /* 0x8 */ -#define Abode(x) (IS(x, TYPE_ROOM, "ABODE")) /* 0x10 */ -#define JumpOk(x) (IS(x, TYPE_ROOM, "JUMP_OK")) /* 0x20 */ -#define NoTel(x) (IS(x, TYPE_ROOM, "NO_TEL")) /* 0x40 */ -#define RoomListen(x) (IS(x, TYPE_ROOM, "LISTENER")) /* 0x100 */ -#define RoomZTel(x) (IS(x, TYPE_ROOM, "Z_TEL")) /* 0x200 */ -#define RoomInhearit(x) (IS(x, TYPE_ROOM, "LISTEN_PARENT")) /* 0x400 */ +#define Floating(x) (IS(x, TYPE_ROOM, "FLOATING")) /* 0x8 */ +#define Abode(x) (IS(x, TYPE_ROOM, "ABODE")) /* 0x10 */ +#define JumpOk(x) (IS(x, TYPE_ROOM, "JUMP_OK")) /* 0x20 */ +#define NoTel(x) (IS(x, TYPE_ROOM, "NO_TEL")) /* 0x40 */ +#define RoomListen(x) (IS(x, TYPE_ROOM, "LISTENER")) /* 0x100 */ +#define RoomZTel(x) (IS(x, TYPE_ROOM, "Z_TEL")) /* 0x200 */ +#define RoomInhearit(x) (IS(x, TYPE_ROOM, "LISTEN_PARENT")) /* 0x400 */ -#define Uninspected(x) (IS(x, TYPE_ROOM, "UNINSPECTED")) /* 0x1000 */ +#define Uninspected(x) (IS(x, TYPE_ROOM, "UNINSPECTED")) /* 0x1000 */ #define ZTel(x) (ThingZTel(x) || RoomZTel(x)) /******* Exit toggles */ -#define Cloudy(x) (IS(x, TYPE_EXIT, "CLOUDY")) /* 0x8 */ +#define Cloudy(x) (IS(x, TYPE_EXIT, "CLOUDY")) /* 0x8 */ /* Flags anything can have */ @@ -330,15 +330,15 @@ extern void convert_object_powers(dbref, int); /* the code is in division.c.. * stored in a doubly-linked list sorted by message recipient. */ struct mail { - struct mail *next; /**< Pointer to next message */ - struct mail *prev; /**< Pointer to previous message */ - dbref to; /**< Recipient dbref */ - dbref from; /**< Sender's dbref */ - time_t from_ctime; /**< Sender's creation time */ - chunk_reference_t msgid; /**< Message text, compressed */ - time_t time; /**< Message date/time */ - unsigned char *subject; /**< Message subject, compressed */ - int read; /**< Bitflags of message status */ + struct mail *next; /**< Pointer to next message */ + struct mail *prev; /**< Pointer to previous message */ + dbref to; /**< Recipient dbref */ + dbref from; /**< Sender's dbref */ + time_t from_ctime; /**< Sender's creation time */ + chunk_reference_t msgid; /**< Message text, compressed */ + time_t time; /**< Message date/time */ + unsigned char *subject; /**< Message subject, compressed */ + int read; /**< Bitflags of message status */ }; typedef struct mail MAIL; @@ -350,4 +350,4 @@ extern const char *EOD; if (SW_ISSET(sw, SWITCH_SPOOF) && (controls(player, cause) || Can_Nspemit(player))) \ player = cause; -#endif /* __DBDEFS_H */ +#endif /* __DBDEFS_H */ diff --git a/hdrs/dbio.h b/hdrs/dbio.h index b7b3182..380daef 100644 --- a/hdrs/dbio.h +++ b/hdrs/dbio.h @@ -20,7 +20,7 @@ extern jmp_buf db_err; extern void putref(FILE * f, long int ref); extern void putstring(FILE * f, const char *s); extern void db_write_labeled_string(FILE * f, char const *label, - char const *value); + char const *value); extern void db_write_labeled_number(FILE * f, char const *label, int value); extern void db_write_labeled_dbref(FILE * f, char const *label, dbref value); extern void db_write_flag_db(FILE *); @@ -32,7 +32,7 @@ extern int db_paranoid_write(FILE * f, int flag); extern const char *getstring_noalloc(FILE * f); extern long getref(FILE * f); extern void db_read_this_labeled_string(FILE * f, const char *label, - char **val); + char **val); extern void db_read_labeled_string(FILE * f, char **label, char **val); extern void db_read_this_labeled_number(FILE * f, const char *label, int *val); extern void db_read_labeled_number(FILE * f, char **label, int *val); diff --git a/hdrs/extchat.h b/hdrs/extchat.h index 6e09fe6..462131e 100644 --- a/hdrs/extchat.h +++ b/hdrs/extchat.h @@ -53,22 +53,22 @@ * Each chat channel maintains a linked list of users. */ struct chanuser { - dbref who; /**< Dbref of joined object */ - long int type; /**< Bitflags for this user */ - char title[CU_TITLE_LEN]; /**< User's channel title */ - struct chanuser *next; /**< Pointer to next user in list */ + dbref who; /**< Dbref of joined object */ + long int type; /**< Bitflags for this user */ + char title[CU_TITLE_LEN]; /**< User's channel title */ + struct chanuser *next; /**< Pointer to next user in list */ }; /* Flags and macros for channel users */ -#define CU_QUIET 0x1 /* Do not hear connection messages */ -#define CU_HIDE 0x2 /* Do not appear on the user list */ -#define CU_GAG 0x4 /* Do not hear any messages */ +#define CU_QUIET 0x1 /* Do not hear connection messages */ +#define CU_HIDE 0x2 /* Do not appear on the user list */ +#define CU_GAG 0x4 /* Do not hear any messages */ #define CU_DEFAULT_FLAGS 0x0 /* channel_broadcast flags */ -#define CB_CHECKQUIET 0x1 /* Check for quiet flag on recipients */ -#define CB_NOSPOOF 0x2 /* Use nospoof emits */ -#define CB_PRESENCE 0x4 /* This is a presence message, not sound */ +#define CB_CHECKQUIET 0x1 /* Check for quiet flag on recipients */ +#define CB_NOSPOOF 0x2 /* Use nospoof emits */ +#define CB_PRESENCE 0x4 /* This is a presence message, not sound */ #define CUdbref(u) ((u)->who) #define CUtype(u) ((u)->type) @@ -110,8 +110,8 @@ struct channel { * with each object */ struct chanlist { - CHAN *chan; /**< Channel data */ - struct chanlist *next; /**< Next channel in list */ + CHAN *chan; /**< Channel data */ + struct chanlist *next; /**< Next channel in list */ }; #define Chanlist(x) ((struct chanlist *)get_objdata(x, "CHANNELS")) @@ -236,7 +236,7 @@ extern void do_chan_what(dbref player, const char *partname); extern void do_chan_desc(dbref player, const char *name, const char *title); extern void do_chan_title(dbref player, const char *name, const char *title); extern void do_chan_recall(dbref player, const char *name, char *lineinfo[], - int quiet); + int quiet); extern void do_chan_buffer(dbref player, const char *name, const char *lines); extern void init_chat(void); extern void do_channel @@ -246,7 +246,7 @@ extern void do_chan_admin (dbref player, char *name, const char *perms, int flag); extern enum cmatch_type find_channel(const char *p, CHAN **chan, dbref player); extern enum cmatch_type find_channel_partial(const char *p, CHAN **chan, - dbref player); + dbref player); extern void do_channel_list(dbref player, const char *partname); extern int do_chat_by_name (dbref player, const char *name, const char *msg, int source); diff --git a/hdrs/externs.h b/hdrs/externs.h index a05905c..6d8681f 100644 --- a/hdrs/externs.h +++ b/hdrs/externs.h @@ -85,7 +85,7 @@ extern char *scan_list(dbref player, char *command); #ifdef WIN32 /* From timer.c */ extern void init_timer(void); -#endif /* WIN32 */ +#endif /* WIN32 */ /* From attrib.c */ extern dbref atr_on_obj; @@ -239,7 +239,7 @@ extern void div_parse_que(dbref division, const char *command, dbref called_divi extern int queue_attribute_base (dbref executor, const char *atrname, dbref enactor, int noparent); extern ATTR *queue_attribute_getatr(dbref executor, const char *atrname, - int noparent); + int noparent); extern int queue_attribute_useatr(dbref executor, ATTR *a, dbref enactor); /** Queue the code in an attribute, including parent objects */ @@ -247,7 +247,7 @@ extern int queue_attribute_useatr(dbref executor, ATTR *a, dbref enactor); /** Queue the code in an attribute, excluding parent objects */ #define queue_attribute_noparent(a,b,c) queue_attribute_base(a,b,c,1) extern void dequeue_semaphores(dbref thing, char const *aname, int count, - int all, int drain); + int all, int drain); extern void shutdown_queues(void); extern void do_hourly(void); @@ -263,10 +263,10 @@ extern const char *get_namedreg(HASHTAB *, const char *); extern dbref do_dig(dbref player, const char *name, char **argv, int tport); extern dbref do_create(dbref player, char *name, int cost); extern dbref do_real_open(dbref player, const char *direction, - const char *linkto, dbref pseudo); + const char *linkto, dbref pseudo); extern void do_open(dbref player, const char *direction, char **links); extern void do_link(dbref player, const char *name, const char *room_name, - int preserve); + int preserve); extern void do_unlink(dbref player, const char *name); extern dbref do_clone(dbref player, char *name, char *newname, int preserve); extern void copy_zone(dbref executor, dbref zmo); @@ -329,9 +329,9 @@ extern dbref lookup_player(const char *name); extern dbref lookup_player_name(const char *name); /* from player.c */ extern dbref create_player(const char *name, const char *password, - const char *host, const char *ip); + const char *host, const char *ip); extern dbref connect_player(const char *name, const char *password, - const char *host, const char *ip, char *errbuf); + const char *host, const char *ip, char *errbuf); extern void check_last(dbref player, const char *host, const char *ip); extern void check_lastfailed(dbref player, const char *host); @@ -339,6 +339,7 @@ extern void check_lastfailed(dbref player, const char *host); extern int is_number(const char *str); extern int is_strict_number(const char *str); extern int is_strict_integer(const char *str); +int is_good_number(double); /* From plyrlist.c */ void clear_players(void); @@ -346,7 +347,7 @@ void add_player(dbref player); void add_player_alias(dbref player, const char *alias); void delete_player(dbref player, const char *alias); void reset_player_list(dbref player, const char *oldname, const char *oldalias, - const char *name, const char *alias); + const char *name, const char *alias); /* From predicat.c */ extern int pay_quota(dbref, int); @@ -396,14 +397,14 @@ dbref first_visible(dbref player, dbref thing); /* From set.c */ extern void chown_object(dbref player, dbref thing, dbref newowner, - int preserve); + int preserve); /* From speech.c */ const char *spname(dbref thing); extern void notify_except(dbref first, dbref exception, const char *msg, - int flags); + int flags); extern void notify_except2(dbref first, dbref exc1, dbref exc2, - const char *msg, int flags); + const char *msg, int flags); /* Return thing/PREFIX + msg */ extern void make_prefixstr(dbref thing, const char *msg, char *tbuf1); extern int filter_found(dbref thing, const char *msg, int flag); @@ -442,7 +443,7 @@ extern void s_Pennies(dbref thing, int amount); extern char *split_token(char **sp, char sep); extern char *chopstr(const char *str, size_t lim); extern int string_prefix(const char *RESTRICT string, - const char *RESTRICT prefix); + const char *RESTRICT prefix); extern const char *string_match(const char *src, const char *sub); extern char *strupper(const char *s); extern char *strlower(const char *s); @@ -472,9 +473,9 @@ strdup(const char *s) /** A string, with ansi attributes broken out from the text */ typedef struct { - char text[BUFFER_LEN]; /**< Text of the string */ - char *codes[BUFFER_LEN]; /**< Ansi codes associated with each char of text */ - size_t len; /**< Length of text */ + char text[BUFFER_LEN]; /**< Text of the string */ + char *codes[BUFFER_LEN]; /**< Ansi codes associated with each char of text */ + size_t len; /**< Length of text */ } ansi_string; @@ -539,24 +540,24 @@ extern int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *bu (const char *RESTRICT old, const char *RESTRICT newbit, const char *RESTRICT string) __attribute_malloc__; extern char *replace_string2(const char *old[2], const char *newbits[2], - const char *RESTRICT string) + const char *RESTRICT string) __attribute_malloc__; - extern const char *standard_tokens[2]; /* ## and #@ */ + extern const char *standard_tokens[2]; /* ## and #@ */ extern char *trim_space_sep(char *str, char sep); extern int do_wordcount(char *str, char sep); extern char *remove_word(char *list, char *word, char sep); extern char *next_in_list(const char **head); extern void safe_itemizer(int cur_num, int done, const char *delim, - const char *conjoin, const char *space, - char *buff, char **bp); + const char *conjoin, const char *space, + char *buff, char **bp); extern char *show_time(time_t t, int utc); extern char *show_tm(struct tm *t); /** This structure associates html entities and base ascii representations */ typedef struct { - const char *base; /**< Base ascii representation */ - const char *entity; /**< HTML entity */ + const char *base; /**< Base ascii representation */ + const char *entity; /**< HTML entity */ } accent_info; extern accent_info accent_table[]; @@ -578,9 +579,9 @@ extern int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *bu /* From utils.c */ extern void parse_attrib(dbref player, char *str, dbref *thing, - ATTR **attrib); + ATTR **attrib); extern void parse_anon_attrib(dbref player, char *str, dbref *thing, - ATTR **attrib); + ATTR **attrib); extern void free_anon_attrib(ATTR *attrib); typedef struct _ufun_attrib { dbref thing; @@ -589,16 +590,16 @@ extern int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *bu char *errmess; } ufun_attrib; extern int fetch_ufun_attrib(char *attrname, dbref executor, - ufun_attrib * ufun, int accept_lambda); + ufun_attrib * ufun, int accept_lambda); extern int call_ufun(ufun_attrib * ufun, char **wenv_args, int wenv_argc, - char *ret, dbref executor, dbref enactor, - PE_Info * pe_info); + char *ret, dbref executor, dbref enactor, + PE_Info * pe_info); extern int member(dbref thing, dbref list); extern int recursive_member(dbref disallow, dbref from, int count); extern dbref remove_first(dbref first, dbref what); extern dbref reverse(dbref list); extern Malloc_t mush_malloc(size_t size, - const char *check) __attribute_malloc__; + const char *check) __attribute_malloc__; extern void mush_free(Malloc_t RESTRICT ptr, const char *RESTRICT check); extern long get_random_long(long low, long high); extern char *fullalias(dbref it); @@ -620,17 +621,17 @@ extern int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *bu /* From wild.c */ extern int local_wild_match_case(const char *RESTRICT s, - const char *RESTRICT d, int cs); + const char *RESTRICT d, int cs); extern int wildcard(const char *s); extern int quick_wild_new(const char *RESTRICT tstr, - const char *RESTRICT dstr, int cs); + const char *RESTRICT dstr, int cs); extern int regexp_match_case_r(const char *RESTRICT s, - const char *RESTRICT d, int cs, char **, int, - char *, int); + const char *RESTRICT d, int cs, char **, int, + char *, int); extern int quick_regexp_match(const char *RESTRICT s, - const char *RESTRICT d, int cs); + const char *RESTRICT d, int cs); extern int wild_match_case_r(const char *RESTRICT s, const char *RESTRICT d, - int cs, char **, int, char *, int); + int cs, char **, int, char *, int); extern int quick_wild(const char *RESTRICT tsr, const char *RESTRICT dstr); extern int atr_wild(const char *RESTRICT tstr, const char *RESTRICT dstr); /** Default (case-insensitive) local wildcard match */ @@ -714,7 +715,7 @@ extern int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *bu /* funlist.c */ void do_gensort(dbref player, char *keys[], char *strs[], int n, - char *sort_type); + char *sort_type); /* sig.c */ /** Type definition for signal handlers */ diff --git a/hdrs/extmail.h b/hdrs/extmail.h index 482d56e..1965fe9 100644 --- a/hdrs/extmail.h +++ b/hdrs/extmail.h @@ -45,12 +45,12 @@ typedef unsigned int mail_flag; * messages. Messages can be selected in several ways. */ struct mail_selector { - int low; /**< Minimum message number */ - int high; /**< Maximum message number */ - mail_flag flags; /**< Message flags */ - dbref player; /**< Message sender's dbref */ - int days; /**< Target message age in days */ - int day_comp; /**< Direction of comparison to target age */ + int low; /**< Minimum message number */ + int high; /**< Maximum message number */ + mail_flag flags; /**< Message flags */ + dbref player; /**< Message sender's dbref */ + int days; /**< Target message age in days */ + int day_comp; /**< Direction of comparison to target age */ }; typedef int folder_array[MAX_FOLDERS + 1]; @@ -105,4 +105,4 @@ extern struct mail *desc_mail(dbref player); extern void desc_mail_set(dbref player, struct mail *mp); extern void desc_mail_clear(void); -#endif /* _EXTMAIL_H */ +#endif /* _EXTMAIL_H */ diff --git a/hdrs/flags.h b/hdrs/flags.h index 8d4f606..10d470f 100644 --- a/hdrs/flags.h +++ b/hdrs/flags.h @@ -16,12 +16,12 @@ typedef struct flag_info FLAG; * available for setting on objects in the game. */ struct flag_info { - const char *name; /**< Name of the flag */ - char letter; /**< Flag character, which may be nul */ - int type; /**< Bitflags of object types this flag applies to */ - int bitpos; /**< Bit position assigned to this flag for now */ - int perms; /**< Bitflags of who can set this flag */ - int negate_perms; /**< Bitflags of who can clear this flag */ + const char *name; /**< Name of the flag */ + char letter; /**< Flag character, which may be nul */ + int type; /**< Bitflags of object types this flag applies to */ + int bitpos; /**< Bit position assigned to this flag for now */ + int perms; /**< Bitflags of who can set this flag */ + int negate_perms; /**< Bitflags of who can clear this flag */ }; typedef struct flag_alias FLAG_ALIAS; @@ -30,8 +30,8 @@ typedef struct flag_alias FLAG_ALIAS; * A simple structure that associates an alias with a canonical flag name. */ struct flag_alias { - const char *alias; /**< The alias name */ - const char *realname; /**< The real name of the flag */ + const char *alias; /**< The alias name */ + const char *realname; /**< The real name of the flag */ }; typedef struct flagspace FLAGSPACE; @@ -142,9 +142,19 @@ extern void decompile_flags(dbref player, dbref thing, const char *name); #define F_MDARK 0x1000 /* admin/God can see this flag */ #define F_ODARK 0x2000 /* owner/admin/God can see this flag */ #define F_DISABLED 0x4000 /* flag can't be used */ -/* RESERVED 0x8000 */ +#define F_LOG 0x8000 #define F_SELF 0x10000 /* can set on self, regardless of the above */ +/* Flags can be in the flaglist multiple times, thanks to aliases. Keep + * a reference count of how many times, and free memory when it goes to 0. */ +#define F_REF_MASK 0xFF000000 /**< Mask to get the reference count */ +#define F_REF_NOT 0x00FFFFFF /**< Everything but */ +#define FLAG_REF(r) (((r) & F_REF_MASK) >> 30) +#define ZERO_FLAG_REF(r) ((r) & F_REF_NOT) +#define INCR_FLAG_REF(r) (ZERO_FLAG_REF((r)) | (((r) & F_REF_MASK) + (1 << 30))) +#define DECR_FLAG_REF(r) (ZERO_FLAG_REF((r)) | (((r) & F_REF_MASK) - (1 << 30))) + + /* we don't use these anymore.. but kept aroudn for DB conversion */ diff --git a/hdrs/function.h b/hdrs/function.h index a16d026..34adc77 100644 --- a/hdrs/function.h +++ b/hdrs/function.h @@ -45,24 +45,24 @@ typedef struct fun FUN; #endif typedef void (*function_func) (FUN *, char *, char **, int, char *[], int[], - dbref, dbref, dbref, const char *, PE_Info *); + dbref, dbref, dbref, const char *, PE_Info *); /** A calling pointer to a function. * This union holds either a pointer to a function's code or * the offset of the function in the user-defined function table. */ union fun_call { - function_func fun; /**< Pointer to compiled function code */ - size_t offset; /**< Offset into user-defined function table */ + function_func fun; /**< Pointer to compiled function code */ + size_t offset; /**< Offset into user-defined function table */ }; /** A function. * This structure represents a mushcode function. */ struct fun { - const char *name; /**< Function name */ - union fun_call where; /**< Where to find the function to call it */ - int minargs; /**< Minimum arguments required, or 0 */ + const char *name; /**< Function name */ + union fun_call where; /**< Where to find the function to call it */ + int minargs; /**< Minimum arguments required, or 0 */ /** Maximum arguments allowed. * Maximum arguments allowed. If there is no limit, this is INT_MAX. * If this is negatve, the final argument to the function can contain @@ -80,26 +80,26 @@ typedef struct userfn_entry USERFN_ENTRY; * This structure represents an entry in the user-defined function table. */ struct userfn_entry { - char *fn; /**< Name of the function */ - dbref thing; /**< Dbref of object where the function is defined */ - char *name; /**< Name of attribute where the function is defined */ - unsigned int flags; /**< Bitflags of function */ + char *fn; /**< Name of the function */ + dbref thing; /**< Dbref of object where the function is defined */ + char *name; /**< Name of attribute where the function is defined */ + unsigned int flags; /**< Bitflags of function */ }; extern USERFN_ENTRY *userfn_tab; extern void do_userfn(char *buff, char **bp, - dbref obj, ATTR *attrib, - int nargs, char **args, - dbref executor, dbref caller, dbref enactor, - PE_Info * pe_info); + dbref obj, ATTR *attrib, + int nargs, char **args, + dbref executor, dbref caller, dbref enactor, + PE_Info * pe_info); extern FUN *func_hash_lookup(const char *name); extern int check_func(dbref player, FUN *fp); extern int restrict_function(const char *name, const char *restrict); extern int alias_function(const char *function, const char *alias); extern void do_function_restrict(dbref player, const char *name, - const char *restrict); + const char *restrict); extern void do_function_restore(dbref player, const char *name); extern void do_list_functions(dbref player, int lc); extern char *list_functions(void); @@ -115,6 +115,6 @@ extern void function_init_postconfig(void); int arglen[], dbref executor, dbref caller, dbref enactor, \ char const *called_as, PE_Info *pe_info) extern void function_add(const char *name, function_func fun, int minargs, - int maxargs, int ftype); + int maxargs, int ftype); #endif diff --git a/hdrs/game.h b/hdrs/game.h index abf45a3..70c9087 100644 --- a/hdrs/game.h +++ b/hdrs/game.h @@ -13,13 +13,13 @@ #define CHECK_GLOBAL 0x200 /* hash table stuff */ -extern void init_func_hashtab(void); /* eval.c */ -extern void init_math_hashtab(void); /* funmath.c */ -extern void init_aname_table(void); /* atr_tab.c */ -extern void init_flagspaces(void); /* flags.c */ -extern void init_flag_table(const char *ns); /* flags.c */ -extern void init_tag_hashtab(void); /* funstr.c */ -extern void init_pronouns(void); /* funstr.c */ +extern void init_func_hashtab(void); /* eval.c */ +extern void init_math_hashtab(void); /* funmath.c */ +extern void init_aname_table(void); /* atr_tab.c */ +extern void init_flagspaces(void); /* flags.c */ +extern void init_flag_table(const char *ns); /* flags.c */ +extern void init_tag_hashtab(void); /* funstr.c */ +extern void init_pronouns(void); /* funstr.c */ /* From bsd.c */ extern void fcache_init(void); @@ -46,7 +46,7 @@ extern int do_signal_qid(dbref signalby, int qid, enum qid_flags qid_flags, int /* From command.c */ enum hook_type { HOOK_BEFORE, HOOK_AFTER, HOOK_IGNORE, HOOK_OVERRIDE }; extern void do_hook(dbref player, char *command, char *obj, char *attrname, - enum hook_type flag); + enum hook_type flag); extern void do_hook_list(dbref player, char *command); @@ -75,10 +75,10 @@ extern void do_score(dbref player); extern void do_sweep(dbref player, const char *arg1); enum ent_type { ENT_EXITS, ENT_THINGS, ENT_PLAYERS, ENT_ROOMS, ENT_ALL }; extern void do_entrances(dbref player, const char *where, char **argv, - enum ent_type val); + enum ent_type val); enum dec_type { DEC_NORMAL, DEC_DB, DEC_FLAG, DEC_ATTR }; extern void do_decompile(dbref player, const char *name, const char *prefix, - enum dec_type dbflag, int skipdef); + enum dec_type dbflag, int skipdef); /* From move.c */ extern void do_get(dbref player, const char *what); @@ -90,7 +90,7 @@ extern void do_firstexit(dbref player, const char *what); /* From player.c */ extern void do_password(dbref player, dbref cause, - const char *old, const char *newobj); + const char *old, const char *newobj); /* From predicat.c */ extern void do_switch @@ -130,10 +130,10 @@ extern void do_whisper_list extern void do_pose(dbref player, const char *tbuf1, int space); enum wall_type { WALL_ALL }; extern void do_wall(dbref player, const char *message, enum wall_type target, - int emit); + int emit); extern void do_page(dbref player, const char *arg1, const char *arg2, - dbref cause, int noeval, int multipage, int override, - int has_eq); + dbref cause, int noeval, int multipage, int override, + int has_eq); extern void do_page_port(dbref player, const char *arg1, const char *arg2); extern void do_think(dbref player, const char *message); #define PEMIT_SILENT 0x1 @@ -143,13 +143,13 @@ extern void do_emit(dbref player, const char *tbuf1, int flags); extern void do_pemit (dbref player, const char *arg1, const char *arg2, int flags); extern void do_pemit_list(dbref player, char *list, const char *message, - int flags); + int flags); extern void do_remit(dbref player, char *arg1, const char *arg2, int flags); extern void do_lemit(dbref player, const char *tbuf1, int flags); extern void do_zemit(dbref player, const char *arg1, const char *arg2, - int flags); + int flags); extern void do_oemit_list(dbref player, char *arg1, const char *arg2, - int flags); + int flags); extern void do_teach(dbref player, dbref cause, const char *tbuf1); /* From wiz.c */ @@ -195,4 +195,4 @@ extern void signal_cpu_limit(int signo); /* From version.c */ extern void do_version(dbref player); -#endif /* __GAME_H */ +#endif /* __GAME_H */ diff --git a/hdrs/getpgsiz.h b/hdrs/getpgsiz.h index a7cbc14..e821cf6 100644 --- a/hdrs/getpgsiz.h +++ b/hdrs/getpgsiz.h @@ -21,20 +21,20 @@ #define getpagesize() NBPG * CLSIZE #ifndef CLSIZE #define CLSIZE 1 -#endif /* no CLSIZE */ -#else /* no NBPG */ +#endif /* no CLSIZE */ +#else /* no NBPG */ #ifdef NBPC #define getpagesize() NBPC -#else /* no NBPC either? Bummer */ +#else /* no NBPC either? Bummer */ #ifdef PAGESIZE #define getpagesize() PAGESIZE -#else /* Sigh. Time for a total guess. */ +#else /* Sigh. Time for a total guess. */ #define getpagesize() 1024 -#endif /* no PAGESIZE */ -#endif /* no NBPC */ -#endif /* no NBPG */ -#endif /* no EXEC_PAGESIZE */ -#endif /* no PAGESIZE_VALUE */ -#endif /* not HAS_GETPAGESIZE */ +#endif /* no PAGESIZE */ +#endif /* no NBPC */ +#endif /* no NBPG */ +#endif /* no EXEC_PAGESIZE */ +#endif /* no PAGESIZE_VALUE */ +#endif /* not HAS_GETPAGESIZE */ -#endif /* __GETPGSIZ_H */ +#endif /* __GETPGSIZ_H */ diff --git a/hdrs/help.h b/hdrs/help.h index 06478b8..69cd86b 100644 --- a/hdrs/help.h +++ b/hdrs/help.h @@ -10,8 +10,8 @@ * */ typedef struct { - long pos; /**< Position of topic in help file, in bytes */ - char topic[TOPIC_NAME_LEN + 1]; /**< name of topic of help entry */ + long pos; /**< Position of topic in help file, in bytes */ + char topic[TOPIC_NAME_LEN + 1]; /**< name of topic of help entry */ } help_indx; /** A help command. @@ -19,11 +19,11 @@ typedef struct { * file and an in-memory index. */ typedef struct { - char *command; /**< The name of the help command */ - char *file; /**< The file of help text */ - int admin; /**< Is this an admin-only help command? */ - help_indx *indx; /**< An array of help index entries */ - size_t entries; /**< Number of entries in the help file */ + char *command; /**< The name of the help command */ + char *file; /**< The file of help text */ + int admin; /**< Is this an admin-only help command? */ + help_indx *indx; /**< An array of help index entries */ + size_t entries; /**< Number of entries in the help file */ } help_file; @@ -31,4 +31,4 @@ extern void init_help_files(void); extern void add_help_file (const char *command_name, const char *filename, int admin); extern void help_reindex(dbref player); -#endif /* __HELP_H */ +#endif /* __HELP_H */ diff --git a/hdrs/htab.h b/hdrs/htab.h index a9b19be..2fba985 100644 --- a/hdrs/htab.h +++ b/hdrs/htab.h @@ -24,14 +24,14 @@ typedef struct hashtable HASHTAB; /** A hash table. */ struct hashtable { - int hashsize; /**< Size of hash table */ - int mask; /**< Mask for entries in table */ - int entries; /**< Number of entries stored */ - HASHENT **buckets; /**< Pointer to pointer to entries */ - int last_hval; /**< State for hashfirst & hashnext. */ - HASHENT *last_entry; /**< State for hashfirst & hashnext. */ - int entry_size; /**< Size of each entry */ - void (*free_data) (void *); /**< Function to call on data when deleting + int hashsize; /**< Size of hash table */ + int mask; /**< Mask for entries in table */ + int entries; /**< Number of entries stored */ + HASHENT **buckets; /**< Pointer to pointer to entries */ + int last_hval; /**< State for hashfirst & hashnext. */ + HASHENT *last_entry; /**< State for hashfirst & hashnext. */ + int entry_size; /**< Size of each entry */ + void (*free_data) (void *); /**< Function to call on data when deleting a entry. */ }; diff --git a/hdrs/ident.h b/hdrs/ident.h index 2445bcf..e9d8f2f 100644 --- a/hdrs/ident.h +++ b/hdrs/ident.h @@ -44,9 +44,9 @@ extern "C" { * This structure stores the result of an ident call. */ typedef struct { - char *identifier; /**< Normally user name */ - char *opsys; /**< Operating system */ - char *charset; /**< Character set */ + char *identifier; /**< Normally user name */ + char *opsys; /**< Operating system */ + char *charset; /**< Character set */ } IDENT; /* High-level calls */ @@ -54,8 +54,8 @@ extern "C" { extern char *ident_id(int fd, int *timeout); extern IDENT *ident_query(struct sockaddr *laddr, socklen_t llen, - struct sockaddr *raddr, socklen_t rlen, - int *timeout); + struct sockaddr *raddr, socklen_t rlen, + int *timeout); void ident_free(IDENT *id); diff --git a/hdrs/lock.h b/hdrs/lock.h index 70f901e..d10ebe4 100644 --- a/hdrs/lock.h +++ b/hdrs/lock.h @@ -22,11 +22,11 @@ * An object's locks are represented as a linked list of these structures. */ struct lock_list { - lock_type type; /**< Type of lock */ - boolexp key; /**< Lock value ("key") */ - dbref creator; /**< Dbref of lock creator */ - int flags; /**< Lock flags */ - struct lock_list *next; /**< Pointer to next lock in object's list */ + lock_type type; /**< Type of lock */ + boolexp key; /**< Lock value ("key") */ + dbref creator; /**< Dbref of lock creator */ + int flags; /**< Lock flags */ + struct lock_list *next; /**< Pointer to next lock in object's list */ }; /* Our table of lock types, attributes, and default flags */ @@ -57,16 +57,16 @@ lock_type match_lock(lock_type type); const lock_list *get_lockproto(lock_type type); int add_lock(dbref player, dbref thing, lock_type type, boolexp key, int flags); int add_lock_raw(dbref player, dbref thing, lock_type type, - boolexp key, int flags); + boolexp key, int flags); void free_locks(lock_list *ll); int eval_lock(dbref player, dbref thing, lock_type ltype); int eval_lock_with(dbref player, dbref thing, lock_type ltype, dbref env0, - dbref env1); + dbref env1); int fail_lock(dbref player, dbref thing, lock_type ltype, const char *def, - dbref loc); + dbref loc); void do_unlock(dbref player, const char *name, lock_type type); void do_lock(dbref player, const char *name, const char *keyname, - lock_type type); + lock_type type); void init_locks(void); void clone_locks(dbref player, dbref orig, dbref clone); void do_lset(dbref player, char *what, char *flags); diff --git a/hdrs/log.h b/hdrs/log.h index 43fa90b..417a341 100644 --- a/hdrs/log.h +++ b/hdrs/log.h @@ -7,7 +7,7 @@ #define LT_WIZ 2 #define LT_CONN 3 #define LT_TRACE 4 -#define LT_RPAGE 5 /* Obsolete */ +#define LT_RPAGE 5 /* Obsolete */ #define LT_CHECK 6 #define LT_HUH 7 @@ -26,10 +26,10 @@ extern void do_logwipe(dbref player, int logtype, char *str); #define LA_CMD 0 #define LA_PE 1 #define LA_LOCK 2 -#define ACTIVITY_LOG_SIZE 3 /* In BUFFER_LEN-size lines */ +#define ACTIVITY_LOG_SIZE 3 /* In BUFFER_LEN-size lines */ extern void log_activity(int type, dbref player, const char *action); extern void notify_activity(dbref player, int num_lines, int dump); extern const char *last_activity(void); extern int last_activity_type(void); -#endif /* LOG_H */ +#endif /* LOG_H */ diff --git a/hdrs/malias.h b/hdrs/malias.h index 44ca603..8cee083 100644 --- a/hdrs/malias.h +++ b/hdrs/malias.h @@ -4,23 +4,23 @@ #define _MALIAS_H -#define MALIAS_TOKEN '+' /* Initial char for alias names */ +#define MALIAS_TOKEN '+' /* Initial char for alias names */ -#define ALIAS_MEMBERS 0x1 /* Only those on the alias */ -#define ALIAS_ADMIN 0x2 /* Only admin/powered */ -#define ALIAS_OWNER 0x4 /* Only the owner */ +#define ALIAS_MEMBERS 0x1 /* Only those on the alias */ +#define ALIAS_ADMIN 0x2 /* Only admin/powered */ +#define ALIAS_OWNER 0x4 /* Only the owner */ /** A mail alias. * This structure represents a mail alias (or mailing list). */ struct mail_alias { - char *name; /**< Name of the alias */ - unsigned char *desc; /**< Description */ - int size; /**< Size of the members array */ - dbref *members; /**< Pointer to an array of dbrefs of list members */ - int nflags; /**< Permissions for who can use/see alias name */ - int mflags; /**< Permissions for who can list alias members */ - dbref owner; /**< Who owns (controls) this alias */ + char *name; /**< Name of the alias */ + unsigned char *desc; /**< Description */ + int size; /**< Size of the members array */ + dbref *members; /**< Pointer to an array of dbrefs of list members */ + int nflags; /**< Permissions for who can use/see alias name */ + int mflags; /**< Permissions for who can list alias members */ + dbref owner; /**< Who owns (controls) this alias */ }; @@ -46,7 +46,7 @@ extern void load_malias(FILE * fp); extern void save_malias(FILE * fp); extern void malias_cleanup(dbref player); extern void do_malias_set(dbref player, char *alias, char *tolist); -#else /* MAIL_ALIASES */ +#else /* MAIL_ALIASES */ /* We still need this one */ void load_malias(FILE * fp); diff --git a/hdrs/match.h b/hdrs/match.h index 7ce6954..26724ec 100644 --- a/hdrs/match.h +++ b/hdrs/match.h @@ -58,4 +58,4 @@ extern dbref match_controlled(dbref player, const char *name); #define match_thing(player,name) \ noisy_match_result((player), (name), NOTYPE, MAT_EVERYTHING) -#endif /* __MATCH_H */ +#endif /* __MATCH_H */ diff --git a/hdrs/mushdb.h b/hdrs/mushdb.h index ab49741..a5e07cd 100644 --- a/hdrs/mushdb.h +++ b/hdrs/mushdb.h @@ -236,4 +236,4 @@ int unfindable(dbref); /* Available: 0x08 - 0x8000 */ #define RDBF_SU_EXIT_PATH 0x00010000 -#endif /* __DB_H */ +#endif /* __DB_H */ diff --git a/hdrs/mushtype.h b/hdrs/mushtype.h index c0ed601..cc2ed13 100644 --- a/hdrs/mushtype.h +++ b/hdrs/mushtype.h @@ -48,10 +48,10 @@ typedef int dbref; typedef long int warn_type; /* special dbref's */ -#define NOTHING (-1) /* null dbref */ -#define AMBIGUOUS (-2) /* multiple possibilities, for matchers */ -#define HOME (-3) /* virtual room, represents mover's home */ -#define ANY_OWNER (-2) /* For lstats and @stat */ +#define NOTHING (-1) /* null dbref */ +#define AMBIGUOUS (-2) /* multiple possibilities, for matchers */ +#define HOME (-3) /* virtual room, represents mover's home */ +#define ANY_OWNER (-2) /* For lstats and @stat */ #define INTERACT_SEE 0x1 @@ -77,12 +77,12 @@ typedef struct debug_info Debug_Info; * this struct unless you _really_ want to get your hands dirty. */ struct pe_info { - int fun_invocations; /**< Invocation count */ - int fun_depth; /**< Recursion count */ - int nest_depth; /**< Depth of function nesting, for DEBUG */ - int call_depth; /**< Function call counter */ - Debug_Info *debug_strings; /**< DEBUG infromation */ - int arg_count; /**< Number of arguments passed to function */ + int fun_invocations; /**< Invocation count */ + int fun_depth; /**< Recursion count */ + int nest_depth; /**< Depth of function nesting, for DEBUG */ + int call_depth; /**< Function call counter */ + Debug_Info *debug_strings; /**< DEBUG infromation */ + int arg_count; /**< Number of arguments passed to function */ }; /* new attribute foo */ @@ -105,16 +105,16 @@ typedef struct su_exit_path_t { /** A text block */ struct text_block { - int nchars; /**< Number of characters in the block */ - struct text_block *nxt; /**< Pointer to next block in queue */ - unsigned char *start; /**< Start of text */ - unsigned char *buf; /**< Current position in text */ + int nchars; /**< Number of characters in the block */ + struct text_block *nxt; /**< Pointer to next block in queue */ + unsigned char *start; /**< Start of text */ + unsigned char *buf; /**< Current position in text */ }; /** A queue of text blocks. */ struct text_queue { - struct text_block *head; /**< Pointer to the head of the queue */ - struct text_block **tail; /**< Pointer to pointer to tail of the queue */ + struct text_block *head; /**< Pointer to the head of the queue */ + struct text_block **tail; /**< Pointer to pointer to tail of the queue */ }; diff --git a/hdrs/mymalloc.h b/hdrs/mymalloc.h index f622e04..12a1fe9 100644 --- a/hdrs/mymalloc.h +++ b/hdrs/mymalloc.h @@ -5,20 +5,6 @@ #ifndef _MYMALLOC_H #define _MYMALLOC_H -#ifdef WIN32 -#undef malloc -#undef calloc -#undef realloc -#undef free -#endif - -/* If you're using gmalloc on some linux kernels, and have trouble - * with the compile, consider uncommenting this line: */ -/*#undef I_MALLOC */ -#ifdef I_MALLOC -#include -#endif - #include "options.h" #if (MALLOC_PACKAGE == 1) @@ -32,4 +18,4 @@ #include "csrimalloc.h" #endif -#endif /* _MYMALLOC_H */ +#endif /* _MYMALLOC_H */ diff --git a/hdrs/mysocket.h b/hdrs/mysocket.h index 0cafc8b..e412efc 100644 --- a/hdrs/mysocket.h +++ b/hdrs/mysocket.h @@ -17,7 +17,7 @@ #endif #include #include -#undef EINTR /* Clashes with errno.h */ +#undef EINTR /* Clashes with errno.h */ #define EINTR WSAEINTR #define EWOULDBLOCK WSAEWOULDBLOCK #define EINPROGRESS WSAEINPROGRESS @@ -45,14 +45,14 @@ typedef unsigned int socklen_t; /** Information about a host. */ struct hostname_info { - const char *hostname; /**< Host's name */ - const char *port; /**< Host's source port */ + const char *hostname; /**< Host's name */ + const char *port; /**< Host's source port */ }; /** A union for sockaddr manipulation */ union sockaddr_u { - struct sockaddr addr; /**< A sockaddr structure */ - char data[MAXSOCKADDR]; /**< A byte array representation */ + struct sockaddr addr; /**< A sockaddr structure */ + char data[MAXSOCKADDR]; /**< A byte array representation */ }; /* What htons expects. Is this even used anymore? */ @@ -67,7 +67,7 @@ int make_socket (Port_t port, union sockaddr_u *addr, socklen_t *len, const char *host); /* Connect somewhere */ int make_socket_conn(const char *host, struct sockaddr *myiterface, - socklen_t myilen, Port_t port, int *timeout); + socklen_t myilen, Port_t port, int *timeout); void make_nonblocking(int s); void set_keepalive(int s); int connect_nonb @@ -78,7 +78,7 @@ int connect_nonb #else extern void shutdownsock(DESC *d); extern BOOL GetErrorMessage(const DWORD dwError, LPTSTR lpszError, const UINT - nMaxError); + nMaxError); #endif @@ -99,62 +99,62 @@ const char *inet_ntop(int, const void *, char *, size_t); */ struct addrinfo { - int ai_flags; /**< AI_PASSIVE, AI_CANONNAME */ - int ai_family; /**< PF_xxx */ - int ai_socktype; /**< SOCK_xxx */ - int ai_protocol; /**< IPPROTO_xxx for IPv4 and IPv6 */ - size_t ai_addrlen; /**< length of ai_addr */ - char *ai_canonname; /**< canonical name for host */ - struct sockaddr *ai_addr; /**< binary address */ - struct addrinfo *ai_next; /**< next structure in linked list */ + int ai_flags; /**< AI_PASSIVE, AI_CANONNAME */ + int ai_family; /**< PF_xxx */ + int ai_socktype; /**< SOCK_xxx */ + int ai_protocol; /**< IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /**< length of ai_addr */ + char *ai_canonname; /**< canonical name for host */ + struct sockaddr *ai_addr; /**< binary address */ + struct addrinfo *ai_next; /**< next structure in linked list */ }; struct addrinfo; - /* following for getaddrinfo() */ -#define AI_PASSIVE 1 /* socket is intended for bind() + listen() */ -#define AI_CANONNAME 2 /* return canonical name */ - - /* error returns */ -#define EAI_ADDRFAMILY 1 /* address family for host not supported */ -#define EAI_AGAIN 2 /* temporary failure in name resolution */ -#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ -#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ -#define EAI_FAMILY 5 /* ai_family not supported */ -#define EAI_MEMORY 6 /* memory allocation failure */ -#define EAI_NODATA 7 /* no address associated with host */ -#define EAI_NONAME 8 /* host nor service provided, or not known */ -#define EAI_SERVICE 9 /* service not supported for ai_socktype */ -#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ -#define EAI_SYSTEM 11 /* system error returned in errno */ + /* following for getaddrinfo() */ +#define AI_PASSIVE 1 /* socket is intended for bind() + listen() */ +#define AI_CANONNAME 2 /* return canonical name */ + + /* error returns */ +#define EAI_ADDRFAMILY 1 /* address family for host not supported */ +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#define EAI_NODATA 7 /* no address associated with host */ +#define EAI_NONAME 8 /* host nor service provided, or not known */ +#define EAI_SERVICE 9 /* service not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ int getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hintsp, struct addrinfo **result); + const struct addrinfo *hintsp, struct addrinfo **result); /* If we don't have getaddrinfo, we won't have these either... */ void freeaddrinfo(struct addrinfo *old); -#endif /* HAS_GETADDRINFO */ +#endif /* HAS_GETADDRINFO */ #ifndef HAS_GAI_STRERROR const char *gai_strerror(int errval); #endif -#ifndef HAS_GETNAMEINFO /* following for getnameinfo() */ +#ifndef HAS_GETNAMEINFO /* following for getnameinfo() */ #ifndef __APPLE__ /* Apple has these in netdb.h */ -#define NI_MAXHOST 1025 /* max hostname returned */ -#define NI_MAXSERV 32 /* max service name returned */ - -#define NI_NOFQDN 1 /* do not return FQDN */ -#define NI_NUMERICHOST 2 /* return numeric form of hostname */ -#define NI_NAMEREQD 4 /* return error if hostname not found */ -#define NI_NUMERICSERV 8 /* return numeric form of service name */ -#define NI_DGRAM 16 /* datagram service for getservbyname() */ +#define NI_MAXHOST 1025 /* max hostname returned */ +#define NI_MAXSERV 32 /* max service name returned */ + +#define NI_NOFQDN 1 /* do not return FQDN */ +#define NI_NUMERICHOST 2 /* return numeric form of hostname */ +#define NI_NAMEREQD 4 /* return error if hostname not found */ +#define NI_NUMERICSERV 8 /* return numeric form of service name */ +#define NI_DGRAM 16 /* datagram service for getservbyname() */ #endif int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags); -#endif /* HAS_GETNAMEINFO */ + size_t hostlen, char *serv, size_t servlen, int flags); +#endif /* HAS_GETNAMEINFO */ -#endif /* MYSOCKET_H */ +#endif /* MYSOCKET_H */ diff --git a/hdrs/myssl.h b/hdrs/myssl.h index 70c2dc6..277f603 100644 --- a/hdrs/myssl.h +++ b/hdrs/myssl.h @@ -18,14 +18,14 @@ int ssl_need_accept(int state); int ssl_need_handshake(int state); int ssl_want_write(int state); int ssl_read(SSL * ssl, int state, int net_read_ready, int net_write_ready, - char *buf, int bufsize, int *bytes_read); + char *buf, int bufsize, int *bytes_read); int ssl_write(SSL * ssl, int state, int net_read_ready, int net_write_ready, - unsigned char *buf, int bufsize, int *offset); + unsigned char *buf, int bufsize, int *offset); void ssl_write_session(FILE * fp, SSL * ssl); void ssl_read_session(FILE * fp); void ssl_write_ssl(FILE * fp, SSL * ssl); SSL *ssl_read_ssl(FILE * fp, int sock); -#endif /* HAS_OPENSSL */ -#endif /* _MYSSL_H */ +#endif /* HAS_OPENSSL */ +#endif /* _MYSSL_H */ diff --git a/hdrs/oldflags.h b/hdrs/oldflags.h index b1c767d..818e485 100644 --- a/hdrs/oldflags.h +++ b/hdrs/oldflags.h @@ -116,46 +116,46 @@ * Thing flags */ -#define THING_DEST_OK 0x8 /* can be destroyed by anyone */ -#define THING_PUPPET 0x10 /* echoes to its owner */ -#define THING_LISTEN 0x20 /* checks for ^ patterns */ -#define THING_NOLEAVE 0x40 /* Can't be left */ -#define THING_INHEARIT 0x80 /* checks parent chain for ^ patterns */ -#define THING_Z_TEL 0x100 /* If set on ZMO players may only @tel - within the zone */ +#define THING_DEST_OK 0x8 /* can be destroyed by anyone */ +#define THING_PUPPET 0x10 /* echoes to its owner */ +#define THING_LISTEN 0x20 /* checks for ^ patterns */ +#define THING_NOLEAVE 0x40 /* Can't be left */ +#define THING_INHEARIT 0x80 /* checks parent chain for ^ patterns */ +#define THING_Z_TEL 0x100 /* If set on ZMO players may only @tel + within the zone */ /*-------------------------------------------------------------------------- * Room flags */ -#define ROOM_FLOATING 0x8 /* room is not linked to rest of - * MUSH. Don't blather about it. - */ -#define ROOM_ABODE 0x10 /* players may link themselves here */ -#define ROOM_JUMP_OK 0x20 /* anyone may @teleport to here */ -#define ROOM_NO_TEL 0x40 /* mortals cannot @tel from here */ -#define ROOM_TEMPLE 0x80 /* objects dropped here are sacrificed - * (destroyed) and player gets money. - * Now used only for conversion. - */ -#define ROOM_LISTEN 0x100 /* checks for ^ patterns */ -#define ROOM_Z_TEL 0x200 /* If set on a room, players may - * only @tel to another room in the - * same zone - */ -#define ROOM_INHEARIT 0x400 /* checks parent chain for ^ patterns */ - -#define ROOM_UNINSPECT 0x1000 /* Not inspected */ +#define ROOM_FLOATING 0x8 /* room is not linked to rest of + * MUSH. Don't blather about it. + */ +#define ROOM_ABODE 0x10 /* players may link themselves here */ +#define ROOM_JUMP_OK 0x20 /* anyone may @teleport to here */ +#define ROOM_NO_TEL 0x40 /* mortals cannot @tel from here */ +#define ROOM_TEMPLE 0x80 /* objects dropped here are sacrificed + * (destroyed) and player gets money. + * Now used only for conversion. + */ +#define ROOM_LISTEN 0x100 /* checks for ^ patterns */ +#define ROOM_Z_TEL 0x200 /* If set on a room, players may + * only @tel to another room in the + * same zone + */ +#define ROOM_INHEARIT 0x400 /* checks parent chain for ^ patterns */ + +#define ROOM_UNINSPECT 0x1000 /* Not inspected */ /*-------------------------------------------------------------------------- * Exit flags */ -#define EXIT_CLOUDY 0x8 /* Looking through a cloudy transparent - * exit shows the room's desc, not contents. - * Looking through a cloudy !trans exit, - * shows the room's contents, not desc - */ +#define EXIT_CLOUDY 0x8 /* Looking through a cloudy transparent + * exit shows the room's desc, not contents. + * Looking through a cloudy !trans exit, + * shows the room's contents, not desc + */ -#endif /* __OLDFLAGS_H */ +#endif /* __OLDFLAGS_H */ diff --git a/hdrs/parse.h b/hdrs/parse.h index ac3f36a..4d8a738 100644 --- a/hdrs/parse.h +++ b/hdrs/parse.h @@ -23,18 +23,18 @@ #define HUGE_NVAL HUGE_DOUBLE /* These are some common error messages. */ -extern char e_int[]; /* #-1 ARGUMENT MUST BE INTEGER */ -extern char e_ints[]; /* #-1 ARGUMENTS MUST BE INTEGERS */ -extern char e_uint[]; /* #-1 ARGUMENT MUST BE POSITIVE INTEGER */ -extern char e_uints[]; /* #-1 ARGUMENTS MUST BE POSITIVE INTEGERS */ -extern char e_num[]; /* #-1 ARGUMENT MUST BE NUMBER */ -extern char e_nums[]; /* #-1 ARGUMENTS MUST BE NUMBERS */ -extern char e_perm[]; /* #-1 PERMISSION DENIED */ -extern char e_atrperm[]; /* #-1 NO PERMISSION TO GET ATTRIBUTE */ -extern char e_match[]; /* #-1 NO MATCH */ -extern char e_notvis[]; /* #-1 NO SUCH OBJECT VISIBLE */ -extern char e_disabled[]; /* #-1 FUNCTION DISABLED */ -extern char e_range[]; /* #-1 OUT OF RANGE */ +extern char e_int[]; /* #-1 ARGUMENT MUST BE INTEGER */ +extern char e_ints[]; /* #-1 ARGUMENTS MUST BE INTEGERS */ +extern char e_uint[]; /* #-1 ARGUMENT MUST BE POSITIVE INTEGER */ +extern char e_uints[]; /* #-1 ARGUMENTS MUST BE POSITIVE INTEGERS */ +extern char e_num[]; /* #-1 ARGUMENT MUST BE NUMBER */ +extern char e_nums[]; /* #-1 ARGUMENTS MUST BE NUMBERS */ +extern char e_perm[]; /* #-1 PERMISSION DENIED */ +extern char e_atrperm[]; /* #-1 NO PERMISSION TO GET ATTRIBUTE */ +extern char e_match[]; /* #-1 NO MATCH */ +extern char e_notvis[]; /* #-1 NO SUCH OBJECT VISIBLE */ +extern char e_disabled[]; /* #-1 FUNCTION DISABLED */ +extern char e_range[]; /* #-1 OUT OF RANGE */ /* The following routines all take strings as arguments, and return * data of the appropriate types. @@ -151,8 +151,8 @@ typedef struct fun FUN; /* process_expression() evaluates expressions. What a concept. */ int process_expression(char *buff, char **bp, char const **str, - dbref executor, dbref caller, dbref enactor, - int eflags, int tflags, PE_Info * pe_info); + dbref executor, dbref caller, dbref enactor, + int eflags, int tflags, PE_Info * pe_info); /* buff is a pointer to a BUFFER_LEN string to contain the expression * result. *bp is the point in buff at which the result should be written. @@ -251,4 +251,4 @@ int process_expression(char *buff, char **bp, char const **str, extern void start_cpu_timer(void); extern void reset_cpu_timer(void); -#endif /* !_PARSE_H_ */ +#endif /* !_PARSE_H_ */ diff --git a/hdrs/pcre.h b/hdrs/pcre.h index 27f5c7d..af1ddbe 100644 --- a/hdrs/pcre.h +++ b/hdrs/pcre.h @@ -94,7 +94,7 @@ extern "C" { #define PCRE_ERROR_NOMEMORY (-6) #define PCRE_ERROR_NOSUBSTRING (-7) #define PCRE_ERROR_MATCHLIMIT (-8) -#define PCRE_ERROR_CALLOUT (-9) /* Never used by PCRE itself */ +#define PCRE_ERROR_CALLOUT (-9) /* Never used by PCRE itself */ #define PCRE_ERROR_BADUTF8 (-10) #define PCRE_ERROR_BADUTF8_OFFSET (-11) #define PCRE_ERROR_PARTIAL (-12) @@ -114,7 +114,7 @@ extern "C" { #define PCRE_INFO_CAPTURECOUNT 2 #define PCRE_INFO_BACKREFMAX 3 #define PCRE_INFO_FIRSTBYTE 4 -#define PCRE_INFO_FIRSTCHAR 4 /* For backwards compatibility */ +#define PCRE_INFO_FIRSTCHAR 4 /* For backwards compatibility */ #define PCRE_INFO_FIRSTTABLE 5 #define PCRE_INFO_LASTLITERAL 6 #define PCRE_INFO_NAMEENTRYSIZE 7 @@ -140,18 +140,18 @@ extern "C" { /* Types */ - struct real_pcre; /* declaration; the definition is private */ + struct real_pcre; /* declaration; the definition is private */ typedef struct real_pcre pcre; /* The structure for passing additional data to pcre_exec(). This is defined in such as way as to be extensible. */ typedef struct pcre_extra { - unsigned long int flags; /* Bits for which fields are set */ - void *study_data; /* Opaque data from pcre_study() */ - unsigned long int match_limit; /* Maximum number of calls to match() */ - void *callout_data; /* Data passed back in callouts */ - const unsigned char *tables; /* Pointer to character tables */ + unsigned long int flags; /* Bits for which fields are set */ + void *study_data; /* Opaque data from pcre_study() */ + unsigned long int match_limit; /* Maximum number of calls to match() */ + void *callout_data; /* Data passed back in callouts */ + const unsigned char *tables; /* Pointer to character tables */ } pcre_extra; /* The structure for passing out data via the pcre_callout_function. We use a @@ -160,20 +160,20 @@ without changing the API of the function, thereby allowing old clients to work without modification. */ typedef struct pcre_callout_block { - int version; /* Identifies version of block */ + int version; /* Identifies version of block */ /* ------------------------ Version 0 ------------------------------- */ - int callout_number; /* Number compiled into pattern */ - int *offset_vector; /* The offset vector */ - const char *subject; /* The subject being matched */ - int subject_length; /* The length of the subject */ - int start_match; /* Offset to start of this match attempt */ - int current_position; /* Where we currently are in the subject */ - int capture_top; /* Max current capture */ - int capture_last; /* Most recently closed capture */ - void *callout_data; /* Data passed in with the call */ + int callout_number; /* Number compiled into pattern */ + int *offset_vector; /* The offset vector */ + const char *subject; /* The subject being matched */ + int subject_length; /* The length of the subject */ + int start_match; /* Offset to start of this match attempt */ + int current_position; /* Where we currently are in the subject */ + int capture_top; /* Max current capture */ + int capture_last; /* Most recently closed capture */ + void *callout_data; /* Data passed in with the call */ /* ------------------- Added for Version 1 -------------------------- */ - int pattern_position; /* Offset to next item in the pattern */ - int next_item_length; /* Length of next item in the pattern */ + int pattern_position; /* Offset to next item in the pattern */ + int next_item_length; /* Length of next item in the pattern */ /* ------------------------------------------------------------------ */ } pcre_callout_block; @@ -181,23 +181,23 @@ without modification. */ /* Exported PCRE functions */ extern pcre *pcre_compile(const char *, int, const char **, - int *, const unsigned char *); + int *, const unsigned char *); extern int pcre_copy_substring(const char *, int *, int, int, char *, int); int pcre_get_substring(const char *, int *, int, int, const char **); extern int pcre_exec(const pcre *, const pcre_extra *, - const char *, int, int, int, int *, int); + const char *, int, int, int, int *, int); extern const unsigned char *pcre_maketables(void); extern pcre_extra *pcre_study(const pcre *, int, const char **); extern int pcre_fullinfo(const pcre * argument_re, - const pcre_extra * extra_data, int what, - void *where); + const pcre_extra * extra_data, int what, + void *where); extern int pcre_get_stringnumber(const pcre * code, const char *stringname); extern int pcre_copy_named_substring(const pcre * code, const char *subject, - int *ovector, int stringcount, - const char *stringname, char *buffer, int size); + int *ovector, int stringcount, + const char *stringname, char *buffer, int size); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* End of pcre.h */ +#endif /* End of pcre.h */ diff --git a/hdrs/privtab.h b/hdrs/privtab.h index 8532cf8..aa31a86 100644 --- a/hdrs/privtab.h +++ b/hdrs/privtab.h @@ -16,10 +16,10 @@ typedef struct priv_info PRIV; * a string of restrictions into a bitmask. */ struct priv_info { - const char *name; /**< Name of the privilege */ - char letter; /**< One-letter abbreviation */ - long int bits_to_set; /**< Bitflags required to set this privilege */ - long int bits_to_show; /**< Bitflags required to see this privilege */ + const char *name; /**< Name of the privilege */ + char letter; /**< One-letter abbreviation */ + long int bits_to_set; /**< Bitflags required to set this privilege */ + long int bits_to_show; /**< Bitflags required to see this privilege */ }; #define PrivName(x) ((x)->name) @@ -30,9 +30,9 @@ struct priv_info { extern int string_to_privs(PRIV *table, const char *str, long int origprivs); extern int list_to_privs(PRIV *table, const char *str, long int origprivs); extern int string_to_privsets(PRIV *table, const char *str, int *setprivs, - int *clrprivs); + int *clrprivs); extern int letter_to_privs(PRIV *table, const char *str, long int origprivs); extern const char *privs_to_string(PRIV *table, int privs); extern const char *privs_to_letters(PRIV *table, int privs); -#endif /* __PRIVTAB_H */ +#endif /* __PRIVTAB_H */ diff --git a/hdrs/ptab.h b/hdrs/ptab.h index 79a200f..5540986 100644 --- a/hdrs/ptab.h +++ b/hdrs/ptab.h @@ -9,11 +9,11 @@ struct ptab_entry; * data is looked up by the best matching prefix of the given key. */ typedef struct ptab { - int state; /**< Internal table state */ - int len; /**< Table size */ - int maxlen; /**< Maximum table size */ - int current; /**< Internal table state */ - struct ptab_entry **tab; /**< Pointer to array of entries */ + int state; /**< Internal table state */ + int len; /**< Table size */ + int maxlen; /**< Maximum table size */ + int current; /**< Internal table state */ + struct ptab_entry **tab; /**< Pointer to array of entries */ } PTAB; @@ -32,4 +32,4 @@ void *ptab_nextentry_new(PTAB *, char *key); #define ptab_firstentry(x) ptab_firstentry_new(x,NULL) #define ptab_nextentry(x) ptab_nextentry_new(x,NULL) -#endif /* PTAB_H */ +#endif /* PTAB_H */ diff --git a/hdrs/pueblo.h b/hdrs/pueblo.h index ebb62bb..1853b6d 100644 --- a/hdrs/pueblo.h +++ b/hdrs/pueblo.h @@ -34,7 +34,7 @@ int safe_tag(char const *a_tag, char *buf, char **bp); int safe_tag_cancel(char const *a_tag, char *buf, char **bp); int safe_tag_wrap(char const *a_tag, char const *params, - char const *data, char *buf, char **bp, dbref player); + char const *data, char *buf, char **bp, dbref player); /* Please STAY SANE when modifying. * Making this something like 'x' and 'y' is a BAD IDEA diff --git a/hdrs/shs.h b/hdrs/shs.h index 98b9422..ca5027f 100644 --- a/hdrs/shs.h +++ b/hdrs/shs.h @@ -32,11 +32,11 @@ typedef unsigned int LONG; /** An shs digest. */ typedef struct { - LONG digest[5]; /**< message digest */ - LONG countLo; /**< 64-bit bit count, low half */ - LONG countHi; /**< 64-bit bit count, high half */ - LONG data[16]; /**< SHS data buffer */ - BYTE reverse_wanted; /**< true to reverse (little_endian) false to not */ + LONG digest[5]; /**< message digest */ + LONG countLo; /**< 64-bit bit count, low half */ + LONG countHi; /**< 64-bit bit count, high half */ + LONG data[16]; /**< SHS data buffer */ + BYTE reverse_wanted; /**< true to reverse (little_endian) false to not */ } SHS_INFO; void shsInit(SHS_INFO *shsInfo); diff --git a/hdrs/strtree.h b/hdrs/strtree.h index 71ccffa..67c5845 100644 --- a/hdrs/strtree.h +++ b/hdrs/strtree.h @@ -14,10 +14,10 @@ typedef struct strnode StrNode; * This is a node in a red/black binary strtree. */ struct strnode { - StrNode *left; /**< Pointer to left child */ - StrNode *right; /**< Pointer to right child */ - unsigned char info; /**< Red/black and other internal state */ - char string[BUFFER_LEN]; /**< Node label (value) */ + StrNode *left; /**< Pointer to left child */ + StrNode *right; /**< Pointer to right child */ + unsigned char info; /**< Red/black and other internal state */ + char string[BUFFER_LEN]; /**< Node label (value) */ }; typedef struct strtree StrTree; @@ -25,9 +25,9 @@ typedef struct strtree StrTree; * A red/black binary tree of strings. */ struct strtree { - StrNode *root; /**< Pointer to root node */ - size_t count; /**< Number of nodes in the tree */ - size_t mem; /**< Memory used by the tree */ + StrNode *root; /**< Pointer to root node */ + size_t count; /**< Number of nodes in the tree */ + size_t mem; /**< Memory used by the tree */ }; void st_init(StrTree *root); diff --git a/src/access.c b/src/access.c index fa2101d..c78a1f2 100644 --- a/src/access.c +++ b/src/access.c @@ -91,9 +91,9 @@ typedef struct a_acsflag acsflag; * This structure is used to build a table of access control flags. */ struct a_acsflag { - const char *name; /**< Name of the access flag */ - int toggle; /**< Is this a negatable flag? */ - int flag; /**< Bitmask of the flag */ + const char *name; /**< Name of the access flag */ + int toggle; /**< Is this a negatable flag? */ + int flag; /**< Bitmask of the flag */ }; static acsflag acslist[] = { {"connect", 1, ACS_CONNECT}, @@ -118,7 +118,7 @@ static void free_access_list(void); static int add_access_node(const char *host, const dbref who, const int can, - const int cant, const char *comment) + const int cant, const char *comment) { struct access *end; struct access *tmp; @@ -183,37 +183,37 @@ read_access_file(void) while (fgets(buf, BUFFER_LEN, fp)) { /* Strip end of line if it's \r\n or \n */ if ((p = strchr(buf, '\r'))) - *p = '\0'; + *p = '\0'; else if ((p = strchr(buf, '\n'))) - *p = '\0'; + *p = '\0'; /* Find beginning of line; ignore blank lines */ p = buf; if (*p && isspace((unsigned char) *p)) - p++; + p++; if (*p && *p != '#') { - can = cant = 0; - comment = NULL; - /* Is this the @sitelock entry? */ - if (!strncasecmp(p, "@sitelock", 9)) { - if (!add_access_node("@sitelock", AMBIGUOUS, ACS_SITELOCK, 0, "")) - do_log(LT_ERR, GOD, GOD, T("Failed to add sitelock node!")); - } else { - if ((comment = strchr(p, '#'))) { - *comment++ = '\0'; - while (*comment && isspace((unsigned char) *comment)) - comment++; - } - /* Move past the host name */ - while (*p && !isspace((unsigned char) *p)) - p++; - if (*p) - *p++ = '\0'; - if (!parse_access_options(p, &who, &can, &cant, NOTHING)) - /* Nothing listed, so assume we can't do anything! */ - cant = ACS_DEFAULT; - if (!add_access_node(buf, who, can, cant, comment)) - do_log(LT_ERR, GOD, GOD, T("Failed to add access node!")); - } + can = cant = 0; + comment = NULL; + /* Is this the @sitelock entry? */ + if (!strncasecmp(p, "@sitelock", 9)) { + if (!add_access_node("@sitelock", AMBIGUOUS, ACS_SITELOCK, 0, "")) + do_log(LT_ERR, GOD, GOD, T("Failed to add sitelock node!")); + } else { + if ((comment = strchr(p, '#'))) { + *comment++ = '\0'; + while (*comment && isspace((unsigned char) *comment)) + comment++; + } + /* Move past the host name */ + while (*p && !isspace((unsigned char) *p)) + p++; + if (*p) + *p++ = '\0'; + if (!parse_access_options(p, &who, &can, &cant, NOTHING)) + /* Nothing listed, so assume we can't do anything! */ + cant = ACS_DEFAULT; + if (!add_access_node(buf, who, can, cant, comment)) + do_log(LT_ERR, GOD, GOD, T("Failed to add access node!")); + } } } retval = 1; @@ -243,36 +243,36 @@ write_access_file(void) } else { for (ap = access_top; ap; ap = ap->next) { if (strcmp(ap->host, "@sitelock") == 0) { - fprintf(fp, "@sitelock\n"); - continue; + fprintf(fp, "@sitelock\n"); + continue; } fprintf(fp, "%s %d ", ap->host, ap->who); switch (ap->can) { case ACS_SITELOCK: - break; + break; case ACS_DEFAULT: - fprintf(fp, "DEFAULT "); - break; + fprintf(fp, "DEFAULT "); + break; default: - for (c = acslist; c->name; c++) - if (ap->can & c->flag) - fprintf(fp, "%s ", c->name); - break; + for (c = acslist; c->name; c++) + if (ap->can & c->flag) + fprintf(fp, "%s ", c->name); + break; } switch (ap->cant) { case ACS_DEFAULT: - fprintf(fp, "NONE "); - break; + fprintf(fp, "NONE "); + break; default: - for (c = acslist; c->name; c++) - if (c->toggle && (ap->cant & c->flag)) - fprintf(fp, "!%s ", c->name); - break; + for (c = acslist; c->name; c++) + if (c->toggle && (ap->cant & c->flag)) + fprintf(fp, "!%s ", c->name); + break; } if (ap->comment && *ap->comment) - fprintf(fp, "# %s\n", ap->comment); + fprintf(fp, "# %s\n", ap->comment); else - fprintf(fp, "\n"); + fprintf(fp, "\n"); } fclose(fp); #ifdef WIN32 @@ -401,22 +401,22 @@ site_check_access(const char *hname, dbref who, int *rulenum) for (ap = access_top; ap; ap = ap->next) { (*rulenum)++; if (!(ap->can & ACS_SITELOCK) - && ((ap->can & ACS_REGEXP) - ? (quick_regexp_match(ap->host, hname, 0) - || (p && quick_regexp_match(ap->host, p, 0)) + && ((ap->can & ACS_REGEXP) + ? (quick_regexp_match(ap->host, hname, 0) + || (p && quick_regexp_match(ap->host, p, 0)) #ifdef FORCE_IPV4 - || quick_regexp_match(ip4_to_ip6(ap->host), hname, 0) - || (p && quick_regexp_match(ip4_to_ip6(ap->host), p, 0)) + || quick_regexp_match(ip4_to_ip6(ap->host), hname, 0) + || (p && quick_regexp_match(ip4_to_ip6(ap->host), p, 0)) #endif - ) - : (quick_wild(ap->host, hname) - || (p && quick_wild(ap->host, p)) + ) + : (quick_wild(ap->host, hname) + || (p && quick_wild(ap->host, p)) #ifdef FORCE_IPV4 - || quick_wild(ip4_to_ip6(ap->host), hname) - || (p && quick_wild(ip4_to_ip6(ap->host), p)) + || quick_wild(ip4_to_ip6(ap->host), hname) + || (p && quick_wild(ip4_to_ip6(ap->host), p)) #endif - )) - && (ap->who == AMBIGUOUS || ap->who == who)) { + )) + && (ap->who == AMBIGUOUS || ap->who == who)) { /* Got one */ return ap; } @@ -435,11 +435,11 @@ site_check_access(const char *hname, dbref who, int *rulenum) */ int format_access(struct access *ap, int rulenum, - dbref who __attribute__ ((__unused__)), char *buff, char **bp) + dbref who __attribute__ ((__unused__)), char *buff, char **bp) { if (ap) { safe_format(buff, bp, T("Matched line %d: %s %s"), rulenum, ap->host, - (ap->can & ACS_REGEXP) ? "(regexp)" : ""); + (ap->can & ACS_REGEXP) ? "(regexp)" : ""); safe_chr('\n', buff, bp); safe_format(buff, bp, T("Comment: %s"), ap->comment); safe_chr('\n', buff, bp); @@ -495,7 +495,7 @@ format_access(struct access *ap, int rulenum, */ int add_access_sitelock(dbref player, const char *host, dbref who, int can, - int cant) + int cant) { struct access *end; struct access *tmp; @@ -509,7 +509,7 @@ add_access_sitelock(dbref player, const char *host, dbref who, int can, tmp->cant = cant; strcpy(tmp->host, host); sprintf(tmp->comment, "By %s(#%d) on %s", Name(player), player, - show_time(mudtime, 0)); + show_time(mudtime, 0)); tmp->next = NULL; if (!access_top) { @@ -525,7 +525,7 @@ add_access_sitelock(dbref player, const char *host, dbref who, int can, if (end->can != ACS_SITELOCK) { /* We're at the end and there's no sitelock marker. Add one */ if (!add_access_node("@sitelock", AMBIGUOUS, ACS_SITELOCK, 0, "")) - return 0; + return 0; end = end->next; } else { /* We're in the middle, so be sure we keep the list linked */ @@ -565,9 +565,9 @@ remove_access_sitelock(const char *pattern) n++; mush_free(ap, "struct_access"); if (prev) - prev->next = next; + prev->next = next; else - access_top = next; + access_top = next; } else { prev = ap; } @@ -610,27 +610,27 @@ do_list_access(dbref player) if (ap->can != ACS_SITELOCK) { bp = flaglist; for (c = acslist; c->name; c++) { - if (c->flag == ACS_DEFAULT) - continue; - if (ap->can & c->flag) { - safe_chr(' ', flaglist, &bp); - safe_str(c->name, flaglist, &bp); - } - if (c->toggle && (ap->cant & c->flag)) { - safe_chr(' ', flaglist, &bp); - safe_chr('!', flaglist, &bp); - safe_str(c->name, flaglist, &bp); - } + if (c->flag == ACS_DEFAULT) + continue; + if (ap->can & c->flag) { + safe_chr(' ', flaglist, &bp); + safe_str(c->name, flaglist, &bp); + } + if (c->toggle && (ap->cant & c->flag)) { + safe_chr(' ', flaglist, &bp); + safe_chr('!', flaglist, &bp); + safe_str(c->name, flaglist, &bp); + } } *bp = '\0'; notify_format(player, - "%3d SITE: %-20s DBREF: %-6s FLAGS:%s", rulenum, - ap->host, unparse_dbref(ap->who), flaglist); + "%3d SITE: %-20s DBREF: %-6s FLAGS:%s", rulenum, + ap->host, unparse_dbref(ap->who), flaglist); notify_format(player, " COMMENT: %s", ap->comment); } else { notify(player, - T - ("---- @sitelock will add sites immediately below this line ----")); + T + ("---- @sitelock will add sites immediately below this line ----")); } } @@ -649,7 +649,7 @@ do_list_access(dbref player) */ int parse_access_options(const char *opts, dbref *who, int *can, int *cant, - dbref player) + dbref player) { char myopts[BUFFER_LEN]; char *p; @@ -668,13 +668,13 @@ parse_access_options(const char *opts, dbref *who, int *can, int *cant, while ((w = split_token(&p, ' '))) { found = 0; - if (first && who) { /* Check for a character */ + if (first && who) { /* Check for a character */ first = 0; - if (is_integer(w)) { /* We have a dbref */ - *who = parse_integer(w); - if (*who != AMBIGUOUS && !GoodObject(*who)) - *who = AMBIGUOUS; - continue; + if (is_integer(w)) { /* We have a dbref */ + *who = parse_integer(w); + if (*who != AMBIGUOUS && !GoodObject(*who)) + *who = AMBIGUOUS; + continue; } } @@ -682,31 +682,31 @@ parse_access_options(const char *opts, dbref *who, int *can, int *cant, /* Found a negated warning */ w++; for (c = acslist; c->name; c++) { - if (c->toggle && !strncasecmp(w, c->name, strlen(c->name))) { - *cant |= c->flag; - found++; - } + if (c->toggle && !strncasecmp(w, c->name, strlen(c->name))) { + *cant |= c->flag; + found++; + } } } else { /* None is special */ if (!strncasecmp(w, "NONE", 4)) { - *cant = ACS_DEFAULT; - found++; + *cant = ACS_DEFAULT; + found++; } else { - for (c = acslist; c->name; c++) { - if (!strncasecmp(w, c->name, strlen(c->name))) { - *can |= c->flag; - found++; - } - } + for (c = acslist; c->name; c++) { + if (!strncasecmp(w, c->name, strlen(c->name))) { + *can |= c->flag; + found++; + } + } } } /* At this point, we haven't matched any warnings. */ if (!found) { if (GoodObject(player)) - notify_format(player, T("Unknown access option: %s"), w); + notify_format(player, T("Unknown access option: %s"), w); else - do_log(LT_ERR, GOD, GOD, T("Unknown access flag: %s"), w); + do_log(LT_ERR, GOD, GOD, T("Unknown access flag: %s"), w); } else { totalfound += found; } diff --git a/src/atr_tab.c b/src/atr_tab.c index 72c915e..984b382 100644 --- a/src/atr_tab.c +++ b/src/atr_tab.c @@ -30,8 +30,8 @@ extern ATTR *catchall; /** An alias for an attribute. */ typedef struct atr_alias { - const char *alias; /**< The alias. */ - const char *realname; /**< The attribute's canonical name. */ + const char *alias; /**< The alias. */ + const char *realname; /**< The attribute's canonical name. */ } ATRALIAS; @@ -347,14 +347,14 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive) if (retroactive) { for (i = 0; i < db_top; i++) { if ((ap2 = atr_get_noparent(i, name))) { - AL_FLAGS(ap2) = flags; - AL_CREATOR(ap2) = player; + AL_FLAGS(ap2) = flags; + AL_CREATOR(ap2) = player; } } } notify_format(player, T("%s -- Attribute permissions now: %s"), name, - privs_to_string(attr_privs_view, flags)); + privs_to_string(attr_privs_view, flags)); } @@ -436,8 +436,8 @@ do_attribute_rename(dbref player, char *old, char *newname) ap = (ATTR *) ptab_find_exact(&ptab_attrib, newname); if (ap) { notify_format(player, - T("The name %s is already used in the attribute table."), - newname); + T("The name %s is already used in the attribute table."), + newname); return; } /* Is the old name a real attribute? */ @@ -456,7 +456,7 @@ do_attribute_rename(dbref player, char *old, char *newname) ptab_insert(&ptab_attrib, newname, ap); ptab_end_inserts(&ptab_attrib); notify_format(player, - T("Renamed %s to %s in attribute table."), old, newname); + T("Renamed %s to %s in attribute table."), old, newname); return; } @@ -498,8 +498,8 @@ do_attribute_info(dbref player, char *name) } notify_format(player, "Attribute: %s", ap == catchall ? "Default Attribute" : AL_NAME(ap)); notify_format(player, - " Flags: %s", privs_to_string(attr_privs_view, - AL_FLAGS(ap))); + " Flags: %s", privs_to_string(attr_privs_view, + AL_FLAGS(ap))); notify_format(player, " Creator: %s", unparse_dbref(AL_CREATOR(ap))); /* Now Locks */ if(!(AL_RLock(ap) == TRUE_BOOLEXP)) diff --git a/src/attrib.c b/src/attrib.c index 2e08e42..5cf215a 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -44,7 +44,7 @@ extern PRIV attr_privs_view[]; dbref atr_on_obj = NOTHING; static int real_atr_clr(dbref thinking, char const *atr, dbref player, - int we_are_wiping); + int we_are_wiping); dbref global_parent_depth[] = { 0, 0 }; @@ -376,7 +376,7 @@ atrflag_to_string(int mask) */ static int can_create_attr(dbref player, dbref obj, char const *atr_name, - unsigned int flags) + unsigned int flags) { char *p; ATTR tmpatr, *atr; @@ -1916,7 +1916,7 @@ do_set_atr(dbref thing, const char *RESTRICT atr, const char *RESTRICT s, was_listener = Listener(thing); res = s ? atr_add(thing, name, s, player, - (flags & 0x02) ? AF_NOPROG : 0) + (flags & 0x02) ? AF_NOPROG : AF_EMPTY_FLAGS) : atr_clr(thing, name, player); switch (res) { case AE_SAFE: @@ -2377,10 +2377,10 @@ atr_clear_children(dbref player, dbref thing, ATTR *root) sub && string_prefix(AL_NAME(sub), AL_NAME(root)); sub = next) { if (AL_FLAGS(sub) & AF_ROOT) { if (!atr_clear_children(player, thing, sub)) { - skipped++; - next = AL_NEXT(sub); - prev = sub; - continue; + skipped++; + next = AL_NEXT(sub); + prev = sub; + continue; } } diff --git a/src/bsd.c b/src/bsd.c index b3269b0..01ab285 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -27,8 +27,8 @@ #define EINTR WSAEINTR #define EWOULDBLOCK WSAEWOULDBLOCK #define MAXHOSTNAMELEN 32 -#pragma warning( disable : 4761) /* disable warning re conversion */ -#else /* !WIN32 */ +#pragma warning( disable : 4761) /* disable warning re conversion */ +#else /* !WIN32 */ #ifdef I_SYS_FILE #include #endif @@ -52,7 +52,7 @@ #ifdef I_SYS_STAT #include #endif -#endif /* !WIN32 */ +#endif /* !WIN32 */ #include #ifdef I_SYS_WAIT #include @@ -388,7 +388,7 @@ static void parse_puebloclient(DESC *d, char *command); static int dump_messages(DESC *d, dbref player, int new); static int check_connect(DESC *d, const char *msg); static void parse_connect(const char *msg, char *command, char *user, - char *pass); + char *pass); static void close_sockets(void); dbref find_player_by_desc(int port); static DESC *lookup_desc(dbref executor, const char *name); @@ -400,7 +400,7 @@ void reaper(int sig); sig_atomic_t dump_error = 0; WAIT_TYPE dump_status = 0; #endif -extern Pid_t forked_dump_pid; /**< Process id of forking dump process */ +extern Pid_t forked_dump_pid; /**< Process id of forking dump process */ static void dump_users(DESC *call_by, char *match, int doing); static const char *time_format_1(long int dt); static const char *time_format_2(long int dt); @@ -464,7 +464,7 @@ mainthread(int argc, char **argv) */ int main(int argc, char **argv) -#endif /* WIN32SERVICES */ +#endif /* WIN32SERVICES */ { #ifdef AUTORESTART FILE *id; @@ -489,10 +489,10 @@ main(int argc, char **argv) exit(1); } } -#endif /* WIN32 */ +#endif /* WIN32 */ #ifdef HAS_GETRLIMIT - init_rlimit(); /* unlimit file descriptors */ + init_rlimit(); /* unlimit file descriptors */ #endif /* These are FreeBSDisms to fix floating point exceptions */ @@ -503,6 +503,8 @@ main(int argc, char **argv) fpsetmask(0L); #endif + options.mem_check = 1; + time(&mudtime); /* If we have setlocale, call it to set locale info @@ -662,7 +664,7 @@ main(int argc, char **argv) #ifdef HAS_GETRUSAGE rusage_stats(); -#endif /* HAS_RUSAGE */ +#endif /* HAS_RUSAGE */ do_rawlog(LT_ERR, T("MUSH shutdown completed.")); @@ -673,12 +675,12 @@ main(int argc, char **argv) #ifdef WIN32SERVICES shutdown_checkpoint(); #endif - WSACleanup(); /* clean up */ + WSACleanup(); /* clean up */ #else exit(0); #endif } -#endif /* BOOLEXP_DEBUGGING */ +#endif /* BOOLEXP_DEBUGGING */ /** Close and reopen the logfiles - called on SIGHUP */ void @@ -690,8 +692,8 @@ reopen_logs(void) newerr = fopen(errlog, "a"); if (!newerr) { fprintf(stderr, - T("Unable to open %s. Error output continues to stderr.\n"), - errlog); + T("Unable to open %s. Error output continues to stderr.\n"), + errlog); } else { if (!freopen(errlog, "a", stderr)) { printf(T("Ack! Failed reopening stderr!")); @@ -841,7 +843,7 @@ update_quotas(struct timeval *last, struct timeval *current) for (d = descriptor_list; d; d = d->next) { d->quota += COMMANDS_PER_TIME * nslices; if (d->quota > COMMAND_BURST_SIZE) - d->quota = COMMAND_BURST_SIZE; + d->quota = COMMAND_BURST_SIZE; } } } @@ -929,7 +931,7 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) sslsock = make_socket(sslport, NULL, NULL, SSL_IP_ADDR); ssl_master_socket = ssl_setup_socket(sslsock); if (sslsock >= maxd) - maxd = sslsock + 1; + maxd = sslsock + 1; } #endif } @@ -939,7 +941,7 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) #ifndef COMPILE_CONSOLE avail_descriptors = how_many_fds() - 4; #ifdef INFO_SLAVE - avail_descriptors -= 2; /* reserve some more for setting up the slave */ + avail_descriptors -= 2; /* reserve some more for setting up the slave */ FD_ZERO(&info_pending); #endif @@ -970,14 +972,14 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) #ifndef WIN32 if (dump_error) { if (WIFSIGNALED(dump_status)) { - do_rawlog(LT_ERR, T("ERROR! forking dump exited with signal %d"), - WTERMSIG(dump_status)); - flag_broadcast("ROYALTY WIZARD", 0, - T("GAME: ERROR! Forking database save failed!")); + do_rawlog(LT_ERR, T("ERROR! forking dump exited with signal %d"), + WTERMSIG(dump_status)); + flag_broadcast("ROYALTY WIZARD", 0, + T("GAME: ERROR! Forking database save failed!")); } else if (WIFEXITED(dump_status) && WEXITSTATUS(dump_status) == 0) { - time(&globals.last_dump_time); - if (DUMP_NOFORK_COMPLETE && *DUMP_NOFORK_COMPLETE) - flag_broadcast(0, 0, "%s", DUMP_NOFORK_COMPLETE); + time(&globals.last_dump_time); + if (DUMP_NOFORK_COMPLETE && *DUMP_NOFORK_COMPLETE) + flag_broadcast(0, 0, "%s", DUMP_NOFORK_COMPLETE); } dump_error = 0; dump_status = 0; @@ -985,11 +987,11 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) #if defined(INFO_SLAVE) && !defined(COMPILE_CONSOLE) if (slave_error) { do_rawlog(LT_ERR, T("info_slave on pid %d exited unexpectedly!"), - slave_error); + slave_error); slave_error = 0; } #endif -#endif /* !WIN32 */ +#endif /* !WIN32 */ if (signal_shutdown_flag) { flag_broadcast(0, 0, T("GAME: Shutdown by external signal")); @@ -1284,10 +1286,10 @@ new_connection(int oldsock, int *result, int use_ssl) *bp = '\0'; if (Forbidden_Site(tbuf1) || Forbidden_Site(tbuf2)) { if (!Deny_Silent_Site(tbuf1, AMBIGUOUS) - || !Deny_Silent_Site(tbuf2, AMBIGUOUS)) { + || !Deny_Silent_Site(tbuf2, AMBIGUOUS)) { do_log(LT_CONN, 0, 0, "[%d/%s/%s] %s (%s %s)", newsock, tbuf1, tbuf2, - T("Refused connection"), T("remote port"), - hi ? hi->port : T("(unknown)")); + T("Refused connection"), T("remote port"), + hi ? hi->port : T("(unknown)")); } shutdown(newsock, 2); closesocket(newsock); @@ -1297,7 +1299,7 @@ new_connection(int oldsock, int *result, int use_ssl) return 0; } do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Connection opened."), newsock, tbuf1, - tbuf2); + tbuf2); set_keepalive(newsock); return initializesock(newsock, tbuf1, tbuf2, use_ssl); } @@ -1365,7 +1367,7 @@ fcache_read(FBLOCK *fb, const char *filename) if ((fh = CreateFile(filename, GENERIC_READ, 0, NULL, - OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) + OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) return -1; if (!GetFileInformationByHandle(fh, &sb)) { @@ -1407,7 +1409,7 @@ fcache_read(FBLOCK *fb, const char *filename) if (fstat(fd, &sb) < 0) { do_log(LT_ERR, 0, 0, T("Couldn't get the size of text file '%s'"), - filename); + filename); close(fd); reserve_fd(); return -1; @@ -1416,7 +1418,7 @@ fcache_read(FBLOCK *fb, const char *filename) if (!(fb->buff = mush_malloc(sb.st_size, "fcache_data"))) { do_log(LT_ERR, 0, 0, T("Couldn't allocate %d bytes of memory for '%s'!"), - (int) sb.st_size, filename); + (int) sb.st_size, filename); close(fd); reserve_fd(); return -1; @@ -1435,7 +1437,7 @@ fcache_read(FBLOCK *fb, const char *filename) reserve_fd(); fb->len = sb.st_size; } -#endif /* Posix read code */ +#endif /* Posix read code */ return fb->len; } @@ -1572,7 +1574,7 @@ shutdownsock(DESC *d) if (d->connected) { do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Logout by %s(#%d)"), - d->descriptor, d->addr, d->ip, Name(d->player), d->player); + d->descriptor, d->addr, d->ip, Name(d->player), d->player); if (d->connected != 2) { fcache_dump(d, fcache.quit_fcache, NULL); /* Player was not allowed to log in from the connect screen */ @@ -1592,15 +1594,15 @@ shutdownsock(DESC *d) if (MAX_LOGINS) { login_number--; if (!under_limit && (login_number < MAX_LOGINS)) { - under_limit = 1; - do_log(LT_CONN, 0, 0, - T("Below maximum player limit of %d. Logins enabled."), - MAX_LOGINS); + under_limit = 1; + do_log(LT_CONN, 0, 0, + T("Below maximum player limit of %d. Logins enabled."), + MAX_LOGINS); } } } else { do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Connection closed, never connected."), - d->descriptor, d->addr, d->ip); + d->descriptor, d->addr, d->ip); } process_output(d); clearstrings(d); @@ -1672,7 +1674,7 @@ shutdownsock(DESC *d) closesocket(d->descriptor); if (d->prev) d->prev->next = d->next; - else /* d was the first one! */ + else /* d was the first one! */ descriptor_list = d->next; if (d->next) d->next->prev = d->prev; @@ -1822,7 +1824,7 @@ make_info_slave(void) return; } if (getnameinfo(&addr.addr, opt, NULL, 0, num, sizeof num, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { + NI_NUMERICHOST | NI_NUMERICSERV) != 0) { perror("getting address of slave stream socket"); fflush(stderr); closesocket(info_slave); @@ -1848,20 +1850,20 @@ make_info_slave(void) info_slave = socks[0]; closesocket(socks[1]); do_rawlog(LT_ERR, - "Spawning info slave using socketpair, pid %d, ident %d", - child, USE_IDENT); + "Spawning info slave using socketpair, pid %d, ident %d", + child, USE_IDENT); #else do_rawlog(LT_ERR, "Spawning info slave on port %s, pid %d, ident %d", - num, child, USE_IDENT); + num, child, USE_IDENT); #endif } else { /* Close unneeded fds and sockets */ for (n = 3; n < maxd; n++) { if (n == fileno(stderr)) - continue; + continue; #ifdef HAS_SOCKETPAIR if (n == socks[1]) - continue; + continue; #endif close(n); } @@ -1870,10 +1872,10 @@ make_info_slave(void) #endif if (!USE_IDENT) execl("./info_slave", "./info_slave", num, "-1", USE_DNS ? "1" : "0", - (char *) NULL); + (char *) NULL); else execl("./info_slave", "./info_slave", num, tprintf("%d", IDENT_TIMEOUT), - USE_DNS ? "1" : "0", (char *) NULL); + USE_DNS ? "1" : "0", (char *) NULL); perror("execing info slave"); exit(1); } @@ -1919,7 +1921,7 @@ promote_info_slave(void) do_rawlog(LT_ERR, "Accepted info slave from unix-domain socket"); #else if (getnameinfo(&addr.addr, addr_len, NULL, 0, port, sizeof port, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { + NI_NUMERICHOST | NI_NUMERICSERV) != 0) { perror("getting info slave port number"); } else { do_rawlog(LT_ERR, "Accepted info slave from port %s", port); @@ -1937,7 +1939,7 @@ query_info_slave(int fd) { int size, slen; socklen_t llen, rlen; - static char buf[1024]; /* overkill */ + static char buf[1024]; /* overkill */ union sockaddr_u laddr, raddr; char *bp; struct hostname_info *hi; @@ -1975,12 +1977,12 @@ query_info_slave(int fd) if (Forbidden_Site(buf)) { char port[NI_MAXSERV]; if (getnameinfo(&raddr.addr, rlen, NULL, 0, port, sizeof port, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) + NI_NUMERICHOST | NI_NUMERICSERV) != 0) perror("getting remote port number"); else { if (!Deny_Silent_Site(buf, AMBIGUOUS)) { - do_log(LT_CONN, 0, 0, T("[%d/%s] Refused connection (remote port %s)"), - fd, buf, port); + do_log(LT_CONN, 0, 0, T("[%d/%s] Refused connection (remote port %s)"), + fd, buf, port); } } shutdown(fd, 2); @@ -2030,7 +2032,7 @@ static void reap_info_slave(void) { int fd, len, size; - static char buf[10000]; /* overkill */ + static char buf[10000]; /* overkill */ char *bp, *bp2; struct iovec dat[2]; @@ -2104,22 +2106,22 @@ reap_info_slave(void) *bp2++ = '\0'; /* buf is ip addr, bp is local port^ident info */ if ((bp = strchr(bp2, '^'))) - *bp++ = '\0'; + *bp++ = '\0'; } /* Now, either buf = ipaddr, bp2 = port, bp = ident info, * or buf = ipaddr, bp2 = port */ if (Forbidden_Site(buf) || (bp && Forbidden_Site(bp))) { if (!Deny_Silent_Site(buf, AMBIGUOUS) || !Deny_Silent_Site(bp, AMBIGUOUS)) { - do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Refused connection."), fd, - bp ? bp : "", buf); + do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Refused connection."), fd, + bp ? bp : "", buf); } shutdown(fd, 2); closesocket(fd); return; } do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Connection opened."), fd, - bp ? bp : "", buf); + bp ? bp : "", buf); set_keepalive(fd); (void) initializesock(fd, bp ? bp : buf, buf, (atoi(bp2) == SSLPORT)); } @@ -2271,13 +2273,13 @@ process_output(DESC *d) d->output_chars += cnt; if (cnt == cur->nchars) { if (!cur->nxt) - d->output.tail = qp; + d->output.tail = qp; *qp = cur->nxt; #ifdef DEBUG do_rawlog(LT_ERR, "free_text_block(0x%x) at 2.", cur); -#endif /* DEBUG */ +#endif /* DEBUG */ free_text_block(cur); - continue; /* do not adv ptr */ + continue; /* do not adv ptr */ } cur->nchars -= cnt; cur->start += cnt; @@ -2328,7 +2330,7 @@ setup_telnet(DESC *d) unsigned char extra_options[6] = "\xFF\xFD\x1F" "\xFF\xFD\x18"; d->conn_flags &= ~CONN_TELNET_QUERY; do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Switching to Telnet mode."), - d->descriptor, d->addr, d->ip); + d->descriptor, d->addr, d->ip); queue_newwrite(d, extra_options, 6); process_output(d); } @@ -2493,7 +2495,7 @@ handle_telnet(DESC *d, unsigned char **q, unsigned char *qend) queue_newwrite(d, reply, 6); } else if (**q == TN_SGA || **q == TN_NAWS) { /* This is good to be at. */ - } else { /* Refuse options we don't handle */ + } else { /* Refuse options we don't handle */ unsigned char reply[3]; reply[0] = IAC; reply[1] = DONT; @@ -2502,7 +2504,7 @@ handle_telnet(DESC *d, unsigned char **q, unsigned char *qend) process_output(d); } break; - case DO: /* Client is asking us to do something */ + case DO: /* Client is asking us to do something */ setup_telnet(d); if (*q >= qend) return -1; @@ -2526,18 +2528,18 @@ handle_telnet(DESC *d, unsigned char **q, unsigned char *qend) process_output(d); } break; - case WONT: /* Client won't do something we want. */ - case DONT: /* Client doesn't want us to do something */ + case WONT: /* Client won't do something we want. */ + case DONT: /* Client doesn't want us to do something */ setup_telnet(d); #ifdef DEBUG_TELNET fprintf(stderr, "Got IAC %s 0x%x\n", **q == WONT ? "WONT" : "DONT", - *(*q + 1)); + *(*q + 1)); #endif if (*q + 1 >= qend) return -1; (*q)++; break; - default: /* Also catches IAC IAC for a literal 255 */ + default: /* Also catches IAC IAC for a literal 255 */ return 0; } return 1; @@ -2552,7 +2554,7 @@ process_input_helper(DESC *d, char *tbuf1, int got) if (!d->raw_input) { d->raw_input = (unsigned char *) mush_malloc(sizeof(char) * MAX_COMMAND_LEN, - "descriptor_raw_input"); + "descriptor_raw_input"); if (!d->raw_input) mush_panic("Out of memory"); d->raw_input_at = d->raw_input; @@ -2619,34 +2621,34 @@ process_input(DESC *d, int output_ready __attribute__ ((__unused__))) if (ssl_need_handshake(d->ssl_state)) { d->ssl_state = ssl_handshake(d->ssl); if (d->ssl_state < 0) { - /* Fatal error */ - ssl_close_connection(d->ssl); - d->ssl = NULL; - d->ssl_state = 0; - return 0; + /* Fatal error */ + ssl_close_connection(d->ssl); + d->ssl = NULL; + d->ssl_state = 0; + return 0; } else if (ssl_need_handshake(d->ssl_state)) { - /* We're still not ready to send to this connection. Alas. */ - return 1; + /* We're still not ready to send to this connection. Alas. */ + return 1; } } /* Insure that we're not in a state where we need an SSL_accept() */ if (ssl_need_accept(d->ssl_state)) { d->ssl_state = ssl_accept(d->ssl); if (d->ssl_state < 0) { - /* Fatal error */ - ssl_close_connection(d->ssl); - d->ssl = NULL; - d->ssl_state = 0; - return 0; + /* Fatal error */ + ssl_close_connection(d->ssl); + d->ssl = NULL; + d->ssl_state = 0; + return 0; } else if (ssl_need_accept(d->ssl_state)) { - /* We're still not ready to send to this connection. Alas. */ - return 1; + /* We're still not ready to send to this connection. Alas. */ + return 1; } } /* It's an SSL connection, proceed accordingly */ d->ssl_state = ssl_read(d->ssl, d->ssl_state, 1, output_ready, tbuf1, sizeof tbuf1, - &got); + &got); if (d->ssl_state < 0) { /* Fatal error */ ssl_close_connection(d->ssl); @@ -2676,9 +2678,9 @@ process_input(DESC *d, int output_ready __attribute__ ((__unused__))) #else if ((errno == EWOULDBLOCK) || (errno == EINTR)) #endif - return 1; + return 1; else - return 0; + return 0; } #ifndef COMPILE_CONSOLE #ifdef HAS_OPENSSL @@ -2814,16 +2816,16 @@ do_command(DESC *d, char *command) } else if (!strncmp(command, "SCREENHEIGHT", 12)) { d->height = parse_integer(command + 12); } else if (SUPPORT_PUEBLO - && !strncmp(command, PUEBLO_COMMAND, strlen(PUEBLO_COMMAND))) { + && !strncmp(command, PUEBLO_COMMAND, strlen(PUEBLO_COMMAND))) { parse_puebloclient(d, command); if (!(d->conn_flags & CONN_HTML)) { queue_newwrite(d, (unsigned char *) PUEBLO_SEND, strlen(PUEBLO_SEND)); process_output(d); do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Switching to Pueblo mode."), - d->descriptor, d->addr, d->ip); + d->descriptor, d->addr, d->ip); d->conn_flags |= CONN_HTML; if (!d->connected) - welcome_user(d); + welcome_user(d); } } else { if (d->connected) { @@ -2847,7 +2849,7 @@ do_command(DESC *d, char *command) global_eval_context.cplr = NOTHING; } else { if (!check_connect(d, command)) - return 0; + return 0; } } return 1; @@ -2862,9 +2864,9 @@ parse_puebloclient(DESC *d, char *command) p += 5; if ((end = strchr(p, '"'))) { if ((end > p) && ((end - p) <= PUEBLO_CHECKSUM_LEN)) { - /* Got it! */ - strncpy(d->checksum, p, end - p); - d->checksum[end - p] = '\0'; + /* Got it! */ + strncpy(d->checksum, p, end - p); + d->checksum[end - p] = '\0'; } } } @@ -2888,8 +2890,8 @@ dump_messages(DESC *d, dbref player, int isnew) if (under_limit && (login_number > MAX_LOGINS)) { under_limit = 0; do_rawlog(LT_CONN, - T("Limit of %d players reached. Logins disabled.\n"), - MAX_LOGINS); + T("Limit of %d players reached. Logins disabled.\n"), + MAX_LOGINS); } } /* give players a message on connection */ @@ -2922,7 +2924,7 @@ dump_messages(DESC *d, dbref player, int isnew) if (tmpd->player == player) { num++; if (is_hidden) - tmpd->hide = 1; + tmpd->hide = 1; } } /* give permanent text messages */ @@ -3054,75 +3056,75 @@ check_connect(DESC *d, const char *msg) if (!Site_Can_Create(d->addr) || !Site_Can_Create(d->ip)) { fcache_dump(d, fcache.register_fcache, NULL); if (!Deny_Silent_Site(d->addr, AMBIGUOUS) - && !Deny_Silent_Site(d->ip, AMBIGUOUS)) { - do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Refused create for '%s'."), - d->descriptor, d->addr, d->ip, user); + && !Deny_Silent_Site(d->ip, AMBIGUOUS)) { + do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Refused create for '%s'."), + d->descriptor, d->addr, d->ip, user); } return 0; } if (!options.login_allow || !options.create_allow) { if (!options.login_allow) - fcache_dump(d, fcache.down_fcache, NULL); + fcache_dump(d, fcache.down_fcache, NULL); else - fcache_dump(d, fcache.register_fcache, NULL); + fcache_dump(d, fcache.register_fcache, NULL); do_rawlog(LT_CONN, - "REFUSED CREATION for %s from %s on descriptor %d.\n", - user, d->addr, d->descriptor); + "REFUSED CREATION for %s from %s on descriptor %d.\n", + user, d->addr, d->descriptor); return 0; } else if (MAX_LOGINS && !under_limit) { fcache_dump(d, fcache.full_fcache, NULL); do_rawlog(LT_CONN, - "REFUSED CREATION for %s from %s on descriptor %d.\n", - user, d->addr, d->descriptor); + "REFUSED CREATION for %s from %s on descriptor %d.\n", + user, d->addr, d->descriptor); return 0; } player = create_player(user, password, d->addr, d->ip); if (player == NOTHING) { queue_string_eol(d, T(create_fail)); do_log(LT_CONN, 0, 0, - T("[%d/%s/%s] Failed create for '%s' (bad name)."), - d->descriptor, d->addr, d->ip, user); + T("[%d/%s/%s] Failed create for '%s' (bad name)."), + d->descriptor, d->addr, d->ip, user); } else if (player == AMBIGUOUS) { queue_string_eol(d, T(password_fail)); do_log(LT_CONN, 0, 0, - T("[%d/%s/%s] Failed create for '%s' (bad password)."), - d->descriptor, d->addr, d->ip, user); + T("[%d/%s/%s] Failed create for '%s' (bad password)."), + d->descriptor, d->addr, d->ip, user); } else { do_log(LT_CONN, 0, 0, "[%d/%s/%s] Created %s(#%d)", - d->descriptor, d->addr, d->ip, Name(player), player); + d->descriptor, d->addr, d->ip, Name(player), player); if ((dump_messages(d, player, 1)) == 0) { - d->connected = 2; - return 0; + d->connected = 2; + return 0; } - } /* successful player creation */ + } /* successful player creation */ } else if (string_prefix("register", command)) { if (!Site_Can_Register(d->addr) || !Site_Can_Register(d->ip)) { fcache_dump(d, fcache.register_fcache, NULL); if (!Deny_Silent_Site(d->addr, AMBIGUOUS) - && !Deny_Silent_Site(d->ip, AMBIGUOUS)) { - do_log(LT_CONN, 0, 0, - T("[%d/%s/%s] Refused registration (bad site) for '%s'."), - d->descriptor, d->addr, d->ip, user); + && !Deny_Silent_Site(d->ip, AMBIGUOUS)) { + do_log(LT_CONN, 0, 0, + T("[%d/%s/%s] Refused registration (bad site) for '%s'."), + d->descriptor, d->addr, d->ip, user); } return 0; } if (!options.create_allow) { fcache_dump(d, fcache.register_fcache, NULL); do_rawlog(LT_CONN, - "Refused registration (creation disabled) for %s from %s on descriptor %d.\n", - user, d->addr, d->descriptor); + "Refused registration (creation disabled) for %s from %s on descriptor %d.\n", + user, d->addr, d->descriptor); return 0; } if ((player = email_register_player(user, password, d->addr, d->ip)) == - NOTHING) { + NOTHING) { queue_string_eol(d, T(register_fail)); do_log(LT_CONN, 0, 0, T("[%d/%s/%s] Failed registration for '%s'."), - d->descriptor, d->addr, d->ip, user); + d->descriptor, d->addr, d->ip, user); } else { queue_string_eol(d, T(register_success)); do_log(LT_CONN, 0, 0, "[%d/%s/%s] Registered %s(#%d) to %s", - d->descriptor, d->addr, d->ip, Name(player), player, password); + d->descriptor, d->addr, d->ip, Name(player), player, password); } /* Whether it succeeds or fails, leave them connected */ @@ -3159,17 +3161,17 @@ parse_connect(const char *msg1, char *command, char *user, char *pass) for (; *msg && ((*msg == '\"') || isspace(*msg)); msg++) ; while (*msg && (*msg != '\"')) { while (*msg && !isspace(*msg) && (*msg != '\"')) - *p++ = *msg++; + *p++ = *msg++; if (*msg == '\"') { - msg++; - while (*msg && isspace(*msg)) - msg++; - break; + msg++; + while (*msg && isspace(*msg)) + msg++; + break; } while (*msg && isspace(*msg)) - msg++; + msg++; if (*msg && (*msg != '\"')) - *p++ = ' '; + *p++ = ' '; } } else while (*msg && isprint(*msg) && !isspace(*msg)) @@ -3303,16 +3305,16 @@ do_page_port(dbref player, const char *pc, const char *message) switch (key) { case 1: safe_format(tbuf, &tbp, T("From afar, %s%s%s"), Name(player), gap, - message + 1); + message + 1); notify_format(player, T("Long distance to %s: %s%s%s"), - target != NOTHING ? Name(target) : - T("a connecting player"), Name(player), gap, message + 1); + target != NOTHING ? Name(target) : + T("a connecting player"), Name(player), gap, message + 1); break; case 3: safe_format(tbuf, &tbp, T("%s pages: %s"), Name(player), message); notify_format(player, T("You paged %s with '%s'."), - target != NOTHING ? Name(target) : - T("a connecting player"), message); + target != NOTHING ? Name(target) : + T("a connecting player"), message); break; } *tbp = '\0'; @@ -3340,8 +3342,8 @@ inactive_desc(dbref player) DESC_ITER_CONN(d) { if (d->player == player) { numd++; - if (now - d->last_time > 60) - in = d; + if (difftime(now, d->last_time) > 60.0) + in = d; } } if (numd > 1) @@ -3711,7 +3713,7 @@ time_format_1(time_t dt) delta = gmtime(&dt); if (delta->tm_yday > 0) { sprintf(buf, "%dd %02d:%02d", - delta->tm_yday, delta->tm_hour, delta->tm_min); + delta->tm_yday, delta->tm_hour, delta->tm_min); } else { sprintf(buf, "%02d:%02d", delta->tm_hour, delta->tm_min); } @@ -3763,13 +3765,13 @@ announce_connect(dbref player, int isnew, int num) /* Redundant, but better for translators */ if (Dark(player)) { sprintf(tbuf1, (num > 1) ? T("%s has DARK-reconnected.") : - T("%s has DARK-connected."), Name(player)); + T("%s has DARK-connected."), Name(player)); } else if (hidden(player)) { sprintf(tbuf1, (num > 1) ? T("%s has HIDDEN-reconnected.") : - T("%s has HIDDEN-connected."), Name(player)); + T("%s has HIDDEN-connected."), Name(player)); } else { sprintf(tbuf1, (num > 1) ? T("%s has reconnected.") : - T("%s has connected."), Name(player)); + T("%s has connected."), Name(player)); } /* send out messages */ @@ -3828,13 +3830,13 @@ announce_connect(dbref player, int isnew, int num) case TYPE_ROOM: /* check every object in the room for a connect action */ DOLIST(obj, Contents(zone)) { - (void) queue_attribute(obj, "ACONNECT", player); + (void) queue_attribute(obj, "ACONNECT", player); } break; default: do_log(LT_ERR, 0, 0, - T("Invalid zone #%d for %s(#%d) has bad type %d"), zone, - Name(player), player, Typeof(zone)); + T("Invalid zone #%d for %s(#%d) has bad type %d"), zone, + Name(player), player, Typeof(zone)); } } /* now try the master room */ @@ -3934,13 +3936,13 @@ announce_disconnect(dbref player) /* Redundant, but better for translators */ if (Dark(player)) { sprintf(tbuf1, (num < 2) ? T("%s has DARK-disconnected.") : - T("%s has partially DARK-disconnected."), Name(player)); + T("%s has partially DARK-disconnected."), Name(player)); } else if (hidden(player)) { sprintf(tbuf1, (num < 2) ? T("%s has HIDDEN-disconnected.") : - T("%s has partially HIDDEN-disconnected."), Name(player)); + T("%s has partially HIDDEN-disconnected."), Name(player)); } else { sprintf(tbuf1, (num < 2) ? T("%s has disconnected.") : - T("%s has partially disconnected."), Name(player)); + T("%s has partially disconnected."), Name(player)); } if (!Dark(player)) flag_broadcast(0, "MONITOR", "%s %s", T("GAME:"), tbuf1); @@ -3965,8 +3967,8 @@ do_motd(dbref player, enum motd_type key, const char *message) if (!Site(player) && key != MOTD_LIST) { notify(player, - T - ("You may get 15 minutes of fame and glory in life, but not right now.")); + T + ("You may get 15 minutes of fame and glory in life, but not right now.")); return; } switch (key) { @@ -4015,7 +4017,7 @@ do_doing(dbref player, const char *message) /* now smash undesirable characters and truncate */ for (i = 0; i < DOING_LEN; i++) { if ((buf[i] == '\r') || (buf[i] == '\n') || - (buf[i] == '\t') || (buf[i] == BEEP_CHAR)) + (buf[i] == '\t') || (buf[i] == BEEP_CHAR)) buf[i] = ' '; } buf[DOING_LEN - 1] = '\0'; @@ -4065,7 +4067,7 @@ do_poll(dbref player, const char *message, int clear) strncpy(poll_msg, remove_markup(message, NULL), DOING_LEN - 1); for (i = 0; i < DOING_LEN; i++) { if ((poll_msg[i] == '\r') || (poll_msg[i] == '\n') || - (poll_msg[i] == '\t') || (poll_msg[i] == BEEP_CHAR)) + (poll_msg[i] == '\t') || (poll_msg[i] == BEEP_CHAR)) poll_msg[i] = ' '; } poll_msg[DOING_LEN - 1] = '\0'; @@ -4095,15 +4097,15 @@ short_page(const char *match) for (d = descriptor_list; d; d = d->next) { if (d->connected) { if (match && !string_prefix(Name(d->player), match)) - continue; + continue; if (!strcasecmp(Name(d->player), match)) { - count = 1; - who1 = d->player; - break; + count = 1; + who1 = d->player; + break; } if (who1 == NOTHING || d->player != who1) { - who1 = d->player; - count++; + who1 = d->player; + count++; } } } @@ -4275,8 +4277,8 @@ most_conn_time(dbref player) DESC *d, *match = NULL; DESC_ITER_CONN(d) { if ((d->player == player) && !Hidden(d) && (!match || - (d->connected_at > - match->connected_at))) + (d->connected_at > + match->connected_at))) match = d; } if (match) { @@ -4297,7 +4299,7 @@ most_conn_time_priv(dbref player) DESC *d, *match = NULL; DESC_ITER_CONN(d) { if ((d->player == player) && (!match || - (d->connected_at > match->connected_at))) + (d->connected_at > match->connected_at))) match = d; } if (match) { @@ -4318,7 +4320,7 @@ least_idle_time(dbref player) DESC *d, *match = NULL; DESC_ITER_CONN(d) { if ((d->player == player) && !Hidden(d) && - (!match || (d->last_time > match->last_time))) + (!match || (d->last_time > match->last_time))) match = d; } if (match) { @@ -4718,7 +4720,7 @@ FUNCTION(fun_ports) target = lookup_player(args[0]); if (target == NOTHING) { target = match_result(executor, args[0], TYPE_PLAYER, - MAT_ABSOLUTE | MAT_PLAYER | MAT_ME); + MAT_ABSOLUTE | MAT_PLAYER | MAT_ME); } if (target != executor && !Priv_Who(executor) && !(Inherit_Powers(executor) && Priv_Who(Owner(executor)))) { @@ -4734,9 +4736,9 @@ FUNCTION(fun_ports) DESC_ITER_CONN(d) { if (d->player == target) { if (first) - first = 0; + first = 0; else - safe_chr(' ', buff, bp); + safe_chr(' ', buff, bp); safe_integer(d->descriptor, buff, bp); } } @@ -4763,7 +4765,7 @@ hide_player(dbref player, int hide) if (Can_Hide(player)) { DESC_ITER_CONN(d) { if (d->player == player) - d->hide = hide; + d->hide = hide; } } if (hide) @@ -4781,7 +4783,9 @@ inactivity_check(void) DESC *d, *nextd; ATTR *a; char tbuf[BUFFER_LEN]; - time_t now, idle, idle_for, unconnected_idle; + time_t now; + int idle, idle_for, unconnected_idle; + if (!INACTIVITY_LIMIT && !UNCONNECTED_LIMIT) return; now = mudtime; @@ -4789,11 +4793,22 @@ inactivity_check(void) unconnected_idle = UNCONNECTED_LIMIT ? UNCONNECTED_LIMIT : INT_MAX; for (d = descriptor_list; d; d = nextd) { nextd = d->next; - idle_for = now - d->last_time; + idle_for = (int) difftime(now, d->last_time); /* If they've been connected for 60 seconds without getting a telnet-option back, the client probably doesn't understand them */ - if ((d->conn_flags & CONN_TELNET_QUERY) && idle_for > 60) + if ((d->conn_flags & CONN_TELNET_QUERY) && difftime(now, d->connected_at) > 60) d->conn_flags &= ~CONN_TELNET_QUERY; +#ifndef COMPILE_CONSOLE + /* If they've been idle for 60 seconds and are set KEEPALIVE and using + a telnet-aware client, send a NOP */ + if (d->conn_flags & CONN_TELNET && idle_for >= 60 + && IS(d->player, TYPE_PLAYER, "KEEPALIVE")) { + const unsigned char nopmsg[2] = { IAC, NOP }; + queue_newwrite(d, nopmsg, 2); + process_output(d); + } +#endif + if(d->connected && GoodObject(d->player) && ((a = atr_get(d->player, "IDLE_TIMEOUT"))!=NULL)) { memset(tbuf, '\0', BUFFER_LEN); strncpy(tbuf, atr_value(a), BUFFER_LEN-1); @@ -4801,6 +4816,7 @@ inactivity_check(void) if(idle > 0) goto after_idle_atr_check; } + idle = INACTIVITY_LIMIT ? INACTIVITY_LIMIT : INT_MAX; after_idle_atr_check: if ((d->connected) ? (idle_for > idle ) : (idle_for > unconnected_idle)) { @@ -4840,9 +4856,9 @@ hidden(dbref player) DESC_ITER_CONN(d) { if (d->player == player) { if (Hidden(d)) - return 1; + return 1; else - return 0; + return 0; } } return 0; @@ -4998,7 +5014,7 @@ f_close(stream) } #define fclose(x) f_close(x) -#endif /* SUN_OS */ +#endif /* SUN_OS */ #ifdef COMPILE_CONSOLE void @@ -5147,18 +5163,18 @@ dump_reboot_db(void) putref(f, d->idle_total); putref(f, d->unidle_times); if (GoodObject(d->player)) - putref(f, d->player); + putref(f, d->player); else - putref(f, -1); + putref(f, -1); putref(f, d->last_time); if (d->output_prefix) - putstring(f, (char *) d->output_prefix); + putstring(f, (char *) d->output_prefix); else - putstring(f, "__NONE__"); + putstring(f, "__NONE__"); if (d->output_suffix) - putstring(f, (char *) d->output_suffix); + putstring(f, (char *) d->output_suffix); else - putstring(f, "__NONE__"); + putstring(f, "__NONE__"); putstring(f, d->addr); putstring(f, d->ip); putstring(f, d->doing); @@ -5207,7 +5223,7 @@ load_reboot_db(void) * If not, assume we're using the original format, in which the * sock appears first * */ - c = getc(f); /* Skip the V */ + c = getc(f); /* Skip the V */ if (c == 'V') { flags = getref(f); } else { @@ -5350,6 +5366,7 @@ load_reboot_db(void) tbuf1[strlen(tbuf1)+1] = '\0'; (void) atr_add(closed->player, "LASTACTIVITY", tbuf1, GOD, 0); announce_disconnect(closed->player); + mush_free(closed->ttype, "terminal description"); mush_free(closed, "descriptor"); closed = nextclosed; } diff --git a/src/bufferq.c b/src/bufferq.c index ad66f78..aaa029d 100644 --- a/src/bufferq.c +++ b/src/bufferq.c @@ -194,7 +194,7 @@ reallocate_bufferq(BUFFERQ * bq, int lines) */ char * iter_bufferq(BUFFERQ * bq, char **p, dbref *player, int *type, - time_t * timestamp) + time_t * timestamp) { static char tbuf1[BUFFER_LEN]; int size; @@ -206,7 +206,7 @@ iter_bufferq(BUFFERQ * bq, char **p, dbref *player, int *type, return NULL; if (!*p) - *p = bq->buffer; /* Reset to beginning */ + *p = bq->buffer; /* Reset to beginning */ memcpy(&size, *p, sizeof(size)); *p += sizeof(size); diff --git a/src/chunk.c b/src/chunk.c index 6c98c9e..d04c64f 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -235,7 +235,7 @@ #include "confmagic.h" #ifdef WIN32 -#pragma warning( disable : 4761) /* disable warning re conversion */ +#pragma warning( disable : 4761) /* disable warning re conversion */ #endif /* A whole bunch of debugging #defines. */ @@ -262,10 +262,10 @@ /* debug... */ #ifdef CHUNK_DEBUG #define ASSERT(x) assert(x) -#else /* CHUNK_DEBUG */ -static int ignore; /**< Used to shut up compiler warnings when not asserting */ +#else /* CHUNK_DEBUG */ +static int ignore; /**< Used to shut up compiler warnings when not asserting */ #define ASSERT(x) ignore++ -#endif /* CHUNK_DEBUG */ +#endif /* CHUNK_DEBUG */ /* * Sizes, limits, etc. @@ -528,26 +528,26 @@ static int ignore; /**< Used to shut up compiler warnings when not asserting */ * the rest of the 64K bytes of the region contain chunks. */ typedef struct region_header { - u_int_16 region_id; /**< will be INVALID_REGION_ID if not in use */ - u_int_16 first_free; /**< offset of 1st free chunk */ - struct region_header *prev; /**< linked list prev for LRU cache */ - struct region_header *next; /**< linked list next for LRU cache */ + u_int_16 region_id; /**< will be INVALID_REGION_ID if not in use */ + u_int_16 first_free; /**< offset of 1st free chunk */ + struct region_header *prev; /**< linked list prev for LRU cache */ + struct region_header *next; /**< linked list next for LRU cache */ } RegionHeader; #define FIRST_CHUNK_OFFSET_IN_REGION sizeof(RegionHeader) /** In-memory (never paged) region info. */ typedef struct region { - u_int_16 used_count; /**< number of used chunks */ - u_int_16 free_count; /**< number of free chunks */ - u_int_16 free_bytes; /**< number of free bytes (with headers) */ - u_int_16 largest_free_chunk; /**< largest single free chunk */ - unsigned int total_derefs; /**< total of all used chunk derefs */ - unsigned int period_last_touched; /**< "this" period, for deref counts; + u_int_16 used_count; /**< number of used chunks */ + u_int_16 free_count; /**< number of free chunks */ + u_int_16 free_bytes; /**< number of free bytes (with headers) */ + u_int_16 largest_free_chunk; /**< largest single free chunk */ + unsigned int total_derefs; /**< total of all used chunk derefs */ + unsigned int period_last_touched; /**< "this" period, for deref counts; we don't page in regions to update counts on period change! */ - RegionHeader *in_memory; /**< cache entry; NULL if paged out */ - u_int_16 oddballs[NUM_ODDBALLS]; /**< chunk offsets with odd derefs */ + RegionHeader *in_memory; /**< cache entry; NULL if paged out */ + u_int_16 oddballs[NUM_ODDBALLS]; /**< chunk offsets with odd derefs */ } Region; #define RegionDerefs(region) \ @@ -585,44 +585,44 @@ static u_int_32 curr_period; /* * Info about all regions */ -static u_int_32 region_count; /**< regions in use */ -static u_int_32 region_array_len; /**< length of regions array */ -static Region *regions; /**< regions array, realloced as (rarely) needed */ +static u_int_32 region_count; /**< regions in use */ +static u_int_32 region_array_len; /**< length of regions array */ +static Region *regions; /**< regions array, realloced as (rarely) needed */ /* * regions presently in memory */ -static u_int_32 cached_region_count; /**< number of regions in cache */ -static RegionHeader *cache_head; /**< most recently used region */ -static RegionHeader *cache_tail; /**< least recently used region */ +static u_int_32 cached_region_count; /**< number of regions in cache */ +static RegionHeader *cache_head; /**< most recently used region */ +static RegionHeader *cache_tail; /**< least recently used region */ /* * statistics */ -static int stat_used_short_count; /**< How many short chunks? */ -static int stat_used_short_bytes; /**< How much space in short chunks? */ -static int stat_used_medium_count; /**< How many medium chunks? */ -static int stat_used_medium_bytes; /**< How much space in medium chunks? */ -static int stat_used_long_count; /**< How many long chunks? */ -static int stat_used_long_bytes; /**< How much space in long chunks? */ -static int stat_deref_count; /**< Dereferences this period */ -static int stat_deref_maxxed; /**< Number of chunks with max derefs */ +static int stat_used_short_count; /**< How many short chunks? */ +static int stat_used_short_bytes; /**< How much space in short chunks? */ +static int stat_used_medium_count; /**< How many medium chunks? */ +static int stat_used_medium_bytes; /**< How much space in medium chunks? */ +static int stat_used_long_count; /**< How many long chunks? */ +static int stat_used_long_bytes; /**< How much space in long chunks? */ +static int stat_deref_count; /**< Dereferences this period */ +static int stat_deref_maxxed; /**< Number of chunks with max derefs */ /** histogram for average derefs of regions being paged in/out */ static int stat_paging_histogram[CHUNK_DEREF_MAX + 1]; -static int stat_page_out; /**< Number of page-outs */ -static int stat_page_in; /**< Number of page-ins */ -static int stat_migrate_slide; /**< Number of slide migrations */ -static int stat_migrate_move; /**< Number of move migrations */ -static int stat_migrate_away; /**< Number of chunk evictions */ -static int stat_create; /**< Number of chunk creations */ -static int stat_delete; /**< Number of chunk deletions */ +static int stat_page_out; /**< Number of page-outs */ +static int stat_page_in; /**< Number of page-ins */ +static int stat_migrate_slide; /**< Number of slide migrations */ +static int stat_migrate_move; /**< Number of move migrations */ +static int stat_migrate_away; /**< Number of chunk evictions */ +static int stat_create; /**< Number of chunk creations */ +static int stat_delete; /**< Number of chunk deletions */ /* * migration globals that are used for holding relevant data... */ -static int m_count; /**< The used length for the arrays. */ +static int m_count; /**< The used length for the arrays. */ static chunk_reference_t **m_references; /**< The passed-in references array. */ #ifdef CHUNK_PARANOID @@ -659,7 +659,7 @@ debug_log(char const *format, ...) rolling_pos = (rolling_pos + 1) % ROLLING_LOG_SIZE; #else if (format) - return; /* shut up the compiler warning */ + return; /* shut up the compiler warning */ #endif } @@ -714,11 +714,11 @@ debug_dump_region(u_int_16 region, FILE * fp) rhp = rp->in_memory; fprintf(fp, "region: id:%04x period:%-8x deref:%-8x (%-2x per chunk)\n", - region, rp->period_last_touched, rp->total_derefs, - RegionDerefs(region)); + region, rp->period_last_touched, rp->total_derefs, + RegionDerefs(region)); fprintf(fp, " #used:%-4x #free:%-4x fbytes:%-4x hole:%-4x ", - rp->used_count, rp->free_count, rp->free_bytes, - rp->largest_free_chunk); + rp->used_count, rp->free_count, rp->free_bytes, + rp->largest_free_chunk); if (rhp) fprintf(fp, "first:%-4x h_id:%-4x\n", rhp->first_free, rhp->region_id); else @@ -727,25 +727,25 @@ debug_dump_region(u_int_16 region, FILE * fp) if (rhp) { for (offset = FIRST_CHUNK_OFFSET_IN_REGION; - offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { + offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { fprintf(fp, "chunk:%c%4s %-6s off:%04x full:%04x ", - migratable(region, offset) ? '*' : ' ', - ChunkIsFree(region, offset) ? "FREE" : "", - ChunkIsShort(region, offset) ? "SHORT" : - (ChunkIsMedium(region, offset) ? "MEDIUM" : "LONG"), - offset, ChunkFullLen(region, offset)); + migratable(region, offset) ? '*' : ' ', + ChunkIsFree(region, offset) ? "FREE" : "", + ChunkIsShort(region, offset) ? "SHORT" : + (ChunkIsMedium(region, offset) ? "MEDIUM" : "LONG"), + offset, ChunkFullLen(region, offset)); if (ChunkIsFree(region, offset)) { - fprintf(fp, "next:%04x\n", ChunkNextFree(region, offset)); + fprintf(fp, "next:%04x\n", ChunkNextFree(region, offset)); } else { - fprintf(fp, "doff:%04x len:%04x ", - ChunkDataPtr(region, offset) - (unsigned char *) rhp, - ChunkLen(region, offset)); - count = ChunkDerefs(region, offset); - if (count == 0xFF) { - fprintf(fp, "deref:many\n"); - } else { - fprintf(fp, "deref:%04x\n", count); - } + fprintf(fp, "doff:%04x len:%04x ", + ChunkDataPtr(region, offset) - (unsigned char *) rhp, + ChunkLen(region, offset)); + count = ChunkDerefs(region, offset); + if (count == 0xFF) { + fprintf(fp, "deref:many\n"); + } else { + fprintf(fp, "deref:%04x\n", count); + } } } } @@ -767,7 +767,7 @@ verify_used_chunk(u_int_16 region, u_int_16 offset) pos < REGION_SIZE; pos += ChunkFullLen(region, pos)) { if (pos == offset) { if (ChunkIsFree(region, pos)) - mush_panic("Invalid reference to free chunk as used"); + mush_panic("Invalid reference to free chunk as used"); return; } } @@ -800,7 +800,7 @@ region_is_valid(u_int_16 region) if (region >= region_count) { do_rawlog(LT_ERR, "region 0x%04x is not valid: region_count is 0x%04x", - region, region_count); + region, region_count); return 0; } result = 1; @@ -808,21 +808,21 @@ region_is_valid(u_int_16 region) rp = regions + region; if (rp->used_count > REGION_SIZE / MIN_REMNANT_LEN) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: chunk count is ludicrous: 0x%04x", - region, rp->used_count); + "region 0x%04x is not valid: chunk count is ludicrous: 0x%04x", + region, rp->used_count); result = 0; } if (rp->free_count > REGION_SIZE / MIN_REMNANT_LEN) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: free count is ludicrous: 0x%04x", - region, rp->free_count); + "region 0x%04x is not valid: free count is ludicrous: 0x%04x", + region, rp->free_count); result = 0; } if (rp->largest_free_chunk > rp->free_bytes) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: largest free chunk > free bytes:" - " 0x%04x > 0x%04x", - region, rp->largest_free_chunk, rp->free_bytes); + "region 0x%04x is not valid: largest free chunk > free bytes:" + " 0x%04x > 0x%04x", + region, rp->largest_free_chunk, rp->free_bytes); result = 0; } if (!rp->in_memory) @@ -832,7 +832,7 @@ region_is_valid(u_int_16 region) if (rhp->region_id != region) { do_rawlog(LT_ERR, "region 0x%04x is not valid: region in cache is 0x%04x", - region, rhp->region_id); + region, rhp->region_id); result = 0; } dump = 0; @@ -847,8 +847,8 @@ region_is_valid(u_int_16 region) offset < REGION_SIZE; offset += len) { if (was_free && ChunkIsFree(region, offset)) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: uncoalesced free chunk:" - " 0x%04x (see map)", region, offset); + "region 0x%04x is not valid: uncoalesced free chunk:" + " 0x%04x (see map)", region, offset); result = 0; dump = 1; } @@ -858,80 +858,80 @@ region_is_valid(u_int_16 region) free_count++; free_bytes += len; if (largest_free < len) - largest_free = len; + largest_free = len; if (next_free != offset) { - do_rawlog(LT_ERR, - "region 0x%04x is not valid: free chain broken:" - " 0x%04x, expecting 0x%04x (see map)", - region, offset, next_free); - result = 0; - dump = 1; + do_rawlog(LT_ERR, + "region 0x%04x is not valid: free chain broken:" + " 0x%04x, expecting 0x%04x (see map)", + region, offset, next_free); + result = 0; + dump = 1; } next_free = ChunkNextFree(region, offset); } else { used_count++; total_derefs += ChunkDerefs(region, offset); if (ChunkIsMedium(region, offset) && - ChunkLen(region, offset) <= MAX_SHORT_CHUNK_LEN) { - do_rawlog(LT_ERR, - "region 0x%04x is not valid: medium chunk too small:" - " 0x%04x (see map)", region, offset); - result = 0; - dump = 1; + ChunkLen(region, offset) <= MAX_SHORT_CHUNK_LEN) { + do_rawlog(LT_ERR, + "region 0x%04x is not valid: medium chunk too small:" + " 0x%04x (see map)", region, offset); + result = 0; + dump = 1; } if (ChunkIsLong(region, offset) && - ChunkLen(region, offset) <= MAX_MEDIUM_CHUNK_LEN) { - do_rawlog(LT_ERR, - "region 0x%04x is not valid: long chunk too small:" - " 0x%04x (see map)", region, offset); - result = 0; - dump = 1; + ChunkLen(region, offset) <= MAX_MEDIUM_CHUNK_LEN) { + do_rawlog(LT_ERR, + "region 0x%04x is not valid: long chunk too small:" + " 0x%04x (see map)", region, offset); + result = 0; + dump = 1; } } } if (offset != REGION_SIZE) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: last chunk past bounds (see map)", - region); + "region 0x%04x is not valid: last chunk past bounds (see map)", + region); result = 0; } if (next_free != 0) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: free chain unterminated:" - " expecting 0x%04x (see map)", region, next_free); + "region 0x%04x is not valid: free chain unterminated:" + " expecting 0x%04x (see map)", region, next_free); result = 0; dump = 1; } if (rp->used_count != used_count) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: used count is wrong:" - " 0x%04x should be 0x%04x", region, rp->used_count, used_count); + "region 0x%04x is not valid: used count is wrong:" + " 0x%04x should be 0x%04x", region, rp->used_count, used_count); result = 0; } if (rp->total_derefs != total_derefs) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: total derefs is wrong:" - " 0x%04x should be 0x%04x", - region, rp->total_derefs, total_derefs); + "region 0x%04x is not valid: total derefs is wrong:" + " 0x%04x should be 0x%04x", + region, rp->total_derefs, total_derefs); result = 0; } if (rp->free_count != free_count) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: free count is wrong:" - " 0x%04x should be 0x%04x", region, rp->free_count, free_count); + "region 0x%04x is not valid: free count is wrong:" + " 0x%04x should be 0x%04x", region, rp->free_count, free_count); result = 0; } if (rp->free_bytes != free_bytes) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: free bytes is wrong:" - " 0x%04x should be 0x%04x", region, rp->free_bytes, free_bytes); + "region 0x%04x is not valid: free bytes is wrong:" + " 0x%04x should be 0x%04x", region, rp->free_bytes, free_bytes); result = 0; } if (rp->largest_free_chunk != largest_free) { do_rawlog(LT_ERR, - "region 0x%04x is not valid: largest free is wrong:" - " 0x%04x should be 0x%04x", - region, rp->largest_free_chunk, largest_free); + "region 0x%04x is not valid: largest free is wrong:" + " 0x%04x should be 0x%04x", + region, rp->largest_free_chunk, largest_free); result = 0; } if (dump) { @@ -955,8 +955,8 @@ region_is_valid(u_int_16 region) */ static void write_used_chunk(u_int_16 region, u_int_16 offset, u_int_16 full_len, - unsigned char const *data, u_int_16 data_len, - unsigned char derefs) + unsigned char const *data, u_int_16 data_len, + unsigned char derefs) { unsigned char *cptr = ChunkPointer(region, offset); if (full_len <= MAX_SHORT_CHUNK_LEN + CHUNK_SHORT_DATA_OFFSET) { @@ -991,7 +991,7 @@ write_used_chunk(u_int_16 region, u_int_16 offset, u_int_16 full_len, */ static void write_free_chunk(u_int_16 region, u_int_16 offset, u_int_16 full_len, - u_int_16 next) + u_int_16 next) { unsigned char *cptr = ChunkPointer(region, offset); if (full_len <= MAX_SHORT_CHUNK_LEN + CHUNK_SHORT_DATA_OFFSET) { @@ -1176,9 +1176,9 @@ split_hole(u_int_16 region, u_int_16 offset, u_int_16 full_len, int align) else { u_int_16 hole; for (hole = rp->in_memory->first_free; - hole; hole = ChunkNextFree(region, hole)) - if (ChunkNextFree(region, hole) == offset) - break; + hole; hole = ChunkNextFree(region, hole)) + if (ChunkNextFree(region, hole) == offset) + break; ASSERT(hole); write_next_free(region, hole, ChunkNextFree(region, offset)); } @@ -1197,15 +1197,15 @@ split_hole(u_int_16 region, u_int_16 offset, u_int_16 full_len, int align) if (align == 1) { rp->free_bytes -= full_len; write_free_chunk(region, offset + full_len, - hole_len - full_len, ChunkNextFree(region, offset)); + hole_len - full_len, ChunkNextFree(region, offset)); if (rp->in_memory->first_free == offset) rp->in_memory->first_free += full_len; else { u_int_16 hole; for (hole = rp->in_memory->first_free; - hole; hole = ChunkNextFree(region, hole)) - if (ChunkNextFree(region, hole) == offset) - break; + hole; hole = ChunkNextFree(region, hole)) + if (ChunkNextFree(region, hole) == offset) + break; ASSERT(hole); write_next_free(region, hole, offset + full_len); } @@ -1215,7 +1215,7 @@ split_hole(u_int_16 region, u_int_16 offset, u_int_16 full_len, int align) } else { rp->free_bytes -= full_len; write_free_chunk(region, offset, - hole_len - full_len, ChunkNextFree(region, offset)); + hole_len - full_len, ChunkNextFree(region, offset)); if (rp->largest_free_chunk == hole_len) rp->largest_free_chunk = largest_hole(region); return offset + hole_len - full_len; @@ -1273,7 +1273,7 @@ read_cache_region(fd_type fd, RegionHeader * rhp, u_int_16 region) remaining -= done; pos += done; if (!remaining) - return; + return; } #ifndef WIN32 if (done == -1 && errno == EAGAIN) @@ -1338,7 +1338,7 @@ write_cache_region(fd_type fd, RegionHeader * rhp, u_int_16 region) remaining -= done; pos += done; if (!remaining) - return; + return; } #ifndef WIN32 if (done == -1 && errno == EAGAIN) @@ -1415,7 +1415,7 @@ find_available_cache_region(void) find_oddballs(rhp->region_id); #ifdef DEBUG_CHUNK_PAGING do_rawlog(LT_TRACE, "CHUNK: Paging out region %04x (offset %08x)", - rhp->region_id, (unsigned) file_offset); + rhp->region_id, (unsigned) file_offset); #endif write_cache_region(swap_fd, rhp, rhp->region_id); /* keep statistics */ @@ -1457,7 +1457,7 @@ bring_in_region(u_int_16 region) /* page it in */ #ifdef DEBUG_CHUNK_PAGING do_rawlog(LT_TRACE, "CHUNK: Paging in region %04x (offset %08x)", - region, (unsigned) file_offset); + region, (unsigned) file_offset); #endif read_cache_region(swap_fd, rhp, region); /* link the region to its cache entry */ @@ -1474,17 +1474,17 @@ bring_in_region(u_int_16 region) if (shift > 8) { rp->total_derefs = 0; for (offset = FIRST_CHUNK_OFFSET_IN_REGION; - offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { - ChunkDerefs(region, offset) = 0; + offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { + ChunkDerefs(region, offset) = 0; } } else { rp->total_derefs = 0; for (offset = FIRST_CHUNK_OFFSET_IN_REGION; - offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { - if (ChunkIsFree(region, offset)) - continue; - ChunkDerefs(region, offset) >>= shift; - rp->total_derefs += ChunkDerefs(region, offset); + offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { + if (ChunkIsFree(region, offset)) + continue; + ChunkDerefs(region, offset) >>= shift; + rp->total_derefs += ChunkDerefs(region, offset); } } rp->period_last_touched = curr_period; @@ -1519,7 +1519,7 @@ create_region(void) #endif regions = (Region *) realloc(regions, region_array_len * sizeof(Region)); if (!regions) - mush_panic("chunk: region array realloc failure"); + mush_panic("chunk: region array realloc failure"); } region = region_count; region_count++; @@ -1537,7 +1537,7 @@ create_region(void) regions[region].in_memory->region_id = region; regions[region].in_memory->first_free = FIRST_CHUNK_OFFSET_IN_REGION; write_free_chunk(region, FIRST_CHUNK_OFFSET_IN_REGION, - regions[region].free_bytes, 0); + regions[region].free_bytes, 0); touch_cache_region(regions[region].in_memory); return region; @@ -1570,12 +1570,12 @@ find_oddballs(u_int_16 region) j = NUM_ODDBALLS; while (j--) { if (!rp->oddballs[j]) - continue; + continue; d2 = abs(mean - ChunkDerefs(region, rp->oddballs[j])); if (d1 < d2) - break; + break; if (j < NUM_ODDBALLS - 1) - rp->oddballs[j + 1] = rp->oddballs[j]; + rp->oddballs[j + 1] = rp->oddballs[j]; } j++; if (j >= NUM_ODDBALLS) @@ -1610,8 +1610,8 @@ find_best_region(u_int_16 full_len, int derefs, u_int_16 old_region) rp = regions + region; free_bytes += rp->free_bytes; if (!FitsInSpace(full_len, rp->largest_free_chunk) && - !(rp->free_count == 2 && - rp->free_bytes - rp->largest_free_chunk == full_len)) + !(rp->free_count == 2 && + rp->free_bytes - rp->largest_free_chunk == full_len)) continue; if (region == old_region) @@ -1637,8 +1637,8 @@ find_best_region(u_int_16 full_len, int derefs, u_int_16 old_region) #endif best_region = create_region(); } else if (best_score > (1 << LONLINESS_LIMIT) + IN_MEMORY_BIAS && - (free_bytes * 100 / (REGION_CAPACITY * region_count)) < - FREE_PERCENT_LIMIT) { + (free_bytes * 100 / (REGION_CAPACITY * region_count)) < + FREE_PERCENT_LIMIT) { #ifdef DEBUG_CHUNK_REGION_CREATE do_rawlog(LT_TRACE, "find_best_region chose to create region %04x", region); #endif @@ -1655,7 +1655,7 @@ find_best_region(u_int_16 full_len, int derefs, u_int_16 old_region) */ static u_int_16 find_best_offset(u_int_16 full_len, u_int_16 region, - u_int_16 old_region, u_int_16 old_offset) + u_int_16 old_region, u_int_16 old_offset) { u_int_16 fits, offset; @@ -1666,9 +1666,9 @@ find_best_offset(u_int_16 full_len, u_int_16 region, offset = ChunkNextFree(region, offset)) { if (region == old_region) { if (offset > old_offset) - break; + break; if (offset + ChunkFullLen(region, offset) == old_offset) - return fits ? fits : offset; + return fits ? fits : offset; } if (ChunkFullLen(region, offset) == full_len) return offset; @@ -1757,49 +1757,49 @@ chunk_statistics(dbref player) stat_used_medium_count * CHUNK_MEDIUM_DATA_OFFSET + stat_used_long_count * CHUNK_LONG_DATA_OFFSET; STAT_OUT(tprintf - ("Chunks: %10d allocated (%10d bytes, %10d (%2d%%) overhead)", - used_count, used_bytes, overhead, - used_bytes ? overhead * 100 / used_bytes : 0)); + ("Chunks: %10d allocated (%10d bytes, %10d (%2d%%) overhead)", + used_count, used_bytes, overhead, + used_bytes ? overhead * 100 / used_bytes : 0)); overhead = stat_used_short_count * CHUNK_SHORT_DATA_OFFSET; STAT_OUT(tprintf - (" %10d short (%10d bytes, %10d (%2d%%) overhead)", - stat_used_short_count, stat_used_short_bytes, overhead, - stat_used_short_bytes ? overhead * 100 / - stat_used_short_bytes : 0)); + (" %10d short (%10d bytes, %10d (%2d%%) overhead)", + stat_used_short_count, stat_used_short_bytes, overhead, + stat_used_short_bytes ? overhead * 100 / + stat_used_short_bytes : 0)); overhead = stat_used_medium_count * CHUNK_MEDIUM_DATA_OFFSET; STAT_OUT(tprintf - (" %10d medium (%10d bytes, %10d (%2d%%) overhead)", - stat_used_medium_count, stat_used_medium_bytes, overhead, - stat_used_medium_bytes ? overhead * 100 / - stat_used_medium_bytes : 0)); + (" %10d medium (%10d bytes, %10d (%2d%%) overhead)", + stat_used_medium_count, stat_used_medium_bytes, overhead, + stat_used_medium_bytes ? overhead * 100 / + stat_used_medium_bytes : 0)); overhead = stat_used_long_count * CHUNK_LONG_DATA_OFFSET; STAT_OUT(tprintf - (" %10d long (%10d bytes, %10d (%2d%%) overhead)", - stat_used_long_count, stat_used_long_bytes, overhead, - stat_used_long_bytes ? overhead * 100 / stat_used_long_bytes : 0)); + (" %10d long (%10d bytes, %10d (%2d%%) overhead)", + stat_used_long_count, stat_used_long_bytes, overhead, + stat_used_long_bytes ? overhead * 100 / stat_used_long_bytes : 0)); STAT_OUT(tprintf - (" %10d free (%10d bytes, %10d (%2d%%) fragmented)", - free_count, free_bytes, free_bytes - free_large, - free_bytes ? (free_bytes - free_large) * 100 / free_bytes : 0)); + (" %10d free (%10d bytes, %10d (%2d%%) fragmented)", + free_count, free_bytes, free_bytes - free_large, + free_bytes ? (free_bytes - free_large) * 100 / free_bytes : 0)); overhead = region_count * REGION_SIZE + region_array_len * sizeof(Region); STAT_OUT(tprintf("Storage: %10d total (%2d%% saturation)", - overhead, used_bytes * 100 / overhead)); + overhead, used_bytes * 100 / overhead)); STAT_OUT(tprintf("Regions: %10d total, %8d cached", - region_count, cached_region_count)); + region_count, cached_region_count)); STAT_OUT(tprintf("Paging: %10d out, %10d in", - stat_page_out, stat_page_in)); + stat_page_out, stat_page_in)); STAT_OUT(" "); STAT_OUT(tprintf("Period: %10d (%10d accesses so far, %10d chunks at max)", - curr_period, stat_deref_count, stat_deref_maxxed)); + curr_period, stat_deref_count, stat_deref_maxxed)); STAT_OUT(tprintf("Activity: %10d creates, %10d deletes this period", - stat_create, stat_delete)); + stat_create, stat_delete)); STAT_OUT(tprintf("Migration: %10d moves this period", - stat_migrate_slide + stat_migrate_move)); + stat_migrate_slide + stat_migrate_move)); STAT_OUT(tprintf(" %10d slide %10d move", - stat_migrate_slide, stat_migrate_move)); + stat_migrate_slide, stat_migrate_move)); STAT_OUT(tprintf(" %10d in region%10d out of region", - stat_migrate_slide + stat_migrate_move - stat_migrate_away, - stat_migrate_away)); + stat_migrate_slide + stat_migrate_move - stat_migrate_away, + stat_migrate_away)); } /** Show just the page counts. @@ -1810,7 +1810,7 @@ chunk_page_stats(dbref player) { const char *s; STAT_OUT(tprintf("Paging: %10d out, %10d in", - stat_page_out, stat_page_in)); + stat_page_out, stat_page_in)); } /** Display the per-region stats. @@ -1827,11 +1827,11 @@ chunk_region_statistics(dbref player) } for (rid = 0; rid < region_count; rid++) { STAT_OUT(tprintf - ("region:%4d #used:%5d #free:%5d " - "fbytes:%04x largest:%04x deref:%3d", - rid, regions[rid].used_count, regions[rid].free_count, - regions[rid].free_bytes, regions[rid].largest_free_chunk, - RegionDerefs(rid))); + ("region:%4d #used:%5d #free:%5d " + "fbytes:%04x largest:%04x deref:%3d", + rid, regions[rid].used_count, regions[rid].free_count, + regions[rid].free_bytes, regions[rid].largest_free_chunk, + RegionDerefs(rid))); } } @@ -1892,19 +1892,19 @@ chunk_histogram(dbref player, int const *histogram, char const *legend) if (k > max) { sprintf(num, "(%d)", k); if (j < 32) { - if (j < pen) - ante = 18; - else - ante = 19; - memcpy(buffer[ante] + j + 1, num, strlen(num)); - pen = j + strlen(num) + 1; + if (j < pen) + ante = 18; + else + ante = 19; + memcpy(buffer[ante] + j + 1, num, strlen(num)); + pen = j + strlen(num) + 1; } else { - if (j - (int) strlen(num) < pen) - ante = 18; - else - ante = 19; - memcpy(buffer[ante] + j - strlen(num), num, strlen(num)); - pen = j; + if (j - (int) strlen(num) < pen) + ante = 18; + else + ante = 19; + memcpy(buffer[ante] + j - strlen(num), num, strlen(num)); + pen = j; } } } @@ -1938,7 +1938,7 @@ migrate_sort(void) t = m_references[j]; for (k = j; k--;) { if (m_references[k][0] < t[0]) - break; + break; m_references[k + 1] = m_references[k]; } m_references[k + 1] = t; @@ -1957,7 +1957,7 @@ migrate_slide(u_int_16 region, u_int_16 offset, int which) u_int_16 o_len, len, next, other, prev, o_off, o_oth; debug_log("migrate_slide %d (%08x) to %04x%04x", - which, m_references[which][0], region, offset); + which, m_references[which][0], region, offset); bring_in_region(region); @@ -1972,7 +1972,7 @@ migrate_slide(u_int_16 region, u_int_16 offset, int which) memmove(ChunkPointer(region, offset), ChunkPointer(region, other), o_len); #ifdef DEBUG_CHUNK_MIGRATE do_rawlog(LT_TRACE, "CHUNK: Sliding chunk %08x to %04x%04x", - m_references[which][0], region, offset); + m_references[which][0], region, offset); #endif m_references[which][0] = ChunkReference(region, offset); other = offset + o_len; @@ -1981,7 +1981,7 @@ migrate_slide(u_int_16 region, u_int_16 offset, int which) memmove(ChunkPointer(region, prev), ChunkPointer(region, other), o_len); #ifdef DEBUG_CHUNK_MIGRATE do_rawlog(LT_TRACE, "CHUNK: Sliding chunk %08x to %04x%04x", - m_references[which][0], region, prev); + m_references[which][0], region, prev); #endif m_references[which][0] = ChunkReference(region, prev); } @@ -2003,7 +2003,7 @@ migrate_slide(u_int_16 region, u_int_16 offset, int which) if (!region_is_valid(region)) { do_rawlog(LT_TRACE, "Invalid region after migrate_slide!"); do_rawlog(LT_TRACE, "Was moving %04x%04x to %04x%04x (became %08x)...", - region, o_oth, region, o_off, m_references[which][0]); + region, o_oth, region, o_off, m_references[which][0]); do_rawlog(LT_TRACE, "Chunk length %04x into hole length %04x", o_len, len); debug_dump_region(region, tracelog_fp); dump_debug_log(tracelog_fp); @@ -2026,7 +2026,7 @@ migrate_move(u_int_16 region, u_int_16 offset, int which, int align) Region *srp; debug_log("migrate_move %d (%08x) to %04x%04x, alignment %d", - which, m_references[which][0], region, offset, align); + which, m_references[which][0], region, offset, align); s_reg = ChunkReferenceToRegion(m_references[which][0]); s_off = ChunkReferenceToOffset(m_references[which][0]); @@ -2050,7 +2050,7 @@ migrate_move(u_int_16 region, u_int_16 offset, int which, int align) if (!FitsInSpace(s_len, ChunkFullLen(region, offset))) { dump_debug_log(tracelog_fp); mush_panicf("Trying to migrate into too small a hole: %04x into %04x!", - s_len, length); + s_len, length); } #endif @@ -2059,7 +2059,7 @@ migrate_move(u_int_16 region, u_int_16 offset, int which, int align) memcpy(ChunkPointer(region, offset), ChunkPointer(s_reg, s_off), s_len); #ifdef DEBUG_CHUNK_MIGRATE do_rawlog(LT_TRACE, "CHUNK: moving chunk %08x to %04x%04x", - m_references[which][0], region, offset); + m_references[which][0], region, offset); #endif m_references[which][0] = ChunkReference(region, offset); rp->total_derefs += ChunkDerefs(region, offset); @@ -2071,9 +2071,9 @@ migrate_move(u_int_16 region, u_int_16 offset, int which, int align) if (!region_is_valid(region)) { do_rawlog(LT_TRACE, "Invalid region after migrate_move!"); do_rawlog(LT_TRACE, "Was moving %04x%04x to %04x%04x (became %04x%04x)...", - s_reg, s_off, region, o_off, region, offset); + s_reg, s_off, region, o_off, region, offset); do_rawlog(LT_TRACE, "Chunk length %04x into hole length %04x, alignment %d", - s_len, length, align); + s_len, length, align); debug_dump_region(region, tracelog_fp); mush_panic("Invalid region after migrate_move!"); } @@ -2100,9 +2100,9 @@ migrate_region(u_int_16 region) best_region = find_best_region(length, derefs, region); best_offset = find_best_offset(length, best_region, region, offset); if (best_offset) - migrate_move(best_region, best_offset, j, 1); + migrate_move(best_region, best_offset, j, 1); if (best_region != region) - stat_migrate_away++; + stat_migrate_away++; } } migrate_sort(); @@ -2184,7 +2184,7 @@ chunk_delete(chunk_reference_t reference) */ u_int_16 chunk_fetch(chunk_reference_t reference, - unsigned char *buffer, u_int_16 buffer_len) + unsigned char *buffer, u_int_16 buffer_len) { u_int_16 region, offset, len; region = ChunkReferenceToRegion(reference); @@ -2274,24 +2274,24 @@ chunk_migration(int count, chunk_reference_t ** references) /* Make sure we have something to migrate, in the region. */ for (k = 0; k < m_count; k++) if (ChunkReferenceToRegion(m_references[k][0]) == region) - break; + break; if (k >= m_count) continue; if (!regions[region].in_memory) { /* If not in memory, see if we've got an oddball. */ while (k < m_count) { - if (ChunkReferenceToRegion(m_references[k][0]) != region) - break; - offset = ChunkReferenceToOffset(m_references[k][0]); - for (l = 0; l < NUM_ODDBALLS; l++) { - if (regions[region].oddballs[l] == offset) { - /* Yup, have an oddball... that's worth bringing it in. */ - bring_in_region(region); - goto do_migrate; - } - } - k++; + if (ChunkReferenceToRegion(m_references[k][0]) != region) + break; + offset = ChunkReferenceToOffset(m_references[k][0]); + for (l = 0; l < NUM_ODDBALLS; l++) { + if (regions[region].oddballs[l] == offset) { + /* Yup, have an oddball... that's worth bringing it in. */ + bring_in_region(region); + goto do_migrate; + } + } + k++; } } else { do_migrate: @@ -2336,7 +2336,7 @@ chunk_init(void) #ifdef WIN32 swap_fd = CreateFile(CHUNK_SWAP_FILE, GENERIC_READ | GENERIC_WRITE, - 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); + 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); if (swap_fd == INVALID_HANDLE_VALUE) mush_panicf("Cannot open swap file: %d", GetLastError()); #else @@ -2380,15 +2380,15 @@ chunk_stats(dbref player, enum chunk_stats_type which) break; case CSTATS_REGIONG: chunk_histogram(player, chunk_regionhist(), - "Chart number of regions (y) vs. references (x)"); + "Chart number of regions (y) vs. references (x)"); break; case CSTATS_PAGINGG: chunk_histogram(player, stat_paging_histogram, - "Chart pages in/out (y) vs. references (x)"); + "Chart pages in/out (y) vs. references (x)"); break; case CSTATS_FREESPACEG: chunk_histogram(player, chunk_freehist(), - "Chart region free space (y) vs. references (x)"); + "Chart region free space (y) vs. references (x)"); break; case CSTATS_REGION: chunk_region_statistics(player); @@ -2438,17 +2438,17 @@ chunk_new_period(void) if (shift > 8) { rp->total_derefs = 0; for (offset = FIRST_CHUNK_OFFSET_IN_REGION; - offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { - ChunkDerefs(region, offset) = 0; + offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { + ChunkDerefs(region, offset) = 0; } } else { rp->total_derefs = 0; for (offset = FIRST_CHUNK_OFFSET_IN_REGION; - offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { - if (ChunkIsFree(region, offset)) - continue; - ChunkDerefs(region, offset) >>= shift; - rp->total_derefs += ChunkDerefs(region, offset); + offset < REGION_SIZE; offset += ChunkFullLen(region, offset)) { + if (ChunkIsFree(region, offset)) + continue; + ChunkDerefs(region, offset) >>= shift; + rp->total_derefs += ChunkDerefs(region, offset); } } rp->period_last_touched = curr_period; @@ -2536,4 +2536,4 @@ chunk_fork_done(void) unlink(child_filename); swap_fd_child = -1; } -#endif /* !WIN32 */ +#endif /* !WIN32 */ diff --git a/src/cmds.c b/src/cmds.c index 662a1cc..99d74f7 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -37,12 +37,12 @@ void do_poor(dbref player, char *arg1); void do_list_memstats(dbref player); -#define DOL_MAP 1 /**< dolist/map bitflag */ -#define DOL_NOTIFY 2 /**< dolist/notify bitflag */ -#define DOL_DELIM 4 /**< dolist/delim bitflag */ +#define DOL_MAP 1 /**< dolist/map bitflag */ +#define DOL_NOTIFY 2 /**< dolist/notify bitflag */ +#define DOL_DELIM 4 /**< dolist/delim bitflag */ void do_dolist(dbref player, char *list, char *command, - dbref cause, unsigned int flags); + dbref cause, unsigned int flags); void do_list(dbref player, char *arg, int lc); void do_writelog(dbref player, char *str, int ltype); void do_readcache(dbref player); @@ -186,7 +186,7 @@ COMMAND (cmd_config) { return; } if (!config_set(arg_left, arg_right, 1, 0) - && !config_set(arg_left, arg_right, 1, 1)) + && !config_set(arg_left, arg_right, 1, 1)) notify(player, T("Couldn't set that option")); else notify(player, T("Option set.")); @@ -221,7 +221,7 @@ COMMAND (cmd_decompile) { /* @dec/tf overrides @dec/prefix */ ATTR *a; if (((a = atr_get_noparent(player, "TFPREFIX")) != NULL) && - AL_STR(a) && *AL_STR(a)) { + AL_STR(a) && *AL_STR(a)) { strcpy(prefix, atr_value(a)); } else { strcpy(prefix, "FugueEdit > "); @@ -326,8 +326,8 @@ COMMAND (cmd_dump) { COMMAND (cmd_edit) { do_gedit(player, arg_left, args_right, - SW_ISSET(sw, SWITCH_FIRST) ? EDIT_FIRST : EDIT_ALL, - SW_ISSET(sw, SWITCH_CHECK) ? 0 : 1); + SW_ISSET(sw, SWITCH_FIRST) ? EDIT_FIRST : EDIT_ALL, + SW_ISSET(sw, SWITCH_CHECK) ? 0 : 1); } COMMAND (cmd_elock) { @@ -424,8 +424,8 @@ COMMAND (cmd_function) { split = 1; saved = args_right[2]; if ((args_right[2] = strchr(args_right[1], '/')) == NULL) { - notify(player, T("#-1 INVALID SECOND ARGUMENT")); - return; + notify(player, T("#-1 INVALID SECOND ARGUMENT")); + return; } *args_right[2]++ = '\0'; } @@ -437,7 +437,7 @@ COMMAND (cmd_function) { do_function(player, NULL, NULL, 0); if (split) { if (args_right[2]) - *--args_right[2] = '/'; + *--args_right[2] = '/'; args_right[2] = saved; } } @@ -445,9 +445,9 @@ COMMAND (cmd_function) { COMMAND (cmd_grep) { do_grep(player, arg_left, arg_right, ((SW_ISSET(sw, SWITCH_IPRINT)) - || (SW_ISSET(sw, SWITCH_PRINT))), - ((SW_ISSET(sw, SWITCH_IPRINT)) - || (SW_ISSET(sw, SWITCH_ILIST)))); + || (SW_ISSET(sw, SWITCH_PRINT))), + ((SW_ISSET(sw, SWITCH_IPRINT)) + || (SW_ISSET(sw, SWITCH_ILIST)))); } COMMAND (cmd_halt) { @@ -500,7 +500,7 @@ COMMAND (cmd_lemit) { int spflags = !strcmp(cmd->name, "@NSLEMIT") ? PEMIT_SPOOF : 0; SPOOF(player, cause, sw); do_lemit(player, arg_left, - (SW_ISSET(sw, SWITCH_SILENT) * PEMIT_SILENT) | spflags); + (SW_ISSET(sw, SWITCH_SILENT) * PEMIT_SILENT) | spflags); } COMMAND (cmd_link) { @@ -613,7 +613,7 @@ COMMAND (cmd_mail) { else if (SW_ISSET(sw, SWITCH_UNTAG)) do_mail_untag(player, arg_left); else if (SW_ISSET(sw, SWITCH_FWD) || SW_ISSET(sw, SWITCH_FORWARD) - || SW_ISSET(sw, SWITCH_SEND) || silent || urgent || nosig) { + || SW_ISSET(sw, SWITCH_SEND) || silent || urgent || nosig) { /* These commands are not allowed to gagged players */ if (Gagged(player)) { notify(player, T("You cannot do that while gagged.")); @@ -625,9 +625,9 @@ COMMAND (cmd_mail) { do_mail_fwd(player, arg_left, arg_right); else if (SW_ISSET(sw, SWITCH_SEND) || silent || urgent || nosig) do_mail_send(player, arg_left, arg_right, - urgent ? M_URGENT : 0, silent, nosig); + urgent ? M_URGENT : 0, silent, nosig); } else - do_mail(player, arg_left, arg_right); /* Does its own gagged check */ + do_mail(player, arg_left, arg_right); /* Does its own gagged check */ } @@ -820,7 +820,7 @@ COMMAND (cmd_scan) { do_scan(player, arg_left, CHECK_GLOBAL); else do_scan(player, arg_left, CHECK_INVENTORY | CHECK_NEIGHBORS | - CHECK_SELF | CHECK_HERE | CHECK_ZONE | CHECK_GLOBAL); + CHECK_SELF | CHECK_HERE | CHECK_ZONE | CHECK_GLOBAL); } COMMAND (cmd_search) { @@ -829,7 +829,7 @@ COMMAND (cmd_search) { COMMAND (cmd_select) { do_switch(player, arg_left, args_right, cause, 1, - SW_ISSET(sw, SWITCH_NOTIFY), SW_ISSET(sw, SWITCH_REGEXP)); + SW_ISSET(sw, SWITCH_NOTIFY), SW_ISSET(sw, SWITCH_REGEXP)); } COMMAND (cmd_set) { @@ -897,7 +897,7 @@ COMMAND (cmd_sweep) { COMMAND (cmd_switch) { do_switch(player, arg_left, args_right, cause, SW_ISSET(sw, SWITCH_FIRST), - SW_ISSET(sw, SWITCH_NOTIFY), SW_ISSET(sw, SWITCH_REGEXP)); + SW_ISSET(sw, SWITCH_NOTIFY), SW_ISSET(sw, SWITCH_REGEXP)); } COMMAND (cmd_squota) { @@ -910,7 +910,7 @@ COMMAND (cmd_teleport) { notify(player, T("You can't teleport to nothing!")); else do_teleport(player, arg_left, arg_right, (SW_ISSET(sw, SWITCH_SILENT)), - (SW_ISSET(sw, SWITCH_INSIDE))); + (SW_ISSET(sw, SWITCH_INSIDE))); } COMMAND (cmd_trigger) { @@ -1095,9 +1095,9 @@ COMMAND (cmd_page) { do_page_port(player, arg_left, arg_right); else do_page(player, arg_left, arg_right, cause, SW_ISSET(sw, SWITCH_NOEVAL), - !(SW_ISSET(sw, SWITCH_BLIND) || - (!(SW_ISSET(sw, SWITCH_LIST)) && (BLIND_PAGE))), - SW_ISSET(sw, SWITCH_OVERRIDE), rhs_present); + !(SW_ISSET(sw, SWITCH_BLIND) || + (!(SW_ISSET(sw, SWITCH_LIST)) && (BLIND_PAGE))), + SW_ISSET(sw, SWITCH_OVERRIDE), rhs_present); } COMMAND (cmd_pose) { @@ -1126,8 +1126,8 @@ COMMAND (cmd_think) { COMMAND (cmd_whisper) { do_whisper(player, arg_left, arg_right, - (SW_ISSET(sw, SWITCH_NOISY) || - (!SW_ISSET(sw, SWITCH_SILENT) && NOISY_WHISPER))); + (SW_ISSET(sw, SWITCH_NOISY) || + (!SW_ISSET(sw, SWITCH_SILENT) && NOISY_WHISPER))); } COMMAND (cmd_use) { @@ -1143,7 +1143,7 @@ COMMAND (command_atrset) { /* If it's &attr obj, we must pass a NULL. If &attr obj=, pass "" */ if (rhs_present) { do_set_atr(thing, switches, arg_right, player, - 0x1 | (SW_ISSET(sw, SWITCH_NOEVAL) ? 0 : 0x02)); + 0x1 | (SW_ISSET(sw, SWITCH_NOEVAL) ? 0 : 0x02)); } else { do_set_atr(thing, switches, NULL, player, 1); } @@ -1155,8 +1155,8 @@ COMMAND (cmd_null) { COMMAND (cmd_warn_on_missing) { notify_format(Owner(player), - T - ("No command found in code by %s - don't start code with functions."), - unparse_dbref(player)); + T + ("No command found in code by %s - don't start code with functions."), + unparse_dbref(player)); return; } diff --git a/src/command.c b/src/command.c index 5a59f7c..34dff97 100644 --- a/src/command.c +++ b/src/command.c @@ -422,7 +422,7 @@ switch_find(COMMAND_INFO *cmd, char *sw) if (!cmd) { while (sw_val->name) { if (strcmp(sw_val->name, sw) == 0) - return sw_val->value; + return sw_val->value; sw_val++; } return 0; @@ -910,7 +910,7 @@ command_parse(dbref player, dbref cause, dbref realcause, char *string, int from #if 0 /* Messes up hooks when chat_strip_quote is yes. See bug #6677 */ if (CHAT_STRIP_QUOTE) - p--; /* Since 'say' strips out the '"' */ + p--; /* Since 'say' strips out the '"' */ #endif break; case POSE_TOKEN: @@ -992,14 +992,14 @@ command_parse(dbref player, dbref cause, dbref realcause, char *string, int from } else { c = command; while ((*c) && (*c != '/')) - c++; + c++; b = *c; *c = '\0'; cmd = command_find(command); *c = b; /* Is this for internal use? If so, players can't use it! */ if (cmd && (cmd->type & CMD_T_INTERNAL)) - cmd = NULL; + cmd = NULL; } } @@ -1065,21 +1065,21 @@ command_parse(dbref player, dbref cause, dbref realcause, char *string, int from t = swtch; c++; while ((*c) && (*c != ' ') && (*c != '/')) - *t++ = *c++; + *t++ = *c++; *t = '\0'; switchnum = switch_find(cmd, upcasestr(swtch)); if (!switchnum) { - if (cmd->type & CMD_T_SWITCHES) { - if (*swp) - strcat(swp, " "); - strcat(swp, swtch); - } else { - if (se == switch_err) - safe_format(switch_err, &se, - T("%s doesn't know switch %s."), cmd->name, swtch); - } + if (cmd->type & CMD_T_SWITCHES) { + if (*swp) + strcat(swp, " "); + strcat(swp, swtch); + } else { + if (se == switch_err) + safe_format(switch_err, &se, + T("%s doesn't know switch %s."), cmd->name, swtch); + } } else { - SW_SET(sw, switchnum); + SW_SET(sw, switchnum); } } } @@ -1574,12 +1574,12 @@ COMMAND (cmd_command) { if (SW_ISSET(sw, SWITCH_RESTRICT)) { if (!arg_right || !arg_right[0]) { - notify(player, T("How do you want to restrict the command?")); - return; + notify(player, T("How do you want to restrict the command?")); + return; } if (!restrict_command(arg_left, arg_right)) - notify(player, T("Restrict attempt failed.")); + notify(player, T("Restrict attempt failed.")); } if ((command->func == cmd_command) && (command->type & CMD_T_DISABLED)) { @@ -1654,13 +1654,13 @@ COMMAND (cmd_command) { buff[0] = '\0'; bp = buff; if (command->type & CMD_T_RS_ARGS) { - if (command->type & CMD_T_RS_SPACE) - strccat(buff, &bp, "Space-Args"); - else - strccat(buff, &bp, "Args"); + if (command->type & CMD_T_RS_SPACE) + strccat(buff, &bp, "Space-Args"); + else + strccat(buff, &bp, "Args"); } if (command->type & CMD_T_RS_NOPARSE) - strccat(buff, &bp, "Noparse"); + strccat(buff, &bp, "Noparse"); *bp = '\0'; notify_format(player, "Rightside : %s", buff); } else { @@ -1830,7 +1830,7 @@ has_hook(struct hook_data *hook) */ int run_hook(dbref player, dbref cause, struct hook_data *hook, char *saveregs[], - int save) + int save) { ATTR *atr; char *code; @@ -1858,7 +1858,7 @@ run_hook(dbref player, dbref cause, struct hook_data *hook, char *saveregs[], bp = buff; process_expression(buff, &bp, &cp, hook->obj, cause, player, PE_DEFAULT, - PT_DEFAULT, NULL); + PT_DEFAULT, NULL); *bp = '\0'; if (save) @@ -1882,7 +1882,7 @@ run_hook(dbref player, dbref cause, struct hook_data *hook, char *saveregs[], */ void do_hook(dbref player, char *command, char *obj, char *attrname, - enum hook_type flag) + enum hook_type flag) { COMMAND_INFO *cmd; struct hook_data *h; @@ -1953,15 +1953,15 @@ do_hook_list(dbref player, char *command) if (Site(player)) { if (GoodObject(cmd->hooks.before.obj)) notify_format(player, "@hook/before: #%d/%s", - cmd->hooks.before.obj, cmd->hooks.before.attrname); + cmd->hooks.before.obj, cmd->hooks.before.attrname); if (GoodObject(cmd->hooks.after.obj)) notify_format(player, "@hook/after: #%d/%s", cmd->hooks.after.obj, - cmd->hooks.after.attrname); + cmd->hooks.after.attrname); if (GoodObject(cmd->hooks.ignore.obj)) notify_format(player, "@hook/ignore: #%d/%s", - cmd->hooks.ignore.obj, cmd->hooks.ignore.attrname); + cmd->hooks.ignore.obj, cmd->hooks.ignore.attrname); if (GoodObject(cmd->hooks.override.obj)) notify_format(player, "@hook/override: #%d/%s", - cmd->hooks.override.obj, cmd->hooks.override.attrname); + cmd->hooks.override.obj, cmd->hooks.override.attrname); } } diff --git a/src/comp_h.c b/src/comp_h.c index 6cfa42e..ba26fe3 100644 --- a/src/comp_h.c +++ b/src/comp_h.c @@ -25,16 +25,16 @@ #include "mymalloc.h" #include "confmagic.h" #ifdef WIN32 -#pragma warning( disable : 4244) /* NJG: disable warning re conversion */ +#pragma warning( disable : 4244) /* NJG: disable warning re conversion */ #endif -#define TABLE_SIZE 256 /**< allow all characters */ -#define EOS 0 /**< use null code for end of string */ -#define CHAR_BITS 8 /**< number of bits in char */ -#define CHAR_MASK 255 /**< mask for just one char */ -#define CODE_BITS 25 /**< max number of bits in code */ +#define TABLE_SIZE 256 /**< allow all characters */ +#define EOS 0 /**< use null code for end of string */ +#define CHAR_BITS 8 /**< number of bits in char */ +#define CHAR_MASK 255 /**< mask for just one char */ +#define CODE_BITS 25 /**< max number of bits in code */ #ifndef SAMPLE_SIZE -#define SAMPLE_SIZE 0 /**< sample entire database */ +#define SAMPLE_SIZE 0 /**< sample entire database */ #endif @@ -45,9 +45,9 @@ typedef unsigned long CType; /** A node in the huffman compression tree. */ typedef struct cnode { - struct cnode *left; /**< Left child node. */ - struct cnode *right; /**< Right child node. */ - unsigned char c; /**< character at this node. */ + struct cnode *left; /**< Left child node. */ + struct cnode *right; /**< Right child node. */ + unsigned char c; /**< character at this node. */ } CNode; static CNode *ctop; @@ -87,7 +87,7 @@ compress(const char *s) /* Part 1 - how long will the compressed string be? */ for (p = (const unsigned char *) s; p && *p; p++) bits += ltable[*p]; - bits += CHAR_BITS * 2 - 1; /* add space for the ending \0 */ + bits += CHAR_BITS * 2 - 1; /* add space for the ending \0 */ needed_length = bits / CHAR_BITS; /* Part 2 - Actually get around to compressing the data... */ @@ -261,9 +261,9 @@ add_ones(CNode *node) if ((count >= 7) || ((count >= 3) && !node->left && !node->right)) { ctop = (CNode *) malloc((unsigned) sizeof(CNode)); if (!ctop) { - do_rawlog(LT_ERR, - "Cannot allocate memory for compression tree. Aborting."); - exit(1); + do_rawlog(LT_ERR, + "Cannot allocate memory for compression tree. Aborting."); + exit(1); } ctop->left = node->left; ctop->right = node->right; @@ -297,7 +297,7 @@ build_ctable(CNode *root, CType code, int numbits) #endif if (numbits > CODE_BITS) { do_rawlog(LT_ERR, "Illegal compression code length (%d). Aborting.", - numbits); + numbits); exit(1); } } else { @@ -342,7 +342,7 @@ init_compress(FILE * f) table[total].node = (CNode *) malloc((unsigned) sizeof(CNode)); if (!table[total].node) { do_rawlog(LT_ERR, - "Cannot allocate memory for compression tree. Aborting."); + "Cannot allocate memory for compression tree. Aborting."); exit(1); } table[total].node->c = total; @@ -365,7 +365,7 @@ init_compress(FILE * f) #ifdef STANDALONE for (indx = 0; indx < TABLE_SIZE; indx++) { printf(isprint(indx) ? "Frequency for '%c': %d\n" - : "Frequency for %d: %d\n", (unsigned char) indx, table[indx].freq); + : "Frequency for %d: %d\n", (unsigned char) indx, table[indx].freq); } #endif @@ -405,7 +405,7 @@ init_compress(FILE * f) */ for (indx = 2; indx < TABLE_SIZE; indx++) { for (count = indx; - (count > 1) && (table[count - 1].freq < table[count].freq); count--) { + (count > 1) && (table[count - 1].freq < table[count].freq); count--) { temp = table[count].freq; table[count].freq = table[count - 1].freq; table[count - 1].freq = temp; @@ -437,7 +437,7 @@ init_compress(FILE * f) node = (CNode *) malloc((unsigned) sizeof(CNode)); if (!node) { do_rawlog(LT_ERR, - "Cannot allocate memory for compression tree. Aborting."); + "Cannot allocate memory for compression tree. Aborting."); exit(1); } node->left = table[indx].node; @@ -445,7 +445,7 @@ init_compress(FILE * f) table[indx - 1].freq += table[indx].freq; table[indx - 1].node = node; for (count = indx - 1; - (count > 1) && (table[count - 1].freq <= table[count].freq); count--) { + (count > 1) && (table[count - 1].freq <= table[count].freq); count--) { temp = table[count].freq; table[count].freq = table[count - 1].freq; table[count - 1].freq = temp; @@ -481,7 +481,7 @@ init_compress(FILE * f) /* Force a 1 at fifth position on the left edge of tree. (Or terminating * 1 for the all 0 code.) */ - node = table[1].node; /* top of tree */ + node = table[1].node; /* top of tree */ for (count = 0; node->left && (count < 4); count++) node = node->left; ctop = (CNode *) malloc((unsigned) sizeof(CNode)); @@ -505,14 +505,14 @@ init_compress(FILE * f) /* Part 4(e): Finally add in EOS as 00000000. */ - node = table[1].node; /* top of tree */ + node = table[1].node; /* top of tree */ for (count = 0; count < 8; count++) { if (!node->left) { ctop = (CNode *) malloc((unsigned) sizeof(CNode)); if (!ctop) { - do_rawlog(LT_ERR, - "Cannot allocate memory for compression tree. Aborting."); - exit(1); + do_rawlog(LT_ERR, + "Cannot allocate memory for compression tree. Aborting."); + exit(1); } ctop->left = (CNode *) NULL; ctop->right = (CNode *) NULL; @@ -572,7 +572,7 @@ main(argc, argv) p1 = otherbuf; while (p1 && *p1) { for (count = 0; count < 8; count++) - printf("%d", (*p1 >> count) & 1); + printf("%d", (*p1 >> count) & 1); p1++; } printf("\n"); @@ -582,7 +582,7 @@ main(argc, argv) printf("Text: %s!\n", newbuffer); printf("Strcoll(orig,uncomp) = %d\n", strcoll(newbuffer, buffer)); printf("strlen(orig) = %d, strlen(uncomp) = %d\n", strlen(buffer), - strlen(newbuffer)); + strlen(newbuffer)); p1 = buffer; p2 = newbuffer; /* diff --git a/src/comp_w.c b/src/comp_w.c index 802c3d3..d3b0305 100644 --- a/src/comp_w.c +++ b/src/comp_w.c @@ -127,14 +127,14 @@ #include "mymalloc.h" #include "confmagic.h" -#define MAXTABLE 32768 /**< Maximum words in the table */ -#define MAXWORDS 100 /**< Maximum size of a word */ -#define COLLISION_LIMIT 20 /**< Maximum allowed collisions */ +#define MAXTABLE 32768 /**< Maximum words in the table */ +#define MAXWORDS 100 /**< Maximum size of a word */ +#define COLLISION_LIMIT 20 /**< Maximum allowed collisions */ -#define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */ +#define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */ -#define TABLE_FLAG 0x80 /**< Distinguish a table */ -#define TABLE_MASK 0x7F /**< Mask out words within a table */ +#define TABLE_FLAG 0x80 /**< Distinguish a table */ +#define TABLE_MASK 0x7F /**< Mask out words within a table */ /* Table of words */ @@ -162,7 +162,7 @@ static void output_previous_word(void); int init_compress(FILE * f); #ifdef COMP_STATS void compress_stats(long *entries, long *mem_used, - long *total_uncompressed, long *total_compressed); + long *total_uncompressed, long *total_compressed); #endif static unsigned int hash_fn(const char *s, int hashtab_mask); @@ -172,7 +172,7 @@ output_previous_word(void) char *p; int i, j; - word[wordpos++] = 0; /* word's trailing null */ + word[wordpos++] = 0; /* word's trailing null */ /* Don't bother putting single or double letter words in the table */ @@ -189,14 +189,14 @@ output_previous_word(void) (words[i] || (i & 0xFF) == 0) && j < COLLISION_LIMIT; i++, j++) if (words[i]) if (strcmp(word, words[i]) == 0) { - *b++ = (i >> 8) | TABLE_FLAG; - *b++ = i & 0xFF; - return; + *b++ = (i >> 8) | TABLE_FLAG; + *b++ = i & 0xFF; + return; } /* not in table, add to it */ if ((i & 0xFF) == 0) { - i++; /* make sure we don't have a null in the message */ + i++; /* make sure we don't have a null in the message */ j++; } /* Can't add to table if full */ @@ -223,7 +223,7 @@ output_previous_word(void) *b++ = (i >> 8) | TABLE_FLAG; *b++ = i & 0xFF; -} /* end of output_previous_word */ +} /* end of output_previous_word */ /** Word-compress a string. * @@ -251,11 +251,11 @@ compress(char const *s) while (*p) { if (!(isdigit(*p) || isalpha(*p)) || wordpos >= MAXWORDS) { if (wordpos) { - word[wordpos++] = *p & 0x7F; /* add trailing punctuation */ - output_previous_word(); - wordpos = 0; + word[wordpos++] = *p & 0x7F; /* add trailing punctuation */ + output_previous_word(); + wordpos = 0; } else - *b++ = *p & 0x7F; + *b++ = *p & 0x7F; } else word[wordpos++] = *p & 0x7F; p++; @@ -264,15 +264,15 @@ compress(char const *s) if (wordpos) output_previous_word(); - *b = 0; /* trailing null */ + *b = 0; /* trailing null */ #ifdef COMP_STATS - total_comp += u_strlen(buf); /* calculate size of compressed text */ - total_uncomp += strlen(s); /* calculate size of uncompressed text */ + total_comp += u_strlen(buf); /* calculate size of compressed text */ + total_uncomp += strlen(s); /* calculate size of uncompressed text */ #endif return u_strdup(buf); -} /* end of compress; */ +} /* end of compress; */ /** Word-uncompress a string. @@ -308,16 +308,16 @@ uncompress(unsigned char const *s) if (c & TABLE_FLAG) { i = ((c & TABLE_MASK) << 8) | *(++p); if (i >= MAXTABLE || words[i] == NULL) { - static int panicking = 0; - if (panicking) { - do_rawlog(LT_ERR, - "Error in string decompression occurred during panic dump."); - exit(1); - } else { - panicking = 1; /* don't panic from within panic */ - do_rawlog(LT_ERR, "Error in string decompression, i = %i", i); - mush_panic("Fatal error in decompression"); - } + static int panicking = 0; + if (panicking) { + do_rawlog(LT_ERR, + "Error in string decompression occurred during panic dump."); + exit(1); + } else { + panicking = 1; /* don't panic from within panic */ + do_rawlog(LT_ERR, "Error in string decompression, i = %i", i); + mush_panic("Fatal error in decompression"); + } } strncpy((char *) b, words[i], words_len[i]); b += words_len[i] - 1; @@ -326,11 +326,11 @@ uncompress(unsigned char const *s) p++; } - *b++ = 0; /* trailing null */ + *b++ = 0; /* trailing null */ return buf; -} /* end of uncompress; */ +} /* end of uncompress; */ /** Word-uncompress a string, allocating memory. * this function should be used when you're doing something like @@ -371,7 +371,7 @@ init_compress(FILE * f __attribute__ ((__unused__))) */ void compress_stats(long *entries, long *mem_used, long *total_uncompressed, - long *total_compressed) + long *total_compressed) { *entries = total_entries; diff --git a/src/comp_w8.c b/src/comp_w8.c index e81821e..284582b 100644 --- a/src/comp_w8.c +++ b/src/comp_w8.c @@ -128,15 +128,15 @@ #include "mymalloc.h" #include "confmagic.h" -#define MAXTABLE 32768 /**< Maximum words in the table */ -#define MAXWORDS 100 /**< Maximum length of a word */ -#define COLLISION_LIMIT 20 /**< Maximum allowed collisions */ +#define MAXTABLE 32768 /**< Maximum words in the table */ +#define MAXWORDS 100 /**< Maximum length of a word */ +#define COLLISION_LIMIT 20 /**< Maximum allowed collisions */ -#define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */ +#define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */ -#define MARKER_CHAR 0x06 /**< Separates words. This char is the only one that can't be represented */ -#define TABLE_FLAG 0x80 /**< Distinguishes a table */ -#define TABLE_MASK 0x7F /**< Mask out words within a table */ +#define MARKER_CHAR 0x06 /**< Separates words. This char is the only one that can't be represented */ +#define TABLE_FLAG 0x80 /**< Distinguishes a table */ +#define TABLE_MASK 0x7F /**< Mask out words within a table */ /* Table of words */ @@ -164,7 +164,7 @@ static void output_previous_word(void); int init_compress(FILE * f); #ifdef COMP_STATS void compress_stats(long *entries, long *mem_used, - long *total_uncompressed, long *total_compressed); + long *total_uncompressed, long *total_compressed); #endif static unsigned int hash_fn(const char *s, int hashtab_mask); @@ -174,7 +174,7 @@ output_previous_word(void) char *p; int i, j; - word[wordpos++] = 0; /* word's trailing null */ + word[wordpos++] = 0; /* word's trailing null */ /* Don't bother putting few-letter words in the table */ @@ -191,15 +191,15 @@ output_previous_word(void) (words[i] || (i & 0xFF) == 0) && j < COLLISION_LIMIT; i++, j++) if (words[i]) if (strcmp(word, words[i]) == 0) { - *b++ = MARKER_CHAR; - *b++ = (i >> 8) | TABLE_FLAG; - *b++ = i & 0xFF; - return; + *b++ = MARKER_CHAR; + *b++ = (i >> 8) | TABLE_FLAG; + *b++ = i & 0xFF; + return; } /* not in table, add to it */ if ((i & 0xFF) == 0) { - i++; /* make sure we don't have a null in the message */ + i++; /* make sure we don't have a null in the message */ j++; } /* Can't add to table if full */ @@ -227,7 +227,7 @@ output_previous_word(void) *b++ = (i >> 8) | TABLE_FLAG; *b++ = i & 0xFF; -} /* end of output_previous_word */ +} /* end of output_previous_word */ /** Word-compress a string. * @@ -255,11 +255,11 @@ compress(char const *s) while (*p) { if (!(isdigit(*p) || isalpha(*p)) || wordpos >= MAXWORDS) { if (wordpos) { - word[wordpos++] = *p; /* add trailing punctuation */ - output_previous_word(); - wordpos = 0; + word[wordpos++] = *p; /* add trailing punctuation */ + output_previous_word(); + wordpos = 0; } else - *b++ = *p; + *b++ = *p; } else word[wordpos++] = *p; p++; @@ -268,15 +268,15 @@ compress(char const *s) if (wordpos) output_previous_word(); - *b = 0; /* trailing null */ + *b = 0; /* trailing null */ #ifdef COMP_STATS - total_comp += u_strlen(buf); /* calculate size of compressed text */ - total_uncomp += strlen(s); /* calculate size of uncompressed text */ + total_comp += u_strlen(buf); /* calculate size of compressed text */ + total_uncomp += strlen(s); /* calculate size of uncompressed text */ #endif return u_strdup(buf); -} /* end of compress; */ +} /* end of compress; */ /** Word-uncompress a string. @@ -314,16 +314,16 @@ uncompress(unsigned char const *s) c = *p; i = ((c & TABLE_MASK) << 8) | *(++p); if (i >= MAXTABLE || words[i] == NULL) { - static int panicking = 0; - if (panicking) { - fprintf(stderr, - "Error in string decompression occurred during panic dump.\n"); - exit(1); - } else { - panicking = 1; /* don't panic from within panic */ - fprintf(stderr, "Error in string decompression, i = %i\n", i); - mush_panic("Fatal error in decompression"); - } + static int panicking = 0; + if (panicking) { + fprintf(stderr, + "Error in string decompression occurred during panic dump.\n"); + exit(1); + } else { + panicking = 1; /* don't panic from within panic */ + fprintf(stderr, "Error in string decompression, i = %i\n", i); + mush_panic("Fatal error in decompression"); + } } strncpy((char *) b, words[i], words_len[i]); b += words_len[i] - 1; @@ -332,11 +332,11 @@ uncompress(unsigned char const *s) p++; } - *b++ = 0; /* trailing null */ + *b++ = 0; /* trailing null */ return buf; -} /* end of uncompress; */ +} /* end of uncompress; */ /** Word-uncompress a string, allocating memory. * this function should be used when you're doing something like @@ -377,7 +377,7 @@ init_compress(FILE * f __attribute__ ((__unused__))) */ void compress_stats(long *entries, long *mem_used, long *total_uncompressed, - long *total_compressed) + long *total_compressed) { *entries = total_entries; diff --git a/src/compress.c b/src/compress.c index 1c8fa49..c23a047 100644 --- a/src/compress.c +++ b/src/compress.c @@ -17,7 +17,7 @@ #if defined(COMPRESSION_TYPE) && (COMPRESSION_TYPE == 0) /* No compression */ -char ucbuff[BUFFER_LEN]; /**< Dummy buffer for no compression */ +char ucbuff[BUFFER_LEN]; /**< Dummy buffer for no compression */ #elif (COMPRESSION_TYPE == 1) || (COMPRESSION_TYPE == 2) /* Huffman compression */ @@ -38,4 +38,4 @@ char ucbuff[BUFFER_LEN]; /**< Dummy buffer for no compression */ */ char ucbuff[BUFFER_LEN]; -#endif /* Compression type checks */ +#endif /* Compression type checks */ diff --git a/src/conf.c b/src/conf.c index a4b3587..8c9475a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -566,7 +566,7 @@ new_config(void) */ COBRA_CONF * add_config(const char *name, config_func handler, void *loc, int max, - const char *group) + const char *group) { COBRA_CONF *cnf; if ((cnf = get_config(name))) @@ -607,7 +607,7 @@ get_config(const char *name) */ int cf_bool(const char *opt, const char *val, void *loc, - int maxval __attribute__ ((__unused__)), int source) + int maxval __attribute__ ((__unused__)), int source) { /* enter boolean parameter */ @@ -615,7 +615,7 @@ cf_bool(const char *opt, const char *val, void *loc, !strcasecmp(val, "1")) *((int *) loc) = 1; else if (!strcasecmp(val, "no") || !strcasecmp(val, "false") || - !strcasecmp(val, "0")) + !strcasecmp(val, "0")) *((int *) loc) = 0; else { if (source == 0) { @@ -681,13 +681,13 @@ cf_dbref(const char *opt, const char *val, void *loc, int maxval, int source) n = maxval; if (source == 0) { do_rawlog(LT_ERR, T("CONFIG: option %s value limited to #%d\n"), opt, - maxval); + maxval); } } if (source && (!GoodObject(n) || IsGarbage(n))) { do_rawlog(LT_ERR, - T("CONFIG: attempt to set option %s to a bad dbref (#%d)"), - opt, n); + T("CONFIG: attempt to set option %s to a bad dbref (#%d)"), + opt, n); return 0; } *((dbref *) loc) = n; @@ -720,7 +720,7 @@ cf_int(const char *opt, const char *val, void *loc, int maxval, int source) n = maxval; if (source == 0) { do_rawlog(LT_ERR, T("CONFIG: option %s value limited to %d\n"), opt, - maxval); + maxval); } } *((int *) loc) = n; @@ -755,10 +755,10 @@ cf_time(const char *opt, const char *val, void *loc, int maxval, int source) switch (*end) { case '\0': if (in_minutes) - secs += n * 60; + secs += n * 60; else - secs += n; - goto done; /* Sigh. What I wouldn't give for named loops in C */ + secs += n; + goto done; /* Sigh. What I wouldn't give for named loops in C */ case 's': case 'S': secs += n; @@ -773,7 +773,7 @@ cf_time(const char *opt, const char *val, void *loc, int maxval, int source) break; default: if (source == 0) - do_rawlog(LT_ERR, T("CONFIG: Unknown time interval in option %s"), opt); + do_rawlog(LT_ERR, T("CONFIG: Unknown time interval in option %s"), opt); return 0; } val = end + 1; @@ -784,7 +784,7 @@ done: secs = maxval; if (source == 0) { do_rawlog(LT_ERR, T("CONFIG: option %s value limited to %d\n"), opt, - maxval); + maxval); } } *((int *) loc) = secs; @@ -813,7 +813,7 @@ cf_flag(const char *opt, const char *val, void *loc, int maxval, int source) len = maxval - total - 1; if (len <= 0) { if (source == 0) - do_rawlog(LT_ERR, T("CONFIG: option %s value overflow\n"), opt); + do_rawlog(LT_ERR, T("CONFIG: option %s value overflow\n"), opt); return 0; } if (source == 0) @@ -842,7 +842,7 @@ config_set(const char *opt, char *val, int source, int restrictions) char *p; if (!val) - return 0; /* NULL val is no good, but "" is ok */ + return 0; /* NULL val is no good, but "" is ok */ /* Was this "restrict_command "? If so, do it */ if(!strcasecmp(opt, "lock_command")) { @@ -870,18 +870,18 @@ config_set(const char *opt, char *val, int source, int restrictions) if (*p) { *p++ = '\0'; if (!restrict_command(val, p)) { - if (source == 0) { - do_rawlog(LT_ERR, - T("CONFIG: Invalid command or restriction for %s.\n"), val); - } - return 0; + if (source == 0) { + do_rawlog(LT_ERR, + T("CONFIG: Invalid command or restriction for %s.\n"), val); + } + return 0; } } else { if (source == 0) { - do_rawlog(LT_ERR, - T - ("CONFIG: restrict_command %s requires a restriction value.\n"), - val); + do_rawlog(LT_ERR, + T + ("CONFIG: restrict_command %s requires a restriction value.\n"), + val); } return 0; } @@ -893,19 +893,19 @@ config_set(const char *opt, char *val, int source, int restrictions) if (*p) { *p++ = '\0'; if (!restrict_function(val, p)) { - if (source == 0) { - do_rawlog(LT_ERR, - T("CONFIG: Invalid function or restriction for %s.\n"), - val); - } - return 0; + if (source == 0) { + do_rawlog(LT_ERR, + T("CONFIG: Invalid function or restriction for %s.\n"), + val); + } + return 0; } } else { if (source == 0) { - do_rawlog(LT_ERR, - T - ("CONFIG: restrict_function %s requires a restriction value.\n"), - val); + do_rawlog(LT_ERR, + T + ("CONFIG: restrict_function %s requires a restriction value.\n"), + val); } return 0; } @@ -922,15 +922,15 @@ config_set(const char *opt, char *val, int source, int restrictions) if (*p) { *p++ = '\0'; if (!alias_command(val, p)) { - if (source == 0) { - do_rawlog(LT_ERR, T("CONFIG: Couldn't alias %s to %s.\n"), p, val); - } - return 0; + if (source == 0) { + do_rawlog(LT_ERR, T("CONFIG: Couldn't alias %s to %s.\n"), p, val); + } + return 0; } } else { if (source == 0) { - do_rawlog(LT_ERR, - T("CONFIG: command_alias %s requires an alias.\n"), val); + do_rawlog(LT_ERR, + T("CONFIG: command_alias %s requires an alias.\n"), val); } return 0; } @@ -942,15 +942,15 @@ config_set(const char *opt, char *val, int source, int restrictions) if (*p) { *p++ = '\0'; if (!alias_attribute(val, p)) { - if (source == 0) { - do_rawlog(LT_ERR, T("CONFIG: Couldn't alias %s to %s.\n"), p, val); - } - return 0; + if (source == 0) { + do_rawlog(LT_ERR, T("CONFIG: Couldn't alias %s to %s.\n"), p, val); + } + return 0; } } else { if (source == 0) { - do_rawlog(LT_ERR, - T("CONFIG: attribute_alias %s requires an alias.\n"), val); + do_rawlog(LT_ERR, + T("CONFIG: attribute_alias %s requires an alias.\n"), val); } return 0; } @@ -962,21 +962,21 @@ config_set(const char *opt, char *val, int source, int restrictions) if (*p) { *p++ = '\0'; if (!alias_function(val, p)) { - if (source == 0) { - do_rawlog(LT_ERR, T("CONFIG: Couldn't alias %s to %s.\n"), p, val); - } - return 0; + if (source == 0) { + do_rawlog(LT_ERR, T("CONFIG: Couldn't alias %s to %s.\n"), p, val); + } + return 0; } } else { if (source == 0) { - do_rawlog(LT_ERR, - T("CONFIG: function_alias %s requires an alias.\n"), val); + do_rawlog(LT_ERR, + T("CONFIG: function_alias %s requires an alias.\n"), val); } return 0; } return 1; } else if (!strcasecmp(opt, "help_command") - || !strcasecmp(opt, "ahelp_command")) { + || !strcasecmp(opt, "ahelp_command")) { char *comm, *file; int admin = !strcasecmp(opt, "ahelp_command"); if (!restrictions) @@ -986,8 +986,8 @@ config_set(const char *opt, char *val, int source, int restrictions) return 0; if (!val || !*val) { do_rawlog(LT_ERR, - T - ("CONFIG: help_command requires a command name and file name.\n")); + T + ("CONFIG: help_command requires a command name and file name.\n")); return 0; } comm = val; @@ -998,8 +998,8 @@ config_set(const char *opt, char *val, int source, int restrictions) return 1; } else { do_rawlog(LT_ERR, - T - ("CONFIG: help_command requires a command name and file name.\n")); + T + ("CONFIG: help_command requires a command name and file name.\n")); return 0; } } else if (restrictions) { @@ -1012,11 +1012,11 @@ config_set(const char *opt, char *val, int source, int restrictions) for (cp = conftable; cp->name; cp++) { int i = 0; if ((!source || (cp->group && strcmp(cp->group, "files") != 0 - && strcmp(cp->group, "messages") != 0)) - && !strcasecmp(cp->name, opt)) { + && strcmp(cp->group, "messages") != 0)) + && !strcasecmp(cp->name, opt)) { i = cp->handler(opt, val, cp->loc, cp->max, source); if (i) - cp->overridden = 1; + cp->overridden = 1; return i; } } @@ -1024,11 +1024,11 @@ config_set(const char *opt, char *val, int source, int restrictions) cp = (COBRA_CONF *) hash_nextentry(&local_options)) { int i = 0; if ((!source || (cp->group && strcmp(cp->group, "files") != 0 - && strcmp(cp->group, "messages") != 0)) - && !strcasecmp(cp->name, opt)) { + && strcmp(cp->group, "messages") != 0)) + && !strcasecmp(cp->name, opt)) { i = cp->handler(opt, val, cp->loc, cp->max, source); if (i) - cp->overridden = 1; + cp->overridden = 1; return i; } } @@ -1075,7 +1075,7 @@ conf_default_set(void) options.keepalive_timeout = 300; options.dump_interval = 3601; strcpy(options.dump_message, - T("GAME: Dumping database. Game may freeze for a minute")); + T("GAME: Dumping database. Game may freeze for a minute")); strcpy(options.dump_complete, T("GAME: Dump complete. Time in.")); options.ident_timeout = 5; options.max_logins = 128; @@ -1107,7 +1107,7 @@ conf_default_set(void) strcpy(options.compressprog, "compress"); strcpy(options.uncompressprog, "uncompress"); strcpy(options.compresssuff, ".Z"); -#endif /* WIN32 */ +#endif /* WIN32 */ strcpy(options.connect_file[0], "txt/connect.txt"); strcpy(options.motd_file[0], "txt/motd.txt"); strcpy(options.newuser_file[0], "txt/newuser.txt"); @@ -1136,9 +1136,9 @@ conf_default_set(void) options.warn_interval = 3600; options.use_dns = 1; strcpy(options.dump_warning_1min, - T("GAME: Database will be dumped in 1 minute.")); + T("GAME: Database will be dumped in 1 minute.")); strcpy(options.dump_warning_5min, - T("GAME: Database will be dumped in 5 minutes.")); + T("GAME: Database will be dumped in 5 minutes.")); options.noisy_whisper = 0; options.possessive_get = 1; options.possessive_get_d = 1; @@ -1218,7 +1218,7 @@ conf_default_set(void) strcpy(options.ssl_ca_file, ""); options.ssl_require_client_cert = 0; #endif - options.mem_check = 0; + options.mem_check = 1; #ifdef HAS_MYSQL strcpy(options.sql_platform, "disabled"); strcpy(options.sql_database, ""); @@ -1260,7 +1260,7 @@ config_file_startup(const char *conf, int restrictions) char tbuf1[BUFFER_LEN]; char *p, *q, *s; - static char cfile[BUFFER_LEN]; /* Remember the last one */ + static char cfile[BUFFER_LEN]; /* Remember the last one */ if (conf_recursion == 0) { if (conf && *conf) strcpy(cfile, conf); @@ -1275,7 +1275,7 @@ config_file_startup(const char *conf, int restrictions) fp = fopen(conf, FOPEN_READ); if (fp == NULL) { do_rawlog(LT_ERR, T("ERROR: Cannot open configuration file %s."), - (conf && *conf) ? conf : "Unknown"); + (conf && *conf) ? conf : "Unknown"); return 0; } do_rawlog(LT_ERR, "Reading %s", conf); @@ -1299,43 +1299,43 @@ config_file_startup(const char *conf, int restrictions) */ for (p = tbuf1; *p && (*p != '\n') && (*p != '\r'); p++) ; - *p = '\0'; /* strip the end of line char(s) */ - for (p = tbuf1; *p && isspace((unsigned char) *p); p++) /* strip spaces */ + *p = '\0'; /* strip the end of line char(s) */ + for (p = tbuf1; *p && isspace((unsigned char) *p); p++) /* strip spaces */ ; - for (q = p; *q && !isspace((unsigned char) *q); q++) /* move over command */ + for (q = p; *q && !isspace((unsigned char) *q); q++) /* move over command */ ; if (*q) - *q++ = '\0'; /* split off command */ - for (; *q && isspace((unsigned char) *q); q++) /* skip spaces */ + *q++ = '\0'; /* split off command */ + for (; *q && isspace((unsigned char) *q); q++) /* skip spaces */ ; /* If the first character of the value is a #, and that is followed by a number, treat it as a dbref instead of a comment. */ if (*q == '#' && isdigit((unsigned char) *(q + 1))) { - for (s = q + 1; *s && (*s != '#'); s++) /* look for a real comment */ - ; + for (s = q + 1; *s && (*s != '#'); s++) /* look for a real comment */ + ; } else { - for (s = q; *s && (*s != '#'); s++) /* look for comment */ - ; + for (s = q; *s && (*s != '#'); s++) /* look for comment */ + ; } - if (*s) /* if found nuke it */ + if (*s) /* if found nuke it */ *s = '\0'; - for (s = s - 1; (s >= q) && isspace((unsigned char) *s); s--) /* smash trailing stuff */ + for (s = s - 1; (s >= q) && isspace((unsigned char) *s); s--) /* smash trailing stuff */ *s = '\0'; - if (strlen(p) != 0) { /* skip blank lines */ + if (strlen(p) != 0) { /* skip blank lines */ /* Handle include filename directives separetly */ if (strcasecmp(p, "include") == 0) { - conf_recursion++; - if (conf_recursion > 10) { - do_rawlog(LT_ERR, T("CONFIG: include depth too deep in file %s"), - conf); - } else { - config_file_startup(q, restrictions); - } - conf_recursion--; + conf_recursion++; + if (conf_recursion > 10) { + do_rawlog(LT_ERR, T("CONFIG: include depth too deep in file %s"), + conf); + } else { + config_file_startup(q, restrictions); + } + conf_recursion--; } else - config_set(p, q, 0, restrictions); + config_set(p, q, 0, restrictions); } fgets(tbuf1, BUFFER_LEN, fp); } @@ -1373,16 +1373,16 @@ config_file_startup(const char *conf, int restrictions) /* if we're on Win32, complain about compression */ if ((options.compressprog && *options.compressprog)) { do_rawlog(LT_ERR, - T - ("CONFIG: compression program is specified but not used in Win32, ignoring"), - options.compressprog); + T + ("CONFIG: compression program is specified but not used in Win32, ignoring"), + options.compressprog); } if (((options.compresssuff && *options.compresssuff))) { do_rawlog(LT_ERR, - T - ("CONFIG: compression suffix is specified but not used in Win32, ignoring"), - options.compresssuff); + T + ("CONFIG: compression suffix is specified but not used in Win32, ignoring"), + options.compresssuff); } /* Also remove the compression options */ @@ -1490,7 +1490,7 @@ config_list_helper(dbref player __attribute__ ((__unused__)), COBRA_CONF *cp, in safe_format(result, &bp, " %-40s %s", MAYBE_LC(cp->name), (char *) cp->loc); else if (cp->handler == cf_int) safe_format(result, &bp, " %-40s %d", MAYBE_LC(cp->name), - *((int *) cp->loc)); + *((int *) cp->loc)); else if (cp->handler == cf_time) { div_t n; int secs = *(int *) cp->loc; @@ -1511,10 +1511,10 @@ config_list_helper(dbref player __attribute__ ((__unused__)), COBRA_CONF *cp, in safe_format(result, &bp, "%ds", secs); } else if (cp->handler == cf_bool) safe_format(result, &bp, " %-40s %s", MAYBE_LC(cp->name), - (*((int *) cp->loc) ? "Yes" : "No")); + (*((int *) cp->loc) ? "Yes" : "No")); else if (cp->handler == cf_dbref) safe_format(result, &bp, " %-40s #%d", MAYBE_LC(cp->name), - *((dbref *) cp->loc)); + *((dbref *) cp->loc)); *bp = '\0'; return result; } @@ -1616,15 +1616,15 @@ do_enable(dbref player, const char *param, int state) for (cp = conftable; cp->name; cp++) { if (cp->group && !strcasecmp(cp->name, param)) { if (cp->handler == cf_bool) { - cf_bool(param, (state ? "yes" : "no"), cp->loc, cp->max, 1); - if (state == 0) - notify(player, T("Disabled.")); - else - notify(player, T("Enabled.")); - do_log(LT_WIZ, player, NOTHING, "%s %s", - cp->name, (state) ? "ENABLED" : "DISABLED"); + cf_bool(param, (state ? "yes" : "no"), cp->loc, cp->max, 1); + if (state == 0) + notify(player, T("Disabled.")); + else + notify(player, T("Enabled.")); + do_log(LT_WIZ, player, NOTHING, "%s %s", + cp->name, (state) ? "ENABLED" : "DISABLED"); } else - notify(player, T("That isn't a on/off option.")); + notify(player, T("That isn't a on/off option.")); return; } } diff --git a/src/cque.c b/src/cque.c index cc628a6..b455e8f 100644 --- a/src/cque.c +++ b/src/cque.c @@ -138,23 +138,23 @@ waitable_attr(dbref thing, const char *atr) if (!atr || !*atr) return 0; a = atr_get_noparent(thing, atr); - if (!a) { /* Attribute isn't set */ + if (!a) { /* Attribute isn't set */ a = atr_match(atr); - if (!a) /* It's not a built in attribute */ + if (!a) /* It's not a built in attribute */ return 1; - return !strcmp(AL_NAME(a), "SEMAPHORE"); /* Only allow SEMAPHORE for now */ - } else { /* Attribute is set. Check for proper owner and flags and value */ + return !strcmp(AL_NAME(a), "SEMAPHORE"); /* Only allow SEMAPHORE for now */ + } else { /* Attribute is set. Check for proper owner and flags and value */ if ((AL_CREATOR(a) == GOD) && (AL_FLAGS(a) == SEMAPHORE_FLAGS)) { char *v = atr_value(a); if (!*v || is_integer(v)) - return 1; + return 1; else - return 0; + return 0; } else { return 0; } } - return 0; /* Not reached */ + return 0; /* Not reached */ } static int @@ -189,7 +189,7 @@ static int add_to_sem(dbref player, int am, const char *name) { return (add_to_generic - (player, am, name ? name : "SEMAPHORE", SEMAPHORE_FLAGS)); + (player, am, name ? name : "SEMAPHORE", SEMAPHORE_FLAGS)); } static int @@ -314,7 +314,7 @@ parse_que(dbref player, const char *command, dbref cause) int qid; if (!IsPlayer(player) && (Halted(player))) return; - if (!pay_queue(player, command)) /* make sure player can afford to do it */ + if (!pay_queue(player, command)) /* make sure player can afford to do it */ return; if((qid = create_qid()) == -1) /* No room for a process ID, don't do anything */ return; @@ -428,7 +428,7 @@ div_parse_que(dbref division, const char *command, dbref called_division, dbref */ int queue_attribute_base(dbref executor, const char *atrname, dbref enactor, - int noparent) + int noparent) { ATTR *a; @@ -443,7 +443,7 @@ ATTR * queue_attribute_getatr(dbref executor, const char *atrname, int noparent) { return (noparent ? atr_get_noparent(executor, strupper(atrname)) : - atr_get(executor, strupper(atrname))); + atr_get(executor, strupper(atrname))); } int @@ -550,7 +550,7 @@ wait_que(dbref player, int waittill, char *command, dbref cause, dbref sem, if (waittill >= 0) tmp->left = mudtime + waittill; else - tmp->left = 0; /* semaphore wait without a timeout */ + tmp->left = 0; /* semaphore wait without a timeout */ } tmp->sem = sem; if (sem == NOTHING) { @@ -558,7 +558,7 @@ wait_que(dbref player, int waittill, char *command, dbref cause, dbref sem, BQUE *point, *trail = NULL; for (point = qwait; - point && (point->left <= tmp->left); point = point->next) + point && (point->left <= tmp->left); point = point->next) trail = point; tmp->next = point; @@ -617,16 +617,16 @@ do_second(void) point->left = 0; if (IsPlayer(point->cause)) { if (qlast) { - qlast->next = point; - qlast = point; + qlast->next = point; + qlast = point; } else - qlast = qfirst = point; + qlast = qfirst = point; } else { if (qllast) { - qllast->next = point; - qllast = point; + qllast->next = point; + qllast = point; } else - qllast = qlfirst = point; + qllast = qlfirst = point; } } @@ -648,16 +648,16 @@ do_second(void) point->next = NULL; if (IsPlayer(point->cause)) { if (qlast) { - qlast->next = point; - qlast = point; + qlast->next = point; + qlast = point; } else - qlast = qfirst = point; + qlast = qfirst = point; } else { if (qllast) { - qllast->next = point; - qllast = point; + qllast->next = point; + qllast = point; } else - qllast = qlfirst = point; + qllast = qlfirst = point; } } } @@ -721,8 +721,9 @@ do_top(int ncom) local_ooref = ooref; ooref = entry->ooref; if(!entry->fqueued) { - process_expression(global_eval_context.ccom, &r, &s, global_eval_context.cplr, entry->cause, - entry->realcause, PE_NOTHING, PT_SEMI, NULL); + process_expression(global_eval_context.ccom, &r, &s, + global_eval_context.cplr, entry->cause, + entry->realcause, PE_NOTHING, PT_SEMI, NULL); *r = '\0'; if (*s == ';') s++; @@ -743,8 +744,9 @@ do_top(int ncom) } } } else { - process_expression(global_eval_context.ccom, &r, &s, global_eval_context.cplr, entry->cause, entry->realcause, PE_DEFAULT, - PT_DEFAULT, (PE_Info *) NULL); + process_expression(global_eval_context.ccom, &r, &s, + global_eval_context.cplr, entry->cause, entry->realcause, PE_DEFAULT, + PT_DEFAULT, (PE_Info *) NULL); *r = '\0'; notify(global_eval_context.cplr, global_eval_context.ccom); } @@ -799,7 +801,7 @@ que_next(void) } for (point = qsemfirst; point; point = point->next) { - if (point->left == 0) /* no timeout */ + if (point->left == 0) /* no timeout */ continue; curr = (int) difftime(point->left, mudtime); if (curr <= 2) @@ -814,9 +816,9 @@ que_next(void) static int drain_helper(dbref player __attribute__ ((__unused__)), dbref thing, - dbref parent __attribute__ ((__unused__)), - char const *pattern __attribute__ ((__unused__)), ATTR *atr, - void *args __attribute__ ((__unused__))) + dbref parent __attribute__ ((__unused__)), + char const *pattern __attribute__ ((__unused__)), ATTR *atr, + void *args __attribute__ ((__unused__))) { if (waitable_attr(thing, AL_NAME(atr))) (void) atr_clr(thing, AL_NAME(atr), GOD); @@ -834,7 +836,7 @@ drain_helper(dbref player __attribute__ ((__unused__)), dbref thing, */ void dequeue_semaphores(dbref thing, char const *aname, int count, int all, - int drain) + int drain) { BQUE **point; BQUE *entry; @@ -857,8 +859,8 @@ dequeue_semaphores(dbref thing, char const *aname, int count, int all, if (qsemlast == entry) { qsemlast = qsemfirst; if (qsemlast) - while (qsemlast->next) - qsemlast = qsemlast->next; + while (qsemlast->next) + qsemlast = qsemlast->next; } /* Update bookkeeping */ @@ -873,17 +875,17 @@ dequeue_semaphores(dbref thing, char const *aname, int count, int all, free_qentry(entry); } else if (IsPlayer(entry->cause)) { if (qlast) { - qlast->next = entry; - qlast = entry; + qlast->next = entry; + qlast = entry; } else { - qlast = qfirst = entry; + qlast = qfirst = entry; } } else { if (qllast) { - qllast->next = entry; - qllast = entry; + qllast->next = entry; + qllast = entry; } else { - qllast = qlfirst = entry; + qllast = qlfirst = entry; } } } @@ -925,8 +927,8 @@ COMMAND (cmd_notify_drain) { if (pos) { if (SW_ISSET(sw, SWITCH_ANY)) { notify(player, - T - ("You may not specify a semaphore attribute with the ANY switch.")); + T + ("You may not specify a semaphore attribute with the ANY switch.")); return; } *pos++ = '\0'; @@ -958,7 +960,7 @@ COMMAND (cmd_notify_drain) { if (arg_right && *arg_right) { if (all) { notify(player, - T("You may not specify a semaphore count with the ALL switch.")); + T("You may not specify a semaphore count with the ALL switch.")); return; } if (!is_uinteger(arg_right)) { @@ -1038,13 +1040,13 @@ do_wait(dbref player, dbref cause, char *arg1, char *cmd, int until, char finvoc if (aname) { tcount = strchr(aname, '/'); if (!tcount) { - if (is_strict_integer(aname)) { /* Timeout */ - tcount = aname; - aname = (char *) "SEMAPHORE"; - } else { /* Attribute */ - upcasestr(aname); + if (is_strict_integer(aname)) { /* Timeout */ + tcount = aname; + aname = (char *) "SEMAPHORE"; + } else { /* Attribute */ + upcasestr(aname); } - } else { /* attribute/timeout */ + } else { /* attribute/timeout */ *tcount++ = '\0'; upcasestr(aname); } @@ -1071,7 +1073,7 @@ do_wait(dbref player, dbref cause, char *arg1, char *cmd, int until, char finvoc num = 0; if (num <= 0) { thing = NOTHING; - waitfor = -1; /* just in case there was a timeout given */ + waitfor = -1; /* just in case there was a timeout given */ } qid = wait_que(player, waitfor, arg2, cause, thing, aname, until, finvoc); mush_free(arg2, "strip_braces.buff"); @@ -1080,7 +1082,7 @@ do_wait(dbref player, dbref cause, char *arg1, char *cmd, int until, char finvoc static void show_queue(dbref player, dbref victim, int q_type, int q_quiet, int q_all, - BQUE *q_ptr, int *tot, int *self, int *del) + BQUE *q_ptr, int *tot, int *self, int *del) { BQUE *tmp; for (tmp = q_ptr; tmp; tmp = tmp->next) { @@ -1088,9 +1090,11 @@ show_queue(dbref player, dbref victim, int q_type, int q_quiet, int q_all, if (!GoodObject(tmp->player)) (*del)++; else if (q_all || (Owner(tmp->player) == victim)) { - (*self)++; - if (!q_quiet && (CanSeeQ(player, victim) + if ((CanSeeQ(player, victim) || Owns(tmp->player, player))) { + (*self)++; + if(q_quiet) + continue; switch (q_type) { case 1: /* wait queue */ notify_format(player, "[QID: %d%s/%ld]%s:%s", tmp->qid, qid_table[tmp->qid] == QID_FREEZE ? "(F)" : "", @@ -1143,7 +1147,7 @@ do_queue(dbref player, const char *what, enum queue_type flag) victim = player; else victim = match_result(player, what, TYPE_PLAYER, - MAT_PLAYER | MAT_ABSOLUTE | MAT_ME); + MAT_PLAYER | MAT_ABSOLUTE | MAT_ME); } if (!CanSeeQ(player, victim)) victim = player; @@ -1179,8 +1183,8 @@ do_queue(dbref player, const char *what, enum queue_type flag) if (!quick) notify(player, T("------------ Queue Done ------------")); notify_format(player, - "Totals: Player...%d/%d[%ddel] Object...%d/%d[%ddel] Wait...%d/%d Semaphore...%d/%d", - pq, tpq, dpq, oq, toq, doq, wq, twq, sq, tsq); + "Totals: Player...%d/%d[%ddel] Object...%d/%d[%ddel] Wait...%d/%d Semaphore...%d/%d", + pq, tpq, dpq, oq, toq, doq, wq, twq, sq, tsq); } } @@ -1366,19 +1370,19 @@ do_halt(dbref owner, const char *ncom, dbref victim) else player = victim; quiet_notify(Owner(player), - tprintf("%s: %s(#%d).", T("Halted"), Name(player), player)); + tprintf("%s: %s(#%d).", T("Halted"), Name(player), player)); for (tmp = qfirst; tmp; tmp = tmp->next) if (GoodObject(tmp->player) - && ((tmp->player == player) - || (Owner(tmp->player) == player))) { + && ((tmp->player == player) + || (Owner(tmp->player) == player))) { num--; giveto(player, QUEUE_COST); tmp->player = NOTHING; } for (tmp = qlfirst; tmp; tmp = tmp->next) if (GoodObject(tmp->player) - && ((tmp->player == player) - || (Owner(tmp->player) == player))) { + && ((tmp->player == player) + || (Owner(tmp->player) == player))) { num--; giveto(player, QUEUE_COST); tmp->player = NOTHING; @@ -1386,13 +1390,13 @@ do_halt(dbref owner, const char *ncom, dbref victim) /* remove wait q stuff */ for (point = qwait; point; point = next) { if (((point->player == player) - || (Owner(point->player) == player))) { + || (Owner(point->player) == player))) { num--; giveto(player, QUEUE_COST); if (trail) - trail->next = next = point->next; + trail->next = next = point->next; else - qwait = next = point->next; + qwait = next = point->next; free_qentry(point); } else next = (trail = point)->next; @@ -1402,15 +1406,15 @@ do_halt(dbref owner, const char *ncom, dbref victim) for (point = qsemfirst, trail = NULL; point; point = next) { if (((point->player == player) - || (Owner(point->player) == player))) { + || (Owner(point->player) == player))) { num--; giveto(player, QUEUE_COST); if (trail) - trail->next = next = point->next; + trail->next = next = point->next; else - qsemfirst = next = point->next; + qsemfirst = next = point->next; if (point == qsemlast) - qsemlast = trail; + qsemlast = trail; add_to_sem(point->sem, -1, point->semattr); free_qentry(point); } else @@ -1446,8 +1450,8 @@ do_halt1(dbref player, const char *arg1, const char *arg2) do_halt(player, "", player); else { if ((victim = - noisy_match_result(player, arg1, NOTYPE, - MAT_OBJECTS | MAT_HERE)) == NOTHING) + noisy_match_result(player, arg1, NOTYPE, + MAT_OBJECTS | MAT_HERE)) == NOTHING) return; if (!Owns(player, victim) && !CanHalt(player, victim)) { notify(player, T("Permission denied.")); @@ -1463,24 +1467,24 @@ do_halt1(dbref player, const char *arg1, const char *arg2) do_halt(player, arg2, victim); if (IsPlayer(victim)) { if (victim == player) { - notify(player, T("All of your objects have been halted.")); + notify(player, T("All of your objects have been halted.")); } else { - notify_format(player, - T("All objects for %s have been halted."), Name(victim)); - notify_format(victim, - T("All of your objects have been halted by %s."), - Name(player)); + notify_format(player, + T("All objects for %s have been halted."), Name(victim)); + notify_format(victim, + T("All of your objects have been halted by %s."), + Name(player)); } } else { if (Owner(victim) != player) { - notify_format(player, "%s: %s's %s(%s)", T("Halted"), - Name(Owner(victim)), Name(victim), unparse_dbref(victim)); - notify_format(Owner(victim), - "%s: %s(%s), by %s", T("Halted"), - Name(victim), unparse_dbref(victim), Name(player)); + notify_format(player, "%s: %s's %s(%s)", T("Halted"), + Name(Owner(victim)), Name(victim), unparse_dbref(victim)); + notify_format(Owner(victim), + "%s: %s(%s), by %s", T("Halted"), + Name(victim), unparse_dbref(victim), Name(player)); } if (*arg2 == '\0') - set_flag_internal(victim, "HALT"); + set_flag_internal(victim, "HALT"); } } } @@ -1494,14 +1498,14 @@ do_allhalt(dbref player) dbref victim; if (!HaltAny(player)) { notify(player, - T("You do not have the power to bring the world to a halt.")); + T("You do not have the power to bring the world to a halt.")); return; } for (victim = 0; victim < db_top; victim++) { if (IsPlayer(victim)) { notify_format(victim, - T("Your objects have been globally halted by %s"), - Name(player)); + T("Your objects have been globally halted by %s"), + Name(player)); do_halt(victim, "", victim); } } @@ -1530,8 +1534,8 @@ do_allrestart(dbref player) } if (IsPlayer(thing)) { notify_format(thing, - T("Your objects are being globally restarted by %s"), - Name(player)); + T("Your objects are being globally restarted by %s"), + Name(player)); } } } @@ -1545,8 +1549,8 @@ do_raw_restart(victim) if (IsPlayer(victim)) { for (thing = 0; thing < db_top; thing++) { if ((Owner(thing) == victim) && !IsGarbage(thing) - && !(Halted(thing))) - (void) queue_attribute_noparent(thing, "STARTUP", thing); + && !(Halted(thing))) + (void) queue_attribute_noparent(thing, "STARTUP", thing); } } else { /* A single object */ @@ -1568,7 +1572,7 @@ do_restart_com(dbref player, const char *arg1) do_raw_restart(player); } else { if ((victim = - noisy_match_result(player, arg1, NOTYPE, MAT_OBJECTS)) == NOTHING) + noisy_match_result(player, arg1, NOTYPE, MAT_OBJECTS)) == NOTHING) return; if (!Owns(player, victim) && !CanHalt(player, victim)) { notify(player, T("Permission denied.")); @@ -1576,26 +1580,26 @@ do_restart_com(dbref player, const char *arg1) } if (Owner(victim) != player) { if (IsPlayer(victim)) { - notify_format(player, - T("All objects for %s are being restarted."), - Name(victim)); - notify_format(victim, - T("All of your objects are being restarted by %s."), - Name(player)); + notify_format(player, + T("All objects for %s are being restarted."), + Name(victim)); + notify_format(victim, + T("All of your objects are being restarted by %s."), + Name(player)); } else { - notify_format(player, - "Restarting: %s's %s(%s)", - Name(Owner(victim)), Name(victim), unparse_dbref(victim)); - notify_format(Owner(victim), - "Restarting: %s(%s), by %s", - Name(victim), unparse_dbref(victim), Name(player)); + notify_format(player, + "Restarting: %s's %s(%s)", + Name(Owner(victim)), Name(victim), unparse_dbref(victim)); + notify_format(Owner(victim), + "Restarting: %s(%s), by %s", + Name(victim), unparse_dbref(victim), Name(player)); } } else { if (victim == player) - notify(player, T("All of your objects are being restarted.")); + notify(player, T("All of your objects are being restarted.")); else - notify_format(player, "Restarting: %s(%s)", Name(victim), - unparse_dbref(victim)); + notify_format(player, "Restarting: %s(%s)", Name(victim), + unparse_dbref(victim)); } do_halt(player, "", victim); do_raw_restart(victim); diff --git a/src/create.c b/src/create.c index f2b35fc..a3e68aa 100644 --- a/src/create.c +++ b/src/create.c @@ -27,7 +27,7 @@ static dbref parse_linkable_room(dbref player, const char *room_name); static dbref check_var_link(const char *dest_name); static dbref clone_object(dbref player, dbref thing, const char *newname, - int preserve); + int preserve); struct db_stat_info current_state; /**< Current stats for database */ @@ -46,7 +46,7 @@ parse_linkable_room(dbref player, const char *room_name) if (!strcasecmp(room_name, "here")) { room = IsExit(player) ? Source(player) : Location(player); } else if (!strcasecmp(room_name, "home")) { - return HOME; /* HOME is always linkable */ + return HOME; /* HOME is always linkable */ } else { room = parse_dbref(room_name); } @@ -90,7 +90,7 @@ check_var_link(const char *dest_name) */ dbref do_real_open(dbref player, const char *direction, const char *linkto, - dbref pseudo) + dbref pseudo) { dbref loc = (pseudo != @@ -142,15 +142,15 @@ do_real_open(dbref player, const char *direction, const char *linkto, if (linkto && *linkto != '\0') { notify(player, T("Trying to link...")); if ((loc = check_var_link(linkto)) == NOTHING) - loc = parse_linkable_room(player, linkto); + loc = parse_linkable_room(player, linkto); if (loc != NOTHING) { - if (!payfor(player, LINK_COST)) { - notify_format(player, T("You don't have enough %s to link."), MONIES); - } else { - /* it's ok, link it */ - Location(new_exit) = loc; - notify_format(player, T("Linked exit #%d to #%d"), new_exit, loc); - } + if (!payfor(player, LINK_COST)) { + notify_format(player, T("You don't have enough %s to link."), MONIES); + } else { + /* it's ok, link it */ + Location(new_exit) = loc; + notify_format(player, T("Linked exit #%d to #%d"), new_exit, loc); + } } } current_state.exits++; @@ -209,18 +209,18 @@ do_unlink(dbref player, const char *name) } else { switch (Typeof(exit_l)) { case TYPE_EXIT: - old_loc = Location(exit_l); - Location(exit_l) = NOTHING; - notify_format(player, T("Unlinked exit #%d (Used to lead to %s)."), - exit_l, unparse_object(player, old_loc)); - break; + old_loc = Location(exit_l); + Location(exit_l) = NOTHING; + notify_format(player, T("Unlinked exit #%d (Used to lead to %s)."), + exit_l, unparse_object(player, old_loc)); + break; case TYPE_ROOM: - Location(exit_l) = NOTHING; - notify(player, T("Dropto removed.")); - break; + Location(exit_l) = NOTHING; + notify(player, T("Dropto removed.")); + break; default: - notify(player, T("You can't unlink that!")); - break; + notify(player, T("You can't unlink that!")); + break; } } } @@ -424,7 +424,7 @@ do_dig(dbref player, const char *name, char **argv, int tport) * and Z_TEL checking */ char roomstr[MAX_COMMAND_LEN]; sprintf(roomstr, "#%d", room); - do_teleport(player, "me", roomstr, 0, 0); /* if flag, move the player */ + do_teleport(player, "me", roomstr, 0, 0); /* if flag, move the player */ } return room; } @@ -461,7 +461,7 @@ do_create(dbref player, char *name, int cost) /* initialize everything */ set_name(thing, name); - if (!IsExit(player)) /* Exits shouldn't have contents! */ + if (!IsExit(player)) /* Exits shouldn't have contents! */ Location(thing) = player; else Location(thing) = Source(player); @@ -476,10 +476,10 @@ do_create(dbref player, char *name, int cost) /* home is here (if we can link to it) or player's home */ if ((loc = Location(player)) != NOTHING && - (controls(player, loc) || Abode(loc))) { - Home(thing) = loc; /* home */ + (controls(player, loc) || Abode(loc))) { + Home(thing) = loc; /* home */ } else { - Home(thing) = Home(player); /* home */ + Home(thing) = Home(player); /* home */ } /* link it in */ @@ -581,7 +581,7 @@ do_clone(dbref player, char *name, char *newname, int preserve) } if (preserve && !Director(player)) { notify(player, - T("You cannot @CLONE/PRESERVE. Use normal @CLONE instead.")); + T("You cannot @CLONE/PRESERVE. Use normal @CLONE instead.")); return NOTHING; } /* make sure owner can afford it */ @@ -591,13 +591,13 @@ do_clone(dbref player, char *name, char *newname, int preserve) clone = clone_object(player, thing, newname, preserve); notify_format(player, T("Cloned: Object %s."), unparse_dbref(clone)); if (IsRoom(player)) - moveto(clone, player); + moveto(clone, player); else - moveto(clone, Location(player)); + moveto(clone, Location(player)); current_state.things++; local_data_clone(clone, thing); real_did_it(player, clone, NULL, NULL, NULL, NULL, "ACLONE", NOTHING, - global_eval_context.wenv, 0); + global_eval_context.wenv, 0); return clone; } return NOTHING; @@ -610,7 +610,7 @@ do_clone(dbref player, char *name, char *newname, int preserve) current_state.rooms++; local_data_clone(clone, thing); real_did_it(player, clone, NULL, NULL, NULL, NULL, "ACLONE", NOTHING, - global_eval_context.wenv, 0); + global_eval_context.wenv, 0); return clone; } return NOTHING; diff --git a/src/csrimalloc.c b/src/csrimalloc.c index 924510a..d214696 100644 --- a/src/csrimalloc.c +++ b/src/csrimalloc.c @@ -22,7 +22,7 @@ #include "conf.h" #include "externs.h" #include "mymalloc.h" -#include "csrimalloc.h" /* Must be after mymalloc.h! */ +#include "csrimalloc.h" /* Must be after mymalloc.h! */ #ifdef CSRI_TRACE #undef malloc(x) @@ -37,7 +37,7 @@ #undef strsave(p) #undef cfree(p) #undef free(p) -extern char *strdup _((const char *)); +extern char *strdup(const char *); #endif @@ -98,7 +98,7 @@ extern char *getenv proto((const char *)); * sprintf(). */ -#if 0 /* can't win with this one */ +#if 0 /* can't win with this one */ extern int sprintf proto((char *, const char *, ...)); #endif @@ -111,6 +111,9 @@ extern int setvbuf proto((FILE *, char *, int, memsize_t)); /* Character Handling: */ +#if 0 +/* We'd better not have to do this - Javelin */ + #ifndef HAS_MEMSET extern univptr_t memset proto((univptr_t, int, memsize_t)); #endif @@ -119,8 +122,6 @@ extern univptr_t memset proto((univptr_t, int, memsize_t)); extern univptr_t memcpy proto((univptr_t, const univptr_t, memsize_t)); #endif -#if 0 -/* We'd better not have to do this - Javelin */ extern char *strcpy proto((char *, const char *)); extern memsize_t strlen proto((const char *)); #endif @@ -133,19 +134,19 @@ extern int open proto((const char * /*path */ , int /*flags */ , ...)); #define caddr_t char * extern caddr_t sbrk proto((int)); -#ifdef _SC_PAGESIZE /* Solaris 2.x, SVR4? */ +#ifdef _SC_PAGESIZE /* Solaris 2.x, SVR4? */ #define getpagesize() sysconf(_SC_PAGESIZE) -#else /* ! _SC_PAGESIZE */ -#ifdef _SC_PAGE_SIZE /* HP, IBM */ +#else /* ! _SC_PAGESIZE */ +#ifdef _SC_PAGE_SIZE /* HP, IBM */ #define getpagesize() sysconf(_SC_PAGE_SIZE) -#else /* ! _SC_PAGE_SIZE */ +#else /* ! _SC_PAGE_SIZE */ #ifndef getpagesize extern int getpagesize proto((void)); -#endif /* getpagesize */ -#endif /* _SC_PAGE_SIZE */ -#endif /* _SC_PAGESIZE */ +#endif /* getpagesize */ +#endif /* _SC_PAGE_SIZE */ +#endif /* _SC_PAGESIZE */ -#ifdef _AIX /* IBM AIX doesn't declare sbrk, but is STDHEADERS. */ +#ifdef _AIX /* IBM AIX doesn't declare sbrk, but is STDHEADERS. */ extern caddr_t sbrk proto((int)); #endif @@ -184,7 +185,7 @@ extern int madvise proto((caddr_t, size_t, int)); extern caddr_t mmap proto((caddr_t, size_t, int, int, int, off_t)); #endif -#endif /* EXTERNS_H__ */ /* Do not add anything after this line */ +#endif /* EXTERNS_H__ */ /* Do not add anything after this line */ /* $Id: csrimalloc.c,v 1.2 2005-12-13 20:34:11 ari Exp $ */ #ifndef __ASSERT_H__ @@ -204,7 +205,7 @@ proto((const char *, const char *, univptr_t, int, const char *, int)); #define ASSERT_SP(p, s, s2, sp) #define ASSERT_EP(p, s, s2, ep) #endif -#endif /* __ASSERT_H__ */ /* Do not add anything after this line */ +#endif /* __ASSERT_H__ */ /* Do not add anything after this line */ #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif @@ -299,19 +300,19 @@ static size_t _N = NALIGN; /* a number used normally for size of a shift */ #if gcos #define BITSPERBYTE 9 -#else /* ! gcos */ +#else /* ! gcos */ #define BITSPERBYTE 8 -#endif /* gcos */ -#endif /* BITSPERBYTE */ +#endif /* gcos */ +#endif /* BITSPERBYTE */ #ifndef BITS #define BITS(type) (BITSPERBYTE * (int) sizeof(type)) -#endif /* BITS */ +#endif /* BITS */ /* size_t with only the high-order bit turned on */ #define HIBITSZ (((size_t) 1) << (BITS(size_t) - 1)) -#endif /* __ALIGN_H__ */ /* Do not add anything after this line */ +#endif /* __ALIGN_H__ */ /* Do not add anything after this line */ /* * We assume that FREE is a 0 bit, and the tag for a free block, Or'ing the @@ -327,18 +328,18 @@ static size_t _N = NALIGN; #define DEF_SBRKUNITS 1024 -union word { /* basic unit of storage */ - size_t size; /* size of this block + 1 bit status */ - union word *next; /* next free block */ - union word *prev; /* prev free block */ - univptr_t ptr; /* stops lint complaining, keeps alignment */ +union word { /* basic unit of storage */ + size_t size; /* size of this block + 1 bit status */ + union word *next; /* next free block */ + union word *prev; /* prev free block */ + univptr_t ptr; /* stops lint complaining, keeps alignment */ char c; int i; char *cp; char **cpp; int *ip; int **ipp; - ALIGN; /* alignment stuff - wild fun */ + ALIGN; /* alignment stuff - wild fun */ }; typedef union word Word; @@ -405,7 +406,7 @@ typedef union word Word; #ifdef CSRI_DEBUG #define REALSIZE(sp) (((sp)+1)->size) -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ #define NEXT(ep) (((ep)-1)->next) #define PREV(ep) (((ep)-2)->prev) @@ -415,16 +416,16 @@ typedef union word Word; * free block header uses extra words in the block itself */ #ifdef CSRI_DEBUG -#define HEADERWORDS 2 /* Start boundary tag + real size in bytes */ -#else /* ! CSRI_DEBUG */ -#define HEADERWORDS 1 /* Start boundary tag */ -#endif /* CSRI_DEBUG */ +#define HEADERWORDS 2 /* Start boundary tag + real size in bytes */ +#else /* ! CSRI_DEBUG */ +#define HEADERWORDS 1 /* Start boundary tag */ +#endif /* CSRI_DEBUG */ #define TRAILERWORDS 1 -#define FREEHEADERWORDS 1 /* Start boundary tag */ +#define FREEHEADERWORDS 1 /* Start boundary tag */ -#define FREETRAILERWORDS 3 /* next and prev, end boundary tag */ +#define FREETRAILERWORDS 3 /* next and prev, end boundary tag */ #define ALLOC_OVERHEAD (HEADERWORDS + TRAILERWORDS) #define FREE_OVERHEAD (FREEHEADERWORDS + FREETRAILERWORDS) @@ -442,7 +443,7 @@ typedef union word Word; * tags that are permanantly marked allocated, so that no attempt is * made to coalesce past them. See the code in dumpheap for more info. */ -#define ARENASTART 2 /* next ptr + fake start tag */ +#define ARENASTART 2 /* next ptr + fake start tag */ #ifdef CSRI_DEBUG /* @@ -450,10 +451,10 @@ typedef union word Word; * REALSIZE word */ #define FIXEDOVERHEAD (1 + ALLOC_OVERHEAD) -#else /* ! CSRI_DEBUG */ +#else /* ! CSRI_DEBUG */ /* 1 for prev link, 1 for next link, + header and trailer */ #define FIXEDOVERHEAD (2 + ALLOC_OVERHEAD) -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ /* * Check that pointer is safe to dereference i.e. actually points @@ -485,7 +486,7 @@ typedef union word Word; */ #ifndef u_char #define u_char unsigned char -#endif /* u_char */ +#endif /* u_char */ #define MAGIC_BYTE ((u_char) '\252') @@ -532,11 +533,11 @@ typedef union word Word; */ #define TOO_SMALL(sp) (SIZE(sp) < ALLOC_OVERHEAD) -#else /* ! CSRI_DEBUG */ +#else /* ! CSRI_DEBUG */ #define SET_REALSIZE(sp, n) #define VALID_MAGIC(sp) (1) #define TOO_SMALL(sp) (0) -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ /* * Check that a free list ptr points to a block with something pointing @@ -571,7 +572,7 @@ typedef union word Word; #define fputs(s, f) write(fileno(f), (s), strlen(s)) #define setvbuf(f, s, n, l) __nothing() #define fflush(f) __nothing() -#endif /* USESTDIO */ +#endif /* USESTDIO */ #ifdef CSRI_TRACE /* @@ -616,11 +617,11 @@ typedef union word Word; } else \ _malloc_debugging += 0 -#else /* !CSRI_DEBUG */ +#else /* !CSRI_DEBUG */ #define CHECKHEAP() #define CHECKFREEPTR(ep, msg) #define CHECKALLOCPTR(sp, msg) -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ #define FREEMAGIC '\125' @@ -649,7 +650,7 @@ typedef union word Word; * variable accessed in a way not obvious to the compiler", so should * be called volatile. Amazing - a use for const volatile... */ -#ifndef RCSID /* define RCSID(x) to nothing if don't want the rcs headers */ +#ifndef RCSID /* define RCSID(x) to nothing if don't want the rcs headers */ #if defined(lint) || defined(__STRICT_ANSI__) #define RCSID(x) #else @@ -657,7 +658,7 @@ typedef union word Word; #endif #endif -#endif /* __DEFS_H__ */ /* Do not add anything after this line */ +#endif /* __DEFS_H__ */ /* Do not add anything after this line */ /* Author: Mark Moraes */ @@ -699,7 +700,7 @@ typedef union word Word; #ifdef CSRI_PROFILESIZES #define _malloc_scount __MALC_scount -#endif /* CSRI_PROFILESIZES */ +#endif /* CSRI_PROFILESIZES */ #ifdef CSRI_DEBUG /* @@ -708,13 +709,13 @@ typedef union word Word; * malloc/free/realloc/memalign. (the rest call these) */ #define _malloc_debugging __MALD_debugging -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ #define _malloc_version __MALE_version #define _malloc_memfunc __MALF_memfunc -#endif /* SHORTNAMES */ /* Do not add anything after this line */ -#endif /* __GLOBALRENAME_H__ */ /* Do not add anything after this line */ +#endif /* SHORTNAMES */ /* Do not add anything after this line */ +#endif /* __GLOBALRENAME_H__ */ /* Do not add anything after this line */ const char *_malloc_version = "CSRI, University of Toronto Malloc Version 1.18alpha"; @@ -766,14 +767,14 @@ Word *_malloc_mem = NULL; * you want to format something before printing. We don't want stdio * calling malloc() if we can help it */ -int _malloc_tracing = 0; /* No tracing */ +int _malloc_tracing = 0; /* No tracing */ char _malloc_statsbuf[128]; int _malloc_leaktrace = 0; #ifdef CSRI_PROFILESIZES int _malloc_scount[MAXPROFILESIZE]; -#endif /* CSRI_PROFILESIZES */ +#endif /* CSRI_PROFILESIZES */ #ifdef CSRI_DEBUG /* @@ -782,7 +783,7 @@ int _malloc_scount[MAXPROFILESIZE]; * malloc/free/realloc/memalign. (the rest call these) */ int _malloc_debugging = 0; -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ univptr_t (*_malloc_memfunc) proto((size_t)) = _mal_sbrk; @@ -812,7 +813,7 @@ size_t _malloc_sbrkunits; extern Word *_malloc_mem; extern int - _malloc_tracing; /* No tracing */ + _malloc_tracing; /* No tracing */ extern char _malloc_statsbuf[]; @@ -822,7 +823,7 @@ extern int #ifdef CSRI_PROFILESIZES extern int _malloc_scount[]; -#endif /* CSRI_PROFILESIZES */ +#endif /* CSRI_PROFILESIZES */ #ifdef CSRI_DEBUG /* @@ -832,15 +833,16 @@ extern int */ extern int _malloc_debugging; -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ extern -univptr_t (*_malloc_memfunc) proto((size_t)); +univptr_t (*_malloc_memfunc) + proto((size_t)); extern int __m_prblock proto((univptr_t, int, FILE *)); -#endif /* __GLOBALS_H__ */ /* Do not add anything after this line */ +#endif /* __GLOBALS_H__ */ /* Do not add anything after this line */ /* ** sptree.h: The following type declarations provide the binary tree @@ -862,27 +864,27 @@ typedef struct _spblk { struct _spblk *uplink; univptr_t - key; /* formerly time/timetyp */ + key; /* formerly time/timetyp */ univptr_t - data; /* formerly aux/auxtype */ + data; /* formerly aux/auxtype */ univptr_t datb; } SPBLK; typedef struct { - SPBLK *root; /* root node */ + SPBLK *root; /* root node */ /* Statistics, not strictly necessary, but handy for tuning */ int - lookups; /* number of splookup()s */ + lookups; /* number of splookup()s */ int - lkpcmps; /* number of lookup comparisons */ + lkpcmps; /* number of lookup comparisons */ int - enqs; /* number of spenq()s */ + enqs; /* number of spenq()s */ int - enqcmps; /* compares in spenq */ + enqcmps; /* compares in spenq */ int splays; @@ -915,7 +917,7 @@ __spdelete __proto((SPBLK *, SPTREE *)); #undef __proto -#endif /* SPTREE_H */ +#endif /* SPTREE_H */ #ifndef __CSRI_TRACE_H__ #define __CSRI_TRACE_H__ @@ -937,87 +939,89 @@ __m_delete_record proto((univptr_t)); else \ _malloc_leaktrace += 0 -#endif /* __CSRI_TRACE_H__ */ /* Do not add anything after this line */ +#endif /* __CSRI_TRACE_H__ */ /* Do not add anything after this line */ #include "confmagic.h" #ifdef CSRI_TRACE /* Tracing malloc definitions - helps find leaks */ univptr_t -trace__malloc _((size_t nbytes, const char *fname, int linenum)); + trace__malloc(size_t nbytes, const char *fname, int linenum); +univptr_t + trace__calloc(size_t nelem, size_t elsize, const char *fname, int linenum); univptr_t -trace__calloc _((size_t nelem, size_t elsize, const char *fname, int linenum)); + trace__realloc(univptr_t cp, size_t nbytes, const char *fname, int linenum); univptr_t -trace__realloc _((univptr_t cp, size_t nbytes, const char *fname, int linenum)); -univptr_t trace__valloc _((size_t size, const char *fname, int linenum)); + trace__valloc(size_t size, const char *fname, int linenum); univptr_t - trace__memalign -_((size_t alignment, size_t size, const char *fname, int linenum)); -univptr_t trace__emalloc _((size_t nbytes, const char *fname, int linenum)); + trace__memalign(size_t alignment, size_t size, const char *fname, int linenum); univptr_t -trace__ecalloc _((size_t nelem, size_t sz, const char *fname, int linenum)); + trace__emalloc(size_t nbytes, const char *fname, int linenum); univptr_t - trace__erealloc -_((univptr_t ptr, size_t nbytes, const char *fname, int linenum)); -char *trace__strdup _((const char *s, const char *fname, int linenum)); -char *trace__strsave _((const char *s, const char *fname, int linenum)); + trace__ecalloc(size_t nelem, size_t sz, const char *fname, int linenum); +univptr_t + trace__erealloc(univptr_t ptr, size_t nbytes, const char *fname, int linenum); +char *trace__strdup(const char *s, const char *fname, int linenum); +char *trace__strsave(const char *s, const char *fname, int linenum); void -trace__free _((univptr_t cp, const char *fname, int linenum)); + trace__free(univptr_t cp, const char *fname, int linenum); void -trace__cfree _((univptr_t cp, const char *fname, int linenum)); -#else /* CSRI_TRACE */ + trace__cfree(univptr_t cp, const char *fname, int linenum); +#else /* CSRI_TRACE */ univptr_t -malloc _((size_t nbytes)); + malloc(size_t nbytes); univptr_t -calloc _((size_t nelem, size_t elsize)); + calloc(size_t nelem, size_t elsize); univptr_t -realloc _((univptr_t cp, size_t nbytes)); + realloc(univptr_t cp, size_t nbytes); univptr_t -valloc _((size_t size)); + valloc(size_t size); univptr_t -memalign _((size_t alignment, size_t size)); + memalign(size_t alignment, size_t size); univptr_t -emalloc _((size_t nbytes)); + emalloc(size_t nbytes); univptr_t -ecalloc _((size_t nelem, size_t sz)); + ecalloc(size_t nelem, size_t sz); univptr_t -erealloc _((univptr_t ptr, size_t nbytes)); -Free_t free _((univptr_t cp)); -Free_t cfree _((univptr_t cp)); -#endif /* CSRI_TRACE */ + erealloc(univptr_t ptr, size_t nbytes); +Free_t + free(univptr_t cp); +Free_t + cfree(univptr_t cp); +#endif /* CSRI_TRACE */ int __m_botch -_((const char *s1, const char *s2, univptr_t p, - int is_end_ptr, const char *filename, int linenumber)); + (const char *s1, const char *s2, univptr_t p, + int is_end_ptr, const char *filename, int linenumber); void -__m_prnode _((SPBLK * spblk)); + __m_prnode(SPBLK * spblk); void -mal_contents _((FILE * fp)); + mal_contents(FILE * fp); #ifdef CSRI_DEBUG void -mal_debug _((int level)); + mal_debug(int level); int -mal_verify _((int fullcheck)); + mal_verify(int fullcheck); #endif void -mal_dumpleaktrace _((FILE * fp)); + mal_dumpleaktrace(FILE * fp); void -mal_heapdump _((FILE * fp)); + mal_heapdump(FILE * fp); void -mal_leaktrace _((int value)); + mal_leaktrace(int value); void -mal_sbrkset _((int n)); + mal_sbrkset(int n); void -mal_slopset _((int n)); + mal_slopset(int n); #ifdef CSRI_PROFILESIZES void -mal_statsdump _((FILE * fp)); + mal_statsdump(FILE * fp); #endif void -mal_trace _((int value)); + mal_trace(int value); void -mal_mmap _((char *fname)); + mal_mmap(char *fname); #ifdef CSRI_TRACE @@ -1039,8 +1043,7 @@ trace__emalloc(nbytes, fname, linenum) univptr_t trace__erealloc(ptr, nbytes, fname, linenum) - univptr_t - ptr; + univptr_t ptr; size_t nbytes; const char *fname; int @@ -1110,8 +1113,7 @@ trace__free(cp, fname, linenum) univptr_t trace__realloc(cp, nbytes, fname, linenum) - univptr_t - cp; + univptr_t cp; size_t nbytes; const char *fname; int @@ -1224,7 +1226,7 @@ trace__strsave(s, fname, linenum) RECORD_FILE_AND_LINE((univptr_t) cp, fname, linenum); return (cp); } -#endif /* CSRI_TRACE */ +#endif /* CSRI_TRACE */ int __nothing() { @@ -1243,7 +1245,7 @@ __m_botch(s1, s2, p, is_end_ptr, filename, linenumber) const char *filename; int linenumber, is_end_ptr; { - static char linebuf[32]; /* Enough for a BIG linenumber! */ + static char linebuf[32]; /* Enough for a BIG linenumber! */ static int notagain = 0; if (notagain == 0) { @@ -1265,10 +1267,10 @@ __m_botch(s1, s2, p, is_end_ptr, filename, linenumber) * tried to unbuffer it */ (void) fflush(stderr); - notagain++; /* just in case abort() tries to cleanup */ + notagain++; /* just in case abort() tries to cleanup */ abort(); } - return 0; /* SHOULDNTHAPPEN */ + return 0; /* SHOULDNTHAPPEN */ } /* Author: Mark Moraes */ @@ -1287,7 +1289,7 @@ __m_prblock(p, is_end_ptr, fp) Word *blkend; ulong tag; ulong blksize; - char buf[512]; /* long enough for the sprintfs below */ + char buf[512]; /* long enough for the sprintfs below */ if (blk == NULL) return 0; @@ -1306,8 +1308,8 @@ __m_prblock(p, is_end_ptr, fp) blkend = blk + blksize - 1; } (void) sprintf(buf, " %s blk: 0x%lx to 0x%lx, %lu (0x%lx) words", - tag == FREE ? "Free" : "Allocated", (ulong) blk, - (ulong) blkend, blksize, blksize); + tag == FREE ? "Free" : "Allocated", (ulong) blk, + (ulong) blkend, blksize, blksize); (void) fputs(buf, fp); if (is_end_ptr && !PTR_IN_HEAP(blk)) { sprintf(buf, " ** start pointer 0x%lx not in heap\n", (ulong) blk); @@ -1327,7 +1329,7 @@ __m_prblock(p, is_end_ptr, fp) char *cp; (void) sprintf(buf, " next=0x%lx, prev=0x%lx\n", - (ulong) NEXT(blkend), (ulong) PREV(blkend)); + (ulong) NEXT(blkend), (ulong) PREV(blkend)); (void) fputs(buf, fp); /* Make sure free block is filled with FREEMAGIC */ n = (blksize - FREE_OVERHEAD) * sizeof(Word); @@ -1335,8 +1337,8 @@ __m_prblock(p, is_end_ptr, fp) #ifdef CSRI_DEBUG for (i = 0; i < n; i++, cp++) { if (*cp != FREEMAGIC) { - (void) fputs(" ** modified after free().\n", fp); - break; + (void) fputs(" ** modified after free().\n", fp); + break; } } #endif @@ -1384,9 +1386,9 @@ mal_heapdump(fp) REGISTER Word *blk; REGISTER Word *blkend; int i; - char buf[512]; /* long enough for the sprintfs below */ + char buf[512]; /* long enough for the sprintfs below */ - if (_malloc_loword == NULL) { /* Nothing malloc'ed yet */ + if (_malloc_loword == NULL) { /* Nothing malloc'ed yet */ (void) fputs("Null heap - nothing malloc'ed yet\n", fp); return; } @@ -1410,26 +1412,26 @@ mal_heapdump(fp) } if (_malloc_rovers[MAXBINS] != NULL) { (void) sprintf(buf, " ** rover terminator is 0x%lx, fixing\n", - (ulong) _malloc_rovers[MAXBINS]); + (ulong) _malloc_rovers[MAXBINS]); (void) fputs(buf, fp); _malloc_rovers[MAXBINS] = NULL; } for (ptr = _malloc_mem; ptr != NULL; ptr = ptr->next) { /* print the arena */ (void) sprintf(buf, "Arena from 0x%lx to 0x%lx, %lu (0x%lx) words\n", - (ulong) ptr, (ulong) (ptr + SIZE(ptr + 1)), - (ulong) SIZE(ptr + 1) + 1, (ulong) SIZE(ptr + 1) + 1); + (ulong) ptr, (ulong) (ptr + SIZE(ptr + 1)), + (ulong) SIZE(ptr + 1) + 1, (ulong) SIZE(ptr + 1) + 1); (void) fputs(buf, fp); (void) sprintf(buf, "Next arena is 0x%lx\n", (ulong) ptr->next); (void) fputs(buf, fp); (void) fflush(fp); ASSERT(SIZEFIELD(ptr + 1) == SIZEFIELD(ptr + SIZE(ptr + 1)), - "mal_dumpheap: corrupt malloc arena"); + "mal_dumpheap: corrupt malloc arena"); blkend = ptr + SIZE(ptr + 1); for (blk = ptr + ARENASTART; blk < blkend; blk += SIZE(blk)) { if (!__m_prblock((univptr_t) blk, 0, fp)) { - __m_botch("mal_dumpheap: corrupt block", "", - (univptr_t) 0, 0, __FILE__, __LINE__); + __m_botch("mal_dumpheap: corrupt block", "", + (univptr_t) 0, 0, __FILE__, __LINE__); } } } @@ -1469,8 +1471,7 @@ emalloc(nbytes) */ univptr_t erealloc(ptr, nbytes) - univptr_t - ptr; + univptr_t ptr; size_t nbytes; { univptr_t cp = realloc(ptr, nbytes); @@ -1523,7 +1524,7 @@ _mal_sbrk(nbytes) */ if (nbytes > 0) { ASSERT(p > lastsbrk, - "system call error? sbrk returned value lower than previous calls"); + "system call error? sbrk returned value lower than previous calls"); lastsbrk = p; } return p; @@ -1589,7 +1590,7 @@ _mal_mmap(nbytes) } mmf.i_size = stbuf.st_size; mmf.i_data = mmap((caddr_t) 0, mmf.i_size, PROT_READ | PROT_WRITE, - MAP_SHARED, mmf.i_fd, (off_t) 0); + MAP_SHARED, mmf.i_fd, (off_t) 0); if (mmf.i_data == (caddr_t) - 1) return (univptr_t) -1; mmf.i_end = mmf.i_data + mmf.i_size; @@ -1598,7 +1599,7 @@ _mal_mmap(nbytes) (void) madvise(mmf.i_data, mmf.i_size, MADV_RANDOM); return mmf.i_data; } -#else /* !HAVE_MMAP */ +#else /* !HAVE_MMAP */ univptr_t _mal_mmap(nbytes) size_t nbytes __attribute__ ((__unused__)); @@ -1606,7 +1607,7 @@ _mal_mmap(nbytes) return (univptr_t) -1; } -#endif /* HAVE_MMAP */ +#endif /* HAVE_MMAP */ void mal_mmap(fname) @@ -1689,8 +1690,8 @@ __m_prnode(spblk) if ((unsigned long) spblk->datb < min_num) return; (void) sprintf(_malloc_statsbuf, "%s%8lu %8lu(0x%08lx)\n", - (char *) spblk->data, (unsigned long) spblk->datb, - (unsigned long) spblk->key, (unsigned long) spblk->key); + (char *) spblk->data, (unsigned long) spblk->datb, + (unsigned long) spblk->key, (unsigned long) spblk->key); (void) fputs(_malloc_statsbuf, dumpfp); } @@ -1736,7 +1737,7 @@ __m_delete_record(addr) } } -static void __m_count _((SPBLK * spblk)); +static void __m_count(SPBLK * spblk); static void __m_count(spblk) @@ -1761,8 +1762,8 @@ mal_contents(fp) global_nbytes = 0; __spscan(__m_count, (SPBLK *) NULL, sp); (void) sprintf(_malloc_statsbuf, - "%% %lu bytes %lu mallocs %p vm\n", - global_nbytes, nmallocs, sbrk(0)); + "%% %lu bytes %lu mallocs %p vm\n", + global_nbytes, nmallocs, sbrk(0)); (void) fputs(_malloc_statsbuf, fp); (void) fflush(fp); } @@ -1858,7 +1859,7 @@ mal_contents(fp) } \ } -static int grabhunk _((size_t)); +static int grabhunk(size_t); static int grabhunk(nwords) @@ -1878,7 +1879,7 @@ grabhunk(nwords) */ #define EXCESS 3 sbrkwords = (size_t) (((nwords + EXCESS) / _malloc_sbrkunits + 1) * - _malloc_sbrkunits); + _malloc_sbrkunits); morecore = sbrkwords * sizeof(Word) + SBRKEXTRA; if ((cp = (*_malloc_memfunc) (morecore)) == (univptr_t) -1) return (0); @@ -1905,7 +1906,7 @@ grabhunk(nwords) spare = (char *) (ptr + sbrkwords); nspare = (morecore - sbrkwords * sizeof(Word)); PRCSRI_TRACE(sprintf(_malloc_statsbuf, "sbrk %lu\n", - (ulong) sbrkwords * sizeof(Word))); + (ulong) sbrkwords * sizeof(Word))); /* * If the new chunk adjoins _malloc_hiword, then _malloc_hiword @@ -1946,7 +1947,7 @@ grabhunk(nwords) SIZEFIELD(ptr) = ALLOCED | sbrkwords; _malloc_hiword += sbrkwords - 1; PRCSRI_TRACE(sprintf(_malloc_statsbuf, "heapend 0x%lx\n", - (ulong) _malloc_hiword)); + (ulong) _malloc_hiword)); SIZEFIELD(_malloc_hiword) = ALLOCED | sbrkwords; /* * Subtract 2 for the special arena end tags. */ @@ -1958,7 +1959,7 @@ grabhunk(nwords) LINK(ptr, sbrkwords, _malloc_lastbin) _malloc_rovers[_malloc_lastbin] = ptr; while (_malloc_rovers[_malloc_firstbin] == NULL && - _malloc_firstbin < MAXBINS - 1) + _malloc_firstbin < MAXBINS - 1) _malloc_firstbin++; return (1); } @@ -1996,7 +1997,7 @@ malloc(nbytes) errno = EINVAL; return (NULL); } -#endif /* SVID_MALLOC_0 */ +#endif /* SVID_MALLOC_0 */ required = ALLOC_OVERHEAD + (nbytes + sizeof(Word) - 1) / sizeof(Word); if (required < (size_t) _malloc_minchunk) @@ -2021,9 +2022,9 @@ malloc(nbytes) CHECKFREEPTR(search, "while searching in malloc()"); searchsize = FREESIZE(search); if (searchsize >= required) { - break; + break; } else { - search = NEXT(search); + search = NEXT(search); } } while (search != start); } @@ -2048,9 +2049,9 @@ malloc(nbytes) p = search - searchsize + 1; SIZEFIELD(p) = SIZEFIELD(p + required - 1) = ALLOCMASK(required); PRCSRI_TRACE(sprintf - (_malloc_statsbuf, "+ %lu %lu 0x%lx\n", (ulong) nbytes, - (ulong) (required - ALLOC_OVERHEAD) * sizeof(Word), - (ulong) (p + HEADERWORDS))); + (_malloc_statsbuf, "+ %lu %lu 0x%lx\n", (ulong) nbytes, + (ulong) (required - ALLOC_OVERHEAD) * sizeof(Word), + (ulong) (p + HEADERWORDS))); COUNTSIZE(required); SET_REALSIZE(p, nbytes); return ((univptr_t) (p + HEADERWORDS)); @@ -2060,8 +2061,7 @@ malloc(nbytes) Free_t free(cp) - univptr_t - cp; + univptr_t cp; { /* * This is where the boundary tags come into their own. The @@ -2107,8 +2107,8 @@ free(cp) sizep0 = SIZE(p0); DMEMSET(p0 + FREEHEADERWORDS, sizep0 - FREE_OVERHEAD); PRCSRI_TRACE(sprintf(_malloc_statsbuf, "- %lu 0x%lx\n", - (ulong) (sizep0 - ALLOC_OVERHEAD) * sizeof(Word), - (ulong) (p0 + HEADERWORDS))); + (ulong) (sizep0 - ALLOC_OVERHEAD) * sizeof(Word), + (ulong) (p0 + HEADERWORDS))); p1 = p0 - 1; /* @@ -2141,7 +2141,7 @@ free(cp) SIZEFIELD(p2 - sizep0 + 1) = SIZEFIELD(p2) = FREEMASK(sizep0); /* Smash p0's old end tag and p2's old start tag. */ DMEMSET(p0 - FREETRAILERWORDS + 1, FREETRAILERWORDS + FREEHEADERWORDS); - p0 = p2; /* p0 just vanished - became part of p2 */ + p0 = p2; /* p0 just vanished - became part of p2 */ } if (TAG(p1) == FREE) { /* @@ -2197,8 +2197,7 @@ free(cp) */ univptr_t realloc(cp, nbytes) - univptr_t - cp; + univptr_t cp; size_t nbytes; { REGISTER Word *p0 = (Word *) cp; @@ -2281,9 +2280,9 @@ realloc(cp, nbytes) SIZEFIELD(p0) = SIZEFIELD(p0 + sizep0 - 1) = ALLOCMASK(sizep0); SET_REALSIZE(p0, nbytes); PRCSRI_TRACE(sprintf(_malloc_statsbuf, "++ %lu %lu 0x%lx\n", - (ulong) nbytes, - (ulong) (sizep0 - ALLOC_OVERHEAD) * sizeof(Word), - (ulong) cp)); + (ulong) nbytes, + (ulong) (sizep0 - ALLOC_OVERHEAD) * sizeof(Word), + (ulong) cp)); CHECKHEAP(); return (cp); } @@ -2312,8 +2311,7 @@ calloc(nelem, elsize) */ Free_t cfree(cp) - univptr_t - cp; + univptr_t cp; { #ifdef INT_FREE return free(cp); @@ -2356,14 +2354,14 @@ memalign(alignment, size) size_t blksize; #ifdef CSRI_DEBUG int tmp_debugging = _malloc_debugging; -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ if (alignment < sizeof(int) || !is_power_of_2(alignment) || size == 0) { errno = EINVAL; return (NULL); } if (alignment < sizeof(Word)) - return (malloc(size)); /* We guarantee this alignment anyway */ + return (malloc(size)); /* We guarantee this alignment anyway */ /* * Life starts to get complicated - need to get a block large * enough to hold a block 'size' long, starting on an 'alignment' @@ -2423,7 +2421,7 @@ memalign(alignment, size) SET_REALSIZE(p1, size); if (after > 0) { /* We can now free the block after the memaligned block. */ - p1 += blksize + ALLOC_OVERHEAD; /* SIZE(p1) */ + p1 += blksize + ALLOC_OVERHEAD; /* SIZE(p1) */ /* * p1 now points to the space after the memaligned block. we * fix the size, mark it alloced, and call free - the block @@ -2440,7 +2438,7 @@ memalign(alignment, size) * call free(). */ _malloc_debugging = 0; -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ free((univptr_t) (p1 + HEADERWORDS)); } if (addr != cp) { @@ -2473,7 +2471,7 @@ memalign(alignment, size) } #ifdef CSRI_DEBUG _malloc_debugging = tmp_debugging; -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ return (addr); } @@ -2514,7 +2512,7 @@ mal_debug(level) } _malloc_debugging = level; } -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ /* * Allows you to control the number of system calls made, which might @@ -2575,7 +2573,7 @@ mal_trace(value) * sure we print the heap start for xmem analysis. */ PRCSRI_TRACE(sprintf(_malloc_statsbuf, "heapstart 0x%lx\n", - (ulong) _malloc_loword)); + (ulong) _malloc_loword)); } } else { /* For symmetry */ @@ -2603,21 +2601,21 @@ mal_statsdump(fp) for (i = 1; i < MAXPROFILESIZE; i++) { if (_malloc_scount[i] > 0) { (void) sprintf(buf, "%lu: %lu\n", (ulong) i * sizeof(Word), - (ulong) _malloc_scount[i]); + (ulong) _malloc_scount[i]); (void) fputs(buf, fp); _malloc_scount[i] = 0; } } if (_malloc_scount[0] > 0) { (void) sprintf(buf, ">= %lu: %lu\n", - (ulong) MAXPROFILESIZE * sizeof(Word), - (ulong) _malloc_scount[0]); + (ulong) MAXPROFILESIZE * sizeof(Word), + (ulong) _malloc_scount[0]); (void) fputs(buf, fp); _malloc_scount[0] = 0; } (void) fflush(fp); } -#endif /* CSRI_PROFILESIZES */ +#endif /* CSRI_PROFILESIZES */ /* Author: Mark Moraes */ @@ -2666,7 +2664,7 @@ mal_verify(fullcheck) REGISTER Word *ptr, *p, *blk, *blkend; int i; - if (_malloc_loword == NULL) /* Nothing malloc'ed yet */ + if (_malloc_loword == NULL) /* Nothing malloc'ed yet */ return (0); for (i = 0; i < MAXBINS; i++) { @@ -2683,35 +2681,35 @@ mal_verify(fullcheck) * despite similar appearance of the test */ ASSERT(SIZEFIELD(ptr + 1) == SIZEFIELD(ptr + SIZE(ptr + 1)), - "corrupt malloc arena"); + "corrupt malloc arena"); blkend = ptr + SIZE(ptr + 1); for (blk = ptr + ARENASTART; blk < blkend; blk += SIZE(blk)) { ASSERT_SP(PTR_IN_HEAP(blk), "corrupt pointer", "", blk); ASSERT_SP(VALID_START_SIZE_FIELD(blk), "corrupt SIZE field", "", blk); if (TAG(blk) == FREE) { - p = blk + FREESIZE(blk) - 1; - ASSERT_EP(VALID_NEXT_PTR(p), "corrupt NEXT pointer", "", p); - ASSERT_EP(VALID_PREV_PTR(p), "corrupt PREV pointer", "", p); - if (fullcheck) { - /* Make sure all free blocks are filled with FREEMAGIC */ - int n; - char *cp; - - n = (SIZE(blk) - FREE_OVERHEAD) * sizeof(Word); - cp = (char *) (blk + FREEHEADERWORDS); - for (i = 0; i < n; i++, cp++) { - ASSERT_SP(*cp == FREEMAGIC, - "free block modified after free()", "", blk); - } - } + p = blk + FREESIZE(blk) - 1; + ASSERT_EP(VALID_NEXT_PTR(p), "corrupt NEXT pointer", "", p); + ASSERT_EP(VALID_PREV_PTR(p), "corrupt PREV pointer", "", p); + if (fullcheck) { + /* Make sure all free blocks are filled with FREEMAGIC */ + int n; + char *cp; + + n = (SIZE(blk) - FREE_OVERHEAD) * sizeof(Word); + cp = (char *) (blk + FREEHEADERWORDS); + for (i = 0; i < n; i++, cp++) { + ASSERT_SP(*cp == FREEMAGIC, + "free block modified after free()", "", blk); + } + } } else { - ASSERT_SP(VALID_MAGIC(blk), "overwritten end of block", "", blk); + ASSERT_SP(VALID_MAGIC(blk), "overwritten end of block", "", blk); } } } return (0); } -#endif /* CSRI_DEBUG */ +#endif /* CSRI_DEBUG */ /* * This file contains a few splay tree routines snarfed from David @@ -2894,7 +2892,7 @@ spfhead(q) return (x); -} /* spfhead */ +} /* spfhead */ @@ -2946,23 +2944,23 @@ spfnext(n) while (x->leftlink != NULL) x = x->leftlink; next = x; - } else { /* x == NULL */ + } else { /* x == NULL */ x = n->uplink; next = NULL; while (x != NULL) { if (x->leftlink == n) { - next = x; - x = NULL; + next = x; + x = NULL; } else { - n = x; - x = n->uplink; + n = x; + x = n->uplink; } } } return (next); -} /* spfnext */ +} /* spfnext */ char * @@ -2982,7 +2980,7 @@ __spstats(q) sloops = q->splays ? (float) q->splayloops / q->splays : 0; (void) sprintf(buf, "f(%d %4.2f) i(%d %4.2f) s(%d %4.2f)", - q->lookups, llen, q->enqs, elen, q->splays, sloops); + q->lookups, llen, q->enqs, elen, q->splays, sloops); return buf; } @@ -3073,11 +3071,11 @@ __spdelete(n, q) splay(n, q); x = spdeq(&q->root->rightlink); - if (x == NULL) { /* empty right subtree */ + if (x == NULL) { /* empty right subtree */ q->root = q->root->leftlink; if (q->root) q->root->uplink = NULL; - } else { /* non-empty right subtree */ + } else { /* non-empty right subtree */ x->uplink = NULL; x->leftlink = q->root->leftlink; x->rightlink = q->root->rightlink; @@ -3088,7 +3086,7 @@ __spdelete(n, q) q->root = x; } spfree(n, q); -} /* spdelete */ +} /* spdelete */ /* @@ -3173,9 +3171,9 @@ spenq(n, q) REGISTER SPBLK *n; REGISTER SPTREE *q; { - REGISTER SPBLK *left; /* the rightmost node in the left tree */ - REGISTER SPBLK *right; /* the leftmost node in the right tree */ - REGISTER SPBLK *next; /* the root of the unsplit part */ + REGISTER SPBLK *left; /* the rightmost node in the left tree */ + REGISTER SPBLK *right; /* the leftmost node in the right tree */ + REGISTER SPBLK *next; /* the root of the unsplit part */ REGISTER SPBLK *temp; REGISTER univptr_t key; @@ -3184,10 +3182,10 @@ spenq(n, q) n->uplink = NULL; next = q->root; q->root = n; - if (next == NULL) { /* trivial enq */ + if (next == NULL) { /* trivial enq */ n->leftlink = NULL; n->rightlink = NULL; - } else { /* difficult enq */ + } else { /* difficult enq */ key = n->key; left = n; right = n; @@ -3200,27 +3198,27 @@ spenq(n, q) if (COMPARE(next->key, key) > 0) goto two; - one: /* assert next->key <= key */ + one: /* assert next->key <= key */ - do { /* walk to the right in the left tree */ + do { /* walk to the right in the left tree */ temp = next->rightlink; if (temp == NULL) { - left->rightlink = next; - next->uplink = left; - right->leftlink = NULL; - goto done; /* job done, entire tree split */ + left->rightlink = next; + next->uplink = left; + right->leftlink = NULL; + goto done; /* job done, entire tree split */ } q->enqcmps++; if (COMPARE(temp->key, key) > 0) { - left->rightlink = next; - next->uplink = left; - left = next; - next = temp; - goto two; /* change sides */ + left->rightlink = next; + next->uplink = left; + left = next; + next = temp; + goto two; /* change sides */ } next->rightlink = temp->leftlink; if (temp->leftlink != NULL) - temp->leftlink->uplink = next; + temp->leftlink->uplink = next; left->rightlink = temp; temp->uplink = left; temp->leftlink = next; @@ -3228,34 +3226,34 @@ spenq(n, q) left = temp; next = temp->rightlink; if (next == NULL) { - right->leftlink = NULL; - goto done; /* job done, entire tree split */ + right->leftlink = NULL; + goto done; /* job done, entire tree split */ } q->enqcmps++; - } while (COMPARE(next->key, key) <= 0); /* change sides */ + } while (COMPARE(next->key, key) <= 0); /* change sides */ - two: /* assert next->key > key */ + two: /* assert next->key > key */ - do { /* walk to the left in the right tree */ + do { /* walk to the left in the right tree */ temp = next->leftlink; if (temp == NULL) { - right->leftlink = next; - next->uplink = right; - left->rightlink = NULL; - goto done; /* job done, entire tree split */ + right->leftlink = next; + next->uplink = right; + left->rightlink = NULL; + goto done; /* job done, entire tree split */ } q->enqcmps++; if (COMPARE(temp->key, key) <= 0) { - right->leftlink = next; - next->uplink = right; - right = next; - next = temp; - goto one; /* change sides */ + right->leftlink = next; + next->uplink = right; + right = next; + next = temp; + goto one; /* change sides */ } next->leftlink = temp->rightlink; if (temp->rightlink != NULL) - temp->rightlink->uplink = next; + temp->rightlink->uplink = next; right->leftlink = temp; temp->uplink = right; temp->rightlink = next; @@ -3263,16 +3261,16 @@ spenq(n, q) right = temp; next = temp->leftlink; if (next == NULL) { - left->rightlink = NULL; - goto done; /* job done, entire tree split */ + left->rightlink = NULL; + goto done; /* job done, entire tree split */ } q->enqcmps++; - } while (COMPARE(next->key, key) > 0); /* change sides */ + } while (COMPARE(next->key, key) > 0); /* change sides */ goto one; - done: /* split is done, branches of n need reversal */ + done: /* split is done, branches of n need reversal */ temp = n->leftlink; n->leftlink = n->rightlink; @@ -3281,7 +3279,7 @@ spenq(n, q) return (n); -} /* spenq */ +} /* spenq */ /*---------------- @@ -3295,14 +3293,14 @@ spenq(n, q) */ static SPBLK * spdeq(np) - SPBLK **np; /* pointer to a node pointer */ + SPBLK **np; /* pointer to a node pointer */ { - REGISTER SPBLK *deq; /* one to return */ - REGISTER SPBLK *next; /* the next thing to deal with */ - REGISTER SPBLK *left; /* the left child of next */ - REGISTER SPBLK *farleft; /* the left child of left */ - REGISTER SPBLK *farfarleft; /* the left child of farleft */ + REGISTER SPBLK *deq; /* one to return */ + REGISTER SPBLK *next; /* the next thing to deal with */ + REGISTER SPBLK *left; /* the left child of next */ + REGISTER SPBLK *farleft; /* the left child of left */ + REGISTER SPBLK *farfarleft; /* the left child of farleft */ if (np == NULL || *np == NULL) { deq = NULL; @@ -3314,44 +3312,44 @@ spdeq(np) *np = next->rightlink; if (*np != NULL) - (*np)->uplink = NULL; + (*np)->uplink = NULL; } else - for (;;) { /* left is not null */ - /* next is not it, left is not NULL, might be it */ - farleft = left->leftlink; - if (farleft == NULL) { - deq = left; - next->leftlink = left->rightlink; - if (left->rightlink != NULL) - left->rightlink->uplink = next; - break; - } - /* next, left are not it, farleft is not NULL, might be it */ - farfarleft = farleft->leftlink; - if (farfarleft == NULL) { - deq = farleft; - left->leftlink = farleft->rightlink; - if (farleft->rightlink != NULL) - farleft->rightlink->uplink = left; - break; - } - /* next, left, farleft are not it, rotate */ - next->leftlink = farleft; - farleft->uplink = next; - left->leftlink = farleft->rightlink; - if (farleft->rightlink != NULL) - farleft->rightlink->uplink = left; - farleft->rightlink = left; - left->uplink = farleft; - next = farleft; - left = farfarleft; + for (;;) { /* left is not null */ + /* next is not it, left is not NULL, might be it */ + farleft = left->leftlink; + if (farleft == NULL) { + deq = left; + next->leftlink = left->rightlink; + if (left->rightlink != NULL) + left->rightlink->uplink = next; + break; + } + /* next, left are not it, farleft is not NULL, might be it */ + farfarleft = farleft->leftlink; + if (farfarleft == NULL) { + deq = farleft; + left->leftlink = farleft->rightlink; + if (farleft->rightlink != NULL) + farleft->rightlink->uplink = left; + break; + } + /* next, left, farleft are not it, rotate */ + next->leftlink = farleft; + farleft->uplink = next; + left->leftlink = farleft->rightlink; + if (farleft->rightlink != NULL) + farleft->rightlink->uplink = left; + farleft->rightlink = left; + left->uplink = farleft; + next = farleft; + left = farfarleft; } } return (deq); -} /* spdeq */ +} /* spdeq */ /*---------------- @@ -3376,12 +3374,12 @@ splay(n, q) SPTREE *q; { - REGISTER SPBLK *up; /* points to the node being dealt with */ - REGISTER SPBLK *prev; /* a descendent of up, already dealt with */ - REGISTER SPBLK *upup; /* the parent of up */ - REGISTER SPBLK *upupup; /* the grandparent of up */ - REGISTER SPBLK *left; /* the top of left subtree being built */ - REGISTER SPBLK *right; /* the top of right subtree being built */ + REGISTER SPBLK *up; /* points to the node being dealt with */ + REGISTER SPBLK *prev; /* a descendent of up, already dealt with */ + REGISTER SPBLK *upup; /* the parent of up */ + REGISTER SPBLK *upupup; /* the grandparent of up */ + REGISTER SPBLK *left; /* the top of left subtree being built */ + REGISTER SPBLK *right; /* the top of right subtree being built */ left = n->leftlink; right = n->rightlink; @@ -3397,48 +3395,48 @@ splay(n, q) n into the left subtree, all to right into the right subtree */ upup = up->uplink; - if (up->leftlink == prev) { /* up is to the right of n */ - if (upup != NULL && upup->leftlink == up) { /* rotate */ - upupup = upup->uplink; - upup->leftlink = up->rightlink; - if (upup->leftlink != NULL) - upup->leftlink->uplink = upup; - up->rightlink = upup; - upup->uplink = up; - if (upupup == NULL) - q->root = up; - else if (upupup->leftlink == upup) - upupup->leftlink = up; - else - upupup->rightlink = up; - up->uplink = upupup; - upup = upupup; + if (up->leftlink == prev) { /* up is to the right of n */ + if (upup != NULL && upup->leftlink == up) { /* rotate */ + upupup = upup->uplink; + upup->leftlink = up->rightlink; + if (upup->leftlink != NULL) + upup->leftlink->uplink = upup; + up->rightlink = upup; + upup->uplink = up; + if (upupup == NULL) + q->root = up; + else if (upupup->leftlink == upup) + upupup->leftlink = up; + else + upupup->rightlink = up; + up->uplink = upupup; + upup = upupup; } up->leftlink = right; if (right != NULL) - right->uplink = up; + right->uplink = up; right = up; - } else { /* up is to the left of n */ - if (upup != NULL && upup->rightlink == up) { /* rotate */ - upupup = upup->uplink; - upup->rightlink = up->leftlink; - if (upup->rightlink != NULL) - upup->rightlink->uplink = upup; - up->leftlink = upup; - upup->uplink = up; - if (upupup == NULL) - q->root = up; - else if (upupup->rightlink == upup) - upupup->rightlink = up; - else - upupup->leftlink = up; - up->uplink = upupup; - upup = upupup; + } else { /* up is to the left of n */ + if (upup != NULL && upup->rightlink == up) { /* rotate */ + upupup = upup->uplink; + upup->rightlink = up->leftlink; + if (upup->rightlink != NULL) + upup->rightlink->uplink = upup; + up->leftlink = upup; + upup->uplink = up; + if (upupup == NULL) + q->root = up; + else if (upupup->rightlink == upup) + upupup->rightlink = up; + else + upupup->leftlink = up; + up->uplink = upupup; + upup = upupup; } up->rightlink = left; if (left != NULL) - left->uplink = up; + left->uplink = up; left = up; } prev = up; @@ -3461,4 +3459,4 @@ splay(n, q) q->root = n; n->uplink = NULL; -} /* splay */ +} /* splay */ diff --git a/src/db.c b/src/db.c index 4be028a..2fa080f 100644 --- a/src/db.c +++ b/src/db.c @@ -168,22 +168,22 @@ db_grow(dbref newtop) /* make the initial one */ db_size = (db_init) ? db_init : DB_INITIAL_SIZE; while (db_top > db_size) - db_size *= 2; + db_size *= 2; if ((db = (struct object *) - malloc(db_size * sizeof(struct object))) == NULL) { - do_rawlog(LT_ERR, "ERROR: out of memory while creating database!"); - abort(); + malloc(db_size * sizeof(struct object))) == NULL) { + do_rawlog(LT_ERR, "ERROR: out of memory while creating database!"); + abort(); } } /* maybe grow it */ if (db_top > db_size) { /* make sure it's big enough */ while (db_top > db_size) - db_size *= 2; + db_size *= 2; if ((newdb = (struct object *) - realloc(db, db_size * sizeof(struct object))) == NULL) { - do_rawlog(LT_ERR, "ERROR: out of memory while extending database!"); - abort(); + realloc(db, db_size * sizeof(struct object))) == NULL) { + do_rawlog(LT_ERR, "ERROR: out of memory while extending database!"); + abort(); } db = newdb; } @@ -327,15 +327,15 @@ db_read_labeled_string(FILE * f, char **label, char **value) c = getc(f); while (isspace(c)) { if (c == '\n') - dbline++; + dbline++; c = getc(f); } if (c == '#') { while ((c = getc(f)) != '\n' && c != EOF) { - /* nothing */ + /* nothing */ } if (c == '\n') - dbline++; + dbline++; } } while (c != EOF && isspace(c)); @@ -348,10 +348,10 @@ db_read_labeled_string(FILE * f, char **label, char **value) p = lbuf; do { - if (c != '_' && c != '-' && c != '!' && c != '.' && c != '>' && c != '<' && c != '#' && /* these really should only be first time */ - !isalnum(c)) { + if (c != '_' && c != '-' && c != '!' && c != '.' && c != '>' && c != '<' && c != '#' && /* these really should only be first time */ + !isalnum(c)) { do_rawlog(LT_ERR, "DB: Illegal character '%c'(%d) in label, line %d", - c, c, dbline); + c, c, dbline); longjmp(db_err, 1); } safe_chr(c, lbuf, &p); @@ -371,7 +371,7 @@ db_read_labeled_string(FILE * f, char **label, char **value) do_rawlog(LT_ERR, T("DB: Unexpected EOF at line %d"), dbline); else do_rawlog(LT_ERR, T("DB: Missing value for '%s' at line %d"), lbuf, - dbline); + dbline); longjmp(db_err, 1); } @@ -385,37 +385,37 @@ db_read_labeled_string(FILE * f, char **label, char **value) for (;;) { c = getc(f); if (c == '"') - break; + break; if (c == '\\') - c = getc(f); + c = getc(f); if (c == EOF) { - do_rawlog(LT_ERR, "DB: Unclosed quoted string starting on line %d", - sline); - longjmp(db_err, 1); + do_rawlog(LT_ERR, "DB: Unclosed quoted string starting on line %d", + sline); + longjmp(db_err, 1); } if (c == '\0') - do_rawlog(LT_ERR, - "DB: warning: null in quoted string, remainder lost, line %d", - dbline); + do_rawlog(LT_ERR, + "DB: warning: null in quoted string, remainder lost, line %d", + dbline); if (c == '\n') - dbline++; + dbline++; safe_chr(c, vbuf, &p); } do { c = getc(f); if (c != EOF && !isspace(c)) { - do_rawlog(LT_ERR, "DB: Garbage after quoted string, line %d", dbline); - longjmp(db_err, 1); + do_rawlog(LT_ERR, "DB: Garbage after quoted string, line %d", dbline); + longjmp(db_err, 1); } } while (c != '\n' && c != EOF); } else { /* non-quoted value */ do { if (c != '_' && c != '-' && c != '!' && c != '.' && - c != '#' && !isalnum(c) && !isspace(c)) { - do_rawlog(LT_ERR, "DB: Illegal character '%c'(%d) in value, line %d", - c, c, dbline); - longjmp(db_err, 1); + c != '#' && !isalnum(c) && !isspace(c)) { + do_rawlog(LT_ERR, "DB: Illegal character '%c'(%d) in value, line %d", + c, c, dbline); + longjmp(db_err, 1); } safe_chr(c, vbuf, &p); c = getc(f); @@ -450,8 +450,8 @@ db_read_this_labeled_string(FILE * f, const char *label, char **value) if (strcmp(readlabel, label)) { do_rawlog(LT_ERR, - T("DB: error: Got label '%s', expected label '%s' at line %d"), - readlabel, label, dbline); + T("DB: error: Got label '%s', expected label '%s' at line %d"), + readlabel, label, dbline); longjmp(db_err, 1); } } @@ -473,8 +473,8 @@ db_read_this_labeled_number(FILE * f, const char *label, int *value) if (strcmp(readlabel, label)) { do_rawlog(LT_ERR, - T("DB: error: Got label '%s', expected label '%s' at line %d"), - readlabel, label, dbline); + T("DB: error: Got label '%s', expected label '%s' at line %d"), + readlabel, label, dbline); longjmp(db_err, 1); } @@ -551,8 +551,8 @@ db_read_this_labeled_dbref(FILE * f, const char *label, dbref *val) if (strcmp(readlabel, label)) { do_rawlog(LT_ERR, - T("DB: error: Got label '%s', expected label '%s' at line %d"), - readlabel, label, dbline); + T("DB: error: Got label '%s', expected label '%s' at line %d"), + readlabel, label, dbline); longjmp(db_err, 1); } *val = qparse_dbref(readvalue); @@ -848,8 +848,8 @@ db_paranoid_write_object(FILE * f, dbref i, int flag) strcpy(name, AL_NAME(list)); for (p = name; *p; p++) { if (!isprint((unsigned char) *p) || isspace((unsigned char) *p)) { - *p = '!'; - fixmemdb = err = 1; + *p = '!'; + fixmemdb = err = 1; } } if (err) { @@ -857,17 +857,17 @@ db_paranoid_write_object(FILE * f, dbref i, int flag) * number to the end. Give up if we can't find one < 10000 */ if (atr_get_noparent(i, name)) { - count = 0; - do { - name[BUFFER_LEN - 6] = '\0'; - sprintf(tbuf1, "%s%d", name, count); - count++; - } while (count < 10000 && atr_get_noparent(i, tbuf1)); - strcpy(name, tbuf1); + count = 0; + do { + name[BUFFER_LEN - 6] = '\0'; + sprintf(tbuf1, "%s%d", name, count); + count++; + } while (count < 10000 && atr_get_noparent(i, tbuf1)); + strcpy(name, tbuf1); } do_rawlog(LT_CHECK, - T(" * Bad attribute name on #%d. Changing name to %s.\n"), - i, name); + T(" * Bad attribute name on #%d. Changing name to %s.\n"), + i, name); err = 0; } /* check the owner */ @@ -892,18 +892,18 @@ db_paranoid_write_object(FILE * f, dbref i, int flag) lastp = '\0'; for (p = tbuf1; *p; p++) { if (!isprint((unsigned char) *p)) { - if (!isspace((unsigned char) *p)) { - *p = '!'; - err = 1; - } + if (!isspace((unsigned char) *p)) { + *p = '!'; + err = 1; + } } lastp = *p; } if (err) { fixmemdb = 1; do_rawlog(LT_CHECK, - T(" * Bad text in attribute %s on #%d. Changed to:\n"), name, - i); + T(" * Bad text in attribute %s on #%d. Changed to:\n"), name, + i); do_rawlog(LT_CHECK, "%s\n", tbuf1); } db_write_labeled_string(f, " value", tbuf1); @@ -1036,11 +1036,11 @@ getstring_noalloc(FILE * f) } else if (c != '"') { for (;;) { if ((c == '\0') || (c == EOF) || - ((c == '\n') && ((p == buf) || (p[-1] != '\r')))) { - *p = '\0'; - if (c == '\n') - dbline++; - return buf; + ((c == '\n') && ((p == buf) || (p[-1] != '\r')))) { + *p = '\0'; + if (c == '\n') + dbline++; + return buf; } safe_chr(c, buf, &p); c = fgetc(f); @@ -1049,24 +1049,24 @@ getstring_noalloc(FILE * f) for (;;) { c = fgetc(f); if (c == '"') { - /* It's a closing quote if it's followed by \r or \n */ - c = fgetc(f); - if (c == '\r') { - /* Get a possible \n, too */ - if ((c = fgetc(f)) != '\n') - ungetc(c, f); - else - dbline++; - } else if (c != '\n') - ungetc(c, f); - *p = '\0'; - return buf; + /* It's a closing quote if it's followed by \r or \n */ + c = fgetc(f); + if (c == '\r') { + /* Get a possible \n, too */ + if ((c = fgetc(f)) != '\n') + ungetc(c, f); + else + dbline++; + } else if (c != '\n') + ungetc(c, f); + *p = '\0'; + return buf; } else if (c == '\\') { - c = fgetc(f); + c = fgetc(f); } if ((c == '\0') || (c == EOF)) { - *p = '\0'; - return buf; + *p = '\0'; + return buf; } safe_chr(c, buf, &p); } @@ -1143,9 +1143,9 @@ get_new_locks(dbref i, FILE * f, int c) if (found != count) do_rawlog(LT_ERR, - T - ("WARNING: Actual lock count (%d) different from expected count (%d)."), - found, count); + T + ("WARNING: Actual lock count (%d) different from expected count (%d)."), + found, count); } @@ -1175,7 +1175,7 @@ getlocks(dbref i, FILE * f) do_rawlog(LT_ERR, T("ERROR: Invalid lock format on object #%d"), i); return; } - b = getboolexp(f, buf); /* Which will clobber a '\n' */ + b = getboolexp(f, buf); /* Which will clobber a '\n' */ if (b == TRUE_BOOLEXP) { /* getboolexp() would already have complained. */ return; @@ -1275,22 +1275,22 @@ get_list(FILE * f, dbref i) tbuf1[0] = '\0'; while (1) switch (c = getc(f)) { - case ']': /* new style attribs, read name then value */ + case ']': /* new style attribs, read name then value */ /* Using getstring_noalloc here will cause problems with attribute names starting with ". This is probably a better fix than just disallowing " in attribute names. */ fgets(tbuf1, BUFFER_LEN + 150, f); if (!(p = strchr(tbuf1, '^'))) { - do_rawlog(LT_ERR, T("ERROR: Bad format on new attributes. object #%d"), - i); - return -1; + do_rawlog(LT_ERR, T("ERROR: Bad format on new attributes. object #%d"), + i); + return -1; } *p++ = '\0'; if (!(q = strchr(p, '^'))) { - do_rawlog(LT_ERR, - T("ERROR: Bad format on new attribute %s. object #%d"), - tbuf1, i); - return -1; + do_rawlog(LT_ERR, + T("ERROR: Bad format on new attribute %s. object #%d"), + tbuf1, i); + return -1; } *q++ = '\0'; flags = atoi(q); @@ -1320,31 +1320,31 @@ get_list(FILE * f, dbref i) * attributes (which, if not built-in attrs, have a flag val of 0.) */ break; - case '>': /* old style attribs, die noisily */ + case '>': /* old style attribs, die noisily */ do_rawlog(LT_ERR, T("ERROR: old-style attribute format in object %d"), i); return -1; break; - case '<': /* end of list */ + case '<': /* end of list */ if ('\n' != getc(f)) { - do_rawlog(LT_ERR, T("ERROR: no line feed after < on object %d"), i); - return -1; + do_rawlog(LT_ERR, T("ERROR: no line feed after < on object %d"), i); + return -1; } return count; default: if (c == EOF) { - do_rawlog(LT_ERR, T("ERROR: Unexpected EOF on file.")); - return -1; + do_rawlog(LT_ERR, T("ERROR: Unexpected EOF on file.")); + return -1; } do_rawlog(LT_ERR, - T - ("ERROR: Bad character %c (%d) in attribute list on object %d"), - c, c, i); + T + ("ERROR: Bad character %c (%d) in attribute list on object %d"), + c, c, i); do_rawlog(LT_ERR, - T(" (expecting ], >, or < as first character of the line.)")); + T(" (expecting ], >, or < as first character of the line.)")); if (*tbuf1) - do_rawlog(LT_ERR, T(" Last attribute read was: %s"), tbuf1); + do_rawlog(LT_ERR, T(" Last attribute read was: %s"), tbuf1); else - do_rawlog(LT_ERR, T(" No attributes had been read yet.")); + do_rawlog(LT_ERR, T(" No attributes had been read yet.")); return -1; } } @@ -2060,6 +2060,8 @@ db_read(FILE * f) static void init_objdata_htab(int size, void (*free_data) (void *)) { + if (size < 128) + size = 128; hash_init(&htab_objdata, size, 4, free_data); hashinit(&htab_objdata_keys, 8, 32); } diff --git a/src/destroy.c b/src/destroy.c index 85790a4..bafc8ca 100644 --- a/src/destroy.c +++ b/src/destroy.c @@ -230,8 +230,8 @@ what_to_destroy(dbref player, char *name, int confirm) */ if (!controls(player, thing) && !(IsExit(thing) && - (controls(player, Destination(thing)) || - controls(player, Source(thing)))) && + (controls(player, Destination(thing)) || + controls(player, Source(thing)))) && !(DestOk(thing) && eval_lock(player, thing, Destroy_Lock))) { notify(player, T("Permission denied.")); return NOTHING; @@ -244,11 +244,11 @@ what_to_destroy(dbref player, char *name, int confirm) if (REALLY_SAFE) { if (Safe(thing) && !DestOk(thing)) { notify(player, - T - ("That object is set SAFE. You must set it !SAFE before destroying it.")); + T + ("That object is set SAFE. You must set it !SAFE before destroying it.")); return NOTHING; } - } else { /* REALLY_SAFE */ + } else { /* REALLY_SAFE */ if (Safe(thing) && !DestOk(thing) && !confirm) { notify(player, T("That object is marked SAFE. Use @nuke to destroy it.")); return NOTHING; @@ -257,7 +257,7 @@ what_to_destroy(dbref player, char *name, int confirm) /* check to make sure there's no accidental destruction */ if (!confirm && !Owns(player, thing) && !DestOk(thing)) { notify(player, - T("That object does not belong to you. Use @nuke to destroy it.")); + T("That object does not belong to you. Use @nuke to destroy it.")); return NOTHING; } /* what kind of thing we are destroying? */ @@ -277,7 +277,7 @@ what_to_destroy(dbref player, char *name, int confirm) } if (Connected(thing)) { notify(player, - T("How gruesome. You may not destroy players who are connected.")); + T("How gruesome. You may not destroy players who are connected.")); return NOTHING; } if (!confirm) { @@ -482,10 +482,10 @@ pre_destroy(dbref player, dbref thing) case TYPE_PLAYER: if (DESTROY_POSSESSIONS) { for (tmp = 0; tmp < db_top; tmp++) { - if (Owner(tmp) == thing && - (tmp != thing) && (!REALLY_SAFE || !Safe(thing))) { - pre_destroy(player, tmp); - } + if (Owner(tmp) == thing && + (tmp != thing) && (!REALLY_SAFE || !Safe(thing))) { + pre_destroy(player, tmp); + } } } break; @@ -497,9 +497,9 @@ pre_destroy(dbref player, dbref thing) * whose owner hasn't already been notified. */ if ((Owner(thing) != Owner(Source(thing))) && Going(Source(thing))) { if (!Owns(player, thing)) { - notify_format(Owner(thing), - T("%s has scheduled your %s for destruction."), - Name(player), object_header(Owner(thing), thing)); + notify_format(Owner(thing), + T("%s has scheduled your %s for destruction."), + Name(player), object_header(Owner(thing), thing)); } } break; @@ -539,11 +539,11 @@ undestroy(dbref player, dbref thing) if (Going(Owner(thing))) { if (Owner(thing) != player) { notify_format(player, - T("%s has been spared from destruction."), - object_header(player, Owner(thing))); + T("%s has been spared from destruction."), + object_header(player, Owner(thing))); notify_format(Owner(thing), - T("You have been spared from destruction by %s."), - Name(player)); + T("You have been spared from destruction by %s."), + Name(player)); } else { notify(player, T("You have been spared from destruction.")); } @@ -557,11 +557,11 @@ undestroy(dbref player, dbref thing) * be purged when the room is purged. */ for (tmp = 0; tmp < db_top; tmp++) { - if (Owns(thing, tmp) && - (tmp != thing) && - !(IsExit(tmp) && !Owns(thing, Source(tmp)) && Going(Source(tmp)))) { - (void) undestroy(player, tmp); - } + if (Owns(thing, tmp) && + (tmp != thing) && + !(IsExit(tmp) && !Owns(thing, Source(tmp)) && Going(Source(tmp)))) { + (void) undestroy(player, tmp); + } } break; case TYPE_DIVISION: @@ -572,13 +572,13 @@ undestroy(dbref player, dbref thing) if (Going(Source(thing))) { (void) undestroy(player, Source(thing)); notify_format(player, - T("The room %s has been spared from destruction."), - object_header(player, Source(thing))); + T("The room %s has been spared from destruction."), + object_header(player, Source(thing))); if (Owner(Source(thing)) != player) { - notify_format(Owner(Source(thing)), - T("The room %s has been spared from destruction by %s."), - object_header(Owner(Source(thing)), Source(thing)), - Name(player)); + notify_format(Owner(Source(thing)), + T("The room %s has been spared from destruction by %s."), + object_header(Owner(Source(thing)), Source(thing)), + Name(player)); } } break; @@ -588,7 +588,7 @@ undestroy(dbref player, dbref thing) */ DOLIST(tmp, Exits(thing)) { if (DESTROY_POSSESSIONS ? (!Going(Owner(tmp)) || Safe(tmp)) : 1) { - (void) undestroy(player, tmp); + (void) undestroy(player, tmp); } } break; @@ -634,7 +634,7 @@ free_object(dbref thing) break; default: do_log(LT_ERR, NOTHING, NOTHING, T("Unknown type on #%d in free_object."), - thing); + thing); return; } @@ -656,22 +656,22 @@ free_object(dbref thing) case TYPE_DIVISION: case TYPE_PLAYER: case TYPE_THING: - Home(i) = DEFAULT_HOME; - break; + Home(i) = DEFAULT_HOME; + break; case TYPE_EXIT: - /* Huh. An exit that claims to be from here, but wasn't linked - * in properly. */ - do_rawlog(LT_ERR, - T("ERROR: Exit %s leading from invalid room #%d destroyed."), - unparse_object(GOD, i), thing); - free_object(i); - break; + /* Huh. An exit that claims to be from here, but wasn't linked + * in properly. */ + do_rawlog(LT_ERR, + T("ERROR: Exit %s leading from invalid room #%d destroyed."), + unparse_object(GOD, i), thing); + free_object(i); + break; case TYPE_ROOM: - /* Hrm. It claims we're an exit from it, but we didn't agree. - * Clean it up anyway. */ - do_log(LT_ERR, NOTHING, NOTHING, - T("Found a destroyed exit #%d in room #%d"), thing, i); - break; + /* Hrm. It claims we're an exit from it, but we didn't agree. + * Clean it up anyway. */ + do_log(LT_ERR, NOTHING, NOTHING, + T("Found a destroyed exit #%d in room #%d"), thing, i); + break; } } /* The location check MUST be done AFTER the home check. */ @@ -680,22 +680,22 @@ free_object(dbref thing) case TYPE_DIVISION: case TYPE_PLAYER: case TYPE_THING: - /* Huh. It thought it was here, but we didn't agree. */ - enter_room(i, Home(i), 0); - break; + /* Huh. It thought it was here, but we didn't agree. */ + enter_room(i, Home(i), 0); + break; case TYPE_EXIT: - /* If our destination is destroyed, then we relink to the - * source room (so that the exit can't be stolen). Yes, it's - * inconsistent with the treatment of exits leading from - * destroyed rooms, but it's a lot better than turning exits - * into nasty limbo exits. - */ - Destination(i) = Source(i); - break; + /* If our destination is destroyed, then we relink to the + * source room (so that the exit can't be stolen). Yes, it's + * inconsistent with the treatment of exits leading from + * destroyed rooms, but it's a lot better than turning exits + * into nasty limbo exits. + */ + Destination(i) = Source(i); + break; case TYPE_ROOM: - /* Just remove a dropto. */ - Location(i) = NOTHING; - break; + /* Just remove a dropto. */ + Location(i) = NOTHING; + break; } } if (Next(i) == thing) { @@ -737,7 +737,7 @@ free_object(dbref thing) else current_state.players--; break; - case TYPE_EXIT: /* This probably won't be needed, but lets make sure */ + case TYPE_EXIT: /* This probably won't be needed, but lets make sure */ loc = Source(thing); if (GoodObject(loc)) Exits(loc) = remove_first(Exits(loc), thing); @@ -785,9 +785,9 @@ empty_contents(dbref thing) dbref rest; dbref target; notify_except(Contents(thing), NOTHING, - T - ("The floor disappears under your feet, you fall through NOTHINGness and then:"), - 0); + T + ("The floor disappears under your feet, you fall through NOTHINGness and then:"), + 0); first = Contents(thing); Contents(thing) = NOTHING; /* send all objects to nowhere */ @@ -799,23 +799,23 @@ empty_contents(dbref thing) rest = Next(first); /* if home is in thing set it to limbo */ switch (Typeof(first)) { - case TYPE_EXIT: /* if holding exits, destroy it */ + case TYPE_EXIT: /* if holding exits, destroy it */ free_object(first); break; - case TYPE_THING: /* move to home */ + case TYPE_THING: /* move to home */ case TYPE_PLAYER: /* Make sure the home is a reasonable object. */ if (!GoodObject(Home(first)) || IsExit(Home(first)) || - Home(first) == thing) - Home(first) = DEFAULT_HOME; + Home(first) == thing) + Home(first) = DEFAULT_HOME; target = Home(first); /* If home isn't a good place to send it, send it to DEFAULT_HOME. */ if (!GoodObject(target) || recursive_member(target, first, 0)) - target = DEFAULT_HOME; + target = DEFAULT_HOME; if (target != NOTHING) { - /* Use enter_room() on everything so that AENTER and such - * are all triggered properly. */ - enter_room(first, target, 0); + /* Use enter_room() on everything so that AENTER and such + * are all triggered properly. */ + enter_room(first, target, 0); } break; } @@ -842,9 +842,9 @@ clear_thing(dbref thing) clear_flag_internal(thing, "PUPPET"); if (!Quiet(thing) && !Quiet(Owner(thing))) notify_format(Owner(thing), - T("You get your %d %s deposit back for %s."), - a, ((a == 1) ? MONEY : MONIES), - object_header(Owner(thing), thing)); + T("You get your %d %s deposit back for %s."), + a, ((a == 1) ? MONEY : MONIES), + object_header(Owner(thing), thing)); } static void @@ -879,9 +879,9 @@ clear_player(dbref thing) for (i = 0; i < db_top; i++) { if (Owner(i) == thing && i != thing) { if (DESTROY_POSSESSIONS ? (REALLY_SAFE ? Safe(i) : 0) : 1) { - chown_object(GOD, i, GOD, 0); + chown_object(GOD, i, GOD, 0); } else { - free_object(i); + free_object(i); } } } @@ -989,9 +989,9 @@ purge(void) continue; } else if (Going(thing)) { if (Going_Twice(thing)) { - free_object(thing); + free_object(thing); } else { - set_flag_internal(thing, "GOING_TWICE"); + set_flag_internal(thing, "GOING_TWICE"); } } else { continue; @@ -1097,10 +1097,10 @@ check_fields(void) dbref next; next = Next(thing); if ((!GoodObject(next) || !IsGarbage(next)) && (next != NOTHING)) { - do_rawlog(LT_ERR, T("ERROR: Invalid next pointer #%d from object %s"), - next, unparse_object(GOD, thing)); - Next(thing) = NOTHING; - fix_free_list(); + do_rawlog(LT_ERR, T("ERROR: Invalid next pointer #%d from object %s"), + next, unparse_object(GOD, thing)); + Next(thing) = NOTHING; + fix_free_list(); } continue; } else { @@ -1108,22 +1108,22 @@ check_fields(void) dbref zone, loc, parent, home, owner, next; zone = Zone(thing); if (GoodObject(zone) && IsGarbage(zone)) - Zone(thing) = NOTHING; + Zone(thing) = NOTHING; parent = Parent(thing); if (GoodObject(parent) && IsGarbage(parent)) - Parent(thing) = NOTHING; + Parent(thing) = NOTHING; owner = Owner(thing); if (!GoodObject(owner) || IsGarbage(owner) || !IsPlayer(owner)) { - do_rawlog(LT_ERR, T("ERROR: Invalid object owner on %s(%d)"), - Name(thing), thing); - report(); - Owner(thing) = GOD; + do_rawlog(LT_ERR, T("ERROR: Invalid object owner on %s(%d)"), + Name(thing), thing); + report(); + Owner(thing) = GOD; } next = Next(thing); if ((!GoodObject(next) || IsGarbage(next)) && (next != NOTHING)) { - do_rawlog(LT_ERR, T("ERROR: Invalid next pointer #%d from object %s"), - next, unparse_object(GOD, thing)); - Next(thing) = NOTHING; + do_rawlog(LT_ERR, T("ERROR: Invalid next pointer #%d from object %s"), + next, unparse_object(GOD, thing)); + Next(thing) = NOTHING; } if((next == thing)) /* its saying itself is next? */ Next(thing) = NOTHING; @@ -1267,14 +1267,14 @@ check_connected_marks(void) ClearMarked(loc); else if (IsRoom(loc)) { if (!Name(loc)) { - do_log(LT_ERR, NOTHING, NOTHING, T("ERROR: no name for room #%d."), - loc); - set_name(loc, "XXXX"); + do_log(LT_ERR, NOTHING, NOTHING, T("ERROR: no name for room #%d."), + loc); + set_name(loc, "XXXX"); } if (!Going(loc) && !Floating(loc) && !NoWarnable(loc) && - (!EXITS_CONNECT_ROOMS || (Exits(loc) == NOTHING))) { - notify_format(Owner(loc), T("You own a disconnected room, %s"), - object_header(Owner(loc), loc)); + (!EXITS_CONNECT_ROOMS || (Exits(loc) == NOTHING))) { + notify_format(Owner(loc), T("You own a disconnected room, %s"), + object_header(Owner(loc), loc)); } } } @@ -1315,9 +1315,9 @@ check_zones(void) if (!IsGarbage(n) && Marked(n)) { ClearMarked(n); notify_format(Owner(n), - T - ("You own an object without a @lock/zone being used as a zone: %s"), - object_header(Owner(n), n)); + T + ("You own an object without a @lock/zone being used as a zone: %s"), + object_header(Owner(n), n)); } } } @@ -1370,7 +1370,7 @@ mark_contents(dbref thing) break; default: do_rawlog(LT_ERR, T("Bad object type found for %s in mark_contents"), - unparse_object(GOD, thing)); + unparse_object(GOD, thing)); break; } } @@ -1393,10 +1393,10 @@ check_contents(void) for (thing = 0; thing < db_top; thing++) { if (!IsRoom(thing) && !IsGarbage(thing) && !Marked(thing)) { do_rawlog(LT_ERR, T("Object %s not pointed to by anything."), - unparse_object(GOD, thing)); + unparse_object(GOD, thing)); notify_format(Owner(thing), - T("You own an object %s that was \'orphaned\'."), - object_header(Owner(thing), thing)); + T("You own an object %s that was \'orphaned\'."), + object_header(Owner(thing), thing)); /* We try to fix this by trying to send players and things to * their current location, to their home, or to DEFAULT_HOME, in * that order, and relinking exits to their source. @@ -1405,53 +1405,53 @@ check_contents(void) switch (Typeof(thing)) { case TYPE_PLAYER: case TYPE_THING: - if (GoodObject(Location(thing)) && - !IsGarbage(Location(thing)) && Marked(Location(thing))) { - PUSH(thing, Contents(Location(thing))); - } else if (GoodObject(Home(thing)) && - !IsGarbage(Home(thing)) && Marked(Home(thing))) { - Contents(Location(thing)) = - remove_first(Contents(Location(thing)), thing); - PUSH(thing, Contents(Home(thing))); - Location(thing) = Home(thing); - } else { - Contents(Location(thing)) = - remove_first(Contents(Location(thing)), thing); - PUSH(thing, Contents(DEFAULT_HOME)); - Location(thing) = DEFAULT_HOME; - } - enter_room(thing, Location(thing), 0); - /* If we've managed to reconnect it, then we've reconnected - * its contents. */ - mark_contents(Contents(thing)); - notify_format(Owner(thing), T("It was moved to %s."), - object_header(Owner(thing), Location(thing))); - do_rawlog(LT_ERR, T("Moved to %s."), - unparse_object(GOD, Location(thing))); - break; + if (GoodObject(Location(thing)) && + !IsGarbage(Location(thing)) && Marked(Location(thing))) { + PUSH(thing, Contents(Location(thing))); + } else if (GoodObject(Home(thing)) && + !IsGarbage(Home(thing)) && Marked(Home(thing))) { + Contents(Location(thing)) = + remove_first(Contents(Location(thing)), thing); + PUSH(thing, Contents(Home(thing))); + Location(thing) = Home(thing); + } else { + Contents(Location(thing)) = + remove_first(Contents(Location(thing)), thing); + PUSH(thing, Contents(DEFAULT_HOME)); + Location(thing) = DEFAULT_HOME; + } + enter_room(thing, Location(thing), 0); + /* If we've managed to reconnect it, then we've reconnected + * its contents. */ + mark_contents(Contents(thing)); + notify_format(Owner(thing), T("It was moved to %s."), + object_header(Owner(thing), Location(thing))); + do_rawlog(LT_ERR, T("Moved to %s."), + unparse_object(GOD, Location(thing))); + break; case TYPE_EXIT: - if (GoodObject(Source(thing)) && IsRoom(Source(thing))) { - PUSH(thing, Exits(Source(thing))); - notify_format(Owner(thing), T("It was moved to %s."), - object_header(Owner(thing), Source(thing))); - do_rawlog(LT_ERR, T("Moved to %s."), - unparse_object(GOD, Source(thing))); - } else { - /* Just destroy the exit. */ - Source(thing) = NOTHING; - notify(Owner(thing), T("It was destroyed.")); - do_rawlog(LT_ERR, T("Orphaned exit destroyed.")); - free_object(thing); - } - break; + if (GoodObject(Source(thing)) && IsRoom(Source(thing))) { + PUSH(thing, Exits(Source(thing))); + notify_format(Owner(thing), T("It was moved to %s."), + object_header(Owner(thing), Source(thing))); + do_rawlog(LT_ERR, T("Moved to %s."), + unparse_object(GOD, Source(thing))); + } else { + /* Just destroy the exit. */ + Source(thing) = NOTHING; + notify(Owner(thing), T("It was destroyed.")); + do_rawlog(LT_ERR, T("Orphaned exit destroyed.")); + free_object(thing); + } + break; case TYPE_ROOM: - /* We should never get here. */ - do_log(LT_ERR, NOTHING, NOTHING, T("Disconnected room. So what?")); - break; + /* We should never get here. */ + do_log(LT_ERR, NOTHING, NOTHING, T("Disconnected room. So what?")); + break; default: - do_log(LT_ERR, NOTHING, NOTHING, - T("Surprising type on #%d found in check_cycles."), thing); - break; + do_log(LT_ERR, NOTHING, NOTHING, + T("Surprising type on #%d found in check_cycles."), thing); + break; } } } @@ -1473,43 +1473,43 @@ check_locations(void) for (loc = 0; loc < db_top; loc++) { if (!IsExit(loc)) { for (thing = Contents(loc); thing != NOTHING; thing = Next(thing)) { - if (!Mobile(thing)) { - do_rawlog(LT_ERR, - T - ("ERROR: Contents of object %d corrupt at object %d cleared"), - loc, thing); - /* Remove this from the list and start over. */ - Contents(loc) = remove_first(Contents(loc), thing); - thing = Contents(loc); - continue; - } else if (Location(thing) != loc) { - /* Well, it would fit here, and it can't be elsewhere because - * we've done a check_contents already, so let's just put it - * here. - */ - do_rawlog(LT_ERR, - T("Incorrect location on object %s. Reset to #%d."), - unparse_object(GOD, thing), loc); - Location(thing) = loc; - } - SetMarked(thing); + if (!Mobile(thing)) { + do_rawlog(LT_ERR, + T + ("ERROR: Contents of object %d corrupt at object %d cleared"), + loc, thing); + /* Remove this from the list and start over. */ + Contents(loc) = remove_first(Contents(loc), thing); + thing = Contents(loc); + continue; + } else if (Location(thing) != loc) { + /* Well, it would fit here, and it can't be elsewhere because + * we've done a check_contents already, so let's just put it + * here. + */ + do_rawlog(LT_ERR, + T("Incorrect location on object %s. Reset to #%d."), + unparse_object(GOD, thing), loc); + Location(thing) = loc; + } + SetMarked(thing); } } if (IsRoom(loc)) { for (thing = Exits(loc); thing != NOTHING; thing = Next(thing)) { - if (!IsExit(thing)) { - do_rawlog(LT_ERR, - T("ERROR: Exits of room %d corrupt at object %d cleared"), - loc, thing); - /* Remove this from the list and start over. */ - Exits(loc) = remove_first(Exits(loc), thing); - thing = Exits(loc); - continue; - } else if (Source(thing) != loc) { - do_rawlog(LT_ERR, - T("Incorrect source on exit %s. Reset to #%d."), - unparse_object(GOD, thing), loc); - } + if (!IsExit(thing)) { + do_rawlog(LT_ERR, + T("ERROR: Exits of room %d corrupt at object %d cleared"), + loc, thing); + /* Remove this from the list and start over. */ + Exits(loc) = remove_first(Exits(loc), thing); + thing = Exits(loc); + continue; + } else if (Source(thing) != loc) { + do_rawlog(LT_ERR, + T("Incorrect source on exit %s. Reset to #%d."), + unparse_object(GOD, thing), loc); + } } } } diff --git a/src/extchat.c b/src/extchat.c index 1708b65..5bab816 100644 --- a/src/extchat.c +++ b/src/extchat.c @@ -89,9 +89,9 @@ static void channel_wipe(dbref player, CHAN *chan); static int yesno(const char *str); static int canstilladd(dbref player); static enum cmatch_type find_channel_partial_on(const char *name, CHAN **chan, - dbref player); + dbref player); static enum cmatch_type find_channel_partial_off(const char *name, CHAN **chan, - dbref player); + dbref player); static char *list_cuflags(CHANUSER *u, int verbose); static void channel_join_self(dbref player, const char *name); static void channel_leave_self(dbref player, const char *name); @@ -124,7 +124,7 @@ const char *chan_hide_lock = "ChanHideLock"; /**< Name of hide lock */ int num_channels; /**< Number of channels defined */ -CHAN *channels; /**< Pointer to channel list */ +CHAN *channels; /**< Pointer to channel list */ static PRIV priv_table[] = { {"Disabled", 'D', CHANNEL_DISABLED, CHANNEL_DISABLED}, @@ -288,8 +288,8 @@ load_chatdb(FILE * fp) if (strcmp(chat_timestamp, db_timestamp)) do_rawlog(LT_ERR, - T - ("CHAT: warning: chatdb and game db were saved at different times!")); + T + ("CHAT: warning: chatdb and game db were saved at different times!")); /* How many channels? */ db_read_this_labeled_number(fp, "channels", &num_channels); @@ -580,11 +580,11 @@ load_chanusers(FILE * fp, CHAN *ch) strcpy(CUtitle(user), getstring_noalloc(fp)); CUnext(user) = NULL; if (insert_user(user, ch)) - num++; + num++; } else { /* But be sure to read (and discard) the player's info */ do_log(LT_ERR, 0, 0, T("Bad object #%d removed from channel %s"), - player, ChanName(ch)); + player, ChanName(ch)); (void) getref(fp); (void) getstring_noalloc(fp); } @@ -724,9 +724,9 @@ insert_obj_chan(dbref who, CHAN **ch) } else { /* Otherwise, find which channel this channel should be inserted after */ for (; - p->next - && (strcasecoll(ChanName(p->next->chan), ChanName(*ch)) < 0); - p = p->next) ; + p->next + && (strcasecoll(ChanName(p->next->chan), ChanName(*ch)) < 0); + p = p->next) ; if (p->next && !strcasecmp(ChanName(p->next->chan), ChanName(*ch))) { /* Don't add the same channel twice! */ free_chanlist(tmp); @@ -818,9 +818,9 @@ insert_user(CHANUSER *user, CHAN *ch) } else { /* Otherwise, find which user this user should be inserted after */ for (; - p->next - && (strcasecoll(Name(CUdbref(p->next)), Name(CUdbref(user))) <= 0); - p = p->next) ; + p->next + && (strcasecoll(Name(CUdbref(p->next)), Name(CUdbref(user))) <= 0); + p = p->next) ; if (CUdbref(p) == CUdbref(user)) { /* Don't add the same user twice! */ mush_free((Malloc_t) user, "CHANUSER"); @@ -1091,12 +1091,12 @@ list_partial_matches(dbref player, const char *name, enum chan_match_type type) if (!Chan_Can_See(p, player)) continue; if ((type == PMATCH_ALL) || ((type == PMATCH_ON) - ? !!onchannel(player, p) - : !onchannel(player, p))) { + ? !!onchannel(player, p) + : !onchannel(player, p))) { strcpy(cleanp, remove_markup(ChanName(p), NULL)); if (string_prefix(cleanp, cleanname)) { - safe_chr(' ', buff, &bp); - safe_str(ChanName(p), buff, &bp); + safe_chr(' ', buff, &bp); + safe_str(ChanName(p), buff, &bp); } } } @@ -1188,13 +1188,13 @@ find_channel_partial_off(const char *name, CHAN **chan, dbref player) if (!OnChannel(player, p)) { strcpy(cleanp, remove_markup(ChanName(p), NULL)); if (!strcasecmp(cleanname, cleanp)) { - *chan = p; - return CMATCH_EXACT; + *chan = p; + return CMATCH_EXACT; } if (string_prefix(cleanp, cleanname)) { - if (!*chan) - *chan = p; - count++; + if (!*chan) + *chan = p; + count++; } } } @@ -1261,8 +1261,8 @@ do_channel(dbref player, const char *name, const char *target, const char *com) if (!Chan_Can_See(chan, player)) { if (OnChannel(player, chan)) notify_format(player, - T("CHAT: You can't do that with channel <%s>."), - ChanName(chan)); + T("CHAT: You can't do that with channel <%s>."), + ChanName(chan)); else notify(player, T("CHAT: I don't recognize that channel.")); return; @@ -1294,8 +1294,8 @@ do_channel(dbref player, const char *name, const char *target, const char *com) if (!strcasecmp("on", com) || !strcasecmp("join", com)) { if (!Chan_Ok_Type(chan, victim)) { notify_format(player, - T("Sorry, wrong type of thing for channel <%s>."), - ChanName(chan)); + T("Sorry, wrong type of thing for channel <%s>."), + ChanName(chan)); return; } if (Guest(player)) { @@ -1395,7 +1395,7 @@ channel_join_self(dbref player, const char *name) case CMATCH_NONE: if (find_channel_partial_on(name, &chan, player)) notify_format(player, T("CHAT: You are already on channel <%s>"), - ChanName(chan)); + ChanName(chan)); else notify(player, T("CHAT: I don't recognize that channel.")); return; @@ -1412,8 +1412,8 @@ channel_join_self(dbref player, const char *name) } if (!Chan_Ok_Type(chan, player)) { notify_format(player, - T("Sorry, wrong type of thing for channel <%s>."), - ChanName(chan)); + T("Sorry, wrong type of thing for channel <%s>."), + ChanName(chan)); return; } /* Does victim pass the joinlock? */ @@ -1421,8 +1421,8 @@ channel_join_self(dbref player, const char *name) if (Director(player)) { /* Directors can override join locks */ notify(player, - T - ("CHAT: Warning: You don't meet channel join permissions (joining anyway)")); + T + ("CHAT: Warning: You don't meet channel join permissions (joining anyway)")); } else { notify(player, T("Permission to join denied.")); return; @@ -1457,9 +1457,9 @@ channel_leave_self(dbref player, const char *name) switch (find_channel_partial_on(name, &chan, player)) { case CMATCH_NONE: if (find_channel_partial_off(name, &chan, player) - && Chan_Can_See(chan, player)) + && Chan_Can_See(chan, player)) notify_format(player, T("CHAT: You are not on channel <%s>"), - ChanName(chan)); + ChanName(chan)); else notify(player, T("CHAT: I don't recognize that channel.")); return; @@ -1573,7 +1573,7 @@ do_chat_by_name(dbref player, const char *name, const char *msg, int source) case CMATCH_NONE: if (find_channel(name, &c, player) == CMATCH_NONE) { if (source) - notify(player, T("CHAT: No such channel.")); + notify(player, T("CHAT: No such channel.")); return 0; } } @@ -1845,7 +1845,7 @@ do_chan_admin(dbref player, char *name, const char *perms, int flag) /* Can the player afford it? There's a cost */ if (!payfor(Owner(player), CHANNEL_COST)) { notify_format(player, T("You can't afford the %d %s."), CHANNEL_COST, - MONIES); + MONIES); return; } /* Ok, let's do it */ @@ -1901,8 +1901,8 @@ do_chan_admin(dbref player, char *name, const char *perms, int flag) * itself */ if (temp != chan) { - notify(player, T("The channel needs a more unique new name.")); - return; + notify(player, T("The channel needs a more unique new name.")); + return; } } if (strlen(perms) > CHAN_NAME_LEN - 1) { @@ -1915,8 +1915,8 @@ do_chan_admin(dbref player, char *name, const char *perms, int flag) strcpy(ChanName(chan), perms); insert_channel(&chan); channel_broadcast(chan, player, 0, - "<%s> %s has renamed channel %s to %s.", - ChanName(chan), Name(player), old, ChanName(chan)); + "<%s> %s has renamed channel %s to %s.", + ChanName(chan), Name(player), old, ChanName(chan)); notify(player, T("Channel renamed.")); break; case 3: @@ -1936,13 +1936,13 @@ do_chan_admin(dbref player, char *name, const char *perms, int flag) notify(player, T("Warning: channel will be disabled.")); if (type == ChanType(chan)) { notify_format(player, - T - ("Invalid or same permissions on channel <%s>. No changes made."), - ChanName(chan)); + T + ("Invalid or same permissions on channel <%s>. No changes made."), + ChanName(chan)); } else { ChanType(chan) = type; notify_format(player, - T("Permissions on channel <%s> changed."), ChanName(chan)); + T("Permissions on channel <%s> changed."), ChanName(chan)); } break; } @@ -1993,7 +1993,7 @@ ok_channel_name(const char *n) */ void do_chan_user_flags(dbref player, char *name, const char *isyn, int flag, - int silent) + int silent) { CHAN *c = NULL; CHANUSER *u; @@ -2011,15 +2011,15 @@ do_chan_user_flags(dbref player, char *name, const char *isyn, int flag, switch (flag) { case 0: notify(player, setting ? T("All channels have been muted.") - : T("All channels have been unmuted.")); + : T("All channels have been unmuted.")); break; case 1: notify(player, setting ? T("You hide on all the channels you can.") - : T("You unhide on all channels.")); + : T("You unhide on all channels.")); break; case 2: notify(player, setting ? T("All channels have been gagged.") - : T("All channels have been ungagged.")); + : T("All channels have been ungagged.")); break; } } else { @@ -2040,7 +2040,7 @@ do_chan_user_flags(dbref player, char *name, const char *isyn, int flag, if (!u) { /* This should only happen if they gave us a bad name */ if (!silent) - notify_format(player, T("You are not on channel <%s>."), ChanName(c)); + notify_format(player, T("You are not on channel <%s>."), ChanName(c)); return; } @@ -2140,7 +2140,7 @@ do_chan_title(dbref player, const char *name, const char *title) /* Stomp newlines and other weird whitespace */ for (scan = title; *scan; scan++) { if ((isspace((unsigned char) *scan) && (*scan != ' ')) - || (*scan == BEEP_CHAR)) { + || (*scan == BEEP_CHAR)) { notify(player, T("Invalid character in title.")); return; } @@ -2181,18 +2181,18 @@ do_channel_list(dbref player, const char *partname) if (SUPPORT_PUEBLO) notify_noenter(player, tprintf("%cSAMP%c", TAG_START, TAG_END)); notify_format(player, "%-30s %-5s %8s %-16s %-8s %-3s", - "Name", "Users", "Msgs", T("Chan Type"), "Status", "Buf"); + "Name", "Users", "Msgs", T("Chan Type"), "Status", "Buf"); for (c = channels; c; c = c->next) { strcpy(cleanname, remove_markup(ChanName(c), NULL)); if (Chan_Can_See(c, player) && string_prefix(cleanname, partname)) { u = onchannel(player, c); if (SUPPORT_PUEBLO) - sprintf(numusers, - "%cA XCH_CMD=\"@channel/who %s\" XCH_HINT=\"See who's on this channel now\"%c%5ld%c/A%c", - TAG_START, cleanname, TAG_END, ChanNumUsers(c), - TAG_START, TAG_END); + sprintf(numusers, + "%cA XCH_CMD=\"@channel/who %s\" XCH_HINT=\"See who's on this channel now\"%c%5ld%c/A%c", + TAG_START, cleanname, TAG_END, ChanNumUsers(c), + TAG_START, TAG_END); else - sprintf(numusers, "%5ld", ChanNumUsers(c)); + sprintf(numusers, "%5ld", ChanNumUsers(c)); /* Display length is strlen(cleanname), but actual length is * strlen(ChanName(c)). There are two different cases: * 1. actual length <= 30. No problems. @@ -2325,9 +2325,9 @@ FUNCTION(fun_cflags) } if (nargs == 1) { if (string_prefix(called_as, "CL")) - safe_str(privs_to_string(priv_table, ChanType(c)), buff, bp); + safe_str(privs_to_string(priv_table, ChanType(c)), buff, bp); else - safe_str(privs_to_letters(priv_table, ChanType(c)), buff, bp); + safe_str(privs_to_letters(priv_table, ChanType(c)), buff, bp); return; } thing = match_thing(executor, args[1]); @@ -2427,9 +2427,9 @@ FUNCTION(fun_ctitle) u = onchannel(thing, c); if (!u) { if (can_ex || ok) - safe_str(T("#-1 NOT ON CHANNEL"), buff, bp); + safe_str(T("#-1 NOT ON CHANNEL"), buff, bp); else - safe_str(T("#-1 PERMISSION DENIED"), buff, bp); + safe_str(T("#-1 PERMISSION DENIED"), buff, bp); return; } ok &= !Chanuser_Hide(u); @@ -2484,7 +2484,7 @@ FUNCTION(fun_cstatus) } /* They're on the channel, but maybe we can't see them? */ if (Chanuser_Hide(u) && - !(Priv_Who(executor) || Can_Examine(executor, thing))) { + !(Priv_Who(executor) || Can_Examine(executor, thing))) { safe_str("Off", buff, bp); return; } @@ -2533,7 +2533,7 @@ channel_wipe(dbref player, CHAN *chan) victim = CUdbref(u); if (remove_user(u, chan)) notify_format(victim, T("CHAT: %s has removed all users from <%s>."), - Name(player), ChanName(chan)); + Name(player), ChanName(chan)); } ChanNumUsers(chan) = 0; return; @@ -2595,8 +2595,8 @@ do_chan_chown(dbref player, const char *name, const char *newowner) */ chan_chown(c, victim); notify_format(player, - T("CHAT: Channel <%s> now owned by %s."), ChanName(c), - Name(ChanCreator(c))); + T("CHAT: Channel <%s> now owned by %s."), ChanName(c), + Name(ChanCreator(c))); return; } @@ -2688,36 +2688,36 @@ do_chan_lock(dbref player, const char *name, const char *lockstr, int whichlock) free_boolexp(ChanJoinLock(c)); ChanJoinLock(c) = key; notify_format(player, (key == TRUE_BOOLEXP) ? - T("CHAT: Joinlock on <%s> reset.") : - T("CHAT: Joinlock on <%s> set."), ChanName(c)); + T("CHAT: Joinlock on <%s> reset.") : + T("CHAT: Joinlock on <%s> set."), ChanName(c)); break; case CL_SPEAK: free_boolexp(ChanSpeakLock(c)); ChanSpeakLock(c) = key; notify_format(player, (key == TRUE_BOOLEXP) ? - T("CHAT: Speaklock on <%s> reset.") : - T("CHAT: Speaklock on <%s> set."), ChanName(c)); + T("CHAT: Speaklock on <%s> reset.") : + T("CHAT: Speaklock on <%s> set."), ChanName(c)); break; case CL_SEE: free_boolexp(ChanSeeLock(c)); ChanSeeLock(c) = key; notify_format(player, (key == TRUE_BOOLEXP) ? - T("CHAT: Seelock on <%s> reset.") : - T("CHAT: Seelock on <%s> set."), ChanName(c)); + T("CHAT: Seelock on <%s> reset.") : + T("CHAT: Seelock on <%s> set."), ChanName(c)); break; case CL_HIDE: free_boolexp(ChanHideLock(c)); ChanHideLock(c) = key; notify_format(player, (key == TRUE_BOOLEXP) ? - T("CHAT: Hidelock on <%s> reset.") : - T("CHAT: Hidelock on <%s> set."), ChanName(c)); + T("CHAT: Hidelock on <%s> reset.") : + T("CHAT: Hidelock on <%s> set."), ChanName(c)); break; case CL_MOD: free_boolexp(ChanModLock(c)); ChanModLock(c) = key; notify_format(player, (key == TRUE_BOOLEXP) ? - T("CHAT: Modlock on <%s> reset.") : - T("CHAT: Modlock on <%s> set."), ChanName(c)); + T("CHAT: Modlock on <%s> reset.") : + T("CHAT: Modlock on <%s> set."), ChanName(c)); break; } return; @@ -2935,11 +2935,11 @@ FUNCTION(fun_cwho) for (u = ChanUsers(chan); u; u = u->next) { who = CUdbref(u); if ((IsThing(who) || Connected(who)) && - (!Chanuser_Hide(u) || Priv_Who(executor))) { + (!Chanuser_Hide(u) || Priv_Who(executor))) { if (first) - first = 0; + first = 0; else - safe_chr(' ', buff, bp); + safe_chr(' ', buff, bp); safe_dbref(who, buff, bp); } } @@ -2975,11 +2975,11 @@ do_chan_desc(dbref player, const char *name, const char *title) if (!title || !*title) { ChanTitle(c)[0] = '\0'; notify_format(player, T("CHAT: Channel <%s> description cleared."), - ChanName(c)); + ChanName(c)); } else { strcpy(ChanTitle(c), title); notify_format(player, T("CHAT: Channel <%s> description set."), - ChanName(c)); + ChanName(c)); } } @@ -3107,35 +3107,35 @@ FUNCTION(fun_channels) if (GoodObject(it)) { int first = 1; if (!delim_check(buff, bp, nargs, args, 2, &sep)) - return; + return; can_ex = Can_Examine(executor, it); for (cl = Chanlist(it); cl; cl = cl->next) { - if (can_ex || ((u = onchannel(it, cl->chan)) &&!Chanuser_Hide(u) - && onchannel(executor, cl->chan))) { - if (!first) - safe_chr(sep, buff, bp); - safe_str(ChanName(cl->chan), buff, bp); - first = 0; - } + if (can_ex || ((u = onchannel(it, cl->chan)) &&!Chanuser_Hide(u) + && onchannel(executor, cl->chan))) { + if (!first) + safe_chr(sep, buff, bp); + safe_str(ChanName(cl->chan), buff, bp); + first = 0; + } } return; } else { /* args[0] didn't match. Maybe it's a delimiter? */ if (arglens[0] > 1) { - if (it == NOTHING) - notify(executor, T("I can't see that here.")); - else if (it == AMBIGUOUS) - notify(executor, T("I don't know which thing you mean.")); - return; + if (it == NOTHING) + notify(executor, T("I can't see that here.")); + else if (it == AMBIGUOUS) + notify(executor, T("I don't know which thing you mean.")); + return; } else if (!delim_check(buff, bp, nargs, args, 1, &sep)) - return; + return; } } /* No arguments (except maybe delimiter) - return list of all channels */ for (c = channels; c; c = c->next) { if (Chan_Can_See(c, executor)) { if (c != channels) - safe_chr(sep, buff, bp); + safe_chr(sep, buff, bp); safe_str(ChanName(c), buff, bp); } } @@ -3187,8 +3187,8 @@ FUNCTION(fun_clock) if (nargs == 2) { if (FUNCTION_SIDE_EFFECTS) { if (!command_check_byname(executor, "@clock") || fun->flags & FN_NOSIDEFX) { - safe_str(T(e_perm), buff, bp); - return; + safe_str(T(e_perm), buff, bp); + return; } do_chan_lock(executor, args[0], args[1], which_lock); return; @@ -3307,27 +3307,27 @@ FUNCTION(fun_crecall) start--; } while ((buf = iter_bufferq(ChanBufferQ(chan), &p, &speaker, &type, - ×tamp)) && num_lines > 0) { + ×tamp)) && num_lines > 0) { if (first) first = 0; else safe_chr(sep, buff, bp); if (Nospoof(executor) && GoodObject(speaker)) { char *nsmsg = ns_esnotify(speaker, na_one, &executor, - Paranoid(executor) ? 1 : 0); + Paranoid(executor) ? 1 : 0); if (!showstamp) - safe_format(buff, bp, T("%s %s"), nsmsg, buf); + safe_format(buff, bp, T("%s %s"), nsmsg, buf); else { - stamp = show_time(timestamp, 0); - safe_format(buff, bp, T("[%s] %s %s"), stamp, nsmsg, buf); + stamp = show_time(timestamp, 0); + safe_format(buff, bp, T("[%s] %s %s"), stamp, nsmsg, buf); } mush_free(nsmsg, "string"); } else { if (!showstamp) - safe_str(buf, buff, bp); + safe_str(buf, buff, bp); else { - stamp = show_time(timestamp, 0); - safe_format(buff, bp, T("[%s] %s"), stamp, buf); + stamp = show_time(timestamp, 0); + safe_format(buff, bp, T("[%s] %s"), stamp, buf); } } num_lines--; @@ -3464,7 +3464,7 @@ channel_broadcast(CHAN *channel, dbref player, int flags, const char *fmt, ...) #ifdef HAS_VSNPRINTF char tbuf1[BUFFER_LEN]; #else - char tbuf1[BUFFER_LEN * 2]; /* Safety margin as per tprintf */ + char tbuf1[BUFFER_LEN * 2]; /* Safety margin as per tprintf */ #endif struct na_cpass nac; int na_flags = NA_INTER_LOCK; @@ -3488,10 +3488,10 @@ channel_broadcast(CHAN *channel, dbref player, int flags, const char *fmt, ...) if (Channel_Interact(channel)) na_flags |= (flags & CB_PRESENCE) ? NA_INTER_PRESENCE : NA_INTER_HEAR; notify_anything(player, na_channel, &nac, ns_esnotify, - na_flags | ((flags & CB_NOSPOOF) ? 0 : NA_SPOOF), tbuf1); + na_flags | ((flags & CB_NOSPOOF) ? 0 : NA_SPOOF), tbuf1); if (ChanBufferQ(channel)) add_to_bufferq(ChanBufferQ(channel), 0, - (flags & CB_NOSPOOF) ? player : NOTHING, tbuf1); + (flags & CB_NOSPOOF) ? player : NOTHING, tbuf1); } @@ -3513,7 +3513,7 @@ do_chan_recall(dbref player, const char *name, char *lineinfo[], int quiet) CHANUSER *u; const char *lines; const char *startpos; - int num_lines = 10; /* Default if none is given */ + int num_lines = 10; /* Default if none is given */ int start = -1; int all; char *p = NULL, *buf; @@ -3539,7 +3539,7 @@ do_chan_recall(dbref player, const char *name, char *lineinfo[], int quiet) if (is_integer(lines)) { num_lines = parse_integer(lines); if (num_lines == 0) - num_lines = INT_MAX; + num_lines = INT_MAX; } else { notify(player, T("How many lines did you want to recall?")); return; @@ -3554,8 +3554,8 @@ do_chan_recall(dbref player, const char *name, char *lineinfo[], int quiet) if (!Chan_Can_See(chan, player)) { if (OnChannel(player, chan)) notify_format(player, - T("CHAT: You can't do that with channel <%s>."), - ChanName(chan)); + T("CHAT: You can't do that with channel <%s>."), + ChanName(chan)); else notify(player, T("CHAT: I don't recognize that channel.")); return; @@ -3584,23 +3584,23 @@ do_chan_recall(dbref player, const char *name, char *lineinfo[], int quiet) start--; } while ((buf = iter_bufferq(ChanBufferQ(chan), &p, &speaker, &type, - ×tamp)) && num_lines > 0) { + ×tamp)) && num_lines > 0) { if (Nospoof(player) && GoodObject(speaker)) { char *nsmsg = ns_esnotify(speaker, na_one, &player, - Paranoid(player) ? 1 : 0); + Paranoid(player) ? 1 : 0); if (quiet) - notify_format(player, T("%s %s"), nsmsg, buf); + notify_format(player, T("%s %s"), nsmsg, buf); else { - stamp = show_time(timestamp, 0); - notify_format(player, T("[%s] %s %s"), stamp, nsmsg, buf); + stamp = show_time(timestamp, 0); + notify_format(player, T("[%s] %s %s"), stamp, nsmsg, buf); } mush_free(nsmsg, "string"); } else { if (quiet) - notify(player, buf); + notify(player, buf); else { - stamp = show_time(timestamp, 0); - notify_format(player, T("[%s] %s"), stamp, buf); + stamp = show_time(timestamp, 0); + notify_format(player, T("[%s] %s"), stamp, buf); } } num_lines--; @@ -3608,9 +3608,9 @@ do_chan_recall(dbref player, const char *name, char *lineinfo[], int quiet) notify(player, T("CHAT: End recall")); if (!all) notify_format(player, - T - ("CHAT: To recall the entire buffer, use @chan/recall %s=0"), - ChanName(chan)); + T + ("CHAT: To recall the entire buffer, use @chan/recall %s=0"), + ChanName(chan)); } /** Set the size of a channel's buffer in maximum lines. diff --git a/src/extmail.c b/src/extmail.c index 6407907..4281d7f 100644 --- a/src/extmail.c +++ b/src/extmail.c @@ -91,7 +91,7 @@ #ifdef USE_MAILER -extern int do_convtime(const char *str, struct tm *ttm); /* funtime.c */ +extern int do_convtime(const char *str, struct tm *ttm); /* funtime.c */ static void do_mail_flags (dbref player, const char *msglist, mail_flag flag, int negate); @@ -100,19 +100,19 @@ static MAIL *mail_fetch(dbref player, int num); static MAIL *real_mail_fetch(dbref player, int num, int folder); static MAIL *mailfun_fetch(dbref player, int nargs, char *arg1, char *arg2); static void count_mail(dbref player, - int folder, int *rcount, int *ucount, int *ccount); + int folder, int *rcount, int *ucount, int *ccount); static int real_send_mail(dbref player, - dbref target, char *subject, char *message, - mail_flag flags, int silent, int nosig); + dbref target, char *subject, char *message, + mail_flag flags, int silent, int nosig); static void send_mail(dbref player, - dbref target, char *subject, char *message, - mail_flag flags, int silent, int nosig); + dbref target, char *subject, char *message, + mail_flag flags, int silent, int nosig); static int send_mail_alias(dbref player, - char *aname, char *subject, - char *message, mail_flag flags, int silent, - int nosig); + char *aname, char *subject, + char *message, mail_flag flags, int silent, + int nosig); static void filter_mail(dbref from, dbref player, char *subject, - char *message, int mailnumber, mail_flag flags); + char *message, int mailnumber, mail_flag flags); static MAIL *find_insertion_point(dbref player); static int get_folder_number(dbref player, char *name); static char *get_folder_name(dbref player, int fld); @@ -132,17 +132,17 @@ static char *get_subject(MAIL *mp); static char *get_sender(MAIL *mp, int full); static int was_sender(dbref player, MAIL *mp); -MAIL *maildb; /**< The head of the mail list */ -MAIL *tail_ptr; /**< The end of the mail list */ +MAIL *maildb; /**< The head of the mail list */ +MAIL *tail_ptr; /**< The end of the mail list */ -#define HEAD maildb /**< The head of the mail list */ -#define TAIL tail_ptr /**< The end of the mail list */ +#define HEAD maildb /**< The head of the mail list */ +#define TAIL tail_ptr /**< The end of the mail list */ /** A line of...dashes! */ #define DASH_LINE \ "-----------------------------------------------------------------------------" -int mdb_top = 0; /**< total number of messages in mail db */ +int mdb_top = 0; /**< total number of messages in mail db */ /*-------------------------------------------------------------------------* * User mail functions (these are called from game.c) @@ -201,11 +201,11 @@ get_subject(MAIL *mp) /* Stop at a return or a tab */ for (p = sbuf; *p; p++) { if ((*p == '\r') || (*p == '\n') || (*p == '\t')) { - *p = '\0'; - break; + *p = '\0'; + break; } if (!isprint((unsigned char) *p)) { - *p = ' '; + *p = ' '; } } } else @@ -227,7 +227,7 @@ get_sender(MAIL *mp, int full) safe_str(Name(mp->from), tbuf1, &bp); else safe_format(tbuf1, &bp, "%s (owner: %s)", Name(mp->from), - Name(Owner(mp->from))); + Name(Owner(mp->from))); *bp = '\0'; return tbuf1; } @@ -266,8 +266,8 @@ do_mail_change_folder(dbref player, char *fld, char *newname) check_mail(player, pfld, 1); pfld = player_folder(player); notify_format(player, - T("MAIL: Current folder is %d [%s]."), pfld, - get_folder_name(player, pfld)); + T("MAIL: Current folder is %d [%s]."), pfld, + get_folder_name(player, pfld)); return; } pfld = parse_folder(player, fld); @@ -283,8 +283,8 @@ do_mail_change_folder(dbref player, char *fld, char *newname) } for (p = newname; p && *p; p++) { if (!isdigit((unsigned char) *p) && !isalpha((unsigned char) *p)) { - notify(player, T("MAIL: Illegal folder name")); - return; + notify(player, T("MAIL: Illegal folder name")); + return; } } add_folder_name(player, pfld, newname); @@ -293,8 +293,8 @@ do_mail_change_folder(dbref player, char *fld, char *newname) /* Set a new folder */ set_player_folder(player, pfld); notify_format(player, - T("MAIL: Current folder set to %d [%s]."), pfld, - get_folder_name(player, pfld)); + T("MAIL: Current folder set to %d [%s]."), pfld, + get_folder_name(player, pfld)); } } @@ -391,50 +391,50 @@ do_mail_flags(dbref player, const char *msglist, mail_flag flag, int negate) if ((mp->to == player) && (All(ms) || (Folder(mp) == folder))) { i[Folder(mp)]++; if (mail_match(player, mp, ms, i[Folder(mp)])) { - j++; - if (negate) { - mp->read &= ~flag; - } else { - mp->read |= flag; - } - switch (flag) { - case M_TAG: - if (All(ms)) { - if (!notified) { - notify_format(player, - T("MAIL: All messages in all folders %s."), - negate ? "untagged" : "tagged"); - notified++; - } - } else - notify_format(player, - "MAIL: Msg #%d:%d %s.", Folder(mp), - i[Folder(mp)], negate ? "untagged" : "tagged"); - break; - case M_CLEARED: - if (All(ms)) { - if (!notified) { - notify_format(player, - T("MAIL: All messages in all folders %s."), - negate ? "uncleared" : "cleared"); - notified++; - } - } else { - if (Unread(mp) && !negate) { - notify_format(player, - T - ("MAIL: Unread Msg #%d:%d cleared! Use @mail/unclear %d:%d to recover."), - Folder(mp), i[Folder(mp)], Folder(mp), - i[Folder(mp)]); - } else { - notify_format(player, - (negate ? T("MAIL: Msg #%d:%d uncleared.") : - T("MAIL: Msg #%d:%d cleared.")), Folder(mp), - i[Folder(mp)]); - } - } - break; - } + j++; + if (negate) { + mp->read &= ~flag; + } else { + mp->read |= flag; + } + switch (flag) { + case M_TAG: + if (All(ms)) { + if (!notified) { + notify_format(player, + T("MAIL: All messages in all folders %s."), + negate ? "untagged" : "tagged"); + notified++; + } + } else + notify_format(player, + "MAIL: Msg #%d:%d %s.", Folder(mp), + i[Folder(mp)], negate ? "untagged" : "tagged"); + break; + case M_CLEARED: + if (All(ms)) { + if (!notified) { + notify_format(player, + T("MAIL: All messages in all folders %s."), + negate ? "uncleared" : "cleared"); + notified++; + } + } else { + if (Unread(mp) && !negate) { + notify_format(player, + T + ("MAIL: Unread Msg #%d:%d cleared! Use @mail/unclear %d:%d to recover."), + Folder(mp), i[Folder(mp)], Folder(mp), + i[Folder(mp)]); + } else { + notify_format(player, + (negate ? T("MAIL: Msg #%d:%d uncleared.") : + T("MAIL: Msg #%d:%d cleared.")), Folder(mp), + i[Folder(mp)]); + } + } + break; + } } } } @@ -477,22 +477,22 @@ do_mail_file(dbref player, char *msglist, char *folder) if ((mp->to == player) && (All(ms) || (Folder(mp) == origfold))) { i[Folder(mp)]++; if (mail_match(player, mp, ms, i[Folder(mp)])) { - j++; - mp->read &= M_FMASK; /* Clear the folder */ - mp->read &= ~M_CLEARED; /* Unclear it if it was marked cleared */ - mp->read |= FolderBit(foldernum); - if (All(ms)) { - if (!notified) { - notify_format(player, - T("MAIL: All messages filed in folder %d [%s]"), - foldernum, get_folder_name(player, foldernum)); - notified++; - } - } else - notify_format(player, - T("MAIL: Msg %d:%d filed in folder %d [%s]"), - origfold, i[origfold], foldernum, - get_folder_name(player, foldernum)); + j++; + mp->read &= M_FMASK; /* Clear the folder */ + mp->read &= ~M_CLEARED; /* Unclear it if it was marked cleared */ + mp->read |= FolderBit(foldernum); + if (All(ms)) { + if (!notified) { + notify_format(player, + T("MAIL: All messages filed in folder %d [%s]"), + foldernum, get_folder_name(player, foldernum)); + notified++; + } + } else + notify_format(player, + T("MAIL: Msg %d:%d filed in folder %d [%s]"), + origfold, i[origfold], foldernum, + get_folder_name(player, foldernum)); } } } @@ -529,40 +529,40 @@ do_mail_read(dbref player, char *msglist) if ((mp->to == player) && (All(ms) || Folder(mp) == folder)) { i[Folder(mp)]++; if (mail_match(player, mp, ms, i[Folder(mp)])) { - /* Read it */ - j++; - if (SUPPORT_PUEBLO) { - notify_noenter(player, tprintf("%cSAMP%c", TAG_START, TAG_END)); - sprintf(folderheader, - "%cA XCH_HINT=\"List messages in this folder\" XCH_CMD=\"@mail/list %d:1-\"%c%s%c/A%c", - TAG_START, Folder(mp), TAG_END, T("Folder:"), TAG_START, - TAG_END); - } else - strcpy(folderheader, T("Folder:")); - notify(player, DASH_LINE); - strcpy(tbuf1, get_sender(mp, 1)); - notify_format(player, - T - ("From: %-55s %s\nDate: %-25s %s %2d Message: %d\nStatus: %s"), - tbuf1, ((*tbuf1 != '!') && IsPlayer(mp->from) - && Connected(mp->from) - && (!hidden(mp->from) - || Priv_Who(player))) ? " (Conn)" : " ", - show_time(mp->time, 0), folderheader, Folder(mp), - i[Folder(mp)], status_string(mp)); - notify_format(player, T("Subject: %s"), get_subject(mp)); - notify(player, DASH_LINE); - if (SUPPORT_PUEBLO) - notify_noenter(player, tprintf("%c/SAMP%c", TAG_START, TAG_END)); - strcpy(tbuf1, get_message(mp)); - notify(player, tbuf1); - if (SUPPORT_PUEBLO) - notify_format(player, "%cSAMP%c%s%c/SAMP%c", TAG_START, TAG_END, - DASH_LINE, TAG_START, TAG_END); - else - notify(player, DASH_LINE); - if (Unread(mp)) - mp->read |= M_MSGREAD; /* mark message as read */ + /* Read it */ + j++; + if (SUPPORT_PUEBLO) { + notify_noenter(player, tprintf("%cSAMP%c", TAG_START, TAG_END)); + sprintf(folderheader, + "%cA XCH_HINT=\"List messages in this folder\" XCH_CMD=\"@mail/list %d:1-\"%c%s%c/A%c", + TAG_START, Folder(mp), TAG_END, T("Folder:"), TAG_START, + TAG_END); + } else + strcpy(folderheader, T("Folder:")); + notify(player, DASH_LINE); + strcpy(tbuf1, get_sender(mp, 1)); + notify_format(player, + T + ("From: %-55s %s\nDate: %-25s %s %2d Message: %d\nStatus: %s"), + tbuf1, ((*tbuf1 != '!') && IsPlayer(mp->from) + && Connected(mp->from) + && (!hidden(mp->from) + || Priv_Who(player))) ? " (Conn)" : " ", + show_time(mp->time, 0), folderheader, Folder(mp), + i[Folder(mp)], status_string(mp)); + notify_format(player, T("Subject: %s"), get_subject(mp)); + notify(player, DASH_LINE); + if (SUPPORT_PUEBLO) + notify_noenter(player, tprintf("%c/SAMP%c", TAG_START, TAG_END)); + strcpy(tbuf1, get_message(mp)); + notify(player, tbuf1); + if (SUPPORT_PUEBLO) + notify_format(player, "%cSAMP%c%s%c/SAMP%c", TAG_START, TAG_END, + DASH_LINE, TAG_START, TAG_END); + else + notify(player, DASH_LINE); + if (Unread(mp)) + mp->read |= M_MSGREAD; /* mark message as read */ } } } @@ -598,32 +598,32 @@ do_mail_list(dbref player, const char *msglist) if (SUPPORT_PUEBLO) notify_noenter(player, tprintf("%cSAMP%c", TAG_START, TAG_END)); notify_format(player, - T - ("--------------------------- MAIL (folder %2d) ------------------------------"), - folder); + T + ("--------------------------- MAIL (folder %2d) ------------------------------"), + folder); for (mp = find_exact_starting_point(player); mp && (mp->to == player); mp = mp->next) { if ((mp->to == player) && (All(ms) || Folder(mp) == folder)) { i[Folder(mp)]++; if (mail_match(player, mp, ms, i[Folder(mp)])) { - /* list it */ - if (SUPPORT_PUEBLO) - notify_noenter(player, - tprintf - ("%cA XCH_CMD=\"@mail/read %d:%d\" XCH_HINT=\"Read message %d in folder %d\"%c", - TAG_START, Folder(mp), i[Folder(mp)], - i[Folder(mp)], Folder(mp), TAG_END)); - strcpy(subj, chopstr(get_subject(mp), 28)); - strcpy(sender, chopstr(get_sender(mp, 0), 12)); - notify_format(player, "[%s] %2d:%-3d %c%-12s %-*s %s", - status_chars(mp), Folder(mp), i[Folder(mp)], - ((*sender != '!') && (Connected(mp->from) && - (!hidden(mp->from) - || Priv_Who(player))) - ? '*' : ' '), sender, 30, subj, - mail_list_time(show_time(mp->time, 0), 1)); - if (SUPPORT_PUEBLO) - notify_noenter(player, tprintf("%c/A%c", TAG_START, TAG_END)); + /* list it */ + if (SUPPORT_PUEBLO) + notify_noenter(player, + tprintf + ("%cA XCH_CMD=\"@mail/read %d:%d\" XCH_HINT=\"Read message %d in folder %d\"%c", + TAG_START, Folder(mp), i[Folder(mp)], + i[Folder(mp)], Folder(mp), TAG_END)); + strcpy(subj, chopstr(get_subject(mp), 28)); + strcpy(sender, chopstr(get_sender(mp, 0), 12)); + notify_format(player, "[%s] %2d:%-3d %c%-12s %-*s %s", + status_chars(mp), Folder(mp), i[Folder(mp)], + ((*sender != '!') && (Connected(mp->from) && + (!hidden(mp->from) + || Priv_Who(player))) + ? '*' : ' '), sender, 30, subj, + mail_list_time(show_time(mp->time, 0), 1)); + if (SUPPORT_PUEBLO) + notify_noenter(player, tprintf("%c/A%c", TAG_START, TAG_END)); } } } @@ -653,11 +653,11 @@ mail_list_time(const char *the_time, int flag /* 1 for no year */ ) if (!flag) { for (i = 0; i < 3; i++) { if (*p) - p++; + p++; } for (i = 0; i < 5; i++) { if (*p) - *q++ = *p++; + *q++ = *p++; } } *q = '\0'; @@ -683,14 +683,14 @@ do_mail_purge(dbref player) /* Delete this one */ /* head and tail of the list are special */ if (mp == HEAD) - HEAD = mp->next; + HEAD = mp->next; else if (mp == TAIL) - TAIL = mp->prev; + TAIL = mp->prev; /* relink the list */ if (mp->prev != NULL) - mp->prev->next = mp->next; + mp->prev->next = mp->next; if (mp->next != NULL) - mp->next->prev = mp->prev; + mp->next->prev = mp->prev; /* save the pointer */ nextp = mp->next; /* then wipe */ @@ -760,47 +760,47 @@ do_mail_fwd(dbref player, char *msglist, char *tolist) if ((mp->to == player) && (All(ms) || (Folder(mp) == folder))) { i[Folder(mp)]++; if (mail_match(player, mp, ms, i[Folder(mp)])) { - /* forward it to all players listed */ - head = tolist; - while (head && *head) { - current = next_in_list(start); - /* Now locate a target */ - num = atoi(current); - if (num) { - /* reply to a mail message */ - temp = mail_fetch(player, num); - if (!temp) { - notify(player, T("MAIL: You can't reply to nonexistant mail.")); - } else { - char tbuf1[BUFFER_LEN]; - unsigned char tbuf2[BUFFER_LEN]; - strcpy(tbuf1, uncompress(mp->subject)); - u_strcpy(tbuf2, get_compressed_message(mp)); - send_mail(player, temp->from, tbuf1, (char *) tbuf2, - M_FORWARD | M_REPLY, 1, 0); - num_recpts++; - } - } else { - /* forwarding to a player */ - target = - match_result(player, current, TYPE_PLAYER, - MAT_ME | MAT_ABSOLUTE | MAT_PLAYER); - if (!GoodObject(target)) - target = lookup_player(current); - if (!GoodObject(target)) - target = short_page(current); - if (!GoodObject(target) || !IsPlayer(target)) { - notify_format(player, T("No such unique player: %s."), current); - } else { - char tbuf1[BUFFER_LEN]; - unsigned char tbuf2[BUFFER_LEN]; - strcpy(tbuf1, uncompress(mp->subject)); - u_strcpy(tbuf2, get_compressed_message(mp)); - send_mail(player, target, tbuf1, (char *) tbuf2, M_FORWARD, 1, 0); - num_recpts++; - } - } - } + /* forward it to all players listed */ + head = tolist; + while (head && *head) { + current = next_in_list(start); + /* Now locate a target */ + num = atoi(current); + if (num) { + /* reply to a mail message */ + temp = mail_fetch(player, num); + if (!temp) { + notify(player, T("MAIL: You can't reply to nonexistant mail.")); + } else { + char tbuf1[BUFFER_LEN]; + unsigned char tbuf2[BUFFER_LEN]; + strcpy(tbuf1, uncompress(mp->subject)); + u_strcpy(tbuf2, get_compressed_message(mp)); + send_mail(player, temp->from, tbuf1, (char *) tbuf2, + M_FORWARD | M_REPLY, 1, 0); + num_recpts++; + } + } else { + /* forwarding to a player */ + target = + match_result(player, current, TYPE_PLAYER, + MAT_ME | MAT_ABSOLUTE | MAT_PLAYER); + if (!GoodObject(target)) + target = lookup_player(current); + if (!GoodObject(target)) + target = short_page(current); + if (!GoodObject(target) || !IsPlayer(target)) { + notify_format(player, T("No such unique player: %s."), current); + } else { + char tbuf1[BUFFER_LEN]; + unsigned char tbuf2[BUFFER_LEN]; + strcpy(tbuf1, uncompress(mp->subject)); + u_strcpy(tbuf2, get_compressed_message(mp)); + send_mail(player, target, tbuf1, (char *) tbuf2, M_FORWARD, 1, 0); + num_recpts++; + } + } + } } } mp = mp->next; @@ -818,7 +818,7 @@ do_mail_fwd(dbref player, char *msglist, char *tolist) */ void do_mail_send(dbref player, char *tolist, char *message, mail_flag flags, - int silent, int nosig) + int silent, int nosig) { const char *head; int num; @@ -839,7 +839,7 @@ do_mail_send(dbref player, char *tolist, char *message, mail_flag flags, return; } sb = sbuf; - mb = message; /* Save the message pointer */ + mb = message; /* Save the message pointer */ while (*message && (i < SUBJECT_LEN) && *message != SUBJECT_COOKIE) { *sb++ = *message++; i++; @@ -868,29 +868,29 @@ do_mail_send(dbref player, char *tolist, char *message, mail_flag flags, temp = mail_fetch(player, num); if (!temp) { - notify(player, T("MAIL: You can't reply to nonexistent mail.")); - return; + notify(player, T("MAIL: You can't reply to nonexistent mail.")); + return; } if (subject_given) - send_mail(player, temp->from, sbuf, message, mail_flags, silent, nosig); + send_mail(player, temp->from, sbuf, message, mail_flags, silent, nosig); else - send_mail(player, temp->from, uncompress(temp->subject), message, - mail_flags | M_REPLY, silent, nosig); + send_mail(player, temp->from, uncompress(temp->subject), message, + mail_flags | M_REPLY, silent, nosig); } else { /* send a new mail message */ target = - match_result(player, current, TYPE_PLAYER, - MAT_ME | MAT_ABSOLUTE | MAT_PLAYER); + match_result(player, current, TYPE_PLAYER, + MAT_ME | MAT_ABSOLUTE | MAT_PLAYER); if (!GoodObject(target)) - target = lookup_player(current); + target = lookup_player(current); if (!GoodObject(target)) - target = short_page(current); + target = short_page(current); if (!GoodObject(target) || !IsPlayer(target)) { - if (!send_mail_alias - (player, current, sbuf, message, mail_flags, silent, nosig)) - notify_format(player, T("No such unique player: %s."), current); + if (!send_mail_alias + (player, current, sbuf, message, mail_flags, silent, nosig)) + notify_format(player, T("No such unique player: %s."), current); } else - send_mail(player, target, sbuf, message, mail_flags, silent, nosig); + send_mail(player, target, sbuf, message, mail_flags, silent, nosig); } } } @@ -945,11 +945,11 @@ count_mail(dbref player, int folder, int *rcount, int *ucount, int *ccount) mp && (mp->to == player); mp = mp->next) { if ((mp->to == player) && ((folder == -1) || (Folder(mp) == folder))) { if (Cleared(mp)) - cc++; + cc++; else if (Read(mp)) - rc++; + rc++; else - uc++; + uc++; } } *rcount = rc; @@ -960,7 +960,7 @@ count_mail(dbref player, int folder, int *rcount, int *ucount, int *ccount) static void send_mail(dbref player, dbref target, char *subject, char *message, - mail_flag flags, int silent, int nosig) + mail_flag flags, int silent, int nosig) { /* send a message to a target, consulting the target's mailforward. * If mailforward isn't set, just deliver to targt. @@ -984,13 +984,13 @@ send_mail(dbref player, dbref target, char *subject, char *message, fwdstr = trim_space_sep(orig, ' '); while ((curr = split_token(&fwdstr, ' ')) != NULL) { if (is_objid(curr)) { - fwd = parse_objid(curr); - if (GoodObject(fwd) && Can_MailForward(target, fwd)) { - good += - real_send_mail(player, fwd, subject, message, flags, 1, nosig); - } else - notify_format(target, T("Failed attempt to forward @mail to #%d"), - fwd); + fwd = parse_objid(curr); + if (GoodObject(fwd) && Can_MailForward(target, fwd)) { + good += + real_send_mail(player, fwd, subject, message, flags, 1, nosig); + } else + notify_format(target, T("Failed attempt to forward @mail to #%d"), + fwd); } } free((Malloc_t) orig); @@ -1078,11 +1078,11 @@ real_send_mail(dbref player, dbref target, char *subject, char *message, /* Append the MAILSIGNATURE to the mail - Cordin@Dune's idea */ buff = (char *) mush_malloc(BUFFER_LEN, "string"); if (!buff) - mush_panic(T("Failed to allocate string in send_mail")); + mush_panic(T("Failed to allocate string in send_mail")); ms = mailsig = safe_atr_value(a); bp = buff; process_expression(buff, &bp, &ms, player, player, player, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; free(mailsig); safe_str(buff, newmsg, &nm); @@ -1097,7 +1097,7 @@ real_send_mail(dbref player, dbref target, char *subject, char *message, } newp->time = mudtime; - newp->read = flags & M_FMASK; /* Send to folder 0 */ + newp->read = flags & M_FMASK; /* Send to folder 0 */ /* Where do we insert it? After mp, wherever that is. * This can return NULL if there are no messages or @@ -1140,10 +1140,10 @@ real_send_mail(dbref player, dbref target, char *subject, char *message, /* notify people */ if (!silent) notify_format(player, - T("MAIL: You sent your message to %s."), Name(target)); + T("MAIL: You sent your message to %s."), Name(target)); notify_format(target, - T("MAIL: You have a new message (%d) from %s."), - rc + uc + cc + 1, Name(player)); + T("MAIL: You have a new message (%d) from %s."), + rc + uc + cc + 1, Name(player)); /* Check @mailfilter */ filter_mail(player, target, subject, message, rc + uc + cc + 1, flags); @@ -1182,7 +1182,7 @@ do_mail_nuke(dbref player) desc_mail_clear(); do_log(LT_ERR, 0, 0, T("** MAIL PURGE ** done by %s(#%d)."), - Name(player), player); + Name(player), player); notify(player, T("You annihilate the post office. All messages cleared.")); } @@ -1223,51 +1223,51 @@ do_mail_debug(dbref player, const char *action, const char *victim) } else if (string_prefix("sanity", action)) { for (i = 0, mp = HEAD; mp != NULL; i++, mp = mp->next) { if (!GoodObject(mp->to)) - notify_format(player, T("Bad object #%d has mail."), mp->to); + notify_format(player, T("Bad object #%d has mail."), mp->to); else if (!IsPlayer(mp->to)) - notify_format(player, T("%s(#%d) has mail but is not a player."), - Name(mp->to), mp->to); + notify_format(player, T("%s(#%d) has mail but is not a player."), + Name(mp->to), mp->to); } if (i != mdb_top) { notify_format(player, - T - ("Mail database top is %d, actual message count is %d. Fixing."), - mdb_top, i); + T + ("Mail database top is %d, actual message count is %d. Fixing."), + mdb_top, i); mdb_top = i; } notify(player, T("Mail sanity check completed.")); } else if (string_prefix("fix", action)) { for (i = 0, mp = HEAD; mp != NULL; i++, mp = nextp) { if (!GoodObject(mp->to) || !IsPlayer(mp->to)) { - notify_format(player, T("Fixing mail for #%d."), mp->to); - /* Delete this one */ - /* head and tail of the list are special */ - if (mp == HEAD) - HEAD = mp->next; - else if (mp == TAIL) - TAIL = mp->prev; - /* relink the list */ - if (mp->prev != NULL) - mp->prev->next = mp->next; - if (mp->next != NULL) - mp->next->prev = mp->prev; - /* save the pointer */ - nextp = mp->next; - /* then wipe */ - mdb_top--; - if (mp->subject) - free(mp->subject); - chunk_delete(mp->msgid); - mush_free((Malloc_t) mp, "mail"); + notify_format(player, T("Fixing mail for #%d."), mp->to); + /* Delete this one */ + /* head and tail of the list are special */ + if (mp == HEAD) + HEAD = mp->next; + else if (mp == TAIL) + TAIL = mp->prev; + /* relink the list */ + if (mp->prev != NULL) + mp->prev->next = mp->next; + if (mp->next != NULL) + mp->next->prev = mp->prev; + /* save the pointer */ + nextp = mp->next; + /* then wipe */ + mdb_top--; + if (mp->subject) + free(mp->subject); + chunk_delete(mp->msgid); + mush_free((Malloc_t) mp, "mail"); } else if (!GoodObject(mp->from)) { - /* Oops, it's from a player whose dbref is out of range! - * We'll make it appear to be from #0 instead because there's - * no really good choice - */ - mp->from = 0; - nextp = mp->next; + /* Oops, it's from a player whose dbref is out of range! + * We'll make it appear to be from #0 instead because there's + * no really good choice + */ + mp->from = 0; + nextp = mp->next; } else { - nextp = mp->next; + nextp = mp->next; } } notify(player, T("Mail sanity fix completed.")); @@ -1327,52 +1327,52 @@ do_mail_stats(dbref player, char *name, enum mail_stats_type full) if (!payfor(player, FIND_COST)) { notify_format(player, T("Finding mail stats costs %d %s."), FIND_COST, - (FIND_COST == 1) ? MONEY : MONIES); + (FIND_COST == 1) ? MONEY : MONIES); return; } - if (target == AMBIGUOUS) { /* stats for all */ + if (target == AMBIGUOUS) { /* stats for all */ if (full == MSTATS_COUNT) { notify_format(player, - T("There are %d messages in the mail spool."), mdb_top); + T("There are %d messages in the mail spool."), mdb_top); return; } else if (full == MSTATS_READ) { for (mp = HEAD; mp != NULL; mp = mp->next) { - if (Cleared(mp)) - fc++; - else if (Read(mp)) - fr++; - else - fu++; + if (Cleared(mp)) + fc++; + else if (Read(mp)) + fr++; + else + fu++; } notify_format(player, - T - ("MAIL: There are %d msgs in the mail spool, %d unread, %d cleared."), - fc + fr + fu, fu, fc); + T + ("MAIL: There are %d msgs in the mail spool, %d unread, %d cleared."), + fc + fr + fu, fu, fc); return; } else { for (mp = HEAD; mp != NULL; mp = mp->next) { - if (Cleared(mp)) { - fc++; - cchars += strlen(get_message(mp)); - } else if (Read(mp)) { - fr++; - fchars += strlen(get_message(mp)); - } else { - fu++; - tchars += strlen(get_message(mp)); - } + if (Cleared(mp)) { + fc++; + cchars += strlen(get_message(mp)); + } else if (Read(mp)) { + fr++; + fchars += strlen(get_message(mp)); + } else { + fu++; + tchars += strlen(get_message(mp)); + } } notify_format(player, - T - ("MAIL: There are %d old msgs in the mail spool, totalling %d characters."), - fr, fchars); + T + ("MAIL: There are %d old msgs in the mail spool, totalling %d characters."), + fr, fchars); notify_format(player, - T - ("MAIL: There are %d new msgs in the mail spool, totalling %d characters."), - fu, tchars); + T + ("MAIL: There are %d new msgs in the mail spool, totalling %d characters."), + fu, tchars); notify_format(player, - ("MAIL: There are %d cleared msgs in the mail spool, totalling %d characters."), - fc, cchars); + ("MAIL: There are %d cleared msgs in the mail spool, totalling %d characters."), + fc, cchars); return; } } @@ -1382,9 +1382,9 @@ do_mail_stats(dbref player, char *name, enum mail_stats_type full) /* just count number of messages */ for (mp = HEAD; mp != NULL; mp = mp->next) { if (was_sender(target, mp)) - fr++; + fr++; if (mp->to == target) - tr++; + tr++; } notify_format(player, T("%s sent %d messages."), Name(target), fr); notify_format(player, T("%s has %d messages."), Name(target), tr); @@ -1394,25 +1394,25 @@ do_mail_stats(dbref player, char *name, enum mail_stats_type full) for (mp = HEAD; mp != NULL; mp = mp->next) { if (was_sender(target, mp)) { if (Cleared(mp)) - fc++; + fc++; else if (Read(mp)) - fr++; + fr++; else - fu++; + fu++; if (full == MSTATS_SIZE) - fchars += strlen(get_message(mp)); + fchars += strlen(get_message(mp)); } if (mp->to == target) { if (!tr && !tu) - strcpy(last, show_time(mp->time, 0)); + strcpy(last, show_time(mp->time, 0)); if (Cleared(mp)) - tc++; + tc++; else if (Read(mp)) - tr++; + tr++; else - tu++; + tu++; if (full == MSTATS_SIZE) - tchars += strlen(get_message(mp)); + tchars += strlen(get_message(mp)); } } @@ -1420,18 +1420,18 @@ do_mail_stats(dbref player, char *name, enum mail_stats_type full) if (full == MSTATS_READ) { notify_format(player, T("%d messages sent, %d unread, %d cleared."), - fc + fr + fu, fu, fc); + fc + fr + fu, fu, fc); notify_format(player, T("%d messages received, %d unread, %d cleared."), - tc + tr + tu, tu, tc); + tc + tr + tu, tu, tc); } else { notify_format(player, - T - ("%d messages sent, %d unread, %d cleared, totalling %d characters."), - fc + fr + fu, fu, fc, fchars); + T + ("%d messages sent, %d unread, %d cleared, totalling %d characters."), + fc + fr + fu, fu, fc, fchars); notify_format(player, - T - ("%d messages received, %d unread, %d cleared, totalling %d characters."), - tc + tr + tu, tu, tc, tchars); + T + ("%d messages received, %d unread, %d cleared, totalling %d characters."), + tc + tr + tu, tu, tc, tchars); } if (tc + tr + tu > 0) @@ -1490,7 +1490,7 @@ do_mail(dbref player, char *arg1, char *arg2) } else { /* Must be reading or listing mail - no arg2 */ if (((p = strchr(arg1, ':')) && (*(p + 1) == '\0')) - || !(isdigit((unsigned char) *arg1) && !strchr(arg1, '-'))) + || !(isdigit((unsigned char) *arg1) && !strchr(arg1, '-'))) do_mail_list(player, arg1); else do_mail_read(player, arg1); @@ -1537,8 +1537,8 @@ FUNCTION(fun_folderstats) break; case 2: if ((player = - noisy_match_result(executor, args[0], TYPE_PLAYER, - MAT_ME | MAT_ABSOLUTE | MAT_PLAYER)) == NOTHING) { + noisy_match_result(executor, args[0], TYPE_PLAYER, + MAT_ME | MAT_ABSOLUTE | MAT_PLAYER)) == NOTHING) { safe_str(T("#-1 NO SUCH PLAYER"), buff, bp); return; } else if ((executor != player) && !MailAdmin(executor, player)) { @@ -1632,8 +1632,8 @@ mailfun_fetch(dbref player, int nargs, char *arg1, char *arg2) } else { /* Both a target and a message */ if ((target = - noisy_match_result(player, arg1, TYPE_PLAYER, - MAT_ME | MAT_ABSOLUTE | MAT_PLAYER)) == NOTHING) { + noisy_match_result(player, arg1, TYPE_PLAYER, + MAT_ME | MAT_ABSOLUTE | MAT_PLAYER)) == NOTHING) { return NULL; } else if ((player != target) && !MailAdmin(player, target)) { notify(player, T("Permission denied")); @@ -1729,10 +1729,10 @@ FUNCTION(fun_mailstats) if (!payfor(executor, FIND_COST)) { notify_format(executor, T("Finding mail stats costs %d %s."), FIND_COST, - (FIND_COST == 1) ? MONEY : MONIES); + (FIND_COST == 1) ? MONEY : MONIES); return; } - if (target == AMBIGUOUS) { /* stats for all */ + if (target == AMBIGUOUS) { /* stats for all */ if (full == 0) { /* FORMAT * total mail @@ -1741,12 +1741,12 @@ FUNCTION(fun_mailstats) return; } else if (full == 1) { for (mp = HEAD; mp != NULL; mp = mp->next) { - if (Cleared(mp)) - fc++; - else if (Read(mp)) - fr++; - else - fu++; + if (Cleared(mp)) + fc++; + else if (Read(mp)) + fr++; + else + fu++; } /* FORMAT * sent, sent_unread, sent_cleared @@ -1754,16 +1754,16 @@ FUNCTION(fun_mailstats) safe_format(buff, bp, "%d %d %d", fc + fr + fu, fu, fc); } else { for (mp = HEAD; mp != NULL; mp = mp->next) { - if (Cleared(mp)) { - fc++; - cchars += strlen(get_message(mp)); - } else if (Read(mp)) { - fr++; - fchars += strlen(get_message(mp)); - } else { - fu++; - tchars += strlen(get_message(mp)); - } + if (Cleared(mp)) { + fc++; + cchars += strlen(get_message(mp)); + } else if (Read(mp)) { + fr++; + fchars += strlen(get_message(mp)); + } else { + fu++; + tchars += strlen(get_message(mp)); + } } /* FORMAT * sent_read, sent_read_characters, @@ -1771,7 +1771,7 @@ FUNCTION(fun_mailstats) * sent_clear, sent_clear_characters */ safe_format(buff, bp, "%d %d %d %d %d %d", - fr, fchars, fu, tchars, fc, cchars); + fr, fchars, fu, tchars, fc, cchars); return; } } @@ -1782,9 +1782,9 @@ FUNCTION(fun_mailstats) /* just count number of messages */ for (mp = HEAD; mp != NULL; mp = mp->next) { if (was_sender(target, mp)) - fr++; + fr++; if (mp->to == target) - tr++; + tr++; } /* FORMAT * sent, received @@ -1796,25 +1796,25 @@ FUNCTION(fun_mailstats) for (mp = HEAD; mp != NULL; mp = mp->next) { if (was_sender(target, mp)) { if (Cleared(mp)) - fc++; + fc++; else if (Read(mp)) - fr++; + fr++; else - fu++; + fu++; if (full == 2) - fchars += strlen(get_message(mp)); + fchars += strlen(get_message(mp)); } if (mp->to == target) { if (!tr && !tu) - strcpy(last, show_time(mp->time, 0)); + strcpy(last, show_time(mp->time, 0)); if (Cleared(mp)) - tc++; + tc++; else if (Read(mp)) - tr++; + tr++; else - tu++; + tu++; if (full == 2) - tchars += strlen(get_message(mp)); + tchars += strlen(get_message(mp)); } } @@ -1824,14 +1824,14 @@ FUNCTION(fun_mailstats) * received, rec_unread, rec_cleared */ safe_format(buff, bp, "%d %d %d %d %d %d", - fc + fr + fu, fu, fc, tc + tr + tu, tu, tc); + fc + fr + fu, fu, fc, tc + tr + tu, tu, tc); } else { /* FORMAT * sent, sent_unread, sent_cleared, sent_bytes * received, rec_unread, rec_cleared, rec_bytes */ safe_format(buff, bp, "%d %d %d %d %d %d %d %d", - fc + fr + fu, fu, fc, fchars, tc + tr + tu, tu, tc, tchars); + fc + fr + fu, fu, fc, fchars, tc + tr + tu, tu, tc, tchars); } } @@ -1917,8 +1917,8 @@ dump_mail(FILE * fp) if (count != mdb_top) { do_log(LT_ERR, 0, 0, T("MAIL: Count of messages is %d, mdb_top is %d."), - count, mdb_top); - mdb_top = count; /* Doesn't help if we forked, but oh well */ + count, mdb_top); + mdb_top = count; /* Doesn't help if we forked, but oh well */ } return (count); } @@ -1945,7 +1945,7 @@ find_exact_starting_point(dbref player) * has mail - we have to scan the maildb. */ if (HEAD->to > player) - return NULL; /* No mail chain */ + return NULL; /* No mail chain */ for (mp = HEAD; mp && (mp->to < player); mp = mp->next) ; } else { while (mp && (mp->to >= player)) @@ -1979,7 +1979,7 @@ find_insertion_point(dbref player) * has mail - we have to scan the maildb. */ if (HEAD->to > player) - return NULL; /* No mail chain */ + return NULL; /* No mail chain */ for (mp = TAIL; mp && (mp->to > player); mp = mp->prev) ; } else { while (mp && (mp->to <= player)) @@ -2122,24 +2122,24 @@ load_mail(FILE * fp) /* Search for where to put it */ mp->prev = NULL; for (done = 0, tmpmp = HEAD; tmpmp && !done; tmpmp = tmpmp->next) { - if (tmpmp->to > mp->to) { - /* Insert before tmpmp */ - mp->next = tmpmp; - mp->prev = tmpmp->prev; - if (tmpmp->prev) { - /* tmpmp isn't HEAD */ - tmpmp->prev->next = mp; - } else { - /* tmpmp is HEAD */ - HEAD = mp; - } - tmpmp->prev = mp; - done = 1; - } + if (tmpmp->to > mp->to) { + /* Insert before tmpmp */ + mp->next = tmpmp; + mp->prev = tmpmp->prev; + if (tmpmp->prev) { + /* tmpmp isn't HEAD */ + tmpmp->prev->next = mp; + } else { + /* tmpmp is HEAD */ + HEAD = mp; + } + tmpmp->prev = mp; + done = 1; + } } if (!done) { - /* This is bad */ - do_rawlog(LT_ERR, T("MAIL: bad code.")); + /* This is bad */ + do_rawlog(LT_ERR, T("MAIL: bad code.")); } } } @@ -2260,7 +2260,7 @@ add_folder_name(dbref player, int fld, const char *name) while (!isspace((unsigned char) *r)) r++; *r = '\0'; - res = replace_string(old, new, tbuf); /* mallocs mem! */ + res = replace_string(old, new, tbuf); /* mallocs mem! */ } else { r = res = (char *) mush_malloc(BUFFER_LEN + 1, "replace_string.buff"); if (a) @@ -2392,7 +2392,7 @@ parse_msglist(const char *msglist, struct mail_selector *ms, dbref player) p++; if (!p || !*p) { ms->flags |= M_FOLDER; - return 1; /* all messages in current folder */ + return 1; /* all messages in current folder */ } if (isdigit((unsigned char) *p) || *p == '-') { if (!parse_message_spec(player, p, &ms->low, &ms->high, &folder)) { @@ -2550,9 +2550,9 @@ status_string(MAIL *mp) void check_mail(dbref player, int folder, int silent) { - int rc; /* read messages */ - int uc; /* unread messages */ - int cc; /* cleared messages */ + int rc; /* read messages */ + int uc; /* unread messages */ + int cc; /* cleared messages */ int total; /* just count messages */ @@ -2560,14 +2560,14 @@ check_mail(dbref player, int folder, int silent) total = rc + uc + cc; if (total > 0) notify_format(player, - T - ("MAIL: %d messages in folder %d [%s] (%d unread, %d cleared)."), - total, folder, get_folder_name(player, folder), uc, cc); + T + ("MAIL: %d messages in folder %d [%s] (%d unread, %d cleared)."), + total, folder, get_folder_name(player, folder), uc, cc); else if (!silent) notify(player, T("\nMAIL: You have no mail.\n")); if ((folder == 0) && (total + 5 > MAIL_LIMIT)) notify_format(player, T("MAIL: Warning! Limit on inbox messages is %d!"), - MAIL_LIMIT); + MAIL_LIMIT); return; } @@ -2591,7 +2591,7 @@ sign(int x) */ static int parse_message_spec(dbref player, const char *s, int *msglow, int *msghigh, - int *folder) + int *folder) { char buf[BUFFER_LEN]; char *p, *q; @@ -2607,42 +2607,42 @@ parse_message_spec(dbref player, const char *s, int *msglow, int *msghigh, /* f:low-high */ *q++ = '\0'; if (!*p) - *msglow = 0; + *msglow = 0; else if (!is_integer(p)) - return 0; + return 0; else { - *msglow = parse_integer(p); - if (*msglow == 0) - *msglow = -1; + *msglow = parse_integer(p); + if (*msglow == 0) + *msglow = -1; } if (!*q) - *msghigh = 0; + *msghigh = 0; else if (!is_integer(q)) - return 0; + return 0; else { - *msghigh = parse_integer(q); - if (*msghigh == 0) - *msghigh = -1; + *msghigh = parse_integer(q); + if (*msghigh == 0) + *msghigh = -1; } } else { /* f:m */ if (!*p) { - /* f: */ - *msglow = 0; - if (msghigh) - *msghigh = HUGE_INT; + /* f: */ + *msglow = 0; + if (msghigh) + *msghigh = HUGE_INT; } else { - if (!is_integer(p)) - return 0; - *msglow = parse_integer(p); - if (*msglow == 0) - *msglow = -1; - if (msghigh) - *msghigh = *msglow; + if (!is_integer(p)) + return 0; + *msglow = parse_integer(p); + if (*msglow == 0) + *msglow = -1; + if (msghigh) + *msghigh = *msglow; } } if (*msglow < 0 || (msghigh && *msghigh < 0) || *folder < 0 - || *folder > MAX_FOLDERS) + || *folder > MAX_FOLDERS) return 0; } else { /* No folder spec */ @@ -2651,32 +2651,32 @@ parse_message_spec(dbref player, const char *s, int *msglow, int *msghigh, /* low-high */ *q++ = '\0'; if (!*buf) - *msglow = 0; + *msglow = 0; else if (!is_integer(buf)) - return 0; + return 0; else { - *msglow = parse_integer(buf); - if (*msglow == 0) - *msglow = -1; + *msglow = parse_integer(buf); + if (*msglow == 0) + *msglow = -1; } if (!*q) - *msghigh = 0; + *msghigh = 0; else if (!is_integer(q)) - return 0; + return 0; else { - *msghigh = parse_integer(q); - if (*msghigh == 0) - *msghigh = -1; + *msghigh = parse_integer(q); + if (*msghigh == 0) + *msghigh = -1; } } else { /* m */ if (!is_integer(buf)) - return 0; + return 0; *msglow = parse_integer(buf); if (*msglow == 0) - *msglow = -1; + *msglow = -1; if (msghigh) - *msghigh = *msglow; + *msghigh = *msglow; } if (*msglow < 0 || (msghigh && *msghigh < 0)) return 0; @@ -2686,7 +2686,7 @@ parse_message_spec(dbref player, const char *s, int *msglow, int *msghigh, static int send_mail_alias(dbref player, char *aname, char *subject, char *message, - mail_flag flags, int silent, int nosig) + mail_flag flags, int silent, int nosig) { struct mail_alias *m; int i; @@ -2729,7 +2729,7 @@ send_mail_alias(dbref player, char *aname, char *subject, char *message, */ void filter_mail(dbref from, dbref player, char *subject, - char *message, int mailnumber, mail_flag flags) + char *message, int mailnumber, mail_flag flags) { ATTR *f; char buff[BUFFER_LEN], *bp, *asave; diff --git a/src/filecopy.c b/src/filecopy.c index 29182dc..dfcc5ad 100644 --- a/src/filecopy.c +++ b/src/filecopy.c @@ -21,7 +21,7 @@ #include "log.h" #include "confmagic.h" -extern char confname[BUFFER_LEN]; /* From bsd.c */ +extern char confname[BUFFER_LEN]; /* From bsd.c */ /* This is bad, but only for WIN32, which is bad anyway... */ #define EMBEDDED_MKINDX diff --git a/src/flags.c b/src/flags.c index 68f1ad0..e0e98ff 100644 --- a/src/flags.c +++ b/src/flags.c @@ -141,6 +141,7 @@ FLAG flag_table[] = { {"CLOUDY", 'x', TYPE_EXIT, EXIT_CLOUDY, F_ANY, F_ANY}, {"GOING_TWICE", '\0', NOTYPE, GOING_TWICE, F_INTERNAL | F_DARK, F_INTERNAL | F_DARK}, + {"KEEPALIVE", 'k', TYPE_PLAYER, 0, F_ANY, F_ANY}, {NULL, '\0', 0, 0, 0, 0} }; @@ -300,10 +301,20 @@ new_flag(void) static void clear_all_flags(FLAGSPACE * n) { + FLAG *f; + + for (f = ptab_firstentry(n->tab); f; f = ptab_nextentry(n->tab)) { + f->perms = DECR_FLAG_REF(f->perms); + if (FLAG_REF(f->perms) == 0) { + mush_free((void *) f->name, "flag.name"); + mush_free(f, "flag"); + } + } + ptab_free(n->tab); /* Finally, the flags array */ if (n->flags) - free(n->flags); + mush_free(n->flags, "flagspace.flags"); n->flags = NULL; n->flagbits = 0; } @@ -334,9 +345,16 @@ flag_add(FLAGSPACE * n, const char *name, FLAG *f) * We could improve this algorithm to use the next available * slot after deletions, too, but this will do for now. */ + + /* Can't have more than 255 references to the same flag */ + if (FLAG_REF(f->perms) == 0xFFU) + return; + if (f->bitpos < 0) f->bitpos = n->flagbits; + f->perms = INCR_FLAG_REF(f->perms); + /* Insert the flag in the ptab by the given name (maybe an alias) */ ptab_start_inserts(n->tab); ptab_insert(n->tab, name, f); @@ -355,16 +373,15 @@ flag_add(FLAGSPACE * n, const char *name, FLAG *f) if (f->bitpos >= n->flagbits) { /* Oops, we need a bigger array */ if (n->flagbits == 0) - n->flags = (FLAG **) malloc(sizeof(FLAG *)); + n->flags = mush_malloc(sizeof(FLAG *), "flagspace.flags"); else { - n->flags = - (FLAG **) realloc(n->flags, (f->bitpos + 1) * sizeof(FLAG *)); - if (!n->flags) - mush_panic("Unable to reallocate flags array!\n"); + n->flags = realloc(n->flags, (f->bitpos + 1) * sizeof(FLAG *)); + if (!n->flags) + mush_panic("Unable to reallocate flags array!\n"); } /* Make sure the new space is full of NULLs */ for (i = n->flagbits; i <= f->bitpos; i++) - n->flags[i] = NULL; + n->flags[i] = NULL; } /* Put the canonical flag in the flags array */ n->flags[f->bitpos] = f; @@ -406,7 +423,7 @@ flag_read_oldstyle(FILE * in) c = mush_strdup(getstring_noalloc(in), "flag name"); if (!strcmp(c, "FLAG ALIASES")) { mush_free(c, "flag name"); - return NULL; /* We're done */ + return NULL; /* We're done */ } f = new_flag(); f->name = c; @@ -506,7 +523,7 @@ flag_read(FILE * in) f->type = ALLTYPES; } db_read_this_labeled_string(in, "perms", &tmp); - f->perms = string_to_privs(flag_privs, tmp, 0); + f->perms = F_REF_NOT & string_to_privs(flag_privs, tmp, 0); db_read_this_labeled_string(in, "negate_perms", &tmp); f->negate_perms = string_to_privs(flag_privs, tmp, 0); return f; @@ -649,7 +666,7 @@ flag_write(FILE * out, FLAG *f, const char *name) db_write_labeled_string(out, " letter", tprintf("%c", f->letter)); db_write_labeled_string(out, " type", f->type == ALLTYPES ? "ANY" :privs_to_string(type_privs, f->type)); db_write_labeled_string(out, " perms", - privs_to_string(flag_privs, f->perms)); + privs_to_string(flag_privs, F_REF_NOT & f->perms)); db_write_labeled_string(out, " negate_perms", privs_to_string(flag_privs, f->negate_perms)); } @@ -763,7 +780,7 @@ init_flag_table(const char *ns) flag_add(n, a->alias, f); else do_rawlog(LT_ERR, - T("FLAG INIT: flag alias %s matches no known flag."), a->alias); + T("FLAG INIT: flag alias %s matches no known flag."), a->alias); } flag_add_additional(); @@ -787,6 +804,7 @@ flag_add_additional(void) F_PRIVILEGE | F_SELF); add_flag("ZCLONE_OK", '\0', TYPE_THING, F_PRIVILEGE, F_PRIVILEGE); add_flag("WEIRDSITE", '\0', TYPE_PLAYER, F_GOD | F_DARK, F_GOD | F_DARK); + add_flag("KEEPALIVE", 'k', TYPE_PLAYER, F_ANY, F_ANY); add_flag("MISTRUST", 'm', TYPE_THING | TYPE_EXIT | TYPE_ROOM, F_PRIVILEGE, F_PRIVILEGE); add_flag("ORPHAN", 'i', NOTYPE, F_ANY, F_ANY); @@ -1114,7 +1132,7 @@ has_any_bits(const char *ns, object_flag_type source, object_flag_type bitmask) */ const char * bits_to_string(const char *ns, object_flag_type bitmask, dbref privs, - dbref thing) + dbref thing) { FLAG *f; FLAGSPACE *n; @@ -1128,11 +1146,11 @@ bits_to_string(const char *ns, object_flag_type bitmask, dbref privs, for (i = 0; i < n->flagbits; i++) { if ((f = n->flags[i])) { if (has_bit(bitmask, f->bitpos) && - (!GoodObject(thing) || Can_See_Flag(privs, thing, f))) { - if (!first) - safe_chr(' ', buf, &bp); - safe_str(f->name, buf, &bp); - first = 0; + (!GoodObject(thing) || Can_See_Flag(privs, thing, f))) { + if (!first) + safe_chr(' ', buf, &bp); + safe_str(f->name, buf, &bp); + first = 0; } } } @@ -1161,7 +1179,7 @@ string_to_bits(const char *ns, const char *str) return bitmask; } if (!str) - return bitmask; /* We're done, then */ + return bitmask; /* We're done, then */ copy = mush_strdup(str, "flagstring"); s = trim_space_sep(copy, ' '); while (s) { @@ -1409,7 +1427,7 @@ twiddle_flag_internal(const char *ns, dbref thing, const char *flag, int negate) */ void set_flag(dbref player, dbref thing, const char *flag, int negate, - int hear, int listener) + int hear, int listener) { FLAG *f; char tbuf1[BUFFER_LEN]; @@ -1610,13 +1628,13 @@ set_flag(dbref player, dbref thing, const char *flag, int negate, /* notify the area if something stops listening, but only if it wasn't listening before */ if (!IsPlayer(thing) && (hear || listener) && - !Hearer(thing) && !Listener(thing)) { + !Hearer(thing) && !Listener(thing)) { tp = tbuf1; safe_format(tbuf1, &tp, T("%s is no longer listening."), Name(thing)); *tp = '\0'; if (GoodObject(Location(thing))) - notify_except(Contents(Location(thing)), NOTHING, tbuf1, - NA_INTER_PRESENCE); + notify_except(Contents(Location(thing)), NOTHING, tbuf1, + NA_INTER_PRESENCE); notify_except(Contents(thing), NOTHING, tbuf1, 0); } if (IsRoom(thing) && is_flag(f, "MONITOR") && !hear && !Listener(thing)) { @@ -1628,25 +1646,25 @@ set_flag(dbref player, dbref thing, const char *flag, int negate, if (is_flag(f, "AUDIBLE")) { switch (Typeof(thing)) { case TYPE_EXIT: - if (Audible(Source(thing))) { - tp = tbuf1; - safe_format(tbuf1, &tp, T("Exit %s is no longer broadcasting."), - Name(thing)); - *tp = '\0'; - notify_except(Contents(Source(thing)), NOTHING, tbuf1, 0); - } - break; + if (Audible(Source(thing))) { + tp = tbuf1; + safe_format(tbuf1, &tp, T("Exit %s is no longer broadcasting."), + Name(thing)); + *tp = '\0'; + notify_except(Contents(Source(thing)), NOTHING, tbuf1, 0); + } + break; case TYPE_ROOM: - notify_except(Contents(thing), NOTHING, - T("Audible exits in this room have been deactivated."), - 0); - break; + notify_except(Contents(thing), NOTHING, + T("Audible exits in this room have been deactivated."), + 0); + break; case TYPE_THING: case TYPE_PLAYER: - notify_except(Contents(thing), thing, - T("This room is no longer broadcasting."), 0); - notify(thing, T("Your contents can no longer be heard from outside.")); - break; + notify_except(Contents(thing), thing, + T("This room is no longer broadcasting."), 0); + notify(thing, T("Your contents can no longer be heard from outside.")); + break; } } if (is_flag(f, "QUIET") || (!AreQuiet(player, thing))) { @@ -1682,13 +1700,13 @@ set_flag(dbref player, dbref thing, const char *flag, int negate, hide_player(thing, 1); /* notify area if something starts listening */ if (!IsPlayer(thing) && - (is_flag(f, "PUPPET") || is_flag(f, "MONITOR")) && !hear && !listener) { + (is_flag(f, "PUPPET") || is_flag(f, "MONITOR")) && !hear && !listener) { tp = tbuf1; safe_format(tbuf1, &tp, T("%s is now listening."), Name(thing)); *tp = '\0'; if (GoodObject(Location(thing))) - notify_except(Contents(Location(thing)), NOTHING, tbuf1, - NA_INTER_PRESENCE); + notify_except(Contents(Location(thing)), NOTHING, tbuf1, + NA_INTER_PRESENCE); notify_except(Contents(thing), NOTHING, tbuf1, 0); } if (IsRoom(thing) && is_flag(f, "MONITOR") && !hear && !listener) { @@ -1701,24 +1719,24 @@ set_flag(dbref player, dbref thing, const char *flag, int negate, if (is_flag(f, "AUDIBLE")) { switch (Typeof(thing)) { case TYPE_EXIT: - if (Audible(Source(thing))) { - tp = tbuf1; - safe_format(tbuf1, &tp, T("Exit %s is now broadcasting."), - Name(thing)); - *tp = '\0'; - notify_except(Contents(Source(thing)), NOTHING, tbuf1, 0); - } - break; + if (Audible(Source(thing))) { + tp = tbuf1; + safe_format(tbuf1, &tp, T("Exit %s is now broadcasting."), + Name(thing)); + *tp = '\0'; + notify_except(Contents(Source(thing)), NOTHING, tbuf1, 0); + } + break; case TYPE_ROOM: - notify_except(Contents(thing), NOTHING, - T("Audible exits in this room have been activated."), 0); - break; + notify_except(Contents(thing), NOTHING, + T("Audible exits in this room have been activated."), 0); + break; case TYPE_PLAYER: case TYPE_THING: - notify_except(Contents(thing), thing, - T("This room is now broadcasting."), 0); - notify(thing, T("Your contents can now be heard from outside.")); - break; + notify_except(Contents(thing), thing, + T("This room is now broadcasting."), 0); + notify(thing, T("Your contents can now be heard from outside.")); + break; } } if (is_flag(f, "QUIET") || (!AreQuiet(player, thing))) { @@ -1748,7 +1766,7 @@ set_flag(dbref player, dbref thing, const char *flag, int negate, */ int flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, - int type) + int type) { char *s; FLAG *fp; @@ -1771,52 +1789,60 @@ flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, negate = 1; s++; } else { - negate = 0; /* It's important to clear this at appropriate times; - * else !Dc means (!D && !c), instead of (!D && c). */ + negate = 0; /* It's important to clear this at appropriate times; + * else !Dc means (!D && !c), instead of (!D && c). */ } if (!*s) /* We got a '!' that wasn't followed by a letter. * Fail the check. */ return (type == 1) ? 0 : ret; /* Find the flag. */ - if ((fp = letter_to_flagptr(n, *s, Typeof(it))) == NULL) { - /* Maybe *s is a type specifier (P, T, E, R). These aren't really - * flags, but we grandfather them in to preserve old code - */ - if ((*s == 'T') || (*s == 'R') || (*s == 'E') || (*s == 'P')) { - temp = (*s == 'T') ? (Typeof(it) == TYPE_THING) : - ((*s == 'R') ? (Typeof(it) == TYPE_ROOM) : - ((*s == 'E') ? (Typeof(it) == TYPE_EXIT) : - (Typeof(it) == TYPE_PLAYER))); - if ((type == 1) && ((negate && temp) || (!negate && !temp))) - return 0; - else if ((type == 0) && ((!negate && temp) || (negate && !temp))) - ret |= 1; + fp = letter_to_flagptr(n, *s, Typeof(it)); + if (!fp) { + if (n->tab == &ptab_flag) { + /* Maybe *s is a type specifier (P, T, E, R). These aren't really + * flags, but we grandfather them in to preserve old code + */ + if ((*s == 'T') || (*s == 'R') || (*s == 'E') || (*s == 'P')) { + temp = (*s == 'T') ? (Typeof(it) == TYPE_THING) : + ((*s == 'R') ? (Typeof(it) == TYPE_ROOM) : + ((*s == 'E') ? (Typeof(it) == TYPE_EXIT) : + (Typeof(it) == TYPE_PLAYER))); + if ((type == 1) && ((negate && temp) || (!negate && !temp))) + return 0; + else if ((type == 0) && ((!negate && temp) || (negate && !temp))) + ret |= 1; + } else { + /* Either we got a '!' that wasn't followed by a letter, or + * we couldn't find that flag. For AND, since we've failed + * a check, we can return false. Otherwise we just go on. + */ + if (type == 1) + return 0; + else + continue; + } } else { - /* Either we got a '!' that wasn't followed by a letter, or - * we couldn't find that flag. For AND, since we've failed - * a check, we can return false. Otherwise we just go on. - */ - if (type == 1) - return 0; - else - continue; + if (type == 1) + return 0; + else + continue; } } else { /* does the object have this flag? */ temp = (has_flag(it, fp) && Can_See_Flag(player, it, fp)); if ((type == 1) && ((negate && temp) || (!negate && !temp))) { - /* Too bad there's no NXOR function... - * At this point we've either got a flag and we don't want - * it, or we don't have a flag and we want it. Since it's - * AND, we return false. - */ - return 0; + /* Too bad there's no NXOR function... + * At this point we've either got a flag and we don't want + * it, or we don't have a flag and we want it. Since it's + * AND, we return false. + */ + return 0; } else if ((type == 0) && ((!negate && temp) || (negate && !temp))) { - /* We've found something we want, in an OR. We OR a - * true with the current value. - */ - ret |= 1; + /* We've found something we want, in an OR. We OR a + * true with the current value. + */ + ret |= 1; } /* Otherwise, we don't need to do anything. */ } @@ -1824,6 +1850,7 @@ flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, return ret; } + /** Check if an object has one or all of a list of flag names. * This function is used by orlflags and andlflags to check to see * if an object has one or all of the flags signified by a list @@ -1838,7 +1865,7 @@ flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, */ int flaglist_check_long(const char *ns, dbref player, dbref it, const char *fstr, - int type) + int type) { char *s, *copy, *sp; FLAG *fp; @@ -1863,14 +1890,14 @@ flaglist_check_long(const char *ns, dbref player, dbref it, const char *fstr, negate = 1; s++; } else { - negate = 0; /* It's important to clear this at appropriate times; - * else !D c means (!D && !c), instead of (!D && c). */ + negate = 0; /* It's important to clear this at appropriate times; + * else !D c means (!D && !c), instead of (!D && c). */ } if (!*s) { /* We got a '!' that wasn't followed by a string. * Fail the check. */ if (type == 1) - ret = 0; + ret = 0; break; } /* Find the flag. */ @@ -1880,10 +1907,10 @@ flaglist_check_long(const char *ns, dbref player, dbref it, const char *fstr, * a check, we can return false. Otherwise we just go on. */ if (type == 1) { - ret = 0; - break; + ret = 0; + break; } else - continue; + continue; } else { /* does the object have this flag? There's a special case * here, as we want (for consistency with flaglist_check) @@ -2031,7 +2058,7 @@ do_flag_info(const char *ns, dbref player, const char *name) notify_format(player, " Type(s): %s", f->type == ALLTYPES ? "ANY" : privs_to_string(type_privs, f->type)); notify_format(player, " Perms: %s", privs_to_string(flag_privs, f->perms)); notify_format(player, "ResetPrms: %s", - privs_to_string(flag_privs, f->negate_perms)); + privs_to_string(flag_privs, f->negate_perms)); } /** Change the permissions on a flag. @@ -2082,8 +2109,8 @@ do_flag_restrict(dbref player, const char *name, char *args_right[]) } else { negate_perms = string_to_privs(flag_privs, args_right[2], 0); if ((!negate_perms) || (negate_perms & (F_INTERNAL | F_DISABLED))) { - notify(player, T("I don't understand those permissions.")); - return; + notify(player, T("I don't understand those permissions.")); + return; } } } else { @@ -2128,7 +2155,7 @@ do_flag_type(const char *ns, dbref player, const char *name, char *type_string) } if (!type_string || !*type_string) { notify_format(player, T("What type do you want to make that %s?"), - strlower(ns)); + strlower(ns)); return; } if (!strcasecmp(type_string, "any")) { @@ -2349,13 +2376,18 @@ alias_flag_generic(const char *ns, const char *name, const char *alias) f = match_flag_ns(n, name); if (!f) { - return 0; /* no such flag 'name' */ + return 0; /* no such flag 'name' */ } if (ptab_find_exact(n->tab, strupper(alias))) { - return 0; /* a flag called 'alias' already exists */ + return 0; /* a flag called 'alias' already exists */ } + if (FLAG_REF(f->perms) == 0xFFU) + return 0; /* Too many copies already */ + + f->perms = INCR_FLAG_REF(f->perms); + ptab_start_inserts(n->tab); ptab_insert(n->tab, strupper(alias), f); ptab_end_inserts(n->tab); @@ -2481,10 +2513,10 @@ do_flag_delete(dbref player, const char *name) tmpf = ptab_firstentry_new(n->tab, flagname); while (tmpf) { if (!strcmp(tmpf->name, f->name) && - strcmp(n->flags[f->bitpos]->name, flagname)) { - ptab_delete(n->tab, flagname); - got_one = 1; - break; + strcmp(n->flags[f->bitpos]->name, flagname)) { + ptab_delete(n->tab, flagname); + got_one = 1; + break; } tmpf = ptab_nextentry_new(n->tab, flagname); } @@ -2545,10 +2577,10 @@ list_aliases(FLAGSPACE * n, FLAG *given) f = ptab_firstentry_new(n->tab, flagname); while (f) { if (!strcmp(given->name, f->name) && - strcmp(n->flags[f->bitpos]->name, flagname)) { + strcmp(n->flags[f->bitpos]->name, flagname)) { /* This is an alias! */ if (!first) - safe_chr(' ', buf, &bp); + safe_chr(' ', buf, &bp); first = 0; safe_str(flagname, buf, &bp); } @@ -2584,7 +2616,7 @@ list_all_flags(const char *ns, const char *name, dbref privs, int which) for (i = 0; i < n->flagbits; i++) { if ((f = n->flags[i]) && !(f->perms & disallowed)) { if (!name || !*name || quick_wild(name, f->name)) - ptrs[numptrs++] = (char *) f->name; + ptrs[numptrs++] = (char *) f->name; } } do_gensort(privs, ptrs, NULL, numptrs, ALPHANUM_LIST); @@ -2593,25 +2625,25 @@ list_all_flags(const char *ns, const char *name, dbref privs, int which) switch (which) { case 0x3: if (i) - safe_strl(", ", 2, buf, &bp); + safe_strl(", ", 2, buf, &bp); safe_str(ptrs[i], buf, &bp); f = match_flag_ns(n, ptrs[i]); if (!f) - break; + break; if (f->letter != '\0') - safe_format(buf, &bp, " (%c)", f->letter); + safe_format(buf, &bp, " (%c)", f->letter); if (f->perms & F_DISABLED) - safe_str(T(" (disabled)"), buf, &bp); + safe_str(T(" (disabled)"), buf, &bp); break; case 0x2: if (i) - safe_chr(' ', buf, &bp); + safe_chr(' ', buf, &bp); safe_str(ptrs[i], buf, &bp); break; case 0x1: f = match_flag_ns(n, ptrs[i]); if (f && (f->letter != '\0')) - safe_chr(f->letter, buf, &bp); + safe_chr(f->letter, buf, &bp); break; } } diff --git a/src/funcrypt.c b/src/funcrypt.c index f3e5d70..348d828 100644 --- a/src/funcrypt.c +++ b/src/funcrypt.c @@ -55,8 +55,8 @@ crunch_code(char *code) while (*in) { while (*in == ESC_CHAR) { while (*in && *in != 'm') - in++; - in++; /* skip 'm' */ + in++; + in++; /* skip 'm' */ } if ((*in >= 32) && (*in <= 126)) { *out++ = *in; diff --git a/src/function.c b/src/function.c index 331bc1d..338402d 100644 --- a/src/function.c +++ b/src/function.c @@ -33,7 +33,7 @@ extern void local_functions(void); static int apply_restrictions(unsigned int result, const char *restriction); USERFN_ENTRY *userfn_tab; /**< Table of user-defined functions */ -HASHTAB htab_function; /**< Function hash table */ +HASHTAB htab_function; /**< Function hash table */ HASHTAB htab_user_function; /**< User-defined function hash table */ /* -------------------------------------------------------------------------* @@ -126,7 +126,7 @@ load_global_regs(char *preserve[]) */ void save_global_env(const char *funcname __attribute__ ((__unused__)), - char *preserve[]) + char *preserve[]) { int i; for (i = 0; i < 10; i++) @@ -139,7 +139,7 @@ save_global_env(const char *funcname __attribute__ ((__unused__)), */ void restore_global_env(const char *funcname __attribute__ ((__unused__)), - char *preserve[]) + char *preserve[]) { int i; for (i = 0; i < 10; i++) @@ -158,7 +158,7 @@ restore_global_env(const char *funcname __attribute__ ((__unused__)), */ void save_global_nxt(const char *funcname, char *preservew[], char *preserver[], - char *valw[], char *valr[]) + char *valw[], char *valr[]) { int i; for (i = 0; i < NUMQ; i++) { @@ -229,7 +229,7 @@ restore_global_nxt(const char *funcname, char *preservew[], char *preserver[], */ int delim_check(char *buff, char **bp, int nfargs, char *fargs[], int sep_arg, - char *sep) + char *sep) { /* Find a delimiter. */ @@ -255,11 +255,11 @@ delim_check(char *buff, char **bp, int nfargs, char *fargs[], int sep_arg, * This structure represents a function's entry in the function table. */ typedef struct fun_tab { - const char *name; /**< Name of the function, uppercase. */ - function_func fun; /**< Pointer to code to call for this function. */ - int minargs; /**< Minimum args required. */ - int maxargs; /**< Maximum args, or INT_MAX. If <0, last arg may have commas */ - int flags; /**< Flags to control how the function is parsed. */ + const char *name; /**< Name of the function, uppercase. */ + function_func fun; /**< Pointer to code to call for this function. */ + int minargs; /**< Minimum args required. */ + int maxargs; /**< Maximum args, or INT_MAX. If <0, last arg may have commas */ + int flags; /**< Flags to control how the function is parsed. */ } FUNTAB; @@ -864,7 +864,7 @@ function_init_postconfig(void) { userfn_tab = (USERFN_ENTRY *) mush_malloc(MAX_GLOBAL_FNS * sizeof(USERFN_ENTRY), - "userfn_tab"); + "userfn_tab"); } /** Check permissions to run a function. @@ -925,7 +925,7 @@ alias_function(const char *function, const char *alias) return 0; function_add(strdup(strupper(alias)), fp->where.fun, - fp->minargs, fp->maxargs, fp->flags); + fp->minargs, fp->maxargs, fp->flags); return 1; } @@ -938,7 +938,7 @@ alias_function(const char *function, const char *alias) */ void function_add(const char *name, function_func fun, int minargs, int maxargs, - int ftype) + int ftype) { FUN *fp; fp = (FUN *) mush_malloc(sizeof(FUN), "function"); @@ -971,7 +971,7 @@ strip_braces(const char *str) buff = (char *) mush_malloc(BUFFER_LEN, "strip_braces.buff"); bufc = buff; - while (isspace((unsigned char) *str)) /* eat spaces at the beginning */ + while (isspace((unsigned char) *str)) /* eat spaces at the beginning */ str++; switch (*str) { @@ -980,7 +980,7 @@ strip_braces(const char *str) process_expression(buff, &bufc, &str, 0, 0, 0, PE_NOTHING, PT_BRACE, NULL); *bufc = '\0'; return buff; - break; /* NOT REACHED */ + break; /* NOT REACHED */ default: strcpy(buff, str); return buff; @@ -1159,19 +1159,19 @@ do_function(dbref player, char *name, char *argv[], int preserve) */ notify(player, T("Function Name Dbref # Attrib")); for (fp = (FUN *) hash_firstentry(&htab_user_function); - fp; fp = (FUN *) hash_nextentry(&htab_user_function)) { - notify_format(player, - "%-32s %6d %s", fp->name, - userfn_tab[fp->where.offset].thing, - userfn_tab[fp->where.offset].name); + fp; fp = (FUN *) hash_nextentry(&htab_user_function)) { + notify_format(player, + "%-32s %6d %s", fp->name, + userfn_tab[fp->where.offset].thing, + userfn_tab[fp->where.offset].name); } } else { /* just print out the list of available functions */ safe_str(T("User functions:"), tbuf1, &bp); for (fp = (FUN *) hash_firstentry(&htab_user_function); - fp; fp = (FUN *) hash_nextentry(&htab_user_function)) { - safe_chr(' ', tbuf1, &bp); - safe_str(fp->name, tbuf1, &bp); + fp; fp = (FUN *) hash_nextentry(&htab_user_function)) { + safe_chr(' ', tbuf1, &bp); + safe_str(fp->name, tbuf1, &bp); } *bp = '\0'; notify(player, tbuf1); @@ -1232,18 +1232,18 @@ do_function(dbref player, char *name, char *argv[], int preserve) if (argv[3] && *argv[3]) { fp->minargs = parse_integer(argv[3]); if (fp->minargs < 0) - fp->minargs = 0; + fp->minargs = 0; else if (fp->minargs > 10) - fp->minargs = 10; + fp->minargs = 10; } else fp->minargs = 0; if (argv[4] && *argv[4]) { fp->maxargs = parse_integer(argv[4]); if (fp->maxargs < -10) - fp->maxargs = -10; + fp->maxargs = -10; else if (fp->maxargs > 10) - fp->maxargs = 10; + fp->maxargs = 10; } else fp->maxargs = 10; if (argv[5] && *argv[5]) @@ -1270,10 +1270,10 @@ do_function(dbref player, char *name, char *argv[], int preserve) notify(player, T("You cannot change that built-in function.")); return; } - if (fp->flags & FN_BUILTIN) { /* Overriding a built in function */ + if (fp->flags & FN_BUILTIN) { /* Overriding a built in function */ if (userfn_count >= (Size_t) MAX_GLOBAL_FNS) { - notify(player, T("Function table full.")); - return; + notify(player, T("Function table full.")); + return; } fp = (FUN *) mush_malloc(sizeof(FUN), "func_hash.FUN"); fp->name = mush_strdup(name, "func_hash.name"); @@ -1285,24 +1285,24 @@ do_function(dbref player, char *name, char *argv[], int preserve) userfn_tab[fp->where.offset].thing = thing; if (userfn_tab[fp->where.offset].name) mush_free((Malloc_t) userfn_tab[fp->where.offset].name, - "userfn_tab.name"); + "userfn_tab.name"); userfn_tab[fp->where.offset].name = mush_strdup(upcasestr(argv[2]), "userfn_tab.name"); if (argv[3] && *argv[3]) { fp->minargs = parse_integer(argv[3]); if (fp->minargs < 0) - fp->minargs = 0; + fp->minargs = 0; else if (fp->minargs > 10) - fp->minargs = 10; + fp->minargs = 10; } else fp->minargs = 0; if (argv[4] && *argv[4]) { fp->maxargs = parse_integer(argv[4]); if (fp->maxargs < -10) - fp->maxargs = -10; + fp->maxargs = -10; else if (fp->maxargs > 10) - fp->maxargs = 10; + fp->maxargs = 10; } else fp->maxargs = 10; @@ -1598,8 +1598,8 @@ do_function_report(dbref player, char *name) if (!(fp->flags & FN_BUILTIN) && Global_Funcs(player)) { notify_format(player, T("Location : #%d/%s"), - userfn_tab[fp->where.offset].thing, - userfn_tab[fp->where.offset].name); + userfn_tab[fp->where.offset].thing, + userfn_tab[fp->where.offset].name); } maxargs = abs(fp->maxargs); @@ -1618,5 +1618,5 @@ do_function_report(dbref player, char *name) notify_format(player, T("Arguments : At least %d %s"), fp->minargs, tbuf); else notify_format(player, - T("Arguments : %d to %d %s"), fp->minargs, maxargs, tbuf); + T("Arguments : %d to %d %s"), fp->minargs, maxargs, tbuf); } diff --git a/src/fundb.c b/src/fundb.c index 70d3f0c..8aa35c4 100644 --- a/src/fundb.c +++ b/src/fundb.c @@ -54,9 +54,9 @@ do_get_attrib(dbref executor, dbref thing, const char *attrib) if (a) { if (Can_Read_Attr(executor, thing, a)) { if (strlen(value = atr_value(a)) < BUFFER_LEN) - return value; + return value; else - return T("#-1 ATTRIBUTE LENGTH TOO LONG"); + return T("#-1 ATTRIBUTE LENGTH TOO LONG"); } return T(e_atrperm); } @@ -84,10 +84,10 @@ struct lh_args { /* ARGSUSED */ static int lattr_helper(dbref player __attribute__ ((__unused__)), - dbref thing __attribute__ ((__unused__)), - dbref parent __attribute__ ((__unused__)), - char const *pattern __attribute__ ((__unused__)), - ATTR *atr, void *args) + dbref thing __attribute__ ((__unused__)), + dbref parent __attribute__ ((__unused__)), + char const *pattern __attribute__ ((__unused__)), + ATTR *atr, void *args) { struct lh_args *lh = args; if (lh->first) @@ -113,7 +113,7 @@ FUNCTION(fun_lattr) if (pattern) *pattern++ = '\0'; else - pattern = (char *) "*"; /* match anything */ + pattern = (char *) "*"; /* match anything */ thing = match_thing(executor, args[0]); if (!GoodObject(thing)) { @@ -228,7 +228,7 @@ FUNCTION(fun_default) dp = mstr; sp = args[i - 1]; process_expression(mstr, &dp, &sp, executor, caller, enactor, PE_DEFAULT, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); *dp = '\0'; parse_attrib(executor, mstr, &thing, &attrib); if (GoodObject(thing) && attrib && Can_Read_Attr(executor, thing, attrib)) { @@ -242,7 +242,7 @@ FUNCTION(fun_default) /* We couldn't get it. Evaluate the last arg and return it */ sp = args[nargs - 1]; process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); return; } @@ -270,7 +270,7 @@ FUNCTION(fun_eval) tp = tbuf = safe_atr_value(a); add_check("fun_eval.attr_value"); process_expression(buff, bp, &tp, thing, executor, executor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); mush_free((Malloc_t) tbuf, "fun_eval.attr_value"); return; } else if (a || !Can_Examine(executor, thing)) { @@ -310,7 +310,7 @@ FUNCTION(fun_get_eval) tp = tbuf = safe_atr_value(a); add_check("fun_eval.attr_value"); process_expression(buff, bp, &tp, thing, executor, executor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); mush_free((Malloc_t) tbuf, "fun_eval.attr_value"); return; } else if (a || !Can_Examine(executor, thing)) { @@ -335,7 +335,7 @@ FUNCTION(fun_edefault) dp = mstr; sp = args[0]; process_expression(mstr, &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *dp = '\0'; parse_attrib(executor, mstr, &thing, &attrib); if (GoodObject(thing) && attrib && Can_Read_Attr(executor, thing, attrib)) { @@ -347,14 +347,14 @@ FUNCTION(fun_edefault) sp = sbuf = safe_atr_value(attrib); add_check("fun_edefault.attr_value"); process_expression(buff, bp, &sp, thing, executor, executor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); mush_free((Malloc_t) sbuf, "fun_edefault.attr_value"); return; } /* We couldn't get it. Evaluate args[1] and return it */ sp = args[1]; process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); return; } @@ -378,7 +378,7 @@ FUNCTION(fun_v) case '8': case '9': if (global_eval_context.wenv[c - '0']) - safe_str(global_eval_context.wenv[c - '0'], buff, bp); + safe_str(global_eval_context.wenv[c - '0'], buff, bp); return; case '#': /* enactor dbref */ @@ -477,7 +477,7 @@ FUNCTION(fun_lflags) } #ifdef WIN32 -#pragma warning( default : 4761) /* Re-enable conversion warning */ +#pragma warning( default : 4761) /* Re-enable conversion warning */ #endif /* ARGSUSED */ @@ -593,28 +593,28 @@ dbwalk(char *buff, char **bp, dbref executor, dbref enactor, * use type == TYPE_PLAYER for this check. :-/. */ if (!(Typeof(thing) & type) || - !can_interact(thing, executor, INTERACT_SEE) || - (skipdark && Dark(thing) && !Light(thing) && !Light(loc)) || - ((type == TYPE_PLAYER) && skipdark && !Connected(thing))) - continue; + !can_interact(thing, executor, INTERACT_SEE) || + (skipdark && Dark(thing) && !Light(thing) && !Light(loc)) || + ((type == TYPE_PLAYER) && skipdark && !Connected(thing))) + continue; nthing += 1; if (count < 1 || (nthing >= start && nthing < start + count)) { - if (buff) { - if (first) - first = 0; - else - safe_chr(' ', buff, bp); - safe_dbref(thing, buff, bp); - } + if (buff) { + if (first) + first = 0; + else + safe_chr(' ', buff, bp); + safe_dbref(thing, buff, bp); + } } if (result == NOTHING) { - if (after == NOTHING) - result = thing; - if (after == thing) - after = NOTHING; + if (after == NOTHING) + result = thing; + if (after == thing) + after = NOTHING; } if (retcount) - *retcount = nthing; + *retcount = nthing; } } else if (buff) safe_str("#-1", buff, bp); @@ -683,7 +683,7 @@ FUNCTION(fun_dbwalker) } dbwalk(buffptr, bptr, executor, enactor, type, loc, NOTHING, - vis, start, count, &result); + vis, start, count, &result); if (!buffptr) { safe_integer(result, buff, bp); @@ -751,7 +751,7 @@ FUNCTION(fun_entrances) dbref counter; dbref entrance; int found; - int exd, td, pd, rd; /* what we're looking for */ + int exd, td, pd, rd; /* what we're looking for */ char *p; if (!command_check_byname(executor, "@entrances")) { @@ -776,27 +776,27 @@ FUNCTION(fun_entrances) switch (*p) { case 'a': case 'A': - exd = td = pd = rd = 1; - break; + exd = td = pd = rd = 1; + break; case 'e': case 'E': - exd = 1; - break; + exd = 1; + break; case 't': case 'T': - td = 1; - break; + td = 1; + break; case 'p': case 'P': - pd = 1; - break; + pd = 1; + break; case 'r': case 'R': - rd = 1; - break; + rd = 1; + break; default: - safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp); - return; + safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp); + return; } p++; } @@ -835,7 +835,7 @@ FUNCTION(fun_entrances) } if (!payfor(executor, FIND_COST)) { notify_format(executor, T("You don't have %d %s to do that."), - FIND_COST, ((FIND_COST == 1) ? MONEY : MONIES)); + FIND_COST, ((FIND_COST == 1) ? MONEY : MONIES)); safe_str("#-1", buff, bp); return; } @@ -844,19 +844,19 @@ FUNCTION(fun_entrances) for (counter = low; counter <= high; counter++) { if (controls(executor, where) || controls(executor, counter)) { if ((exd && IsExit(counter)) || - (td && IsThing(counter)) || - (pd && IsPlayer(counter)) || (rd && IsRoom(counter))) { - if (Mobile(counter)) - entrance = Home(counter); - else - entrance = Location(counter); - if (entrance == where) { - if (!found) - found = 1; - else - safe_chr(' ', buff, bp); - safe_dbref(counter, buff, bp); - } + (td && IsThing(counter)) || + (pd && IsPlayer(counter)) || (rd && IsRoom(counter))) { + if (Mobile(counter)) + entrance = Home(counter); + else + entrance = Location(counter); + if (entrance == where) { + if (!found) + found = 1; + else + safe_chr(' ', buff, bp); + safe_dbref(counter, buff, bp); + } } } } @@ -964,7 +964,7 @@ FUNCTION(fun_type) default: safe_str("WEIRD OBJECT", buff, bp); do_rawlog(LT_ERR, T("WARNING: Weird object #%d (type %d)\n"), it, - Typeof(it)); + Typeof(it)); } } @@ -1074,10 +1074,10 @@ FUNCTION(fun_orlflags) dbref it = match_thing(executor, args[0]); if (!strcmp(called_as, "ORLPOWERS")) safe_boolean(flaglist_check_long("POWER", executor, it, args[1], 0), buff, - bp); + bp); else safe_boolean(flaglist_check_long("FLAG", executor, it, args[1], 0), buff, - bp); + bp); } /* ARGSUSED */ @@ -1086,10 +1086,10 @@ FUNCTION(fun_andlflags) dbref it = match_thing(executor, args[0]); if (!strcmp(called_as, "ANDLPOWERS")) safe_boolean(flaglist_check_long("POWER", executor, it, args[1], 1), buff, - bp); + bp); else safe_boolean(flaglist_check_long("FLAG", executor, it, args[1], 1), buff, - bp); + bp); } static lock_type @@ -1134,7 +1134,7 @@ FUNCTION(fun_lock) if (GoodObject(it) && (real_ltype != NULL) && Can_Read_Lock(executor, it, real_ltype)) { safe_str(unparse_boolexp(executor, getlock(it, real_ltype), UB_DBREF), - buff, bp); + buff, bp); return; } safe_str("#-1", buff, bp); @@ -1294,7 +1294,7 @@ FUNCTION(fun_rloc) else { for (i = 0; i < deep; i++) { if (!GoodObject(it) || IsRoom(it)) - break; + break; it = Location(it); } safe_dbref(it, buff, bp); @@ -1403,9 +1403,9 @@ FUNCTION(fun_money) if (is_integer(args[0])) { int a = parse_integer(args[0]); if (abs(a) == 1) - safe_str(MONEY, buff, bp); + safe_str(MONEY, buff, bp); else - safe_str(MONIES, buff, bp); + safe_str(MONIES, buff, bp); } else { /* Guess we're just making a typo or something. */ safe_str("#-1", buff, bp); @@ -1437,7 +1437,7 @@ FUNCTION(fun_owner) if (strchr(args[0], '/')) { parse_attrib(executor, args[0], &thing, &attrib); if (!GoodObject(thing) || !attrib - || !Can_Read_Attr(executor, thing, attrib)) + || !Can_Read_Attr(executor, thing, attrib)) safe_str("#-1", buff, bp); else safe_dbref(attrib->creator, buff, bp); @@ -1736,7 +1736,7 @@ FUNCTION(fun_locate) match_flags |= MAT_ENGLISH; break; case 'X': - ambig_ok = 1; /* okay to pick last match */ + ambig_ok = 1; /* okay to pick last match */ break; default: notify_format(executor, T("I don't understand switch '%c'."), *p); @@ -1773,13 +1773,13 @@ FUNCTION(fun_locate) if (Can_Examine(executor, loc)) safe_dbref(item, buff, bp); else if (can_interact(item, executor, INTERACT_SEE) - && (!DarkLegal(item) || Light(loc) || Light(item))) + && (!DarkLegal(item) || Light(loc) || Light(item))) safe_dbref(item, buff, bp); else safe_dbref(NOTHING, buff, bp); } else { if (can_interact(item, executor, INTERACT_SEE) - && (See_All(executor) || !DarkLegal(item) || Light(item))) + && (See_All(executor) || !DarkLegal(item) || Light(item))) safe_dbref(item, buff, bp); else safe_dbref(NOTHING, buff, bp); @@ -2063,9 +2063,9 @@ FUNCTION(fun_atrlock) if (status == 1) { if (FUNCTION_SIDE_EFFECTS) { if (!command_check_byname(executor, "@atrlock") - || fun->flags & FN_NOSIDEFX) { - safe_str(T(e_perm), buff, bp); - return; + || fun->flags & FN_NOSIDEFX) { + safe_str(T(e_perm), buff, bp); + return; } do_atrlock(executor, args[0], args[1], 0); return; @@ -2086,7 +2086,7 @@ FUNCTION(fun_atrlock) if ((thing = noisy_match_result(executor, args[0], NOTYPE, - MAT_EVERYTHING)) == NOTHING) { + MAT_EVERYTHING)) == NOTHING) { safe_str(T(e_notvis), buff, bp); return; } diff --git a/src/funlist.c b/src/funlist.c index d142055..9941d57 100644 --- a/src/funlist.c +++ b/src/funlist.c @@ -311,7 +311,7 @@ FUNCTION(fun_munge) uargs[0] = lp; uargs[1] = isep; do_userfn(rlist, &rp, thing, attrib, 2, uargs, - executor, caller, enactor, pe_info); + executor, caller, enactor, pe_info); *rp = '\0'; /* Now that we have our result, put it back into array form. Search @@ -328,13 +328,13 @@ FUNCTION(fun_munge) for (i = 0; i < nresults; i++) { for (j = 0; j < nptrs1; j++) { if (ptrs3[j] && !strcmp(results[i], ptrs1[j])) { - if (first) - first = 0; - else - safe_str(osep, buff, bp); - safe_str(ptrs3[j], buff, bp); - ptrs3[j] = NULL; - break; + if (first) + first = 0; + else + safe_str(osep, buff, bp); + safe_str(ptrs3[j], buff, bp); + ptrs3[j] = NULL; + break; } } } @@ -432,7 +432,7 @@ FUNCTION(fun_matchall) r = split_token(&s, sep); if (quick_wild(args[1], r)) { if (*bp != b) - safe_str(osep, buff, bp); + safe_str(osep, buff, bp); safe_integer(wcount, buff, bp); } wcount++; @@ -466,7 +466,7 @@ FUNCTION(fun_graball) r = split_token(&s, sep); if (quick_wild(args[1], r)) { if (*bp != b) - safe_str(osep, buff, bp); + safe_str(osep, buff, bp); safe_str(r, buff, bp); } } while (s); @@ -521,7 +521,7 @@ FUNCTION(fun_fold) wenv[1] = split_token(&cp, sep); per = call_ufun(&ufun, wenv, 2, result, executor, enactor, pe_info); if (per || (pe_info->fun_invocations >= FUNCTION_LIMIT && - pe_info->fun_invocations == funccount && !strcmp(base, result))) + pe_info->fun_invocations == funccount && !strcmp(base, result))) break; funccount = pe_info->fun_invocations; strcpy(base, result); @@ -620,12 +620,12 @@ FUNCTION(fun_filter) if (call_ufun(&ufun, wenv, 1, result, executor, enactor, pe_info)) break; if ((check_bool == 0) - ? (*result == '1' && *(result + 1) == '\0') - : parse_boolean(result)) { + ? (*result == '1' && *(result + 1) == '\0') + : parse_boolean(result)) { if (first) - first = 0; + first = 0; else - safe_str(osep, buff, bp); + safe_str(osep, buff, bp); safe_str(wenv[0], buff, bp); } /* Can't do *bp == oldbp like in all the others, because bp might not @@ -704,31 +704,31 @@ autodetect_list(char *ptrs[], int nptrs) switch (lt) { case L_NUMERIC: if (!is_strict_integer(ptrs[i])) { - /* If it's not an integer, see if it's a floating-point number */ - if (is_strict_number(ptrs[i])) { - lt = L_FLOAT; - sort_type = FLOAT_LIST; - } else if (i == 0) { - - /* If we get something non-numeric, switch to an - * alphanumeric guess, unless this is the first - * element and we have a dbref. - */ - if (is_objid(ptrs[i])) { - lt = L_DBREF; - sort_type = DBREF_LIST; - } else - return ALPHANUM_LIST; - } + /* If it's not an integer, see if it's a floating-point number */ + if (is_strict_number(ptrs[i])) { + lt = L_FLOAT; + sort_type = FLOAT_LIST; + } else if (i == 0) { + + /* If we get something non-numeric, switch to an + * alphanumeric guess, unless this is the first + * element and we have a dbref. + */ + if (is_objid(ptrs[i])) { + lt = L_DBREF; + sort_type = DBREF_LIST; + } else + return ALPHANUM_LIST; + } } break; case L_FLOAT: if (!is_strict_number(ptrs[i])) - return ALPHANUM_LIST; + return ALPHANUM_LIST; break; case L_DBREF: if (!is_objid(ptrs[i])) - return ALPHANUM_LIST; + return ALPHANUM_LIST; break; default: return ALPHANUM_LIST; @@ -752,13 +752,13 @@ typedef void (*makerecord) (s_rec *, dbref player, char *sortflags); * its 'key' to sort by. Sort of a hardcode munge. */ struct sort_record { - char *ptr; /**< NULL except for sortkey */ - char *val; /**< The string this is */ - dbref db; /**< dbref (default 0, bad is -1) */ - char *str; /**< string comparisons */ - int num; /**< integer comparisons */ - NVAL numval; /**< float comparisons */ - int freestr; /**< free str on completion */ + char *ptr; /**< NULL except for sortkey */ + char *val; /**< The string this is */ + dbref db; /**< dbref (default 0, bad is -1) */ + char *str; /**< string comparisons */ + int num; /**< integer comparisons */ + NVAL numval; /**< float comparisons */ + int freestr; /**< free str on completion */ }; /* Compare(r,x,y) { @@ -978,12 +978,12 @@ get_list_type(char *args[], int nargs, int type_pos, char *ptrs[], int nptrs) strcpy(stype, str); str = strchr(stype, ':'); if (str) - *(str++) = '\0'; + *(str++) = '\0'; for (i = 0; ltypelist[i].name && strcasecmp(ltypelist[i].name, stype); - i++) ; + i++) ; /* return ltypelist[i].name; */ if (ltypelist[i].name) { - return args[type_pos - 1]; + return args[type_pos - 1]; } } } @@ -1002,9 +1002,9 @@ get_list_type_noauto(char *args[], int nargs, int type_pos) strcpy(stype, str); str = strchr(stype, ':'); if (str) - *(str++) = '\0'; + *(str++) = '\0'; for (i = 0; ltypelist[i].name && strcasecmp(ltypelist[i].name, stype); - i++) ; + i++) ; /* return ltypelist[i].name; */ return args[type_pos - 1]; } @@ -1037,8 +1037,8 @@ u_comp(const void *s1, const void *s2) tbuf = ucomp_buff; rp = result; if (process_expression(result, &rp, &tbuf, - ucomp_executor, ucomp_caller, ucomp_enactor, - PE_DEFAULT, PT_DEFAULT, ucomp_pe_info)) + ucomp_executor, ucomp_caller, ucomp_enactor, + PE_DEFAULT, PT_DEFAULT, ucomp_pe_info)) return 0; n = parse_integer(result); @@ -1065,11 +1065,11 @@ gencomp(dbref player, char *a, char *b, char *sort_type) if (!*ptr) ptr = NULL; for (i = 0; - ltypelist[i].name && strncasecmp(ltypelist[i].name, sort_type, len); - i++) ; + ltypelist[i].name && strncasecmp(ltypelist[i].name, sort_type, len); + i++) ; } else { for (i = 0; ltypelist[i].name && strcasecmp(ltypelist[i].name, sort_type); - i++) ; + i++) ; } s1.freestr = s2.freestr = 0; if (ltypelist[i].isdbs) { @@ -1121,12 +1121,12 @@ do_gensort(dbref player, char *keys[], char *strs[], int n, char *sort_type) if (!*ptr) ptr = NULL; for (sorti = 0; - ltypelist[sorti].name && strcasecmp(ltypelist[sorti].name, stype); - sorti++) ; + ltypelist[sorti].name && strcasecmp(ltypelist[sorti].name, stype); + sorti++) ; } else { for (sorti = 0; - ltypelist[sorti].name && strcasecmp(ltypelist[sorti].name, sort_type); - sorti++) ; + ltypelist[sorti].name && strcasecmp(ltypelist[sorti].name, sort_type); + sorti++) ; } sp = (s_rec *) mush_malloc(n * sizeof(s_rec), "do_gensort"); for (i = 0; i < n; i++) { @@ -1142,7 +1142,7 @@ do_gensort(dbref player, char *keys[], char *strs[], int n, char *sort_type) if (ltypelist[sorti].isdbs) { sp[i].db = parse_objid(keys[i]); if (!RealGoodObject(sp[i].db)) - sp[i].db = NOTHING; + sp[i].db = NOTHING; } ltypelist[sorti].make_record(&(sp[i]), player, ptr); } @@ -1222,7 +1222,7 @@ loop: if (compare(array[i], array[left]) < 0) { last++; if (last == i) - continue; + continue; tmp = array[last]; array[last] = array[i]; @@ -1348,7 +1348,7 @@ FUNCTION(fun_sortby) /* Split up the list, sort it, reconstruct it. */ nptrs = list2arr_ansi(ptrs, MAX_SORTSIZE, args[1], sep); - if (nptrs > 1) /* pointless to sort less than 2 elements */ + if (nptrs > 1) /* pointless to sort less than 2 elements */ sane_qsort((void *) ptrs, 0, nptrs - 1, u_comp); arr2list(ptrs, nptrs, buff, bp, osep); @@ -1399,7 +1399,7 @@ FUNCTION(fun_setinter) osepd[0] = sep; osep = osepd; if (sep) - osepl = 1; + osepl = 1; } } else if (nargs == 5) { sort_type = get_list_type(args, nargs, 4, a1, n1); @@ -1416,20 +1416,20 @@ FUNCTION(fun_setinter) if (val < 0) { x1++; if (x1 >= n1) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; } } else { x2++; if (x2 >= n2) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; } } } @@ -1449,23 +1449,23 @@ FUNCTION(fun_setinter) while ((x1 < n1) && (x2 < n2)) { while ((val = gencomp(executor, a1[x1], a2[x2], sort_type))) { if (val < 0) { - x1++; - if (x1 >= n1) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; - } + x1++; + if (x1 >= n1) { + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; + } } else { - x2++; - if (x2 >= n2) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; - } + x2++; + if (x2 >= n2) { + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; + } } } safe_strl(osep, osepl, buff, bp); @@ -1473,11 +1473,11 @@ FUNCTION(fun_setinter) while (!gencomp(executor, a1[x1], a2[x2], sort_type)) { x1++; if (x1 >= n1) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; } } } @@ -1529,7 +1529,7 @@ FUNCTION(fun_setunion) osepd[0] = sep; osep = osepd; if (sep) - osepl = 1; + osepl = 1; } } else if (nargs == 5) { sort_type = get_list_type(args, nargs, 4, a1, n1); @@ -1555,68 +1555,68 @@ FUNCTION(fun_setunion) if (x1 < n1 && lastx1 >= 0) { val = gencomp(executor, a1[lastx1], a1[x1], sort_type); if (val == 0) { - x1++; - continue; + x1++; + continue; } } if (x1 < n1 && lastx2 >= 0) { val = gencomp(executor, a2[lastx2], a1[x1], sort_type); if (val == 0) { - x1++; - continue; + x1++; + continue; } } if (x2 < n2 && lastx1 >= 0) { val = gencomp(executor, a1[lastx1], a2[x2], sort_type); if (val == 0) { - x2++; - continue; + x2++; + continue; } } if (x2 < n2 && lastx2 >= 0) { val = gencomp(executor, a2[lastx2], a2[x2], sort_type); if (val == 0) { - x2++; - continue; + x2++; + continue; } } if (x1 >= n1) { /* Just copy off the rest of a2 */ if (x2 < n2) { - if (found) - safe_strl(osep, osepl, buff, bp); - safe_str(a2[x2], buff, bp); - lastx2 = x2; - x2++; - found = 1; + if (found) + safe_strl(osep, osepl, buff, bp); + safe_str(a2[x2], buff, bp); + lastx2 = x2; + x2++; + found = 1; } } else if (x2 >= n2) { /* Just copy off the rest of a1 */ if (x1 < n1) { - if (found) - safe_strl(osep, osepl, buff, bp); - safe_str(a1[x1], buff, bp); - lastx1 = x1; - x1++; - found = 1; + if (found) + safe_strl(osep, osepl, buff, bp); + safe_str(a1[x1], buff, bp); + lastx1 = x1; + x1++; + found = 1; } } else { /* At this point, we're merging. Take the lower of the two. */ val = gencomp(executor, a1[x1], a2[x2], sort_type); if (val <= 0) { - if (found) - safe_strl(osep, osepl, buff, bp); - safe_str(a1[x1], buff, bp); - lastx1 = x1; - x1++; - found = 1; + if (found) + safe_strl(osep, osepl, buff, bp); + safe_str(a1[x1], buff, bp); + lastx1 = x1; + x1++; + found = 1; } else { - if (found) - safe_strl(osep, osepl, buff, bp); - safe_str(a2[x2], buff, bp); - lastx2 = x2; - x2++; - found = 1; + if (found) + safe_strl(osep, osepl, buff, bp); + safe_str(a2[x2], buff, bp); + lastx2 = x2; + x2++; + found = 1; } } } @@ -1667,7 +1667,7 @@ FUNCTION(fun_setdiff) osepd[0] = sep; osep = osepd; if (sep) - osepl = 1; + osepl = 1; } } else if (nargs == 5) { sort_type = get_list_type(args, nargs, 4, a1, n1); @@ -1685,16 +1685,16 @@ FUNCTION(fun_setdiff) if (val > 0) { x2++; if (x2 >= n2) - break; + break; } if (!val) { x1++; if (x1 >= n1) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; } } } @@ -1718,14 +1718,14 @@ FUNCTION(fun_setdiff) } if (val <= 0) { do { - x1++; - if (x1 >= n1) { - freearr(a1, n1); - freearr(a2, n2); - mush_free((Malloc_t) a1, "ptrarray"); - mush_free((Malloc_t) a2, "ptrarray"); - return; - } + x1++; + if (x1 >= n1) { + freearr(a1, n1); + freearr(a2, n2); + mush_free((Malloc_t) a1, "ptrarray"); + mush_free((Malloc_t) a2, "ptrarray"); + return; + } } while (!gencomp(executor, a1[x1], a1[x1 - 1], sort_type)); } if (val >= 0) @@ -1843,14 +1843,14 @@ FUNCTION(fun_lnum) start = end; end = parse_number(args[1]); if ((start == 0) && (end == 0)) { - safe_str("0", buff, bp); /* Special case - lnum(0,0) -> 0 */ + safe_str("0", buff, bp); /* Special case - lnum(0,0) -> 0 */ return; } } else { if (end == 0) - return; /* Special case - lnum(0) -> blank string */ + return; /* Special case - lnum(0) -> blank string */ else if (end == 1) { - safe_str("0", buff, bp); /* Special case - lnum(1) -> 0 */ + safe_str("0", buff, bp); /* Special case - lnum(1) -> 0 */ return; } end--; @@ -1881,30 +1881,30 @@ FUNCTION(fun_lnum) safe_integer(istart, cresult[cpos], &cp); if (istart <= iend) { for (k = istart + 1; k <= iend; k++) { - safe_str(osep, cresult[cpos], &cp); - if (safe_integer(k, cresult[cpos], &cp)) - break; + safe_str(osep, cresult[cpos], &cp); + if (safe_integer(k, cresult[cpos], &cp)) + break; } } else { for (k = istart - 1; k >= iend; k--) { - safe_str(osep, cresult[cpos], &cp); - if (safe_integer(k, cresult[cpos], &cp)) - break; + safe_str(osep, cresult[cpos], &cp); + if (safe_integer(k, cresult[cpos], &cp)) + break; } } } else { safe_number(start, cresult[cpos], &cp); if (start <= end) { for (j = start + 1; j <= end; j++) { - safe_str(osep, cresult[cpos], &cp); - if (safe_number(j, cresult[cpos], &cp)) - break; + safe_str(osep, cresult[cpos], &cp); + if (safe_number(j, cresult[cpos], &cp)) + break; } } else { for (j = start - 1; j >= end; j--) { - safe_str(osep, cresult[cpos], &cp); - if (safe_number(j, cresult[cpos], &cp)) - break; + safe_str(osep, cresult[cpos], &cp); + if (safe_number(j, cresult[cpos], &cp)) + break; } } } @@ -1954,7 +1954,7 @@ FUNCTION(fun_randword) word_index--; } - if (!s || !*s) /* ran off the end of the string */ + if (!s || !*s) /* ran off the end of the string */ return; /* Chop off the end, and copy. No length checking needed. */ @@ -2070,12 +2070,12 @@ FUNCTION(fun_namegraball) r = split_token(&s, sep); victim = parse_dbref(r); if (!RealGoodObject(victim)) - continue; /* Don't bother with garbage */ + continue; /* Don't bother with garbage */ if (!can_interact(victim, executor, INTERACT_MATCH)) - continue; + continue; /* It's real, and is interact-able */ if (!first) - safe_chr(sep, buff, bp); + safe_chr(sep, buff, bp); safe_str(r, buff, bp); first = 0; } while (s); @@ -2232,7 +2232,7 @@ FUNCTION(fun_extract) start--; } - if (!s || !*s) /* ran off the end of the string */ + if (!s || !*s) /* ran off the end of the string */ return; /* Find the end of the string that we want. */ @@ -2335,7 +2335,7 @@ FUNCTION(fun_element) el++; } while (*s); - safe_chr('0', buff, bp); /* no match */ + safe_chr('0', buff, bp); /* no match */ } /* ARGSUSED */ @@ -2413,7 +2413,7 @@ FUNCTION(fun_index) */ static void do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, - char *sep, enum itemfun_op flag) + char *sep, enum itemfun_op flag) { char c; int el, count, len = -1; @@ -2446,7 +2446,7 @@ do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, count = 1; /* go to the correct item in the string */ - if (el < 0) { /* if using insert() with a negative insertion param */ + if (el < 0) { /* if using insert() with a negative insertion param */ /* count keeps track of the number of words from the right * of the string. When count equals the correct position, then * sptr will point to the count'th word from the right, or @@ -2455,10 +2455,10 @@ do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, * eptr is just a helper. */ for (len = strlen(str); len >= 0 && count < abs(el); len--, eptr--) { if (*eptr == c) - count++; + count++; if (count == abs(el)) { - sptr = eptr + 1; - break; + sptr = eptr + 1; + break; } } } else { @@ -2484,11 +2484,11 @@ do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, switch (flag) { case IF_DELETE: /* deletion */ - if (!eptr) { /* last element in the string */ + if (!eptr) { /* last element in the string */ if (el != 1) - safe_str(str, buff, bp); - } else if (sptr == str) { /* first element in the string */ - eptr++; /* chop leading separator */ + safe_str(str, buff, bp); + } else if (sptr == str) { /* first element in the string */ + eptr++; /* chop leading separator */ safe_str(eptr, buff, bp); } else { safe_str(str, buff, bp); @@ -2497,13 +2497,13 @@ do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, break; case IF_REPLACE: /* replacing */ - if (!eptr) { /* last element in string */ + if (!eptr) { /* last element in string */ if (el != 1) { - safe_str(str, buff, bp); - safe_chr(c, buff, bp); + safe_str(str, buff, bp); + safe_chr(c, buff, bp); } safe_str(word, buff, bp); - } else if (sptr == str) { /* first element in string */ + } else if (sptr == str) { /* first element in string */ safe_str(word, buff, bp); safe_str(eptr, buff, bp); } else { @@ -2515,7 +2515,7 @@ do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, break; case IF_INSERT: /* insertion */ - if (sptr == str) { /* first element in string */ + if (sptr == str) { /* first element in string */ safe_str(word, buff, bp); safe_chr(c, buff, bp); safe_str(str, buff, bp); @@ -2523,9 +2523,9 @@ do_itemfuns(char *buff, char **bp, char *str, char *num, char *word, safe_str(str, buff, bp); safe_chr(c, buff, bp); safe_str(word, buff, bp); - if (sptr && *sptr) { /* Don't add an osep to the end of the list */ - safe_chr(c, buff, bp); - safe_str(sptr, buff, bp); + if (sptr && *sptr) { /* Don't add an osep to the end of the list */ + safe_chr(c, buff, bp); + safe_str(sptr, buff, bp); } } break; @@ -2583,7 +2583,7 @@ FUNCTION(fun_member) el++; } while (s); - safe_chr('0', buff, bp); /* not found */ + safe_chr('0', buff, bp); /* not found */ } /* ARGSUSED */ @@ -2755,7 +2755,7 @@ FUNCTION(fun_iter) char *isep = insep; const char *arg3 = args[2]; process_expression(insep, &isep, &arg3, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *isep = '\0'; strcpy(args[2], insep); } @@ -2772,13 +2772,13 @@ FUNCTION(fun_iter) const char *arg4 = args[3]; char *osep = outsep; process_expression(outsep, &osep, &arg4, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *osep = '\0'; } lp = list; sp = args[0]; process_expression(list, &lp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *lp = '\0'; lp = trim_space_sep(list, sep); if (!*lp) { @@ -2803,7 +2803,7 @@ FUNCTION(fun_iter) tbuf2 = replace_string2(standard_tokens, replace, args[1]); sp = tbuf2; if (process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info)) { + PE_DEFAULT, PT_DEFAULT, pe_info)) { mush_free((Malloc_t) tbuf2, "replace_string.buff"); break; } @@ -2947,7 +2947,7 @@ FUNCTION(fun_step) ap = asave; process_expression(buff, bp, &ap, thing, executor, enactor, - pe_flags, PT_DEFAULT, pe_info); + pe_flags, PT_DEFAULT, pe_info); oldbp = *bp; funccount = pe_info->fun_invocations; while (lp) { @@ -2955,15 +2955,15 @@ FUNCTION(fun_step) for (n = 0; n < step; n++) { global_eval_context.wenv[n] = split_token(&lp, sep); if (!lp) { - n++; - break; + n++; + break; } } for (; n < 10; n++) global_eval_context.wenv[n] = NULL; ap = asave; if (process_expression(buff, bp, &ap, thing, executor, enactor, - pe_flags, PT_DEFAULT, pe_info)) + pe_flags, PT_DEFAULT, pe_info)) break; if (*bp == (buff + BUFFER_LEN - 1) && pe_info->fun_invocations == funccount) break; @@ -3049,7 +3049,7 @@ FUNCTION(fun_mix) int lists, words; int first = 1; - if (nargs > 3) { /* Last arg must be the delimiter */ + if (nargs > 3) { /* Last arg must be the delimiter */ n = nargs; lists = nargs - 2; } else { @@ -3072,11 +3072,11 @@ FUNCTION(fun_mix) words = 0; for (n = 0; n < lists; n++) { if (lp[n] && *lp[n]) { - list[n] = split_token(&lp[n], sep); - if (list[n]) - words++; + list[n] = split_token(&lp[n], sep); + if (list[n]) + words++; } else { - list[n] = NULL; + list[n] = NULL; } } if (!words) @@ -3165,13 +3165,13 @@ FUNCTION(fun_table) col += field_width + !!osep; if (col > line_length) { if (NEWLINE_ONE_CHAR) - safe_str("\n", buff, bp); + safe_str("\n", buff, bp); else - safe_str("\r\n", buff, bp); + safe_str("\r\n", buff, bp); col = field_width + !!osep; } else { if (osep) - safe_chr(osep, buff, bp); + safe_chr(osep, buff, bp); } t = split_token(&cp, sep); if (!t) @@ -3235,7 +3235,7 @@ FUNCTION(fun_regreplace) abp = abuf; r = args[0]; process_expression(abuf, &abp, &r, executor, caller, enactor, PE_DEFAULT, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); *abp = '\0'; postp = postbuf; @@ -3252,7 +3252,7 @@ FUNCTION(fun_regreplace) tbp = tbuf; r = args[i]; process_expression(tbuf, &tbp, &r, executor, caller, enactor, PE_DEFAULT, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); *tbp = '\0'; if ((re = pcre_compile(tbuf, flags, &errptr, &erroffset, tables)) == NULL) { @@ -3267,13 +3267,13 @@ FUNCTION(fun_regreplace) if (all) { study = pcre_study(re, 0, &errptr); if (errptr != NULL) { - mush_free((Malloc_t) re, "pcre"); - safe_str(T("#-1 REGEXP ERROR: "), buff, bp); - safe_str(errptr, buff, bp); - return; + mush_free((Malloc_t) re, "pcre"); + safe_str(T("#-1 REGEXP ERROR: "), buff, bp); + safe_str(errptr, buff, bp); + return; } if (study != NULL) - add_check("pcre.extra"); + add_check("pcre.extra"); } len = strlen(prebuf); start = prebuf; @@ -3284,7 +3284,7 @@ FUNCTION(fun_regreplace) safe_str(prebuf, postbuf, &postp); mush_free((Malloc_t) re, "pcre"); if (study) - mush_free((Malloc_t) study, "pcre.extra"); + mush_free((Malloc_t) study, "pcre.extra"); continue; } @@ -3305,10 +3305,10 @@ FUNCTION(fun_regreplace) global_eval_context.re_offsets = offsets; global_eval_context.re_subpatterns = subpatterns; process_expression(postbuf, &postp, &obp, executor, caller, enactor, - PE_DEFAULT | PE_DOLLAR, PT_DEFAULT, pe_info); + PE_DEFAULT | PE_DOLLAR, PT_DEFAULT, pe_info); if ((*bp == (buff + BUFFER_LEN - 1)) - && (pe_info->fun_invocations == funccount)) - break; + && (pe_info->fun_invocations == funccount)) + break; oldbp = postp; funccount = pe_info->fun_invocations; @@ -3317,11 +3317,11 @@ FUNCTION(fun_regreplace) match_offset = offsets[1]; /* Make sure we advance at least 1 char */ if (offsets[0] == match_offset) - match_offset++; + match_offset++; } while (all && match_offset < len && (subpatterns = - pcre_exec(re, study, prebuf, len, - match_offset, 0, offsets, - 99)) >= 0); + pcre_exec(re, study, prebuf, len, + match_offset, 0, offsets, + 99)) >= 0); /* Now copy everything after the matched bit */ @@ -3367,7 +3367,7 @@ FUNCTION(fun_regmatch) if (strcmp(called_as, "REGMATCHI") == 0) flags = PCRE_CASELESS; - if (nargs == 2) { /* Don't care about saving sub expressions */ + if (nargs == 2) { /* Don't care about saving sub expressions */ safe_boolean(quick_regexp_match(args[1], args[0], flags ? 0 : 1), buff, bp); return; } @@ -3398,9 +3398,9 @@ FUNCTION(fun_regmatch) /* subexpr:register */ *regname++ = '\0'; if (is_strict_integer(qregs[i])) - subpattern = parse_integer(qregs[i]); + subpattern = parse_integer(qregs[i]); else - named_subpattern = qregs[i]; + named_subpattern = qregs[i]; } else { /* Get subexpr by position in list */ subpattern = i; @@ -3408,7 +3408,7 @@ FUNCTION(fun_regmatch) } if (regname && regname[0] && !regname[1] && - ((qindex = qreg_indexes[(unsigned char) regname[0]]) != -1)) + ((qindex = qreg_indexes[(unsigned char) regname[0]]) != -1)) curq = qindex; else curq = -1; @@ -3419,11 +3419,11 @@ FUNCTION(fun_regmatch) global_eval_context.renv[curq][0] = '\0'; else if (named_subpattern) pcre_copy_named_substring(re, args[0], offsets, subpatterns, - named_subpattern, - global_eval_context.renv[curq], BUFFER_LEN); + named_subpattern, + global_eval_context.renv[curq], BUFFER_LEN); else pcre_copy_substring(args[0], offsets, subpatterns, subpattern, - global_eval_context.renv[curq], BUFFER_LEN); + global_eval_context.renv[curq], BUFFER_LEN); } mush_free((Malloc_t) re, "pcre"); } @@ -3431,11 +3431,11 @@ FUNCTION(fun_regmatch) /** Structure to hold data for regrep */ struct regrep_data { - pcre *re; /**< Pointer to compiled regular expression */ - pcre_extra *study; /**< Pointer to studied data about re */ - char *buff; /**< Buffer to store regrep results */ - char **bp; /**< Pointer to address of insertion point in buff */ - int first; /**< Is this the first match or a later match? */ + pcre *re; /**< Pointer to compiled regular expression */ + pcre_extra *study; /**< Pointer to studied data about re */ + char *buff; /**< Buffer to store regrep results */ + char **bp; /**< Pointer to address of insertion point in buff */ + int first; /**< Is this the first match or a later match? */ }; /* Like grep(), but using a regexp pattern. This same function handles @@ -3467,7 +3467,7 @@ FUNCTION(fun_regrep) flags = PCRE_CASELESS; if ((reharg.re = pcre_compile(args[2], flags, - &errptr, &erroffset, tables)) == NULL) { + &errptr, &erroffset, tables)) == NULL) { /* Matching error. */ safe_str(T("#-1 REGEXP ERROR: "), buff, bp); safe_str(errptr, buff, bp); @@ -3496,10 +3496,10 @@ FUNCTION(fun_regrep) static int regrep_helper(dbref who __attribute__ ((__unused__)), - dbref what __attribute__ ((__unused__)), - dbref parent __attribute__ ((__unused__)), - char const *name __attribute__ ((__unused__)), - ATTR *atr, void *args) + dbref what __attribute__ ((__unused__)), + dbref parent __attribute__ ((__unused__)), + char const *name __attribute__ ((__unused__)), + ATTR *atr, void *args) { struct regrep_data *reharg = args; char const *str; @@ -3572,10 +3572,10 @@ FUNCTION(fun_regrab) r = split_token(&s, sep); if (pcre_exec(re, study, r, strlen(r), 0, 0, offsets, 99) >= 0) { if (all && *bp != b) - safe_str(osep, buff, bp); + safe_str(osep, buff, bp); safe_str(r, buff, bp); if (!all) - break; + break; } } while (s); diff --git a/src/funmath.c b/src/funmath.c index 009f135..01e415d 100644 --- a/src/funmath.c +++ b/src/funmath.c @@ -55,7 +55,7 @@ static MATH *math_hash_lookup(char *); static NVAL angle_to_rad(NVAL angle, const char *from); static NVAL rad_to_angle(NVAL angle, const char *to); static double frac(double v, double *RESTRICT n, double *RESTRICT d, - double error); + double error); void init_math_hashtab(void); extern int format_long(long n, char *buff, char **bp, int maxlen, @@ -1275,7 +1275,6 @@ FUNCTION(fun_fraction) { double num = 0, denom = 0; NVAL n; - int sign = 0; if (!is_number(args[0])) { safe_str(T(e_num), buff, bp); @@ -1286,21 +1285,22 @@ FUNCTION(fun_fraction) if (n < 0) { n = fabs(n); - sign = 1; + safe_chr('-', buff, bp); } else if (EQ(n, 0)) { safe_chr('0', buff, bp); return; } - frac(n, &num, &denom, 1.0e-10); - - if (sign) - safe_chr('-', buff, bp); + if (is_good_number(n)) { + frac(n, &num, &denom, 1.0e-10); - if (fabs(denom - 1) < 1.0e-10) - safe_format(buff, bp, "%.0lf", num); - else - safe_format(buff, bp, "%.0lf/%.0lf", num, denom); + if (fabs(denom - 1) < 1.0e-10) + safe_format(buff, bp, "%.0f", num); + else + safe_format(buff, bp, "%.0f/%.0f", num, denom); + } else { + safe_number(n, buff, bp); + } } FUNCTION(fun_isint) diff --git a/src/funmisc.c b/src/funmisc.c index 4d0fee1..d17a7c9 100644 --- a/src/funmisc.c +++ b/src/funmisc.c @@ -31,7 +31,7 @@ #include "confmagic.h" #ifdef WIN32 -#pragma warning( disable : 4761) /* NJG: disable warning re conversion */ +#pragma warning( disable : 4761) /* NJG: disable warning re conversion */ #endif extern FUN flist[]; @@ -267,9 +267,9 @@ FUNCTION(fun_die) if (show_all) { for (count = 0; count < n; count++) { if (first) - first = 0; + first = 0; else - safe_chr(' ', buff, bp); + safe_chr(' ', buff, bp); safe_uinteger(get_random_long(1, die), buff, bp); } } else { @@ -305,7 +305,7 @@ FUNCTION(fun_switch) dp = mstr; sp = args[0]; process_expression(mstr, &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *dp = '\0'; /* try matching, return match immediately when found */ @@ -314,30 +314,30 @@ FUNCTION(fun_switch) dp = pstr; sp = args[j]; process_expression(pstr, &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *dp = '\0'; if ((!exact) - ? local_wild_match(pstr, mstr) - : (strcmp(pstr, mstr) == 0)) { + ? local_wild_match(pstr, mstr) + : (strcmp(pstr, mstr) == 0)) { /* If there's a #$ in a switch's action-part, replace it with * the value of the conditional (mstr) before evaluating it. */ if (!exact) - tbuf1 = replace_string("#$", mstr, args[j + 1]); + tbuf1 = replace_string("#$", mstr, args[j + 1]); else - tbuf1 = args[j + 1]; + tbuf1 = args[j + 1]; sp = tbuf1; per = process_expression(buff, bp, &sp, - executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + executor, caller, enactor, + PE_DEFAULT, PT_DEFAULT, pe_info); if (!exact) - mush_free((Malloc_t) tbuf1, "replace_string.buff"); + mush_free((Malloc_t) tbuf1, "replace_string.buff"); found = 1; if (per || first) - return; + return; } } @@ -349,7 +349,7 @@ FUNCTION(fun_switch) } else sp = args[nargs - 1]; process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); if (!exact) mush_free((Malloc_t) tbuf1, "replace_string.buff"); } @@ -375,7 +375,7 @@ FUNCTION(fun_reswitch) dp = mstr; sp = args[0]; process_expression(mstr, &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *dp = '\0'; /* try matching, return match immediately when found */ @@ -384,7 +384,7 @@ FUNCTION(fun_reswitch) dp = pstr; sp = args[j]; process_expression(pstr, &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *dp = '\0'; if (quick_regexp_match(pstr, mstr, cs)) { @@ -396,12 +396,12 @@ FUNCTION(fun_reswitch) sp = tbuf1; per = process_expression(buff, bp, &sp, - executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + executor, caller, enactor, + PE_DEFAULT, PT_DEFAULT, pe_info); mush_free((Malloc_t) tbuf1, "replace_string.buff"); found = 1; if (per || first) - return; + return; } } @@ -410,7 +410,7 @@ FUNCTION(fun_reswitch) tbuf1 = replace_string("#$", mstr, args[nargs - 1]); sp = tbuf1; process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); mush_free((Malloc_t) tbuf1, "replace_string.buff"); } } @@ -424,16 +424,16 @@ FUNCTION(fun_if) tp = tbuf; sp = args[0]; process_expression(tbuf, &tp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *tp = '\0'; if (parse_boolean(tbuf)) { sp = args[1]; process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); } else if (nargs > 2) { sp = args[2]; process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); } } @@ -541,7 +541,7 @@ FUNCTION(fun_soundex) if (!args[0] || !*args[0] || !isalpha((unsigned char) *args[0]) || strchr(args[0], ' ')) { safe_str(T("#-1 FUNCTION (SOUNDEX) REQUIRES A SINGLE WORD ARGUMENT"), buff, - bp); + bp); return; } safe_str(soundex(args[0]), buff, bp); @@ -560,7 +560,7 @@ FUNCTION(fun_soundlike) || !isalpha((unsigned char) *args[1]) || strchr(args[0], ' ') || strchr(args[1], ' ')) { safe_str(T("#-1 FUNCTION (SOUNDLIKE) REQUIRES TWO ONE-WORD ARGUMENTS"), - buff, bp); + buff, bp); return; } /* soundex uses a static buffer, so we need to save it */ @@ -699,7 +699,7 @@ do_whichof(char *args[], int nargs, enum whichof_t flag, char *buff, char **bp, FUNCTION(fun_firstof) { do_whichof(args, nargs, DO_FIRSTOF, buff, bp, executor, - caller, enactor, pe_info); + caller, enactor, pe_info); } @@ -707,7 +707,7 @@ FUNCTION(fun_firstof) FUNCTION(fun_allof) { do_whichof(args, nargs, DO_ALLOF, buff, bp, executor, - caller, enactor, pe_info); + caller, enactor, pe_info); } /* Signal Shit */ diff --git a/src/funstr.c b/src/funstr.c index 8daf98e..539fc96 100644 --- a/src/funstr.c +++ b/src/funstr.c @@ -29,7 +29,7 @@ #ifdef WIN32 -#pragma warning( disable : 4761) /* NJG: disable warning re conversion */ +#pragma warning( disable : 4761) /* NJG: disable warning re conversion */ #endif HASHTAB htab_tag; /**< Hash table of safe html tags */ @@ -81,10 +81,10 @@ get_gender(dbref player) } } -char *subj[4]; /**< Subjective pronouns */ -char *poss[4]; /**< Possessive pronouns */ -char *obj[4]; /**< Objective pronouns */ -char *absp[4]; /**< Absolute possessive pronouns */ +char *subj[4]; /**< Subjective pronouns */ +char *poss[4]; /**< Possessive pronouns */ +char *obj[4]; /**< Objective pronouns */ +char *absp[4]; /**< Absolute possessive pronouns */ /** Macro to set a pronoun entry based on whether we're translating or not */ #define SET_PRONOUN(p,v,u) p = strdup((translate) ? (v) : (u)) @@ -491,7 +491,7 @@ FUNCTION(fun_comp) } switch (type) { - case 'A': /* Case-sensitive lexicographic */ + case 'A': /* Case-sensitive lexicographic */ { char left[BUFFER_LEN], right[BUFFER_LEN], *l, *r; size_t llen, rlen; @@ -500,10 +500,10 @@ FUNCTION(fun_comp) r = remove_markup(args[1], &rlen); memcpy(right, r, rlen); safe_integer(comp_gencomp(executor, left, right, ALPHANUM_LIST), buff, - bp); + bp); return; } - case 'I': /* Case-insensitive lexicographic */ + case 'I': /* Case-insensitive lexicographic */ { char left[BUFFER_LEN], right[BUFFER_LEN], *l, *r; size_t llen, rlen; @@ -512,16 +512,16 @@ FUNCTION(fun_comp) r = remove_markup(args[1], &rlen); memcpy(right, r, rlen); safe_integer(comp_gencomp(executor, left, right, INSENS_ALPHANUM_LIST), - buff, bp); + buff, bp); return; } - case 'N': /* Integers */ + case 'N': /* Integers */ if (!is_strict_integer(args[0]) || !is_strict_integer(args[1])) { safe_str(T(e_ints), buff, bp); return; } safe_integer(comp_gencomp(executor, args[0], args[1], NUMERIC_LIST), buff, - bp); + bp); return; case 'F': if (!is_strict_number(args[0]) || !is_strict_number(args[1])) { @@ -529,7 +529,7 @@ FUNCTION(fun_comp) return; } safe_integer(comp_gencomp(executor, args[0], args[1], FLOAT_LIST), buff, - bp); + bp); return; case 'D': { @@ -537,11 +537,11 @@ FUNCTION(fun_comp) a = parse_objid(args[0]); b = parse_objid(args[1]); if (a == NOTHING || b == NOTHING) { - safe_str(T("#-1 INVALID DBREF"), buff, bp); - return; + safe_str(T("#-1 INVALID DBREF"), buff, bp); + return; } safe_integer(comp_gencomp(executor, args[0], args[1], DBREF_LIST), buff, - bp); + bp); return; } default: @@ -581,9 +581,9 @@ FUNCTION(fun_lpos) for (n = 0; n < len; n++) if (pos[n] == c) { if (first) - first = 0; + first = 0; else - safe_chr(' ', buff, bp); + safe_chr(' ', buff, bp); safe_integer(n, buff, bp); } } @@ -693,19 +693,19 @@ FUNCTION(fun_tr) if (*(c + 1) && *(c + 1) == '-' && *(c + 2)) { dest = (unsigned char) *(c + 2); if (!goodchr(dest)) { - safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); - return; + safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); + return; } if (dest > cur) { - for (; cur <= dest; cur++) { - if (goodchr(cur)) - safe_chr(cur, instr, &ip); - } + for (; cur <= dest; cur++) { + if (goodchr(cur)) + safe_chr(cur, instr, &ip); + } } else { - for (; cur >= dest; cur--) { - if (goodchr(cur)) - safe_chr(cur, instr, &ip); - } + for (; cur >= dest; cur--) { + if (goodchr(cur)) + safe_chr(cur, instr, &ip); + } } c += 3; } else { @@ -731,19 +731,19 @@ FUNCTION(fun_tr) if (*(c + 1) && *(c + 1) == '-' && *(c + 2)) { dest = (unsigned char) *(c + 2); if (!goodchr(dest)) { - safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); - return; + safe_str(T("#-1 TR CANNOT ACCEPT NONPRINTING CHARS"), buff, bp); + return; } if (dest > cur) { - for (; cur <= dest; cur++) { - if (goodchr(cur)) - safe_chr(cur, outstr, &op); - } + for (; cur <= dest; cur++) { + if (goodchr(cur)) + safe_chr(cur, outstr, &op); + } } else { - for (; cur >= dest; cur--) { - if (goodchr(cur)) - safe_chr(cur, outstr, &op); - } + for (; cur >= dest; cur--) { + if (goodchr(cur)) + safe_chr(cur, outstr, &op); + } } c += 3; } else { @@ -850,7 +850,7 @@ FUNCTION(fun_repeat) while (times) { if (times & 1) { if (safe_strl(args[0], arglens[0], buff, bp) != 0) - break; + break; } safe_str(args[0], args[0], &ap); *ap = '\0'; @@ -1114,7 +1114,7 @@ FUNCTION(fun_foreach) *cbuf = *lp++; ap = asave; if (process_expression(buff, bp, &ap, thing, executor, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info)) + PE_DEFAULT, PT_DEFAULT, pe_info)) break; if (*bp == oldbp && pe_info->fun_invocations == funccount) break; @@ -1170,7 +1170,7 @@ FUNCTION(fun_escape) safe_chr('\\', buff, bp); for (s = (unsigned char *) args[0]; *s; s++) { if ((s != (unsigned char *) args[0]) && escaped_chars[*s]) - safe_chr('\\', buff, bp); + safe_chr('\\', buff, bp); safe_chr(*s, buff, bp); } } @@ -1276,14 +1276,14 @@ FUNCTION(fun_squish) tp--; tp[1] = '\0'; - for (tp = args[0]; *tp == sep; tp++) /* skip leading spaces */ + for (tp = args[0]; *tp == sep; tp++) /* skip leading spaces */ ; while (*tp) { safe_chr(*tp, buff, bp); if (*tp == sep) while (*tp == sep) - tp++; + tp++; else tp++; } @@ -1372,7 +1372,7 @@ FUNCTION(fun_ord) m = remove_markup(args[0], &len); what = (unsigned char) *m; - if (len != 2) /* len includes trailing nul */ + if (len != 2) /* len includes trailing nul */ safe_str(T("#-1 FUNCTION (ORD) EXPECTS ONE CHARACTER"), buff, bp); else if(isprint(what) || what == '\n') safe_integer((unsigned char) *m, buff, bp); @@ -1438,8 +1438,8 @@ FUNCTION(fun_tag) safe_strl(args[0], arglens[0], buff, bp); for (i = 1; i < nargs; i++) { if (ok_tag_attribute(executor, args[i])) { - safe_chr(' ', buff, bp); - safe_strl(args[i], arglens[i], buff, bp); + safe_chr(' ', buff, bp); + safe_strl(args[i], arglens[i], buff, bp); } } safe_chr(TAG_END, buff, bp); @@ -1468,30 +1468,30 @@ FUNCTION(fun_tagwrap) } } -#define COL_FLASH (1) /**< ANSI flash attribute bit */ -#define COL_HILITE (2) /**< ANSI hilite attribute bit */ -#define COL_INVERT (4) /**< ANSI inverse attribute bit */ -#define COL_UNDERSCORE (8) /**< ANSI underscore attribute bit */ - -#define VAL_FLASH (5) /**< ANSI flag attribute value */ -#define VAL_HILITE (1) /**< ANSI hilite attribute value */ -#define VAL_INVERT (7) /**< ANSI inverse attribute value */ -#define VAL_UNDERSCORE (4) /**< ANSI underscore attribute value */ - -#define COL_BLACK (30) /**< ANSI color black */ -#define COL_RED (31) /**< ANSI color red */ -#define COL_GREEN (32) /**< ANSI color green */ -#define COL_YELLOW (33) /**< ANSI color yellow */ -#define COL_BLUE (34) /**< ANSI color blue */ -#define COL_MAGENTA (35) /**< ANSI color magenta */ -#define COL_CYAN (36) /**< ANSI color cyan */ -#define COL_WHITE (37) /**< ANSI color white */ +#define COL_FLASH (1) /**< ANSI flash attribute bit */ +#define COL_HILITE (2) /**< ANSI hilite attribute bit */ +#define COL_INVERT (4) /**< ANSI inverse attribute bit */ +#define COL_UNDERSCORE (8) /**< ANSI underscore attribute bit */ + +#define VAL_FLASH (5) /**< ANSI flag attribute value */ +#define VAL_HILITE (1) /**< ANSI hilite attribute value */ +#define VAL_INVERT (7) /**< ANSI inverse attribute value */ +#define VAL_UNDERSCORE (4) /**< ANSI underscore attribute value */ + +#define COL_BLACK (30) /**< ANSI color black */ +#define COL_RED (31) /**< ANSI color red */ +#define COL_GREEN (32) /**< ANSI color green */ +#define COL_YELLOW (33) /**< ANSI color yellow */ +#define COL_BLUE (34) /**< ANSI color blue */ +#define COL_MAGENTA (35) /**< ANSI color magenta */ +#define COL_CYAN (36) /**< ANSI color cyan */ +#define COL_WHITE (37) /**< ANSI color white */ /** The ansi attributes associated with a character. */ typedef struct { - char flags; /**< Ansi text attributes */ - char fore; /**< Ansi foreground color */ - char back; /**< Ansi background color */ + char flags; /**< Ansi text attributes */ + char fore; /**< Ansi foreground color */ + char back; /**< Ansi background color */ } ansi_data; static void dump_ansi_codes(ansi_data * ad, char *buff, char **bp); @@ -1577,7 +1577,7 @@ FUNCTION(fun_ansi) tbp = tbuff; arg0 = args[0]; process_expression(tbuff, &tbp, &arg0, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *tbp = '\0'; sp[1] = sp[0]; @@ -1585,81 +1585,81 @@ FUNCTION(fun_ansi) for (tbp = tbuff; *tbp; tbp++) { switch (*tbp) { - case 'n': /* normal */ + case 'n': /* normal */ sp->flags = 0; sp->fore = 0; sp->back = 0; break; - case 'f': /* flash */ + case 'f': /* flash */ sp->flags |= COL_FLASH; break; - case 'h': /* hilite */ + case 'h': /* hilite */ sp->flags |= COL_HILITE; break; - case 'i': /* inverse */ + case 'i': /* inverse */ sp->flags |= COL_INVERT; break; - case 'u': /* underscore */ + case 'u': /* underscore */ sp->flags |= COL_UNDERSCORE; break; - case 'F': /* flash */ + case 'F': /* flash */ sp->flags &= ~COL_FLASH; break; - case 'H': /* hilite */ + case 'H': /* hilite */ sp->flags &= ~COL_HILITE; break; - case 'I': /* inverse */ + case 'I': /* inverse */ sp->flags &= ~COL_INVERT; break; - case 'U': /* underscore */ + case 'U': /* underscore */ sp->flags &= ~COL_UNDERSCORE; break; - case 'b': /* blue fg */ + case 'b': /* blue fg */ sp->fore = COL_BLUE; break; - case 'c': /* cyan fg */ + case 'c': /* cyan fg */ sp->fore = COL_CYAN; break; - case 'g': /* green fg */ + case 'g': /* green fg */ sp->fore = COL_GREEN; break; - case 'm': /* magenta fg */ + case 'm': /* magenta fg */ sp->fore = COL_MAGENTA; break; - case 'r': /* red fg */ + case 'r': /* red fg */ sp->fore = COL_RED; break; - case 'w': /* white fg */ + case 'w': /* white fg */ sp->fore = COL_WHITE; break; - case 'x': /* black fg */ + case 'x': /* black fg */ sp->fore = COL_BLACK; break; - case 'y': /* yellow fg */ + case 'y': /* yellow fg */ sp->fore = COL_YELLOW; break; - case 'B': /* blue bg */ + case 'B': /* blue bg */ sp->back = COL_BLUE; break; - case 'C': /* cyan bg */ + case 'C': /* cyan bg */ sp->back = COL_CYAN; break; - case 'G': /* green bg */ + case 'G': /* green bg */ sp->back = COL_GREEN; break; - case 'M': /* magenta bg */ + case 'M': /* magenta bg */ sp->back = COL_MAGENTA; break; - case 'R': /* red bg */ + case 'R': /* red bg */ sp->back = COL_RED; break; - case 'W': /* white bg */ + case 'W': /* white bg */ sp->back = COL_WHITE; break; - case 'X': /* black bg */ + case 'X': /* black bg */ sp->back = COL_BLACK; break; - case 'Y': /* yellow bg */ + case 'Y': /* yellow bg */ sp->back = COL_YELLOW; break; } @@ -1669,7 +1669,7 @@ FUNCTION(fun_ansi) arg1 = args[1]; process_expression(buff, bp, &arg1, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); dump_ansi_codes(--sp, buff, bp); @@ -1702,8 +1702,8 @@ FUNCTION(fun_edit) for (i = 1; i < nargs - 1; i += 2) { postp = postbuf; - f = args[i]; /* find this */ - r = args[i + 1]; /* replace it with this */ + f = args[i]; /* find this */ + r = args[i + 1]; /* replace it with this */ flen = arglens[i]; rlen = arglens[i + 1]; @@ -1724,21 +1724,21 @@ FUNCTION(fun_edit) size_t last; safe_strl(r, rlen, postbuf, &postp); for (last = 0; last < prebuf->len; last++) { - safe_ansi_string(prebuf, last, 1, postbuf, &postp); - safe_strl(r, rlen, postbuf, &postp); + safe_ansi_string(prebuf, last, 1, postbuf, &postp); + safe_strl(r, rlen, postbuf, &postp); } } else { char *p; size_t last = 0; while (last < prebuf->len && (p = strstr(prebuf->text + last, f)) != NULL) { - safe_ansi_string(prebuf, last, p - (prebuf->text + last), - postbuf, &postp); - safe_strl(r, rlen, postbuf, &postp); - last = p - prebuf->text + flen; + safe_ansi_string(prebuf, last, p - (prebuf->text + last), + postbuf, &postp); + safe_strl(r, rlen, postbuf, &postp); + last = p - prebuf->text + flen; } if (last < prebuf->len) - safe_ansi_string(prebuf, last, prebuf->len, postbuf, &postp); + safe_ansi_string(prebuf, last, prebuf->len, postbuf, &postp); } *postp = '\0'; free_ansi_string(prebuf); @@ -1756,7 +1756,7 @@ FUNCTION(fun_brackets) int rbrack, lbrack, rbrace, lbrace, lcurl, rcurl; lcurl = rcurl = rbrack = lbrack = rbrace = lbrace = 0; - str = args[0]; /* The string to count the brackets in */ + str = args[0]; /* The string to count the brackets in */ while (*str) { switch (*str) { case '[': @@ -1783,7 +1783,7 @@ FUNCTION(fun_brackets) str++; } safe_format(buff, bp, "%d %d %d %d %d %d", lbrack, rbrack, - lbrace, rbrace, lcurl, rcurl); + lbrace, rbrace, lcurl, rcurl); } @@ -1803,7 +1803,7 @@ wraplen(char *str, int maxlen) */ while (i < length) { if ((str[i] == '\n') || (str[i] == '\r')) - return i; + return i; i++; } return length; @@ -1852,9 +1852,9 @@ FUNCTION(fun_wrap) * args[3] = output delimiter (btwn lines) */ - char *pstr; /* start of string */ + char *pstr; /* start of string */ ansi_string *as; - const char *pend; /* end of string */ + const char *pend; /* end of string */ int linewidth, width1st, width; int linenr = 0; const char *linesep; @@ -1897,13 +1897,13 @@ FUNCTION(fun_wrap) /* word doesn't fit on one line, so cut it */ safe_ansi_string2(as, pstr - as->text, ansiwidth - 1, buff, bp); safe_chr('-', buff, bp); - pstr += ansiwidth - 1; /* move to start of next line */ + pstr += ansiwidth - 1; /* move to start of next line */ } else { /* normal line */ safe_ansi_string2(as, pstr - as->text, ansilen, buff, bp); if (pstr[ansilen] == '\r') - ++ansilen; - pstr += ansilen + 1; /* move to start of next line */ + ++ansilen; + pstr += ansilen + 1; /* move to start of next line */ } } free_ansi_string(as); @@ -1918,10 +1918,10 @@ FUNCTION(fun_wrap) static int align_one_line(char *buff, char **bp, int ncols, - int cols[MAX_COLS], int calign[MAX_COLS], char *ptrs[MAX_COLS], - ansi_string *as[MAX_COLS], - int linenum, char *fieldsep, int fslen, - char *linesep, int lslen, char filler) + int cols[MAX_COLS], int calign[MAX_COLS], char *ptrs[MAX_COLS], + ansi_string *as[MAX_COLS], + int linenum, char *fieldsep, int fslen, + char *linesep, int lslen, char filler) { static char line[BUFFER_LEN]; static char segment[BUFFER_LEN]; @@ -1940,13 +1940,13 @@ align_one_line(char *buff, char **bp, int ncols, for (i = 0; i < ncols; i++) { if (!ptrs[i] || !*ptrs[i]) { if (calign[i] & AL_REPEAT) { - ptrs[i] = as[i]->text; + ptrs[i] = as[i]->text; } else { - lp += cols[i]; - if (i < (ncols - 1) && fslen) - safe_str(fieldsep, line, &lp); - cols_done++; - continue; + lp += cols[i]; + if (i < (ncols - 1) && fslen) + safe_str(fieldsep, line, &lp); + cols_done++; + continue; } } if (calign[i] & AL_REPEAT) { @@ -1954,24 +1954,24 @@ align_one_line(char *buff, char **bp, int ncols, } for (len = 0, ptr = ptrs[i], lastspace = NULL; len < cols[i]; ptr++, len++) { if ((!*ptr) || (*ptr == '\n')) - break; + break; if (isspace((unsigned char) *ptr)) { - lastspace = ptr; + lastspace = ptr; } } skipspace = 0; sp = segment; if (!*ptr) { if (len > 0) { - safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); + safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); } ptrs[i] = ptr; } else if (*ptr == '\n') { for (tptr = ptr; - *tptr && tptr >= ptrs[i] && isspace((unsigned char) *tptr); tptr--) ; + *tptr && tptr >= ptrs[i] && isspace((unsigned char) *tptr); tptr--) ; len = (tptr - ptrs[i]) + 1; if (len > 0) { - safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); + safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); } ptrs[i] = ptr + 1; ptr = tptr; @@ -1979,15 +1979,15 @@ align_one_line(char *buff, char **bp, int ncols, ptr = lastspace; skipspace = 1; for (tptr = ptr; - *tptr && tptr >= ptrs[i] && isspace((unsigned char) *tptr); tptr--) ; + *tptr && tptr >= ptrs[i] && isspace((unsigned char) *tptr); tptr--) ; len = (tptr - ptrs[i]) + 1; if (len > 0) { - safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); + safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); } ptrs[i] = lastspace; } else { if (len > 0) { - safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); + safe_ansi_string2(as[i], ptrs[i] - (as[i]->text), len, segment, &sp); } ptrs[i] = ptr; } @@ -2011,8 +2011,8 @@ align_one_line(char *buff, char **bp, int ncols, safe_str(fieldsep, line, &lp); if (skipspace) for (; - *ptrs[i] && (*ptrs[i] != '\n') && isspace((unsigned char) *ptrs[i]); - ptrs[i]++) ; + *ptrs[i] && (*ptrs[i] != '\n') && isspace((unsigned char) *ptrs[i]); + ptrs[i]++) ; } if (cols_done == ncols) return 0; @@ -2126,7 +2126,7 @@ FUNCTION(fun_align) nline = 0; while (1) { if (!align_one_line(buff, bp, ncols, cols, calign, ptrs, - as, nline++, fieldsep, fslen, linesep, lslen, filler)) + as, nline++, fieldsep, fslen, linesep, lslen, filler)) break; } **bp = '\0'; @@ -2213,7 +2213,7 @@ FUNCTION(fun_speak) if (*string == ' ') { /* semipose it instead */ while (*string == ' ') - string++; + string++; } else safe_chr(' ', buff, bp); break; @@ -2224,7 +2224,7 @@ FUNCTION(fun_speak) /* pose it instead */ safe_chr(' ', buff, bp); while (*string == ' ') - string++; + string++; } break; case '|': @@ -2242,7 +2242,7 @@ FUNCTION(fun_speak) /* nice and easy */ if (say) safe_format(buff, bp, "%s %s \"%s\"", accented_name(speaker), - say_string, string); + say_string, string); else safe_str(string, buff, bp); LEAVE_OOREF; @@ -2289,48 +2289,48 @@ FUNCTION(fun_speak) } funccount = pe_info->fun_invocations; while (!finished && ((say && fragment == 0 && (speech = string)) - || (speech = strstr(string, open)))) { + || (speech = strstr(string, open)))) { fragment++; indx = string - speech; if (indx < 0) - indx *= -1; + indx *= -1; if (string != NULL && strlen(string) > 0 && indx > 0) - safe_strl(string, indx, buff, bp); + safe_strl(string, indx, buff, bp); if (!say || fragment > 1) - speech = speech + strlen(open); /* move past open char */ + speech = speech + strlen(open); /* move past open char */ /* find close-char */ string = strstr(speech, close); if (!string || !(string = string + strlen(close))) { - /* no close char, or nothing after it; we're at the end! */ - finished = 1; + /* no close char, or nothing after it; we're at the end! */ + finished = 1; } delete = (string == NULL ? strlen(speech) : strlen(speech) - - (strlen(string) + strlen(close))); + (strlen(string) + strlen(close))); speech = chopstr(speech, delete); wenv[0] = speech; wenv[1] = speaker_str; wenv[2] = unparse_integer(fragment); if (call_ufun(&transufun, wenv, 3, rbuff, executor, enactor, pe_info)) - break; + break; if (*bp == (buff + BUFFER_LEN - 1) && - pe_info->fun_invocations == funccount) - break; + pe_info->fun_invocations == funccount) + break; funccount = pe_info->fun_invocations; if ((null == 1) && (strlen(rbuff) == 0)) { - wenv[0] = speaker_str; - wenv[1] = unparse_integer(fragment); - if (call_ufun(&nullufun, wenv, 2, rbuff, executor, enactor, pe_info)) - break; + wenv[0] = speaker_str; + wenv[1] = unparse_integer(fragment); + if (call_ufun(&nullufun, wenv, 2, rbuff, executor, enactor, pe_info)) + break; } if (strlen(rbuff) > 0) { - safe_str(rbuff, buff, bp); + safe_str(rbuff, buff, bp); } if (*bp == (buff + BUFFER_LEN - 1) && - pe_info->fun_invocations == funccount) - break; + pe_info->fun_invocations == funccount) + break; } if (string != NULL && strlen(string) > 0) { - safe_str(string, buff, bp); /* remaining string (not speech, so not t) */ + safe_str(string, buff, bp); /* remaining string (not speech, so not t) */ } } diff --git a/src/funtime.c b/src/funtime.c index aa9bec5..dc2e1c5 100644 --- a/src/funtime.c +++ b/src/funtime.c @@ -28,7 +28,7 @@ int do_convtime(const char *str, struct tm *ttm); void do_timestring(char *buff, char **bp, const char *format, - unsigned long secs); + unsigned long secs); extern char valid_timefmt_codes[256]; @@ -40,7 +40,7 @@ FUNCTION(fun_timefmt) int len, n; if (!args[0] || !*args[0]) - return; /* No field? Bad user. */ + return; /* No field? Bad user. */ if (nargs == 2) { /* This is silly, but time_t is signed on several platforms, @@ -71,11 +71,11 @@ FUNCTION(fun_timefmt) args[0][n] = '%'; n++; if (args[0][n] == '$') - args[0][n] = '%'; + args[0][n] = '%'; else if (!valid_timefmt_codes[(unsigned char) args[0][n]]) { - safe_format(buff, bp, T("#-1 INVALID ESCAPE CODE '$%c'"), - args[0][n] ? args[0][n] : ' '); - return; + safe_format(buff, bp, T("#-1 INVALID ESCAPE CODE '$%c'"), + args[0][n] ? args[0][n] : ' '); + return; } } } @@ -284,37 +284,37 @@ FUNCTION(fun_stringsecs) i++; } if (i == 0) { - safe_str(T("#-1 INVALID TIMESTRING"), buff, bp); // no numbers + safe_str(T("#-1 INVALID TIMESTRING"), buff, bp); /* no numbers */ return; } str2[i] = '\0'; if (!*str1) { - secs += parse_integer(str2); // no more chars, just add seconds and stop + secs += parse_integer(str2); /* no more chars, just add seconds and stop */ break; } switch (*str1) { case 'd': case 'D': - secs += (parse_integer(str2) * 86400); // days + secs += (parse_integer(str2) * 86400); /* days */ break; case 'h': case 'H': - secs += (parse_integer(str2) * 3600); // hours + secs += (parse_integer(str2) * 3600); /* hours */ break; case 'm': case 'M': - secs += (parse_integer(str2) * 60); // minutes + secs += (parse_integer(str2) * 60); /* minutes */ break; case 's': case 'S': case ' ': - secs += parse_integer(str2); // seconds + secs += parse_integer(str2); /* seconds */ break; default: safe_str(T("#-1 INVALID TIMESTRING"), buff, bp); return; } - str1++; // move past the time char + str1++; /* move past the time char */ } safe_integer(secs, buff, bp); } @@ -389,7 +389,7 @@ do_convtime_gd(const char *str, struct tm *ttm) #ifdef NEVER if (getdate_err <= 7) do_rawlog(LT_ERR, "getdate returned error code %d for %s", getdate_err, - str); + str); #endif return 0; } @@ -456,14 +456,14 @@ do_convtime(const char *mystr, struct tm *ttm) if (strlen(p) != 3) return 0; for (i = 0; (i < 12) && strcmp(month_table[i], p); i++) ; - if (i == 12) /* not found */ + if (i == 12) /* not found */ return 0; else ttm->tm_mon = i; /* get the day of month */ p = q; - while (isspace((unsigned char) *p)) /* skip leading space */ + while (isspace((unsigned char) *p)) /* skip leading space */ p++; if (!(q = strchr(p, ' '))) return 0; @@ -567,137 +567,137 @@ do_timestring(char *buff, char **bp, const char *format, unsigned long secs) c++; width = strtol(c, &w, 10); if (c == w) - pad = 0; + pad = 0; else - pad = 1; + pad = 1; if (width < 0) - width = 0; + width = 0; else if (width >= BUFFER_LEN) - width = BUFFER_LEN - 1; + width = BUFFER_LEN - 1; even_if_0 = in_format_flags = 1; include_suffix = 0; while (in_format_flags) { - switch (*w) { - case 'x': - case 'X': - include_suffix = 1; - w++; - break; - case 'z': - case 'Z': - even_if_0 = 0; - w++; - break; - case '$': - in_format_flags = 0; - if (pad) - safe_format(buff, bp, "%*c", width, '$'); - else - safe_chr('$', buff, bp); - break; - case 's': - in_format_flags = 0; - if (secs || even_if_0) { - if (pad) - safe_format(buff, bp, "%*lu", width, secs); - else - safe_uinteger(secs, buff, bp); - if (include_suffix) - safe_chr('s', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'S': - in_format_flags = 0; - if (secs || even_if_0) { - if (pad) - safe_format(buff, bp, "%0*lu", width, secs); - else - safe_format(buff, bp, "%0lu", secs); - if (include_suffix) - safe_chr('s', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'm': - in_format_flags = 0; - if (mins || even_if_0) { - if (pad) - safe_format(buff, bp, "%*d", width, mins); - else - safe_integer(mins, buff, bp); - if (include_suffix) - safe_chr('m', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'M': - in_format_flags = 0; - if (mins || even_if_0) { - if (pad) - safe_format(buff, bp, "%0*d", width, mins); - else - safe_format(buff, bp, "%0d", mins); - if (include_suffix) - safe_chr('m', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'h': - in_format_flags = 0; - if (hours || even_if_0) { - if (pad) - safe_format(buff, bp, "%*d", width, hours); - else - safe_integer(hours, buff, bp); - if (include_suffix) - safe_chr('h', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'H': - in_format_flags = 0; - if (hours || even_if_0) { - if (pad) - safe_format(buff, bp, "%0*d", width, hours); - else - safe_format(buff, bp, "%0d", hours); - if (include_suffix) - safe_chr('h', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'd': - in_format_flags = 0; - if (days || even_if_0) { - if (pad) - safe_format(buff, bp, "%*d", width, days); - else - safe_integer(days, buff, bp); - if (include_suffix) - safe_chr('d', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - case 'D': - in_format_flags = 0; - if (days || even_if_0) { - if (pad) - safe_format(buff, bp, "%0*d", width, days); - else - safe_format(buff, bp, "%0d", days); - if (include_suffix) - safe_chr('d', buff, bp); - } else if (pad) - safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); - break; - default: - in_format_flags = 0; - safe_chr('$', buff, bp); - for (; c != w; c++) - safe_chr(*c, buff, bp); - safe_chr(*c, buff, bp); - } + switch (*w) { + case 'x': + case 'X': + include_suffix = 1; + w++; + break; + case 'z': + case 'Z': + even_if_0 = 0; + w++; + break; + case '$': + in_format_flags = 0; + if (pad) + safe_format(buff, bp, "%*c", width, '$'); + else + safe_chr('$', buff, bp); + break; + case 's': + in_format_flags = 0; + if (secs || even_if_0) { + if (pad) + safe_format(buff, bp, "%*lu", width, secs); + else + safe_uinteger(secs, buff, bp); + if (include_suffix) + safe_chr('s', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'S': + in_format_flags = 0; + if (secs || even_if_0) { + if (pad) + safe_format(buff, bp, "%0*lu", width, secs); + else + safe_format(buff, bp, "%0lu", secs); + if (include_suffix) + safe_chr('s', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'm': + in_format_flags = 0; + if (mins || even_if_0) { + if (pad) + safe_format(buff, bp, "%*d", width, mins); + else + safe_integer(mins, buff, bp); + if (include_suffix) + safe_chr('m', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'M': + in_format_flags = 0; + if (mins || even_if_0) { + if (pad) + safe_format(buff, bp, "%0*d", width, mins); + else + safe_format(buff, bp, "%0d", mins); + if (include_suffix) + safe_chr('m', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'h': + in_format_flags = 0; + if (hours || even_if_0) { + if (pad) + safe_format(buff, bp, "%*d", width, hours); + else + safe_integer(hours, buff, bp); + if (include_suffix) + safe_chr('h', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'H': + in_format_flags = 0; + if (hours || even_if_0) { + if (pad) + safe_format(buff, bp, "%0*d", width, hours); + else + safe_format(buff, bp, "%0d", hours); + if (include_suffix) + safe_chr('h', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'd': + in_format_flags = 0; + if (days || even_if_0) { + if (pad) + safe_format(buff, bp, "%*d", width, days); + else + safe_integer(days, buff, bp); + if (include_suffix) + safe_chr('d', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + case 'D': + in_format_flags = 0; + if (days || even_if_0) { + if (pad) + safe_format(buff, bp, "%0*d", width, days); + else + safe_format(buff, bp, "%0d", days); + if (include_suffix) + safe_chr('d', buff, bp); + } else if (pad) + safe_fill(' ', width + (include_suffix ? 1 : 0), buff, bp); + break; + default: + in_format_flags = 0; + safe_chr('$', buff, bp); + for (; c != w; c++) + safe_chr(*c, buff, bp); + safe_chr(*c, buff, bp); + } } c = w; } else @@ -706,5 +706,5 @@ do_timestring(char *buff, char **bp, const char *format, unsigned long secs) } #ifdef WIN32 -#pragma warning( default : 4761) /* NJG: enable warning re conversion */ +#pragma warning( default : 4761) /* NJG: enable warning re conversion */ #endif diff --git a/src/funufun.c b/src/funufun.c index cbaa6e6..2c2f79f 100644 --- a/src/funufun.c +++ b/src/funufun.c @@ -22,8 +22,8 @@ #include "confmagic.h" void do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, - char **args, dbref executor, dbref caller, dbref enactor, - PE_Info * pe_info); + char **args, dbref executor, dbref caller, dbref enactor, + PE_Info * pe_info); /* ARGSUSED */ FUNCTION(fun_s) @@ -31,7 +31,7 @@ FUNCTION(fun_s) char const *p; p = args[0]; process_expression(buff, bp, &p, executor, caller, enactor, PE_DEFAULT, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); } /* ARGSUSED */ @@ -44,7 +44,7 @@ FUNCTION(fun_localize) p = args[0]; process_expression(buff, bp, &p, executor, caller, enactor, PE_DEFAULT, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); restore_global_regs("localize", saver); } @@ -66,7 +66,7 @@ FUNCTION(fun_objeval) s = name; p = args[0]; process_expression(name, &s, &p, executor, caller, enactor, PE_DEFAULT, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); *s = '\0'; if (FUNCTION_SIDE_EFFECTS) { @@ -107,8 +107,8 @@ FUNCTION(fun_objeval) */ void do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, - char **args, dbref executor, dbref caller - __attribute__ ((__unused__)), dbref enactor, PE_Info * pe_info) + char **args, dbref executor, dbref caller + __attribute__ ((__unused__)), dbref enactor, PE_Info * pe_info) { int j; char *tptr[10]; @@ -123,7 +123,7 @@ do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, /* copy the appropriate args into the stack */ if (nargs > 10) - nargs = 10; /* maximum ten args */ + nargs = 10; /* maximum ten args */ for (j = 0; j < nargs; j++) global_eval_context.wenv[j] = args[j]; for (; j < 10; j++) @@ -137,7 +137,7 @@ do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs, if (attrib->flags & AF_DEBUG) pe_flags |= PE_DEBUG; process_expression(buff, bp, &tp, obj, executor, enactor, pe_flags, - PT_DEFAULT, pe_info); + PT_DEFAULT, pe_info); free(tbuf); /* restore the stack */ @@ -250,7 +250,7 @@ FUNCTION(fun_uldefault) dp = mstr; sp = args[0]; process_expression(mstr, &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); *dp = '\0'; parse_attrib(executor, mstr, &thing, &attrib); if (GoodObject(thing) && attrib && CanEvalAttr(executor, thing, attrib) @@ -261,27 +261,27 @@ FUNCTION(fun_uldefault) xargs = NULL; if (nargs > 2) { xargs = - (char **) mush_malloc((nargs - 2) * sizeof(char *), "udefault.xargs"); + (char **) mush_malloc((nargs - 2) * sizeof(char *), "udefault.xargs"); for (i = 0; i < nargs - 2; i++) { - xargs[i] = (char *) mush_malloc(BUFFER_LEN, "udefault"); - dp = xargs[i]; - sp = args[i + 2]; - process_expression(xargs[i], &dp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); - *dp = '\0'; + xargs[i] = (char *) mush_malloc(BUFFER_LEN, "udefault"); + dp = xargs[i]; + sp = args[i + 2]; + process_expression(xargs[i], &dp, &sp, executor, caller, enactor, + PE_DEFAULT, PT_DEFAULT, pe_info); + *dp = '\0'; } } if (called_as[1] == 'L') save_global_regs("uldefault.save", preserve); do_userfn(buff, bp, thing, attrib, nargs - 2, xargs, - executor, caller, enactor, pe_info); + executor, caller, enactor, pe_info); if (called_as[1] == 'L') restore_global_regs("uldefault.save", preserve); /* Free the xargs */ if (nargs > 2) { for (i = 0; i < nargs - 2; i++) - mush_free(xargs[i], "udefault"); + mush_free(xargs[i], "udefault"); mush_free(xargs, "udefault.xargs"); } LEAVE_OOREF; @@ -293,7 +293,7 @@ FUNCTION(fun_uldefault) if (called_as[1] == 'L') save_global_regs("uldefault.save", preserve); process_expression(buff, bp, &sp, executor, caller, enactor, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); if (called_as[1] == 'L') restore_global_regs("uldefault.save", preserve); diff --git a/src/game.c b/src/game.c index 5b02bbc..d596007 100644 --- a/src/game.c +++ b/src/game.c @@ -27,7 +27,7 @@ #ifdef WIN32 #include #include -#undef OPAQUE /* Clashes with flags.h */ +#undef OPAQUE /* Clashes with flags.h */ void Win32MUSH_setup(void); #endif #ifdef I_SYS_TYPES @@ -77,7 +77,7 @@ void Win32MUSH_setup(void); #ifdef hpux #include #define getrusage(x,p) syscall(SYS_GETRUSAGE,x,p) -#endif /* fix to HP-UX getrusage() braindamage */ +#endif /* fix to HP-UX getrusage() braindamage */ #include "confmagic.h" #ifdef HAS_WAITPID @@ -114,17 +114,17 @@ static int fail_commands(dbref player); void do_readcache(dbref player); int check_alias(const char *command, const char *list); int list_check(dbref thing, dbref player, char type, - char end, char *str, int just_match); + char end, char *str, int just_match); int alias_list_check(dbref thing, const char *command, const char *type); int loc_alias_check(dbref loc, const char *command, const char *type); void do_poor(dbref player, char *arg1); void do_writelog(dbref player, char *str, int ltype); void bind_and_queue(dbref player, dbref cause, char *action, const char *arg, - const char *placestr); + const char *placestr); void do_scan(dbref player, char *command, int flag); void do_list(dbref player, char *arg, int lc); void do_dolist(dbref player, char *list, char *command, - dbref cause, unsigned int flags); + dbref cause, unsigned int flags); void do_uptime(dbref player, int mortal); static char *make_new_epoch_file(const char *basename, int the_epoch); #ifdef HAS_GETRUSAGE @@ -194,41 +194,41 @@ do_dump(dbref player, char *num, enum dump_type flag) /* want to do a scan before dumping each object */ globals.paranoid_dump = 1; if (num && *num) { - /* checkpoint interval given */ - globals.paranoid_checkpt = atoi(num); - if ((globals.paranoid_checkpt < 1) - || (globals.paranoid_checkpt >= db_top)) { - notify(player, T("Permission denied. Invalid checkpoint interval.")); - globals.paranoid_dump = 0; - return; - } + /* checkpoint interval given */ + globals.paranoid_checkpt = atoi(num); + if ((globals.paranoid_checkpt < 1) + || (globals.paranoid_checkpt >= db_top)) { + notify(player, T("Permission denied. Invalid checkpoint interval.")); + globals.paranoid_dump = 0; + return; + } } else { - /* use a default interval */ - globals.paranoid_checkpt = db_top / 5; - if (globals.paranoid_checkpt < 1) - globals.paranoid_checkpt = 1; + /* use a default interval */ + globals.paranoid_checkpt = db_top / 5; + if (globals.paranoid_checkpt < 1) + globals.paranoid_checkpt = 1; } if (flag == DUMP_PARANOID) { - notify_format(player, T("Paranoid dumping, checkpoint interval %d."), - globals.paranoid_checkpt); - do_rawlog(LT_CHECK, - "*** PARANOID DUMP *** done by %s(#%d),\n", - Name(player), player); + notify_format(player, T("Paranoid dumping, checkpoint interval %d."), + globals.paranoid_checkpt); + do_rawlog(LT_CHECK, + "*** PARANOID DUMP *** done by %s(#%d),\n", + Name(player), player); } else { - notify_format(player, T("Debug dumping, checkpoint interval %d."), - globals.paranoid_checkpt); - do_rawlog(LT_CHECK, - "*** DEBUG DUMP *** done by %s(#%d),\n", - Name(player), player); + notify_format(player, T("Debug dumping, checkpoint interval %d."), + globals.paranoid_checkpt); + do_rawlog(LT_CHECK, + "*** DEBUG DUMP *** done by %s(#%d),\n", + Name(player), player); } do_rawlog(LT_CHECK, T("\tcheckpoint interval %d, at %s"), - globals.paranoid_checkpt, show_time(mudtime, 0)); + globals.paranoid_checkpt, show_time(mudtime, 0)); } else { /* normal dump */ - globals.paranoid_dump = 0; /* just to be safe */ + globals.paranoid_dump = 0; /* just to be safe */ notify(player, "Dumping..."); do_rawlog(LT_CHECK, "** DUMP ** done by %s(#%d) at %s", - Name(player), player, show_time(mudtime, 0)); + Name(player), player, show_time(mudtime, 0)); } fork_and_dump(1); globals.paranoid_dump = 0; @@ -302,7 +302,7 @@ do_shutdown(dbref player, enum shutdown_type flag) { flag_broadcast(0, 0, T("GAME: Shutdown by %s"), Name(player)); do_log(LT_ERR, player, NOTHING, T("SHUTDOWN by %s(%s)\n"), - Name(player), unparse_dbref(player)); + Name(player), unparse_dbref(player)); /* This will create a file used to check if a restart should occur */ #ifdef AUTORESTART @@ -313,10 +313,10 @@ do_shutdown(dbref player, enum shutdown_type flag) mush_panic("@shutdown/panic"); } else { if (flag == SHUT_PARANOID) { - globals.paranoid_checkpt = db_top / 5; - if (globals.paranoid_checkpt < 1) - globals.paranoid_checkpt = 1; - globals.paranoid_dump = 1; + globals.paranoid_checkpt = db_top / 5; + if (globals.paranoid_checkpt < 1) + globals.paranoid_checkpt = 1; + globals.paranoid_dump = 1; } shutdown_flag = 1; } @@ -480,9 +480,9 @@ mush_panic(const char *message) if (already_panicking) { do_rawlog(LT_ERR, - T - ("PANIC: Attempted to panic because of '%s' while already panicking. Run in circles, scream and shout!"), - message); + T + ("PANIC: Attempted to panic because of '%s' while already panicking. Run in circles, scream and shout!"), + message); _exit(133); } @@ -594,7 +594,7 @@ fork_and_dump(int forking) if (NO_FORK) nofork = 1; else - nofork = !forking || (globals.paranoid_dump == 2); /* Don't fork for dump/debug */ + nofork = !forking || (globals.paranoid_dump == 2); /* Don't fork for dump/debug */ #ifdef WIN32 nofork = 1; #endif @@ -619,14 +619,14 @@ fork_and_dump(int forking) if (child < 0) { /* Oops, fork failed. Let's do a nofork dump */ do_log(LT_ERR, 0, 0, - "fork_and_dump: fork() failed! Dumping nofork instead."); + "fork_and_dump: fork() failed! Dumping nofork instead."); if (DUMP_NOFORK_MESSAGE && *DUMP_NOFORK_MESSAGE) - flag_broadcast(0, 0, "%s", DUMP_NOFORK_MESSAGE); + flag_broadcast(0, 0, "%s", DUMP_NOFORK_MESSAGE); child = 0; nofork = 1; if (split) { - split = 0; - chunk_fork_done(); + split = 0; + chunk_fork_done(); } } else if (child > 0) { forked_dump_pid = child; @@ -637,12 +637,12 @@ fork_and_dump(int forking) /* Lower the priority of the child to make parent more responsive */ #ifdef HAS_GETPRIORITY setpriority(PRIO_PROCESS, child, getpriority(PRIO_PROCESS, child) + 4); -#else /* HAS_GETPRIORITY */ +#else /* HAS_GETPRIORITY */ setpriority(PRIO_PROCESS, child, 8); -#endif /* HAS_GETPRIORITY */ -#endif /* HAS_SETPRIORITY */ +#endif /* HAS_GETPRIORITY */ +#endif /* HAS_SETPRIORITY */ } -#endif /* WIN32 */ +#endif /* WIN32 */ } else { if (DUMP_NOFORK_MESSAGE && *DUMP_NOFORK_MESSAGE) flag_broadcast(0, 0, "%s", DUMP_NOFORK_MESSAGE); @@ -664,11 +664,11 @@ fork_and_dump(int forking) chunk_fork_done(); #endif if (!nofork) { - _exit(status); /* !!! */ + _exit(status); /* !!! */ } else { reserve_fd(); if (DUMP_NOFORK_COMPLETE && *DUMP_NOFORK_COMPLETE) - flag_broadcast(0, 0, "%s", DUMP_NOFORK_COMPLETE); + flag_broadcast(0, 0, "%s", DUMP_NOFORK_COMPLETE); } } #ifdef LOG_CHUNK_STATS @@ -696,10 +696,10 @@ do_restart(void) for (thing = 0; thing < db_top; thing++) { if (IsPlayer(thing)) { if ((s = atr_get_noparent(thing, "ALIAS")) != NULL) { - bp = buf; - safe_str(atr_value(s), buf, &bp); - *bp = '\0'; - add_player_alias(thing, buf); + bp = buf; + safe_str(atr_value(s), buf, &bp); + *bp = '\0'; + add_player_alias(thing, buf); } } } @@ -724,10 +724,10 @@ do_restart(void) for (thing = 0; thing < db_top; thing++) { if (Name(thing) == NULL) { if (IsGarbage(thing)) - set_name(thing, "Garbage"); + set_name(thing, "Garbage"); else { - do_log(LT_ERR, NOTHING, NOTHING, T("Null name on object #%d"), thing); - set_name(thing, "XXXX"); + do_log(LT_ERR, NOTHING, NOTHING, T("Null name on object #%d"), thing); + set_name(thing, "XXXX"); } } if (STARTUPS && !IsGarbage(thing) && !(Halted(thing))) { @@ -804,7 +804,7 @@ init_game_config(const char *conf) do_rawlog(LT_ERR, "CobraMUSH v%s [%s]", VERSION, VBRANCH); do_rawlog(LT_ERR, T("MUSH restarted, PID %d, at %s"), - (int) getpid(), show_time(globals.start_time, 0)); + (int) getpid(), show_time(globals.start_time, 0)); } /** Post-db-load configuration. @@ -845,7 +845,7 @@ init_game_postdb(const char *conf) /* Set up ssl */ if (!ssl_init()) { fprintf(stderr, "SSL initialization failure\n"); - options.ssl_port = 0; /* Disable ssl */ + options.ssl_port = 0; /* Disable ssl */ } #endif #if (defined(HAS_MYSQL) && defined(_SWMP_)) @@ -873,7 +873,7 @@ init_game_dbs(void) int panicdb; #ifdef WIN32 - Win32MUSH_setup(); /* create index files, copy databases etc. */ + Win32MUSH_setup(); /* create index files, copy databases etc. */ #endif infile = restarting ? options.output_db : options.input_db; @@ -961,16 +961,16 @@ init_game_dbs(void) /* complain about bad config options */ if (!GoodObject(PLAYER_START) || (!IsRoom(PLAYER_START))) do_rawlog(LT_ERR, T("WARNING: Player_start (#%d) is NOT a room."), - PLAYER_START); + PLAYER_START); if (!GoodObject(MASTER_ROOM) || (!IsRoom(MASTER_ROOM))) do_rawlog(LT_ERR, T("WARNING: Master room (#%d) is NOT a room."), - MASTER_ROOM); + MASTER_ROOM); if (!GoodObject(BASE_ROOM) || (!IsRoom(BASE_ROOM))) do_rawlog(LT_ERR, T("WARNING: Base room (#%d) is NOT a room."), - BASE_ROOM); + BASE_ROOM); if (!GoodObject(DEFAULT_HOME) || (!IsRoom(DEFAULT_HOME))) do_rawlog(LT_ERR, T("WARNING: Default home (#%d) is NOT a room."), - DEFAULT_HOME); + DEFAULT_HOME); if (!GoodObject(GOD) || (!IsPlayer(GOD))) do_rawlog(LT_ERR, T("WARNING: God (#%d) is NOT a player."), GOD); @@ -1086,11 +1086,11 @@ passwd_filter(const char *cmd) int eo; pass_ptn = pcre_compile("^(@pass.*?)\\s([^=]*)=(.*)", - PCRE_CASELESS, &errptr, &eo, tables); + PCRE_CASELESS, &errptr, &eo, tables); if (!pass_ptn) do_log(LT_ERR, GOD, GOD, "pcre_compile: %s", errptr); newpass_ptn = pcre_compile("^(@(?:newp|pcreate)[^=]*)=(.*)", - PCRE_CASELESS, &errptr, &eo, tables); + PCRE_CASELESS, &errptr, &eo, tables); if (!newpass_ptn) do_log(LT_ERR, GOD, GOD, "pcre_compile: %s", errptr); initialized = 1; @@ -1107,7 +1107,7 @@ passwd_filter(const char *cmd) safe_chr('=', buff, &bp); safe_fill('*', ovec[7] - ovec[6], buff, &bp); } else if ((matched = pcre_exec(newpass_ptn, NULL, cmd, cmdlen, 0, 0, - ovec, 20)) > 0) { + ovec, 20)) > 0) { pcre_copy_substring(cmd, ovec, matched, 1, buff, BUFFER_LEN); bp = buff + strlen(buff); safe_chr('=', buff, &bp); @@ -1141,12 +1141,12 @@ void process_command(dbref player, char *command, dbref cause, dbref realcause, int from_port) { int a; - char *p; /* utility */ + char *p; /* utility */ - char unp[BUFFER_LEN]; /* unparsed command */ + char unp[BUFFER_LEN]; /* unparsed command */ /* general form command arg0=arg1,arg2...arg10 */ - char temp[BUFFER_LEN]; /* utility */ - int i; /* utility */ + char temp[BUFFER_LEN]; /* utility */ + int i; /* utility */ char *cptr; dbref errdb; dbref check_loc; @@ -1163,7 +1163,7 @@ process_command(dbref player, char *command, dbref cause, dbref realcause, int /* robustify player */ if (!GoodObject(player)) { do_log(LT_ERR, NOTHING, NOTHING, T("process_command bad player #%d"), - player); + player); return; } @@ -1175,23 +1175,23 @@ process_command(dbref player, char *command, dbref cause, dbref realcause, int /* And neither can halted players if the command isn't from_port */ if (Halted(player) && (!IsPlayer(player) || !from_port)) { notify_format(Owner(player), - T("Attempt to execute command by halted object #%d"), player); + T("Attempt to execute command by halted object #%d"), player); return; } /* Players, things, and exits should not have invalid locations. This check * must be done _after_ the destroyed-object check. */ check_loc = IsExit(player) ? Source(player) : (IsRoom(player) ? player : - Location(player)); + Location(player)); if (!GoodObject(check_loc) || IsGarbage(check_loc)) { notify_format(Owner(player), - T("Invalid location on command execution: %s(#%d)"), - Name(player), player); + T("Invalid location on command execution: %s(#%d)"), + Name(player), player); do_log(LT_ERR, NOTHING, NOTHING, - T("Command attempted by %s(#%d) in invalid location #%d."), - Name(player), player, Location(player)); + T("Command attempted by %s(#%d) in invalid location #%d."), + Name(player), player, Location(player)); if (Mobile(player)) - moveto(player, PLAYER_START); /* move it someplace valid */ + moveto(player, PLAYER_START); /* move it someplace valid */ } orator = player; @@ -1228,20 +1228,20 @@ process_command(dbref player, char *command, dbref cause, dbref realcause, int a = 0; if (!Gagged(player)) { if (Mobile(player)) { - /* if the "player" is an exit or room, no need to do these checks */ - /* try matching enter aliases */ - if (check_loc != NOTHING && - (i = alias_list_check(Contents(check_loc), cptr, "EALIAS")) != -1) { - - sprintf(temp, "#%d", i); - do_enter(player, temp); - goto done; - } - /* if that didn't work, try matching leave aliases */ - if (!IsRoom(check_loc) && (loc_alias_check(check_loc, cptr, "LALIAS"))) { - do_leave(player); - goto done; - } + /* if the "player" is an exit or room, no need to do these checks */ + /* try matching enter aliases */ + if (check_loc != NOTHING && + (i = alias_list_check(Contents(check_loc), cptr, "EALIAS")) != -1) { + + sprintf(temp, "#%d", i); + do_enter(player, temp); + goto done; + } + /* if that didn't work, try matching leave aliases */ + if (!IsRoom(check_loc) && (loc_alias_check(check_loc, cptr, "LALIAS"))) { + do_leave(player); + goto done; + } } /* try matching user defined functions before chopping */ @@ -1380,12 +1380,12 @@ check_alias(const char *command, const char *list) const char *p; while (*list) { for (p = command; (*p && DOWNCASE(*p) == DOWNCASE(*list) - && *list != EXIT_DELIMITER); p++, list++) ; + && *list != EXIT_DELIMITER); p++, list++) ; if (*p == '\0') { while (isspace((unsigned char) *list)) - list++; + list++; if (*list == '\0' || *list == EXIT_DELIMITER) - return 1; /* word matched */ + return 1; /* word matched */ } /* didn't match. check next word in list */ while (*list && *list++ != EXIT_DELIMITER) ; @@ -1411,14 +1411,14 @@ check_alias(const char *command, const char *list) */ int list_check(dbref thing, dbref player, char type, char end, char *str, - int just_match) + int just_match) { int match = 0; dbref errdb = NOTHING; while (thing != NOTHING) { if (atr_comm_match - (thing, player, type, end, str, just_match, NULL, NULL, &errdb)) + (thing, player, type, end, str, just_match, NULL, NULL, &errdb)) match = 1; else { MAYBE_ADD_ERRDB(errdb); @@ -1449,7 +1449,7 @@ alias_list_check(dbref thing, const char *command, const char *type) if (a) { strcpy(alias, atr_value(a)); if (check_alias(command, alias) != 0) - return thing; /* matched an alias */ + return thing; /* matched an alias */ } thing = Next(thing); } @@ -1564,11 +1564,11 @@ do_poor(dbref player, char *arg1) if (IsPlayer(a)) s_Pennies(a, amt); notify_format(player, - T - ("The money supply of all players has been reset to %d %s."), - amt, MONIES); + T + ("The money supply of all players has been reset to %d %s."), + amt, MONIES); do_log(LT_WIZ, player, NOTHING, - T("** POOR done ** Money supply reset to %d %s."), amt, MONIES); + T("** POOR done ** Money supply reset to %d %s."), amt, MONIES); } @@ -1584,7 +1584,7 @@ void do_writelog(dbref player, char *str, int ltype) { do_rawlog(ltype, "LOG: %s(#%d%s): %s", Name(player), player, - unparse_flags(player, GOD), str); + unparse_flags(player, GOD), str); notify(player, "Logged."); } @@ -1598,7 +1598,7 @@ do_writelog(dbref player, char *str, int ltype) */ void bind_and_queue(dbref player, dbref cause, char *action, - const char *arg, const char *placestr) + const char *arg, const char *placestr) { char *repl, *command; const char *replace[2]; @@ -1676,19 +1676,19 @@ scan_list(dbref player, char *command) if (IsRoom(Zone(Location(player)))) { /* zone of player's location is a zone master room */ if (Location(player) != Zone(player)) { - DOLIST(thing, Contents(Zone(Location(player)))) { - if (ScanFind(player, thing)) { - *ptr = '\0'; - safe_str(atrname, tbuf, &tp); - ptr = atrname; - } - } + DOLIST(thing, Contents(Zone(Location(player)))) { + if (ScanFind(player, thing)) { + *ptr = '\0'; + safe_str(atrname, tbuf, &tp); + ptr = atrname; + } + } } } else { /* regular zone object */ if (ScanFind(player, Zone(Location(player)))) { - *ptr = '\0'; - safe_str(atrname, tbuf, &tp); + *ptr = '\0'; + safe_str(atrname, tbuf, &tp); } } } @@ -1698,13 +1698,13 @@ scan_list(dbref player, char *command) /* check the player's personal zone */ if (IsRoom(Zone(player))) { if (Location(player) != Zone(player)) { - DOLIST(thing, Contents(Zone(player))) { - if (ScanFind(player, thing)) { - *ptr = '\0'; - safe_str(atrname, tbuf, &tp); - ptr = atrname; - } - } + DOLIST(thing, Contents(Zone(player))) { + if (ScanFind(player, thing)) { + *ptr = '\0'; + safe_str(atrname, tbuf, &tp); + ptr = atrname; + } + } } } else if (ScanFind(player, Zone(player))) { *ptr = '\0'; @@ -1718,15 +1718,15 @@ scan_list(dbref player, char *command) /* try Master Room stuff */ DOLIST(thing, Contents(MASTER_ROOM)) { if (ScanFind(player, thing)) { - *ptr = '\0'; - safe_str(atrname, tbuf, &tp); - ptr = atrname; + *ptr = '\0'; + safe_str(atrname, tbuf, &tp); + ptr = atrname; } } } *tp = '\0'; if (*tbuf && *tbuf == ' ') - return tbuf + 1; /* atrname comes with leading spaces */ + return tbuf + 1; /* atrname comes with leading spaces */ return tbuf; } @@ -1776,7 +1776,7 @@ do_scan(dbref player, char *command, int flag) if (ScanFind(player, Location(player))) { *ptr = '\0'; notify_format(player, T("Matched here: %s [%d:%s]"), - unparse_object(player, Location(player)), num, atrname); + unparse_object(player, Location(player)), num, atrname); } } ptr = atrname; @@ -1784,10 +1784,10 @@ do_scan(dbref player, char *command, int flag) notify(player, T("Matches on carried objects:")); DOLIST(thing, Contents(player)) { if (ScanFind(player, thing)) { - *ptr = '\0'; - notify_format(player, "%s [%d:%s]", - unparse_object(player, thing), num, atrname); - ptr = atrname; + *ptr = '\0'; + notify_format(player, "%s [%d:%s]", + unparse_object(player, thing), num, atrname); + ptr = atrname; } } } @@ -1796,7 +1796,7 @@ do_scan(dbref player, char *command, int flag) if (ScanFind(player, player)) { *ptr = '\0'; notify_format(player, T("Matched self: %s [%d:%s]"), - unparse_object(player, player), num, atrname); + unparse_object(player, player), num, atrname); } } ptr = atrname; @@ -1804,49 +1804,49 @@ do_scan(dbref player, char *command, int flag) /* zone checks */ if (Zone(Location(player)) != NOTHING) { if (IsRoom(Zone(Location(player)))) { - /* zone of player's location is a zone master room */ - if (Location(player) != Zone(player)) { - notify(player, T("Matches on zone master room of location:")); - DOLIST(thing, Contents(Zone(Location(player)))) { - if (ScanFind(player, thing)) { - *ptr = '\0'; - notify_format(player, "%s [%d:%s]", - unparse_object(player, thing), num, atrname); - ptr = atrname; - } - } - } + /* zone of player's location is a zone master room */ + if (Location(player) != Zone(player)) { + notify(player, T("Matches on zone master room of location:")); + DOLIST(thing, Contents(Zone(Location(player)))) { + if (ScanFind(player, thing)) { + *ptr = '\0'; + notify_format(player, "%s [%d:%s]", + unparse_object(player, thing), num, atrname); + ptr = atrname; + } + } + } } else { - /* regular zone object */ - if (ScanFind(player, Zone(Location(player)))) { - *ptr = '\0'; - notify_format(player, - T("Matched zone of location: %s [%d:%s]"), - unparse_object(player, - Zone(Location(player))), num, atrname); - } + /* regular zone object */ + if (ScanFind(player, Zone(Location(player)))) { + *ptr = '\0'; + notify_format(player, + T("Matched zone of location: %s [%d:%s]"), + unparse_object(player, + Zone(Location(player))), num, atrname); + } } } ptr = atrname; if ((Zone(player) != NOTHING) - && (Zone(player) != Zone(Location(player)))) { + && (Zone(player) != Zone(Location(player)))) { /* check the player's personal zone */ if (IsRoom(Zone(player))) { - if (Location(player) != Zone(player)) { - notify(player, T("Matches on personal zone master room:")); - DOLIST(thing, Contents(Zone(player))) { - if (ScanFind(player, thing)) { - *ptr = '\0'; - notify_format(player, "%s [%d:%s]", - unparse_object(player, thing), num, atrname); - ptr = atrname; - } - } - } + if (Location(player) != Zone(player)) { + notify(player, T("Matches on personal zone master room:")); + DOLIST(thing, Contents(Zone(player))) { + if (ScanFind(player, thing)) { + *ptr = '\0'; + notify_format(player, "%s [%d:%s]", + unparse_object(player, thing), num, atrname); + ptr = atrname; + } + } + } } else if (ScanFind(player, Zone(player))) { - *ptr = '\0'; - notify_format(player, T("Matched personal zone: %s [%d:%s]"), - unparse_object(player, Zone(player)), num, atrname); + *ptr = '\0'; + notify_format(player, T("Matched personal zone: %s [%d:%s]"), + unparse_object(player, Zone(player)), num, atrname); } } } @@ -1859,10 +1859,10 @@ do_scan(dbref player, char *command, int flag) notify(player, T("Matches on objects in the Master Room:")); DOLIST(thing, Contents(MASTER_ROOM)) { if (ScanFind(player, thing)) { - *ptr = '\0'; - notify_format(player, "%s [%d:%s]", - unparse_object(player, thing), num, atrname); - ptr = atrname; + *ptr = '\0'; + notify_format(player, "%s [%d:%s]", + unparse_object(player, thing), num, atrname); + ptr = atrname; } } } @@ -1885,7 +1885,7 @@ do_scan(dbref player, char *command, int flag) */ void do_dolist(dbref player, char *list, char *command, dbref cause, - unsigned int flags) + unsigned int flags) { char *curr, *objstring; char outbuf[BUFFER_LEN]; @@ -1905,7 +1905,7 @@ do_dolist(dbref player, char *list, char *command, dbref cause, if (list[1] != ' ') { notify(player, T("Separator must be one character.")); if (flags & DOL_NOTIFY) - parse_que(player, "@notify me", cause); + parse_que(player, "@notify me", cause); return; } delim = list[0]; @@ -1941,12 +1941,12 @@ do_dolist(dbref player, char *list, char *command, dbref cause, char *ebuf, *ebufptr; /* it's @map, add to the output list */ if (bp != outbuf) - safe_chr(delim, outbuf, &bp); + safe_chr(delim, outbuf, &bp); replace[0] = curr; replace[1] = placestr; ebufptr = ebuf = replace_string2(standard_tokens, replace, command); process_expression(outbuf, &bp, (char const **) &ebuf, player, - cause, cause, PE_DEFAULT, PT_DEFAULT, NULL); + cause, cause, PE_DEFAULT, PT_DEFAULT, NULL); mush_free(ebufptr, "replace_string.buff"); } } @@ -1982,7 +1982,7 @@ linux_uptime(dbref player __attribute__ ((__unused__))) /* Use /proc files instead of calling the external uptime program on linux */ char tbuf1[BUFFER_LEN]; FILE *fp; - char line[128]; /* Overkill */ + char line[128]; /* Overkill */ char *nl; Pid_t pid; int psize; @@ -2007,9 +2007,9 @@ linux_uptime(dbref player __attribute__ ((__unused__))) only care about seconds. */ uptime = strtol(line, NULL, 10); if (uptime > 86400) - fmt = "up $d days, $2h:$2M,"; + fmt = "up $d days, $2h:$2M,"; else - fmt = "up $2h:$2M,"; + fmt = "up $2h:$2M,"; do_timestring(tbuf1, &nl, fmt, uptime); } else { safe_str("Unknown uptime,", tbuf1, &nl); @@ -2031,7 +2031,7 @@ linux_uptime(dbref player __attribute__ ((__unused__))) l = x; load[2] = strtod(l, NULL); safe_format(tbuf1, &nl, " load average: %.2f, %.2f, %.2f", - load[0], load[1], load[2]); + load[0], load[1], load[2]); } else { safe_str("Unknown load", tbuf1, &nl); } @@ -2076,9 +2076,9 @@ linux_uptime(dbref player __attribute__ ((__unused__))) for (n = 0; fields[n]; n++) { size_t len = strlen(fields[n]); if (strncmp(line, fields[n], len) == 0) { - if ((nl = strchr(line, '\n')) != NULL) - *nl = '\0'; - notify(player, line); + if ((nl = strchr(line, '\n')) != NULL) + *nl = '\0'; + notify(player, line); } } } @@ -2213,7 +2213,7 @@ do_uptime(dbref player, int mortal) if (globals.last_dump_time > 0) { when = localtime(&globals.last_dump_time); strftime(tbuf1, sizeof tbuf1, - T(" Time of last database save: %a %b %d %X %Z %Y"), when); + T(" Time of last database save: %a %b %d %X %Z %Y"), when); notify(player, tbuf1); } @@ -2221,47 +2221,47 @@ do_uptime(dbref player, int mortal) when = localtime(&options.dump_counter); strftime(tbuf1, sizeof tbuf1, "%X", when); notify_format(player, - T - ("Time until next database save: %ld minutes %ld seconds, at %s"), - ((long) difftime(options.dump_counter, mudtime)) / 60, - ((long) difftime(options.dump_counter, mudtime)) % 60, tbuf1); + T + ("Time until next database save: %ld minutes %ld seconds, at %s"), + ((long) difftime(options.dump_counter, mudtime)) / 60, + ((long) difftime(options.dump_counter, mudtime)) % 60, tbuf1); when = localtime(&options.dbck_counter); strftime(tbuf1, sizeof tbuf1, "%X", when); notify_format(player, - T - (" Time until next dbck check: %ld minutes %ld seconds, at %s."), - ((long) difftime(options.dbck_counter, mudtime)) / 60, - ((long) difftime(options.dbck_counter, mudtime)) % 60, tbuf1); + T + (" Time until next dbck check: %ld minutes %ld seconds, at %s."), + ((long) difftime(options.dbck_counter, mudtime)) / 60, + ((long) difftime(options.dbck_counter, mudtime)) % 60, tbuf1); when = localtime(&options.purge_counter); strftime(tbuf1, sizeof tbuf1, "%X", when); notify_format(player, - T - (" Time until next purge: %ld minutes %ld seconds, at %s."), - ((long) difftime(options.purge_counter, mudtime)) / 60, - ((long) difftime(options.purge_counter, mudtime)) % 60, tbuf1); + T + (" Time until next purge: %ld minutes %ld seconds, at %s."), + ((long) difftime(options.purge_counter, mudtime)) / 60, + ((long) difftime(options.purge_counter, mudtime)) % 60, tbuf1); if (options.warn_interval) { when = localtime(&options.warn_counter); strftime(tbuf1, sizeof tbuf1, "%X", when); notify_format(player, - T - (" Time until next @warnings: %ld minutes %ld seconds, at %s."), - ((long) difftime(options.warn_counter, mudtime)) / 60, - ((long) difftime(options.warn_counter, mudtime)) % 60, tbuf1); + T + (" Time until next @warnings: %ld minutes %ld seconds, at %s."), + ((long) difftime(options.warn_counter, mudtime)) / 60, + ((long) difftime(options.warn_counter, mudtime)) % 60, tbuf1); } notify_format(player, - T - ("PennMUSH Uptime: %ld days %ld hours %ld minutes %ld seconds"), - ((long) difftime(mudtime, globals.first_start_time)) / 86400, - ((long) difftime(mudtime, globals.first_start_time) % 86400) / - 3600, - (((long) difftime(mudtime, globals.first_start_time) % 86400) % - 3600) / 60, - (((long) difftime(mudtime, globals.first_start_time) % 86400) % - 3600) % 60); + T + ("PennMUSH Uptime: %ld days %ld hours %ld minutes %ld seconds"), + ((long) difftime(mudtime, globals.first_start_time)) / 86400, + ((long) difftime(mudtime, globals.first_start_time) % 86400) / + 3600, + (((long) difftime(mudtime, globals.first_start_time) % 86400) % + 3600) / 60, + (((long) difftime(mudtime, globals.first_start_time) % 86400) % + 3600) % 60); /* Mortals, go no further! */ if (!Site(player) || mortal) @@ -2294,17 +2294,17 @@ db_open(const char *filename) fclose(f); f = #ifdef __LCC__ - (FILE *) + (FILE *) #endif - popen(tprintf - ("%s < %s%s", options.uncompressprog, filename, - options.compresssuff), "r"); + popen(tprintf + ("%s < %s%s", options.uncompressprog, filename, + options.compresssuff), "r"); /* Force the pipe to be fully buffered */ if (f) - setvbuf(f, NULL, _IOFBF, BUFSIZ); + setvbuf(f, NULL, _IOFBF, BUFSIZ); } } else -#endif /* WIN32 */ +#endif /* WIN32 */ { f = fopen(filename, FOPEN_READ); } @@ -2329,13 +2329,13 @@ db_open_write(const char *filename) if (chdir(workdir) < 0) #endif fprintf(stderr, - "chdir to %s failed in db_open_write, errno %d (%s)\n", - workdir, errno, strerror(errno)); + "chdir to %s failed in db_open_write, errno %d (%s)\n", + workdir, errno, strerror(errno)); } else { /* If this fails, we probably can't write to a log, either, though */ fprintf(stderr, - "getcwd failed during db_open_write, errno %d (%s)\n", - errno, strerror(errno)); + "getcwd failed during db_open_write, errno %d (%s)\n", + errno, strerror(errno)); } #ifndef WIN32 if (options.compressprog && *options.compressprog) { @@ -2344,13 +2344,13 @@ db_open_write(const char *filename) (FILE *) #endif popen(tprintf - ("%s >%s%s", options.compressprog, filename, - options.compresssuff), "w"); + ("%s >%s%s", options.compressprog, filename, + options.compresssuff), "w"); /* Force the pipe to be fully buffered */ if (f) setvbuf(f, NULL, _IOFBF, BUFSIZ); } else -#endif /* WIN32 */ +#endif /* WIN32 */ { f = fopen(filename, FOPEN_WRITE); } @@ -2368,7 +2368,7 @@ db_close(FILE * f) if (options.compressprog && *options.compressprog) { pclose(f); } else -#endif /* WIN32 */ +#endif /* WIN32 */ { fclose(f); } @@ -2451,29 +2451,29 @@ do_list_memstats(dbref player) compress_stats(&items, &used, &total_uncomp, &total_comp); notify(player, "---------- Internal attribute compression ----------"); notify_format(player, - "%10ld compression table items used, " - "taking %ld bytes.", items, used); + "%10ld compression table items used, " + "taking %ld bytes.", items, used); notify_format(player, "%10ld bytes in text before compression. ", - total_uncomp); + total_uncomp); notify_format(player, "%10ld bytes in text AFTER compression. ", - total_comp); + total_comp); percent = ((float) (total_comp)) / ((float) total_uncomp) * 100.0; notify_format(player, - "%10.0f %% text compression ratio (lower is better). ", - percent); + "%10.0f %% text compression ratio (lower is better). ", + percent); percent = ((float) (total_comp + used + (32768L * sizeof(char *)))) / ((float) total_uncomp) * 100.0; notify_format(player, - "%10.0f %% OVERALL compression ratio (lower is better). ", - percent); + "%10.0f %% OVERALL compression ratio (lower is better). ", + percent); notify_format(player, - T - (" (Includes table items, and table of words pointers of %ld bytes)"), - 32768L * sizeof(char *)); + T + (" (Includes table items, and table of words pointers of %ld bytes)"), + 32768L * sizeof(char *)); if (percent >= 100.0) notify(player, - " " "(Compression ratio improves with larger database)"); + " " "(Compression ratio improves with larger database)"); } #endif @@ -2484,7 +2484,7 @@ do_list_memstats(dbref player) static char * make_new_epoch_file(const char *basename, int the_epoch) { - static char result[BUFFER_LEN]; /* STATIC! */ + static char result[BUFFER_LEN]; /* STATIC! */ /* Unlink the last the_epoch and create a new one */ sprintf(result, "%s.#%d#", basename, the_epoch - 1); unlink(result); @@ -2516,7 +2516,7 @@ static void errdb_grow(void) { if (errdbsize >= 50) - return; /* That's it, no more, forget it */ + return; /* That's it, no more, forget it */ errdbsize++; errdblist = realloc(errdblist, errdbsize * sizeof(dbref)); errdbtail = errdblist + errdbsize - 1; diff --git a/src/gmalloc.c b/src/gmalloc.c index 2854954..e69de29 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -1,1295 +0,0 @@ -/* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */ - -#define _MALLOC_INTERNAL - -/* The malloc headers and source files from the C library follow here. */ - -/* Declarations for `malloc' and friends. - Copyright 1990, 1991, 1992, 1993, 1995 Free Software Foundation, Inc. - Written May 1989 by Mike Haertel. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_H - -#define _MALLOC_H 1 - -#ifdef _MALLOC_INTERNAL - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#ifndef memset -#define memset(s, zero, n) bzero ((s), (n)) -#endif -#ifndef memcpy -#define memcpy(d, s, n) bcopy ((s), (d), (n)) -#endif - - -#if defined (__GNU_LIBRARY__) || (defined (__STDC__) && __STDC__) -#include -#else -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -#endif /* _MALLOC_INTERNAL. */ - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) -#undef __P -#define __P(args) args -#undef __ptr_t -#define __ptr_t void * -#else /* Not C++ or ANSI C. */ -#undef __P -#define __P(args) () -#undef const -#define const -#undef __ptr_t -#define __ptr_t char * -#endif /* C++ or ANSI C. */ - -#if defined (__STDC__) && __STDC__ -#include -#define __malloc_size_t size_t -#define __malloc_ptrdiff_t ptrdiff_t -#else -#define __malloc_size_t unsigned int -#define __malloc_ptrdiff_t int -#endif - -#ifndef NULL -#define NULL 0 -#endif - - -/* Allocate SIZE bytes of memory. */ - extern __ptr_t malloc __P((__malloc_size_t __size)); -/* Re-allocate the previously allocated block - in __ptr_t, making the new block SIZE bytes long. */ - extern __ptr_t realloc __P((__ptr_t __ptr, __malloc_size_t __size)); -/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */ - extern __ptr_t calloc __P((__malloc_size_t __nmemb, __malloc_size_t __size)); -/* Free a block allocated by `malloc', `realloc' or `calloc'. */ - extern void free __P((__ptr_t __ptr)); - -/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ - extern __ptr_t memalign __P((__malloc_size_t __alignment, - __malloc_size_t __size)); - -/* Allocate SIZE bytes on a page boundary. */ - extern __ptr_t valloc __P((__malloc_size_t __size)); - - -#ifdef _MALLOC_INTERNAL - -/* The allocator divides the heap into blocks of fixed size; large - requests receive one or more whole blocks, and small requests - receive a fragment of a block. Fragment sizes are powers of two, - and all fragments of a block are the same size. When all the - fragments in a block have been freed, the block itself is freed. */ -#define INT_BIT (CHAR_BIT * sizeof(int)) -#define BLOCKLOG (INT_BIT > 16 ? 12 : 9) -#define BLOCKSIZE (1 << BLOCKLOG) -#define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE) - -/* Determine the amount of memory spanned by the initial heap table - (not an absolute limit). */ -#define HEAP (INT_BIT > 16 ? 4194304 : 65536) - -/* Number of contiguous free blocks allowed to build up at the end of - memory before they will be returned to the system. */ -#define FINAL_FREE_BLOCKS 8 - -/* Data structure giving per-block information. */ - typedef union { - /* Heap information for a busy block. */ - struct { - /* Zero for a large (multiblock) object, or positive giving the - logarithm to the base two of the fragment size. */ - int type; - union { - struct { - __malloc_size_t nfree; /* Free frags in a fragmented block. */ - __malloc_size_t first; /* First free fragment of the block. */ - } frag; - /* For a large object, in its first block, this has the number - of blocks in the object. In the other blocks, this has a - negative number which says how far back the first block is. */ - __malloc_ptrdiff_t size; - } info; - } busy; - /* Heap information for a free block - (that may be the first of a free cluster). */ - struct { - __malloc_size_t size; /* Size (in blocks) of a free cluster. */ - __malloc_size_t next; /* Index of next free cluster. */ - __malloc_size_t prev; /* Index of previous free cluster. */ - } free; - } malloc_info; - -/* Pointer to first block of the heap. */ - extern char *_heapbase; - -/* Table indexed by block number giving per-block information. */ - extern malloc_info *_heapinfo; - -/* Address to block number and vice versa. */ -#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1) -#define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase)) - -/* Current search index for the heap table. */ - extern __malloc_size_t _heapindex; - -/* Limit of valid info table indices. */ - extern __malloc_size_t _heaplimit; - -/* Doubly linked lists of free fragments. */ - struct list { - struct list *next; - struct list *prev; - }; - -/* Free list headers for each fragment size. */ - extern struct list _fraghead[]; - -/* List of blocks allocated with `memalign' (or `valloc'). */ - struct alignlist { - struct alignlist *next; - __ptr_t aligned; /* The address that memaligned returned. */ - __ptr_t exact; /* The address that malloc returned. */ - }; - extern struct alignlist *_aligned_blocks; - -/* Instrumentation. */ - extern __malloc_size_t _chunks_used; - extern __malloc_size_t _bytes_used; - extern __malloc_size_t _chunks_free; - extern __malloc_size_t _bytes_free; - -/* Internal version of `free' used in `morecore' (malloc.c). */ - extern void _free_internal __P((__ptr_t __ptr)); - -#endif /* _MALLOC_INTERNAL. */ - -/* Given an address in the middle of a malloc'd object, - return the address of the beginning of the object. */ - extern __ptr_t malloc_find_object_address __P((__ptr_t __ptr)); - -/* Underlying allocation function; successive calls should - return contiguous pieces of memory. */ - extern __ptr_t (*__morecore) __P((__malloc_ptrdiff_t __size)); - -/* Default value of `__morecore'. */ - extern __ptr_t __default_morecore __P((__malloc_ptrdiff_t __size)); - -/* If not NULL, this function is called after each time - `__morecore' is called to increase the data size. */ - extern void (*__after_morecore_hook) __P((void)); - -/* Nonzero if `malloc' has been called and done its initialization. */ - extern int __malloc_initialized; - -/* Hooks for debugging versions. */ - extern void (*__malloc_initialize_hook) __P((void)); - extern void (*__free_hook) __P((__ptr_t __ptr)); - extern __ptr_t (*__malloc_hook) __P((__malloc_size_t __size)); - extern __ptr_t (*__realloc_hook) - __P((__ptr_t __ptr, __malloc_size_t __size)); - extern __ptr_t (*__memalign_hook) - __P((__malloc_size_t __size, __malloc_size_t __alignment)); - -/* Return values for `mprobe': these are the kinds of inconsistencies that - `mcheck' enables detection of. */ - enum mcheck_status { - MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */ - MCHECK_OK, /* Block is fine. */ - MCHECK_FREE, /* Block freed twice. */ - MCHECK_HEAD, /* Memory before the block was clobbered. */ - MCHECK_TAIL /* Memory after the block was clobbered. */ - }; - -/* Activate a standard collection of debugging hooks. This must be called - before `malloc' is ever called. ABORTFUNC is called with an error code - (see enum above) when an inconsistency is detected. If ABORTFUNC is - null, the standard function prints on stderr and then calls `abort'. */ - extern int mcheck __P((void (*__abortfunc) __P((enum mcheck_status)))); - -/* Check for aberrations in a particular malloc'd block. You must have - called `mcheck' already. These are the same checks that `mcheck' does - when you free or reallocate a block. */ - extern enum mcheck_status mprobe __P((__ptr_t __ptr)); - -/* Activate a standard collection of tracing hooks. */ - extern void mtrace __P((void)); - extern void muntrace __P((void)); - -/* Statistics available to the user. */ - struct mstats { - __malloc_size_t bytes_total; /* Total size of the heap. */ - __malloc_size_t chunks_used; /* Chunks allocated by the user. */ - __malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */ - __malloc_size_t chunks_free; /* Chunks in the free list. */ - __malloc_size_t bytes_free; /* Byte total of chunks in the free list. */ - }; - -/* Pick up the current statistics. */ - extern struct mstats mstats __P((void)); - -/* Call WARNFUN with a warning message when memory usage is high. */ - extern void memory_warnings __P((__ptr_t __start, - void (*__warnfun) __P((const char *)))); - - -/* Relocating allocator. */ - -/* Allocate SIZE bytes, and store the address in *HANDLEPTR. */ - extern __ptr_t r_alloc __P((__ptr_t *__handleptr, __malloc_size_t __size)); - -/* Free the storage allocated in HANDLEPTR. */ - extern void r_alloc_free __P((__ptr_t *__handleptr)); - -/* Adjust the block at HANDLEPTR to be SIZE bytes long. */ - extern __ptr_t r_re_alloc __P((__ptr_t *__handleptr, __malloc_size_t __size)); - - -#ifdef __cplusplus -} -#endif -#endif /* malloc.h */ /* Allocate memory on a page boundary. - Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ -#if defined (__GNU_LIBRARY__) || defined (_LIBC) -#include -#include -extern size_t __getpagesize __P((void)); -#else -#include "getpgsiz.h" -#define __getpagesize() getpagesize() -#endif -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif -static __malloc_size_t pagesize; - -__ptr_t -valloc(size) - __malloc_size_t size; -{ - if (pagesize == 0) - pagesize = __getpagesize(); - - return memalign(pagesize, size); -} - -/* Memory allocator `malloc'. - Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. - Written May 1989 by Mike Haertel. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -/* How to really get more memory. */ -__ptr_t (*__morecore) __P((ptrdiff_t __size)) = __default_morecore; - -/* Debugging hook for `malloc'. */ -__ptr_t (*__malloc_hook) __P((__malloc_size_t __size)); - -/* Pointer to the base of the first block. */ -char *_heapbase; - -/* Block information table. Allocated with align/__free (not malloc/free). */ -malloc_info *_heapinfo; - -/* Number of info entries. */ -static -__malloc_size_t heapsize; - -/* Search index in the info table. */ -__malloc_size_t _heapindex; - -/* Limit of valid info table indices. */ -__malloc_size_t _heaplimit; - -/* Free lists for each fragment size. */ -struct list - _fraghead[BLOCKLOG]; - -/* Instrumentation. */ -__malloc_size_t _chunks_used; -__malloc_size_t _bytes_used; -__malloc_size_t _chunks_free; -__malloc_size_t _bytes_free; - -/* Are you experienced? */ -int - __malloc_initialized; - -void (*__malloc_initialize_hook) - __P((void)); -void (*__after_morecore_hook) - __P((void)); - -/* Aligned allocation. */ -static -__ptr_t align __P((__malloc_size_t)); -static - __ptr_t -align(size) - __malloc_size_t size; -{ - __ptr_t result; - unsigned long int adj; - - result = (*__morecore) (size); - adj = (unsigned long int) ((unsigned long int) ((char *) result - - (char *) NULL)) % BLOCKSIZE; - if (adj != 0) { - adj = BLOCKSIZE - adj; - (void) (*__morecore) (adj); - result = (char *) result + adj; - } - if (__after_morecore_hook) - (*__after_morecore_hook) (); - - return result; -} - -/* Set everything up and remember that we have. */ -static int initialize __P((void)); -static int -initialize() -{ - if (__malloc_initialize_hook) - (*__malloc_initialize_hook) (); - - heapsize = HEAP / BLOCKSIZE; - _heapinfo = (malloc_info *) align(heapsize * sizeof(malloc_info)); - if (_heapinfo == NULL) - return 0; - memset(_heapinfo, 0, heapsize * sizeof(malloc_info)); - _heapinfo[0].free.size = 0; - _heapinfo[0].free.next = _heapinfo[0].free.prev = 0; - _heapindex = 0; - _heapbase = (char *) _heapinfo; - - /* Account for the _heapinfo block itself in the statistics. */ - _bytes_used = heapsize * sizeof(malloc_info); - _chunks_used = 1; - - __malloc_initialized = 1; - return 1; -} - -/* Get neatly aligned memory, initializing or - growing the heap info table as necessary. */ -static __ptr_t morecore __P((__malloc_size_t)); -static __ptr_t -morecore(size) - __malloc_size_t size; -{ - __ptr_t result; - malloc_info *newinfo, *oldinfo; - __malloc_size_t newsize; - - result = align(size); - if (result == NULL) - return NULL; - - /* Check if we need to grow the info table. */ - if ((__malloc_size_t) BLOCK((char *) result + size) > heapsize) { - newsize = heapsize; - while ((__malloc_size_t) BLOCK((char *) result + size) > newsize) - newsize *= 2; - newinfo = (malloc_info *) align(newsize * sizeof(malloc_info)); - if (newinfo == NULL) { - (*__morecore) (-size); - return NULL; - } - memcpy(newinfo, _heapinfo, heapsize * sizeof(malloc_info)); - memset(&newinfo[heapsize], 0, (newsize - heapsize) * sizeof(malloc_info)); - oldinfo = _heapinfo; - newinfo[BLOCK(oldinfo)].busy.type = 0; - newinfo[BLOCK(oldinfo)].busy.info.size - = BLOCKIFY(heapsize * sizeof(malloc_info)); - _heapinfo = newinfo; - /* Account for the _heapinfo block itself in the statistics. */ - _bytes_used += newsize * sizeof(malloc_info); - ++_chunks_used; - _free_internal(oldinfo); - heapsize = newsize; - } - _heaplimit = BLOCK((char *) result + size); - return result; -} - -/* Allocate memory from the heap. */ -__ptr_t -malloc(size) - __malloc_size_t size; -{ - __ptr_t result; - __malloc_size_t block, blocks, lastblocks, start; - register __malloc_size_t i; - struct list *next; - - /* ANSI C allows `malloc (0)' to either return NULL, or to return a - valid address you can realloc and free (though not dereference). - - It turns out that some extant code (sunrpc, at least Ultrix's version) - expects `malloc (0)' to return non-NULL and breaks otherwise. - Be compatible. */ - -#if 0 - if (size == 0) - return NULL; -#endif - - if (__malloc_hook != NULL) - return (*__malloc_hook) (size); - - if (!__malloc_initialized) - if (!initialize()) - return NULL; - - if (size < sizeof(struct list)) - size = sizeof(struct list); - -#ifdef SUNOS_LOCALTIME_BUG - if (size < 16) - size = 16; -#endif - - /* Determine the allocation policy based on the request size. */ - if (size <= BLOCKSIZE / 2) { - /* Small allocation to receive a fragment of a block. - Determine the logarithm to base two of the fragment size. */ - register __malloc_size_t log = 1; - --size; - while ((size /= 2) != 0) - ++log; - - /* Look in the fragment lists for a - free fragment of the desired size. */ - next = _fraghead[log].next; - if (next != NULL) { - /* There are free fragments of this size. - Pop a fragment out of the fragment list and return it. - Update the block's nfree and first counters. */ - result = (__ptr_t) next; - next->prev->next = next->next; - if (next->next != NULL) - next->next->prev = next->prev; - block = BLOCK(result); - if (--_heapinfo[block].busy.info.frag.nfree != 0) - _heapinfo[block].busy.info.frag.first = (unsigned long int) - ((unsigned long int) ((char *) next->next - (char *) NULL) - % BLOCKSIZE) >> log; - - /* Update the statistics. */ - ++_chunks_used; - _bytes_used += 1 << log; - --_chunks_free; - _bytes_free -= 1 << log; - } else { - /* No free fragments of the desired size, so get a new block - and break it into fragments, returning the first. */ - result = malloc(BLOCKSIZE); - if (result == NULL) - return NULL; - - /* Link all fragments but the first into the free list. */ - for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> log); ++i) { - next = (struct list *) ((char *) result + (i << log)); - next->next = _fraghead[log].next; - next->prev = &_fraghead[log]; - next->prev->next = next; - if (next->next != NULL) - next->next->prev = next; - } - - /* Initialize the nfree and first counters for this block. */ - block = BLOCK(result); - _heapinfo[block].busy.type = log; - _heapinfo[block].busy.info.frag.nfree = i - 1; - _heapinfo[block].busy.info.frag.first = i - 1; - - _chunks_free += (BLOCKSIZE >> log) - 1; - _bytes_free += BLOCKSIZE - (1 << log); - _bytes_used -= BLOCKSIZE - (1 << log); - } - } else { - /* Large allocation to receive one or more blocks. - Search the free list in a circle starting at the last place visited. - If we loop completely around without finding a large enough - space we will have to get more memory from the system. */ - blocks = BLOCKIFY(size); - start = block = _heapindex; - while (_heapinfo[block].free.size < blocks) { - block = _heapinfo[block].free.next; - if (block == start) { - /* Need to get more from the system. Check to see if - the new core will be contiguous with the final free - block; if so we don't need to get as much. */ - block = _heapinfo[0].free.prev; - lastblocks = _heapinfo[block].free.size; - if (_heaplimit != 0 && block + lastblocks == _heaplimit && - (*__morecore) (0) == ADDRESS(block + lastblocks) && - (morecore((blocks - lastblocks) * BLOCKSIZE)) != NULL) { - /* Which block we are extending (the `final free - block' referred to above) might have changed, if - it got combined with a freed info table. */ - block = _heapinfo[0].free.prev; - _heapinfo[block].free.size += (blocks - lastblocks); - _bytes_free += (blocks - lastblocks) * BLOCKSIZE; - continue; - } - result = morecore(blocks * BLOCKSIZE); - if (result == NULL) - return NULL; - block = BLOCK(result); - _heapinfo[block].busy.type = 0; - _heapinfo[block].busy.info.size = blocks; - ++_chunks_used; - _bytes_used += blocks * BLOCKSIZE; - return result; - } - } - - /* At this point we have found a suitable free list entry. - Figure out how to remove what we need from the list. */ - result = ADDRESS(block); - if (_heapinfo[block].free.size > blocks) { - /* The block we found has a bit left over, - so relink the tail end back into the free list. */ - _heapinfo[block + blocks].free.size = _heapinfo[block].free.size - blocks; - _heapinfo[block + blocks].free.next = _heapinfo[block].free.next; - _heapinfo[block + blocks].free.prev = _heapinfo[block].free.prev; - _heapinfo[_heapinfo[block].free.prev].free.next - = _heapinfo[_heapinfo[block].free.next].free.prev - = _heapindex = block + blocks; - } else { - /* The block exactly matches our requirements, - so just remove it from the list. */ - _heapinfo[_heapinfo[block].free.next].free.prev - = _heapinfo[block].free.prev; - _heapinfo[_heapinfo[block].free.prev].free.next - = _heapindex = _heapinfo[block].free.next; - --_chunks_free; - } - - _heapinfo[block].busy.type = 0; - _heapinfo[block].busy.info.size = blocks; - ++_chunks_used; - _bytes_used += blocks * BLOCKSIZE; - _bytes_free -= blocks * BLOCKSIZE; - - /* Mark all the blocks of the object just allocated except for the - first with a negative number so you can find the first block by - adding that adjustment. */ - while (--blocks > 0) - _heapinfo[block + blocks].busy.info.size = -blocks; - } - - return result; -} - -#ifndef _LIBC - -/* On some ANSI C systems, some libc functions call _malloc, _free - and _realloc. Make them use the GNU functions. */ - -__ptr_t _malloc _((__malloc_size_t size)); - -__ptr_t -_malloc(size) - __malloc_size_t size; -{ - return malloc(size); -} - -void _free _((__ptr_t ptr)); - -void -_free(ptr) - __ptr_t ptr; -{ - free(ptr); -} - -__ptr_t _realloc _((__ptr_t ptr, size_t size)); - -__ptr_t -_realloc(ptr, size) - __ptr_t ptr; - __malloc_size_t size; -{ - return realloc(ptr, size); -} - -#endif -/* Free a block of memory allocated by `malloc'. - Copyright 1990, 1991, 1992, 1994 Free Software Foundation, Inc. - Written May 1989 by Mike Haertel. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -/* Debugging hook for free. */ -void (*__free_hook) __P((__ptr_t __ptr)); - -/* List of blocks allocated by memalign. */ -struct alignlist *_aligned_blocks = NULL; - -/* Return memory to the heap. - Like `free' but don't call a __free_hook if there is one. */ -void -_free_internal(ptr) - __ptr_t ptr; -{ - int type; - __malloc_size_t block, blocks; - register __malloc_size_t i; - struct list *prev, *next; - - block = BLOCK(ptr); - - type = _heapinfo[block].busy.type; - switch (type) { - case 0: - /* Get as many statistics as early as we can. */ - --_chunks_used; - _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE; - _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE; - - /* Find the free cluster previous to this one in the free list. - Start searching at the last block referenced; this may benefit - programs with locality of allocation. */ - i = _heapindex; - if (i > block) - while (i > block) - i = _heapinfo[i].free.prev; - else { - do - i = _heapinfo[i].free.next; - while (i > 0 && i < block); - i = _heapinfo[i].free.prev; - } - - /* Determine how to link this block into the free list. */ - if (block == i + _heapinfo[i].free.size) { - /* Coalesce this block with its predecessor. */ - _heapinfo[i].free.size += _heapinfo[block].busy.info.size; - block = i; - } else { - /* Really link this block back into the free list. */ - _heapinfo[block].free.size = _heapinfo[block].busy.info.size; - _heapinfo[block].free.next = _heapinfo[i].free.next; - _heapinfo[block].free.prev = i; - _heapinfo[i].free.next = block; - _heapinfo[_heapinfo[block].free.next].free.prev = block; - ++_chunks_free; - } - - /* Now that the block is linked in, see if we can coalesce it - with its successor (by deleting its successor from the list - and adding in its size). */ - if (block + _heapinfo[block].free.size == _heapinfo[block].free.next) { - _heapinfo[block].free.size - += _heapinfo[_heapinfo[block].free.next].free.size; - _heapinfo[block].free.next - = _heapinfo[_heapinfo[block].free.next].free.next; - _heapinfo[_heapinfo[block].free.next].free.prev = block; - --_chunks_free; - } - /* Now see if we can return stuff to the system. */ - blocks = _heapinfo[block].free.size; - if (blocks >= FINAL_FREE_BLOCKS && block + blocks == _heaplimit - && (*__morecore) (0) == ADDRESS(block + blocks)) { - register __malloc_size_t bytes = blocks * BLOCKSIZE; - _heaplimit -= blocks; - (*__morecore) (-bytes); - _heapinfo[_heapinfo[block].free.prev].free.next - = _heapinfo[block].free.next; - _heapinfo[_heapinfo[block].free.next].free.prev - = _heapinfo[block].free.prev; - block = _heapinfo[block].free.prev; - --_chunks_free; - _bytes_free -= bytes; - } - /* Set the next search to begin at this block. */ - _heapindex = block; - break; - - default: - /* Do some of the statistics. */ - --_chunks_used; - _bytes_used -= 1 << type; - ++_chunks_free; - _bytes_free += 1 << type; - - /* Get the address of the first free fragment in this block. */ - prev = (struct list *) ((char *) ADDRESS(block) + - (_heapinfo[block].busy.info.frag.first << type)); - - if (_heapinfo[block].busy.info.frag.nfree == - (__malloc_size_t) (BLOCKSIZE >> type) - 1) { - /* If all fragments of this block are free, remove them - from the fragment list and free the whole block. */ - next = prev; - for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> type); ++i) - next = next->next; - prev->prev->next = next; - if (next != NULL) - next->prev = prev->prev; - _heapinfo[block].busy.type = 0; - _heapinfo[block].busy.info.size = 1; - - /* Keep the statistics accurate. */ - ++_chunks_used; - _bytes_used += BLOCKSIZE; - _chunks_free -= BLOCKSIZE >> type; - _bytes_free -= BLOCKSIZE; - - free(ADDRESS(block)); - } else if (_heapinfo[block].busy.info.frag.nfree != 0) { - /* If some fragments of this block are free, link this - fragment into the fragment list after the first free - fragment of this block. */ - next = (struct list *) ptr; - next->next = prev->next; - next->prev = prev; - prev->next = next; - if (next->next != NULL) - next->next->prev = next; - ++_heapinfo[block].busy.info.frag.nfree; - } else { - /* No fragments of this block are free, so link this - fragment into the fragment list and announce that - it is the first free fragment of this block. */ - prev = (struct list *) ptr; - _heapinfo[block].busy.info.frag.nfree = 1; - _heapinfo[block].busy.info.frag.first = (unsigned long int) - ((unsigned long int) ((char *) ptr - (char *) NULL) - % BLOCKSIZE >> type); - prev->next = _fraghead[type].next; - prev->prev = &_fraghead[type]; - prev->prev->next = prev; - if (prev->next != NULL) - prev->next->prev = prev; - } - break; - } -} - -/* Return memory to the heap. */ -void -free(ptr) - __ptr_t ptr; -{ - register struct alignlist *l; - - if (ptr == NULL) - return; - - for (l = _aligned_blocks; l != NULL; l = l->next) - if (l->aligned == ptr) { - l->aligned = NULL; /* Mark the slot in the list as free. */ - ptr = l->exact; - break; - } - if (__free_hook != NULL) - (*__free_hook) (ptr); - else - _free_internal(ptr); -} - -/* Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -#ifdef _LIBC - -#include -#include - -#undef cfree - -function_alias(cfree, free, void, (ptr), DEFUN(cfree, (ptr), PTR ptr)) -#else - -void cfree _((__ptr_t ptr)); - -void -cfree(ptr) - __ptr_t ptr; -{ - free(ptr); -} - -#endif -/* Change the size of a block allocated by `malloc'. - Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. - Written May 1989 by Mike Haertel. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -#if (defined (MEMMOVE_MISSING) || \ - !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG)) - -/* Snarfed directly from Emacs src/dispnew.c: - XXX Should use system bcopy if it handles overlap. */ -#ifndef emacs - -/* Like bcopy except never gets confused by overlap. */ - -static void -safe_bcopy(from, to, size) - char *from, *to; - int size; -{ - if (size <= 0 || from == to) - return; - - /* If the source and destination don't overlap, then bcopy can - handle it. If they do overlap, but the destination is lower in - memory than the source, we'll assume bcopy can handle that. */ - if (to < from || from + size <= to) - bcopy(from, to, size); - - /* Otherwise, we'll copy from the end. */ - else { - register char *endf = from + size; - register char *endt = to + size; - - /* If TO - FROM is large, then we should break the copy into - nonoverlapping chunks of TO - FROM bytes each. However, if - TO - FROM is small, then the bcopy function call overhead - makes this not worth it. The crossover point could be about - anywhere. Since I don't think the obvious copy loop is too - bad, I'm trying to err in its favor. */ - if (to - from < 64) { - do - *--endt = *--endf; - while (endf != from); - } else { - for (;;) { - endt -= (to - from); - endf -= (to - from); - - if (endt < to) - break; - - bcopy(endf, endt, to - from); - } - - /* If SIZE wasn't a multiple of TO - FROM, there will be a - little left over. The amount left over is - (endt + (to - from)) - to, which is endt - from. */ - bcopy(from, to, endt - from); - } - } -} -#endif /* Not emacs. */ - -#define memmove(to, from, size) safe_bcopy ((from), (to), (size)) - -#endif - - -#define min(A, B) ((A) < (B) ? (A) : (B)) - -/* Debugging hook for realloc. */ -__ptr_t (*__realloc_hook) __P((__ptr_t __ptr, __malloc_size_t __size)); - -/* Resize the given region to the new size, returning a pointer - to the (possibly moved) region. This is optimized for speed; - some benchmarks seem to indicate that greater compactness is - achieved by unconditionally allocating and copying to a - new region. This module has incestuous knowledge of the - internals of both free and malloc. */ -__ptr_t -realloc(ptr, size) - __ptr_t ptr; - __malloc_size_t size; -{ - __ptr_t result; - int type; - __malloc_size_t block, blocks, oldlimit; - - if (size == 0) { - free(ptr); - return malloc(0); - } else if (ptr == NULL) - return malloc(size); - - if (__realloc_hook != NULL) - return (*__realloc_hook) (ptr, size); - - block = BLOCK(ptr); - - type = _heapinfo[block].busy.type; - switch (type) { - case 0: - /* Maybe reallocate a large block to a small fragment. */ - if (size <= BLOCKSIZE / 2) { - result = malloc(size); - if (result != NULL) { - memcpy(result, ptr, size); - _free_internal(ptr); - return result; - } - } - /* The new size is a large allocation as well; - see if we can hold it in place. */ - blocks = BLOCKIFY(size); - if ((__malloc_ptrdiff_t) blocks < _heapinfo[block].busy.info.size) { - /* The new size is smaller; return - excess memory to the free list. */ - _heapinfo[block + blocks].busy.type = 0; - _heapinfo[block + blocks].busy.info.size - = _heapinfo[block].busy.info.size - blocks; - _heapinfo[block].busy.info.size = blocks; - /* We have just created a new chunk by splitting a chunk in two. - Now we will free this chunk; increment the statistics counter - so it doesn't become wrong when _free_internal decrements it. */ - ++_chunks_used; - _free_internal(ADDRESS(block + blocks)); - result = ptr; - } else if ((__malloc_ptrdiff_t) blocks == _heapinfo[block].busy.info.size) - /* No size change necessary. */ - result = ptr; - else { - /* Won't fit, so allocate a new region that will. - Free the old region first in case there is sufficient - adjacent free space to grow without moving. */ - blocks = _heapinfo[block].busy.info.size; - /* Prevent free from actually returning memory to the system. */ - oldlimit = _heaplimit; - _heaplimit = 0; - _free_internal(ptr); - _heaplimit = oldlimit; - result = malloc(size); - if (result == NULL) { - /* Now we're really in trouble. We have to unfree - the thing we just freed. Unfortunately it might - have been coalesced with its neighbors. */ - if (_heapindex == block) - (void) malloc(blocks * BLOCKSIZE); - else { - __ptr_t previous = malloc((block - _heapindex) * BLOCKSIZE); - (void) malloc(blocks * BLOCKSIZE); - _free_internal(previous); - } - return NULL; - } - if (ptr != result) - memmove(result, ptr, blocks * BLOCKSIZE); - } - break; - - default: - /* Old size is a fragment; type is logarithm - to base two of the fragment size. */ - if (size > (__malloc_size_t) (1 << (type - 1)) && - size <= (__malloc_size_t) (1 << type)) - /* The new size is the same kind of fragment. */ - result = ptr; - else { - /* The new size is different; allocate a new space, - and copy the lesser of the new size and the old. */ - result = malloc(size); - if (result == NULL) - return NULL; - memcpy(result, ptr, min(size, (__malloc_size_t) 1 << type)); - free(ptr); - } - break; - } - - return result; -} - -/* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -/* Allocate an array of NMEMB elements each SIZE bytes long. - The entire array is initialized to zeros. */ -__ptr_t -calloc(nmemb, size) - register __malloc_size_t nmemb; - register __malloc_size_t size; -{ - register __ptr_t result = malloc(nmemb * size); - - if (result != NULL) - (void) memset(result, 0, nmemb * size); - - return result; -} - -/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library 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, or (at your option) - any later version. - - The GNU C Library 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 the GNU C Library; see the file COPYING. If not, write to - the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -#ifndef __GNU_LIBRARY__ -#define __sbrk sbrk -#endif - -#ifdef __GNU_LIBRARY__ -/* It is best not to declare this and cast its result on foreign operating - systems with potentially hostile include files. */ -extern __ptr_t __sbrk __P((int increment)); -#endif - -#ifndef NULL -#define NULL 0 -#endif - -/* Allocate INCREMENT more bytes of data space, - and return the start of data space, or NULL on errors. - If INCREMENT is negative, shrink data space. */ -__ptr_t -__default_morecore(increment) -#ifdef __STDC__ - ptrdiff_t increment; -#else - int - increment; -#endif -{ - __ptr_t result = (__ptr_t) __sbrk((int) increment); - if (result == (__ptr_t) -1) - return NULL; - return result; -} - -/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., 675 Mass Ave, - Cambridge, MA 02139, USA. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -__ptr_t (*__memalign_hook) __P((size_t __size, size_t __alignment)); - -__ptr_t -memalign(alignment, size) - __malloc_size_t alignment; - __malloc_size_t size; -{ - __ptr_t result; - unsigned long int adj; - - if (__memalign_hook) - return (*__memalign_hook) (alignment, size); - - size = ((size + alignment - 1) / alignment) * alignment; - - result = malloc(size); - if (result == NULL) - return NULL; - adj = (unsigned long int) ((unsigned long int) ((char *) result - - (char *) NULL)) % alignment; - if (adj != 0) { - struct alignlist *l; - for (l = _aligned_blocks; l != NULL; l = l->next) - if (l->aligned == NULL) - /* This slot is free. Use it. */ - break; - if (l == NULL) { - l = (struct alignlist *) malloc(sizeof(struct alignlist)); - if (l == NULL) { - free(result); - return NULL; - } - l->next = _aligned_blocks; - _aligned_blocks = l; - } - l->exact = result; - result = l->aligned = (char *) result + alignment - adj; - } - return result; -} diff --git a/src/help.c b/src/help.c index 948e6ce..102e949 100644 --- a/src/help.c +++ b/src/help.c @@ -33,15 +33,15 @@ static void do_new_spitfile(dbref player, char *arg1, help_file *help_dat); static const char *string_spitfile(help_file *help_dat, char *arg1); static help_indx *help_find_entry(help_file *help_dat, const char *the_topic); static const char *list_matching_entries(char *pattern, help_file *help_dat, - const char *sep); + const char *sep); static const char *normalize_entry(help_file *help_dat, char *arg1); static void help_build_index(help_file *h, int restricted); /** Linked list of help topic names. */ typedef struct TLIST { - char topic[TOPIC_NAME_LEN + 1]; /**< Name of topic */ - struct TLIST *next; /**< Pointer to next list entry */ + char topic[TOPIC_NAME_LEN + 1]; /**< Name of topic */ + struct TLIST *next; /**< Pointer to next list entry */ } tlist; tlist *top = NULL; /**< Pointer to top of linked list of topic names */ @@ -52,8 +52,8 @@ unsigned top_topics = 0; /**< Maximum number of topics loaded */ static void write_topic(long int p); -#define TRUE 1 /**< A true value */ -#define FALSE 0 /**< A false value */ +#define TRUE 1 /**< A true value */ +#define FALSE 0 /**< A false value */ COMMAND (cmd_helpcmd) { help_file *h; @@ -72,7 +72,7 @@ COMMAND (cmd_helpcmd) { if (wildcard(arg_left)) notify_format(player, T("Here are the entries which match '%s':\n%s"), - arg_left, list_matching_entries(arg_left, h, ", ")); + arg_left, list_matching_entries(arg_left, h, ", ")); else do_new_spitfile(player, arg_left, h); } @@ -152,7 +152,7 @@ help_reindex(dbref player) if (player != NOTHING) { notify(player, T("Help files reindexed.")); do_rawlog(LT_WIZ, T("Help files reindexed by %s(#%d)"), Name(player), - player); + player); } else do_rawlog(LT_WIZ, T("Help files reindexed.")); } @@ -200,7 +200,7 @@ do_new_spitfile(dbref player, char *arg1, help_file *help_dat) if ((fp = fopen(help_dat->file, FOPEN_READ)) == NULL) { notify(player, T("Sorry, that function is temporarily unavailable.")); do_log(LT_ERR, 0, 0, T("Can't open text file %s for reading"), - help_dat->file); + help_dat->file); return; } if (fseek(fp, entry->pos, 0) < 0L) { @@ -228,8 +228,8 @@ do_new_spitfile(dbref player, char *arg1, help_file *help_dat) notify(player, " "); } else { for (p = line; *p != '\0'; p++) - if (*p == '\n') - *p = '\0'; + if (*p == '\n') + *p = '\0'; notify(player, line); } } @@ -247,14 +247,14 @@ help_find_entry(help_file *help_dat, const char *the_topic) size_t n; help_indx *entry = NULL; - if (help_dat->entries < 10) { /* Just do a linear search for small files */ + if (help_dat->entries < 10) { /* Just do a linear search for small files */ for (n = 0; n < help_dat->entries; n++) { if (string_prefix(help_dat->indx[n].topic, the_topic)) { - entry = &help_dat->indx[n]; - break; + entry = &help_dat->indx[n]; + break; } } - } else { /* Binary search of the index */ + } else { /* Binary search of the index */ int left = 0; int cmp; int right = help_dat->entries - 1; @@ -263,31 +263,31 @@ help_find_entry(help_file *help_dat, const char *the_topic) n = (left + right) / 2; if (left > right) - break; + break; cmp = strcasecmp(the_topic, help_dat->indx[n].topic); if (cmp == 0) { - entry = &help_dat->indx[n]; - break; + entry = &help_dat->indx[n]; + break; } else if (cmp < 0) { - /* We need to catch the first prefix */ - if (string_prefix(help_dat->indx[n].topic, the_topic)) { - int m; - for (m = n - 1; m >= 0; m--) { - if (!string_prefix(help_dat->indx[m].topic, the_topic)) - break; - } - entry = &help_dat->indx[m + 1]; - break; - } - if (left == right) - break; - right = n - 1; - } else { /* cmp > 0 */ - if (left == right) - break; - left = n + 1; + /* We need to catch the first prefix */ + if (string_prefix(help_dat->indx[n].topic, the_topic)) { + int m; + for (m = n - 1; m >= 0; m--) { + if (!string_prefix(help_dat->indx[m].topic, the_topic)) + break; + } + entry = &help_dat->indx[m + 1]; + break; + } + if (left == right) + break; + right = n - 1; + } else { /* cmp > 0 */ + if (left == right) + break; + left = n + 1; } } } @@ -304,11 +304,11 @@ write_topic(long int p) if (num_topics >= top_topics) { top_topics += top_topics / 2 + 20; if (topics) - topics = (help_indx *) realloc(topics, top_topics * sizeof(help_indx)); + topics = (help_indx *) realloc(topics, top_topics * sizeof(help_indx)); else - topics = (help_indx *) malloc(top_topics * sizeof(help_indx)); + topics = (help_indx *) malloc(top_topics * sizeof(help_indx)); if (!topics) { - mush_panic(T("Out of memory")); + mush_panic(T("Out of memory")); } } temp = &topics[num_topics++]; @@ -368,19 +368,19 @@ help_build_index(help_file *h, int restricted) if (ntopics == 0) { /* Looking for the first topic, but we'll ignore blank lines */ if (!line[0]) { - /* Someone's feeding us /dev/null? */ - do_rawlog(LT_ERR, T("Malformed help file %s doesn't start with &"), - h->file); - fclose(rfp); - return; + /* Someone's feeding us /dev/null? */ + do_rawlog(LT_ERR, T("Malformed help file %s doesn't start with &"), + h->file); + fclose(rfp); + return; } if (isspace((unsigned char) line[0])) - continue; + continue; if (line[0] != '&') { - do_rawlog(LT_ERR, T("Malformed help file %s doesn't start with &"), - h->file); - fclose(rfp); - return; + do_rawlog(LT_ERR, T("Malformed help file %s doesn't start with &"), + h->file); + fclose(rfp); + return; } } n = strlen(line); @@ -390,36 +390,36 @@ help_build_index(help_file *h, int restricted) if (line[0] == '&') { ++ntopics; if (!in_topic) { - /* Finish up last entry */ - if (ntopics > 1) { - write_topic(pos); - } - in_topic = TRUE; + /* Finish up last entry */ + if (ntopics > 1) { + write_topic(pos); + } + in_topic = TRUE; } /* parse out the topic */ /* Get the beginning of the topic string */ for (topic = &line[1]; - (*topic == ' ' || *topic == '\t') && *topic != '\0'; topic++) ; + (*topic == ' ' || *topic == '\t') && *topic != '\0'; topic++) ; /* Get the topic */ strcpy(the_topic, ""); for (i = -1, s = topic; *s != '\n' && *s != '\0'; s++) { - if (i >= TOPIC_NAME_LEN - 1) - break; - if (*s != ' ' || the_topic[i] != ' ') - the_topic[++i] = *s; + if (i >= TOPIC_NAME_LEN - 1) + break; + if (*s != ' ' || the_topic[i] != ' ') + the_topic[++i] = *s; } if ((restricted && the_topic[0] == '&') - || (!restricted && the_topic[0] != '&')) { - the_topic[++i] = '\0'; - cur = (tlist *) malloc(sizeof(tlist)); - strcpy(cur->topic, the_topic); - cur->next = top; - top = cur; + || (!restricted && the_topic[0] != '&')) { + the_topic[++i] = '\0'; + cur = (tlist *) malloc(sizeof(tlist)); + strcpy(cur->topic, the_topic); + cur->next = top; + top = cur; } } else { if (in_topic) { - pos = bigpos; + pos = bigpos; } in_topic = FALSE; } @@ -554,7 +554,7 @@ list_matching_entries(char *pattern, help_file *help_dat, const char *sep) bp = buff; if (help_dat->admin) - offset = 1; /* To skip the leading & */ + offset = 1; /* To skip the leading & */ else offset = 0; @@ -580,7 +580,7 @@ list_matching_entries(char *pattern, help_file *help_dat, const char *sep) if (quick_wild(pattern, help_dat->indx[n].topic + offset)) { safe_str(help_dat->indx[n].topic + offset, buff, &bp); if (sep) - safe_strl(sep, len, buff, &bp); + safe_strl(sep, len, buff, &bp); } if (bp > buff) diff --git a/src/htab.c b/src/htab.c index 08a30a1..f3bf6c5 100644 --- a/src/htab.c +++ b/src/htab.c @@ -29,8 +29,8 @@ static int hash_val(register const char *k, int mask); /* This hash function adapted from http://burtleburtle.net/bob/hash/evahash.html */ -typedef unsigned long int u4; /**< unsigned 4-byte type */ -typedef unsigned char u1; /**< unsigned 1-byte type */ +typedef unsigned long int u4; /**< unsigned 4-byte type */ +typedef unsigned char u1; /**< unsigned 1-byte type */ /* The mixing step */ #define mix(a,b,c) \ @@ -50,14 +50,14 @@ typedef unsigned char u1; /**< unsigned 1-byte type */ static int hash_val(register const char *k, int mask) { - register u4 a, b, c; /* the internal state */ - u4 len, length; /* how many key bytes still need mixing */ - static u4 initval = 5432; /* the previous hash, or an arbitrary value */ + register u4 a, b, c; /* the internal state */ + u4 len, length; /* how many key bytes still need mixing */ + static u4 initval = 5432; /* the previous hash, or an arbitrary value */ /* Set up the internal state */ length = len = strlen(k); - a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */ - c = initval; /* variable initialization of internal state */ + a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */ + c = initval; /* variable initialization of internal state */ /*---------------------------------------- handle most of the key */ while (len >= 12) { @@ -71,7 +71,7 @@ hash_val(register const char *k, int mask) /*------------------------------------- handle the last 11 bytes */ c = c + length; - switch (len) { /* all the case statements fall through */ + switch (len) { /* all the case statements fall through */ case 11: c = c + ((u4) k[10] << 24); case 10: @@ -103,7 +103,7 @@ hash_val(register const char *k, int mask) } -#else /* NEW_HASH_FUN */ +#else /* NEW_HASH_FUN */ /** Compute a hash value for mask-style hashing. * Given a null key, return 0. Otherwise, add up the numeric value * of all the characters and return the sum modulo the size of the @@ -124,7 +124,7 @@ hash_val(const char *key, int hashmask) hash = (hash << 5) + hash + *sp; return (hash & hashmask); } -#endif /* NEW_HASH_FUN */ +#endif /* NEW_HASH_FUN */ /* ---------------------------------------------------------------------- * hash_getmask: Get hash mask for mask-style hashing. @@ -261,15 +261,15 @@ hash_resize(HASHTAB *htab, int size) nent = hent->next; hval = hash_val(hent->key, mask); for (curr = newarr[hval], old = NULL; curr; old = curr, curr = curr->next) { - if (strcmp(curr->key, hent->key) > 0) - break; + if (strcmp(curr->key, hent->key) > 0) + break; } if (old) { - old->next = hent; - hent->next = curr; + old->next = hent; + hent->next = curr; } else { - hent->next = newarr[hval]; - newarr[hval] = hent; + hent->next = newarr[hval]; + newarr[hval] = hent; } hent = nent; } @@ -312,7 +312,7 @@ hash_new(HASHTAB *htab, const char *key) for (curr = old->next; curr; old = curr, curr = curr->next) { /* Comparison will never be 0 because hash_add checks to see if the entry is already present. */ - if (strcmp(key, curr->key) < 0) { /* Insert before curr */ + if (strcmp(key, curr->key) < 0) { /* Insert before curr */ old->next = hptr; hptr->next = curr; return hptr; @@ -336,7 +336,7 @@ hash_new(HASHTAB *htab, const char *key) */ int hash_add(HASHTAB *htab, const char *key, void *hashdata, - int extra_size __attribute__ ((__unused__))) + int extra_size __attribute__ ((__unused__))) { HASHENT *hptr; @@ -527,7 +527,7 @@ void hash_stats_header(dbref player) { notify_format(player, - "Table Buckets Entries LChain ECh 1Ch 2Ch 3Ch 4+Ch AvgCh ~Memory"); + "Table Buckets Entries LChain ECh 1Ch 2Ch 3Ch 4+Ch AvgCh ~Memory"); } /** Display stats on a hashtable. @@ -572,8 +572,8 @@ hash_stats(dbref player, HASHTAB *htab, const char *hname) totchains += lengths[n]; notify_format(player, - "%-10s %7d %7d %6d %4d %4d %4d %4d %4d %6.3f %7u", hname, - htab->hashsize, htab->entries, longest, lengths[0], lengths[1], - lengths[2], lengths[3], lengths[4], - totchains > 0 ? chainlens / totchains : 0.0, bytes); + "%-10s %7d %7d %6d %4d %4d %4d %4d %4d %6.3f %7u", hname, + htab->hashsize, htab->entries, longest, lengths[0], lengths[1], + lengths[2], lengths[3], lengths[4], + totchains > 0 ? chainlens / totchains : 0.0, bytes); } diff --git a/src/ident.c b/src/ident.c index 0ee9f58..4ae8c99 100644 --- a/src/ident.c +++ b/src/ident.c @@ -49,7 +49,7 @@ #include #endif #include -#endif /* WIN32 */ +#endif /* WIN32 */ #ifdef I_UNISTD #include @@ -67,19 +67,19 @@ /** Structure to track an ident connection. */ typedef struct { - int fd; /**< file descriptor to read from. */ - char buf[IDBUFSIZE]; /**< buffer to hold ident data. */ + int fd; /**< file descriptor to read from. */ + char buf[IDBUFSIZE]; /**< buffer to hold ident data. */ } ident_t; static ident_t *id_open(struct sockaddr *faddr, - socklen_t flen, - struct sockaddr *laddr, socklen_t llen, int *timeout); + socklen_t flen, + struct sockaddr *laddr, socklen_t llen, int *timeout); static int id_query(ident_t * id, - struct sockaddr *laddr, - socklen_t llen, - struct sockaddr *faddr, socklen_t flen, int *timeout); + struct sockaddr *laddr, + socklen_t llen, + struct sockaddr *faddr, socklen_t flen, int *timeout); static int id_close(ident_t * id); @@ -117,7 +117,7 @@ ident_lookup(int fd, int *timeout) */ IDENT * ident_query(struct sockaddr *laddr, socklen_t llen, - struct sockaddr *raddr, socklen_t rlen, int *timeout) + struct sockaddr *raddr, socklen_t rlen, int *timeout) { int res; ident_t *id; @@ -159,7 +159,7 @@ ident_query(struct sockaddr *laddr, socklen_t llen, } id_close(id); - return ident; /* At last! */ + return ident; /* At last! */ } /** Perform an ident lookup and return the remote identifier as a @@ -209,7 +209,7 @@ ident_free(IDENT *id) static ident_t * id_open(struct sockaddr *faddr, socklen_t flen, - struct sockaddr *laddr, socklen_t llen, int *timeout) + struct sockaddr *laddr, socklen_t llen, int *timeout) { ident_t *id; char host[NI_MAXHOST]; @@ -227,7 +227,7 @@ id_open(struct sockaddr *faddr, socklen_t flen, memset(id, 0, sizeof(ident_t)); if (getnameinfo(faddr, flen, host, sizeof(host), NULL, 0, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { + NI_NUMERICHOST | NI_NUMERICSERV) != 0) { free(id); return 0; } @@ -237,14 +237,14 @@ id_open(struct sockaddr *faddr, socklen_t flen, memcpy(&myinterface, laddr, llen); if (myinterface.addr.sa_family == AF_INET) ((struct sockaddr_in *) &myinterface.addr)->sin_port = 0; -#ifdef HAS_IPV6 /* Bleah, I wanted to avoid stuff like this */ +#ifdef HAS_IPV6 /* Bleah, I wanted to avoid stuff like this */ else if (myinterface.addr.sa_family == AF_INET6) ((struct sockaddr_in6 *) &myinterface.addr)->sin6_port = 0; #endif id->fd = make_socket_conn(host, &myinterface.addr, llen, IDPORT, timeout); - if (id->fd < 0) /* Couldn't connect to an ident server */ + if (id->fd < 0) /* Couldn't connect to an ident server */ goto ERROR_BRANCH; if (timeout) { @@ -285,7 +285,7 @@ id_open(struct sockaddr *faddr, socklen_t flen, ERROR_BRANCH: #ifndef WIN32 - tmperrno = errno; /* Save, so close() won't erase it */ + tmperrno = errno; /* Save, so close() won't erase it */ #endif closesocket(id->fd); free(id); @@ -320,7 +320,7 @@ id_close(ident_t * id) static int id_query(ident_t * id, struct sockaddr *laddr, socklen_t llen, - struct sockaddr *faddr, socklen_t flen, int *timeout) + struct sockaddr *faddr, socklen_t flen, int *timeout) { int res; char buf[80]; @@ -329,10 +329,10 @@ id_query(ident_t * id, struct sockaddr *laddr, socklen_t llen, struct timeval to; getnameinfo(laddr, llen, NULL, 0, port, sizeof(port), - NI_NUMERICHOST | NI_NUMERICSERV); + NI_NUMERICHOST | NI_NUMERICSERV); sprintf(buf, "%s , ", port); getnameinfo(faddr, flen, NULL, 0, port, sizeof(port), - NI_NUMERICHOST | NI_NUMERICSERV); + NI_NUMERICHOST | NI_NUMERICSERV); strncat(buf, port, sizeof(buf)); strncat(buf, "\r\n", sizeof(buf)); @@ -458,7 +458,7 @@ id_parse(ident_t * id, int *timeout, IDENT **ident) } } while (pos < sizeof(id->buf) && - (res = recv(id->fd, id->buf + pos, 1, 0)) == 1 && id->buf[pos] != '\n') + (res = recv(id->fd, id->buf + pos, 1, 0)) == 1 && id->buf[pos] != '\n') pos++; if (res < 0) return -1; @@ -509,7 +509,7 @@ id_parse(ident_t * id, int *timeout, IDENT **ident) if (c == ',') { cp = xstrtok(NULL, ":", &c); if (!cp) - return -2; + return -2; tmp_charset = cp; @@ -517,7 +517,7 @@ id_parse(ident_t * id, int *timeout, IDENT **ident) /* We have even more subfields - ignore them */ if (c == ',') - xstrtok(NULL, ":", &c); + xstrtok(NULL, ":", &c); } if (tmp_charset && strcmp(tmp_charset, "OCTET") == 0) cp = xstrtok(NULL, NULL, &c); diff --git a/src/info_slave.c b/src/info_slave.c index 6b82690..4ad2746 100644 --- a/src/info_slave.c +++ b/src/info_slave.c @@ -101,7 +101,7 @@ main(int argc, char *argv[]) int port; int fd; union sockaddr_u local, remote; - static char buf[BUFFER_LEN]; /* overkill */ + static char buf[BUFFER_LEN]; /* overkill */ char *bp; int len, size; IDENT *ident_result; @@ -132,10 +132,10 @@ main(int argc, char *argv[]) use_dns = 1; #ifdef HAS_SOCKETPAIR - mush = port; /* We inherit open file descriptions and sockets from parent */ + mush = port; /* We inherit open file descriptions and sockets from parent */ #else mush = make_socket_conn("127.0.0.1", NULL, 0, port, NULL); - if (mush == -1) { /* Couldn't connect */ + if (mush == -1) { /* Couldn't connect */ fprintf(stderr, "Couldn't connect to mush!\n"); return EXIT_FAILURE; } @@ -182,13 +182,13 @@ main(int argc, char *argv[]) bp = buf; if (getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, 0, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) + NI_NUMERICHOST | NI_NUMERICSERV) != 0) safe_str("An error occured", buf, &bp); else safe_str(host, buf, &bp); safe_chr('^', buf, &bp); if (getnameinfo(&local.addr, llen, NULL, 0, lport, sizeof lport, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) + NI_NUMERICHOST | NI_NUMERICSERV) != 0) safe_str("An error occured", buf, &bp); else safe_str(lport, buf, &bp); @@ -197,20 +197,20 @@ main(int argc, char *argv[]) if (use_ident > 0) { timeout = use_ident; ident_result = - ident_query(&local.addr, llen, &remote.addr, rlen, &timeout); + ident_query(&local.addr, llen, &remote.addr, rlen, &timeout); if (ident_result && ident_result->identifier) { - safe_str(ident_result->identifier, buf, &bp); - safe_chr('@', buf, &bp); + safe_str(ident_result->identifier, buf, &bp); + safe_chr('@', buf, &bp); } if (ident_result) - ident_free(ident_result); + ident_free(ident_result); } if (use_dns) { if (getnameinfo(&remote.addr, rlen, host, sizeof host, NULL, 0, - NI_NUMERICSERV) != 0) { - safe_str("An error occured", buf, &bp); + NI_NUMERICSERV) != 0) { + safe_str("An error occured", buf, &bp); } else { - safe_str(host, buf, &bp); + safe_str(host, buf, &bp); } } else safe_str(host, buf, &bp); diff --git a/src/local.dst b/src/local.dst index 120c07a..b38bcea 100644 --- a/src/local.dst +++ b/src/local.dst @@ -53,9 +53,9 @@ local_configs() * but just config_string for strings. */ add_config("use_example", cf_bool, &config_example, sizeof config_example, - "cosmetic"); + "cosmetic"); add_config("some_string", cf_str, config_string, sizeof config_string, - "cosmetic"); + "cosmetic"); #endif } @@ -114,8 +114,8 @@ local_timer(void) */ void local_connect(dbref player __attribute__ ((__unused__)), - int isnew __attribute__ ((__unused__)), - int num __attribute__ ((__unused__))) + int isnew __attribute__ ((__unused__)), + int num __attribute__ ((__unused__))) { } @@ -124,7 +124,7 @@ local_connect(dbref player __attribute__ ((__unused__)), */ void local_disconnect(dbref player __attribute__ ((__unused__)), - int num __attribute__ ((__unused__))) + int num __attribute__ ((__unused__))) { } @@ -166,7 +166,7 @@ local_data_create(dbref object __attribute__ ((__unused__))) void local_data_clone(dbref clone __attribute__ ((__unused__)), - dbref source __attribute__ ((__unused__))) + dbref source __attribute__ ((__unused__))) { } @@ -191,8 +191,8 @@ local_data_free(dbref object __attribute__ ((__unused__))) */ int local_can_interact_first(dbref from __attribute__ ((__unused__)), - dbref to __attribute__ ((__unused__)), int type - __attribute__ ((__unused__))) + dbref to __attribute__ ((__unused__)), int type + __attribute__ ((__unused__))) { return NOTHING; @@ -201,8 +201,8 @@ local_can_interact_first(dbref from __attribute__ ((__unused__)), /* This one is called *after* most standard interaction checks. */ int local_can_interact_last(dbref from __attribute__ ((__unused__)), - dbref to __attribute__ ((__unused__)), int type - __attribute__ ((__unused__))) + dbref to __attribute__ ((__unused__)), int type + __attribute__ ((__unused__))) { /* from is where the message is coming from, in theory. It makes sense * for sound, but think of it as light rays for visiblity or matching. @@ -256,10 +256,10 @@ local_can_interact_last(dbref from __attribute__ ((__unused__)), /* Splits the universe in half, half FOO and half not. */ return (has_flag_by_name(to, "FOO", NOTYPE) == - has_flag_by_name(from, "FOO", NOTYPE)); + has_flag_by_name(from, "FOO", NOTYPE)); -#endif /* NEVER */ +#endif /* NEVER */ /* You want to return NOTHING if you haven't made up your mind */ return NOTHING; diff --git a/src/lock.c b/src/lock.c index 1e886c1..16e56b2 100644 --- a/src/lock.c +++ b/src/lock.c @@ -54,27 +54,27 @@ /* If any lock_type ever contains the character '|', reading in locks * from the db will break. */ -const lock_type Basic_Lock = "Basic"; /**< Name of basic lock */ -const lock_type Enter_Lock = "Enter"; /**< Name of enter lock */ -const lock_type Use_Lock = "Use"; /**< Name of use lock */ -const lock_type Zone_Lock = "Zone"; /**< Name of zone lock */ -const lock_type Page_Lock = "Page"; /**< Name of page lock */ +const lock_type Basic_Lock = "Basic"; /**< Name of basic lock */ +const lock_type Enter_Lock = "Enter"; /**< Name of enter lock */ +const lock_type Use_Lock = "Use"; /**< Name of use lock */ +const lock_type Zone_Lock = "Zone"; /**< Name of zone lock */ +const lock_type Page_Lock = "Page"; /**< Name of page lock */ const lock_type Tport_Lock = "Teleport"; /**< Name of teleport lock */ -const lock_type Speech_Lock = "Speech"; /**< Name of speech lock */ -const lock_type Listen_Lock = "Listen"; /**< Name of listen lock */ +const lock_type Speech_Lock = "Speech"; /**< Name of speech lock */ +const lock_type Listen_Lock = "Listen"; /**< Name of listen lock */ const lock_type Command_Lock = "Command"; /**< Name of command lock */ -const lock_type Parent_Lock = "Parent"; /**< Name of parent lock */ -const lock_type Link_Lock = "Link"; /**< Name of link lock */ -const lock_type Leave_Lock = "Leave"; /**< Name of leave lock */ -const lock_type Drop_Lock = "Drop"; /**< Name of drop lock */ -const lock_type Give_Lock = "Give"; /**< Name of give lock */ -const lock_type Mail_Lock = "Mail"; /**< Name of mail lock */ -const lock_type Follow_Lock = "Follow"; /**< Name of follow lock */ +const lock_type Parent_Lock = "Parent"; /**< Name of parent lock */ +const lock_type Link_Lock = "Link"; /**< Name of link lock */ +const lock_type Leave_Lock = "Leave"; /**< Name of leave lock */ +const lock_type Drop_Lock = "Drop"; /**< Name of drop lock */ +const lock_type Give_Lock = "Give"; /**< Name of give lock */ +const lock_type Mail_Lock = "Mail"; /**< Name of mail lock */ +const lock_type Follow_Lock = "Follow"; /**< Name of follow lock */ const lock_type Examine_Lock = "Examine"; /**< Name of examine lock */ -const lock_type Chzone_Lock = "Chzone"; /**< Name of chzone lock */ +const lock_type Chzone_Lock = "Chzone"; /**< Name of chzone lock */ const lock_type Forward_Lock = "Forward"; /**< Name of forward lock */ const lock_type Control_Lock = "Control"; /**< Name of control lock */ -const lock_type Dropto_Lock = "Dropto"; /**< Name of dropto lock */ +const lock_type Dropto_Lock = "Dropto"; /**< Name of dropto lock */ const lock_type Destroy_Lock = "Destroy"; /**< Name of destroy lock */ const lock_type Interact_Lock = "Interact"; /**< Name of interaction lock */ const lock_type Take_Lock = "Take"; /**< Name of take lock */ @@ -353,17 +353,17 @@ getlockstruct(dbref thing, lock_type type) do { for (; GoodObject(p); p = Parent(p)) { if (count++ > 100) - return NULL; + return NULL; if (p == ancestor) - ancestor_in_chain = 1; + ancestor_in_chain = 1; ll = Locks(p); while (ll && L_TYPE(ll)) { - cmp = strcasecmp(L_TYPE(ll), type); - if (cmp == 0) - return (p != thing && (ll->flags & LF_PRIVATE)) ? NULL : ll; - else if (cmp > 0) - break; - ll = ll->next; + cmp = strcasecmp(L_TYPE(ll), type); + if (cmp == 0) + return (p != thing && (ll->flags & LF_PRIVATE)) ? NULL : ll; + else if (cmp > 0) + break; + ll = ll->next; } } p = ancestor; @@ -530,9 +530,9 @@ add_lock_raw(dbref player, dbref thing, lock_type type, boolexp key, int flags) if (flags == -1) { const lock_list *l2 = get_lockproto(real_type); if (l2) - ll->flags = l2->flags; + ll->flags = l2->flags; else - ll->flags = 0; + ll->flags = 0; } else { ll->flags = flags; } @@ -820,7 +820,7 @@ eval_lock(dbref player, dbref thing, lock_type ltype) */ int eval_lock_with(dbref player, dbref thing, lock_type ltype, dbref env0, - dbref env1) + dbref env1) { char *myenv[10] = { NULL }; char e0[SBUF_LEN], e1[SBUF_LEN], *ep; @@ -863,7 +863,7 @@ eval_lock_with(dbref player, dbref thing, lock_type ltype, dbref env0, */ int fail_lock(dbref player, dbref thing, lock_type ltype, const char *def, - dbref loc) + dbref loc) { const LOCKMSGINFO *lm; char atr[BUFFER_LEN]; @@ -999,21 +999,21 @@ check_zone_lock(dbref player, dbref zone, int noisy) add_lock(GOD, zone, Zone_Lock, parse_boolexp(zone, "=me", Zone_Lock), -1); if (noisy) notify_format(player, - T - ("Unlocked zone %s - automatically zone-locking to itself"), - unparse_object(player, zone)); + T + ("Unlocked zone %s - automatically zone-locking to itself"), + unparse_object(player, zone)); } else if (eval_lock(Location(player), zone, Zone_Lock)) { /* Does #0 and #2 pass it? If so, probably trivial elock */ if (eval_lock(PLAYER_START, zone, Zone_Lock) && - eval_lock(MASTER_ROOM, zone, Zone_Lock)) { + eval_lock(MASTER_ROOM, zone, Zone_Lock)) { if (noisy) - notify_format(player, - T("Zone %s really should have a more secure zone-lock."), - unparse_object(player, zone)); - } else /* Probably inexact zone lock */ + notify_format(player, + T("Zone %s really should have a more secure zone-lock."), + unparse_object(player, zone)); + } else /* Probably inexact zone lock */ notify_format(player, - T - ("Warning: Zone %s may have loose zone lock. Lock zones to =player, not player"), - unparse_object(player, zone)); + T + ("Warning: Zone %s may have loose zone lock. Lock zones to =player, not player"), + unparse_object(player, zone)); } } diff --git a/src/log.c b/src/log.c index 7242970..7e87c70 100644 --- a/src/log.c +++ b/src/log.c @@ -41,7 +41,7 @@ static void end_log(const char *filename); BUFFERQ *activity_bq = NULL; -HASHTAB htab_logfiles; /**< Hash table of logfile names and descriptors */ +HASHTAB htab_logfiles; /**< Hash table of logfile names and descriptors */ /* log file pointers */ FILE *connlog_fp; /**< Connect log */ @@ -69,7 +69,7 @@ quick_unparse(dbref object) default: bp = buff; safe_format(buff, &bp, "%s(#%d%s)", - Name(object), object, unparse_flags(object, GOD)); + Name(object), object, unparse_flags(object, GOD)); *bp = '\0'; } @@ -100,12 +100,12 @@ start_log(FILE ** fp, const char *filename) *fp = fopen(newfilename, "a"); if (*fp == NULL) { - fprintf(stderr, T("WARNING: cannot open log %s\n"), newfilename); - *fp = stderr; + fprintf(stderr, T("WARNING: cannot open log %s\n"), newfilename); + *fp = stderr; } else { - hashadd(strupper(filename), (void *) *fp, &htab_logfiles); - fprintf(*fp, "START OF LOG.\n"); - fflush(*fp); + hashadd(strupper(filename), (void *) *fp, &htab_logfiles); + fprintf(*fp, "START OF LOG.\n"); + fflush(*fp); } } } @@ -280,11 +280,11 @@ do_log(int logtype, dbref player, dbref object, const char *fmt, ...) if (GoodObject(object)) { strcpy(unp2, quick_unparse(object)); do_rawlog(logtype, T("CMD: %s %s / %s: %s"), - (Suspect(player) ? "SUSPECT" : ""), unp1, unp2, tbuf1); + (Suspect(player) ? "SUSPECT" : ""), unp1, unp2, tbuf1); } else { strcpy(unp2, quick_unparse(Location(player))); do_rawlog(logtype, T("CMD: %s %s in %s: %s"), - (Suspect(player) ? "SUSPECT" : ""), unp1, unp2, tbuf1); + (Suspect(player) ? "SUSPECT" : ""), unp1, unp2, tbuf1); } break; case LT_WIZ: @@ -310,9 +310,9 @@ do_log(int logtype, dbref player, dbref object, const char *fmt, ...) strcpy(unp1, quick_unparse(player)); strcpy(unp2, quick_unparse(Location(player))); do_rawlog(logtype, T("HUH: %s in %s [%s]: %s"), - unp1, unp2, - (GoodObject(Location(player))) ? - Name(Owner(Location(player))) : T("bad object"), tbuf1); + unp1, unp2, + (GoodObject(Location(player))) ? + Name(Owner(Location(player))) : T("bad object"), tbuf1); } break; default: @@ -355,7 +355,7 @@ do_logwipe(dbref player, int logtype, char *str) } notify(player, T("Wrong password.")); do_log(LT_WIZ, player, NOTHING, - T("Invalid attempt to wipe the %s log, password %s"), lname, str); + T("Invalid attempt to wipe the %s log, password %s"), lname, str); return; } switch (logtype) { @@ -468,26 +468,26 @@ notify_activity(dbref player, int num_lines, int dump) buf = iter_bufferq(activity_bq, &p, &plr, &type, ×tamp); if (skip <= 0) { if (buf) { - stamp = show_time(timestamp, 0); - switch (type) { - case LA_CMD: - typestr = "CMD"; - break; - case LA_PE: - typestr = "EXP"; - break; - case LA_LOCK: - typestr = "LCK"; - break; - default: - typestr = "???"; - break; - } - - if (dump) - do_rawlog(LT_ERR, "[%s/#%d/%s] %s", stamp, plr, typestr, buf); - else - notify_format(player, "[%s/#%d/%s] %s", stamp, plr, typestr, buf); + stamp = show_time(timestamp, 0); + switch (type) { + case LA_CMD: + typestr = "CMD"; + break; + case LA_PE: + typestr = "EXP"; + break; + case LA_LOCK: + typestr = "LCK"; + break; + default: + typestr = "???"; + break; + } + + if (dump) + do_rawlog(LT_ERR, "[%s/#%d/%s] %s", stamp, plr, typestr, buf); + else + notify_format(player, "[%s/#%d/%s] %s", stamp, plr, typestr, buf); } } skip--; diff --git a/src/look.c b/src/look.c index a563d60..5d96b67 100644 --- a/src/look.c +++ b/src/look.c @@ -103,10 +103,10 @@ look_exits(dbref player, dbref loc, const char *exit_name) bp = arg; DOLIST(thing, Exits(loc)) { if (((Light(loc) || Light(thing)) || !(Dark(loc) || Dark(thing))) - && can_interact(thing, player, INTERACT_SEE)) { - if (bp != arg) - safe_chr(' ', arg, &bp); - safe_dbref(thing, arg, &bp); + && can_interact(thing, player, INTERACT_SEE)) { + if (bp != arg) + safe_chr(' ', arg, &bp); + safe_dbref(thing, arg, &bp); } } *bp = '\0'; @@ -140,23 +140,23 @@ look_exits(dbref player, dbref loc, const char *exit_name) for (thing = Exits(loc); thing != NOTHING; thing = Next(thing)) { total_count++; if (!Transparented(loc) || Opaque(thing)) - exit_count++; + exit_count++; } } else if (Dark(loc)) { for (thing = Exits(loc); thing != NOTHING; thing = Next(thing)) { if (Light(thing) && can_interact(thing, player, INTERACT_SEE)) { - total_count++; - if (!Transparented(loc) || Opaque(thing)) - exit_count++; + total_count++; + if (!Transparented(loc) || Opaque(thing)) + exit_count++; } } } else { for (thing = Exits(loc); thing != NOTHING; thing = Next(thing)) { if ((Light(thing) || !DarkLegal(thing)) && - can_interact(thing, player, INTERACT_SEE)) { - total_count++; - if (!Transparented(loc) || Opaque(thing)) - exit_count++; + can_interact(thing, player, INTERACT_SEE)) { + total_count++; + if (!Transparented(loc) || Opaque(thing)) + exit_count++; } } } @@ -436,7 +436,7 @@ look_simple(dbref player, dbref thing) PEND; notify_by(thing, player, pbuff); look_description(player, thing, T("You see nothing special."), "DESCRIBE", - "DESCFORMAT"); + "DESCFORMAT"); did_it(player, thing, NULL, NULL, "ODESCRIBE", NULL, "ADESCRIBE", NOTHING); if (IsExit(thing) && Transparented(thing)) { if (Cloudy(thing)) @@ -488,9 +488,9 @@ look_room(dbref player, dbref loc, enum look_type style) if (SUPPORT_PUEBLO && style == LOOK_AUTO) { a = atr_get(loc, "VRML_URL"); if (a) { - tag(tprintf("IMG XCH_GRAPH=LOAD HREF=\"%s\"", atr_value(a))); + tag(tprintf("IMG XCH_GRAPH=LOAD HREF=\"%s\"", atr_value(a))); } else { - tag("IMG XCH_GRAPH=HIDE"); + tag("IMG XCH_GRAPH=HIDE"); } } tag("HR"); @@ -501,25 +501,25 @@ look_room(dbref player, dbref loc, enum look_type style) if (!IsRoom(loc)) { if (style != LOOK_AUTO || !Terse(player)) { if (atr_get(loc, "IDESCRIBE")) { - look_description(player, loc, NULL, "IDESCRIBE", "IDESCFORMAT"); - did_it(player, loc, NULL, NULL, "OIDESCRIBE", NULL, - "AIDESCRIBE", NOTHING); + look_description(player, loc, NULL, "IDESCRIBE", "IDESCFORMAT"); + did_it(player, loc, NULL, NULL, "OIDESCRIBE", NULL, + "AIDESCRIBE", NOTHING); } else if (atr_get(loc, "IDESCFORMAT")) { - look_description(player, loc, NULL, "DESCRIBE", "IDESCFORMAT"); + look_description(player, loc, NULL, "DESCRIBE", "IDESCFORMAT"); } else - look_description(player, loc, NULL, "DESCRIBE", "DESCFORMAT"); + look_description(player, loc, NULL, "DESCRIBE", "DESCFORMAT"); } } /* tell him the description */ else { if (style == LOOK_NORMAL || style == LOOK_AUTO) { if (style == LOOK_NORMAL || !Terse(player)) { - look_description(player, loc, NULL, "DESCRIBE", "DESCFORMAT"); - did_it(player, loc, NULL, NULL, "ODESCRIBE", NULL, - "ADESCRIBE", NOTHING); + look_description(player, loc, NULL, "DESCRIBE", "DESCFORMAT"); + did_it(player, loc, NULL, NULL, "ODESCRIBE", NULL, + "ADESCRIBE", NOTHING); } else - did_it(player, loc, NULL, NULL, "ODESCRIBE", NULL, "ADESCRIBE", - NOTHING); + did_it(player, loc, NULL, NULL, "ODESCRIBE", NULL, "ADESCRIBE", + NOTHING); } else if (style != LOOK_CLOUDY) look_description(player, loc, NULL, "DESCRIBE", "DESCFORMAT"); } @@ -527,12 +527,12 @@ look_room(dbref player, dbref loc, enum look_type style) if (IsRoom(loc) && (style == LOOK_NORMAL || style == LOOK_AUTO)) { if (style == LOOK_AUTO && Terse(player)) { if (could_doit(player, loc)) - did_it(player, loc, NULL, NULL, "OSUCCESS", NULL, "ASUCCESS", NOTHING); + did_it(player, loc, NULL, NULL, "OSUCCESS", NULL, "ASUCCESS", NOTHING); else - did_it(player, loc, NULL, NULL, "OFAILURE", NULL, "AFAILURE", NOTHING); + did_it(player, loc, NULL, NULL, "OFAILURE", NULL, "AFAILURE", NOTHING); } else if (could_doit(player, loc)) did_it(player, loc, "SUCCESS", NULL, "OSUCCESS", NULL, "ASUCCESS", - NOTHING); + NOTHING); else fail_lock(player, loc, Basic_Lock, NULL, NOTHING); } @@ -546,7 +546,7 @@ look_room(dbref player, dbref loc, enum look_type style) static void look_description(dbref player, dbref thing, const char *def, - const char *descname, const char *descformatname) + const char *descname, const char *descformatname) { /* Show thing's description to player, obeying DESCFORMAT if set */ ATTR *a, *f; @@ -567,7 +567,7 @@ look_description(dbref player, dbref thing, const char *def, ap = asave; bp = buff; process_expression(buff, &bp, &ap, thing, player, player, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; free((Malloc_t) asave); } @@ -580,7 +580,7 @@ look_description(dbref player, dbref thing, const char *def, ap = asave; fbp = fbuff; process_expression(fbuff, &fbp, &ap, thing, player, player, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *fbp = '\0'; free((Malloc_t) asave); notify_by(thing, player, fbuff); @@ -604,7 +604,7 @@ do_look_around(dbref player) dbref loc; if ((loc = Location(player)) == NOTHING) return; - look_room(player, loc, LOOK_AUTO); /* auto-look. Obey TERSE. */ + look_room(player, loc, LOOK_AUTO); /* auto-look. Obey TERSE. */ } /** Look at something. @@ -621,7 +621,7 @@ do_look_at(dbref player, const char *name, int key) if (!GoodObject(Location(player))) return; - if (key) { /* look outside */ + if (key) { /* look outside */ /* can't see through opaque objects */ if (IsRoom(Location(player)) || Opaque(Location(player))) { notify(player, T("You can't see through that.")); @@ -639,7 +639,7 @@ do_look_at(dbref player, const char *name, int key) } thing = match_result(loc, name, NOTYPE, - MAT_PLAYER | MAT_REMOTE_CONTENTS | MAT_EXIT | MAT_REMOTES); + MAT_PLAYER | MAT_REMOTE_CONTENTS | MAT_EXIT | MAT_REMOTES); if (thing == NOTHING) { notify(player, T("I don't see that here.")); return; @@ -647,7 +647,7 @@ do_look_at(dbref player, const char *name, int key) notify(player, T("I don't know which one you mean.")); return; } - } else { /* regular look */ + } else { /* regular look */ if (*name == '\0') { look_room(player, Location(player), LOOK_NORMAL); return; @@ -758,8 +758,8 @@ do_examine(dbref player, const char *name, enum exam_type flag, int all) /* look it up */ if ((thing = - noisy_match_result(player, real_name, NOTYPE, - MAT_EVERYTHING)) == NOTHING) + noisy_match_result(player, real_name, NOTYPE, + MAT_EVERYTHING)) == NOTHING) return; } @@ -884,11 +884,11 @@ do_examine(dbref player, const char *name, enum exam_type flag, int all) if(IsDivision(content) && IsDivision(thing)) continue; if (!listed) { - listed = 1; - if (IsPlayer(thing)) - notify(player, T("Carrying:")); - else - notify(player, T("Contents:")); + listed = 1; + if (IsPlayer(thing)) + notify(player, T("Carrying:")); + else + notify(player, T("Contents:")); } notify(player, object_header(player, content)); } @@ -966,8 +966,8 @@ do_examine(dbref player, const char *name, enum exam_type flag, int all) break; default: notify_format(player, - T("Destination: %s"), - object_header(player, Destination(thing))); + T("Destination: %s"), + object_header(player, Destination(thing))); break; } break; @@ -1031,10 +1031,10 @@ do_inventory(dbref player) bp2 = arg2; DOLIST(thing, Contents(player)) { if (bp != arg) - safe_chr(' ', arg, &bp); + safe_chr(' ', arg, &bp); safe_dbref(thing, arg, &bp); if (bp2 != arg2) - safe_chr('|', arg2, &bp2); + safe_chr('|', arg2, &bp2); safe_str(unparse_object_myopic(player, thing), arg2, &bp2); } *bp = '\0'; @@ -1087,7 +1087,7 @@ do_find(dbref player, const char *name, char *argv[]) if (!payfor(player, FIND_COST)) { notify_format(player, T("Finds cost %d %s."), FIND_COST, - ((FIND_COST == 1) ? MONEY : MONIES)); + ((FIND_COST == 1) ? MONEY : MONIES)); return; } /* determinte range */ @@ -1114,7 +1114,7 @@ do_find(dbref player, const char *name, char *argv[]) for (i = bot; i < top; i++) { if (!IsGarbage(i) && !IsExit(i) && controls(player, i) && - (!*name || string_match(Name(i), name))) { + (!*name || string_match(Name(i), name))) { notify(player, object_header(player, i)); count++; } @@ -1163,47 +1163,47 @@ do_sweep(dbref player, const char *arg1) if (connect_flag) { /* only worry about puppet and players who's owner's are connected */ if (Connected(here) || (Puppet(here) && Connected(Owner(here)))) { - if (IsPlayer(here)) { - notify_format(player, T("%s is listening."), Name(here)); - } else { - notify_format(player, T("%s [owner: %s] is listening."), - Name(here), Name(Owner(here))); - } + if (IsPlayer(here)) { + notify_format(player, T("%s is listening."), Name(here)); + } else { + notify_format(player, T("%s [owner: %s] is listening."), + Name(here), Name(Owner(here))); + } } } else { if (Hearer(here) || Listener(here)) { - if (Connected(here)) - notify_format(player, T("%s (this room) [speech]. (connected)"), - Name(here)); - else - notify_format(player, T("%s (this room) [speech]."), Name(here)); + if (Connected(here)) + notify_format(player, T("%s (this room) [speech]. (connected)"), + Name(here)); + else + notify_format(player, T("%s (this room) [speech]."), Name(here)); } if (Commer(here)) - notify_format(player, T("%s (this room) [commands]."), Name(here)); + notify_format(player, T("%s (this room) [commands]."), Name(here)); if (Audible(here)) - notify_format(player, T("%s (this room) [broadcasting]."), Name(here)); + notify_format(player, T("%s (this room) [broadcasting]."), Name(here)); } for (here = Contents(here); here != NOTHING; here = Next(here)) { if (connect_flag) { - /* only worry about puppet and players who's owner's are connected */ - if (Connected(here) || (Puppet(here) && Connected(Owner(here)))) { - if (IsPlayer(here)) { - notify_format(player, T("%s is listening."), Name(here)); - } else { - notify_format(player, T("%s [owner: %s] is listening."), - Name(here), Name(Owner(here))); - } - } + /* only worry about puppet and players who's owner's are connected */ + if (Connected(here) || (Puppet(here) && Connected(Owner(here)))) { + if (IsPlayer(here)) { + notify_format(player, T("%s is listening."), Name(here)); + } else { + notify_format(player, T("%s [owner: %s] is listening."), + Name(here), Name(Owner(here))); + } + } } else { - if (Hearer(here) || Listener(here)) { - if (Connected(here)) - notify_format(player, "%s [speech]. (connected)", Name(here)); - else - notify_format(player, "%s [speech].", Name(here)); - } - if (Commer(here)) - notify_format(player, "%s [commands].", Name(here)); + if (Hearer(here) || Listener(here)) { + if (Connected(here)) + notify_format(player, "%s [speech]. (connected)", Name(here)); + else + notify_format(player, "%s [speech].", Name(here)); + } + if (Commer(here)) + notify_format(player, "%s [commands].", Name(here)); } } } @@ -1212,12 +1212,12 @@ do_sweep(dbref player, const char *arg1) if (Audible(Location(player))) { /* listening exits only work if the room is AUDIBLE */ for (here = Exits(Location(player)); here != NOTHING; here = Next(here)) { - if (Audible(here)) { - strcpy(tbuf1, Name(here)); - for (p = tbuf1; *p && (*p != ';'); p++) ; - *p = '\0'; - notify_format(player, "%s [broadcasting].", tbuf1); - } + if (Audible(here)) { + strcpy(tbuf1, Name(here)); + for (p = tbuf1; *p && (*p != ';'); p++) ; + *p = '\0'; + notify_format(player, "%s [broadcasting].", tbuf1); + } } } } @@ -1226,24 +1226,24 @@ do_sweep(dbref player, const char *arg1) for (here = Contents(player); here != NOTHING; here = Next(here)) { if (connect_flag) { - /* only worry about puppet and players who's owner's are connected */ - if (Connected(here) || (Puppet(here) && Connected(Owner(here)))) { - if (IsPlayer(here)) { - notify_format(player, T("%s is listening."), Name(here)); - } else { - notify_format(player, T("%s [owner: %s] is listening."), - Name(here), Name(Owner(here))); - } - } + /* only worry about puppet and players who's owner's are connected */ + if (Connected(here) || (Puppet(here) && Connected(Owner(here)))) { + if (IsPlayer(here)) { + notify_format(player, T("%s is listening."), Name(here)); + } else { + notify_format(player, T("%s [owner: %s] is listening."), + Name(here), Name(Owner(here))); + } + } } else { - if (Hearer(here) || Listener(here)) { - if (Connected(here)) - notify_format(player, "%s [speech]. (connected)", Name(here)); - else - notify_format(player, "%s [speech].", Name(here)); - } - if (Commer(here)) - notify_format(player, "%s [commands].", Name(here)); + if (Hearer(here) || Listener(here)) { + if (Connected(here)) + notify_format(player, "%s [speech]. (connected)", Name(here)); + else + notify_format(player, "%s [speech].", Name(here)); + } + if (Commer(here)) + notify_format(player, "%s [commands].", Name(here)); } } } @@ -1297,8 +1297,8 @@ do_entrances(dbref player, const char *where, char *argv[], enum ent_type val) { dbref place; dbref counter; - int exc, tc, pc, rc; /* how many we've found */ - int exd, td, pd, rd; /* what we're looking for */ + int exc, tc, pc, rc; /* how many we've found */ + int exd, td, pd, rd; /* what we're looking for */ int bot = 0; int top = db_top; @@ -1309,7 +1309,7 @@ do_entrances(dbref player, const char *where, char *argv[], enum ent_type val) return; } else { if ((place = noisy_match_result(player, where, NOTYPE, MAT_EVERYTHING)) - == NOTHING) + == NOTHING) return; } @@ -1319,7 +1319,7 @@ do_entrances(dbref player, const char *where, char *argv[], enum ent_type val) } if (!payfor(player, FIND_COST)) { notify_format(player, T("You don't have enough %d %s to do that."), - FIND_COST, ((FIND_COST == 1) ? MONEY : MONIES)); + FIND_COST, ((FIND_COST == 1) ? MONEY : MONIES)); return; } /* figure out what we're looking for */ @@ -1358,39 +1358,39 @@ do_entrances(dbref player, const char *where, char *argv[], enum ent_type val) if (controls(player, place) || controls(player, counter)) { switch (Typeof(counter)) { case TYPE_EXIT: - if (exd) { - if (Location(counter) == place) { - notify_format(player, - "%s(#%d) [from: %s(#%d)]", Name(counter), - counter, Name(Source(counter)), Source(counter)); - exc++; - } - } - break; + if (exd) { + if (Location(counter) == place) { + notify_format(player, + "%s(#%d) [from: %s(#%d)]", Name(counter), + counter, Name(Source(counter)), Source(counter)); + exc++; + } + } + break; case TYPE_ROOM: - if (rd) { - if (Location(counter) == place) { - notify_format(player, "%s(#%d) [dropto]", Name(counter), counter); - rc++; - } - } - break; + if (rd) { + if (Location(counter) == place) { + notify_format(player, "%s(#%d) [dropto]", Name(counter), counter); + rc++; + } + } + break; case TYPE_THING: - if (td) { - if (Home(counter) == place) { - notify_format(player, "%s(#%d) [home]", Name(counter), counter); - tc++; - } - } - break; + if (td) { + if (Home(counter) == place) { + notify_format(player, "%s(#%d) [home]", Name(counter), counter); + tc++; + } + } + break; case TYPE_PLAYER: - if (pd) { - if (Home(counter) == place) { - notify_format(player, "%s(#%d) [home]", Name(counter), counter); - pc++; - } - } - break; + if (pd) { + if (Home(counter) == place) { + notify_format(player, "%s(#%d) [home]", Name(counter), counter); + pc++; + } + } + break; } } } @@ -1401,17 +1401,17 @@ do_entrances(dbref player, const char *where, char *argv[], enum ent_type val) } else { notify(player, T("---------- Entrances Done ----------")); notify_format(player, - "Totals: Rooms...%d Exits...%d Objects...%d Players...%d", - rc, exc, tc, pc); + "Totals: Rooms...%d Exits...%d Objects...%d Players...%d", + rc, exc, tc, pc); return; } } /** Store arguments for decompile_helper() */ struct dh_args { - char const *prefix; /**< Decompile/tf prefix */ - char const *name; /**< Decompile object name */ - int skipdef; /**< Skip default flags on attributes if true */ + char const *prefix; /**< Decompile/tf prefix */ + char const *name; /**< Decompile object name */ + int skipdef; /**< Skip default flags on attributes if true */ }; extern char escaped_chars[UCHAR_MAX + 1]; @@ -1426,24 +1426,24 @@ insert_spaces(int count, int dospace, char *buff, char **bp) safe_str(")]", buff, bp); } else if (count == 1) { if (dospace) { - safe_str("%b", buff, bp); + safe_str("%b", buff, bp); } else { - safe_chr(' ', buff, bp); + safe_chr(' ', buff, bp); } } else { /* Take care of the final %b */ count--; if (dospace) { - safe_str("%b", buff, bp); - count--; + safe_str("%b", buff, bp); + count--; } while (count) { - safe_chr(' ', buff, bp); - count--; - if (count) { - count--; - safe_str("%b", buff, bp); - } + safe_chr(' ', buff, bp); + count--; + if (count) { + count--; + safe_str("%b", buff, bp); + } } safe_str("%b", buff, bp); } @@ -1708,7 +1708,7 @@ decompile_helper(dbref player, dbref thing __attribute__ ((__unused__)), /* Are we different? If so, do as usual */ unsigned int npmflags = AL_FLAGS(ptr) & (~AF_PREFIXMATCH); if (AL_FLAGS(atr) != AL_FLAGS(ptr) && AL_FLAGS(atr) != npmflags) - privs = privs_to_string(attr_privs_view, AL_FLAGS(atr)); + privs = privs_to_string(attr_privs_view, AL_FLAGS(atr)); } else { privs = privs_to_string(attr_privs_view, AL_FLAGS(atr)); } @@ -1728,7 +1728,7 @@ decompile_helper(dbref player, dbref thing __attribute__ ((__unused__)), */ void decompile_atrs(dbref player, dbref thing, const char *name, const char *pattern, - const char *prefix, int skipdef) + const char *prefix, int skipdef) { struct dh_args dh; dh.prefix = prefix; @@ -1785,7 +1785,7 @@ decompile_locks(dbref player, dbref thing, const char *name, int skipdef) */ void do_decompile(dbref player, const char *name, const char *prefix, - enum dec_type dbflag, int skipdef) + enum dec_type dbflag, int skipdef) { dbref thing; const char *object = NULL; @@ -1820,9 +1820,9 @@ do_decompile(dbref player, const char *name, const char *prefix, break; default: if (IsRoom(thing)) - decompile_atrs(player, thing, "here", attrib, prefix, skipdef); + decompile_atrs(player, thing, "here", attrib, prefix, skipdef); else - decompile_atrs(player, thing, Name(thing), attrib, prefix, skipdef); + decompile_atrs(player, thing, Name(thing), attrib, prefix, skipdef); break; } return; @@ -1866,7 +1866,7 @@ do_decompile(dbref player, const char *name, const char *prefix, } else { object = shortname(thing); if (dbflag != DEC_ATTR) - notify_format(player, "%s@open %s", prefix, Name(thing)); + notify_format(player, "%s@open %s", prefix, Name(thing)); } break; case TYPE_DIVISION: @@ -1883,17 +1883,17 @@ do_decompile(dbref player, const char *name, const char *prefix, if (dbflag != DEC_ATTR) { if (Mobile(thing)) { if (GoodObject(Home(thing))) - notify_format(player, "%s@link %s = #%d", prefix, object, Home(thing)); + notify_format(player, "%s@link %s = #%d", prefix, object, Home(thing)); else if (Home(thing) == HOME) - notify_format(player, "%s@link %s = HOME", prefix, object); + notify_format(player, "%s@link %s = HOME", prefix, object); } else { if (GoodObject(Destination(thing))) - notify_format(player, "%s@link %s = #%d", prefix, object, - Destination(thing)); + notify_format(player, "%s@link %s = #%d", prefix, object, + Destination(thing)); else if (Destination(thing) == AMBIGUOUS) - notify_format(player, "%s@link %s = VARIABLE", prefix, object); + notify_format(player, "%s@link %s = VARIABLE", prefix, object); else if (Destination(thing) == HOME) - notify_format(player, "%s@link %s = HOME", prefix, object); + notify_format(player, "%s@link %s = HOME", prefix, object); } if (GoodObject(Zone(thing))) diff --git a/src/malias.c b/src/malias.c index 1c7ff47..19ce76d 100644 --- a/src/malias.c +++ b/src/malias.c @@ -33,7 +33,7 @@ * \endverbatim */ -#define MA_INC 3 /**< How many maliases we malloc at a time */ +#define MA_INC 3 /**< How many maliases we malloc at a time */ #include "config.h" #include "copyrite.h" @@ -66,7 +66,7 @@ int ma_size = 0; /**< Number of maliases */ -int ma_top = 0; /**< Top of alias array */ +int ma_top = 0; /**< Top of alias array */ struct mail_alias *malias; /**< Pointer to linked list of aliases */ /** Privilege table for maliases. */ @@ -144,8 +144,8 @@ do_malias_create(dbref player, char *alias, char *tolist) } if (*alias != MALIAS_TOKEN) { notify_format(player, - T("MAIL: All Mail aliases must begin with '%c'."), - MALIAS_TOKEN); + T("MAIL: All Mail aliases must begin with '%c'."), + MALIAS_TOKEN); return; } good = "`$_-.'"; @@ -158,8 +158,8 @@ do_malias_create(dbref player, char *alias, char *tolist) return; } } - m = get_malias(GOD, alias); /* GOD can see all aliases */ - if (m) { /* Ensures no duplicates! */ + m = get_malias(GOD, alias); /* GOD can see all aliases */ + if (m) { /* Ensures no duplicates! */ notify_format(player, T("MAIL: Mail Alias '%s' already exists."), alias); return; } @@ -167,12 +167,12 @@ do_malias_create(dbref player, char *alias, char *tolist) ma_size = MA_INC; malias = (struct mail_alias *) mush_malloc(sizeof(struct mail_alias) * - ma_size, "malias_list"); + ma_size, "malias_list"); } else if (ma_top >= ma_size) { ma_size += MA_INC; m = (struct mail_alias *) mush_malloc(sizeof(struct mail_alias) * - (ma_size), "malias_list"); + (ma_size), "malias_list"); memcpy(m, malias, sizeof(struct mail_alias) * ma_top); mush_free((Malloc_t) malias, "malias_list"); malias = m; @@ -189,13 +189,13 @@ do_malias_create(dbref player, char *alias, char *tolist) tail = head; while (*tail && (*tail != ' ')) { if (*tail == '"') { - head++; - tail++; - while (*tail && (*tail != '"')) - tail++; + head++; + tail++; + while (*tail && (*tail != '"')) + tail++; } if (*tail) - tail++; + tail++; } tail--; if (*tail != '"') @@ -349,7 +349,7 @@ do_malias_desc(dbref player, char *alias, char *desc) return; } else if (MailAdmin(player, m->owner) || (player == m->owner)) { if (m->desc) - free(m->desc); /* No need to update MEM_CHECK records here */ + free(m->desc); /* No need to update MEM_CHECK records here */ m->desc = compress(desc); notify(player, T("MAIL: Description changed.")); } else @@ -381,8 +381,8 @@ do_malias_chown(dbref player, char *alias, char *owner) return; } else { if ((no = lookup_player(owner)) == NOTHING) { - notify(player, T("MAIL: I cannot find that player.")); - return; + notify(player, T("MAIL: I cannot find that player.")); + return; } m->owner = no; notify(player, T("MAIL: Owner changed for alias.")); @@ -411,8 +411,8 @@ do_malias_rename(dbref player, char *alias, char *newname) } if (*newname != MALIAS_TOKEN) { notify_format(player, - T("MAIL: Bad alias. Aliases must start with '%c'."), - MALIAS_TOKEN); + T("MAIL: Bad alias. Aliases must start with '%c'."), + MALIAS_TOKEN); return; } if (get_malias(GOD, newname) != NULL) { @@ -424,7 +424,7 @@ do_malias_rename(dbref player, char *alias, char *newname) return; } - free(m->name); /* No need to update MEM_CHECK records here. */ + free(m->name); /* No need to update MEM_CHECK records here. */ m->name = strdup(newname + 1); notify(player, T("MAIL: Mail Alias renamed.")); @@ -446,8 +446,8 @@ do_malias_destroy(dbref player, char *alias) m = get_malias(player, alias); if (!m) { notify(player, - T - ("MAIL: Not a valid alias. Remember to prefix the alias name with *.")); + T + ("MAIL: Not a valid alias. Remember to prefix the alias name with *.")); return; } if (MailAdmin(player, m->owner) || (m->owner == player)) { @@ -486,9 +486,9 @@ do_malias_set(dbref player, char *alias, char *tolist) m = get_malias(player, alias); if (!m) { notify_format(player, - T - ("MAIL: Not a valid alias. Remember to prefix the alias name with %c."), - MALIAS_TOKEN); + T + ("MAIL: Not a valid alias. Remember to prefix the alias name with %c."), + MALIAS_TOKEN); return; } if (!tolist || !*tolist) { @@ -510,13 +510,13 @@ do_malias_set(dbref player, char *alias, char *tolist) tail = head; while (*tail && (*tail != ' ')) { if (*tail == '"') { - head++; - tail++; - while (*tail && (*tail != '"')) - tail++; + head++; + tail++; + while (*tail && (*tail != '"')) + tail++; } if (*tail) - tail++; + tail++; } tail--; if (*tail != '"') @@ -585,14 +585,14 @@ do_malias_all(dbref player) return; } notify(player, - "Num Name Description Owner Count"); + "Num Name Description Owner Count"); for (i = 0; i < ma_top; i++) { m = &malias[i]; notify_format(player, "#%-4d %c%-10.10s %-40.40s %-11.11s (%3d)", - i, MALIAS_TOKEN, m->name, - uncompress((unsigned char *) m->desc), - Name(m->owner), m->size); + i, MALIAS_TOKEN, m->name, + uncompress((unsigned char *) m->desc), + Name(m->owner), m->size); } notify(player, T("***** End of Mail Aliases *****")); @@ -614,7 +614,7 @@ do_malias_stats(dbref player) notify(player, T("MAIL: Permission denied.")); else { notify_format(player, - T("MAIL: Number of mail aliases defined: %d"), ma_top); + T("MAIL: Number of mail aliases defined: %d"), ma_top); notify_format(player, T("MAIL: Allocated slots %d"), ma_size); } } @@ -635,15 +635,15 @@ do_malias_nuke(dbref player) notify(player, T("MAIL: Only god can do that!")); return; } - if (ma_size) { /* aliases defined ? */ + if (ma_size) { /* aliases defined ? */ for (i = 0; i < ma_top; i++) { m = &malias[i]; if (m->name) - mush_free(m->name, "malias_name"); + mush_free(m->name, "malias_name"); if (m->desc) - mush_free(m->desc, "malias_desc"); + mush_free(m->desc, "malias_desc"); if (m->members) - mush_free((Malloc_t) m->members, "malias_members"); + mush_free((Malloc_t) m->members, "malias_members"); } mush_free((Malloc_t) malias, "malias_list"); } @@ -678,8 +678,8 @@ do_malias_privs(dbref player, char *alias, char *privs, int type) p = type ? &m->mflags : &m->nflags; *p = string_to_privs(malias_priv_table, privs, 0); notify_format(player, - T("MAIL: Permission to see/use alias '%s' changed to %s"), - alias, privs_to_string(malias_priv_table, *p)); + T("MAIL: Permission to see/use alias '%s' changed to %s"), + alias, privs_to_string(malias_priv_table, *p)); } @@ -720,13 +720,13 @@ do_malias_add(dbref player, char *alias, char *tolist) tail = head; while (*tail && (*tail != ' ')) { if (*tail == '"') { - head++; - tail++; - while (*tail && (*tail != '"')) - tail++; + head++; + tail++; + while (*tail && (*tail != '"')) + tail++; } if (*tail) - tail++; + tail++; } tail--; if (*tail != '"') @@ -746,14 +746,14 @@ do_malias_add(dbref player, char *alias, char *tolist) notify_format(player, T("MAIL: No such player '%s'."), head); } else { if (ismember(m, target)) { - notify_format(player, - T("MAIL: player '%s' exists already in alias %s."), - head, alias); + notify_format(player, + T("MAIL: player '%s' exists already in alias %s."), + head, alias); } else { - buff = unparse_object(player, target); - notify_format(player, T("MAIL: %s added to alias %s"), buff, alias); - alist[i] = target; - i++; + buff = unparse_object(player, target); + notify_format(player, T("MAIL: %s added to alias %s"), buff, alias); + alist[i] = target; + i++; } } /* @@ -826,13 +826,13 @@ do_malias_remove(dbref player, char *alias, char *tolist) tail = head; while (*tail && (*tail != ' ')) { if (*tail == '"') { - head++; - tail++; - while (*tail && (*tail != '"')) - tail++; + head++; + tail++; + while (*tail && (*tail != '"')) + tail++; } if (*tail) - tail++; + tail++; } tail--; if (*tail != '"') @@ -852,12 +852,12 @@ do_malias_remove(dbref player, char *alias, char *tolist) notify_format(player, T("MAIL: No such player '%s'."), head); } else { if (!(i = ismember(m, target))) { - notify_format(player, T("MAIL: player '%s' is not in alias %s."), - head, alias); + notify_format(player, T("MAIL: player '%s' is not in alias %s."), + head, alias); } else { - buff = unparse_object(player, target); - m->members[i - 1] = m->members[--m->size]; - notify_format(player, T("MAIL: %s removed from alias %s"), buff, alias); + buff = unparse_object(player, target); + m->members[i - 1] = m->members[--m->size]; + notify_format(player, T("MAIL: %s removed from alias %s"), buff, alias); } } /* @@ -925,7 +925,7 @@ ismember(struct mail_alias *m, dbref player) int i; for (i = 0; i < m->size; i++) { if (player == m->members[i]) - return (i + 1); /* To avoid entry "0" */ + return (i + 1); /* To avoid entry "0" */ } return 0; } @@ -1005,7 +1005,7 @@ load_malias(FILE * fp) if (ma_top > 0) malias = (struct mail_alias *) mush_malloc(sizeof(struct mail_alias) * - ma_size, "malias_list"); + ma_size, "malias_list"); else malias = NULL; @@ -1023,9 +1023,9 @@ load_malias(FILE * fp) if (m->size > 0) { m->members = - (dbref *) mush_malloc(m->size * sizeof(dbref), "malias_members"); + (dbref *) mush_malloc(m->size * sizeof(dbref), "malias_members"); for (j = 0; j < m->size; j++) { - m->members[j] = getref(fp); + m->members[j] = getref(fp); } } else { m->members = NULL; diff --git a/src/match.c b/src/match.c index 56c72b5..b899035 100644 --- a/src/match.c +++ b/src/match.c @@ -65,8 +65,8 @@ static dbref match_here(const dbref who, const char *name); #define match_absolute(name) parse_objid(name) static dbref match_player(const dbref matcher, const char *match_name); static dbref choose_thing(const dbref match_who, const int preferred_type, - long int flags, dbref thing1, dbref thing2); -extern int check_alias(const char *command, const char *list); /* game.c */ + long int flags, dbref thing1, dbref thing2); +extern int check_alias(const char *command, const char *list); /* game.c */ /** A wrapper for returning a match, AMBIGUOUS, or NOTHING. @@ -80,7 +80,7 @@ extern int check_alias(const char *command, const char *list); /* game.c */ */ dbref match_result(const dbref who, const char *name, const int type, - const long flags) + const long flags) { return match_result_internal(who, name, type, flags); } @@ -98,7 +98,7 @@ match_result(const dbref who, const char *name, const int type, */ dbref noisy_match_result(const dbref who, const char *name, const int type, - const long flags) + const long flags) { return match_result_internal(who, name, type, flags | MAT_NOISY); } @@ -115,7 +115,7 @@ noisy_match_result(const dbref who, const char *name, const int type, */ dbref last_match_result(const dbref who, const char *name, const int type, - const long flags) + const long flags) { return match_result_internal(who, name, type, flags | MAT_LAST); } @@ -185,9 +185,9 @@ match_controlled(dbref player, const char *name) * e. If we got no matches, complain */ -#define MATCH_NONE 0x0 /**< No matches were found */ -#define MATCH_EXACT 0x1 /**< At least one exact match found */ -#define MATCH_PARTIAL 0x2 /**< At least one partial match found, no exact */ +#define MATCH_NONE 0x0 /**< No matches were found */ +#define MATCH_EXACT 0x1 /**< At least one exact match found */ +#define MATCH_PARTIAL 0x2 /**< At least one partial match found, no exact */ /** Prototype for matching functions */ #define MATCH_FUNC_PROTO(fun_name) \ /* ARGSUSED */ /* try to keep lint happy */ \ @@ -269,7 +269,7 @@ finished: if (!exact_matches_to_go) match = exact_match; else if (GoodObject(last_match)) - match = last_match; /* nth exact-or-partial match, or nothing? */ + match = last_match; /* nth exact-or-partial match, or nothing? */ /* This shouldn't happen, but just in case we have a valid match, * and an invalid last_match in the matchnum case, fall through and * use the match. @@ -277,18 +277,18 @@ finished: } else if (GoodObject(exact_match)) { /* How many exact matches? */ if (exact_matches_to_go == -1) - match = exact_match; /* Good */ + match = exact_match; /* Good */ else if (flags & MAT_LAST) - match = exact_match; /* Good enough */ + match = exact_match; /* Good enough */ else match = AMBIGUOUS; } else { if (!matches_to_go) - match = NOTHING; /* No matches */ + match = NOTHING; /* No matches */ else if (matches_to_go == -1) - match = last_match; /* Good */ + match = last_match; /* Good */ else if (flags & MAT_LAST) - match = last_match; /* Good enough */ + match = last_match; /* Good enough */ else match = AMBIGUOUS; } @@ -387,14 +387,14 @@ parse_english(const char **name, long *flags) *name += 10; *flags &= ~(MAT_POSSESSION | MAT_EXIT); } else if (!strncasecmp(*name, "here ", 5) - || !strncasecmp(*name, "this ", 5)) { + || !strncasecmp(*name, "this ", 5)) { *name += 5; *flags &= - ~(MAT_POSSESSION | MAT_EXIT | MAT_REMOTE_CONTENTS | MAT_CONTAINER); + ~(MAT_POSSESSION | MAT_EXIT | MAT_REMOTE_CONTENTS | MAT_CONTAINER); } } if ((*flags & MAT_POSSESSION) && (!strncasecmp(*name, "my ", 3) - || !strncasecmp(*name, "me ", 3))) { + || !strncasecmp(*name, "me ", 3))) { *name += 3; *flags &= ~(MAT_NEIGHBOR | MAT_EXIT | MAT_CONTAINER | MAT_REMOTE_CONTENTS); } @@ -435,16 +435,16 @@ parse_english(const char **name, long *flags) count = -1; } else if ((count > 10) && (count < 14)) { if (strcasecmp(e, "th")) - count = -1; + count = -1; } else if ((count % 10) == 1) { if (strcasecmp(e, "st")) - count = -1; + count = -1; } else if ((count % 10) == 2) { if (strcasecmp(e, "nd")) - count = -1; + count = -1; } else if ((count % 10) == 3) { if (strcasecmp(e, "rd")) - count = -1; + count = -1; } else if (strcasecmp(e, "th")) { count = -1; } @@ -599,22 +599,22 @@ MATCH_FUNC(match_exit_internal) (*matches_to_go)--; return MATCH_EXACT; } else if (check_alias(name, Name(exit_tmp)) - && (can_interact(exit_tmp, who, INTERACT_MATCH))) { + && (can_interact(exit_tmp, who, INTERACT_MATCH))) { /* Matched an exit alias, but there may be more */ (*exact_matches_to_go)--; (*matches_to_go)--; if (nth_match) { - if (!(*exact_matches_to_go)) { - /* We're done */ - *match = exit_tmp; - return MATCH_EXACT; - } + if (!(*exact_matches_to_go)) { + /* We're done */ + *match = exit_tmp; + return MATCH_EXACT; + } } else { - if (match_type == MATCH_EXACT) - *match = choose_thing(who, type, flags, *match, exit_tmp); - else - *match = exit_tmp; - match_type = MATCH_EXACT; + if (match_type == MATCH_EXACT) + *match = choose_thing(who, type, flags, *match, exit_tmp); + else + *match = exit_tmp; + match_type = MATCH_EXACT; } } } @@ -630,7 +630,7 @@ MATCH_FUNC(match_possession) if (!GoodObject(who)) return NOTHING; return match_list(who, name, type, flags, Contents(who), match, - exact_matches_to_go, matches_to_go); + exact_matches_to_go, matches_to_go); } MATCH_FUNC(match_container) @@ -638,7 +638,7 @@ MATCH_FUNC(match_container) if (!GoodObject(who)) return NOTHING; return match_list(who, name, type, flags, Location(who), match, - exact_matches_to_go, matches_to_go); + exact_matches_to_go, matches_to_go); } MATCH_FUNC(match_neighbor) @@ -650,13 +650,13 @@ MATCH_FUNC(match_neighbor) if (!GoodObject(loc)) return NOTHING; return match_list(who, name, type, flags, Contents(loc), match, - exact_matches_to_go, matches_to_go); + exact_matches_to_go, matches_to_go); } static dbref choose_thing(const dbref match_who, const int preferred_type, long flags, - dbref thing1, dbref thing2) + dbref thing1, dbref thing2) { int has1; int has2; diff --git a/src/memcheck.c b/src/memcheck.c index a151c95..70d5e02 100644 --- a/src/memcheck.c +++ b/src/memcheck.c @@ -26,9 +26,9 @@ typedef struct mem_check MEM; /** A linked list for storing memory allocation counts */ struct mem_check { - int ref_count; /**< Number of allocations of this type. */ - MEM *next; /**< Pointer to next in linked list. */ - char ref_name[BUFFER_LEN]; /**< Name of this allocation type. */ + int ref_count; /**< Number of allocations of this type. */ + MEM *next; /**< Pointer to next in linked list. */ + char ref_name[BUFFER_LEN]; /**< Name of this allocation type. */ }; static MEM *my_check = NULL; @@ -88,11 +88,11 @@ del_check(const char *ref) if (cmp == 0) { loop->ref_count--; if (!loop->ref_count) { - if (!prev) - my_check = loop->next; - else - prev->next = loop->next; - free(loop); + if (!prev) + my_check = loop->next; + else + prev->next = loop->next; + free(loop); } return; } else if (cmp < 0) @@ -100,8 +100,8 @@ del_check(const char *ref) prev = loop; } do_rawlog(LT_CHECK, - T("ERROR: Tried deleting a check that was never added! :%s\n"), - ref); + T("ERROR: Tried deleting a check that was never added! :%s\n"), + ref); } /** List allocations. diff --git a/src/move.c b/src/move.c index 65b9aed..a5db883 100644 --- a/src/move.c +++ b/src/move.c @@ -77,9 +77,9 @@ moveit(dbref what, dbref where, int nomovemsgs) switch (where) { case NOTHING: Location(what) = NOTHING; - return; /* NOTHING doesn't have contents */ + return; /* NOTHING doesn't have contents */ case HOME: - where = Home(what); /* home */ + where = Home(what); /* home */ safe_tel(what, where, nomovemsgs); return; /*NOTREACHED */ @@ -168,7 +168,7 @@ maybe_dropto(dbref loc, dbref dropto) { dbref thing; if (loc == dropto) - return; /* bizarre special case */ + return; /* bizarre special case */ if (!IsRoom(loc)) return; /* check for players */ @@ -216,14 +216,14 @@ enter_room(dbref player, dbref loc, int nomovemsgs) } if (loc == player) { do_rawlog(LT_ERR, T("ERROR: Attempt to move player %d into itself\n"), - player); + player); deep--; return; } if (recursive_member(loc, player, 0)) { do_rawlog(LT_ERR, - T("ERROR: Attempt to move player %d into carried object %d\n"), - player, loc); + T("ERROR: Attempt to move player %d into carried object %d\n"), + player, loc); deep--; return; } @@ -278,8 +278,8 @@ safe_tel(dbref player, dbref dest, int nomovemsgs) * the player. */ if (!controls(player, first) - && (Sticky(first) - && (Home(first) != player))) + && (Sticky(first) + && (Home(first) != player))) enter_room(first, HOME, nomovemsgs); else { PUSH(first, Contents(player)); @@ -341,7 +341,7 @@ find_var_dest(dbref player, dbref exit_obj) ap = abuf; bp = buff; process_expression(buff, &bp, &ap, exit_obj, player, player, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; dest_room = parse_objid(buff); free((Malloc_t) abuf); @@ -368,15 +368,15 @@ do_move(dbref player, const char *direction, enum move_type type) /* send him home */ /* but steal all his possessions */ if (!Mobile(player) || !GoodObject(Home(player)) || - recursive_member(Home(player), player, 0) - || (player == Home(player))) { + recursive_member(Home(player), player, 0) + || (player == Home(player))) { notify(player, T("Bad destination.")); return; } if ((loc = Location(player)) != NOTHING && !Dark(player) && !Dark(loc)) { /* tell everybody else */ notify_except(Contents(loc), player, - tprintf(T("%s goes home."), Name(player)), NA_INTER_SEE); + tprintf(T("%s goes home."), Name(player)), NA_INTER_SEE); } /* give the player the messages */ notify(player, T("There's no place like home...")); @@ -387,16 +387,16 @@ do_move(dbref player, const char *direction, enum move_type type) /* find the exit */ if (type == MOVE_GLOBAL) exit_m = - match_result(player, direction, TYPE_EXIT, - MAT_ENGLISH | MAT_EXIT | MAT_GLOBAL | MAT_CHECK_KEYS); + match_result(player, direction, TYPE_EXIT, + MAT_ENGLISH | MAT_EXIT | MAT_GLOBAL | MAT_CHECK_KEYS); else if (type == MOVE_ZONE) exit_m = - match_result(player, direction, TYPE_EXIT, - MAT_ENGLISH | MAT_EXIT | MAT_REMOTES | MAT_CHECK_KEYS); + match_result(player, direction, TYPE_EXIT, + MAT_ENGLISH | MAT_EXIT | MAT_REMOTES | MAT_CHECK_KEYS); else exit_m = - match_result(player, direction, TYPE_EXIT, - MAT_ENGLISH | MAT_EXIT | MAT_CHECK_KEYS); + match_result(player, direction, TYPE_EXIT, + MAT_ENGLISH | MAT_EXIT | MAT_CHECK_KEYS); switch (exit_m) { case NOTHING: /* try to force the object */ @@ -502,7 +502,7 @@ do_firstexit(dbref player, const char *what) dbref loc; if ((thing = noisy_match_result(player, what, TYPE_EXIT, - MAT_ENGLISH | MAT_EXIT)) == NOTHING) + MAT_ENGLISH | MAT_EXIT)) == NOTHING) return; loc = Home(thing); if (!controls(player, loc)) { @@ -659,9 +659,9 @@ do_drop(dbref player, const char *name) if ((loc = Location(player)) == NOTHING) return; switch (thing = - match_result(player, name, TYPE_THING, - MAT_POSSESSION | MAT_ABSOLUTE | MAT_CONTROL | - MAT_ENGLISH)) { + match_result(player, name, TYPE_THING, + MAT_POSSESSION | MAT_ABSOLUTE | MAT_CONTROL | + MAT_ENGLISH)) { case NOTHING: notify(player, T("You don't have that!")); return; @@ -686,7 +686,7 @@ do_drop(dbref player, const char *name) notify(thing, T("Dropped.")); safe_tel(thing, HOME, 0); } else if ((Location(loc) != NOTHING) && IsRoom(loc) && !Sticky(loc) - && eval_lock(thing, loc, Dropto_Lock)) { + && eval_lock(thing, loc, Dropto_Lock)) { /* location has immediate dropto */ notify_format(thing, T("%s drops you."), Name(player)); moveto(thing, Location(loc)); @@ -741,7 +741,7 @@ do_empty(dbref player, const char *what) return; thing = noisy_match_result(player, what, TYPE_THING | TYPE_PLAYER, - MAT_NEAR_THINGS | MAT_ENGLISH); + MAT_NEAR_THINGS | MAT_ENGLISH); if (!GoodObject(thing)) return; thing_loc = Location(thing); @@ -755,31 +755,31 @@ do_empty(dbref player, const char *what) item = first_visible(player, next)) { next = Next(item); if (IsExit(item)) - continue; /* No dropping exits */ + continue; /* No dropping exits */ empty_ok = 0; if (player == thing) { /* empty me: You don't need to get what's in your inventory already */ if (eval_lock(player, item, Drop_Lock) && - (!IsRoom(thing_loc) || eval_lock(player, thing_loc, Drop_Lock))) - empty_ok = 1; + (!IsRoom(thing_loc) || eval_lock(player, thing_loc, Drop_Lock))) + empty_ok = 1; } /* Check that player can get stuff from thing */ else if (controls(player, thing) || - (EnterOk(thing) && eval_lock(player, thing, Enter_Lock))) { + (EnterOk(thing) && eval_lock(player, thing, Enter_Lock))) { /* Check that player can get item */ if (!could_doit(player, item)) { - /* Send failure message if set, otherwise be quiet */ - fail_lock(player, thing, Basic_Lock, NULL, NOTHING); - continue; + /* Send failure message if set, otherwise be quiet */ + fail_lock(player, thing, Basic_Lock, NULL, NOTHING); + continue; } /* Now check for dropping in the destination */ /* Thing is in player's inventory - sufficient */ if (thing_loc == player) - empty_ok = 1; + empty_ok = 1; /* Thing is in player's location - player must also be able to drop */ else if (eval_lock(player, item, Drop_Lock) && - (!IsRoom(thing_loc) || eval_lock(player, thing_loc, Drop_Lock))) - empty_ok = 1; + (!IsRoom(thing_loc) || eval_lock(player, thing_loc, Drop_Lock))) + empty_ok = 1; } /* Now do the work, if we should. That includes triggering messages */ if (empty_ok) { @@ -863,8 +863,8 @@ do_enter(dbref player, const char *what) /* the object must pass the lock. Also, the thing being entered */ /* has to be controlled, or must be enter_ok */ if (!((EnterOk(thing) || controls(player, thing)) && - (eval_lock(player, thing, Enter_Lock)) - )) { + (eval_lock(player, thing, Enter_Lock)) + )) { fail_lock(player, thing, Enter_Lock, T("Permission denied."), NOTHING); return; } @@ -911,7 +911,7 @@ int global_exit(dbref player, const char *direction) { return (GoodObject - (match_result(player, direction, TYPE_EXIT, MAT_GLOBAL | MAT_EXIT))); + (match_result(player, direction, TYPE_EXIT, MAT_GLOBAL | MAT_EXIT))); } /** Is direction a remote exit? @@ -924,7 +924,7 @@ int remote_exit(dbref player, const char *direction) { return (GoodObject - (match_result(player, direction, TYPE_EXIT, MAT_REMOTES | MAT_EXIT))); + (match_result(player, direction, TYPE_EXIT, MAT_REMOTES | MAT_EXIT))); } /** Wrapper for exit movement. @@ -998,7 +998,7 @@ do_follow(dbref player, const char *arg) /* Ok, are we allowed to follow them? */ if (!eval_lock(player, leader, Follow_Lock)) { fail_lock(player, leader, Follow_Lock, - T("You're not alllowed to follow."), Location(player)); + T("You're not alllowed to follow."), Location(player)); return; } /* Ok, looks good */ @@ -1102,9 +1102,9 @@ do_desert(dbref player, const char *arg) } /* Are we following or leading them? */ if (!is_following(who, player) - && !is_following(player, who)) { + && !is_following(player, who)) { notify_format(player, - T("%s isn't following you, nor vice versa."), Name(who)); + T("%s isn't following you, nor vice versa."), Name(who)); return; } /* Ok, looks good */ @@ -1168,7 +1168,7 @@ add_follow(dbref leader, dbref follower, int noisy) strcpy(msg, tprintf(T("You begin following %s."), Name(leader))); notify_format(leader, T("%s begins following you."), Name(follower)); did_it(follower, leader, "FOLLOW", msg, "OFOLLOW", NULL, - "AFOLLOW", NOTHING); + "AFOLLOW", NOTHING); } } @@ -1182,7 +1182,7 @@ del_follower(dbref leader, dbref follower) char flwr[BUFFER_LEN]; a = atr_get_noparent(leader, "FOLLOWERS"); if (!a) - return; /* No followers, so no deletion */ + return; /* No followers, so no deletion */ /* Let's take it apart and put it back together w/o follower */ strcpy(flwr, unparse_dbref(follower)); strcpy(tbuf1, atr_value(a)); @@ -1198,7 +1198,7 @@ del_following(dbref follower, dbref leader) char ldr[BUFFER_LEN]; a = atr_get_noparent(follower, "FOLLOWING"); if (!a) - return; /* Not following, so no deletion */ + return; /* Not following, so no deletion */ /* Let's take it apart and put it back together w/o leader */ strcpy(ldr, unparse_dbref(leader)); strcpy(tbuf1, atr_value(a)); @@ -1215,7 +1215,7 @@ del_follow(dbref leader, dbref follower, int noisy) strcpy(msg, tprintf(T("You stop following %s."), Name(leader))); notify_format(leader, T("%s stops following you."), Name(follower)); did_it(follower, leader, "UNFOLLOW", msg, "OUNFOLLOW", - NULL, "AUNFOLLOW", NOTHING); + NULL, "AUNFOLLOW", NOTHING); } } @@ -1241,7 +1241,7 @@ list_followers(dbref player) who = parse_dbref(sp); if (GoodObject(who)) { if (!first) - safe_str(", ", buff, &bp); + safe_str(", ", buff, &bp); safe_str(Name(who), buff, &bp); first = 0; } @@ -1272,7 +1272,7 @@ list_following(dbref player) who = parse_dbref(sp); if (GoodObject(who)) { if (!first) - safe_str(", ", buff, &bp); + safe_str(", ", buff, &bp); safe_str(Name(who), buff, &bp); first = 0; } @@ -1293,7 +1293,7 @@ is_following(dbref follower, dbref leader) */ a = atr_get_noparent(follower, "FOLLOWING"); if (!a) - return 0; /* Following no one */ + return 0; /* Following no one */ strcpy(tbuf1, atr_value(a)); s = trim_space_sep(tbuf1, ' '); while (s) { @@ -1317,7 +1317,7 @@ clear_followers(dbref leader, int noisy) dbref flwr; a = atr_get_noparent(leader, "FOLLOWERS"); if (!a) - return; /* No one's following me */ + return; /* No one's following me */ strcpy(tbuf1, atr_value(a)); s = trim_space_sep(tbuf1, ' '); while (s) { @@ -1326,7 +1326,7 @@ clear_followers(dbref leader, int noisy) if (GoodObject(flwr)) { del_following(flwr, leader); if (noisy) - notify_format(flwr, T("You stop following %s."), Name(leader)); + notify_format(flwr, T("You stop following %s."), Name(leader)); } } (void) atr_clr(leader, "FOLLOWERS", GOD); @@ -1345,7 +1345,7 @@ clear_following(dbref follower, int noisy) dbref ldr; a = atr_get_noparent(follower, "FOLLOWING"); if (!a) - return; /* I'm not following anyone */ + return; /* I'm not following anyone */ strcpy(tbuf1, atr_value(a)); s = trim_space_sep(tbuf1, ' '); while (s) { @@ -1354,7 +1354,7 @@ clear_following(dbref follower, int noisy) if (GoodObject(ldr)) { del_follower(ldr, follower); if (noisy) - notify_format(ldr, T("%s stops following you."), Name(follower)); + notify_format(ldr, T("%s stops following you."), Name(follower)); } } (void) atr_clr(follower, "FOLLOWING", GOD); diff --git a/src/mymalloc.c b/src/mymalloc.c index fab647e..63f0901 100644 --- a/src/mymalloc.c +++ b/src/mymalloc.c @@ -19,6 +19,4 @@ #include "csrimalloc.c" #elif (MALLOC_PACKAGE == 2) #include "csrimalloc.c" -#elif (MALLOC_PACKAGE == 5) -#include "gmalloc.c" #endif diff --git a/src/mysocket.c b/src/mysocket.c index d361b97..455e653 100644 --- a/src/mysocket.c +++ b/src/mysocket.c @@ -119,7 +119,7 @@ hostname_convert(struct sockaddr *host, int len) static char port[NI_MAXSERV]; if (getnameinfo(host, len, hostname, sizeof hostname, port, sizeof port, - (USE_DNS ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV) != 0) { + (USE_DNS ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV) != 0) { return NULL; } hi.hostname = hostname; @@ -140,14 +140,14 @@ ip_convert(struct sockaddr *host, int len) static char port[NI_MAXSERV]; if (getnameinfo(host, len, hostname, sizeof hostname, port, sizeof port, - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { + NI_NUMERICHOST | NI_NUMERICSERV) != 0) { return NULL; } hi.hostname = hostname; hi.port = port; return &hi; } -#endif /* INFOSLAVE */ +#endif /* INFOSLAVE */ /** Open a tcp connection to a given host and port. Basically * tcp_connect from UNPv1 @@ -160,7 +160,7 @@ ip_convert(struct sockaddr *host, int len) */ int make_socket_conn(const char *host, struct sockaddr *myiterface, - socklen_t myilen, Port_t port, int *timeout) + socklen_t myilen, Port_t port, int *timeout) { struct addrinfo hints, *server, *save; char cport[NI_MAXSERV]; @@ -170,7 +170,7 @@ make_socket_conn(const char *host, struct sockaddr *myiterface, memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; - hints.ai_family = AF_UNSPEC; /* Try to use IPv6 if available */ + hints.ai_family = AF_UNSPEC; /* Try to use IPv6 if available */ hints.ai_socktype = SOCK_STREAM; sprintf(cport, "%hu", port); @@ -198,11 +198,11 @@ make_socket_conn(const char *host, struct sockaddr *myiterface, if (myiterface && myilen > 0) { /* Bind to a specific interface. Needed for ident lookups */ if (bind(s, myiterface, myilen) < 0) - perror("bind failed (Possibly harmless)"); + perror("bind failed (Possibly harmless)"); } if ((err = connect_nonb(s, server->ai_addr, server->ai_addrlen, timeout)) == - 0) + 0) break; #ifdef DEBUG @@ -243,7 +243,7 @@ make_socket_conn(const char *host, struct sockaddr *myiterface, */ int make_socket(Port_t port, union sockaddr_u *addr, socklen_t *len, - const char *host) + const char *host) { int s, opt, ipv = 4; /* Use getaddrinfo() to fill in the sockaddr fields. This @@ -258,10 +258,10 @@ make_socket(Port_t port, union sockaddr_u *addr, socklen_t *len, memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; #ifdef FORCE_IPV4 - hints.ai_family = AF_INET; /* OpenBSD apparently doesn't properly - map IPv4 connections to IPv6 servers. */ + hints.ai_family = AF_INET; /* OpenBSD apparently doesn't properly + map IPv4 connections to IPv6 servers. */ #else - hints.ai_family = AF_UNSPEC; /* Try to use IPv6 if available */ + hints.ai_family = AF_UNSPEC; /* Try to use IPv6 if available */ #endif hints.ai_socktype = SOCK_STREAM; @@ -295,7 +295,7 @@ make_socket(Port_t port, union sockaddr_u *addr, socklen_t *len, } if (bind(s, server->ai_addr, server->ai_addrlen) == 0) - break; /* Success */ + break; /* Success */ perror("binding stream socket (Possibly ignorable)"); closesocket(s); @@ -343,7 +343,7 @@ make_nonblocking(int s) } if (fcntl(s, F_SETFL, flags | O_NDELAY) == -1) { -#endif /* WIN32 */ +#endif /* WIN32 */ perror("make_nonblocking: fcntl"); #ifndef INFOSLAVE mush_panic("O_NDELAY fcntl failed"); @@ -370,7 +370,7 @@ set_keepalive(int s __attribute__ ((__unused__))) /* enable TCP keepalive */ if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, - (void *) &keepalive, sizeof(keepalive)) == -1) + (void *) &keepalive, sizeof(keepalive)) == -1) fprintf(stderr, "[%d] could not set SO_KEEPALIVE: errno %d", s, errno); /* And set the ping time to something reasonable instead of the @@ -378,11 +378,11 @@ set_keepalive(int s __attribute__ ((__unused__))) this. OS X and possibly others use TCP_KEEPALIVE. */ #if defined(TCP_KEEPIDLE) if (setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE, - (void *) &keepidle, sizeof(keepidle)) == -1) + (void *) &keepidle, sizeof(keepidle)) == -1) fprintf(stderr, "[%d] could not set TCP_KEEPIDLE: errno %d", s, errno); #elif defined(TCP_KEEPALIVE) if (setsockopt(s, IPPROTO_TCP, TCP_KEEPALIVE, - (void *) &keepidle, sizeof(keepidle)) == -1) + (void *) &keepidle, sizeof(keepidle)) == -1) fprintf(stderr, "[%d] could not set TCP_KEEPALIVE: errno %d", s, errno); #endif #endif @@ -405,7 +405,7 @@ set_keepalive(int s __attribute__ ((__unused__))) */ int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, - int *timeout) + int *timeout) { int n, error; time_t start, end; @@ -437,7 +437,7 @@ connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, time(&start); if ((n = select(sockfd + 1, &rset, &wset, NULL, &tval)) == 0) { - closesocket(sockfd); /* timeout */ + closesocket(sockfd); /* timeout */ errno = ETIMEDOUT; return -1; } @@ -449,14 +449,14 @@ connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, if (FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) { len = sizeof(error); if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (__ptr_t) &error, &len) < 0) - return -1; /* Solaris pending error */ + return -1; /* Solaris pending error */ } else return -1; done: if (error) { - closesocket(sockfd); /* just in case */ + closesocket(sockfd); /* just in case */ errno = error; return -1; } @@ -501,7 +501,7 @@ done: #define INT16SZ 2 #ifndef AF_INET6 -#define AF_INET6 AF_MAX+1 /* just to let this compile */ +#define AF_INET6 AF_MAX+1 /* just to let this compile */ #endif /* @@ -597,14 +597,14 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) - cur.base = i, cur.len = 1; + cur.base = i, cur.len = 1; else - cur.len++; + cur.len++; } else { if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; } } } @@ -623,7 +623,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && i < (best.base + best.len)) { if (i == best.base) - *tp++ = ':'; + *tp++ = ':'; continue; } /* Are we following an initial run of 0x00s or any real hex? */ @@ -631,9 +631,9 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) *tp++ = ':'; /* Is this address an encapsulated IPv4? */ if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { if (!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp))) - return (NULL); + return (NULL); tp += strlen(tp); break; } @@ -737,16 +737,16 @@ inet_pton4(const char *src, unsigned char *dst) unsigned int new = *tp * 10 + (pch - digits); if (new > 255) - return (0); + return (0); *tp = new; if (!saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; + if (++octets > 4) + return (0); + saw_digit = 1; } } else if (ch == '.' && saw_digit) { if (octets == 4) - return (0); + return (0); *++tp = 0; saw_digit = 0; } else @@ -801,20 +801,20 @@ inet_pton6(const char *src, unsigned char *dst) val <<= 4; val |= (pch - xdigits); if (val > 0xffff) - return (0); + return (0); saw_xdigit = 1; continue; } if (ch == ':') { curtok = src; if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; + if (colonp) + return (0); + colonp = tp; + continue; } if (tp + INT16SZ > endp) - return (0); + return (0); *tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) val & 0xff; saw_xdigit = 0; @@ -824,7 +824,7 @@ inet_pton6(const char *src, unsigned char *dst) if (ch == '.' && ((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) { tp += INADDRSZ; saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ + break; /* '\0' was seen by inet_pton4(). */ } return (0); } @@ -858,7 +858,7 @@ inet_pton6(const char *src, unsigned char *dst) #ifndef HAS_GETNAMEINFO static int gn_ipv46(char *, size_t, char *, size_t, void *, size_t, - int, int, int); + int, int, int); /* * Handle either an IPv4 or an IPv6 address and port. @@ -867,7 +867,7 @@ static int gn_ipv46(char *, size_t, char *, size_t, void *, size_t, /* include gn_ipv46 */ static int gn_ipv46(char *host, size_t hostlen, char *serv, size_t servlen, - void *aptr, size_t alen, int family, int port, int flags) + void *aptr, size_t alen, int family, int port, int flags) { char *ptr; struct hostent *hptr; @@ -875,25 +875,25 @@ gn_ipv46(char *host, size_t hostlen, char *serv, size_t servlen, if (hostlen > 0) { if (flags & NI_NUMERICHOST) { if (inet_ntop(family, aptr, host, hostlen) == NULL) - return (1); + return (1); } else { hptr = gethostbyaddr(aptr, alen, family); if (hptr != NULL && hptr->h_name != NULL) { - if (flags & NI_NOFQDN) { - if ((ptr = strchr(hptr->h_name, '.')) != NULL) - *ptr = 0; /* overwrite first dot */ - } + if (flags & NI_NOFQDN) { + if ((ptr = strchr(hptr->h_name, '.')) != NULL) + *ptr = 0; /* overwrite first dot */ + } #ifdef HAS_SNPRINTF - snprintf(host, hostlen, "%s", hptr->h_name); + snprintf(host, hostlen, "%s", hptr->h_name); #else - strncpy(host, hptr->h_name, hostlen); - host[hostlen - 1] = '\0'; + strncpy(host, hptr->h_name, hostlen); + host[hostlen - 1] = '\0'; #endif } else { - if (flags & NI_NAMEREQD) - return (1); - if (inet_ntop(family, aptr, host, hostlen) == NULL) - return (1); + if (flags & NI_NAMEREQD) + return (1); + if (inet_ntop(family, aptr, host, hostlen) == NULL) + return (1); } } } @@ -924,7 +924,7 @@ gn_ipv46(char *host, size_t hostlen, char *serv, size_t servlen, /* include getnameinfo */ int getnameinfo(const struct sockaddr *sa, socklen_t salen, - char *host, size_t hostlen, char *serv, size_t servlen, int flags) + char *host, size_t hostlen, char *serv, size_t servlen, int flags) { switch (sa->sa_family) { @@ -933,8 +933,8 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, struct sockaddr_in *sain = (struct sockaddr_in *) sa; return (gn_ipv46(host, hostlen, serv, servlen, - &sain->sin_addr, sizeof(struct in_addr), - AF_INET, sain->sin_port, flags)); + &sain->sin_addr, sizeof(struct in_addr), + AF_INET, sain->sin_port, flags)); } #endif @@ -943,8 +943,8 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, struct sockaddr_in6 *sain = (struct sockaddr_in6 *) sa; return (gn_ipv46(host, hostlen, serv, servlen, - &sain->sin6_addr, sizeof(struct in6_addr), - AF_INET6, sain->sin6_port, flags)); + &sain->sin6_addr, sizeof(struct in6_addr), + AF_INET6, sain->sin6_port, flags)); } #endif @@ -961,12 +961,12 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, /* include ga1 */ struct search { - const char *host; /* hostname or address string */ - int family; /* AF_xxx */ + const char *host; /* hostname or address string */ + int family; /* AF_xxx */ }; static int ga_aistruct(struct addrinfo ***, const struct addrinfo *, - const void *, int); + const void *, int); static struct addrinfo *ga_clone(struct addrinfo *); static int ga_echeck(const char *, const char *, int, int, int, int); static int ga_nsearch(const char *, const struct addrinfo *, struct search *); @@ -976,7 +976,7 @@ static int ga_serv(struct addrinfo *, const struct addrinfo *, const char *); int getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hintsp, struct addrinfo **result) + const struct addrinfo *hintsp, struct addrinfo **result) { int rc, error, nsearch; char **ap, *canon; @@ -990,7 +990,7 @@ getaddrinfo(const char *hostname, const char *servname, */ #define error(e) { error = (e); goto bad; } - aihead = NULL; /* initialize automatic variables */ + aihead = NULL; /* initialize automatic variables */ aipnext = &aihead; canon = NULL; @@ -998,11 +998,11 @@ getaddrinfo(const char *hostname, const char *servname, memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; } else - hints = *hintsp; /* struct copy */ + hints = *hintsp; /* struct copy */ /* 4first some basic error checking */ if ((rc = ga_echeck(hostname, servname, hints.ai_flags, hints.ai_family, - hints.ai_socktype, hints.ai_protocol)) != 0) + hints.ai_socktype, hints.ai_protocol)) != 0) error(rc); /* end ga1 */ @@ -1017,14 +1017,14 @@ getaddrinfo(const char *hostname, const char *servname, struct in_addr inaddr; if (inet_pton(AF_INET, sptr->host, &inaddr) == 1) { - if (hints.ai_family != AF_UNSPEC && hints.ai_family != AF_INET) - error(EAI_ADDRFAMILY); - if (sptr->family != AF_INET) - continue; /* ignore */ - rc = ga_aistruct(&aipnext, &hints, &inaddr, AF_INET); - if (rc != 0) - error(rc); - continue; + if (hints.ai_family != AF_UNSPEC && hints.ai_family != AF_INET) + error(EAI_ADDRFAMILY); + if (sptr->family != AF_INET) + continue; /* ignore */ + rc = ga_aistruct(&aipnext, &hints, &inaddr, AF_INET); + if (rc != 0) + error(rc); + continue; } } #endif @@ -1032,18 +1032,18 @@ getaddrinfo(const char *hostname, const char *servname, #ifdef HAS_IPV6 /* 4check for an IPv6 hex string */ if ((isxdigit((unsigned char) sptr->host[0]) || sptr->host[0] == ':') && - (strchr(sptr->host, ':') != NULL)) { + (strchr(sptr->host, ':') != NULL)) { struct in6_addr in6addr; if (inet_pton(AF_INET6, sptr->host, &in6addr) == 1) { - if (hints.ai_family != AF_UNSPEC && hints.ai_family != AF_INET6) - error(EAI_ADDRFAMILY); - if (sptr->family != AF_INET6) - continue; /* ignore */ - rc = ga_aistruct(&aipnext, &hints, &in6addr, AF_INET6); - if (rc != 0) - error(rc); - continue; + if (hints.ai_family != AF_UNSPEC && hints.ai_family != AF_INET6) + error(EAI_ADDRFAMILY); + if (sptr->family != AF_INET6) + continue; /* ignore */ + rc = ga_aistruct(&aipnext, &hints, &in6addr, AF_INET6); + if (rc != 0) + error(rc); + continue; } } #endif @@ -1052,7 +1052,7 @@ getaddrinfo(const char *hostname, const char *servname, /* 4remainder of for() to look up hostname */ #ifdef HAS_IPV6 if ((_res.options & RES_INIT) == 0) - res_init(); /* need this to set _res.options */ + res_init(); /* need this to set _res.options */ #endif if (nsearch == 2) { @@ -1063,27 +1063,27 @@ getaddrinfo(const char *hostname, const char *servname, } else { #ifdef HAS_IPV6 if (sptr->family == AF_INET6) - _res.options |= RES_USE_INET6; + _res.options |= RES_USE_INET6; else - _res.options &= ~RES_USE_INET6; + _res.options &= ~RES_USE_INET6; #endif hptr = gethostbyname(sptr->host); } if (hptr == NULL) { if (nsearch == 2) - continue; /* failure OK if multiple searches */ + continue; /* failure OK if multiple searches */ switch (h_errno) { case HOST_NOT_FOUND: - error(EAI_NONAME); + error(EAI_NONAME); case TRY_AGAIN: - error(EAI_AGAIN); + error(EAI_AGAIN); case NO_RECOVERY: - error(EAI_FAIL); + error(EAI_FAIL); case NO_DATA: - error(EAI_NODATA); + error(EAI_NODATA); default: - error(EAI_NONAME); + error(EAI_NONAME); } } @@ -1093,30 +1093,30 @@ getaddrinfo(const char *hostname, const char *servname, /* 4save canonical name first time */ if (hostname != NULL && hostname[0] != '\0' && - (hints.ai_flags & AI_CANONNAME) && canon == NULL) { + (hints.ai_flags & AI_CANONNAME) && canon == NULL) { if ((canon = strdup(hptr->h_name)) == NULL) - error(EAI_MEMORY); + error(EAI_MEMORY); } /* 4create one addrinfo{} for each returned address */ for (ap = hptr->h_addr_list; *ap != NULL; ap++) { rc = ga_aistruct(&aipnext, &hints, *ap, hptr->h_addrtype); if (rc != 0) - error(rc); + error(rc); } } if (aihead == NULL) - error(EAI_NONAME); /* nothing found */ + error(EAI_NONAME); /* nothing found */ /* end ga4 */ /* include ga5 */ /* 4return canonical name */ if (hostname != NULL && hostname[0] != '\0' && hints.ai_flags & AI_CANONNAME) { if (canon != NULL) - aihead->ai_canonname = canon; /* strdup'ed earlier */ + aihead->ai_canonname = canon; /* strdup'ed earlier */ else { if ((aihead->ai_canonname = strdup(search[0].host)) == NULL) - error(EAI_MEMORY); + error(EAI_MEMORY); } } @@ -1126,11 +1126,11 @@ getaddrinfo(const char *hostname, const char *servname, error(rc); } - *result = aihead; /* pointer to first structure in linked list */ + *result = aihead; /* pointer to first structure in linked list */ return (0); bad: - freeaddrinfo(aihead); /* free any alloc'ed memory */ + freeaddrinfo(aihead); /* free any alloc'ed memory */ return (error); } @@ -1143,14 +1143,14 @@ bad: /* include ga_echeck */ static int ga_echeck(const char *hostname, const char *servname, - int flags, int family, int socktype, int protocol) + int flags, int family, int socktype, int protocol) { if (flags & ~(AI_PASSIVE | AI_CANONNAME)) - return (EAI_BADFLAGS); /* unknown flag bits */ + return (EAI_BADFLAGS); /* unknown flag bits */ if (hostname == NULL || hostname[0] == '\0') { if (servname == NULL || servname[0] == '\0') - return (EAI_NONAME); /* host or service must be specified */ + return (EAI_NONAME); /* host or service must be specified */ } switch (family) { @@ -1159,21 +1159,21 @@ ga_echeck(const char *hostname, const char *servname, #ifdef IPv4 case AF_INET: if (socktype != 0 && - (socktype != SOCK_STREAM && - socktype != SOCK_DGRAM && socktype != SOCK_RAW)) - return (EAI_SOCKTYPE); /* invalid socket type */ + (socktype != SOCK_STREAM && + socktype != SOCK_DGRAM && socktype != SOCK_RAW)) + return (EAI_SOCKTYPE); /* invalid socket type */ break; #endif #ifdef HAS_IPV6 case AF_INET6: if (socktype != 0 && - (socktype != SOCK_STREAM && - socktype != SOCK_DGRAM && socktype != SOCK_RAW)) - return (EAI_SOCKTYPE); /* invalid socket type */ + (socktype != SOCK_STREAM && + socktype != SOCK_DGRAM && socktype != SOCK_RAW)) + return (EAI_SOCKTYPE); /* invalid socket type */ break; #endif default: - return (EAI_FAMILY); /* unknown protocol family */ + return (EAI_FAMILY); /* unknown protocol family */ } return (0); } @@ -1189,7 +1189,7 @@ ga_echeck(const char *hostname, const char *servname, /* include ga_nsearch1 */ static int ga_nsearch(const char *hostname, const struct addrinfo *hintsp, - struct search *search) + struct search *search) { int nsearch = 0; @@ -1199,30 +1199,30 @@ ga_nsearch(const char *hostname, const struct addrinfo *hintsp, switch (hintsp->ai_family) { #ifdef IPv4 case AF_INET: - search[nsearch].host = "0.0.0.0"; - search[nsearch].family = AF_INET; - nsearch++; - break; + search[nsearch].host = "0.0.0.0"; + search[nsearch].family = AF_INET; + nsearch++; + break; #endif #ifdef HAS_IPV6 case AF_INET6: - search[nsearch].host = "0::0"; - search[nsearch].family = AF_INET6; - nsearch++; - break; + search[nsearch].host = "0::0"; + search[nsearch].family = AF_INET6; + nsearch++; + break; #endif case AF_UNSPEC: #ifdef HAS_IPV6 - search[nsearch].host = "0::0"; /* IPv6 first, then IPv4 */ - search[nsearch].family = AF_INET6; - nsearch++; + search[nsearch].host = "0::0"; /* IPv6 first, then IPv4 */ + search[nsearch].family = AF_INET6; + nsearch++; #endif #ifdef IPv4 - search[nsearch].host = "0.0.0.0"; - search[nsearch].family = AF_INET; - nsearch++; + search[nsearch].host = "0.0.0.0"; + search[nsearch].family = AF_INET; + nsearch++; #endif - break; + break; } /* end ga_nsearch1 */ /* include ga_nsearch2 */ @@ -1231,35 +1231,35 @@ ga_nsearch(const char *hostname, const struct addrinfo *hintsp, switch (hintsp->ai_family) { #ifdef IPv4 case AF_INET: - search[nsearch].host = "localhost"; /* 127.0.0.1 */ - search[nsearch].family = AF_INET; - nsearch++; - break; + search[nsearch].host = "localhost"; /* 127.0.0.1 */ + search[nsearch].family = AF_INET; + nsearch++; + break; #endif #ifdef HAS_IPV6 case AF_INET6: - search[nsearch].host = "0::1"; - search[nsearch].family = AF_INET6; - nsearch++; - break; + search[nsearch].host = "0::1"; + search[nsearch].family = AF_INET6; + nsearch++; + break; #endif case AF_UNSPEC: #ifdef HAS_IPV6 - search[nsearch].host = "0::1"; /* IPv6 first, then IPv4 */ - search[nsearch].family = AF_INET6; - nsearch++; + search[nsearch].host = "0::1"; /* IPv6 first, then IPv4 */ + search[nsearch].family = AF_INET6; + nsearch++; #endif #ifdef IPv4 - search[nsearch].host = "localhost"; - search[nsearch].family = AF_INET; - nsearch++; + search[nsearch].host = "localhost"; + search[nsearch].family = AF_INET; + nsearch++; #endif - break; + break; } } /* end ga_nsearch2 */ /* include ga_nsearch3 */ - } else { /* host is specified */ + } else { /* host is specified */ switch (hintsp->ai_family) { #ifdef IPv4 case AF_INET: @@ -1278,12 +1278,12 @@ ga_nsearch(const char *hostname, const struct addrinfo *hintsp, case AF_UNSPEC: #ifdef HAS_IPV6 search[nsearch].host = hostname; - search[nsearch].family = AF_INET6; /* IPv6 first */ + search[nsearch].family = AF_INET6; /* IPv6 first */ nsearch++; #endif #ifdef IPv4 search[nsearch].host = hostname; - search[nsearch].family = AF_INET; /* then IPv4 */ + search[nsearch].family = AF_INET; /* then IPv4 */ nsearch++; #endif break; @@ -1306,7 +1306,7 @@ ga_nsearch(const char *hostname, const struct addrinfo *hintsp, /* include ga_aistruct1 */ int ga_aistruct(struct addrinfo ***paipnext, const struct addrinfo *hintsp, - const void *addr, int family) + const void *addr, int family) { struct addrinfo *ai; @@ -1331,7 +1331,7 @@ ga_aistruct(struct addrinfo ***paipnext, const struct addrinfo *hintsp, /* 4allocate sockaddr_in{} and fill in all but port */ if ((sinptr = calloc(1, sizeof(struct sockaddr_in))) == NULL) - return (EAI_MEMORY); + return (EAI_MEMORY); #ifdef HAVE_SOCKADDR_SA_LEN sinptr->sin_len = sizeof(struct sockaddr_in); #endif @@ -1341,14 +1341,14 @@ ga_aistruct(struct addrinfo ***paipnext, const struct addrinfo *hintsp, ai->ai_addrlen = sizeof(struct sockaddr_in); break; } -#endif /* IPV4 */ +#endif /* IPV4 */ #ifdef HAS_IPV6 case AF_INET6:{ struct sockaddr_in6 *sin6ptr; /* 4allocate sockaddr_in6{} and fill in all but port */ if ((sin6ptr = calloc(1, sizeof(struct sockaddr_in6))) == NULL) - return (EAI_MEMORY); + return (EAI_MEMORY); #ifdef HAVE_SOCKADDR_SA_LEN sin6ptr->sin6_len = sizeof(struct sockaddr_in6); #endif @@ -1358,7 +1358,7 @@ ga_aistruct(struct addrinfo ***paipnext, const struct addrinfo *hintsp, ai->ai_addrlen = sizeof(struct sockaddr_in6); break; } -#endif /* IPV6 */ +#endif /* IPV6 */ } return (0); @@ -1373,34 +1373,34 @@ ga_aistruct(struct addrinfo ***paipnext, const struct addrinfo *hintsp, /* include ga_serv */ int ga_serv(struct addrinfo *aihead, const struct addrinfo *hintsp, - const char *serv) + const char *serv) { int port, rc, nfound; nfound = 0; - if (isdigit((unsigned char) serv[0])) { /* check for port number string first */ + if (isdigit((unsigned char) serv[0])) { /* check for port number string first */ port = (int) htons((unsigned short) atoi(serv)); if (hintsp->ai_socktype) { /* 4caller specifies socket type */ if ((rc = ga_port(aihead, port, hintsp->ai_socktype)) < 0) - return (EAI_MEMORY); + return (EAI_MEMORY); nfound += rc; } else { /* 4caller does not specify socket type */ if ((rc = ga_port(aihead, port, SOCK_STREAM)) < 0) - return (EAI_MEMORY); + return (EAI_MEMORY); nfound += rc; if ((rc = ga_port(aihead, port, SOCK_DGRAM)) < 0) - return (EAI_MEMORY); + return (EAI_MEMORY); nfound += rc; } } if (nfound == 0) { if (hintsp->ai_socktype == 0) - return (EAI_NONAME); /* all calls to getservbyname() failed */ + return (EAI_NONAME); /* all calls to getservbyname() failed */ else - return (EAI_SERVICE); /* service not supported for socket type */ + return (EAI_SERVICE); /* service not supported for socket type */ } return (0); } @@ -1437,7 +1437,7 @@ ga_serv(struct addrinfo *aihead, const struct addrinfo *hintsp, /* include ga_port */ int ga_port(struct addrinfo *aihead, int port, int socktype) - /* port must be in network byte order */ + /* port must be in network byte order */ { int nfound = 0; struct addrinfo *ai; @@ -1445,12 +1445,12 @@ ga_port(struct addrinfo *aihead, int port, int socktype) for (ai = aihead; ai != NULL; ai = ai->ai_next) { if (ai->ai_flags & AI_CLONE) { if (ai->ai_socktype != 0) { - if ((ai = ga_clone(ai)) == NULL) - return (-1); /* memory allocation error */ - /* ai points to newly cloned entry, which is what we want */ + if ((ai = ga_clone(ai)) == NULL) + return (-1); /* memory allocation error */ + /* ai points to newly cloned entry, which is what we want */ } } else if (ai->ai_socktype != socktype) - continue; /* ignore if mismatch on socket type */ + continue; /* ignore if mismatch on socket type */ ai->ai_socktype = socktype; @@ -1490,7 +1490,7 @@ ga_clone(struct addrinfo *ai) new->ai_next = ai->ai_next; ai->ai_next = new; - new->ai_flags = 0; /* make sure AI_CLONE is off */ + new->ai_flags = 0; /* make sure AI_CLONE is off */ new->ai_family = ai->ai_family; new->ai_socktype = ai->ai_socktype; new->ai_protocol = ai->ai_protocol; @@ -1504,7 +1504,7 @@ ga_clone(struct addrinfo *ai) } /* end ga_clone */ -#endif /* HAS_GETADDRINFO */ +#endif /* HAS_GETADDRINFO */ /* * Return a string containing some additional information after an @@ -1542,7 +1542,7 @@ gai_strerror(int err) return ("unknown getaddrinfo() error"); } } -#endif /* HAS_GAI_STRERROR */ +#endif /* HAS_GAI_STRERROR */ #ifndef HAS_GETADDRINFO @@ -1554,16 +1554,16 @@ freeaddrinfo(struct addrinfo *aihead) for (ai = aihead; ai != NULL; ai = ainext) { if (ai->ai_addr != NULL) - free(ai->ai_addr); /* socket address structure */ + free(ai->ai_addr); /* socket address structure */ if (ai->ai_canonname != NULL) free(ai->ai_canonname); - ainext = ai->ai_next; /* can't fetch ai_next after free() */ - free(ai); /* the addrinfo{} itself */ + ainext = ai->ai_next; /* can't fetch ai_next after free() */ + free(ai); /* the addrinfo{} itself */ } } /* end freeaddrinfo */ -#endif /* HAS_GETADDRINFO */ +#endif /* HAS_GETADDRINFO */ diff --git a/src/myssl.c b/src/myssl.c index 4dfa313..391d553 100644 --- a/src/myssl.c +++ b/src/myssl.c @@ -28,7 +28,7 @@ #define MAXHOSTNAMELEN 32 #define LC_MESSAGES 6 void shutdown_checkpoint(void); -#else /* !WIN32 */ +#else /* !WIN32 */ #ifdef I_SYS_FILE #include #endif @@ -52,7 +52,7 @@ void shutdown_checkpoint(void); #ifdef I_SYS_STAT #include #endif -#endif /* !WIN32 */ +#endif /* !WIN32 */ #include #ifdef I_SYS_WAIT #include @@ -73,6 +73,7 @@ void shutdown_checkpoint(void); #include #include #include +#include #include "conf.h" #include "mysocket.h" @@ -81,13 +82,13 @@ void shutdown_checkpoint(void); #include "parse.h" #include "confmagic.h" -#define MYSSL_RB 0x1 /**< Read blocked (on read) */ -#define MYSSL_WB 0x2 /**< Write blocked (on write) */ -#define MYSSL_RBOW 0x4 /**< Read blocked (on write) */ -#define MYSSL_WBOR 0x8 /**< Write blocked (on read) */ -#define MYSSL_ACCEPT 0x10 /**< We need to call SSL_accept (again) */ -#define MYSSL_VERIFIED 0x20 /**< This is an authenticated connection */ -#define MYSSL_HANDSHAKE 0x40 /**< We need to call SSL_do_handshake */ +#define MYSSL_RB 0x1 /**< Read blocked (on read) */ +#define MYSSL_WB 0x2 /**< Write blocked (on write) */ +#define MYSSL_RBOW 0x4 /**< Read blocked (on write) */ +#define MYSSL_WBOR 0x8 /**< Write blocked (on read) */ +#define MYSSL_ACCEPT 0x10 /**< We need to call SSL_accept (again) */ +#define MYSSL_VERIFIED 0x20 /**< This is an authenticated connection */ +#define MYSSL_HANDSHAKE 0x40 /**< We need to call SSL_do_handshake */ #undef MYSSL_DEBUG #ifdef MYSSL_DEBUG @@ -104,6 +105,8 @@ static DH *get_dh1024(void); static BIO *bio_err = NULL; static SSL_CTX *ctx = NULL; +unsigned int genrand_int32(void); + /** Initialize the SSL context. * \return pointer to SSL context object. */ @@ -112,6 +115,8 @@ ssl_init(void) { SSL_METHOD *meth; unsigned char context[128]; + DH *dh; + unsigned int reps = 1; if (!bio_err) { if (!SSL_library_init()) @@ -120,11 +125,23 @@ ssl_init(void) /* Error write context */ bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); } -#ifndef HAS_DEV_URANDOM - /* We need to seed the RNG with RAND_seed() or RAND_egd() here. - * Where are we going to get an unpredictable seed? - */ -#endif + + do_rawlog(LT_ERR, "Seeding OpenSSL random number pool."); + while (!RAND_status()) { + /* At this point, a system with /dev/urandom or a EGD file in the usual + places will have enough entropy. Otherwise, be lazy and use random numbers + until it's satisfied. */ + unsigned int gibberish[4]; + int n; + + for (n = 0; n < 4; n++) + gibberish[n] = genrand_int32(); + + RAND_seed(gibberish, sizeof gibberish); + + reps += 1; + } + do_rawlog(LT_ERR, "Seeded after %u %s.", reps, reps > 1 ? "cycles" : "cycle"); /* Set up SIGPIPE handler here? */ @@ -164,11 +181,14 @@ ssl_init(void) SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE | SSL_OP_ALL); SSL_CTX_set_mode(ctx, - SSL_MODE_ENABLE_PARTIAL_WRITE | - SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); + SSL_MODE_ENABLE_PARTIAL_WRITE | + SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); /* Set up DH callback */ + dh = get_dh1024(); SSL_CTX_set_tmp_dh(ctx, get_dh1024()); + /* The above function makes a private copy of this */ + DH_free(dh); /* Set the cipher list to the usual default list, except that * we'll allow anonymous diffie-hellman, too. @@ -199,7 +219,7 @@ client_verify_callback(int preverify_ok, X509_STORE_CTX * x509_ctx) X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256); if (!preverify_ok) { do_log(LT_ERR, 0, 0, "verify error:num=%d:%s:depth=%d:%s\n", err, - X509_verify_cert_error_string(err), depth, buf); + X509_verify_cert_error_string(err), depth, buf); if (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT) { X509_NAME_oneline(X509_get_issuer_name(x509_ctx->current_cert), buf, 256); do_log(LT_ERR, 0, 0, "issuer= %s\n", buf); @@ -422,10 +442,10 @@ ssl_accept(SSL * ssl) /* Successful accept - report it */ if ((peer = SSL_get_peer_certificate(ssl))) { if (SSL_get_verify_result(ssl) == X509_V_OK) { - /* The client sent a certificate which verified OK */ - X509_NAME_oneline(X509_get_subject_name(peer), buf, 256); - do_log(LT_CONN, 0, 0, "SSL client certificate accepted: %s", buf); - state |= MYSSL_VERIFIED; + /* The client sent a certificate which verified OK */ + X509_NAME_oneline(X509_get_subject_name(peer), buf, 256); + do_log(LT_CONN, 0, 0, "SSL client certificate accepted: %s", buf); + state |= MYSSL_VERIFIED; } } } @@ -446,7 +466,7 @@ ssl_accept(SSL * ssl) */ int ssl_read(SSL * ssl, int state, int net_read_ready, int net_write_ready, - char *buf, int bufsize, int *bytes_read) + char *buf, int bufsize, int *bytes_read) { if ((net_read_ready && !(state & MYSSL_WBOR)) || (net_write_ready && (state & MYSSL_RBOW))) { @@ -455,27 +475,27 @@ ssl_read(SSL * ssl, int state, int net_read_ready, int net_write_ready, *bytes_read = SSL_read(ssl, buf, bufsize); switch (SSL_get_error(ssl, *bytes_read)) { case SSL_ERROR_NONE: - /* Yay */ - return state; + /* Yay */ + return state; case SSL_ERROR_ZERO_RETURN: - /* End of data on this socket */ - return -1; + /* End of data on this socket */ + return -1; case SSL_ERROR_WANT_READ: - /* More needs to be read from the underlying socket */ - ssl_debugdump("SSL_read wants read"); - state |= MYSSL_RB; - break; + /* More needs to be read from the underlying socket */ + ssl_debugdump("SSL_read wants read"); + state |= MYSSL_RB; + break; case SSL_ERROR_WANT_WRITE: - /* More needs to be written to the underlying socket. - * This can happen during a rehandshake. - */ - ssl_debugdump("SSL_read wants write"); - state |= MYSSL_RBOW; - break; + /* More needs to be written to the underlying socket. + * This can happen during a rehandshake. + */ + ssl_debugdump("SSL_read wants write"); + state |= MYSSL_RBOW; + break; default: - /* Should never happen */ - ssl_errordump("Unknown ssl_read failure!"); - return -1; + /* Should never happen */ + ssl_errordump("Unknown ssl_read failure!"); + return -1; } } while (SSL_pending(ssl) && !(state & MYSSL_RB)); } @@ -494,7 +514,7 @@ ssl_read(SSL * ssl, int state, int net_read_ready, int net_write_ready, */ int ssl_write(SSL * ssl, int state, int net_read_ready, int net_write_ready, - unsigned char *buf, int bufsize, int *offset) + unsigned char *buf, int bufsize, int *offset) { int r; if ((net_write_ready && bufsize) || (net_read_ready && !(state & MYSSL_WBOR))) { @@ -586,7 +606,7 @@ ssl_read_ssl(FILE * fp, int sock) SSL_set_bio(ssl, bio, bio); return ssl; } -#endif /* BROKEN */ +#endif /* BROKEN */ -#endif /* HAS_OPENSSL */ +#endif /* HAS_OPENSSL */ diff --git a/src/notify.c b/src/notify.c index df415d4..7ca7d7e 100644 --- a/src/notify.c +++ b/src/notify.c @@ -20,7 +20,7 @@ #include #include #include -#else /* !WIN32 */ +#else /* !WIN32 */ #ifdef I_SYS_FILE #include #endif @@ -43,7 +43,7 @@ #ifdef I_SYS_STAT #include #endif -#endif /* !WIN32 */ +#endif /* !WIN32 */ #include #include #include @@ -213,35 +213,35 @@ fillstate(int state[6], const unsigned char **f) p++; while (*p && *p != 'm') { if ((*p > '9') || (*p < '0')) { - /* Nada */ + /* Nada */ } else if (!(*(p + 1)) || (*(p + 1) == 'm') || (*(p + 1) == ';')) { - /* ShortCode */ ; - switch (*p) { - case '0': - for (i = 0; i < 6; i++) - state[i] = 0; - break; - case '1': - state[TA_BOLD] = 1; - break; - case '7': - state[TA_REV] = 1; - break; - case '5': - state[TA_BLINK] = 1; - break; - case '4': - state[TA_ULINE] = 1; - break; - } + /* ShortCode */ ; + switch (*p) { + case '0': + for (i = 0; i < 6; i++) + state[i] = 0; + break; + case '1': + state[TA_BOLD] = 1; + break; + case '7': + state[TA_REV] = 1; + break; + case '5': + state[TA_BLINK] = 1; + break; + case '4': + state[TA_ULINE] = 1; + break; + } } else { - n = (*p - '0') * 10; - p++; - n += (*p - '0'); - if ((n >= 30) && (n <= 37)) - state[TA_FGC] = n - 29; - else if ((n >= 40) && (n <= 47)) - state[TA_BGC] = n - 39; + n = (*p - '0') * 10; + p++; + n += (*p - '0'); + if ((n >= 30) && (n <= 37)) + state[TA_FGC] = n - 29; + else if ((n >= 40) && (n <= 47)) + state[TA_BGC] = n - 39; } p++; } @@ -349,18 +349,18 @@ notify_makestring(const char *message, struct notify_strings messages[], while (*p) { switch (*p) { case TAG_START: - while (*p && *p != TAG_END) - p++; - break; + while (*p && *p != TAG_END) + p++; + break; case '\r': case BEEP_CHAR: - break; + break; case ESC_CHAR: - while (*p && *p != 'm') - p++; - break; + while (*p && *p != 'm') + p++; + break; default: - safe_chr(*p, t, &o); + safe_chr(*p, t, &o); } p++; } @@ -378,31 +378,31 @@ notify_makestring(const char *message, struct notify_strings messages[], while (*p) { switch (*p) { case IAC: - if (type == NA_TPASCII) - safe_str("\xFF\xFF", t, &o); - else if (strip) - safe_str(accent_table[IAC].base, t, &o); - else - safe_chr((char) IAC, t, &o); - break; + if (type == NA_TPASCII) + safe_strl("\xFF\xFF", 2, t, &o); + else if (strip) + safe_str(accent_table[IAC].base, t, &o); + else + safe_chr((char) IAC, t, &o); + break; case TAG_START: - while (*p && *p != TAG_END) - p++; - break; + while (*p && *p != TAG_END) + p++; + break; case ESC_CHAR: - while (*p && *p != 'm') - p++; - break; + while (*p && *p != 'm') + p++; + break; case '\r': - break; + break; case '\n': - safe_str("\r\n", t, &o); - break; + safe_strl("\r\n", 2, t, &o); + break; default: - if (strip && accent_table[(unsigned char) *p].base) - safe_str(accent_table[(unsigned char) *p].base, t, &o); - else - safe_chr(*p, t, &o); + if (strip && accent_table[(unsigned char) *p].base) + safe_str(accent_table[(unsigned char) *p].base, t, &o); + else + safe_chr(*p, t, &o); } p++; } @@ -428,83 +428,83 @@ notify_makestring(const char *message, struct notify_strings messages[], while (*p) { switch ((unsigned char) *p) { case IAC: - if (changed) { - changed = 0; - ansi_change_state(t, &o, color, state, newstate); - } - if (type == NA_TANSI || type == NA_TCOLOR) - safe_str("\xFF\xFF", t, &o); - else if (strip && accent_table[IAC].base) - safe_str(accent_table[IAC].base, t, &o); - else - safe_chr((char) IAC, t, &o); - break; + if (changed) { + changed = 0; + ansi_change_state(t, &o, color, state, newstate); + } + if (type == NA_TANSI || type == NA_TCOLOR) + safe_str("\xFF\xFF", t, &o); + else if (strip && accent_table[IAC].base) + safe_str(accent_table[IAC].base, t, &o); + else + safe_chr((char) IAC, t, &o); + break; case TAG_START: - if (pueblo) { - safe_chr('<', t, &o); - p++; - while ((*p) && (*p != TAG_END)) { - safe_chr(*p, t, &o); - p++; - } - safe_chr('>', t, &o); - } else { - /* Non-pueblo */ - while (*p && *p != TAG_END) - p++; - } - break; + if (pueblo) { + safe_chr('<', t, &o); + p++; + while ((*p) && (*p != TAG_END)) { + safe_chr(*p, t, &o); + p++; + } + safe_chr('>', t, &o); + } else { + /* Non-pueblo */ + while (*p && *p != TAG_END) + p++; + } + break; case TAG_END: - /* Should never be seen alone */ - break; + /* Should never be seen alone */ + break; case '\r': - break; + break; case ESC_CHAR: - fillstate(newstate, &p); - changed = 1; - break; + fillstate(newstate, &p); + changed = 1; + break; default: - if (changed) { - changed = 0; - ansi_change_state(t, &o, color, state, newstate); - } - if (pueblo) { - if (strip) { - /* Even if we're NOACCENTS, we must still translate a few things */ - switch ((unsigned char) *p) { - case '\n': - case '&': - case '<': - case '>': - case '"': - safe_str(accent_table[(unsigned char) *p].entity, t, &o); - break; - default: - if (accent_table[(unsigned char) *p].base) - safe_str(accent_table[(unsigned char) *p].base, t, &o); - else - safe_chr(*p, t, &o); - break; - } - } else if (accent_table[(unsigned char) *p].entity) - safe_str(accent_table[(unsigned char) *p].entity, t, &o); - else - safe_chr(*p, t, &o); - } else { - /* Non-pueblo */ - if ((unsigned char) *p == '\n') - safe_str("\r\n", t, &o); - else if (strip && accent_table[(unsigned char) *p].base) - safe_str(accent_table[(unsigned char) *p].base, t, &o); - else - safe_chr(*p, t, &o); - } + if (changed) { + changed = 0; + ansi_change_state(t, &o, color, state, newstate); + } + if (pueblo) { + if (strip) { + /* Even if we're NOACCENTS, we must still translate a few things */ + switch ((unsigned char) *p) { + case '\n': + case '&': + case '<': + case '>': + case '"': + safe_str(accent_table[(unsigned char) *p].entity, t, &o); + break; + default: + if (accent_table[(unsigned char) *p].base) + safe_str(accent_table[(unsigned char) *p].base, t, &o); + else + safe_chr(*p, t, &o); + break; + } + } else if (accent_table[(unsigned char) *p].entity) + safe_str(accent_table[(unsigned char) *p].entity, t, &o); + else + safe_chr(*p, t, &o); + } else { + /* Non-pueblo */ + if ((unsigned char) *p == '\n') + safe_str("\r\n", t, &o); + else if (strip && accent_table[(unsigned char) *p].base) + safe_str(accent_table[(unsigned char) *p].base, t, &o); + else + safe_chr(*p, t, &o); + } } p++; } if (state[TA_BOLD] || state[TA_REV] || - state[TA_BLINK] || state[TA_ULINE] || - (color && (state[TA_FGC] || state[TA_BGC]))) + state[TA_BLINK] || state[TA_ULINE] || + (color && (state[TA_FGC] || state[TA_BGC]))) safe_str(ANSI_NORMAL, t, &o); break; @@ -661,7 +661,7 @@ na_exceptN(dbref current, void *data) check = 0; for (i = 2; i < dbrefs[0] + 2; i++) if (current == dbrefs[i]) - check = 1; + check = 1; } while (check); return current; } @@ -693,14 +693,14 @@ notify_type(DESC *d) } else if (ShowAnsi(d->player)) { if (ShowAnsiColor(d->player)) { if (strip) - poutput = NA_NCOLOR; + poutput = NA_NCOLOR; else - poutput = (d->conn_flags & CONN_TELNET) ? NA_TCOLOR : NA_COLOR; + poutput = (d->conn_flags & CONN_TELNET) ? NA_TCOLOR : NA_COLOR; } else { if (strip) - poutput = NA_NANSI; + poutput = NA_NANSI; else - poutput = (d->conn_flags & CONN_TELNET) ? NA_TANSI : NA_ANSI; + poutput = (d->conn_flags & CONN_TELNET) ? NA_TANSI : NA_ANSI; } } else { if (strip) @@ -726,9 +726,9 @@ notify_type(DESC *d) */ void notify_anything_loc(dbref speaker, na_lookup func, - void *fdata, char *(*nsfunc) (dbref, na_lookup func, void *, - int), int flags, - const char *message, dbref loc) + void *fdata, char *(*nsfunc) (dbref, na_lookup func, void *, + int), int flags, + const char *message, dbref loc) { dbref target; dbref passalong[3]; @@ -1031,9 +1031,9 @@ notify_anything_loc(dbref speaker, na_lookup func, */ void notify_anything(dbref speaker, na_lookup func, - void *fdata, char *(*nsfunc) (dbref, na_lookup func, void *, - int), int flags, - const char *message) + void *fdata, char *(*nsfunc) (dbref, na_lookup func, void *, + int), int flags, + const char *message) { dbref loc; @@ -1089,9 +1089,9 @@ notify_format(dbref player, const char *fmt, ...) */ void WIN32_CDECL notify_anything_format(dbref speaker, na_lookup func, - void *fdata, char *(*nsfunc) (dbref, na_lookup func, - void *, int), int flags, - const char *fmt, ...) + void *fdata, char *(*nsfunc) (dbref, na_lookup func, + void *, int), int flags, + const char *fmt, ...) { #ifdef HAS_VSNPRINTF char buff[BUFFER_LEN]; @@ -1122,7 +1122,7 @@ notify_anything_format(dbref speaker, na_lookup func, */ void notify_list(dbref speaker, dbref thing, const char *atr, const char *msg, - int flags) + int flags) { char *fwdstr, *orig, *curr; char tbuf1[BUFFER_LEN], *bp; @@ -1142,9 +1142,9 @@ notify_list(dbref speaker, dbref thing, const char *atr, const char *msg, make_prefixstr(thing, msg, tbuf1); if (!(flags & NA_SPOOF)) { if (Nospoof(thing)) - nsflags |= NA_NOSPOOF; + nsflags |= NA_NOSPOOF; if (Paranoid(thing)) - nsflags |= NA_PARANOID; + nsflags |= NA_PARANOID; } } else { safe_str(msg, tbuf1, &bp); @@ -1239,7 +1239,7 @@ safe_tag_cancel(char const *a_tag, char *buf, char **bp) */ int safe_tag_wrap(char const *a_tag, char const *params, char const *data, - char *buf, char **bp, dbref player) + char *buf, char **bp, dbref player) { int result = 0; char *save = buf; @@ -1378,7 +1378,7 @@ flush_queue(struct text_queue *q, int n) q->head = p->nxt; #ifdef DEBUG do_rawlog(LT_ERR, "free_text_block(0x%x) at 1.", p); -#endif /* DEBUG */ +#endif /* DEBUG */ free_text_block(p); } p = @@ -1403,7 +1403,7 @@ ssl_flush_queue(struct text_queue *q) q->head->nxt = p->nxt; #ifdef DEBUG do_rawlog(LT_ERR, "free_text_block(0x%x) at 1.", p); -#endif /* DEBUG */ +#endif /* DEBUG */ free_text_block(p); } } @@ -1482,13 +1482,13 @@ queue_newwrite(DESC *d, const unsigned char *b, int n) if (space < 0) { #ifdef HAS_OPENSSL if (d->ssl) { - /* Now we have a problem, as SSL works in blocks and you can't - * just partially flush stuff. - */ - d->output_size = ssl_flush_queue(&d->output); + /* Now we have a problem, as SSL works in blocks and you can't + * just partially flush stuff. + */ + d->output_size = ssl_flush_queue(&d->output); } else #endif - d->output_size -= flush_queue(&d->output, -space); + d->output_size -= flush_queue(&d->output, -space); } } add_to_queue(&d->output, b, n); @@ -1561,7 +1561,7 @@ freeqs(DESC *d) next = cur->nxt; #ifdef DEBUG do_rawlog(LT_ERR, "free_text_block(0x%x) at 3.", cur); -#endif /* DEBUG */ +#endif /* DEBUG */ free_text_block(cur); cur = next; } @@ -1573,7 +1573,7 @@ freeqs(DESC *d) next = cur->nxt; #ifdef DEBUG do_rawlog(LT_ERR, "free_text_block(0x%x) at 4.", cur); -#endif /* DEBUG */ +#endif /* DEBUG */ free_text_block(cur); cur = next; } @@ -1596,7 +1596,7 @@ freeqs(DESC *d) * */ char * ns_esnotify(dbref speaker, na_lookup func __attribute__ ((__unused__)), - void *fdata __attribute__ ((__unused__)), int para) + void *fdata __attribute__ ((__unused__)), int para) { char *dest, *bp; bp = dest = mush_malloc(BUFFER_LEN, "string"); @@ -1608,7 +1608,7 @@ ns_esnotify(dbref speaker, na_lookup func __attribute__ ((__unused__)), safe_format(dest, &bp, "[%s(#%d)] ", Name(speaker), speaker); else safe_format(dest, &bp, "[%s(#%d)'s %s(#%d)] ", Name(Owner(speaker)), - Owner(speaker), Name(speaker), speaker); + Owner(speaker), Name(speaker), speaker); } else safe_format(dest, &bp, "[%s:] ", spname(speaker)); *bp = '\0'; diff --git a/src/parse.c b/src/parse.c index 89b8d25..334d3e8 100644 --- a/src/parse.c +++ b/src/parse.c @@ -34,7 +34,7 @@ #include "mymalloc.h" #include "confmagic.h" -extern char *absp[], *obj[], *poss[], *subj[]; /* fundb.c */ +extern char *absp[], *obj[], *poss[], *subj[]; /* fundb.c */ extern int inum, inum_limit; extern char *iter_rep[]; int global_fun_invocations; @@ -48,9 +48,9 @@ extern int iter_break; /** Structure for storing DEBUG output in a linked list */ struct debug_info { - char *string; /**< A DEBUG string */ - Debug_Info *prev; /**< Previous node in the linked list */ - Debug_Info *next; /**< Next node in the linked list */ + char *string; /**< A DEBUG string */ + Debug_Info *prev; /**< Previous node in the linked list */ + Debug_Info *next; /**< Next node in the linked list */ }; FUNCTION_PROTO(fun_gfun); @@ -159,7 +159,7 @@ parse_objid(char const *str) time_t matchtime; p++; if (!is_strict_integer(p)) - return NOTHING; + return NOTHING; matchtime = parse_integer(p); return (CreTime(it) == matchtime) ? it : NOTHING; } else @@ -199,12 +199,12 @@ parse_boolean(char const *str) return 0; /* Non-zero numbers are true, zero is false */ if (is_strict_number(str)) - return parse_number(str) != 0; /* avoid rounding problems */ + return parse_number(str) != 0; /* avoid rounding problems */ /* Skip blanks */ while (*str == ' ') str++; /* If there's any non-blanks left, it's true */ - return *str != '\0'; /* force to 1 or 0 */ + return *str != '\0'; /* force to 1 or 0 */ } } @@ -348,6 +348,27 @@ is_strict_number(char const *str) return end > str; } +/** Is string a number that isn't inf or nan? + * \param num NVAL + * \retval 1 num is a good number. + * \retval 0 num is not a good number. + */ +int +is_good_number(NVAL val) +{ + char numbuff[128]; + char *p; + snprintf(numbuff, 128, "%f", val); + p = numbuff; + /* Negative? */ + if (*p == '-') + p++; + /* Must start with a digit. */ + if (!*p || !isdigit((unsigned char) *p)) + return 0; + return 1; +} + /** Is string an integer by the strict definition? * A strict integer is a non-null string that passes strtol. * \param str string to check. @@ -394,7 +415,7 @@ extern char active_table[UCHAR_MAX + 1]; extern signed char qreg_indexes[UCHAR_MAX + 1]; #ifdef WIN32 -#pragma warning( disable : 4761) /* NJG: disable warning re conversion */ +#pragma warning( disable : 4761) /* NJG: disable warning re conversion */ #endif @@ -450,8 +471,8 @@ extern signed char qreg_indexes[UCHAR_MAX + 1]; */ int process_expression(char *buff, char **bp, char const **str, - dbref executor, dbref caller, dbref enactor, - int eflags, int tflags, PE_Info * pe_info) + dbref executor, dbref caller, dbref enactor, + int eflags, int tflags, PE_Info * pe_info) { int debugging = 0, made_info = 0; char *debugstr = NULL, *sourcestr = NULL; @@ -477,11 +498,11 @@ process_expression(char *buff, char **bp, char const **str, * it might never get displayed. */ if (!Quiet(enactor)) - notify(enactor, T("CPU usage exceeded.")); + notify(enactor, T("CPU usage exceeded.")); do_rawlog(LT_TRACE, - T - ("CPU time limit exceeded. enactor=#%d executor=#%d caller=#%d code=%s"), - enactor, executor, caller, *str); + T + ("CPU time limit exceeded. enactor=#%d executor=#%d caller=#%d code=%s"), + enactor, executor, caller, *str); } return 1; } @@ -498,7 +519,7 @@ process_expression(char *buff, char **bp, char const **str, inum_limit = inum; made_info = 1; pe_info = (PE_Info *) mush_malloc(sizeof(PE_Info), - "process_expression.pe_info"); + "process_expression.pe_info"); pe_info->fun_invocations = 0; pe_info->fun_depth = 0; pe_info->nest_depth = 0; @@ -523,7 +544,7 @@ process_expression(char *buff, char **bp, char const **str, realbuff = buff; realbp = *bp; buff = (char *) mush_malloc(BUFFER_LEN, - "process_expression.buffer_extension"); + "process_expression.buffer_extension"); *bp = buff; startpos = buff; } @@ -548,29 +569,29 @@ process_expression(char *buff, char **bp, char const **str, Debug_Info *node; debugstr = (char *) mush_malloc(BUFFER_LEN, - "process_expression.debug_source"); + "process_expression.debug_source"); debugp = debugstr; safe_dbref(executor, debugstr, &debugp); safe_chr('!', debugstr, &debugp); for (j = 0; j <= pe_info->nest_depth; j++) - safe_chr(' ', debugstr, &debugp); + safe_chr(' ', debugstr, &debugp); sourcestr = debugp; mark = *str; process_expression(debugstr, &debugp, str, - executor, caller, enactor, - PE_NOTHING, tflags, pe_info); + executor, caller, enactor, + PE_NOTHING, tflags, pe_info); *str = mark; if (eflags & PE_COMPRESS_SPACES) - while ((debugp > sourcestr) && (debugp[-1] == ' ')) - debugp--; + while ((debugp > sourcestr) && (debugp[-1] == ' ')) + debugp--; *debugp = '\0'; node = (Debug_Info *) mush_malloc(sizeof(Debug_Info), - "process_expression.debug_node"); + "process_expression.debug_node"); node->string = debugstr; node->prev = pe_info->debug_strings; node->next = NULL; if (node->prev) - node->prev->next = node; + node->prev->next = node; pe_info->debug_strings = node; pe_info->nest_depth++; } @@ -593,16 +614,16 @@ process_expression(char *buff, char **bp, char const **str, /* Inlined strcspn() equivalent, to save on overhead and portability */ pos = *str; while (!active_table[*(unsigned char const *) *str]) - (*str)++; + (*str)++; /* Inlined safe_str(), since the source string * may not be null terminated */ len = *str - pos; len2 = BUFFER_LEN - 1 - (*bp - buff); if (len > len2) - len = len2; + len = len2; if (len >= 0) { - memcpy(*bp, pos, len); - *bp += len; + memcpy(*bp, pos, len); + *bp += len; } } @@ -1403,21 +1424,21 @@ process_expression(char *buff, char **bp, char const **str, safe_chr(' ', buff, bp); (*str)++; if (eflags & PE_COMPRESS_SPACES) { - while (**str == ' ') - (*str)++; + while (**str == ' ') + (*str)++; } else - while (**str == ' ') { - safe_chr(' ', buff, bp); - (*str)++; - } + while (**str == ' ') { + safe_chr(' ', buff, bp); + (*str)++; + } break; /* Escape charater */ case '\\': if (!(eflags & PE_EVALUATE)) - safe_chr('\\', buff, bp); + safe_chr('\\', buff, bp); (*str)++; if (!**str) - goto exit_sequence; + goto exit_sequence; /* FALL THROUGH */ /* Basic character */ default: @@ -1430,51 +1451,51 @@ process_expression(char *buff, char **bp, char const **str, exit_sequence: if (eflags != PE_NOTHING) { if ((eflags & PE_COMPRESS_SPACES) && had_space && - ((*str)[-1] == ' ') && ((*bp)[-1] == ' ')) + ((*str)[-1] == ' ') && ((*bp)[-1] == ' ')) (*bp)--; if (debugging) { pe_info->nest_depth--; **bp = '\0'; if (strcmp(sourcestr, startpos)) { - static char dbuf[BUFFER_LEN]; - char *dbp; - if (pe_info->debug_strings) { - while (pe_info->debug_strings->prev) - pe_info->debug_strings = pe_info->debug_strings->prev; - while (pe_info->debug_strings->next) { - dbp = dbuf; - dbuf[0] = '\0'; - safe_format(dbuf, &dbp, "%s :", pe_info->debug_strings->string); - *dbp = '\0'; - if (Connected(Owner(executor))) - raw_notify(Owner(executor), dbuf); - notify_list(executor, executor, "DEBUGFORWARDLIST", dbuf, - NA_NOLISTEN | NA_NOPREFIX); - pe_info->debug_strings = pe_info->debug_strings->next; - mush_free((Malloc_t) pe_info->debug_strings->prev, - "process_expression.debug_node"); - } - mush_free((Malloc_t) pe_info->debug_strings, - "process_expression.debug_node"); - pe_info->debug_strings = NULL; - } - dbp = dbuf; - dbuf[0] = '\0'; - safe_format(dbuf, &dbp, "%s => %s", debugstr, startpos); - *dbp = '\0'; - if (Connected(Owner(executor))) - raw_notify(Owner(executor), dbuf); - notify_list(executor, executor, "DEBUGFORWARDLIST", dbuf, - NA_NOLISTEN | NA_NOPREFIX); + static char dbuf[BUFFER_LEN]; + char *dbp; + if (pe_info->debug_strings) { + while (pe_info->debug_strings->prev) + pe_info->debug_strings = pe_info->debug_strings->prev; + while (pe_info->debug_strings->next) { + dbp = dbuf; + dbuf[0] = '\0'; + safe_format(dbuf, &dbp, "%s :", pe_info->debug_strings->string); + *dbp = '\0'; + if (Connected(Owner(executor))) + raw_notify(Owner(executor), dbuf); + notify_list(executor, executor, "DEBUGFORWARDLIST", dbuf, + NA_NOLISTEN | NA_NOPREFIX); + pe_info->debug_strings = pe_info->debug_strings->next; + mush_free((Malloc_t) pe_info->debug_strings->prev, + "process_expression.debug_node"); + } + mush_free((Malloc_t) pe_info->debug_strings, + "process_expression.debug_node"); + pe_info->debug_strings = NULL; + } + dbp = dbuf; + dbuf[0] = '\0'; + safe_format(dbuf, &dbp, "%s => %s", debugstr, startpos); + *dbp = '\0'; + if (Connected(Owner(executor))) + raw_notify(Owner(executor), dbuf); + notify_list(executor, executor, "DEBUGFORWARDLIST", dbuf, + NA_NOLISTEN | NA_NOPREFIX); } else { - Debug_Info *node; - node = pe_info->debug_strings; - if (node) { - pe_info->debug_strings = node->prev; - if (node->prev) - node->prev->next = NULL; - mush_free((Malloc_t) node, "process_expression.debug_node"); - } + Debug_Info *node; + node = pe_info->debug_strings; + if (node) { + pe_info->debug_strings = node->prev; + if (node->prev) + node->prev->next = NULL; + mush_free((Malloc_t) node, "process_expression.debug_node"); + } } mush_free((Malloc_t) debugstr, "process_expression.debug_source"); } @@ -1497,5 +1518,5 @@ exit_sequence: } #ifdef WIN32 -#pragma warning( default : 4761) /* NJG: enable warning re conversion */ +#pragma warning( default : 4761) /* NJG: enable warning re conversion */ #endif diff --git a/src/pcre.c b/src/pcre.c index 6d66d2e..eceb705 100644 --- a/src/pcre.c +++ b/src/pcre.c @@ -69,7 +69,7 @@ POSSIBILITY OF SUCH DAMAGE. -#define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */ +#define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */ typedef unsigned char uschar; @@ -155,15 +155,15 @@ but skip the top bit so we can use ints for convenience without getting tangled with negative values. The public options defined in pcre.h start at the least significant end. Make sure they don't overlap! */ -#define PCRE_FIRSTSET 0x40000000 /* first_byte is set */ -#define PCRE_REQCHSET 0x20000000 /* req_byte is set */ -#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */ -#define PCRE_ICHANGED 0x08000000 /* i option changes within regex */ -#define PCRE_NOPARTIAL 0x04000000 /* can't use partial with this regex */ +#define PCRE_FIRSTSET 0x40000000 /* first_byte is set */ +#define PCRE_REQCHSET 0x20000000 /* req_byte is set */ +#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */ +#define PCRE_ICHANGED 0x08000000 /* i option changes within regex */ +#define PCRE_NOPARTIAL 0x04000000 /* can't use partial with this regex */ /* Options for the "extra" block produced by pcre_study(). */ -#define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */ +#define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */ /* Masks for identifying the public options that are permitted at compile time, run time, or study time, respectively. */ @@ -181,12 +181,12 @@ time, run time, or study time, respectively. */ (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART) -#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ +#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ /* Magic number to provide a small check against being handed junk. Also used to detect whether a pattern was compiled on a host of different endianness. */ -#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ +#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ /* Negative values for the firstchar and reqchar variables */ @@ -201,8 +201,8 @@ req_byte match. */ /* Flags added to firstbyte or reqbyte; a "non-literal" item is either a variable-length repeat, or a anything other than literal characters. */ -#define REQ_CASELESS 0x0100 /* indicates caselessness */ -#define REQ_VARY 0x0200 /* reqbyte followed non-literal item */ +#define REQ_CASELESS 0x0100 /* indicates caselessness */ +#define REQ_VARY 0x0200 /* reqbyte followed non-literal item */ /* Miscellaneous definitions */ @@ -257,14 +257,14 @@ enum { ESC_A = 1, ESC_G, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, /* Flag bits and data types for the extended class (OP_XCLASS) for classes that contain UTF-8 characters with values greater than 255. */ -#define XCL_NOT 0x01 /* Flag: this is a negative class */ -#define XCL_MAP 0x02 /* Flag: a 32-byte map is present */ +#define XCL_NOT 0x01 /* Flag: this is a negative class */ +#define XCL_MAP 0x02 /* Flag: a 32-byte map is present */ -#define XCL_END 0 /* Marks end of individual items */ -#define XCL_SINGLE 1 /* Single item (one multibyte char) follows */ -#define XCL_RANGE 2 /* A range (two multibyte chars) follows */ -#define XCL_PROP 3 /* Unicode property (one property code) follows */ -#define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */ +#define XCL_END 0 /* Marks end of individual items */ +#define XCL_SINGLE 1 /* Single item (one multibyte char) follows */ +#define XCL_RANGE 2 /* A range (two multibyte chars) follows */ +#define XCL_PROP 3 /* Unicode property (one property code) follows */ +#define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */ /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets @@ -274,115 +274,115 @@ Note that whenever this list is updated, the two macro definitions that follow must also be updated to match. */ enum { - OP_END, /* 0 End of pattern */ + OP_END, /* 0 End of pattern */ /* Values corresponding to backslashed metacharacters */ - OP_SOD, /* 1 Start of data: \A */ - OP_SOM, /* 2 Start of match (subject + offset): \G */ - OP_NOT_WORD_BOUNDARY, /* 3 \B */ - OP_WORD_BOUNDARY, /* 4 \b */ - OP_NOT_DIGIT, /* 5 \D */ - OP_DIGIT, /* 6 \d */ - OP_NOT_WHITESPACE, /* 7 \S */ - OP_WHITESPACE, /* 8 \s */ - OP_NOT_WORDCHAR, /* 9 \W */ - OP_WORDCHAR, /* 10 \w */ - OP_ANY, /* 11 Match any character */ - OP_ANYBYTE, /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */ - OP_NOTPROP, /* 13 \P (not Unicode property) */ - OP_PROP, /* 14 \p (Unicode property) */ - OP_EXTUNI, /* 15 \X (extended Unicode sequence */ - OP_EODN, /* 16 End of data or \n at end of data: \Z. */ - OP_EOD, /* 17 End of data: \z */ - - OP_OPT, /* 18 Set runtime options */ - OP_CIRC, /* 19 Start of line - varies with multiline switch */ - OP_DOLL, /* 20 End of line - varies with multiline switch */ - OP_CHAR, /* 21 Match one character, casefully */ - OP_CHARNC, /* 22 Match one character, caselessly */ - OP_NOT, /* 23 Match anything but the following char */ - - OP_STAR, /* 24 The maximizing and minimizing versions of */ - OP_MINSTAR, /* 25 all these opcodes must come in pairs, with */ - OP_PLUS, /* 26 the minimizing one second. */ - OP_MINPLUS, /* 27 This first set applies to single characters */ - OP_QUERY, /* 28 */ - OP_MINQUERY, /* 29 */ - OP_UPTO, /* 30 From 0 to n matches */ - OP_MINUPTO, /* 31 */ - OP_EXACT, /* 32 Exactly n matches */ - - OP_NOTSTAR, /* 33 The maximizing and minimizing versions of */ - OP_NOTMINSTAR, /* 34 all these opcodes must come in pairs, with */ - OP_NOTPLUS, /* 35 the minimizing one second. */ - OP_NOTMINPLUS, /* 36 This set applies to "not" single characters */ - OP_NOTQUERY, /* 37 */ - OP_NOTMINQUERY, /* 38 */ - OP_NOTUPTO, /* 39 From 0 to n matches */ - OP_NOTMINUPTO, /* 40 */ - OP_NOTEXACT, /* 41 Exactly n matches */ - - OP_TYPESTAR, /* 42 The maximizing and minimizing versions of */ - OP_TYPEMINSTAR, /* 43 all these opcodes must come in pairs, with */ - OP_TYPEPLUS, /* 44 the minimizing one second. These codes must */ - OP_TYPEMINPLUS, /* 45 be in exactly the same order as those above. */ - OP_TYPEQUERY, /* 46 This set applies to character types such as \d */ - OP_TYPEMINQUERY, /* 47 */ - OP_TYPEUPTO, /* 48 From 0 to n matches */ - OP_TYPEMINUPTO, /* 49 */ - OP_TYPEEXACT, /* 50 Exactly n matches */ - - OP_CRSTAR, /* 51 The maximizing and minimizing versions of */ - OP_CRMINSTAR, /* 52 all these opcodes must come in pairs, with */ - OP_CRPLUS, /* 53 the minimizing one second. These codes must */ - OP_CRMINPLUS, /* 54 be in exactly the same order as those above. */ - OP_CRQUERY, /* 55 These are for character classes and back refs */ - OP_CRMINQUERY, /* 56 */ - OP_CRRANGE, /* 57 These are different to the three sets above. */ - OP_CRMINRANGE, /* 58 */ - - OP_CLASS, /* 59 Match a character class, chars < 256 only */ - OP_NCLASS, /* 60 Same, but the bitmap was created from a negative - class - the difference is relevant only when a UTF-8 - character > 255 is encountered. */ - - OP_XCLASS, /* 61 Extended class for handling UTF-8 chars within the - class. This does both positive and negative. */ - - OP_REF, /* 62 Match a back reference */ - OP_RECURSE, /* 63 Match a numbered subpattern (possibly recursive) */ - OP_CALLOUT, /* 64 Call out to external function if provided */ - - OP_ALT, /* 65 Start of alternation */ - OP_KET, /* 66 End of group that doesn't have an unbounded repeat */ - OP_KETRMAX, /* 67 These two must remain together and in this */ - OP_KETRMIN, /* 68 order. They are for groups the repeat for ever. */ + OP_SOD, /* 1 Start of data: \A */ + OP_SOM, /* 2 Start of match (subject + offset): \G */ + OP_NOT_WORD_BOUNDARY, /* 3 \B */ + OP_WORD_BOUNDARY, /* 4 \b */ + OP_NOT_DIGIT, /* 5 \D */ + OP_DIGIT, /* 6 \d */ + OP_NOT_WHITESPACE, /* 7 \S */ + OP_WHITESPACE, /* 8 \s */ + OP_NOT_WORDCHAR, /* 9 \W */ + OP_WORDCHAR, /* 10 \w */ + OP_ANY, /* 11 Match any character */ + OP_ANYBYTE, /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */ + OP_NOTPROP, /* 13 \P (not Unicode property) */ + OP_PROP, /* 14 \p (Unicode property) */ + OP_EXTUNI, /* 15 \X (extended Unicode sequence */ + OP_EODN, /* 16 End of data or \n at end of data: \Z. */ + OP_EOD, /* 17 End of data: \z */ + + OP_OPT, /* 18 Set runtime options */ + OP_CIRC, /* 19 Start of line - varies with multiline switch */ + OP_DOLL, /* 20 End of line - varies with multiline switch */ + OP_CHAR, /* 21 Match one character, casefully */ + OP_CHARNC, /* 22 Match one character, caselessly */ + OP_NOT, /* 23 Match anything but the following char */ + + OP_STAR, /* 24 The maximizing and minimizing versions of */ + OP_MINSTAR, /* 25 all these opcodes must come in pairs, with */ + OP_PLUS, /* 26 the minimizing one second. */ + OP_MINPLUS, /* 27 This first set applies to single characters */ + OP_QUERY, /* 28 */ + OP_MINQUERY, /* 29 */ + OP_UPTO, /* 30 From 0 to n matches */ + OP_MINUPTO, /* 31 */ + OP_EXACT, /* 32 Exactly n matches */ + + OP_NOTSTAR, /* 33 The maximizing and minimizing versions of */ + OP_NOTMINSTAR, /* 34 all these opcodes must come in pairs, with */ + OP_NOTPLUS, /* 35 the minimizing one second. */ + OP_NOTMINPLUS, /* 36 This set applies to "not" single characters */ + OP_NOTQUERY, /* 37 */ + OP_NOTMINQUERY, /* 38 */ + OP_NOTUPTO, /* 39 From 0 to n matches */ + OP_NOTMINUPTO, /* 40 */ + OP_NOTEXACT, /* 41 Exactly n matches */ + + OP_TYPESTAR, /* 42 The maximizing and minimizing versions of */ + OP_TYPEMINSTAR, /* 43 all these opcodes must come in pairs, with */ + OP_TYPEPLUS, /* 44 the minimizing one second. These codes must */ + OP_TYPEMINPLUS, /* 45 be in exactly the same order as those above. */ + OP_TYPEQUERY, /* 46 This set applies to character types such as \d */ + OP_TYPEMINQUERY, /* 47 */ + OP_TYPEUPTO, /* 48 From 0 to n matches */ + OP_TYPEMINUPTO, /* 49 */ + OP_TYPEEXACT, /* 50 Exactly n matches */ + + OP_CRSTAR, /* 51 The maximizing and minimizing versions of */ + OP_CRMINSTAR, /* 52 all these opcodes must come in pairs, with */ + OP_CRPLUS, /* 53 the minimizing one second. These codes must */ + OP_CRMINPLUS, /* 54 be in exactly the same order as those above. */ + OP_CRQUERY, /* 55 These are for character classes and back refs */ + OP_CRMINQUERY, /* 56 */ + OP_CRRANGE, /* 57 These are different to the three sets above. */ + OP_CRMINRANGE, /* 58 */ + + OP_CLASS, /* 59 Match a character class, chars < 256 only */ + OP_NCLASS, /* 60 Same, but the bitmap was created from a negative + class - the difference is relevant only when a UTF-8 + character > 255 is encountered. */ + + OP_XCLASS, /* 61 Extended class for handling UTF-8 chars within the + class. This does both positive and negative. */ + + OP_REF, /* 62 Match a back reference */ + OP_RECURSE, /* 63 Match a numbered subpattern (possibly recursive) */ + OP_CALLOUT, /* 64 Call out to external function if provided */ + + OP_ALT, /* 65 Start of alternation */ + OP_KET, /* 66 End of group that doesn't have an unbounded repeat */ + OP_KETRMAX, /* 67 These two must remain together and in this */ + OP_KETRMIN, /* 68 order. They are for groups the repeat for ever. */ /* The assertions must come before ONCE and COND */ - OP_ASSERT, /* 69 Positive lookahead */ - OP_ASSERT_NOT, /* 70 Negative lookahead */ - OP_ASSERTBACK, /* 71 Positive lookbehind */ - OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */ - OP_REVERSE, /* 73 Move pointer back - used in lookbehind assertions */ + OP_ASSERT, /* 69 Positive lookahead */ + OP_ASSERT_NOT, /* 70 Negative lookahead */ + OP_ASSERTBACK, /* 71 Positive lookbehind */ + OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */ + OP_REVERSE, /* 73 Move pointer back - used in lookbehind assertions */ /* ONCE and COND must come after the assertions, with ONCE first, as there's a test for >= ONCE for a subpattern that isn't an assertion. */ - OP_ONCE, /* 74 Once matched, don't back up into the subpattern */ - OP_COND, /* 75 Conditional group */ - OP_CREF, /* 76 Used to hold an extraction string number (cond ref) */ + OP_ONCE, /* 74 Once matched, don't back up into the subpattern */ + OP_COND, /* 75 Conditional group */ + OP_CREF, /* 76 Used to hold an extraction string number (cond ref) */ - OP_BRAZERO, /* 77 These two must remain together and in this */ - OP_BRAMINZERO, /* 78 order. */ + OP_BRAZERO, /* 77 These two must remain together and in this */ + OP_BRAMINZERO, /* 78 order. */ - OP_BRANUMBER, /* 79 Used for extracting brackets whose number is greater - than can fit into an opcode. */ + OP_BRANUMBER, /* 79 Used for extracting brackets whose number is greater + than can fit into an opcode. */ - OP_BRA /* 80 This and greater values are used for brackets that - extract substrings up to EXTRACT_BASIC_MAX. After - that, use is made of OP_BRANUMBER. */ + OP_BRA /* 80 This and greater values are used for brackets that + extract substrings up to EXTRACT_BASIC_MAX. After + that, use is made of OP_BRANUMBER. */ }; /* WARNING WARNING WARNING: There is an implicit assumption in pcre.c and @@ -503,28 +503,28 @@ NOTE NOTE NOTE: typedef struct real_pcre { pcre_uint32 magic_number; - pcre_uint32 size; /* Total that was malloced */ + pcre_uint32 size; /* Total that was malloced */ pcre_uint32 options; - pcre_uint32 dummy1; /* For future use, maybe */ + pcre_uint32 dummy1; /* For future use, maybe */ pcre_uint16 top_bracket; pcre_uint16 top_backref; pcre_uint16 first_byte; pcre_uint16 req_byte; - pcre_uint16 name_table_offset; /* Offset to name table that follows */ - pcre_uint16 name_entry_size; /* Size of any name items */ - pcre_uint16 name_count; /* Number of name items */ - pcre_uint16 ref_count; /* Reference count */ + pcre_uint16 name_table_offset; /* Offset to name table that follows */ + pcre_uint16 name_entry_size; /* Size of any name items */ + pcre_uint16 name_count; /* Number of name items */ + pcre_uint16 ref_count; /* Reference count */ - const unsigned char *tables; /* Pointer to tables or NULL for std */ - const unsigned char *nullpad; /* NULL padding */ + const unsigned char *tables; /* Pointer to tables or NULL for std */ + const unsigned char *nullpad; /* NULL padding */ } real_pcre; /* The format of the block used to store data from pcre_study(). The same remark (see NOTE above) about extending this structure applies. */ typedef struct pcre_study_data { - pcre_uint32 size; /* Total that was malloced */ + pcre_uint32 size; /* Total that was malloced */ pcre_uint32 options; uschar start_bits[32]; } pcre_study_data; @@ -533,19 +533,19 @@ typedef struct pcre_study_data { doing the compiling, so that they are thread-safe. */ typedef struct compile_data { - const uschar *lcc; /* Points to lower casing table */ - const uschar *fcc; /* Points to case-flipping table */ - const uschar *cbits; /* Points to character type table */ - const uschar *ctypes; /* Points to table of type maps */ - const uschar *start_code; /* The start of the compiled code */ - const uschar *start_pattern; /* The start of the pattern */ - uschar *name_table; /* The name/number table */ - int names_found; /* Number of entries so far */ - int name_entry_size; /* Size of each entry */ - int top_backref; /* Maximum back reference */ - unsigned int backref_map; /* Bitmap of low back refs */ - int req_varyopt; /* "After variable item" flag for reqbyte */ - BOOL nopartial; /* Set TRUE if partial won't work */ + const uschar *lcc; /* Points to lower casing table */ + const uschar *fcc; /* Points to case-flipping table */ + const uschar *cbits; /* Points to character type table */ + const uschar *ctypes; /* Points to table of type maps */ + const uschar *start_code; /* The start of the compiled code */ + const uschar *start_pattern; /* The start of the pattern */ + uschar *name_table; /* The name/number table */ + int names_found; /* Number of entries so far */ + int name_entry_size; /* Size of each entry */ + int top_backref; /* Maximum back reference */ + unsigned int backref_map; /* Bitmap of low back refs */ + int req_varyopt; /* "After variable item" flag for reqbyte */ + BOOL nopartial; /* Set TRUE if partial won't work */ } compile_data; /* Structure for maintaining a chain of pointers to the currently incomplete @@ -560,12 +560,12 @@ typedef struct branch_chain { call within the pattern. */ typedef struct recursion_info { - struct recursion_info *prevrec; /* Previous recursion record (or NULL) */ - int group_num; /* Number of group that was called */ - const uschar *after_call; /* "Return value": points after the call in the expr */ - const uschar *save_start; /* Old value of md->start_match */ - int *offset_save; /* Pointer to start of saved offsets */ - int saved_max; /* Number of saved offsets */ + struct recursion_info *prevrec; /* Previous recursion record (or NULL) */ + int group_num; /* Number of group that was called */ + const uschar *after_call; /* "Return value": points after the call in the expr */ + const uschar *save_start; /* Old value of md->start_match */ + int *offset_save; /* Pointer to start of saved offsets */ + int saved_max; /* Number of saved offsets */ } recursion_info; /* When compiling in a mode that doesn't use recursive calls to match(), @@ -582,45 +582,45 @@ struct heapframe; doing traditional NFA matching, so that they are thread-safe. */ typedef struct match_data { - unsigned long int match_call_count; /* As it says */ - unsigned long int match_limit; /* As it says */ - int *offset_vector; /* Offset vector */ - int offset_end; /* One past the end */ - int offset_max; /* The maximum usable for return data */ - const uschar *lcc; /* Points to lower casing table */ - const uschar *ctypes; /* Points to table of type maps */ - BOOL offset_overflow; /* Set if too many extractions */ - BOOL notbol; /* NOTBOL flag */ - BOOL noteol; /* NOTEOL flag */ - BOOL utf8; /* UTF8 flag */ - BOOL endonly; /* Dollar not before final \n */ - BOOL notempty; /* Empty string match not wanted */ - BOOL partial; /* PARTIAL flag */ - BOOL hitend; /* Hit the end of the subject at some point */ - const uschar *start_code; /* For use when recursing */ - const uschar *start_subject; /* Start of the subject string */ - const uschar *end_subject; /* End of the subject string */ - const uschar *start_match; /* Start of this match attempt */ - const uschar *end_match_ptr; /* Subject position at end match */ - int end_offset_top; /* Highwater mark at end of match */ - int capture_last; /* Most recent capture number */ - int start_offset; /* The start offset value */ - recursion_info *recursive; /* Linked list of recursion data */ - void *callout_data; /* To pass back to callouts */ - struct heapframe *thisframe; /* Used only when compiling for no recursion */ + unsigned long int match_call_count; /* As it says */ + unsigned long int match_limit; /* As it says */ + int *offset_vector; /* Offset vector */ + int offset_end; /* One past the end */ + int offset_max; /* The maximum usable for return data */ + const uschar *lcc; /* Points to lower casing table */ + const uschar *ctypes; /* Points to table of type maps */ + BOOL offset_overflow; /* Set if too many extractions */ + BOOL notbol; /* NOTBOL flag */ + BOOL noteol; /* NOTEOL flag */ + BOOL utf8; /* UTF8 flag */ + BOOL endonly; /* Dollar not before final \n */ + BOOL notempty; /* Empty string match not wanted */ + BOOL partial; /* PARTIAL flag */ + BOOL hitend; /* Hit the end of the subject at some point */ + const uschar *start_code; /* For use when recursing */ + const uschar *start_subject; /* Start of the subject string */ + const uschar *end_subject; /* End of the subject string */ + const uschar *start_match; /* Start of this match attempt */ + const uschar *end_match_ptr; /* Subject position at end match */ + int end_offset_top; /* Highwater mark at end of match */ + int capture_last; /* Most recent capture number */ + int start_offset; /* The start offset value */ + recursion_info *recursive; /* Linked list of recursion data */ + void *callout_data; /* To pass back to callouts */ + struct heapframe *thisframe; /* Used only when compiling for no recursion */ } match_data; /* A similar structure is used for the same purpose by the DFA matching functions. */ typedef struct dfa_match_data { - const uschar *start_code; /* Start of the compiled pattern */ - const uschar *start_subject; /* Start of the subject string */ - const uschar *end_subject; /* End of subject string */ - const uschar *tables; /* Character tables */ - int moptions; /* Match options */ - int poptions; /* Pattern options */ - void *callout_data; /* To pass back to callouts */ + const uschar *start_code; /* Start of the compiled pattern */ + const uschar *start_subject; /* Start of the subject string */ + const uschar *end_subject; /* End of subject string */ + const uschar *tables; /* Character tables */ + int moptions; /* Match options */ + int poptions; /* Pattern options */ + void *callout_data; /* To pass back to callouts */ } dfa_match_data; /* Bit definitions for entries in the pcre_ctypes table. */ @@ -629,23 +629,23 @@ typedef struct dfa_match_data { #define ctype_letter 0x02 #define ctype_digit 0x04 #define ctype_xdigit 0x08 -#define ctype_word 0x10 /* alphameric or '_' */ -#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ +#define ctype_word 0x10 /* alphameric or '_' */ +#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set of bits for a class map. Some classes are built by combining these tables. */ -#define cbit_space 0 /* [:space:] or \s */ -#define cbit_xdigit 32 /* [:xdigit:] */ -#define cbit_digit 64 /* [:digit:] or \d */ -#define cbit_upper 96 /* [:upper:] */ -#define cbit_lower 128 /* [:lower:] */ -#define cbit_word 160 /* [:word:] or \w */ -#define cbit_graph 192 /* [:graph:] */ -#define cbit_print 224 /* [:print:] */ -#define cbit_punct 256 /* [:punct:] */ -#define cbit_cntrl 288 /* [:cntrl:] */ -#define cbit_length 320 /* Length of the cbits table */ +#define cbit_space 0 /* [:space:] or \s */ +#define cbit_xdigit 32 /* [:xdigit:] */ +#define cbit_digit 64 /* [:digit:] or \d */ +#define cbit_upper 96 /* [:upper:] */ +#define cbit_lower 128 /* [:lower:] */ +#define cbit_word 160 /* [:word:] or \w */ +#define cbit_graph 192 /* [:graph:] */ +#define cbit_print 224 /* [:print:] */ +#define cbit_punct 256 /* [:punct:] */ +#define cbit_cntrl 288 /* [:cntrl:] */ +#define cbit_length 320 /* Length of the cbits table */ /* Offsets of the various tables from the base tables pointer, and total length. */ @@ -818,39 +818,39 @@ print, punct, and cntrl. Other classes are built from combinations. */ 0x80 regular expression metacharacter or binary zero */ - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0- 7 */ - 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, /* 8- 15 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16- 23 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ - 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* - ' */ - 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, /* ( - / */ - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, /* 0 - 7 */ - 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 8 - ? */ - 0x00, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* @ - G */ - 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* H - O */ - 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* P - W */ - 0x12, 0x12, 0x12, 0x80, 0x00, 0x00, 0x80, 0x10, /* X - _ */ - 0x00, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* ` - g */ - 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* h - o */ - 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* p - w */ - 0x12, 0x12, 0x12, 0x80, 0x80, 0x00, 0x00, 0x00, /* x -127 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128-135 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 136-143 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 144-151 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 152-159 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 160-167 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 168-175 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 176-183 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 192-199 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 200-207 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 208-215 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 216-223 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 224-231 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 232-239 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 240-247 */ + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0- 7 */ + 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, /* 8- 15 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16- 23 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ + 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* - ' */ + 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, /* ( - / */ + 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, /* 0 - 7 */ + 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 8 - ? */ + 0x00, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* @ - G */ + 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* H - O */ + 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* P - W */ + 0x12, 0x12, 0x12, 0x80, 0x00, 0x00, 0x80, 0x10, /* X - _ */ + 0x00, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* ` - g */ + 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* h - o */ + 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* p - w */ + 0x12, 0x12, 0x12, 0x80, 0x80, 0x00, 0x00, 0x00, /* x -127 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128-135 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 136-143 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 144-151 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 152-159 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 160-167 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 168-175 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 176-183 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 192-199 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 200-207 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 208-215 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 216-223 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 224-231 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 232-239 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 240-247 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; /* 248-255 */ +}; /* 248-255 */ /* End of chartables.c */ @@ -929,18 +929,18 @@ Returns: the new block if is is indeed a byte-flipped regex */ real_pcre *_pcre_try_flipped(const real_pcre * re, real_pcre * internal_re, - const pcre_study_data * study, - pcre_study_data * internal_study); + const pcre_study_data * study, + pcre_study_data * internal_study); real_pcre * _pcre_try_flipped(const real_pcre * re, real_pcre * internal_re, - const pcre_study_data * study, - pcre_study_data * internal_study) + const pcre_study_data * study, + pcre_study_data * internal_study) { if (byteflip(re->magic_number, sizeof(re->magic_number)) != MAGIC_NUMBER) return NULL; - *internal_re = *re; /* To copy other fields */ + *internal_re = *re; /* To copy other fields */ internal_re->size = byteflip(re->size, sizeof(re->size)); internal_re->options = byteflip(re->options, sizeof(re->options)); internal_re->top_bracket = @@ -953,14 +953,14 @@ _pcre_try_flipped(const real_pcre * re, real_pcre * internal_re, (pcre_uint16) byteflip(re->req_byte, sizeof(re->req_byte)); internal_re->name_table_offset = (pcre_uint16) byteflip(re->name_table_offset, - sizeof(re->name_table_offset)); + sizeof(re->name_table_offset)); internal_re->name_entry_size = (pcre_uint16) byteflip(re->name_entry_size, sizeof(re->name_entry_size)); internal_re->name_count = (pcre_uint16) byteflip(re->name_count, sizeof(re->name_count)); if (study != NULL) { - *internal_study = *study; /* To copy other fields */ + *internal_study = *study; /* To copy other fields */ internal_study->size = byteflip(study->size, sizeof(study->size)); internal_study->options = byteflip(study->options, sizeof(study->options)); } @@ -996,7 +996,7 @@ Returns: 0 if data returned, negative on error int pcre_fullinfo(const pcre * argument_re, const pcre_extra * extra_data, int what, - void *where) + void *where) { real_pcre internal_re; pcre_study_data internal_study; @@ -1171,7 +1171,7 @@ Returns: if successful: int pcre_copy_substring(const char *subject, int *ovector, int stringcount, - int stringnumber, char *buffer, int size) + int stringnumber, char *buffer, int size) { int yield; if (stringnumber < 0 || stringnumber >= stringcount) @@ -1216,8 +1216,8 @@ Returns: if successful: int pcre_copy_named_substring(const pcre * code, const char *subject, int *ovector, - int stringcount, const char *stringname, char *buffer, - int size) + int stringcount, const char *stringname, char *buffer, + int size) { int n = pcre_get_stringnumber(code, stringname); if (n <= 0) @@ -1250,11 +1250,11 @@ Returns: if successful: 0 int pcre_get_substring_list(const char *subject, int *ovector, int stringcount, - const char ***listptr); + const char ***listptr); int pcre_get_substring_list(const char *subject, int *ovector, int stringcount, - const char ***listptr) + const char ***listptr) { int i; int size = sizeof(char *); @@ -1334,11 +1334,11 @@ Returns: if successful: int pcre_get_substring(const char *subject, int *ovector, int stringcount, - int stringnumber, const char **stringptr); + int stringnumber, const char **stringptr); int pcre_get_substring(const char *subject, int *ovector, int stringcount, - int stringnumber, const char **stringptr) + int stringnumber, const char **stringptr) { int yield; char *substring; @@ -1385,13 +1385,13 @@ Returns: if successful: int pcre_get_named_substring(const pcre * code, const char *subject, int *ovector, - int stringcount, const char *stringname, - const char **stringptr); + int stringcount, const char *stringname, + const char **stringptr); int pcre_get_named_substring(const pcre * code, const char *subject, int *ovector, - int stringcount, const char *stringname, - const char **stringptr) + int stringcount, const char *stringname, + const char **stringptr) { int n = pcre_get_stringnumber(code, stringname); if (n <= 0) @@ -1590,7 +1590,7 @@ Returns: TRUE if table built, FALSE otherwise static BOOL set_start_bits(const uschar * code, uschar * start_bits, BOOL caseless, - BOOL utf8, compile_data * cd) + BOOL utf8, compile_data * cd) { register int c; @@ -1611,261 +1611,261 @@ the pcre module can use all the optimization it can get). */ recurse to set bits from within them. That's all for this branch. */ if ((int) *tcode >= OP_BRA || *tcode == OP_ASSERT) { - if (!set_start_bits(tcode, start_bits, caseless, utf8, cd)) - return FALSE; - try_next = FALSE; + if (!set_start_bits(tcode, start_bits, caseless, utf8, cd)) + return FALSE; + try_next = FALSE; } else - switch (*tcode) { - default: - return FALSE; - - /* Skip over callout */ - - case OP_CALLOUT: - tcode += 2 + 2 * LINK_SIZE; - break; - - /* Skip over extended extraction bracket number */ - - case OP_BRANUMBER: - tcode += 3; - break; - - /* Skip over lookbehind and negative lookahead assertions */ - - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - do - tcode += GET(tcode, 1); - while (*tcode == OP_ALT); - tcode += 1 + LINK_SIZE; - break; - - /* Skip over an option setting, changing the caseless flag */ - - case OP_OPT: - caseless = (tcode[1] & PCRE_CASELESS) != 0; - tcode += 2; - break; - - /* BRAZERO does the bracket, but carries on. */ - - case OP_BRAZERO: - case OP_BRAMINZERO: - if (!set_start_bits(++tcode, start_bits, caseless, utf8, cd)) - return FALSE; - dummy = 1; - do - tcode += GET(tcode, 1); - while (*tcode == OP_ALT); - tcode += 1 + LINK_SIZE; - break; - - /* Single-char * or ? sets the bit and tries the next item */ - - case OP_STAR: - case OP_MINSTAR: - case OP_QUERY: - case OP_MINQUERY: - set_bit(start_bits, tcode[1], caseless, cd); - tcode += 2; - break; - - /* Single-char upto sets the bit and tries the next */ - - case OP_UPTO: - case OP_MINUPTO: - set_bit(start_bits, tcode[3], caseless, cd); - tcode += 4; - break; - - /* At least one single char sets the bit and stops */ - - case OP_EXACT: /* Fall through */ - tcode += 2; - - case OP_CHAR: - case OP_CHARNC: - case OP_PLUS: - case OP_MINPLUS: - set_bit(start_bits, tcode[1], caseless, cd); - try_next = FALSE; - break; - - /* Single character type sets the bits and stops */ - - case OP_NOT_DIGIT: - for (c = 0; c < 32; c++) - start_bits[c] |= ~cd->cbits[c + cbit_digit]; - try_next = FALSE; - break; - - case OP_DIGIT: - for (c = 0; c < 32; c++) - start_bits[c] |= cd->cbits[c + cbit_digit]; - try_next = FALSE; - break; - - case OP_NOT_WHITESPACE: - for (c = 0; c < 32; c++) - start_bits[c] |= ~cd->cbits[c + cbit_space]; - try_next = FALSE; - break; - - case OP_WHITESPACE: - for (c = 0; c < 32; c++) - start_bits[c] |= cd->cbits[c + cbit_space]; - try_next = FALSE; - break; - - case OP_NOT_WORDCHAR: - for (c = 0; c < 32; c++) - start_bits[c] |= ~cd->cbits[c + cbit_word]; - try_next = FALSE; - break; - - case OP_WORDCHAR: - for (c = 0; c < 32; c++) - start_bits[c] |= cd->cbits[c + cbit_word]; - try_next = FALSE; - break; - - /* One or more character type fudges the pointer and restarts, knowing - it will hit a single character type and stop there. */ - - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - tcode++; - break; - - case OP_TYPEEXACT: - tcode += 3; - break; - - /* Zero or more repeats of character types set the bits and then - try again. */ - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - tcode += 2; /* Fall through */ - - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - switch (tcode[1]) { - case OP_ANY: - return FALSE; - - case OP_NOT_DIGIT: - for (c = 0; c < 32; c++) - start_bits[c] |= ~cd->cbits[c + cbit_digit]; - break; - - case OP_DIGIT: - for (c = 0; c < 32; c++) - start_bits[c] |= cd->cbits[c + cbit_digit]; - break; - - case OP_NOT_WHITESPACE: - for (c = 0; c < 32; c++) - start_bits[c] |= ~cd->cbits[c + cbit_space]; - break; - - case OP_WHITESPACE: - for (c = 0; c < 32; c++) - start_bits[c] |= cd->cbits[c + cbit_space]; - break; - - case OP_NOT_WORDCHAR: - for (c = 0; c < 32; c++) - start_bits[c] |= ~cd->cbits[c + cbit_word]; - break; - - case OP_WORDCHAR: - for (c = 0; c < 32; c++) - start_bits[c] |= cd->cbits[c + cbit_word]; - break; - } - - tcode += 2; - break; - - /* Character class where all the information is in a bit map: set the - bits and either carry on or not, according to the repeat count. If it was - a negative class, and we are operating with UTF-8 characters, any byte - with a value >= 0xc4 is a potentially valid starter because it starts a - character with a value > 255. */ - - case OP_NCLASS: - if (utf8) { - start_bits[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ - memset(start_bits + 25, 0xff, 7); /* Bits for 0xc9 - 0xff */ - } - /* Fall through */ - - case OP_CLASS: - { - tcode++; - - /* In UTF-8 mode, the bits in a bit map correspond to character - values, not to byte values. However, the bit map we are constructing is - for byte values. So we have to do a conversion for characters whose - value is > 127. In fact, there are only two possible starting bytes for - characters in the range 128 - 255. */ - - if (utf8) { - for (c = 0; c < 16; c++) - start_bits[c] |= tcode[c]; - for (c = 128; c < 256; c++) { - if ((tcode[c / 8] && (1 << (c & 7))) != 0) { - int d = (c >> 6) | 0xc0; /* Set bit for this starter */ - start_bits[d / 8] |= (1 << (d & 7)); /* and then skip on to the */ - c = (c & 0xc0) + 0x40 - 1; /* next relevant character. */ - } - } - } - - /* In non-UTF-8 mode, the two bit maps are completely compatible. */ - - else { - for (c = 0; c < 32; c++) - start_bits[c] |= tcode[c]; - } - - /* Advance past the bit map, and act on what follows */ - - tcode += 32; - switch (*tcode) { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRQUERY: - case OP_CRMINQUERY: - tcode++; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - if (((tcode[1] << 8) + tcode[2]) == 0) - tcode += 5; - else - try_next = FALSE; - break; - - default: - try_next = FALSE; - break; - } - } - break; /* End of bitmap class handling */ - - } /* End of switch */ - } /* End of try_next loop */ - - code += GET(code, 1); /* Advance to next branch */ + switch (*tcode) { + default: + return FALSE; + + /* Skip over callout */ + + case OP_CALLOUT: + tcode += 2 + 2 * LINK_SIZE; + break; + + /* Skip over extended extraction bracket number */ + + case OP_BRANUMBER: + tcode += 3; + break; + + /* Skip over lookbehind and negative lookahead assertions */ + + case OP_ASSERT_NOT: + case OP_ASSERTBACK: + case OP_ASSERTBACK_NOT: + do + tcode += GET(tcode, 1); + while (*tcode == OP_ALT); + tcode += 1 + LINK_SIZE; + break; + + /* Skip over an option setting, changing the caseless flag */ + + case OP_OPT: + caseless = (tcode[1] & PCRE_CASELESS) != 0; + tcode += 2; + break; + + /* BRAZERO does the bracket, but carries on. */ + + case OP_BRAZERO: + case OP_BRAMINZERO: + if (!set_start_bits(++tcode, start_bits, caseless, utf8, cd)) + return FALSE; + dummy = 1; + do + tcode += GET(tcode, 1); + while (*tcode == OP_ALT); + tcode += 1 + LINK_SIZE; + break; + + /* Single-char * or ? sets the bit and tries the next item */ + + case OP_STAR: + case OP_MINSTAR: + case OP_QUERY: + case OP_MINQUERY: + set_bit(start_bits, tcode[1], caseless, cd); + tcode += 2; + break; + + /* Single-char upto sets the bit and tries the next */ + + case OP_UPTO: + case OP_MINUPTO: + set_bit(start_bits, tcode[3], caseless, cd); + tcode += 4; + break; + + /* At least one single char sets the bit and stops */ + + case OP_EXACT: /* Fall through */ + tcode += 2; + + case OP_CHAR: + case OP_CHARNC: + case OP_PLUS: + case OP_MINPLUS: + set_bit(start_bits, tcode[1], caseless, cd); + try_next = FALSE; + break; + + /* Single character type sets the bits and stops */ + + case OP_NOT_DIGIT: + for (c = 0; c < 32; c++) + start_bits[c] |= ~cd->cbits[c + cbit_digit]; + try_next = FALSE; + break; + + case OP_DIGIT: + for (c = 0; c < 32; c++) + start_bits[c] |= cd->cbits[c + cbit_digit]; + try_next = FALSE; + break; + + case OP_NOT_WHITESPACE: + for (c = 0; c < 32; c++) + start_bits[c] |= ~cd->cbits[c + cbit_space]; + try_next = FALSE; + break; + + case OP_WHITESPACE: + for (c = 0; c < 32; c++) + start_bits[c] |= cd->cbits[c + cbit_space]; + try_next = FALSE; + break; + + case OP_NOT_WORDCHAR: + for (c = 0; c < 32; c++) + start_bits[c] |= ~cd->cbits[c + cbit_word]; + try_next = FALSE; + break; + + case OP_WORDCHAR: + for (c = 0; c < 32; c++) + start_bits[c] |= cd->cbits[c + cbit_word]; + try_next = FALSE; + break; + + /* One or more character type fudges the pointer and restarts, knowing + it will hit a single character type and stop there. */ + + case OP_TYPEPLUS: + case OP_TYPEMINPLUS: + tcode++; + break; + + case OP_TYPEEXACT: + tcode += 3; + break; + + /* Zero or more repeats of character types set the bits and then + try again. */ + + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + tcode += 2; /* Fall through */ + + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + switch (tcode[1]) { + case OP_ANY: + return FALSE; + + case OP_NOT_DIGIT: + for (c = 0; c < 32; c++) + start_bits[c] |= ~cd->cbits[c + cbit_digit]; + break; + + case OP_DIGIT: + for (c = 0; c < 32; c++) + start_bits[c] |= cd->cbits[c + cbit_digit]; + break; + + case OP_NOT_WHITESPACE: + for (c = 0; c < 32; c++) + start_bits[c] |= ~cd->cbits[c + cbit_space]; + break; + + case OP_WHITESPACE: + for (c = 0; c < 32; c++) + start_bits[c] |= cd->cbits[c + cbit_space]; + break; + + case OP_NOT_WORDCHAR: + for (c = 0; c < 32; c++) + start_bits[c] |= ~cd->cbits[c + cbit_word]; + break; + + case OP_WORDCHAR: + for (c = 0; c < 32; c++) + start_bits[c] |= cd->cbits[c + cbit_word]; + break; + } + + tcode += 2; + break; + + /* Character class where all the information is in a bit map: set the + bits and either carry on or not, according to the repeat count. If it was + a negative class, and we are operating with UTF-8 characters, any byte + with a value >= 0xc4 is a potentially valid starter because it starts a + character with a value > 255. */ + + case OP_NCLASS: + if (utf8) { + start_bits[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ + memset(start_bits + 25, 0xff, 7); /* Bits for 0xc9 - 0xff */ + } + /* Fall through */ + + case OP_CLASS: + { + tcode++; + + /* In UTF-8 mode, the bits in a bit map correspond to character + values, not to byte values. However, the bit map we are constructing is + for byte values. So we have to do a conversion for characters whose + value is > 127. In fact, there are only two possible starting bytes for + characters in the range 128 - 255. */ + + if (utf8) { + for (c = 0; c < 16; c++) + start_bits[c] |= tcode[c]; + for (c = 128; c < 256; c++) { + if ((tcode[c / 8] && (1 << (c & 7))) != 0) { + int d = (c >> 6) | 0xc0; /* Set bit for this starter */ + start_bits[d / 8] |= (1 << (d & 7)); /* and then skip on to the */ + c = (c & 0xc0) + 0x40 - 1; /* next relevant character. */ + } + } + } + + /* In non-UTF-8 mode, the two bit maps are completely compatible. */ + + else { + for (c = 0; c < 32; c++) + start_bits[c] |= tcode[c]; + } + + /* Advance past the bit map, and act on what follows */ + + tcode += 32; + switch (*tcode) { + case OP_CRSTAR: + case OP_CRMINSTAR: + case OP_CRQUERY: + case OP_CRMINQUERY: + tcode++; + break; + + case OP_CRRANGE: + case OP_CRMINRANGE: + if (((tcode[1] << 8) + tcode[2]) == 0) + tcode += 5; + else + try_next = FALSE; + break; + + default: + try_next = FALSE; + break; + } + } + break; /* End of bitmap class handling */ + + } /* End of switch */ + } /* End of try_next loop */ + + code += GET(code, 1); /* Advance to next branch */ } while (*code == OP_ALT); return TRUE; @@ -1928,7 +1928,7 @@ at present. */ tables = re->tables; if (tables == NULL) (void) pcre_fullinfo(external_re, NULL, PCRE_INFO_DEFAULT_TABLES, - (void *) (&tables)); + (void *) (&tables)); compile_block.lcc = tables + lcc_offset; compile_block.fcc = tables + fcc_offset; @@ -1939,7 +1939,7 @@ at present. */ memset(start_bits, 0, 32 * sizeof(uschar)); if (!set_start_bits(code, start_bits, (re->options & PCRE_CASELESS) != 0, - (re->options & PCRE_UTF8) != 0, &compile_block)) + (re->options & PCRE_UTF8) != 0, &compile_block)) return NULL; /* Get a pcre_extra block and a pcre_study_data block. The study data is put in @@ -1994,21 +1994,21 @@ are simple data values; negative values are for special things like \d and so on. Zero means further processing is needed (for things like \x), or the escape is invalid. */ -#if !EBCDIC /* This is the "normal" table for ASCII systems */ +#if !EBCDIC /* This is the "normal" table for ASCII systems */ static const short int escapes[] = { - 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 7 */ - 0, 0, ':', ';', '<', '=', '>', '?', /* 8 - ? */ - '@', -ESC_A, -ESC_B, -ESC_C, -ESC_D, -ESC_E, 0, -ESC_G, /* @ - G */ - 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ - -ESC_P, -ESC_Q, 0, -ESC_S, 0, 0, 0, -ESC_W, /* P - W */ - -ESC_X, 0, -ESC_Z, '[', '\\', ']', '^', '_', /* X - _ */ - '`', 7, -ESC_b, 0, -ESC_d, ESC_e, ESC_f, 0, /* ` - g */ - 0, 0, 0, 0, 0, 0, ESC_n, 0, /* h - o */ - -ESC_p, 0, ESC_r, -ESC_s, ESC_tee, 0, 0, -ESC_w, /* p - w */ - 0, 0, -ESC_z /* x - z */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 7 */ + 0, 0, ':', ';', '<', '=', '>', '?', /* 8 - ? */ + '@', -ESC_A, -ESC_B, -ESC_C, -ESC_D, -ESC_E, 0, -ESC_G, /* @ - G */ + 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ + -ESC_P, -ESC_Q, 0, -ESC_S, 0, 0, 0, -ESC_W, /* P - W */ + -ESC_X, 0, -ESC_Z, '[', '\\', ']', '^', '_', /* X - _ */ + '`', 7, -ESC_b, 0, -ESC_d, ESC_e, ESC_f, 0, /* ` - g */ + 0, 0, 0, 0, 0, 0, ESC_n, 0, /* h - o */ + -ESC_p, 0, ESC_r, -ESC_s, ESC_tee, 0, 0, -ESC_w, /* p - w */ + 0, 0, -ESC_z /* x - z */ }; -#else /* This is the "abnormal" table for EBCDIC systems */ +#else /* This is the "abnormal" table for EBCDIC systems */ static const short int escapes[] = { /* 48 */ 0, 0, 0, '.', '<', '(', '+', '|', /* 50 */ '&', 0, 0, 0, 0, 0, 0, 0, @@ -2056,20 +2056,20 @@ to form the class. The table for [:blank:] is dynamically modified to remove the vertical space characters. */ static const int posix_class_maps[] = { - cbit_lower, cbit_upper, -1, /* alpha */ - cbit_lower, -1, -1, /* lower */ - cbit_upper, -1, -1, /* upper */ - cbit_digit, cbit_lower, cbit_upper, /* alnum */ - cbit_print, cbit_cntrl, -1, /* ascii */ - cbit_space, -1, -1, /* blank - a GNU extension */ - cbit_cntrl, -1, -1, /* cntrl */ - cbit_digit, -1, -1, /* digit */ - cbit_graph, -1, -1, /* graph */ - cbit_print, -1, -1, /* print */ - cbit_punct, -1, -1, /* punct */ - cbit_space, -1, -1, /* space */ - cbit_word, -1, -1, /* word - a Perl extension */ - cbit_xdigit, -1, -1 /* xdigit */ + cbit_lower, cbit_upper, -1, /* alpha */ + cbit_lower, -1, -1, /* lower */ + cbit_upper, -1, -1, /* upper */ + cbit_digit, cbit_lower, cbit_upper, /* alnum */ + cbit_print, cbit_cntrl, -1, /* ascii */ + cbit_space, -1, -1, /* blank - a GNU extension */ + cbit_cntrl, -1, -1, /* cntrl */ + cbit_digit, -1, -1, /* digit */ + cbit_graph, -1, -1, /* graph */ + cbit_print, -1, -1, /* print */ + cbit_punct, -1, -1, /* punct */ + cbit_space, -1, -1, /* space */ + cbit_word, -1, -1, /* word - a Perl extension */ + cbit_xdigit, -1, -1 /* xdigit */ }; @@ -2153,112 +2153,112 @@ For convenience, we use the same bit definitions as in chartables: Then we can use ctype_digit and ctype_xdigit in the code. */ -#if !EBCDIC /* This is the "normal" case, for ASCII systems */ +#if !EBCDIC /* This is the "normal" case, for ASCII systems */ static const unsigned char digitab[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0- 7 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8- 15 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16- 23 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - ' */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ( - / */ - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 0 - 7 */ - 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 - ? */ - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* @ - G */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* H - O */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* P - W */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X - _ */ - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* ` - g */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* h - o */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p - w */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x -127 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128-135 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 136-143 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 144-151 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 152-159 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 160-167 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 168-175 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 176-183 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 192-199 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 200-207 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 208-215 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 216-223 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 224-231 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 232-239 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 240-247 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0- 7 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8- 15 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16- 23 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - ' */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ( - / */ + 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 0 - 7 */ + 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8 - ? */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* @ - G */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* H - O */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* P - W */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X - _ */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* ` - g */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* h - o */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* p - w */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* x -127 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128-135 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 136-143 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 144-151 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 152-159 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 160-167 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 168-175 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 176-183 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 192-199 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 200-207 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 208-215 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 216-223 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 224-231 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 232-239 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 240-247 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; /* 248-255 */ +}; /* 248-255 */ -#else /* This is the "abnormal" case, for EBCDIC systems */ +#else /* This is the "abnormal" case, for EBCDIC systems */ static const unsigned char digitab[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0- 7 0 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8- 15 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16- 23 10 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 32- 39 20 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40- 47 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 48- 55 30 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56- 63 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - 71 40 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 72- | */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* & - 87 50 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 88- ¬ */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - -103 60 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 104- ? */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 112-119 70 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 120- " */ - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* 128- g 80 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* h -143 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 144- p 90 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* q -159 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 160- x A0 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* y -175 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^ -183 B0 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ - 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* { - G C0 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* H -207 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* } - P D0 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Q -223 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* \ - X E0 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y -239 */ - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 0 - 7 F0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0- 7 0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8- 15 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16- 23 10 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 32- 39 20 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40- 47 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 48- 55 30 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56- 63 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - 71 40 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 72- | */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* & - 87 50 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 88- ¬ */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - -103 60 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 104- ? */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 112-119 70 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 120- " */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* 128- g 80 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* h -143 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 144- p 90 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* q -159 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 160- x A0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* y -175 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^ -183 B0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /* { - G C0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* H -207 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* } - P D0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Q -223 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* \ - X E0 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y -239 */ + 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 0 - 7 F0 */ 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; /* 8 -255 */ - -static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */ - 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* 0- 7 */ - 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, /* 8- 15 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* 16- 23 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* 32- 39 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40- 47 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 48- 55 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56- 63 */ - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - 71 */ - 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, /* 72- | */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* & - 87 */ - 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, /* 88- ¬ */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - -103 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, /* 104- ? */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 112-119 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 120- " */ - 0x00, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* 128- g */ - 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* h -143 */ - 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* 144- p */ - 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* q -159 */ - 0x00, 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* 160- x */ - 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* y -175 */ - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^ -183 */ - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ - 0x80, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* { - G */ - 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* H -207 */ - 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* } - P */ - 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Q -223 */ - 0x00, 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* \ - X */ - 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y -239 */ - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, /* 0 - 7 */ +}; /* 8 -255 */ + +static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */ + 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* 0- 7 */ + 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, /* 8- 15 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* 16- 23 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24- 31 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* 32- 39 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40- 47 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 48- 55 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56- 63 */ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - 71 */ + 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, /* 72- | */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* & - 87 */ + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, /* 88- ¬ */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* - -103 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, /* 104- ? */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 112-119 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 120- " */ + 0x00, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* 128- g */ + 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* h -143 */ + 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* 144- p */ + 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* q -159 */ + 0x00, 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* 160- x */ + 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* y -175 */ + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^ -183 */ + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, /* 184-191 */ + 0x80, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x12, /* { - G */ + 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* H -207 */ + 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* } - P */ + 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Q -223 */ + 0x00, 0x00, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, /* \ - X */ + 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y -239 */ + 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, /* 0 - 7 */ 0x1c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; /* 8 -255 */ +}; /* 8 -255 */ #endif @@ -2266,7 +2266,7 @@ static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */ static BOOL compile_regex(int, int, int *, uschar **, const uschar **, int *, BOOL, int, - int *, int *, branch_chain *, compile_data *); + int *, int *, branch_chain *, compile_data *); @@ -2294,7 +2294,7 @@ Returns: zero or positive => a data character static int check_escape(const uschar ** ptrptr, int *errorcodeptr, int bracount, - int options, BOOL isclass) + int options, BOOL isclass) { const uschar *ptr = *ptrptr; int c, i; @@ -2309,13 +2309,13 @@ check_escape(const uschar ** ptrptr, int *errorcodeptr, int bracount, a table. A non-zero result is something that can be returned immediately. Otherwise further processing may be required. */ -#if !EBCDIC /* ASCII coding */ +#if !EBCDIC /* ASCII coding */ else if (c < '0' || c > 'z') { } /* Not alphameric */ else if ((i = escapes[c - '0']) != 0) c = i; -#else /* EBCDIC coding */ +#else /* EBCDIC coding */ else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) { } /* Not alphameric */ else if ((i = escapes[c - 0x48]) != 0) @@ -2361,15 +2361,15 @@ Otherwise further processing may be required. */ case '9': if (!isclass) { - oldptr = ptr; - c -= '0'; - while ((digitab[ptr[1]] & ctype_digit) != 0) - c = c * 10 + *(++ptr) - '0'; - if (c < 10 || c <= bracount) { - c = -(ESC_REF + c); - break; - } - ptr = oldptr; /* Put the pointer back and fall through */ + oldptr = ptr; + c -= '0'; + while ((digitab[ptr[1]] & ctype_digit) != 0) + c = c * 10 + *(++ptr) - '0'; + if (c < 10 || c <= bracount) { + c = -(ESC_REF + c); + break; + } + ptr = oldptr; /* Put the pointer back and fall through */ } /* Handle an octal number following \. If the first digit is 8 or 9, Perl @@ -2377,9 +2377,9 @@ Otherwise further processing may be required. */ Thus we have to pull back the pointer by one. */ if ((c = *ptr) >= '8') { - ptr--; - c = 0; - break; + ptr--; + c = 0; + break; } /* \0 always starts an octal number, but we may drop through to here with a @@ -2388,8 +2388,8 @@ Otherwise further processing may be required. */ case '0': c -= '0'; while (i++ < 2 && ptr[1] >= '0' && ptr[1] <= '7') - c = c * 8 + *(++ptr) - '0'; - c &= 255; /* Take least significant 8 bits */ + c = c * 8 + *(++ptr) - '0'; + c &= 255; /* Take least significant 8 bits */ break; /* \x is complicated when UTF-8 is enabled. \x{ddd} is a character number @@ -2401,16 +2401,16 @@ Otherwise further processing may be required. */ c = 0; while (i++ < 2 && (digitab[ptr[1]] & ctype_xdigit) != 0) { - int cc; /* Some compilers don't like ++ */ - cc = *(++ptr); /* in initializers */ -#if !EBCDIC /* ASCII coding */ - if (cc >= 'a') - cc -= 32; /* Convert to upper case */ - c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10)); -#else /* EBCDIC coding */ - if (cc <= 'z') - cc += 64; /* Convert to upper case */ - c = c * 16 + cc - ((cc >= '0') ? '0' : ('A' - 10)); + int cc; /* Some compilers don't like ++ */ + cc = *(++ptr); /* in initializers */ +#if !EBCDIC /* ASCII coding */ + if (cc >= 'a') + cc -= 32; /* Convert to upper case */ + c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10)); +#else /* EBCDIC coding */ + if (cc <= 'z') + cc += 64; /* Convert to upper case */ + c = c * 16 + cc - ((cc >= '0') ? '0' : ('A' - 10)); #endif } break; @@ -2420,21 +2420,21 @@ Otherwise further processing may be required. */ case 'c': c = *(++ptr); if (c == 0) { - *errorcodeptr = ERR2; - return 0; + *errorcodeptr = ERR2; + return 0; } /* A letter is upper-cased; then the 0x40 bit is flipped. This coding is ASCII-specific, but then the whole concept of \cx is ASCII-specific. (However, an EBCDIC equivalent has now been added.) */ -#if !EBCDIC /* ASCII coding */ +#if !EBCDIC /* ASCII coding */ if (c >= 'a' && c <= 'z') - c -= 32; + c -= 32; c ^= 0x40; -#else /* EBCDIC coding */ +#else /* EBCDIC coding */ if (c >= 'a' && c <= 'z') - c += 64; + c += 64; c ^= 0xC0; #endif break; @@ -2447,11 +2447,11 @@ Otherwise further processing may be required. */ default: if ((options & PCRE_EXTRA) != 0) - switch (c) { - default: - *errorcodeptr = ERR3; - break; - } + switch (c) { + default: + *errorcodeptr = ERR3; + break; + } break; } } @@ -2504,17 +2504,17 @@ preceded by ^ for negation. */ for (i = 0; i <= 2; i++) { c = *(++ptr); if (c == 0) - goto ERROR_RETURN; + goto ERROR_RETURN; if (c == '}') - break; + break; name[i] = c; } - if (c != '}') { /* Try to distinguish error cases */ + if (c != '}') { /* Try to distinguish error cases */ while (*(++ptr) != 0 && *ptr != '}') ; if (*ptr == '}') - goto UNKNOWN_RETURN; + goto UNKNOWN_RETURN; else - goto ERROR_RETURN; + goto ERROR_RETURN; } name[i] = 0; } @@ -2643,14 +2643,14 @@ Also, max must not be less than min. */ if (*(++p) != '}') { max = 0; while ((digitab[*p] & ctype_digit) != 0) - max = max * 10 + *p++ - '0'; + max = max * 10 + *p++ - '0'; if (max < 0 || max > 65535) { - *errorcodeptr = ERR5; - return p; + *errorcodeptr = ERR5; + return p; } if (max < min) { - *errorcodeptr = ERR4; - return p; + *errorcodeptr = ERR4; + return p; } } } @@ -2687,13 +2687,13 @@ Returns: pointer to the first significant opcode static const uschar * first_significant_code(const uschar * code, int *options, int optbit, - BOOL skipassert) + BOOL skipassert) { for (;;) { switch ((int) *code) { case OP_OPT: if (optbit > 0 && ((int) code[1] & optbit) != (*options & optbit)) - *options = (int) code[1]; + *options = (int) code[1]; code += 2; break; @@ -2701,9 +2701,9 @@ first_significant_code(const uschar * code, int *options, int optbit, case OP_ASSERTBACK: case OP_ASSERTBACK_NOT: if (!skipassert) - return code; + return code; do - code += GET(code, 1); + code += GET(code, 1); while (*code == OP_ALT); code += _pcre_OP_lengths[*code]; break; @@ -2711,7 +2711,7 @@ first_significant_code(const uschar * code, int *options, int optbit, case OP_WORD_BOUNDARY: case OP_NOT_WORD_BOUNDARY: if (!skipassert) - return code; + return code; /* Fall through */ case OP_CALLOUT: @@ -2769,10 +2769,10 @@ branch, check the length against that of the other branches. */ case OP_COND: d = find_fixedlength(cc, options); if (d < 0) - return d; + return d; branchlength += d; do - cc += GET(cc, 1); + cc += GET(cc, 1); while (*cc == OP_ALT); cc += 1 + LINK_SIZE; break; @@ -2787,11 +2787,11 @@ branch, check the length against that of the other branches. */ case OP_KETRMIN: case OP_END: if (length < 0) - length = branchlength; + length = branchlength; else if (length != branchlength) - return -1; + return -1; if (*cc != OP_ALT) - return length; + return length; cc += 1 + LINK_SIZE; branchlength = 0; break; @@ -2803,7 +2803,7 @@ branch, check the length against that of the other branches. */ case OP_ASSERTBACK: case OP_ASSERTBACK_NOT: do - cc += GET(cc, 1); + cc += GET(cc, 1); while (*cc == OP_ALT); /* Fall through */ @@ -2881,18 +2881,18 @@ branch, check the length against that of the other branches. */ case OP_CRMINSTAR: case OP_CRQUERY: case OP_CRMINQUERY: - return -1; + return -1; case OP_CRRANGE: case OP_CRMINRANGE: - if (GET2(cc, 1) != GET2(cc, 3)) - return -1; - branchlength += GET2(cc, 1); - cc += 5; - break; + if (GET2(cc, 1) != GET2(cc, 3)) + return -1; + branchlength += GET2(cc, 1); + cc += 5; + break; default: - branchlength++; + branchlength++; } break; @@ -2926,7 +2926,7 @@ Returns: pointer to the opcode for the bracket, or NULL if not found static const uschar * find_bracket(const uschar * code, BOOL utf8, int number) { - utf8 = utf8; /* Stop pedantic compilers complaining */ + utf8 = utf8; /* Stop pedantic compilers complaining */ for (;;) { register int c = *code; @@ -2935,9 +2935,9 @@ find_bracket(const uschar * code, BOOL utf8, int number) else if (c > OP_BRA) { int n = c - OP_BRA; if (n > EXTRACT_BASIC_MAX) - n = GET2(code, 2 + LINK_SIZE); + n = GET2(code, 2 + LINK_SIZE); if (n == number) - return (uschar *) code; + return (uschar *) code; code += _pcre_OP_lengths[OP_BRA]; } else { code += _pcre_OP_lengths[c]; @@ -2965,7 +2965,7 @@ Returns: pointer to the opcode for OP_RECURSE, or NULL if not found static const uschar * find_recurse(const uschar * code, BOOL utf8) { - utf8 = utf8; /* Stop pedantic compilers complaining */ + utf8 = utf8; /* Stop pedantic compilers complaining */ for (;;) { register int c = *code; @@ -3017,54 +3017,54 @@ could_be_empty_branch(const uschar * code, const uschar * endcode, BOOL utf8) if (c >= OP_BRA) { BOOL empty_branch; if (GET(code, 1) == 0) - return TRUE; /* Hit unclosed bracket */ + return TRUE; /* Hit unclosed bracket */ /* Scan a closed bracket */ empty_branch = FALSE; do { - if (!empty_branch && could_be_empty_branch(code, endcode, utf8)) - empty_branch = TRUE; - code += GET(code, 1); + if (!empty_branch && could_be_empty_branch(code, endcode, utf8)) + empty_branch = TRUE; + code += GET(code, 1); } while (*code == OP_ALT); if (!empty_branch) - return FALSE; /* All branches are non-empty */ + return FALSE; /* All branches are non-empty */ code += 1 + LINK_SIZE; c = *code; } else switch (c) { - /* Check for quantifiers after a class */ + /* Check for quantifiers after a class */ case OP_CLASS: case OP_NCLASS: - ccode = code + 33; + ccode = code + 33; - switch (*ccode) { - case OP_CRSTAR: /* These could be empty; continue */ - case OP_CRMINSTAR: - case OP_CRQUERY: - case OP_CRMINQUERY: - break; + switch (*ccode) { + case OP_CRSTAR: /* These could be empty; continue */ + case OP_CRMINSTAR: + case OP_CRQUERY: + case OP_CRMINQUERY: + break; - default: /* Non-repeat => class must match */ - case OP_CRPLUS: /* These repeats aren't empty */ - case OP_CRMINPLUS: - return FALSE; + default: /* Non-repeat => class must match */ + case OP_CRPLUS: /* These repeats aren't empty */ + case OP_CRMINPLUS: + return FALSE; - case OP_CRRANGE: - case OP_CRMINRANGE: - if (GET2(ccode, 1) > 0) - return FALSE; /* Minimum > 0 */ - break; - } - break; + case OP_CRRANGE: + case OP_CRMINRANGE: + if (GET2(ccode, 1) > 0) + return FALSE; /* Minimum > 0 */ + break; + } + break; - /* Opcodes that must match a character */ + /* Opcodes that must match a character */ case OP_PROP: case OP_NOTPROP: @@ -3089,18 +3089,18 @@ could_be_empty_branch(const uschar * code, const uschar * endcode, BOOL utf8) case OP_TYPEPLUS: case OP_TYPEMINPLUS: case OP_TYPEEXACT: - return FALSE; + return FALSE; - /* End of branch */ + /* End of branch */ case OP_KET: case OP_KETRMAX: case OP_KETRMIN: case OP_ALT: - return TRUE; + return TRUE; - /* In UTF-8 mode, STAR, MINSTAR, QUERY, MINQUERY, UPTO, and MINUPTO may be - followed by a multibyte character */ + /* In UTF-8 mode, STAR, MINSTAR, QUERY, MINQUERY, UPTO, and MINUPTO may be + followed by a multibyte character */ } } @@ -3130,7 +3130,7 @@ Returns: TRUE if what is matched could be empty static BOOL could_be_empty(const uschar * code, const uschar * endcode, - branch_chain * bcptr, BOOL utf8) + branch_chain * bcptr, BOOL utf8) { while (bcptr != NULL && bcptr->current >= code) { if (!could_be_empty_branch(bcptr->current, endcode, utf8)) @@ -3161,10 +3161,10 @@ Returns: TRUE or FALSE static BOOL check_posix_syntax(const uschar * ptr, const uschar ** endptr, - compile_data * cd) + compile_data * cd) { - int terminator; /* Don't combine these lines; the Solaris cc */ - terminator = *(++ptr); /* compiler warns about "non-constant" initializer. */ + int terminator; /* Don't combine these lines; the Solaris cc */ + terminator = *(++ptr); /* compiler warns about "non-constant" initializer. */ if (*(++ptr) == '^') ptr++; while ((cd->ctypes[*ptr] & ctype_letter) != 0) @@ -3199,7 +3199,7 @@ check_posix_name(const uschar * ptr, int len) register int yield = 0; while (posix_name_lengths[yield] != 0) { if (len == posix_name_lengths[yield] && - strncmp((const char *) ptr, posix_names[yield], len) == 0) + strncmp((const char *) ptr, posix_names[yield], len) == 0) return yield; yield++; } @@ -3264,8 +3264,8 @@ auto_callout(uschar * code, const uschar * ptr, compile_data * cd) { *code++ = OP_CALLOUT; *code++ = 255; - PUT(code, 0, ptr - cd->start_pattern); /* Pattern offset */ - PUT(code, LINK_SIZE, 0); /* Default length */ + PUT(code, 0, ptr - cd->start_pattern); /* Pattern offset */ + PUT(code, LINK_SIZE, 0); /* Default length */ return code + 2 * LINK_SIZE; } @@ -3289,7 +3289,7 @@ Returns: nothing static void complete_callout(uschar * previous_callout, const uschar * ptr, - compile_data * cd) + compile_data * cd) { int length = ptr - cd->start_pattern - GET(previous_callout, 2); PUT(previous_callout, 2 + LINK_SIZE, length); @@ -3334,7 +3334,7 @@ get_othercase_range(int *cptr, int d, int *ocptr, int *odptr) for (++c; c <= d; c++) { if (_pcre_ucp_findchar(c, &chartype, &othercase) != ucp_L || - othercase != next) + othercase != next) break; next++; } @@ -3344,7 +3344,7 @@ get_othercase_range(int *cptr, int d, int *ocptr, int *odptr) return TRUE; } -#endif /* SUPPORT_UCP */ +#endif /* SUPPORT_UCP */ /************************************************* @@ -3372,11 +3372,11 @@ Returns: TRUE on success static BOOL compile_branch(int *optionsptr, int *brackets, uschar ** codeptr, - const uschar ** ptrptr, int *errorcodeptr, int *firstbyteptr, - int *reqbyteptr, branch_chain * bcptr, compile_data * cd) + const uschar ** ptrptr, int *errorcodeptr, int *firstbyteptr, + int *reqbyteptr, branch_chain * bcptr, compile_data * cd) { int repeat_type, op_type; - int repeat_min = 0, repeat_max = 0; /* To please picky compilers */ + int repeat_min = 0, repeat_max = 0; /* To please picky compilers */ int bravalue = 0; int greedy_default, greedy_non_default; int firstbyte, reqbyte; @@ -3446,19 +3446,19 @@ case status of the value. This is used only for ASCII characters. */ if (inescq && c != 0) { if (c == '\\' && ptr[1] == 'E') { - inescq = FALSE; - ptr++; - continue; + inescq = FALSE; + ptr++; + continue; } else { - if (previous_callout != NULL) { - complete_callout(previous_callout, ptr, cd); - previous_callout = NULL; - } - if ((options & PCRE_AUTO_CALLOUT) != 0) { - previous_callout = code; - code = auto_callout(code, ptr, cd); - } - goto NORMAL_CHAR; + if (previous_callout != NULL) { + complete_callout(previous_callout, ptr, cd); + previous_callout = NULL; + } + if ((options & PCRE_AUTO_CALLOUT) != 0) { + previous_callout = code; + code = auto_callout(code, ptr, cd); + } + goto NORMAL_CHAR; } } @@ -3469,7 +3469,7 @@ case status of the value. This is used only for ASCII characters. */ (c == '{' && is_counted_repeat(ptr + 1)); if (!is_quantifier && previous_callout != NULL && - after_manual_callout-- <= 0) { + after_manual_callout-- <= 0) { complete_callout(previous_callout, ptr, cd); previous_callout = NULL; } @@ -3478,13 +3478,13 @@ case status of the value. This is used only for ASCII characters. */ if ((options & PCRE_EXTENDED) != 0) { if ((cd->ctypes[c] & ctype_space) != 0) - continue; + continue; if (c == '#') { - /* The space before the ; is to avoid a warning on a silly compiler - on the Macintosh. */ - while ((c = *(++ptr)) != 0 && c != NEWLINE) ; - if (c != 0) - continue; /* Else fall through to handle end of string */ + /* The space before the ; is to avoid a warning on a silly compiler + on the Macintosh. */ + while ((c = *(++ptr)) != 0 && c != NEWLINE) ; + if (c != 0) + continue; /* Else fall through to handle end of string */ } } @@ -3512,8 +3512,8 @@ case status of the value. This is used only for ASCII characters. */ case '^': if ((options & PCRE_MULTILINE) != 0) { - if (firstbyte == REQ_UNSET) - firstbyte = REQ_NONE; + if (firstbyte == REQ_UNSET) + firstbyte = REQ_NONE; } previous = NULL; *code++ = OP_CIRC; @@ -3529,7 +3529,7 @@ case status of the value. This is used only for ASCII characters. */ case '.': if (firstbyte == REQ_UNSET) - firstbyte = REQ_NONE; + firstbyte = REQ_NONE; zerofirstbyte = firstbyte; zeroreqbyte = reqbyte; previous = code; @@ -3555,18 +3555,18 @@ case status of the value. This is used only for ASCII characters. */ they are encountered at the top level, so we'll do that too. */ if ((ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') && - check_posix_syntax(ptr, &tempptr, cd)) { - *errorcodeptr = (ptr[1] == ':') ? ERR13 : ERR31; - goto FAILED; + check_posix_syntax(ptr, &tempptr, cd)) { + *errorcodeptr = (ptr[1] == ':') ? ERR13 : ERR31; + goto FAILED; } /* If the first character is '^', set the negation flag and skip it. */ if ((c = *(++ptr)) == '^') { - negate_class = TRUE; - c = *(++ptr); + negate_class = TRUE; + c = *(++ptr); } else { - negate_class = FALSE; + negate_class = FALSE; } /* Keep a count of chars with values < 256 so that we can optimize the case @@ -3592,264 +3592,264 @@ case status of the value. This is used only for ASCII characters. */ do { - /* Inside \Q...\E everything is literal except \E */ - - if (inescq) { - if (c == '\\' && ptr[1] == 'E') { - inescq = FALSE; - ptr++; - continue; - } else - goto LONE_SINGLE_CHARACTER; - } - - /* Handle POSIX class names. Perl allows a negation extension of the - form [:^name:]. A square bracket that doesn't match the syntax is - treated as a literal. We also recognize the POSIX constructions - [.ch.] and [=ch=] ("collating elements") and fault them, as Perl - 5.6 and 5.8 do. */ - - if (c == '[' && - (ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') && - check_posix_syntax(ptr, &tempptr, cd)) { - BOOL local_negate = FALSE; - int posix_class, i; - register const uschar *cbits = cd->cbits; - - if (ptr[1] != ':') { - *errorcodeptr = ERR31; - goto FAILED; - } - - ptr += 2; - if (*ptr == '^') { - local_negate = TRUE; - ptr++; - } - - posix_class = check_posix_name(ptr, tempptr - ptr); - if (posix_class < 0) { - *errorcodeptr = ERR30; - goto FAILED; - } - - /* If matching is caseless, upper and lower are converted to - alpha. This relies on the fact that the class table starts with - alpha, lower, upper as the first 3 entries. */ - - if ((options & PCRE_CASELESS) != 0 && posix_class <= 2) - posix_class = 0; - - /* Or into the map we are building up to 3 of the static class - tables, or their negations. The [:blank:] class sets up the same - chars as the [:space:] class (all white space). We remove the vertical - white space chars afterwards. */ - - posix_class *= 3; - for (i = 0; i < 3; i++) { - BOOL blankclass = strncmp((char *) ptr, "blank", 5) == 0; - int taboffset = posix_class_maps[posix_class + i]; - if (taboffset < 0) - break; - if (local_negate) { - if (i == 0) - for (c = 0; c < 32; c++) - classbits[c] |= ~cbits[c + taboffset]; - else - for (c = 0; c < 32; c++) - classbits[c] &= ~cbits[c + taboffset]; - if (blankclass) - classbits[1] |= 0x3c; - } else { - for (c = 0; c < 32; c++) - classbits[c] |= cbits[c + taboffset]; - if (blankclass) - classbits[1] &= ~0x3c; - } - } - - ptr = tempptr + 1; - class_charcount = 10; /* Set > 1; assumes more than 1 per class */ - continue; /* End of POSIX syntax handling */ - } - - /* Backslash may introduce a single character, or it may introduce one - of the specials, which just set a flag. Escaped items are checked for - validity in the pre-compiling pass. The sequence \b is a special case. - Inside a class (and only there) it is treated as backspace. Elsewhere - it marks a word boundary. Other escapes have preset maps ready to - or into the one we are building. We assume they have more than one - character in them, so set class_charcount bigger than one. */ - - if (c == '\\') { - c = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE); - - if (-c == ESC_b) - c = '\b'; /* \b is backslash in a class */ - else if (-c == ESC_X) - c = 'X'; /* \X is literal X in a class */ - else if (-c == ESC_Q) { /* Handle start of quoted string */ - if (ptr[1] == '\\' && ptr[2] == 'E') { - ptr += 2; /* avoid empty string */ - } else - inescq = TRUE; - continue; - } - - if (c < 0) { - register const uschar *cbits = cd->cbits; - class_charcount += 2; /* Greater than 1 is what matters */ - switch (-c) { - case ESC_d: - for (c = 0; c < 32; c++) - classbits[c] |= cbits[c + cbit_digit]; - continue; - - case ESC_D: - for (c = 0; c < 32; c++) - classbits[c] |= ~cbits[c + cbit_digit]; - continue; - - case ESC_w: - for (c = 0; c < 32; c++) - classbits[c] |= cbits[c + cbit_word]; - continue; - - case ESC_W: - for (c = 0; c < 32; c++) - classbits[c] |= ~cbits[c + cbit_word]; - continue; - - case ESC_s: - for (c = 0; c < 32; c++) - classbits[c] |= cbits[c + cbit_space]; - classbits[1] &= ~0x08; /* Perl 5.004 onwards omits VT from \s */ - continue; - - case ESC_S: - for (c = 0; c < 32; c++) - classbits[c] |= ~cbits[c + cbit_space]; - classbits[1] |= 0x08; /* Perl 5.004 onwards omits VT from \s */ - continue; + /* Inside \Q...\E everything is literal except \E */ + + if (inescq) { + if (c == '\\' && ptr[1] == 'E') { + inescq = FALSE; + ptr++; + continue; + } else + goto LONE_SINGLE_CHARACTER; + } + + /* Handle POSIX class names. Perl allows a negation extension of the + form [:^name:]. A square bracket that doesn't match the syntax is + treated as a literal. We also recognize the POSIX constructions + [.ch.] and [=ch=] ("collating elements") and fault them, as Perl + 5.6 and 5.8 do. */ + + if (c == '[' && + (ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') && + check_posix_syntax(ptr, &tempptr, cd)) { + BOOL local_negate = FALSE; + int posix_class, i; + register const uschar *cbits = cd->cbits; + + if (ptr[1] != ':') { + *errorcodeptr = ERR31; + goto FAILED; + } + + ptr += 2; + if (*ptr == '^') { + local_negate = TRUE; + ptr++; + } + + posix_class = check_posix_name(ptr, tempptr - ptr); + if (posix_class < 0) { + *errorcodeptr = ERR30; + goto FAILED; + } + + /* If matching is caseless, upper and lower are converted to + alpha. This relies on the fact that the class table starts with + alpha, lower, upper as the first 3 entries. */ + + if ((options & PCRE_CASELESS) != 0 && posix_class <= 2) + posix_class = 0; + + /* Or into the map we are building up to 3 of the static class + tables, or their negations. The [:blank:] class sets up the same + chars as the [:space:] class (all white space). We remove the vertical + white space chars afterwards. */ + + posix_class *= 3; + for (i = 0; i < 3; i++) { + BOOL blankclass = strncmp((char *) ptr, "blank", 5) == 0; + int taboffset = posix_class_maps[posix_class + i]; + if (taboffset < 0) + break; + if (local_negate) { + if (i == 0) + for (c = 0; c < 32; c++) + classbits[c] |= ~cbits[c + taboffset]; + else + for (c = 0; c < 32; c++) + classbits[c] &= ~cbits[c + taboffset]; + if (blankclass) + classbits[1] |= 0x3c; + } else { + for (c = 0; c < 32; c++) + classbits[c] |= cbits[c + taboffset]; + if (blankclass) + classbits[1] &= ~0x3c; + } + } + + ptr = tempptr + 1; + class_charcount = 10; /* Set > 1; assumes more than 1 per class */ + continue; /* End of POSIX syntax handling */ + } + + /* Backslash may introduce a single character, or it may introduce one + of the specials, which just set a flag. Escaped items are checked for + validity in the pre-compiling pass. The sequence \b is a special case. + Inside a class (and only there) it is treated as backspace. Elsewhere + it marks a word boundary. Other escapes have preset maps ready to + or into the one we are building. We assume they have more than one + character in them, so set class_charcount bigger than one. */ + + if (c == '\\') { + c = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE); + + if (-c == ESC_b) + c = '\b'; /* \b is backslash in a class */ + else if (-c == ESC_X) + c = 'X'; /* \X is literal X in a class */ + else if (-c == ESC_Q) { /* Handle start of quoted string */ + if (ptr[1] == '\\' && ptr[2] == 'E') { + ptr += 2; /* avoid empty string */ + } else + inescq = TRUE; + continue; + } + + if (c < 0) { + register const uschar *cbits = cd->cbits; + class_charcount += 2; /* Greater than 1 is what matters */ + switch (-c) { + case ESC_d: + for (c = 0; c < 32; c++) + classbits[c] |= cbits[c + cbit_digit]; + continue; + + case ESC_D: + for (c = 0; c < 32; c++) + classbits[c] |= ~cbits[c + cbit_digit]; + continue; + + case ESC_w: + for (c = 0; c < 32; c++) + classbits[c] |= cbits[c + cbit_word]; + continue; + + case ESC_W: + for (c = 0; c < 32; c++) + classbits[c] |= ~cbits[c + cbit_word]; + continue; + + case ESC_s: + for (c = 0; c < 32; c++) + classbits[c] |= cbits[c + cbit_space]; + classbits[1] &= ~0x08; /* Perl 5.004 onwards omits VT from \s */ + continue; + + case ESC_S: + for (c = 0; c < 32; c++) + classbits[c] |= ~cbits[c + cbit_space]; + classbits[1] |= 0x08; /* Perl 5.004 onwards omits VT from \s */ + continue; #ifdef SUPPORT_UCP - case ESC_p: - case ESC_P: - { - BOOL negated; - int property = get_ucp(&ptr, &negated, errorcodeptr); - if (property < 0) - goto FAILED; - class_utf8 = TRUE; - *class_utf8data++ = ((-c == ESC_p) != negated) ? - XCL_PROP : XCL_NOTPROP; - *class_utf8data++ = property; - class_charcount -= 2; /* Not a < 256 character */ - } - continue; + case ESC_p: + case ESC_P: + { + BOOL negated; + int property = get_ucp(&ptr, &negated, errorcodeptr); + if (property < 0) + goto FAILED; + class_utf8 = TRUE; + *class_utf8data++ = ((-c == ESC_p) != negated) ? + XCL_PROP : XCL_NOTPROP; + *class_utf8data++ = property; + class_charcount -= 2; /* Not a < 256 character */ + } + continue; #endif - /* Unrecognized escapes are faulted if PCRE is running in its - strict mode. By default, for compatibility with Perl, they are - treated as literals. */ - - default: - if ((options & PCRE_EXTRA) != 0) { - *errorcodeptr = ERR7; - goto FAILED; - } - c = *ptr; /* The final character */ - class_charcount -= 2; /* Undo the default count from above */ - } - } - - /* Fall through if we have a single character (c >= 0). This may be - > 256 in UTF-8 mode. */ - - } - - - /* End of backslash handling */ - /* A single character may be followed by '-' to form a range. However, - Perl does not permit ']' to be the end of the range. A '-' character - here is treated as a literal. */ - if (ptr[1] == '-' && ptr[2] != ']') { - int d; - ptr += 2; - - d = *ptr; /* Not UTF-8 mode */ - - /* The second part of a range can be a single-character escape, but - not any of the other escapes. Perl 5.6 treats a hyphen as a literal - in such circumstances. */ - - if (d == '\\') { - const uschar *oldptr = ptr; - d = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE); - - /* \b is backslash; \X is literal X; any other special means the '-' - was literal */ - - if (d < 0) { - if (d == -ESC_b) - d = '\b'; - else if (d == -ESC_X) - d = 'X'; - else { - ptr = oldptr - 2; - goto LONE_SINGLE_CHARACTER; /* A few lines below */ - } - } - } - - /* The check that the two values are in the correct order happens in - the pre-pass. Optimize one-character ranges */ - - if (d == c) - goto LONE_SINGLE_CHARACTER; /* A few lines below */ - - /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless - matching, we have to use an XCLASS with extra data items. Caseless - matching for characters > 127 is available only if UCP support is - available. */ - - - /* We use the bit map for all cases when not in UTF-8 mode; else - ranges that lie entirely within 0-127 when there is UCP support; else - for partial ranges without UCP support. */ - - for (; c <= d; c++) { - classbits[c / 8] |= (1 << (c & 7)); - if ((options & PCRE_CASELESS) != 0) { - int uc = cd->fcc[c]; /* flip case */ - classbits[uc / 8] |= (1 << (uc & 7)); - } - class_charcount++; /* in case a one-char range */ - class_lastchar = c; - } - - continue; /* Go get the next char in the class */ - } - - /* Handle a lone single character - we can get here for a normal - non-escape char, or after \ that introduces a single character or for an - apparent range that isn't. */ + /* Unrecognized escapes are faulted if PCRE is running in its + strict mode. By default, for compatibility with Perl, they are + treated as literals. */ + + default: + if ((options & PCRE_EXTRA) != 0) { + *errorcodeptr = ERR7; + goto FAILED; + } + c = *ptr; /* The final character */ + class_charcount -= 2; /* Undo the default count from above */ + } + } + + /* Fall through if we have a single character (c >= 0). This may be + > 256 in UTF-8 mode. */ + + } + + + /* End of backslash handling */ + /* A single character may be followed by '-' to form a range. However, + Perl does not permit ']' to be the end of the range. A '-' character + here is treated as a literal. */ + if (ptr[1] == '-' && ptr[2] != ']') { + int d; + ptr += 2; + + d = *ptr; /* Not UTF-8 mode */ + + /* The second part of a range can be a single-character escape, but + not any of the other escapes. Perl 5.6 treats a hyphen as a literal + in such circumstances. */ + + if (d == '\\') { + const uschar *oldptr = ptr; + d = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE); + + /* \b is backslash; \X is literal X; any other special means the '-' + was literal */ + + if (d < 0) { + if (d == -ESC_b) + d = '\b'; + else if (d == -ESC_X) + d = 'X'; + else { + ptr = oldptr - 2; + goto LONE_SINGLE_CHARACTER; /* A few lines below */ + } + } + } + + /* The check that the two values are in the correct order happens in + the pre-pass. Optimize one-character ranges */ + + if (d == c) + goto LONE_SINGLE_CHARACTER; /* A few lines below */ + + /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless + matching, we have to use an XCLASS with extra data items. Caseless + matching for characters > 127 is available only if UCP support is + available. */ + + + /* We use the bit map for all cases when not in UTF-8 mode; else + ranges that lie entirely within 0-127 when there is UCP support; else + for partial ranges without UCP support. */ + + for (; c <= d; c++) { + classbits[c / 8] |= (1 << (c & 7)); + if ((options & PCRE_CASELESS) != 0) { + int uc = cd->fcc[c]; /* flip case */ + classbits[uc / 8] |= (1 << (uc & 7)); + } + class_charcount++; /* in case a one-char range */ + class_lastchar = c; + } + + continue; /* Go get the next char in the class */ + } + + /* Handle a lone single character - we can get here for a normal + non-escape char, or after \ that introduces a single character or for an + apparent range that isn't. */ LONE_SINGLE_CHARACTER: - /* Handle a character that cannot go in the bit map */ + /* Handle a character that cannot go in the bit map */ - /* Handle a single-byte character */ - { - classbits[c / 8] |= (1 << (c & 7)); - if ((options & PCRE_CASELESS) != 0) { - c = cd->fcc[c]; /* flip case */ - classbits[c / 8] |= (1 << (c & 7)); - } - class_charcount++; - class_lastchar = c; - } + /* Handle a single-byte character */ + { + classbits[c / 8] |= (1 << (c & 7)); + if ((options & PCRE_CASELESS) != 0) { + c = cd->fcc[c]; /* flip case */ + classbits[c / 8] |= (1 << (c & 7)); + } + class_charcount++; + class_lastchar = c; + } } /* Loop until ']' reached; the check for end of string happens inside the @@ -3872,27 +3872,27 @@ case status of the value. This is used only for ASCII characters. */ reqbyte, save the previous value for reinstating. */ if (class_charcount == 1) { - zeroreqbyte = reqbyte; - - /* The OP_NOT opcode works on one-byte characters only. */ - - if (negate_class) { - if (firstbyte == REQ_UNSET) - firstbyte = REQ_NONE; - zerofirstbyte = firstbyte; - *code++ = OP_NOT; - *code++ = class_lastchar; - break; - } - - /* For a single, positive character, get the value into mcbuffer, and - then we can handle this with the normal one-character code. */ - - { - mcbuffer[0] = class_lastchar; - mclength = 1; - } - goto ONE_CHAR; + zeroreqbyte = reqbyte; + + /* The OP_NOT opcode works on one-byte characters only. */ + + if (negate_class) { + if (firstbyte == REQ_UNSET) + firstbyte = REQ_NONE; + zerofirstbyte = firstbyte; + *code++ = OP_NOT; + *code++ = class_lastchar; + break; + } + + /* For a single, positive character, get the value into mcbuffer, and + then we can handle this with the normal one-character code. */ + + { + mcbuffer[0] = class_lastchar; + mclength = 1; + } + goto ONE_CHAR; } @@ -3902,7 +3902,7 @@ case status of the value. This is used only for ASCII characters. */ repeat count. Any reqbyte setting must remain unchanged after any kind of repeat. */ if (firstbyte == REQ_UNSET) - firstbyte = REQ_NONE; + firstbyte = REQ_NONE; zerofirstbyte = firstbyte; zeroreqbyte = reqbyte; @@ -3917,12 +3917,12 @@ case status of the value. This is used only for ASCII characters. */ setting must remain unchanged after any kind of repeat. */ if (negate_class) { - *code++ = OP_NCLASS; - for (c = 0; c < 32; c++) - code[c] = ~classbits[c]; + *code++ = OP_NCLASS; + for (c = 0; c < 32; c++) + code[c] = ~classbits[c]; } else { - *code++ = OP_CLASS; - memcpy(code, classbits, 32); + *code++ = OP_CLASS; + memcpy(code, classbits, 32); } code += 32; break; @@ -3932,10 +3932,10 @@ case status of the value. This is used only for ASCII characters. */ case '{': if (!is_quantifier) - goto NORMAL_CHAR; + goto NORMAL_CHAR; ptr = read_repeat_counts(ptr + 1, &repeat_min, &repeat_max, errorcodeptr); if (*errorcodeptr != 0) - goto FAILED; + goto FAILED; goto REPEAT; case '*': @@ -3954,21 +3954,21 @@ case status of the value. This is used only for ASCII characters. */ REPEAT: if (previous == NULL) { - *errorcodeptr = ERR9; - goto FAILED; + *errorcodeptr = ERR9; + goto FAILED; } if (repeat_min == 0) { - firstbyte = zerofirstbyte; /* Adjust for zero repeat */ - reqbyte = zeroreqbyte; /* Ditto */ + firstbyte = zerofirstbyte; /* Adjust for zero repeat */ + reqbyte = zeroreqbyte; /* Ditto */ } /* Remember whether this is a variable length repeat */ reqvary = (repeat_min == repeat_max) ? 0 : REQ_VARY; - op_type = 0; /* Default single-char op codes */ - possessive_quantifier = FALSE; /* Default not possessive quantifier */ + op_type = 0; /* Default single-char op codes */ + possessive_quantifier = FALSE; /* Default not possessive quantifier */ /* Save start of previous item, in case we have to move it up to make space for an inserted OP_ONCE for the additional '+' extension. */ @@ -3982,26 +3982,26 @@ case status of the value. This is used only for ASCII characters. */ repeat type to the non-default. */ if (ptr[1] == '+') { - repeat_type = 0; /* Force greedy */ - possessive_quantifier = TRUE; - ptr++; + repeat_type = 0; /* Force greedy */ + possessive_quantifier = TRUE; + ptr++; } else if (ptr[1] == '?') { - repeat_type = greedy_non_default; - ptr++; + repeat_type = greedy_non_default; + ptr++; } else - repeat_type = greedy_default; + repeat_type = greedy_default; /* If previous was a recursion, we need to wrap it inside brackets so that it can be replicated if necessary. */ if (*previous == OP_RECURSE) { - memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE); - code += 1 + LINK_SIZE; - *previous = OP_BRA; - PUT(previous, 1, code - previous); - *code = OP_KET; - PUT(code, 1, code - previous); - code += 1 + LINK_SIZE; + memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE); + code += 1 + LINK_SIZE; + *previous = OP_BRA; + PUT(previous, 1, code - previous); + *code = OP_KET; + PUT(code, 1, code - previous); + code += 1 + LINK_SIZE; } /* If previous was a character match, abolish the item and generate a @@ -4011,22 +4011,22 @@ case status of the value. This is used only for ASCII characters. */ instead. */ if (*previous == OP_CHAR || *previous == OP_CHARNC) { - /* Deal with UTF-8 characters that take up more than one byte. It's - easier to write this out separately than try to macrify it. Use c to - hold the length of the character in bytes, plus 0x80 to flag that it's a - length rather than a small character. */ + /* Deal with UTF-8 characters that take up more than one byte. It's + easier to write this out separately than try to macrify it. Use c to + hold the length of the character in bytes, plus 0x80 to flag that it's a + length rather than a small character. */ - /* Handle the case of a single byte - either with no UTF8 support, or - with UTF-8 disabled, or for a UTF-8 character < 128. */ + /* Handle the case of a single byte - either with no UTF8 support, or + with UTF-8 disabled, or for a UTF-8 character < 128. */ - { - c = code[-1]; - if (repeat_min > 1) - reqbyte = c | req_caseopt | cd->req_varyopt; - } + { + c = code[-1]; + if (repeat_min > 1) + reqbyte = c | req_caseopt | cd->req_varyopt; + } - goto OUTPUT_SINGLE_REPEAT; /* Code shared with single character types */ + goto OUTPUT_SINGLE_REPEAT; /* Code shared with single character types */ } /* If previous was a single negated character ([^a] or similar), we use @@ -4035,9 +4035,9 @@ case status of the value. This is used only for ASCII characters. */ repeat_type. OP_NOT is currently used only for single-byte chars. */ else if (*previous == OP_NOT) { - op_type = OP_NOTSTAR - OP_STAR; /* Use "not" opcodes */ - c = previous[1]; - goto OUTPUT_SINGLE_REPEAT; + op_type = OP_NOTSTAR - OP_STAR; /* Use "not" opcodes */ + c = previous[1]; + goto OUTPUT_SINGLE_REPEAT; } /* If previous was a character type match (\d or similar), abolish it and @@ -4048,110 +4048,110 @@ case status of the value. This is used only for ASCII characters. */ makes it horribly messy. */ else if (*previous < OP_EODN) { - uschar *oldcode; - int prop_type; - op_type = OP_TYPESTAR - OP_STAR; /* Use type opcodes */ - c = *previous; + uschar *oldcode; + int prop_type; + op_type = OP_TYPESTAR - OP_STAR; /* Use type opcodes */ + c = *previous; OUTPUT_SINGLE_REPEAT: - prop_type = (*previous == OP_PROP || *previous == OP_NOTPROP) ? - previous[1] : -1; - - oldcode = code; - code = previous; /* Usually overwrite previous item */ - - /* If the maximum is zero then the minimum must also be zero; Perl allows - this case, so we do too - by simply omitting the item altogether. */ - - if (repeat_max == 0) - goto END_REPEAT; - - /* All real repeats make it impossible to handle partial matching (maybe - one day we will be able to remove this restriction). */ - - if (repeat_max != 1) - cd->nopartial = TRUE; - - /* Combine the op_type with the repeat_type */ - - repeat_type += op_type; - - /* A minimum of zero is handled either as the special case * or ?, or as - an UPTO, with the maximum given. */ - - if (repeat_min == 0) { - if (repeat_max == -1) - *code++ = OP_STAR + repeat_type; - else if (repeat_max == 1) - *code++ = OP_QUERY + repeat_type; - else { - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max); - } - } - - /* A repeat minimum of 1 is optimized into some special cases. If the - maximum is unlimited, we use OP_PLUS. Otherwise, the original item it - left in place and, if the maximum is greater than 1, we use OP_UPTO with - one less than the maximum. */ - - else if (repeat_min == 1) { - if (repeat_max == -1) - *code++ = OP_PLUS + repeat_type; - else { - code = oldcode; /* leave previous item in place */ - if (repeat_max == 1) - goto END_REPEAT; - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max - 1); - } - } - - /* The case {n,n} is just an EXACT, while the general case {n,m} is - handled as an EXACT followed by an UPTO. */ - - else { - *code++ = OP_EXACT + op_type; /* NB EXACT doesn't have repeat_type */ - PUT2INC(code, 0, repeat_min); - - /* If the maximum is unlimited, insert an OP_STAR. Before doing so, - we have to insert the character for the previous code. For a repeated - Unicode property match, there is an extra byte that defines the - required property. In UTF-8 mode, long characters have their length in - c, with the 0x80 bit as a flag. */ - - if (repeat_max < 0) { - { - *code++ = c; - if (prop_type >= 0) - *code++ = prop_type; - } - *code++ = OP_STAR + repeat_type; - } - - /* Else insert an UPTO if the max is greater than the min, again - preceded by the character, for the previously inserted code. */ - - else if (repeat_max != repeat_min) { - *code++ = c; - if (prop_type >= 0) - *code++ = prop_type; - repeat_max -= repeat_min; - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max); - } - } - - /* The character or character type itself comes last in all cases. */ - - *code++ = c; - - /* For a repeated Unicode property match, there is an extra byte that - defines the required property. */ + prop_type = (*previous == OP_PROP || *previous == OP_NOTPROP) ? + previous[1] : -1; + + oldcode = code; + code = previous; /* Usually overwrite previous item */ + + /* If the maximum is zero then the minimum must also be zero; Perl allows + this case, so we do too - by simply omitting the item altogether. */ + + if (repeat_max == 0) + goto END_REPEAT; + + /* All real repeats make it impossible to handle partial matching (maybe + one day we will be able to remove this restriction). */ + + if (repeat_max != 1) + cd->nopartial = TRUE; + + /* Combine the op_type with the repeat_type */ + + repeat_type += op_type; + + /* A minimum of zero is handled either as the special case * or ?, or as + an UPTO, with the maximum given. */ + + if (repeat_min == 0) { + if (repeat_max == -1) + *code++ = OP_STAR + repeat_type; + else if (repeat_max == 1) + *code++ = OP_QUERY + repeat_type; + else { + *code++ = OP_UPTO + repeat_type; + PUT2INC(code, 0, repeat_max); + } + } + + /* A repeat minimum of 1 is optimized into some special cases. If the + maximum is unlimited, we use OP_PLUS. Otherwise, the original item it + left in place and, if the maximum is greater than 1, we use OP_UPTO with + one less than the maximum. */ + + else if (repeat_min == 1) { + if (repeat_max == -1) + *code++ = OP_PLUS + repeat_type; + else { + code = oldcode; /* leave previous item in place */ + if (repeat_max == 1) + goto END_REPEAT; + *code++ = OP_UPTO + repeat_type; + PUT2INC(code, 0, repeat_max - 1); + } + } + + /* The case {n,n} is just an EXACT, while the general case {n,m} is + handled as an EXACT followed by an UPTO. */ + + else { + *code++ = OP_EXACT + op_type; /* NB EXACT doesn't have repeat_type */ + PUT2INC(code, 0, repeat_min); + + /* If the maximum is unlimited, insert an OP_STAR. Before doing so, + we have to insert the character for the previous code. For a repeated + Unicode property match, there is an extra byte that defines the + required property. In UTF-8 mode, long characters have their length in + c, with the 0x80 bit as a flag. */ + + if (repeat_max < 0) { + { + *code++ = c; + if (prop_type >= 0) + *code++ = prop_type; + } + *code++ = OP_STAR + repeat_type; + } + + /* Else insert an UPTO if the max is greater than the min, again + preceded by the character, for the previously inserted code. */ + + else if (repeat_max != repeat_min) { + *code++ = c; + if (prop_type >= 0) + *code++ = prop_type; + repeat_max -= repeat_min; + *code++ = OP_UPTO + repeat_type; + PUT2INC(code, 0, repeat_max); + } + } + + /* The character or character type itself comes last in all cases. */ + + *code++ = c; + + /* For a repeated Unicode property match, there is an extra byte that + defines the required property. */ #ifdef SUPPORT_UCP - if (prop_type >= 0) - *code++ = prop_type; + if (prop_type >= 0) + *code++ = prop_type; #endif } @@ -4159,187 +4159,187 @@ case status of the value. This is used only for ASCII characters. */ stuff after it, but just skip the item if the repeat was {0,0}. */ else if (*previous == OP_CLASS || - *previous == OP_NCLASS || *previous == OP_REF) { - if (repeat_max == 0) { - code = previous; - goto END_REPEAT; - } - - /* All real repeats make it impossible to handle partial matching (maybe - one day we will be able to remove this restriction). */ - - if (repeat_max != 1) - cd->nopartial = TRUE; - - if (repeat_min == 0 && repeat_max == -1) - *code++ = OP_CRSTAR + repeat_type; - else if (repeat_min == 1 && repeat_max == -1) - *code++ = OP_CRPLUS + repeat_type; - else if (repeat_min == 0 && repeat_max == 1) - *code++ = OP_CRQUERY + repeat_type; - else { - *code++ = OP_CRRANGE + repeat_type; - PUT2INC(code, 0, repeat_min); - if (repeat_max == -1) - repeat_max = 0; /* 2-byte encoding for max */ - PUT2INC(code, 0, repeat_max); - } + *previous == OP_NCLASS || *previous == OP_REF) { + if (repeat_max == 0) { + code = previous; + goto END_REPEAT; + } + + /* All real repeats make it impossible to handle partial matching (maybe + one day we will be able to remove this restriction). */ + + if (repeat_max != 1) + cd->nopartial = TRUE; + + if (repeat_min == 0 && repeat_max == -1) + *code++ = OP_CRSTAR + repeat_type; + else if (repeat_min == 1 && repeat_max == -1) + *code++ = OP_CRPLUS + repeat_type; + else if (repeat_min == 0 && repeat_max == 1) + *code++ = OP_CRQUERY + repeat_type; + else { + *code++ = OP_CRRANGE + repeat_type; + PUT2INC(code, 0, repeat_min); + if (repeat_max == -1) + repeat_max = 0; /* 2-byte encoding for max */ + PUT2INC(code, 0, repeat_max); + } } /* If previous was a bracket group, we may have to replicate it in certain cases. */ else if (*previous >= OP_BRA || *previous == OP_ONCE || - *previous == OP_COND) { - register int i; - int ketoffset = 0; - int len = code - previous; - uschar *bralink = NULL; - - /* If the maximum repeat count is unlimited, find the end of the bracket - by scanning through from the start, and compute the offset back to it - from the current code pointer. There may be an OP_OPT setting following - the final KET, so we can't find the end just by going back from the code - pointer. */ - - if (repeat_max == -1) { - register uschar *ket = previous; - do - ket += GET(ket, 1); - while (*ket != OP_KET); - ketoffset = code - ket; - } - - /* The case of a zero minimum is special because of the need to stick - OP_BRAZERO in front of it, and because the group appears once in the - data, whereas in other cases it appears the minimum number of times. For - this reason, it is simplest to treat this case separately, as otherwise - the code gets far too messy. There are several special subcases when the - minimum is zero. */ - - if (repeat_min == 0) { - /* If the maximum is also zero, we just omit the group from the output - altogether. */ - - if (repeat_max == 0) { - code = previous; - goto END_REPEAT; - } - - /* If the maximum is 1 or unlimited, we just have to stick in the - BRAZERO and do no more at this point. However, we do need to adjust - any OP_RECURSE calls inside the group that refer to the group itself or - any internal group, because the offset is from the start of the whole - regex. Temporarily terminate the pattern while doing this. */ - - if (repeat_max <= 1) { - *code = OP_END; - adjust_recurse(previous, 1, utf8, cd); - memmove(previous + 1, previous, len); - code++; - *previous++ = OP_BRAZERO + repeat_type; - } - - /* If the maximum is greater than 1 and limited, we have to replicate - in a nested fashion, sticking OP_BRAZERO before each set of brackets. - The first one has to be handled carefully because it's the original - copy, which has to be moved up. The remainder can be handled by code - that is common with the non-zero minimum case below. We have to - adjust the value or repeat_max, since one less copy is required. Once - again, we may have to adjust any OP_RECURSE calls inside the group. */ - - else { - int offset; - *code = OP_END; - adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd); - memmove(previous + 2 + LINK_SIZE, previous, len); - code += 2 + LINK_SIZE; - *previous++ = OP_BRAZERO + repeat_type; - *previous++ = OP_BRA; - - /* We chain together the bracket offset fields that have to be - filled in later when the ends of the brackets are reached. */ - - offset = (bralink == NULL) ? 0 : previous - bralink; - bralink = previous; - PUTINC(previous, 0, offset); - } - - repeat_max--; - } - - /* If the minimum is greater than zero, replicate the group as many - times as necessary, and adjust the maximum to the number of subsequent - copies that we need. If we set a first char from the group, and didn't - set a required char, copy the latter from the former. */ - - else { - if (repeat_min > 1) { - if (groupsetfirstbyte && reqbyte < 0) - reqbyte = firstbyte; - for (i = 1; i < repeat_min; i++) { - memcpy(code, previous, len); - code += len; - } - } - if (repeat_max > 0) - repeat_max -= repeat_min; - } - - /* This code is common to both the zero and non-zero minimum cases. If - the maximum is limited, it replicates the group in a nested fashion, - remembering the bracket starts on a stack. In the case of a zero minimum, - the first one was set up above. In all cases the repeat_max now specifies - the number of additional copies needed. */ - - if (repeat_max >= 0) { - for (i = repeat_max - 1; i >= 0; i--) { - *code++ = OP_BRAZERO + repeat_type; - - /* All but the final copy start a new nesting, maintaining the - chain of brackets outstanding. */ - - if (i != 0) { - int offset; - *code++ = OP_BRA; - offset = (bralink == NULL) ? 0 : code - bralink; - bralink = code; - PUTINC(code, 0, offset); - } - - memcpy(code, previous, len); - code += len; - } - - /* Now chain through the pending brackets, and fill in their length - fields (which are holding the chain links pro tem). */ - - while (bralink != NULL) { - int oldlinkoffset; - int offset = code - bralink + 1; - uschar *bra = code - offset; - oldlinkoffset = GET(bra, 1); - bralink = (oldlinkoffset == 0) ? NULL : bralink - oldlinkoffset; - *code++ = OP_KET; - PUTINC(code, 0, offset); - PUT(bra, 1, offset); - } - } - - /* If the maximum is unlimited, set a repeater in the final copy. We - can't just offset backwards from the current code point, because we - don't know if there's been an options resetting after the ket. The - correct offset was computed above. */ - - else - code[-ketoffset] = OP_KETRMAX + repeat_type; + *previous == OP_COND) { + register int i; + int ketoffset = 0; + int len = code - previous; + uschar *bralink = NULL; + + /* If the maximum repeat count is unlimited, find the end of the bracket + by scanning through from the start, and compute the offset back to it + from the current code pointer. There may be an OP_OPT setting following + the final KET, so we can't find the end just by going back from the code + pointer. */ + + if (repeat_max == -1) { + register uschar *ket = previous; + do + ket += GET(ket, 1); + while (*ket != OP_KET); + ketoffset = code - ket; + } + + /* The case of a zero minimum is special because of the need to stick + OP_BRAZERO in front of it, and because the group appears once in the + data, whereas in other cases it appears the minimum number of times. For + this reason, it is simplest to treat this case separately, as otherwise + the code gets far too messy. There are several special subcases when the + minimum is zero. */ + + if (repeat_min == 0) { + /* If the maximum is also zero, we just omit the group from the output + altogether. */ + + if (repeat_max == 0) { + code = previous; + goto END_REPEAT; + } + + /* If the maximum is 1 or unlimited, we just have to stick in the + BRAZERO and do no more at this point. However, we do need to adjust + any OP_RECURSE calls inside the group that refer to the group itself or + any internal group, because the offset is from the start of the whole + regex. Temporarily terminate the pattern while doing this. */ + + if (repeat_max <= 1) { + *code = OP_END; + adjust_recurse(previous, 1, utf8, cd); + memmove(previous + 1, previous, len); + code++; + *previous++ = OP_BRAZERO + repeat_type; + } + + /* If the maximum is greater than 1 and limited, we have to replicate + in a nested fashion, sticking OP_BRAZERO before each set of brackets. + The first one has to be handled carefully because it's the original + copy, which has to be moved up. The remainder can be handled by code + that is common with the non-zero minimum case below. We have to + adjust the value or repeat_max, since one less copy is required. Once + again, we may have to adjust any OP_RECURSE calls inside the group. */ + + else { + int offset; + *code = OP_END; + adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd); + memmove(previous + 2 + LINK_SIZE, previous, len); + code += 2 + LINK_SIZE; + *previous++ = OP_BRAZERO + repeat_type; + *previous++ = OP_BRA; + + /* We chain together the bracket offset fields that have to be + filled in later when the ends of the brackets are reached. */ + + offset = (bralink == NULL) ? 0 : previous - bralink; + bralink = previous; + PUTINC(previous, 0, offset); + } + + repeat_max--; + } + + /* If the minimum is greater than zero, replicate the group as many + times as necessary, and adjust the maximum to the number of subsequent + copies that we need. If we set a first char from the group, and didn't + set a required char, copy the latter from the former. */ + + else { + if (repeat_min > 1) { + if (groupsetfirstbyte && reqbyte < 0) + reqbyte = firstbyte; + for (i = 1; i < repeat_min; i++) { + memcpy(code, previous, len); + code += len; + } + } + if (repeat_max > 0) + repeat_max -= repeat_min; + } + + /* This code is common to both the zero and non-zero minimum cases. If + the maximum is limited, it replicates the group in a nested fashion, + remembering the bracket starts on a stack. In the case of a zero minimum, + the first one was set up above. In all cases the repeat_max now specifies + the number of additional copies needed. */ + + if (repeat_max >= 0) { + for (i = repeat_max - 1; i >= 0; i--) { + *code++ = OP_BRAZERO + repeat_type; + + /* All but the final copy start a new nesting, maintaining the + chain of brackets outstanding. */ + + if (i != 0) { + int offset; + *code++ = OP_BRA; + offset = (bralink == NULL) ? 0 : code - bralink; + bralink = code; + PUTINC(code, 0, offset); + } + + memcpy(code, previous, len); + code += len; + } + + /* Now chain through the pending brackets, and fill in their length + fields (which are holding the chain links pro tem). */ + + while (bralink != NULL) { + int oldlinkoffset; + int offset = code - bralink + 1; + uschar *bra = code - offset; + oldlinkoffset = GET(bra, 1); + bralink = (oldlinkoffset == 0) ? NULL : bralink - oldlinkoffset; + *code++ = OP_KET; + PUTINC(code, 0, offset); + PUT(bra, 1, offset); + } + } + + /* If the maximum is unlimited, set a repeater in the final copy. We + can't just offset backwards from the current code point, because we + don't know if there's been an options resetting after the ket. The + correct offset was computed above. */ + + else + code[-ketoffset] = OP_KETRMAX + repeat_type; } /* Else there's some kind of shambles */ else { - *errorcodeptr = ERR11; - goto FAILED; + *errorcodeptr = ERR11; + goto FAILED; } /* If the character following a repeat is '+', we wrap the entire repeated @@ -4349,14 +4349,14 @@ case status of the value. This is used only for ASCII characters. */ repeated. However, we don't support '+' after a greediness '?'. */ if (possessive_quantifier) { - int len = code - tempcode; - memmove(tempcode + 1 + LINK_SIZE, tempcode, len); - code += 1 + LINK_SIZE; - len += 1 + LINK_SIZE; - tempcode[0] = OP_ONCE; - *code++ = OP_KET; - PUTINC(code, 0, len); - PUT(tempcode, 1, len); + int len = code - tempcode; + memmove(tempcode + 1 + LINK_SIZE, tempcode, len); + code += 1 + LINK_SIZE; + len += 1 + LINK_SIZE; + tempcode[0] = OP_ONCE; + *code++ = OP_KET; + PUTINC(code, 0, len); + PUT(tempcode, 1, len); } /* In all case we no longer have a previous item. We also set the @@ -4381,317 +4381,317 @@ case status of the value. This is used only for ASCII characters. */ skipbytes = 0; if (*(++ptr) == '?') { - int set, unset; - int *optset; - - switch (*(++ptr)) { - case '#': /* Comment; skip to ket */ - ptr++; - while (*ptr != ')') - ptr++; - continue; - - case ':': /* Non-extracting bracket */ - bravalue = OP_BRA; - ptr++; - break; - - case '(': - bravalue = OP_COND; /* Conditional group */ - - /* Condition to test for recursion */ - - if (ptr[1] == 'R') { - code[1 + LINK_SIZE] = OP_CREF; - PUT2(code, 2 + LINK_SIZE, CREF_RECURSE); - skipbytes = 3; - ptr += 3; - } - - /* Condition to test for a numbered subpattern match. We know that - if a digit follows ( then there will just be digits until ) because - the syntax was checked in the first pass. */ - - else if ((digitab[ptr[1]] && ctype_digit) != 0) { - int condref; /* Don't amalgamate; some compilers */ - condref = *(++ptr) - '0'; /* grumble at autoincrement in declaration */ - while (*(++ptr) != ')') - condref = condref * 10 + *ptr - '0'; - if (condref == 0) { - *errorcodeptr = ERR35; - goto FAILED; - } - ptr++; - code[1 + LINK_SIZE] = OP_CREF; - PUT2(code, 2 + LINK_SIZE, condref); - skipbytes = 3; - } - /* For conditions that are assertions, we just fall through, having - set bravalue above. */ - break; - - case '=': /* Positive lookahead */ - bravalue = OP_ASSERT; - ptr++; - break; - - case '!': /* Negative lookahead */ - bravalue = OP_ASSERT_NOT; - ptr++; - break; - - case '<': /* Lookbehinds */ - switch (*(++ptr)) { - case '=': /* Positive lookbehind */ - bravalue = OP_ASSERTBACK; - ptr++; - break; - - case '!': /* Negative lookbehind */ - bravalue = OP_ASSERTBACK_NOT; - ptr++; - break; - } - break; - - case '>': /* One-time brackets */ - bravalue = OP_ONCE; - ptr++; - break; - - case 'C': /* Callout - may be followed by digits; */ - previous_callout = code; /* Save for later completion */ - after_manual_callout = 1; /* Skip one item before completing */ - *code++ = OP_CALLOUT; /* Already checked that the terminating */ - { /* closing parenthesis is present. */ - int n = 0; - while ((digitab[*(++ptr)] & ctype_digit) != 0) - n = n * 10 + *ptr - '0'; - if (n > 255) { - *errorcodeptr = ERR38; - goto FAILED; - } - *code++ = n; - PUT(code, 0, ptr - cd->start_pattern + 1); /* Pattern offset */ - PUT(code, LINK_SIZE, 0); /* Default length */ - code += 2 * LINK_SIZE; - } - previous = NULL; - continue; - - case 'P': /* Named subpattern handling */ - if (*(++ptr) == '<') { /* Definition */ - int i, namelen; - uschar *slot = cd->name_table; - const uschar *name; /* Don't amalgamate; some compilers */ - name = ++ptr; /* grumble at autoincrement in declaration */ - - while (*ptr++ != '>') ; - namelen = ptr - name - 1; - - for (i = 0; i < cd->names_found; i++) { - int crc = memcmp(name, slot + 2, namelen); - if (crc == 0) { - if (slot[2 + namelen] == 0) { - *errorcodeptr = ERR43; - goto FAILED; - } - crc = -1; /* Current name is substring */ - } - if (crc < 0) { - memmove(slot + cd->name_entry_size, slot, - (cd->names_found - i) * cd->name_entry_size); - break; - } - slot += cd->name_entry_size; - } - - PUT2(slot, 0, *brackets + 1); - memcpy(slot + 2, name, namelen); - slot[2 + namelen] = 0; - cd->names_found++; - goto NUMBERED_GROUP; - } - - if (*ptr == '=' || *ptr == '>') { /* Reference or recursion */ - int i, namelen; - int type = *ptr++; - const uschar *name = ptr; - uschar *slot = cd->name_table; - - while (*ptr != ')') - ptr++; - namelen = ptr - name; - - for (i = 0; i < cd->names_found; i++) { - if (strncmp((char *) name, (char *) slot + 2, namelen) == 0) - break; - slot += cd->name_entry_size; - } - if (i >= cd->names_found) { - *errorcodeptr = ERR15; - goto FAILED; - } - - recno = GET2(slot, 0); - - if (type == '>') - goto HANDLE_RECURSION; /* A few lines below */ - - /* Back reference */ - - previous = code; - *code++ = OP_REF; - PUT2INC(code, 0, recno); - cd->backref_map |= (recno < 32) ? (1 << recno) : 1; - if (recno > cd->top_backref) - cd->top_backref = recno; - continue; - } - - /* Should never happen */ - break; - - case 'R': /* Pattern recursion */ - ptr++; /* Same as (?0) */ - /* Fall through */ - - /* Recursion or "subroutine" call */ - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - const uschar *called; - recno = 0; - while ((digitab[*ptr] & ctype_digit) != 0) - recno = recno * 10 + *ptr++ - '0'; - - /* Come here from code above that handles a named recursion */ - - HANDLE_RECURSION: - - previous = code; - - /* Find the bracket that is being referenced. Temporarily end the - regex in case it doesn't exist. */ - - *code = OP_END; - called = (recno == 0) ? - cd->start_code : find_bracket(cd->start_code, utf8, recno); - - if (called == NULL) { - *errorcodeptr = ERR15; - goto FAILED; - } - - /* If the subpattern is still open, this is a recursive call. We - check to see if this is a left recursion that could loop for ever, - and diagnose that case. */ - - if (GET(called, 1) == 0 - && could_be_empty(called, code, bcptr, utf8)) { - *errorcodeptr = ERR40; - goto FAILED; - } - - /* Insert the recursion/subroutine item */ - - *code = OP_RECURSE; - PUT(code, 1, called - cd->start_code); - code += 1 + LINK_SIZE; - } - continue; - - /* Character after (? not specially recognized */ - - default: /* Option setting */ - set = unset = 0; - optset = &set; - - while (*ptr != ')' && *ptr != ':') { - switch (*ptr++) { - case '-': - optset = &unset; - break; - - case 'i': - *optset |= PCRE_CASELESS; - break; - case 'm': - *optset |= PCRE_MULTILINE; - break; - case 's': - *optset |= PCRE_DOTALL; - break; - case 'x': - *optset |= PCRE_EXTENDED; - break; - case 'U': - *optset |= PCRE_UNGREEDY; - break; - case 'X': - *optset |= PCRE_EXTRA; - break; - } - } - - /* Set up the changed option bits, but don't change anything yet. */ - - newoptions = (options | set) & (~unset); - - /* If the options ended with ')' this is not the start of a nested - group with option changes, so the options change at this level. Compile - code to change the ims options if this setting actually changes any of - them. We also pass the new setting back so that it can be put at the - start of any following branches, and when this group ends (if we are in - a group), a resetting item can be compiled. - - Note that if this item is right at the start of the pattern, the - options will have been abstracted and made global, so there will be no - change to compile. */ - - if (*ptr == ')') { - if ((options & PCRE_IMS) != (newoptions & PCRE_IMS)) { - *code++ = OP_OPT; - *code++ = newoptions & PCRE_IMS; - } - - /* Change options at this level, and pass them back for use - in subsequent branches. Reset the greedy defaults and the case - value for firstbyte and reqbyte. */ - - *optionsptr = options = newoptions; - greedy_default = ((newoptions & PCRE_UNGREEDY) != 0); - greedy_non_default = greedy_default ^ 1; - req_caseopt = ((options & PCRE_CASELESS) != 0) ? REQ_CASELESS : 0; - - previous = NULL; /* This item can't be repeated */ - continue; /* It is complete */ - } - - /* If the options ended with ':' we are heading into a nested group - with possible change of options. Such groups are non-capturing and are - not assertions of any kind. All we need to do is skip over the ':'; - the newoptions value is handled below. */ - - bravalue = OP_BRA; - ptr++; - } + int set, unset; + int *optset; + + switch (*(++ptr)) { + case '#': /* Comment; skip to ket */ + ptr++; + while (*ptr != ')') + ptr++; + continue; + + case ':': /* Non-extracting bracket */ + bravalue = OP_BRA; + ptr++; + break; + + case '(': + bravalue = OP_COND; /* Conditional group */ + + /* Condition to test for recursion */ + + if (ptr[1] == 'R') { + code[1 + LINK_SIZE] = OP_CREF; + PUT2(code, 2 + LINK_SIZE, CREF_RECURSE); + skipbytes = 3; + ptr += 3; + } + + /* Condition to test for a numbered subpattern match. We know that + if a digit follows ( then there will just be digits until ) because + the syntax was checked in the first pass. */ + + else if ((digitab[ptr[1]] && ctype_digit) != 0) { + int condref; /* Don't amalgamate; some compilers */ + condref = *(++ptr) - '0'; /* grumble at autoincrement in declaration */ + while (*(++ptr) != ')') + condref = condref * 10 + *ptr - '0'; + if (condref == 0) { + *errorcodeptr = ERR35; + goto FAILED; + } + ptr++; + code[1 + LINK_SIZE] = OP_CREF; + PUT2(code, 2 + LINK_SIZE, condref); + skipbytes = 3; + } + /* For conditions that are assertions, we just fall through, having + set bravalue above. */ + break; + + case '=': /* Positive lookahead */ + bravalue = OP_ASSERT; + ptr++; + break; + + case '!': /* Negative lookahead */ + bravalue = OP_ASSERT_NOT; + ptr++; + break; + + case '<': /* Lookbehinds */ + switch (*(++ptr)) { + case '=': /* Positive lookbehind */ + bravalue = OP_ASSERTBACK; + ptr++; + break; + + case '!': /* Negative lookbehind */ + bravalue = OP_ASSERTBACK_NOT; + ptr++; + break; + } + break; + + case '>': /* One-time brackets */ + bravalue = OP_ONCE; + ptr++; + break; + + case 'C': /* Callout - may be followed by digits; */ + previous_callout = code; /* Save for later completion */ + after_manual_callout = 1; /* Skip one item before completing */ + *code++ = OP_CALLOUT; /* Already checked that the terminating */ + { /* closing parenthesis is present. */ + int n = 0; + while ((digitab[*(++ptr)] & ctype_digit) != 0) + n = n * 10 + *ptr - '0'; + if (n > 255) { + *errorcodeptr = ERR38; + goto FAILED; + } + *code++ = n; + PUT(code, 0, ptr - cd->start_pattern + 1); /* Pattern offset */ + PUT(code, LINK_SIZE, 0); /* Default length */ + code += 2 * LINK_SIZE; + } + previous = NULL; + continue; + + case 'P': /* Named subpattern handling */ + if (*(++ptr) == '<') { /* Definition */ + int i, namelen; + uschar *slot = cd->name_table; + const uschar *name; /* Don't amalgamate; some compilers */ + name = ++ptr; /* grumble at autoincrement in declaration */ + + while (*ptr++ != '>') ; + namelen = ptr - name - 1; + + for (i = 0; i < cd->names_found; i++) { + int crc = memcmp(name, slot + 2, namelen); + if (crc == 0) { + if (slot[2 + namelen] == 0) { + *errorcodeptr = ERR43; + goto FAILED; + } + crc = -1; /* Current name is substring */ + } + if (crc < 0) { + memmove(slot + cd->name_entry_size, slot, + (cd->names_found - i) * cd->name_entry_size); + break; + } + slot += cd->name_entry_size; + } + + PUT2(slot, 0, *brackets + 1); + memcpy(slot + 2, name, namelen); + slot[2 + namelen] = 0; + cd->names_found++; + goto NUMBERED_GROUP; + } + + if (*ptr == '=' || *ptr == '>') { /* Reference or recursion */ + int i, namelen; + int type = *ptr++; + const uschar *name = ptr; + uschar *slot = cd->name_table; + + while (*ptr != ')') + ptr++; + namelen = ptr - name; + + for (i = 0; i < cd->names_found; i++) { + if (strncmp((char *) name, (char *) slot + 2, namelen) == 0) + break; + slot += cd->name_entry_size; + } + if (i >= cd->names_found) { + *errorcodeptr = ERR15; + goto FAILED; + } + + recno = GET2(slot, 0); + + if (type == '>') + goto HANDLE_RECURSION; /* A few lines below */ + + /* Back reference */ + + previous = code; + *code++ = OP_REF; + PUT2INC(code, 0, recno); + cd->backref_map |= (recno < 32) ? (1 << recno) : 1; + if (recno > cd->top_backref) + cd->top_backref = recno; + continue; + } + + /* Should never happen */ + break; + + case 'R': /* Pattern recursion */ + ptr++; /* Same as (?0) */ + /* Fall through */ + + /* Recursion or "subroutine" call */ + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + const uschar *called; + recno = 0; + while ((digitab[*ptr] & ctype_digit) != 0) + recno = recno * 10 + *ptr++ - '0'; + + /* Come here from code above that handles a named recursion */ + + HANDLE_RECURSION: + + previous = code; + + /* Find the bracket that is being referenced. Temporarily end the + regex in case it doesn't exist. */ + + *code = OP_END; + called = (recno == 0) ? + cd->start_code : find_bracket(cd->start_code, utf8, recno); + + if (called == NULL) { + *errorcodeptr = ERR15; + goto FAILED; + } + + /* If the subpattern is still open, this is a recursive call. We + check to see if this is a left recursion that could loop for ever, + and diagnose that case. */ + + if (GET(called, 1) == 0 + && could_be_empty(called, code, bcptr, utf8)) { + *errorcodeptr = ERR40; + goto FAILED; + } + + /* Insert the recursion/subroutine item */ + + *code = OP_RECURSE; + PUT(code, 1, called - cd->start_code); + code += 1 + LINK_SIZE; + } + continue; + + /* Character after (? not specially recognized */ + + default: /* Option setting */ + set = unset = 0; + optset = &set; + + while (*ptr != ')' && *ptr != ':') { + switch (*ptr++) { + case '-': + optset = &unset; + break; + + case 'i': + *optset |= PCRE_CASELESS; + break; + case 'm': + *optset |= PCRE_MULTILINE; + break; + case 's': + *optset |= PCRE_DOTALL; + break; + case 'x': + *optset |= PCRE_EXTENDED; + break; + case 'U': + *optset |= PCRE_UNGREEDY; + break; + case 'X': + *optset |= PCRE_EXTRA; + break; + } + } + + /* Set up the changed option bits, but don't change anything yet. */ + + newoptions = (options | set) & (~unset); + + /* If the options ended with ')' this is not the start of a nested + group with option changes, so the options change at this level. Compile + code to change the ims options if this setting actually changes any of + them. We also pass the new setting back so that it can be put at the + start of any following branches, and when this group ends (if we are in + a group), a resetting item can be compiled. + + Note that if this item is right at the start of the pattern, the + options will have been abstracted and made global, so there will be no + change to compile. */ + + if (*ptr == ')') { + if ((options & PCRE_IMS) != (newoptions & PCRE_IMS)) { + *code++ = OP_OPT; + *code++ = newoptions & PCRE_IMS; + } + + /* Change options at this level, and pass them back for use + in subsequent branches. Reset the greedy defaults and the case + value for firstbyte and reqbyte. */ + + *optionsptr = options = newoptions; + greedy_default = ((newoptions & PCRE_UNGREEDY) != 0); + greedy_non_default = greedy_default ^ 1; + req_caseopt = ((options & PCRE_CASELESS) != 0) ? REQ_CASELESS : 0; + + previous = NULL; /* This item can't be repeated */ + continue; /* It is complete */ + } + + /* If the options ended with ':' we are heading into a nested group + with possible change of options. Such groups are non-capturing and are + not assertions of any kind. All we need to do is skip over the ':'; + the newoptions value is handled below. */ + + bravalue = OP_BRA; + ptr++; + } } /* If PCRE_NO_AUTO_CAPTURE is set, all unadorned brackets become non-capturing and behave like (?:...) brackets */ else if ((options & PCRE_NO_AUTO_CAPTURE) != 0) { - bravalue = OP_BRA; + bravalue = OP_BRA; } /* Else we have a referencing group; adjust the opcode. If the bracket @@ -4700,13 +4700,13 @@ case status of the value. This is used only for ASCII characters. */ else { NUMBERED_GROUP: - if (++(*brackets) > EXTRACT_BASIC_MAX) { - bravalue = OP_BRA + EXTRACT_BASIC_MAX + 1; - code[1 + LINK_SIZE] = OP_BRANUMBER; - PUT2(code, 2 + LINK_SIZE, *brackets); - skipbytes = 3; - } else - bravalue = OP_BRA + *brackets; + if (++(*brackets) > EXTRACT_BASIC_MAX) { + bravalue = OP_BRA + EXTRACT_BASIC_MAX + 1; + code[1 + LINK_SIZE] = OP_BRANUMBER; + PUT2(code, 2 + LINK_SIZE, *brackets); + skipbytes = 3; + } else + bravalue = OP_BRA + *brackets; } /* Process nested bracketed re. Assertions may not be repeated, but other @@ -4717,21 +4717,21 @@ case status of the value. This is used only for ASCII characters. */ previous = (bravalue >= OP_ONCE) ? code : NULL; *code = bravalue; tempcode = code; - tempreqvary = cd->req_varyopt; /* Save value before bracket */ - - if (!compile_regex(newoptions, /* The complete new option state */ - options & PCRE_IMS, /* The previous ims option state */ - brackets, /* Extracting bracket count */ - &tempcode, /* Where to put code (updated) */ - &ptr, /* Input pointer (updated) */ - errorcodeptr, /* Where to put an error message */ - (bravalue == OP_ASSERTBACK || bravalue == OP_ASSERTBACK_NOT), /* TRUE if back assert */ - skipbytes, /* Skip over OP_COND/OP_BRANUMBER */ - &subfirstbyte, /* For possible first char */ - &subreqbyte, /* For possible last char */ - bcptr, /* Current branch chain */ - cd)) /* Tables block */ - goto FAILED; + tempreqvary = cd->req_varyopt; /* Save value before bracket */ + + if (!compile_regex(newoptions, /* The complete new option state */ + options & PCRE_IMS, /* The previous ims option state */ + brackets, /* Extracting bracket count */ + &tempcode, /* Where to put code (updated) */ + &ptr, /* Input pointer (updated) */ + errorcodeptr, /* Where to put an error message */ + (bravalue == OP_ASSERTBACK || bravalue == OP_ASSERTBACK_NOT), /* TRUE if back assert */ + skipbytes, /* Skip over OP_COND/OP_BRANUMBER */ + &subfirstbyte, /* For possible first char */ + &subreqbyte, /* For possible last char */ + bcptr, /* Current branch chain */ + cd)) /* Tables block */ + goto FAILED; /* At the end of compiling, code is still pointing to the start of the group, while tempcode has been updated to point past the end of the group @@ -4742,25 +4742,25 @@ case status of the value. This is used only for ASCII characters. */ two branches in the group. */ else if (bravalue == OP_COND) { - uschar *tc = code; - condcount = 0; + uschar *tc = code; + condcount = 0; - do { - condcount++; - tc += GET(tc, 1); - } - while (*tc != OP_KET); + do { + condcount++; + tc += GET(tc, 1); + } + while (*tc != OP_KET); - if (condcount > 2) { - *errorcodeptr = ERR27; - goto FAILED; - } + if (condcount > 2) { + *errorcodeptr = ERR27; + goto FAILED; + } - /* If there is just one branch, we must not make use of its firstbyte or - reqbyte, because this is equivalent to an empty second branch. */ + /* If there is just one branch, we must not make use of its firstbyte or + reqbyte, because this is equivalent to an empty second branch. */ - if (condcount == 1) - subfirstbyte = subreqbyte = REQ_NONE; + if (condcount == 1) + subfirstbyte = subreqbyte = REQ_NONE; } /* Handle updating of the required and first characters. Update for normal @@ -4774,33 +4774,33 @@ case status of the value. This is used only for ASCII characters. */ groupsetfirstbyte = FALSE; if (bravalue >= OP_BRA || bravalue == OP_ONCE || bravalue == OP_COND) { - /* If we have not yet set a firstbyte in this branch, take it from the - subpattern, remembering that it was set here so that a repeat of more - than one can replicate it as reqbyte if necessary. If the subpattern has - no firstbyte, set "none" for the whole branch. In both cases, a zero - repeat forces firstbyte to "none". */ - - if (firstbyte == REQ_UNSET) { - if (subfirstbyte >= 0) { - firstbyte = subfirstbyte; - groupsetfirstbyte = TRUE; - } else - firstbyte = REQ_NONE; - zerofirstbyte = REQ_NONE; - } - - /* If firstbyte was previously set, convert the subpattern's firstbyte - into reqbyte if there wasn't one, using the vary flag that was in - existence beforehand. */ - - else if (subfirstbyte >= 0 && subreqbyte < 0) - subreqbyte = subfirstbyte | tempreqvary; - - /* If the subpattern set a required byte (or set a first byte that isn't - really the first byte - see above), set it. */ - - if (subreqbyte >= 0) - reqbyte = subreqbyte; + /* If we have not yet set a firstbyte in this branch, take it from the + subpattern, remembering that it was set here so that a repeat of more + than one can replicate it as reqbyte if necessary. If the subpattern has + no firstbyte, set "none" for the whole branch. In both cases, a zero + repeat forces firstbyte to "none". */ + + if (firstbyte == REQ_UNSET) { + if (subfirstbyte >= 0) { + firstbyte = subfirstbyte; + groupsetfirstbyte = TRUE; + } else + firstbyte = REQ_NONE; + zerofirstbyte = REQ_NONE; + } + + /* If firstbyte was previously set, convert the subpattern's firstbyte + into reqbyte if there wasn't one, using the vary flag that was in + existence beforehand. */ + + else if (subfirstbyte >= 0 && subreqbyte < 0) + subreqbyte = subfirstbyte | tempreqvary; + + /* If the subpattern set a required byte (or set a first byte that isn't + really the first byte - see above), set it. */ + + if (subreqbyte >= 0) + reqbyte = subreqbyte; } /* For a forward assertion, we take the reqbyte, if set. This can be @@ -4812,7 +4812,7 @@ case status of the value. This is used only for ASCII characters. */ firstbyte, looking for an asserted first char. */ else if (bravalue == OP_ASSERT && subreqbyte >= 0) - reqbyte = subreqbyte; + reqbyte = subreqbyte; /* Now update the main code pointer to the end of the group. */ @@ -4821,8 +4821,8 @@ case status of the value. This is used only for ASCII characters. */ /* Error if hit end of pattern */ if (*ptr != ')') { - *errorcodeptr = ERR14; - goto FAILED; + *errorcodeptr = ERR14; + goto FAILED; } break; @@ -4842,55 +4842,55 @@ case status of the value. This is used only for ASCII characters. */ have to change if any new ones are ever created. */ if (c < 0) { - if (-c == ESC_Q) { /* Handle start of quoted string */ - if (ptr[1] == '\\' && ptr[2] == 'E') - ptr += 2; /* avoid empty string */ - else - inescq = TRUE; - continue; - } + if (-c == ESC_Q) { /* Handle start of quoted string */ + if (ptr[1] == '\\' && ptr[2] == 'E') + ptr += 2; /* avoid empty string */ + else + inescq = TRUE; + continue; + } - /* For metasequences that actually match a character, we disable the - setting of a first character if it hasn't already been set. */ + /* For metasequences that actually match a character, we disable the + setting of a first character if it hasn't already been set. */ - if (firstbyte == REQ_UNSET && -c > ESC_b && -c < ESC_Z) - firstbyte = REQ_NONE; + if (firstbyte == REQ_UNSET && -c > ESC_b && -c < ESC_Z) + firstbyte = REQ_NONE; - /* Set values to reset to if this is followed by a zero repeat. */ + /* Set values to reset to if this is followed by a zero repeat. */ - zerofirstbyte = firstbyte; - zeroreqbyte = reqbyte; + zerofirstbyte = firstbyte; + zeroreqbyte = reqbyte; - /* Back references are handled specially */ + /* Back references are handled specially */ - if (-c >= ESC_REF) { - int number = -c - ESC_REF; - previous = code; - *code++ = OP_REF; - PUT2INC(code, 0, number); - } + if (-c >= ESC_REF) { + int number = -c - ESC_REF; + previous = code; + *code++ = OP_REF; + PUT2INC(code, 0, number); + } - /* So are Unicode property matches, if supported. We know that get_ucp - won't fail because it was tested in the pre-pass. */ + /* So are Unicode property matches, if supported. We know that get_ucp + won't fail because it was tested in the pre-pass. */ #ifdef SUPPORT_UCP - else if (-c == ESC_P || -c == ESC_p) { - BOOL negated; - int value = get_ucp(&ptr, &negated, errorcodeptr); - previous = code; - *code++ = ((-c == ESC_p) != negated) ? OP_PROP : OP_NOTPROP; - *code++ = value; - } + else if (-c == ESC_P || -c == ESC_p) { + BOOL negated; + int value = get_ucp(&ptr, &negated, errorcodeptr); + previous = code; + *code++ = ((-c == ESC_p) != negated) ? OP_PROP : OP_NOTPROP; + *code++ = value; + } #endif - /* For the rest, we can obtain the OP value by negating the escape - value */ + /* For the rest, we can obtain the OP value by negating the escape + value */ - else { - previous = (-c > ESC_b && -c < ESC_Z) ? code : NULL; - *code++ = -c; - } - continue; + else { + previous = (-c > ESC_b && -c < ESC_Z) ? code : NULL; + *code++ = -c; + } + continue; } /* We have a data character whose value is in c. In UTF-8 mode it may have @@ -4899,8 +4899,8 @@ case status of the value. This is used only for ASCII characters. */ { - mcbuffer[0] = c; - mclength = 1; + mcbuffer[0] = c; + mclength = 1; } goto ONE_CHAR; @@ -4922,7 +4922,7 @@ case status of the value. This is used only for ASCII characters. */ previous = code; *code++ = ((options & PCRE_CASELESS) != 0) ? OP_CHARNC : OP_CHAR; for (c = 0; c < mclength; c++) - *code++ = mcbuffer[c]; + *code++ = mcbuffer[c]; /* Set the first and required bytes appropriately. If no previous first byte, set it from this character, but revert to none on a zero repeat. @@ -4930,33 +4930,33 @@ case status of the value. This is used only for ASCII characters. */ repeat. */ if (firstbyte == REQ_UNSET) { - zerofirstbyte = REQ_NONE; - zeroreqbyte = reqbyte; - - /* If the character is more than one byte long, we can set firstbyte - only if it is not to be matched caselessly. */ - - if (mclength == 1 || req_caseopt == 0) { - firstbyte = mcbuffer[0] | req_caseopt; - if (mclength != 1) - reqbyte = code[-1] | cd->req_varyopt; - } else - firstbyte = reqbyte = REQ_NONE; + zerofirstbyte = REQ_NONE; + zeroreqbyte = reqbyte; + + /* If the character is more than one byte long, we can set firstbyte + only if it is not to be matched caselessly. */ + + if (mclength == 1 || req_caseopt == 0) { + firstbyte = mcbuffer[0] | req_caseopt; + if (mclength != 1) + reqbyte = code[-1] | cd->req_varyopt; + } else + firstbyte = reqbyte = REQ_NONE; } /* firstbyte was previously set; we can set reqbyte only the length is 1 or the matching is caseful. */ else { - zerofirstbyte = firstbyte; - zeroreqbyte = reqbyte; - if (mclength == 1 || req_caseopt == 0) - reqbyte = code[-1] | req_caseopt | cd->req_varyopt; + zerofirstbyte = firstbyte; + zeroreqbyte = reqbyte; + if (mclength == 1 || req_caseopt == 0) + reqbyte = code[-1] | req_caseopt | cd->req_varyopt; } - break; /* End of literal character handling */ + break; /* End of literal character handling */ } - } /* end of big loop */ + } /* end of big loop */ /* Control never reaches here by falling through, only by a goto for all the error states. Pass back the position in the pattern so that it can be displayed @@ -5001,9 +5001,9 @@ Returns: TRUE on success static BOOL compile_regex(int options, int oldims, int *brackets, uschar ** codeptr, - const uschar ** ptrptr, int *errorcodeptr, BOOL lookbehind, - int skipbytes, int *firstbyteptr, int *reqbyteptr, - branch_chain * bcptr, compile_data * cd) + const uschar ** ptrptr, int *errorcodeptr, BOOL lookbehind, + int skipbytes, int *firstbyteptr, int *reqbyteptr, + branch_chain * bcptr, compile_data * cd) { const uschar *ptr = *ptrptr; uschar *code = *codeptr; @@ -5045,7 +5045,7 @@ compile_regex(int options, int oldims, int *brackets, uschar ** codeptr, /* Now compile the branch */ if (!compile_branch(&options, brackets, &code, &ptr, errorcodeptr, - &branchfirstbyte, &branchreqbyte, &bc, cd)) { + &branchfirstbyte, &branchreqbyte, &bc, cd)) { *ptrptr = ptr; return FALSE; } @@ -5069,23 +5069,23 @@ compile_regex(int options, int oldims, int *brackets, uschar ** codeptr, no reqbyte, it takes on the value of the old firstbyte. */ if (firstbyte >= 0 && firstbyte != branchfirstbyte) { - if (reqbyte < 0) - reqbyte = firstbyte; - firstbyte = REQ_NONE; + if (reqbyte < 0) + reqbyte = firstbyte; + firstbyte = REQ_NONE; } /* If we (now or from before) have no firstbyte, a firstbyte from the branch becomes a reqbyte if there isn't a branch reqbyte. */ if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0) - branchreqbyte = branchfirstbyte; + branchreqbyte = branchfirstbyte; /* Now ensure that the reqbytes match */ if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY)) - reqbyte = REQ_NONE; + reqbyte = REQ_NONE; else - reqbyte |= branchreqbyte; /* To "or" REQ_VARY */ + reqbyte |= branchreqbyte; /* To "or" REQ_VARY */ } /* If lookbehind, check that this branch matches a fixed-length string, @@ -5097,9 +5097,9 @@ compile_regex(int options, int oldims, int *brackets, uschar ** codeptr, *code = OP_END; length = find_fixedlength(last_branch, options); if (length < 0) { - *errorcodeptr = (length == -2) ? ERR36 : ERR25; - *ptrptr = ptr; - return FALSE; + *errorcodeptr = (length == -2) ? ERR36 : ERR25; + *ptrptr = ptr; + return FALSE; } PUT(reverse_count, 0, length); } @@ -5116,10 +5116,10 @@ compile_regex(int options, int oldims, int *brackets, uschar ** codeptr, if (*ptr != '|') { int length = code - last_branch; do { - int prev_length = GET(last_branch, 1); - PUT(last_branch, 1, length); - length = prev_length; - last_branch -= length; + int prev_length = GET(last_branch, 1); + PUT(last_branch, 1, length); + length = prev_length; + last_branch -= length; } while (length > 0); @@ -5132,8 +5132,8 @@ compile_regex(int options, int oldims, int *brackets, uschar ** codeptr, /* Resetting option if needed */ if ((options & PCRE_IMS) != oldims && *ptr == ')') { - *code++ = OP_OPT; - *code++ = oldims; + *code++ = OP_OPT; + *code++ = oldims; } /* Set values to pass back */ @@ -5202,12 +5202,12 @@ Returns: TRUE or FALSE static BOOL is_anchored(register const uschar * code, int *options, - unsigned int bracket_map, unsigned int backref_map) + unsigned int bracket_map, unsigned int backref_map) { do { const uschar *scode = first_significant_code(code + 1 + LINK_SIZE, options, PCRE_MULTILINE, - FALSE); + FALSE); register int op = *scode; /* Capturing brackets */ @@ -5216,36 +5216,36 @@ is_anchored(register const uschar * code, int *options, int new_map; op -= OP_BRA; if (op > EXTRACT_BASIC_MAX) - op = GET2(scode, 2 + LINK_SIZE); + op = GET2(scode, 2 + LINK_SIZE); new_map = bracket_map | ((op < 32) ? (1 << op) : 1); if (!is_anchored(scode, options, new_map, backref_map)) - return FALSE; + return FALSE; } /* Other brackets */ else if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND) { if (!is_anchored(scode, options, bracket_map, backref_map)) - return FALSE; + return FALSE; } /* .* is not anchored unless DOTALL is set and it isn't in brackets that are or may be referenced. */ else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR) && - (*options & PCRE_DOTALL) != 0) { + (*options & PCRE_DOTALL) != 0) { if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) - return FALSE; + return FALSE; } /* Check for explicit anchoring */ else if (op != OP_SOD && op != OP_SOM && - ((*options & PCRE_MULTILINE) != 0 || op != OP_CIRC)) + ((*options & PCRE_MULTILINE) != 0 || op != OP_CIRC)) return FALSE; code += GET(code, 1); } - while (*code == OP_ALT); /* Loop for each alternative */ + while (*code == OP_ALT); /* Loop for each alternative */ return TRUE; } @@ -5274,11 +5274,11 @@ Returns: TRUE or FALSE static BOOL is_startline(const uschar * code, unsigned int bracket_map, - unsigned int backref_map) + unsigned int backref_map) { do { const uschar *scode = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, - FALSE); + FALSE); register int op = *scode; /* Capturing brackets */ @@ -5287,17 +5287,17 @@ is_startline(const uschar * code, unsigned int bracket_map, int new_map; op -= OP_BRA; if (op > EXTRACT_BASIC_MAX) - op = GET2(scode, 2 + LINK_SIZE); + op = GET2(scode, 2 + LINK_SIZE); new_map = bracket_map | ((op < 32) ? (1 << op) : 1); if (!is_startline(scode, new_map, backref_map)) - return FALSE; + return FALSE; } /* Other brackets */ else if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND) { if (!is_startline(scode, bracket_map, backref_map)) - return FALSE; + return FALSE; } /* .* means "start at start or after \n" if it isn't in brackets that @@ -5305,7 +5305,7 @@ is_startline(const uschar * code, unsigned int bracket_map, else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR) { if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) - return FALSE; + return FALSE; } /* Check for explicit circumflex */ @@ -5317,7 +5317,7 @@ is_startline(const uschar * code, unsigned int bracket_map, code += GET(code, 1); } - while (*code == OP_ALT); /* Loop for each alternative */ + while (*code == OP_ALT); /* Loop for each alternative */ return TRUE; } @@ -5351,7 +5351,7 @@ find_firstassertedchar(const uschar * code, int *options, BOOL inassert) int d; const uschar *scode = first_significant_code(code + 1 + LINK_SIZE, options, PCRE_CASELESS, - TRUE); + TRUE); register int op = *scode; if (op >= OP_BRA) @@ -5366,14 +5366,14 @@ find_firstassertedchar(const uschar * code, int *options, BOOL inassert) case OP_ONCE: case OP_COND: if ((d = find_firstassertedchar(scode, options, op == OP_ASSERT)) < 0) - return -1; + return -1; if (c < 0) - c = d; + c = d; else if (c != d) - return -1; + return -1; break; - case OP_EXACT: /* Fall through */ + case OP_EXACT: /* Fall through */ scode += 2; case OP_CHAR: @@ -5381,13 +5381,13 @@ find_firstassertedchar(const uschar * code, int *options, BOOL inassert) case OP_PLUS: case OP_MINPLUS: if (!inassert) - return -1; + return -1; if (c < 0) { - c = scode[1]; - if ((*options & PCRE_CASELESS) != 0) - c |= REQ_CASELESS; + c = scode[1]; + if ((*options & PCRE_CASELESS) != 0) + c |= REQ_CASELESS; } else if (c != scode[1]) - return -1; + return -1; break; } @@ -5399,7 +5399,7 @@ find_firstassertedchar(const uschar * code, int *options, BOOL inassert) pcre *pcre_compile2(const char *, int, int *, const char **, - int *, const unsigned char *); + int *, const unsigned char *); /************************************************* @@ -5426,7 +5426,7 @@ Returns: pointer to compiled data block, or NULL on error, pcre * pcre_compile(const char *pattern, int options, const char **errorptr, - int *erroroffset, const unsigned char *tables) + int *erroroffset, const unsigned char *tables) { return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables); } @@ -5434,11 +5434,11 @@ pcre_compile(const char *pattern, int options, const char **errorptr, pcre * pcre_compile2(const char *pattern, int options, int *errorcodeptr, - const char **errorptr, int *erroroffset, - const unsigned char *tables) + const char **errorptr, int *erroroffset, + const unsigned char *tables) { real_pcre *re; - int length = 1 + LINK_SIZE; /* For initial BRA plus length */ + int length = 1 + LINK_SIZE; /* For initial BRA plus length */ int c, firstbyte, reqbyte; int bracount = 0; int branch_extra = 0; @@ -5531,7 +5531,7 @@ pattern. We can't be so clever for #-comments. */ if (inescq) { if ((options & PCRE_AUTO_CALLOUT) != 0) - length += 2 + 2 * LINK_SIZE; + length += 2 + 2 * LINK_SIZE; goto NORMAL_CHAR; } @@ -5539,24 +5539,24 @@ pattern. We can't be so clever for #-comments. */ if ((options & PCRE_EXTENDED) != 0) { if ((compile_block.ctypes[c] & ctype_space) != 0) - continue; + continue; if (c == '#') { - /* The space before the ; is to avoid a warning on a silly compiler - on the Macintosh. */ - while ((c = *(++ptr)) != 0 && c != NEWLINE) ; - if (c == 0) - break; - continue; + /* The space before the ; is to avoid a warning on a silly compiler + on the Macintosh. */ + while ((c = *(++ptr)) != 0 && c != NEWLINE) ; + if (c == 0) + break; + continue; } } - item_count++; /* Is zero for the first non-comment item */ + item_count++; /* Is zero for the first non-comment item */ /* Allow space for auto callout before every item except quantifiers. */ if ((options & PCRE_AUTO_CALLOUT) != 0 && - c != '*' && c != '+' && c != '?' && - (c != '{' || !is_counted_repeat(ptr + 1))) + c != '*' && c != '+' && c != '?' && + (c != '{' || !is_counted_repeat(ptr + 1))) length += 2 + 2 * LINK_SIZE; switch (c) { @@ -5566,30 +5566,30 @@ pattern. We can't be so clever for #-comments. */ case '\\': c = check_escape(&ptr, &errorcode, bracount, options, FALSE); if (errorcode != 0) - goto PCRE_ERROR_RETURN; + goto PCRE_ERROR_RETURN; - lastitemlength = 1; /* Default length of last item for repeats */ + lastitemlength = 1; /* Default length of last item for repeats */ - if (c >= 0) { /* Data character */ - length += 2; /* For a one-byte character */ + if (c >= 0) { /* Data character */ + length += 2; /* For a one-byte character */ - continue; + continue; } /* If \Q, enter "literal" mode */ if (-c == ESC_Q) { - inescq = TRUE; - continue; + inescq = TRUE; + continue; } /* \X is supported only if Unicode property support is compiled */ #ifndef SUPPORT_UCP if (-c == ESC_X) { - errorcode = ERR45; - goto PCRE_ERROR_RETURN; + errorcode = ERR45; + goto PCRE_ERROR_RETURN; } #endif @@ -5598,15 +5598,15 @@ pattern. We can't be so clever for #-comments. */ else if (-c == ESC_P || -c == ESC_p) { #ifdef SUPPORT_UCP - BOOL negated; - length += 2; - lastitemlength = 2; - if (get_ucp(&ptr, &negated, &errorcode) < 0) - goto PCRE_ERROR_RETURN; - continue; + BOOL negated; + length += 2; + lastitemlength = 2; + if (get_ucp(&ptr, &negated, &errorcode) < 0) + goto PCRE_ERROR_RETURN; + continue; #else - errorcode = ERR45; - goto PCRE_ERROR_RETURN; + errorcode = ERR45; + goto PCRE_ERROR_RETURN; #endif } @@ -5619,71 +5619,71 @@ pattern. We can't be so clever for #-comments. */ back reference. */ if (c <= -ESC_REF) { - int refnum = -c - ESC_REF; - compile_block.backref_map |= (refnum < 32) ? (1 << refnum) : 1; - if (refnum > compile_block.top_backref) - compile_block.top_backref = refnum; - length += 2; /* For single back reference */ - if (ptr[1] == '{' && is_counted_repeat(ptr + 2)) { - ptr = read_repeat_counts(ptr + 2, &min, &max, &errorcode); - if (errorcode != 0) - goto PCRE_ERROR_RETURN; - if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) - length++; - else - length += 5; - if (ptr[1] == '?') - ptr++; - } + int refnum = -c - ESC_REF; + compile_block.backref_map |= (refnum < 32) ? (1 << refnum) : 1; + if (refnum > compile_block.top_backref) + compile_block.top_backref = refnum; + length += 2; /* For single back reference */ + if (ptr[1] == '{' && is_counted_repeat(ptr + 2)) { + ptr = read_repeat_counts(ptr + 2, &min, &max, &errorcode); + if (errorcode != 0) + goto PCRE_ERROR_RETURN; + if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) + length++; + else + length += 5; + if (ptr[1] == '?') + ptr++; + } } continue; - case '^': /* Single-byte metacharacters */ + case '^': /* Single-byte metacharacters */ case '.': case '$': length++; lastitemlength = 1; continue; - case '*': /* These repeats won't be after brackets; */ - case '+': /* those are handled separately */ + case '*': /* These repeats won't be after brackets; */ + case '+': /* those are handled separately */ case '?': length++; - goto POSESSIVE; /* A few lines below */ + goto POSESSIVE; /* A few lines below */ /* This covers the cases of braced repeats after a single char, metachar, class, or back reference. */ case '{': if (!is_counted_repeat(ptr + 1)) - goto NORMAL_CHAR; + goto NORMAL_CHAR; ptr = read_repeat_counts(ptr + 1, &min, &max, &errorcode); if (errorcode != 0) - goto PCRE_ERROR_RETURN; + goto PCRE_ERROR_RETURN; /* These special cases just insert one extra opcode */ if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) - length++; + length++; /* These cases might insert additional copies of a preceding character. */ else { - if (min != 1) { - length -= lastitemlength; /* Uncount the original char or metachar */ - if (min > 0) - length += 3 + lastitemlength; - } - length += lastitemlength + ((max > 0) ? 3 : 1); + if (min != 1) { + length -= lastitemlength; /* Uncount the original char or metachar */ + if (min > 0) + length += 3 + lastitemlength; + } + length += lastitemlength + ((max > 0) ? 3 : 1); } if (ptr[1] == '?') - ptr++; /* Needs no extra length */ + ptr++; /* Needs no extra length */ - POSESSIVE: /* Test for possessive quantifier */ + POSESSIVE: /* Test for possessive quantifier */ if (ptr[1] == '+') { - ptr++; - length += 2 + 2 * LINK_SIZE; /* Allow for atomic brackets */ + ptr++; + length += 2 + 2 * LINK_SIZE; /* Allow for atomic brackets */ } continue; @@ -5706,133 +5706,133 @@ pattern. We can't be so clever for #-comments. */ case '[': if (*(++ptr) == '^') { - class_optcount = 10; /* Greater than one */ - ptr++; + class_optcount = 10; /* Greater than one */ + ptr++; } else - class_optcount = 0; + class_optcount = 0; /* Written as a "do" so that an initial ']' is taken as data */ if (*ptr != 0) - do { - /* Inside \Q...\E everything is literal except \E */ - - if (inescq) { - if (*ptr != '\\' || ptr[1] != 'E') - goto GET_ONE_CHARACTER; - inescq = FALSE; - ptr += 1; - continue; - } - - /* Outside \Q...\E, check for escapes */ - - if (*ptr == '\\') { - c = check_escape(&ptr, &errorcode, bracount, options, TRUE); - if (errorcode != 0) - goto PCRE_ERROR_RETURN; - - /* \b is backspace inside a class; \X is literal */ - - if (-c == ESC_b) - c = '\b'; - else if (-c == ESC_X) - c = 'X'; - - /* \Q enters quoting mode */ - - else if (-c == ESC_Q) { - inescq = TRUE; - continue; - } - - /* Handle escapes that turn into characters */ - - if (c >= 0) - goto NON_SPECIAL_CHARACTER; - - /* Escapes that are meta-things. The normal ones just affect the - bit map, but Unicode properties require an XCLASS extended item. */ - - else { - class_optcount = 10; /* \d, \s etc; make sure > 1 */ - } - } - - /* Check the syntax for POSIX stuff. The bits we actually handle are - checked during the real compile phase. */ - - else if (*ptr == '[' && check_posix_syntax(ptr, &ptr, &compile_block)) { - ptr++; - class_optcount = 10; /* Make sure > 1 */ - } - - /* Anything else increments the possible optimization count. We have to - detect ranges here so that we can compute the number of extra ranges for - caseless wide characters when UCP support is available. If there are wide - characters, we are going to have to use an XCLASS, even for single - characters. */ - - else { - int d; - - GET_ONE_CHARACTER: - - c = *ptr; - - /* Come here from handling \ above when it escapes to a char value */ - - NON_SPECIAL_CHARACTER: - class_optcount++; - - d = -1; - if (ptr[1] == '-') { - uschar const *hyptr = ptr++; - if (ptr[1] == '\\') { - ptr++; - d = check_escape(&ptr, &errorcode, bracount, options, TRUE); - if (errorcode != 0) - goto PCRE_ERROR_RETURN; - if (-d == ESC_b) - d = '\b'; /* backspace */ - else if (-d == ESC_X) - d = 'X'; /* literal X in a class */ - } else if (ptr[1] != 0 && ptr[1] != ']') { - ptr++; - d = *ptr; - } - if (d < 0) - ptr = hyptr; /* go back to hyphen as data */ - } - - /* If d >= 0 we have a range. In UTF-8 mode, if the end is > 255, or > - 127 for caseless matching, we will need to use an XCLASS. */ - - if (d >= 0) { - class_optcount = 10; /* Ensure > 1 */ - if (d < c) { - errorcode = ERR8; - goto PCRE_ERROR_RETURN; - } - - - } - - /* We have a single character. There is nothing to be done unless we - are in UTF-8 mode. If the char is > 255, or 127 when caseless, we must - allow for an XCL_SINGLE item, doubled for caselessness if there is UCP - support. */ - - else { - } - } - } - while (*(++ptr) != 0 && (inescq || *ptr != ']')); /* Concludes "do" above */ - - if (*ptr == 0) { /* Missing terminating ']' */ - errorcode = ERR6; - goto PCRE_ERROR_RETURN; + do { + /* Inside \Q...\E everything is literal except \E */ + + if (inescq) { + if (*ptr != '\\' || ptr[1] != 'E') + goto GET_ONE_CHARACTER; + inescq = FALSE; + ptr += 1; + continue; + } + + /* Outside \Q...\E, check for escapes */ + + if (*ptr == '\\') { + c = check_escape(&ptr, &errorcode, bracount, options, TRUE); + if (errorcode != 0) + goto PCRE_ERROR_RETURN; + + /* \b is backspace inside a class; \X is literal */ + + if (-c == ESC_b) + c = '\b'; + else if (-c == ESC_X) + c = 'X'; + + /* \Q enters quoting mode */ + + else if (-c == ESC_Q) { + inescq = TRUE; + continue; + } + + /* Handle escapes that turn into characters */ + + if (c >= 0) + goto NON_SPECIAL_CHARACTER; + + /* Escapes that are meta-things. The normal ones just affect the + bit map, but Unicode properties require an XCLASS extended item. */ + + else { + class_optcount = 10; /* \d, \s etc; make sure > 1 */ + } + } + + /* Check the syntax for POSIX stuff. The bits we actually handle are + checked during the real compile phase. */ + + else if (*ptr == '[' && check_posix_syntax(ptr, &ptr, &compile_block)) { + ptr++; + class_optcount = 10; /* Make sure > 1 */ + } + + /* Anything else increments the possible optimization count. We have to + detect ranges here so that we can compute the number of extra ranges for + caseless wide characters when UCP support is available. If there are wide + characters, we are going to have to use an XCLASS, even for single + characters. */ + + else { + int d; + + GET_ONE_CHARACTER: + + c = *ptr; + + /* Come here from handling \ above when it escapes to a char value */ + + NON_SPECIAL_CHARACTER: + class_optcount++; + + d = -1; + if (ptr[1] == '-') { + uschar const *hyptr = ptr++; + if (ptr[1] == '\\') { + ptr++; + d = check_escape(&ptr, &errorcode, bracount, options, TRUE); + if (errorcode != 0) + goto PCRE_ERROR_RETURN; + if (-d == ESC_b) + d = '\b'; /* backspace */ + else if (-d == ESC_X) + d = 'X'; /* literal X in a class */ + } else if (ptr[1] != 0 && ptr[1] != ']') { + ptr++; + d = *ptr; + } + if (d < 0) + ptr = hyptr; /* go back to hyphen as data */ + } + + /* If d >= 0 we have a range. In UTF-8 mode, if the end is > 255, or > + 127 for caseless matching, we will need to use an XCLASS. */ + + if (d >= 0) { + class_optcount = 10; /* Ensure > 1 */ + if (d < c) { + errorcode = ERR8; + goto PCRE_ERROR_RETURN; + } + + + } + + /* We have a single character. There is nothing to be done unless we + are in UTF-8 mode. If the char is > 255, or 127 when caseless, we must + allow for an XCL_SINGLE item, doubled for caselessness if there is UCP + support. */ + + else { + } + } + } + while (*(++ptr) != 0 && (inescq || *ptr != ']')); /* Concludes "do" above */ + + if (*ptr == 0) { /* Missing terminating ']' */ + errorcode = ERR6; + goto PCRE_ERROR_RETURN; } /* We can optimize when there was only one optimizable character. Repeats @@ -5840,27 +5840,27 @@ pattern. We can't be so clever for #-comments. */ code. Here, we handle repeats for the class opcodes. */ if (class_optcount == 1) - length += 3; + length += 3; else { - length += 33; - - /* A repeat needs either 1 or 5 bytes. If it is a possessive quantifier, - we also need extra for wrapping the whole thing in a sub-pattern. */ - - if (*ptr != 0 && ptr[1] == '{' && is_counted_repeat(ptr + 2)) { - ptr = read_repeat_counts(ptr + 2, &min, &max, &errorcode); - if (errorcode != 0) - goto PCRE_ERROR_RETURN; - if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) - length++; - else - length += 5; - if (ptr[1] == '+') { - ptr++; - length += 2 + 2 * LINK_SIZE; - } else if (ptr[1] == '?') - ptr++; - } + length += 33; + + /* A repeat needs either 1 or 5 bytes. If it is a possessive quantifier, + we also need extra for wrapping the whole thing in a sub-pattern. */ + + if (*ptr != 0 && ptr[1] == '{' && is_counted_repeat(ptr + 2)) { + ptr = read_repeat_counts(ptr + 2, &min, &max, &errorcode); + if (errorcode != 0) + goto PCRE_ERROR_RETURN; + if ((min == 0 && (max == 1 || max == -1)) || (min == 1 && max == -1)) + length++; + else + length += 5; + if (ptr[1] == '+') { + ptr++; + length += 2 + 2 * LINK_SIZE; + } else if (ptr[1] == '?') + ptr++; + } } continue; @@ -5874,306 +5874,306 @@ pattern. We can't be so clever for #-comments. */ /* Handle special forms of bracket, which all start (? */ if (ptr[1] == '?') { - int set, unset; - int *optset; - - switch (c = ptr[2]) { - /* Skip over comments entirely */ - case '#': - ptr += 3; - while (*ptr != 0 && *ptr != ')') - ptr++; - if (*ptr == 0) { - errorcode = ERR18; - goto PCRE_ERROR_RETURN; - } - continue; - - /* Non-referencing groups and lookaheads just move the pointer on, and - then behave like a non-special bracket, except that they don't increment - the count of extracting brackets. Ditto for the "once only" bracket, - which is in Perl from version 5.005. */ - - case ':': - case '=': - case '!': - case '>': - ptr += 2; - break; - - /* (?R) specifies a recursive call to the regex, which is an extension - to provide the facility which can be obtained by (?p{perl-code}) in - Perl 5.6. In Perl 5.8 this has become (??{perl-code}). - - From PCRE 4.00, items such as (?3) specify subroutine-like "calls" to - the appropriate numbered brackets. This includes both recursive and - non-recursive calls. (?R) is now synonymous with (?0). */ - - case 'R': - ptr++; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - ptr += 2; - if (c != 'R') - while ((digitab[*(++ptr)] & ctype_digit) != 0) ; - if (*ptr != ')') { - errorcode = ERR29; - goto PCRE_ERROR_RETURN; - } - length += 1 + LINK_SIZE; - - /* If this item is quantified, it will get wrapped inside brackets so - as to use the code for quantified brackets. We jump down and use the - code that handles this for real brackets. */ - - if (ptr[1] == '+' || ptr[1] == '*' || ptr[1] == '?' || ptr[1] == '{') { - length += 2 + 2 * LINK_SIZE; /* to make bracketed */ - duplength = 5 + 3 * LINK_SIZE; - goto HANDLE_QUANTIFIED_BRACKETS; - } - continue; - - /* (?C) is an extension which provides "callout" - to provide a bit of - the functionality of the Perl (?{...}) feature. An optional number may - follow (default is zero). */ - - case 'C': - ptr += 2; - while ((digitab[*(++ptr)] & ctype_digit) != 0) ; - if (*ptr != ')') { - errorcode = ERR39; - goto PCRE_ERROR_RETURN; - } - length += 2 + 2 * LINK_SIZE; - continue; - - /* Named subpatterns are an extension copied from Python */ - - case 'P': - ptr += 3; - - /* Handle the definition of a named subpattern */ - - if (*ptr == '<') { - const uschar *p; /* Don't amalgamate; some compilers */ - p = ++ptr; /* grumble at autoincrement in declaration */ - while ((compile_block.ctypes[*ptr] & ctype_word) != 0) - ptr++; - if (*ptr != '>') { - errorcode = ERR42; - goto PCRE_ERROR_RETURN; - } - name_count++; - if (ptr - p > max_name_size) - max_name_size = (ptr - p); - capturing = TRUE; /* Named parentheses are always capturing */ - break; - } - - /* Handle back references and recursive calls to named subpatterns */ - - if (*ptr == '=' || *ptr == '>') { - while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0) ; - if (*ptr != ')') { - errorcode = ERR42; - goto PCRE_ERROR_RETURN; - } - break; - } - - /* Unknown character after (?P */ - - errorcode = ERR41; - goto PCRE_ERROR_RETURN; - - /* Lookbehinds are in Perl from version 5.005 */ - - case '<': - ptr += 3; - if (*ptr == '=' || *ptr == '!') { - branch_newextra = 1 + LINK_SIZE; - length += 1 + LINK_SIZE; /* For the first branch */ - break; - } - errorcode = ERR24; - goto PCRE_ERROR_RETURN; - - /* Conditionals are in Perl from version 5.005. The bracket must either - be followed by a number (for bracket reference) or by an assertion - group, or (a PCRE extension) by 'R' for a recursion test. */ - - case '(': - if (ptr[3] == 'R' && ptr[4] == ')') { - ptr += 4; - length += 3; - } else if ((digitab[ptr[3]] & ctype_digit) != 0) { - ptr += 4; - length += 3; - while ((digitab[*ptr] & ctype_digit) != 0) - ptr++; - if (*ptr != ')') { - errorcode = ERR26; - goto PCRE_ERROR_RETURN; - } - } else { /* An assertion must follow */ - - ptr++; /* Can treat like ':' as far as spacing is concerned */ - if (ptr[2] != '?' || - (ptr[3] != '=' && ptr[3] != '!' && ptr[3] != '<')) { - ptr += 2; /* To get right offset in message */ - errorcode = ERR28; - goto PCRE_ERROR_RETURN; - } - } - break; - - /* Else loop checking valid options until ) is met. Anything else is an - error. If we are without any brackets, i.e. at top level, the settings - act as if specified in the options, so massage the options immediately. - This is for backward compatibility with Perl 5.004. */ - - default: - set = unset = 0; - optset = &set; - ptr += 2; - - for (;; ptr++) { - c = *ptr; - switch (c) { - case 'i': - *optset |= PCRE_CASELESS; - continue; - - case 'm': - *optset |= PCRE_MULTILINE; - continue; - - case 's': - *optset |= PCRE_DOTALL; - continue; - - case 'x': - *optset |= PCRE_EXTENDED; - continue; - - case 'X': - *optset |= PCRE_EXTRA; - continue; - - case 'U': - *optset |= PCRE_UNGREEDY; - continue; - - case '-': - optset = &unset; - continue; - - /* A termination by ')' indicates an options-setting-only item; if - this is at the very start of the pattern (indicated by item_count - being zero), we use it to set the global options. This is helpful - when analyzing the pattern for first characters, etc. Otherwise - nothing is done here and it is handled during the compiling - process. - - We allow for more than one options setting at the start. If such - settings do not change the existing options, nothing is compiled. - However, we must leave space just in case something is compiled. - This can happen for pathological sequences such as (?i)(?-i) - because the global options will end up with -i set. The space is - small and not significant. (Before I did this there was a reported - bug with (?i)(?-i) in a machine-generated pattern.) - - [Historical note: Up to Perl 5.8, options settings at top level - were always global settings, wherever they appeared in the pattern. - That is, they were equivalent to an external setting. From 5.8 - onwards, they apply only to what follows (which is what you might - expect).] */ - - case ')': - if (item_count == 0) { - options = (options | set) & (~unset); - set = unset = 0; /* To save length */ - item_count--; /* To allow for several */ - length += 2; - } - - /* Fall through */ - - /* A termination by ':' indicates the start of a nested group with - the given options set. This is again handled at compile time, but - we must allow for compiled space if any of the ims options are - set. We also have to allow for resetting space at the end of - the group, which is why 4 is added to the length and not just 2. - If there are several changes of options within the same group, this - will lead to an over-estimate on the length, but this shouldn't - matter very much. We also have to allow for resetting options at - the start of any alternations, which we do by setting - branch_newextra to 2. Finally, we record whether the case-dependent - flag ever changes within the regex. This is used by the "required - character" code. */ - - case ':': - if (((set | unset) & PCRE_IMS) != 0) { - length += 4; - branch_newextra = 2; - if (((set | unset) & PCRE_CASELESS) != 0) - options |= PCRE_ICHANGED; - } - goto END_OPTIONS; - - /* Unrecognized option character */ - - default: - errorcode = ERR12; - goto PCRE_ERROR_RETURN; - } - } - - /* If we hit a closing bracket, that's it - this is a freestanding - option-setting. We need to ensure that branch_extra is updated if - necessary. The only values branch_newextra can have here are 0 or 2. - If the value is 2, then branch_extra must either be 2 or 5, depending - on whether this is a lookbehind group or not. */ - - END_OPTIONS: - if (c == ')') { - if (branch_newextra == 2 && - (branch_extra == 0 || branch_extra == 1 + LINK_SIZE)) - branch_extra += branch_newextra; - continue; - } - - /* If options were terminated by ':' control comes here. This is a - non-capturing group with an options change. There is nothing more that - needs to be done because "capturing" is already set FALSE by default; - we can just fall through. */ - - } + int set, unset; + int *optset; + + switch (c = ptr[2]) { + /* Skip over comments entirely */ + case '#': + ptr += 3; + while (*ptr != 0 && *ptr != ')') + ptr++; + if (*ptr == 0) { + errorcode = ERR18; + goto PCRE_ERROR_RETURN; + } + continue; + + /* Non-referencing groups and lookaheads just move the pointer on, and + then behave like a non-special bracket, except that they don't increment + the count of extracting brackets. Ditto for the "once only" bracket, + which is in Perl from version 5.005. */ + + case ':': + case '=': + case '!': + case '>': + ptr += 2; + break; + + /* (?R) specifies a recursive call to the regex, which is an extension + to provide the facility which can be obtained by (?p{perl-code}) in + Perl 5.6. In Perl 5.8 this has become (??{perl-code}). + + From PCRE 4.00, items such as (?3) specify subroutine-like "calls" to + the appropriate numbered brackets. This includes both recursive and + non-recursive calls. (?R) is now synonymous with (?0). */ + + case 'R': + ptr++; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + ptr += 2; + if (c != 'R') + while ((digitab[*(++ptr)] & ctype_digit) != 0) ; + if (*ptr != ')') { + errorcode = ERR29; + goto PCRE_ERROR_RETURN; + } + length += 1 + LINK_SIZE; + + /* If this item is quantified, it will get wrapped inside brackets so + as to use the code for quantified brackets. We jump down and use the + code that handles this for real brackets. */ + + if (ptr[1] == '+' || ptr[1] == '*' || ptr[1] == '?' || ptr[1] == '{') { + length += 2 + 2 * LINK_SIZE; /* to make bracketed */ + duplength = 5 + 3 * LINK_SIZE; + goto HANDLE_QUANTIFIED_BRACKETS; + } + continue; + + /* (?C) is an extension which provides "callout" - to provide a bit of + the functionality of the Perl (?{...}) feature. An optional number may + follow (default is zero). */ + + case 'C': + ptr += 2; + while ((digitab[*(++ptr)] & ctype_digit) != 0) ; + if (*ptr != ')') { + errorcode = ERR39; + goto PCRE_ERROR_RETURN; + } + length += 2 + 2 * LINK_SIZE; + continue; + + /* Named subpatterns are an extension copied from Python */ + + case 'P': + ptr += 3; + + /* Handle the definition of a named subpattern */ + + if (*ptr == '<') { + const uschar *p; /* Don't amalgamate; some compilers */ + p = ++ptr; /* grumble at autoincrement in declaration */ + while ((compile_block.ctypes[*ptr] & ctype_word) != 0) + ptr++; + if (*ptr != '>') { + errorcode = ERR42; + goto PCRE_ERROR_RETURN; + } + name_count++; + if (ptr - p > max_name_size) + max_name_size = (ptr - p); + capturing = TRUE; /* Named parentheses are always capturing */ + break; + } + + /* Handle back references and recursive calls to named subpatterns */ + + if (*ptr == '=' || *ptr == '>') { + while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0) ; + if (*ptr != ')') { + errorcode = ERR42; + goto PCRE_ERROR_RETURN; + } + break; + } + + /* Unknown character after (?P */ + + errorcode = ERR41; + goto PCRE_ERROR_RETURN; + + /* Lookbehinds are in Perl from version 5.005 */ + + case '<': + ptr += 3; + if (*ptr == '=' || *ptr == '!') { + branch_newextra = 1 + LINK_SIZE; + length += 1 + LINK_SIZE; /* For the first branch */ + break; + } + errorcode = ERR24; + goto PCRE_ERROR_RETURN; + + /* Conditionals are in Perl from version 5.005. The bracket must either + be followed by a number (for bracket reference) or by an assertion + group, or (a PCRE extension) by 'R' for a recursion test. */ + + case '(': + if (ptr[3] == 'R' && ptr[4] == ')') { + ptr += 4; + length += 3; + } else if ((digitab[ptr[3]] & ctype_digit) != 0) { + ptr += 4; + length += 3; + while ((digitab[*ptr] & ctype_digit) != 0) + ptr++; + if (*ptr != ')') { + errorcode = ERR26; + goto PCRE_ERROR_RETURN; + } + } else { /* An assertion must follow */ + + ptr++; /* Can treat like ':' as far as spacing is concerned */ + if (ptr[2] != '?' || + (ptr[3] != '=' && ptr[3] != '!' && ptr[3] != '<')) { + ptr += 2; /* To get right offset in message */ + errorcode = ERR28; + goto PCRE_ERROR_RETURN; + } + } + break; + + /* Else loop checking valid options until ) is met. Anything else is an + error. If we are without any brackets, i.e. at top level, the settings + act as if specified in the options, so massage the options immediately. + This is for backward compatibility with Perl 5.004. */ + + default: + set = unset = 0; + optset = &set; + ptr += 2; + + for (;; ptr++) { + c = *ptr; + switch (c) { + case 'i': + *optset |= PCRE_CASELESS; + continue; + + case 'm': + *optset |= PCRE_MULTILINE; + continue; + + case 's': + *optset |= PCRE_DOTALL; + continue; + + case 'x': + *optset |= PCRE_EXTENDED; + continue; + + case 'X': + *optset |= PCRE_EXTRA; + continue; + + case 'U': + *optset |= PCRE_UNGREEDY; + continue; + + case '-': + optset = &unset; + continue; + + /* A termination by ')' indicates an options-setting-only item; if + this is at the very start of the pattern (indicated by item_count + being zero), we use it to set the global options. This is helpful + when analyzing the pattern for first characters, etc. Otherwise + nothing is done here and it is handled during the compiling + process. + + We allow for more than one options setting at the start. If such + settings do not change the existing options, nothing is compiled. + However, we must leave space just in case something is compiled. + This can happen for pathological sequences such as (?i)(?-i) + because the global options will end up with -i set. The space is + small and not significant. (Before I did this there was a reported + bug with (?i)(?-i) in a machine-generated pattern.) + + [Historical note: Up to Perl 5.8, options settings at top level + were always global settings, wherever they appeared in the pattern. + That is, they were equivalent to an external setting. From 5.8 + onwards, they apply only to what follows (which is what you might + expect).] */ + + case ')': + if (item_count == 0) { + options = (options | set) & (~unset); + set = unset = 0; /* To save length */ + item_count--; /* To allow for several */ + length += 2; + } + + /* Fall through */ + + /* A termination by ':' indicates the start of a nested group with + the given options set. This is again handled at compile time, but + we must allow for compiled space if any of the ims options are + set. We also have to allow for resetting space at the end of + the group, which is why 4 is added to the length and not just 2. + If there are several changes of options within the same group, this + will lead to an over-estimate on the length, but this shouldn't + matter very much. We also have to allow for resetting options at + the start of any alternations, which we do by setting + branch_newextra to 2. Finally, we record whether the case-dependent + flag ever changes within the regex. This is used by the "required + character" code. */ + + case ':': + if (((set | unset) & PCRE_IMS) != 0) { + length += 4; + branch_newextra = 2; + if (((set | unset) & PCRE_CASELESS) != 0) + options |= PCRE_ICHANGED; + } + goto END_OPTIONS; + + /* Unrecognized option character */ + + default: + errorcode = ERR12; + goto PCRE_ERROR_RETURN; + } + } + + /* If we hit a closing bracket, that's it - this is a freestanding + option-setting. We need to ensure that branch_extra is updated if + necessary. The only values branch_newextra can have here are 0 or 2. + If the value is 2, then branch_extra must either be 2 or 5, depending + on whether this is a lookbehind group or not. */ + + END_OPTIONS: + if (c == ')') { + if (branch_newextra == 2 && + (branch_extra == 0 || branch_extra == 1 + LINK_SIZE)) + branch_extra += branch_newextra; + continue; + } + + /* If options were terminated by ':' control comes here. This is a + non-capturing group with an options change. There is nothing more that + needs to be done because "capturing" is already set FALSE by default; + we can just fall through. */ + + } } /* Ordinary parentheses, not followed by '?', are capturing unless PCRE_NO_AUTO_CAPTURE is set. */ else - capturing = (options & PCRE_NO_AUTO_CAPTURE) == 0; + capturing = (options & PCRE_NO_AUTO_CAPTURE) == 0; /* Capturing brackets must be counted so we can process escapes in a Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to need an additional 3 bytes of memory per capturing bracket. */ if (capturing) { - bracount++; - if (bracount > EXTRACT_BASIC_MAX) - bracket_length += 3; + bracount++; + if (bracount > EXTRACT_BASIC_MAX) + bracket_length += 3; } /* Save length for computing whole length at end if there's a repeat that @@ -6182,8 +6182,8 @@ pattern. We can't be so clever for #-comments. */ will either be 2 for a (?imsx: group, or 3 for a lookbehind assertion. */ if (brastackptr >= sizeof(brastack) / sizeof(int)) { - errorcode = ERR19; - goto PCRE_ERROR_RETURN; + errorcode = ERR19; + goto PCRE_ERROR_RETURN; } bralenstack[brastackptr] = branch_extra; @@ -6202,10 +6202,10 @@ pattern. We can't be so clever for #-comments. */ case ')': length += 1 + LINK_SIZE; if (brastackptr > 0) { - duplength = length - brastack[--brastackptr]; - branch_extra = bralenstack[brastackptr]; + duplength = length - brastack[--brastackptr]; + branch_extra = bralenstack[brastackptr]; } else - duplength = 0; + duplength = 0; /* The following code is also used when a recursion such as (?3) is followed by a quantifier, because in that case, it has to be wrapped inside @@ -6218,24 +6218,24 @@ pattern. We can't be so clever for #-comments. */ automatically; for the others we need an increment. */ if ((c = ptr[1]) == '{' && is_counted_repeat(ptr + 2)) { - ptr = read_repeat_counts(ptr + 2, &min, &max, &errorcode); - if (errorcode != 0) - goto PCRE_ERROR_RETURN; + ptr = read_repeat_counts(ptr + 2, &min, &max, &errorcode); + if (errorcode != 0) + goto PCRE_ERROR_RETURN; } else if (c == '*') { - min = 0; - max = -1; - ptr++; + min = 0; + max = -1; + ptr++; } else if (c == '+') { - min = 1; - max = -1; - ptr++; + min = 1; + max = -1; + ptr++; } else if (c == '?') { - min = 0; - max = 1; - ptr++; + min = 0; + max = 1; + ptr++; } else { - min = 1; - max = 1; + min = 1; + max = 1; } /* If the minimum is zero, we have to allow for an OP_BRAZERO before the @@ -6244,9 +6244,9 @@ pattern. We can't be so clever for #-comments. */ bracket set. */ if (min == 0) { - length++; - if (max > 0) - length += (max - 1) * (duplength + 3 + 2 * LINK_SIZE); + length++; + if (max > 0) + length += (max - 1) * (duplength + 3 + 2 * LINK_SIZE); } /* When the minimum is greater than zero, we have to replicate up to @@ -6256,17 +6256,17 @@ pattern. We can't be so clever for #-comments. */ but one of the optional copies. */ else { - length += (min - 1) * duplength; - if (max > min) /* Need this test as max=-1 means no limit */ - length += (max - min) * (duplength + 3 + 2 * LINK_SIZE) - - (2 + 2 * LINK_SIZE); + length += (min - 1) * duplength; + if (max > min) /* Need this test as max=-1 means no limit */ + length += (max - min) * (duplength + 3 + 2 * LINK_SIZE) + - (2 + 2 * LINK_SIZE); } /* Allow space for once brackets for "possessive quantifier" */ if (ptr[1] == '+') { - ptr++; - length += 2 + 2 * LINK_SIZE; + ptr++; + length += 2 + 2 * LINK_SIZE; } continue; @@ -6278,13 +6278,13 @@ pattern. We can't be so clever for #-comments. */ NORMAL_CHAR: if (inescq && c == '\\' && ptr[1] == 'E') { - inescq = FALSE; - ptr++; - continue; + inescq = FALSE; + ptr++; + continue; } - length += 2; /* For a one-byte character */ - lastitemlength = 1; /* Default length of last item for repeats */ + length += 2; /* For a one-byte character */ + lastitemlength = 1; /* Default length of last item for repeats */ /* In UTF-8 mode, check for additional bytes. */ @@ -6293,10 +6293,10 @@ pattern. We can't be so clever for #-comments. */ } } - length += 2 + LINK_SIZE; /* For final KET and END */ + length += 2 + LINK_SIZE; /* For final KET and END */ if ((options & PCRE_AUTO_CALLOUT) != 0) - length += 2 + 2 * LINK_SIZE; /* For final callout */ + length += 2 + 2 * LINK_SIZE; /* For final callout */ if (length > MAX_PATTERN_SIZE) { errorcode = ERR20; @@ -6351,8 +6351,8 @@ of the function here. */ *code = OP_BRA; bracount = 0; (void) compile_regex(options, options & PCRE_IMS, &bracount, &code, &ptr, - &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, - &compile_block); + &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, + &compile_block); re->top_bracket = bracount; re->top_backref = compile_block.top_backref; @@ -6407,14 +6407,14 @@ start with ^. and also when all branches start with .* for non-DOTALL matches. re->options |= PCRE_ANCHORED; else { if (firstbyte < 0) - firstbyte = find_firstassertedchar(codestart, &temp_options, FALSE); - if (firstbyte >= 0) { /* Remove caseless flag for non-caseable chars */ - int ch = firstbyte & 255; - re->first_byte = ((firstbyte & REQ_CASELESS) != 0 && - compile_block.fcc[ch] == ch) ? ch : firstbyte; - re->options |= PCRE_FIRSTSET; + firstbyte = find_firstassertedchar(codestart, &temp_options, FALSE); + if (firstbyte >= 0) { /* Remove caseless flag for non-caseable chars */ + int ch = firstbyte & 255; + re->first_byte = ((firstbyte & REQ_CASELESS) != 0 && + compile_block.fcc[ch] == ch) ? ch : firstbyte; + re->options |= PCRE_FIRSTSET; } else if (is_startline(codestart, 0, compile_block.backref_map)) - re->options |= PCRE_STARTLINE; + re->options |= PCRE_STARTLINE; } } @@ -6426,8 +6426,8 @@ bytes. */ ((re->options & PCRE_ANCHORED) == 0 || (reqbyte & REQ_VARY) != 0)) { int ch = reqbyte & 255; re->req_byte = ((reqbyte & REQ_CASELESS) != 0 && - compile_block.fcc[ch] == - ch) ? (reqbyte & ~REQ_CASELESS) : reqbyte; + compile_block.fcc[ch] == + ch) ? (reqbyte & ~REQ_CASELESS) : reqbyte; re->options |= PCRE_REQCHSET; } @@ -6462,8 +6462,8 @@ typedef struct eptrblock { /* Flag bits for the match() function */ -#define match_condassert 0x01 /* Called to check a condition assertion */ -#define match_isgroup 0x02 /* Set if start of bracketed group */ +#define match_condassert 0x01 /* Called to check a condition assertion */ +#define match_isgroup 0x02 /* Set if start of bracketed group */ /* Non-error returns from the match() function. Error returns are externally defined PCRE_ERROR_xxx codes, which are all negative. */ @@ -6506,7 +6506,7 @@ Returns: TRUE if matched static BOOL match_ref(int offset, register const uschar * eptr, int length, match_data * md, - unsigned long int ims) + unsigned long int ims) { const uschar *p = md->start_subject + md->offset_vector[offset]; @@ -6521,11 +6521,11 @@ match_ref(int offset, register const uschar * eptr, int length, match_data * md, if ((ims & PCRE_CASELESS) != 0) { while (length-- > 0) if (md->lcc[*p++] != md->lcc[*eptr++]) - return FALSE; + return FALSE; } else { while (length-- > 0) if (*p++ != *eptr++) - return FALSE; + return FALSE; } return TRUE; @@ -6725,10 +6725,10 @@ match(REGISTER const uschar * eptr, REGISTER const uschar * ecode, so they can be ordinary variables in all cases. Mark them with "register" because they are used a lot in loops. */ - register int rrc; /* Returns from recursive calls */ - register int i; /* Used for loops not involving calls to RMATCH() */ - register int c; /* Character values not kept over RMATCH() calls */ - register BOOL utf8; /* Local copy of UTF-8 flag for speed */ + register int rrc; /* Returns from recursive calls */ + register int i; /* Used for loops not involving calls to RMATCH() */ + register int c; /* Character values not kept over RMATCH() calls */ + register BOOL utf8; /* Local copy of UTF-8 flag for speed */ /* When recursion is not being used, all "local" variables that have to be preserved over calls to RMATCH() are part of a "frame" which is obtained from @@ -6737,7 +6737,7 @@ heap whenever RMATCH() does a "recursion". See the macro definitions above. */ #ifdef NO_RECURSE heapframe *frame = malloc(sizeof(heapframe)); - frame->Xprevframe = NULL; /* Marks the top level */ + frame->Xprevframe = NULL; /* Marks the top level */ /* Copy in the original argument variables */ @@ -6815,17 +6815,17 @@ i, and fc and c, can be the same variables. */ #define fc c - const uschar *callpat; /* them within each of those blocks. */ - const uschar *data; /* However, in order to accommodate the */ - const uschar *next; /* version of this code that uses an */ - const uschar *pp; /* external "stack" implemented on the */ - const uschar *prev; /* heap, it is easier to declare them */ - const uschar *saved_eptr; /* all here, so the declarations can */ + const uschar *callpat; /* them within each of those blocks. */ + const uschar *data; /* However, in order to accommodate the */ + const uschar *next; /* version of this code that uses an */ + const uschar *pp; /* external "stack" implemented on the */ + const uschar *prev; /* heap, it is easier to declare them */ + const uschar *saved_eptr; /* all here, so the declarations can */ /* be cut out in a block. The only */ - recursion_info new_recursive; /* declarations within blocks below are */ + recursion_info new_recursive; /* declarations within blocks below are */ /* for variables that do not have to */ - BOOL cur_is_word; /* be preserved over a recursive call */ - BOOL condition; /* to RMATCH(). */ + BOOL cur_is_word; /* be preserved over a recursive call */ + BOOL condition; /* to RMATCH(). */ BOOL minimize; BOOL prev_is_word; @@ -6874,8 +6874,8 @@ performance when true recursion is being used. */ if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT); - original_ims = ims; /* Save for resetting on ')' */ - utf8 = md->utf8; /* Local copy of the flag */ + original_ims = ims; /* Save for resetting on ')' */ + utf8 = md->utf8; /* Local copy of the flag */ /* At the start of a bracketed group, add the current subject pointer to the stack of such pointers, to be re-instated at the end of the group when we hit @@ -6921,52 +6921,52 @@ this stack. */ number from a dummy opcode at the start. */ if (number > EXTRACT_BASIC_MAX) - number = GET2(ecode, 2 + LINK_SIZE); + number = GET2(ecode, 2 + LINK_SIZE); offset = number << 1; if (offset < md->offset_max) { - save_offset1 = md->offset_vector[offset]; - save_offset2 = md->offset_vector[offset + 1]; - save_offset3 = md->offset_vector[md->offset_end - number]; - save_capture_last = md->capture_last; + save_offset1 = md->offset_vector[offset]; + save_offset2 = md->offset_vector[offset + 1]; + save_offset3 = md->offset_vector[md->offset_end - number]; + save_capture_last = md->capture_last; - md->offset_vector[md->offset_end - number] = eptr - md->start_subject; + md->offset_vector[md->offset_end - number] = eptr - md->start_subject; - do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - md->capture_last = save_capture_last; - ecode += GET(ecode, 1); - } - while (*ecode == OP_ALT); + do { + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + md->capture_last = save_capture_last; + ecode += GET(ecode, 1); + } + while (*ecode == OP_ALT); - md->offset_vector[offset] = save_offset1; - md->offset_vector[offset + 1] = save_offset2; - md->offset_vector[md->offset_end - number] = save_offset3; + md->offset_vector[offset] = save_offset1; + md->offset_vector[offset + 1] = save_offset2; + md->offset_vector[md->offset_end - number] = save_offset3; - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); } /* Insufficient room for saving captured contents */ else - op = OP_BRA; + op = OP_BRA; } /* Other types of node can be handled by a switch */ switch (op) { - case OP_BRA: /* Non-capturing bracket: optimized */ + case OP_BRA: /* Non-capturing bracket: optimized */ do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - ecode += GET(ecode, 1); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + ecode += GET(ecode, 1); } while (*ecode == OP_ALT); RRETURN(MATCH_NOMATCH); @@ -6977,35 +6977,35 @@ this stack. */ exactly what going to the ket would do. */ case OP_COND: - if (ecode[LINK_SIZE + 1] == OP_CREF) { /* Condition extract or recurse test */ - offset = GET2(ecode, LINK_SIZE + 2) << 1; /* Doubled ref number */ - condition = (offset == CREF_RECURSE * 2) ? - (md->recursive != NULL) : - (offset < offset_top && md->offset_vector[offset] >= 0); - RMATCH(rrc, eptr, ecode + (condition ? - (LINK_SIZE + 4) : (LINK_SIZE + 1 + - GET(ecode, 1))), - offset_top, md, ims, eptrb, match_isgroup); - RRETURN(rrc); + if (ecode[LINK_SIZE + 1] == OP_CREF) { /* Condition extract or recurse test */ + offset = GET2(ecode, LINK_SIZE + 2) << 1; /* Doubled ref number */ + condition = (offset == CREF_RECURSE * 2) ? + (md->recursive != NULL) : + (offset < offset_top && md->offset_vector[offset] >= 0); + RMATCH(rrc, eptr, ecode + (condition ? + (LINK_SIZE + 4) : (LINK_SIZE + 1 + + GET(ecode, 1))), + offset_top, md, ims, eptrb, match_isgroup); + RRETURN(rrc); } /* The condition is an assertion. Call match() to evaluate it - setting the final argument TRUE causes it to stop at the end of an assertion. */ else { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, - match_condassert | match_isgroup); - if (rrc == MATCH_MATCH) { - ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); - while (*ecode == OP_ALT) - ecode += GET(ecode, 1); - } else if (rrc != MATCH_NOMATCH) { - RRETURN(rrc); /* Need braces because of following else */ - } else - ecode += GET(ecode, 1); - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); - RRETURN(rrc); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, + match_condassert | match_isgroup); + if (rrc == MATCH_MATCH) { + ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); + while (*ecode == OP_ALT) + ecode += GET(ecode, 1); + } else if (rrc != MATCH_NOMATCH) { + RRETURN(rrc); /* Need braces because of following else */ + } else + ecode += GET(ecode, 1); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + match_isgroup); + RRETURN(rrc); } /* Control never reaches here */ @@ -7022,23 +7022,23 @@ this stack. */ case OP_END: if (md->recursive != NULL && md->recursive->group_num == 0) { - recursion_info *rec = md->recursive; - md->recursive = rec->prevrec; - memmove(md->offset_vector, rec->offset_save, - rec->saved_max * sizeof(int)); - md->start_match = rec->save_start; - ims = original_ims; - ecode = rec->after_call; - break; + recursion_info *rec = md->recursive; + md->recursive = rec->prevrec; + memmove(md->offset_vector, rec->offset_save, + rec->saved_max * sizeof(int)); + md->start_match = rec->save_start; + ims = original_ims; + ecode = rec->after_call; + break; } /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty string - backtracking will then try other alternatives, if any. */ if (md->notempty && eptr == md->start_match) - RRETURN(MATCH_NOMATCH); - md->end_match_ptr = eptr; /* Record where we ended */ - md->end_offset_top = offset_top; /* and how many extracts were taken */ + RRETURN(MATCH_NOMATCH); + md->end_match_ptr = eptr; /* Record where we ended */ + md->end_offset_top = offset_top; /* and how many extracts were taken */ RRETURN(MATCH_MATCH); /* Change option settings */ @@ -7057,28 +7057,28 @@ this stack. */ case OP_ASSERT: case OP_ASSERTBACK: do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, - match_isgroup); - if (rrc == MATCH_MATCH) - break; - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - ecode += GET(ecode, 1); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, + match_isgroup); + if (rrc == MATCH_MATCH) + break; + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + ecode += GET(ecode, 1); } while (*ecode == OP_ALT); if (*ecode == OP_KET) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); /* If checking an assertion for a condition, return MATCH_MATCH. */ if ((flags & match_condassert) != 0) - RRETURN(MATCH_MATCH); + RRETURN(MATCH_MATCH); /* Continue from after the assertion, updating the offsets high water mark, since extracts may have been taken during the assertion. */ do - ecode += GET(ecode, 1); + ecode += GET(ecode, 1); while (*ecode == OP_ALT); ecode += 1 + LINK_SIZE; offset_top = md->end_offset_top; @@ -7089,18 +7089,18 @@ this stack. */ case OP_ASSERT_NOT: case OP_ASSERTBACK_NOT: do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, - match_isgroup); - if (rrc == MATCH_MATCH) - RRETURN(MATCH_NOMATCH); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - ecode += GET(ecode, 1); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, + match_isgroup); + if (rrc == MATCH_MATCH) + RRETURN(MATCH_NOMATCH); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + ecode += GET(ecode, 1); } while (*ecode == OP_ALT); if ((flags & match_condassert) != 0) - RRETURN(MATCH_MATCH); + RRETURN(MATCH_MATCH); ecode += 1 + LINK_SIZE; continue; @@ -7115,9 +7115,9 @@ this stack. */ /* No UTF-8 support, or not in UTF-8 mode: count is byte count */ { - eptr -= GET(ecode, 1); - if (eptr < md->start_subject) - RRETURN(MATCH_NOMATCH); + eptr -= GET(ecode, 1); + if (eptr < md->start_subject) + RRETURN(MATCH_NOMATCH); } /* Skip to next op code */ @@ -7131,23 +7131,23 @@ this stack. */ case OP_CALLOUT: if (pcre_callout != NULL) { - pcre_callout_block cb; - cb.version = 1; /* Version 1 of the callout block */ - cb.callout_number = ecode[1]; - cb.offset_vector = md->offset_vector; - cb.subject = (const char *) md->start_subject; - cb.subject_length = md->end_subject - md->start_subject; - cb.start_match = md->start_match - md->start_subject; - cb.current_position = eptr - md->start_subject; - cb.pattern_position = GET(ecode, 2); - cb.next_item_length = GET(ecode, 2 + LINK_SIZE); - cb.capture_top = offset_top / 2; - cb.capture_last = md->capture_last; - cb.callout_data = md->callout_data; - if ((rrc = (*pcre_callout) (&cb)) > 0) - RRETURN(MATCH_NOMATCH); - if (rrc < 0) - RRETURN(rrc); + pcre_callout_block cb; + cb.version = 1; /* Version 1 of the callout block */ + cb.callout_number = ecode[1]; + cb.offset_vector = md->offset_vector; + cb.subject = (const char *) md->start_subject; + cb.subject_length = md->end_subject - md->start_subject; + cb.start_match = md->start_match - md->start_subject; + cb.current_position = eptr - md->start_subject; + cb.pattern_position = GET(ecode, 2); + cb.next_item_length = GET(ecode, 2 + LINK_SIZE); + cb.capture_top = offset_top / 2; + cb.capture_last = md->capture_last; + cb.callout_data = md->callout_data; + if ((rrc = (*pcre_callout) (&cb)) > 0) + RRETURN(MATCH_NOMATCH); + if (rrc < 0) + RRETURN(rrc); } ecode += 2 + 2 * LINK_SIZE; break; @@ -7173,67 +7173,67 @@ this stack. */ case OP_RECURSE: { - callpat = md->start_code + GET(ecode, 1); - new_recursive.group_num = *callpat - OP_BRA; - - /* For extended extraction brackets (large number), we have to fish out - the number from a dummy opcode at the start. */ - - if (new_recursive.group_num > EXTRACT_BASIC_MAX) - new_recursive.group_num = GET2(callpat, 2 + LINK_SIZE); - - /* Add to "recursing stack" */ - - new_recursive.prevrec = md->recursive; - md->recursive = &new_recursive; - - /* Find where to continue from afterwards */ - - ecode += 1 + LINK_SIZE; - new_recursive.after_call = ecode; - - /* Now save the offset data. */ - - new_recursive.saved_max = md->offset_end; - if (new_recursive.saved_max <= REC_STACK_SAVE_MAX) - new_recursive.offset_save = stacksave; - else { - new_recursive.offset_save = - (int *) malloc(new_recursive.saved_max * sizeof(int)); - if (new_recursive.offset_save == NULL) - RRETURN(PCRE_ERROR_NOMEMORY); - } - - memcpy(new_recursive.offset_save, md->offset_vector, - new_recursive.saved_max * sizeof(int)); - new_recursive.save_start = md->start_match; - md->start_match = eptr; - - /* OK, now we can do the recursion. For each top-level alternative we - restore the offset and recursion data. */ - - do { - RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, - eptrb, match_isgroup); - if (rrc == MATCH_MATCH) { - md->recursive = new_recursive.prevrec; - if (new_recursive.offset_save != stacksave) - free(new_recursive.offset_save); - RRETURN(MATCH_MATCH); - } else if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - - md->recursive = &new_recursive; - memcpy(md->offset_vector, new_recursive.offset_save, - new_recursive.saved_max * sizeof(int)); - callpat += GET(callpat, 1); - } - while (*callpat == OP_ALT); - - md->recursive = new_recursive.prevrec; - if (new_recursive.offset_save != stacksave) - free(new_recursive.offset_save); - RRETURN(MATCH_NOMATCH); + callpat = md->start_code + GET(ecode, 1); + new_recursive.group_num = *callpat - OP_BRA; + + /* For extended extraction brackets (large number), we have to fish out + the number from a dummy opcode at the start. */ + + if (new_recursive.group_num > EXTRACT_BASIC_MAX) + new_recursive.group_num = GET2(callpat, 2 + LINK_SIZE); + + /* Add to "recursing stack" */ + + new_recursive.prevrec = md->recursive; + md->recursive = &new_recursive; + + /* Find where to continue from afterwards */ + + ecode += 1 + LINK_SIZE; + new_recursive.after_call = ecode; + + /* Now save the offset data. */ + + new_recursive.saved_max = md->offset_end; + if (new_recursive.saved_max <= REC_STACK_SAVE_MAX) + new_recursive.offset_save = stacksave; + else { + new_recursive.offset_save = + (int *) malloc(new_recursive.saved_max * sizeof(int)); + if (new_recursive.offset_save == NULL) + RRETURN(PCRE_ERROR_NOMEMORY); + } + + memcpy(new_recursive.offset_save, md->offset_vector, + new_recursive.saved_max * sizeof(int)); + new_recursive.save_start = md->start_match; + md->start_match = eptr; + + /* OK, now we can do the recursion. For each top-level alternative we + restore the offset and recursion data. */ + + do { + RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, + eptrb, match_isgroup); + if (rrc == MATCH_MATCH) { + md->recursive = new_recursive.prevrec; + if (new_recursive.offset_save != stacksave) + free(new_recursive.offset_save); + RRETURN(MATCH_MATCH); + } else if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + + md->recursive = &new_recursive; + memcpy(md->offset_vector, new_recursive.offset_save, + new_recursive.saved_max * sizeof(int)); + callpat += GET(callpat, 1); + } + while (*callpat == OP_ALT); + + md->recursive = new_recursive.prevrec; + if (new_recursive.offset_save != stacksave) + free(new_recursive.offset_save); + RRETURN(MATCH_NOMATCH); } /* Control never reaches here */ @@ -7246,73 +7246,73 @@ this stack. */ case OP_ONCE: { - prev = ecode; - saved_eptr = eptr; - - do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, - eptrb, match_isgroup); - if (rrc == MATCH_MATCH) - break; - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - ecode += GET(ecode, 1); - } - while (*ecode == OP_ALT); - - /* If hit the end of the group (which could be repeated), fail */ - - if (*ecode != OP_ONCE && *ecode != OP_ALT) - RRETURN(MATCH_NOMATCH); - - /* Continue as from after the assertion, updating the offsets high water - mark, since extracts may have been taken. */ - - do - ecode += GET(ecode, 1); - while (*ecode == OP_ALT); - - offset_top = md->end_offset_top; - eptr = md->end_match_ptr; - - /* For a non-repeating ket, just continue at this level. This also - happens for a repeating ket if no characters were matched in the group. - This is the forcible breaking of infinite loops as implemented in Perl - 5.005. If there is an options reset, it will get obeyed in the normal - course of events. */ - - if (*ecode == OP_KET || eptr == saved_eptr) { - ecode += 1 + LINK_SIZE; - break; - } - - /* The repeating kets try the rest of the pattern or restart from the - preceding bracket, in the appropriate order. We need to reset any options - that changed within the bracket before re-running it, so check the next - opcode. */ - - if (ecode[1 + LINK_SIZE] == OP_OPT) { - ims = (ims & ~PCRE_IMS) | ecode[4]; - } - - if (*ecode == OP_KETRMIN) { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } else { /* OP_KETRMAX */ - - RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } + prev = ecode; + saved_eptr = eptr; + + do { + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, + eptrb, match_isgroup); + if (rrc == MATCH_MATCH) + break; + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + ecode += GET(ecode, 1); + } + while (*ecode == OP_ALT); + + /* If hit the end of the group (which could be repeated), fail */ + + if (*ecode != OP_ONCE && *ecode != OP_ALT) + RRETURN(MATCH_NOMATCH); + + /* Continue as from after the assertion, updating the offsets high water + mark, since extracts may have been taken. */ + + do + ecode += GET(ecode, 1); + while (*ecode == OP_ALT); + + offset_top = md->end_offset_top; + eptr = md->end_match_ptr; + + /* For a non-repeating ket, just continue at this level. This also + happens for a repeating ket if no characters were matched in the group. + This is the forcible breaking of infinite loops as implemented in Perl + 5.005. If there is an options reset, it will get obeyed in the normal + course of events. */ + + if (*ecode == OP_KET || eptr == saved_eptr) { + ecode += 1 + LINK_SIZE; + break; + } + + /* The repeating kets try the rest of the pattern or restart from the + preceding bracket, in the appropriate order. We need to reset any options + that changed within the bracket before re-running it, so check the next + opcode. */ + + if (ecode[1 + LINK_SIZE] == OP_OPT) { + ims = (ims & ~PCRE_IMS) | ecode[4]; + } + + if (*ecode == OP_KETRMIN) { + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } else { /* OP_KETRMAX */ + + RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } } RRETURN(MATCH_NOMATCH); @@ -7321,7 +7321,7 @@ this stack. */ case OP_ALT: do - ecode += GET(ecode, 1); + ecode += GET(ecode, 1); while (*ecode == OP_ALT); break; @@ -7333,28 +7333,28 @@ this stack. */ case OP_BRAZERO: { - next = ecode + 1; - RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - do - next += GET(next, 1); - while (*next == OP_ALT); - ecode = next + 1 + LINK_SIZE; + next = ecode + 1; + RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + do + next += GET(next, 1); + while (*next == OP_ALT); + ecode = next + 1 + LINK_SIZE; } break; case OP_BRAMINZERO: { - next = ecode + 1; - do - next += GET(next, 1); - while (*next == OP_ALT); - RMATCH(rrc, eptr, next + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - ecode++; + next = ecode + 1; + do + next += GET(next, 1); + while (*next == OP_ALT); + RMATCH(rrc, eptr, next + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + ecode++; } break; @@ -7367,110 +7367,110 @@ this stack. */ case OP_KETRMIN: case OP_KETRMAX: { - prev = ecode - GET(ecode, 1); - saved_eptr = eptrb->epb_saved_eptr; + prev = ecode - GET(ecode, 1); + saved_eptr = eptrb->epb_saved_eptr; - /* Back up the stack of bracket start pointers. */ + /* Back up the stack of bracket start pointers. */ - eptrb = eptrb->epb_prev; + eptrb = eptrb->epb_prev; - if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || - *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || - *prev == OP_ONCE) { - md->end_match_ptr = eptr; /* For ONCE */ - md->end_offset_top = offset_top; - RRETURN(MATCH_MATCH); - } + if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || + *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || + *prev == OP_ONCE) { + md->end_match_ptr = eptr; /* For ONCE */ + md->end_offset_top = offset_top; + RRETURN(MATCH_MATCH); + } - /* In all other cases except a conditional group we have to check the - group number back at the start and if necessary complete handling an - extraction by setting the offsets and bumping the high water mark. */ + /* In all other cases except a conditional group we have to check the + group number back at the start and if necessary complete handling an + extraction by setting the offsets and bumping the high water mark. */ - if (*prev != OP_COND) { - number = *prev - OP_BRA; + if (*prev != OP_COND) { + number = *prev - OP_BRA; - /* For extended extraction brackets (large number), we have to fish out - the number from a dummy opcode at the start. */ + /* For extended extraction brackets (large number), we have to fish out + the number from a dummy opcode at the start. */ - if (number > EXTRACT_BASIC_MAX) - number = GET2(prev, 2 + LINK_SIZE); - offset = number << 1; + if (number > EXTRACT_BASIC_MAX) + number = GET2(prev, 2 + LINK_SIZE); + offset = number << 1; #ifdef DEBUG - printf("end bracket %d", number); - printf("\n"); + printf("end bracket %d", number); + printf("\n"); #endif - /* Test for a numbered group. This includes groups called as a result - of recursion. Note that whole-pattern recursion is coded as a recurse - into group 0, so it won't be picked up here. Instead, we catch it when - the OP_END is reached. */ - - if (number > 0) { - md->capture_last = number; - if (offset >= md->offset_max) - md->offset_overflow = TRUE; - else { - md->offset_vector[offset] = - md->offset_vector[md->offset_end - number]; - md->offset_vector[offset + 1] = eptr - md->start_subject; - if (offset_top <= offset) - offset_top = offset + 2; - } - - /* Handle a recursively called group. Restore the offsets - appropriately and continue from after the call. */ - - if (md->recursive != NULL && md->recursive->group_num == number) { - recursion_info *rec = md->recursive; - md->recursive = rec->prevrec; - md->start_match = rec->save_start; - memcpy(md->offset_vector, rec->offset_save, - rec->saved_max * sizeof(int)); - ecode = rec->after_call; - ims = original_ims; - break; - } - } - } - - /* Reset the value of the ims flags, in case they got changed during - the group. */ - - ims = original_ims; - - /* For a non-repeating ket, just continue at this level. This also - happens for a repeating ket if no characters were matched in the group. - This is the forcible breaking of infinite loops as implemented in Perl - 5.005. If there is an options reset, it will get obeyed in the normal - course of events. */ - - if (*ecode == OP_KET || eptr == saved_eptr) { - ecode += 1 + LINK_SIZE; - break; - } - - /* The repeating kets try the rest of the pattern or restart from the - preceding bracket, in the appropriate order. */ - - if (*ecode == OP_KETRMIN) { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } else { /* OP_KETRMAX */ - - RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } + /* Test for a numbered group. This includes groups called as a result + of recursion. Note that whole-pattern recursion is coded as a recurse + into group 0, so it won't be picked up here. Instead, we catch it when + the OP_END is reached. */ + + if (number > 0) { + md->capture_last = number; + if (offset >= md->offset_max) + md->offset_overflow = TRUE; + else { + md->offset_vector[offset] = + md->offset_vector[md->offset_end - number]; + md->offset_vector[offset + 1] = eptr - md->start_subject; + if (offset_top <= offset) + offset_top = offset + 2; + } + + /* Handle a recursively called group. Restore the offsets + appropriately and continue from after the call. */ + + if (md->recursive != NULL && md->recursive->group_num == number) { + recursion_info *rec = md->recursive; + md->recursive = rec->prevrec; + md->start_match = rec->save_start; + memcpy(md->offset_vector, rec->offset_save, + rec->saved_max * sizeof(int)); + ecode = rec->after_call; + ims = original_ims; + break; + } + } + } + + /* Reset the value of the ims flags, in case they got changed during + the group. */ + + ims = original_ims; + + /* For a non-repeating ket, just continue at this level. This also + happens for a repeating ket if no characters were matched in the group. + This is the forcible breaking of infinite loops as implemented in Perl + 5.005. If there is an options reset, it will get obeyed in the normal + course of events. */ + + if (*ecode == OP_KET || eptr == saved_eptr) { + ecode += 1 + LINK_SIZE; + break; + } + + /* The repeating kets try the rest of the pattern or restart from the + preceding bracket, in the appropriate order. */ + + if (*ecode == OP_KETRMIN) { + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } else { /* OP_KETRMAX */ + + RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, + 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } } RRETURN(MATCH_NOMATCH); @@ -7479,12 +7479,12 @@ this stack. */ case OP_CIRC: if (md->notbol && eptr == md->start_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); if ((ims & PCRE_MULTILINE) != 0) { - if (eptr != md->start_subject && eptr[-1] != NEWLINE) - RRETURN(MATCH_NOMATCH); - ecode++; - break; + if (eptr != md->start_subject && eptr[-1] != NEWLINE) + RRETURN(MATCH_NOMATCH); + ecode++; + break; } /* ... else fall through */ @@ -7492,7 +7492,7 @@ this stack. */ case OP_SOD: if (eptr != md->start_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; @@ -7500,7 +7500,7 @@ this stack. */ case OP_SOM: if (eptr != md->start_subject + md->start_offset) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; @@ -7509,25 +7509,25 @@ this stack. */ case OP_DOLL: if ((ims & PCRE_MULTILINE) != 0) { - if (eptr < md->end_subject) { - if (*eptr != NEWLINE) - RRETURN(MATCH_NOMATCH); - } else { - if (md->noteol) - RRETURN(MATCH_NOMATCH); - } - ecode++; - break; + if (eptr < md->end_subject) { + if (*eptr != NEWLINE) + RRETURN(MATCH_NOMATCH); + } else { + if (md->noteol) + RRETURN(MATCH_NOMATCH); + } + ecode++; + break; } else { - if (md->noteol) - RRETURN(MATCH_NOMATCH); - if (!md->endonly) { - if (eptr < md->end_subject - 1 || - (eptr == md->end_subject - 1 && *eptr != NEWLINE)) - RRETURN(MATCH_NOMATCH); - ecode++; - break; - } + if (md->noteol) + RRETURN(MATCH_NOMATCH); + if (!md->endonly) { + if (eptr < md->end_subject - 1 || + (eptr == md->end_subject - 1 && *eptr != NEWLINE)) + RRETURN(MATCH_NOMATCH); + ecode++; + break; + } } /* ... else fall through */ @@ -7535,7 +7535,7 @@ this stack. */ case OP_EOD: if (eptr < md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; @@ -7543,8 +7543,8 @@ this stack. */ case OP_EODN: if (eptr < md->end_subject - 1 || - (eptr == md->end_subject - 1 && *eptr != NEWLINE)) - RRETURN(MATCH_NOMATCH); + (eptr == md->end_subject - 1 && *eptr != NEWLINE)) + RRETURN(MATCH_NOMATCH); ecode++; break; @@ -7554,25 +7554,25 @@ this stack. */ case OP_WORD_BOUNDARY: { - /* Find out if the previous and current characters are "word" characters. - It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to - be "non-word" characters. */ + /* Find out if the previous and current characters are "word" characters. + It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to + be "non-word" characters. */ - /* More streamlined when not in UTF-8 mode */ + /* More streamlined when not in UTF-8 mode */ - { - prev_is_word = (eptr != md->start_subject) && - ((md->ctypes[eptr[-1]] & ctype_word) != 0); - cur_is_word = (eptr < md->end_subject) && - ((md->ctypes[*eptr] & ctype_word) != 0); - } + { + prev_is_word = (eptr != md->start_subject) && + ((md->ctypes[eptr[-1]] & ctype_word) != 0); + cur_is_word = (eptr < md->end_subject) && + ((md->ctypes[*eptr] & ctype_word) != 0); + } - /* Now see if the situation is what we want */ + /* Now see if the situation is what we want */ - if ((*ecode++ == OP_WORD_BOUNDARY) ? - cur_is_word == prev_is_word : cur_is_word != prev_is_word) - RRETURN(MATCH_NOMATCH); + if ((*ecode++ == OP_WORD_BOUNDARY) ? + cur_is_word == prev_is_word : cur_is_word != prev_is_word) + RRETURN(MATCH_NOMATCH); } break; @@ -7580,10 +7580,10 @@ this stack. */ case OP_ANY: if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject - && *eptr == NEWLINE) - RRETURN(MATCH_NOMATCH); + && *eptr == NEWLINE) + RRETURN(MATCH_NOMATCH); if (eptr++ >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; @@ -7592,61 +7592,61 @@ this stack. */ case OP_ANYBYTE: if (eptr++ >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; case OP_NOT_DIGIT: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); if ((md->ctypes[c] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; case OP_DIGIT: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); if ((md->ctypes[c] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; case OP_NOT_WHITESPACE: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); if ((md->ctypes[c] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; case OP_WHITESPACE: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); if ((md->ctypes[c] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; case OP_NOT_WORDCHAR: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); if ((md->ctypes[c] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; case OP_WORDCHAR: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); if ((md->ctypes[c] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; break; @@ -7657,23 +7657,23 @@ this stack. */ case OP_PROP: case OP_NOTPROP: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); { - int chartype, rqdtype; - int othercase; - int category = _pcre_ucp_findchar(c, &chartype, &othercase); - - rqdtype = *(++ecode); - ecode++; - - if (rqdtype >= 128) { - if ((rqdtype - 128 != category) == (op == OP_PROP)) - RRETURN(MATCH_NOMATCH); - } else { - if ((rqdtype != chartype) == (op == OP_PROP)) - RRETURN(MATCH_NOMATCH); - } + int chartype, rqdtype; + int othercase; + int category = _pcre_ucp_findchar(c, &chartype, &othercase); + + rqdtype = *(++ecode); + ecode++; + + if (rqdtype >= 128) { + if ((rqdtype - 128 != category) == (op == OP_PROP)) + RRETURN(MATCH_NOMATCH); + } else { + if ((rqdtype != chartype) == (op == OP_PROP)) + RRETURN(MATCH_NOMATCH); + } } break; @@ -7682,26 +7682,26 @@ this stack. */ case OP_EXTUNI: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); { - int chartype; - int othercase; - int category = _pcre_ucp_findchar(c, &chartype, &othercase); - if (category == ucp_M) - RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject) { - int len = 1; - if (!utf8) - c = *eptr; - else { - GETCHARLEN(c, eptr, len); - } - category = _pcre_ucp_findchar(c, &chartype, &othercase); - if (category != ucp_M) - break; - eptr += len; - } + int chartype; + int othercase; + int category = _pcre_ucp_findchar(c, &chartype, &othercase); + if (category == ucp_M) + RRETURN(MATCH_NOMATCH); + while (eptr < md->end_subject) { + int len = 1; + if (!utf8) + c = *eptr; + else { + GETCHARLEN(c, eptr, len); + } + category = _pcre_ucp_findchar(c, &chartype, &othercase); + if (category != ucp_M) + break; + eptr += len; + } } ecode++; break; @@ -7718,105 +7718,105 @@ this stack. */ case OP_REF: { - offset = GET2(ecode, 1) << 1; /* Doubled ref number */ - ecode += 3; /* Advance past item */ - - /* If the reference is unset, set the length to be longer than the amount - of subject left; this ensures that every attempt at a match fails. We - can't just fail here, because of the possibility of quantifiers with zero - minima. */ - - length = (offset >= offset_top || md->offset_vector[offset] < 0) ? - md->end_subject - eptr + 1 : - md->offset_vector[offset + 1] - md->offset_vector[offset]; - - /* Set up for repetition, or handle the non-repeated case */ - - switch (*ecode) { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - c = *ecode++ - OP_CRSTAR; - minimize = (c & 1) != 0; - min = rep_min[c]; /* Pick up values from tables; */ - max = rep_max[c]; /* zero for max => infinity */ - if (max == 0) - max = INT_MAX; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - minimize = (*ecode == OP_CRMINRANGE); - min = GET2(ecode, 1); - max = GET2(ecode, 3); - if (max == 0) - max = INT_MAX; - ecode += 5; - break; - - default: /* No repeat follows */ - if (!match_ref(offset, eptr, length, md, ims)) - RRETURN(MATCH_NOMATCH); - eptr += length; - continue; /* With the main loop */ - } - - /* If the length of the reference is zero, just continue with the - main loop. */ - - if (length == 0) - continue; - - /* First, ensure the minimum number of matches are present. We get back - the length of the reference string explicitly rather than passing the - address of eptr, so that eptr can be a register variable. */ - - for (i = 1; i <= min; i++) { - if (!match_ref(offset, eptr, length, md, ims)) - RRETURN(MATCH_NOMATCH); - eptr += length; - } - - /* If min = max, continue at the same level without recursion. - They are not both allowed to be zero. */ - - if (min == max) - continue; - - /* If minimizing, keep trying and advancing the pointer */ - - if (minimize) { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || !match_ref(offset, eptr, length, md, ims)) - RRETURN(MATCH_NOMATCH); - eptr += length; - } - /* Control never gets here */ - } - - /* If maximizing, find the longest string and work backwards */ - - else { - pp = eptr; - for (i = min; i < max; i++) { - if (!match_ref(offset, eptr, length, md, ims)) - break; - eptr += length; - } - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - eptr -= length; - } - RRETURN(MATCH_NOMATCH); - } + offset = GET2(ecode, 1) << 1; /* Doubled ref number */ + ecode += 3; /* Advance past item */ + + /* If the reference is unset, set the length to be longer than the amount + of subject left; this ensures that every attempt at a match fails. We + can't just fail here, because of the possibility of quantifiers with zero + minima. */ + + length = (offset >= offset_top || md->offset_vector[offset] < 0) ? + md->end_subject - eptr + 1 : + md->offset_vector[offset + 1] - md->offset_vector[offset]; + + /* Set up for repetition, or handle the non-repeated case */ + + switch (*ecode) { + case OP_CRSTAR: + case OP_CRMINSTAR: + case OP_CRPLUS: + case OP_CRMINPLUS: + case OP_CRQUERY: + case OP_CRMINQUERY: + c = *ecode++ - OP_CRSTAR; + minimize = (c & 1) != 0; + min = rep_min[c]; /* Pick up values from tables; */ + max = rep_max[c]; /* zero for max => infinity */ + if (max == 0) + max = INT_MAX; + break; + + case OP_CRRANGE: + case OP_CRMINRANGE: + minimize = (*ecode == OP_CRMINRANGE); + min = GET2(ecode, 1); + max = GET2(ecode, 3); + if (max == 0) + max = INT_MAX; + ecode += 5; + break; + + default: /* No repeat follows */ + if (!match_ref(offset, eptr, length, md, ims)) + RRETURN(MATCH_NOMATCH); + eptr += length; + continue; /* With the main loop */ + } + + /* If the length of the reference is zero, just continue with the + main loop. */ + + if (length == 0) + continue; + + /* First, ensure the minimum number of matches are present. We get back + the length of the reference string explicitly rather than passing the + address of eptr, so that eptr can be a register variable. */ + + for (i = 1; i <= min; i++) { + if (!match_ref(offset, eptr, length, md, ims)) + RRETURN(MATCH_NOMATCH); + eptr += length; + } + + /* If min = max, continue at the same level without recursion. + They are not both allowed to be zero. */ + + if (min == max) + continue; + + /* If minimizing, keep trying and advancing the pointer */ + + if (minimize) { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || !match_ref(offset, eptr, length, md, ims)) + RRETURN(MATCH_NOMATCH); + eptr += length; + } + /* Control never gets here */ + } + + /* If maximizing, find the longest string and work backwards */ + + else { + pp = eptr; + for (i = min; i < max; i++) { + if (!match_ref(offset, eptr, length, md, ims)) + break; + eptr += length; + } + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + eptr -= length; + } + RRETURN(MATCH_NOMATCH); + } } /* Control never gets here */ @@ -7836,103 +7836,103 @@ this stack. */ case OP_NCLASS: case OP_CLASS: { - data = ecode + 1; /* Save for matching */ - ecode += 33; /* Advance past the item */ - - switch (*ecode) { - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - c = *ecode++ - OP_CRSTAR; - minimize = (c & 1) != 0; - min = rep_min[c]; /* Pick up values from tables; */ - max = rep_max[c]; /* zero for max => infinity */ - if (max == 0) - max = INT_MAX; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - minimize = (*ecode == OP_CRMINRANGE); - min = GET2(ecode, 1); - max = GET2(ecode, 3); - if (max == 0) - max = INT_MAX; - ecode += 5; - break; - - default: /* No repeat follows */ - min = max = 1; - break; - } - - /* First, ensure the minimum number of matches are present. */ - - /* Not UTF-8 mode */ - { - for (i = 1; i <= min; i++) { - if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); - c = *eptr++; - if ((data[c / 8] & (1 << (c & 7))) == 0) - RRETURN(MATCH_NOMATCH); - } - } - - /* If max == min we can continue with the main loop without the - need to recurse. */ - - if (min == max) - continue; - - /* If minimizing, keep testing the rest of the expression and advancing - the pointer while it matches the class. */ - - if (minimize) { - /* Not UTF-8 mode */ - { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); - c = *eptr++; - if ((data[c / 8] & (1 << (c & 7))) == 0) - RRETURN(MATCH_NOMATCH); - } - } - /* Control never gets here */ - } - - /* If maximizing, find the longest possible run, then work backwards. */ - - else { - pp = eptr; - - /* Not UTF-8 mode */ - { - for (i = min; i < max; i++) { - if (eptr >= md->end_subject) - break; - c = *eptr; - if ((data[c / 8] & (1 << (c & 7))) == 0) - break; - eptr++; - } - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - eptr--; - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } - } - - RRETURN(MATCH_NOMATCH); - } + data = ecode + 1; /* Save for matching */ + ecode += 33; /* Advance past the item */ + + switch (*ecode) { + case OP_CRSTAR: + case OP_CRMINSTAR: + case OP_CRPLUS: + case OP_CRMINPLUS: + case OP_CRQUERY: + case OP_CRMINQUERY: + c = *ecode++ - OP_CRSTAR; + minimize = (c & 1) != 0; + min = rep_min[c]; /* Pick up values from tables; */ + max = rep_max[c]; /* zero for max => infinity */ + if (max == 0) + max = INT_MAX; + break; + + case OP_CRRANGE: + case OP_CRMINRANGE: + minimize = (*ecode == OP_CRMINRANGE); + min = GET2(ecode, 1); + max = GET2(ecode, 3); + if (max == 0) + max = INT_MAX; + ecode += 5; + break; + + default: /* No repeat follows */ + min = max = 1; + break; + } + + /* First, ensure the minimum number of matches are present. */ + + /* Not UTF-8 mode */ + { + for (i = 1; i <= min; i++) { + if (eptr >= md->end_subject) + RRETURN(MATCH_NOMATCH); + c = *eptr++; + if ((data[c / 8] & (1 << (c & 7))) == 0) + RRETURN(MATCH_NOMATCH); + } + } + + /* If max == min we can continue with the main loop without the + need to recurse. */ + + if (min == max) + continue; + + /* If minimizing, keep testing the rest of the expression and advancing + the pointer while it matches the class. */ + + if (minimize) { + /* Not UTF-8 mode */ + { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject) + RRETURN(MATCH_NOMATCH); + c = *eptr++; + if ((data[c / 8] & (1 << (c & 7))) == 0) + RRETURN(MATCH_NOMATCH); + } + } + /* Control never gets here */ + } + + /* If maximizing, find the longest possible run, then work backwards. */ + + else { + pp = eptr; + + /* Not UTF-8 mode */ + { + for (i = min; i < max; i++) { + if (eptr >= md->end_subject) + break; + c = *eptr; + if ((data[c / 8] & (1 << (c & 7))) == 0) + break; + eptr++; + } + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + eptr--; + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } + } + + RRETURN(MATCH_NOMATCH); + } } /* Control never gets here */ @@ -7947,11 +7947,11 @@ this stack. */ /* Non-UTF-8 mode */ { - if (md->end_subject - eptr < 1) - RRETURN(MATCH_NOMATCH); - if (ecode[1] != *eptr++) - RRETURN(MATCH_NOMATCH); - ecode += 2; + if (md->end_subject - eptr < 1) + RRETURN(MATCH_NOMATCH); + if (ecode[1] != *eptr++) + RRETURN(MATCH_NOMATCH); + ecode += 2; } break; @@ -7961,11 +7961,11 @@ this stack. */ /* Non-UTF-8 mode */ { - if (md->end_subject - eptr < 1) - RRETURN(MATCH_NOMATCH); - if (md->lcc[ecode[1]] != md->lcc[*eptr++]) - RRETURN(MATCH_NOMATCH); - ecode += 2; + if (md->end_subject - eptr < 1) + RRETURN(MATCH_NOMATCH); + if (md->lcc[ecode[1]] != md->lcc[*eptr++]) + RRETURN(MATCH_NOMATCH); + ecode += 2; } break; @@ -7992,10 +7992,10 @@ this stack. */ case OP_MINQUERY: c = *ecode++ - OP_STAR; minimize = (c & 1) != 0; - min = rep_min[c]; /* Pick up values from tables; */ - max = rep_max[c]; /* zero for max => infinity */ + min = rep_min[c]; /* Pick up values from tables; */ + max = rep_max[c]; /* zero for max => infinity */ if (max == 0) - max = INT_MAX; + max = INT_MAX; /* Common code for all repeated single-character matches. We can give up quickly if there are fewer than the minimum number of characters left in @@ -8005,9 +8005,9 @@ this stack. */ /* When not in UTF-8 mode, load a single-byte character. */ { - if (min > md->end_subject - eptr) - RRETURN(MATCH_NOMATCH); - fc = *ecode++; + if (min > md->end_subject - eptr) + RRETURN(MATCH_NOMATCH); + fc = *ecode++; } /* The value of fc at this point is always less than 256, though we may or @@ -8021,71 +8021,71 @@ this stack. */ if ((ims & PCRE_CASELESS) != 0) { - fc = md->lcc[fc]; - for (i = 1; i <= min; i++) - if (fc != md->lcc[*eptr++]) - RRETURN(MATCH_NOMATCH); - if (min == max) - continue; - if (minimize) { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject || fc != md->lcc[*eptr++]) - RRETURN(MATCH_NOMATCH); - } - /* Control never gets here */ - } else { - pp = eptr; - for (i = min; i < max; i++) { - if (eptr >= md->end_subject || fc != md->lcc[*eptr]) - break; - eptr++; - } - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - eptr--; - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } - RRETURN(MATCH_NOMATCH); - } - /* Control never gets here */ + fc = md->lcc[fc]; + for (i = 1; i <= min; i++) + if (fc != md->lcc[*eptr++]) + RRETURN(MATCH_NOMATCH); + if (min == max) + continue; + if (minimize) { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject || fc != md->lcc[*eptr++]) + RRETURN(MATCH_NOMATCH); + } + /* Control never gets here */ + } else { + pp = eptr; + for (i = min; i < max; i++) { + if (eptr >= md->end_subject || fc != md->lcc[*eptr]) + break; + eptr++; + } + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + eptr--; + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } + RRETURN(MATCH_NOMATCH); + } + /* Control never gets here */ } /* Caseful comparisons (includes all multi-byte characters) */ else { - for (i = 1; i <= min; i++) - if (fc != *eptr++) - RRETURN(MATCH_NOMATCH); - if (min == max) - continue; - if (minimize) { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject || fc != *eptr++) - RRETURN(MATCH_NOMATCH); - } - /* Control never gets here */ - } else { - pp = eptr; - for (i = min; i < max; i++) { - if (eptr >= md->end_subject || fc != *eptr) - break; - eptr++; - } - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - eptr--; - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } - RRETURN(MATCH_NOMATCH); - } + for (i = 1; i <= min; i++) + if (fc != *eptr++) + RRETURN(MATCH_NOMATCH); + if (min == max) + continue; + if (minimize) { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject || fc != *eptr++) + RRETURN(MATCH_NOMATCH); + } + /* Control never gets here */ + } else { + pp = eptr; + for (i = min; i < max; i++) { + if (eptr >= md->end_subject || fc != *eptr) + break; + eptr++; + } + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + eptr--; + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } + RRETURN(MATCH_NOMATCH); + } } /* Control never gets here */ @@ -8094,16 +8094,16 @@ this stack. */ case OP_NOT: if (eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); ecode++; GETCHARINCTEST(c, eptr); if ((ims & PCRE_CASELESS) != 0) { - c = md->lcc[c]; - if (md->lcc[*ecode++] == c) - RRETURN(MATCH_NOMATCH); + c = md->lcc[c]; + if (md->lcc[*ecode++] == c) + RRETURN(MATCH_NOMATCH); } else { - if (*ecode++ == c) - RRETURN(MATCH_NOMATCH); + if (*ecode++ == c) + RRETURN(MATCH_NOMATCH); } break; @@ -8135,10 +8135,10 @@ this stack. */ case OP_NOTMINQUERY: c = *ecode++ - OP_NOTSTAR; minimize = (c & 1) != 0; - min = rep_min[c]; /* Pick up values from tables; */ - max = rep_max[c]; /* zero for max => infinity */ + min = rep_min[c]; /* Pick up values from tables; */ + max = rep_max[c]; /* zero for max => infinity */ if (max == 0) - max = INT_MAX; + max = INT_MAX; /* Common code for all repeated single-byte matches. We can give up quickly if there are fewer than the minimum number of bytes left in the @@ -8146,7 +8146,7 @@ this stack. */ REPEATNOTCHAR: if (min > md->end_subject - eptr) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); fc = *ecode++; /* The code is duplicated for the caseless and caseful cases, for speed, @@ -8158,108 +8158,108 @@ this stack. */ characters and work backwards. */ if ((ims & PCRE_CASELESS) != 0) { - fc = md->lcc[fc]; - - - /* Not UTF-8 mode */ - { - for (i = 1; i <= min; i++) - if (fc == md->lcc[*eptr++]) - RRETURN(MATCH_NOMATCH); - } - - if (min == max) - continue; - - if (minimize) { - /* Not UTF-8 mode */ - { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject - || fc == md->lcc[*eptr++]) - RRETURN(MATCH_NOMATCH); - } - } - /* Control never gets here */ - } - - /* Maximize case */ - - else { - pp = eptr; - - /* Not UTF-8 mode */ - { - for (i = min; i < max; i++) { - if (eptr >= md->end_subject || fc == md->lcc[*eptr]) - break; - eptr++; - } - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - eptr--; - } - } - - RRETURN(MATCH_NOMATCH); - } - /* Control never gets here */ + fc = md->lcc[fc]; + + + /* Not UTF-8 mode */ + { + for (i = 1; i <= min; i++) + if (fc == md->lcc[*eptr++]) + RRETURN(MATCH_NOMATCH); + } + + if (min == max) + continue; + + if (minimize) { + /* Not UTF-8 mode */ + { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject + || fc == md->lcc[*eptr++]) + RRETURN(MATCH_NOMATCH); + } + } + /* Control never gets here */ + } + + /* Maximize case */ + + else { + pp = eptr; + + /* Not UTF-8 mode */ + { + for (i = min; i < max; i++) { + if (eptr >= md->end_subject || fc == md->lcc[*eptr]) + break; + eptr++; + } + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + eptr--; + } + } + + RRETURN(MATCH_NOMATCH); + } + /* Control never gets here */ } /* Caseful comparisons */ else { - /* Not UTF-8 mode */ - { - for (i = 1; i <= min; i++) - if (fc == *eptr++) - RRETURN(MATCH_NOMATCH); - } - - if (min == max) - continue; - - if (minimize) { - /* Not UTF-8 mode */ - { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject || fc == *eptr++) - RRETURN(MATCH_NOMATCH); - } - } - /* Control never gets here */ - } - - /* Maximize case */ - - else { - pp = eptr; - - /* Not UTF-8 mode */ - { - for (i = min; i < max; i++) { - if (eptr >= md->end_subject || fc == *eptr) - break; - eptr++; - } - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - eptr--; - } - } - - RRETURN(MATCH_NOMATCH); - } + /* Not UTF-8 mode */ + { + for (i = 1; i <= min; i++) + if (fc == *eptr++) + RRETURN(MATCH_NOMATCH); + } + + if (min == max) + continue; + + if (minimize) { + /* Not UTF-8 mode */ + { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject || fc == *eptr++) + RRETURN(MATCH_NOMATCH); + } + } + /* Control never gets here */ + } + + /* Maximize case */ + + else { + pp = eptr; + + /* Not UTF-8 mode */ + { + for (i = min; i < max; i++) { + if (eptr >= md->end_subject || fc == *eptr) + break; + eptr++; + } + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + eptr--; + } + } + + RRETURN(MATCH_NOMATCH); + } } /* Control never gets here */ @@ -8289,31 +8289,31 @@ this stack. */ case OP_TYPEMINQUERY: c = *ecode++ - OP_TYPESTAR; minimize = (c & 1) != 0; - min = rep_min[c]; /* Pick up values from tables; */ - max = rep_max[c]; /* zero for max => infinity */ + min = rep_min[c]; /* Pick up values from tables; */ + max = rep_max[c]; /* zero for max => infinity */ if (max == 0) - max = INT_MAX; + max = INT_MAX; /* Common code for all repeated single character type matches. Note that in UTF-8 mode, '.' matches a character of any length, but for the other character types, the valid characters are all one-byte long. */ REPEATTYPE: - ctype = *ecode++; /* Code for the character type */ + ctype = *ecode++; /* Code for the character type */ #ifdef SUPPORT_UCP if (ctype == OP_PROP || ctype == OP_NOTPROP) { - prop_fail_result = ctype == OP_NOTPROP; - prop_type = *ecode++; - if (prop_type >= 128) { - prop_test_against = prop_type - 128; - prop_test_variable = &prop_category; - } else { - prop_test_against = prop_type; - prop_test_variable = &prop_chartype; - } + prop_fail_result = ctype == OP_NOTPROP; + prop_type = *ecode++; + if (prop_type >= 128) { + prop_test_against = prop_type - 128; + prop_test_variable = &prop_category; + } else { + prop_test_against = prop_type; + prop_test_variable = &prop_chartype; + } } else - prop_type = -1; + prop_type = -1; #endif /* First, ensure the minimum number of matches are present. Use inline @@ -8325,113 +8325,113 @@ this stack. */ and single-bytes. */ if (min > md->end_subject - eptr) - RRETURN(MATCH_NOMATCH); + RRETURN(MATCH_NOMATCH); if (min > 0) { #ifdef SUPPORT_UCP - if (prop_type > 0) { - for (i = 1; i <= min; i++) { - GETCHARINC(c, eptr); - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if ((*prop_test_variable == prop_test_against) == prop_fail_result) - RRETURN(MATCH_NOMATCH); - } - } - - /* Match extended Unicode sequences. We will get here only if the - support is in the binary; otherwise a compile-time error occurs. */ - - else if (ctype == OP_EXTUNI) { - for (i = 1; i <= min; i++) { - GETCHARINCTEST(c, eptr); - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category == ucp_M) - RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject) { - int len = 1; - if (!utf8) - c = *eptr; - else { - GETCHARLEN(c, eptr, len); - } - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category != ucp_M) - break; - eptr += len; - } - } - } - - else -#endif /* SUPPORT_UCP */ + if (prop_type > 0) { + for (i = 1; i <= min; i++) { + GETCHARINC(c, eptr); + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if ((*prop_test_variable == prop_test_against) == prop_fail_result) + RRETURN(MATCH_NOMATCH); + } + } + + /* Match extended Unicode sequences. We will get here only if the + support is in the binary; otherwise a compile-time error occurs. */ + + else if (ctype == OP_EXTUNI) { + for (i = 1; i <= min; i++) { + GETCHARINCTEST(c, eptr); + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category == ucp_M) + RRETURN(MATCH_NOMATCH); + while (eptr < md->end_subject) { + int len = 1; + if (!utf8) + c = *eptr; + else { + GETCHARLEN(c, eptr, len); + } + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category != ucp_M) + break; + eptr += len; + } + } + } + + else +#endif /* SUPPORT_UCP */ /* Handle all other cases when the coding is UTF-8 */ - /* Code for the non-UTF-8 case for minimum matching of operators other - than OP_PROP and OP_NOTPROP. */ - - switch (ctype) { - case OP_ANY: - if ((ims & PCRE_DOTALL) == 0) { - for (i = 1; i <= min; i++) - if (*eptr++ == NEWLINE) - RRETURN(MATCH_NOMATCH); - } else - eptr += min; - break; - - case OP_ANYBYTE: - eptr += min; - break; - - case OP_NOT_DIGIT: - for (i = 1; i <= min; i++) - if ((md->ctypes[*eptr++] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_DIGIT: - for (i = 1; i <= min; i++) - if ((md->ctypes[*eptr++] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WHITESPACE: - for (i = 1; i <= min; i++) - if ((md->ctypes[*eptr++] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WHITESPACE: - for (i = 1; i <= min; i++) - if ((md->ctypes[*eptr++] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WORDCHAR: - for (i = 1; i <= min; i++) - if ((md->ctypes[*eptr++] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WORDCHAR: - for (i = 1; i <= min; i++) - if ((md->ctypes[*eptr++] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - break; - - default: - RRETURN(PCRE_ERROR_INTERNAL); - } + /* Code for the non-UTF-8 case for minimum matching of operators other + than OP_PROP and OP_NOTPROP. */ + + switch (ctype) { + case OP_ANY: + if ((ims & PCRE_DOTALL) == 0) { + for (i = 1; i <= min; i++) + if (*eptr++ == NEWLINE) + RRETURN(MATCH_NOMATCH); + } else + eptr += min; + break; + + case OP_ANYBYTE: + eptr += min; + break; + + case OP_NOT_DIGIT: + for (i = 1; i <= min; i++) + if ((md->ctypes[*eptr++] & ctype_digit) != 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_DIGIT: + for (i = 1; i <= min; i++) + if ((md->ctypes[*eptr++] & ctype_digit) == 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_NOT_WHITESPACE: + for (i = 1; i <= min; i++) + if ((md->ctypes[*eptr++] & ctype_space) != 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_WHITESPACE: + for (i = 1; i <= min; i++) + if ((md->ctypes[*eptr++] & ctype_space) == 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_NOT_WORDCHAR: + for (i = 1; i <= min; i++) + if ((md->ctypes[*eptr++] & ctype_word) != 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_WORDCHAR: + for (i = 1; i <= min; i++) + if ((md->ctypes[*eptr++] & ctype_word) == 0) + RRETURN(MATCH_NOMATCH); + break; + + default: + RRETURN(PCRE_ERROR_INTERNAL); + } } /* If min = max, continue at the same level without recursing */ if (min == max) - continue; + continue; /* If minimizing, we have to test the rest of the pattern before each subsequent match. Again, separate the UTF-8 case for speed, and also @@ -8439,109 +8439,109 @@ this stack. */ if (minimize) { #ifdef SUPPORT_UCP - if (prop_type > 0) { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); - GETCHARINC(c, eptr); - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if ((*prop_test_variable == prop_test_against) == prop_fail_result) - RRETURN(MATCH_NOMATCH); - } - } - - /* Match extended Unicode sequences. We will get here only if the - support is in the binary; otherwise a compile-time error occurs. */ - - else if (ctype == OP_EXTUNI) { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); - GETCHARINCTEST(c, eptr); - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category == ucp_M) - RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject) { - int len = 1; - if (!utf8) - c = *eptr; - else { - GETCHARLEN(c, eptr, len); - } - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category != ucp_M) - break; - eptr += len; - } - } - } - - else -#endif /* SUPPORT_UCP */ - - /* Not UTF-8 mode */ - { - for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (fi >= max || eptr >= md->end_subject) - RRETURN(MATCH_NOMATCH); - c = *eptr++; - switch (ctype) { - case OP_ANY: - if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) - RRETURN(MATCH_NOMATCH); - break; - - case OP_ANYBYTE: - break; - - case OP_NOT_DIGIT: - if ((md->ctypes[c] & ctype_digit) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_DIGIT: - if ((md->ctypes[c] & ctype_digit) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WHITESPACE: - if ((md->ctypes[c] & ctype_space) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WHITESPACE: - if ((md->ctypes[c] & ctype_space) == 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_NOT_WORDCHAR: - if ((md->ctypes[c] & ctype_word) != 0) - RRETURN(MATCH_NOMATCH); - break; - - case OP_WORDCHAR: - if ((md->ctypes[c] & ctype_word) == 0) - RRETURN(MATCH_NOMATCH); - break; - - default: - RRETURN(PCRE_ERROR_INTERNAL); - } - } - } - /* Control never gets here */ + if (prop_type > 0) { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject) + RRETURN(MATCH_NOMATCH); + GETCHARINC(c, eptr); + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if ((*prop_test_variable == prop_test_against) == prop_fail_result) + RRETURN(MATCH_NOMATCH); + } + } + + /* Match extended Unicode sequences. We will get here only if the + support is in the binary; otherwise a compile-time error occurs. */ + + else if (ctype == OP_EXTUNI) { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject) + RRETURN(MATCH_NOMATCH); + GETCHARINCTEST(c, eptr); + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category == ucp_M) + RRETURN(MATCH_NOMATCH); + while (eptr < md->end_subject) { + int len = 1; + if (!utf8) + c = *eptr; + else { + GETCHARLEN(c, eptr, len); + } + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category != ucp_M) + break; + eptr += len; + } + } + } + + else +#endif /* SUPPORT_UCP */ + + /* Not UTF-8 mode */ + { + for (fi = min;; fi++) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (fi >= max || eptr >= md->end_subject) + RRETURN(MATCH_NOMATCH); + c = *eptr++; + switch (ctype) { + case OP_ANY: + if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) + RRETURN(MATCH_NOMATCH); + break; + + case OP_ANYBYTE: + break; + + case OP_NOT_DIGIT: + if ((md->ctypes[c] & ctype_digit) != 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_DIGIT: + if ((md->ctypes[c] & ctype_digit) == 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_NOT_WHITESPACE: + if ((md->ctypes[c] & ctype_space) != 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_WHITESPACE: + if ((md->ctypes[c] & ctype_space) == 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_NOT_WORDCHAR: + if ((md->ctypes[c] & ctype_word) != 0) + RRETURN(MATCH_NOMATCH); + break; + + case OP_WORDCHAR: + if ((md->ctypes[c] & ctype_word) == 0) + RRETURN(MATCH_NOMATCH); + break; + + default: + RRETURN(PCRE_ERROR_INTERNAL); + } + } + } + /* Control never gets here */ } /* If maximizing it is worth using inline code for speed, doing the type @@ -8549,182 +8549,182 @@ this stack. */ UTF-8 and UCP stuff separate. */ else { - pp = eptr; /* Remember where we started */ + pp = eptr; /* Remember where we started */ #ifdef SUPPORT_UCP - if (prop_type > 0) { - for (i = min; i < max; i++) { - int len = 1; - if (eptr >= md->end_subject) - break; - GETCHARLEN(c, eptr, len); - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if ((*prop_test_variable == prop_test_against) == prop_fail_result) - break; - eptr += len; - } - - /* eptr is now past the end of the maximum run */ - - for (;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (eptr-- == pp) - break; /* Stop if tried at original pos */ - BACKCHAR(eptr); - } - } - - /* Match extended Unicode sequences. We will get here only if the - support is in the binary; otherwise a compile-time error occurs. */ - - else if (ctype == OP_EXTUNI) { - for (i = min; i < max; i++) { - if (eptr >= md->end_subject) - break; - GETCHARINCTEST(c, eptr); - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category == ucp_M) - break; - while (eptr < md->end_subject) { - int len = 1; - if (!utf8) - c = *eptr; - else { - GETCHARLEN(c, eptr, len); - } - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category != ucp_M) - break; - eptr += len; - } - } - - /* eptr is now past the end of the maximum run */ - - for (;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - if (eptr-- == pp) - break; /* Stop if tried at original pos */ - for (;;) { /* Move back over one extended */ - int len = 1; - BACKCHAR(eptr); - if (!utf8) - c = *eptr; - else { - GETCHARLEN(c, eptr, len); - } - prop_category = - _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); - if (prop_category != ucp_M) - break; - eptr--; - } - } - } - - else -#endif /* SUPPORT_UCP */ - - - /* Not UTF-8 mode */ - { - switch (ctype) { - case OP_ANY: - if ((ims & PCRE_DOTALL) == 0) { - for (i = min; i < max; i++) { - if (eptr >= md->end_subject || *eptr == NEWLINE) - break; - eptr++; - } - break; - } - /* For DOTALL case, fall through and treat as \C */ - - case OP_ANYBYTE: - c = max - min; - if (c > md->end_subject - eptr) - c = md->end_subject - eptr; - eptr += c; - break; - - case OP_NOT_DIGIT: - for (i = min; i < max; i++) { - if (eptr >= md->end_subject - || (md->ctypes[*eptr] & ctype_digit) != 0) - break; - eptr++; - } - break; - - case OP_DIGIT: - for (i = min; i < max; i++) { - if (eptr >= md->end_subject - || (md->ctypes[*eptr] & ctype_digit) == 0) - break; - eptr++; - } - break; - - case OP_NOT_WHITESPACE: - for (i = min; i < max; i++) { - if (eptr >= md->end_subject - || (md->ctypes[*eptr] & ctype_space) != 0) - break; - eptr++; - } - break; - - case OP_WHITESPACE: - for (i = min; i < max; i++) { - if (eptr >= md->end_subject - || (md->ctypes[*eptr] & ctype_space) == 0) - break; - eptr++; - } - break; - - case OP_NOT_WORDCHAR: - for (i = min; i < max; i++) { - if (eptr >= md->end_subject - || (md->ctypes[*eptr] & ctype_word) != 0) - break; - eptr++; - } - break; - - case OP_WORDCHAR: - for (i = min; i < max; i++) { - if (eptr >= md->end_subject - || (md->ctypes[*eptr] & ctype_word) == 0) - break; - eptr++; - } - break; - - default: - RRETURN(PCRE_ERROR_INTERNAL); - } - - /* eptr is now past the end of the maximum run */ - - while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); - eptr--; - if (rrc != MATCH_NOMATCH) - RRETURN(rrc); - } - } - - /* Get here if we can't make it match with any permitted repetitions */ - - RRETURN(MATCH_NOMATCH); + if (prop_type > 0) { + for (i = min; i < max; i++) { + int len = 1; + if (eptr >= md->end_subject) + break; + GETCHARLEN(c, eptr, len); + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if ((*prop_test_variable == prop_test_against) == prop_fail_result) + break; + eptr += len; + } + + /* eptr is now past the end of the maximum run */ + + for (;;) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (eptr-- == pp) + break; /* Stop if tried at original pos */ + BACKCHAR(eptr); + } + } + + /* Match extended Unicode sequences. We will get here only if the + support is in the binary; otherwise a compile-time error occurs. */ + + else if (ctype == OP_EXTUNI) { + for (i = min; i < max; i++) { + if (eptr >= md->end_subject) + break; + GETCHARINCTEST(c, eptr); + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category == ucp_M) + break; + while (eptr < md->end_subject) { + int len = 1; + if (!utf8) + c = *eptr; + else { + GETCHARLEN(c, eptr, len); + } + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category != ucp_M) + break; + eptr += len; + } + } + + /* eptr is now past the end of the maximum run */ + + for (;;) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + if (eptr-- == pp) + break; /* Stop if tried at original pos */ + for (;;) { /* Move back over one extended */ + int len = 1; + BACKCHAR(eptr); + if (!utf8) + c = *eptr; + else { + GETCHARLEN(c, eptr, len); + } + prop_category = + _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase); + if (prop_category != ucp_M) + break; + eptr--; + } + } + } + + else +#endif /* SUPPORT_UCP */ + + + /* Not UTF-8 mode */ + { + switch (ctype) { + case OP_ANY: + if ((ims & PCRE_DOTALL) == 0) { + for (i = min; i < max; i++) { + if (eptr >= md->end_subject || *eptr == NEWLINE) + break; + eptr++; + } + break; + } + /* For DOTALL case, fall through and treat as \C */ + + case OP_ANYBYTE: + c = max - min; + if (c > md->end_subject - eptr) + c = md->end_subject - eptr; + eptr += c; + break; + + case OP_NOT_DIGIT: + for (i = min; i < max; i++) { + if (eptr >= md->end_subject + || (md->ctypes[*eptr] & ctype_digit) != 0) + break; + eptr++; + } + break; + + case OP_DIGIT: + for (i = min; i < max; i++) { + if (eptr >= md->end_subject + || (md->ctypes[*eptr] & ctype_digit) == 0) + break; + eptr++; + } + break; + + case OP_NOT_WHITESPACE: + for (i = min; i < max; i++) { + if (eptr >= md->end_subject + || (md->ctypes[*eptr] & ctype_space) != 0) + break; + eptr++; + } + break; + + case OP_WHITESPACE: + for (i = min; i < max; i++) { + if (eptr >= md->end_subject + || (md->ctypes[*eptr] & ctype_space) == 0) + break; + eptr++; + } + break; + + case OP_NOT_WORDCHAR: + for (i = min; i < max; i++) { + if (eptr >= md->end_subject + || (md->ctypes[*eptr] & ctype_word) != 0) + break; + eptr++; + } + break; + + case OP_WORDCHAR: + for (i = min; i < max; i++) { + if (eptr >= md->end_subject + || (md->ctypes[*eptr] & ctype_word) == 0) + break; + eptr++; + } + break; + + default: + RRETURN(PCRE_ERROR_INTERNAL); + } + + /* eptr is now past the end of the maximum run */ + + while (eptr >= pp) { + RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + eptr--; + if (rrc != MATCH_NOMATCH) + RRETURN(rrc); + } + } + + /* Get here if we can't make it match with any permitted repetitions */ + + RRETURN(MATCH_NOMATCH); } /* Control never gets here */ @@ -8741,7 +8741,7 @@ this stack. */ that "continue" in the code above comes out to here to repeat the main loop. */ - } /* End of main loop */ + } /* End of main loop */ /* Control never reaches here */ } @@ -8830,8 +8830,8 @@ Returns: > 0 => success; value is the number of elements filled in int pcre_exec(const pcre * argument_re, const pcre_extra * extra_data, - const char *subject, int length, int start_offset, int options, - int *offsets, int offsetcount) + const char *subject, int length, int start_offset, int options, + int *offsets, int offsetcount) { int rc, resetcount, ocount; int first_byte = -1; @@ -8936,7 +8936,7 @@ study data too. */ match_block.partial = (options & PCRE_PARTIAL) != 0; match_block.hitend = FALSE; - match_block.recursive = NULL; /* No recursion at top level */ + match_block.recursive = NULL; /* No recursion at top level */ match_block.lcc = tables + lcc_offset; match_block.ctypes = tables + ctypes_offset; @@ -9007,11 +9007,11 @@ studied, there may be a bitmap of possible first characters. */ if ((re->options & PCRE_FIRSTSET) != 0) { first_byte = re->first_byte & 255; if ((first_byte_caseless = - ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) - first_byte = match_block.lcc[first_byte]; + ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) + first_byte = match_block.lcc[first_byte]; } else if (!startline && study != NULL && - (study->options & PCRE_STUDY_MAPPED) != 0) + (study->options & PCRE_STUDY_MAPPED) != 0) start_bits = study->start_bits; } @@ -9021,7 +9021,7 @@ character" set. */ if ((re->options & PCRE_REQCHSET) != 0) { req_byte = re->req_byte & 255; req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; - req_byte2 = (tables + fcc_offset)[req_byte]; /* case flipped */ + req_byte2 = (tables + fcc_offset)[req_byte]; /* case flipped */ } /* Loop for handling unanchored repeated matching attempts; for anchored regexs @@ -9036,7 +9036,7 @@ the loop runs just once. */ register int *iptr = match_block.offset_vector; register int *iend = iptr + resetcount; while (iptr < iend) - *iptr++ = -1; + *iptr++ = -1; } /* Advance to a unique first char if possible. If firstline is TRUE, the @@ -9048,7 +9048,7 @@ the loop runs just once. */ if (firstline) { const uschar *t = start_match; while (t < save_end_subject && *t != '\n') - t++; + t++; end_subject = t; } @@ -9056,20 +9056,20 @@ the loop runs just once. */ if (first_byte >= 0) { if (first_byte_caseless) - while (start_match < end_subject && - match_block.lcc[*start_match] != first_byte) - start_match++; + while (start_match < end_subject && + match_block.lcc[*start_match] != first_byte) + start_match++; else - while (start_match < end_subject && *start_match != first_byte) - start_match++; + while (start_match < end_subject && *start_match != first_byte) + start_match++; } /* Or to just after \n for a multiline match if possible */ else if (startline) { if (start_match > match_block.start_subject + start_offset) { - while (start_match < end_subject && start_match[-1] != NEWLINE) - start_match++; + while (start_match < end_subject && start_match[-1] != NEWLINE) + start_match++; } } @@ -9077,11 +9077,11 @@ the loop runs just once. */ else if (start_bits != NULL) { while (start_match < end_subject) { - register unsigned int c = *start_match; - if ((start_bits[c / 8] & (1 << (c & 7))) == 0) - start_match++; - else - break; + register unsigned int c = *start_match; + if ((start_bits[c / 8] & (1 << (c & 7))) == 0) + start_match++; + else + break; } } @@ -9089,7 +9089,7 @@ the loop runs just once. */ end_subject = save_end_subject; -#ifdef DEBUG /* Sigh. Some compilers never learn. */ +#ifdef DEBUG /* Sigh. Some compilers never learn. */ printf(">>>> Match against: "); pchars(start_match, end_subject - start_match, TRUE, &match_block); printf("\n"); @@ -9112,40 +9112,40 @@ the loop runs just once. */ */ if (req_byte >= 0 && - end_subject - start_match < REQ_BYTE_MAX && !match_block.partial) { + end_subject - start_match < REQ_BYTE_MAX && !match_block.partial) { register const uschar *p = start_match + ((first_byte >= 0) ? 1 : 0); /* We don't need to repeat the search if we haven't yet reached the place we found it at last time. */ if (p > req_byte_ptr) { - if (req_byte_caseless) { - while (p < end_subject) { - register int pp = *p++; - if (pp == req_byte || pp == req_byte2) { - p--; - break; - } - } - } else { - while (p < end_subject) { - if (*p++ == req_byte) { - p--; - break; - } - } - } - - /* If we can't find the required character, break the matching loop */ - - if (p >= end_subject) - break; - - /* If we have found the required character, save the point where we - found it, so that we don't search again next time round the loop if - the start hasn't passed this character yet. */ - - req_byte_ptr = p; + if (req_byte_caseless) { + while (p < end_subject) { + register int pp = *p++; + if (pp == req_byte || pp == req_byte2) { + p--; + break; + } + } + } else { + while (p < end_subject) { + if (*p++ == req_byte) { + p--; + break; + } + } + } + + /* If we can't find the required character, break the matching loop */ + + if (p >= end_subject) + break; + + /* If we have found the required character, save the point where we + found it, so that we don't search again next time round the loop if + the start hasn't passed this character yet. */ + + req_byte_ptr = p; } } @@ -9160,7 +9160,7 @@ the loop runs just once. */ match_block.match_call_count = 0; rc = match(start_match, match_block.start_code, 2, &match_block, ims, NULL, - match_isgroup); + match_isgroup); /* When the result is no match, if the subject's first character was a newline and the PCRE_FIRSTLINE option is set, break (which will return @@ -9171,7 +9171,7 @@ the loop runs just once. */ if (rc == MATCH_NOMATCH) { if (firstline && *start_match == NEWLINE) - break; + break; start_match++; continue; } @@ -9185,11 +9185,11 @@ the loop runs just once. */ if (using_temporary_offsets) { if (offsetcount >= 4) { - memcpy(offsets + 2, match_block.offset_vector + 2, - (offsetcount - 2) * sizeof(int)); + memcpy(offsets + 2, match_block.offset_vector + 2, + (offsetcount - 2) * sizeof(int)); } if (match_block.end_offset_top > offsetcount) - match_block.offset_overflow = TRUE; + match_block.offset_overflow = TRUE; free(match_block.offset_vector); } diff --git a/src/player.c b/src/player.c index 50aece7..eb6d799 100644 --- a/src/player.c +++ b/src/player.c @@ -92,15 +92,15 @@ password_check(dbref player, const char *password) /* shs encryption didn't match. Try crypt(3) */ if (strcmp(crypt(password, "XX"), saved) != 0) /* Nope */ -#endif /* HAS_CRYPT */ +#endif /* HAS_CRYPT */ /* crypt() didn't work. Try plaintext, being sure to not * allow unencrypted entry of encrypted password */ if ((strcmp(saved, password) != 0) - || (strlen(password) < 4) - || ((password[0] == 'X') && (password[1] == 'X'))) { - /* Nothing worked. You lose. */ - free(saved); - return 0; + || (strlen(password) < 4) + || ((password[0] == 'X') && (password[1] == 'X'))) { + /* Nothing worked. You lose. */ + free(saved); + return 0; } /* Something worked. Change password to SHS-encrypted */ (void) atr_add(player, pword_attr, passwd, GOD, 0); @@ -175,8 +175,8 @@ connect_player(const char *name, const char *password, const char *host, } if (Suspect_Site(host, player) || Suspect_Site(ip, player)) { do_log(LT_CONN, 0, 0, - T("Connection from Suspect site. Setting %s(#%d) suspect."), - Name(player), player); + T("Connection from Suspect site. Setting %s(#%d) suspect."), + Name(player), player); set_flag_internal(player, "SUSPECT"); } return player; @@ -244,7 +244,7 @@ dbref create_guest(const char *host, const char *ip) { */ dbref create_player(const char *name, const char *password, const char *host, - const char *ip) + const char *ip) { dbref player; if (!ok_player_name(name, NOTHING, NOTHING)) { @@ -291,7 +291,7 @@ create_player(const char *name, const char *password, const char *host, */ dbref email_register_player(const char *name, const char *email, const char *host, - const char *ip) + const char *ip) { char *p; char passwd[BUFFER_LEN]; @@ -318,9 +318,9 @@ email_register_player(const char *name, const char *email, const char *host, p++; if (!Site_Can_Register(p)) { if (!Deny_Silent_Site(p, AMBIGUOUS)) { - do_log(LT_CONN, 0, 0, - T("Failed registration (bad site in email: %s) from %s"), - email, host); + do_log(LT_CONN, 0, 0, + T("Failed registration (bad site in email: %s) from %s"), + email, host); } return NOTHING; } @@ -329,9 +329,9 @@ email_register_player(const char *name, const char *email, const char *host, if (!Site_Can_Register(email)) { *p = '!'; if (!Deny_Silent_Site(email, AMBIGUOUS)) { - do_log(LT_CONN, 0, 0, - T("Failed registration (bad site in email: %s) from %s"), - email, host); + do_log(LT_CONN, 0, 0, + T("Failed registration (bad site in email: %s) from %s"), + email, host); } return NOTHING; } else @@ -339,7 +339,7 @@ email_register_player(const char *name, const char *email, const char *host, } else { if (!Deny_Silent_Site(host, AMBIGUOUS)) { do_log(LT_CONN, 0, 0, T("Failed registration (bad email: %s) from %s"), - email, host); + email, host); } return NOTHING; } @@ -369,8 +369,8 @@ email_register_player(const char *name, const char *email, const char *host, #endif popen(tprintf("%s -t", SENDMAIL), "w")) == NULL) { do_log(LT_CONN, 0, 0, - T("Failed registration of %s by %s: unable to open sendmail"), - name, email); + T("Failed registration of %s by %s: unable to open sendmail"), + name, email); reserve_fd(); return NOTHING; } @@ -384,7 +384,7 @@ email_register_player(const char *name, const char *email, const char *host, fprintf(fp, T("The password is %s\n"), passwd); fprintf(fp, "\n"); fprintf(fp, T("To access this character, connect to %s and type:\n"), - MUDNAME); + MUDNAME); fprintf(fp, "\tconnect \"%s\" %s\n", name, passwd); fprintf(fp, "\n"); pclose(fp); @@ -399,7 +399,7 @@ email_register_player(const char *name, const char *email, const char *host, #else dbref email_register_player(const char *name, const char *email, const char *host, - const char *ip) + const char *ip) { do_log(LT_CONN, 0, 0, T("Failed registration (no sendmail) from %s"), host); return NOTHING; @@ -408,12 +408,11 @@ email_register_player(const char *name, const char *email, const char *host, static dbref make_player(const char *name, const char *password, const char *host, - const char *ip) + const char *ip) { dbref player; char temp[SBUF_LEN]; - object_flag_type flags; player = new_object(); @@ -424,16 +423,14 @@ make_player(const char *name, const char *password, const char *host, Owner(player) = player; Parent(player) = NOTHING; Type(player) = TYPE_PLAYER; - flags = string_to_bits("FLAG", options.player_flags); - copy_flag_bitmask("FLAG", Flags(player), flags); - destroy_flag_bitmask(flags); + Flags(player) = string_to_bits("FLAG", options.player_flags); if (Suspect_Site(host, player) || Suspect_Site(ip, player)) set_flag_internal(player, "SUSPECT"); set_initial_warnings(player); /* Modtime tracks login failures */ ModTime(player) = (time_t) 0; (void) atr_add(player, "XYXXY", mush_crypt(password), GOD, 0); - giveto(player, START_BONUS); /* starting bonus */ + giveto(player, START_BONUS); /* starting bonus */ (void) atr_add(player, "LAST", show_time(mudtime, 0), GOD, 0); (void) atr_add(player, "LASTSITE", host, GOD, 0); (void) atr_add(player, "LASTIP", ip, GOD, 0); @@ -486,14 +483,14 @@ do_password(dbref player, dbref cause, const char *old, const char *newobj) sp = old; bp = old_eval; process_expression(old_eval, &bp, &sp, player, player, cause, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; old = old_eval; sp = newobj; bp = new_eval; process_expression(new_eval, &bp, &sp, player, player, cause, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; newobj = new_eval; } diff --git a/src/plyrlist.c b/src/plyrlist.c index 75377aa..1638c5a 100644 --- a/src/plyrlist.c +++ b/src/plyrlist.c @@ -188,7 +188,7 @@ delete_player(dbref player, const char *alias) */ void reset_player_list(dbref player, const char *oldname, const char *oldalias, - const char *name, const char *alias) + const char *name, const char *alias) { char tbuf1[BUFFER_LEN]; char tbuf2[BUFFER_LEN]; diff --git a/src/portmsg.c b/src/portmsg.c index 161b3a0..fea0109 100644 --- a/src/portmsg.c +++ b/src/portmsg.c @@ -151,7 +151,7 @@ main(int argc, char **argv) } if ((msgfd = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, "error: cannot open message file [%s]: %s\n", argv[1], - strerror(errno)); + strerror(errno)); return 1; } /* read the message */ diff --git a/src/predicat.c b/src/predicat.c index a9b4f46..f4de0dd 100644 --- a/src/predicat.c +++ b/src/predicat.c @@ -39,12 +39,12 @@ int forbidden_name(const char *name); void do_switch(dbref player, char *expression, char **argv, - dbref cause, int first, int notifyme, int regexp); + dbref cause, int first, int notifyme, int regexp); void do_verb(dbref player, dbref cause, char *arg1, char **argv); static int grep_util_helper(dbref player, dbref thing, dbref parent, - char const *pattern, ATTR *atr, void *args); + char const *pattern, ATTR *atr, void *args); static int grep_helper(dbref player, dbref thing, dbref parent, - char const *pattern, ATTR *atr, void *args); + char const *pattern, ATTR *atr, void *args); void do_grep(dbref player, char *obj, char *lookfor, int flag, int insensitive); int pay_quota(dbref, int); extern PRIV attr_privs_view[]; @@ -61,7 +61,7 @@ tprintf(const char *fmt, ...) #ifdef HAS_VSNPRINTF static char buff[BUFFER_LEN]; #else - static char buff[BUFFER_LEN * 3]; /* safety margin */ + static char buff[BUFFER_LEN * 3]; /* safety margin */ #endif va_list args; @@ -123,8 +123,8 @@ charge_action(dbref player, dbref thing, const char *awhat) /* charges left, decrement and execute */ int res; if ((res = queue_attribute(thing, awhat, player))) - (void) atr_add(thing, "CHARGES", tprintf("%d", num - 1), - Owner(b->creator), 0); + (void) atr_add(thing, "CHARGES", tprintf("%d", num - 1), + Owner(b->creator), 0); return res; } else { /* no charges left, try to execute runout */ @@ -153,7 +153,7 @@ did_it(dbref player, dbref thing, const char *what, const char *def, /* Bunch o' nulls */ static char *myenv[10] = { NULL }; return real_did_it(player, thing, what, def, owhat, odef, awhat, loc, myenv, - NA_INTER_HEAR); + NA_INTER_HEAR); } /** A wrapper for real_did_it that can set %0 and %1 to dbrefs. @@ -173,8 +173,8 @@ did_it(dbref player, dbref thing, const char *what, const char *def, */ int did_it_with(dbref player, dbref thing, const char *what, const char *def, - const char *owhat, const char *odef, const char *awhat, - dbref loc, dbref env0, dbref env1, int flags) + const char *owhat, const char *odef, const char *awhat, + dbref loc, dbref env0, dbref env1, int flags) { char *myenv[10] = { NULL }; char e0[SBUF_LEN], e1[SBUF_LEN], *ep; @@ -194,7 +194,7 @@ did_it_with(dbref player, dbref thing, const char *what, const char *def, } return real_did_it(player, thing, what, def, owhat, odef, awhat, loc, myenv, - flags); + flags); } @@ -213,13 +213,13 @@ did_it_with(dbref player, dbref thing, const char *what, const char *def, */ int did_it_interact(dbref player, dbref thing, const char *what, const char *def, - const char *owhat, const char *odef, const char *awhat, - dbref loc, int flags) + const char *owhat, const char *odef, const char *awhat, + dbref loc, int flags) { /* Bunch o' nulls */ static char *myenv[10] = { NULL }; return real_did_it(player, thing, what, def, owhat, odef, awhat, loc, myenv, - flags); + flags); } /** Take an action on an object and trigger attributes. @@ -244,8 +244,8 @@ did_it_interact(dbref player, dbref thing, const char *what, const char *def, */ int real_did_it(dbref player, dbref thing, const char *what, const char *def, - const char *owhat, const char *odef, const char *awhat, dbref loc, - char *myenv[10], int flags) + const char *owhat, const char *odef, const char *awhat, dbref loc, + char *myenv[10], int flags) { ATTR *d; @@ -778,12 +778,12 @@ ok_name(const char *n) /* No magic cookies */ return (name - && *name - && *name != LOOKUP_TOKEN - && *name != NUMBER_TOKEN - && *name != NOT_TOKEN && strcasecmp((char *) name, "me") - && strcasecmp((char *) name, "home") - && strcasecmp((char *) name, "here")); + && *name + && *name != LOOKUP_TOKEN + && *name != NUMBER_TOKEN + && *name != NOT_TOKEN && strcasecmp((char *) name, "me") + && strcasecmp((char *) name, "home") + && strcasecmp((char *) name, "here")); } /** Is a name a valid player name when applied by player to thing? @@ -918,7 +918,7 @@ ok_command_name(const char *name) return 0; default: if (!isupper((unsigned char) *name) && !isdigit((unsigned char) *name) - && !ispunct((unsigned char) *name)) + && !ispunct((unsigned char) *name)) return 0; } /* Everything else must be printable and non-space, and we need @@ -1043,7 +1043,7 @@ ok_tag_attribute(dbref player, char *params) */ void do_switch(dbref player, char *expression, char **argv, dbref cause, - int first, int notifyme, int regexp) + int first, int notifyme, int regexp) { int any = 0, a; char buff[BUFFER_LEN], *bp; @@ -1068,12 +1068,12 @@ do_switch(dbref player, char *expression, char **argv, dbref cause, ap = argv[a]; bp = buff; process_expression(buff, &bp, &ap, player, cause, cause, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; /* check for a match */ if (regexp ? quick_regexp_match(buff, expression, 0) - : local_wild_match(buff, expression)) { + : local_wild_match(buff, expression)) { any = 1; tbuf1 = replace_string("#$", expression, argv[a + 1]); parse_que(player, tbuf1, cause); @@ -1106,15 +1106,15 @@ do_switch(dbref player, char *expression, char **argv, dbref cause, dbref parse_match_possessor(dbref player, const char **str) { - const char *box; /* name of container */ - char *obj; /* name of object */ + const char *box; /* name of container */ + char *obj; /* name of object */ box = *str; /* check to see if we have an 's sequence */ if ((obj = strchr(box, '\'')) == NULL) return NOTHING; - *obj++ = '\0'; /* terminate */ + *obj++ = '\0'; /* terminate */ if ((*obj == '\0') || ((*obj != 's') && (*obj != 'S'))) return NOTHING; /* skip over the 's' and whitespace */ @@ -1137,7 +1137,7 @@ parse_match_possessor(dbref player, const char **str) */ void page_return(dbref player, dbref target, const char *type, - const char *message, const char *def) + const char *message, const char *def) { ATTR *d; char buff[BUFFER_LEN], *bp, *asave; @@ -1151,17 +1151,17 @@ page_return(dbref player, dbref target, const char *type, ap = asave; bp = buff; process_expression(buff, &bp, &ap, target, player, player, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; free((Malloc_t) asave); if (*buff) { - ptr = (struct tm *) localtime(&mudtime); - notify_format(player, T("%s message from %s: %s"), type, - Name(target), buff); - if (!Haven(target)) - notify_format(target, - T("[%d:%02d] %s message sent to %s."), ptr->tm_hour, - ptr->tm_min, type, Name(player)); + ptr = (struct tm *) localtime(&mudtime); + notify_format(player, T("%s message from %s: %s"), type, + Name(target), buff); + if (!Haven(target)) + notify_format(target, + T("[%d:%02d] %s message sent to %s."), ptr->tm_hour, + ptr->tm_min, type, Name(player)); } } else if (def && *def) notify(player, def); @@ -1281,8 +1281,8 @@ do_verb(dbref player, dbref cause, char *arg1, char **argv) } real_did_it(actor, victim, - upcasestr(argv[2]), argv[3], upcasestr(argv[4]), argv[5], - NULL, Location(actor), global_eval_context.wenv, NA_INTER_HEAR); + upcasestr(argv[2]), argv[3], upcasestr(argv[4]), argv[5], + NULL, Location(actor), global_eval_context.wenv, NA_INTER_HEAR); for (i = 0; i < 10; i++) global_eval_context.wenv[i] = wsave[i]; @@ -1298,30 +1298,30 @@ do_verb(dbref player, dbref cause, char *arg1, char **argv) /** Structure for passing arguments to grep_util_helper(). */ struct guh_args { - char *buff; /**< Buffer for output */ - char *bp; /**< Pointer to buff's current position */ - char *lookfor; /**< Pattern to grep for */ - int sensitive; /**< If 1, case-sensitive match; if 0, insensitive */ + char *buff; /**< Buffer for output */ + char *bp; /**< Pointer to buff's current position */ + char *lookfor; /**< Pattern to grep for */ + int sensitive; /**< If 1, case-sensitive match; if 0, insensitive */ }; static int grep_util_helper(dbref player __attribute__ ((__unused__)), - dbref thing __attribute__ ((__unused__)), - dbref parent __attribute__ ((__unused__)), - char const *pattern - __attribute__ ((__unused__)), ATTR *atr, void *args) + dbref thing __attribute__ ((__unused__)), + dbref parent __attribute__ ((__unused__)), + char const *pattern + __attribute__ ((__unused__)), ATTR *atr, void *args) { struct guh_args *guh = args; int found = 0; char *s; int len; - s = (char *) atr_value(atr); /* warning: static */ + s = (char *) atr_value(atr); /* warning: static */ len = strlen(guh->lookfor); found = 0; while (*s && !found) { if ((guh->sensitive && !strncmp(guh->lookfor, s, len)) || - (!guh->sensitive && !strncasecmp(guh->lookfor, s, len))) + (!guh->sensitive && !strncasecmp(guh->lookfor, s, len))) found = 1; else s++; @@ -1336,10 +1336,10 @@ grep_util_helper(dbref player __attribute__ ((__unused__)), static int wildgrep_util_helper(dbref player __attribute__ ((__unused__)), - dbref thing __attribute__ ((__unused__)), - dbref parent __attribute__ ((__unused__)), - char const *pattern - __attribute__ ((__unused__)), ATTR *atr, void *args) + dbref thing __attribute__ ((__unused__)), + dbref parent __attribute__ ((__unused__)), + char const *pattern + __attribute__ ((__unused__)), ATTR *atr, void *args) { struct guh_args *guh = args; int found = 0; @@ -1366,7 +1366,7 @@ wildgrep_util_helper(dbref player __attribute__ ((__unused__)), */ char * grep_util(dbref player, dbref thing, char *pattern, char *lookfor, - int sensitive, int wild) + int sensitive, int wild) { struct guh_args guh; @@ -1403,10 +1403,10 @@ grep_helper(dbref player, dbref thing __attribute__ ((__unused__)), found = 0; tbp = tbuf1; - s = (char *) atr_value(atr); /* warning: static */ + s = (char *) atr_value(atr); /* warning: static */ while (s && *s) { if ((gh->insensitive && !strncasecmp(gh->lookfor, s, gh->len)) || - (!gh->insensitive && !strncmp(gh->lookfor, s, gh->len))) { + (!gh->insensitive && !strncmp(gh->lookfor, s, gh->len))) { found = 1; strncpy(buf, s, gh->len); buf[gh->len] = '\0'; @@ -1422,10 +1422,10 @@ grep_helper(dbref player, dbref thing __attribute__ ((__unused__)), /* if we got it, display it */ if (found) notify_format(player, "%s%s [#%d%s]%s %s", - ANSI_HILITE, AL_NAME(atr), - Owner(AL_CREATOR(atr)), - privs_to_letters(attr_privs_view, AL_FLAGS(atr)), - ANSI_NORMAL, tbuf1); + ANSI_HILITE, AL_NAME(atr), + Owner(AL_CREATOR(atr)), + privs_to_letters(attr_privs_view, AL_FLAGS(atr)), + ANSI_NORMAL, tbuf1); return found; } @@ -1455,7 +1455,7 @@ do_grep(dbref player, char *obj, char *lookfor, int flag, int insensitive) /* find the attribute pattern */ pattern = strchr(obj, '/'); if (!pattern) - pattern = (char *) "*"; /* set it to global match */ + pattern = (char *) "*"; /* set it to global match */ else *pattern++ = '\0'; @@ -1477,7 +1477,7 @@ do_grep(dbref player, char *obj, char *lookfor, int flag, int insensitive) } else { tp = grep_util(player, thing, pattern, lookfor, !insensitive, 0); notify_format(player, T("Matches of '%s' on %s(#%d): %s"), lookfor, - Name(thing), thing, tp); + Name(thing), thing, tp); mush_free((Malloc_t) tp, "grep_util.buff"); } } diff --git a/src/privtab.c b/src/privtab.c index 3e42ccf..160e0d7 100644 --- a/src/privtab.c +++ b/src/privtab.c @@ -52,29 +52,29 @@ string_to_privs(PRIV *table, const char *str, long int origprivs) if (*p == '!') { not = 1; if (!*++p) - continue; + continue; } ltr = 0; if (strlen(p) == 1) { /* One-letter string is treated as a character if possible */ ltr = letter_to_privs(table, p, 0); if (not) - no |= ltr; + no |= ltr; else - yes |= ltr; + yes |= ltr; } /* If we didn't handle a one-char string as a character, * or if the string is longer than one char, use prefix-matching */ if (!ltr) { for (c = table; c->name; c++) { - if (string_prefix(c->name, p)) { - if (not) - no |= c->bits_to_set; - else - yes |= c->bits_to_set; - break; - } + if (string_prefix(c->name, p)) { + if (not) + no |= c->bits_to_set; + else + yes |= c->bits_to_set; + break; + } } } } @@ -116,15 +116,15 @@ list_to_privs(PRIV *table, const char *str, long int origprivs) if (*p == '!') { not = 1; if (!*++p) - continue; + continue; } for (c = table; c->name; c++) { if (!strcasecmp(c->name, p)) { - if (not) - no |= c->bits_to_set; - else - yes |= c->bits_to_set; - break; + if (not) + no |= c->bits_to_set; + else + yes |= c->bits_to_set; + break; } } } @@ -174,22 +174,22 @@ string_to_privsets(PRIV *table, const char *str, int *setprivs, int *clrprivs) /* One-letter string is treated as a character if possible */ ltr = letter_to_privs(table, p, 0); if (not) - *clrprivs |= ltr; + *clrprivs |= ltr; else - *setprivs |= ltr; + *setprivs |= ltr; } if (ltr) { found++; } else { for (c = table; c->name; c++) { - if (string_prefix(c->name, p)) { - found++; - if (not) - *clrprivs |= c->bits_to_set; - else - *setprivs |= c->bits_to_set; - break; - } + if (string_prefix(c->name, p)) { + found++; + if (not) + *clrprivs |= c->bits_to_set; + else + *setprivs |= c->bits_to_set; + break; + } } } } @@ -223,15 +223,15 @@ letter_to_privs(PRIV *table, const char *str, long int origprivs) if (*p == '!') { not = 1; if (!*++p) - break; + break; } for (c = table; c->name; c++) { if (c->letter == *p) { - if (not) - no |= c->bits_to_set; - else - yes |= c->bits_to_set; - break; + if (not) + no |= c->bits_to_set; + else + yes |= c->bits_to_set; + break; } } } @@ -254,7 +254,7 @@ privs_to_string(PRIV *table, int privs) for (c = table; c->name; c++) { if (privs & c->bits_to_show) { if (bp != buf) - safe_chr(' ', buf, &bp); + safe_chr(' ', buf, &bp); safe_str(c->name, buf, &bp); privs &= ~c->bits_to_set; } diff --git a/src/ptab.c b/src/ptab.c index d6fbfff..dd05010 100644 --- a/src/ptab.c +++ b/src/ptab.c @@ -20,8 +20,8 @@ static int WIN32_CDECL ptab_cmp(const void *, const void *); /** A ptab entry. */ typedef struct ptab_entry { - void *data; /**< pointer to data */ - char key[BUFFER_LEN]; /**< the index key */ + void *data; /**< pointer to data */ + char key[BUFFER_LEN]; /**< the index key */ } ptab_entry; /** The memory usage of a ptab entry, not including data. */ @@ -72,16 +72,16 @@ ptab_find(PTAB *tab, const char *key) if (!tab || !key || !*key || tab->state) return NULL; - if (tab->len < 10) { /* Just do a linear search for small tables */ + if (tab->len < 10) { /* Just do a linear search for small tables */ for (nun = 0; nun < tab->len; nun++) { if (string_prefix(tab->tab[nun]->key, key)) { - if (nun + 1 < tab->len && string_prefix(tab->tab[nun + 1]->key, key)) - return NULL; - else - return tab->tab[nun]->data; + if (nun + 1 < tab->len && string_prefix(tab->tab[nun + 1]->key, key)) + return NULL; + else + return tab->tab[nun]->data; } } - } else { /* Binary search of the index */ + } else { /* Binary search of the index */ int left = 0; int cmp; int right = tab->len - 1; @@ -90,44 +90,44 @@ ptab_find(PTAB *tab, const char *key) nun = (left + right) / 2; if (left > right) - break; + break; cmp = strcasecmp(key, tab->tab[nun]->key); if (cmp == 0) { - return tab->tab[nun]->data; + return tab->tab[nun]->data; } else if (cmp < 0) { - int mem; - /* We need to catch the first unique prefix */ - if (string_prefix(tab->tab[nun]->key, key)) { - for (mem = nun - 1; mem >= 0; mem--) { - if (string_prefix(tab->tab[mem]->key, key)) { - if (strcasecmp(tab->tab[mem]->key, key) == 0) - return tab->tab[mem]->data; - } else - break; - } - /* Non-unique prefix */ - if (mem != nun - 1) - return NULL; - for (mem = nun + 1; mem < tab->len; mem++) { - if (string_prefix(tab->tab[mem]->key, key)) { - if (strcasecmp(tab->tab[mem]->key, key) == 0) - return tab->tab[mem]->data; - } else - break; - } - if (mem != nun + 1) - return NULL; - return tab->tab[nun]->data; - } - if (left == right) - break; - right = nun - 1; - } else { /* cmp > 0 */ - if (left == right) - break; - left = nun + 1; + int mem; + /* We need to catch the first unique prefix */ + if (string_prefix(tab->tab[nun]->key, key)) { + for (mem = nun - 1; mem >= 0; mem--) { + if (string_prefix(tab->tab[mem]->key, key)) { + if (strcasecmp(tab->tab[mem]->key, key) == 0) + return tab->tab[mem]->data; + } else + break; + } + /* Non-unique prefix */ + if (mem != nun - 1) + return NULL; + for (mem = nun + 1; mem < tab->len; mem++) { + if (string_prefix(tab->tab[mem]->key, key)) { + if (strcasecmp(tab->tab[mem]->key, key) == 0) + return tab->tab[mem]->data; + } else + break; + } + if (mem != nun + 1) + return NULL; + return tab->tab[nun]->data; + } + if (left == right) + break; + right = nun - 1; + } else { /* cmp > 0 */ + if (left == right) + break; + left = nun + 1; } } } @@ -160,16 +160,16 @@ ptab_find_exact_nun(PTAB *tab, const char *key) if (!tab || !key || tab->state) return -1; - if (tab->len < 10) { /* Just do a linear search for small tables */ + if (tab->len < 10) { /* Just do a linear search for small tables */ int cmp; for (nun = 0; nun < tab->len; nun++) { cmp = strcasecmp(tab->tab[nun]->key, key); if (cmp == 0) - return nun; + return nun; else if (cmp > 0) - return -1; + return -1; } - } else { /* Binary search of the index */ + } else { /* Binary search of the index */ int left = 0; int cmp; int right = tab->len - 1; @@ -178,18 +178,18 @@ ptab_find_exact_nun(PTAB *tab, const char *key) nun = (left + right) / 2; if (left > right) - break; + break; cmp = strcasecmp(key, tab->tab[nun]->key); if (cmp == 0) - return nun; + return nun; if (left == right) - break; + break; if (cmp < 0) - right = nun - 1; - else /* cmp > 0 */ - left = nun + 1; + right = nun - 1; + else /* cmp > 0 */ + left = nun + 1; } } return -1; @@ -360,5 +360,5 @@ ptab_stats(dbref player, PTAB *tab, const char *pname) mem += PTAB_SIZE + strlen(tab->tab[nun]->key) + 1; notify_format(player, "%-10s %7d %14.3f %39d", pname, tab->len, log(tab->len), - mem); + mem); } diff --git a/src/rob.c b/src/rob.c index 24cb53f..32b137c 100644 --- a/src/rob.c +++ b/src/rob.c @@ -256,7 +256,7 @@ do_buy(dbref player, char *item, char *from, int price) int affordable; int costcount, ci; int count, i; - int low, high; /* lower bound, upper bound of cost */ + int low, high; /* lower bound, upper bound of cost */ ATTR *a; if (!GoodObject(Location(player))) @@ -268,8 +268,8 @@ do_buy(dbref player, char *item, char *from, int price) if (from != NULL && *from) { switch (vendor = - match_result(player, from, TYPE_PLAYER, - MAT_NEAR_THINGS | MAT_ENGLISH)) { + match_result(player, from, TYPE_PLAYER, + MAT_NEAR_THINGS | MAT_ENGLISH)) { case NOTHING: notify(player, T("Buy from whom?")); return; @@ -317,77 +317,77 @@ do_buy(dbref player, char *item, char *from, int price) continue; for (i = 0; i < count; i++) { if (!strncasecmp(finditem, r[i], len)) { - /* Check cost */ - cost = r[i] + len; - if (!*cost) - continue; - costcount = list2arr(c, BUFFER_LEN / 2, cost, ','); - for (ci = 0; ci < costcount; ci++) { - cost = c[ci]; - /* Formats: - * 10,2000+,10-100 - */ - if ((plus = strchr(cost, '-'))) { - *(plus++) = '\0'; - if (!is_strict_integer(cost)) - continue; - if (!is_strict_integer(plus)) - continue; - low = parse_integer(cost); - high = parse_integer(plus); - if (price < 0) { - boughtit = low; - } else if (price >= low && price <= high) { - boughtit = price; - } - } else if ((plus = strchr(cost, '+'))) { - *(plus++) = '\0'; - if (!is_strict_integer(cost)) - continue; - low = parse_integer(cost); - if (price < 0) { - boughtit = low; - } else if (price > low) { - boughtit = price; - } - } else if (is_strict_integer(cost)) { - low = parse_integer(cost); - if (price < 0) { - boughtit = low; - } else if (low == price) { - boughtit = price; - } - } else { - continue; - } - if (boughtit >= 0) { - if (!payfor(player, boughtit)) { - affordable = 0; - boughtit = 0; - continue; - } - bp = strchr(finditem, ':'); - if (bp) - *bp = '\0'; - for (bp = finditem; *bp; bp++) - *bp = DOWNCASE(*bp); - bp = buff; - safe_format(buff, &bp, "You buy a %s from %s.", - finditem, Name(vendor)); - *bp = '\0'; - bp = obuff; - safe_format(obuff, &bp, "buys a %s from %s.", - finditem, Name(vendor)); - buy_env[0] = finditem; - buy_env[1] = buycost; - bp = buycost; - safe_integer(boughtit, buycost, &bp); - *bp = '\0'; - real_did_it(player, vendor, "BUY", buff, "OBUY", obuff, "ABUY", - NOTHING, buy_env, NA_INTER_SEE); - return; - } - } + /* Check cost */ + cost = r[i] + len; + if (!*cost) + continue; + costcount = list2arr(c, BUFFER_LEN / 2, cost, ','); + for (ci = 0; ci < costcount; ci++) { + cost = c[ci]; + /* Formats: + * 10,2000+,10-100 + */ + if ((plus = strchr(cost, '-'))) { + *(plus++) = '\0'; + if (!is_strict_integer(cost)) + continue; + if (!is_strict_integer(plus)) + continue; + low = parse_integer(cost); + high = parse_integer(plus); + if (price < 0) { + boughtit = low; + } else if (price >= low && price <= high) { + boughtit = price; + } + } else if ((plus = strchr(cost, '+'))) { + *(plus++) = '\0'; + if (!is_strict_integer(cost)) + continue; + low = parse_integer(cost); + if (price < 0) { + boughtit = low; + } else if (price > low) { + boughtit = price; + } + } else if (is_strict_integer(cost)) { + low = parse_integer(cost); + if (price < 0) { + boughtit = low; + } else if (low == price) { + boughtit = price; + } + } else { + continue; + } + if (boughtit >= 0) { + if (!payfor(player, boughtit)) { + affordable = 0; + boughtit = 0; + continue; + } + bp = strchr(finditem, ':'); + if (bp) + *bp = '\0'; + for (bp = finditem; *bp; bp++) + *bp = DOWNCASE(*bp); + bp = buff; + safe_format(buff, &bp, "You buy a %s from %s.", + finditem, Name(vendor)); + *bp = '\0'; + bp = obuff; + safe_format(obuff, &bp, "buys a %s from %s.", + finditem, Name(vendor)); + buy_env[0] = finditem; + buy_env[1] = buycost; + bp = buycost; + safe_integer(boughtit, buycost, &bp); + *bp = '\0'; + real_did_it(player, vendor, "BUY", buff, "OBUY", obuff, "ABUY", + NOTHING, buy_env, NA_INTER_SEE); + return; + } + } } } } while (!from && ((vendor = Next(vendor)) != NOTHING)); @@ -397,7 +397,7 @@ do_buy(dbref player, char *item, char *from, int price) notify(player, T("I can't find that item with that price here.")); } else { notify_format(player, T("%s isn't selling that item for that price"), - Name(vendor)); + Name(vendor)); } } else if (affordable) { if (!from) { diff --git a/src/services.c b/src/services.c index 73a6e56..57c01da 100644 --- a/src/services.c +++ b/src/services.c @@ -1,13 +1,16 @@ -/* Win32 services routines */ - -/* Author: Nick Gammon */ +/** \file services.c + * \brief Win32 services routines + * + * Original author: Nick Gammon + */ -#ifdef WIN32 #include "copyrite.h" #include "config.h" -#include /* for service and thread routines */ +#ifdef WIN32 + +#include /* for service and thread routines */ #include #include @@ -30,7 +33,7 @@ int WIN32_CDECL main(int argc, char **argv); void mainthread(int argc, char **argv); -SERVICE_STATUS ssStatus; /* current status of the service */ +SERVICE_STATUS ssStatus; /* current status of the service */ SERVICE_STATUS_HANDLE sshStatusHandle; DWORD dwGlobalErr; @@ -44,8 +47,8 @@ SC_HANDLE SCmanager = NULL; VOID service_main(DWORD dwArgc, LPTSTR * lpszArgv); VOID WINAPI service_ctrl(DWORD dwCtrlCode); BOOL ReportStatusToSCMgr(DWORD dwCurrentState, - DWORD dwWin32ExitCode, - DWORD dwCheckPoint, DWORD dwWaitHint); + DWORD dwWin32ExitCode, + DWORD dwCheckPoint, DWORD dwWaitHint); VOID worker_thread(VOID * notused); VOID StopService(LPTSTR lpszMsg); @@ -100,8 +103,8 @@ main(argc, argv) status = get_service_status(&svcstatus, TRUE); if (status == 0 && svcstatus.dwCurrentState == SERVICE_RUNNING) { - fprintf(stderr, T("The MUSH is already running as a service.\n")); - return 1; + fprintf(stderr, T("The MUSH is already running as a service.\n")); + return 1; } worker_thread(NULL); } else @@ -168,35 +171,35 @@ service_main(DWORD dwArgc, LPTSTR * lpszArgv) /* report the status to Service Control Manager. */ - if (!ReportStatusToSCMgr(SERVICE_START_PENDING, /* service state */ - NO_ERROR, /* exit code */ - 1, /* checkpoint */ - 3000)) /* wait hint */ + if (!ReportStatusToSCMgr(SERVICE_START_PENDING, /* service state */ + NO_ERROR, /* exit code */ + 1, /* checkpoint */ + 3000)) /* wait hint */ goto cleanup; /* start the thread that performs the work of the service. */ - threadHandle = (HANDLE) _beginthreadex(NULL, /* security attributes */ - 0, /* stack size (0 means inherit parent's stack size) */ - (LPTHREAD_START_ROUTINE) worker_thread, NULL, /* argument to thread */ - 0, /* thread creation flags */ - &TID); /* pointer to thread ID */ + threadHandle = (HANDLE) _beginthreadex(NULL, /* security attributes */ + 0, /* stack size (0 means inherit parent's stack size) */ + (LPTHREAD_START_ROUTINE) worker_thread, NULL, /* argument to thread */ + 0, /* thread creation flags */ + &TID); /* pointer to thread ID */ if (!threadHandle) goto cleanup; /* report the status to the service control manager. */ - if (!ReportStatusToSCMgr(SERVICE_RUNNING, /* service state */ - NO_ERROR, /* exit code */ - 0, /* checkpoint */ - 0)) /* wait hint */ + if (!ReportStatusToSCMgr(SERVICE_RUNNING, /* service state */ + NO_ERROR, /* exit code */ + 0, /* checkpoint */ + 0)) /* wait hint */ goto cleanup; /* wait indefinitely until threadHandle is signaled. */ /* The thread handle is signalled when the thread terminates */ - dwWait = WaitForSingleObject(threadHandle, /* event object */ - INFINITE); /* wait indefinitely */ + dwWait = WaitForSingleObject(threadHandle, /* event object */ + INFINITE); /* wait indefinitely */ cleanup: @@ -208,7 +211,7 @@ cleanup: /* process, the StartServiceCtrlDispatcher function in */ /* the main thread returns, terminating the process. */ return; -} /* end of service_main */ +} /* end of service_main */ @@ -248,10 +251,10 @@ service_ctrl(DWORD dwCtrlCode) /* Report the status, specifying the checkpoint and waithint, */ /* before setting the termination event. */ - ReportStatusToSCMgr(SERVICE_STOP_PENDING, /* current state */ - NO_ERROR, /* exit code */ - 1, /* checkpoint */ - 10000); /* waithint (10 secs) */ + ReportStatusToSCMgr(SERVICE_STOP_PENDING, /* current state */ + NO_ERROR, /* exit code */ + 1, /* checkpoint */ + 10000); /* waithint (10 secs) */ shutdown_flag = 1; @@ -267,11 +270,11 @@ service_ctrl(DWORD dwCtrlCode) default: break; - } /* end of switch */ + } /* end of switch */ /* send a status response. */ ReportStatusToSCMgr(dwState, NO_ERROR, 0, 0); -} /* end of service_ctrl */ +} /* end of service_ctrl */ /* utility functions... */ @@ -284,7 +287,7 @@ service_ctrl(DWORD dwCtrlCode) /* to the service control manager. */ static BOOL ReportStatusToSCMgr(DWORD dwCurrentState, - DWORD dwWin32ExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) + DWORD dwWin32ExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL fResult; @@ -303,14 +306,14 @@ ReportStatusToSCMgr(DWORD dwCurrentState, ssStatus.dwWaitHint = dwWaitHint; /* Report the status of the service to the service control manager. */ - if (!(fResult = SetServiceStatus(sshStatusHandle, /* service reference handle */ - &ssStatus))) { /* SERVICE_STATUS structure */ + if (!(fResult = SetServiceStatus(sshStatusHandle, /* service reference handle */ + &ssStatus))) { /* SERVICE_STATUS structure */ /* If an error occurs, stop the service. */ StopService("SetServiceStatus"); } return fResult; -} /* end of ReportStatusToSCMgr */ +} /* end of ReportStatusToSCMgr */ @@ -333,21 +336,21 @@ StopService(LPTSTR lpszMsg) lpszStrings[1] = lpszMsg; if (hEventSource) { - ReportEvent(hEventSource, /* handle of event source */ - EVENTLOG_ERROR_TYPE, /* event type */ - 0, /* event category */ - 0, /* event ID */ - NULL, /* current user's SID */ - 2, /* strings in lpszStrings */ - 0, /* no bytes of raw data */ - lpszStrings, /* array of error strings */ - NULL); /* no raw data */ + ReportEvent(hEventSource, /* handle of event source */ + EVENTLOG_ERROR_TYPE, /* event type */ + 0, /* event category */ + 0, /* event ID */ + NULL, /* current user's SID */ + 2, /* strings in lpszStrings */ + 0, /* no bytes of raw data */ + lpszStrings, /* array of error strings */ + NULL); /* no raw data */ (VOID) DeregisterEventSource(hEventSource); } if (threadHandle) TerminateThread(threadHandle, 1); -} /* end of StopService */ +} /* end of StopService */ /* called at shutdown, ctrl-c etc. */ @@ -369,7 +372,7 @@ shut_down_handler(DWORD dwCtrlType) } return FALSE; -} /* end of shut_down_handler */ +} /* end of shut_down_handler */ /* @@ -432,7 +435,7 @@ worker_thread(VOID * notused) mainthread(argc, argv); -} /* end of worker_thread */ +} /* end of worker_thread */ void WIN32_CDECL Win32_Exit(int exit_code) @@ -446,7 +449,7 @@ Win32_Exit(int exit_code) else _exit(exit_code); -} /* end of Win32_Exit */ +} /* end of Win32_Exit */ /* this is called from db_write (every 256 objects) */ /* to keep the service manager happy (it needs a checkpoint every 3 seconds) */ @@ -457,12 +460,12 @@ shutdown_checkpoint(void) static DWORD checkpoint = 1; if (threadHandle && shutdown_flag) - ReportStatusToSCMgr(SERVICE_STOP_PENDING, /* current state */ - NO_ERROR, /* exit code */ - ++checkpoint, /* checkpoint */ - 3000); /* waithint (3 seconds) */ + ReportStatusToSCMgr(SERVICE_STOP_PENDING, /* current state */ + NO_ERROR, /* exit code */ + ++checkpoint, /* checkpoint */ + 3000); /* waithint (3 seconds) */ -} /* end of shutdown_checkpoint */ +} /* end of shutdown_checkpoint */ /* We need to close these handles so often I'll do it in a separate routine */ @@ -476,7 +479,7 @@ close_service_handles(void) if (SCmanager) CloseServiceHandle(SCmanager); SCmanager = NULL; -} /* end of close_service_handles */ +} /* end of close_service_handles */ /* We put out *so* many error messages, let's centralise the whole thing */ @@ -498,12 +501,12 @@ service_error(DWORD error_code, char *themessage, ...) if (error_code) fprintf(stderr, " ** Error %ld\n ** %s\n", - error_code, convert_error(error_code)); + error_code, convert_error(error_code)); close_service_handles(); return TRUE; -} /* end of service_error */ +} /* end of service_error */ /* Open a handle to the Service Control Manager. @@ -517,11 +520,11 @@ open_service_manager(void) if (!SCmanager) return service_error(GetLastError(), - T("Unable to talk to the Service Control Manager")); + T("Unable to talk to the Service Control Manager")); return FALSE; -} /* end of openServiceManager */ +} /* end of openServiceManager */ /* @@ -536,7 +539,7 @@ get_service(void) return service_error(GetLastError(), T("Cannot access service definition")); return FALSE; -} /* end of get_service */ +} /* end of get_service */ /* Opens the service manager and gets the status, optionally leaving @@ -582,7 +585,7 @@ get_service_status(SERVICE_STATUS * svcstatus, int leave_open) return 0; -} /* end of get_service_status */ +} /* end of get_service_status */ /* Install this service. @@ -611,11 +614,11 @@ CmdInstallService(int argc, char *argv[]) Now create the service definition. */ - service = CreateService(SCmanager, THIS_SERVICE, THIS_SERVICE_DISPLAY, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, fullfilename, NULL, /* no load ordering group */ - NULL, /* no tag identifier */ - NULL, /* no dependencies */ - NULL, /* LocalSystem account */ - NULL); /* no password */ + service = CreateService(SCmanager, THIS_SERVICE, THIS_SERVICE_DISPLAY, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, fullfilename, NULL, /* no load ordering group */ + NULL, /* no tag identifier */ + NULL, /* no dependencies */ + NULL, /* LocalSystem account */ + NULL); /* no password */ if (!service) return service_error(GetLastError(), T("Unable to create service")); @@ -625,7 +628,7 @@ CmdInstallService(int argc, char *argv[]) fprintf(stderr, T("Service successfully installed\n")); return FALSE; -} /* end of CmdInstallService */ +} /* end of CmdInstallService */ /* Remove this service. @@ -650,8 +653,8 @@ CmdRemoveService(void) if (svcstatus.dwCurrentState != SERVICE_STOPPED) return service_error(0, - T - ("You must stop the service before you can remove it.")); + T + ("You must stop the service before you can remove it.")); /* Everything is fine, so delete the service definition. @@ -665,7 +668,7 @@ CmdRemoveService(void) fprintf(stderr, T("Service successfully removed\n")); return FALSE; -} /* end of CmdRemoveService */ +} /* end of CmdRemoveService */ /* @@ -700,7 +703,7 @@ CmdStartService(void) fprintf(stderr, T("Start request sent to service\n")); return FALSE; -} /* end of CmdStartService */ +} /* end of CmdStartService */ /* Stop this service. @@ -734,7 +737,7 @@ CmdStopService(void) fprintf(stderr, T("Stop request sent to service\n")); return FALSE; -} /* end of CmdStopService */ +} /* end of CmdStopService */ /* @@ -780,12 +783,12 @@ CmdStatusService(void) default: p = T("Unrecognised status."); break; - } /* end of switch */ + } /* end of switch */ fprintf(stderr, "%s\n", p); return FALSE; -} /* end of CmdStatusService */ +} /* end of CmdStatusService */ @@ -798,18 +801,18 @@ CmdDisplayFormat(void) { fprintf(stderr, T("Usage is :-\n")); fprintf(stderr, T(" %s - runs as a service, or stand-alone\n"), - THIS_SERVICE); + THIS_SERVICE); fprintf(stderr, T(" %s /run - runs stand-alone\n"), THIS_SERVICE); fprintf(stderr, T(" %s /start - starts this service\n"), THIS_SERVICE); fprintf(stderr, T(" %s /stop - stops this service\n"), THIS_SERVICE); fprintf(stderr, T(" %s /install - installs this service\n"), THIS_SERVICE); fprintf(stderr, T(" %s /remove - removes (un-installs) this service\n"), - THIS_SERVICE); + THIS_SERVICE); fprintf(stderr, T(" %s /status - displays the status of this service\n"), - THIS_SERVICE); + THIS_SERVICE); fprintf(stderr, T(" %s /help - displays this information\n"), - THIS_SERVICE); -} /* end of CmdDisplayFormat */ + THIS_SERVICE); +} /* end of CmdDisplayFormat */ static char * convert_error(DWORD error) @@ -819,16 +822,16 @@ convert_error(DWORD error) static char buff[100]; if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - error, LANG_NEUTRAL, (LPTSTR) & formattedmsg, 0, NULL)) { + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + error, LANG_NEUTRAL, (LPTSTR) & formattedmsg, 0, NULL)) { sprintf(buff, "", error); return buff; } else return formattedmsg; -} /* end of convert_error */ +} /* end of convert_error */ -#endif /* WIN32SERVICES */ -#endif /* WIN32 */ +#endif /* WIN32SERVICES */ +#endif /* WIN32 */ diff --git a/src/set.c b/src/set.c index 6c89b1d..f13cc20 100644 --- a/src/set.c +++ b/src/set.c @@ -154,7 +154,7 @@ do_name(dbref player, const char *name, char *newname) if (!AreQuiet(player, thing)) notify(player, T("Name set.")); real_did_it(player, thing, NULL, NULL, "ONAME", NULL, "ANAME", NOTHING, - myenv, NA_INTER_PRESENCE); + myenv, NA_INTER_PRESENCE); mush_free(myenv[0], "string"); mush_free(myenv[1], "string"); } @@ -224,9 +224,9 @@ do_chown(dbref player, const char *name, const char *newobj, int preserve) if (!can_pay_fees(newowner, Pennies(thing))) { /* not enough money or quota */ if (newowner != player) - notify(player, - T - ("That player doesn't have enough money or quota to receive that object.")); + notify(player, + T + ("That player doesn't have enough money or quota to receive that object.")); return; } /* Credit the current owner */ @@ -348,7 +348,7 @@ do_chzone(dbref player, char const *name, char const *newobj, int noisy) zone = NOTHING; else { if ((zone = noisy_match_result(player, newobj, NOTYPE, MAT_EVERYTHING)) - == NOTHING) + == NOTHING) return 0; } @@ -468,10 +468,10 @@ af_helper(dbref player, dbref thing, dbref parent __attribute__ ((__unused__)), * There is one special case - the resetting of the SAFE flag. */ if (!(Can_Write_Attr(player, thing, AL_ATTR(atr)) || - ((af->clrf & AF_SAFE) && - Can_Write_Attr_Ignore_Safe(player, thing, AL_ATTR(atr))))) { + ((af->clrf & AF_SAFE) && + Can_Write_Attr_Ignore_Safe(player, thing, AL_ATTR(atr))))) { notify_format(player, T("You cannot change that flag on %s/%s"), - Name(thing), AL_NAME(atr)); + Name(thing), AL_NAME(atr)); return 0; } @@ -480,13 +480,13 @@ af_helper(dbref player, dbref thing, dbref parent __attribute__ ((__unused__)), AL_FLAGS(atr) &= ~af->clrf; if (!AreQuiet(player, thing)) notify_format(player, T("%s/%s - %s reset."), Name(thing), AL_NAME(atr), - af->clrflags); + af->clrflags); } if (af->setf) { AL_FLAGS(atr) |= af->setf; if (!AreQuiet(player, thing)) notify_format(player, T("%s/%s - %s set."), Name(thing), AL_NAME(atr), - af->setflags); + af->setflags); } return 1; @@ -499,8 +499,8 @@ copy_attrib_flags(dbref player, dbref target, ATTR *atr, int flags) return; if (!Can_Write_Attr(player, target, AL_ATTR(atr))) { notify_format(player, - T("You cannot set attrib flags on %s/%s"), Name(target), - AL_NAME(atr)); + T("You cannot set attrib flags on %s/%s"), Name(target), + AL_NAME(atr)); return; } AL_FLAGS(atr) = flags; @@ -514,7 +514,7 @@ copy_attrib_flags(dbref player, dbref target, ATTR *atr, int flags) */ void do_attrib_flags(dbref player, const char *obj, const char *atrname, - const char *flag) + const char *flag) { struct af_args af; dbref thing; @@ -672,32 +672,32 @@ do_cpattr(dbref player, char *oldpair, char **newpair, int move, int noflagcopy) strcpy(tbuf1, newpair[i]); q = strchr(tbuf1, '/'); if (!q || !*q) { - q = (char *) AL_NAME(a); + q = (char *) AL_NAME(a); } else { - *q++ = '\0'; + *q++ = '\0'; } newobj = noisy_match_result(player, tbuf1, NOTYPE, MAT_EVERYTHING); if (GoodObject(newobj) && - ((newobj != oldobj) || strcasecmp(AL_NAME(a), q)) && - do_set_atr(newobj, q, text, player, 1)) - copies++; + ((newobj != oldobj) || strcasecmp(AL_NAME(a), q)) && + do_set_atr(newobj, q, text, player, 1)) + copies++; /* copy the attribute flags too */ if (!noflagcopy) - copy_attrib_flags(player, newobj, - atr_get_noparent(newobj, strupper(q)), a->flags); + copy_attrib_flags(player, newobj, + atr_get_noparent(newobj, strupper(q)), a->flags); } } - free((Malloc_t) text); /* safe_uncompress malloc()s memory */ + free((Malloc_t) text); /* safe_uncompress malloc()s memory */ if (copies) { notify_format(player, T("Attribute %s (%d copies)"), - (move ? "moved" : "copied"), copies); + (move ? "moved" : "copied"), copies); if (move) do_set_atr(oldobj, AL_NAME(a), NULL, player, 1); } else { notify_format(player, T("Unable to %s attribute."), - (move ? "move" : "copy")); + (move ? "move" : "copy")); } return; } @@ -712,9 +712,9 @@ struct gedit_args { static int gedit_helper(dbref player, dbref thing, - dbref parent __attribute__ ((__unused__)), - char const *pattern - __attribute__ ((__unused__)), ATTR *a, void *args) + dbref parent __attribute__ ((__unused__)), + char const *pattern + __attribute__ ((__unused__)), ATTR *a, void *args) { int ansi_long_flag = 0; const char *r; @@ -734,7 +734,7 @@ gedit_helper(dbref player, dbref thing, tbufp = tbuf1; tbufap = tbuf_ansi; - if (!a) { /* Shouldn't ever happen, but better safe than sorry */ + if (!a) { /* Shouldn't ever happen, but better safe than sorry */ notify(player, T("No such attribute, try set instead.")); return 0; } @@ -742,7 +742,7 @@ gedit_helper(dbref player, dbref thing, notify(player, T("You need to control an attribute to edit it.")); return 0; } - s = (char *) atr_value(a); /* warning: pointer to static buffer */ + s = (char *) atr_value(a); /* warning: pointer to static buffer */ if (vlen == 1 && *val == '$') { /* append */ @@ -750,7 +750,7 @@ gedit_helper(dbref player, dbref thing, safe_str(r, tbuf1, &tbufp); if (safe_format(tbuf_ansi, &tbufap, "%s%s%s%s", s, ANSI_HILITE, r, - ANSI_NORMAL)) + ANSI_NORMAL)) ansi_long_flag = 1; } else if (vlen == 1 && *val == '^') { /* prepend */ @@ -758,7 +758,7 @@ gedit_helper(dbref player, dbref thing, safe_str(s, tbuf1, &tbufp); if (safe_format(tbuf_ansi, &tbufap, "%s%s%s%s", ANSI_HILITE, r, ANSI_NORMAL, - s)) + s)) ansi_long_flag = 1; } else if (!*val) { /* insert replacement string between every character */ @@ -771,27 +771,27 @@ gedit_helper(dbref player, dbref thing, /* Add one at the start */ if (!safe_strl(r, rlen, tbuf1, &tbufp)) { if (gargs->target != EDIT_FIRST) { - for (last = 0; last < haystack->len; last++) { - /* Add the next character */ - if (safe_ansi_string(haystack, last, 1, tbuf1, &tbufp)) { - too_long = 1; - break; - } - if (!ansi_long_flag) { - if (safe_ansi_string(haystack, last, 1, tbuf_ansi, &tbufap)) - ansi_long_flag = 1; - } - /* Copy in r */ - if (safe_strl(r, rlen, tbuf1, &tbufp)) { - too_long = 1; - break; - } - if (!ansi_long_flag) { - if (safe_format(tbuf_ansi, &tbufap, "%s%s%s", ANSI_HILITE, r, - ANSI_NORMAL)) - ansi_long_flag = 1; - } - } + for (last = 0; last < haystack->len; last++) { + /* Add the next character */ + if (safe_ansi_string(haystack, last, 1, tbuf1, &tbufp)) { + too_long = 1; + break; + } + if (!ansi_long_flag) { + if (safe_ansi_string(haystack, last, 1, tbuf_ansi, &tbufap)) + ansi_long_flag = 1; + } + /* Copy in r */ + if (safe_strl(r, rlen, tbuf1, &tbufp)) { + too_long = 1; + break; + } + if (!ansi_long_flag) { + if (safe_format(tbuf_ansi, &tbufap, "%s%s%s", ANSI_HILITE, r, + ANSI_NORMAL)) + ansi_long_flag = 1; + } + } } } free_ansi_string(haystack); @@ -805,37 +805,37 @@ gedit_helper(dbref player, dbref thing, haystack = parse_ansi_string(s); while (last < haystack->len - && (p = strstr(haystack->text + last, val)) != NULL) { + && (p = strstr(haystack->text + last, val)) != NULL) { if (safe_ansi_string(haystack, last, p - (haystack->text + last), - tbuf1, &tbufp)) { - too_long = 1; - break; + tbuf1, &tbufp)) { + too_long = 1; + break; } if (!ansi_long_flag) { - if (safe_ansi_string(haystack, last, p - (haystack->text + last), - tbuf_ansi, &tbufap)) - ansi_long_flag = 1; + if (safe_ansi_string(haystack, last, p - (haystack->text + last), + tbuf_ansi, &tbufap)) + ansi_long_flag = 1; } /* Copy in r */ if (safe_strl(r, rlen, tbuf1, &tbufp)) { - too_long = 1; - break; + too_long = 1; + break; } if (!ansi_long_flag) { - if (safe_format(tbuf_ansi, &tbufap, "%s%s%s", ANSI_HILITE, r, - ANSI_NORMAL)) - ansi_long_flag = 1; + if (safe_format(tbuf_ansi, &tbufap, "%s%s%s", ANSI_HILITE, r, + ANSI_NORMAL)) + ansi_long_flag = 1; } last = p - haystack->text + vlen; if (gargs->target == EDIT_FIRST) - break; + break; } if (last < haystack->len && !too_long) { safe_ansi_string(haystack, last, haystack->len, tbuf1, &tbufp); if (!ansi_long_flag) { - if (safe_ansi_string(haystack, last, haystack->len, tbuf_ansi, &tbufap)) - ansi_long_flag = 1; + if (safe_ansi_string(haystack, last, haystack->len, tbuf_ansi, &tbufap)) + ansi_long_flag = 1; } } free_ansi_string(haystack); @@ -982,7 +982,7 @@ do_use(dbref player, const char *what) if ((thing = noisy_match_result(player, what, TYPE_THING, - MAT_NEAR_THINGS)) != NOTHING) { + MAT_NEAR_THINGS)) != NOTHING) { if (!eval_lock(player, thing, Use_Lock)) { fail_lock(player, thing, Use_Lock, T("Permission denied."), NOTHING); return; @@ -1013,7 +1013,7 @@ do_parent(dbref player, char *name, char *parent_name) if (!parent_name || !*parent_name || !strcasecmp(parent_name, "none")) parent = NOTHING; else if ((parent = noisy_match_result(player, parent_name, NOTYPE, - MAT_EVERYTHING)) == NOTHING) + MAT_EVERYTHING)) == NOTHING) return; /* do control check */ @@ -1055,10 +1055,10 @@ do_parent(dbref player, char *name, char *parent_name) if (parent != NOTHING) { for (i = 0, check = Parent(parent); - (i < MAX_PARENTS) && (check != NOTHING); i++, check = Parent(check)) { + (i < MAX_PARENTS) && (check != NOTHING); i++, check = Parent(check)) { if (check == thing) { - notify(player, T("You are not allowed to be your own ancestor!")); - return; + notify(player, T("You are not allowed to be your own ancestor!")); + return; } } if (i >= MAX_PARENTS) { diff --git a/src/shs.c b/src/shs.c index bc4ed10..34223d5 100644 --- a/src/shs.c +++ b/src/shs.c @@ -29,10 +29,10 @@ /* The SHS f() functions */ -#define f1(x, y, z) ( (x & y) | (~x & z) ) /* rounds 0-19 */ -#define f2(x, y, z) ( x ^ y ^ z ) /* rounds 20-39 */ -#define f3(x, y, z) ( (x & y) | (x & z) | (y & z) ) /* rounds 40-59 */ -#define f4(x, y, z) ( x ^ y ^ z ) /* rounds 60-79 */ +#define f1(x, y, z) ( (x & y) | (~x & z) ) /* rounds 0-19 */ +#define f2(x, y, z) ( x ^ y ^ z ) /* rounds 20-39 */ +#define f3(x, y, z) ( (x & y) | (x & z) | (y & z) ) /* rounds 40-59 */ +#define f4(x, y, z) ( x ^ y ^ z ) /* rounds 60-79 */ /* The SHS mysterious constants */ @@ -108,7 +108,7 @@ LONG h0, h1, h2, h3, h4; LONG A, B, C, D, E; -#endif /* DOXYGEN_SHOULD_SKIP_THIS */ +#endif /* DOXYGEN_SHOULD_SKIP_THIS */ /* Initialise the SHS values */ @@ -314,7 +314,7 @@ shsTransform(SHS_INFO *shsInfo) shsInfo->digest[3] += D; shsInfo->digest[4] += E; -} /* end of shsTransform */ +} /* end of shsTransform */ static void byteReverse(LONG * buffer, int byteCount); static void @@ -329,7 +329,7 @@ byteReverse(LONG * buffer, int byteCount) value = (buffer[count] << 16) | (buffer[count] >> 16); buffer[count] = ((value & 0xFF00FF00L) >> 8) | ((value & 0x00FF00FFL) << 8); } -} /* end of byteReverse */ +} /* end of byteReverse */ /** Update SHS for a block of data. This code assumes that the buffer @@ -346,7 +346,7 @@ shsUpdate(SHS_INFO *shsInfo, const BYTE * buffer, int count) /* Update bitcount */ if ((shsInfo->countLo + ((LONG) count << 3)) < shsInfo->countLo) - shsInfo->countHi++; /* Carry from low to high bitcount */ + shsInfo->countHi++; /* Carry from low to high bitcount */ shsInfo->countLo += ((LONG) count << 3); shsInfo->countHi += ((LONG) count >> 29); @@ -360,7 +360,7 @@ shsUpdate(SHS_INFO *shsInfo, const BYTE * buffer, int count) shsTransform(shsInfo); buffer += SHS_BLOCKSIZE; count -= SHS_BLOCKSIZE; - } /* end of looping processing each chunk */ + } /* end of looping processing each chunk */ /* Handle any remaining bytes of data. This should only happen once on the final lot of data */ @@ -421,4 +421,4 @@ shsFinal(SHS_INFO *shsInfo) byteReverse(shsInfo->data, SHS_DIGESTSIZE); } -#endif /* HAS_OPENSSL */ +#endif /* HAS_OPENSSL */ diff --git a/src/sig.c b/src/sig.c index 5cd0538..8558619 100644 --- a/src/sig.c +++ b/src/sig.c @@ -42,7 +42,7 @@ install_sig_handler(int signo, Sigfunc func) if (sigaction(signo, &act, &oact) < 0) return SIG_ERR; return oact.sa_handler; -#else /* No sigaction, drat. */ +#else /* No sigaction, drat. */ return signal(signo, func); #endif } @@ -53,7 +53,7 @@ install_sig_handler(int signo, Sigfunc func) */ void reload_sig_handler(int signo __attribute__ ((__unused__)), - Sigfunc func __attribute__ ((__unused__))) + Sigfunc func __attribute__ ((__unused__))) { #if !(defined(HAS_SIGACTION) || defined(SIGNALS_KEPT)) signal(signo, func); @@ -72,7 +72,7 @@ ignore_signal(int signo) sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(signo, &act, NULL); -#else /* No sigaction, drat. */ +#else /* No sigaction, drat. */ signal(signo, SIG_IGN); #endif } diff --git a/src/speech.c b/src/speech.c index c24c41a..2257f98 100644 --- a/src/speech.c +++ b/src/speech.c @@ -163,8 +163,8 @@ do_say(dbref player, const char *tbuf1) /* notify everybody */ notify_format(player, T("You say, \"%s\""), tbuf1); notify_except(Contents(loc), player, - tprintf(T("%s says, \"%s\""), spname(player), tbuf1), - NA_INTER_HEAR); + tprintf(T("%s says, \"%s\""), spname(player), tbuf1), + NA_INTER_HEAR); } /** A comparator for raw dbrefs. @@ -276,7 +276,7 @@ do_oemit_list(dbref player, char *list, const char *message, int flags) continue; pass[1] = locs[i]; notify_anything_loc(orator, na_exceptN, pass, ns_esnotify, na_flags, - message, locs[i]); + message, locs[i]); do_audible_stuff(pass[1], &pass[2], pass[0], message); } } @@ -379,12 +379,12 @@ do_whisper(dbref player, const char *arg1, const char *arg2, int noisy) if (key == 1) { notify_format(player, (gcount > 1) ? T("%s sense: %s%s%s") : - T("%s senses: %s%s%s"), tbuf + 4, Name(player), gap, arg2); + T("%s senses: %s%s%s"), tbuf + 4, Name(player), gap, arg2); p = tprintf("You sense: %s%s%s", Name(player), gap, arg2); } else { notify_format(player, T("You whisper, \"%s\"%s."), arg2, tbuf); p = tprintf("%s whispers%s: %s", Name(player), - gcount > 1 ? tbuf : "", arg2); + gcount > 1 ? tbuf : "", arg2); } for (who = 0; who < gcount; who++) { @@ -400,13 +400,13 @@ do_whisper(dbref player, const char *arg1, const char *arg2, int noisy) DOLIST(first, first) { overheard = 1; for (who = 0; who < gcount; who++) { - if ((first == player) || (first == good[who])) { - overheard = 0; - break; - } + if ((first == player) || (first == good[who])) { + overheard = 0; + break; + } } if (overheard) - notify_noecho(first, p); + notify_noecho(first, p); } } mush_free((Malloc_t) tbuf, "string"); @@ -492,7 +492,7 @@ do_pemit(dbref player, const char *arg1, const char *arg2, int flags) nospoof = (flags & PEMIT_SPOOF) ? 0 : 1; switch (who = match_result(player, arg1, NOTYPE, - MAT_OBJECTS | MAT_HERE | MAT_CONTAINER)) { + MAT_OBJECTS | MAT_HERE | MAT_CONTAINER)) { case NOTHING: notify(player, T("I don't see that here.")); break; @@ -502,23 +502,23 @@ do_pemit(dbref player, const char *arg1, const char *arg2, int flags) default: if (!okay_pemit(player, who)) { notify_format(player, - T("I'm sorry, but %s wishes to be left alone now."), - Name(who)); + T("I'm sorry, but %s wishes to be left alone now."), + Name(who)); return; } if (!silent) notify_format(player, T("You pemit \"%s\" to %s."), arg2, Name(who)); if (nospoof && Nospoof(who)) { if (Paranoid(who)) { - if (player == Owner(player)) - notify_format(who, "[%s(#%d)->%s] %s", Name(player), player, - Name(who), arg2); - else - notify_format(who, "[%s(#%d)'s %s(#%d)->%s] %s", - Name(Owner(player)), Owner(player), - Name(player), player, Name(who), arg2); + if (player == Owner(player)) + notify_format(who, "[%s(#%d)->%s] %s", Name(player), player, + Name(who), arg2); + else + notify_format(who, "[%s(#%d)'s %s(#%d)->%s] %s", + Name(Owner(player)), Owner(player), + Name(player), player, Name(who), arg2); } else - notify_format(who, "[%s->%s] %s", Name(player), Name(who), arg2); + notify_format(who, "[%s->%s] %s", Name(player), Name(who), arg2); } else { notify_must_puppet(who, arg2); } @@ -548,10 +548,10 @@ do_pose(dbref player, const char *tbuf1, int space) /* notify everybody */ if (!space) notify_except(Contents(loc), NOTHING, - tprintf("%s %s", spname(player), tbuf1), NA_INTER_HEAR); + tprintf("%s %s", spname(player), tbuf1), NA_INTER_HEAR); else notify_except(Contents(loc), NOTHING, - tprintf("%s%s", spname(player), tbuf1), NA_INTER_HEAR); + tprintf("%s%s", spname(player), tbuf1), NA_INTER_HEAR); } /** The *wall commands. @@ -577,7 +577,7 @@ do_wall(dbref player, const char *message, enum wall_type target, int emit) switch (*message) { case SAY_TOKEN: if (CHAT_STRIP_QUOTE) - message++; + message++; break; case SEMI_POSE_TOKEN: gap = ""; @@ -603,8 +603,8 @@ do_wall(dbref player, const char *message, enum wall_type target, int emit) flag_broadcast(mask, 0, "%s [%s]: %s", prefix, Name(player), message); else flag_broadcast(mask, 0, - "%s %s %s, \"%s\"", prefix, Name(player), - target == WALL_ALL ? "shouts" : "says", message); + "%s %s %s, \"%s\"", prefix, Name(player), + target == WALL_ALL ? "shouts" : "says", message); } /** The page command. @@ -619,7 +619,7 @@ do_wall(dbref player, const char *message, enum wall_type target, int emit) */ void do_page(dbref player, const char *arg1, const char *arg2, dbref cause, - int noeval, int multipage, int override, int has_eq) + int noeval, int multipage, int override, int has_eq) { dbref target; const char *message; @@ -648,7 +648,7 @@ do_page(dbref player, const char *arg1, const char *arg2, dbref cause, if (*arg1 && has_eq) { /* page to=[msg]. Always evaluate to, maybe evaluate msg */ process_expression(tbuf2, &tp2, &arg1, player, cause, cause, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *tp2 = '\0'; head = tbuf2; message = arg2; @@ -672,7 +672,7 @@ do_page(dbref player, const char *arg1, const char *arg2, dbref cause, notify_format(player, T("You last paged %s."), head); mush_free((Malloc_t) tbuf2, "string"); if (hp) - free((Malloc_t) hp); + free((Malloc_t) hp); return; } } @@ -808,7 +808,7 @@ do_page(dbref player, const char *arg1, const char *arg2, dbref cause, mush_panic("Unable to allocate memory in do_page"); process_expression(msgbuf, &mb, &message, player, cause, cause, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *mb = '\0'; message = msgbuf; } @@ -939,10 +939,10 @@ filter_found(dbref thing, const char *msg, int flag) char *filter; ATTR *a; char *p, *bp; - char *temp; /* need this so we don't leak memory - * by failing to free the storage - * allocated by safe_uncompress - */ + char *temp; /* need this so we don't leak memory + * by failing to free the storage + * allocated by safe_uncompress + */ int i; int matched = 0; @@ -959,12 +959,12 @@ filter_found(dbref thing, const char *msg, int flag) for (i = 0; (i < MAX_ARG) && !matched; i++) { p = bp = filter; process_expression(p, &bp, (char const **) &filter, 0, 0, 0, - PE_NOTHING, PT_COMMA, NULL); + PE_NOTHING, PT_COMMA, NULL); if (*filter == ',') *filter++ = '\0'; - if (*p == '\0' && *filter == '\0') /* No more filters */ + if (*p == '\0' && *filter == '\0') /* No more filters */ break; - if (*p == '\0') /* Empty filter */ + if (*p == '\0') /* Empty filter */ continue; if (AF_Regexp(a)) matched = quick_regexp_match(p, msg, AF_Case(a)); @@ -1008,7 +1008,7 @@ make_prefixstr(dbref thing, const char *msg, char *tbuf1) asave = safe_atr_value(a); ap = asave; process_expression(tbuf1, &bp, &ap, thing, orator, orator, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); free((Malloc_t) asave); restore_global_regs("prefix_save", preserve); for (j = 0; j < 10; j++) @@ -1050,7 +1050,7 @@ propagate_sound(dbref thing, const char *msg) if (IsExit(thing)) { notify_anything(orator, na_next, &Contents(loc), NULL, NA_INTER_HEAR, - tbuf1); + tbuf1); } else { pass[0] = Contents(loc); pass[1] = thing; @@ -1071,12 +1071,12 @@ do_audible_stuff(dbref loc, dbref *excs, int numexcs, const char *msg) if (IsRoom(loc)) { DOLIST(e, Exits(loc)) { if (Audible(e)) - propagate_sound(e, msg); + propagate_sound(e, msg); } } else { for (i = 0; i < numexcs; i++) if (*(excs + i) == loc) - exclude = 1; + exclude = 1; if (!exclude) propagate_sound(loc, msg); } @@ -1271,7 +1271,7 @@ do_lemit(dbref player, const char *tbuf1, int flags) if (((room = Location(player)) == player) || !GoodObject(room)) { notify(player, T("Invalid container object.")); do_rawlog(LT_ERR, T("** BAD CONTAINER ** #%d is inside #%d."), player, - room); + room); return; } while (!IsRoom(room) && (rec < 15)) { diff --git a/src/sql.c b/src/sql.c index c68dfa3..43d1487 100644 --- a/src/sql.c +++ b/src/sql.c @@ -94,11 +94,11 @@ sql_init(void) mysql_struct = mysql_init(NULL); if (!mysql_real_connect - (mysql_struct, SQL_HOST, SQL_USER, SQL_PASS, SQL_DB, 3306, 0, 0)) { - do_rawlog(LT_ERR, "Failed mysql connection: %s\n", - mysql_error(mysql_struct)); - sql_shutdown(); - sleep(1); + (mysql_struct, SQL_HOST, SQL_USER, SQL_PASS, SQL_DB, 3306, 0, 0)) { + do_rawlog(LT_ERR, "Failed mysql connection: %s\n", + mysql_error(mysql_struct)); + sql_shutdown(); + sleep(1); } retries--; } @@ -249,7 +249,7 @@ FUNCTION(fun_mapsql) for (i = 0; (i < numfields) && (i < 9); i++) { wenv[i + 1] = row_p[i]; if (!wenv[i + 1]) - wenv[i + 1] = (char *) ""; + wenv[i + 1] = (char *) ""; } /* Now call the ufun. */ if (call_ufun(&ufun, wenv, i + 1, rbuff, executor, enactor, pe_info)) @@ -312,12 +312,12 @@ FUNCTION(fun_sql) } for (i = 0; i < numfields; i++) { if (i > 0) { - if (safe_str(fieldsep, buff, bp)) - goto finished; + if (safe_str(fieldsep, buff, bp)) + goto finished; } if (row_p[i] && *row_p[i]) - if (safe_str(row_p[i], buff, bp)) - goto finished; /* We filled the buffer, best stop */ + if (safe_str(row_p[i], buff, bp)) + goto finished; /* We filled the buffer, best stop */ } } finished: @@ -385,9 +385,9 @@ COMMAND (cmd_sql) { rownum++; if (numfields > 0) { for (i = 0; i < numfields; i++) { - cell = row_p[i]; - notify_format(player, "Row %d, Field %s: %s", - rownum, fields[i].name, (cell && *cell) ? cell : "NULL"); + cell = row_p[i]; + notify_format(player, "Row %d, Field %s: %s", + rownum, fields[i].name, (cell && *cell) ? cell : "NULL"); } } else notify_format(player, "Row %d: NULL", rownum); diff --git a/src/strtree.c b/src/strtree.c index f8c7597..b08ad58 100644 --- a/src/strtree.c +++ b/src/strtree.c @@ -46,15 +46,15 @@ #include "confmagic.h" #ifndef UCHAR_MAX -#define UCHAR_MAX 255 /**< Largest unsigned character */ +#define UCHAR_MAX 255 /**< Largest unsigned character */ #endif /* Various constants. Their import is either bleedingly obvious * or explained below. */ -#define ST_MAX_DEPTH 64 /**< Max depth of the tree */ -#define ST_RED 1 /**< This node is red */ -#define ST_BLACK 0 /**< This node is black */ -#define ST_COLOR 1 /**< Bit mask for colors */ +#define ST_MAX_DEPTH 64 /**< Max depth of the tree */ +#define ST_RED 1 /**< This node is red */ +#define ST_BLACK 0 /**< This node is black */ +#define ST_COLOR 1 /**< Bit mask for colors */ #define ST_USE_STEP 2 #define ST_USE_LIMIT (UCHAR_MAX - ST_USE_STEP + 1) @@ -68,7 +68,7 @@ */ static StrNode *path[ST_MAX_DEPTH]; -unsigned long st_mem = 0; /**< Memory used by string trees */ +unsigned long st_mem = 0; /**< Memory used by string trees */ static void st_left_rotate(int tree_depth, StrNode **root); static void st_right_rotate(int tree_depth, StrNode **root); @@ -125,7 +125,7 @@ void st_stats_header(dbref player) { notify(player, - "Tree Entries Leaves MinDep Max Avg PermEnt AvgTmpC ~Memory"); + "Tree Entries Leaves MinDep Max Avg PermEnt AvgTmpC ~Memory"); } /** Statistics about the tree. @@ -267,45 +267,45 @@ st_insert(char const *s, StrTree *root) StrNode *y; y = path[tree_depth - 1]->right; if (y && (y->info & ST_COLOR) == ST_RED) { - /* Hmph. Uncle is red. Push the mess up the tree. */ - path[tree_depth]->info &= ~ST_RED; - y->info &= ~ST_RED; - tree_depth--; - path[tree_depth]->info |= ST_RED; - tree_depth--; + /* Hmph. Uncle is red. Push the mess up the tree. */ + path[tree_depth]->info &= ~ST_RED; + y->info &= ~ST_RED; + tree_depth--; + path[tree_depth]->info |= ST_RED; + tree_depth--; } else { - /* Okay, uncle is black. We can fix everything, now. */ - if (path[tree_depth + 1] == path[tree_depth]->right) { - st_left_rotate(tree_depth, &root->root); - path[tree_depth + 1]->info &= ~ST_RED; - } else { - path[tree_depth]->info &= ~ST_RED; - } - path[tree_depth - 1]->info |= ST_RED; - st_right_rotate(tree_depth - 1, &root->root); - break; + /* Okay, uncle is black. We can fix everything, now. */ + if (path[tree_depth + 1] == path[tree_depth]->right) { + st_left_rotate(tree_depth, &root->root); + path[tree_depth + 1]->info &= ~ST_RED; + } else { + path[tree_depth]->info &= ~ST_RED; + } + path[tree_depth - 1]->info |= ST_RED; + st_right_rotate(tree_depth - 1, &root->root); + break; } } else { StrNode *y; y = path[tree_depth - 1]->left; if (y && (y->info & ST_COLOR) == ST_RED) { - /* Hmph. Uncle is red. Push the mess up the tree. */ - path[tree_depth]->info &= ~ST_RED; - y->info &= ~ST_RED; - tree_depth--; - path[tree_depth]->info |= ST_RED; - tree_depth--; + /* Hmph. Uncle is red. Push the mess up the tree. */ + path[tree_depth]->info &= ~ST_RED; + y->info &= ~ST_RED; + tree_depth--; + path[tree_depth]->info |= ST_RED; + tree_depth--; } else { - /* Okay, uncle is black. We can fix everything, now. */ - if (path[tree_depth + 1] == path[tree_depth]->left) { - st_right_rotate(tree_depth, &root->root); - path[tree_depth + 1]->info &= ~ST_RED; - } else { - path[tree_depth]->info &= ~ST_RED; - } - path[tree_depth - 1]->info |= ST_RED; - st_left_rotate(tree_depth - 1, &root->root); - break; + /* Okay, uncle is black. We can fix everything, now. */ + if (path[tree_depth + 1] == path[tree_depth]->left) { + st_right_rotate(tree_depth, &root->root); + path[tree_depth + 1]->info &= ~ST_RED; + } else { + path[tree_depth]->info &= ~ST_RED; + } + path[tree_depth - 1]->info |= ST_RED; + st_left_rotate(tree_depth - 1, &root->root); + break; } } } @@ -449,77 +449,77 @@ st_delete(char const *s, StrTree *root) if ((y->info & ST_COLOR) == ST_BLACK) { while (x != root->root && (!x || (x->info & ST_COLOR) == ST_BLACK)) { if (x == path[tree_depth - 1]->left) { - StrNode *w = path[tree_depth - 1]->right; - assert(w); - if (w && (w->info & ST_COLOR) == ST_RED) { - w->info &= ~ST_RED; - path[tree_depth - 1]->info |= ST_RED; - st_left_rotate(tree_depth - 1, &root->root); - path[tree_depth] = path[tree_depth - 1]; - path[tree_depth - 1] = w; - tree_depth++; - w = path[tree_depth - 1]->right; - assert(w); - } - assert((w->info & ST_COLOR) == ST_BLACK); - if ((!w->left || (w->left->info & ST_COLOR) == ST_BLACK) && - (!w->right || (w->right->info & ST_COLOR) == ST_BLACK)) { - w->info |= ST_RED; - x = path[tree_depth - 1]; - tree_depth--; - } else { - if (!w->right || (w->right->info & ST_COLOR) == ST_BLACK) { - assert(w->left); - w->left->info &= ~ST_RED; - path[tree_depth] = w; - st_right_rotate(tree_depth, &root->root); - w = path[tree_depth - 1]->right; - assert(w); - } - w->info = - (w->info & ~ST_COLOR) | (path[tree_depth - 1]->info & ST_COLOR); - path[tree_depth - 1]->info &= ~ST_RED; - assert(w->right); - w->right->info &= ~ST_RED; - st_left_rotate(tree_depth - 1, &root->root); - x = root->root; - } + StrNode *w = path[tree_depth - 1]->right; + assert(w); + if (w && (w->info & ST_COLOR) == ST_RED) { + w->info &= ~ST_RED; + path[tree_depth - 1]->info |= ST_RED; + st_left_rotate(tree_depth - 1, &root->root); + path[tree_depth] = path[tree_depth - 1]; + path[tree_depth - 1] = w; + tree_depth++; + w = path[tree_depth - 1]->right; + assert(w); + } + assert((w->info & ST_COLOR) == ST_BLACK); + if ((!w->left || (w->left->info & ST_COLOR) == ST_BLACK) && + (!w->right || (w->right->info & ST_COLOR) == ST_BLACK)) { + w->info |= ST_RED; + x = path[tree_depth - 1]; + tree_depth--; + } else { + if (!w->right || (w->right->info & ST_COLOR) == ST_BLACK) { + assert(w->left); + w->left->info &= ~ST_RED; + path[tree_depth] = w; + st_right_rotate(tree_depth, &root->root); + w = path[tree_depth - 1]->right; + assert(w); + } + w->info = + (w->info & ~ST_COLOR) | (path[tree_depth - 1]->info & ST_COLOR); + path[tree_depth - 1]->info &= ~ST_RED; + assert(w->right); + w->right->info &= ~ST_RED; + st_left_rotate(tree_depth - 1, &root->root); + x = root->root; + } } else { - StrNode *w = path[tree_depth - 1]->left; - assert(w); - if (w && (w->info & ST_COLOR) == ST_RED) { - w->info &= ~ST_RED; - path[tree_depth - 1]->info |= ST_RED; - st_right_rotate(tree_depth - 1, &root->root); - path[tree_depth] = path[tree_depth - 1]; - path[tree_depth - 1] = w; - tree_depth++; - w = path[tree_depth - 1]->left; - assert(w); - } - assert((w->info & ST_COLOR) == ST_BLACK); - if ((!w->right || (w->right->info & ST_COLOR) == ST_BLACK) && - (!w->left || (w->left->info & ST_COLOR) == ST_BLACK)) { - w->info |= ST_RED; - x = path[tree_depth - 1]; - tree_depth--; - } else { - if (!w->left || (w->left->info & ST_COLOR) == ST_BLACK) { - assert(w->right); - w->right->info &= ~ST_RED; - path[tree_depth] = w; - st_left_rotate(tree_depth, &root->root); - w = path[tree_depth - 1]->left; - assert(w); - } - w->info = - (w->info & ~ST_COLOR) | (path[tree_depth - 1]->info & ST_COLOR); - path[tree_depth - 1]->info &= ~ST_RED; - assert(w->left); - w->left->info &= ~ST_RED; - st_right_rotate(tree_depth - 1, &root->root); - x = root->root; - } + StrNode *w = path[tree_depth - 1]->left; + assert(w); + if (w && (w->info & ST_COLOR) == ST_RED) { + w->info &= ~ST_RED; + path[tree_depth - 1]->info |= ST_RED; + st_right_rotate(tree_depth - 1, &root->root); + path[tree_depth] = path[tree_depth - 1]; + path[tree_depth - 1] = w; + tree_depth++; + w = path[tree_depth - 1]->left; + assert(w); + } + assert((w->info & ST_COLOR) == ST_BLACK); + if ((!w->right || (w->right->info & ST_COLOR) == ST_BLACK) && + (!w->left || (w->left->info & ST_COLOR) == ST_BLACK)) { + w->info |= ST_RED; + x = path[tree_depth - 1]; + tree_depth--; + } else { + if (!w->left || (w->left->info & ST_COLOR) == ST_BLACK) { + assert(w->right); + w->right->info &= ~ST_RED; + path[tree_depth] = w; + st_left_rotate(tree_depth, &root->root); + w = path[tree_depth - 1]->left; + assert(w); + } + w->info = + (w->info & ~ST_COLOR) | (path[tree_depth - 1]->info & ST_COLOR); + path[tree_depth - 1]->info &= ~ST_RED; + assert(w->left); + w->left->info &= ~ST_RED; + st_right_rotate(tree_depth - 1, &root->root); + x = root->root; + } } } if (x) @@ -554,8 +554,8 @@ st_print_tree(StrNode *node, int tree_depth, int lead) tmp = leader[tree_depth * 2]; leader[tree_depth * 2] = '\0'; printf("%s%c-+ %c %d %s%s\n", leader, lead, - (node->info & ST_COLOR) ? 'r' : 'b', node->info / ST_USE_STEP, - node->string, looped ? " -LOOPING" : ""); + (node->info & ST_COLOR) ? 'r' : 'b', node->info / ST_USE_STEP, + node->string, looped ? " -LOOPING" : ""); leader[tree_depth * 2] = ' ' + '|' - tmp; leader[0] = ' '; if (node->right && !looped) @@ -579,8 +579,8 @@ static void st_depth_helper unsigned long *perms, unsigned long *nperms, int count); static void st_depth_helper(StrNode *node, int *maxdepth, int *mindepth, - int *avgdepth, int *leaves, unsigned long *perms, - unsigned long *nperms, int count) + int *avgdepth, int *leaves, unsigned long *perms, + unsigned long *nperms, int count) { if (!node) return; @@ -596,14 +596,14 @@ st_depth_helper(StrNode *node, int *maxdepth, int *mindepth, if (node->left) { /* Inner node */ st_depth_helper(node->left, maxdepth, mindepth, avgdepth, leaves, perms, - nperms, count + 1); + nperms, count + 1); } if (node->right) { /* Inner node */ st_depth_helper(node->right, maxdepth, mindepth, avgdepth, leaves, perms, - nperms, count + 1); + nperms, count + 1); } - if (!node->left && !node->right) { /* This is a leaf node */ + if (!node->left && !node->right) { /* This is a leaf node */ (*leaves)++; (*avgdepth) += count; if (*mindepth > count) @@ -615,7 +615,7 @@ st_depth_helper(StrNode *node, int *maxdepth, int *mindepth, /* Find the depth and number of permanment nodes */ static void st_traverse_stats(StrNode *node, int *maxdepth, int *mindepth, int *avgdepth, - int *leaves, unsigned long *perms, unsigned long *nperms) + int *leaves, unsigned long *perms, unsigned long *nperms) { *maxdepth = 0; *mindepth = node ? (ST_MAX_DEPTH + 1) : 0; diff --git a/src/strutil.c b/src/strutil.c index 6fb5bf3..8c5bec4 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -128,8 +128,8 @@ strncasecmp(const char *s1, const char *s2, size_t n) return 0; } -#endif /* !WIN32 */ -#endif /* !HAS_STRCASECMP */ +#endif /* !WIN32 */ +#endif /* !HAS_STRCASECMP */ /** Does string begin with prefix? * This comparison is case-insensitive. @@ -162,14 +162,14 @@ string_match(const char *src, const char *sub) if (*sub != '\0') { while (*src) { if (string_prefix(src, sub)) - return src; + return src; /* else scan to beginning of next word */ while (*src && (isalpha((unsigned char) *src) - || isdigit((unsigned char) *src))) - src++; + || isdigit((unsigned char) *src))) + src++; while (*src && !isalpha((unsigned char) *src) - && !isdigit((unsigned char) *src)) - src++; + && !isdigit((unsigned char) *src)) + src++; } } return NULL; @@ -260,7 +260,7 @@ upcasestr(char *s) */ int safe_accent(const char *RESTRICT base, const char *RESTRICT tmplate, size_t len, - char *buff, char **bp) + char *buff, char **bp) { /* base and tmplate must be the same length */ size_t n; @@ -271,307 +271,307 @@ safe_accent(const char *RESTRICT base, const char *RESTRICT tmplate, size_t len, case 'A': switch (tmplate[n]) { case '`': - c = 192; - break; + c = 192; + break; case '\'': - c = 193; - break; + c = 193; + break; case '^': - c = 194; - break; + c = 194; + break; case '~': - c = 195; - break; + c = 195; + break; case ':': - c = 196; - break; + c = 196; + break; case 'o': - c = 197; - break; + c = 197; + break; case 'e': case 'E': - c = 198; - break; + c = 198; + break; default: - c = 'A'; + c = 'A'; } break; case 'a': switch (tmplate[n]) { case '`': - c = 224; - break; + c = 224; + break; case '\'': - c = 225; - break; + c = 225; + break; case '^': - c = 226; - break; + c = 226; + break; case '~': - c = 227; - break; + c = 227; + break; case ':': - c = 228; - break; + c = 228; + break; case 'o': - c = 229; - break; + c = 229; + break; case 'e': case 'E': - c = 230; - break; + c = 230; + break; default: - c = 'a'; + c = 'a'; } break; case 'C': if (tmplate[n] == ',') - c = 199; + c = 199; else - c = 'C'; + c = 'C'; break; case 'c': if (tmplate[n] == ',') - c = 231; + c = 231; else - c = 'c'; + c = 'c'; break; case 'E': switch (tmplate[n]) { case '`': - c = 200; - break; + c = 200; + break; case '\'': - c = 201; - break; + c = 201; + break; case '^': - c = 202; - break; + c = 202; + break; case ':': - c = 203; - break; + c = 203; + break; default: - c = 'E'; + c = 'E'; } break; case 'e': switch (tmplate[n]) { case '`': - c = 232; - break; + c = 232; + break; case '\'': - c = 233; - break; + c = 233; + break; case '^': - c = 234; - break; + c = 234; + break; case ':': - c = 235; - break; + c = 235; + break; default: - c = 'e'; + c = 'e'; } break; case 'I': switch (tmplate[n]) { case '`': - c = 204; - break; + c = 204; + break; case '\'': - c = 205; - break; + c = 205; + break; case '^': - c = 206; - break; + c = 206; + break; case ':': - c = 207; - break; + c = 207; + break; default: - c = 'I'; + c = 'I'; } break; case 'i': switch (tmplate[n]) { case '`': - c = 236; - break; + c = 236; + break; case '\'': - c = 237; - break; + c = 237; + break; case '^': - c = 238; - break; + c = 238; + break; case ':': - c = 239; - break; + c = 239; + break; default: - c = 'i'; + c = 'i'; } break; case 'N': if (tmplate[n] == '~') - c = 209; + c = 209; else - c = 'N'; + c = 'N'; break; case 'n': if (tmplate[n] == '~') - c = 241; + c = 241; else - c = 'n'; + c = 'n'; break; case 'O': switch (tmplate[n]) { case '`': - c = 210; - break; + c = 210; + break; case '\'': - c = 211; - break; + c = 211; + break; case '^': - c = 212; - break; + c = 212; + break; case '~': - c = 213; - break; + c = 213; + break; case ':': - c = 214; - break; + c = 214; + break; default: - c = 'O'; + c = 'O'; } break; case 'o': switch (tmplate[n]) { case '&': - c = 240; - break; + c = 240; + break; case '`': - c = 242; - break; + c = 242; + break; case '\'': - c = 243; - break; + c = 243; + break; case '^': - c = 244; - break; + c = 244; + break; case '~': - c = 245; - break; + c = 245; + break; case ':': - c = 246; - break; + c = 246; + break; default: - c = 'o'; + c = 'o'; } break; case 'U': switch (tmplate[n]) { case '`': - c = 217; - break; + c = 217; + break; case '\'': - c = 218; - break; + c = 218; + break; case '^': - c = 219; - break; + c = 219; + break; case ':': - c = 220; - break; + c = 220; + break; default: - c = 'U'; + c = 'U'; } break; case 'u': switch (tmplate[n]) { case '`': - c = 249; - break; + c = 249; + break; case '\'': - c = 250; - break; + c = 250; + break; case '^': - c = 251; - break; + c = 251; + break; case ':': - c = 252; - break; + c = 252; + break; default: - c = 'u'; + c = 'u'; } break; case 'Y': if (tmplate[n] == '\'') - c = 221; + c = 221; else - c = 'Y'; + c = 'Y'; break; case 'y': if (tmplate[n] == '\'') - c = 253; + c = 253; else if (tmplate[n] == ':') - c = 255; + c = 255; else - c = 'y'; + c = 'y'; break; case '?': if (tmplate[n] == 'u') - c = 191; + c = 191; else - c = '?'; + c = '?'; break; case '!': if (tmplate[n] == 'u') - c = 161; + c = 161; else - c = '!'; + c = '!'; break; case '<': if (tmplate[n] == '"') - c = 171; + c = 171; else - c = '<'; + c = '<'; break; case '>': if (tmplate[n] == '"') - c = 187; + c = 187; else - c = '>'; + c = '>'; break; case 's': if (tmplate[n] == 'B') - c = 223; + c = 223; else - c = 's'; + c = 's'; break; case 'p': if (tmplate[n] == '|') - c = 254; + c = 254; else - c = 'p'; + c = 'p'; break; case 'P': if (tmplate[n] == '|') - c = 222; + c = 222; else - c = 'P'; + c = 'P'; break; case 'D': if (tmplate[n] == '-') - c = 208; + c = 208; else - c = 'D'; + c = 'D'; break; default: c = base[n]; } if (isprint(c)) { if (safe_chr((char) c, buff, bp)) - return 1; + return 1; } else { if (safe_chr(base[n], buff, bp)) - return 1; + return 1; } } return 0; @@ -744,7 +744,7 @@ safe_str_space(const char *c, char *buff, char **bp) if (strchr(c, ' ')) { if (safe_chr('"', buff, bp) || safe_str(c, buff, bp) || - safe_chr('"', buff, bp)) { + safe_chr('"', buff, bp)) { *bp = saved; return 1; } @@ -884,7 +884,7 @@ u_strcpy(unsigned char *target, const unsigned char *source) */ char * replace_string(const char *RESTRICT old, const char *RESTRICT newbit, - const char *RESTRICT string) + const char *RESTRICT string) { char *result, *r; size_t len, newlen; @@ -898,7 +898,7 @@ replace_string(const char *RESTRICT old, const char *RESTRICT newbit, while (*string) { char *s = strstr(string, old); - if (s) { /* Match found! */ + if (s) { /* Match found! */ safe_strl(string, s - string, result, &r); safe_strl(newbit, newlen, result, &r); string = s + len; @@ -952,7 +952,7 @@ const char *standard_tokens[2] = { "##", "#@" }; */ char * replace_string2(const char *old[2], const char *newbits[2], - const char *RESTRICT string) + const char *RESTRICT string) { char *result, *rp; char firsts[3] = { '\0', '\0', '\0' }; @@ -1070,7 +1070,7 @@ split_token(char **sp, char sep) *str++ = '\0'; if (sep == ' ') { while (*str == sep) - str++; + str++; } } else { str = NULL; @@ -1110,10 +1110,10 @@ ansi_strlen(const char *p) while (*p) { if (*p == ESC_CHAR) { while ((*p) && (*p != 'm')) - p++; + p++; } else if (*p == TAG_START) { while ((*p) && (*p != TAG_END)) - p++; + p++; } else { i++; } @@ -1139,13 +1139,13 @@ ansi_strnlen(const char *p, size_t numchars) while (*p && numchars > 0) { if (*p == ESC_CHAR) { while ((*p) && (*p != 'm')) { - p++; - i++; + p++; + i++; } } else if (*p == TAG_START) { while ((*p) && (*p != TAG_END)) { - p++; - i++; + p++; + i++; } } else numchars--; @@ -1316,9 +1316,9 @@ mush_strncpy(char *RESTRICT dst, const char *RESTRICT src, size_t len) int format_long(long val, char *buff, char **bp, int maxlen, int base) { - char stack[128]; /* Even a negative 64 bit number will only be 21 - digits or so max. This should be plenty of - buffer room. */ + char stack[128]; /* Even a negative 64 bit number will only be 21 + digits or so max. This should be plenty of + buffer room. */ char *current; int size = 0, neg = 0; ldiv_t r; @@ -1343,14 +1343,14 @@ format_long(long val, char *buff, char **bp, int maxlen, int base) easy way out since this value is rarely encountered. */ switch (base) { case 10: - return safe_format(buff, bp, "%ld", val); + return safe_format(buff, bp, "%ld", val); case 16: - return safe_format(buff, bp, "%lx", val); + return safe_format(buff, bp, "%lx", val); case 8: - return safe_format(buff, bp, "%lo", val); + return safe_format(buff, bp, "%lo", val); default: - /* Weird base /and/ LONG_MIN. Fix someday. */ - return 0; + /* Weird base /and/ LONG_MIN. Fix someday. */ + return 0; } } @@ -1385,27 +1385,27 @@ format_long(long val, char *buff, char **bp, int maxlen, int base) switch (size % 8) { case 0: while (current < stack + sizeof(stack)) { - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 7: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 6: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 5: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 4: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 3: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 2: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); case 1: - *((*bp)++) = *(current++); + *((*bp)++) = *(current++); } } } else { while (current < stack + sizeof(stack)) { if (*bp - buff >= maxlen - 1) { - return 1; + return 1; } *((*bp)++) = *(current++); } @@ -1509,7 +1509,7 @@ strncasecoll(const char *s1, const char *s2, size_t t) mush_free(d2, "string"); return result; } -#endif /* HAS_STRXFRM && !WIN32 */ +#endif /* HAS_STRXFRM && !WIN32 */ /** Return a string pointer past any ansi/html markup at the start. * \param p a string. @@ -1523,10 +1523,10 @@ skip_leading_ansi(const char *p) while (*p == ESC_CHAR || *p == TAG_START) { if (*p == ESC_CHAR) { while (*p && *p != 'm') - p++; - } else { /* TAG_START */ + p++; + } else { /* TAG_START */ while (*p && *p != TAG_END) - p++; + p++; } if (*p) p++; @@ -1562,7 +1562,7 @@ parse_ansi_string(const char *src) y = skip_leading_ansi(src); if (y != src) { if (current) - mush_free(current, "markup_codes"); + mush_free(current, "markup_codes"); current = mush_strndup(src, y - src, "markup_codes"); src = y; } @@ -1605,11 +1605,11 @@ populate_codes(ansi_string *as) for (p = 0; p < as->len; p++) if (as->codes[p]) { if (current) - mush_free(current, "markup_codes"); + mush_free(current, "markup_codes"); current = mush_strdup(as->codes[p], "markup_codes"); } else { if (!current) - current = mush_strdup(ANSI_NORMAL, "markup_codes"); + current = mush_strdup(ANSI_NORMAL, "markup_codes"); as->codes[p] = mush_strdup(current, "markup_codes"); } if (current) @@ -1632,24 +1632,24 @@ depopulate_codes(ansi_string *as) for (p = 0; p <= as->len; p++) { if (as->codes[p]) { if (normal) { - if (strcmp(as->codes[p], ANSI_NORMAL) == 0) { - mush_free(as->codes[p], "markup_codes"); - as->codes[p] = NULL; - continue; - } else { - normal = 0; - } + if (strcmp(as->codes[p], ANSI_NORMAL) == 0) { + mush_free(as->codes[p], "markup_codes"); + as->codes[p] = NULL; + continue; + } else { + normal = 0; + } } m = p; for (p++; p < as->len; p++) { - if (as->codes[p] && strcmp(as->codes[p], as->codes[m]) == 0) { - mush_free(as->codes[p], "markup_codes"); - as->codes[p] = NULL; - } else { - p--; - break; - } + if (as->codes[p] && strcmp(as->codes[p], as->codes[m]) == 0) { + mush_free(as->codes[p], "markup_codes"); + as->codes[p] = NULL; + } else { + p--; + break; + } } } } @@ -1757,11 +1757,11 @@ int safe_ansi_string(ansi_string *as, size_t start, size_t len, char *buff, char /* p is now pointing to a starting code */ q = p; while ((q >= 0) && as->codes[q] && !is_end_html_code(as->codes[q]) && - !is_end_ansi_code(as->codes[q])) { + !is_end_ansi_code(as->codes[q])) { if (is_ansi_code(as->codes[q])) - in_ansi = 1; + in_ansi = 1; else if (is_start_html_code(as->codes[q])) - in_html++; + in_html++; q--; } /* p is now pointing to the first starting code, and we know if we're @@ -1877,15 +1877,15 @@ int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *buff, cha for (p = (int) start; p < (int) (start + len) && p < (int) as->len; p++) { if (as->codes[p]) { if (safe_str(as->codes[p], buff, bp)) - return 1; + return 1; if (is_end_ansi_code(as->codes[p])) - in_ansi = 0; + in_ansi = 0; else if (is_ansi_code(as->codes[p])) - in_ansi = 1; + in_ansi = 1; if (is_end_html_code(as->codes[p])) - in_html--; + in_html--; else if (is_start_html_code(as->codes[p])) - in_html++; + in_html++; } if (safe_chr(as->text[p], buff, bp)) return 1; @@ -1897,13 +1897,13 @@ int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *buff, cha break; if (as->codes[p]) { if (is_end_ansi_code(as->codes[p])) { - in_ansi = 0; - if (safe_str(as->codes[p], buff, bp)) - return 1; + in_ansi = 0; + if (safe_str(as->codes[p], buff, bp)) + return 1; } else if (is_end_html_code(as->codes[p])) { - in_html--; - if (safe_str(as->codes[p], buff, bp)) - return 1; + in_html--; + if (safe_str(as->codes[p], buff, bp)) + return 1; } } p++; @@ -1929,7 +1929,7 @@ int safe_ansi_string2(ansi_string *as, size_t start, size_t len, char *buff, cha */ void safe_itemizer(int cur_num, int done, const char *delim, const char *conjoin, - const char *space, char *buff, char **bp) + const char *space, char *buff, char **bp) { /* We don't do anything if it's the first one */ if (cur_num == 1) diff --git a/src/timer.c b/src/timer.c index f552e6d..257db5d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -92,7 +92,7 @@ usr1_handler(int x __attribute__ ((__unused__))) reload_sig_handler(SIGUSR1, usr1_handler); } -#endif /* WIN32 */ +#endif /* WIN32 */ /** Set up signal handlers. */ @@ -221,8 +221,8 @@ dispatch(void) /* A USR1 does a shutdown/reboot */ if (usr1_triggered) { do_rawlog(LT_ERR, T("SIGUSR1 received. Rebooting.")); - do_reboot(NOTHING, 0); /* We don't return from this */ - usr1_triggered = 0; /* But just in case */ + do_reboot(NOTHING, 0); /* We don't return from this */ + usr1_triggered = 0; /* But just in case */ } if (!globals.on_second) return; @@ -267,15 +267,15 @@ dispatch(void) fork_and_dump(1); strcpy(global_eval_context.ccom, ""); flag_broadcast(0, "ON-VACATION", "%s", - T - ("Your ON-VACATION flag is set! If you're back, clear it.")); + T + ("Your ON-VACATION flag is set! If you're back, clear it.")); } else if (NO_FORK && - (options.dump_counter - 60 == mudtime) && - *options.dump_warning_1min) { + (options.dump_counter - 60 == mudtime) && + *options.dump_warning_1min) { flag_broadcast(0, 0, "%s", options.dump_warning_1min); } else if (NO_FORK && - (options.dump_counter - 300 == mudtime) && - *options.dump_warning_5min) { + (options.dump_counter - 300 == mudtime) && + *options.dump_warning_5min) { flag_broadcast(0, 0, "%s", options.dump_warning_5min); } if (options.warn_interval && (options.warn_counter <= mudtime)) { @@ -300,7 +300,7 @@ dispatch(void) } sig_atomic_t cpu_time_limit_hit = 0; /** Was the cpu time limit hit? */ -int cpu_limit_warning_sent = 0; /** Have we issued a cpu limit warning? */ +int cpu_limit_warning_sent = 0; /** Have we issued a cpu limit warning? */ #ifndef PROFILING #if defined(HAS_ITIMER) @@ -326,7 +326,7 @@ win32_timer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) } #endif #endif -int timer_set = 0; /**< Is a CPU timer set? */ +int timer_set = 0; /**< Is a CPU timer set? */ /** Start the cpu timer (before running a command). */ @@ -337,7 +337,7 @@ start_cpu_timer(void) cpu_time_limit_hit = 0; cpu_limit_warning_sent = 0; timer_set = 1; -#if defined(HAS_ITIMER) /* UNIX way */ +#if defined(HAS_ITIMER) /* UNIX way */ { struct itimerval time_limit; if (options.queue_entry_cpu_time > 0) { @@ -349,16 +349,16 @@ start_cpu_timer(void) time_limit.it_interval.tv_sec = 0; time_limit.it_interval.tv_usec = 0; if (setitimer(ITIMER_PROF, &time_limit, NULL)) { - perror("setitimer"); - timer_set = 0; + perror("setitimer"); + timer_set = 0; } } else timer_set = 0; } -#elif defined(WIN32) /* Windoze way */ +#elif defined(WIN32) /* Windoze way */ if (options.queue_entry_cpu_time > 0) timer_id = SetTimer(NULL, 0, (unsigned) options.queue_entry_cpu_time, - (TIMERPROC) win32_timer); + (TIMERPROC) win32_timer); else timer_set = 0; #endif diff --git a/src/unparse.c b/src/unparse.c index 62278bb..29a85c8 100644 --- a/src/unparse.c +++ b/src/unparse.c @@ -116,7 +116,7 @@ unparse_room(dbref player, dbref loc) ***/ const char * real_unparse(dbref player, dbref loc, int obey_myopic, int use_nameformat, - int use_nameaccent) + int use_nameaccent) { static char buf[BUFFER_LEN], *bp; static char tbuf1[BUFFER_LEN]; @@ -124,7 +124,7 @@ real_unparse(dbref player, dbref loc, int obey_myopic, int use_nameformat, couldunparse = 0; if (!(GoodObject(loc) || (loc == NOTHING) || (loc == AMBIGUOUS) || - (loc == HOME))) + (loc == HOME))) return T("*NOTHING*"); switch (loc) { case NOTHING: @@ -217,7 +217,7 @@ nameformat(dbref player, dbref loc, char *tbuf1, char *defname) sp = save = safe_atr_value(a); bp = tbuf1; process_expression(tbuf1, &bp, &sp, loc, player, player, - PE_DEFAULT, PT_DEFAULT, NULL); + PE_DEFAULT, PT_DEFAULT, NULL); *bp = '\0'; free((Malloc_t) save); for (j = 0; j < 10; j++) { @@ -287,7 +287,7 @@ unparse_uinteger(unsigned long num) char * unparse_number(NVAL num) { - static char str[100]; /* Should be large enough for even the HUGE floats */ + static char str[100]; /* Should be large enough for even the HUGE floats */ char *p; sprintf(str, "%.*f", FLOAT_PRECISION, num); diff --git a/src/utils.c b/src/utils.c index 67c427a..f2de85b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -30,7 +30,7 @@ #endif #ifdef WIN32 #include -#include /* For GetCurrentProcessId() */ +#include /* For GetCurrentProcessId() */ #endif #include "conf.h" @@ -48,7 +48,7 @@ dbref find_entrance(dbref door); void initialize_mt(void); -static unsigned long genrand_int32(void); +unsigned int genrand_int32(void); static void init_genrand(unsigned long); static void init_by_array(unsigned long *, int); extern int local_can_interact_first(dbref from, dbref to, int type); @@ -81,7 +81,7 @@ mush_malloc(size_t size, const char *check) */ void mush_free(Malloc_t RESTRICT ptr, const char *RESTRICT check - __attribute__ ((__unused__))) + __attribute__ ((__unused__))) { del_check(check); free(ptr); @@ -142,9 +142,10 @@ parse_anon_attrib(dbref player, char *str, dbref *thing, ATTR **attrib) } else { *attrib = mush_malloc(sizeof(ATTR), "anon_attr"); AL_CREATOR(*attrib) = player; - AL_NAME(*attrib) = strdup("#lambda"); + AL_NAME(*attrib) = mush_strdup("#lambda", "anon_attr.lambda"); t = compress(str); (*attrib)->data = chunk_create(t, (u_int_16) u_strlen(t), 0); + free(t); AL_RLock(*attrib) = AL_WLock(*attrib) = TRUE_BOOLEXP; AL_FLAGS(*attrib) = AF_ANON; AL_NEXT(*attrib) = NULL; @@ -162,7 +163,7 @@ void free_anon_attrib(ATTR *attrib) { if (attrib && (AL_FLAGS(attrib) & AF_ANON)) { - free((char *) AL_NAME(attrib)); + mush_free((void *) AL_NAME(attrib), "anon_attr.lambda"); chunk_delete(attrib->data); mush_free(attrib, "anon_attr"); } @@ -300,7 +301,7 @@ call_ufun(ufun_attrib * ufun, char **wenv_args, int wenv_argc, char *ret, ap = ufun->contents; pe_ret = process_expression(ret, &rp, &ap, ufun->thing, executor, - enactor, ufun->pe_flags, PT_DEFAULT, pe_info); + enactor, ufun->pe_flags, PT_DEFAULT, pe_info); *rp = '\0'; /* Restore the old wenv */ @@ -334,9 +335,9 @@ find_entrance(dbref door) if (IsRoom(room)) { thing = Exits(room); while (thing != NOTHING) { - if (thing == door) - return room; - thing = Next(thing); + if (thing == door) + return room; + thing = Next(thing); } } return NOTHING; @@ -359,8 +360,8 @@ remove_first(dbref first, dbref what) /* have to find it */ DOLIST(prev, first) { if (Next(prev) == what) { - Next(prev) = Next(what); - return first; + Next(prev) = Next(what); + return first; } } return first; @@ -486,7 +487,7 @@ initialize_mt(void) close(fd); if (r <= 0) { do_rawlog(LT_ERR, - "Couldn't read from /dev/urandom! Resorting to normal seeding method."); + "Couldn't read from /dev/urandom! Resorting to normal seeding method."); } else { do_rawlog(LT_ERR, "Seeded RNG from /dev/urandom"); init_by_array(buf, r / sizeof(unsigned long)); @@ -494,7 +495,7 @@ initialize_mt(void) } } else do_rawlog(LT_ERR, - "Couldn't open /dev/urandom to seed random number generator. Resorting to normal seeding method."); + "Couldn't open /dev/urandom to seed random number generator. Resorting to normal seeding method."); #endif /* Default seeder. Pick a seed that's fairly random */ @@ -524,12 +525,12 @@ initialize_mt(void) /* Period parameters */ #define M 397 /**< PRNG constant */ -#define MATRIX_A 0x9908b0dfUL /**< PRNG constant vector a */ -#define UPPER_MASK 0x80000000UL /**< PRNG most significant w-r bits */ -#define LOWER_MASK 0x7fffffffUL /**< PRNG least significant r bits */ +#define MATRIX_A 0x9908b0dfUL /**< PRNG constant vector a */ +#define UPPER_MASK 0x80000000UL /**< PRNG most significant w-r bits */ +#define LOWER_MASK 0x7fffffffUL /**< PRNG least significant r bits */ -static unsigned long mt[N]; /* the array for the state vector */ -static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */ +static unsigned long mt[N]; /* the array for the state vector */ +static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */ /** initializes mt[N] with a seed. * \param a seed value. @@ -563,8 +564,8 @@ init_by_array(unsigned long init_key[], int key_length) k = (N > key_length ? N : key_length); for (; k; k--) { mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL)) - + init_key[j] + j; /* non linear */ - mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ + + init_key[j] + j; /* non linear */ + mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ i++; j++; if (i >= N) { @@ -576,8 +577,8 @@ init_by_array(unsigned long init_key[], int key_length) } for (k = N - 1; k; k--) { mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL)) - - i; /* non linear */ - mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ + - i; /* non linear */ + mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ i++; if (i >= N) { mt[0] = mt[N - 1]; @@ -585,22 +586,22 @@ init_by_array(unsigned long init_key[], int key_length) } } - mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ + mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ } /* generates a random number on [0,0xffffffff]-interval */ -static unsigned long +unsigned int genrand_int32(void) { unsigned long y; static unsigned long mag01[2] = { 0x0UL, MATRIX_A }; /* mag01[x] = x * MATRIX_A for x=0,1 */ - if (mti >= N) { /* generate N words at one time */ + if (mti >= N) { /* generate N words at one time */ int kk; - if (mti == N + 1) /* if init_genrand() has not been called, */ - init_genrand(5489UL); /* a default initial seed is used */ + if (mti == N + 1) /* if init_genrand() has not been called, */ + init_genrand(5489UL); /* a default initial seed is used */ for (kk = 0; kk < N - M; kk++) { y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); @@ -688,8 +689,10 @@ fullalias(dbref it) static char n[BUFFER_LEN]; /* STATIC */ ATTR *a = atr_get_noparent(it, "ALIAS"); - if (!a) - return '\0'; + if (!a) { + n[0] = '\0'; + return n; + } strncpy(n, atr_value(a), BUFFER_LEN - 1); n[BUFFER_LEN - 1] = '\0'; @@ -709,8 +712,10 @@ shortalias(dbref it) char *s; s = fullalias(it); - if (!(s && *s)) - return '\0'; + if (!(s && *s)) { + n[0] = '\0'; + return n; + } strncpy(n, s, BUFFER_LEN - 1); n[BUFFER_LEN - 1] = '\0'; @@ -728,7 +733,7 @@ shortalias(dbref it) char * shortname(dbref it) { - static char n[BUFFER_LEN]; /* STATIC */ + static char n[BUFFER_LEN]; /* STATIC */ char *s; strncpy(n, Name(it), BUFFER_LEN - 1); diff --git a/src/warnings.c b/src/warnings.c index 0d32105..70d2547 100644 --- a/src/warnings.c +++ b/src/warnings.c @@ -27,23 +27,23 @@ /* We might check for both locked and unlocked warnings if we can't * figure out a lock. */ -#define W_UNLOCKED 0x1 /**< Check for unlocked-object warnings */ -#define W_LOCKED 0x2 /**< Check for locked-object warnings */ - -#define W_EXIT_ONEWAY 0x1 /**< Find one-way exits */ -#define W_EXIT_MULTIPLE 0x2 /**< Find multiple exits to same place */ -#define W_EXIT_MSGS 0x4 /**< Find exits without messages */ -#define W_EXIT_DESC 0x8 /**< Find exits without descs */ -#define W_EXIT_UNLINKED 0x10 /**< Find unlinked exits */ +#define W_UNLOCKED 0x1 /**< Check for unlocked-object warnings */ +#define W_LOCKED 0x2 /**< Check for locked-object warnings */ + +#define W_EXIT_ONEWAY 0x1 /**< Find one-way exits */ +#define W_EXIT_MULTIPLE 0x2 /**< Find multiple exits to same place */ +#define W_EXIT_MSGS 0x4 /**< Find exits without messages */ +#define W_EXIT_DESC 0x8 /**< Find exits without descs */ +#define W_EXIT_UNLINKED 0x10 /**< Find unlinked exits */ /* Space for more exit stuff */ -#define W_THING_MSGS 0x100 /**< Find things without messages */ -#define W_THING_DESC 0x200 /**< Find things without descs */ +#define W_THING_MSGS 0x100 /**< Find things without messages */ +#define W_THING_DESC 0x200 /**< Find things without descs */ /* Space for more thing stuff */ -#define W_ROOM_DESC 0x1000 /**< Find rooms without descs */ +#define W_ROOM_DESC 0x1000 /**< Find rooms without descs */ /* Space for more room stuff */ -#define W_PLAYER_DESC 0x10000 /**< Find players without descs */ +#define W_PLAYER_DESC 0x10000 /**< Find players without descs */ -#define W_LOCK_PROBS 0x100000 /**< Find bad locks */ +#define W_LOCK_PROBS 0x100000 /**< Find bad locks */ /* Groups of warnings */ #define W_NONE 0 /**< No warnings */ @@ -59,8 +59,8 @@ /** A structure representing a topology warning check. */ typedef struct a_tcheck { - const char *name; /**< Name of warning. */ - warn_type flag; /**< Bitmask of warning. */ + const char *name; /**< Name of warning. */ + warn_type flag; /**< Bitmask of warning. */ } tcheck; @@ -76,7 +76,7 @@ static void ct_thing(dbref player, dbref i, warn_type flags); static tcheck checklist[] = { - {"none", W_NONE}, /* MUST BE FIRST! */ + {"none", W_NONE}, /* MUST BE FIRST! */ {"exit-unlinked", W_EXIT_UNLINKED}, {"thing-desc", W_THING_DESC}, {"room-desc", W_ROOM_DESC}, @@ -108,7 +108,7 @@ complain(dbref player, dbref i, const char *name, const char *desc, ...) #ifdef HAS_VSNPRINTF char buff[BUFFER_LEN]; #else - char buff[BUFFER_LEN * 3]; /* safety margin */ + char buff[BUFFER_LEN * 3]; /* safety margin */ #endif va_list args; @@ -124,7 +124,7 @@ complain(dbref player, dbref i, const char *name, const char *desc, ...) va_end(args); notify_format(player, T("Warning '%s' for %s:"), - name, unparse_object(player, i)); + name, unparse_object(player, i)); notify(player, buff); } @@ -162,7 +162,7 @@ ct_exit(dbref player, dbref i, warn_type flags) dst = Destination(i); if ((flags & W_EXIT_UNLINKED) && (dst == NOTHING)) complain(player, i, "exit-unlinked", - T("exit is unlinked; anyone can steal it")); + T("exit is unlinked; anyone can steal it")); if ((flags & W_EXIT_UNLINKED) && dst == AMBIGUOUS) { ATTR *a; @@ -174,12 +174,12 @@ ct_exit(dbref player, dbref i, warn_type flags) var = "EXITTO"; if (!a) complain(player, i, "exit-unlinked", - T("Variable exit has no %s attribute"), var); + T("Variable exit has no %s attribute"), var); else { const char *x = atr_value(a); if (!x || !*x) - complain(player, i, "exit-unlinked", - T("Variable exit has empty %s attribute"), var); + complain(player, i, "exit-unlinked", + T("Variable exit has empty %s attribute"), var); } } @@ -187,17 +187,17 @@ ct_exit(dbref player, dbref i, warn_type flags) if (flags & W_EXIT_MSGS) { lt = warning_lock_type(getlock(i, Basic_Lock)); if ((lt & W_UNLOCKED) && - (!atr_get(i, "OSUCCESS") || !atr_get(i, "ODROP") || - !atr_get(i, "SUCCESS"))) - complain(player, i, "exit-msgs", - T("possibly unlocked exit missing succ/osucc/odrop")); + (!atr_get(i, "OSUCCESS") || !atr_get(i, "ODROP") || + !atr_get(i, "SUCCESS"))) + complain(player, i, "exit-msgs", + T("possibly unlocked exit missing succ/osucc/odrop")); if ((lt & W_LOCKED) && !atr_get(i, "FAILURE")) - complain(player, i, "exit-msgs", - T("possibly locked exit missing fail")); + complain(player, i, "exit-msgs", + T("possibly locked exit missing fail")); } if (flags & W_EXIT_DESC) { if (!atr_get(i, "DESCRIBE")) - complain(player, i, "exit-desc", T("exit is missing description")); + complain(player, i, "exit-desc", T("exit is missing description")); } } src = Source(i); @@ -212,15 +212,15 @@ ct_exit(dbref player, dbref i, warn_type flags) for (j = Exits(dst); GoodObject(j); j = Next(j)) if (Location(j) == src) { if (!(flags & W_EXIT_MULTIPLE)) - return; + return; else - count++; + count++; } if ((count == 0) && (flags & W_EXIT_ONEWAY)) complain(player, i, "exit-oneway", T("exit has no return exit")); else if ((count > 1) && (flags & W_EXIT_MULTIPLE)) complain(player, i, "exit-multiple", - T("exit has multiple (%d) return exits"), count); + T("exit has multiple (%d) return exits"), count); } @@ -248,13 +248,13 @@ ct_thing(dbref player, dbref i, warn_type flags) if (flags & W_THING_MSGS) { lt = warning_lock_type(getlock(i, Basic_Lock)); if ((lt & W_UNLOCKED) && - (!atr_get(i, "OSUCCESS") || !atr_get(i, "ODROP") || - !atr_get(i, "SUCCESS") || !atr_get(i, "DROP"))) + (!atr_get(i, "OSUCCESS") || !atr_get(i, "ODROP") || + !atr_get(i, "SUCCESS") || !atr_get(i, "DROP"))) complain(player, i, "thing-msgs", - T("possibly unlocked thing missing succ/osucc/drop/odrop")); + T("possibly unlocked thing missing succ/osucc/drop/odrop")); if ((lt & W_LOCKED) && !atr_get(i, "FAILURE")) complain(player, i, "thing-msgs", - T("possibly locked thing missing fail")); + T("possibly locked thing missing fail")); } } @@ -306,7 +306,7 @@ do_warnings(dbref player, const char *name, const char *warns) Warnings(thing) = w; if (Warnings(thing)) notify_format(player, T("@warnings set to: %s"), - unparse_warnings(Warnings(thing))); + unparse_warnings(Warnings(thing))); else notify(player, T("@warnings cleared.")); } else { @@ -338,25 +338,25 @@ parse_warnings(dbref player, const char *warnings) while (w && *w) { found = 0; if (*w == '!') { - /* Found a negated warning */ - w++; - for (c = checklist; c->name; c++) { - if (!strcasecmp(w, c->name)) { - negate_flags |= c->flag; - found++; - } - } + /* Found a negated warning */ + w++; + for (c = checklist; c->name; c++) { + if (!strcasecmp(w, c->name)) { + negate_flags |= c->flag; + found++; + } + } } else { - for (c = checklist; c->name; c++) { - if (!strcasecmp(w, c->name)) { - flags |= c->flag; - found++; - } - } + for (c = checklist; c->name; c++) { + if (!strcasecmp(w, c->name)) { + flags |= c->flag; + found++; + } + } } /* At this point, we haven't matched any warnings. */ if (!found && player != NOTHING) { - notify_format(player, T("Unknown warning: %s"), w); + notify_format(player, T("Unknown warning: %s"), w); } w = split_token(&s, ' '); } diff --git a/src/wild.c b/src/wild.c index 15ca7a0..66efbf0 100644 --- a/src/wild.c +++ b/src/wild.c @@ -51,9 +51,9 @@ static int wild1 (const char *RESTRICT tstr, const char *RESTRICT dstr, int arg, char **wbuf, int *len, int cs, char **ary, int max); static int wild(const char *RESTRICT s, const char *RESTRICT d, int p, int cs, - char **ary, int max, char *buffer, int len); + char **ary, int max, char *buffer, int len); static int check_literals(const char *RESTRICT tstr, const char *RESTRICT dstr, - int cs); + int cs); static char *strip_backslashes(const char *str); /** Do a wildcard match, without remembering the wild data. @@ -96,7 +96,7 @@ quick_wild_new(const char *RESTRICT tstr, const char *RESTRICT dstr, int cs) * end of data. */ if (!*dstr) - return 0; + return 0; break; case '\\': /* Escape character. Move up, and force literal @@ -109,9 +109,9 @@ quick_wild_new(const char *RESTRICT tstr, const char *RESTRICT dstr, int cs) * If matching end of data, return true. */ if (NOTEQUAL(cs, *dstr, *tstr)) - return 0; + return 0; if (!*dstr) - return 1; + return 1; } tstr++; dstr++; @@ -128,7 +128,7 @@ quick_wild_new(const char *RESTRICT tstr, const char *RESTRICT dstr, int cs) while ((*tstr == '?') || (*tstr == '*')) { if (*tstr == '?') { if (!*dstr) - return 0; + return 0; dstr++; } tstr++; @@ -179,14 +179,14 @@ atr_wild(const char *RESTRICT tstr, const char *RESTRICT dstr) * end of data. */ if (!*dstr || *dstr == '`') - return 0; + return 0; break; case '`': /* Delimiter match. Special handling if at end of pattern. */ if (*dstr != '`') - return 0; + return 0; if (!tstr[1]) - return !strchr(dstr + 1, '`'); + return !strchr(dstr + 1, '`'); break; case '\\': /* Escape character. Move up, and force literal @@ -199,9 +199,9 @@ atr_wild(const char *RESTRICT tstr, const char *RESTRICT dstr) * If matching end of data, return true. */ if (NOTEQUAL(0, *dstr, *tstr)) - return 0; + return 0; if (!*dstr) - return 1; + return 1; } tstr++; dstr++; @@ -215,7 +215,7 @@ atr_wild(const char *RESTRICT tstr, const char *RESTRICT dstr) while (starcount < 2 && ((*tstr == '?') || (*tstr == '*'))) { if (*tstr == '?') { if (!*dstr || *dstr == '`') - return 0; + return 0; dstr++; starcount = 0; } else @@ -235,7 +235,7 @@ atr_wild(const char *RESTRICT tstr, const char *RESTRICT dstr) /* Scan for possible matches. */ while (*dstr) { if (*dstr != '`' && atr_wild(tstr + 1, dstr + 1)) - return 1; + return 1; dstr++; } } else { @@ -278,19 +278,19 @@ wild1(const char *RESTRICT tstr, const char *RESTRICT dstr, int arg, * end of data. */ if (!*dstr) - return 0; + return 0; if (*len >= 2) { - ary[arg++] = *wbuf; - *(*wbuf)++ = *dstr; - *(*wbuf)++ = '\0'; - *len -= 2; + ary[arg++] = *wbuf; + *(*wbuf)++ = *dstr; + *(*wbuf)++ = '\0'; + *len -= 2; } /* Jump to the fast routine if we can. */ if (arg >= (int) max || *len < 2) - return quick_wild_new(tstr + 1, dstr + 1, cs); + return quick_wild_new(tstr + 1, dstr + 1, cs); break; case '\\': /* Escape character. Move up, and force literal @@ -303,9 +303,9 @@ wild1(const char *RESTRICT tstr, const char *RESTRICT dstr, int arg, * If matching end of data, return true. */ if (NOTEQUAL(cs, *dstr, *tstr)) - return 0; + return 0; if (!*dstr) - return 1; + return 1; } tstr++; dstr++; @@ -334,27 +334,27 @@ wild1(const char *RESTRICT tstr, const char *RESTRICT dstr, int arg, * before a fixed string. */ if (*len >= 1) { - ary[argpos++] = *wbuf; - *(*wbuf)++ = '\0'; - *len -= 1; + ary[argpos++] = *wbuf; + *(*wbuf)++ = '\0'; + *len -= 1; } /* Jump to the fast routine if we can. */ if (argpos >= (int) max || *len < 2) - return quick_wild_new(tstr, dstr, cs); + return quick_wild_new(tstr, dstr, cs); /* Fill in any intervening '?'s */ while (argpos < arg) { - if (*len >= 2) { - ary[argpos++] = *wbuf; - *(*wbuf)++ = *datapos++; - *(*wbuf)++ = '\0'; - *len -= 2; - } - - /* Jump to the fast routine if we can. */ - if (argpos >= (int) max || *len < 1) - return quick_wild_new(tstr, dstr, cs); + if (*len >= 2) { + ary[argpos++] = *wbuf; + *(*wbuf)++ = *datapos++; + *(*wbuf)++ = '\0'; + *len -= 2; + } + + /* Jump to the fast routine if we can. */ + if (argpos >= (int) max || *len < 1) + return quick_wild_new(tstr, dstr, cs); } } /* Skip over the '*' for now... */ @@ -365,7 +365,7 @@ wild1(const char *RESTRICT tstr, const char *RESTRICT dstr, int arg, numextra = 0; while (*tstr == '?') { if (!*dstr) - return 0; + return 0; tstr++; dstr++; arg++; @@ -386,11 +386,11 @@ wild1(const char *RESTRICT tstr, const char *RESTRICT dstr, int arg, else { while (1) { if (EQUAL(cs, *dstr, *tstr) && - ((arg < (int) max) ? wild1(tstr, dstr, arg, wbuf, len, cs, ary, max) - : quick_wild_new(tstr, dstr, cs))) - break; + ((arg < (int) max) ? wild1(tstr, dstr, arg, wbuf, len, cs, ary, max) + : quick_wild_new(tstr, dstr, cs))) + break; if (!*dstr) - return 0; + return 0; dstr++; } } @@ -481,7 +481,7 @@ wild(const char *RESTRICT s, const char *RESTRICT d, int p, int cs, */ int wild_match_case_r(const char *RESTRICT s, const char *RESTRICT d, int cs, - char **matches, int nmatches, char *data, int len) + char **matches, int nmatches, char *data, int len) { int n; @@ -508,7 +508,7 @@ wild_match_case_r(const char *RESTRICT s, const char *RESTRICT d, int cs, */ int regexp_match_case_r(const char *RESTRICT s, const char *RESTRICT val, int cs, - char **matches, int nmatches, char *data, int len) + char **matches, int nmatches, char *data, int len) { pcre *re; int i; @@ -523,7 +523,7 @@ regexp_match_case_r(const char *RESTRICT s, const char *RESTRICT val, int cs, matches[i] = NULL; if ((re = pcre_compile(s, (cs ? 0 : PCRE_CASELESS), &errptr, &erroffset, - tables)) == NULL) { + tables)) == NULL) { /* * This is a matching error. We have an error message in * errptr that we can ignore, since we're doing @@ -557,18 +557,15 @@ regexp_match_case_r(const char *RESTRICT s, const char *RESTRICT val, int cs, for (i = 0; i < nmatches && i < subpatterns && len > 1; i++) { int sublen; - const char *submatch; - pcre_get_substring(d, offsets, subpatterns, (int) i, &submatch); - sublen = strlen(submatch); + sublen = pcre_copy_substring(d, offsets, subpatterns, (int) i, data, len); - if (sublen >= len) + if (sublen < 0) break; - strcpy(data, submatch); matches[i] = data; - data += sublen + 1; - len -= sublen + 1; + data += sublen + 2; + len -= sublen + 2; } mush_free(re, "pcre"); @@ -596,10 +593,10 @@ quick_regexp_match(const char *RESTRICT s, const char *RESTRICT d, int cs) int erroffset; int offsets[99]; int r; - int flags = 0; /* There's a PCRE_NO_AUTO_CAPTURE flag to turn all raw - ()'s into (?:)'s, which would be nice to use, - except that people might use backreferences in - their patterns. Argh. */ + int flags = 0; /* There's a PCRE_NO_AUTO_CAPTURE flag to turn all raw + ()'s into (?:)'s, which would be nice to use, + except that people might use backreferences in + their patterns. Argh. */ if (!cs) flags |= PCRE_CASELESS; @@ -643,15 +640,15 @@ local_wild_match_case(const char *RESTRICT s, const char *RESTRICT d, int cs) case '>': s++; if (is_number(s) && is_number(d)) - return (parse_number(s) < parse_number(d)); + return (parse_number(s) < parse_number(d)); else - return (strcoll(s, d) < 0); + return (strcoll(s, d) < 0); case '<': s++; if (is_number(s) && is_number(d)) - return (parse_number(s) > parse_number(d)); + return (parse_number(s) > parse_number(d)); else - return (strcoll(s, d) > 0); + return (strcoll(s, d) > 0); default: return quick_wild_new(s, d, cs); } diff --git a/src/wiz.c b/src/wiz.c index d272133..b159ccc 100644 --- a/src/wiz.c +++ b/src/wiz.c @@ -83,9 +83,9 @@ int tport_dest_ok(dbref player, dbref victim, dbref dest); int tport_control_ok(dbref player, dbref victim, dbref loc); static int mem_usage(dbref thing); static int raw_search(dbref player, const char *owner, int nargs, - const char **args, dbref **result, PE_Info * pe_info); + const char **args, dbref **result, PE_Info * pe_info); static int fill_search_spec(dbref player, const char *owner, int nargs, - const char **args, struct search_spec *spec); + const char **args, struct search_spec *spec); #ifdef INFO_SLAVE void kill_info_slave(void); @@ -121,11 +121,11 @@ do_pcreate(dbref creator, const char *player_name, const char *player_password) } if (player == AMBIGUOUS) { notify_format(creator, T("Failure creating '%s' (bad password)"), - player_name); + player_name); return NOTHING; } notify_format(creator, T("New player '%s' (#%d) created with password '%s'"), - player_name, player, player_password); + player_name, player, player_password); do_log(LT_WIZ, creator, player, T("Player creation")); return player; } @@ -1407,12 +1407,12 @@ FUNCTION(fun_quota) return; } /* count up all owned objects */ - owned = -1; /* a player is never included in his own - * quota */ + owned = -1; /* a player is never included in his own + * quota */ for (thing = 0; thing < db_top; thing++) { if (Owner(thing) == who) if (!IsGarbage(thing)) - ++owned; + ++owned; } safe_integer(owned + get_current_quota(who), buff, bp); @@ -1431,7 +1431,7 @@ FUNCTION(fun_quota) */ void do_sitelock(dbref player, const char *site, const char *opts, const char *who, - enum sitelock_type type) + enum sitelock_type type) { if (opts && *opts) { @@ -1447,11 +1447,11 @@ do_sitelock(dbref player, const char *site, const char *opts, const char *who, notify(player, T("No valid options found.")); return; } - if (who && *who) { /* Specify a character */ + if (who && *who) { /* Specify a character */ whod = lookup_player(who); if (!GoodObject(whod)) { - notify(player, T("Who do you want to lock?")); - return; + notify(player, T("Who do you want to lock?")); + return; } } @@ -1459,11 +1459,11 @@ do_sitelock(dbref player, const char *site, const char *opts, const char *who, write_access_file(); if (whod != AMBIGUOUS) { notify_format(player, - T("Site %s access options for %s(%s) set to %s"), - site, Name(whod), unparse_dbref(whod), opts); + T("Site %s access options for %s(%s) set to %s"), + site, Name(whod), unparse_dbref(whod), opts); do_log(LT_WIZ, player, NOTHING, - T("*** SITELOCK *** %s for %s(%s) --> %s"), site, - Name(whod), unparse_dbref(whod), opts); + T("*** SITELOCK *** %s for %s(%s) --> %s"), site, + Name(whod), unparse_dbref(whod), opts); } else { notify_format(player, T("Site %s access options set to %s"), site, opts); do_log(LT_WIZ, player, NOTHING, "*** SITELOCK *** %s --> %s", site, opts); @@ -1491,27 +1491,27 @@ do_sitelock(dbref player, const char *site, const char *opts, const char *who, do_log(LT_WIZ, player, NOTHING, "*** SITELOCK *** %s", site); break; case SITELOCK_CHECK:{ - struct access *ap; - char tbuf[BUFFER_LEN], *bp; - int rulenum; - if (!site || !*site) { - do_list_access(player); - return; - } - ap = site_check_access(site, AMBIGUOUS, &rulenum); - bp = tbuf; - format_access(ap, rulenum, AMBIGUOUS, tbuf, &bp); - *bp = '\0'; - notify(player, tbuf); - break; + struct access *ap; + char tbuf[BUFFER_LEN], *bp; + int rulenum; + if (!site || !*site) { + do_list_access(player); + return; + } + ap = site_check_access(site, AMBIGUOUS, &rulenum); + bp = tbuf; + format_access(ap, rulenum, AMBIGUOUS, tbuf, &bp); + *bp = '\0'; + notify(player, tbuf); + break; } case SITELOCK_REMOVE:{ - int n; - n = remove_access_sitelock(site); - if (n > 0) - write_access_file(); - notify_format(player, T("%d sitelocks removed."), n); - break; + int n; + n = remove_access_sitelock(site); + if (n > 0) + write_access_file(); + notify_format(player, T("%d sitelocks removed."), n); + break; } } } @@ -1644,8 +1644,8 @@ mem_usage(dbref thing) int k; ATTR *m; lock_list *l; - k = sizeof(struct object); /* overhead */ - k += strlen(Name(thing)) + 1; /* The name */ + k = sizeof(struct object); /* overhead */ + k += strlen(Name(thing)) + 1; /* The name */ for (m = List(thing); m; m = AL_NEXT(m)) { k += sizeof(ATTR); if (AL_STR(m) && *AL_STR(m)) @@ -1741,7 +1741,7 @@ fill_search_spec(dbref player, const char *owner, int nargs, const char **args, strcpy(spec->name, ""); spec->low = 0; spec->high = db_top - 1; - spec->start = 1; /* 1-indexed */ + spec->start = 1; /* 1-indexed */ spec->count = 0; /* set limits on who we search */ @@ -1978,7 +1978,7 @@ fill_search_spec(dbref player, const char *owner, int nargs, const char **args, /* Does the actual searching */ static int raw_search(dbref player, const char *owner, int nargs, const char **args, - dbref **result, PE_Info * pe_info) + dbref **result, PE_Info * pe_info) { size_t result_size; size_t nresults = 0; @@ -1989,7 +1989,7 @@ raw_search(dbref player, const char *owner, int nargs, const char **args, /* make sure player has money to do the search */ if (!payfor(player, FIND_COST)) { notify_format(player, T("Searches cost %d %s."), FIND_COST, - ((FIND_COST == 1) ? MONEY : MONIES)); + ((FIND_COST == 1) ? MONEY : MONIES)); return -1; } @@ -2056,11 +2056,11 @@ raw_search(dbref player, const char *owner, int nargs, const char **args, ebuf2 = ebuf1; bp = tbuf1; process_expression(tbuf1, &bp, &ebuf2, player, player, player, - PE_DEFAULT, PT_DEFAULT, pe_info); + PE_DEFAULT, PT_DEFAULT, pe_info); mush_free((Malloc_t) ebuf1, "replace_string.buff"); *bp = '\0'; if (!parse_boolean(tbuf1)) - continue; + continue; } /* Only include the matching dbrefs from start to start+count */ @@ -2076,9 +2076,9 @@ raw_search(dbref player, const char *owner, int nargs, const char **args, dbref *newresults; result_size *= 2; newresults = - (dbref *) realloc((Malloc_t) *result, sizeof(dbref) * result_size); + (dbref *) realloc((Malloc_t) *result, sizeof(dbref) * result_size); if (!newresults) - mush_panic(T("Couldn't reallocate memory in search!")); + mush_panic(T("Couldn't reallocate memory in search!")); *result = newresults; } diff --git a/utils/mkvershlp.pl b/utils/mkvershlp.pl index 9326f0c..53db5a3 100755 --- a/utils/mkvershlp.pl +++ b/utils/mkvershlp.pl @@ -21,6 +21,7 @@ my %patchlevels; my $really_started = 0; foreach my $file (@sources) { + next if $file =~ /~$/o; warn "Can't open $file!\n", next unless open(IN,"<$file"); my $target = $file; $target =~ s/.*\.(.*)/pennv$1.hlp/; -- 2.30.2