Mercurial > emacs
annotate src/doprnt.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 | 3165b2697c78 |
| children | b6c62e4abf59 |
| rev | line source |
|---|---|
| 49 | 1 /* Output like sprintf to a buffer of specified size. |
| 2 Also takes args differently: pass one pointer to an array of strings | |
| 3 in addition to the format string which is separate. | |
| 4 Copyright (C) 1985 Free Software Foundation, Inc. | |
| 5 | |
| 6 This file is part of GNU Emacs. | |
| 7 | |
| 8 GNU Emacs is free software; you can redistribute it and/or modify | |
| 9 it under the terms of the GNU General Public License as published by | |
| 10 the Free Software Foundation; either version 1, or (at your option) | |
| 11 any later version. | |
| 12 | |
| 13 GNU Emacs is distributed in the hope that it will be useful, | |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 GNU General Public License for more details. | |
| 17 | |
| 18 You should have received a copy of the GNU General Public License | |
| 19 along with GNU Emacs; see the file COPYING. If not, write to | |
| 20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
| 21 | |
| 22 | |
| 23 #include <stdio.h> | |
| 24 #include <ctype.h> | |
| 25 | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
26 /* Generate output from a format-spec FORMAT, |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
27 terminated at position FORMAT_END. |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
28 Output goes in BUFFER, which has room for BUFSIZE chars. |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
29 If the output does not fit, truncate it to fit. |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
30 Returns the number of characters stored into BUFFER. |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
31 ARGS points to the vector of arguments, and NARGS says how many. |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
32 A double counts as two arguments. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
33 |
| 49 | 34 doprnt (buffer, bufsize, format, format_end, nargs, args) |
| 35 char *buffer; | |
| 36 register int bufsize; | |
| 37 char *format; | |
| 38 char *format_end; | |
| 39 int nargs; | |
| 40 char **args; | |
| 41 { | |
| 42 int cnt = 0; /* Number of arg to gobble next */ | |
| 43 register char *fmt = format; /* Pointer into format string */ | |
| 44 register char *bufptr = buffer; /* Pointer into output buffer.. */ | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
45 /* Use this for sprintf unless we need something really big. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
46 char tembuf[100]; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
47 /* Size of sprintf_buffer. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
48 int size_allocated = 100; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
49 /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
50 char *sprintf_buffer = tembuf; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
51 /* Buffer we have got with malloc. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
52 char *big_buffer = 0; |
| 49 | 53 register int tem; |
| 54 char *string; | |
| 55 char fmtcpy[20]; | |
| 56 int minlen; | |
| 57 int size; /* Field width factor; e.g., %90d */ | |
| 58 | |
| 59 if (format_end == 0) | |
| 60 format_end = format + strlen (format); | |
| 61 | |
| 62 bufsize--; | |
| 116 | 63 while (fmt != format_end && bufsize > 0) /* Loop until end of format |
| 64 string or buffer full */ | |
| 49 | 65 { |
| 66 if (*fmt == '%') /* Check for a '%' character */ | |
| 67 { | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
68 int size_bound; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
69 |
| 49 | 70 fmt++; |
| 484 | 71 /* Copy this one %-spec into fmtcpy. */ |
| 49 | 72 string = fmtcpy; |
| 73 *string++ = '%'; | |
| 484 | 74 while (string < fmtcpy + sizeof fmtcpy - 1) |
| 49 | 75 { |
| 76 *string++ = *fmt; | |
| 77 if (! (*fmt >= '0' && *fmt <= '9') && *fmt != '-' && *fmt != ' ') | |
| 78 break; | |
| 79 fmt++; | |
| 80 } | |
| 81 *string = 0; | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
82 /* Get an idea of how much space we might need. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
83 size_bound = atoi (&fmtcpy[1]) + 50; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
84 /* Make sure we have that much. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
85 if (size_bound > size_allocated) |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
86 { |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
87 if (big_buffer) |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
88 big_buffer = (char *) xrealloc (big_buffer, size_bound); |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
89 else |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
90 big_buffer = (char *) xmalloc (size_bound); |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
91 sprintf_buffer = big_buffer; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
92 size_allocated = size_bound; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
93 } |
| 49 | 94 minlen = 0; |
| 95 switch (*fmt++) | |
| 96 { | |
| 97 default: | |
| 98 error ("Invalid format operation %%%c", fmt[-1]); | |
| 99 | |
| 100 /* case 'b': */ | |
| 101 case 'd': | |
| 102 case 'o': | |
| 103 case 'x': | |
| 104 if (cnt == nargs) | |
| 105 error ("Format string wants too many arguments"); | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
106 sprintf (sprintf_buffer, fmtcpy, args[cnt++]); |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
107 /* Now copy into final output, truncating as nec. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
108 string = sprintf_buffer; |
| 49 | 109 goto doit; |
| 110 | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
111 case 'f': |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
112 case 'e': |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
113 case 'g': |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
114 { |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
115 union { double d; char *half[2]; } u; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
116 if (cnt + 1 == nargs) |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
117 error ("Format string wants too many arguments"); |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
118 u.half[0] = args[cnt++]; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
119 u.half[1] = args[cnt++]; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
120 sprintf (sprintf_buffer, fmtcpy, u.d); |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
121 /* Now copy into final output, truncating as nec. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
122 string = sprintf_buffer; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
123 goto doit; |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
124 } |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
125 |
| 49 | 126 case 'S': |
| 127 string[-1] = 's'; | |
| 128 case 's': | |
| 129 if (cnt == nargs) | |
| 130 error ("Format string wants too many arguments"); | |
| 131 string = args[cnt++]; | |
| 132 if (fmtcpy[1] != 's') | |
| 133 minlen = atoi (&fmtcpy[1]); | |
| 134 /* Copy string into final output, truncating if no room. */ | |
| 135 doit: | |
| 136 tem = strlen (string); | |
| 137 if (minlen > 0) | |
| 138 { | |
| 139 while (minlen > tem && bufsize > 0) | |
| 140 { | |
| 141 *bufptr++ = ' '; | |
| 142 bufsize--; | |
| 143 minlen--; | |
| 144 } | |
| 145 minlen = 0; | |
| 146 } | |
| 147 if (tem > bufsize) | |
| 148 tem = bufsize; | |
| 149 strncpy (bufptr, string, tem); | |
| 150 bufptr += tem; | |
| 151 bufsize -= tem; | |
| 152 if (minlen < 0) | |
| 153 { | |
| 154 while (minlen < - tem && bufsize > 0) | |
| 155 { | |
| 156 *bufptr++ = ' '; | |
| 157 bufsize--; | |
| 158 minlen++; | |
| 159 } | |
| 160 minlen = 0; | |
| 161 } | |
| 162 continue; | |
| 163 | |
| 164 case 'c': | |
| 165 if (cnt == nargs) | |
| 166 error ("Format string wants too many arguments"); | |
| 167 *bufptr++ = (int) args[cnt++]; | |
| 168 bufsize--; | |
| 169 continue; | |
| 170 | |
| 171 case '%': | |
| 172 fmt--; /* Drop thru and this % will be treated as normal */ | |
| 173 } | |
| 174 } | |
| 175 *bufptr++ = *fmt++; /* Just some characters; Copy 'em */ | |
| 176 bufsize--; | |
| 177 }; | |
| 178 | |
|
147
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
179 /* If we had to malloc something, free it. */ |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
180 if (big_buffer) |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
181 free (big_buffer); |
|
0f50f1badd75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
116
diff
changeset
|
182 |
| 49 | 183 *bufptr = 0; /* Make sure our string end with a '\0' */ |
| 184 return bufptr - buffer; | |
| 185 } |
