January 2003 archive

More Weblogging

I restructured growlmurrdurr’s weblogging today to be a bit more sensical in directory usage, and exploit the power of Apache server config files more. Also, I added RSS feed capability into it. Wheeha. Still need to check all this into SVN, though.

COMImageLib

Once upon a time, in a galaxy far far away, I was writting a small piece of code to capture a screenshot in Windows. It wasn’t difficult to capture the screenshot, nor convert it to a device independant bitmap, nor output it as a .bmp file. But bmp files are huge, and these screenshots were going to be uploaded to a software issue tracking website. So, I decided to convert them to the much more compressable PNG image file format.

It would have been socially inacceptable for me to link libpng and zlib into the very low-level dll that this image capturing was being put into. I decided to make a COM module which would wrap libpng and zlib together. This way, the existence of the COM module could be detected and PNG files used, otherwise BMP files could be used as a last resort measure.

All this COM module can do is convert a BMP file to a PNG file. I hardly wrote any actual code, though. I yoinked the BMP -> PNG conversion from the web page of Jason Summers, and wrote a dead simple interface:

interface IPngImage : IDispatch
{
    [id(1), helpstring("method ConvertBMPToPNG")]
        HRESULT ConvertBMPToPNG([in] BSTR bsBMP, [in] BSTR bsPNG);
};

Happily this was all I needed. However, if you need something different, this COM module provides a nice framework for doing any work with PNG files since it statically links with pre-built libpng and zlib libraries (included in the source).

Source, Binary

Dictionary String Sorting

The following two functions define a method of comparing two strings. The method is similar to that implemented by strcmp, but differs in two ways. Whitespace within the strings is ignored, and numbers are compared numerically rather than character by character. ’10′ is greater than ’5′, for example.

/**
 * Determines whether a character is whitespace or not.
 */
int iswhitespace(char x)
{
    return x == ' ' || x == '\\n' || x == '\\r' || x == '\\t';
}

/**
 * qsort comparison function for 'dictionary' like string sorting.  Differs
 * from strcmp in two important ways.  1) "Baby Zoe" comes after "Babyface",
 * whitespace is ignored.  2) "5" comes before "10", numbers are sorted
 * numerically.
 *
 * @param       pStr1   Sort parameter 1. (ptr to char)
 * @param       pStr2   Sort parameter 2. (ptr to char)
 * @return      {-1, 0, 1} if pStr1 is {less than, equal to, greather than}
 *              pStr2.
 */
int dictionarySort(void* pStr1, void* pStr2)
{
    char* a = pStr1;
    char* b = pStr2;

    for (;;)
    {
        if (*a == *b && *a == '\\0')
            return 0;
        else if (*a == '\\0')
            return -1;
        else if (*b == '\\0')
            return 1;

        while (iswhitespace(*a) && *a != '\\0') a++;
        while (iswhitespace(*b) && *b != '\\0') b++;

        if (*a >= '0' && *a <= '9' &&
            *b >= '0' && *b <= '9')
        {
            /* a and b look to be pointing towards the start of numeric
             * strings! :) 
             */
            int nNumericA = atoi(a);
            int nNumericB = atoi(b);

            if (nNumericA < nNumericB)
                return -1;
            else if (nNumericA > nNumericB)
                return 1;

            while (*a >= '0' && *a <= '9' && *a != '\\0') a++;
            while (*b >= '0' && *b <= '9' && *b != '\\0') b++;
        }

        if (*a < *b)
            return -1;
        else if (*a > *b)
            return 1;

        a++;
        b++;
    }

    /* shut off compiler warnings. */
    return 0;
}

Internet Access

Finally got home Internet access today. Hooray.

Today sucked, though, in general. Our source control system at work was down in the morning due to database corruption. It was taking hours to run a repair utility, so Cecil and I went out and toured a near-to-nearby computer store out of boredom. Then we returned to work, found that the source control was still down, and left to go back to my home. We waited around for the ADSL installer, had lunch, and then decided to take the rest of the afternoon off too. We didn’t do anything all too productive. Mostly it was an exercise in not working out of spite.

It’s nice having Internet access. To be able to lay in bed and be online is comforting. Good night world.

The Joys of a New Home

On Monday, I will finally get Internet access at my home. Yay! The Nucleus installer is coming over at 1pm to setup my ADSL line. I’m so happy. The thought of having constantly accessable Internet access is so good. So often lately I’ve needed to use Google to find technical or other information and been unable to without slowly dialing up and blah blah blah and getting angry and smashing things. Or something.

Work is pretty busy. I’ve got a team of engineers as technical guidance people for a new piece of software. It’s less frustrating, more fun, and more rewarding than working on a project alone with no input. I’ve got a meeting on Tuesday which I’m kinda dreading.

Cecil and I spent about 5 hours last night playing Master of Orion 2 at work, until we got tired and hungry and left for food. I came back over to his apartment this morning to continue the game, which took another 4 or so hours before we had happily genocided the galaxy into our own image. We went out, shopped around Future Shop, and then picked up Claudia at the airport after she arrived from her trip home.

I think tomorrow we might go out geocaching, so expect some new pictures and fun! I dunno where we’ll go, or what we’ll find, but I do know that Superman will protect us from the evil Lex Luthor.