/* * MathPlanner 3.1.1 - Mathematical design tool. * Copyright(C) 2002 Jarmo Nikkanen * * 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. * * You should have received a copy of the GNU General Public License with this program. * */ #include "Unit.h" #include "Error.h" #include "ConfigReader.h" #include #include #include #include QString mpl_unit::UnitName(int i) { return(unit[i].unit+", "+unit[i].name); } QString mpl_unit::Subs(int i) { return(unit[i].subs); } QString mpl_unit::Display(QString n,bool f) { int i; char pw[COUNT]; CreatePower(n,pw); n=CreateSubs(pw); if (f) for(i=0;i0) { g=true; n=unit[i].unit; req.search(n); s+=req.cap(1); if (pw[i]==2) s+="²"; else if (pw[i]==3) s+="³"; else if (pw[i]>1) s+=QString::number((int)pw[i]); } for(i=0;i0) s+="+"; s+=QString::number((int)pw[i]); s+=b; } else s+=n; } return(s); } int mpl_unit::Units() { return(total); } QString mpl_unit::Unit(QString n) { QRegExp req("((\\(|\\[)\\w+)"); QRegExp req2("((\\)|\\]))"); req.search(n); req2.search(n); return(req.cap(1)+req2.cap(1)); } int mpl_unit::FindUnit(QString n) { int i; n=Unit(n); for(i=0;iHas(name)) { co=strdup(Prefs->String(name).latin1()); if (co) { tok=strtok(co,se); if (tok) unit[no].unit=QString(tok); tok=strtok(NULL,se); if (tok) unit[no].name=QString(tok); unit[no].base=true; base++; total++; free(co); no++; i++; } else ErrorReport("Unit","Error"); } else go=false; } i=0; go=true; while(go) { sprintf(name,"Prefix%d",i+1); if (Prefs->Has(name)) { lat=(char *)Prefs->String(name).latin1(); co=strdup(lat); if (co) { tok=strtok(co,se); if (tok) unit[no].unit=QString(tok); tok=strtok(NULL,se); if (tok) unit[no].name=QString(tok); tok=strtok(NULL,se); if (tok) unit[no].prefix=(char)QString(tok).toInt(); unit[no].base=true; base++; total++; free(co); no++; i++; } } else go=false; } i=0; go=true; while(go) { sprintf(name,"Unit%d",i+1); if (Prefs->Has(name)) { lat=(char *)Prefs->String(name).latin1(); co=strdup(lat); if (co) { tok=strtok(co,se); if (tok) unit[no].unit=QString(tok); tok=strtok(NULL,se); if (tok) unit[no].name=QString(tok); tok=strtok(NULL,se); if (tok) unit[no].subs=QString(tok); unit[no].base=false; total++; free(co); no++; i++; } } else go=false; } if (base>=COUNT) ErrorReport("Unit:","Too many base-units"); ProcessSubs(); CreatePowers(); }