Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] (PR#2483) Cleanup from* functions in common/*
Home

[Freeciv-Dev] (PR#2483) Cleanup from* functions in common/*

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2483) Cleanup from* functions in common/*
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 3 Dec 2002 07:55:05 -0800
Reply-to: rt@xxxxxxxxxxxxxx


The attached patch does:
 - s/fromFile/from_file/ and s/fromFP/from_stream/. The old version
 violates the style guide.
 - s/FILE */fz_FILE */. Basically we don't want to use
 FILE. Internally in inputfile we use fz_FILE anyway.
 - unify inf_from_file with inf_from_stream (The same should be done
 to fz_from_file and fz_from_stream but this is not so easy/nice).

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Last year, out in California, at a PC users group, there was a demo of
  smart speech recognition software. Before the demonstrator could begin
  his demo, a voice called out from the audience: "Format c, return. Yes,
  return." Damned short demo, it was.

Index: common/inputfile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/inputfile.c,v
retrieving revision 1.29
diff -u -r1.29 inputfile.c
--- common/inputfile.c  2002/11/30 18:39:24     1.29
+++ common/inputfile.c  2002/12/03 15:39:26
@@ -215,25 +215,21 @@
   Open the file, and return an allocated, initialized structure.
   Returns NULL if the file could not be opened.
 ***********************************************************************/
-struct inputfile *inf_fromFile(const char *filename, datafilename_fn_t datafn)
+struct inputfile *inf_from_file(const char *filename,
+                               datafilename_fn_t datafn)
 {
   struct inputfile *inf;
   fz_FILE *fp;
 
   assert(filename != NULL);
-  assert(strlen(filename)>0);
-  fp = fz_fromFile(filename, "r", FZ_NOT_USED, FZ_NOT_USED);
+  assert(strlen(filename) > 0);
+  fp = fz_from_file(filename, "r", FZ_NOT_USED, FZ_NOT_USED);
   if (!fp) {
     return NULL;
   }
-  inf = (struct inputfile *)fc_malloc(sizeof(struct inputfile));
-  init_zeros(inf);
-  
-  inf->filename = mystrdup(filename);
-  inf->fp = fp;
-  inf->datafn = datafn;
-
   freelog(LOG_DEBUG, "inputfile: opened \"%s\" ok", filename);
+  inf = inf_from_stream(fp, datafn);
+  inf->filename = mystrdup(filename);
   return inf;
 }
 
@@ -241,21 +237,16 @@
   Open the stream, and return an allocated, initialized structure.
   Returns NULL if the file could not be opened.
 ***********************************************************************/
-struct inputfile *inf_fromFP(FILE *stream, datafilename_fn_t datafn)
+struct inputfile *inf_from_stream(fz_FILE * stream, datafilename_fn_t datafn)
 {
   struct inputfile *inf;
-  fz_FILE *fp;
 
   assert(stream != NULL);
-  fp = fz_fromFP(stream);
-  if (!fp) {
-    return NULL;
-  }
-  inf = (struct inputfile *)fc_malloc(sizeof(struct inputfile));
+  inf = fc_malloc(sizeof(*inf));
   init_zeros(inf);
   
   inf->filename = NULL;
-  inf->fp = fp;
+  inf->fp = stream;
   inf->datafn = datafn;
 
   freelog(LOG_DEBUG, "inputfile: opened \"%s\" ok", inf_filename(inf));
@@ -420,7 +411,7 @@
     } while((inc=inc->included_from));
   }
   
-  new_inf = inf_fromFile(full_name, inf->datafn);
+  new_inf = inf_from_file(full_name, inf->datafn);
 
   /* Swap things around so that memory pointed to by inf (user pointer,
      and pointer in calling functions) contains the new inputfile,
Index: common/inputfile.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/inputfile.h,v
retrieving revision 1.8
diff -u -r1.8 inputfile.h
--- common/inputfile.h  2002/12/02 18:08:16     1.8
+++ common/inputfile.h  2002/12/03 15:39:27
@@ -19,8 +19,7 @@
 #ifndef FC__INPUTFILE_H
 #define FC__INPUTFILE_H
 
-#include <stdio.h>             /* FILE type */
-
+#include "ioz.h"
 #include "shared.h"            /* bool type */
 
 struct inputfile;              /* opaque */
@@ -28,8 +27,10 @@
 typedef char *(*datafilename_fn_t)(const char *filename);
 
 const char *inf_filename(struct inputfile *inf);
-struct inputfile *inf_fromFile(const char *filename, datafilename_fn_t datafn);
-struct inputfile *inf_fromFP(FILE *stream, datafilename_fn_t datafn);
+struct inputfile *inf_from_file(const char *filename,
+                               datafilename_fn_t datafn);
+struct inputfile *inf_from_stream(fz_FILE * stream,
+                                 datafilename_fn_t datafn);
 void inf_close(struct inputfile *inf);
 bool inf_at_eof(struct inputfile *inf);
 
Index: common/ioz.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/ioz.c,v
retrieving revision 1.13
diff -u -r1.13 ioz.c
--- common/ioz.c        2002/11/30 18:39:24     1.13
+++ common/ioz.c        2002/12/03 15:39:27
@@ -68,8 +68,8 @@
   (If errno is 0, and using FZ_ZLIB, probably had zlib error
   Z_MEM_ERROR.  Wishlist: better interface for errors?)
 ***************************************************************/
