Format specifiers
Contents
Introduction
aMule is developped in the C++ programming language. This language alows to handle strings very easily but sometimes it needs a little tweaking in those strings.
When translating aMule, you might encounter with strange things. Sometimes this will be just typos, but sometimes they are there on purpose.
This document is a must read for anyone willing or actually translating aMule. It describes all the cases of groups of characters which should not ever be modified.
So, the following is a description of all the groups of characters which are not supposed to be modified and what they actually mean.
Escape codes
Non-representable ASCII codes
This are codes which represent characters of the ASCII codeset which aren't representable with the keyboard.
- \a -> This will normally cause an audible alert (sometimes visual) like a beep
- \b -> Will go back one character
- \f -> On most systems this will clean the screen
- \n -> Ends the current line and starts a new one, palcing the cursor at the begining
- \r -> Goes to the beggining of the current line
- \t -> Torizontal tabulation
- \v -> Vertical tabulation
- \<octal digits> -> Will display the value octal digits in octal
- \x<hex digits> -> Will display the value hex digits in hexadecimal
Disambiguation escape codes
The following are not characters non-representable on the keyboard, but due to limitations in the C++ programming language, are needed to be used this way:
- \? -> Displays a question mark ( ? ) to avoid trigraph translations (not all compilers support trigraph translating, so it's not allways necessary)
- \\ -> Displays a backslash ( \ )
- \ -> Displays a single quote ( ' )
- \" -> Displays a double quote ( " )
Examples
The following are some examples for the above escape codes. They are listed as couples of code-line + output. So, the first line represents the line in the way it is written into the C++ code and the second line (or group of lines if it needs more than one line) represents how that C++ code line is displayed on execution:
- Code line: I am an angel\aOh, true, I am not.
- Output: I am an angelOh, true, I am not (A beep will be heard right after displaying the word angel and the next word (Oh) will not be displayed untill the beep finishes.
- Code line: I have 6\b5 fingers in my right hand
- Output: I have 5 fingers in my right hand
- Code line: Where is the <RETURN> key???\nAh, here it is!
- Output: Where is the <RETURN> key???
Ah, here it is!
- Code line: I am a BIG lier\rI'm married with Marilyn Monroe
- Output: I'm married with Marilyn Monroe
- Code line: \141\115\165\x6C\x65
- Output: aMule (Notice that the octal value of a in the ASCII codeset is 141, the ctal value of M is 115, the octal value of u is 165, the hexadecimal value of l is 6C and the hexadecimal value of e is 65)
- Code line: Isn\'t it complicated to use the \" and \\ characters\?
- Output: Isn't it complicated to use the " and \ characters?
Format specifiers
Basic format specifiers
%d signed int variable, decimal representation (equivalent to %i) %u unsigned int variable, decimal representation %x unsigned int variable, lowercase hexadecimal representation %X unsigned int variable, uppercase hexadecimal representation %o unsigned int variable, octal representation
(there are no format specifiers for binary representation)
%f float/double, normal notation %e float/double, exponential notation (%E uses E instead of e) %g float/double, notation %f or %e chosen depending on value (%E if %G) %c character (passed as int), text representation %s string (see 10. Arrays, strings and pointers) %p pointer (see 10. Arrays, strings and pointers) %n number of characters written upto now will be written to int
that the corresponding argument points to
Type extensions
You can change the type of the printed variable by inserting one of the following characters between the % sign and the type character (for example: %ld for long int instead of an int). h for d,i,o,u,x,X: short int instead of int
(the short int will be promoted to int when passed anyway) for n: store result in short int instead of int
l for d,i,o,u,x,X: long int instead of int
for n: store result in long int instead of int Do NOT use for e,E,f,F,g,G for e.g. printing doubles.
L for e,E,f,F,g,G: long double instead of float/double
Output tweaks
There are some flags and modifiers that can be put between the % and the type character: - left alignment, pad on the right with spaces (default=right alignment) + print plus sign if positive (default=only print minus sign if negative)
(for signed numbers only)
space print space if positive (default=only print minus sign if negative)
(for signed numbers only)
0 pad with zeros instead of with spaces (for numbers only)
- "alternate form": - o: 0 will be prepended to a non-zero result
- x/X: prepends 0x/0X to result - f/F,e/E,g/G: decimal point even if no decimals - g/G: trailing zeros are not removed
<nonzero decimal value> specify field width to which result will be padded
(this can be used together with the 0 flag)
- field width will be passed as int parameter before the actual argument
.<nonzero decimal value> specify precision (default for f/F,e/E = 6)
(for s, precision will limit the number of printed characters)
.0 no decimal point is printed for f/F,e/E .* precision will be passed as int parameter before the actual argument
Example
Other stuff
Leading and ending blank spaces
Overall example
Example:
- Untranslated:
- msgid="I am %s and I a %d-year old\nand I'm a happy \"aMule\" user "
- msgstr=""
- Would become (translation to spanish):
- msgid="I am %s, %d years old\nand &I'm a happy \"rabitty-aMule\" user "
- msgstr="Soy %s y tengo %d años\ny soy un fel&iz usuario del \"conejillo-aMule\" "
- Explanation:
- %s and %d must be copied literally since they will be substituted in the program with some string or number. General rule: anything between a character % and the next letter-character (that is, a, b, 'c, etc...) or percentage character (%) must be copied literally.
- \n must be copied literally too since it brakes the line into a new line. The general rule is: \ and it's very next character (can be \, a, n, t, ,f, ", ', etc) must be copied literally.
- & must be placed 'before the very same letter in the translation since it indicates the combination ALT+letter that will select that option.
- The ending space is left since in the original message it was there. Never remove startng or ending spaces, even if they look ugly. They are there for some reason. Nomally this will be because either before or after that string comes another string. For example: "Opening file " has a blank space at the end, so you can expect that right after it the name of a file will be displayed. Something like Opening file server.met