Cygwin: /proc/<PID>/stat: set field (18) according to scheduling policy
[newlib-cygwin.git] / newlib / doc / makedoc.c
blob81aa6f9412949892fa2c14be99922f52b23c9a61
1 /* chew
2 Copyright (C) 1990-1992 Free Software Foundation, Inc.
3 Contributed by steve chamberlain @cygnus
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 Yet another way of extracting documentation from source.
22 No, I haven't finished it yet, but I hope you people like it better
23 that the old way
25 sac
27 Basically, this is a sort of string forth, maybe we should call it
28 struth?
30 You define new words thus:
31 : <newword> <oldwords> ;
32 There is no
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <ctype.h>
41 #include <string.h>
42 #include <stdint.h>
44 #define DEF_SIZE 5000
45 #define STACK 50
46 #define MIN_CMDLEN 4 /* Minimum length of a command */
48 int internal_wanted;
49 int internal_mode;
50 int Verbose=0;
54 /* Here is a string type ... */
56 typedef struct buffer
58 char *ptr;
59 unsigned int write_idx;
60 unsigned int size;
61 } string_type;
69 static void
70 init_string_with_size (string_type *buffer, unsigned int size)
72 buffer->write_idx = 0;
73 buffer->size = size;
74 buffer->ptr = malloc(size);
77 static void
78 init_string (string_type *buffer)
80 init_string_with_size(buffer, DEF_SIZE);
84 static int
85 find (string_type *str, char *what)
87 unsigned int i;
88 char *p;
89 p = what;
90 for (i = 0; i < str->write_idx && *p; i++)
92 if (*p == str->ptr[i])
93 p++;
94 else
95 p = what;
97 return (*p == 0);
101 static void
102 write_buffer (string_type *buffer)
104 fwrite(buffer->ptr, buffer->write_idx, 1, stdout);
108 static void
109 delete_string (string_type *buffer)
111 free(buffer->ptr);
115 static char *
116 addr (string_type *buffer, unsigned int idx)
118 return buffer->ptr + idx;
121 static char
122 at (string_type *buffer, unsigned int pos)
124 if ( pos >= buffer->write_idx)
126 return 0;
128 return buffer->ptr[pos];
131 static void
132 catchar (string_type *buffer, char ch)
134 if (buffer->write_idx == buffer->size)
136 buffer->size *=2;
137 buffer->ptr = realloc(buffer->ptr, buffer->size);
138 if (!buffer->ptr)
140 fprintf(stderr,"Can't allocate memory\n");
141 exit(1);
145 buffer->ptr[buffer->write_idx ++ ] = ch;
149 static void
150 overwrite_string (string_type *dst, string_type *src)
152 free(dst->ptr);
153 dst->size = src->size;
154 dst->write_idx = src->write_idx;
155 dst->ptr = src->ptr;
158 static void
159 catstr (string_type *dst, string_type *src)
161 unsigned int i;
162 for (i = 0; i < src->write_idx; i++)
164 catchar(dst, src->ptr[i]);
169 static void
170 cattext (string_type *buffer, char *string)
173 while (*string)
175 catchar(buffer, *string);
176 string++;
180 static void
181 catbuf (string_type *buffer, char *buf, unsigned int len)
184 while (len--)
186 catchar(buffer, *buf);
187 buf++;
193 static unsigned int
194 skip_white_and_stars (string_type *src, unsigned int idx)
196 while (isspace(at(src,idx))
197 || (at(src,idx) == '*' && at(src,idx +1) !='/'))
198 idx++;
199 return idx;
203 /***********************************************************************/
206 string_type stack[STACK];
207 string_type *tos;
209 unsigned int idx = 0; /* Pos in input buffer */
210 string_type *ptr; /* and the buffer */
211 typedef void (*stinst_type)(void);
212 stinst_type *pc;
213 stinst_type sstack[STACK];
214 stinst_type *ssp = &sstack[0];
215 uintptr_t istack[STACK];
216 uintptr_t *isp = &istack[0];
218 typedef uintptr_t *word_type;
222 struct dict_struct
224 char *word;
225 struct dict_struct *next;
226 stinst_type *code;
227 int code_length;
228 int code_end;
229 int var;
232 typedef struct dict_struct dict_type;
233 #define WORD(x) static void x(void)
235 static void
236 exec (dict_type *word)
238 pc = word->code;
239 while (*pc)
241 (*pc)();
245 WORD(call)
247 stinst_type *oldpc = pc;
248 dict_type *e;
249 e = (dict_type *)(pc [1]);
250 exec(e);
251 pc = oldpc + 2;
255 WORD(remchar)
257 tos->write_idx--;
258 pc++;
262 WORD(push_number)
264 isp++;
265 pc++;
266 *isp = (uintptr_t)(*pc);
267 pc++;
274 WORD(push_text)
277 tos++;
278 init_string(tos);
279 pc++;
280 cattext(tos,*((char **)pc));
281 pc++;
287 /* This function removes everything not inside comments starting on
288 the first char of the line from the string, also when copying
289 comments, removes blank space and leading *'s
290 Blank lines are turned into one blank line
293 static void
294 remove_noncomments (string_type *src, string_type *dst)
296 unsigned int idx = 0;
298 while (at(src,idx))
300 /* Now see if we have a comment at the start of the line */
301 if (at(src,idx) == '\n'
302 && at(src,idx+1) == '/'
303 && at(src,idx+2) == '*')
305 idx+=3;
307 idx = skip_white_and_stars(src,idx);
309 /* Remove leading dot */
310 if (at(src, idx) == '.')
311 idx++;
313 /* Copy to the end of the line, or till the end of the
314 comment */
315 while (at(src, idx))
317 if (at(src, idx) == '\n')
319 /* end of line, echo and scrape of leading blanks */
320 if (at(src,idx +1) == '\n')
321 catchar(dst,'\n');
322 catchar(dst,'\n');
323 idx++;
324 idx = skip_white_and_stars(src, idx);
326 else if (at(src, idx) == '*' && at(src,idx+1) == '/')
328 idx +=2 ;
329 cattext(dst,"\nENDDD\n");
330 break;
332 else
334 catchar(dst, at(src, idx));
335 idx++;
339 else idx++;
342 /* turn foobar name(stuff); into foobar EXFUN(name,(stuff));
346 static void
347 exfunstuff (void)
349 unsigned int openp;
350 unsigned int fname;
351 unsigned int idx;
352 string_type out;
353 init_string(&out);
356 /* make sure that it's not already exfuned */
357 if(find(tos,"EXFUN") || find(tos,"PROTO") || !find(tos,"(")) {
358 catstr(&out,tos);
360 else
363 /*Find the open paren*/
364 for (openp = 0; at(tos, openp) != '(' && at(tos,openp); openp++)
367 fname = openp;
368 /* Step back to the fname */
369 fname--;
370 while (fname && isspace(at(tos, fname)))
371 fname --;
372 while (fname && !isspace(at(tos,fname)) && at(tos,fname) != '*')
373 fname--;
375 fname++;
377 for (idx = 0; idx < fname; idx++)
379 catchar(&out, at(tos,idx));
382 cattext(&out,"EXFUN(");
383 for (idx = fname; idx < openp; idx++)
385 catchar(&out, at(tos,idx));
387 cattext(&out,", ");
388 while (at(tos,idx) && at(tos,idx) !=';')
390 catchar(&out, at(tos, idx));
391 idx++;
393 cattext(&out,");\n");
395 overwrite_string(tos, &out);
396 pc++;
402 /* turn {*
403 and *} into comments */
405 WORD(translatecomments)
407 unsigned int idx = 0;
408 string_type out;
409 init_string(&out);
411 while (at(tos, idx))
413 if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
415 cattext(&out," /*");
416 idx+=2;
418 else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
420 cattext(&out,"*/");
421 idx+=2;
423 else
425 catchar(&out, at(tos, idx));
426 idx++;
431 overwrite_string(tos, &out);
433 pc++;
437 #if 0
438 /* turn everything not starting with a . into a comment */
440 WORD(manglecomments)
442 unsigned int idx = 0;
443 string_type out;
444 init_string(&out);
446 while (at(tos, idx))
448 if (at(tos,idx) == '\n' && at(tos,idx+1) =='*')
450 cattext(&out," /*");
451 idx+=2;
453 else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
455 cattext(&out,"*/");
456 idx+=2;
458 else
460 catchar(&out, at(tos, idx));
461 idx++;
466 overwrite_string(tos, &out);
468 pc++;
471 #endif
473 /* Mod tos so that only lines with leading dots remain */
474 static void
475 outputdots (void)
477 unsigned int idx = 0;
478 string_type out;
479 init_string(&out);
481 while (at(tos, idx))
483 if (at(tos, idx) == '\n' && at(tos, idx+1) == '.')
485 idx += 2;
487 while (at(tos, idx) && at(tos, idx)!='\n')
489 if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
491 cattext(&out," /*");
492 idx+=2;
494 else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
496 cattext(&out,"*/");
497 idx+=2;
499 else
501 catchar(&out, at(tos, idx));
502 idx++;
505 catchar(&out,'\n');
507 else
509 idx++;
513 overwrite_string(tos, &out);
514 pc++;
518 /* Find lines starting with . and | and put example around them on tos
519 turn
520 {* into open comment and *} into close comment
521 escape curlies
524 WORD(courierize)
526 string_type out;
527 unsigned int idx = 0;
529 init_string(&out);
531 while (at(tos, idx))
533 if (at(tos, idx) == '\n'
534 && (at(tos, idx +1 ) == '.'
535 || at(tos,idx+1) == '|'))
537 cattext(&out,"\n@smallexample\n");
540 idx += 2;
542 while (at(tos, idx) && at(tos, idx)!='\n')
544 if (at(tos,idx)=='{' && at(tos,idx+1) =='*')
546 cattext(&out," /*");
547 idx+=2;
549 else if (at(tos,idx)=='*' && at(tos,idx+1) =='}')
551 cattext(&out,"*/");
552 idx+=2;
554 else if (at(tos,idx) == '{')
556 cattext(&out,"@{");
557 idx++;
559 else if (at(tos,idx) == '}')
561 cattext(&out,"@}");
562 idx++;
564 else
566 catchar(&out, at(tos, idx));
567 idx++;
571 catchar(&out,'\n');
573 while (at(tos, idx) == '\n'
574 && (at(tos, idx+1) == '.')
575 || (at(tos,idx+1) == '|'));
576 cattext(&out,"@end smallexample");
578 else
580 catchar(&out, at(tos, idx));
581 idx++;
585 overwrite_string(tos, &out);
586 pc++;
592 bulletize: look for bullet item commands at start of line
593 Bullet list:
594 O+ emit @itemize @bullet
595 o emit @item [note lowercase]
596 O- emit @end itemize
598 Variable label list:
599 o+ emit @table @code
600 o emit @item
601 o- emit @end table
605 WORD(bulletize)
607 unsigned int idx = 0;
608 string_type out;
609 init_string(&out);
611 while (at(tos, idx)) {
612 if (at(tos, idx) == '\n' && at(tos, idx+1) == 'o')
614 if (at(tos,idx+2) == '+') {
615 cattext(&out,"\n@table @code\n");
616 idx+=3;
618 else if (at(tos,idx+2) == '-') {
619 cattext(&out,"\n@end table\n");
620 idx+=3;
622 else if (isspace(at(tos,idx+2))) {
623 cattext(&out,"\n@item ");
624 idx+=3;
626 else {
627 catchar(&out, at(tos, idx));
628 idx++;
632 else
633 if (at(tos, idx) == '\n' && at(tos, idx+1) == 'O')
635 if (at(tos,idx+2) == '+') {
636 cattext(&out,"\n@itemize @bullet\n");
637 idx+=3;
640 else if (at(tos,idx+2) == '-') {
641 cattext(&out,"\n@end itemize\n");
642 idx+=3;
644 else {
645 catchar(&out, at(tos, idx));
646 idx++;
649 else
651 catchar(&out, at(tos, idx));
652 idx++;
656 delete_string(tos);
657 *tos = out;
658 pc++;
662 /* Turn <<foo>> into @code{foo} in place at TOS
663 Turn <[foo]> into @var{foo} in place at TOS
664 nest them too !
669 WORD(do_fancy_stuff)
671 unsigned int idx = 0;
672 string_type out;
673 init_string(&out);
674 while (at(tos, idx))
676 if (at(tos, idx) == '<'
677 && at(tos, idx+1) == '<'
678 && (!isspace(at(tos,idx + 2)) || at(tos,idx+3) == '>'))
680 /* This qualifies as a << startup */
681 idx +=2;
682 cattext(&out,"@code{");
685 else if (at(tos, idx) == '<'
686 && at(tos, idx+1) == '['
687 && !isspace(at(tos,idx + 2)))
689 /* This qualifies as a <[ startup */
690 idx +=2;
691 cattext(&out,"@var{");
693 else if (at(tos, idx) == '>'
694 && at(tos,idx+1) =='>')
697 cattext(&out,"}");
698 idx+=2;
700 else if (at(tos, idx) == ']'
701 && at(tos,idx+1) =='>')
703 cattext(&out,"}");
704 idx+=2;
706 else
708 catchar(&out, at(tos, idx));
709 idx++;
712 delete_string(tos);
713 *tos = out;
714 pc++;
717 /* A command is all upper case,and alone on a line */
718 static int
719 iscommand (string_type *ptr, unsigned int idx)
721 unsigned int len = 0;
723 while (isupper(at(ptr,idx)) || at(ptr,idx) == '_') {
724 len++;
725 idx++;
728 while (at(ptr,idx) == ' ') {
729 len++;
730 idx++;
733 if(at(ptr,idx) == '\n')
735 /* The length check will never fail on a real command
736 * because the commands are screened as the definitions file
737 * is read. */
738 if (len >= MIN_CMDLEN) return 1;
739 return 0;
742 return 0;
747 unsigned int
748 copy_past_newline (string_type *ptr, unsigned int idx, string_type *dst)
750 while (at(ptr, idx) && at(ptr, idx) != '\n')
752 catchar(dst, at(ptr, idx));
753 idx++;
756 catchar(dst, at(ptr, idx));
757 idx++;
758 return idx;
762 WORD(icopy_past_newline)
764 tos++;
765 init_string(tos);
766 idx = copy_past_newline(ptr, idx, tos);
767 pc++;
771 /* indent
772 Take the string at the top of the stack, do some prettying */
777 WORD(kill_bogus_lines)
779 int sl ;
781 int idx = 0;
782 int c;
783 int dot = 0 ;
785 string_type out;
786 init_string(&out);
787 /* Drop leading nl */
788 while (at(tos,idx) == '\n')
790 idx++;
792 c = idx;
794 /* Find the last char */
795 while (at(tos,idx))
797 idx++;
800 /* find the last non white before the nl */
801 idx--;
803 while (idx && isspace(at(tos,idx)))
804 idx--;
805 idx++;
807 /* Copy buffer upto last char, but blank lines before and after
808 dots don't count */
809 sl = 1;
811 while (c < idx)
813 if (at(tos,c) == '\n'
814 && at(tos,c+1) == '\n'
815 && at(tos,c+2) == '.')
817 /* Ignore two linelines before a dot*/
818 c++;
820 else if (at(tos,c) == '.' && sl)
822 /* remember that this line started with a dot */
823 dot=2;
825 else if (at(tos,c) == '\n'
826 && at(tos,c+1) == '\n'
827 && dot)
829 c++;
830 /* Ignore two newlines when last line was dot */
833 catchar(&out, at(tos,c));
834 if (at(tos,c) == '\n')
836 sl = 1;
838 if (dot == 2)dot=1;else dot = 0;
841 c++;
845 /* Append nl*/
846 catchar(&out, '\n');
847 pc++;
848 delete_string(tos);
849 *tos = out;
854 WORD(indent)
856 string_type out;
857 int tab = 0;
858 int idx = 0;
859 int ol =0;
860 init_string(&out);
861 while (at(tos,idx)) {
862 switch (at(tos,idx))
864 case '\n':
865 cattext(&out,"\n");
866 idx++;
867 if (tab)
869 cattext(&out," ");
871 ol = 0;
872 break;
873 case '(':
874 tab++;
875 if (ol == 0)
876 cattext(&out," ");
877 idx++;
878 cattext(&out,"(");
879 ol = 1;
880 break;
881 case ')':
882 tab--;
883 cattext(&out,")");
884 idx++;
885 ol=1;
887 break;
888 default:
889 catchar(&out,at(tos,idx));
890 ol=1;
892 idx++;
893 break;
897 pc++;
898 delete_string(tos);
899 *tos = out;
903 /* Change the TOS so that all that is left is the stuff inside the
904 first <<foo>> .
907 WORD(get_stuff_in_angle)
909 unsigned int idx = 0;
910 string_type out;
911 init_string(&out);
913 while (at(tos, idx))
915 if (at(tos,idx) == '<' && at(tos,idx+1) =='<')
917 idx+=2;
919 while (!(at(tos,idx) == '>' && at(tos,idx+1) == '>'))
921 catchar(&out, at(tos, idx));
922 idx++;
924 break;
926 idx++;
928 catchar(&out,'\n');
930 overwrite_string(tos, &out);
931 pc++;
935 WORD(get_stuff_in_command)
937 tos++;
938 init_string(tos);
940 while (at(ptr, idx)) {
941 if (iscommand(ptr, idx)) break;
942 idx = copy_past_newline(ptr, idx, tos);
944 pc++;
947 WORD(swap)
949 string_type t;
951 t = tos[0];
952 tos[0] = tos[-1];
953 tos[-1] =t;
954 pc++;
958 WORD(dup_)
960 tos++;
961 init_string(tos);
962 catstr(tos, tos-1);
963 pc++;
969 WORD(icatstr)
971 catstr(tos-1, tos);
972 delete_string(tos);
973 tos--;
974 pc++;
978 WORD(skip_past_newline)
980 while (at(ptr,idx)
981 && at(ptr,idx) != '\n')
982 idx++;
983 idx++;
984 pc++;
988 WORD(internalmode)
990 internal_mode = *(isp);
991 isp--;
992 pc++;
995 WORD(maybecatstr)
997 if (internal_wanted == internal_mode)
999 catstr(tos-1, tos);
1001 delete_string(tos);
1002 tos--;
1003 pc++;
1007 /* write tos to stderr */
1008 WORD(warn)
1010 fputs("Warning: ", stderr);
1011 fwrite(tos->ptr, tos->write_idx, 1, stderr);
1012 fputc('\n', stderr);
1013 delete_string(tos);
1014 tos--;
1015 pc++;
1018 char *
1019 nextword (char *string, char **word)
1021 char *word_start;
1022 int idx;
1023 char *dst;
1024 char *src;
1026 int length = 0;
1028 while (isspace(*string) || *string == '-') {
1029 if (*string == '-')
1031 while (*string && *string != '\n')
1032 string++;
1035 else {
1036 string++;
1039 if (!*string) return 0;
1041 word_start = string;
1042 if (*string == '"')
1044 string++;
1045 length++;
1047 while (*string != '"')
1049 string++;
1050 length++;
1053 else
1057 while (!isspace(*string))
1059 string++;
1060 length++;
1064 *word = malloc(length + 1);
1066 dst = *word;
1067 src = word_start;
1070 for (idx= 0; idx < length; idx++)
1073 if (src[idx] == '\\' && src[idx+1] == 'n')
1075 *dst++ = '\n';
1076 idx++;
1079 else *dst++ = src[idx];
1081 *dst++ = 0;
1087 if(*string)
1088 return string + 1;
1089 else
1090 return 0;
1093 dict_type *root;
1094 dict_type *
1095 lookup_word (char *word)
1097 dict_type *ptr = root;
1098 while (ptr) {
1099 if (strcmp(ptr->word, word) == 0) return ptr;
1100 ptr = ptr->next;
1103 fprintf(stderr,"Can't find %s\n",word);
1104 return 0;
1109 static int
1110 perform (void)
1112 tos = stack;
1113 int errors = 0;
1115 while (at(ptr, idx)) {
1116 /* It's worth looking through the command list */
1117 if (iscommand(ptr, idx))
1119 char *next;
1120 dict_type *word ;
1122 (void) nextword(addr(ptr, idx), &next);
1125 word = lookup_word(next);
1130 if (word)
1132 if(Verbose) fprintf(stderr, "CMD '%s'\n", word->word);
1133 exec(word);
1135 else
1137 fprintf(stderr,"warning, %s is not recognised\n", next);
1138 errors++;
1139 skip_past_newline();
1143 else skip_past_newline();
1146 return errors;
1149 dict_type *
1150 newentry (char *word)
1152 dict_type *new = (dict_type *)malloc(sizeof(dict_type));
1153 new->word = word;
1154 new->next = root;
1155 root = new;
1156 new->code = (stinst_type *)malloc(sizeof(stinst_type ));
1157 new->code_length = 1;
1158 new->code_end = 0;
1159 return new;
1164 unsigned int
1165 add_to_definition (dict_type *entry, stinst_type word)
1167 if (entry->code_end == entry->code_length)
1169 entry->code_length += 2;
1170 entry->code =
1171 (stinst_type *) realloc((char *)(entry->code),
1172 entry->code_length *sizeof(word_type));
1174 entry->code[entry->code_end] = word;
1176 return entry->code_end++;
1185 void
1186 add_intrinsic (char *name, void (*func)(void))
1188 dict_type *new = newentry(name);
1189 add_to_definition(new, func);
1190 add_to_definition(new, 0);
1193 void
1194 add_var (char *name)
1196 dict_type *new = newentry(name);
1197 add_to_definition(new, push_number);
1198 add_to_definition(new, (stinst_type)(&(new->var)));
1199 add_to_definition(new,0);
1207 compile (char *string)
1209 int ret=0;
1210 /* add words to the dictionary */
1211 char *word;
1212 dict_type *lookup;
1214 string = nextword(string, &word);
1215 while (string && *string && word[0])
1217 if (strcmp(word,"var")==0)
1219 string=nextword(string, &word);
1221 add_var(word);
1222 string=nextword(string, &word);
1224 else
1226 if (word[0] == ':')
1228 dict_type *ptr;
1229 /* Compile a word and add to dictionary */
1230 string = nextword(string, &word);
1231 if(Verbose) fprintf(stderr, "Found command '%s'\n", word);
1232 if(strlen(word) < MIN_CMDLEN) {
1233 fprintf(stderr, "ERROR: Command '%s' is too short ", word);
1234 fprintf(stderr, "(MIN_CMDLEN is %d)\n", MIN_CMDLEN);
1235 ret++;
1238 ptr = newentry(word);
1239 string = nextword(string, &word);
1240 while (word[0] != ';' )
1242 switch (word[0])
1246 case '"':
1247 /* got a string, embed magic push string
1248 function */
1249 add_to_definition(ptr, push_text);
1250 add_to_definition(ptr, (stinst_type)(word+1));
1251 break;
1252 case '0':
1253 case '1':
1254 case '2':
1255 case '3':
1256 case '4':
1257 case '5':
1258 case '6':
1259 case '7':
1260 case '8':
1261 case '9':
1262 /* Got a number, embedd the magic push number
1263 function */
1264 add_to_definition(ptr, push_number);
1265 add_to_definition(ptr, (stinst_type)atol(word));
1266 break;
1267 default:
1268 add_to_definition(ptr, call);
1269 lookup = lookup_word(word);
1270 if (!lookup) ret++;
1271 add_to_definition(ptr, (stinst_type)lookup);
1274 string = nextword(string, &word);
1276 add_to_definition(ptr,0);
1277 string = nextword(string, &word);
1279 else
1281 fprintf(stderr,"syntax error at %s\n",string-1);
1282 ret++;
1286 free(word);
1287 return(ret);
1291 static void
1292 bang (void)
1294 *(uintptr_t *)((isp[0])) = isp[-1];
1295 isp-=2;
1296 pc++;
1300 WORD(atsign)
1302 isp[0] = *(uintptr_t *)(isp[0]);
1303 pc++;
1306 WORD(hello)
1309 printf("hello\n");
1310 pc++;
1315 static void
1316 read_in (string_type *str, FILE *file)
1318 char buff[10000];
1319 unsigned int r;
1322 r = fread(buff, 1, sizeof(buff), file);
1323 catbuf(str, buff, r);
1325 while (r);
1326 buff[0] = 0;
1328 catbuf(str, buff,1);
1333 #if 0
1334 static void
1335 usage (void)
1337 fprintf(stderr,"usage: -[i|v] -f macrofile <file >file\n");
1338 exit(33);
1340 #endif
1343 main (int ac, char *av[])
1345 unsigned int i;
1346 int status = 0;
1348 string_type buffer;
1349 string_type pptr;
1352 init_string(&buffer);
1353 init_string(&pptr);
1354 init_string(stack+0);
1355 tos=stack+1;
1356 ptr = &pptr;
1358 add_intrinsic("push_text", push_text);
1359 add_intrinsic("!", bang);
1360 add_intrinsic("@", atsign);
1361 add_intrinsic("hello",hello);
1362 add_intrinsic("skip_past_newline", skip_past_newline );
1363 add_intrinsic("catstr", icatstr );
1364 add_intrinsic("copy_past_newline", icopy_past_newline );
1365 add_intrinsic("dup", dup_ );
1366 add_intrinsic("remchar", remchar );
1367 add_intrinsic("get_stuff_in_command", get_stuff_in_command );
1368 add_intrinsic("get_stuff_in_angle", get_stuff_in_angle );
1369 add_intrinsic("do_fancy_stuff", do_fancy_stuff );
1370 add_intrinsic("bulletize", bulletize );
1371 add_intrinsic("courierize", courierize );
1372 add_intrinsic("swap", swap );
1373 add_intrinsic("outputdots", outputdots );
1374 add_intrinsic("exfunstuff", exfunstuff );
1375 add_intrinsic("maybecatstr", maybecatstr );
1376 add_intrinsic("translatecomments", translatecomments );
1377 add_intrinsic("kill_bogus_lines", kill_bogus_lines);
1378 add_intrinsic("indent", indent);
1379 add_intrinsic("internalmode", internalmode);
1380 add_intrinsic("warn", warn);
1382 /* Put a nl at the start */
1383 catchar(&buffer,'\n');
1385 read_in(&buffer, stdin);
1386 remove_noncomments(&buffer, ptr);
1387 for (i= 1; i < ac; i++)
1389 if (av[i][0] == '-')
1391 if (av[i][1] == 'f')
1393 string_type b;
1394 FILE *f;
1395 init_string(&b);
1397 f = fopen(av[i+1],"r");
1398 if (!f)
1400 fprintf(stderr,"Can't open the input file %s\n",av[i+1]);
1401 return 33;
1403 if(Verbose) fprintf(stderr, "Reading -f '%s'\n", av[i+1]);
1406 read_in(&b, f);
1407 if( compile(b.ptr) ) { fclose(f); exit(1); }
1408 status = perform();
1409 fclose(f);
1411 else if (av[i][1] == 'i')
1413 internal_wanted = 1;
1415 else if (av[i][1] == 'v')
1417 Verbose++;
1422 write_buffer(stack+0);
1423 return status;