home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / FL_PATHS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  2.3 KB  |  122 lines

  1. /*********************
  2.  *
  3.  *  fl_paths.c - File and directory supplements.
  4.  *
  5.  *  Purpose: File handling utilities.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include <string.h>
  13. #include "blackstr.h"
  14. #include "sy_head.h"
  15.  
  16.  
  17. /********
  18.  *
  19.  *   fl_mkpath(path,dr,dir,name,ext) - make a pathname from strings
  20.  *
  21.  **/
  22.  
  23. void fl_mkpath(char *path, char *dr, char *dir,char *name, char *ext)
  24. {
  25.     *path='\0';
  26.     if(dr) {
  27.     strcat(path,strtok(dr," :\\"));
  28.     strcat(path,":");       /* put in drive name */
  29.     }
  30.     if((dir)&&(*dir))
  31.     strcat(path,strtok(dir," :"));
  32.     if(name) {
  33.     if( (strcmp(dir,"\\")) && (dr||dir) )
  34.         strcat(path,"\\");      /* dir separator */
  35.         strcat(path,strtok(name," \\."));
  36.     }
  37.     if(ext!=FALSE) {
  38.     if(!strchr(ext,'.'))
  39.         strcat(path,".");       /* separator if needed */
  40.         strcat(path,ext);
  41.     }
  42. }
  43.  
  44.  
  45. /********
  46.  *
  47.  *   fl_find(path) - find file name (uses global fdir_)
  48.  *
  49.  **/
  50.  
  51. char *fl_find(char *path)
  52. {
  53.     if(path)
  54.     return(sy_ffdir(path,0));       /* first time */
  55.     return(sy_fdir());                  /* subsequent ones */
  56. }
  57.  
  58.  
  59. /********
  60.  *
  61.  *   fl_files(fnames,fpath,ext_f) - get file names to array
  62.  *
  63.  **/
  64.  
  65. int fl_files(char *fnames,char *fpath, int ext_f)
  66. {
  67.     int i=0;
  68.     char *fptr;
  69.  
  70.     if((fptr=fl_find(fpath)) == 0)      /* get first name */
  71.     return(i);
  72.     else {
  73.     if(!ext_f)
  74.         fptr = strtok(fptr,".");
  75.     strcpy(fnames,fptr);
  76.     fnames += strlen(fptr)+1;
  77.     ++i;
  78.     }
  79.     while((fptr = fl_find(NULL)) != 0) {
  80.     if(!ext_f)
  81.         fptr = strtok(fptr,".");
  82.     strcpy(fnames,fptr);    /* put it in the buffer */
  83.     fnames+= strlen(fptr)+1;        /* add 1 for NUL */
  84.     ++i;
  85.     }
  86.     return(i);
  87. }
  88.  
  89. /********
  90.  *
  91.  *   fl_pathex(ext,path) - get extension from path
  92.  *
  93.  **/
  94.  
  95. void fl_pathex(char *ext, char *path)
  96. {
  97.     while(*path++!='.');    /* . delimites */
  98.     strcpy(ext,path);
  99. }
  100.  
  101.  
  102. /********
  103.  *
  104.  *   fl_pathnm(name,path) - get name from path
  105.  *
  106.  **/
  107.  
  108. void fl_pathnm(char *name, char *path)
  109. {
  110.     char *ptr;
  111.  
  112.     ptr = name;
  113.     while((*path) && (*path!='.')) {
  114.     if(*path=='\\')
  115.         ptr = name;     /* back to beginning */
  116.     else
  117.         *ptr++ = *path;
  118.     ++path;
  119.     }
  120.     *ptr = '\0';            /* null terminate it */
  121. }
  122.