antiright-devel
[Top][All Lists]
Advanced

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

[Antiright-devel] antiright/libantiright arguments.c gui.c pipe.c...


From: Jeffrey Bedard
Subject: [Antiright-devel] antiright/libantiright arguments.c gui.c pipe.c...
Date: Sun, 15 Aug 2010 18:52:34 +0000

CVSROOT:        /sources/antiright
Module name:    antiright
Changes by:     Jeffrey Bedard <jefbed> 10/08/15 18:52:34

Modified files:
        libantiright   : arguments.c gui.c pipe.c util.c util.h 

Log message:
        Code cleanups and refactorings.  Made malloc wrappers less potentially
        ambiguous.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/arguments.c?cvsroot=antiright&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/gui.c?cvsroot=antiright&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/pipe.c?cvsroot=antiright&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/util.c?cvsroot=antiright&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/util.h?cvsroot=antiright&r1=1.14&r2=1.15

Patches:
Index: arguments.c
===================================================================
RCS file: /sources/antiright/antiright/libantiright/arguments.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- arguments.c 13 Aug 2010 20:22:23 -0000      1.4
+++ arguments.c 15 Aug 2010 18:52:34 -0000      1.5
@@ -41,20 +41,21 @@
 static void
 ar_ARArguments_delete_contents(struct ARArguments * args)
 {
-       for(; args->argc>0; args->argc--)
+       if(!(args->argv))
+               return;
+       while(--(args->argc) >= 0)
        {
-               gchar * arg = args->argv[args->argc-1];
-               if(arg)
-                       g_free(arg);
+               g_free(args->argv[args->argc]);
+               args->argv[args->argc]=NULL;
        }
-       g_free(args->argv);
+       free(args->argv);
 }
 
 static void
 ar_delete_ARArguments(struct ARArguments * args)
 {
        ar_ARArguments_delete_contents(args);
-       g_free(args);
+       arfree(args);
 }
 
 static void
