home *** CD-ROM | disk | FTP | other *** search
- /*
- * anne.jones - anne.misc.c - 10/12/90
- *
- * Miscellaneous routines used by anne.jones
- */
-
- #include <stdio.h>
- #include <string.h>
- #ifndef AIX /* AIX doesn't have malloc.h. Oh well. */
- #include <malloc.h>
- #endif
- #include "anne.h"
-
- extern char *safemalloc(), *saferealloc(), *get_a_line();
-
- FILE *
- trypath(route, name)
- register char *route, *name;
- {
- register char *s;
-
- if ((s = safemalloc(strlen(route) + strlen(name) + 2)) == (char *) NULL) {
- perror("trypath safemalloc");
- exit(1);
- }
- strcpy(s, route);
- strcat(s, "/");
- strcat(s, name);
-
- return (fopen(s, "r"));
- }
-
- char *
- squeeze(str)
- char *str;
- {
- register char *s, *t, *u;
-
- #ifdef DEBUG
- fprintf(debug, "squeeze got ->%s<-\n", str);
- #endif
- s = str;
-
- /*
- worst case it'll be as long as s .. never longer
- */
- t = u = safemalloc(strlen(s) + 1);
-
- do {
- if (*s != ' ' && *s != '\t')
- *(t++) = *s;
- } while (*s++);
-
- *t = '\0';
- #ifdef DEBUG
- fprintf(debug, "squeeze gave back ->%s<-\n", u);
- #endif
- return (u);
- }
-
- void
- squeeze2(s)
- register char *s;
- {
- register char *t, *u, *orig;
-
- t = u = safemalloc(strlen(s) + 8);
- #ifdef DEBUG
- fprintf(debug, "squeeze2 got ->%s<-\n", s);
- #endif
- orig = s;
- do {
- if (!((*s < '\040') &&
- ((*s >= '\015') || (*s == '\013') || (*s < '\010'))
- )) {
- *(t++) = *s;
- }
- } while (*(++s));
- *t = '\0';
-
- strcpy(orig, u);
- #ifdef DEBUG
- fprintf(debug, "squeeze2 put ->%s<-\n", orig);
- #endif
- free(u);
- }
-
- char *
- getmname(f)
- FILE *f;
- {
- char *s, *t;
- s = safemalloc(NAMESIZE + 1);
- if ((get_a_line(s, NAMESIZE, f)) == (char *) NULL) {
- perror("getmname");
- exit(1);
- }
- fclose(f);
- if (*(t = (s + strlen(s) - 1)) == '\n')
- *t = '\0';
- return (s);
- }
-
- int
- know_head(s)
- char *s;
- {
- register char *t;
-
- if ((t = strstr(allheads, s)) != (char *) NULL)
- return (((t - allheads) / 13) + 1);
- else
- return (NOTKNOWN);
- }
-
- char **
- buildbook(dim)
- int dim;
- {
- register int i;
- register char *pages, **book;
-
- pages = safemalloc(dim * dim);
- if (pages == (char *)NULL) {
- fprintf(stderr, "No heap space for header book items!\n");
- exit(1);
- }
- book = (char **) calloc(dim, sizeof(char *));
- if (book == (char **)NULL) {
- fprintf(stderr, "No heap space for header book!\n");
- exit(1);
- }
- for (i = 0; i < dim; i++) {
- *(book + i) = pages;
- pages += dim;
- }
- return (book);
- }
-
- void
- termin()
- {
- creat("/tmp/termin", 0644);
- exit(0);
- }
-
- /* This was ripped from rn 4.3 */
-
- #ifndef HAVESTRSTR
- /* return ptr to little string in big string, NULL if not found */
- char *
- strstr(big, little)
- char *big, *little;
- {
- register char *t, *s, *x;
-
- for (t = big; *t; t++) {
- for (x = t, s = little; *s; x++, s++) {
- if (!*x)
- return ((char *) NULL);
- if (*s != *x)
- break;
- }
- if (!*s)
- return (t);
- }
- return ((char *) NULL);
- }
- #endif /* HAVESTRSTR */
-