[mw-devel] MW3 r1356 - in trunk/src: . client webclient

welshbyte at sucs.org welshbyte at sucs.org
Sat Nov 2 02:57:06 GMT 2013


Author: welshbyte
Date: 2013-11-02 02:57:06 +0000 (Sat, 02 Nov 2013)
New Revision: 1356

Added:
   trunk/src/client/strings.c
   trunk/src/client/strings.h
Removed:
   trunk/src/strings.c
   trunk/src/strings.h
Modified:
   trunk/src/client/userio.c
   trunk/src/folders.c
   trunk/src/ipc.c
   trunk/src/webclient/import.c
   trunk/src/webclient/import.h
Log:
Move strings.{c,h} into src/client


Copied: trunk/src/client/strings.c (from rev 1352, trunk/src/strings.c)
===================================================================
--- trunk/src/client/strings.c	                        (rev 0)
+++ trunk/src/client/strings.c	2013-11-02 02:57:06 UTC (rev 1356)
@@ -0,0 +1,330 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdarg.h>
+#include "bb.h"
+#include "strings.h"
+
+#define min(a,b) a<b?a:b
+#define max(a,b) a>b?a:b
+
+int stringcmp(const char *a, const char *b, int n)
+{
+	int length;
+
+	/* total match */
+	if (n==-1)
+	{
+		length=max(strlen(a),strlen(b));
+	}
+	/* first partial match */
+	else if (n==-2)
+	{
+		length=min(strlen(a),strlen(b));
+	}
+	/* match by atleast n (or shortest string) */
+	else
+	{
+		if (strlen(a)<n) return 0;
+		length=strlen(a)>strlen(b)?strlen(a):strlen(b);
+		length=n<length?n:length;
+	}
+
+	if (length==0) return 0;
+	return (!strncasecmp(a,b,length));
+}
+
+struct stacked_str *cmd_stack = NULL;
+struct stacked_str **last_cmd = &cmd_stack;
+static int stacked=0;
+
+/*static char stackedline[1024];*/
+
+void stack_str(char *string)
+{
+	stack_cmd(string, CMD_TEXT|CMD_TYPED);
+}
+
+void stack_cmd(char *string, int cmdtype)
+{
+	struct stacked_str *new;
+
+	new = malloc(sizeof(*new));
+	new->text = strdup(string);
+	new->type = cmdtype;
+	new->next = *last_cmd;
+	*last_cmd = new;
+	stacked++;
+}
+
+int is_stacked()
+{
+	return(stacked);
+}
+
+int pop_stack(char *string, int len)
+{
+	int type=0;
+	pop_cmd(string, len, &type);
+	return (type && CMD_FORCED) != 0;
+}
+
+void pop_cmd(char *string, int len, int *type)
+{
+	struct stacked_str *free_me;
+
+	if (stacked > 0)
+	{
+		stacked--;
+		strncpy(string, cmd_stack->text, len);
+		*type = cmd_stack->type;
+		free(cmd_stack->text);
+		free_me = cmd_stack;
+		cmd_stack = cmd_stack->next;
+		free(free_me);
+		if (cmd_stack == NULL) last_cmd = &cmd_stack;
+	}
+	string[len]=0;
+}
+
+void strip_str(char *string)
+{
+	char *array;
+	int i,ptr=0;
+	int len;
+	
+	len=strlen(string);
+	array=(char *)malloc(len+1);
+	for (i=0;i<len;i++)
+	{
+		if (string[i]==033 || (string[i]>=040 && string[i]<=0176) || (unsigned char)string[i]>0177)
+			array[ptr++]=string[i];
+	}
+	array[ptr]=0;
+	strcpy(string,array);
+	free(array);
+}
+
+
+
+/* common file functions */
+
+char *buildpath(const char *a, const char *b, const char *c, const char *d)
+{
+	static char fullpath[PATHSIZE];
+
+	snprintf(fullpath, PATHSIZE-1, "%s/%s%s%s",a,b,c,d);
+	return(fullpath);
+}
+
+int err_open(const char *path,int type,int mode)
+{
+	int x;
+	x=open(path,type,mode);
+	if (x<0)
+		perror(path);
+	return(x);
+}
+
+int get_rand(int min, int max)
+{
+	int r = rand();
+	float	fValue;
+
+	fValue = (float)r * (float)(max - min + 1);
+	fValue /= (float)RAND_MAX;
+	fValue += (float)min;
+
+	return ((int)fValue);
+}
+
+void string_add(char **str, const char *add)
+{
+	if (add != NULL)
+	{
+		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, "")) {
+		return(1);
+	} else {
+		int i;
+
+		for(i=0;i<strlen(in);i++)
+		{
+			if (in[i]!=' ') return(0);
+		}
+		return(1);
+	}
+}
+
+void strlower(char *szString)
+{
+	int	nLength, nIndex;
+
+	nLength = strlen(szString);
+	for (nIndex = 0; nIndex < nLength; nIndex++)
+	{
+		szString[nIndex] = tolower(szString[nIndex]);
+	}
+}
+
+/* replace ESC characters ('\033') with "[ESC]", maybe in black on white */
+static void strip_esc(char *const in, int hilite)
+{
+    static char szOutText[MAXTEXTLENGTH];
+    int         oldlen = strlen(in), nInPos, nOutPos;
+    if (oldlen >= MAXTEXTLENGTH-1) oldlen = MAXTEXTLENGTH;
+
+    for (nInPos = 0, nOutPos = 0; nInPos < oldlen && nOutPos < MAXTEXTLENGTH-1; nInPos++)
+    {
+        /* escape character found */
+        if (in[nInPos] == 033)
+        {
+            const char*const esc = "\033[7m[ESC]\033[0m";
+            const char*const noesc = "[ESC]";
+            if (hilite) {
+                /* like strncpy, but avoid writing incomplete escape sequences */
+                if (nOutPos >= (MAXTEXTLENGTH << 1) + strlen(esc)) {
+                    break; /* not enough space left */
+                }
+                strcpy(szOutText+nOutPos, esc);
+                nOutPos += strlen(esc);
+            } else {
+                strncpy(szOutText+nOutPos, noesc, MAXTEXTLENGTH-nOutPos-1);
+                nOutPos += strlen(noesc);
+            }
+        }
+        /* normal character */
+        else
+        {
+                szOutText[nOutPos++] = in[nInPos];
+        }
+    }
+    szOutText[nOutPos] = 0;
+    strcpy(in, szOutText);
+}
+
+void escprintf(const char *szFormat, ...)
+{
+	static char	szText[MAXTEXTLENGTH];
+	va_list		vaList;
+
+	/* get text to process */
+	va_start(vaList, szFormat);
+	vsnprintf(szText, MAXTEXTLENGTH-1, szFormat, vaList);
+	va_end(vaList);
+
+	/* process control characters into strings */
+	strip_esc(szText,1);
+
+	printf("%s", szText);
+}
+
+/* returns a new string without any mw colour codes in */
+char *strip_colours(const char *text)
+{
+	char *new;
+	int i, j, len, k;
+
+	len = strlen(text);
+	new = malloc(sizeof(char) * (len+1));
+	i=0;
+	j=0;
+	while (i<len)
+	{
+		if (text[i]==033)
+		{
+			i++;
+			k=0;
+			//utf8 safe way to skip the next two chars
+			//we only need this in case someone is mean enough to try using something like
+			// [ESC]r£ as a colour sequence which would previously have us remove the first 
+			// byte of the utf8 sequence leaving us with an invalid char.
+			while(i<len && k<2)
+			{
+				if(((unsigned char)text[i] & 192)==192 )
+				{
+					// skip char is the first byte of a utf8 sequence
+					i++;
+					while( ((unsigned char)text[i] & 192) == 128 && i<len)
+					{
+						//skip all utf8 continuation bytes
+						i++;
+					}
+				}
+				else
+				{
+					// char was ascii so we can just skip it.
+					i++;
+				}
+				k++;
+			}
+			
+			continue;
+		}
+		new[j++]=text[i++];
+	}
+	new[j]=0;
+	return(new);
+}
+
+/* Strip any trailing quote characters (^a) that may have been left at the end
+ *  * of a buffer by snprintf() truncating a quoted string.
+ *   */
+void strip_quote(char *a)
+{
+    char *end = a + strlen(a);
+
+    /* Step back through quote chars */
+    while (end > a && *(--end) == '\001')
+        *end = '\0';
+}
+
+char *quotetext(const char *a)
+{
+        int     count;
+        int     ai, bi;
+        char    *b;
+
+        ai=0;
+        count=0;
+        while(a[ai]!=0)
+        {
+                if (a[ai]=='|') count++;
+                ai++;
+        }
+
+        b = malloc(sizeof(char) * (strlen(a) + count + 1));
+
+        ai=bi=0;
+        while (a[ai]!=0)
+        {
+                if (a[ai]=='|')
+                {
+                        b[bi]=1;
+                        bi++;
+                }
+
+                b[bi]=a[ai];
+                bi++;
+                ai++;
+        }
+        b[bi]=0;
+
+        return (b);
+}
+

