introducing abstract types to mc



Hi,

I'd like to introduce more abstract types into mc. That is, to separate cleanly which files (or functions) _use_ a data type and which ones _implement_ the basic operation on variables of this type.

As an example I have picked the type FileOpContext. There are only four files that need the internals of the type. The others only use variables of the type FileOpContext *.

Using this approach we can quickly tell which functions operate directly on the type. Keeping the number of these functions minimal we have better control of keeping the internal state of these types valid. For example, an abstract type may have some constructors and one destructor. As most files cannot access the internal fields of the type, they must use a constructor to create a variable of that type. The constructor can ensure that all fields get reasonable values. And in case of a modification of the type, the number of functions you must look after is kept minimal.

So far for now ...

Roland
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/mc/mc/src/Makefile.am,v
retrieving revision 1.37
diff -u -r1.37 Makefile.am
--- src/Makefile.am	2 Sep 2004 15:03:48 -0000	1.37
+++ src/Makefile.am	24 Sep 2004 19:19:25 -0000
@@ -47,7 +47,8 @@
 	command.c command.h complete.c complete.h cons.handler.c	\
 	cons.saver.h dialog.c dialog.h dir.c dir.h			\
 	eregex.h execute.c execute.h ext.c ext.h file.c filegui.c	\
-	filegui.h file.h filenot.c fileopctx.c fileopctx.h find.c	\
+	filegui.h file.h filenot.c					\
+	fileopctx.c fileopctx.h fileopctx-impl.h find.c			\
 	find.h findme.c	findme.h fs.h					\
 	glibcompat.c glibcompat.h global.h help.c help.h hotlist.c	\
 	hotlist.h info.c info.h key.c key.h keyxdef.c layout.c		\
Index: src/background.c
===================================================================
RCS file: /cvsroot/mc/mc/src/background.c,v
retrieving revision 1.39
diff -u -r1.39 background.c
--- src/background.c	19 Sep 2004 15:55:59 -0000	1.39
+++ src/background.c	24 Sep 2004 19:19:25 -0000
@@ -42,6 +42,7 @@
 #include "dialog.h"	/* do_refresh() */
 #include "wtools.h"
 #include "fileopctx.h"	/* FileOpContext */
