home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part03 / bbscmisc.c < prev   
C/C++ Source or Header  |  1992-09-08  |  2KB  |  132 lines

  1.  
  2. #include "bbscdef.h"
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7.  
  8. strfill(buf,fillchar,length)    /* fill a string with fillchar */
  9. char    *buf;            /*  for length -1 */
  10. int    fillchar,
  11.     length;
  12.     {
  13.     while(--length)        /* really is length -1 */
  14.         {
  15.         *buf++ = fillchar;
  16.         }
  17.     *buf++ = '\0';        /* need room for this */
  18.     }
  19. #ifndef ATT3B1
  20.  
  21. substr(from,to,start,length)    /* moves chars from "from" to "to" */
  22. char    *from, *to ;        /*  starting at "start" for */
  23.                     /*  "length" number of chars */
  24. int    start, length ;        /* for beginning of string use 1, not 0 */
  25.     {
  26.     int    cnt;
  27.  
  28.     cnt = 0;
  29.  
  30.     while(--start)        /* adjust sending field pointer */
  31.         {
  32.         from++;        
  33.         }
  34.  
  35.     while((cnt < length) && (*to++ = *from++))    /* do the moving */
  36.         {
  37.         cnt++;        
  38.         }
  39.     
  40.     *to = '\0';
  41.  
  42.     }
  43. #endif
  44.  
  45. #ifdef ATT3B1
  46.  
  47. substr(from,to,start,length)
  48. char *from,*to;
  49. int start,length;
  50. {
  51.    int cnt, i;
  52.  
  53.    cnt = 0;
  54.    while(--start)
  55.        from++;
  56.  
  57.    i=0;
  58.    while(cnt < length)
  59.       if (from[i] == NULL)
  60.          break;
  61.       else {
  62.          to[i] = from[i];
  63.          i++;
  64.          cnt++;
  65.      }
  66.  
  67.    to[i] = NULL;
  68. }
  69.  
  70. #endif
  71.  
  72. itoa(str,n)        /* taken from float.c */
  73. char *str;
  74.     {
  75.     sprintf(str,"%d",n) ;
  76.     }
  77. /*    end of function        */
  78.  
  79. seek(fildes,posit,dummy) int fildes,posit,dummy ;
  80.     {
  81. long    pos;
  82.     pos = posit * 128L ;
  83. /*    return(lseek(fildes,posit << 7,0)) ;    */
  84.     return(lseek(fildes,pos,0)) ;
  85.     }
  86. /*    end of function        */
  87.  
  88. char *basename(x)  char *x;
  89. {
  90.     char *ptr;
  91.     ptr = strrchr(x, '/');
  92.     if ( ptr == (char *)NULL )
  93.         return(x);
  94.     else
  95.         return(++ptr);
  96. }
  97.  
  98. int legalname( co, strg )
  99. char *co, *strg;
  100. {
  101.     char *ptr, *indx;
  102.     int i;
  103.     ptr = co;
  104.     while ( *ptr ) {
  105.         i = (int) *ptr++;
  106.         indx = strchr(strg, i);
  107.         if ( indx != NULL )
  108.             return(0);
  109.     }
  110.     return(1);
  111. }
  112.  
  113. int asciicheck(fne)
  114. char *fne;
  115. {
  116.     FILE *tbuf;
  117.     int datar;
  118.     if((tbuf = fopen(fne, "r")) == NULL )
  119.         return(0);
  120.     while ((datar = getc(tbuf)) != EOF ) {
  121.         if(isprint(datar) == 0 && isspace(datar) == 0) {
  122.             fclose(tbuf);
  123.             return(0);
  124.         }
  125.     }
  126.     fclose(tbuf);
  127.     return(1);
  128. }
  129.     
  130.     
  131. /*    end of program      */
  132.