-fz_FILE *fz_fromFile(const char *filename, const char *in_mode,
-                    enum fz_method method, int compress_level)
+fz_FILE *fz_from_file(const char *filename, const char *in_mode,
+                     enum fz_method method, int compress_level)
 {
   fz_FILE *fp;
   char mode[64];
@@ -137,20 +137,17 @@
 /***************************************************************
   Open uncompressed stream for reading/writing.
 ***************************************************************/
-fz_FILE *fz_fromFP(FILE *stream)
+fz_FILE *fz_from_stream(FILE *stream)
 {
   fz_FILE *fp;
 
-  fp = (fz_FILE *)fc_malloc(sizeof(*fp));
+  if (!stream) {
+    return NULL;
+  }
 
+  fp = fc_malloc(sizeof(*fp));
   fp->method = FZ_PLAIN;
-
   fp->u.plain = stream;
-  if (!fp->u.plain) {
-    free(fp);
-    fp = NULL;
-  }
-
   return fp;
 }
 
Index: common/ioz.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/ioz.h,v
retrieving revision 1.4
diff -u -r1.4 ioz.h
--- common/ioz.h        2002/11/30 18:39:24     1.4
+++ common/ioz.h        2002/12/03 15:39:27
@@ -19,7 +19,7 @@
   (Currently only "required" functionality is supported.)
 ***********************************************************************/
 
-#include <stdio.h>             /* FILE type */
+struct FILE;
 
 #include "shared.h"            /* fc__attribute */
 
@@ -30,9 +30,9 @@
 enum fz_method { FZ_PLAIN, FZ_ZLIB, FZ_LAST };
 #define FZ_NOT_USED FZ_LAST
 
-fz_FILE *fz_fromFile(const char *filename, const char *in_mode,
-                    enum fz_method method, int compress_level);
-fz_FILE *fz_fromFP(FILE *stream);
+fz_FILE *fz_from_file(const char *filename, const char *in_mode,
+                     enum fz_method method, int compress_level);
+fz_FILE *fz_from_stream(FILE * stream);
 int fz_fclose(fz_FILE *fp);
 char *fz_fgets(char *buffer, int size, fz_FILE *fp);
 int fz_fprintf(fz_FILE *fp, const char *format, ...)
Index: common/registry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/registry.c,v
retrieving revision 1.56
diff -u -r1.56 registry.c
--- common/registry.c   2002/11/30 18:39:24     1.56
+++ common/registry.c   2002/12/03 15:39:30
@@ -554,7 +554,7 @@
 bool section_file_load(struct section_file *my_section_file,
                      const char *filename)
 {
-  struct inputfile *inf = inf_fromFile(filename, datafilename);
+  struct inputfile *inf = inf_from_file(filename, datafilename);
 
   return section_file_read_dup(my_section_file, filename, inf, TRUE);
 }
@@ -565,7 +565,7 @@
 bool section_file_load_nodup(struct section_file *my_section_file,
                            const char *filename)
 {
-  struct inputfile *inf = inf_fromFile(filename, datafilename);
+  struct inputfile *inf = inf_from_file(filename, datafilename);
 
   return section_file_read_dup(my_section_file, filename, inf, FALSE);
 }
@@ -573,10 +573,10 @@
 /**************************************************************************
 ...
 **************************************************************************/
-bool section_file_loadFP(struct section_file *my_section_file,
-                        FILE *stream)
+bool section_file_load_from_stream(struct section_file *my_section_file,
+                                  fz_FILE * stream)
 {
-  struct inputfile *inf = inf_fromFP(stream, datafilename);
+  struct inputfile *inf = inf_from_stream(stream, datafilename);
 
   return section_file_read_dup(my_section_file, NULL, inf, TRUE);
 }
@@ -603,7 +603,7 @@
 bool section_file_save(struct section_file *my_section_file, const char 
*filename,
                      int compression_level)
 {
-  fz_FILE *fs = fz_fromFile(filename, "w", FZ_ZLIB, compression_level);
+  fz_FILE *fs = fz_from_file(filename, "w", FZ_ZLIB, compression_level);
 
   struct genlist_iterator ent_iter, save_iter, col_iter;
   struct entry *pentry, *col_pentry;
Index: common/registry.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/registry.h,v
retrieving revision 1.22
diff -u -r1.22 registry.h
--- common/registry.h   2002/11/30 18:39:24     1.22
+++ common/registry.h   2002/12/03 15:39:30
@@ -13,8 +13,7 @@
 #ifndef FC__REGISTRY_H
 #define FC__REGISTRY_H
 
-#include <stdio.h>             /* FILE type */
-
+#include "ioz.h"
 #include "shared.h"            /* bool type and fc__attribute */
 
 struct sbuffer;
@@ -34,8 +33,8 @@
                       const char *filename);
 bool section_file_load_nodup(struct section_file *my_section_file,
                            const char *filename);
-bool section_file_loadFP(struct section_file *my_section_file,
-                        FILE *stream);
+bool section_file_load_from_stream(struct section_file *my_section_file,
+                                  fz_FILE * stream);
 bool section_file_save(struct section_file *my_section_file,
                      const char *filename, int compression_level);
 void section_file_free(struct section_file *file);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2483) Cleanup from* functions in common/*, Raimar Falke via RT <=