fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / newlib / doc / makedoc.c
blob12dfc90dd797fab8310c0a3f2ea407cb0b1189df
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 "ansidecl.h"
39 #include <stdio.h>
40 #include <ctype.h>
42 extern PTR malloc();
43 extern PTR realloc();
45 #define DEF_SIZE 5000
46 #define STACK 50
48 int internal_wanted;
49 int internal_mode;
53 /* Here is a string type ... */
55 typedef struct buffer
57 char *ptr;
58 unsigned int write_idx;
59 unsigned int size;
60 } string_type;
68 static void DEFUN(init_string_with_size,(buffer, size),
69 string_type *buffer AND
70 unsigned int size )
72 buffer->write_idx = 0;
73 buffer->size = size;
74 buffer->ptr = malloc(size);
77 static void DEFUN(init_string,(buffer),
78 string_type *buffer)
80 init_string_with_size(buffer, DEF_SIZE);
84 static int DEFUN(find, (str, what),
85 string_type *str AND
86 char *what)
88 unsigned int i;
89 char *p;
90 p = what;
91 for (i = 0; i < str->write_idx && *p; i++)
93 if (*p == str->ptr[i])
94 p++;
95 else
96 p = what;
98 return (*p == 0);
102 static void DEFUN(write_buffer,(buffer),
103 string_type *buffer)
105 fwrite(buffer->ptr, buffer->write_idx, 1, stdout);
109 static void DEFUN(delete_string,(buffer),
110 string_type *buffer)
112 free(buffer->ptr);
116 static char *DEFUN(addr, (buffer, idx),
117 string_type *buffer AND
118 unsigned int idx)
120 return buffer->ptr + idx;
123 static char DEFUN(at,(buffer, pos),
124 string_type *buffer AND
125 unsigned int pos)
127 if ( pos >= buffer->write_idx)
129 return 0;
131 return buffer->ptr[pos];
134 static void DEFUN(catchar,(buffer, ch),
135 string_type *buffer AND
136 char ch)
138 if (buffer->write_idx == buffer->size)
140 buffer->size *=2;
141 buffer->ptr = realloc(buffer->ptr, buffer->size);
144 buffer->ptr[buffer->write_idx ++ ] = ch;
148 static void DEFUN(overwrite_string,(dst, src),
149 string_type *dst AND
150 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 DEFUN(catstr,(dst, src),
159 string_type *dst AND
160 string_type *src)
162 unsigned int i;
163 for (i = 0; i < src->write_idx; i++)
165 catchar(dst, src->ptr[i]);
170 static void DEFUN(cattext,(buffer, string),
171 string_type *buffer AND
172 char *string)
175 while (*string)
177 catchar(buffer, *string);
178 string++;
182 static void DEFUN(catbuf,(buffer, buf, len),
183 string_type *buffer AND
184 char *buf AND
185 unsigned int len)
188 while (len--)
190 catchar(buffer, *buf);
191 buf++;
197 static unsigned int
198 DEFUN(skip_white_and_stars,(src, idx),
199 string_type *src AND
200 unsigned int idx)
202 while (isspace(at(src,idx))
203 || (at(src,idx) == '*' && at(src,idx +1) !='/'))
204 idx++;
205 return idx;
209 /***********************************************************************/
212 string_type stack[STACK];
213 string_type *tos;
215 unsigned int idx = 0; /* Pos in input buffer */
216 string_type *ptr; /* and the buffer */
217 typedef void (*stinst_type)();
218 stinst_type *pc;
219 stinst_type sstack[STACK];
220 stinst_type *ssp = &sstack[0];
221 int istack[STACK];
222 int *isp = &istack[0];
224 typedef int *word_type;
228 struct dict_struct
230 char *word;
231 struct dict_struct *next;
232 stinst_type *code;
233 int code_length;
234 int code_end;
235 int var;
238 typedef struct dict_struct dict_type;
239 #define WORD(x) static void x()
241 static void DEFUN(exec,(word),
242 dict_type *word)
244 pc = word->code;
245 while (*pc)
247 (*pc)();
251 WORD(call)
253 stinst_type *oldpc = pc;
254 dict_type *e;
255 e = (dict_type *)(pc [1]);
256 exec(e);
257 pc = oldpc + 2;
261 WORD(remchar)
263 tos->write_idx--;
264 pc++;
268 WORD(push_number)
270 isp++;
271 pc++;
272 *isp = (int)(*pc);
273 pc++;
280 WORD(push_text)
283 tos++;
284 init_string(tos);
285 pc++;
286 cattext(tos,*((char **)pc));
287 pc++;
293 /* This function removes everything not inside comments starting on
294 the first char of the line from the string, also when copying
295 comments, removes blank space and leading *'s
296 Blank lines are turned into one blank line
299 static void
300 DEFUN(remove_noncomments,(src,dst),
301 string_type *src AND
302 string_type *dst)
304 unsigned int idx = 0;
306 while (at(src,idx))
308 /* Now see if we have a comment at the start of the line */
309 if (at(src,idx) == '\n'
310 && at(src,idx+1) == '/'
311 && at(src,idx+2) == '*')
313 idx+=3;
315 idx = skip_white_and_stars(src,idx);
317 /* Remove leading dot */
318 if (at(src, idx) == '.')
319 idx++;
321 /* Copy to the end of the line, or till the end of the
322 comment */
323 while (at(src, idx))
325 if (at(src, idx) == '\n')
327 /* end of line, echo and scrape of leading blanks */
328 if (at(src,idx +1) == '\n')
329 catchar(dst,'\n');
330 catchar(dst,'\n');
331 idx++;
332 idx = skip_white_and_stars(src, idx);
334 else if (at(src, idx) == '*' && at(src,idx+1) == '/')
336 idx +=2 ;
337 cattext(dst,"\nENDDD\n");
338 break;
340 else
342 catchar(dst, at(src, idx));
343 idx++;
347 else idx++;
350 /* turn foobar name(stuff); into foobar EXFUN(name,(stuff));
354 static void
355 DEFUN_VOID(exfunstuff)
357 unsigned int openp;
358 unsigned int fname;
359 unsigned int idx;
360 string_type out;
361 init_string(&out);
364 /* make sure that it's not already exfuned */
365 if(find(tos,"EXFUN") || find(tos,"PROTO") || !find(tos,"(")) {
366 catstr(&out,tos);
368 else
371 /*Find the open paren*/
372 for (openp = 0; at(tos, openp) != '(' && at(tos,openp); openp++)
375 fname = openp;
376 /* Step back to the fname */
377 fname--;
378 while (fname && isspace(at(tos, fname)))
379 fname --;
380 while (fname && !isspace(at(tos,fname)) && at(tos,fname) != '*')
381 fname--;
383 fname++;
385 for (idx = 0; idx < fname; idx++)
387 catchar(&out, at(tos,idx));
390 cattext(&out,"EXFUN(");
391 for (idx = fname; idx < openp; idx++)
393 catchar(&out, at(tos,idx));
395 cattext(&out,", ");
396 while (at(tos,idx) && at(tos,idx) !=';')
398 catchar(&out, at(tos, idx));
399 idx++;
401 cattext(&out,");\n");
403 overwrite_string(tos, &out);
404 pc++;
410 /* turn {*
411 and *} into comments */
413 WORD(translatecomments)
415 unsigned int idx = 0;
416 string_type out;
417 init_string(&out);
419 while (at(tos, idx))
421 if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
423 cattext(&out," /*");
424 idx+=2;
426 else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
428 cattext(&out,"*/");
429 idx+=2;
431 else
433 catchar(&out, at(tos, idx));
434 idx++;
439 overwrite_string(tos, &out);
441 pc++;
445 /* find something like
446 QUICKREF
447 memchar ansi pure
449 into
450 merge with words on tos and output them to stderror
453 WORD(quickref)
455 string_type *nos = tos-1;
456 unsigned int scan=0;
457 unsigned int nosscan = 0;
458 unsigned int idx = 0;
460 while (at(tos, idx))
462 if (at(tos,idx) == '~')
464 /* Skip the whitespace */
465 while (at(nos, nosscan) == ' ')
466 nosscan++;
468 /* Sub the next word from the nos*/
469 while (at(nos, nosscan) != ' ' &&
470 at(nos, nosscan) != 0)
472 fprintf(stderr, "%c", at(nos, nosscan));
473 nosscan++;
477 else
479 fprintf(stderr,"%c", at(tos, idx));
482 idx++;
485 delete_string(tos);
486 delete_string(nos);
487 tos-=2;
488 pc++;
492 /* turn everything not starting with a . into a comment */
494 WORD(manglecomments)
496 unsigned int idx = 0;
497 string_type out;
498 init_string(&out);
500 while (at(tos, idx))
502 if (at(tos,idx) == '\n' && at(tos,idx+1) =='*')
504 cattext(&out," /*");
505 idx+=2;
507 else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
509 cattext(&out,"*/");
510 idx+=2;
512 else
514 catchar(&out, at(tos, idx));
515 idx++;
520 overwrite_string(tos, &out);
522 pc++;
526 /* Mod tos so that only lines with leading dots remain */
527 static void
528 DEFUN_VOID(outputdots)
530 unsigned int idx = 0;
531 string_type out;
532 init_string(&out);
534 while (at(tos, idx))
536 if (at(tos, idx) == '\n' && at(tos, idx+1) == '.')
538 idx += 2;
540 while (at(tos, idx) && at(tos, idx)!='\n')
542 if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
544 cattext(&out," /*");
545 idx+=2;
547 else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
549 cattext(&out,"*/");
550 idx+=2;
552 else
554 catchar(&out, at(tos, idx));
555 idx++;
558 catchar(&out,'\n');
560 else
562 idx++;
566 overwrite_string(tos, &out);
567 pc++;
571 /* Find lines starting with . and | and put example around them on tos
572 turn
573 {* into open comment and *} into close comment
574 escape curlies
577 WORD(courierize)
579 string_type out;
580 unsigned int idx = 0;
582 init_string(&out);
584 while (at(tos, idx))
586 if (at(tos, idx) == '\n'
587 && (at(tos, idx +1 ) == '.'
588 || at(tos,idx+1) == '|'))
590 cattext(&out,"\n@smallexample\n");
593 idx += 2;
595 while (at(tos, idx) && at(tos, idx)!='\n')
597 if (at(tos,idx)=='{' && at(tos,idx+1) =='*')
599 cattext(&out," /*");
600 idx+=2;
602 else if (at(tos,idx)=='*' && at(tos,idx+1) =='}')
604 cattext(&out,"*/");
605 idx+=2;
607 else if (at(tos,idx) == '{')
609 cattext(&out,"@{");
610 idx++;
612 else if (at(tos,idx) == '}')
614 cattext(&out,"@}");
615 idx++;
617 else
619 catchar(&out, at(tos, idx));
620 idx++;
624 catchar(&out,'\n');
626 while (at(tos, idx) == '\n'
627 && (at(tos, idx+1) == '.')
628 || (at(tos,idx+1) == '|'));
629 cattext(&out,"@end smallexample");
631 else
633 catchar(&out, at(tos, idx));
634 idx++;
638 overwrite_string(tos, &out);
639 pc++;
645 O+ emit @itemize @bullet
646 OO emit @item
647 O- emit @end itemize
649 o+ emit @table @code
650 oo @item
651 o- emit @end table
655 WORD(bulletize)
657 unsigned int idx = 0;
658 int on = 0;
659 string_type out;
660 init_string(&out);
662 while (at(tos, idx)) {
663 if (at(tos, idx) == '@' &&
664 at(tos, idx+1) == '*')
666 cattext(&out,"*");
667 idx+=2;
670 else
671 if (at(tos, idx) == '\n' && at(tos, idx+1) == 'o')
673 if (at(tos,idx+2) == '+') {
674 cattext(&out,"\n@table @code\n");
675 idx+=3;
677 else if (at(tos,idx+2) == '-') {
678 cattext(&out,"\n@end table\n");
679 idx+=3;
681 else if (isspace(at(tos,idx+2))) {
682 cattext(&out,"\n@item ");
683 idx+=3;
685 else {
686 catchar(&out, at(tos, idx));
687 idx++;
691 else
692 if (at(tos, idx) == '\n' && at(tos, idx+1) == 'O')
694 if (at(tos,idx+2) == '+') {
695 cattext(&out,"\n@itemize @bullet\n");
696 idx+=3;
699 else if (at(tos,idx+2) == '-') {
700 cattext(&out,"\n@end itemize\n");
701 idx+=3;
703 else {
704 catchar(&out, at(tos, idx));
705 idx++;
708 else
710 catchar(&out, at(tos, idx));
711 idx++;
715 delete_string(tos);
716 *tos = out;
717 pc++;
721 /* Turn <<foo>> into @code{foo} in place at TOS
722 Turn <[foo]> into @var{foo} in place at TOS
723 nest them too !
728 WORD(do_fancy_stuff)
730 unsigned int idx = 0;
731 string_type out;
732 init_string(&out);
733 while (at(tos, idx))
735 if (at(tos, idx) == '<'
736 && at(tos, idx+1) == '<'
737 && (!isspace(at(tos,idx + 2)) || at(tos,idx+3) == '>'))
739 /* This qualifies as a << startup */
740 idx +=2;
741 cattext(&out,"@code{");
744 else if (at(tos, idx) == '<'
745 && at(tos, idx+1) == '['
746 && !isspace(at(tos,idx + 2)))
748 /* This qualifies as a <[ startup */
749 idx +=2;
750 cattext(&out,"@var{");
752 else if (at(tos, idx) == '>'
753 && at(tos,idx+1) =='>')
756 cattext(&out,"}");
757 idx+=2;
759 else if (at(tos, idx) == ']'
760 && at(tos,idx+1) =='>')
762 cattext(&out,"}");
763 idx+=2;
765 else
767 catchar(&out, at(tos, idx));
768 idx++;
771 delete_string(tos);
772 *tos = out;
773 pc++;
776 /* A command is all upper case,and alone on a line */
777 static int
778 DEFUN( iscommand,(ptr, idx),
779 string_type *ptr AND
780 unsigned int idx)
782 unsigned int len = 0;
783 while (at(ptr,idx)) {
784 if (isupper(at(ptr,idx)) || at(ptr,idx) == ' ' ||
785 at(ptr,idx) == '_')
787 len++;
788 idx++;
790 else if(at(ptr,idx) == '\n')
792 if (len >4) return 1;
793 return 0;
795 else return 0;
797 return 0;
802 DEFUN(copy_past_newline,(ptr, idx, dst),
803 string_type *ptr AND
804 unsigned int idx AND
805 string_type *dst)
807 while (at(ptr, idx) && at(ptr, idx) != '\n')
809 catchar(dst, at(ptr, idx));
810 idx++;
813 catchar(dst, at(ptr, idx));
814 idx++;
815 return idx;
819 WORD(icopy_past_newline)
821 tos++;
822 init_string(tos);
823 idx = copy_past_newline(ptr, idx, tos);
824 pc++;
828 /* indent
829 Take the string at the top of the stack, do some prettying */
834 WORD(kill_bogus_lines)
836 int sl ;
838 int nl = 0;
839 int idx = 0;
840 int c;
841 int dot = 0 ;
843 string_type out;
844 init_string(&out);
845 /* Drop leading nl */
846 while (at(tos,idx) == '\n')
848 idx++;
850 c = idx;
852 /* Find the last char */
853 while (at(tos,idx))
855 idx++;
858 /* find the last non white before the nl */
859 idx--;
861 while (idx && isspace(at(tos,idx)))
862 idx--;
863 idx++;
865 /* Copy buffer upto last char, but blank lines before and after
866 dots don't count */
867 sl = 1;
869 while (c < idx)
871 if (at(tos,c) == '\n'
872 && at(tos,c+1) == '\n'
873 && at(tos,c+2) == '.')
875 /* Ignore two linelines before a dot*/
876 c++;
878 else if (at(tos,c) == '.' && sl)
880 /* remember that this line started with a dot */
881 dot=2;
883 else if (at(tos,c) == '\n'
884 && at(tos,c+1) == '\n'
885 && dot)
887 c++;
888 /* Ignore two newlines when last line was dot */
891 catchar(&out, at(tos,c));
892 if (at(tos,c) == '\n')
894 sl = 1;
896 if (dot == 2)dot=1;else dot = 0;
899 c++;
903 /* Append nl*/
904 catchar(&out, '\n');
905 pc++;
906 delete_string(tos);
907 *tos = out;
912 WORD(indent)
914 string_type out;
915 int tab = 0;
916 int idx = 0;
917 int ol =0;
918 init_string(&out);
919 while (at(tos,idx)) {
920 switch (at(tos,idx))
922 case '\n':
923 cattext(&out,"\n");
924 idx++;
925 if (tab)
927 cattext(&out," ");
929 ol = 0;
930 break;
931 case '(':
932 tab++;
933 if (ol == 0)
934 cattext(&out," ");
935 idx++;
936 cattext(&out,"(");
937 ol = 1;
938 break;
939 case ')':
940 tab--;
941 cattext(&out,")");
942 idx++;
943 ol=1;
945 break;
946 default:
947 catchar(&out,at(tos,idx));
948 ol=1;
950 idx++;
951 break;
955 pc++;
956 delete_string(tos);
957 *tos = out;
961 /* Change the TOS so that all that is left is the stuff inside the
962 first <<foo>> .
965 WORD(get_stuff_in_angle)
967 unsigned int idx = 0;
968 string_type out;
969 init_string(&out);
971 while (at(tos, idx))
973 if (at(tos,idx) == '<' && at(tos,idx+1) =='<')
975 idx+=2;
977 while (!(at(tos,idx) == '>' && at(tos,idx+1) == '>'))
979 catchar(&out, at(tos, idx));
980 idx++;
982 break;
984 idx++;
986 catchar(&out,'\n');
988 overwrite_string(tos, &out);
989 pc++;
993 WORD(get_stuff_in_command)
995 tos++;
996 init_string(tos);
998 while (at(ptr, idx)) {
999 if (iscommand(ptr, idx)) break;
1000 idx = copy_past_newline(ptr, idx, tos);
1002 pc++;
1005 WORD(swap)
1007 string_type t;
1009 t = tos[0];
1010 tos[0] = tos[-1];
1011 tos[-1] =t;
1012 pc++;
1016 WORD(dup)
1018 tos++;
1019 init_string(tos);
1020 catstr(tos, tos-1);
1021 pc++;
1027 WORD(icatstr)
1029 catstr(tos-1, tos);
1030 delete_string(tos);
1031 tos--;
1032 pc++;
1036 WORD(skip_past_newline)
1038 while (at(ptr,idx)
1039 && at(ptr,idx) != '\n')
1040 idx++;
1041 idx++;
1042 pc++;
1046 WORD(internalmode)
1048 internal_mode = *(isp);
1049 isp--;
1050 pc++;
1053 WORD(maybecatstr)
1055 if (internal_wanted == internal_mode)
1057 catstr(tos-1, tos);
1059 delete_string(tos);
1060 tos--;
1061 pc++;
1065 char *
1066 DEFUN(nextword,(string, word),
1067 char *string AND
1068 char **word)
1070 char *word_start;
1071 int idx;
1072 char *dst;
1073 char *src;
1075 int length = 0;
1077 while (isspace(*string) || *string == '-') {
1078 if (*string == '-')
1080 while (*string && *string != '\n')
1081 string++;
1084 else {
1085 string++;
1088 if (!*string) return 0;
1090 word_start = string;
1091 if (*string == '"')
1093 string++;
1094 length++;
1096 while (*string != '"')
1098 string++;
1099 length++;
1102 else
1106 while (!isspace(*string))
1108 string++;
1109 length++;
1113 *word = malloc(length + 1);
1115 dst = *word;
1116 src = word_start;
1119 for (idx= 0; idx < length; idx++)
1122 if (src[idx] == '\\' && src[idx+1] == 'n')
1124 *dst++ = '\n';
1125 idx++;
1128 else *dst++ = src[idx];
1130 *dst++ = 0;
1136 if(*string)
1137 return string + 1;
1138 else
1139 return 0;
1142 dict_type *root;
1143 dict_type *
1144 DEFUN(lookup_word,(word),
1145 char *word)
1147 dict_type *ptr = root;
1148 while (ptr) {
1149 if (strcmp(ptr->word, word) == 0) return ptr;
1150 ptr = ptr->next;
1153 fprintf(stderr,"Can't find %s\n",word);
1154 return 0;
1159 static void DEFUN_VOID(perform)
1161 tos = stack;
1163 while (at(ptr, idx)) {
1164 /* It's worth looking through the command list */
1165 if (iscommand(ptr, idx))
1167 unsigned int i;
1168 int found = 0;
1170 char *next;
1171 dict_type *word ;
1173 (void) nextword(addr(ptr, idx), &next);
1176 word = lookup_word(next);
1181 if (word)
1183 exec(word);
1185 else
1187 fprintf(stderr,"warning, %s is not recognised\n", next);
1188 skip_past_newline();
1192 else skip_past_newline();
1197 dict_type *
1198 DEFUN(newentry,(word),
1199 char *word)
1201 dict_type *new = (dict_type *)malloc(sizeof(dict_type));
1202 new->word = word;
1203 new->next = root;
1204 root = new;
1205 new->code = (stinst_type *)malloc(sizeof(stinst_type ));
1206 new->code_length = 1;
1207 new->code_end = 0;
1208 return new;
1213 unsigned int
1214 DEFUN(add_to_definition,(entry, word),
1215 dict_type *entry AND
1216 stinst_type word)
1218 if (entry->code_end == entry->code_length)
1220 entry->code_length += 2;
1221 entry->code =
1222 (stinst_type *) realloc((char *)(entry->code),
1223 entry->code_length *sizeof(word_type));
1225 entry->code[entry->code_end] = word;
1227 return entry->code_end++;
1236 void
1237 DEFUN(add_intrinsic,(name, func),
1238 char *name AND
1239 void (*func)())
1241 dict_type *new = newentry(name);
1242 add_to_definition(new, func);
1243 add_to_definition(new, 0);
1246 WORD(push_addr)
1252 void
1253 DEFUN(add_var,(name),
1254 char *name)
1256 dict_type *new = newentry(name);
1257 add_to_definition(new, push_number);
1258 add_to_definition(new, (stinst_type)(&(new->var)));
1259 add_to_definition(new,0);
1266 void
1267 DEFUN(compile, (string),
1268 char *string)
1271 int jstack[STACK];
1272 int *jptr = jstack;
1273 /* add words to the dictionary */
1274 char *word;
1275 string = nextword(string, &word);
1276 while (string && *string && word[0])
1278 if (strcmp(word,"var")==0)
1280 string=nextword(string, &word);
1282 add_var(word);
1283 string=nextword(string, &word);
1285 else
1287 if (word[0] == ':')
1289 dict_type *ptr;
1290 /* Compile a word and add to dictionary */
1291 string = nextword(string, &word);
1293 ptr = newentry(word);
1294 string = nextword(string, &word);
1295 while (word[0] != ';' )
1297 switch (word[0])
1301 case '"':
1302 /* got a string, embed magic push string
1303 function */
1304 add_to_definition(ptr, push_text);
1305 add_to_definition(ptr, (stinst_type)(word+1));
1306 break;
1307 case '0':
1308 case '1':
1309 case '2':
1310 case '3':
1311 case '4':
1312 case '5':
1313 case '6':
1314 case '7':
1315 case '8':
1316 case '9':
1317 /* Got a number, embedd the magic push number
1318 function */
1319 add_to_definition(ptr, push_number);
1320 add_to_definition(ptr, atol(word));
1321 break;
1322 default:
1323 add_to_definition(ptr, call);
1324 add_to_definition(ptr, lookup_word(word));
1327 string = nextword(string, &word);
1329 add_to_definition(ptr,0);
1330 string = nextword(string, &word);
1332 else
1334 fprintf(stderr,"syntax error at %s\n",string-1);
1341 static void DEFUN_VOID(bang)
1343 *(int *)((isp[0])) = isp[-1];
1344 isp-=2;
1345 pc++;
1349 WORD(atsign)
1351 isp[0] = *(int *)(isp[0]);
1352 pc++;
1355 WORD(hello)
1358 printf("hello\n");
1359 pc++;
1364 static void DEFUN(read_in, (str, file),
1365 string_type *str AND
1366 FILE *file)
1368 char buff[10000];
1369 unsigned int r;
1372 r = fread(buff, 1, sizeof(buff), file);
1373 catbuf(str, buff, r);
1375 while (r);
1376 buff[0] = 0;
1378 catbuf(str, buff,1);
1383 static void DEFUN_VOID(usage)
1385 fprintf(stderr,"usage: -[d|i|g] <file >file\n");
1386 exit(33);
1389 int DEFUN(main,(ac,av),
1390 int ac AND
1391 char *av[])
1393 unsigned int i;
1396 string_type buffer;
1397 string_type pptr;
1400 init_string(&buffer);
1401 init_string(&pptr);
1402 init_string(stack+0);
1403 tos=stack+1;
1404 ptr = &pptr;
1406 add_intrinsic("push_text", push_text);
1407 add_intrinsic("!", bang);
1408 add_intrinsic("@", atsign);
1409 add_intrinsic("hello",hello);
1410 add_intrinsic("skip_past_newline", skip_past_newline );
1411 add_intrinsic("catstr", icatstr );
1412 add_intrinsic("copy_past_newline", icopy_past_newline );
1413 add_intrinsic("dup", dup );
1414 add_intrinsic("remchar", remchar );
1415 add_intrinsic("get_stuff_in_command", get_stuff_in_command );
1416 add_intrinsic("get_stuff_in_angle", get_stuff_in_angle );
1417 add_intrinsic("do_fancy_stuff", do_fancy_stuff );
1418 add_intrinsic("bulletize", bulletize );
1419 add_intrinsic("courierize", courierize );
1420 add_intrinsic("swap", swap );
1421 add_intrinsic("outputdots", outputdots );
1422 add_intrinsic("exfunstuff", exfunstuff );
1423 add_intrinsic("maybecatstr", maybecatstr );
1424 add_intrinsic("translatecomments", translatecomments );
1425 add_intrinsic("kill_bogus_lines", kill_bogus_lines);
1426 add_intrinsic("indent", indent);
1427 add_intrinsic("quickref", quickref);
1428 add_intrinsic("internalmode", internalmode);
1430 /* Put a nl at the start */
1431 catchar(&buffer,'\n');
1433 read_in(&buffer, stdin);
1434 remove_noncomments(&buffer, ptr);
1435 for (i= 1; i < ac; i++)
1437 if (av[i][0] == '-')
1439 if (av[i][1] == 'f')
1441 string_type b;
1442 FILE *f;
1443 init_string(&b);
1445 f = fopen(av[i+1],"r");
1446 if (!f)
1448 fprintf(stderr,"Can't open the input file %s\n",av[i+1]);
1449 return 33;
1453 read_in(&b, f);
1454 compile(b.ptr);
1455 perform();
1457 else if (av[i][1] == 'i')
1459 internal_wanted = 1;
1464 write_buffer(stack+0);
1465 return 0;