Ejemplo n.º 1
0
Archivo: Shell.cpp Proyecto: jibee/STpp
void Shell::pushInt(const char *str) {
	bool opposite = false;
	if(str[0]=='-') {
		opposite=true;
		str++;
	}
	int v = 0;
	if(str[0] == '0') {
		//Could be octal or hexa
		if(str[1] == 'x')
			v = parseHex(str+2);
		else
			v = parseOct(str+1);

	} else {
		v = parseDec(str);
	}
	if(opposite)
		v = -v;
	s.push(v);
}
Ejemplo n.º 2
0
bool DSO::addCustomFile(const QString &fileName)
{
  m_lastCustomError = "";

  SkFile file(fileName);

  if (!file.open(SkFile::ReadOnly | SkFile::Text))
  {
    m_lastCustomError = tr("File not found!");
    return false;
  }

  QString code;

  do
  {
    if (file.atEnd())
    {
      break;
    }
    QString line = file.readLine();

    if (line.simplified() == "*DATA")
    {
      break;
    }

    code += line;
  } while (true);

  QScriptEngine engine;

  scriptNewTypes.clear();

  engine.globalObject().setProperty("AUTHOR", "");
  engine.globalObject().setProperty("EPOCH", 2000);
  engine.globalObject().setProperty("DESCRIPTION", "");

  engine.globalObject().setProperty("POINT_SOURCE", 0);
  engine.globalObject().setProperty("CIRCLE", 1);
  engine.globalObject().setProperty("CROSS", 2);
  engine.globalObject().setProperty("RECTANGLE", 3);

  QScriptValue fun = engine.newFunction(DEFINE_CUSTOM_OBJECT, 3);
  engine.globalObject().setProperty("DEFINE_CUSTOM_OBJECT", fun);

  QScriptValue result = engine.evaluate(code);
  if (engine.hasUncaughtException())
  {
    int line = engine.uncaughtExceptionLineNumber();
    m_lastCustomError = QString("uncaught exception at line ") + line + " : " + result.toString();
    return false;
  }

  QString author;
  QString description;
  double epoch;

  int nameOffset = 0; // TODO: dat globalne

  QScriptValueIterator it(engine.globalObject());
  while (it.hasNext())
  {
    it.next();

    if (it.name() == "AUTHOR")
    {
      author = it.value().toString();
    }
    else
    if (it.name() == "DESCRIPTION")
    {
      description = it.value().toString();
    }
    else
    if (it.name() == "EPOCH")
    {
      epoch = it.value().toNumber();
    }
  }

  do
  {
    if (file.atEnd())
    {
      break;
    }
    QString line = file.readLine().simplified();

    if (line.startsWith("//"))
    {
      continue;
    }

    if (line.size() == 0)
    {
      continue;
    }

    QStringList list = line.split("|");

    //qDebug() << line << list.count();

    if (list.count() != 10)
    {
      m_lastCustomError = "Invalid record";
      return false;
    }

    QString type = list[0].simplified();
    QString name1 = list[1].simplified();
    QString name2 = list[2].simplified();
    double ra = parseRA(list[3]);
    double dec = parseDec(list[4]);
    double sizeA = parseSize(list[5]);
    double sizeB = parseSize(list[6]);
    double mag = list[7].simplified().toDouble();
    double pa = list[8].simplified().toDouble();
    QString cls = list[9].simplified();

    dso_t dso;

    if (qIsNaN(ra) || qIsNaN(dec))
    {
      m_lastCustomError = "Invalid RA/Dec value";
      return false;
    }

    m_namesMap[USER_OFFSET + nameOffset].append(name1);
    m_namesMap[USER_OFFSET + nameOffset].append(name2);
    nameOffset++;

    dso.cataloque = 0; // TODO: dodelat
    dso.galType = 0; // TODO: dodelat
    dso.mag = SkMath::isNear(mag, 0) ?  NO_DSO_MAG : (short)(mag * 100.);
    dso.nameOffs = USER_OFFSET + nameOffset;
    dso.pa = pa; //TODO: bez PA
    dso.rd.ra = SkMath::toRad(ra);
    dso.rd.dec = SkMath::toRad(dec); //TODO:epoch
    dso.shape = NO_DSO_SHAPE;
    dso.sx = sizeA;
    dso.sy = sizeB;
    dso.type = DSOT_CUSTOM_FLAG; // TODO: user types

    qDebug() << line;
    qDebug() << type << name1 << name2 << ra << dec << sizeA << sizeB << mag << pa << cls;
  } while (true);

  return true;
}