home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xgen / part03 / hash_shell_address.c < prev    next >
C/C++ Source or Header  |  1989-06-29  |  2KB  |  97 lines

  1. #define MAX_NUM_SHELLS 50
  2. #include <stdio.h>
  3. #include <X11/IntrinsicP.h>
  4. #include <X11/Intrinsic.h>
  5. #include <X11/CompositeP.h>
  6. #include <X11/CommandP.h>
  7. #include <X11/LabelP.h>
  8. #include <X11/Box.h>
  9. #include <X11/StringDefs.h>
  10. #include <X11/Shell.h>
  11. #include <X11/Viewport.h>
  12. #include <X11/Form.h>
  13. #include <X11/Core.h>
  14. #include <X11/VPaned.h>
  15. #include "application.h"
  16.  
  17. static struct _shell_address shell_address[MAX_NUM_SHELLS];
  18.  
  19. enter_shell_address( widget_ptr, name)
  20. Widget widget_ptr;
  21. char *name;
  22.  
  23. {
  24.  
  25.     static int i = 0;
  26.     int key;
  27.  
  28.     if( i == 0 )
  29.     {
  30.         for ( i=0 ; i<MAX_NUM_SHELLS ; i++ )
  31.         {
  32.             shell_address[i].name = NULL;
  33.         }
  34.     }
  35.  
  36.  
  37.     key = ((*name) * *(name+1))%MAX_NUM_SHELLS;
  38.  
  39.  
  40.     while( shell_address[key].name != NULL &&
  41.         *(shell_address[key].name) != '!')
  42.         key = ++key%MAX_NUM_SHELLS;
  43.  
  44.  
  45.     shell_address[key].widget_ptr = widget_ptr;
  46.  
  47.  
  48.     shell_address[key].name = (char *)malloc(
  49.         (strlen(name)+1) * sizeof( char ));
  50.  
  51.     strcpy( shell_address[key].name, name);
  52.  
  53. }
  54.  
  55. Widget get_shell_address(name)
  56. char *name;
  57.  
  58. {
  59.     int key;
  60.  
  61.     key = ((*name) * *(name+1))%MAX_NUM_SHELLS;
  62.  
  63.  
  64.  
  65.     while( shell_address[key].widget_ptr != NULL 
  66.         && strcmp(shell_address[key].name, name) != 0)
  67.         key++;
  68.  
  69.  
  70.     return(shell_address[key].widget_ptr);
  71. }
  72.  
  73. remove_shell_address(name)
  74. char *name;
  75. {
  76.     int key;
  77.  
  78.     key = ((*name * *(name+1)))%MAX_NUM_SHELLS;
  79.  
  80.     while( shell_address[key].widget_ptr != NULL &&
  81.         strcmp(shell_address[key].name, name) != 0)
  82.         key++;
  83.  
  84.     if(shell_address[key].widget_ptr  == NULL)
  85.     {
  86.         fprintf(stderr," Shell %s  not found: Not removed\n",
  87.             name);
  88.         return(0);
  89.     }
  90.  
  91.     *(shell_address[key].name) = '!';
  92.  
  93.     return(1);
  94.  
  95.  
  96. }
  97.