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

welshbyte at sucs.org welshbyte at sucs.org
Fri Nov 1 22:41:18 GMT 2013


Author: welshbyte
Date: 2013-11-01 22:41:18 +0000 (Fri, 01 Nov 2013)
New Revision: 1351

Added:
   trunk/src/folders.c
Removed:
   trunk/src/files.c
Modified:
   trunk/src/client/add.c
   trunk/src/client/edit.c
   trunk/src/client/newmain.c
   trunk/src/client/read.h
   trunk/src/client/user.c
   trunk/src/files.h
   trunk/src/folders.h
   trunk/src/webclient/import.h
Log:
More rejigging:
- Move Lock_File and Unlock_File to files.h and static inline them
- Move the folder functions out of files.c and into folders.c
- Remove files.c
- Tidy up some includes


Modified: trunk/src/client/add.c
===================================================================
--- trunk/src/client/add.c	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/client/add.c	2013-11-01 22:41:18 UTC (rev 1351)
@@ -26,6 +26,7 @@
 #include "talker.h"
 #include "bb.h"
 #include "userio.h"
+#include "mesg.h"
 
 extern int eof_caught;
 extern int remote;

Modified: trunk/src/client/edit.c
===================================================================
--- trunk/src/client/edit.c	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/client/edit.c	2013-11-01 22:41:18 UTC (rev 1351)
@@ -31,6 +31,7 @@
 #include "bb.h"
 #include "userio.h"
 #include "who.h"
+#include "mesg.h"
 
 const char *partlist_user[]={
 "edit", "status", "special", "groups", "passwd", "chatprivs", "chatmode",

Modified: trunk/src/client/newmain.c
===================================================================
--- trunk/src/client/newmain.c	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/client/newmain.c	2013-11-01 22:41:18 UTC (rev 1351)
@@ -11,6 +11,7 @@
 #include <stdbool.h>
 #include <locale.h>
 
+#include "folders.h"
 #include "iconv.h"
 #include "strings.h"
 #include "main.h"
@@ -34,6 +35,7 @@
 #include "bb.h"
 #include "alias.h"
 #include "userio.h"
+#include "mesg.h"
 
 extern Alias alias_list;
 

Modified: trunk/src/client/read.h
===================================================================
--- trunk/src/client/read.h	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/client/read.h	2013-11-01 22:41:18 UTC (rev 1351)
@@ -1,8 +1,8 @@
 #ifndef READ_H
 #define READ_H
 
-#include "folders.h"
-#include "mesg.h"
+#include <folders.h>
+#include <mesg.h>
 
 int get_mesg_header(struct folder *data, int msgnum, struct Header *head);
 int get_data(int afile, struct Header *tmp);

Modified: trunk/src/client/user.c
===================================================================
--- trunk/src/client/user.c	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/client/user.c	2013-11-01 22:41:18 UTC (rev 1351)
@@ -26,6 +26,7 @@
 #include "intl.h"
 #include "userio.h"
 #include "user.h"
+#include "mesg.h"
 
 const char *partlist_search[]={
 "status", "special", "groups", "chatprivs", "chatmode", "protpower",

Deleted: trunk/src/files.c
===================================================================
--- trunk/src/files.c	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/files.c	2013-11-01 22:41:18 UTC (rev 1351)
@@ -1,129 +0,0 @@
-/* files.c
- * Operations on the shared files of MW3: who.bb, user.bb, folders.bb
- */
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <string.h>
-#include <errno.h>
-#include "strings.h"
-#include "files.h"
-#include "ipc.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");
-	}
-}
-
-int openfolderfile(int mode)
-{
-	int x;
-	x=open(FOLDERFILE,mode);
-	if (x<0)
-	{
-		perror("Open Folder File");
-	}
-	return(x);
-}
-		
-int nofolders(void)
-{
-	int fd;
-	struct folder fol;
-
-	fd = open(FOLDERFILE, O_RDONLY);
-	if (fd < 0) return 1;
-
-	if (read(fd,&fol,sizeof(struct folder)) < sizeof(struct folder))
-	{
-		close(fd);
-		return 1;
-	}
-
-	close(fd);
-	return 0;
-}
-
-void create_folder_file(void)
-{
-	int file,i;
-	struct folder *record;
-	
-	record=(struct folder *)malloc(sizeof(*record));
-	record->status=0;
-	file=open(FOLDERFILE,O_WRONLY|O_CREAT,0600);
-	Lock_File(file);
-	for (i=0;i<64;i++) 
-		if (write(file,record,sizeof(*record))<0)
-		{
-			perror("creating blank folders");
-			exit(-1);
-		}
-	Unlock_File(file);
-	close(file);
-	free(record);
-}
-
-int foldernumber(const char *name)
-{
-	/* return number of folder name */
-	int file;
-	int number=0;
-	int no;
-	struct folder fold;
-	
-	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)));
-	close(file);
-	
-	if (no==0) return(-1); else return(number-1);
-}
-
-int get_folder_entry(int file, struct folder *tmp)
-{
-	int no;
-	if ((no=read(file,tmp,sizeof(*tmp)))<0)
-	{
-		perror("get_folder_entry");
-		exit(-1);
-	}
-	return(no);
-}
-
-int get_folder_number(struct folder *fol, int num)
-{
-	int file;
-
-	if (nofolders())
-		{printf("There are no folders !\n");return 0;}
-	if ((file=openfolderfile(O_RDONLY)) < 0) return 0;
-	lseek(file,sizeof(*fol)*num,0);
-	if (read(file,fol,sizeof(*fol))<0)
-	{
-		perror("get_folder_number");
-		return 0;
-	}
-	close(file);
-	return 1;
-}

