C coding tips please / Localisation

Michael cuscotravelservices at gmail.com
Sat Jul 11 00:56:37 UTC 2015


Hi Folks,

Well, it has only been more than 6 weeks and still no response to my "No
localisation for rsync?" topic. :(

So far, I have determined that there are at least 4 files that need
translations for rsync. They are the following.

main.c
flist.c
log.c
progress.c

For my initial test I only made the following modifications.

main.c
------
I added the following line ...

#include <libintl.h>

... to the following section of code near the top of the file.

#include "rsync.h"
#include "inums.h"
#include "io.h"
#if defined CONFIG_LOCALE && defined HAVE_LOCALE_H
#include <libintl.h>
#include <locale.h>
#endif

extern int verbose;

Further down, below a lot of "extern" declarations, I added the following
line ...

#define _(String) gettext (String)

... so that the code becomes as follows.

extern struct filter_list_struct daemon_filter_list;

uid_t our_uid;
int am_receiver = 0;  /* Only set to 1 after the receiver/generator fork. */
int am_generator = 0; /* Only set to 1 after the receiver/generator fork. */
int local_server = 0;
int daemon_over_rsh = 0;
mode_t orig_umask = 0;
int batch_gen_fd = -1;

/* Following line added for Localisation. */
#define _(String) gettext (String)

/* There's probably never more than at most 2 outstanding child processes,
 * but set it higher, just in case. */
#define MAXCHILDPROCS 7

In the "main" function I modified the code as follows.

#if defined CONFIG_LOCALE && defined HAVE_SETLOCALE
  setlocale(LC_CTYPE, "");
/* Following 3 lines added for Localisation. The last 2 require libintl.h to
be included in this file (main.c).*/
  setlocale(LC_ALL, "");
  bindtextdomain("rsync","/usr/share/locale");
  textdomain("rsync");
#endif


flist.c
-------
Below a lot of "extern" declarations, I added the following line ...

#define _(String) gettext (String)

... so that the code becomes as follows.

extern struct filter_list_struct daemon_filter_list;

#ifdef ICONV_OPTION
extern int filesfrom_convert;
extern iconv_t ic_send, ic_recv;
#endif

#define PTR_SIZE (sizeof (struct file_struct *))

/* Following line added for Localisation. This requires libintl.h to be
included in the main.c file.*/
#define _(String) gettext (String)

int io_error;

With the above modifications, when I use "make" to compile rsync, there are
some Warning  messages output such as follows.

warning: implicit declaration of function ‘gettext’
[-Wimplicit-function-declaration]
warning: incompatible implicit declaration of built-in function ‘gettext’
[enabled by default]

However, rsync still appears to function correctly and the translations
stored in the .po file are utilised.


When the following line is included, at the top of the flist.c file ...

#include "libintl.h"

... such that the code becomes as follows ...

#include "rsync.h"
#include "ifuncs.h"
#include "rounding.h"
#include "io.h"
#include "libintl.h"

extern int verbose;

... "make" compiles rsync without outputting any warning messages.


So, my initial thinking was that "libintl.h" only needed to be added to the
main.c file, as it contains the "primary code (?)" responsible for
initiating and controlling rsync, and all other code files, used for
compiling rsync, would "see" the reference to "libintl.h" in the main.c file.

However, given the warning messages I saw, maybe this is not the correct
(elegant and most efficient) way for the secondary files to reference
"libintl.h".


Other things I am curious about, for my own edification, in case it is
important to know about them are as follows.

Are "extern" variables always declared before other variables?

What is the purpose of "#define"? I can understand what is happening with
the following line ...

#define _(String) gettext (String)

... but what about the following lines ...

#define NORMAL_NAME 0
#define SLASH_ENDING_NAME 1
#define DOTDIR_NAME 2

... where it seems to be used to declare a variable?

Thanks & hasta pronto, Michael.


More information about the rsync mailing list