gnokii-commit
[Top][All Lists]
Advanced

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

[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-51


From: Daniele Forsi
Subject: [SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-517-g5f13b60
Date: Mon, 29 Apr 2013 17:35:46 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "libgnokii and core programs".

The branch, master has been updated
       via  5f13b60633365b69f0cbe0bea7a72ed78a483a7a (commit)
      from  c48f1b9b1a42e90a159e0ff54305c5e9a1990e30 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/gnokii.git/commit/?id=5f13b60633365b69f0cbe0bea7a72ed78a483a7a


commit 5f13b60633365b69f0cbe0bea7a72ed78a483a7a
Author: Daniele Forsi <address@hidden>
Date:   Mon Apr 29 19:18:30 2013 +0200

    Use enum instead of magic numbers

diff --git a/gnokii/gnokii-app.h b/gnokii/gnokii-app.h
index d704a6c..649b645 100644
--- a/gnokii/gnokii-app.h
+++ b/gnokii/gnokii-app.h
@@ -23,6 +23,13 @@
 
 #define MAX_INPUT_LINE_LEN 512
 
+typedef enum {
+       GNOKII_APP_MODE_Cancel = -1,
+       GNOKII_APP_MODE_Overwrite,
+       GNOKII_APP_MODE_Ask,
+       GNOKII_APP_MODE_Append
+} gnokii_app_mode;
+
 /* shared globals */
 extern volatile bool bshutdown;
 
diff --git a/gnokii/gnokii-mms.c b/gnokii/gnokii-mms.c
index 0807818..331cc39 100644
--- a/gnokii/gnokii-mms.c
+++ b/gnokii/gnokii-mms.c
@@ -77,7 +77,8 @@ gn_error getmms(int argc, char *argv[], gn_data *data, struct 
gn_statemachine *s
        gn_sms_folder_list folderlist;
        gn_mms *message;
        char *memory_type_string;
-       int start_message, end_message, count, mode = 1;
+       int start_message, end_message, count;
+       gnokii_app_mode mode = GNOKII_APP_MODE_Ask;
        char filename[64];
        gn_error error = GN_ERR_NONE;
        gn_mms_format output_format_type = GN_MMS_FORMAT_TEXT;
@@ -115,7 +116,7 @@ gn_error getmms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine *s
                        break;
                /* force mode -- don't ask to overwrite */
                case 'o':
-                       mode = 0;
+                       mode = GNOKII_APP_MODE_Overwrite;
                        break;
                case GN_MMS_FORMAT_MIME:
                        /* FALL THROUGH */
@@ -166,7 +167,7 @@ gn_error getmms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine *s
                                error = fprint_mms(stdout, message);
                                fprintf(stdout, "\n");
                        }
-                       if (del && mode != -1) {
+                       if (del && mode != GNOKII_APP_MODE_Cancel) {
                                if (GN_ERR_NONE != gn_mms_delete(data, state))
                                        fprintf(stderr, _("(delete failed)\n"));
                                else
@@ -177,7 +178,7 @@ gn_error getmms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine *s
                        if ((error == GN_ERR_INVALIDLOCATION) && (end_message 
== INT_MAX) && (count > start_message)) {
                                error = GN_ERR_NONE;
                                /* Force exit */
-                               mode = -1;
+                               mode = GNOKII_APP_MODE_Cancel;
                                break;
                        }
                        fprintf(stderr, _("Getting MMS failed (location %d from 
memory %s)! (%s)\n"), count, memory_type_string, gn_error_print(error));
@@ -190,7 +191,7 @@ gn_error getmms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine *s
                        break;
                }
                gn_mms_free(message);
-               if (mode == -1)
+               if (mode == GNOKII_APP_MODE_Cancel)
                        break;
        }
 
@@ -257,4 +258,3 @@ gn_error deletemms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine
        return error;
 }
 
-
diff --git a/gnokii/gnokii-sms.c b/gnokii/gnokii-sms.c
index c0d23ef..ae20de6 100644
--- a/gnokii/gnokii-sms.c
+++ b/gnokii/gnokii-sms.c
@@ -621,7 +621,8 @@ gn_error getsms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine *s
        gn_sms_folder_list folderlist;
        gn_sms message;
        char *memory_type_string;
-       int start_message, end_message, count, mode = 1;
+       int start_message, end_message, count;
+       gnokii_app_mode mode = GNOKII_APP_MODE_Ask;
        int folder_count = -1;
        int messages_read = 0;
        char filename[64];
@@ -693,11 +694,11 @@ gn_error getsms(int argc, char *argv[], gn_data *data, 
struct gn_statemachine *s
                        break;
                /* append mode */
                case 'a':
-                       mode = 2;
+                       mode = GNOKII_APP_MODE_Append;
                        goto parsefile;
                /* force mode -- don't ask to overwrite */
                case 'F':
-                       mode = 0;
+                       mode = GNOKII_APP_MODE_Overwrite;
                case 'f':
 parsefile:
                        if (optarg) {
@@ -813,10 +814,7 @@ parsefile:
                                        gn_bmp_print(&bitmap, stdout);
                                        if (*filename) {
                                                error = GN_ERR_NONE;
-                                               /* mode == 1, interactive mode
-                                                * mode == 0, overwrite mode
-                                                */
-                                               if (mode && (stat(filename, 
&buf) == 0)) {
+                                               if (mode == GNOKII_APP_MODE_Ask 
&& (stat(filename, &buf) == 0)) {
                                                        fprintf(stdout, _("File 
%s exists.\n"), filename);
                                                        fprintf(stdout, 
_("Overwrite? (yes/no) "));
                                                        gn_line_get(stdin, ans, 
4);
@@ -852,7 +850,7 @@ parsefile:
                        }
                        if (message_text) {
                                fprintf(stdout, "%s\n", message_text);
-                               if ((mode != -1) && *filename) {
+                               if ((mode != GNOKII_APP_MODE_Cancel) && 
*filename) {
                                        char buf[1024];
                                        char *mbox = gn_sms2mbox(&message, 
"gnokii");
                                        snprintf(buf, 1023, "%s", filename);
@@ -860,7 +858,7 @@ parsefile:
                                        free(mbox);
                                }
                        }
-                       if (del && mode != -1) {
+                       if (del && mode != GNOKII_APP_MODE_Cancel) {
                                data->sms = &message;
                                if (GN_ERR_NONE != gn_sms_delete(data, state))
                                        fprintf(stderr, _("(delete failed)\n"));
@@ -876,7 +874,7 @@ parsefile:
                        }
                        break;
                }
-               if (mode == -1)
+               if (mode == GNOKII_APP_MODE_Cancel)
                        cont = false;
                if (count >= end_message)
                        cont = false;
diff --git a/gnokii/gnokii-utils.c b/gnokii/gnokii-utils.c
index bdf8716..bd14bb5 100644
--- a/gnokii/gnokii-utils.c
+++ b/gnokii/gnokii-utils.c
@@ -34,14 +34,14 @@
 #include "gnokii-app.h"
 #include "gnokii.h"
 
-int askoverwrite(const char *filename, int mode)
+gnokii_app_mode askoverwrite(const char *filename, gnokii_app_mode mode)
 {
        int confirm = -1;
        char ans[5];
        struct stat buf;
 
        /* Ask before overwriting */
-       if ((mode == 1) && (stat(filename, &buf) == 0)) {
+       if ((mode == GNOKII_APP_MODE_Ask) && (stat(filename, &buf) == 0)) {
                fprintf(stdout, _("File %s exists.\n"), filename);
                while (confirm < 0) {
                        fprintf(stdout, _("Overwrite? (yes/no) "));
@@ -52,24 +52,20 @@ int askoverwrite(const char *filename, int mode)
                                confirm = 0;
                }
                if (!confirm)
-                       return -1;
+                       return GNOKII_APP_MODE_Cancel;
        }
        return mode;
 }
 
 /* FIXME - this should not ask for confirmation here - I'm not sure what calls 
it though */
-/* mode == 0 -> overwrite
- * mode == 1 -> ask
- * mode == 2 -> append
- */
-int writefile(char *filename, char *text, int mode)
+gnokii_app_mode writefile(char *filename, char *text, gnokii_app_mode mode)
 {
        FILE *file;
 
        mode = askoverwrite(filename, mode);
 
        /* append */
-       if (mode == 2)
+       if (mode == GNOKII_APP_MODE_Append)
                file = fopen(filename, "a");
        /* overwrite */
        else
@@ -77,24 +73,24 @@ int writefile(char *filename, char *text, int mode)
 
        if (!file) {
                fprintf(stderr, _("Can't open file %s for writing!\n"),  
filename);
-               return -1;
+               return GNOKII_APP_MODE_Cancel;
        }
        fprintf(file, "%s\n", text);
        fclose(file);
        /* Return value is used as new mode. Set it to append mode */
-       return 2;
+       return GNOKII_APP_MODE_Append;
 }
 
-int writebuffer(const char *filename, const char *buffer, size_t nitems, int 
mode)
+gnokii_app_mode writebuffer(const char *filename, const char *buffer, size_t 
nitems, gnokii_app_mode mode)
 {
        /* Return value is used as new mode. Set it to append mode */
-       int retval = 2;
+       gnokii_app_mode retval = GNOKII_APP_MODE_Append;
        FILE *file;
 
        mode = askoverwrite(filename, mode);
 
        /* append */
-       if (mode == 2)
+       if (mode == GNOKII_APP_MODE_Append)
                file = fopen(filename, "ab");
        /* overwrite */
        else
@@ -102,11 +98,11 @@ int writebuffer(const char *filename, const char *buffer, 
size_t nitems, int mod
 
        if (!file) {
                fprintf(stderr, _("Can't open file %s for writing!\n"),  
filename);
-               retval = -1;
+               retval = GNOKII_APP_MODE_Cancel;
                goto out;
        }
        if (fwrite(buffer, 1, nitems, file) != nitems)
-               retval = -1;
+               retval = GNOKII_APP_MODE_Cancel;
        fclose(file);
 out:
        return retval;

-----------------------------------------------------------------------

Summary of changes:
 gnokii/gnokii-app.h   |    7 +++++++
 gnokii/gnokii-mms.c   |   12 ++++++------
 gnokii/gnokii-sms.c   |   18 ++++++++----------
 gnokii/gnokii-utils.c |   28 ++++++++++++----------------
 4 files changed, 33 insertions(+), 32 deletions(-)


hooks/post-receive
-- 
libgnokii and core programs



reply via email to

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