home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2032 / anne.misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  2.8 KB  |  170 lines

  1. /*
  2.  * anne.jones - anne.misc.c - 10/12/90
  3.  *
  4.  * Miscellaneous routines used by anne.jones
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #ifndef AIX        /* AIX doesn't have malloc.h.  Oh well. */
  10. #include <malloc.h>
  11. #endif
  12. #include "anne.h"
  13.   
  14. extern char    *safemalloc(), *saferealloc(), *get_a_line();
  15.  
  16. FILE *
  17. trypath(route, name)
  18.      register char *route, *name;
  19. {
  20.   register char *s;
  21.   
  22.   if ((s = safemalloc(strlen(route) + strlen(name) + 2)) == (char *) NULL) {
  23.     perror("trypath safemalloc");
  24.     exit(1);
  25.   }
  26.   strcpy(s, route);
  27.   strcat(s, "/");
  28.   strcat(s, name);
  29.   
  30.   return (fopen(s, "r"));
  31. }
  32.  
  33. char *
  34. squeeze(str)
  35.      char *str;
  36. {
  37.   register char *s, *t, *u;
  38.  
  39. #ifdef    DEBUG
  40.   fprintf(debug, "squeeze got ->%s<-\n", str);
  41. #endif
  42.   s = str;
  43.   
  44.   /*
  45.     worst case it'll be as long as s .. never longer
  46.     */
  47.   t = u = safemalloc(strlen(s) + 1);
  48.   
  49.   do {
  50.     if (*s != ' ' && *s != '\t')
  51.       *(t++) = *s;
  52.   } while (*s++);
  53.   
  54.   *t = '\0';
  55. #ifdef    DEBUG
  56.   fprintf(debug, "squeeze gave back ->%s<-\n", u);
  57. #endif
  58.   return (u);
  59. }
  60.  
  61. void
  62. squeeze2(s)
  63.      register char *s;
  64. {
  65.   register char *t, *u, *orig;
  66.  
  67.   t = u = safemalloc(strlen(s) + 8);
  68. #ifdef    DEBUG
  69.   fprintf(debug, "squeeze2 got ->%s<-\n", s);
  70. #endif
  71.   orig = s;
  72.   do {
  73.     if (!((*s < '\040') &&
  74.       ((*s >= '\015') || (*s == '\013') || (*s < '\010'))
  75.       )) {
  76.       *(t++) = *s;
  77.     }
  78.   } while (*(++s));
  79.   *t = '\0';
  80.   
  81.   strcpy(orig, u);
  82. #ifdef    DEBUG
  83.   fprintf(debug, "squeeze2 put ->%s<-\n", orig);
  84. #endif
  85.   free(u);
  86. }
  87.  
  88. char *
  89. getmname(f)
  90.      FILE *f;
  91. {
  92.   char *s, *t;
  93.   s = safemalloc(NAMESIZE + 1);
  94.   if ((get_a_line(s, NAMESIZE, f)) == (char *) NULL) {
  95.     perror("getmname");
  96.     exit(1);
  97.   }
  98.   fclose(f);
  99.   if (*(t = (s + strlen(s) - 1)) == '\n')
  100.     *t = '\0';
  101.   return (s);
  102. }
  103.  
  104. int
  105. know_head(s)
  106.      char *s;
  107. {
  108.   register char *t;
  109.   
  110.   if ((t = strstr(allheads, s)) != (char *) NULL)
  111.     return (((t - allheads) / 13) + 1);
  112.   else
  113.     return (NOTKNOWN);
  114. }
  115.  
  116. char **
  117. buildbook(dim)
  118.      int dim;
  119. {
  120.   register int i;
  121.   register char *pages, **book;
  122.   
  123.   pages = safemalloc(dim * dim);
  124.   if (pages == (char *)NULL) {
  125.     fprintf(stderr, "No heap space for header book items!\n");
  126.     exit(1);
  127.   }
  128.   book = (char **) calloc(dim, sizeof(char *));
  129.   if (book == (char **)NULL) {
  130.     fprintf(stderr, "No heap space for header book!\n");
  131.     exit(1);
  132.   }
  133.   for (i = 0; i < dim; i++) {
  134.     *(book + i) = pages;
  135.     pages += dim;
  136.   }
  137.   return (book);
  138. }
  139.  
  140. void
  141. termin()
  142. {
  143.   creat("/tmp/termin", 0644);
  144.   exit(0);
  145. }
  146.  
  147. /* This was ripped from rn 4.3 */
  148.  
  149. #ifndef    HAVESTRSTR
  150. /* return ptr to little string in big string, NULL if not found */
  151. char *
  152. strstr(big, little)
  153.      char *big, *little;
  154. {
  155.   register char *t, *s, *x;
  156.   
  157.   for (t = big; *t; t++) {
  158.     for (x = t, s = little; *s; x++, s++) {
  159.       if (!*x)
  160.     return ((char *) NULL);
  161.       if (*s != *x)
  162.     break;
  163.     }
  164.     if (!*s)
  165.       return (t);
  166.   }
  167.   return ((char *) NULL);
  168. }
  169. #endif    /* HAVESTRSTR */
  170.