[comp.windows.x] Wcl Version 1.03 Minor Fix

david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) (08/07/90)

If you have had problems compiling the latest version
of the Widget Creation Library, Mri, and Ari when using
SunOS 4.0 cc, it is because I used the ANSI C library function
strstr in WcCallb.c

Here are the 3 places strstr is referenced in WcCallb.c:
    /* Try this heuristic: if the resource type has "Widget" somewhere within
    ** it, then see if we can convert the resource value to a widget using
    ** WcFullNameToWidget.  This allow relative naming from the calling
    ** widget, including `this' or ^^foobar.
    ** strstr( res_type, "Widget") returns NULL if "Widget" is not in res_type
    */
    if ( strstr( res_type, "Widget")
#ifdef MOTIF
        || strstr( res_type, "Window")  /* wrong: but that's a menuWidget */
#endif
        )

You can change the `strstr' to `strtok' and everything will work fine.

This fix will be in Wc 1.04.

-------------------------------------------------------------------------
David Smyth                             david@jpl-devvax.jpl.nasa.gov
Senior Software Engineer,               seismo!cit-vax!jpl-devvax!david
X and Object Guru.                      (818)393-0983
Jet Propulsion Lab, M/S 230-103, 4800 Oak Grove Drive, Pasadena, CA 91109
--------------------------- Quote of the Day: ---------------------------
   "A Guru is not one who simply knows all the answers.  Rather, a
    Guru is like one who walks among the mountains, and by wandering
    around abit, can see the horizon through long narrow canyons."
-------------------------------------------------------------------------

guy@auspex.auspex.com (Guy Harris) (08/08/90)

 >    if ( strstr( res_type, "Widget")
 >#ifdef MOTIF
 >        || strstr( res_type, "Window")  /* wrong: but that's a menuWidget */
 >#endif
 >        )
 >
 >You can change the `strstr' to `strtok' and everything will work fine.

If that's true, it's sure a lucky coincidence, as "strstr()" and
"strtok()" don't do anything very much related....

An N*M-time implementation of "strstr()" isn't that hard to do.

david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) (08/08/90)

guy@auspex.auspex.com (Guy Harris) writes:
>david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) writes:
> >    if ( strstr( res_type, "Widget")
> >#ifdef MOTIF
> >        || strstr( res_type, "Window")  /* wrong: but that's a menuWidget */
> >#endif
> >        )
> >
> >You can change the `strstr' to `strtok' and everything will work fine.
>
>If that's true, it's sure a lucky coincidence, as "strstr()" and
>"strtok()" don't do anything very much related....
>
>An N*M-time implementation of "strstr()" isn't that hard to do.

OK, OK, OK!  You are right, I was just lucky in my 10 second test...
strtok and strstr are rather different.  Here is a quick implementation
of strstr which seems to work.  I did not copy anybody elses, so you
don't have to worry about copyleft or copyright or whatever.  Please,
please, please, use an ANSI C compiler (e.g., gcc) if you can.  I
don't want to start supporting an ANSI C library!!!!!!!

For you hapless people out there who get "_strstr undefined" errors
when compiling WcCallb.c in Wcl version 1.03, just compile this and
include it on the load line:

/* copyright David E. Smyth 1990 */

char* strstr( s1, s2 )
    char* s1;
    char* s2;
{
    while (*s1)
    {
        if (*s1 == *s2)
        {
            char* start = s1;
            char* c = s2;
            while (*++s1 & *++c && *s1 == *c)
                ;
            if (*c == '\0')
                return start;
            else
                s1 = ++start;
        }
        else
        {
            s1++ ;
        }
    }
    return (char*)0;
}