Diffstat (limited to 'noncore/apps/oxygen/kmolcalc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/oxygen/kmolcalc.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp index 0ba52da..33666b1 100644 --- a/noncore/apps/oxygen/kmolcalc.cpp +++ b/noncore/apps/oxygen/kmolcalc.cpp @@ -1,4 +1,4 @@ -/* +/* * kmolcalc.cpp * * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> @@ -8,13 +8,14 @@ /** * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic * weights and group definitions ELSTABLE, and the currently processed formula, stored - * as a list of elements and their coefficients, ELEMENTS. + * as a list of elements and their coefficients, ELEMENTS. */ #include "kmolcalc.h" #include <qdict.h> #include <qdir.h> #include <qfile.h> +#include <qpe/qpeapplication.h> #include <iostream.h> @@ -36,15 +37,15 @@ void KMolCalc::readElstable() { if (elstable) delete elstable; elstable = new QDict<SubUnit> (197, TRUE); elstable->setAutoDelete(TRUE); - mwfile = "/home/opie/opie/noncore/apps/oxygen/kmolweights"; + mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; QFile f(mwfile); if (f.exists()) readMwfile(f); } -/** - * Parse a string S and construct the ElementList this->ELEMENTS, representing the - * composition of S. Returns 0 if successful, or an error code (currently -1) if +/** + * Parse a string S and construct the ElementList this->ELEMENTS, representing the + * composition of S. Returns 0 if successful, or an error code (currently -1) if * parsing failed. * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. * See help files for correct formula syntax. @@ -64,7 +65,7 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) { QString errors ("OK"); bool ok = TRUE; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; - double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); + double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR ElementList* elstemp = new ElementList; while (i < sl) { @@ -85,22 +86,22 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) { errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); j = ++i; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; - double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); + double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); if (! ok || suffix == 0) { delete inner; delete elstemp; return QString ("Bad formula."); // ERROR - } + } inner->addTo(*elstemp, suffix); delete inner; inner = NULL; } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { - while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || + while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || s[i] == '\'')); QString elname = s.mid(j, i-j); j = i; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; - double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); + double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); if (! ok || suffix == 0) { delete elstemp; return QString ("Bad formula."); // ERROR @@ -176,7 +177,7 @@ void KMolCalc::undefineGroup (const QString& name) { } /** - * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes + * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes * NAME has valid syntax. */ |