Copied: trunk/src/client/strings.h (from rev 1348, trunk/src/strings.h)
===================================================================
--- trunk/src/client/strings.h	                        (rev 0)
+++ trunk/src/client/strings.h	2013-11-02 02:57:06 UTC (rev 1356)
@@ -0,0 +1,38 @@
+#ifndef STRINGS_H
+#define STRINGS_H
+
+#define CMD_TEXT	0	/* Interpreted depending on mode/prefix      */
+#define CMD_BOARD	1	/* Always a board command, used by BOARDEXEC */
+#define CMD_TALKER	2	/* Always a talker command, used by EXEC     */
+#define CMD_TYPED	0	/* Was entered at the keyboard               */
+#define CMD_FORCED	0x100	/* Forced by another user                    */
+
+struct stacked_str {
+	char *text;
+	int type;
+	struct stacked_str *next;
+};
+
+void stack_cmd(char *string, int type);
+void stack_str(char *string);
+int is_stacked(void);
+void pop_cmd(char *string, int len, int *type);
+int pop_stack(char *string, int len);
+int get_rand(int min, int max);
+void string_add(char **str, const char *add);
+int allspace(char *s);
+void strlower(char *szString);
+int stringcmp(const char *a, const char *b, int n);
+
+void escprintf(const char *szFormat, ...) __attribute__((format(printf,1,2)));
+char *strip_colours(const char *text);
+void strip_str(char *string);
+void strip_quote(char *a);
+char *quotetext(const char *a);
+
+char *buildpath(const char *a, const char *b, const char *c, const char *d);
+#define makepath(a,b,c) (buildpath(HOMEPATH,a,b,c))
+
+int err_open(const char *path,int type,int mode);
+
+#endif /* STRINGS_H */