@@ -92,7 +93,7 @@
 {
        struct ARArguments * args;
 
-       args=g_malloc(sizeof(struct ARArguments));
+       args=armalloc(sizeof(struct ARArguments));
        ar_ARArguments_setup(args);
 
        return args;

Index: gui.c
===================================================================
RCS file: /sources/antiright/antiright/libantiright/gui.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gui.c       14 May 2007 18:06:35 -0000      1.1
+++ gui.c       15 Aug 2010 18:52:34 -0000      1.2
@@ -25,7 +25,7 @@
 static void
 ar_delete_ARDimensions(ARDimensions * this)
 {
-       xfree(this);
+       arfree(this);
 }
 
 static void
@@ -50,7 +50,7 @@
 {
        ARDimensions * dimensions;
 
-       dimensions=xmalloc(sizeof(ARDimensions));
+       dimensions=armalloc(sizeof(ARDimensions));
        setup_methods(dimensions);
        
        return dimensions;

Index: pipe.c
===================================================================
RCS file: /sources/antiright/antiright/libantiright/pipe.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- pipe.c      17 May 2007 04:42:49 -0000      1.12
+++ pipe.c      15 Aug 2010 18:52:34 -0000      1.13
@@ -31,13 +31,15 @@
        gchar *text;
        size_t total, read;
 
+       text=NULL;
        total=0;
        read=0;
+
        ar_asprintf(&text, "\0");
-       while((read = fread(buffer, sizeof(char), BUFSIZ, file)) != 0)
+       while((read = fread(buffer, sizeof(gchar), BUFSIZ, file)) != 0)
        {
                total += read;
-               text = (gchar *) g_realloc(text, total*sizeof(char));
+               text = (gchar *) g_realloc(text, total*sizeof(gchar));
                ARPASSERT(text);
                g_strlcat(text, buffer, total);
        }
@@ -48,16 +50,11 @@
 gchar *
 antiright_read_named_file(const gchar * filename)
 {
-       FILE * file;
        gchar * contents;
        
+       g_file_get_contents(filename, &contents, NULL, NULL);
        
-       file=fopen(filename, g_file_test(filename, G_FILE_TEST_EXISTS)
-               ? "r" : "a+");
-       contents=antiright_read_file(file);
-       fclose(file);
-
-       return contents;
+       return contents ? contents : "";
 }
 
 /* Make sure that you free the returned string.  */
@@ -65,66 +62,14 @@
 antiright_pipe_read(const gchar *command_string)
 {
        /* Declare.  */
-       char *text;
-       FILE *pipe;
+       gchar *command_stdout=NULL;
        
        /* Check arguments.  */
        ARPASSERT(command_string);
        
-       /* Initialize.  */
-       text = NULL;
-
+       g_spawn_command_line_sync(command_string, &command_stdout, NULL,
+                       NULL, NULL);
 
-       /* Execute the command indicated by command_string.  */
-       /* Pipe is read-only.  Stdout will be directed to it.  */
-       pipe = popen(command_string, "r");
-#ifdef DEBUG
-       ARPASSERT(pipe);
-#endif /* DEBUG */
-       text=antiright_read_file(pipe);
-       /* Close the pipe once fgets() returns a false condition.  */
-       if(pclose(pipe) == -1)
-       {
-               const gchar * warning;
-               
-               warning="command was not successful";
-               if(text)
-               {
-                       gchar * erred_text;
-
-                       ar_asprintf(&erred_text, "%s\n%s", text, warning);
-                       g_free(text);
-                       text=erred_text;
-               }
-               else
-               {
-                       /* TEXT is NULL */
-                       ARWARN(warning);
-                       return g_strdup(warning);
-               }
-       }
-       return (text);
+       return g_strchomp(command_stdout);
 }
 
-/* void */
-/* antiright_pipe_write(char *command_string, char* data) */
-/* { */
-/* FILE *pipe_fp=popen(command_string, "w"); */
-/* fprintf(pipe_fp, data); */
-/* pclose(pipe_fp); */
-/* } */
-
-/* void */
-/* antiright_fifo_server(char *command_string, char *fifo) */
-/* { */
-/* FILE *fifo_fp; */
-/* FILE *pipe_fp=popen(command_string, "w"); */
-/* char buffer[80]; */
-/* while(0) */
-/* { */
-/* fifo_fp=fopen(fifo, "r"); */
-/* fgets(buffer, 80, fifo_fp); */
-/* fprintf(pipe_fp, buffer); */
-/* fclose(fifo_fp); */
-/* } */
-/* } */

Index: util.c
===================================================================
RCS file: /sources/antiright/antiright/libantiright/util.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- util.c      20 Jul 2007 01:26:35 -0000      1.19
+++ util.c      15 Aug 2010 18:52:34 -0000      1.20
@@ -23,7 +23,7 @@
 #include "library.h"
 
 gpointer
-xmalloc(size_t size)
+armalloc(size_t size)
 {
        gpointer data;
 
@@ -41,7 +41,7 @@
 }
 
 void
-xfree(gpointer data)
+arfree(gpointer data)
 {
 #ifdef LIBGC
        GC_FREE(data);
@@ -111,7 +111,7 @@
 {
        struct ARFunctionDictionary * dict;
 
-       dict = xmalloc(sizeof(struct ARFunctionDictionary));
+       dict = armalloc(sizeof(struct ARFunctionDictionary));
        setup_ARFunctionDictionary_fields(dict);
        setup_ARFunctionDictionary_methods(dict);
 
@@ -160,7 +160,7 @@
 {
        struct ARCommandLineParser * parser;
 
-       parser = xmalloc(sizeof(struct ARCommandLineParser));
+       parser = armalloc(sizeof(struct ARCommandLineParser));
        parser->__dict=dictionary;
        setup_ARCommandLineParser_methods(parser);
 

Index: util.h
===================================================================
RCS file: /sources/antiright/antiright/libantiright/util.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- util.h      13 Aug 2010 20:22:23 -0000      1.14
+++ util.h      15 Aug 2010 18:52:34 -0000      1.15
@@ -27,10 +27,10 @@
        g_file_set_contents(filename, text, strlen(text), NULL)
 
 gpointer
-xmalloc(size_t size);
+armalloc(size_t size);
 
 void
-xfree(gpointer data);
+arfree(gpointer data);
 
 typedef void(*ARActionFunction)(gint *, gchar **);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]