Logo Search packages:      
Sourcecode: icemc version File versions  Download package

IceMenuScanner.cpp

/**
 * IceMC - a menu editor for IceWM
 * Copyright (c) 2000 Georg Mittendorfer
 */

// implementation of CLASS IceMenuScanner

// created:       mig 000720
// last modified: mig 000809
// changes:       ----------
#include <limits.h>
#include "IceMenuInCompiler.h"

//////////////////////////////////////////////////////////////////
// constructor & destructor
//////////////////////////////////////////////////////////////////

00018 IceMenuScanner::IceMenuScanner()
{
  ;//qDebug("IceMenuScanner::IceMenuScanner()");
  sy = noSy;
  lnr = 1;
  synr = 1;

  src = new QFile();
  srcStream = new QTextStream();
}

IceMenuScanner::IceMenuScanner(const QString filePath) 
{ 
  ;//qDebug("IceMenuScanner::IceMenuScanner(const QString filePath)");
  sy = noSy;
  lnr = 1;
  synr = 1;

  src = new QFile();
  srcStream = new QTextStream();

  setFile(filePath);
}

IceMenuScanner::~IceMenuScanner()
{
  ;//qDebug("IceMenuScanner::~IceMenuScanner()");
  src->close();
  ;//qDebug("IceMenuScanner::~IceMenuScanner() file closed");
  delete srcStream;
  delete src;
}

//////////////////////////////////////////////////////////////////
// public methods
//////////////////////////////////////////////////////////////////

void IceMenuScanner::setFile(const QString filePath)
{
  src->setName(filePath);
  sy = noSy;
  lnr = 1;
  synr = 1;
  if (src->isOpen())
    src->close();
  src->open(IO_ReadOnly); // IO_Translate?
  if (!src->exists()) {
    qFatal("FATAL: IceMenuScanner::setFile(...) => file not found: " + filePath);
  }
  srcStream->setDevice(src);
  srcLine = srcStream->readLine();
  ch = ' ';
}

IceMenuScanner::symbolCode IceMenuScanner::newSy()
{
  /* note: handles '#' as eol (everything between "..." is handled extra in switch construct) */
  while (isspace(ch) && operator!=(ch,'\n') && operator!=(ch,'#')) {
    ch = newChar();
  }
  switch (ch) {
  case 0:
    sy = eofSy;
    //    cout << "eof\n\n";
    // ch = newChar();
    break;
  case '#':
    sy = skipRestOfLine();
    break;
  case '\n':
    sy = eolSy;
    //    cout << "eol\n";
    ch = newChar();
    break;
  case '{':
    sy = lBraceSy;
    //    cout << '{';
    ch = newChar();
    break;
  case '}':
    sy = rBraceSy;
    //    cout << '}';
    ch = newChar();
    break;
  case '"':
    // every expression enclosed between two quotes is also an identstring
    // i think the IceWM Parser works like this (but i didn't have a closer look)
    ch = newChar();
    identStr = "";
    while ( (operator!=(ch,'"') && operator!=(ch,0)) ) {
      identStr += ch;
      ch = newChar();
    }
    ch = newChar();
    //    cout << '"' + identStr + '"';
    sy = quotedIdentSy;
    break;
  default:
    if (!isgraph(ch)) { // isgraph == isalnum || ispunct
      sy = noSy;
      qWarning("WARNING: IceMenuScanner::newSy() -> *** not a valid Symbol! ***");
      identStr = "";
    } else {
      identStr = "";
      while ((!isspace(ch)) && operator!=(ch,0) && operator!=(ch,'"')) {
      identStr += ch;
      ch = newChar();
      }

      //cout << identStr;

      if (identStr == "prog")
      sy = progSy;
      else if (identStr ==  "menu")
      sy = menuSy;
      else if (identStr ==  "separator")
      sy = separatorSy;
      else if (identStr ==  "restart")
      sy = restartSy;
      else if (identStr ==  "menufile")
      sy = menufileSy;
      else if (identStr ==  "menuprog")
      sy = menuprogSy;
      else
      sy = identSy;
      break;
    }
  }
  //  cout << " ";
  return sy;
}

IceMenuScanner::symbolCode IceMenuScanner::skipRestOfLine() {
  identStr = "";
  while ( (operator!=(ch, '\n') && operator!=(ch, 0)) ) {
    identStr += ch;
    ch = newChar();
  }
  if (operator==(ch,0)) sy = eofSy;
  else sy = eolSy;
  return sy;
}

QString IceMenuScanner::getIdentStr() const
{ 
  return identStr;
}

///////////////////////////////////////////////////////////
// private methods
///////////////////////////////////////////////////////////

QChar IceMenuScanner::newChar()
{
  QChar localCh;

  if (srcLine.length() >= synr) {
    localCh = srcLine[synr-1];
    synr++;
  } 
  else if (!srcStream->atEnd()) {
    srcLine = srcStream->readLine();
    synr = 1;
    lnr++;
    localCh = '\n';
  } 
  else
    localCh = 0;

  return localCh;
}

void IceMenuScanner::getActPos(int& line, int& sy)
{
  line = lnr;
  sy = int(synr);
}













Generated by  Doxygen 1.6.0   Back to index