The branch, master has been updated
       via  a213d1c Move some code from util.c to util2.c and add sum_as_hex().
       via  fc2d6fa Set number_separator the first time it gets used.
      from  a508e88 More NEWS changes.

;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a213d1cd6efeeacb87f2a5d0f9b56072e07293c1
Author: Wayne Davison <way...@samba.org>
Date:   Tue Jun 11 13:35:19 2013 -0700

    Move some code from util.c to util2.c and add sum_as_hex().

commit fc2d6fabe7ef7543caa0cb36231c8234dd6b6eeb
Author: Wayne Davison <way...@samba.org>
Date:   Tue Jun 11 13:28:45 2013 -0700

    Set number_separator the first time it gets used.

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

Summary of changes:
 Makefile.in  |    2 +-
 lib/compat.c |   11 +++++-
 log.c        |   13 +------
 options.c    |   10 -----
 t_stub.c     |    1 -
 tls.c        |    7 ----
 trimslash.c  |    1 -
 util.c       |   60 --------------------------------
 util2.c      |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wildtest.c   |    1 -
 10 files changed, 122 insertions(+), 93 deletions(-)
 create mode 100644 util2.c


Changeset truncated at 500 lines:

diff --git a/Makefile.in b/Makefile.in
index 1b603b5..40abf0c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -34,7 +34,7 @@ LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o 
lib/mdfour.o lib/md5.o \
 zlib_OBJS=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
        zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
 OBJS1=flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o \
-       util.o main.o checksum.o match.o syscall.o log.o backup.o delete.o
+       util.o util2.o main.o checksum.o match.o syscall.o log.o backup.o 
delete.o
 OBJS2=options.o io.o compat.o hlink.o token.o uidlist.o socket.o hashtable.o \
        fileio.o batch.o clientname.o chmod.o acls.o xattrs.o
 OBJS3=progress.o pipe.o
diff --git a/lib/compat.c b/lib/compat.c
index f756f76..b89ef02 100644
--- a/lib/compat.c
+++ b/lib/compat.c
@@ -22,7 +22,7 @@
 #include "rsync.h"
 #include "itypes.h"
 
-extern char number_separator;
+static char number_separator;
 
 #ifndef HAVE_STRDUP
  char *strdup(char *s)
@@ -190,6 +190,15 @@ char *do_big_num(int64 num, int human_flag, const char 
*fract)
        char *s;
        int len, negated;
 
