Unit tests for CWEB
[ohcount] / test / expected_dir / cweb.w / c / code
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)"
5 @d true 1
6 @d false 0
7 typedef struct MP_instance * MP;
8 typedef struct MP_options {
9 } MP_options;
10 #include <setjmp.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdarg.h>
15 #include <assert.h>
16 #include <unistd.h> /* for access() */
17 #include <time.h> /* for struct tm \& co */
18 #include "mplib.h"
19 #include "mpmp.h" /* internal header */
20 #include "mppsout.h" /* internal header */
21 @h
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) {
27 }
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 */
31 if ( mp->bad>0 ) {
32 char ss[256];
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);
36 return mp->history;
37 }
38 mp_do_initialize(mp); /* erase preloaded mem */
39 if (mp->ini_version) {
40 }
41 mp_set_job_id(mp);
42 mp_init_map_file(mp, mp->troff_mode);
43 mp->history=mp_spotless; /* ready to go! */
44 if (mp->troff_mode) {
45 mp->internal[mp_gtroffmode]=unity; 
46 mp->internal[mp_prologues]=unity; 
47 }
48 if ( mp->start_sym>0 ) { /* insert the `\&{everyjob}' symbol */
49 mp->cur_sym=mp->start_sym; mp_back_input(mp);
50 }
51 return mp->history;
52 }
53 for (i=first_text_char;i<=last_text_char;i++) { 
54 xord(chr(i))=0177;
55 }
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 */
60 t_open_in; 
61 if (mp->last!=0) {
62 loc = mp->first = 0;
63 return true;
64 }
65 while (1) { 
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?");
69 return false;
70 }
71 loc=mp->first;
72 while ( (loc<(int)mp->last)&&(mp->buffer[loc]==' ') ) 
73 incr(loc);
74 if ( loc<(int)mp->last ) { 
75 return true; /* return unless the line was all blank */
76 };
77 do_fprintf(mp->term_out,"Please type the name of your input file.\n");
78 }
79 }
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 */
119 integer k;
120 int l,m,n;
121 char *aline;
122 size_t len;
123 while (1) { 
124 wake_up_terminal;
125 mp_print_nl(mp, "debug # (-1 to exit):"); update_terminal;
126 m = 0;
127 aline = (mp->read_ascii_file)(mp->term_in, &len);
128 if (len) { sscanf(aline,"%i",&m); xfree(aline); }
129 if ( m<=0 )
130 return;
131 n = 0 ;
132 aline = (mp->read_ascii_file)(mp->term_in, &len);
133 if (len) { sscanf(aline,"%i",&n); xfree(aline); }
134 switch (m) {
135 default: mp_print(mp, "?"); break;
136 }
137 }
138 }
139 case 1: mp_print_word(mp, mp->mem[n]); /* display |mem[n]| in all forms */
140 break;
141 case 2: mp_print_int(mp, info(n));
142 break;
143 case 3: mp_print_int(mp, link(n));
144 break;
145 case 4: mp_print_int(mp, eq_type(n)); mp_print_char(mp, ':'); mp_print_int(mp, equiv(n));
146 break;
147 case 5: mp_print_variable_name(mp, n);
148 break;
149 case 6: mp_print_int(mp, mp->internal[n]);
150 break;
151 case 7: mp_do_show_dependencies(mp);
152 break;
153 case 9: mp_show_token_list(mp, n,null,100000,0);
154 break;
155 case 10: mp_print_str(mp, n);
156 break;
157 case 11: mp_check_mem(mp, n>0); /* check wellformedness; print new busy locations if |n>0| */
158 break;
159 case 12: mp_search_mem(mp, n); /* look for pointers to |n| */
160 break;
161 case 13: 
162 l = 0;  
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); 
166 break;
167 case 14: for (k=0;k<=n;k++) mp_print_str(mp, mp->buffer[k]);
168 break;
169 case 15: mp->panicking=! mp->panicking;
170 break;
171
172 if ( mp->filename_template!=0 ) delete_str_ref(mp->filename_template);
173 if ( length(mp->cur_exp)==0 ) mp->filename_template=0;
174 else { 
175 mp->filename_template=mp->cur_exp; add_str_ref(mp->filename_template);
176 }
177 }