#include "hgupinfo.h" #include #include "hadesstd.h" #include #include #include #include #include #include #include int HGupInfo::connectInputFile() { cout << "enter file name > "; HString s(' ',120); cin >> s; filename=s; if (openFile()==HFAILURE) return HFAILURE; return HSUCCESS; } void HGupInfo::closeInputFile() { if(fin) fin.close(); } int HGupInfo::openFile() { fin.open(filename,ios::in); if(fin.fail()) { fin.close(); fin.open(filename,ios::in); } if(fin.fail()) { cerr << "failed to open file " << filename << endl; return HFAILURE; } return HSUCCESS; } int HGupInfo::connectDb(char purpose) { if (!geoDb) { geoDb = new HGeoOraRead; if (purpose=='u') { char user[40]="hades_geom@db-hades.gsi.de"; char password[20]; int ttyfd = 0; struct termios tio, itio; if ((ttyfd = std::open("/dev/tty", O_RDWR)) < 0) { fprintf(stderr, "cannot open tty, using stdin\n"); ttyfd = 0; } if (tcgetattr(ttyfd, &tio) < 0) { fprintf (stderr, "\nUnable to get terminal characteristics: "); cout<<"enter password for user "< "; scanf("%[^\n]%*c",password); } itio = tio; tio.c_lflag &= ~(ECHO|ICANON); tcsetattr (ttyfd, TCSAFLUSH, &tio); cout<<"enter password for user "< "; cin >> password; cin.ignore(1); tcsetattr (ttyfd, TCSAFLUSH, &itio); cout<"; cin >> tmp; newchoice=tmp.lower(); if (newchoice(0,1)=="e") { ftest.close(); exit(1); } else { if (tmp.find("/")>=0) outputName=tmp; else outputName=outDir + tmp; } } ftest.close(); ftest.clear(); } while (writeFlag==0); cout << "output file name for " << modName <<": " << outputName << endl; fout.open(outputName,ios::out); if(fout.fail()) { cerr << "cannot open " << outputName << endl; fout.close(); exit(1); } fout<<"// ***********************************************************"<<'\n'; fout<<"// geometry file for " << modName << " extracted from database"<<'\n'; fout<<"// Date: " << actTime; fout<<"// ***********************************************************"<<'\n'; return HSUCCESS; } HString HGupInfo::getOutDir() { HString outDir, tmp(' ',120); cout << "enter output directory (return = working directory) " << endl; cin.ignore(1); cin.getline(tmp,120); outDir=tmp; return outDir; } void HGupInfo::getTime() { HString day, month; struct tm *newtime; time_t t; time(&t); newtime=localtime(&t); if (newtime->tm_mday<10) day="0" + HString(newtime->tm_mday); else day=HString(newtime->tm_mday); if (newtime->tm_mon<9) month="0" + HString((newtime->tm_mon)+1); else month=HString((newtime->tm_mon)+1); actDate=day + month + HString(newtime->tm_year); actTime=asctime(newtime); return; }