Mercurial > emacs
annotate lib-src/yow.c @ 1717:aa7d6d57504b
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Thu, 24 Dec 1992 06:17:18 +0000 |
| parents | 78165914b12d |
| children | 507f64624555 |
| rev | line source |
|---|---|
| 42 | 1 /* |
| 2 * yow.c | |
| 12 | 3 * |
| 4 * Print a quotation from Zippy the Pinhead. | |
| 5 * Qux <Kaufman-David@Yale> March 6, 1986 | |
| 6 * | |
| 42 | 7 * With dynamic memory allocation. |
| 12 | 8 */ |
| 9 | |
| 42 | 10 #include <stdio.h> |
| 11 #include <ctype.h> | |
| 443 | 12 #include "../src/paths.h" /* For PATH_DATA. */ |
| 42 | 13 |
| 14 #define BUFSIZE 80 | |
| 12 | 15 #define SEP '\0' |
| 42 | 16 |
| 17 #ifndef YOW_FILE | |
| 12 | 18 #define YOW_FILE "yow.lines" |
| 42 | 19 #endif |
| 12 | 20 |
| 21 main (argc, argv) | |
| 22 int argc; | |
| 23 char *argv[]; | |
| 24 { | |
| 25 FILE *fp; | |
| 26 char file[BUFSIZ]; | |
| 42 | 27 void yow(), setup_yow(); |
| 12 | 28 |
| 29 if (argc > 2 && !strcmp (argv[1], "-f")) | |
| 30 strcpy (file, argv[2]); | |
| 31 else | |
| 32 #ifdef vms | |
| 443 | 33 sprintf (file, "%s%s", PATH_DATA, YOW_FILE); |
| 12 | 34 #else |
| 443 | 35 sprintf (file, "%s/%s", PATH_DATA, YOW_FILE); |
| 12 | 36 #endif |
| 37 | |
| 38 if ((fp = fopen(file, "r")) == NULL) { | |
| 39 perror(file); | |
| 40 exit(1); | |
| 41 } | |
| 42 | |
| 43 /* initialize random seed */ | |
| 44 srand((int) (getpid() + time((long *) 0))); | |
| 45 | |
| 42 | 46 setup_yow(fp); |
| 12 | 47 yow(fp); |
| 48 fclose(fp); | |
| 49 exit(0); | |
| 50 } | |
| 51 | |
| 42 | 52 static long len = -1; |
| 53 static long header_len; | |
| 54 | |
| 55 #define AVG_LEN 40 /* average length of a quotation */ | |
| 56 | |
| 57 /* Sets len and header_len */ | |
| 58 void | |
| 59 setup_yow(fp) | |
| 60 FILE *fp; | |
| 61 { | |
| 62 int c; | |
| 63 | |
| 64 /* Get length of file */ | |
| 65 /* Because the header (stuff before the first SEP) can be very long, | |
| 66 * thus biasing our search in favor of the first quotation in the file, | |
| 67 * we explicitly skip that. */ | |
| 68 while ((c = getc(fp)) != SEP) { | |
| 69 if (c == EOF) { | |
| 70 fprintf(stderr, "File contains no separators.\n"); | |
| 71 exit(2); | |
| 72 } | |
| 73 } | |
| 74 header_len = ftell(fp); | |
| 75 if (header_len > AVG_LEN) | |
| 76 header_len -= AVG_LEN; /* allow the first quotation to appear */ | |
| 77 | |
| 78 if (fseek(fp, 0L, 2) == -1) { | |
| 79 perror("fseek 1"); | |
| 80 exit(1); | |
| 81 } | |
| 82 len = ftell(fp) - header_len; | |
| 83 } | |
| 84 | |
| 85 | |
| 86 /* go to a random place in the file and print the quotation there */ | |
| 12 | 87 void |
| 88 yow (fp) | |
| 89 FILE *fp; | |
| 90 { | |
| 91 long offset; | |
| 92 int c, i = 0; | |
| 42 | 93 char *buf; |
| 94 unsigned int bufsize; | |
| 95 char *malloc(), *realloc(); | |
| 12 | 96 |
| 42 | 97 offset = rand() % len + header_len; |
| 12 | 98 if (fseek(fp, offset, 0) == -1) { |
| 99 perror("fseek 2"); | |
| 100 exit(1); | |
| 101 } | |
| 102 | |
| 103 /* Read until SEP, read next line, print it. | |
| 104 (Note that we will never print anything before the first seperator.) | |
| 105 If we hit EOF looking for the first SEP, just recurse. */ | |
| 106 while ((c = getc(fp)) != SEP) | |
| 107 if (c == EOF) { | |
| 108 yow(fp); | |
| 109 return; | |
| 110 } | |
| 111 | |
| 112 /* Skip leading whitespace, then read in a quotation. | |
| 113 If we hit EOF before we find a non-whitespace char, recurse. */ | |
| 114 while (isspace(c = getc(fp))) | |
| 115 ; | |
| 116 if (c == EOF) { | |
| 117 yow(fp); | |
| 118 return; | |
| 119 } | |
| 42 | 120 |
| 121 bufsize = BUFSIZE; | |
| 122 buf = malloc(bufsize); | |
| 123 if (buf == (char *)0) { | |
| 124 fprintf(stderr, "can't allocate any memory\n"); | |
| 125 exit (3); | |
| 126 } | |
| 127 | |
| 12 | 128 buf[i++] = c; |
| 129 while ((c = getc(fp)) != SEP && c != EOF) { | |
| 130 buf[i++] = c; | |
| 42 | 131 |
| 132 if (i == bufsize-1) { | |
| 12 | 133 /* Yow! Is this quotation too long yet? */ |
| 42 | 134 bufsize *= 2; |
| 135 buf = realloc(buf, bufsize); | |
| 136 if (buf == (char *)0) { | |
| 137 fprintf(stderr, "can't allocate more memory\n"); | |
| 138 exit (3); | |
| 139 } | |
| 140 } | |
| 12 | 141 } |
| 142 buf[i++] = 0; | |
| 143 printf("%s\n", buf); | |
| 144 } | |
| 145 |
