Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

naming.c

Go to the documentation of this file.
00001 /****************************************************************************/
00002 /****************************************************************************/
00007 /****************************************************************************/
00008 
00009 #include "memory.h"
00010 #include "types.h"
00011 
00012 char **names=(char**)0;
00013 PROTO *nums=(PROTO*)0;
00014 unsigned long proto_count=0;
00015 unsigned long space=0;
00016 
00017 PROTO mapProtoNameToNum(char *name){
00018   unsigned long l;
00019   if(!name) return 0;
00020   for(l=0;l<proto_count;l++){
00021     if(!strcmp(name, names[l])) return nums[l];
00022   }
00023   return 0;
00024 }
00025 
00026 char *mapProtoNumToName(PROTO num){
00027   unsigned long l;
00028   if(!num) return 0;
00029   for(l=0;l<proto_count;l++){
00030     if(num == nums[l]) return strdup_safe(names[l]);
00031   }
00032   return (char*)0;
00033 }
00034 
00035 int storeProtoMapping(char *name, PROTO num){
00036   unsigned long l;
00037 
00038   if(!name) return 0;
00039 
00040   for(l=0;l<proto_count;l++){
00041     if(nums[l]==num){
00042       if(name && names[l]){
00043         if(!strcmp(name, names[l])) return 0;
00044       }
00045     }
00046   }
00047 
00048   if(space<=proto_count){
00049     space += 100;
00050     nums = realloc_safe(nums, sizeof(PROTO)*space);
00051     names = realloc_safe(names, sizeof(char*)*space);
00052   }
00053   
00054   if(!nums || !names) return 0;
00055 
00056   nums[proto_count] = num;
00057   names[proto_count]= strdup_safe(name);
00058   proto_count++;
00059 
00060   return 1;
00061 }
00062 
00063 void cleanMapping(void){
00064   unsigned long l;
00065   for(l=0;l<proto_count;l++){
00066     free_safe(names[proto_count]);
00067   }
00068   free_safe(names);
00069   names = (char **)0;
00070   free_safe(nums);
00071   nums = (PROTO*)0;
00072   space = 0;
00073   proto_count = 0;
00074 }

Generated at Mon Jul 8 15:16:50 2002 for RUBICON by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000