+       if (human_flag && !number_separator) {
+               char buf[32];
+               snprintf(buf, sizeof buf, "%f", 3.14);
+               if (strchr(buf, '.') != NULL)
+                       number_separator = ',';
+               else
+                       number_separator = '.';
+       }
+
        n = (n + 1) % (sizeof bufs / sizeof bufs[0]);
 
        if (human_flag > 1) {
diff --git a/log.c b/log.c
index a2e5bd2..34a013b 100644
--- a/log.c
+++ b/log.c
@@ -683,23 +683,14 @@ static void log_formatted(enum logcode code, const char 
*format, const char *op,
                        if (protocol_version >= 30
                         && (iflags & ITEM_TRANSFER
                          || (always_checksum && S_ISREG(file->mode)))) {
-                               int i, x1, x2;
                                const char *sum = iflags & ITEM_TRANSFER
                                                ? sender_file_sum : F_SUM(file);
-                               c = buf2 + checksum_len*2;
-                               *c = '\0';
-                               for (i = checksum_len; --i >= 0; ) {
-                                       x1 = CVAL(sum, i);
-                                       x2 = x1 >> 4;
-                                       x1 &= 0xF;
-                                       *--c = x1 <= 9 ? x1 + '0' : x1 + 'a' - 
10;
-                                       *--c = x2 <= 9 ? x2 + '0' : x2 + 'a' - 
10;
-                               }
+                               n = sum_as_hex(sum);
                        } else {
                                memset(buf2, ' ', checksum_len*2);
                                buf2[checksum_len*2] = '\0';
+                               n = buf2;
                        }
-                       n = buf2;
                        break;
                case 'i':
                        if (iflags & ITEM_DELETED) {
diff --git a/options.c b/options.c
index 91e3fdd..cebf256 100644
--- a/options.c
+++ b/options.c
@@ -123,7 +123,6 @@ int checksum_seed = 0;
 int inplace = 0;
 int delay_updates = 0;
 long block_size = 0; /* "long" because popt can't set an int32. */
-char number_separator;
 char *skip_compress = NULL;
 item_list dparam_list = EMPTY_ITEM_LIST;
 
@@ -1870,15 +1869,6 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        verbose > 1 ? "stats3" : "stats2", DEFAULT_PRIORITY);
        }
 
-       if (human_readable) {
-               char buf[32];
-               snprintf(buf, sizeof buf, "%f", 3.14);
-               if (strchr(buf, '.') != NULL)
-                       number_separator = ',';
-               else
-                       number_separator = '.';
-       }
-
 #ifdef ICONV_OPTION
        if (iconv_opt && protect_args != 2) {
                if (!am_server && strcmp(iconv_opt, "-") == 0)
diff --git a/t_stub.c b/t_stub.c
index 013c09d..0fca865 100644
--- a/t_stub.c
+++ b/t_stub.c
@@ -30,7 +30,6 @@ int module_dirlen = 0;
 int preserve_acls = 0;
 int preserve_times = 0;
 int preserve_xattrs = 0;
-char number_separator = ',';
 char *partial_dir;
 char *module_dir;
 filter_rule_list daemon_filter_list;
diff --git a/tls.c b/tls.c
index f111c02..b84085d 100644
--- a/tls.c
+++ b/tls.c
@@ -51,7 +51,6 @@ int link_owner = 0;
 int nsec_times = 0;
 int preserve_perms = 0;
 int preserve_executability = 0;
-char number_separator;
 
 #ifdef SUPPORT_XATTRS
 
@@ -255,12 +254,6 @@ main(int argc, char *argv[])
        if (!extra_args || *extra_args == NULL)
                tls_usage(1);
 
-       snprintf(buf, sizeof buf, "%f", 3.14);
-       if (strchr(buf, '.') != NULL)
-               number_separator = ',';
-       else
-               number_separator = '.';
-
        for (; *extra_args; extra_args++)
                list_file(*extra_args);
        poptFreeContext(pc);
diff --git a/trimslash.c b/trimslash.c
index 448064a..7694eb1 100644
--- a/trimslash.c
+++ b/trimslash.c
@@ -28,7 +28,6 @@ int read_only = 1;
 int list_only = 0;
 int preserve_perms = 0;
 int preserve_executability = 0;
-char number_separator = ',';
 
 int
 main(int argc, char **argv)
diff --git a/util.c b/util.c
index d0dee73..c943ce0 100644
--- a/util.c
+++ b/util.c
@@ -114,18 +114,6 @@ void print_child_argv(const char *prefix, char **cmd)
        rprintf(FCLIENT, " (%d args)\n", cnt);
 }
 
-NORETURN void out_of_memory(const char *str)
-{
-       rprintf(FERROR, "ERROR: out of memory in %s [%s]\n", str, who_am_i());
-       exit_cleanup(RERR_MALLOC);
-}
-
-NORETURN void overflow_exit(const char *str)
-{
-       rprintf(FERROR, "ERROR: buffer overflow in %s [%s]\n", str, who_am_i());
-       exit_cleanup(RERR_MALLOC);
-}
-
 /* This returns 0 for success, 1 for a symlink if symlink time-setting
  * is not possible, or -1 for any other error. */
 int set_modtime(const char *fname, time_t modtime, uint32 mod_nsec, mode_t 
mode)
@@ -1305,36 +1293,6 @@ char *timestring(time_t t)
        return TimeBuf;
 }
 
-/**
- * Sleep for a specified number of milliseconds.
- *
- * Always returns TRUE.  (In the future it might return FALSE if
- * interrupted.)
- **/
-int msleep(int t)
-{
-       int tdiff = 0;
-       struct timeval tval, t1, t2;
-
-       gettimeofday(&t1, NULL);
-
-       while (tdiff < t) {
-               tval.tv_sec = (t-tdiff)/1000;
-               tval.tv_usec = 1000*((t-tdiff)%1000);
-
-               errno = 0;
-               select(0,NULL,NULL, NULL, &tval);
-
-               gettimeofday(&t2, NULL);
-               if (t2.tv_sec < t1.tv_sec)
-                       t1 = t2; /* Time went backwards, so start over. */
-               tdiff = (t2.tv_sec - t1.tv_sec)*1000 +
-                       (t2.tv_usec - t1.tv_usec)/1000;
-       }
-
-       return True;
-}
-
 /* Determine if two time_t values are equivalent (either exact, or in
  * the modification timestamp window established by --modify-window).
  *
@@ -1392,24 +1350,6 @@ int _Insure_trap_error(int a1, int a2, int a3, int a4, 
int a5, int a6)
 }
 #endif
 
-#define MALLOC_MAX 0x40000000
-
-void *_new_array(unsigned long num, unsigned int size, int use_calloc)
-{
-       if (num >= MALLOC_MAX/size)
-               return NULL;
-       return use_calloc ? calloc(num, size) : malloc(num * size);
-}
-
-void *_realloc_array(void *ptr, unsigned int size, size_t num)
-{
-       if (num >= MALLOC_MAX/size)
-               return NULL;
-       if (!ptr)
-               return malloc(size * num);
-       return realloc(ptr, size * num);
-}
-
 /* Take a filename and filename length and return the most significant
  * filename suffix we can find.  This ignores suffixes such as "~",
  * ".bak", ".orig", ".~1~", etc. */
