[mw-devel] MW3 r895 - branches/portable/src

pwb at sucs.org pwb at sucs.org
Fri Jul 28 23:51:19 BST 2006


Author: pwb
Date: 2006-07-28 23:51:07 +0100 (Fri, 28 Jul 2006)
New Revision: 895

Modified:
   branches/portable/src/add.c
   branches/portable/src/edit.c
   branches/portable/src/files.c
   branches/portable/src/files.h
   branches/portable/src/iconv.c
   branches/portable/src/main.c
   branches/portable/src/proto.h
   branches/portable/src/script_inst.c
   branches/portable/src/talker.c
   branches/portable/src/user.c
   branches/portable/src/who.c
Log:
- imported improved iconv.[ch] from newipc branch
- fixed bugs on x86-64 caused by pid_t and long each being 64 bit (the former already fixed in newipc). .sayto now works again.


Modified: branches/portable/src/add.c
===================================================================
--- branches/portable/src/add.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/add.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -30,7 +30,7 @@
 	char *buff;
 	char answer[10];
 	char c; /* temporary storage of a character */
-	long up; /*temp*/
+	int32_t up; /*temp*/
 	struct person usr; /*temp*/
 	long tt,td; /* for calculating position error in index file */
 

Modified: branches/portable/src/edit.c
===================================================================
--- branches/portable/src/edit.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/edit.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -32,7 +32,7 @@
 
 void edit_user(char *args, char *name)
 {
-	long usrposn;
+	int32_t usrposn;
 	struct person usr;
 
 	if (!is_old(&usr,name,&usrposn))
@@ -290,7 +290,7 @@
 		{
 			char answer[10];
 			struct person uu;
-			long uup;
+			int32_t uup;
 
 			if (is_old(&uu,username,&uup))
 			{

Modified: branches/portable/src/files.c
===================================================================
--- branches/portable/src/files.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/files.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -24,7 +24,7 @@
 	return(x);
 }
 
-int is_old(struct person *usr, char *name, long *userposn)
+int is_old(struct person *usr, char *name, int32_t *userposn)
 {
 	int file,found=FALSE;
 
@@ -39,7 +39,7 @@
 	return(found);
 }
 
-void write_usr(struct person *record, long *userposn)
+void write_usr(struct person *record, int32_t *userposn)
 {
 	int outfile;
 	
@@ -64,7 +64,7 @@
 	return(x);
 }
 
-void who_add(int pid, long posn)
+void who_add(int pid, int32_t posn)
 {
 	struct who rec;
 	int wfile;
@@ -76,7 +76,7 @@
 	{
 		if(rec.pid<0)
 		{
-			lseek(wfile,(long)-sizeof(rec),1);
+			lseek(wfile,-sizeof(rec),1);
 			break;
 		}
 	}

Modified: branches/portable/src/files.h
===================================================================
--- branches/portable/src/files.h	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/files.h	2006-07-28 22:51:07 UTC (rev 895)
@@ -11,10 +11,10 @@
 int openfolderfile(int mode);
 int nofolders(void);
 int openuserfile(int mode);
-int is_old(struct person *usr, char *name, long *userposn);
-void write_usr(struct person *record, long *userposn);
+int is_old(struct person *usr, char *name, int32_t *userposn);
+void write_usr(struct person *record, int32_t *userposn);
 int openwhofile(int mode);
-void who_add(int pid, long posn);
+void who_add(int pid, int32_t posn);
 void create_folder_file(void);
 int foldernumber(char *name);
 int get_folder_entry(int file, struct folder *tmp);

Modified: branches/portable/src/iconv.c
===================================================================
--- branches/portable/src/iconv.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/iconv.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -18,13 +18,14 @@
 
 /* convert string in given encoding to wide string */
 wchar_t *
-any2wcs(char * s, char * charset)
+any2wcs(char * s, char * charset, int report_error)
 {
     char * local, * localcpy;
     char * wcs; /* needs to be char * for passing to iconv */
     wchar_t * wcscpy; /* the string as itself */
     size_t localbytesleft, wcsbytesleft;
     iconv_t conv;
+    int errors = 0;
 
     if (!charset || !*charset) {
 	fprintf(stderr, "any2wcs: No source character set specified!\n");
@@ -58,6 +59,7 @@
 		local++;
 		localbytesleft--;
 		errno = 0;
+		errors++;
 		continue;
 	    } else {
 		/* some other error, recover what we can */
@@ -71,18 +73,21 @@
 
     iconv_close(conv);
     free(localcpy);
+    if (report_error && errors>0)
+	printf("warning: iconv found %d invalid bytes, discarding them\n", errors);
     return wcscpy;
 }
 
 /* convert wide string to string in given encoding */
 char *
-wcs2any(wchar_t * ws, char * charset)
+wcs2any(wchar_t * ws, char * charset, int report_error)
 {
     char * wcs; /* needs to be char * for passing to iconv */
     wchar_t * wcscpy; /* the string as itself */
     char * local, * localcpy;
     size_t localbytesleft, wcsbytesleft;
     iconv_t conv;
+    int errors = 0;
 
     if (!charset || !*charset) {
 	fprintf(stderr, "No target character set specified!\n");
@@ -111,10 +116,11 @@
 	if (nconv == (size_t)-1) {
 	    /* iconv barfed, but why? */
 	    if (errno == EILSEQ || errno == EINVAL) {
-		/* invalid input sequence, skip it */
-		(wchar_t *)wcs++;
+		/* invalid or unconvertible input sequence, skip it */
+		wcs+=sizeof(wchar_t);
 		wcsbytesleft-=sizeof(wchar_t);
 		errno = 0;
+		errors++;
 		continue;
 	    } else {
 		/* some other error, recover what we can */
@@ -128,35 +134,37 @@
 
     iconv_close(conv);
     free(wcscpy);
+    if (report_error && errors>0)
+	printf("warning: iconv found %d invalid bytes, discarding them\n", errors);
     return localcpy;
 }
 
 /* convert string in local encoding to wide string */
 wchar_t *
-local2wcs(char * s)
+local2wcs(char * s, int report_error)
 {
-    return any2wcs(s, local_charset);
+    return any2wcs(s, local_charset, report_error);
 }
 
 /* convert wide string to local encoding */
 char *
-wcs2local(wchar_t * ws)
+wcs2local(wchar_t * ws, int report_error)
 {
-    return wcs2any(ws, local_charset);
+    return wcs2any(ws, local_charset, report_error);
 }
 
 /* convert UTF-8 encoded string to wide string */
 wchar_t *
-utf82wcs(char * s)
+utf82wcs(char * s, int report_error)
 {
-    return any2wcs(s, "UTF-8");
+    return any2wcs(s, "UTF-8", report_error);
 }
 
 /* convert wide string to UTF-8 encoded string */
 char *
-wcs2utf8(wchar_t * ws)
+wcs2utf8(wchar_t * ws, int report_error)
 {
-    return wcs2any(ws, "UTF-8");
+    return wcs2any(ws, "UTF-8", report_error);
 }
 
 /* set local charset independently of locale */
@@ -273,13 +281,13 @@
     in = readline("Enter something to convert: ");
     set_local_charset(argv[1]);
 
-    mid = local2wcs(in);
+    mid = local2wcs(in, 1);
     printf("Converted to wchar_t as %ls\n", mid);
 
     free(readline("Change terminal locale and press enter to continue"));
 
     set_local_charset(argv[2]);
-    out = wcs2local(mid);
+    out = wcs2local(mid, 1);
     printf("Converted to target charset as %s\n", out);
 
     return 0;

Modified: branches/portable/src/main.c
===================================================================
--- branches/portable/src/main.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/main.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -96,7 +96,7 @@
 
 struct person *user = NULL;
 struct folder *fold = NULL;
-long userposn;
+int32_t userposn;
 unsigned long loggedin; /* what time did they login */
 unsigned long rights=(unsigned long)0;
 unsigned long forced;
@@ -468,7 +468,7 @@
 	/* display all new messages for given user */
 	if (msguser_num>-1 && getuid()==geteuid())
 	{
-		long tmp;
+		int32_t tmp;
 		if (!is_old(user,argv[msguser_num],&tmp))
 		{
 			fprintf(stderr,_("%s: User %s not found.\n"),argv[0],argv[msguser_num]);
@@ -485,7 +485,7 @@
 	/* jump straight to add_mesg() */
 	if (foldername_num>-1 && getuid()==geteuid())
 	{
-		long tmp;
+		int32_t tmp;
 		currentfolder=foldernumber(argv[foldername_num]);
 		if (currentfolder==-1)
 		{

Modified: branches/portable/src/proto.h
===================================================================
--- branches/portable/src/proto.h	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/proto.h	2006-07-28 22:51:07 UTC (rev 895)
@@ -8,14 +8,14 @@
 /* Assume bb.h was included first */
 #include <stdio.h> /* for FILE */
 /* user.c */
-void update_user(struct person *record, long userposn);
-void fetch_user(struct person *record, long userposn);
-void login_ok(struct person *usr, long *userposn, int *autochat);
+void update_user(struct person *record, int32_t userposn);
+void fetch_user(struct person *record, int32_t userposn);
+void login_ok(struct person *usr, int32_t *userposn, int *autochat);
 void get_login(char *name, int autochat);
 void strip_name(char *string);
 int get_person(int file, struct person *tmp);
 int old_usr(struct person *usr);
-int new_usr(struct person *usr, char *name, long *userposn);
+int new_usr(struct person *usr, char *name, int32_t *userposn);
 void set_defaults(struct person *tmp);
 void pick_salt(char *salt);
 void list_users(int newonly);
@@ -158,10 +158,10 @@
 int openfolderfile(int mode);
 int nofolders(void);
 int openuserfile(int mode);
-int is_old(struct person *usr, char *name, long *userposn);
-void write_usr(struct person *record, long *userposn);
+int is_old(struct person *usr, char *name, int32_t *userposn);
+void write_usr(struct person *record, int32_t *userposn);
 int openwhofile(int mode);
-void who_add(int pid, long posn);
+void who_add(int pid, int32_t posn);
 void create_folder_file(void);
 int foldernumber(char *name);
 int get_folder_entry(int file, struct folder *tmp);
@@ -222,9 +222,9 @@
 void who_list(void);
 int get_user_pid(char *name);
 int get_pid(char *name);
-void check_copies(long where);
+void check_copies(int32_t where);
 char *itime(unsigned long t);
-long get_who_userposn(int pid);
+int32_t get_who_userposn(int pid);
 /* newmain.c */
 void filed_help(char *topic);
 /* talker.c */

Modified: branches/portable/src/script_inst.c
===================================================================
--- branches/portable/src/script_inst.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/script_inst.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -775,7 +775,7 @@
 		/* ignore one user */
 		else
 		{
-			long		tempposn; 
+			int32_t		tempposn; 
 			struct person	tempusr;
 
 			if (!is_old(&tempusr,what, &tempposn))

Modified: branches/portable/src/talker.c
===================================================================
--- branches/portable/src/talker.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/talker.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -49,7 +49,7 @@
 
 extern struct person *user;
 extern struct folder *fold;
-extern long userposn;
+extern int32_t userposn;
 extern unsigned long loggedin; 
 extern int quietmode;
 extern int runautoexec;
@@ -827,7 +827,7 @@
 void t_ungag(CommandList *cm, int argc, char **argv, char *args)
 {
 	char text[MAXTEXTLENGTH];
-	long gpos;
+	int32_t gpos;
 	struct person gusr;
 
 	if (!is_old(&gusr,argv[1],&gpos))
@@ -886,7 +886,7 @@
 {
 	char			text[MAXTEXTLENGTH];
 	struct IgnoreList	*newnode;
-	long			tempposn;
+	int32_t			tempposn;
 	struct person		tempusr;
 	char			*namebuff[MAX_ARGC];
 	int			namecount;

Modified: branches/portable/src/user.c
===================================================================
--- branches/portable/src/user.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/user.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -32,7 +32,7 @@
 		return("");
 }
 
-void update_user(struct person *record, long userposn)
+void update_user(struct person *record, int32_t userposn)
 {
 	int outfile;
 	
@@ -44,7 +44,7 @@
 	close(outfile);
 }
 
-void fetch_user(struct person *record, long userposn)
+void fetch_user(struct person *record, int32_t userposn)
 {
 	int outfile;
 	
@@ -54,7 +54,7 @@
 	close(outfile);
 }
 
-void login_ok(struct person *usr, long *userposn, int *autochat)
+void login_ok(struct person *usr, int32_t *userposn, int *autochat)
 {	
 	/* main function */
 	char name[NAMESIZE+1];
@@ -186,7 +186,7 @@
 	return(TRUE);
 }
 
-int new_usr(struct person *usr, char *name, long *userposn)
+int new_usr(struct person *usr, char *name, int32_t *userposn)
 {
 	char passwd[PASSWDSIZE],passwd2[PASSWDSIZE],salt[3];
 	char c[10];

Modified: branches/portable/src/who.c
===================================================================
--- branches/portable/src/who.c	2006-07-20 17:27:38 UTC (rev 894)
+++ branches/portable/src/who.c	2006-07-28 22:51:07 UTC (rev 895)
@@ -298,7 +298,7 @@
 	return(found);
 }
 
-long get_who_userposn(int pid)
+int32_t get_who_userposn(int pid)
 {
 	struct who w;
 	int wfile;
@@ -374,7 +374,7 @@
 
 #endif
 
-void check_copies(long where)
+void check_copies(int32_t where)
 {
 	struct who u;
 	int file;




More information about the mw-devel mailing list