Mercurial > hg > xemacs-beta
comparison lib-src/b2m.c @ 155:43dd3413c7c7 r20-3b4
Import from CVS: tag r20-3b4
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:39:39 +0200 |
parents | 59463afc5666 |
children | 8eaf7971accc |
comparison
equal
deleted
inserted
replaced
154:94141801dd7e | 155:43dd3413c7c7 |
---|---|
15 * Mon Nov 7 15:54:06 PDT 1988 | 15 * Mon Nov 7 15:54:06 PDT 1988 |
16 */ | 16 */ |
17 | 17 |
18 /* Made conformant to the GNU coding standards January, 1995 | 18 /* Made conformant to the GNU coding standards January, 1995 |
19 by Francesco Potorti` <pot@cnuce.cnr.it>. */ | 19 by Francesco Potorti` <pot@cnuce.cnr.it>. */ |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 #include <config.h> | |
23 /* On some systems, Emacs defines static as nothing for the sake | |
24 of unexec. We don't want that here since we don't use unexec. */ | |
25 #undef static | |
26 #endif | |
20 | 27 |
21 #include <stdio.h> | 28 #include <stdio.h> |
22 #include <stdlib.h> | 29 #include <stdlib.h> |
23 #include <string.h> | 30 #include <string.h> |
24 #include <time.h> | 31 #include <time.h> |
31 #include <config.h> | 38 #include <config.h> |
32 /* On some systems, Emacs defines static as nothing for the sake | 39 /* On some systems, Emacs defines static as nothing for the sake |
33 of unexec. We don't want that here since we don't use unexec. */ | 40 of unexec. We don't want that here since we don't use unexec. */ |
34 #undef static | 41 #undef static |
35 #endif | 42 #endif |
36 | |
37 #undef TRUE | 43 #undef TRUE |
38 #define TRUE 1 | 44 #define TRUE 1 |
39 #undef FALSE | 45 #undef FALSE |
40 #define FALSE 0 | 46 #define FALSE 0 |
41 | 47 |
67 extern char *strtok(); | 73 extern char *strtok(); |
68 | 74 |
69 long *xmalloc (), *xrealloc (); | 75 long *xmalloc (), *xrealloc (); |
70 char *concat (); | 76 char *concat (); |
71 long readline (); | 77 long readline (); |
72 void fatal (); | 78 void fatal (char *); |
73 | 79 |
74 /* | 80 /* |
75 * xnew -- allocate storage. SYNOPSIS: Type *xnew (int n, Type); | 81 * xnew -- allocate storage. SYNOPSIS: Type *xnew (int n, Type); |
76 */ | 82 */ |
77 #define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) | 83 #define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) |
78 | 84 |
79 | 85 |
80 | 86 |
81 char *progname; | 87 char *progname; |
82 | 88 |
83 main (argc, argv) | 89 int |
84 int argc; | 90 main (int argc, char **argv) |
85 char **argv; | |
86 { | 91 { |
87 logical labels_saved, printing, header; | 92 logical labels_saved, printing, header; |
88 time_t ltoday; | 93 time_t ltoday; |
89 char *labels, *p, *today; | 94 char *labels, *p, *today; |
90 struct linebuffer data; | 95 struct linebuffer data; |
158 } | 163 } |
159 | 164 |
160 if (printing) | 165 if (printing) |
161 puts (data.buffer); | 166 puts (data.buffer); |
162 } | 167 } |
168 return 0; | |
163 } | 169 } |
164 | 170 |
165 | 171 |
166 | 172 |
167 /* | 173 /* |
168 * Return a newly-allocated string whose contents | 174 * Return a newly-allocated string whose contents |
169 * concatenate those of s1, s2, s3. | 175 * concatenate those of s1, s2, s3. |
170 */ | 176 */ |
171 char * | 177 char * |
172 concat (s1, s2, s3) | 178 concat (char *s1, char *s2, char *s3) |
173 char *s1, *s2, *s3; | |
174 { | 179 { |
175 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | 180 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); |
176 char *result = xnew (len1 + len2 + len3 + 1, char); | 181 char *result = xnew (len1 + len2 + len3 + 1, char); |
177 | 182 |
178 strcpy (result, s1); | 183 strcpy (result, s1); |
187 * Read a line of text from `stream' into `linebuffer'. | 192 * Read a line of text from `stream' into `linebuffer'. |
188 * Return the number of characters read from `stream', | 193 * Return the number of characters read from `stream', |
189 * which is the length of the line including the newline, if any. | 194 * which is the length of the line including the newline, if any. |
190 */ | 195 */ |
191 long | 196 long |
192 readline (linebuffer, stream) | 197 readline (struct linebuffer *linebuffer, register FILE *stream) |
193 struct linebuffer *linebuffer; | |
194 register FILE *stream; | |
195 { | 198 { |
196 char *buffer = linebuffer->buffer; | 199 char *buffer = linebuffer->buffer; |
197 register char *p = linebuffer->buffer; | 200 register char *p = linebuffer->buffer; |
198 register char *pend; | 201 register char *pend; |
199 int chars_deleted; | 202 int chars_deleted; |
238 | 241 |
239 /* | 242 /* |
240 * Like malloc but get fatal error if memory is exhausted. | 243 * Like malloc but get fatal error if memory is exhausted. |
241 */ | 244 */ |
242 long * | 245 long * |
243 xmalloc (size) | 246 xmalloc (unsigned int size) |
244 unsigned int size; | |
245 { | 247 { |
246 long *result = (long *) malloc (size); | 248 long *result = (long *) malloc (size); |
247 if (result == NULL) | 249 if (result == NULL) |
248 fatal ("virtual memory exhausted"); | 250 fatal ("virtual memory exhausted"); |
249 return result; | 251 return result; |
250 } | 252 } |
251 | 253 |
252 long * | 254 long * |
253 xrealloc (ptr, size) | 255 xrealloc (char *ptr, unsigned int size) |
254 char *ptr; | |
255 unsigned int size; | |
256 { | 256 { |
257 long *result = (long *) realloc (ptr, size); | 257 long *result = (long *) realloc (ptr, size); |
258 if (result == NULL) | 258 if (result == NULL) |
259 fatal ("virtual memory exhausted"); | 259 fatal ("virtual memory exhausted"); |
260 return result; | 260 return result; |
261 } | 261 } |
262 | 262 |
263 void | 263 void |
264 fatal (message) | 264 fatal (char *message) |
265 { | 265 { |
266 fprintf (stderr, "%s: %s\n", progname, message); | 266 fprintf (stderr, "%s: %s\n", progname, message); |
267 exit (BAD); | 267 exit (BAD); |
268 } | 268 } |
269 | 269 |