home *** CD-ROM | disk | FTP | other *** search
- /* str file name functions (for Lattice 3.0 port to MSC 4.0) */
-
- /* ------------------------------------------------------------ */
- /* copyright 1986: */
- /* Nourse Gregg & Browne, Inc. */
- /* 1 Horizon Road. #612 */
- /* Fort Lee, NJ 07024 */
- /* */
- /* ------------------------------------------------------------ */
-
- #include <stdlib.h>
- #include <string.h>
- #include <stddef.h>
-
- #define ZIP '\0'
-
- /* ------------------------------------------------------------ */
- /* strsfn - split filename into components */
-
-
- void strsfn(file,drive,path,node,ext)
-
- char *file; /* input: the whole file name */
- char *drive; /* output: the drive */
- char *path; /* output: the sub-directory path */
- char *node; /* output: the file's base name */
- char *ext; /* output: the file's extension */
- {
- char *p;
- char fn[64];
-
- strncpy(fn,file,63);
- p=strrchr(fn,'.'); /* find start of extension */
- if (p==NULL) *ext=ZIP;
- else
- {
- *p=ZIP;
- strcpy(ext,p+1);
- }
- p=strrchr(fn,'\\'); /* find end of path */
- if (p==NULL)
- {
- *path=ZIP;
- p=strrchr(fn,':');
- if (p==NULL)
- {
- strcpy(node,fn);
- *drive=ZIP;
- }
- else
- {
- strcpy(node,p+1);
- *(p+1)=ZIP;
- strcpy(drive,fn);
- }
- }
- else
- {
- *p=ZIP;
- strcpy(node,p+1);
- p=strrchr(fn,':');
- if (p==NULL)
- {
- strcpy(path,fn);
- *drive=ZIP;
- }
- else
- {
- strcpy(path,p+1);
- *(p+1)=ZIP;
- strcpy(drive,fn);
- }
- }
- }
-
-
-
- /* ------------------------------------------------------------ */
- /* strmfe - make filename with new extension */
-
-
- void strmfe(newname,oldname,ext)
-
- char *newname; /* output: the new file name */
- char *oldname; /* input: the old file name */
- char *ext; /* input: the new extension */
- {
- char *p;
-
- strcpy(newname,oldname);
- p=strrchr(newname,'.');
- if (p==NULL)
- {
- strcat(newname,".");
- strcat(newname,ext);
- }
- else
- {
- strcpy(p+1,ext);
- }
- }
-
-
-
-
- /* ------------------------------------------------------------ */
- /* strmfn - make filename from components */
-
-
- void strmfn(file,drive,path,node,ext)
-
- char *file; /* output: the whole file name */
- char *drive; /* input: the drive (or NULL) */
- char *path; /* input: the directory path (or NULL) */
- char *node; /* input: the file's base name */
- char *ext; /* input: the file's extension (or NULL) */
- {
- int i;
-
- *file='\0';
- if (drive!=NULL)
- {
- strcat(file,drive);
- if (file[1]!=':') strcat(file,":");
- }
- if (path!=NULL)
- {
- strcat(file,path);
- i=strlen(file);
- if (file[i-1]!='\\')
- {
- file[i]='\\';
- file[i+1]='\0';
- }
- }
- if (node!=NULL) strcat(file,node);
- if (ext!=NULL)
- {
- strcat(file,".");
- strcat(file,ext);
- }
- }