home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * fl_paths.c - File and directory supplements.
- *
- * Purpose: File handling utilities.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <string.h>
- #include "blackstr.h"
- #include "sy_head.h"
-
-
- /********
- *
- * fl_mkpath(path,dr,dir,name,ext) - make a pathname from strings
- *
- **/
-
- void fl_mkpath(char *path, char *dr, char *dir,char *name, char *ext)
- {
- *path='\0';
- if(dr) {
- strcat(path,strtok(dr," :\\"));
- strcat(path,":"); /* put in drive name */
- }
- if((dir)&&(*dir))
- strcat(path,strtok(dir," :"));
- if(name) {
- if( (strcmp(dir,"\\")) && (dr||dir) )
- strcat(path,"\\"); /* dir separator */
- strcat(path,strtok(name," \\."));
- }
- if(ext!=FALSE) {
- if(!strchr(ext,'.'))
- strcat(path,"."); /* separator if needed */
- strcat(path,ext);
- }
- }
-
-
- /********
- *
- * fl_find(path) - find file name (uses global fdir_)
- *
- **/
-
- char *fl_find(char *path)
- {
- if(path)
- return(sy_ffdir(path,0)); /* first time */
- return(sy_fdir()); /* subsequent ones */
- }
-
-
- /********
- *
- * fl_files(fnames,fpath,ext_f) - get file names to array
- *
- **/
-
- int fl_files(char *fnames,char *fpath, int ext_f)
- {
- int i=0;
- char *fptr;
-
- if((fptr=fl_find(fpath)) == 0) /* get first name */
- return(i);
- else {
- if(!ext_f)
- fptr = strtok(fptr,".");
- strcpy(fnames,fptr);
- fnames += strlen(fptr)+1;
- ++i;
- }
- while((fptr = fl_find(NULL)) != 0) {
- if(!ext_f)
- fptr = strtok(fptr,".");
- strcpy(fnames,fptr); /* put it in the buffer */
- fnames+= strlen(fptr)+1; /* add 1 for NUL */
- ++i;
- }
- return(i);
- }
-
- /********
- *
- * fl_pathex(ext,path) - get extension from path
- *
- **/
-
- void fl_pathex(char *ext, char *path)
- {
- while(*path++!='.'); /* . delimites */
- strcpy(ext,path);
- }
-
-
- /********
- *
- * fl_pathnm(name,path) - get name from path
- *
- **/
-
- void fl_pathnm(char *name, char *path)
- {
- char *ptr;
-
- ptr = name;
- while((*path) && (*path!='.')) {
- if(*path=='\\')
- ptr = name; /* back to beginning */
- else
- *ptr++ = *path;
- ++path;
- }
- *ptr = '\0'; /* null terminate it */
- }
-