Copyright (C) Kevin Larke 2009-2020

This file is part of libcm.

libcm is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

libcm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See the GNU General Public License distributed with the libcm package or look here: .


//
//  cmSymTblTest() gives a usage example for the symbol table component.
//

void cmSymTblTest( cmCtx_t* ctx )
{
  unsigned    baseSymId = 100;
  unsigned    i;
  unsigned    n = 10;
  unsigned    idArray[n];
  
  // create a symbol table
  cmSymTblH_t h = cmSymTblCreate( cmSymTblNullHandle, baseSymId, ctx );
  
  if( cmSymTblIsValid(h) == false )
  {
    cmRptPrintf(&ctx->rpt,"Symbol table creation failed.");
    return;
  }
  
  // generate and register some symbols
  for(i=0; i<n; ++i)
  {
    bool staticFl = false;
    char str[10];
    snprintf(str,9,"sym%i",i);
    idArray[i] = cmSymTblRegister( h, str, staticFl );    
  }
  
  // remove  the fourth symbol generated
  cmSymTblRemove( h, baseSymId+3 );
  
  // print the symbol table
  cmSymTblReport(h);
  
  // iterate through the symbol table
  for(i=0; i<n; ++i)
  {
    const cmChar_t* lbl = cmSymTblLabel(h,idArray[i]);
    
    if( lbl == NULL )
      cmRptPrintf(&ctx->rpt,"%i <removed>\n",i);
    else
      cmRptPrintf(&ctx->rpt,"%i %i==%i %s \n",i,idArray[i],cmSymTblId(h,lbl),lbl);
  }
  
  // release the symbol table
  cmSymTblDestroy(&h);
  
  return;
}