[jsword-devel] Module Installation
Wed, 04 Feb 2004 19:59:04 -0500
On Wed, 2004-02-04 at 18:56, Joe Walker wrote:
> I got an answer to the module installation problem on sword-devel, now I
> just need to understand it!
> I know from the mail below what the c++ code does to download modules,
> but I don't know c++ so I'm struggling. Can anyone help?
> I was trying to understand where AbsoluteDataPath comes from and I came
> across this line:
> for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 ==
> '\\'))); buf2++);
> And my brain crashed.
Ah. Quite understandable. Let me rewrite the above expression:
1 for (
2 /* no initial condition */;
3 ( (*buf2) &&
4 ( (*buf2 == '.' ) || (*buf2 == '/') || (*buf2 == '\\') ) );
5 buf2++ )
6 /* do nothing */;
I assume buf2 is a char * or some kind of string iterator that pretends
it's a char *. In C, strings terminate with a null ('\0'). And boolean
conditions are numbers where 0 = false and anything else is true. So
the above statement is "loop while [condition in lines 3-4] is true,
moving the buf2 pointer one character further along the string each time
through the loop (line 5)." Presumably buf2 starts out pointing to the
beginning of the string. Since booleans are numbers, line 2 is
equivalent to (*buf2 != 0), or (*buf2 != '\0') -- i.e., "the character
pointed to by buf2 is not the null character", which, being translated,
means, "buf2 doesn't point to the end of the string". Line 3 means, as
you can probably tell, "the character pointed to by buf2 is ., /, or
\". Therefore, the whole expression means, "Advance buf2 along the
string until it hits the end of the string or a ., /, or \". So on the
line after the above expression, buf2 will be pointing at either the end
of the string, in which case *buf2 == 0, or a dot, slash, or backslash,
in which case *buf2 is that character.
Phew. Clear as mud?