/* © 2000 Compaq Computer Corporation COMPAQ Registered in U.S. Patent and Trademark Office. Confidential computer software. Valid license from Compaq required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. */ /* ** StripName - Strips a filename of all except the name part ** ** Usage: ** char *StripName(); ** char *result; ** char filename[]; ** ** result = StripName(filename); ** ** Notes: ** The returned string is in allocated memory and should be ** freed when no longer required. ** ** There is no check to see if the malloc() fails, i.e. the ** program will bomb with an access violation if there is no ** more memory to be had. The chances of this are very slim. ** ** This code should work on VMS or U*IX. ** ** Shamelessly stolen from BITMAP.C and modified for VMS. ** Normal MIT copyright applies. ** ** Trevor Taylor - 24-Feb-1991 */ char *StripName(name) /*--- Strip out a file name ---*/ char *name; { #ifdef VMS char *begin = strrchr(name, ']'); char *end, *result; int length; /* Try '>' so it will work for the Europeans too */ if (!begin) begin = strrchr(name, '>'); /* Look for ':' if no ']', i.e. may be a logical name prefix */ if (!begin) begin = strrchr(name, ':'); begin = (begin ? begin+1 : name); end = strrchr(begin, '.'); /* Use strrchr to be safe */ /* Just in case there is no filetype, look for version number */ if (!end) end = strchr(begin, ';'); #else char *begin = rindex(name, '/'); char *end, *result; int length; begin = (begin ? begin+1 : name); end = index(begin, '.'); /* change to rindex to allow longer names */ #endif length = (end ? (end - begin) : strlen (begin)); result = (char *) malloc(length + 1); strncpy(result, begin, length); result[length] = '\0'; return(result); } /*** End StripName() ***/