Mercurial > hg > xemacs-beta
annotate lib-src/yow.c @ 1330:4542b72c005e
[xemacs-hg @ 2003-03-01 07:25:26 by ben]
build patch
Makefile.in.in: Move src deletions to src/Makefile.in.in.
dump-paths.el, dumped-lisp.el: Delete. Combine stuff into setup-paths.el.
find-paths.el: Removed.
Make this file contain generic routines only. Move stuff to
compute Emacs roots to setup-paths.el.
startup.el: Removed.
Move these variables into setup-paths.el.
setup-paths.el, startup.el: Removed.
Combine all high-level code for computing the paths into
setup-paths.el. Create new function startup-find-load-path to
encapsulate all logic for computing `load-path'. Eliminate
invocation-directory and invocation-name parameters since
there is no point (false generality) -- the code references
other globals, which cannot be specified. Eliminate some code
duplicated between setup-paths.el and startup.el. Clean up
the debug-paths code and output load-path in addition.
Add logic to paths-emacs-root-p to support separated source
and build trees.
loadup.el, make-docfile.el, update-elc-2.el, update-elc.el: Rewrite to allow for separated source and build trees, as may occur
in MS Windows.
NOTE TO BUILD HACKERS:
loadup.el, make-docfile.el, update-elc.el and update-elc-2.el made two
assumptions that are no longer correct:
(1) The source and build trees are in the same place.
(2) They can make assumptions about where `.' is.
These files now compute the locations of the source and build
roots at the top of the file. *ALL* constant file names or path
snippets must now be made absolute using expand-file-name and one
of these roots.
dumped-lisp.el, packages.el: Removed.
Remove some unused lists of Lisp files. packages-hardcoded-lisp
(empty, in any case) moved to dumped-lisp.el.
startup.el: When a compiled init file is out-of-date wrt the uncompiled
version, load the uncompiled version and issue a nasty warning.
update-elc-2.el: Force touching of auto-autoloads files when REBUILD_AUTOLOADS
was set.
update-elc.el: Fix code that checks whether dumping is necessary to check against
xemacs.dmp, not xemacs.exe, when Unix and pdump.
lwlib-Xm.c: Fix compile warning.
README, config.inc.samp, xemacs.mak: -- Major reorganization and cleanup.
-- Add support for separated build tree and source tree.
-- Delete all support for X Windows building, since it's
totally bit-rotten and will never be fixed up. Instruct
people to use Cygwin if they want such support.
make-build-dir: New script to create a skeleton build tree for use with
separated build and source tree compilation.
m/acorn.h, m/alliant-2800.h, m/alliant.h, m/altos.h, m/amdahl.h, m/arm.h, m/att3b.h, m/aviion.h, m/clipper.h, m/cnvrgnt.h, m/convex.h, m/cydra5.h, m/delta.h, m/delta88k.h, m/dpx2.h, m/elxsi.h, m/ews4800r.h, m/gould.h, m/hp800.h, m/hp9000s300.h, m/i860.h, m/ibmps2-aix.h, m/ibmrs6000.h, m/ibmrt-aix.h, m/ibmrt.h, m/intel386.h, m/iris4d.h, m/iris5d.h, m/iris6d.h, m/irist.h, m/m68k.h, m/masscomp.h, m/mg1.h, m/mips-nec.h, m/mips-siemens.h, m/mips.h, m/nh3000.h, m/nh4000.h, m/ns32000.h, m/plexus.h, m/powerpc.h, m/sequent-ptx.h, m/sequent.h, m/sgi-challenge.h, m/stride.h, m/tad68k.h, m/targon31.h, m/tekxd88.h, m/template.h, m/tower32.h, m/tower32v3.h, m/ustation.h, m/wicat.h, m/xps100.h, data.c, doc.c, editfns.c, emacs.c, lrecord.h, ntheap.c, process-unix.c, sysdep.c, unexec.c: Delete all support for bit-rotten CANNOT_DUMP. Just use pdump.
Makefile.in.in: Lots o' cleanup. Use names like LISP, SRC instead of
lispdir, srcdir, for consistency with xemacs.mak and the
conventions in the rest of the file. Eliminate use of ${...}
in favor of $(...), to make it easier to move code between
this file and xemacs.mak. Fix dependency handling wrt
NEEDTODUMP to eliminate problems some people (e.g. Vin) have
been seeing with non-GNU makes. Write a long section about
the subtle but oh-so-important differences in dependency
processing between nmake, make, and GNU make. Add
unicode-encapsulate target, from xemacs.mak.
chartab.c, lrecord.h: Fix crash due to attempt to free objects across dump/undump.
author | ben |
---|---|
date | Sat, 01 Mar 2003 07:25:56 +0000 |
parents | 943eaba38521 |
children |
rev | line source |
---|---|
428 | 1 /* |
2 * yow.c | |
3 * | |
4 * Print a quotation from Zippy the Pinhead. | |
5 * Qux <Kaufman-David@Yale> March 6, 1986 | |
6 * | |
7 * With dynamic memory allocation. | |
8 */ | |
9 | |
10 /* Synched up with: FSF 19.28. */ | |
11 | |
438 | 12 #include <config.h> |
428 | 13 |
14 #include <stdio.h> | |
15 #include <ctype.h> | |
16 #include <../src/paths.h> /* For PATH_DATA. */ | |
17 | |
18 #if __STDC__ || defined(STDC_HEADERS) | |
19 #include <stdlib.h> | |
20 #include <unistd.h> | |
21 #include <string.h> | |
22 #include <time.h> /* for time() */ | |
23 #endif | |
24 | |
25 #define BUFSIZE 80 | |
26 #define SEP '\0' | |
27 | |
28 #ifndef YOW_FILE | |
29 #define YOW_FILE "yow.lines" | |
30 #endif | |
31 | |
32 void yow (FILE *fp); | |
33 void setup_yow (FILE *fp); | |
34 | |
442 | 35 #ifdef WIN32_NATIVE |
428 | 36 #define rootrelativepath(rel) \ |
37 ({\ | |
38 static char res[BUFSIZE], *p;\ | |
39 strcpy (res, argv[0]);\ | |
40 p = res + strlen (res);\ | |
41 while (p != res && *p != '/' && *p != '\\' && *p != ':') p--;\ | |
42 strcpy (p + 1, "../");\ | |
43 strcpy (p + 4, rel);\ | |
44 &res;}) | |
45 #endif | |
46 | |
47 int | |
48 main (int argc, char *argv[]) | |
49 { | |
50 FILE *fp; | |
51 char file[BUFSIZ]; | |
52 | |
53 if (argc > 2 && !strcmp (argv[1], "-f")) | |
54 strcpy (file, argv[2]); | |
55 else | |
56 #ifdef PATH_DATA | |
57 #ifdef vms | |
58 sprintf (file, "%s%s", PATH_DATA, YOW_FILE); | |
59 #else | |
60 sprintf (file, "%s/%s", PATH_DATA, YOW_FILE); | |
61 #endif | |
62 #else /* !PATH_DATA */ | |
63 { | |
64 fprintf (stderr, | |
65 "%s: the location of the \"%s\" file was not supplied at compile-time.\n\ | |
66 You must supply it with the -f command-line option.\n", | |
67 argv[0], YOW_FILE); | |
68 exit (1); | |
69 } | |
70 #endif | |
71 | |
72 if ((fp = fopen(file, "r")) == NULL) { | |
73 perror(file); | |
74 exit(1); | |
75 } | |
76 | |
77 /* initialize random seed */ | |
78 srand((int) (getpid() + time((time_t *) 0))); | |
79 | |
80 setup_yow(fp); | |
81 yow(fp); | |
82 fclose(fp); | |
83 return 0; | |
84 } | |
85 | |
86 static long len = -1; | |
87 static long header_len; | |
88 | |
89 #define AVG_LEN 40 /* average length of a quotation */ | |
90 | |
91 /* Sets len and header_len */ | |
92 void | |
440 | 93 setup_yow (FILE *fp) |
428 | 94 { |
95 int c; | |
96 | |
97 /* Get length of file */ | |
98 /* Because the header (stuff before the first SEP) can be very long, | |
99 * thus biasing our search in favor of the first quotation in the file, | |
100 * we explicitly skip that. */ | |
101 while ((c = getc(fp)) != SEP) { | |
102 if (c == EOF) { | |
103 fprintf(stderr, "File contains no separators.\n"); | |
104 exit(2); | |
105 } | |
106 } | |
107 header_len = ftell(fp); | |
108 if (header_len > AVG_LEN) | |
109 header_len -= AVG_LEN; /* allow the first quotation to appear */ | |
110 | |
111 if (fseek(fp, 0L, 2) == -1) { | |
112 perror("fseek 1"); | |
113 exit(1); | |
114 } | |
115 len = ftell(fp) - header_len; | |
116 } | |
117 | |
118 | |
119 /* go to a random place in the file and print the quotation there */ | |
120 void | |
440 | 121 yow (FILE *fp) |
428 | 122 { |
123 long offset; | |
124 int c, i = 0; | |
125 char *buf; | |
647 | 126 int bufsize; |
428 | 127 |
128 offset = rand() % len + header_len; | |
129 if (fseek(fp, offset, 0) == -1) { | |
130 perror("fseek 2"); | |
131 exit(1); | |
132 } | |
133 | |
134 /* Read until SEP, read next line, print it. | |
135 (Note that we will never print anything before the first separator.) | |
136 If we hit EOF looking for the first SEP, just recurse. */ | |
137 while ((c = getc(fp)) != SEP) | |
138 if (c == EOF) { | |
139 yow(fp); | |
140 return; | |
141 } | |
142 | |
143 /* Skip leading whitespace, then read in a quotation. | |
144 If we hit EOF before we find a non-whitespace char, recurse. */ | |
145 while (isspace(c = getc(fp))) | |
146 ; | |
147 if (c == EOF) { | |
148 yow(fp); | |
149 return; | |
150 } | |
151 | |
152 bufsize = BUFSIZE; | |
153 buf = (char *) malloc(bufsize); | |
154 if (buf == (char *)0) { | |
155 fprintf(stderr, "can't allocate any memory\n"); | |
156 exit (3); | |
157 } | |
158 | |
159 buf[i++] = c; | |
160 while ((c = getc(fp)) != SEP && c != EOF) { | |
161 buf[i++] = c; | |
162 | |
163 if (i == bufsize-1) { | |
164 /* Yow! Is this quotation too long yet? */ | |
165 bufsize *= 2; | |
166 buf = (char *)realloc(buf, bufsize); | |
167 if (buf == (char *)0) { | |
168 fprintf(stderr, "can't allocate more memory\n"); | |
169 exit (3); | |
170 } | |
171 } | |
172 } | |
173 buf[i++] = 0; | |
174 printf("%s\n", buf); | |
175 } | |
176 |