/* A macro is a stream of Turing machine commands which are executed when 'run' is entered as a TM command */ #ifndef MACRO_H #define MACRO_H #include "limits.h" #include /* for strncpy */ #define MAC_WORD_LENGTH 80 /* a macro word may contain a quoted string */ #define MNAME_LENGTH 30 /* length of macro list name */ struct macword { struct macword *nextptr; /* pointer to next word */ struct macword *prevptr; /* pointer to last word */ char *word; int number; /* ordinal number of the word on the list */ }; /* A 'maclist' is a linked list of 'macwords' */ struct maclist { int num_macword; /* number of macwords on the list */ char *list_name; struct macword *root; /* pointer to first macword on the list */ }; /* FUNCTION PROTOTYPES.... */ struct maclist *new_macro(struct maclist *mlist, int *status); /* 'mlist' - pointer to a macro list 'status' - OK means success MEM_ERROR means ran out of memory, for example Returns pointer to a new macro listing. */ void delete_macro(struct maclist *mlist, int *status); /* 'mlst' - pointer to a macro listing 'status' - OK if no error */ void del_all_mac(struct maclist *mlst, int *status); /* 'mlst' - pointer to a macro listing 'status' - OK, or an error. Remove all the words from a macro listing */ void del_list_mac(struct maclist *mlst, int *status); /* 'mlst' - pointer to a macro listing 'status' - OK, or an error. Delete a macro listing. Remove all words in it and the list itself. */ struct macword *new_macword(struct maclist *mlst, char *macstr, int *status); /* 'mlst' - pointer to a macro list 'macstr' - word to add to the end of the macro list 'status' - OK if no error CANT_RUN_RUN if an attempt is made to add the 'run' command MEM_ERROR if malloc fails Add a new item to the end of the macro listing. Returns a pointer to the new macro word. */ void insert_macword(struct maclist *mlst, int *where, int *status, char *macstr); /* 'mlst' - pointer to a macro list 'where' - add the new word after the word at location number 'where' 'macstr' - the word to add 'status' - OK if there is no error WORD_TOO_LONG if macstr is too long. NO_MLIST if mlst doesn't exist CANT_RUN_RUN if an attempt is made to add 'run' to the list MEM_ERROR if malloc fails CANT_INSERT Insert a word after position 'where' in macro list 'mlst' */ int find_macword(struct maclist *mlst, int where, char* str, int *status); /* 'mlst' - pointer to a macro list 'where' - starting location on macrolist for a search 'str' - word to search for on 'mlst' 'status' - OK if there is no error. WORD_NOT_FOUND if the word was not found Returns the location on 'mlst' of word 'str' after location 'where' */ void list_mac(struct maclist *mlst, int *status); /* 'mlst' - a pointer to a macro list 'status' - OK if no error List the macro list 'mlst' */ void edlist(struct maclist *mlst, int lower, int upper, int *status); /* 'mlst' - pointer to a macro list 'lower', 'upper' - a range of macro words to list 'status' - OK if there is no error List all the macro words between 'lower' and 'upper' along with their ordinal numbers */ void del_macword(struct maclist *mlst, int which, int *status); /* 'mlst' - pointer to a macro list 'which' - ordinal number of the word to remove from the list 'status' - OK on success Remove the word at location 'which' from the list 'mlst' */ void set_mac(struct maclist *mlst, int *status); /* 'mlst' - pointer returned to a new macro list. 'status' - OK if success Create a new macro list with appended words */ void nocomma_strcpy(char *to, char *from, int wordlen); /* Copy a word dropping commas and semi-colons unless they are quoted */ void run_mac(struct maclist *mlst, int *status); /* Run the macro 'mlst'. This is done by pushing the macro list on the command stack. */ void edmacro(struct maclist *mptr); /* Edit the macro list with pointer 'mptr'. */ #endif /* MACRO_H */