home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / sharedmem / part01 / src / usr_var.c < prev   
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.2 KB  |  73 lines

  1. /* usr_var.c - utility functions for user only! */
  2.  
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/time.h>
  6. #include <strings.h>
  7.  
  8. #include "cm_constants.h"
  9. #include "cm_sd.h"
  10. #include "cm_interface.h"
  11.  
  12. cm_variable cm_variables[CM_MAXUSERVARIABLES];
  13.  
  14. cm_variable *
  15. get_variable(name)
  16. char *name;
  17. {
  18.         int i;
  19.  
  20.     eprintf(10,"entering get_variable(%s)\n",name);
  21.         for (i=0;i<CM_MAXUSERVARIABLES;i++) {
  22.                 /* create it if we come to an empty variable */
  23.                 if (!cm_variables[i].status.inuse) {
  24.             eprintf(10,"get_variable: found empty variable slot\n");
  25.                     strcpy(cm_variables[i].name,name);
  26.             cm_sd_clear(&cm_variables[i].data);
  27.             cm_variables[i].role.reader = 0;
  28.             cm_variables[i].role.nonxwriter = 0;
  29.             cm_variables[i].role.wakeup = 0;
  30.             cm_variables[i].role.xwriter = 0;
  31.             cm_variables[i].old_count = 0;
  32.             cm_variables[i].count = 0;
  33.             cm_variables[i].command_association = 0;
  34.             cm_time_zero(&cm_variables[i].timestamp);
  35.             cm_variables[i].status.inuse = TRUE;
  36.             cm_variables[i].status.written = FALSE;
  37.             cm_variables[i].status.declared = FALSE;
  38.                     return(&cm_variables[i]);
  39.                 }
  40.                 /* found an old definition */
  41.                 if (!(strcmp(cm_variables[i].name,name))) {
  42.             eprintf(10,"get_variable() found old defn\n");
  43.                         return(&cm_variables[i]);
  44.                 }
  45.         }
  46.         /* no old definition and no space for a new one!!!! */
  47.         return(NULL);
  48. }
  49.  
  50. /*
  51. The following function allows the user to step through all the common
  52. memory values, for example, to see if any have changed.  If v is NULL,
  53. the first value is returned.  If no more cm_variables are in use, NULL is
  54. returned.
  55.  
  56. This function is also used by the common memory system itself, as it
  57. hides the implementation of the user cm_variables as a large array.
  58. Presumably, it will be changed to have a hash index in the future
  59. for speed.
  60. */
  61. cm_variable *
  62. next_user_variable(v)
  63. cm_variable *v;    /* if NULL, start from the beginning */
  64. {
  65.     if (v == 0) v = cm_variables;    /* reinitialize */
  66.     else v++;            /* next one */
  67.  
  68.     for (;v<&cm_variables[CM_MAXUSERVARIABLES];v++) {
  69.         if (v->status.inuse) return(v);
  70.     }
  71.     return((cm_variable *)NULL);
  72. }
  73.