home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / EC / OperationNames / displayOpNames.c next >
Encoding:
C/C++ Source or Header  |  1990-08-16  |  1.8 KB  |  58 lines

  1. #include <stdio.h>
  2. #include "assert.h"
  3. #include "system.h"
  4. #include <sys/types.h>
  5. #include "emTypes.h"
  6. #include "sys/file.h"
  7.  
  8. char assertMessage[] = "Assertion failed: file %s, line %d\n";
  9. #define FILENAME "/EC/OperationNames/Names"
  10.  
  11. struct {
  12.     int hashTableSize;
  13.     int hashTableSizeInBytes;
  14.     int charTableMaxSize;
  15.     int charTableCurrentSize;
  16.     OID nextOIDToAllocate;
  17.     OID maxOIDToAllocate;
  18. } header;
  19.  
  20. typedef int HashValue;
  21.  
  22. typedef struct OpNameEntry {
  23.     int offset;            /* into charTable of the start of the string */
  24.     OID id;            /* what we want */
  25. } HashTableEntry;
  26.  
  27. static HashTableEntry *hashTable;
  28. static char *charTable;
  29.  
  30. void main()
  31. {
  32.     int fd, i;
  33.     char filename[256];
  34.     strcpy(filename, EMDIR);
  35.     strcat(filename, FILENAME);
  36.     fd = open(filename, O_RDONLY, 0);
  37.     assert (fd != -1);
  38.     assert(read(fd, &header, sizeof(header)) == sizeof(header));
  39.     hashTable = (HashTableEntry *) malloc(header.hashTableSizeInBytes);
  40.     charTable = malloc(header.charTableMaxSize);
  41.     assert(read(fd, hashTable, header.hashTableSizeInBytes) == header.hashTableSizeInBytes);
  42.     assert(read(fd, charTable, header.charTableMaxSize) == header.charTableMaxSize);
  43.     close(fd);
  44.     fprintf(stdout, "header.hashTableSize:\t%d\n", header.hashTableSize);
  45.     fprintf(stdout, "header.hashTableSizeInBytes:\t%d\n", header.hashTableSizeInBytes);
  46.     fprintf(stdout, "header.charTableMaxSize:\t%d\n", header.charTableMaxSize);
  47.     fprintf(stdout, "header.charTableCurrentSize:\t%d\n", header.charTableCurrentSize);
  48.     fprintf(stdout, "header.nextOIDToAllocate:\t%x\n", header.nextOIDToAllocate);
  49.     fprintf(stdout, "header.maxOIDToAllocate:\t%x\n", header.maxOIDToAllocate);
  50.     for (i = 0; i < header.hashTableSize; i++) {
  51.     if (hashTable[i].id != 0) {
  52.         fprintf(stdout, "\"%s\" -> 0x%x\n", 
  53.         charTable + hashTable[i].offset,
  54.         hashTable[i].id);
  55.     }
  56.     }
  57. }
  58.