From 1dae0f0aadd0e0fe51893aff89bb3220cba953db Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sun, 10 Jul 2011 10:20:10 +0200 Subject: [PATCH] Protoize * src/buffer.c (mmap_init, mmap_find, mmap_free_1, mmap_enlarge) (mmap_set_vars, mmap_alloc, mmap_free, mmap_realloc): Protoize. * src/data.c (fmod): Likewise. * src/dispnew.c (swap_glyphs_in_rows): Likewise. * src/emacs.c (memory_warning_signal): Likewise. * src/floatfns.c (float_error): Likewise. * src/font.c (check_gstring, check_otf_features, otf_tag_symbol) (otf_open, font_otf_capability, generate_otf_features) (font_otf_DeviceTable, font_otf_ValueRecord, font_otf_Anchor): Likewise. * src/image.c (pbm_read_file): Likewise. * src/indent.c (string_display_width): Likewise. * src/intervals.c (check_for_interval, search_for_interval) (inc_interval_count, count_intervals, root_interval) (adjust_intervals_for_insertion, make_new_interval): Likewise. * src/lread.c (defalias): Likewise. * src/regex.c (set_image_of_range_1, set_image_of_range) (regex_grow_registers): Likewise. * src/sysdep.c (strerror): Likewise. * src/termcap.c (valid_filename_p, tprint, main): Likewise. * src/tparam.c (main): Likewise. * src/unexhp9k800.c (run_time_remap, save_data_space) (update_file_ptrs, read_header, write_header, calculate_checksum) (copy_file, copy_rest, display_header): Likewise. * src/widget.c (mark_shell_size_user_specified, create_frame_gcs): Likewise. * src/xdisp.c (check_it): Likewise. * src/xfaces.c (register_color, unregister_color, unregister_colors): Likewise. * src/xfns.c (print_fontset_result): Likewise. * src/xrdb.c (member, fatal, main): Likewise. --- src/ChangeLog | 34 +++++ src/buffer.c | 115 ++++++--------- src/data.c | 3 +- src/dispnew.c | 3 +- src/emacs.c | 3 +- src/floatfns.c | 3 +- src/font.c | 29 ++-- src/image.c | 4 +- src/indent.c | 3 +- src/intervals.c | 24 +-- src/lread.c | 4 +- src/regex.c | 17 +-- src/sysdep.c | 3 +- src/termcap.c | 50 +++---- src/tparam.c | 5 +- src/unexhp9k800.c | 364 ++++++++++++++++++++++------------------------ src/widget.c | 6 +- src/xdisp.c | 3 +- src/xfaces.c | 10 +- src/xfns.c | 7 +- src/xrdb.c | 23 ++- 21 files changed, 334 insertions(+), 379 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 64ea0a5bcf0..f8acc3b3836 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,37 @@ +2011-07-10 Andreas Schwab + + * buffer.c (mmap_init, mmap_find, mmap_free_1, mmap_enlarge) + (mmap_set_vars, mmap_alloc, mmap_free, mmap_realloc): Protoize. + * data.c (fmod): Likewise. + * dispnew.c (swap_glyphs_in_rows): Likewise. + * emacs.c (memory_warning_signal): Likewise. + * floatfns.c (float_error): Likewise. + * font.c (check_gstring, check_otf_features, otf_tag_symbol) + (otf_open, font_otf_capability, generate_otf_features) + (font_otf_DeviceTable, font_otf_ValueRecord, font_otf_Anchor): + Likewise. + * image.c (pbm_read_file): Likewise. + * indent.c (string_display_width): Likewise. + * intervals.c (check_for_interval, search_for_interval) + (inc_interval_count, count_intervals, root_interval) + (adjust_intervals_for_insertion, make_new_interval): Likewise. + * lread.c (defalias): Likewise. + * regex.c (set_image_of_range_1, set_image_of_range) + (regex_grow_registers): Likewise. + * sysdep.c (strerror): Likewise. + * termcap.c (valid_filename_p, tprint, main): Likewise. + * tparam.c (main): Likewise. + * unexhp9k800.c (run_time_remap, save_data_space) + (update_file_ptrs, read_header, write_header, calculate_checksum) + (copy_file, copy_rest, display_header): Likewise. + * widget.c (mark_shell_size_user_specified, create_frame_gcs): + Likewise. + * xdisp.c (check_it): Likewise. + * xfaces.c (register_color, unregister_color, unregister_colors): + Likewise. + * xfns.c (print_fontset_result): Likewise. + * xrdb.c (member, fatal, main): Likewise. + 2011-07-10 Paul Eggert Fix minor problems found by static checking (Bug#9031). diff --git a/src/buffer.c b/src/buffer.c index e2f34d629e9..1b8b1117893 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -4466,24 +4466,40 @@ static int mmap_initialized_p; #define MMAP_ALLOCATED_P(start, end) 1 #endif -/* Function prototypes. */ +/* Perform necessary intializations for the use of mmap. */ -static int mmap_free_1 (struct mmap_region *); -static int mmap_enlarge (struct mmap_region *, int); -static struct mmap_region *mmap_find (POINTER_TYPE *, POINTER_TYPE *); -static POINTER_TYPE *mmap_alloc (POINTER_TYPE **, size_t); -static POINTER_TYPE *mmap_realloc (POINTER_TYPE **, size_t); -static void mmap_free (POINTER_TYPE **ptr); -static void mmap_init (void); +static void +mmap_init (void) +{ +#if MAP_ANON == 0 + /* The value of mmap_fd is initially 0 in temacs, and -1 + in a dumped Emacs. */ + if (mmap_fd <= 0) + { + /* No anonymous mmap -- we need the file descriptor. */ + mmap_fd = open ("/dev/zero", O_RDONLY); + if (mmap_fd == -1) + fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); + } +#endif /* MAP_ANON == 0 */ + if (mmap_initialized_p) + return; + mmap_initialized_p = 1; + +#if MAP_ANON != 0 + mmap_fd = -1; +#endif + + mmap_page_size = getpagesize (); +} /* Return a region overlapping address range START...END, or null if none. END is not including, i.e. the last byte in the range is at END - 1. */ static struct mmap_region * -mmap_find (start, end) - POINTER_TYPE *start, *end; +mmap_find (POINTER_TYPE *start, POINTER_TYPE *end); { struct mmap_region *r; char *s = (char *) start, *e = (char *) end; @@ -4512,8 +4528,7 @@ mmap_find (start, end) the region. Value is non-zero if successful. */ static int -mmap_free_1 (r) - struct mmap_region *r; +mmap_free_1 (struct mmap_region *r) { if (r->next) r->next->prev = r->prev; @@ -4536,9 +4551,7 @@ mmap_free_1 (r) Value is non-zero if successful. */ static int -mmap_enlarge (r, npages) - struct mmap_region *r; - int npages; +mmap_enlarge (struct mmap_region *r, int npages) { char *region_end = (char *) r + r->nbytes_mapped; size_t nbytes; @@ -4602,8 +4615,7 @@ mmap_enlarge (r, npages) when Emacs starts. */ void -mmap_set_vars (restore_p) - int restore_p; +mmap_set_vars (int restore_p) { struct mmap_region *r; @@ -4636,9 +4648,7 @@ mmap_set_vars (restore_p) return null. */ static POINTER_TYPE * -mmap_alloc (var, nbytes) - POINTER_TYPE **var; - size_t nbytes; +mmap_alloc (POINTER_TYPE **var, size_t nbytes) { void *p; size_t map; @@ -4675,15 +4685,29 @@ mmap_alloc (var, nbytes) } +/* Free a block of relocatable storage whose data is pointed to by + PTR. Store 0 in *PTR to show there's no block allocated. */ + +static void +mmap_free (POINTER_TYPE **var) +{ + mmap_init (); + + if (*var) + { + mmap_free_1 (MMAP_REGION (*var)); + *var = NULL; + } +} + + /* Given a pointer at address VAR to data allocated with mmap_alloc, resize it to size NBYTES. Change *VAR to reflect the new block, and return this value. If more memory cannot be allocated, then leave *VAR unchanged, and return null. */ static POINTER_TYPE * -mmap_realloc (var, nbytes) - POINTER_TYPE **var; - size_t nbytes; +mmap_realloc (POINTER_TYPE **var, size_t nbytes) { POINTER_TYPE *result; @@ -4753,51 +4777,6 @@ mmap_realloc (var, nbytes) } -/* Free a block of relocatable storage whose data is pointed to by - PTR. Store 0 in *PTR to show there's no block allocated. */ - -static void -mmap_free (var) - POINTER_TYPE **var; -{ - mmap_init (); - - if (*var) - { - mmap_free_1 (MMAP_REGION (*var)); - *var = NULL; - } -} - - -/* Perform necessary intializations for the use of mmap. */ - -static void -mmap_init () -{ -#if MAP_ANON == 0 - /* The value of mmap_fd is initially 0 in temacs, and -1 - in a dumped Emacs. */ - if (mmap_fd <= 0) - { - /* No anonymous mmap -- we need the file descriptor. */ - mmap_fd = open ("/dev/zero", O_RDONLY); - if (mmap_fd == -1) - fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); - } -#endif /* MAP_ANON == 0 */ - - if (mmap_initialized_p) - return; - mmap_initialized_p = 1; - -#if MAP_ANON != 0 - mmap_fd = -1; -#endif - - mmap_page_size = getpagesize (); -} - #endif /* USE_MMAP_FOR_BUFFERS */ diff --git a/src/data.c b/src/data.c index 6b4ea32ac9e..7bc04592c57 100644 --- a/src/data.c +++ b/src/data.c @@ -2736,8 +2736,7 @@ Both must be integers or markers. */) #ifndef HAVE_FMOD double -fmod (f1, f2) - double f1, f2; +fmod (double f1, double f2) { double r = f1; diff --git a/src/dispnew.c b/src/dispnew.c index 8691c921853..0026aafafc2 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -1062,8 +1062,7 @@ increment_row_positions (struct glyph_row *row, B without changing glyph pointers in A and B. */ static void -swap_glyphs_in_rows (a, b) - struct glyph_row *a, *b; +swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b) { int area; diff --git a/src/emacs.c b/src/emacs.c index c1d517900ca..bc62735ab88 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -354,8 +354,7 @@ fatal_error_signal (int sig) /* Handler for SIGDANGER. */ void -memory_warning_signal (sig) - int sig; +memory_warning_signal (int sig) { signal (sig, memory_warning_signal); SIGNAL_THREAD_CHECK (sig); diff --git a/src/floatfns.c b/src/floatfns.c index b5c8b4af5c3..e003f492fe6 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -961,8 +961,7 @@ Rounds the value toward zero. */) #ifdef FLOAT_CATCH_SIGILL static void -float_error (signo) - int signo; +float_error (int signo) { if (! in_float) fatal_error_signal (signo); diff --git a/src/font.c b/src/font.c index 5aff20b1346..5f8d22157d6 100644 --- a/src/font.c +++ b/src/font.c @@ -1738,8 +1738,7 @@ font_parse_family_registry (Lisp_Object family, Lisp_Object registry, Lisp_Objec #define LGSTRING_GLYPH_SIZE 8 static int -check_gstring (gstring) - Lisp_Object gstring; +check_gstring (Lisp_Object gstring) { Lisp_Object val; int i, j; @@ -1793,8 +1792,7 @@ check_gstring (gstring) } static void -check_otf_features (otf_features) - Lisp_Object otf_features; +check_otf_features (Lisp_Object otf_features) { Lisp_Object val; @@ -1827,8 +1825,7 @@ check_otf_features (otf_features) Lisp_Object otf_list; static Lisp_Object -otf_tag_symbol (tag) - OTF_Tag tag; +otf_tag_symbol (OTF_Tag tag) { char name[5]; @@ -1837,8 +1834,7 @@ otf_tag_symbol (tag) } static OTF * -otf_open (file) - Lisp_Object file; +otf_open (Lisp_Object file) { Lisp_Object val = Fassoc (file, otf_list); OTF *otf; @@ -1860,8 +1856,7 @@ otf_open (file) (struct font_driver).otf_capability. */ Lisp_Object -font_otf_capability (font) - struct font *font; +font_otf_capability (struct font *font) { OTF *otf; Lisp_Object capability = Fcons (Qnil, Qnil); @@ -1935,9 +1930,7 @@ font_otf_capability (font) FEATURES. */ static void -generate_otf_features (spec, features) - Lisp_Object spec; - char *features; +generate_otf_features (Lisp_Object spec, char *features) { Lisp_Object val; char *p; @@ -1972,8 +1965,7 @@ generate_otf_features (spec, features) } Lisp_Object -font_otf_DeviceTable (device_table) - OTF_DeviceTable *device_table; +font_otf_DeviceTable (OTF_DeviceTable *device_table) { int len = device_table->StartSize - device_table->EndSize + 1; @@ -1982,9 +1974,7 @@ font_otf_DeviceTable (device_table) } Lisp_Object -font_otf_ValueRecord (value_format, value_record) - int value_format; - OTF_ValueRecord *value_record; +font_otf_ValueRecord (int value_format, OTF_ValueRecord *value_record) { Lisp_Object val = Fmake_vector (make_number (8), Qnil); @@ -2008,8 +1998,7 @@ font_otf_ValueRecord (value_format, value_record) } Lisp_Object -font_otf_Anchor (anchor) - OTF_Anchor *anchor; +font_otf_Anchor (OTF_Anchor *anchor) { Lisp_Object val; diff --git a/src/image.c b/src/image.c index 6e8440fb431..fa39ff12681 100644 --- a/src/image.c +++ b/src/image.c @@ -5007,9 +5007,7 @@ pbm_scan_number (unsigned char **s, unsigned char *end) occurred. *SIZE is set to the size of the file. */ static char * -pbm_read_file (file, size) - Lisp_Object file; - int *size; +pbm_read_file (Lisp_Object file, int *size) { FILE *fp = NULL; char *buf = NULL; diff --git a/src/indent.c b/src/indent.c index 02d99d14ded..5c5966175aa 100644 --- a/src/indent.c +++ b/src/indent.c @@ -725,8 +725,7 @@ current_column_1 (void) If END is nil, that stands for the end of STRING. */ static double -string_display_width (string, beg, end) - Lisp_Object string, beg, end; +string_display_width (Lisp_Object string, Lisp_Object beg, Lisp_Object end) { register int col; register unsigned char *ptr, *stop; diff --git a/src/intervals.c b/src/intervals.c index 4de001f2ffc..2063655cdb9 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -247,8 +247,7 @@ static int zero_length; INTERVAL search_interval, found_interval; void -check_for_interval (i) - register INTERVAL i; +check_for_interval (INTERVAL i) { if (i == search_interval) { @@ -258,8 +257,7 @@ check_for_interval (i) } INTERVAL -search_for_interval (i, tree) - register INTERVAL i, tree; +search_for_interval (INTERVAL i, INTERVAL tree) { icount = 0; search_interval = i; @@ -269,8 +267,7 @@ search_for_interval (i, tree) } static void -inc_interval_count (i) - INTERVAL i; +inc_interval_count (INTERVAL i) { icount++; if (LENGTH (i) == 0) @@ -280,8 +277,7 @@ inc_interval_count (i) } int -count_intervals (i) - register INTERVAL i; +count_intervals (INTERVAL i) { icount = 0; idepth = 0; @@ -292,8 +288,7 @@ count_intervals (i) } static INTERVAL -root_interval (interval) - INTERVAL interval; +root_interval (INTERVAL interval) { register INTERVAL i = interval; @@ -804,9 +799,8 @@ update_interval (register INTERVAL i, EMACS_INT pos) to the root. */ static INTERVAL -adjust_intervals_for_insertion (tree, position, length) - INTERVAL tree; - EMACS_INT position, length; +adjust_intervals_for_insertion (INTERVAL tree, EMACS_INT position, + EMACS_INT length) { register EMACS_INT relative_position; register INTERVAL this; @@ -1615,9 +1609,7 @@ reproduce_tree_obj (INTERVAL source, Lisp_Object parent) interval. */ static INTERVAL -make_new_interval (intervals, start, length) - INTERVAL intervals; - EMACS_INT start, length; +make_new_interval (INTERVAL intervals, EMACS_INT start, EMACS_INT length) { INTERVAL slot; diff --git a/src/lread.c b/src/lread.c index a9b69a1977b..6cb217a21c6 100644 --- a/src/lread.c +++ b/src/lread.c @@ -4000,9 +4000,7 @@ defsubr (struct Lisp_Subr *sname) #ifdef NOTDEF /* use fset in subr.el now */ void -defalias (sname, string) - struct Lisp_Subr *sname; - char *string; +defalias (struct Lisp_Subr *sname, char *string) { Lisp_Object sym; sym = intern (string); diff --git a/src/regex.c b/src/regex.c index 479239897bc..625c59ccf0b 100644 --- a/src/regex.c +++ b/src/regex.c @@ -2202,10 +2202,9 @@ extend_range_table_work_area (struct range_table_work_area *work_area) Returns -1 if successful, REG_ESPACE if ran out of space. */ static int -set_image_of_range_1 (work_area, start, end, translate) - RE_TRANSLATE_TYPE translate; - struct range_table_work_area *work_area; - re_wchar_t start, end; +set_image_of_range_1 (struct range_table_work_area *work_area, + re_wchar_t start, re_wchar_t end, + RE_TRANSLATE_TYPE translate) { /* `one_case' indicates a character, or a run of characters, each of which is an isolate (no case-equivalents). @@ -2355,10 +2354,9 @@ set_image_of_range_1 (work_area, start, end, translate) Returns -1 if successful, REG_ESPACE if ran out of space. */ static int -set_image_of_range (work_area, start, end, translate) - RE_TRANSLATE_TYPE translate; - struct range_table_work_area *work_area; - re_wchar_t start, end; +set_image_of_range (struct range_table_work_area *work_area, + re_wchar_t start, re_wchar_t end, + RE_TRANSLATE_TYPE translate) { re_wchar_t cmin, cmax; @@ -2445,8 +2443,7 @@ static re_char **best_regstart, **best_regend; but don't make them smaller. */ static -regex_grow_registers (num_regs) - int num_regs; +regex_grow_registers (int num_regs) { if (num_regs > regs_allocated_size) { diff --git a/src/sysdep.c b/src/sysdep.c index 46667cf292f..fc2f846b0dc 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1802,8 +1802,7 @@ get_random (void) #ifndef HAVE_STRERROR #ifndef WINDOWSNT char * -strerror (errnum) - int errnum; +strerror (int errnum) { extern char *sys_errlist[]; extern int sys_nerr; diff --git a/src/termcap.c b/src/termcap.c index e191f6b3af3..96b9303d62d 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -338,8 +338,7 @@ static int name_match (char *line, char *name); #ifdef MSDOS /* MW, May 1993 */ static int -valid_filename_p (fn) - char *fn; +valid_filename_p (char *fn) { return *fn == '/' || fn[1] == ':'; } @@ -669,9 +668,29 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) #include -main (argc, argv) - int argc; - char **argv; +static void +tprint (char *cap) +{ + char *x = tgetstr (cap, 0); + register char *y; + + printf ("%s: ", cap); + if (x) + { + for (y = x; *y; y++) + if (*y <= ' ' || *y == 0177) + printf ("\\%0o", *y); + else + putchar (*y); + free (x); + } + else + printf ("none"); + putchar ('\n'); +} + +int +main (int argc, char **argv) { char *term; char *buf; @@ -693,27 +712,8 @@ main (argc, argv) printf ("co: %d\n", tgetnum ("co")); printf ("am: %d\n", tgetflag ("am")); -} -tprint (cap) - char *cap; -{ - char *x = tgetstr (cap, 0); - register char *y; - - printf ("%s: ", cap); - if (x) - { - for (y = x; *y; y++) - if (*y <= ' ' || *y == 0177) - printf ("\\%0o", *y); - else - putchar (*y); - free (x); - } - else - printf ("none"); - putchar ('\n'); + return 0; } #endif /* TEST */ diff --git a/src/tparam.c b/src/tparam.c index 6aae0b97db9..ed28cd7397f 100644 --- a/src/tparam.c +++ b/src/tparam.c @@ -265,9 +265,8 @@ tparam1 (const char *string, char *outstring, int len, #ifdef DEBUG -main (argc, argv) - int argc; - char **argv; +int +main (int argc, char **argv) { char buf[50]; int args[3]; diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c index f27415a252c..ce65faffd4e 100644 --- a/src/unexhp9k800.c +++ b/src/unexhp9k800.c @@ -64,8 +64,7 @@ static long brk_on_dump = 0; /* Called from main, if we use shared libraries. */ int -run_time_remap (ignored) - char *ignored; +run_time_remap (char *ignored) { brk ((char *) brk_on_dump); } @@ -74,6 +73,181 @@ run_time_remap (ignored) #define roundup(x,n) (((x) + ((n) - 1)) & ~((n) - 1)) /* n is power of 2 */ #define min(x,y) (((x) < (y)) ? (x) : (y)) +/* Save current data space in the file, update header. */ + +static void +save_data_space (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr, + int size) +{ + /* Write the entire data space out to the file */ + if (write (file, auxhdr->exec_dmem, size) != size) + { perror ("Can't save new data space"); exit (1); } + + /* Update the header to reflect the new data size */ + auxhdr->exec_dsize = size; + auxhdr->exec_bsize = 0; +} + +/* Update the values of file pointers when something is inserted. */ + +static void +update_file_ptrs (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr, + unsigned int location, int offset) +{ + struct subspace_dictionary_record subspace; + int i; + + /* Increase the overall size of the module */ + hdr->som_length += offset; + + /* Update the various file pointers in the header */ +#define update(ptr) if (ptr > location) ptr = ptr + offset + update (hdr->aux_header_location); + update (hdr->space_strings_location); + update (hdr->init_array_location); + update (hdr->compiler_location); + update (hdr->symbol_location); + update (hdr->fixup_request_location); + update (hdr->symbol_strings_location); + update (hdr->unloadable_sp_location); + update (auxhdr->exec_tfile); + update (auxhdr->exec_dfile); + + /* Do for each subspace dictionary entry */ + lseek (file, hdr->subspace_location, 0); + for (i = 0; i < hdr->subspace_total; i++) + { + if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace)) + { perror ("Can't read subspace record"); exit (1); } + + /* If subspace has a file location, update it */ + if (subspace.initialization_length > 0 + && subspace.file_loc_init_value > location) + { + subspace.file_loc_init_value += offset; + lseek (file, -sizeof (subspace), 1); + if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace)) + { perror ("Can't update subspace record"); exit (1); } + } + } + + /* Do for each initialization pointer record */ + /* (I don't think it applies to executable files, only relocatables) */ +#undef update +} + +/* Read in the header records from an a.out file. */ + +static void +read_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr) +{ + + /* Read the header in */ + lseek (file, 0, 0); + if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) + { perror ("Couldn't read header from a.out file"); exit (1); } + + if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC + && hdr->a_magic != DEMAND_MAGIC) + { + fprintf (stderr, "a.out file doesn't have valid magic number\n"); + exit (1); + } + + lseek (file, hdr->aux_header_location, 0); + if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) + { + perror ("Couldn't read auxiliary header from a.out file"); + exit (1); + } +} + +/* Write out the header records into an a.out file. */ + +static void +write_header (int file, struct header *hdr, struct som_exec_auxhdr *auxhdr) +{ + /* Update the checksum */ + hdr->checksum = calculate_checksum (hdr); + + /* Write the header back into the a.out file */ + lseek (file, 0, 0); + if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) + { perror ("Couldn't write header to a.out file"); exit (1); } + lseek (file, hdr->aux_header_location, 0); + if (write (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) + { perror ("Couldn't write auxiliary header to a.out file"); exit (1); } +} + +/* Calculate the checksum of a SOM header record. */ + +static int +calculate_checksum (struct header *hdr) +{ + int checksum, i, *ptr; + + checksum = 0; ptr = (int *) hdr; + + for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++) + checksum ^= ptr[i]; + + return (checksum); +} + +/* Copy size bytes from the old file to the new one. */ + +static void +copy_file (int old, int new, int size) +{ + int len; + int buffer[8192]; /* word aligned will be faster */ + + for (; size > 0; size -= len) + { + len = min (size, sizeof (buffer)); + if (read (old, buffer, len) != len) + { perror ("Read failure on a.out file"); exit (1); } + if (write (new, buffer, len) != len) + { perror ("Write failure in a.out file"); exit (1); } + } +} + +/* Copy the rest of the file, up to EOF. */ + +static void +copy_rest (int old, int new) +{ + int buffer[4096]; + int len; + + /* Copy bytes until end of file or error */ + while ((len = read (old, buffer, sizeof (buffer))) > 0) + if (write (new, buffer, len) != len) break; + + if (len != 0) + { perror ("Unable to copy the rest of the file"); exit (1); } +} + +#ifdef DEBUG +static void +display_header (struct header *hdr, struct som_exec_auxhdr *auxhdr) +{ + /* Display the header information (debug) */ + printf ("\n\nFILE HEADER\n"); + printf ("magic number %d \n", hdr->a_magic); + printf ("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize); + printf ("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize); + printf ("entry %x \n", auxhdr->exec_entry); + printf ("Bss segment size %u\n", auxhdr->exec_bsize); + printf ("\n"); + printf ("data file loc %d size %d\n", + auxhdr->exec_dfile, auxhdr->exec_dsize); + printf ("som_length %d\n", hdr->som_length); + printf ("unloadable sploc %d size %d\n", + hdr->unloadable_sp_location, hdr->unloadable_sp_size); +} +#endif /* DEBUG */ + /* Create a new a.out file, same as old but with current data space */ void @@ -134,189 +308,3 @@ unexec (const char *new_name, /* name of the new a.out file to be created * close (old); close (new); } - -/* Save current data space in the file, update header. */ - -save_data_space (file, hdr, auxhdr, size) - int file; - struct header *hdr; - struct som_exec_auxhdr *auxhdr; - int size; -{ - /* Write the entire data space out to the file */ - if (write (file, auxhdr->exec_dmem, size) != size) - { perror ("Can't save new data space"); exit (1); } - - /* Update the header to reflect the new data size */ - auxhdr->exec_dsize = size; - auxhdr->exec_bsize = 0; -} - -/* Update the values of file pointers when something is inserted. */ - -update_file_ptrs (file, hdr, auxhdr, location, offset) - int file; - struct header *hdr; - struct som_exec_auxhdr *auxhdr; - unsigned int location; - int offset; -{ - struct subspace_dictionary_record subspace; - int i; - - /* Increase the overall size of the module */ - hdr->som_length += offset; - - /* Update the various file pointers in the header */ -#define update(ptr) if (ptr > location) ptr = ptr + offset - update (hdr->aux_header_location); - update (hdr->space_strings_location); - update (hdr->init_array_location); - update (hdr->compiler_location); - update (hdr->symbol_location); - update (hdr->fixup_request_location); - update (hdr->symbol_strings_location); - update (hdr->unloadable_sp_location); - update (auxhdr->exec_tfile); - update (auxhdr->exec_dfile); - - /* Do for each subspace dictionary entry */ - lseek (file, hdr->subspace_location, 0); - for (i = 0; i < hdr->subspace_total; i++) - { - if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace)) - { perror ("Can't read subspace record"); exit (1); } - - /* If subspace has a file location, update it */ - if (subspace.initialization_length > 0 - && subspace.file_loc_init_value > location) - { - subspace.file_loc_init_value += offset; - lseek (file, -sizeof (subspace), 1); - if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace)) - { perror ("Can't update subspace record"); exit (1); } - } - } - - /* Do for each initialization pointer record */ - /* (I don't think it applies to executable files, only relocatables) */ -#undef update -} - -/* Read in the header records from an a.out file. */ - -read_header (file, hdr, auxhdr) - int file; - struct header *hdr; - struct som_exec_auxhdr *auxhdr; -{ - - /* Read the header in */ - lseek (file, 0, 0); - if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) - { perror ("Couldn't read header from a.out file"); exit (1); } - - if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC - && hdr->a_magic != DEMAND_MAGIC) - { - fprintf (stderr, "a.out file doesn't have valid magic number\n"); - exit (1); - } - - lseek (file, hdr->aux_header_location, 0); - if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) - { - perror ("Couldn't read auxiliary header from a.out file"); - exit (1); - } -} - -/* Write out the header records into an a.out file. */ - -write_header (file, hdr, auxhdr) - int file; - struct header *hdr; - struct som_exec_auxhdr *auxhdr; -{ - /* Update the checksum */ - hdr->checksum = calculate_checksum (hdr); - - /* Write the header back into the a.out file */ - lseek (file, 0, 0); - if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) - { perror ("Couldn't write header to a.out file"); exit (1); } - lseek (file, hdr->aux_header_location, 0); - if (write (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) - { perror ("Couldn't write auxiliary header to a.out file"); exit (1); } -} - -/* Calculate the checksum of a SOM header record. */ - -calculate_checksum (hdr) - struct header *hdr; -{ - int checksum, i, *ptr; - - checksum = 0; ptr = (int *) hdr; - - for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++) - checksum ^= ptr[i]; - - return (checksum); -} - -/* Copy size bytes from the old file to the new one. */ - -copy_file (old, new, size) - int new, old; - int size; -{ - int len; - int buffer[8192]; /* word aligned will be faster */ - - for (; size > 0; size -= len) - { - len = min (size, sizeof (buffer)); - if (read (old, buffer, len) != len) - { perror ("Read failure on a.out file"); exit (1); } - if (write (new, buffer, len) != len) - { perror ("Write failure in a.out file"); exit (1); } - } -} - -/* Copy the rest of the file, up to EOF. */ - -copy_rest (old, new) - int new, old; -{ - int buffer[4096]; - int len; - - /* Copy bytes until end of file or error */ - while ((len = read (old, buffer, sizeof (buffer))) > 0) - if (write (new, buffer, len) != len) break; - - if (len != 0) - { perror ("Unable to copy the rest of the file"); exit (1); } -} - -#ifdef DEBUG -display_header (hdr, auxhdr) - struct header *hdr; - struct som_exec_auxhdr *auxhdr; -{ - /* Display the header information (debug) */ - printf ("\n\nFILE HEADER\n"); - printf ("magic number %d \n", hdr->a_magic); - printf ("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize); - printf ("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize); - printf ("entry %x \n", auxhdr->exec_entry); - printf ("Bss segment size %u\n", auxhdr->exec_bsize); - printf ("\n"); - printf ("data file loc %d size %d\n", - auxhdr->exec_dfile, auxhdr->exec_dsize); - printf ("som_length %d\n", hdr->som_length); - printf ("unloadable sploc %d size %d\n", - hdr->unloadable_sp_location, hdr->unloadable_sp_size); -} -#endif /* DEBUG */ diff --git a/src/widget.c b/src/widget.c index 6d871ad7cb2..a09ec2631ad 100644 --- a/src/widget.c +++ b/src/widget.c @@ -224,8 +224,7 @@ get_wm_shell (Widget w) #if 0 /* Currently not used. */ static void -mark_shell_size_user_specified (wmshell) - Widget wmshell; +mark_shell_size_user_specified (Widget wmshell) { if (! XtIsWMShell (wmshell)) abort (); /* This is kind of sleazy, but I can't see how else to tell it to make it @@ -510,8 +509,7 @@ update_wm_hints (EmacsFrame ew) #if 0 static void -create_frame_gcs (ew) - EmacsFrame ew; +create_frame_gcs (EmacsFrame ew) { struct frame *s = ew->emacs_frame.frame; diff --git a/src/xdisp.c b/src/xdisp.c index 774bc22699a..871317d86b8 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -2209,8 +2209,7 @@ safe_call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2) This is for debugging. It is too slow to do unconditionally. */ static void -check_it (it) - struct it *it; +check_it (struct it *it) { if (it->method == GET_FROM_STRING) { diff --git a/src/xfaces.c b/src/xfaces.c index 91f4b133466..c1e75ab3e59 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -536,8 +536,7 @@ int color_count[256]; /* Register color PIXEL as allocated. */ void -register_color (pixel) - unsigned long pixel; +register_color (unsigned long pixel) { xassert (pixel < 256); ++color_count[pixel]; @@ -547,8 +546,7 @@ register_color (pixel) /* Register color PIXEL as deallocated. */ void -unregister_color (pixel) - unsigned long pixel; +unregister_color (unsigned long pixel) { xassert (pixel < 256); if (color_count[pixel] > 0) @@ -561,9 +559,7 @@ unregister_color (pixel) /* Register N colors from PIXELS as deallocated. */ void -unregister_colors (pixels, n) - unsigned long *pixels; - int n; +unregister_colors (unsigned long *pixels, int n) { int i; for (i = 0; i < n; ++i) diff --git a/src/xfns.c b/src/xfns.c index c70f4bb9a82..0d1e4a1bb5e 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -2001,11 +2001,8 @@ xic_create_fontsetname (const char *base_fontname, int motif) #ifdef DEBUG_XIC_FONTSET static void -print_fontset_result (xfs, name, missing_list, missing_count) - XFontSet xfs; - char *name; - char **missing_list; - int missing_count; +print_fontset_result (XFontSet xfs, char *name, char **missing_list, + int missing_count) { if (xfs) fprintf (stderr, "XIC Fontset created: %s\n", name); diff --git a/src/xrdb.c b/src/xrdb.c index e18ff65f799..6a16e3260bd 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -651,9 +651,7 @@ typedef char **List; #define free_arglist(list) static List -member (elt, list) - char *elt; - List list; +member (char *elt, List list) { List p; @@ -665,20 +663,17 @@ member (elt, list) } static void -fatal (msg, prog, x1, x2, x3, x4, x5) - char *msg, *prog; - int x1, x2, x3, x4, x5; +fatal (char *msg, char *prog) { - if (errno) - perror (prog); + if (errno) + perror (prog); - (void) fprintf (stderr, msg, prog, x1, x2, x3, x4, x5); - exit (1); + (void) fprintf (stderr, msg, prog); + exit (1); } -main (argc, argv) - int argc; - char **argv; +int +main (int argc, char **argv) { Display *display; char *displayname, *resource_string, *class, *name; @@ -749,5 +744,7 @@ main (argc, argv) printf ("\tExit.\n\n"); XCloseDisplay (display); + + return 0; } #endif /* TESTRM */