john13@garfield.UUCP (05/03/87)
Here are the diffs to make MenuText and Restore more friendly - they will try to detect if someone else is using UserData, and will abort as gracefully as possible if so, with a warning not to tamper with these menus again. Note 1: If a program does strange things to menus, creating them from arbitrary data or something, don't try to change it. (This is only common sense) Note 2: With all the emphasis on shared libraries, device drivers, files, etc there really should be at least *1* shared access pointer in a window structure. This is, of course, only my personal opinion. Note 3: You can install the diffs (under Unix) like so: cat diffs_1 | patch menutext.c cat diffs_2 | patch restore.c There is a program somewhere to do this via Edit on the Amiga itself, but I don't know its name or where you would find it. John ----------------- diffs_1 - MenuText.c: 222a if (ptr->key != MENU_KEY) return(ABORT); /* someone else has altered UserData; abort */ . 212c struct node *findnode(window,item) /* does item already have related node? */ . 176a goto quit; /* only alter 1 window */ . 154c (item->Flags & COMMSEQ ? COMMWIDTH+4 : 0); . 130a node->key = MENU_KEY; /* create tag value */ . 127a if ( (node = findnode(window,item)) == ABORT) { puts("Window structure not suitable for this program."); goto quit; } /* is this the first alteration of this menuitem? */ if (node == NULL) { . 126c /* test that no other program has set UserData */ . 33a short key; /* indicates valid node if key == 0x1234 */ . 20a /* define a value which will indicate a valid node */ #define MENU_KEY 0x1234 /* define error code other than NULL for immediate exit */ #define ABORT 1 . ------------ diffs_2 - Restore.c: 88a goto quit; /* only 1 window affected */ . 76a /* * De-allocate the nodes created by MENUTEXT. The program will exit with * an error message if an invalid node (one without the proper key) is * found while scanning the list, and attempt to repair any damage by * pointing the window's UserData there (as that may be the original * UserData value). This should never occur, since new menuitems will * never be added to a window with an "altered" UserData, but you never * know... * * */ if (ptr->key != MENU_KEY) { window->UserData = ptr; puts("Invalid node found. Window structure may be corrupted."); puts("Please do not alter this program's menus again."); goto quit; } . 63c screen=IntuitionBase->FirstScreen; /* address of Workbench screen structure */ . 35,39c struct node *next; /* list of new definitions */ short key; /* bug-repellent check value */ char text[46]; /* replacement text */ char *old_text; /* where old text is */ short old_item_width; /* what old width was */ struct MenuItem *altered; /* where old item is */ . 23a /* this will ensure we don't de-allocate someone else's linked structure */ /* except in the case of a really, really big coincidence (this is checked */ /* when the items are added as well) */ #define MENU_KEY 0x1234 . 22d