Modified: trunk/src/files.h
===================================================================
--- trunk/src/files.h	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/files.h	2013-11-01 22:41:18 UTC (rev 1351)
@@ -1,18 +1,25 @@
 #ifndef FILES_H
 #define FILES_H
 
-#include "folders.h"
-#include "user.h"
+#include <sys/file.h>
+#include <errno.h>
+#include <stdio.h>
 
-#define FOLDERFILE  STATEDIR"/folders.bb"
+static inline void Lock_File(int f)
+{
+	errno=0;
+	do{
+		if (flock(f,LOCK_EX))
+			perror("Locking");
+	}while (errno==EINTR);
+}
 
-void Lock_File(int f);
-void Unlock_File(int f);
-int openfolderfile(int mode);
-int nofolders(void);
-void create_folder_file(void);
-int foldernumber(const char *name);
-int get_folder_entry(int file, struct folder *tmp);
-int get_folder_number(struct folder *fol, int num);
+static inline void Unlock_File(int f)
+{
+	if (flock(f,LOCK_UN))
+	{
+		perror("Unlocking");
+	}
+}
 
 #endif

Copied: trunk/src/folders.c (from rev 1350, trunk/src/files.c)
===================================================================
--- trunk/src/folders.c	                        (rev 0)
+++ trunk/src/folders.c	2013-11-01 22:41:18 UTC (rev 1351)
@@ -0,0 +1,104 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "strings.h"
+#include "folders.h"
+#include "files.h"
+
+int openfolderfile(int mode)
+{
+	int x;
+	x=open(FOLDERFILE,mode);
+	if (x<0)
+	{
+		perror("Open Folder File");
+	}
+	return(x);
+}
+
+int nofolders(void)
+{
+	int fd;
+	struct folder fol;
+
+	fd = open(FOLDERFILE, O_RDONLY);
+	if (fd < 0) return 1;
+
+	if (read(fd,&fol,sizeof(struct folder)) < sizeof(struct folder))
+	{
+		close(fd);
+		return 1;
+	}
+
+	close(fd);
+	return 0;
+}
+
+void create_folder_file(void)
+{
+	int file,i;
+	struct folder *record;
+	
+	record=(struct folder *)malloc(sizeof(*record));
+	record->status=0;
+	file=open(FOLDERFILE,O_WRONLY|O_CREAT,0600);
+	Lock_File(file);
+	for (i=0;i<64;i++) 
+		if (write(file,record,sizeof(*record))<0)
+		{
+			perror("creating blank folders");
+			exit(-1);
+		}
+	Unlock_File(file);
+	close(file);
+	free(record);
+}
+
+int foldernumber(const char *name)
+{
+	/* return number of folder name */
+	int file;
+	int number=0;
+	int no;
+	struct folder fold;
+	
+	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)));
+	close(file);
+	
+	if (no==0) return(-1); else return(number-1);
+}
+
+int get_folder_entry(int file, struct folder *tmp)
+{
+	int no;
+	if ((no=read(file,tmp,sizeof(*tmp)))<0)
+	{
+		perror("get_folder_entry");
+		exit(-1);
+	}
+	return(no);
+}
+
+int get_folder_number(struct folder *fol, int num)
+{
+	int file;
+
+	if (nofolders())
+		{printf("There are no folders !\n");return 0;}
+	if ((file=openfolderfile(O_RDONLY)) < 0) return 0;
+	lseek(file,sizeof(*fol)*num,0);
+	if (read(file,fol,sizeof(*fol))<0)
+	{
+		perror("get_folder_number");
+		return 0;
+	}
+	close(file);
+	return 1;
+}

Modified: trunk/src/folders.h
===================================================================
--- trunk/src/folders.h	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/folders.h	2013-11-01 22:41:18 UTC (rev 1351)
@@ -3,6 +3,7 @@
 
 #include <stdint.h>
 
+#define FOLDERFILE  STATEDIR"/folders.bb"
 #define FOLNAMESIZE 	10	/* length of folder names */
 #define TOPICSIZE 	30	/* length of the topic of the folder */
 
@@ -30,4 +31,11 @@
 7	-
 */
 
+int openfolderfile(int mode);
+int nofolders(void);
+void create_folder_file(void);
+int foldernumber(const char *name);
+int get_folder_entry(int file, struct folder *tmp);
+int get_folder_number(struct folder *fol, int num);
+
 #endif /* FOLDERS_H */

Modified: trunk/src/webclient/import.h
===================================================================
--- trunk/src/webclient/import.h	2013-11-01 22:09:51 UTC (rev 1350)
+++ trunk/src/webclient/import.h	2013-11-01 22:41:18 UTC (rev 1351)
@@ -1,4 +1,8 @@
-/* import.c */
+#ifndef IMPORT_H
+#define IMPORT_H
+
+#include <user.h>
+
 int get_person(int file, struct person *tmp);
 void update_user(struct person *record, int32_t userposn);
 unsigned long cm_flags(unsigned long cm, unsigned long flags, int mode);
@@ -12,3 +16,5 @@
 char *remove_first_word(char *args) ;
 void talk_send_to_room(const char *text, int channel, const char *type, int plural);
 int is_old(struct person *usr, const char *name, int32_t *userposn);
+
+#endif /* IMPORT_H */




More information about the mw-devel mailing list