From 143c89a074a95fcc208bb84ef22d4ef45bb265cc Mon Sep 17 00:00:00 2001 From: Taco Hoekwater Date: Mon, 23 Jun 2008 13:13:02 +0000 Subject: [PATCH] some initialization changes, remove the need for non-ini variables git-svn-id: svn+ssh://scm.foundry.supelec.fr/svn/metapost/mplib/trunk@572 b0617d17-b707-0410-b22c-fd2634e05cc4 --- src/texk/web2c/mpdir/mp.w | 344 +++++++++++++++++--------------------- 1 file changed, 153 insertions(+), 191 deletions(-) diff --git a/src/texk/web2c/mpdir/mp.w b/src/texk/web2c/mpdir/mp.w index 01bbfcc..b9735ad 100644 --- a/src/texk/web2c/mpdir/mp.w +++ b/src/texk/web2c/mpdir/mp.w @@ -170,19 +170,22 @@ struct MP_options *mp_options (void) { # define __attribute__(x) #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ -@ @c +@ The whole instance structure is initialized with zeroes, +this greatly reduces the number of statements needed in +the |Allocate or initialize variables| block. + +@d set_callback_option(A) do { mp->A = mp_##A; + if (opt->A!=NULL) mp->A = opt->A; +} while (0) + +@c MP __attribute__ ((noinline)) mp_do_new (struct MP_options *opt, jmp_buf *buf) { MP mp = malloc(sizeof(MP_instance)); if (mp==NULL) return NULL; + memset(mp,0,sizeof(MP_instance)); mp->jump_buf = buf; - @; - @ - if (opt->main_memory>mp->mem_max) - mp_reallocate_memory(mp,opt->main_memory); - mp_reallocate_paths(mp,1000); - mp_reallocate_fonts(mp,8); return mp; } @@ -207,18 +210,36 @@ mp_do_initialize ( MP mp) { @c MP __attribute__ ((noinline)) mp_initialize (struct MP_options *opt) { - jmp_buf buf; MP mp; + jmp_buf buf; + @; mp = mp_do_new(opt, &buf); if (mp == NULL) return NULL; - mp->history=mp_fatal_error_stop; /* in case we quit during initialization */ - @; + @; + mp->noninteractive=opt->noninteractive; + if (*(opt->command_line)) + mp->command_line = xstrdup(opt->command_line); if (mp->noninteractive) { - @; - } else { - t_open_out; /* open the terminal for output */ - } + @; + } + set_callback_option(find_file); + set_callback_option(open_file); + set_callback_option(read_ascii_file); + set_callback_option(read_binary_file); + set_callback_option(close_file); + set_callback_option(eof_file); + set_callback_option(flush_file); + set_callback_option(write_ascii_file); + set_callback_option(write_binary_file); + /* open the terminal for output */ + t_open_out; + @; + @ + mp_reallocate_memory(mp,mp->mem_max); + mp_reallocate_paths(mp,1000); + mp_reallocate_fonts(mp,8); + mp->history=mp_fatal_error_stop; /* in case we quit during initialization */ @; if ( mp->bad>0 ) { char ss[256]; @@ -338,22 +359,6 @@ int main_memory; /* only for options, to set up |mem_max| and |mem_top| */ void *userdata; /* this allows the calling application to setup local */ -@ The code below make the final chosen hash size the next larger -multiple of 2 from the requested size, and this array is a list of -suitable prime numbers to go with such values. - -The top limit is chosen such that it is definately lower than -|max_halfword-3*param_size|, because |param_size| cannot be larger -than |max_halfword/sizeof(pointer)|. - -@= -static int mp_prime_choices[] = - { 12289, 24593, 49157, 98317, - 196613, 393241, 786433, 1572869, - 3145739, 6291469, 12582917, 25165843, - 50331653, 100663319 }; - - @ @d set_value(a,b,c) do { a=c; if (b>c) a=b; } while (0) @@ -365,24 +370,6 @@ set_value(mp->half_error_line,opt->half_error_line,50); if (mp->half_error_line>mp->error_line-15 ) mp->half_error_line = mp->error_line-15; set_value(mp->max_print_line,opt->max_print_line,100); -mp->main_memory=5000; -mp->mem_max=5000; -mp->mem_top=5000; -if (opt->hash_size>0x8000000) opt->hash_size=0x8000000; -set_value(mp->hash_size,(2*opt->hash_size-1),16384); -{ - int i = 14; - mp->hash_size = mp->hash_size>>i; - while (mp->hash_size>=2) { - mp->hash_size /= 2; - i++; - } - mp->hash_size = mp->hash_size << i; - if (mp->hash_size>0x8000000) mp->hash_size=0x8000000; - mp->hash_prime=mp_prime_choices[(i-14)]; -} -set_value(mp->param_size,opt->param_size,150); -set_value(mp->max_in_open,opt->max_in_open,10); mp->userdata=opt->userdata; @ In case somebody has inadvertently made bad settings of the ``constants,'' @@ -449,16 +436,6 @@ that the character set contains at least the letters and symbols associated with ASCII codes 040 through 0176; all of these characters are now available on most computer terminals. -We shall use the name |text_char| to stand for the data type of the characters -that are converted to and from |ASCII_code| when they are input and output. -We shall also assume that |text_char| consists of the elements -|chr(first_text_char)| through |chr(last_text_char)|, inclusive. -The following definitions should be adjusted if necessary. -@^system dependencies@> - -@d first_text_char 0 /* ordinal number of the smallest element of |text_char| */ -@d last_text_char 255 /* ordinal number of the largest element of |text_char| */ - @= typedef unsigned char text_char; /* the data type of characters in text files */ @@ -500,7 +477,7 @@ where |i= -for (i=first_text_char;i<=last_text_char;i++) { +for (i=0;i<=255;i++) { xord(xchr(i))=0177; } for (i=0200;i<=0377;i++) { xord(xchr(i))=i;} @@ -591,24 +568,6 @@ char *mp_find_file (MP mp, const char *fname, const char *fmode, int ftype) { return NULL; } -@ This has to be done very early on, so it is best to put it in with -the |mp_new| allocations - -@d set_callback_option(A) do { mp->A = mp_##A; - if (opt->A!=NULL) mp->A = opt->A; -} while (0) - -@= -set_callback_option(find_file); -set_callback_option(open_file); -set_callback_option(read_ascii_file); -set_callback_option(read_binary_file); -set_callback_option(close_file); -set_callback_option(eof_file); -set_callback_option(flush_file); -set_callback_option(write_ascii_file); -set_callback_option(write_binary_file); - @ Because |mp_find_file| is used so early, it has to be in the helpers section. @@ -902,9 +861,6 @@ initialization. @