home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 125.lha / MenuText / restore.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  3KB  |  112 lines

  1. /*
  2.  *  This program will strip a window of nodes linked to the UserData field.
  3.  *  These nodes *must* be of the size given below (in the absence of some
  4.  *  other type of node).
  5.  *
  6.  *  The nodes are used by MENUTEXT to link new menu text definitions to an
  7.  *  open window; if this program is not run before the window is closed,
  8.  *  the memory will never be freed and fragmentation will result.
  9.  *
  10.  *  An extension which I may include later is actually dis-allowing all
  11.  *  CLOSEWINDOW messages from reaching the window until this program is
  12.  *  run. Easy, but intimidating for someone who isn't familiar with the
  13.  *  workings of the program.
  14.  *
  15.  *  ((c)) 1987, John Russell. Unlimited distribution, but donations to
  16.  *  starving programmers welcome.
  17.  *
  18.  */
  19.  
  20. #include "intuition/intuition.h"
  21. #include "exec/memory.h"
  22. #include "stdio.h"
  23.  
  24. void copy();
  25.  
  26. char *name = "John Russell";
  27. char *address = "5 Alderdice Place";
  28. char *province = "St. John's, Newfoundland, Canada";
  29. char *postal_code = "A1B 2P8";
  30. char *phone = "(709) 726-7847";
  31.  
  32. struct IntuitionBase *IntuitionBase;
  33.  
  34. struct node {
  35.     struct node *next;
  36.     char text[46];
  37.     char *old_text;
  38.     short old_item_width;
  39.     struct MenuItem *altered;
  40. } *ptr,*next;
  41.  
  42. main(argc, argv)
  43. int argc;
  44. char *argv[];
  45. {
  46.     struct Window *window;
  47.     struct Screen *screen;
  48.  
  49.     if ((IntuitionBase=(struct IntuitionBase *)
  50.        OpenLibrary("intuition.library",0L))==NULL) {
  51.            puts("Where is Intuition gone???\n");
  52.            exit(0);
  53.     }
  54.  
  55.     if (argc != 2) {
  56.         puts("You must supply the name of a window. The name is case-sensitive,\n\
  57. but only the first word in the name is considered.");
  58.         exit(0);
  59.     }
  60.  
  61.     Forbid();
  62.  
  63.     screen = IntuitionBase->FirstScreen; /* address of Workbench screen structure */
  64.  
  65.     while (screen) {     /* do all screens */
  66.  
  67.         window = screen->FirstWindow;
  68.  
  69.         while (window) {    /* do all windows */
  70.  
  71.             if (compare(argv[1],window->Title)==0) {  /* search for name */
  72.  
  73.                 ptr = window->UserData;
  74.  
  75.                 while (ptr) {   /* restore menu to original condition */
  76.  
  77.                     next = ptr->next;
  78.  
  79.                     printf("Deleting menutext entry \"%s\"\n",ptr->text);
  80.                     printf("Replacing original entry \"%s\"\n\n",ptr->old_text);
  81.  
  82.                     ptr->altered->ItemFill->IText = ptr->old_text;
  83.                     ptr->altered->Width = ptr->old_item_width;
  84.  
  85.                     FreeMem(ptr,sizeof(struct node));
  86.                     ptr = next;
  87.                 }
  88.                 window->UserData = NULL; /* it was all a dream... */
  89.             }
  90.         window = window->NextWindow;
  91.         }
  92.     screen = screen->NextScreen;
  93.     }
  94.  
  95.     quit:
  96.     Permit();
  97.     CloseLibrary(IntuitionBase);
  98.  
  99. }
  100.  
  101. compare(string1,string2) /* if spaces in windowname, only check first word */
  102. char *string1,*string2;
  103. {
  104.     while ((*string1 != '\0') && (*string1 != ' ')) {
  105.         if (*string1 != *string2) /* space and null both end conditions */
  106.             return(1);
  107.         string1++;
  108.         string2++;
  109.     }
  110.     return(0);  /* return weird values like strcmp() */
  111. }
  112.