Modified: trunk/src/client/userio.c
===================================================================
--- trunk/src/client/userio.c	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/client/userio.c	2013-11-02 02:57:06 UTC (rev 1356)
@@ -3,10 +3,10 @@
 #include <errno.h>
 #include <arpa/telnet.h>
 #include <string.h>
-#include <strings.h>
 
 #include "userio.h"
 #include "main.h"
+#include "strings.h"
 
 extern int internet;
 int eof_caught=0;

Modified: trunk/src/folders.c
===================================================================
--- trunk/src/folders.c	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/folders.c	2013-11-02 02:57:06 UTC (rev 1356)
@@ -64,12 +64,14 @@
 	int number=0;
 	int no;
 	struct folder fold;
-	
+	size_t len = strlen(name);
+
+	if (len == 0) return -1;
 	if ((file=openfolderfile(O_RDONLY)) < 0) return -1;
 	do{
 		no=get_folder_entry(file,&fold);
 		number++;
-	}while (no!=0 && !stringcmp(name,fold.name,strlen(name)));
+	}while (no!=0 && strncasecmp(name,fold.name,len));
 	close(file);
 	
 	if (no==0) return(-1); else return(number-1);

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/ipc.c	2013-11-02 02:57:06 UTC (rev 1356)
@@ -129,7 +129,6 @@
 	if (msgtype != IPC_NOOP) {
 		char	buff[MAXTEXTLENGTH];
 		snprintf(buff, MAXTEXTLENGTH - 1, "%s",data);
-		strip_quote(buff);
 		pid_t mypid = getpid();
 		//ensure text (everything after the first 5 bytes) going into the pipes is clean utf-8 after all the truncating etc. that might have happened to it.
 		//

Deleted: trunk/src/strings.c
===================================================================
--- trunk/src/strings.c	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/strings.c	2013-11-02 02:57:06 UTC (rev 1356)
@@ -1,331 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.h>
-#include "bb.h"
-#include "strings.h"
-//#include "main.h"
-
-#define min(a,b) a<b?a:b
-#define max(a,b) a>b?a:b
-
-int stringcmp(const char *a, const char *b, int n)
-{
-	int length;
-
-	/* total match */
-	if (n==-1)
-	{
-		length=max(strlen(a),strlen(b));
-	}
-	/* first partial match */
-	else if (n==-2)
-	{
-		length=min(strlen(a),strlen(b));
-	}
-	/* match by atleast n (or shortest string) */
-	else
-	{
-		if (strlen(a)<n) return 0;
-		length=strlen(a)>strlen(b)?strlen(a):strlen(b);
-		length=n<length?n:length;
-	}
-
-	if (length==0) return 0;
-	return (!strncasecmp(a,b,length));
-}
-
-struct stacked_str *cmd_stack = NULL;
-struct stacked_str **last_cmd = &cmd_stack;
-static int stacked=0;
-
-/*static char stackedline[1024];*/
-
-void stack_str(char *string)
-{
-	stack_cmd(string, CMD_TEXT|CMD_TYPED);
-}
-
-void stack_cmd(char *string, int cmdtype)
-{
-	struct stacked_str *new;
-
-	new = malloc(sizeof(*new));
-	new->text = strdup(string);
-	new->type = cmdtype;
-	new->next = *last_cmd;
-	*last_cmd = new;
-	stacked++;
-}
-
-int is_stacked()
-{
-	return(stacked);
-}
-
-int pop_stack(char *string, int len)
-{
-	int type=0;
-	pop_cmd(string, len, &type);
-	return (type && CMD_FORCED) != 0;
-}
-
-void pop_cmd(char *string, int len, int *type)
-{
-	struct stacked_str *free_me;
-
-	if (stacked > 0)
-	{
-		stacked--;
-		strncpy(string, cmd_stack->text, len);
-		*type = cmd_stack->type;
-		free(cmd_stack->text);
-		free_me = cmd_stack;
-		cmd_stack = cmd_stack->next;
-		free(free_me);
-		if (cmd_stack == NULL) last_cmd = &cmd_stack;
-	}
-	string[len]=0;
-}
-
-void strip_str(char *string)
-{
-	char *array;
-	int i,ptr=0;
-	int len;
-	
-	len=strlen(string);
-	array=(char *)malloc(len+1);
-	for (i=0;i<len;i++)
-	{
-		if (string[i]==033 || (string[i]>=040 && string[i]<=0176) || (unsigned char)string[i]>0177)
-			array[ptr++]=string[i];
-	}
-	array[ptr]=0;
-	strcpy(string,array);
-	free(array);
-}
-
-
-
-/* common file functions */
-
-char *buildpath(const char *a, const char *b, const char *c, const char *d)
-{
-	static char fullpath[PATHSIZE];
-
-	snprintf(fullpath, PATHSIZE-1, "%s/%s%s%s",a,b,c,d);
-	return(fullpath);
-}
-
-int err_open(const char *path,int type,int mode)
-{
-	int x;
-	x=open(path,type,mode);
-	if (x<0)
-		perror(path);
-	return(x);
-}
-
-int get_rand(int min, int max)
-{
-	int r = rand();
-	float	fValue;
-
-	fValue = (float)r * (float)(max - min + 1);
-	fValue /= (float)RAND_MAX;
-	fValue += (float)min;
-
-	return ((int)fValue);
-}
-
-void string_add(char **str, const char *add)
-{
-	if (add != NULL)
-	{
-		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, "")) {
-		return(1);
-	} else {
-		int i;
-
-		for(i=0;i<strlen(in);i++)
-		{
-			if (in[i]!=' ') return(0);
-		}
-		return(1);
-	}
-}
-
-void strlower(char *szString)
-{
-	int	nLength, nIndex;
-
-	nLength = strlen(szString);
-	for (nIndex = 0; nIndex < nLength; nIndex++)
-	{
-		szString[nIndex] = tolower(szString[nIndex]);
-	}
-}
-
-/* replace ESC characters ('\033') with "[ESC]", maybe in black on white */
-static void strip_esc(char *const in, int hilite)
-{
-    static char szOutText[MAXTEXTLENGTH];
-    int         oldlen = strlen(in), nInPos, nOutPos;
-    if (oldlen >= MAXTEXTLENGTH-1) oldlen = MAXTEXTLENGTH;
-
-    for (nInPos = 0, nOutPos = 0; nInPos < oldlen && nOutPos < MAXTEXTLENGTH-1; nInPos++)
-    {
-        /* escape character found */
-        if (in[nInPos] == 033)
-        {
-            const char*const esc = "\033[7m[ESC]\033[0m";
-            const char*const noesc = "[ESC]";
-            if (hilite) {
-                /* like strncpy, but avoid writing incomplete escape sequences */
-                if (nOutPos >= (MAXTEXTLENGTH << 1) + strlen(esc)) {
-                    break; /* not enough space left */
-                }
-                strcpy(szOutText+nOutPos, esc);
-                nOutPos += strlen(esc);
-            } else {
-                strncpy(szOutText+nOutPos, noesc, MAXTEXTLENGTH-nOutPos-1);
-                nOutPos += strlen(noesc);
-            }
-        }
-        /* normal character */
-        else
-        {
-                szOutText[nOutPos++] = in[nInPos];
-        }
-    }
-    szOutText[nOutPos] = 0;
-    strcpy(in, szOutText);
-}
-
-void escprintf(const char *szFormat, ...)
-{
-	static char	szText[MAXTEXTLENGTH];
-	va_list		vaList;
-
-	/* get text to process */
-	va_start(vaList, szFormat);
-	vsnprintf(szText, MAXTEXTLENGTH-1, szFormat, vaList);
-	va_end(vaList);
-
-	/* process control characters into strings */
-	strip_esc(szText,1);
-
-	printf("%s", szText);
-}
-
-/* returns a new string without any mw colour codes in */
-char *strip_colours(const char *text)
-{
-	char *new;
-	int i, j, len, k;
-
-	len = strlen(text);
-	new = malloc(sizeof(char) * (len+1));
-	i=0;
-	j=0;
-	while (i<len)
-	{
-		if (text[i]==033)
-		{
-			i++;
-			k=0;
-			//utf8 safe way to skip the next two chars
-			//we only need this in case someone is mean enough to try using something like
-			// [ESC]r£ as a colour sequence which would previously have us remove the first 
-			// byte of the utf8 sequence leaving us with an invalid char.
-			while(i<len && k<2)
-			{
-				if(((unsigned char)text[i] & 192)==192 )
-				{
-					// skip char is the first byte of a utf8 sequence
-					i++;
-					while( ((unsigned char)text[i] & 192) == 128 && i<len)
-					{
-						//skip all utf8 continuation bytes
-						i++;
-					}
-				}
-				else
-				{
-					// char was ascii so we can just skip it.
-					i++;
-				}
-				k++;
-			}
-			
-			continue;
-		}
-		new[j++]=text[i++];
-	}
-	new[j]=0;
-	return(new);
-}
-
-/* Strip any trailing quote characters (^a) that may have been left at the end
- *  * of a buffer by snprintf() truncating a quoted string.
- *   */
-void strip_quote(char *a)
-{
-    char *end = a + strlen(a);
-
-    /* Step back through quote chars */
-    while (end > a && *(--end) == '\001')
-        *end = '\0';
-}
-
-char *quotetext(const char *a)
-{
-        int     count;
-        int     ai, bi;
-        char    *b;
-
-        ai=0;
-        count=0;
-        while(a[ai]!=0)
-        {
-                if (a[ai]=='|') count++;
-                ai++;
-        }
-
-        b = malloc(sizeof(char) * (strlen(a) + count + 1));
-
-        ai=bi=0;
-        while (a[ai]!=0)
-        {
-                if (a[ai]=='|')
-                {
-                        b[bi]=1;
-                        bi++;
-                }
-
-                b[bi]=a[ai];
-                bi++;
-                ai++;
-        }
-        b[bi]=0;
-
-        return (b);
-}
-

