In FileIcon2.cxx

The code does an inefficient check for kdedir.  Either use the scandir utilities or...

Find the string "kde" in the user's PATH variable and back up to the start of that path then find the first occurrance of "/" and cut it there.
 
You'll start with something like this...

  .:/home/fltk2/usr32/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin

and end up with something like this.

  /opt/kde3 <-cut-> /bin

This could still miss, but in far fewer cases.  Here's a tester snip.

// find-kde.cpp
#include <string.h> // strdup()
#include <malloc.h> // free()
#include <stdlib.h> // getenv()
#include <stdio.h> // printf()
int main(int argc, char** argv)
{
  char* pathbuf = strdup(getenv("PATH"));
  char* starts = strstr(pathbuf, "kde");
  char* ends = starts;
  int err = 1; // assume the worst; ALL tests must pass.
  do
  {
    if(!starts)
      break;  // no luck.
    
    // scan back to start of string or start of buffer.
    while(( starts > pathbuf) && (*starts != ':'))
      starts--;
    
    // which was it?
    if(*starts == ':')
      starts++; // advance to actual path
    
    ends = strchr(ends, '/');
    
    if(ends)
      *ends = 0;
      
    // terminate string
    *ends = 0;
    
    // Now what if this was actually still two or more paths?  If there's
    // a colon separator, the kde hit did not have a "/bin" part.  This
    // SHOULD not happen for the PATH, but then who knows...
    // We'll just do a quick check in this version.
    
    if(strchr(starts, ':'))
      break; // no "bin" in the kde hit.
    
    err = 0;  // clear the error flag
    // kdedir = strdup(starts);
    printf("found kde here: %s\n", starts);
    
  }while(0); // don't loop
 
  free(pathbuf);
  return err;
}


Attached is the same routine, returning a const char* after checking for KDEDIR in the environment, and still setting the default to /usr if the path check fails.



It would be nicer against a lighter background but at least it's the right icon in the config I am using.

Attachment: FileIcon2.cxx.tar.gz
Description: GNU Zip compressed data

_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to