1 @d banner "This is MetaPost, Version 1.002" /* printed when \MP\ starts */
2 @d metapost_version "1.002"
3 @d mplib_version "0.20"
4 @d version_string " (Cweb version 0.20)"
7 typedef struct MP_instance * MP;
8 typedef struct MP_options {
16 #include <unistd.h> /* for access() */
17 #include <time.h> /* for struct tm \& co */
19 #include "mpmp.h" /* internal header */
20 #include "mppsout.h" /* internal header */
22 #if !defined(__GNUC__) || (__GNUC__ < 2)
23 # define __attribute__(x)
24 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
25 void __attribute__((noinline))
26 mp_do_initialize ( MP mp) {
28 int mp_initialize (MP mp) { /* this procedure gets things started properly */
29 mp->history=mp_fatal_error_stop; /* in case we quit during initialization */
30 t_open_out; /* open the terminal for output */
33 snprintf(ss,256,"Ouch---my internal constants have been clobbered!\n"
34 "---case %i",(int)mp->bad);
35 do_fprintf(mp->err_out,(char *)ss);
38 mp_do_initialize(mp); /* erase preloaded mem */
39 if (mp->ini_version) {
42 mp_init_map_file(mp, mp->troff_mode);
43 mp->history=mp_spotless; /* ready to go! */
45 mp->internal[mp_gtroffmode]=unity;
46 mp->internal[mp_prologues]=unity;
48 if ( mp->start_sym>0 ) { /* insert the `\&{everyjob}' symbol */
49 mp->cur_sym=mp->start_sym; mp_back_input(mp);
53 for (i=first_text_char;i<=last_text_char;i++) {
56 for (i=0200;i<=0377;i++) { xord(xchr(i))=i;}
57 for (i=0;i<=0176;i++) { xord(xchr(i))=i;}
58 @d loc mp->cur_input.loc_field /* location of first unread character in |buffer| */
59 boolean mp_init_terminal (MP mp) { /* gets the terminal input started */
66 wake_up_terminal; do_fprintf(mp->term_out,"**"); update_terminal;
67 if ( ! mp_input_ln(mp, mp->term_in ) ) { /* this shouldn't happen */
68 do_fprintf(mp->term_out,"\n! End of file on the terminal... why?");
72 while ( (loc<(int)mp->last)&&(mp->buffer[loc]==' ') )
74 if ( loc<(int)mp->last ) {
75 return true; /* return unless the line was all blank */
77 do_fprintf(mp->term_out,"Please type the name of your input file.\n");
80 boolean mp_init_terminal (MP mp) ;
81 mp_primitive(mp, "tracingtitles",internal_quantity,mp_tracing_titles);
82 mp_primitive(mp, "tracingequations",internal_quantity,mp_tracing_equations);
83 mp_primitive(mp, "tracingcapsules",internal_quantity,mp_tracing_capsules);
84 mp_primitive(mp, "tracingchoices",internal_quantity,mp_tracing_choices);
85 mp_primitive(mp, "tracingspecs",internal_quantity,mp_tracing_specs);
86 mp_primitive(mp, "tracingcommands",internal_quantity,mp_tracing_commands);
87 mp_primitive(mp, "tracingrestores",internal_quantity,mp_tracing_restores);
88 mp_primitive(mp, "tracingmacros",internal_quantity,mp_tracing_macros);
89 mp_primitive(mp, "tracingoutput",internal_quantity,mp_tracing_output);
90 mp_primitive(mp, "tracingstats",internal_quantity,mp_tracing_stats);
91 mp_primitive(mp, "tracinglostchars",internal_quantity,mp_tracing_lost_chars);
92 mp_primitive(mp, "tracingonline",internal_quantity,mp_tracing_online);
93 mp_primitive(mp, "year",internal_quantity,mp_year);
94 mp_primitive(mp, "month",internal_quantity,mp_month);
95 mp_primitive(mp, "day",internal_quantity,mp_day);
96 mp_primitive(mp, "time",internal_quantity,mp_time);
97 mp_primitive(mp, "charcode",internal_quantity,mp_char_code);
98 mp_primitive(mp, "charext",internal_quantity,mp_char_ext);
99 mp_primitive(mp, "charwd",internal_quantity,mp_char_wd);
100 mp_primitive(mp, "charht",internal_quantity,mp_char_ht);
101 mp_primitive(mp, "chardp",internal_quantity,mp_char_dp);
102 mp_primitive(mp, "charic",internal_quantity,mp_char_ic);
103 mp_primitive(mp, "designsize",internal_quantity,mp_design_size);
104 mp_primitive(mp, "pausing",internal_quantity,mp_pausing);
105 mp_primitive(mp, "showstopping",internal_quantity,mp_showstopping);
106 mp_primitive(mp, "fontmaking",internal_quantity,mp_fontmaking);
107 mp_primitive(mp, "linejoin",internal_quantity,mp_linejoin);
108 mp_primitive(mp, "linecap",internal_quantity,mp_linecap);
109 mp_primitive(mp, "miterlimit",internal_quantity,mp_miterlimit);
110 mp_primitive(mp, "warningcheck",internal_quantity,mp_warning_check);
111 mp_primitive(mp, "boundarychar",internal_quantity,mp_boundary_char);
112 mp_primitive(mp, "prologues",internal_quantity,mp_prologues);
113 mp_primitive(mp, "truecorners",internal_quantity,mp_true_corners);
114 mp_primitive(mp, "mpprocset",internal_quantity,mp_procset);
115 mp_primitive(mp, "troffmode",internal_quantity,mp_gtroffmode);
116 mp_primitive(mp, "defaultcolormodel",internal_quantity,mp_default_color_model);
117 mp_primitive(mp, "restoreclipcolor",internal_quantity,mp_restore_clip_color);
118 void mp_debug_help (MP mp) { /* routine to display various things */
125 mp_print_nl(mp, "debug # (-1 to exit):"); update_terminal;
127 aline = (mp->read_ascii_file)(mp->term_in, &len);
128 if (len) { sscanf(aline,"%i",&m); xfree(aline); }
132 aline = (mp->read_ascii_file)(mp->term_in, &len);
133 if (len) { sscanf(aline,"%i",&n); xfree(aline); }
135 default: mp_print(mp, "?"); break;
139 case 1: mp_print_word(mp, mp->mem[n]); /* display |mem[n]| in all forms */
141 case 2: mp_print_int(mp, info(n));
143 case 3: mp_print_int(mp, link(n));
145 case 4: mp_print_int(mp, eq_type(n)); mp_print_char(mp, ':'); mp_print_int(mp, equiv(n));
147 case 5: mp_print_variable_name(mp, n);
149 case 6: mp_print_int(mp, mp->internal[n]);
151 case 7: mp_do_show_dependencies(mp);
153 case 9: mp_show_token_list(mp, n,null,100000,0);
155 case 10: mp_print_str(mp, n);
157 case 11: mp_check_mem(mp, n>0); /* check wellformedness; print new busy locations if |n>0| */
159 case 12: mp_search_mem(mp, n); /* look for pointers to |n| */
163 aline = (mp->read_ascii_file)(mp->term_in, &len);
164 if (len) { sscanf(aline,"%i",&l); xfree(aline); }
165 mp_print_cmd_mod(mp, n,l);
167 case 14: for (k=0;k<=n;k++) mp_print_str(mp, mp->buffer[k]);
169 case 15: mp->panicking=! mp->panicking;
172 if ( mp->filename_template!=0 ) delete_str_ref(mp->filename_template);
173 if ( length(mp->cur_exp)==0 ) mp->filename_template=0;
175 mp->filename_template=mp->cur_exp; add_str_ref(mp->filename_template);