//-*- mode: c++; indent-tabs-mode: t; coding: utf-8; show-trailing-whitespace: t -*- // file utilities.cpp #include "utilities.hpp" // namespace kwtcom { long int nKWTVAX; } namespace utilities { #ifdef USE_POSIX bool exists(const char *p) { struct stat sb; // return p && (0 == stat (p, &sb)); } #else bool exists(const char *p) { bool bReturnValue = false; std::fstream sFile; // if(p) { sFile.open(p, std::ios_base::in); bReturnValue = sFile.is_open(); if(bReturnValue) sFile.close(); } return bReturnValue; } #endif std::string format(const std::string &format, ...) { va_list args; va_start(args, format); size_t nLength = std::vsnprintf(NULL, 0, format.c_str(), args); va_end (args); std::vector sVector (nLength + 1); va_start (args, format); std::vsnprintf (&sVector[ 0 ], nLength + 1, format.c_str(), args); va_end (args); return &sVector[ 0 ]; } void quiter(void) { ; } // subroutine window. void window(std::ostream &os, std::stringstream &ss) { // Module of interactive emtp usage only, which services "emtspy". // For non-interactive emtp, this module can be destroyed. // For character*132 spy display channel munit6, this serves // to actually output the line to the spy display device. // VAX-11 installation-dependent EMTP module. size_t j; size_t k; std::string sData; // sData = ss.str(); if(abs(spycom::nKVerfy) != 34543) { for(j = 1; j <= 132; j++) { k = 133 - j; if(sData[ k - 1 ] != ' ') break; } os << sData.substr(0, k) << std::endl; os.flush(); } } // subroutine honker. void honker(const long int &nKLevel) { // Module of interactive EMTP only, which services "emtspy". // If no interactive use, this module can be deleted. // VAX-11 installation-dependent emtp module which issues // an audible alarm (via a terminal speaker) of intensity // controlled by argument klevel. This is on a scale of // one to ten, with zero meaning no noise at all, and ten // corresponding to a disaster alert (e.g., air raid sirens). // This VAX-11 module is designed for DEC VT100 terminal. The // idea is by Albert H. Schmidt, BPA route EOGA. At the keyboard, // ctrl-g will ring the bell, and the ascii character 7 is // equivalent within a program. Shortage of 1 bell is due to // carriage control, maybe (see n8 = j + 1, rather than j, below). int nd13; double d13; std::string pSpyTim[ 2 ], pSpDate[ 2 ]; // d13 = 2.0; date_time::time44(pSpyTim); date_time::date44(pSpDate); spyf77::sBuff77 = std::string (10, '\7'); FOREVER { (*reinterpret_cast(spycom::pMFiles[ 5 ])) << " Audible alarm began at "; (*reinterpret_cast(spycom::pMFiles[ 5 ])) << std::setw(4) << pSpyTim[ 0 ] << pSpyTim[ 1 ]; (*reinterpret_cast(spycom::pMFiles[ 5 ])) << " "; (*reinterpret_cast(spycom::pMFiles[ 5 ])) << std::setw(4) << pSpDate[ 0 ] << pSpDate[ 1 ]; (*reinterpret_cast(spycom::pMFiles[ 5 ])) << std::string(5, ' '); (*reinterpret_cast(spycom::pMFiles[ 5 ])) << std::setw(3) << spycom::nKLevel; (*reinterpret_cast(spycom::pMFiles[ 5 ])) << " bells."; (*reinterpret_cast(spycom::pMFiles[ 5 ])) << spyf77::sBuff77 << std::endl << std::flush; window(*reinterpret_cast(blkcom::pLFiles[ 5 ]), \ *reinterpret_cast(spycom::pMFiles[ 5 ])); if(spycom::nKLevel < 10) break; nd13 = (int) d13; date_time::tdelay(nd13); if(d13 == -7654) break; flager(); if(spycom::nKWTSpy != 0) { spycom::nKWTSpy = 0; break; } else d13 = 1.5 * d13; } } // subroutine flager. void flager(void) { // Module of interactive EMTP only, which services "emtspy". // if no interactive use, convert to dummy module ("return"). // VAX-11 installation-dependent emtp module which serves // to read spy command from munit5 if: 1) ctrl-c interrupt // has occurred, or 2) if lockbr = 1 upon entry. long int pIDum[ 3 ]; // if(spycom::nIprSpy >= 10) { (*reinterpret_cast(spycom::pMFiles[ 5 ])) << " Top flager. istep, kwtspy, itype, lastov =" << blkcom::nIStep << blkcom::nKWTSpy << blkcom::nIType << blkcom::nLastOV << std::endl; window(*reinterpret_cast(blkcom::pLFiles[ 5 ]), \ *reinterpret_cast(spycom::pMFiles[ 5 ])); } if(blkcom::nLastOV == 9911) { spyf77::sBuff77 = "space"; blkcom::nKWTSpy = 1; spycom::nKFile5 = 2; goto a3651; } if(kwtcom::nKWTVAX != 0) { spyf77::sProm80 = " spy:"; prompt(*reinterpret_cast(blkcom::pLFiles[ 5 ]), \ spyf77::sProm80); // if (spycom::nIprSpy < 1) (*reinterpret_cast(spycom::pMFiles[ 5 ])) << " Enable VAX ctrl-c interception in \"flager\"." << std::endl; window(*reinterpret_cast(blkcom::pLFiles[ 5 ]), \ *reinterpret_cast(spycom::pMFiles[ 5 ])); a3491: goto a3643; } if((spycom::nLockBR != 1) || (spycom::nKFile5 == 1)) goto a3651; a3643: reinterpret_cast(spycom::pMFiles[ 4 ]) -> read(&spyf77::sBuff77[ 0 ], 80); blkcom::nKWTSpy = 1; spycom::nKFile5 = 2; if(spycom::nKSPSav == 0) goto a3650; if(strcom::toLower(spyf77::sBuff77.substr(0, 7)) == "cancel ") goto a3648; ++spycom::nKSPSav; goto a3643; a3648: --spycom::nKSPSav; if (spycom::nKSPSav > spycom::nNumCRD) goto a3649; std::cout << " Error stop; overflow in \"flager\"." << std::endl; emtp::stoptp(); a3649: spyf77::sFile6[ spycom::nKSPSav - 1 ] = spyf77::sBuff77; a3650: goto a3651; a3651: if (spycom::nIprSpy >= 9) { *((std::stringstream *) spycom::pMFiles[ 5 ]) << " Exit \"flager\". kwtspy =" << blkcom::nKWTSpy << " buff77 = " << spyf77::sBuff77.substr(0, 80) << std::endl; window(*reinterpret_cast(blkcom::pLFiles[ 5 ]), \ *reinterpret_cast(spycom::pMFiles[ 5 ])); } } // subroutine prompt. void prompt(std::ostream &os, const std::string &sPrompt) { // VAX-11 installation-dependent emtp module used only // for interactive EMTP ("emtspy"). Input is program // prompt in character*80 variable prom80 of deck "dekspy". // The prompt must end with colon (":"). Then line feed // will be suppressed, so subsequent read is to right of ":". // For non-interactive EMTP, this module can be destroyed. long int j; long int n2; // n2 = 80; for(j = 1; j <= 80; j++) { if(sPrompt[ n2 - 1 ] == ' ') break; --n2; } os << sPrompt.substr(0, n2); } // subroutine openfile. bool openFile(std::fstream *pFile, \ std::string &sFileName, \ const std::ios::openmode &mode) { bool bReturnValue = false; // if(pFile) { pFile -> open(sFileName.c_str(), mode); bReturnValue = pFile -> good(); } return bReturnValue; } // subroutine closefile. bool closeFile(std::fstream *pFile) { bool bReturnValue = false; // if(pFile) { pFile -> close(); bReturnValue = true; } return bReturnValue; } // subroutine copyfile. bool copyFile(std::fstream *pInFile, \ std::fstream *pOutFile, \ const std::string &sFileName) { bool bReturnValue = false; // if(pInFile && pOutFile) { pOutFile -> close(); pOutFile -> open(sFileName.c_str(), std::ios::out | std::ios::trunc); pInFile -> seekg(0, std::ios::beg); char pTempData[ 80 ]; while(!pInFile -> eof()) { pInFile -> read(pTempData, 80); pOutFile -> write(pTempData, 80); } pOutFile -> close(); pInFile -> seekg(0, std::ios::beg); bReturnValue = true; } return bReturnValue; } // subroutine deletefile. bool deleteFile(const std::string &sFileName) { ; } struct winsize getTerminalSize(void) { struct winsize sReturnValue; // ioctl(STDOUT_FILENO, TIOCGWINSZ, &sReturnValue); if(blkcom::nNOutPR > 0) { (*reinterpret_cast(blkcom::pLFiles[ 5 ])) << " Terminal lines = "; (*reinterpret_cast(blkcom::pLFiles[ 5 ])) << std::setfill(' ') << std::setw(8) << std::dec << sReturnValue.ws_row; (*reinterpret_cast(blkcom::pLFiles[ 5 ])) << ", columns = "; (*reinterpret_cast(blkcom::pLFiles[ 5 ])) << std::setfill(' ') << std::setw(8) << std::dec << sReturnValue.ws_col << std::endl; } return sReturnValue; } void expchk(long int &n1, \ long int &n2, \ long int &n5) { const char cText1 = 'e', cTextN = '-', cTextP = '+'; const char pTexNum[ 11 ] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.' }; char pX[ 80 ]; // long int i; long int j; long int k; long int l; long int n3, n4; long int nKey; // blkcom::sABuff.read(pX, 80); for(i = n1; i <= n2; i += n5) { nKey = 0; for(j = 1; j <= n5; j++) { n3 = i + j - 1; if(pX[ 2 ] == cText1) goto a2622; if(nKey > 0) goto a2620; for(k = 1; k <= 11; k++) { a2619: if(pX[ n3 - 1 ] == pTexNum[ k - 1 ]) nKey = k; goto a2621; a2620: if((pX[ n3 - 1 ] == cTextP) || (pX[ n3 - 1 ] == cTextN)) goto a2622; a2621: ; } goto a2625; a2622: n4 = i + n5 - 1; for(l = 1; l<= 10; l++) { if(pX[ n4 - 1 ] == pTexNum[ l - 1 ]) goto a2625; } a2624: blkcom::nKill = 97; blkcom::pSStat -> m_nWT = i; blkcom::pSStat -> m_nTails = n4; blkcom::pSStat -> m_nTACST = 2624; return; a2625: ; } } } } // end of file utilities.cpp