Deleted: trunk/src/strings.h
===================================================================
--- trunk/src/strings.h	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/strings.h	2013-11-02 02:57:06 UTC (rev 1356)
@@ -1,38 +0,0 @@
-#ifndef STRINGS_H
-#define STRINGS_H
-
-#define CMD_TEXT	0	/* Interpreted depending on mode/prefix      */
-#define CMD_BOARD	1	/* Always a board command, used by BOARDEXEC */
-#define CMD_TALKER	2	/* Always a talker command, used by EXEC     */
-#define CMD_TYPED	0	/* Was entered at the keyboard               */
-#define CMD_FORCED	0x100	/* Forced by another user                    */
-
-struct stacked_str {
-	char *text;
-	int type;
-	struct stacked_str *next;
-};
-
-void stack_cmd(char *string, int type);
-void stack_str(char *string);
-int is_stacked(void);
-void pop_cmd(char *string, int len, int *type);
-int pop_stack(char *string, int len);
-int get_rand(int min, int max);
-void string_add(char **str, const char *add);
-int allspace(char *s);
-void strlower(char *szString);
-int stringcmp(const char *a, const char *b, int n);
-
-void escprintf(const char *szFormat, ...) __attribute__((format(printf,1,2)));
-char *strip_colours(const char *text);
-void strip_str(char *string);
-void strip_quote(char *a);
-char *quotetext(const char *a);
-
-char *buildpath(const char *a, const char *b, const char *c, const char *d);
-#define makepath(a,b,c) (buildpath(HOMEPATH,a,b,c))
-
-int err_open(const char *path,int type,int mode);
-
-#endif /* STRINGS_H */

