Skip to main content.
home | support | download

Back to List Archive

Port of swish-e to Windows

From: Dirk Nerinckx <ind2443(at)not-real.club.innet.be>
Date: Fri Apr 10 1998 - 07:52:43 GMT
Hello,

I'm currently 'porting' SWISH-E to Windows95 and Windows NT using the Microsoft Visual C++ environment.

I have done the following tasks:

- prototyping all functions.
- Replacing opendir and readdir calls by Windows routines.
- Solving all warnings produced by the compiler.
- Replacing all int types by __int16 or __int32

After doing this, I noticed that the program sometimes worked and sometimes did not gave correct results.
I spent quite some time to find out what was happening.
First I figured out how the numbers were stored in the index file, each number is stored in a 128 radix system,
All 'digits' are incremented by 128, except the least significant 'digit'. This way, it is possible to detect the start of a new number in a row of numbers. A row of numbers is ended with a zero byte.
So far, so good, but...

In the function compress ( index.c), there is a very subtile bug:
Look at this loop:

while ( i-- >= 0)
       fputc(s[i] | (i ? 128 : 0), fp);

Because the post-decrement is done after the comparison, i becomes -1 in the loop, so s[-1] is written after each number ! 
Now, I was even more puzzled, because if this was the case , why did the program ever worked ?
After studying the pieces of code that read the numbers, I figured out that these random bytes were consistently skipped.
Only when s[-1] happens to be a zero byte, things go wrong, because zero signifies the end of a row of numbers and all subsequent numbers are ignored !
Furthermore, accessing s[-1] can give unpredictable effects too of course.

So, I changed the above loop to:

while ( --i >= 0)
       fputc(s[i] | (i ? 128 : 0), fp);

But then I had to change all the places where the numbers are read too.
After doing this , everything worked fine.

If anyone has more questions about the Windows code or is interested to have the code, please feel free to ask me.

Dr. Dirk Nerinckx
Wave Research, Belgium

Personal emails can be sent to:  enzo@skynet.be
Received on Fri Apr 10 01:03:13 1998