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,5 +1,5 @@ -/* +/* * kmolcalc.cpp * * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org> @@ -7,15 +7,16 @@ /** * 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> /** @@ -35,17 +36,17 @@ void KMolCalc::readElstable() { weight = -1; // not calculated yet 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. */ @@ -63,9 +64,9 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) { int i = 0; 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) { int j = i; @@ -84,24 +85,24 @@ 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 } @@ -175,9 +176,9 @@ void KMolCalc::undefineGroup (const QString& name) { elstable->remove (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. */ void KMolCalc::defineElement (const QString& name, double weight) { |