src/alphautils.cxx

00001 //           alphautils.cxx
00002 //  Tue Feb 26 17:06:02 2008
00003 //  Copyright  2008  Peter L. Berghold
00004 //  <peter@berghold.net>
00005 //
00006 // $Id: alphautils.cxx,v 1.2 2008/03/04 00:51:09 plankowner Exp $
00007 //
00008 // $Log: alphautils.cxx,v $
00009 // Revision 1.2  2008/03/04 00:51:09  plankowner
00010 // Added more detail for book3 style worlds.
00011 //
00012 // Revision 1.1  2008/02/26 22:26:55  plankowner
00013 // added alphautils module
00014 //
00015 //
00016 //
00017 // This program is free software; you can redistribute it and/or modify
00018 // it under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 // 
00022 // This program is distributed in the hope that it will be useful,
00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 // GNU Library General Public License for more details.
00026 // 
00027 // You should have received a copy of the GNU General Public License
00028 // along with this program; if not, write to the Free Software
00029 // Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
00030 
00031 #include <string.h>
00032 
00033 static char* alpha_utils_cxx_sccs_id="$Id: alphautils.cxx,v 1.2 2008/03/04 00:51:09 plankowner Exp $";
00034 
00035 static char* alphaTable[] ={
00036         "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F",
00037         "G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z",
00038         (char*)0
00039 };
00040 
00041 static int max_index=0;
00042 
00043 
00044 static void calcMaxIndex(){
00045         int ix=0;
00046         while(alphaTable[ix+1] != (char*) 0 ){
00047                 ix++;
00048         }
00049         max_index=ix;
00050 }
00051 
00052 char * itoan(int ix){
00053         if ( max_index == 0 ) 
00054                 calcMaxIndex();
00055         if ( ix < 0 ) return "0";
00056         if ( ix > max_index ) return "Z";
00057         
00058         return alphaTable[ix];
00059 }
00060 
00061 int antoi(char *s){
00062         int ix;
00063         
00064         if ( max_index == 0 ) 
00065                 calcMaxIndex();
00066         
00067         for(ix=0;ix<=max_index;ix++){
00068                 if ( strcmp(s,alphaTable[ix])==0)
00069                         return ix;
00070         }
00071         return 0;
00072         
00073 }
00074 

Generated on Fri Mar 7 16:40:53 2008 for frpuniverse by  doxygen 1.4.7