Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!csd4.milw.wisc.edu!srcsip!tcnet!pwcs!stag!root From: dal@syntel.UUCP (Dale Schumacher) Newsgroups: comp.sys.atari.st Subject: Re: string comparisons in C Message-ID: <1989Jul16.034109.16508@stag.UUCP> Date: 16 Jul 89 03:41:09 GMT Sender: root@stag.UUCP (Computer Abuser) Organization: Mindtools ST Access Group Lines: 57 [covertr@gtephx.UUCP (Richard E. Covert) writes...] > But, I was browsing thru the MWC manual, and lo and behold I see > pnmatch(). Now pnmatch is a wonderful little function which does string > comparisons. And it even accepts wildcards, so I was in business. I just > build an array of strings such as "*.PI1", and then by looping thru the > array I can string compare a user inputted filename against the list of > legal filetypes. Pretty neat solution. > > So, the moral of this little ditty, is READ YOUR MANUAL!! > > P.S. Does anyone know if pnmatch() is implemented on other C compilers?? dLibs contains several useful (though non-standard) functions, including some things which are similar in application to pnmatch(). Here are a few relevent description from the dLibs "manual". char *findfile(char *afn[, *ext]) Return full file spec for if found. If has no extension, extensions from are tried until a match is found, or the list ends. is a list of extensions separated by '\0' characters and ending with an additional '\0', ie. ".ttp\0.tos\0.prg\0" (note that the final null is added by the compiler to any string constant. If already has an extension, is not used. If no matching files are found, NULL is returned. The pointer returned when a match is found points to a buffer which is internal to fullpath(). If you want to save the value returned, you must make a copy before the buffer is overwritten by subsequent calls. Note: several dLibs functions call filefind(), so don't make too many assumptions about how long the internal buffer is going to stay valid. char *pfindfile(char *path, *afn[, *ext]) Like findfile() but search all directories (separated by ',' or ';') in . If is NULL, the "PATH" environment variable is used instead. If specifies a drive or directory, is not used. The internal buffer for findfile() is used by pfindfile(). char *wildcard(char *pathname) Return matches for a wildcard filename. If is not NULL, the first file which matches will be returned. The may contain wildcards only in the filename portion, not in any sub-directories. Subsequent calls to wildcard() with a NULL argument return the next matching filename. NULL is returned when no more files match. Note: the pointer returned points to an internal buffer which is overwritten with each call. It should not be modified, and should be copied into a safe place if you want to save the value. ...etc...there are more. Your moral is quite accurate. You'd be surprised how much interesting code you can find that has been provided for you. In addition, at least with dLibs, you have the source code, so you can actually include the routine directly when porting to a non-dLibs environment. \\ / Dale Schumacher 399 Beacon Ave. \\ / (alias: Dalnefre') St. Paul, MN 55104-3527 >< ...umn-cs!midgard.mn.org!syntel!dal United States of America / \\ "What is wanted is not the will to believe, but the will to find out, / \\ which is the exact opposite." -Bertrand Russell