alias_table.cc


      //  $Id: alias_table.cc,v 1.1 2003/04/11 03:48:16 vickery Exp $
      
      /*  Alias table management.
       *
       *    $Log: alias_table.cc,v $
       *    Revision 1.1  2003/04/11 03:48:16  vickery
       *    Initial revision
       *
       */
      
      
      #include <map>
      
      #include "alias_table.h"
      
      //  Declare the type and the table
      //  ------------------------------------------------------------------
      struct ltstr
      {
        bool 
        operator()(const char* s1, const char* s2) const
        {
          return strcmp(s1, s2) < 0;
        }
      };
      
      typedef std::map< const char *, 
                        const char *,
                        ltstr       > alias_table_t;
      
      alias_table_t alias_table;
      
      //  listAliases()
      //  ------------------------------------------------------------------
      /*
       *    Writes all aliases to stdout.
       */
        void
        listAliases( void )
        {
          alias_table_t::iterator p;
          //  List all alias names and their values.
          for ( p = alias_table.begin(); p != alias_table.end(); p++ )
          {
            printf( "alias %s = %s\n", p->first, p->second );
          }
          return;
        }
      
      //  defineAlias()
      //  ------------------------------------------------------------------
      /*
       *    Define or redefine an alias.
       */
        void
        defineAlias( const char *name, const char *value )
        {
          alias_table[ name ] = value;
          return;
        }
      
      //  lookupAlias()
      //  ------------------------------------------------------------------
      /*
       *    Returns the value of an alias, or null if none.
       */
        const char *
        lookupAlias( const char *key )
        {
          alias_table_t::iterator result = alias_table.find( key );
          if ( result != alias_table.end() )
            return result->second;
          else
            return 0;
        }
      
      //  deleteAlias()
      //  ------------------------------------------------------------------
      /*
       *    Removes an alias from the table.
       */
        int
        deleteAlias( const char *name )
        {
          return alias_table.erase( name );
        }