aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorKaroly Lorentey2006-06-12 07:27:12 +0000
committerKaroly Lorentey2006-06-12 07:27:12 +0000
commit476e9367ec1f440aa23904b7bc482ea4a3b8041c (patch)
tree4f7f5a5e9a6668f908834bb6e216c8fa3727d4b3 /lib-src
parenta13f8f50d4cc544d3bbfa78568e82ce09e68bded (diff)
parent6b519504c3297595101628e823e72c91e562ab45 (diff)
downloademacs-476e9367ec1f440aa23904b7bc482ea4a3b8041c.tar.gz
emacs-476e9367ec1f440aa23904b7bc482ea4a3b8041c.zip
Merged from emacs@sv.gnu.org.
Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-294 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-295 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-296 Update from CVS: admin/FOR-RELEASE: Update refcard section. * emacs@sv.gnu.org/emacs--devo--0--patch-297 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-298 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-299 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-300 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-301 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-302 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-303 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-304 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-103 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-104 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-570
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog37
-rw-r--r--lib-src/Makefile.in5
-rw-r--r--lib-src/digest-doc.c11
-rw-r--r--lib-src/ebrowse.c22
-rw-r--r--lib-src/leditcfns.c21
-rw-r--r--lib-src/makefile.w32-in34
-rw-r--r--lib-src/sorted-doc.c14
-rw-r--r--lib-src/yow.c185
8 files changed, 99 insertions, 230 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 9ba3191ed46..040f155221f 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,40 @@
12006-06-09 Eli Zaretskii <eliz@gnu.org>
2
3 * yow.c: Remove file.
4
5 * makefile.w32-in ($(BLD)/yow.$(O)): Remove target.
6
7 * Makefile.in (UTILITIES): Remove yow${EXEEXT}.
8 yow${EXEEXT}: Remove target.
9
102006-06-04 Masatake YAMATO <jet@gyve.org>
11
12 * ebrowse.c (main): Exit with EXIT_FAILURE if BROWSE file
13 doesn't exist, is not seekable, not is failed in ftall.
14
152006-06-03 Eli Zaretskii <eliz@gnu.org>
16
17 * makefile.w32-in (ALL): Add sorted-doc and digest-doc.
18 ($(BLD)/sorted-doc.exe, $(BLD)/digest-doc.exe)
19 ($(BLD)/test-distrib.exe): New targets.
20 (sorted-doc, digest-doc, test-distrib): New targets.
21 (install): Install sorted-doc.exe and digest-doc.exe.
22 ($(BLD)/sorted-doc.$(O)): Update dependencies.
23
24 * digest-doc.c [DOS_NT] <top level>: Include fcntl.h and io.h.
25 (main) [DOS_NT]: Switch stdin to binary mode, if it is not a
26 terminal device.
27
28 * sorted-doc.c [DOS_NT] <top level>: Include fcntl.h and io.h.
29 [WINDOWSNT] <top level>: Don't redeclare malloc.
30 (main) [DOS_NT]: Switch stdin to binary mode, if it is not a
31 terminal device.
32 (main): Initialize bp, to avoid compiler warnings
33
34 * makefile.w32-in: Delete traces of leditcfns.c.
35
36 * leditcfns.c: Remove file.
37
12006-05-23 Francesco Potort,Al(B <pot@gnu.org> 382006-05-23 Francesco Potort,Al(B <pot@gnu.org>
2 39
3 * pop.c (pop_open, socket_connection, KPOP_SERVICE): Added 40 * pop.c (pop_open, socket_connection, KPOP_SERVICE): Added
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in
index 85a7c13c95a..4eb1658ac0a 100644
--- a/lib-src/Makefile.in
+++ b/lib-src/Makefile.in
@@ -107,7 +107,7 @@ INSTALLABLE_SCRIPTS = rcs-checkin grep-changelog
107# Things that Emacs runs internally, or during the build process, 107# Things that Emacs runs internally, or during the build process,
108# which should not be installed in bindir. 108# which should not be installed in bindir.
109UTILITIES= profile${EXEEXT} digest-doc${EXEEXT} sorted-doc${EXEEXT} movemail${EXEEXT} cvtmail${EXEEXT} fakemail${EXEEXT} \ 109UTILITIES= profile${EXEEXT} digest-doc${EXEEXT} sorted-doc${EXEEXT} movemail${EXEEXT} cvtmail${EXEEXT} fakemail${EXEEXT} \
110 yow${EXEEXT} hexl${EXEEXT} update-game-score${EXEEXT} 110 hexl${EXEEXT} update-game-score${EXEEXT}
111 111
112DONT_INSTALL= test-distrib${EXEEXT} make-docfile${EXEEXT} 112DONT_INSTALL= test-distrib${EXEEXT} make-docfile${EXEEXT}
113 113
@@ -449,9 +449,6 @@ cvtmail${EXEEXT}: ${srcdir}/cvtmail.c
449fakemail${EXEEXT}: ${srcdir}/fakemail.c ../src/config.h 449fakemail${EXEEXT}: ${srcdir}/fakemail.c ../src/config.h
450 $(CC) ${ALL_CFLAGS} ${srcdir}/fakemail.c $(LOADLIBES) -o fakemail 450 $(CC) ${ALL_CFLAGS} ${srcdir}/fakemail.c $(LOADLIBES) -o fakemail
451 451
452yow${EXEEXT}: ${srcdir}/yow.c ../src/epaths.h
453 $(CC) ${ALL_CFLAGS} ${srcdir}/yow.c $(LOADLIBES) -o yow
454
455emacsclient${EXEEXT}: ${srcdir}/emacsclient.c ../src/config.h $(GETOPTDEPS) 452emacsclient${EXEEXT}: ${srcdir}/emacsclient.c ../src/config.h $(GETOPTDEPS)
456 $(CC) ${ALL_CFLAGS} ${srcdir}/emacsclient.c $(GETOPTOBJS) \ 453 $(CC) ${ALL_CFLAGS} ${srcdir}/emacsclient.c $(GETOPTOBJS) \
457 -DVERSION="\"${version}\"" \ 454 -DVERSION="\"${version}\"" \
diff --git a/lib-src/digest-doc.c b/lib-src/digest-doc.c
index 7b5a9677e7c..7787d422e39 100644
--- a/lib-src/digest-doc.c
+++ b/lib-src/digest-doc.c
@@ -26,12 +26,23 @@
26 26
27#include <stdio.h> 27#include <stdio.h>
28 28
29#ifdef DOS_NT
30#include <fcntl.h> /* for O_BINARY */
31#include <io.h> /* for setmode */
32#endif
33
29int 34int
30main () 35main ()
31{ 36{
32 register int ch; 37 register int ch;
33 register int notfirst = 0; 38 register int notfirst = 0;
34 39
40#ifdef DOS_NT
41 /* DOC is a binary file. */
42 if (!isatty (fileno (stdin)))
43 setmode (fileno (stdin), O_BINARY);
44#endif
45
35 printf (".TL\n"); 46 printf (".TL\n");
36 printf ("Command Summary for GNU Emacs\n"); 47 printf ("Command Summary for GNU Emacs\n");
37 printf (".AU\nRichard M. Stallman\n"); 48 printf (".AU\nRichard M. Stallman\n");
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index 94fa9114d23..398dd10896e 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -3909,17 +3909,31 @@ main (argc, argv)
3909 3909
3910 fp = fopen (out_filename, "r"); 3910 fp = fopen (out_filename, "r");
3911 if (fp == NULL) 3911 if (fp == NULL)
3912 yyerror ("file `%s' must exist for --append", out_filename); 3912 {
3913 yyerror ("file `%s' must exist for --append", out_filename);
3914 exit (EXIT_FAILURE);
3915 }
3913 3916
3914 rc = fseek (fp, 0, SEEK_END); 3917 rc = fseek (fp, 0, SEEK_END);
3915 if (rc == -1) 3918 if (rc == -1)
3916 yyerror ("error seeking in file `%s'", out_filename); 3919 {
3920 yyerror ("error seeking in file `%s'", out_filename);
3921 exit (EXIT_FAILURE);
3922 }
3917 3923
3918 rc = ftell (fp); 3924 rc = ftell (fp);
3919 if (rc == -1) 3925 if (rc == -1)
3920 yyerror ("error getting size of file `%s'", out_filename); 3926 {
3927 yyerror ("error getting size of file `%s'", out_filename);
3928 exit (EXIT_FAILURE);
3929 }
3930
3921 else if (rc == 0) 3931 else if (rc == 0)
3922 yyerror ("file `%s' is empty", out_filename); 3932 {
3933 yyerror ("file `%s' is empty", out_filename);
3934 /* It may be ok to use an empty file for appending.
3935 exit (EXIT_FAILURE); */
3936 }
3923 3937
3924 fclose (fp); 3938 fclose (fp);
3925 } 3939 }
diff --git a/lib-src/leditcfns.c b/lib-src/leditcfns.c
deleted file mode 100644
index 239db1cd1fa..00000000000
--- a/lib-src/leditcfns.c
+++ /dev/null
@@ -1,21 +0,0 @@
1#include <sgtty.h>
2#include <signal.h>
3#define STRLEN 100
4static char str[STRLEN+1] = "%?emacs"; /* extra char for the null */
5
6switch_to_proc(){
7 char *ptr = str;
8 while (*ptr) ioctl(0, TIOCSTI, ptr++);
9 ioctl(0, TIOCSTI, "\n");
10 kill(getpid(), SIGTSTP);
11 }
12
13set_proc_str(ptr) char *ptr; {
14 if (strlen(ptr) <= STRLEN)
15 strcpy(str, ptr);
16 else
17 printf("string too long for set-proc-str: %s\n", ptr);
18 }
19
20/* arch-tag: eb7ae804-0d6e-4077-ab42-7173821410c3
21 (do not change this comment) */
diff --git a/lib-src/makefile.w32-in b/lib-src/makefile.w32-in
index 6aa15964f45..96464e39506 100644
--- a/lib-src/makefile.w32-in
+++ b/lib-src/makefile.w32-in
@@ -20,7 +20,7 @@
20# Boston, MA 02110-1301, USA. 20# Boston, MA 02110-1301, USA.
21# 21#
22 22
23ALL = make-docfile hexl ctags etags movemail ebrowse 23ALL = make-docfile hexl ctags etags movemail ebrowse sorted-doc digest-doc
24 24
25.PHONY: $(ALL) 25.PHONY: $(ALL)
26 26
@@ -30,15 +30,10 @@ LOCAL_FLAGS = -DWINDOWSNT -DDOS_NT -DSTDC_HEADERS=1 -DNO_LDAV=1 \
30 30
31# don't know what (if) to do with these yet... 31# don't know what (if) to do with these yet...
32# 32#
33# $(BLD)/sorted-doc.exe \
34# $(BLD)/env.exe \
35# $(BLD)/server.exe \ 33# $(BLD)/server.exe \
36# $(BLD)/emacstool.exe \ 34# $(BLD)/emacstool.exe \
37# $(BLD)/leditcfns.exe \
38# $(BLD)/emacsclient.exe \ 35# $(BLD)/emacsclient.exe \
39# $(BLD)/cvtmail.exe \ 36# $(BLD)/cvtmail.exe \
40# $(BLD)/digest-doc.exe \
41# $(BLD)/test-distrib.exe \
42 37
43LIBS = $(BASE_LIBS) $(ADVAPI32) 38LIBS = $(BASE_LIBS) $(ADVAPI32)
44 39
@@ -48,6 +43,12 @@ $(BLD)/hexl.exe: $(BLD)/hexl.$(O)
48 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/hexl.$(O) $(LIBS) 43 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/hexl.$(O) $(LIBS)
49$(BLD)/fakemail.exe: $(BLD)/fakemail.$(O) $(BLD)/ntlib.$(O) 44$(BLD)/fakemail.exe: $(BLD)/fakemail.$(O) $(BLD)/ntlib.$(O)
50 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/fakemail.$(O) $(BLD)/ntlib.$(O) $(LIBS) 45 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/fakemail.$(O) $(BLD)/ntlib.$(O) $(LIBS)
46$(BLD)/sorted-doc.exe: $(BLD)/sorted-doc.$(O)
47 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/sorted-doc.$(O) $(LIBS)
48$(BLD)/digest-doc.exe: $(BLD)/digest-doc.$(O)
49 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/digest-doc.$(O) $(LIBS)
50$(BLD)/test-distrib.exe: $(BLD)/test-distrib.$(O)
51 $(LINK) $(LINK_OUT)$@ $(LINK_FLAGS) $(BLD)/test-distrib.$(O) $(LIBS)
51 52
52make-docfile: $(BLD) $(BLD)/make-docfile.exe 53make-docfile: $(BLD) $(BLD)/make-docfile.exe
53ctags: $(BLD) $(BLD)/ctags.exe 54ctags: $(BLD) $(BLD)/ctags.exe
@@ -56,6 +57,11 @@ ebrowse: $(BLD) $(BLD)/ebrowse.exe
56hexl: $(BLD) $(BLD)/hexl.exe 57hexl: $(BLD) $(BLD)/hexl.exe
57movemail: $(BLD) $(BLD)/movemail.exe 58movemail: $(BLD) $(BLD)/movemail.exe
58fakemail: $(BLD) $(BLD)/fakemail.exe 59fakemail: $(BLD) $(BLD)/fakemail.exe
60sorted-doc: $(BLD) $(BLD)/sorted-doc.exe
61digest-doc: $(BLD) $(BLD)/digest-doc.exe
62
63test-distrib: $(BLD) $(BLD)/test-distrib.exe
64 "$(BLD)/test-distrib.exe" "$(SRC)/testfile"
59 65
60GETOPTOBJS = $(BLD)/getopt.$(O) $(BLD)/getopt1.$(O) 66GETOPTOBJS = $(BLD)/getopt.$(O) $(BLD)/getopt1.$(O)
61GETOPTDEPS = $(GETOPTOBJS) getopt.h 67GETOPTDEPS = $(GETOPTOBJS) getopt.h
@@ -114,15 +120,10 @@ $(BLD)/ctags.$(O): ctags.c
114# 120#
115# don't know what to do with these yet... 121# don't know what to do with these yet...
116# 122#
117# $(BLD)/sorted-doc.exe: $(BLD)/sorted-doc.$(O)
118# $(BLD)/yow.exe: $(BLD)/yow.$(O)
119# $(BLD)/emacstool.exe: $(BLD)/emacstool.$(O) 123# $(BLD)/emacstool.exe: $(BLD)/emacstool.$(O)
120# $(BLD)/leditcfns.exe: $(BLD)/leditcfns.$(O)
121# $(BLD)/server.exe: $(BLD)/server.$(O) 124# $(BLD)/server.exe: $(BLD)/server.$(O)
122# $(BLD)/cvtmail.exe: $(BLD)/cvtmail.$(O) 125# $(BLD)/cvtmail.exe: $(BLD)/cvtmail.$(O)
123# $(BLD)/digest-doc.exe: $(BLD)/digest-doc.$(O)
124# $(BLD)/emacsclient.exe: $(BLD)/emacsclient.$(O) 126# $(BLD)/emacsclient.exe: $(BLD)/emacsclient.$(O)
125# $(BLD)/test-distrib.exe: $(BLD)/test-distrib.$(O)
126 127
127# 128#
128# From ..\src\Makefile.in 129# From ..\src\Makefile.in
@@ -293,6 +294,8 @@ install: $(INSTALL_FILES)
293 $(CP) $(BLD)/ctags.exe $(INSTALL_DIR)/bin 294 $(CP) $(BLD)/ctags.exe $(INSTALL_DIR)/bin
294 $(CP) $(BLD)/hexl.exe $(INSTALL_DIR)/bin 295 $(CP) $(BLD)/hexl.exe $(INSTALL_DIR)/bin
295 $(CP) $(BLD)/movemail.exe $(INSTALL_DIR)/bin 296 $(CP) $(BLD)/movemail.exe $(INSTALL_DIR)/bin
297 $(CP) $(BLD)/sorted-doc.exe $(INSTALL_DIR)/bin
298 $(CP) $(BLD)/digest-doc.exe $(INSTALL_DIR)/bin
296 - mkdir "$(INSTALL_DIR)/etc" 299 - mkdir "$(INSTALL_DIR)/etc"
297 $(CP) $(DOC) $(INSTALL_DIR)/etc 300 $(CP) $(DOC) $(INSTALL_DIR)/etc
298 301
@@ -448,7 +451,10 @@ $(BLD)/qsort.$(O) : \
448 $(SRC)/qsort.c 451 $(SRC)/qsort.c
449 452
450$(BLD)/sorted-doc.$(O) : \ 453$(BLD)/sorted-doc.$(O) : \
451 $(SRC)/sorted-doc.c 454 $(SRC)/sorted-doc.c \
455 $(EMACS_ROOT)/src/s/ms-w32.h \
456 $(EMACS_ROOT)/src/m/intel386.h \
457 $(EMACS_ROOT)/src/config.h \
452 458
453$(BLD)/tcp.$(O) : \ 459$(BLD)/tcp.$(O) : \
454 $(SRC)/tcp.c 460 $(SRC)/tcp.c
@@ -461,7 +467,3 @@ $(BLD)/timer.$(O) : \
461 $(EMACS_ROOT)/src/s/ms-w32.h \ 467 $(EMACS_ROOT)/src/s/ms-w32.h \
462 $(EMACS_ROOT)/src/m/intel386.h \ 468 $(EMACS_ROOT)/src/m/intel386.h \
463 $(EMACS_ROOT)/lib-src/../src/config.h 469 $(EMACS_ROOT)/lib-src/../src/config.h
464
465$(BLD)/yow.$(O) : \
466 $(SRC)/yow.c \
467 $(EMACS_ROOT)/lib-src/../src/paths.h
diff --git a/lib-src/sorted-doc.c b/lib-src/sorted-doc.c
index 0a06aa2c984..a8b2d441f9a 100644
--- a/lib-src/sorted-doc.c
+++ b/lib-src/sorted-doc.c
@@ -29,9 +29,15 @@
29 29
30#include <stdio.h> 30#include <stdio.h>
31#include <ctype.h> 31#include <ctype.h>
32#ifdef DOS_NT
33#include <fcntl.h> /* for O_BINARY */
34#include <io.h> /* for setmode */
35#endif
32#ifndef HAVE_STDLIB_H /* config.h includes stdlib. */ 36#ifndef HAVE_STDLIB_H /* config.h includes stdlib. */
37#ifndef WINDOWSNT /* src/s/ms-w32.h includes stdlib.h */
33extern char *malloc (); 38extern char *malloc ();
34#endif 39#endif
40#endif
35 41
36#define NUL '\0' 42#define NUL '\0'
37#define MARKER '\037' 43#define MARKER '\037'
@@ -134,6 +140,14 @@ main ()
134 DOCSTR *docs = NULL; /* chain of allocated DOCSTRS */ 140 DOCSTR *docs = NULL; /* chain of allocated DOCSTRS */
135 char buf[512]; /* line buffer */ 141 char buf[512]; /* line buffer */
136 142
143#ifdef DOS_NT
144 /* DOC is a binary file. */
145 if (!isatty (fileno (stdin)))
146 setmode (fileno (stdin), O_BINARY);
147#endif
148
149 bp = buf;
150
137 while (1) /* process one char at a time */ 151 while (1) /* process one char at a time */
138 { 152 {
139 /* this char from the DOCSTR file */ 153 /* this char from the DOCSTR file */
diff --git a/lib-src/yow.c b/lib-src/yow.c
deleted file mode 100644
index 18f0f7b2e13..00000000000
--- a/lib-src/yow.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 * yow.c
3 *
4 * Print a quotation from Zippy the Pinhead.
5 * Qux <Kaufman-David@Yale> March 6, 1986
6 *
7 * This file is in the public domain because the author published it
8 * with no copyright notice before the US signed the Bern Convention.
9 *
10 * With dynamic memory allocation.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <stdio.h>
18#include <ctype.h>
19#ifdef TIME_WITH_SYS_TIME
20#include <sys/time.h>
21#include <time.h>
22#else
23#ifdef HAVE_SYS_TIME_H
24#include <sys/time.h>
25#else
26#include <time.h>
27#endif
28#endif
29#ifdef HAVE_UNISTD_H
30#include <unistd.h>
31#endif
32#include "epaths.h" /* For PATH_DATA. */
33
34#define BUFSIZE 80
35#define SEP '\0'
36
37#ifndef YOW_FILE
38#define YOW_FILE "yow.lines"
39#endif
40
41#ifdef MSDOS
42#define rootrelativepath(rel) \
43({\
44 static char res[BUFSIZE], *p;\
45 strcpy (res, argv[0]);\
46 p = res + strlen (res);\
47 while (p != res && *p != '/' && *p != '\\' && *p != ':') p--;\
48 strcpy (p + 1, "../");\
49 strcpy (p + 4, rel);\
50 &res;})
51#endif
52
53void yow();
54void setup_yow();
55
56int
57main (argc, argv)
58 int argc;
59 char *argv[];
60{
61 FILE *fp;
62 char file[BUFSIZ];
63
64 if (argc > 2 && !strcmp (argv[1], "-f"))
65 strcpy (file, argv[2]);
66 else
67#ifdef vms
68 sprintf (file, "%s%s", PATH_DATA, YOW_FILE);
69#else
70 sprintf (file, "%s/%s", PATH_DATA, YOW_FILE);
71#endif
72
73 if ((fp = fopen(file, "r")) == NULL) {
74 fprintf(stderr, "yow: ");
75 perror(file);
76 exit(EXIT_FAILURE);
77 }
78
79 /* initialize random seed */
80 srand((int) (getpid() + time((time_t *) 0)));
81
82 setup_yow(fp);
83 yow(fp);
84 fclose(fp);
85 return EXIT_SUCCESS;
86}
87
88static long len = -1;
89static long header_len;
90
91#define AVG_LEN 40 /* average length of a quotation */
92
93/* Sets len and header_len */
94void
95setup_yow(fp)
96 FILE *fp;
97{
98 int c;
99
100 /* Get length of file */
101 /* Because the header (stuff before the first SEP) can be very long,
102 * thus biasing our search in favor of the first quotation in the file,
103 * we explicitly skip that. */
104 while ((c = getc(fp)) != SEP) {
105 if (c == EOF) {
106 fprintf(stderr, "yow: file contains no separators\n");
107 exit(EXIT_FAILURE);
108 }
109 }
110 header_len = ftell(fp);
111 if (header_len > AVG_LEN)
112 header_len -= AVG_LEN; /* allow the first quotation to appear */
113
114 if (fseek(fp, 0L, 2) == -1) {
115 perror("yow");
116 exit(EXIT_FAILURE);
117 }
118 len = ftell(fp) - header_len;
119}
120
121
122/* go to a random place in the file and print the quotation there */
123void
124yow (fp)
125 FILE *fp;
126{
127 long offset;
128 int c, i = 0;
129 char *buf;
130 unsigned int bufsize;
131
132 offset = rand() % len + header_len;
133 if (fseek(fp, offset, 0) == -1) {
134 perror("yow");
135 exit(EXIT_FAILURE);
136 }
137
138 /* Read until SEP, read next line, print it.
139 (Note that we will never print anything before the first separator.)
140 If we hit EOF looking for the first SEP, just recurse. */
141 while ((c = getc(fp)) != SEP)
142 if (c == EOF) {
143 yow(fp);
144 return;
145 }
146
147 /* Skip leading whitespace, then read in a quotation.
148 If we hit EOF before we find a non-whitespace char, recurse. */
149 while (isspace(c = getc(fp)))
150 ;
151 if (c == EOF) {
152 yow(fp);
153 return;
154 }
155
156 bufsize = BUFSIZE;
157 buf = (char *) malloc(bufsize);
158 if (buf == (char *)0) {
159 fprintf(stderr, "yow: virtual memory exhausted\n");
160 exit (EXIT_FAILURE);
161 }
162
163 buf[i++] = c;
164 while ((c = getc(fp)) != SEP && c != EOF) {
165 buf[i++] = c;
166
167 if (i == bufsize-1) {
168 /* Yow! Is this quotation too long yet? */
169 bufsize *= 2;
170 buf = (char *) realloc(buf, bufsize);
171 if (buf == (char *)0) {
172 fprintf(stderr, "yow: virtual memory exhausted\n");
173 exit (EXIT_FAILURE);
174 }
175 }
176 }
177 buf[i++] = 0;
178 printf("%s\n", buf);
179 free (buf);
180}
181
182/* arch-tag: e40fc0df-bafb-4001-af24-5c883d1c685e
183 (do not change this comment) */
184
185/* yow.c ends here */