1 |
/* |
/* |
2 |
* yow.c |
* yow.c |
3 |
* |
* |
4 |
* Print a quotation from Zippy the Pinhead. |
* Print a quotation from Zippy the Pinhead. |
5 |
* Qux <Kaufman-David@Yale> March 6, 1986 |
* Qux <Kaufman-David@Yale> March 6, 1986 |
6 |
* |
* |
7 |
* This file is in the public domain because the author published it |
* This file is in the public domain because the author published it |
8 |
* with no copyright notice before the US signed the Bern Convention. |
* with no copyright notice before the US signed the Bern Convention. |
9 |
* |
* |
10 |
* With dynamic memory allocation. |
* With dynamic memory allocation. |
11 |
*/ |
*/ |
12 |
|
|
16 |
|
|
17 |
#include <stdio.h> |
#include <stdio.h> |
18 |
#include <ctype.h> |
#include <ctype.h> |
|
#ifdef HAVE_STRING_H |
|
|
#include <string.h> |
|
|
#endif |
|
19 |
#ifdef TIME_WITH_SYS_TIME |
#ifdef TIME_WITH_SYS_TIME |
20 |
#include <sys/time.h> |
#include <sys/time.h> |
21 |
#include <time.h> |
#include <time.h> |
50 |
&res;}) |
&res;}) |
51 |
#endif |
#endif |
52 |
|
|
|
#ifndef HAVE_STDLIB_H |
|
|
char *malloc __P ((size_t size))), *realloc __P ((POINTER_TYPE *ptr, size_t size)); |
|
|
#endif |
|
|
|
|
53 |
void yow(); |
void yow(); |
54 |
void setup_yow(); |
void setup_yow(); |
55 |
|
|
110 |
header_len = ftell(fp); |
header_len = ftell(fp); |
111 |
if (header_len > AVG_LEN) |
if (header_len > AVG_LEN) |
112 |
header_len -= AVG_LEN; /* allow the first quotation to appear */ |
header_len -= AVG_LEN; /* allow the first quotation to appear */ |
113 |
|
|
114 |
if (fseek(fp, 0L, 2) == -1) { |
if (fseek(fp, 0L, 2) == -1) { |
115 |
perror("yow"); |
perror("yow"); |
116 |
exit(1); |
exit(1); |
154 |
} |
} |
155 |
|
|
156 |
bufsize = BUFSIZE; |
bufsize = BUFSIZE; |
157 |
buf = malloc(bufsize); |
buf = (char *) malloc(bufsize); |
158 |
if (buf == (char *)0) { |
if (buf == (char *)0) { |
159 |
fprintf(stderr, "yow: virtual memory exhausted\n"); |
fprintf(stderr, "yow: virtual memory exhausted\n"); |
160 |
exit (3); |
exit (3); |
163 |
buf[i++] = c; |
buf[i++] = c; |
164 |
while ((c = getc(fp)) != SEP && c != EOF) { |
while ((c = getc(fp)) != SEP && c != EOF) { |
165 |
buf[i++] = c; |
buf[i++] = c; |
166 |
|
|
167 |
if (i == bufsize-1) { |
if (i == bufsize-1) { |
168 |
/* Yow! Is this quotation too long yet? */ |
/* Yow! Is this quotation too long yet? */ |
169 |
bufsize *= 2; |
bufsize *= 2; |
170 |
buf = realloc(buf, bufsize); |
buf = (char *) realloc(buf, bufsize); |
171 |
if (buf == (char *)0) { |
if (buf == (char *)0) { |
172 |
fprintf(stderr, "yow: virtual memory exhausted\n"); |
fprintf(stderr, "yow: virtual memory exhausted\n"); |
173 |
exit (3); |
exit (3); |