www.pudn.com > cppcc.rar > cw_options_recorder.cc


/*
 *  File:       cw_options_recorder.cc
 *              $Id: cw_options_recorder.cc,v 1.5 2003/10/13 10:30:34 alec Exp $
 *
 *  Author:     Alec Panoviciu (alecu@email.com)
 *
 *  Comments:
 *
 *  Revision history:
 *
 *  $Log: cw_options_recorder.cc,v $
 *  Revision 1.5  2003/10/13 10:30:34  alec
 *  added hexa escapes support
 *
 *  Revision 1.4  2002/06/26 20:46:15  alec
 *  g++ 3.x happy
 *
 *  Revision 1.3  2002/06/23 23:33:55  alec
 *  string option bugfix
 *
 *  Revision 1.2  2002/04/29 09:34:10  alec
 *  scanner ptree building compiles
 *
 */

/* 
  Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)

  This program 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 2 of the License, or
  (at your option) any later version.

  This program 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.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 */

#include 
#include 
#include 
using namespace std;

#include "debug.h"
#include "parse_util.hh"
#include "options_recorder.hh"
#include "cw_options_recorder.h"

OptionsRecorder *cw_optionsRecorder = NULL;

/* seems like this one is haunting me.... */
extern int yylineno;
extern int yy_escape_base;

extern "C" void OptionsRecorder_setStringOption (char *key, char *value)
{
  try {
    value[strlen(value)-1]='\0';
    cw_optionsRecorder->setOption(string(key), string(value+1));
  } catch (ParseException &ex) {
    die(formatError(Position(yylineno), ex));
  }
  free(key);
  free(value);
}


extern "C" void OptionsRecorder_setBoolOption (char *key, int value)
{
  try {
    cw_optionsRecorder->setOption(string(key), value != 0);
    if (string(key) == "HEX_ESCAPES")
      yy_escape_base = 16; // this is one HORRIBLE HACK !!!!
  } catch (ParseException &ex) {
    die(formatError(Position(yylineno), ex));
  }
  free(key);
}


extern "C" void OptionsRecorder_setIntOption (char *key, int value)
{
  try {
    cw_optionsRecorder->setOption(string(key), value);
  } catch (ParseException &ex) {
    die(formatError(Position(yylineno), ex));
  }
  free(key);
}


#ifdef DEBUG

extern "C" void OptionsRecorder_dumpOptions ()
{
  fflush(stderr);
  cw_optionsRecorder->dumpRegistry();
  cerr.flush();
}

#endif