Functions | |
ApplicationHelp * | help () |
int | main (int argc, char **argv) |
PACKAGE_INFO (gpsort, GPSORT) | |
template<class PointType > | |
int | sortCurve (bool explicitIndexList, int &argc, char **argv) |
ApplicationHelp* help | ( | ) |
int main | ( | int | argc, |
char ** | argv | ||
) |
References QGpCoreTools::endl(), help(), and QGpCoreTools::tr().
{ CoreApplication a(argc, argv, help); // Options bool explicitIndexList=false; bool namedPoint=false; // Check arguments int i, j=1; for(i=1; i<argc; i++) { QByteArray arg=argv[i]; if(arg[0]=='-') { if(arg=="-explicit") { explicitIndexList=true; } else if(arg=="-cn") { namedPoint=true; } else { App::stream() << tr("gpsort: bad option %1, see -help").arg(argv[i]) << endl; return 2; } } else { argv[j++]=argv[i]; } } if(j < argc) { argv[j]=0; argc=j; } if(namedPoint) { return sortCurve<NamedPoint>(explicitIndexList, argc, argv); } else { return sortCurve<PointND>(explicitIndexList, argc, argv); } }
PACKAGE_INFO | ( | gpsort | , |
GPSORT | |||
) |
int sortCurve | ( | bool | explicitIndexList, |
int & | argc, | ||
char ** | argv | ||
) |
References QGpCoreTools::Curve< pointType >::append(), QGpCoreTools::endl(), QGpCoreTools::Curve< pointType >::isEmpty(), QGpCoreTools::Curve< pointType >::last(), sOut(), str, and QGpCoreTools::tr().
{ // Read stdin for curves until encountering a blank line QString buf; QStringList curveComments; curveComments.append(QString()); QString * curveComment=&curveComments.last(); QList< Curve<PointType> > curves; curves.append(Curve<PointType>()); Curve<PointType> * curve=&curves.last(); PointType p; QTextStream sIn(stdin); QTextStream sOut(stdout); CoreApplication::instance()->debugUserInterrupts(false); while(!sIn.atEnd()) { buf=sIn.readLine(); if(buf[0]=='\n' || buf[0]=='#') { if(!curve->isEmpty()) { curveComments.append(buf+"\n" ); curveComment=&curveComments.last(); curves.append(Curve<PointType>()); curve=&curves.last(); } else { curveComment->append(buf+"\n"); } } else { QString str(buf); p.fromString(str); curve->append(p); } } CoreApplication::instance()->debugUserInterrupts(true); // Output in sected order QSet<int> indexes; for(int i=1 ; i<argc; i++) { int index=atoi(argv[i] ); if(index<curves.count()) { sOut << "# curve's original index: " << index << "\n" << curveComments.at(index) << curves.at(index).toString(); indexes.insert(index); } else { App::stream() << tr("gpsort: index %1 out of range").arg(index) << endl; return 2; } } if(!explicitIndexList) { for(int i=0; i< curves.count();i++) { if(!indexes.contains(i)) { sOut << "# curve's original index: " << i << "\n" << curveComments.at(i) << curves.at(i).toString(); } } } return 0; }