[mw-devel] MW3 r1138 - trunk/src
welshbyte at sucs.org
welshbyte at sucs.org
Wed Dec 16 11:10:08 GMT 2009
Author: welshbyte
Date: 2009-12-16 11:10:07 +0000 (Wed, 16 Dec 2009)
New Revision: 1138
Removed:
trunk/src/linux.locking
trunk/src/locking.bsd.c
trunk/src/locking.linux
trunk/src/locking.linux.c
trunk/src/locking.sysv.c
trunk/src/sentinel.c
trunk/src/sentinel.h
Modified:
trunk/src/Makefile
trunk/src/add.c
trunk/src/files.c
trunk/src/folders.c
trunk/src/gags.c
trunk/src/incoming.c
trunk/src/incoming.h
trunk/src/js.c
trunk/src/log.c
trunk/src/log.h
trunk/src/main.c
trunk/src/newmain.c
trunk/src/proto.h
trunk/src/script.c
trunk/src/script.h
trunk/src/sort.c
trunk/src/strings.c
trunk/src/strings.h
trunk/src/talker_privs.c
trunk/src/uri.c
trunk/src/vars.c
trunk/src/who.c
Log:
Lots of cleanups:
- Remove unused functions
- Remove unused source files
- static-ify some functions
Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/Makefile 2009-12-16 11:10:07 UTC (rev 1138)
@@ -98,7 +98,7 @@
newmain.o init.o talker.o talker_privs.o colour.o bork.o rooms.o alarm.o\
topten.o sort.o tidyup.o gags.o script_inst.o script.o\
incoming.o command.o chattable.o alias.o frl.o hash.o vars.o expand.o\
-files.o completion.o sentinel.o iconv.o gagtable.o \
+files.o completion.o iconv.o gagtable.o \
js.o sqlite.o ipc.o log.o uri.o
$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
Modified: trunk/src/add.c
===================================================================
--- trunk/src/add.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/add.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -384,9 +384,3 @@
free(fol);
return(0);
}
-
-int next_ref_no()
-{
- return(1);
-}
-
Modified: trunk/src/files.c
===================================================================
--- trunk/src/files.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/files.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -13,7 +13,7 @@
#include <errno.h>
#include "strings.h"
-int createuserfile()
+static int createuserfile()
{
int fd;
fd = creat(USERFILE, 0600);
@@ -72,7 +72,7 @@
close(outfile);
}
-int createwhofile()
+static int createwhofile()
{
int fd;
fd = creat(WHOFILE, 0644);
Modified: trunk/src/folders.c
===================================================================
--- trunk/src/folders.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/folders.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -12,12 +12,6 @@
#include "bb.h"
#include "ipc.h"
-void listfolders(struct person *user)
-{
- /*list all the folders*/
- /* supposed to list folder names (wide format) */
-}
-
void add_folder(void)
{
struct folder *new;
Modified: trunk/src/gags.c
===================================================================
--- trunk/src/gags.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/gags.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -289,7 +289,7 @@
gag_wordrep(text,"am ");
}
-char *lookup_morse(char c)
+static char *lookup_morse(char c)
{
switch(toupper(c))
{
@@ -346,7 +346,7 @@
return("......");
}
-char *apply_morse(char *in)
+static char *apply_morse(char *in)
{
int i;
char *out = NULL;
Modified: trunk/src/incoming.c
===================================================================
--- trunk/src/incoming.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/incoming.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -424,20 +424,6 @@
return (MesgStacked > 0);
}
-/* Cancel all pending events. Eg. after termination caused by flooding
- * Further messages cannot trigger events until the stack is cleared.
- */
-void CancelEvents()
-{
- struct mstack *ptr = MesgStack;
- while (ptr)
- {
- ptr->flags &= ~MST_EVENT;
- ptr = ptr->next;
- }
- events_cancelled = 1;
-}
-
void handle_mesg()
{
static uint32_t mesg_pid;
Modified: trunk/src/incoming.h
===================================================================
--- trunk/src/incoming.h 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/incoming.h 2009-12-16 11:10:07 UTC (rev 1138)
@@ -37,4 +37,3 @@
void DisplayStack(void);
void ClearStack(void);
void PopMesg(void);
-void CancelEvents(void);
Modified: trunk/src/js.c
===================================================================
--- trunk/src/js.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/js.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -109,7 +109,7 @@
}
/* called if a script runs too long */
-void js_timeout(void *ptr)
+static void js_timeout(void *ptr)
{
js_interrupted=2;
}
@@ -796,7 +796,7 @@
}
// Create a javascript array of strings from a struct db_data
-JSObject *dbdata_to_jsarray(JSContext *cx, struct db_data *data, int ncols) {
+static JSObject *dbdata_to_jsarray(JSContext *cx, struct db_data *data, int ncols) {
JSObject *jsdata;
JSString *jsstr;
jsval jv;
@@ -829,7 +829,7 @@
// Create a javascript array of arrays (see dbdata_to_jsarray()) from
// a struct db_result
-JSObject *dbresult_to_jsarray(JSContext *cx, struct db_result *data) {
+static JSObject *dbresult_to_jsarray(JSContext *cx, struct db_result *data) {
JSObject *jsarray;
JSObject *jsnode;
jsval jv;
@@ -859,7 +859,7 @@
}
// create a javascript array of column names from a db_result
-JSObject *dbresult_to_jscolnames(JSContext *cx, struct db_result *data) {
+static JSObject *dbresult_to_jscolnames(JSContext *cx, struct db_result *data) {
JSObject *jsarray;
jsval jv;
int i;
@@ -885,7 +885,7 @@
// creates a javascript db object from a struct js_db_result
// on success it return JS_TRUE and the pointer db_object points to the jsval of the new object
// on fail returns JS_FALSE
-JSBool dbresult_to_jsdbobject(JSContext *cx, struct js_db_result *data, jsval *db_object)
+static JSBool dbresult_to_jsdbobject(JSContext *cx, struct js_db_result *data, jsval *db_object)
{
JSObject *result_object;
JSObject *jsarray, *jscolumns;
@@ -1014,8 +1014,9 @@
JSCLASS_NO_OPTIONAL_MEMBERS
};
+#if 0
/* prints the type of a jsval */
-void show_type(char *name, jsval j)
+static void show_type(char *name, jsval j)
{
printf("%s is:",name);
if (JSVAL_IS_BOOLEAN(j)) {
@@ -1036,6 +1037,7 @@
if (JSVAL_IS_VOID(j)) printf(" VOID");
printf(" End.\n");
}
+#endif
/* Execute some javascript commands */
int js_exec(char * name, int argc, char **argvc) {
Deleted: trunk/src/linux.locking
===================================================================
--- trunk/src/linux.locking 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/linux.locking 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,27 +0,0 @@
-/*********************************************************
- * The Milliways III System is copyright 1992 *
- * J.S.Mitchell. (arthur at sugalaxy.swan.ac.uk) *
- * see licence for furthur information. *
- *********************************************************/
-
-#include <sys/file.h>
-#include <errno.h>
-
-void Lock_File(int f)
-{
- extern int errno;
- do{
- if (flock(f,LOCK_EX))
- {
- perror("Locking");
- }
- }while (errno==EINTR);
-}
-
-void Unlock_File(int f)
-{
- if (flock(f,LOCK_UN))
- {
- perror("Unlocking");
- }
-}
Deleted: trunk/src/locking.bsd.c
===================================================================
--- trunk/src/locking.bsd.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/locking.bsd.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,22 +0,0 @@
-/*********************************************************
- * The Milliways III System is copyright 1992 *
- * J.S.Mitchell. (arthur at sugalaxy.swan.ac.uk) *
- * see licence for furthur information. *
- *********************************************************/
-
-#include <sys/file.h>
-void Lock_File(int f)
-{
- if (flock(f,LOCK_EX))
- {
- perror("Locking");
- }
-}
-
-void Unlock_File(int f)
-{
- if (flock(f,LOCK_UN))
- {
- perror("Unlocking");
- }
-}
Deleted: trunk/src/locking.linux
===================================================================
--- trunk/src/locking.linux 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/locking.linux 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,28 +0,0 @@
-/*********************************************************
- * The Milliways III System is copyright 1992 *
- * J.S.Mitchell. (arthur at sugalaxy.swan.ac.uk) *
- * see licence for furthur information. *
- *********************************************************/
-
-#include <sys/errno.h>
-#include <sys/file.h>
-#include <stdio.h>
-
-void Lock_File(int f)
-{
- errno=0;
- do{
- if (flock(f,LOCK_EX))
- {
- perror("Locking");
- }
- while (errno==EINTR);
-}
-
-void Unlock_File(int f)
-{
- if (flock(f,LOCK_UN))
- {
- perror("Unlocking");
- }
-}
Deleted: trunk/src/locking.linux.c
===================================================================
--- trunk/src/locking.linux.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/locking.linux.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,25 +0,0 @@
-/*********************************************************
- * The Milliways III System is copyright 1992 *
- * J.S.Mitchell. (arthur at sugalaxy.swan.ac.uk) *
- * see licence for furthur information. *
- *********************************************************/
-
-#include <sys/errno.h>
-#include <sys/file.h>
-#include <stdio.h>
-void Lock_File(int f)
-{
- errno=0;
- do{
- if (flock(f,LOCK_EX))
- perror("Locking");
- }while (errno==EINTR);
-}
-
-void Unlock_File(int f)
-{
- if (flock(f,LOCK_UN))
- {
- perror("Unlocking");
- }
-}
Deleted: trunk/src/locking.sysv.c
===================================================================
--- trunk/src/locking.sysv.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/locking.sysv.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,67 +0,0 @@
-/*********************************************************
- * The Milliways III System is copyright 1992 *
- * J.S.Mitchell. (arthur at sugalaxy.swan.ac.uk) *
- * see licence for furthur information. *
- *********************************************************/
-
-#include <fcntl.h>
-#include <errno.h>
-
-#define LOCK_IT 1
-#define UNLOCK_IT 0
-
-void Lock_File(int f)
-{
- long position=lseek(f,0,1);
- if(position==-1)
- {
- perror("ltell");
- exit(1);
- }
- if(lseek(f,0,0)==-1)
- {
- perror("rewind");
- exit(1);
- }
- while(lockf(f,LOCK_IT,1))
- {
- if(errno!=EINTR)
- {
- perror("flock");
- exit(-1);
- }
- }
- if(lseek(f,position,0)==-1)
- {
- perror("seekback");
- exit(-1);
- }
-}
-
-void Unlock_File(int f)
-{
- long position=lseek(f,0,1);
- if(position==-1)
- {
- perror("ltell");
- exit(1);
- }
- if(lseek(f,0,0)==-1)
- {
- perror("rewind");
- exit(1);
- }
- while(lockf(f,UNLOCK_IT,1))
- {
- if(errno!=EINTR)
- {
- perror("flock");
- exit(-1);
- }
- }
- if(lseek(f,position,0)==-1)
- {
- perror("seekback");
- exit(-1);
- }
-}
Modified: trunk/src/log.c
===================================================================
--- trunk/src/log.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/log.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -208,7 +208,7 @@
free(text);
}
-char * cleanup_url(const char *in)
+static char * cleanup_url(const char *in)
{
char *out;
const char *p;
@@ -229,7 +229,7 @@
return out;
}
-char *md5(const char *in)
+static char *md5(const char *in)
{
int i;
char *out;
@@ -242,7 +242,7 @@
return out;
}
-char * extract_title(const char *body)
+static char * extract_title(const char *body)
{
char *p,*q;
char *out;
@@ -421,16 +421,3 @@
p->p_buffer[p->i_used] = 0;
return 0;
}
-
-int block_strappend(struct block_t *p, char *data)
-{
- int size = strlen(data);
-
- if (p == NULL) return 1;
- if (p->i_used + size + 1 > p->i_size)
- block_resize(p, p->i_used + size + 1);
- memcpy(&p->p_buffer[p->i_used], data, size);
- p->i_used += size;
- p->p_buffer[p->i_used] = 0;
- return 0;
-}
Modified: trunk/src/log.h
===================================================================
--- trunk/src/log.h 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/log.h 2009-12-16 11:10:07 UTC (rev 1138)
@@ -14,4 +14,3 @@
void block_free(struct block_t *);
void block_resize(struct block_t *, int);
int block_append(struct block_t *p, void *data, int size);
-int block_strappend(struct block_t *p, char *data);
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/main.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -217,7 +217,7 @@
}
-void termcap_screenchange(int n)
+static void termcap_screenchange(int n)
{
/* termcap not available */
if (g_boTermCap == 0) return;
@@ -227,7 +227,7 @@
}
-void init_termcap(void)
+static void init_termcap(void)
{
char *szTermType;
int nResult;
@@ -1484,7 +1484,7 @@
return(c);
}
-char *strip_commandname(char *line)
+static char *strip_commandname(char *line)
{
char *l2 = strdup(line);
char *l2b = l2;
@@ -1495,6 +1495,36 @@
return(out);
}
+static int word_count(char *text)
+{
+ int i;
+ int mode;
+ int count;
+
+ /* add 1 to count on each space->letter transition */
+ count=0;
+ /* 0=space 1=text */
+ mode=0;
+ i=0;
+
+ while (text[i]!=0)
+ {
+ if (isspace(text[i]))
+ mode=0;
+ else
+ {
+ if (mode==0)
+ {
+ mode=1;
+ count++;
+ }else
+ mode=1;
+ }
+ i++;
+ }
+ return(count);
+}
+
char **complete_entry(const char *text, int start, int end)
{
char **matches;
@@ -1756,14 +1786,6 @@
return(matches);
}
-void list_matches(char **a)
-{
- int i;
- i=0;
- printf("Matches:-\n");
- while (a[i]!=NULL) {printf("%d) '%s'\n",i,a[i]); i++;}
-}
-
/* tab completion feature for board commands */
char *list_commands(const char *text, int state)
{
@@ -1856,36 +1878,7 @@
return(NULL);
}
-int word_count(char *text)
-{
- int i;
- int mode;
- int count;
- /* add 1 to count on each space->letter transition */
- count=0;
- /* 0=space 1=text */
- mode=0;
- i=0;
-
- while (text[i]!=0)
- {
- if (isspace(text[i]))
- mode=0;
- else
- {
- if (mode==0)
- {
- mode=1;
- count++;
- }else
- mode=1;
- }
- i++;
- }
- return(count);
-}
-
char *part_who(const char *text, int status)
{
struct person uu;
Modified: trunk/src/newmain.c
===================================================================
--- trunk/src/newmain.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/newmain.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -546,16 +546,6 @@
printf(_("Do you want to lock or unlock it.\n"));
}
-void filed_help(char *topic)
-{
- if (access(makepath(HELPDIR,"",""),00))
- printf(_("Sorry, no help available.\n"));
- else
- {
- help(topic,u_god(user->status));
- }
-}
-
void c_listusers(CommandList *cm, int argc, char **argv, char *args)
{
list_users(FALSE);
Modified: trunk/src/proto.h
===================================================================
--- trunk/src/proto.h 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/proto.h 2009-12-16 11:10:07 UTC (rev 1138)
@@ -41,12 +41,9 @@
void reset_timeout(int secs);
char *dupstr(char *text, char *prepend);
char *duplstr(char *text);
-char **complete_entry(const char *text, int start, int end);
-void list_matches(char **a);
char *list_commands(const char *text, int state);
char *list_chat_commands(const char *text, int state);
char *find_folder(const char *text, int state);
-int word_count(char *text);
char *part_who(const char *text, int status);
char *part_who_talk(const char *text, int status);
char *part_user(const char *text, int status);
@@ -68,9 +65,7 @@
int get_mesg_header(struct folder *data, int msgnum, struct Header *head);
/* add.c */
int add_msg(int folnum, struct person *user, int replyto);
-int next_ref_no(void);
/* folders.c */
-void listfolders(struct person *user);
void add_folder(void);
void auto_subscribe(int folnum, int state);
/* new.c */
@@ -154,7 +149,6 @@
#define makepath(a,b,c) (buildpath(HOMEPATH,a,b,c))
int err_open(char *path, int type, int mode);
char *mw_fgets(char *string, int size, FILE *fp);
-void strcatc(char **str, char c);
/* files.c (see also files.h) */
int openfolderfile(int mode);
int nofolders(void);
@@ -218,15 +212,12 @@
void strip_quote(char *a);
/* who.c */
void who_delete(int pid);
-void copy(char *a, char *b);
void who_list(int mode);
void what_list(void);
int get_pid(char *name);
void check_copies(int32_t where);
char *itime(unsigned long t);
int32_t get_who_userposn(int pid);
-/* newmain.c */
-void filed_help(char *topic);
/* talker.c */
struct IgnoreList *is_ignored(char *name, struct IgnoreList **prev);
int screen_h(void);
Modified: trunk/src/script.c
===================================================================
--- trunk/src/script.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/script.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -104,7 +104,7 @@
return ( strdup(buff) );
}
-int endchar(char *haystack, char needle)
+static int endchar(char *haystack, char needle)
{
int len;
len=strlen(haystack);
@@ -702,20 +702,8 @@
busy--;
}
-void freeargv(char **argv)
+static void Push_Comparisons(int cc, int cm)
{
- int index=0;
-
- while(argv[index]!=NULL)
- {
- free(argv[index]);
- index++;
- }
- free(argv);
-}
-
-void Push_Comparisons(int cc, int cm)
-{
CompStack *temp;
temp=malloc(sizeof(CompStack));
@@ -725,7 +713,7 @@
comparison_stack = temp;
}
-void Pop_Comparisons(int *cc, int *cm)
+static void Pop_Comparisons(int *cc, int *cm)
{
CompStack *temp;
@@ -968,23 +956,6 @@
}
}
-
-struct text_stack { char *text; struct text_stack *next; };
-struct text_stack *text_bits=NULL;
-void text_add(char *chunk, int size) {
- struct text_stack *stack=text_bits, *new;
- while (stack!=NULL && stack->next!=NULL) stack=stack->next;
- new=(struct text_stack *)malloc(sizeof(struct text_stack));
-
- new->text=malloc(sizeof(char) * (size+1));
- strncpy(new->text, chunk, size);
- new->text[size]=0;
-
- new->next=NULL;
- if (stack==NULL) text_bits=new;
- else stack->next=new;
-}
-
char *eval_arg(char *arg, int argc, char **argv)
{
const char *value = eval_str(arg);
Modified: trunk/src/script.h
===================================================================
--- trunk/src/script.h 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/script.h 2009-12-16 11:10:07 UTC (rev 1138)
@@ -238,7 +238,6 @@
char ** argv_shift(int argc, char **argv, int offset, int *newsize);
void CallFunction(struct code *code, int argc, char **argv);
int ExecInst(char *line);
-void freeargv(char **argv);
void scr_devel_msg(struct code *pc, char *fmt, ...);
void RunInitFuncs(int talkinit);
@@ -250,7 +249,6 @@
char *list_mwsfile(const char *text, int state);
int expand_script_dir(char **dir);
-void var_int_force(var_list_t *list, char *name, int val);
void var_str_force_2(char *name, char *val);
char *var_str_val(var_op_t *op);
void var_key_dup(var_op_t *op);
Deleted: trunk/src/sentinel.c
===================================================================
--- trunk/src/sentinel.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/sentinel.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,308 +0,0 @@
-/* sentinel.h
- *
- * Memory allocation functions that add guard values to allocated blocks.
- */
-
-#include "sentinel.h"
-#include <stdlib.h>
-#include <string.h>
-
-/* Freshly allocated blocks are filled with this byte value */
-#define FILL_FRESH 0xf5
-
-/* Freed blocks are filled with this byte value */
-#define FILL_FREED 0xfe
-
-/* Known values stored immediately before & after every malloc'ed block.
- * Note: these are const's rather than #define's so it is simple to memcmp()
- * and memcpy() them.
- */
-static const unsigned long SENTINEL_LEFT = 0xC01055A1;
-static const unsigned long SENTINEL_RIGHT = 0xCABBA9E5;
-
-/* Private functions */
-
-/* Determine the smaller of two values of type size_t.
- * Used by sentinel_realloc() to decide how much old data to copy.
- *
- * Parameters:
- * left, right : Size values
- *
- * Returns:
- * The smaller size.
- */
-static size_t minsize(size_t left,
- size_t right);
-
-/* Function definitions */
-
-void *
-sentinel_malloc(
- size_t size)
-{
- /* Size including guard values */
- size_t newsize;
- /* Real memory block */
- void *block;
- /* Start of area used by caller */
- void *client_block;
- /* End of area used by caller */
- void *client_end;
-
- /* Make room for the guard values */
- newsize = size + sizeof(SENTINEL_LEFT) + sizeof(SENTINEL_RIGHT);
-
- block = malloc(newsize);
- if (block)
- {
- /* Set the left guard value */
- memcpy(block, &SENTINEL_LEFT, sizeof(SENTINEL_LEFT));
-
- /* Compute the block address to return to the caller */
- client_block =
- (void *)((char *)block + sizeof(SENTINEL_LEFT)/sizeof(char));
-
- /* Initialise the client area */
- memset(client_block, FILL_FRESH, size);
-
- /* Compute the address of the right guard value */
- client_end =
- (void *)((char *)client_block + size/sizeof(char));
-
- /* Set the right guard value */
- memcpy(client_end, &SENTINEL_RIGHT, sizeof(SENTINEL_RIGHT));
-
- return client_block;
- } else
- {
- /* Failed to allocate enough memory */
- return NULL;
- }
-}
-
-void *
-sentinel_calloc(
- size_t nelems,
- size_t elemsize)
-{
- /* Requested size */
- size_t size;
- /* Size including guard values */
- size_t newsize;
- /* Real memory block */
- void *block;
- /* Start of area used by caller */
- void *client_block;
- /* End of area used by caller */
- void *client_end;
-
- size = nelems * elemsize;
- newsize = size + sizeof(SENTINEL_LEFT) + sizeof(SENTINEL_RIGHT);
-
- block = malloc(newsize);
- if (block)
- {
- /* Set the left guard value */
- memcpy(block, &SENTINEL_LEFT, sizeof(SENTINEL_LEFT));
-
- /* Compute the block address to return to the caller */
- client_block =
- (void *)((char *)block + sizeof(SENTINEL_LEFT)/sizeof(char));
-
- /* Initialise the client area */
- memset(client_block, 0, size);
-
- /* Compute the address of the right guard value */
- client_end =
- (void *)((char *)client_block + size/sizeof(char));
- memcpy(client_end, &SENTINEL_RIGHT, sizeof(SENTINEL_RIGHT));
- return client_block;
- } else
- {
- /* Failed to allocate enough memory */
- return NULL;
- }
-}
-
-/* Note: this function can nullify the pointer, even if it does not free the
- * block.
- */
-int
-sentinel_realloc(
- void **block,
- size_t old_size,
- size_t new_size)
-{
- /* Client part of replacement block */
- void *new_block;
- /* Damaged sentinel flags */
- int verify_result;
-
- /* Allocate & guard the new block if necessary */
- if (new_size > 0)
- new_block = sentinel_malloc(new_size);
- else
- new_block = NULL;
-
- /* Copy existing data if necessary */
- if (new_block && *block && old_size > 0)
- memcpy(new_block, *block, minsize(old_size, new_size));
-
- /* Was memory moved or freed? */
- if (new_block || new_size <= 0)
- {
- /* Verify the guard values in the old block (It's okay if
- * *block==NULL) */
- verify_result = sentinel_free(*block, old_size);
-
- /* Update the client pointer */
- *block = new_block;
- } else
- {
- /* Failed to allocate memory. Check the old block anyway. */
- verify_result = sentinel_verify(*block, old_size);
- *block = NULL;
- }
-
- return verify_result;
-}
-
-/* Note: this function must be assumed to have freed the block, even if it
- * returns an error code.
- */
-int
-sentinel_free(
- void *client_block,
- size_t client_size)
-{
- /* Underlying memory block */
- void *block;
- /* Damaged sentinel flags */
- int verify_result;
- /* Size of underlying memory block */
- size_t size;
-
- /* Anything to do? */
- if (client_block)
- {
- /* Find the start of the underlying memory block. */
- block =
- (void *)((char *)client_block - sizeof(SENTINEL_LEFT)/sizeof(char));
-
- /* Check the guard values */
- verify_result = sentinel_verify(block, client_size);
-
- /* Safe to free the block? */
- if (verify_result == 0)
- {
- /* Compute the size of the real block */
- size =
- sizeof(SENTINEL_LEFT) + client_size + sizeof(SENTINEL_RIGHT);
-
- /* Fill the freed memory with a known value to help debugging. */
- memset(block, FILL_FREED, size);
-
- free(block);
- } else
- {
- /* Abandon the block & accept the leak */
- }
-
- return verify_result;
- } else
- {
- /* There were no guard values to overwrite. */
- return 0;
- }
-}
-
-int
-sentinel_verify(
- void *block,
- size_t client_size)
-{
- /* End of client area == start of right sentinel */
- void *client_end;
- /* Damaged sentinel flags */
- int verify_result;
-
- verify_result = 0;
-
- /* Left guard value overwritten? */
- if (memcmp(block, &SENTINEL_LEFT, sizeof(SENTINEL_LEFT)) != 0)
- verify_result |= 1;
-
- /* Calculate where the right guard value should be. */
- client_end =
- (void *)((char *)block +
- (client_size + sizeof(SENTINEL_LEFT))/sizeof(char));
-
- /* Right guard value overwritten? */
- if (memcmp(client_end, &SENTINEL_RIGHT, sizeof(SENTINEL_RIGHT)) != 0)
- verify_result |= 2;
-
- return verify_result;
-}
-
-void *
-sentinel_wrap(
- void *block,
- size_t size)
-{
- /* Client part of replacement block */
- void *new_block;
-
- /* Allocate & guard the new block */
- new_block = sentinel_malloc(size);
- if (new_block)
- {
- /* Copy existing data (assumes size==0 || block != NULL) */
- memcpy(new_block, block, size);
-
- free(block);
- return new_block;
- } else
- {
- /* Failed to allocate memory */
- return NULL;
- }
-}
-
-int
-sentinel_unwrap(
- void **block,
- size_t size)
-{
- /* New block (without guard values) */
- void *new_block;
- /* Damaged sentinel flags */
- int verify_result;
-
- /* Allocate an ordinary block */
- new_block = malloc(size);
- if (new_block)
- {
- /* Copy existing data (assumes size==0 || *block != NULL) */
- memcpy(new_block, *block, size);
-
- /* Verify the guard values in the old block (It's okay if
- * *block==NULL) */
- verify_result = sentinel_free(*block, size);
-
- /* Update the caller's pointer */
- *block = new_block;
-
- return verify_result;
- } else
- {
- return 0;
- }
-}
-
-static size_t
-minsize(
- size_t left,
- size_t right)
-{
- return (left <= right? left: right);
-}
Deleted: trunk/src/sentinel.h
===================================================================
--- trunk/src/sentinel.h 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/sentinel.h 2009-12-16 11:10:07 UTC (rev 1138)
@@ -1,155 +0,0 @@
-/* sentinel.h
- *
- * Memory allocation functions that add guard values to allocated blocks.
- */
-
-#ifndef INCLUDED_sentinel_h
-#define INCLUDED_sentinel_h
-
-#include <stdlib.h>
-
-/* Allocate a memory block with guard values before and after.
- * When sentinel_free frees the block it will make sure these values have not
- * been overwritten. This can also be verified at any time using
- * sentinel_verify().
- * Each byte in the newly allocated block is initialised with the value
- * 0xF5.
- *
- * Parameters:
- * size : Required size of block (space for the sentinel
- * values is added automatically).
- *
- * Returns:
- * Pointer to the 'client' part of the allocated block (just after the
- * left sentinel)
- * NULL if not enough memory available
- */
-void *sentinel_malloc(size_t size);
-
-/* Allocate a memory block with guard values before and after.
- * The newly allocated block is initialised with zeroes. Otherwise this
- * function works the same way as sentinel_malloc().
- *
- * Parameters:
- * nelems : Element count
- * size : Element size
- *
- * Returns:
- * Pointer to the 'client' part of the allocated block
- * NULL if not enough memory available
- */
-void *sentinel_calloc(size_t nelems,
- size_t size);
-
-/* Change the size of a memory block allocated with sentinel_malloc().
- * This simply calls sentinel_malloc() for the new block, then sentinel_free()
- * for the old block, so the location always changes.
- * Unlike realloc() the size of the original block is needed.
- *
- * Parameters:
- * *ptr : Block address variable
- * On entry, contains the start address of the original
- * block.
- * On exit, contains the start address of the new block,
- * or NULL if there is insufficient memory.
- * oldsize : Size of the original block.
- * newsize : Desired size of the new block
- *
- * Returns:
- * Verification result. See sentinel_verify() for details.
- *
- * Notes:
- * 1 - The pointer may be overwritten with NULL if allocation fails, but
- * the original pointer is still valid, so either save it, or better
- * still abort() if out of memory.
- * 2 - An unsuccessful verification will not prevent the new block being
- * allocated. Corrupted data may be copied.
- */
-int sentinel_realloc(void **ptr,
- size_t oldsize,
- size_t newsize);
-
-/* Free a block of memory allocated by sentinel_malloc().
- * Before freeing the block, this function calls sentinel_verify() to check
- * that the guard values have not been overwritten, then fills the whole block
- * (including the part originally occupied by the guard values) with the byte
- * value 0xFE.
- *
- * Parameters:
- * ptr : Start of the 'client' part of the allocated block.
- *
- * Returns:
- * Verification result. See sentinel_verify() for details.
- *
- * Notes:
- * 1 - If verification is unsuccessful, the block will not be freed.
- * This will cause memory leaks.
- */
-int sentinel_free(void *ptr,
- size_t size);
-
-/* Inspect an allocated block to see if the guard values have been overwritten.
- *
- * Parameters:
- * ptr : Start of the 'client' part of the allocated block.
- *
- * Returns:
- * Verification result
- * 0 - The guard values are unchanged - good.
- * 1 - The left guard value has been overwritten, i.e. buffer underrun
- * has occurred.
- * 2 - The right guard value has been overwritten, i.e. buffer overrun
- * has occurred.
- * 3 - Both guard values have been overwritten. Something is very wrong.
- */
-int sentinel_verify(void *ptr,
- size_t size);
-
-/* Replace an ordinary memory block (allocated with malloc()) with a guarded
- * block (allocated with sentinel_malloc()).
- * Unfortunately the block cannot be modified in place, so the location will
- * always change. This function is most useful as a wrapper for another
- * function that returns a malloc'ed block (which the caller is expected to
- * free).
- *
- * Parameters:
- * ptr : Start address of the original block (without guard
- * values).
- * size : Size of block
- *
- * Returns:
- * Pointer to the 'client' part of the allocated block
- * NULL if not enough memory available
- */
-void *sentinel_wrap(void *ptr,
- size_t size);
-
-/* Replace an guarded memory block (allocated with sentinel_malloc()) with a
- * guarded block (allocated with malloc()).
- * Unfortunately the block cannot be modified in place, so the location will
- * always change. This function is most useful as a wrapper for another
- * function that is expected to free the block (so the original pointer should
- * not be saved).
- *
- * Parameters:
- * *ptr : Block address variable
- * On entry, contains the start address of the 'client'
- * part of the original block (with guard values).
- * On exit, contains the start address of the new block
- * (without guard values) or NULL if there is
- * insufficient memory.
- * size : Size of block
- *
- * Returns:
- * Verification result. See sentinel_verify() for details.
- *
- * Notes:
- * 1 - The pointer may be overwritten with NULL if allocation fails.
- * The original pointer is still valid, and remains wrapped.
- * 2 - A verification error will not prevent the new block being
- * allocated. Corrupted data may be copied.
- */
-int sentinel_unwrap(void **ptr,
- size_t size);
-
-#endif /* INCLUDED_sentinel_h */
Modified: trunk/src/sort.c
===================================================================
--- trunk/src/sort.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/sort.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -8,12 +8,12 @@
#include "bb.h"
#include "sort.h"
-int IsBigger(struct listing *a, struct listing *b)
+static int IsBigger(struct listing *a, struct listing *b)
{
if (a->size < b->size) return(1); else return(0);
}
-struct listing *Insert(struct listing *a, struct listing *b)
+static struct listing *Insert(struct listing *a, struct listing *b)
{
struct listing *c=a;
struct listing *p=NULL;
Modified: trunk/src/strings.c
===================================================================
--- trunk/src/strings.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/strings.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -55,11 +55,6 @@
/*static char stackedline[1024];*/
-void stack_force(char *string)
-{
- stack_cmd(string, CMD_TEXT|CMD_FORCED);
-}
-
void stack_str(char *string)
{
stack_cmd(string, CMD_TEXT|CMD_TYPED);
@@ -263,22 +258,6 @@
return(string);
}
-int get_very_rand(int min, int max)
-{
- int f;
- unsigned int rand;
-
- f=open("/dev/urandom",O_RDONLY);
- read(f, &rand, sizeof(unsigned int));
- close(f);
-
- rand %= (max - min + 1);
- rand += min;
-
- return (rand);
-}
-
-
int get_rand(int min, int max)
{
float fValue;
@@ -290,18 +269,6 @@
return ((int)fValue);
}
-
-void strcatc(char **str, char c)
-{
- char add[2];
-
- add[0] = c;
- add[1] = 0;
-
- *str = realloc(*str, sizeof(char) * (strlen(*str) + strlen(add) + 1));
- strcat(*str, add);
-}
-
void string_add(char **str, char *add)
{
if (add != NULL)
@@ -318,22 +285,6 @@
}
}
-void string_addnum(char **str, unsigned int num)
-{
- char add[20];
- snprintf(add, 19, "%u", num);
-
- if (*str == NULL)
- {
- *str = strdup(add);
- }
- else
- {
- *str = realloc(*str, sizeof(char) * (strlen(*str) + strlen(add) + 1));
- strcat(*str, add);
- }
-}
-
int allspace(char *in)
{
if (!strcmp(in, "")) {
@@ -349,19 +300,6 @@
}
}
-
-void strupper(char *szString)
-{
- int nLength, nIndex;
-
- nLength = strlen(szString);
- for (nIndex = 0; nIndex < nLength; nIndex++)
- {
- szString[nIndex] = toupper(szString[nIndex]);
- }
-}
-
-
void strlower(char *szString)
{
int nLength, nIndex;
@@ -374,7 +312,7 @@
}
/* replace ESC characters ('\033') with "[ESC]", maybe in black on white */
-void strip_esc(char *const in, int hilite)
+static void strip_esc(char *const in, int hilite)
{
static char szOutText[MAXTEXTLENGTH];
int oldlen = strlen(in), nInPos, nOutPos;
Modified: trunk/src/strings.h
===================================================================
--- trunk/src/strings.h 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/strings.h 2009-12-16 11:10:07 UTC (rev 1138)
@@ -12,16 +12,12 @@
void stack_cmd(char *string, int type);
void stack_str(char *string);
-void stack_force(char *string);
int is_stacked(void);
void pop_cmd(char *string, int len, int *type);
int pop_stack(char *string, int len);
-int get_very_rand(int min, int max);
int get_rand(int min, int max);
void string_add(char **str, char *add);
-void string_addnum(char **str, unsigned int num);
int allspace(char *s);
-void strupper(char *szString);
void strlower(char *szString);
int stringcmp(const char *a, const char *b, int n);
Modified: trunk/src/talker_privs.c
===================================================================
--- trunk/src/talker_privs.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/talker_privs.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -265,7 +265,7 @@
return("Ungag");
}
-unsigned long gag_flags(char *str)
+static unsigned long gag_flags(char *str)
{
int i,j, type;
unsigned long p=0;
Modified: trunk/src/uri.c
===================================================================
--- trunk/src/uri.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/uri.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -43,7 +43,7 @@
};
// turns the db flag string into a bitwise flag field
-int uri_parse_flags(const char *flagstr)
+static int uri_parse_flags(const char *flagstr)
{
int flags = 0;
uriFlagList *fl = uriflagtable;
@@ -78,7 +78,7 @@
}
// creates a the flag descriptions show in uri list from the database flags string
-void uri_make_flags_description(char *shortflags, char *flagstr, int len)
+static void uri_make_flags_description(char *shortflags, char *flagstr, int len)
{
int n=0;
uriFlagList *fl = uriflagtable;
@@ -99,7 +99,7 @@
// returns the long description for flag
// should be duplicated if you want to edit it
-char *uri_get_flag_description(int flag)
+static char *uri_get_flag_description(int flag)
{
uriFlagList *fl = uriflagtable;
Modified: trunk/src/vars.c
===================================================================
--- trunk/src/vars.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/vars.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -40,103 +40,6 @@
return VAR_INT_VAL(&op);
}
-/*
-#define VAR_STR_FORCE(list1, name1, val1) \
-do { \
- var_op_t _op_6; \
- char *_name_6 = (name1); \
- var_list_t *_list_6 = (list1); \
- char *_val_6 = (val1); \
- VAR_OP_INIT(&_op_6, _list_6); \
- VAR_SEARCH(&_op_6, _name_6); \
- if (VAR_FOUND(&_op_6)) \
- { \
- if (script_debug) printf("- %s: updating var $%s (%s) to '%s'\n", pc->inst->name, _name_6, VAR_STR_VAL(&_op_6), _val_6); \
- VAR_STR_UPDATE(&_op_6, _val_6); \
- } else \
- { \
- if (script_debug) printf("- %s: creating var $%s setting to '%s'\n", pc->inst->name, _name_6, _val_6); \
- VAR_STR_CREATE(&_op_6, _val_6); \
- } \
-} while (0)
-
-#define ARG_STR_FORCE(list1, name1, val1) \
-do { \
- var_op_t _op_6; \
- char _name_6[5]; \
- var_list_t *_list_6 = (list1); \
- char *_val_6 = (val1); \
- snprintf(_name_6, 4, "%d", (name1)); \
- VAR_OP_INIT(&_op_6, _list_6); \
- VAR_SEARCH(&_op_6, _name_6); \
- if (VAR_FOUND(&_op_6)) \
- VAR_STR_UPDATE(&_op_6, _val_6); \
- else \
- VAR_STR_CREATE(&_op_6, _val_6); \
-} while (0)
-
-#define VAR_ARRAY_FORCE(list1, name1, val1) \
-do { \
- var_op_t _op_6; \
- char *_name_6 = (name1); \
- var_list_t *_list_6 = (list1); \
- char *_val_6 = (val1); \
- VAR_OP_INIT(&_op_6, _list_6); \
- VAR_SEARCH(&_op_6, _name_6); \
- if (VAR_FOUND(&_op_6)) \
- { \
- if (script_debug) printf("- %s: updating var $%s (%s) to '%s'\n", pc->inst->name, _name_6, VAR_STR_VAL(&_op_6), _val_6); \
- VAR_ARRAY_UPDATE(&_op_6, _val_6); \
- } else \
- { \
- if (script_debug) printf("- %s: creating var $%s setting to '%s'\n", pc->inst->name, _name_6, _val_6); \
- VAR_ARRAY_CREATE(&_op_6, _val_6); \
- } \
-} while (0)
-*/
-
-void var_int_force(var_list_t *list, char *name, int val)
-{
- var_op_t op;
-
- VAR_OP_INIT(&op, list);
- VAR_SEARCH(&op, name);
- if (VAR_FOUND(&op))
- {
- VAR_INT_UPDATE(&op, val);
- } else
- {
- VAR_INT_CREATE(&op, val);
- }
-}
-
-/*
-#define VAR_SEARCH_2(op1, llist1, glist1, name1) \
-do { \
- var_op_t *_op_8 = (op1); \
- char *_name_8 = (name1); \
- VAR_OP_INIT(_op_8, (llist1)); \
- VAR_SEARCH(_op_8, _name_8); \
- if (!VAR_FOUND(_op_8)) \
- { \
- VAR_OP_INIT(_op_8, (glist1)); \
- VAR_SEARCH(_op_8, _name_8); \
- } \
-} while (0);
-
-#define VAR_STR_PREPARE_2(op1, llist1, glist1, name1, dflt) \
-do { \
- var_op_t *_op_9 = (op1); \
- VAR_SEARCH_2(_op_9, llist1, glist1, name1); \
- if (!VAR_FOUND(_op_9)) \
- { \
- if (script_debug) printf("- %s: creating $%s.\n", pc->inst->name, name1); \
- VAR_STR_CREATE(_op_9, dflt); \
- } \
-} while (0);
-
-*/
-
void var_str_force_2(char *name, char *val)
{
var_op_t op;
Modified: trunk/src/who.c
===================================================================
--- trunk/src/who.c 2009-12-16 10:04:11 UTC (rev 1137)
+++ trunk/src/who.c 2009-12-16 11:10:07 UTC (rev 1138)
@@ -45,27 +45,6 @@
close(fd);
}
-void copy(char *a, char *b)
-{
- int af,bf;
- char buff[1024];
- int size;
-
- if ((af=open(a,O_WRONLY|O_CREAT,0600))<0)
- {perror(a);exit(-1);}
- if ((bf=open(b,O_RDONLY))<0)
- {perror(b);exit(-1);}
-
- Lock_File(af);
- while ((size=read(bf,buff,1024)))
- {
- write(af,buff,size);
- }
- Unlock_File(af);
- close(af);
- close(bf);
-}
-
void what_list(void) {
struct person u;
int ufile;
@@ -273,7 +252,7 @@
}
}
-void rwho_list(void)
+static void rwho_list(void)
{
struct person user;
struct who w;
More information about the mw-devel
mailing list