+#include "fileopctx-impl.h"
 #include "key.h"	/* add_select_channel(), delete_select_channel() */
 
 enum ReturnType {
Index: src/background.h
===================================================================
RCS file: /cvsroot/mc/mc/src/background.h,v
retrieving revision 1.13
diff -u -r1.13 background.h
--- src/background.h	26 Oct 2003 05:42:29 -0000	1.13
+++ src/background.h	24 Sep 2004 19:19:25 -0000
@@ -3,6 +3,8 @@
 
 #ifdef WITH_BACKGROUND
 
+#include "fileopctx.h"
+
 enum TaskState {
     Task_Running,
     Task_Stopped
@@ -18,7 +20,6 @@
 
 extern struct TaskList *task_list;
 
-struct FileOpContext;
 int do_background (struct FileOpContext *ctx, char *info);
 int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...);
 char *parent_call_string (void *routine, int argc, ...);
Index: src/file.c
===================================================================
RCS file: /cvsroot/mc/mc/src/file.c,v
retrieving revision 1.127
diff -u -r1.127 file.c
--- src/file.c	24 Sep 2004 18:14:49 -0000	1.127
+++ src/file.c	24 Sep 2004 19:19:25 -0000
@@ -74,6 +74,8 @@
 #include "filegui.h"
 #include "tree.h"
 #include "key.h"
+#include "fileopctx.h"
+#include "fileopctx-impl.h"
 #include "../vfs/vfs-impl.h"
 
 /* }}} */
Index: src/filegui.c
===================================================================
RCS file: /cvsroot/mc/mc/src/filegui.c,v
retrieving revision 1.53
diff -u -r1.53 filegui.c
--- src/filegui.c	21 Sep 2004 12:40:50 -0000	1.53
+++ src/filegui.c	24 Sep 2004 19:19:25 -0000
@@ -66,6 +66,7 @@
 #include "wtools.h"		/* QuickDialog */
 #include "panel.h"		/* current_panel */
 #include "fileopctx.h"		/* FILE_CONT */
+#include "fileopctx-impl.h"
 #include "filegui.h"
 #include "key.h"		/* get_event */
 
Index: src/fileopctx.c
===================================================================
RCS file: /cvsroot/mc/mc/src/fileopctx.c,v
retrieving revision 1.9
diff -u -r1.9 fileopctx.c
--- src/fileopctx.c	23 Jan 2004 21:59:38 -0000	1.9
+++ src/fileopctx.c	24 Sep 2004 19:19:25 -0000
@@ -25,6 +25,7 @@
 
 #include "global.h"
 #include "fileopctx.h"
+#include "fileopctx-impl.h"
 
 
 /**
Index: src/fileopctx.h
===================================================================
RCS file: /cvsroot/mc/mc/src/fileopctx.h,v
retrieving revision 1.13
diff -u -r1.13 fileopctx.h
--- src/fileopctx.h	29 Aug 2004 22:51:54 -0000	1.13
+++ src/fileopctx.h	24 Sep 2004 19:19:25 -0000
@@ -11,7 +11,6 @@
 
 #include <sys/stat.h>
 #include <sys/types.h>
-#include "eregex.h"
 
 typedef enum {
 	OP_COPY,
@@ -24,92 +23,7 @@
 /* This structure describes a context for file operations.  It is used to update
  * the progress windows and pass around options.
  */
-typedef struct FileOpContext {
-	/* Operation type (copy, move, delete) */
-	FileOperation operation;
-
-	/* The estimated time of arrival in seconds */
-	double eta_secs;
-
-	/* Transferred bytes per second */
-	long bps;
-
-	/* Transferred seconds */
-	long bps_time;
-
-	/* Whether the panel total has been computed */
-	int progress_totals_computed;
-
-	/* Counters for progress indicators */
-	off_t progress_count;
-	double progress_bytes;
-
-	/* The value of the "preserve Attributes" checkbox in the copy file dialog.
-	 * We can't use the value of "ctx->preserve" because it can change in order
-	 * to preserve file attributs when moving files across filesystem boundaries
-	 * (we want to keep the value of the checkbox between copy operations).
-	 */
-	int op_preserve;
-
-	/* Result from the recursive query */
-	int recursive_result;
-
-	/* Whether to do a reget */
-	int do_reget;
-
-	/* Controls appending to files */
-	int do_append;
-
-	/* Whether to stat or lstat */
-	int follow_links;
-
-	/* Pointer to the stat function we will use */
-	mc_stat_fn stat_func;
-
-	/* Whether to recompute symlinks */
-	int stable_symlinks;
-
-	/* Preserve the original files' owner, group, permissions, and
-	 * timestamps (owner, group only as root).
-	 */
-	int preserve;
-
-	/* If running as root, preserve the original uid/gid (we don't want to
-	 * try chown for non root) preserve_uidgid = preserve && uid == 0
-	 */
-	int preserve_uidgid;
-
-	/* The bits to preserve in created files' modes on file copy */
-	int umask_kill;
-
-	/* The mask of files to actually operate on */
-	char *dest_mask;
-
-	/* Regex for the file mask */
-	struct re_pattern_buffer rx;
-	struct re_registers regs;
-
-	/* Whether to dive into subdirectories for recursive operations */
-	int dive_into_subdirs;
-
-	/* When moving directories cross filesystem boundaries delete the
-	 * successfully copied files when all files below the directory and its
-	 * subdirectories were processed.
-	 *
-	 * If erase_at_end is zero files will be deleted immediately after their
-	 * successful copy (Note: this behavior is not tested and at the moment
-	 * it can't be changed at runtime).
-	 */
-	int erase_at_end;
-
-	/* PID of the child for background operations */
-	pid_t pid;
-
-	/* User interface data goes here */
-
-	void *ui;
-} FileOpContext;
-
+typedef struct FileOpContext FileOpContext;
 
 FileOpContext *file_op_context_new (FileOperation op);
 void file_op_context_destroy (FileOpContext *ctx);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]