Modified: trunk/src/webclient/import.c
===================================================================
--- trunk/src/webclient/import.c	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/webclient/import.c	2013-11-02 02:57:06 UTC (rev 1356)
@@ -176,7 +176,7 @@
         if (access(USERFILE,00)) return(false);
         file=userdb_open(O_RDONLY);
         while (!found && get_person(file,usr))
-                if (stringcmp(usr->name,name,-1) && !u_del(usr->status))
+                if (!strncasecmp(usr->name,name,strlen(name)) && !u_del(usr->status))
                         found=true;
         if (found)
                 *userposn=lseek(file,0,1)-sizeof(struct person);

Modified: trunk/src/webclient/import.h
===================================================================
--- trunk/src/webclient/import.h	2013-11-02 01:10:49 UTC (rev 1355)
+++ trunk/src/webclient/import.h	2013-11-02 02:57:06 UTC (rev 1356)
@@ -9,7 +9,6 @@
 int32_t get_who_userposn(int pid);
 void fetch_user(struct person *record, int32_t userposn);
 char *quotetext(const char *a);
-void strip_quote(char *a);
 void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason);
 void show_chatmodes(unsigned long cm, char *tmp, int flag);
 void show_chatprivs(unsigned long cp, char *tmp, int flag);




More information about the mw-devel mailing list