home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d109 / uupc.lha / UUpc / Source / lib.c < prev    next >
C/C++ Source or Header  |  1987-10-28  |  2KB  |  147 lines

  1. /*         lib.c
  2.  
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <errno.h>
  8. #include "host.h"
  9.  
  10. #ifndef NULL
  11. #define NULL 0L
  12. #endif
  13.  
  14. char *index();
  15. char *rindex();
  16.  
  17. MKDIR( path )
  18. char * path;
  19. {
  20.     char * cp = path;
  21.  
  22.     if ( *cp == '\0' )
  23.         return( 0 );
  24.         
  25.     /* see if we need to make any intermediate directories */
  26.     while ( ( cp = index( cp, '/' ) ) != (char *) NULL ) {
  27.         *cp = '\0';
  28.         mkdir( path );
  29.         *cp = '/';        
  30.         cp++;
  31.     }
  32.  
  33.     /* make last dir */
  34.     return( mkdir( path ) );
  35.  
  36. }
  37.  
  38. CHDIR( path )
  39. char * path;
  40. {
  41.     char * cp = path;
  42.  
  43.     if ( *cp == '\0' )
  44.         return( 0 );
  45.  
  46.     MKDIR( path );
  47.     
  48.     /* change to last directory */
  49.     return( chdir( path ) );
  50.  
  51. }
  52.  
  53. FILE * FOPEN( name, mode, ftype )
  54. char * name;
  55. char * mode;
  56. char ftype;
  57. {
  58.  
  59.     char * last;
  60.     FILE * results;
  61.  
  62.     /* are we opening for write or append */
  63.  
  64.     FILEMODE( ftype );
  65.     results = fopen( name, mode );
  66.  
  67.     if ( results != (FILE *) NULL || *mode == 'r' )
  68.         return( results );
  69.  
  70.     /* are we opening in sub-directory */
  71.     last = rindex( name, '/' );
  72.  
  73.     /* lets just verify that all sub-dir's exist */
  74.     if ( last != (char *) NULL ) {
  75.         *last = '\0';
  76.         MKDIR( name );
  77.         *last = '/';
  78.     }
  79.  
  80.     /* now try open again */
  81.     return( fopen( name, mode ));
  82.  
  83. }
  84.  
  85. int CREAT( name, mode, ftyp )
  86. char * name;
  87. int mode;
  88. char ftyp;
  89. {
  90.  
  91.     char * last;
  92.     int results;
  93.  
  94.     /* are we opening for write or append */
  95.     FILEMODE( ftyp );
  96.     results = creat( name, mode );
  97.  
  98.     if ( results != -1 )
  99.         return( results );
  100.         
  101.     /* are we opening in sub-directory */
  102.     last = rindex( name, '/' );
  103.  
  104.     /* lets just verify that all sub-dir's exist */
  105.     if ( last != (char *) NULL ) {
  106.         *last = '\0';
  107.         MKDIR( name );
  108.         *last = '/';
  109.     }
  110.  
  111.     /* now try open again */
  112.     return( creat( name, mode ) );
  113.  
  114. }
  115.  
  116. extern FILE *logfile;
  117. extern int debuglevel;
  118. extern int remote;
  119.  
  120. #define MASTER 1
  121.  
  122.  
  123. int getargs( line, flds )
  124. char *line;
  125. char **flds;
  126. {
  127.     int i = 0;
  128.     char *s;
  129.  
  130.     while ( (*line != '\0') && (*line != '\n') )
  131.     {
  132.        if ( isspace(*line) )
  133.        {
  134.           line++;
  135.           continue;
  136.        }
  137.        *flds++ = line;
  138.        i++;
  139.        while( (isspace(*line) == 0) && (*line != '\0') ) line++;
  140.        if (isspace(*line)) *line++ = '\0';
  141.     }
  142.     return(i);
  143. }
  144.  
  145.  
  146.  
  147.