diff --git a/util2.c b/util2.c
new file mode 100644
index 0000000..85b1903
--- /dev/null
+++ b/util2.c
@@ -0,0 +1,109 @@
+/*
+ * Utility routines used in rsync.
+ *
+ * Copyright (C) 1996-2000 Andrew Tridgell
+ * Copyright (C) 1996 Paul Mackerras
+ * Copyright (C) 2001, 2002 Martin Pool <m...@samba.org>
+ * Copyright (C) 2003-2013 Wayne Davison
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, visit the http://fsf.org website.
+ */
+
+#include "rsync.h"
+#include "ifuncs.h"
+#include "itypes.h"
+#include "inums.h"
+
+extern int checksum_len;
+
+/**
+ * Sleep for a specified number of milliseconds.
+ *
+ * Always returns TRUE.  (In the future it might return FALSE if
+ * interrupted.)
+ **/
+int msleep(int t)
+{
+       int tdiff = 0;
+       struct timeval tval, t1, t2;
+
+       gettimeofday(&t1, NULL);
+
+       while (tdiff < t) {
+               tval.tv_sec = (t-tdiff)/1000;
+               tval.tv_usec = 1000*((t-tdiff)%1000);
+
+               errno = 0;
+               select(0,NULL,NULL, NULL, &tval);
+
+               gettimeofday(&t2, NULL);
+               if (t2.tv_sec < t1.tv_sec)
+                       t1 = t2; /* Time went backwards, so start over. */
+               tdiff = (t2.tv_sec - t1.tv_sec)*1000 +
+                       (t2.tv_usec - t1.tv_usec)/1000;
+       }
+
+       return True;
+}
+
+#define MALLOC_MAX 0x40000000
+
+void *_new_array(unsigned long num, unsigned int size, int use_calloc)
+{
+       if (num >= MALLOC_MAX/size)
+               return NULL;
+       return use_calloc ? calloc(num, size) : malloc(num * size);
+}
+
+void *_realloc_array(void *ptr, unsigned int size, size_t num)
+{
+       if (num >= MALLOC_MAX/size)
+               return NULL;
+       if (!ptr)
+               return malloc(size * num);
+       return realloc(ptr, size * num);
+}
+
+const char *sum_as_hex(const char *sum)
+{
+       static char buf[MAX_DIGEST_LEN*2+1];
+       int i, x1, x2;
+       char *c = buf + checksum_len*2;
+
+       assert(c - buf < (int)sizeof buf);
+
+       *c = '\0';
+
+       for (i = checksum_len; --i >= 0; ) {
+               x1 = CVAL(sum, i);
+               x2 = x1 >> 4;
+               x1 &= 0xF;
+               *--c = x1 <= 9 ? x1 + '0' : x1 + 'a' - 10;
+               *--c = x2 <= 9 ? x2 + '0' : x2 + 'a' - 10;
+       }
+
+       return buf;
+}
+
+NORETURN void out_of_memory(const char *str)
+{
+       rprintf(FERROR, "ERROR: out of memory in %s [%s]\n", str, who_am_i());
+       exit_cleanup(RERR_MALLOC);
+}
+
+NORETURN void overflow_exit(const char *str)
+{
+       rprintf(FERROR, "ERROR: buffer overflow in %s [%s]\n", str, who_am_i());
+       exit_cleanup(RERR_MALLOC);
+}
diff --git a/wildtest.c b/wildtest.c
index 10534e0..2621c15 100644
--- a/wildtest.c
+++ b/wildtest.c
@@ -31,7 +31,6 @@ int fnmatch_errors = 0;
 #endif
 
 int wildmatch_errors = 0;
-char number_separator = ',';
 
 typedef char bool;
 


-- 
The rsync repository.
_______________________________________________
rsync-cvs mailing list
rsync-cvs@lists.samba.org
https://lists.samba.org/mailman/listinfo/rsync-cvs

Reply via email to