Tom Collins writes: > Right now, for every string requested from the file, QmailAdmin scans > the entire file looking for it.
You mean that when displaying a single page it will scan the entire file for each substitution? And doesn't terminate the scan when it finds it? That's a little sub-optimal. Then again, it's not something you run every couple of minutes every day so a little inefficiency isn't as bad as it would be in, say, vdelivermail. > This scanning process won't take much longer than searching for a > string at the end of the file. Well, you'd want to malloc memory to avoid buffer overflows or string truncation, so that is going to slow it down compared to a single scan of the file the existing way. But overall I'd guess there will be a speed gain over repeated scans even if you had early termination and the OS cached the file contents so you didn't have to get it from disk more than once. BTW, make sure you allow for the final line in the file being immediately followed by EOF rather than LF and then EOF otherwise that string won't be null-terminated if all you do is substitute NUL for LF.. I can teach your grandmother how to suck eggs, too, if you want. :) > To allow for new strings, it will read in the English file as well, and > set pointers into it for any string not present in the requested > language. You mean read in the English file first, using your proposed scheme, then read in the appropriate language file and change the existing pointers if you find matching entries? Sounds sensible to me and avoids some extra conditionals. I wouldn't bother deleting the English entries if you find a match or trying to substitute the English string in place because the memory management overhead would be large. But perhaps you've already thought of all that. I just thought of some more nasties you have to watch out for, although you may have thought of them already. Watch out for lines which do not start with a positive integer. Watch out for lines being out of numerical sequence. Watch out for lines with a far higher number than you were expecting ever to occur (either ignore them or use a hash table instead of an array or it would be trivial to alter a translation file so it causes qmailadmin to eat all available memory). Watch out for the English file not having all the messages you expect (so check for null pointers to translations before attempting to substitute text). Any of those things could happen accidentally and cause mysterious problems. Some of them might also happen deliberately if a busy sysadmin accepts a new translation file from a 'helpful'volunteer without checking it (I prefer to have code check stuff like that rather than me having to check stuff like that). Yes, I know one should always check, but some people think a data file can't cause problems and give it only casual inspection, if at all, trusting the program to take appropriate precautions. Of course, the truly paranoid will run any contributed translation file through a translation program just to be on the safe side, or simply refuse to take candy from strangers. -- Paul Allen Softflare Support
