C coding tips please / Localisation
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 ... 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 #include #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. -- Please use reply-all for most replies to avoid omitting the mailing list. To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html
Re: C coding tips please / Localisation
On Fri, Jul 10, 2015 at 5:57 PM Michael wrote: > 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". > The best place to add that include and the gettext define would be to put them in rsync.h somewhere, which would make the localisation idiom available in all the .c files. Putting it down at the bottom of the file would be a reasonable spot for it. Are "extern" variables always declared before other variables? > No, they can be declared anywhere before they get used. Rsync just has a particular top-of-file style for them. What is the purpose of "#define"? > It's just a simple search-and-replace mechanism that allows macro definitions in C files. It is sometimes used for inline "functions" and sometimes for global constants (they existed long before "const" vars). I think your idea of adding localisation to rsync is reasonable, though hasn't been that popular of a topic since the translatable messages that it outputs are fairly limited. I think for the official release that I'd make it a configure option so that folks can choose to include it or not, as they see fit. For your localisation efforts, I'd recommend that you either make a "git clone" of the source and change that since that makes it easy to diff your changes and make a patch file with the end results of what you've done. You could also just keep an unchanged version in a directory and use "diff -ru" on the old and new directory hierarchies should you not want to learn to use git. ..wayne.. -- Please use reply-all for most replies to avoid omitting the mailing list. To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html
Re: C coding tips please / Localisation
Wayne Davison samba.org> writes: > The best place to add that include and the gettext define would be to put them in rsync.h somewhere, which would make the localisation idiom available in all the .c files. Putting it down at the bottom of the file would be a reasonable spot for it. Hi Wayne, I thought you must have fallen off the face of the earth or something like that. I have moved the code to rsync.h, as suggested, and that is working. :) > For your localisation efforts, I'd recommend that you either make a "git clone" of the source and change that since that makes it easy to diff your changes and make a patch file with the end results of what you've done. You could also just keep an unchanged version in a directory and use "diff -ru" on the old and new directory hierarchies should you not want to learn to use git. I have no experience with git. I don't have time to waste; how steep is the learning curve? Is "diff -ru" a command that is used within the git interface? Some of the terminology seems a bit obtuse and some of the associated descriptions, on the following page, are vague and lacking in detail. https://download.samba.org/pub/rsync/rsync.html Using luckyBackup (which is how I learnt about rsync and what is driving my need to localise it) for testing, I was trying to determine what "Literal data" and "Matched data" actually refer to and how and when the values are populated. Until I understand that, I can't determine how I think that "Literal data" and "Matched data" could be better expressed for inexperienced users. The aforementioned page has the following description for "Total transferred file size". Total transferred file size is the total sum of all files sizes for just the transferred files. Is the above affected ??? modified files ??? Does the "Total transferred file size" represent the final size of the files which were transferred or updated or should it represent the size of newly transferred files plus the differences for the updated files? Or, does it only represent the size for files that were transferred in their entirety? Is "Literal data" supposed to refer to only the total size of the differences transferred for updated files? One test I made was to add a line of text to a file to see what effect it would have on the output for "Literal data". I expected to see only a few bytes but the output indicated it was using the complete size of the file. I was using that test to see if the following description, about rsync, was accurate. "It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination." My initial understanding, of that description, is that rsync transfers the differences for a given file that has been modified or updated in some way. Now, I am wondering if what it is really saying is that it transfers complete files whether they be files that have been added to the Source directory and don't exist in the Destination directory or they are existing files that exist in both the Source and Destination directories and the files that are in the Source directory have been modified or updated in some way. Please also clarify what "Matched data" refers to. Thanks, Michael. -- Please use reply-all for most replies to avoid omitting the mailing list. To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html
Re: C coding tips please / Localisation
Michael gmail.com> writes: > Is the above affected ??? modified files ??? Ignore the above line that I forgot to remove. -- Please use reply-all for most replies to avoid omitting the mailing list. To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html