annotate lib-src/yow.c @ 83310:e58cb448e07c

Merged from miles@gnu.org--gnu-2005 (patch 80-82, 350-422) Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-350 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-351 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-352 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-353 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-354 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-355 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-356 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-357 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-358 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-359 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-360 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-361 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-362 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-363 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-364 Remove "-face" suffix from widget faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-365 Remove "-face" suffix from custom faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-366 Remove "-face" suffix from change-log faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-367 Remove "-face" suffix from compilation faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368 Remove "-face" suffix from diff-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-369 lisp/longlines.el (longlines-visible-face): Face removed * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-370 Remove "-face" suffix from woman faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371 Remove "-face" suffix from whitespace-highlight face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-372 Remove "-face" suffix from ruler-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373 Remove "-face" suffix from show-paren faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-374 Remove "-face" suffix from log-view faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375 Remove "-face" suffix from smerge faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-376 Remove "-face" suffix from show-tabs faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-377 Remove "-face" suffix from highlight-changes faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-378 Remove "-face" suffix from and downcase info faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-379 Remove "-face" suffix from pcvs faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-380 Update uses of renamed pcvs faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-381 Tweak ChangeLog * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-382 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-383 Remove "-face" suffix from strokes-char face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-384 Remove "-face" suffix from compare-windows face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-385 Remove "-face" suffix from calendar faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-386 Remove "-face" suffix from diary-button face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-387 Remove "-face" suffix from testcover faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-388 Remove "-face" suffix from viper faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-389 Remove "-face" suffix from org faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-390 Remove "-face" suffix from sgml-namespace face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-391 Remove "-face" suffix from table-cell face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-392 Remove "-face" suffix from tex-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-393 Remove "-face" suffix from texinfo-heading face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-394 Remove "-face" suffix from flyspell faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-395 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-396 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-397 Remove "-face" suffix from gomoku faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-398 Remove "-face" suffix from mpuz faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-399 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-400 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-401 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-402 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-403 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-404 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-405 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-406 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-407 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-408 Remove "-face" suffix from Buffer-menu-buffer face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-409 Remove "-face" suffix from antlr-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-410 Remove "-face" suffix from ebrowse faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-411 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-412 Remove "-face" suffix from flymake faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-413 Remove "-face" suffix from idlwave faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414 Remove "-face" suffix from sh-script faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-415 Remove "-face" suffix from vhdl-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-416 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417 Remove "-face" suffix from which-func face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-418 Remove "-face" suffix from cperl-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-419 Remove "-face" suffix from ld-script faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-420 Fix cperl-mode font-lock problem * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421 Tweak which-func face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-422 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-80 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-81 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-82 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-350
author Karoly Lorentey <lorentey@elte.hu>
date Wed, 15 Jun 2005 12:57:51 +0000
parents 00adf45090ee
children 1a11061f92fa 5b029ff3b08d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
1 /*
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
2 * yow.c
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49361
diff changeset
3 *
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 * Print a quotation from Zippy the Pinhead.
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 * Qux <Kaufman-David@Yale> March 6, 1986
11183
2f57a6fbd720 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 10198
diff changeset
6 *
2f57a6fbd720 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 10198
diff changeset
7 * This file is in the public domain because the author published it
2f57a6fbd720 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 10198
diff changeset
8 * with no copyright notice before the US signed the Bern Convention.
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49361
diff changeset
9 *
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
10 * With dynamic memory allocation.
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 */
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
42412
83c1951257f1 Include <config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 42151
diff changeset
13 #ifdef HAVE_CONFIG_H
83c1951257f1 Include <config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 42151
diff changeset
14 #include <config.h>
83c1951257f1 Include <config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 42151
diff changeset
15 #endif
83c1951257f1 Include <config.h>.
Pavel Janík <Pavel@Janik.cz>
parents: 42151
diff changeset
16
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
17 #include <stdio.h>
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
18 #include <ctype.h>
42131
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
19 #ifdef TIME_WITH_SYS_TIME
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
20 #include <sys/time.h>
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
21 #include <time.h>
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
22 #else
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
23 #ifdef HAVE_SYS_TIME_H
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
24 #include <sys/time.h>
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
25 #else
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
26 #include <time.h>
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
27 #endif
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
28 #endif
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
29 #ifdef HAVE_UNISTD_H
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
30 #include <unistd.h>
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
31 #endif
c8cfb8893fac Conditionally include various headers. Use "epaths.h",
Dave Love <fx@gnu.org>
parents: 24408
diff changeset
32 #include "epaths.h" /* For PATH_DATA. */
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
33
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
34 #define BUFSIZE 80
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 #define SEP '\0'
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
36
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
37 #ifndef YOW_FILE
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 #define YOW_FILE "yow.lines"
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
39 #endif
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
7820
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
41 #ifdef MSDOS
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
42 #define rootrelativepath(rel) \
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
43 ({\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
44 static char res[BUFSIZE], *p;\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
45 strcpy (res, argv[0]);\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
46 p = res + strlen (res);\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
47 while (p != res && *p != '/' && *p != '\\' && *p != ':') p--;\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
48 strcpy (p + 1, "../");\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
49 strcpy (p + 4, rel);\
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
50 &res;})
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
51 #endif
128950f29e66 (rootrelativepath) [MSDOS]: Define, expanding to dynamic
Richard M. Stallman <rms@gnu.org>
parents: 4702
diff changeset
52
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
53 void yow();
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
54 void setup_yow();
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
55
9491
dd3b83e4ceb0 Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents: 7820
diff changeset
56 int
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 main (argc, argv)
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 int argc;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 char *argv[];
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 {
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 FILE *fp;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 char file[BUFSIZ];
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 if (argc > 2 && !strcmp (argv[1], "-f"))
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 strcpy (file, argv[2]);
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 else
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 #ifdef vms
443
78165914b12d entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 42
diff changeset
68 sprintf (file, "%s%s", PATH_DATA, YOW_FILE);
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 #else
443
78165914b12d entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 42
diff changeset
70 sprintf (file, "%s/%s", PATH_DATA, YOW_FILE);
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 #endif
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 if ((fp = fopen(file, "r")) == NULL) {
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
74 fprintf(stderr, "yow: ");
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 perror(file);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
76 exit(EXIT_FAILURE);
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 }
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 /* initialize random seed */
42151
e9a441eabced (main): Use time_t, not long, to avoid a compiler warning.
Eli Zaretskii <eliz@gnu.org>
parents: 42131
diff changeset
80 srand((int) (getpid() + time((time_t *) 0)));
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
82 setup_yow(fp);
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 yow(fp);
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 fclose(fp);
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
85 return EXIT_SUCCESS;
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 }
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
88 static long len = -1;
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
89 static long header_len;
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
90
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
91 #define AVG_LEN 40 /* average length of a quotation */
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
92
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
93 /* Sets len and header_len */
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
94 void
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
95 setup_yow(fp)
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
96 FILE *fp;
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
97 {
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
98 int c;
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
99
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
100 /* Get length of file */
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
101 /* Because the header (stuff before the first SEP) can be very long,
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
102 * thus biasing our search in favor of the first quotation in the file,
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
103 * we explicitly skip that. */
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
104 while ((c = getc(fp)) != SEP) {
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
105 if (c == EOF) {
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
106 fprintf(stderr, "yow: file contains no separators\n");
62694
00adf45090ee (setup_yow): Use EXIT_FAILURE in case no separators found.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 55442
diff changeset
107 exit(EXIT_FAILURE);
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
108 }
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
109 }
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
110 header_len = ftell(fp);
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
111 if (header_len > AVG_LEN)
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
112 header_len -= AVG_LEN; /* allow the first quotation to appear */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49361
diff changeset
113
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
114 if (fseek(fp, 0L, 2) == -1) {
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
115 perror("yow");
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
116 exit(EXIT_FAILURE);
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
117 }
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
118 len = ftell(fp) - header_len;
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
119 }
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
120
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
121
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
122 /* go to a random place in the file and print the quotation there */
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 void
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 yow (fp)
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 FILE *fp;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 {
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 long offset;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 int c, i = 0;
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
129 char *buf;
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
130 unsigned int bufsize;
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
132 offset = rand() % len + header_len;
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 if (fseek(fp, offset, 0) == -1) {
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
134 perror("yow");
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
135 exit(EXIT_FAILURE);
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 }
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 /* Read until SEP, read next line, print it.
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 443
diff changeset
139 (Note that we will never print anything before the first separator.)
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 If we hit EOF looking for the first SEP, just recurse. */
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 while ((c = getc(fp)) != SEP)
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 if (c == EOF) {
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 yow(fp);
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 return;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 }
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 /* Skip leading whitespace, then read in a quotation.
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 If we hit EOF before we find a non-whitespace char, recurse. */
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 while (isspace(c = getc(fp)))
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 if (c == EOF) {
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 yow(fp);
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 return;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 }
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
155
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
156 bufsize = BUFSIZE;
49802
dc31cb80909b (yow): Cast result of malloc and realloc.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
157 buf = (char *) malloc(bufsize);
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
158 if (buf == (char *)0) {
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
159 fprintf(stderr, "yow: virtual memory exhausted\n");
62694
00adf45090ee (setup_yow): Use EXIT_FAILURE in case no separators found.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 55442
diff changeset
160 exit (EXIT_FAILURE);
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
161 }
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
162
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 buf[i++] = c;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 while ((c = getc(fp)) != SEP && c != EOF) {
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 buf[i++] = c;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49361
diff changeset
166
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
167 if (i == bufsize-1) {
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 /* Yow! Is this quotation too long yet? */
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
169 bufsize *= 2;
49802
dc31cb80909b (yow): Cast result of malloc and realloc.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
170 buf = (char *) realloc(buf, bufsize);
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
171 if (buf == (char *)0) {
10198
aa59550d809f Include program name in error messages.
David J. MacKenzie <djm@gnu.org>
parents: 9491
diff changeset
172 fprintf(stderr, "yow: virtual memory exhausted\n");
62694
00adf45090ee (setup_yow): Use EXIT_FAILURE in case no separators found.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 55442
diff changeset
173 exit (EXIT_FAILURE);
42
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
174 }
71b3e30e0dd4 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 12
diff changeset
175 }
12
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 }
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 buf[i++] = 0;
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 printf("%s\n", buf);
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 }
4f420246a4f7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49802
diff changeset
181 /* arch-tag: e40fc0df-bafb-4001-af24-5c883d1c685e
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49802
diff changeset
182 (do not change this comment) */
55442
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
183
a47704955f8d Throughout, replace 0 destined for `exit' arg with `EXIT_SUCCESS'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
184 /* yow.c ends here */