rem
stringlengths 0
83.5k
| add
stringlengths 0
223k
| context
stringlengths 10
471k
| meta
stringlengths 120
236
|
---|---|---|---|
XSetIOErrorHandler(xio_errhandler); XCreateSimpleWindow(x11Display, DefaultRootWindow(x11Display), 0, 0, 1, 1, 0, BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display)), BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display))); return XConnectionNumber(x11Display); | XSetIOErrorHandler(xio_errhandler); XCreateSimpleWindow(x11Display, DefaultRootWindow(x11Display), 0, 0, 1, 1, 0, BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display)), BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display))); return XConnectionNumber(x11Display); | int initXconnection(){ x11Display = XOpenDisplay(NULL); if (x11Display != 0L) { XSetIOErrorHandler(xio_errhandler); XCreateSimpleWindow(x11Display, DefaultRootWindow(x11Display), 0, 0, 1, 1, 0, BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display)), BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display))); return XConnectionNumber(x11Display); } else { kdWarning(1205) << "Can't connect to the X Server.\n"; kdWarning(1205) << "Might not terminate at end of session.\n"; return -1; }} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/a15fc46ae247aaa93909392ddc4ca7d2609ed34b/kdesud.cpp/buggy/kdesu/kdesud/kdesud.cpp |
kdWarning(1205) << "Can't connect to the X Server.\n"; kdWarning(1205) << "Might not terminate at end of session.\n"; return -1; | kdWarning(1205) << "Can't connect to the X Server.\n"; kdWarning(1205) << "Might not terminate at end of session.\n"; return -1; | int initXconnection(){ x11Display = XOpenDisplay(NULL); if (x11Display != 0L) { XSetIOErrorHandler(xio_errhandler); XCreateSimpleWindow(x11Display, DefaultRootWindow(x11Display), 0, 0, 1, 1, 0, BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display)), BlackPixelOfScreen(DefaultScreenOfDisplay(x11Display))); return XConnectionNumber(x11Display); } else { kdWarning(1205) << "Can't connect to the X Server.\n"; kdWarning(1205) << "Might not terminate at end of session.\n"; return -1; }} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/a15fc46ae247aaa93909392ddc4ca7d2609ed34b/kdesud.cpp/buggy/kdesu/kdesud/kdesud.cpp |
void put() { assert(ref == 1); ref--; lru_unpin(); } | void put() { ref--; assert(ref >= 0); } | void put() { assert(ref == 1); ref--; lru_unpin(); } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/fff39240db7cba67fed97cd3ceeb604586d2188a/Client.h/clean/ceph/client/Client.h |
QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); | QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir","."); | static void openFilesRememberingFilter_(QString const &filterName, QString const &filters, QStringList & selectedFiles, QString& enc, QString &title){ bool haveLastUsedFilter = false; // by default, there is no last // used filter QSettings settings; // where we keep last used filter in // persistant state QString lastUsedFilter = settings.readEntry("/qgis/UI/" + filterName, QString::null, &haveLastUsedFilter); QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); QString lastUsedEncoding = settings.readEntry("/qgis/UI/encoding");#ifdef QGISDEBUG std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl;#endif QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); // allow for selection of more than one file openFileDialog->setMode(QFileDialog::ExistingFiles); openFileDialog->setCaption(title); if (haveLastUsedFilter) // set the filter to the last one used { openFileDialog->setSelectedFilter(lastUsedFilter); } if (openFileDialog->exec() == QDialog::Accepted) { selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); } settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); delete openFileDialog;} // openFilesRememberingFilter_ | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/7596d4d2b4c345b8cefc8759b48d94eb031b00ca/qgisapp.cpp/buggy/src/qgisapp.cpp |
std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl; | std::cerr << "Opening file dialog with filters: " << filters.local8Bit() << std::endl; | static void openFilesRememberingFilter_(QString const &filterName, QString const &filters, QStringList & selectedFiles, QString& enc, QString &title){ bool haveLastUsedFilter = false; // by default, there is no last // used filter QSettings settings; // where we keep last used filter in // persistant state QString lastUsedFilter = settings.readEntry("/qgis/UI/" + filterName, QString::null, &haveLastUsedFilter); QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); QString lastUsedEncoding = settings.readEntry("/qgis/UI/encoding");#ifdef QGISDEBUG std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl;#endif QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); // allow for selection of more than one file openFileDialog->setMode(QFileDialog::ExistingFiles); openFileDialog->setCaption(title); if (haveLastUsedFilter) // set the filter to the last one used { openFileDialog->setSelectedFilter(lastUsedFilter); } if (openFileDialog->exec() == QDialog::Accepted) { selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); } settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); delete openFileDialog;} // openFilesRememberingFilter_ | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/7596d4d2b4c345b8cefc8759b48d94eb031b00ca/qgisapp.cpp/buggy/src/qgisapp.cpp |
QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); | QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); | static void openFilesRememberingFilter_(QString const &filterName, QString const &filters, QStringList & selectedFiles, QString& enc, QString &title){ bool haveLastUsedFilter = false; // by default, there is no last // used filter QSettings settings; // where we keep last used filter in // persistant state QString lastUsedFilter = settings.readEntry("/qgis/UI/" + filterName, QString::null, &haveLastUsedFilter); QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); QString lastUsedEncoding = settings.readEntry("/qgis/UI/encoding");#ifdef QGISDEBUG std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl;#endif QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); // allow for selection of more than one file openFileDialog->setMode(QFileDialog::ExistingFiles); openFileDialog->setCaption(title); if (haveLastUsedFilter) // set the filter to the last one used { openFileDialog->setSelectedFilter(lastUsedFilter); } if (openFileDialog->exec() == QDialog::Accepted) { selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); } settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); delete openFileDialog;} // openFilesRememberingFilter_ | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/7596d4d2b4c345b8cefc8759b48d94eb031b00ca/qgisapp.cpp/buggy/src/qgisapp.cpp |
selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); | selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); QString myFirstFileName = selectedFiles.first(); QFileInfo myFI(myFirstFileName); QString myPath = myFI.dirPath(); #ifdef QGISDEBUG qDebug("Writing last used dir: " + myPath); #endif settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", myPath); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); | static void openFilesRememberingFilter_(QString const &filterName, QString const &filters, QStringList & selectedFiles, QString& enc, QString &title){ bool haveLastUsedFilter = false; // by default, there is no last // used filter QSettings settings; // where we keep last used filter in // persistant state QString lastUsedFilter = settings.readEntry("/qgis/UI/" + filterName, QString::null, &haveLastUsedFilter); QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); QString lastUsedEncoding = settings.readEntry("/qgis/UI/encoding");#ifdef QGISDEBUG std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl;#endif QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); // allow for selection of more than one file openFileDialog->setMode(QFileDialog::ExistingFiles); openFileDialog->setCaption(title); if (haveLastUsedFilter) // set the filter to the last one used { openFileDialog->setSelectedFilter(lastUsedFilter); } if (openFileDialog->exec() == QDialog::Accepted) { selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); } settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); delete openFileDialog;} // openFilesRememberingFilter_ | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/7596d4d2b4c345b8cefc8759b48d94eb031b00ca/qgisapp.cpp/buggy/src/qgisapp.cpp |
settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); | static void openFilesRememberingFilter_(QString const &filterName, QString const &filters, QStringList & selectedFiles, QString& enc, QString &title){ bool haveLastUsedFilter = false; // by default, there is no last // used filter QSettings settings; // where we keep last used filter in // persistant state QString lastUsedFilter = settings.readEntry("/qgis/UI/" + filterName, QString::null, &haveLastUsedFilter); QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); QString lastUsedEncoding = settings.readEntry("/qgis/UI/encoding");#ifdef QGISDEBUG std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl;#endif QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); // allow for selection of more than one file openFileDialog->setMode(QFileDialog::ExistingFiles); openFileDialog->setCaption(title); if (haveLastUsedFilter) // set the filter to the last one used { openFileDialog->setSelectedFilter(lastUsedFilter); } if (openFileDialog->exec() == QDialog::Accepted) { selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); } settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); delete openFileDialog;} // openFilesRememberingFilter_ | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/7596d4d2b4c345b8cefc8759b48d94eb031b00ca/qgisapp.cpp/buggy/src/qgisapp.cpp |
|
} | } | static void openFilesRememberingFilter_(QString const &filterName, QString const &filters, QStringList & selectedFiles, QString& enc, QString &title){ bool haveLastUsedFilter = false; // by default, there is no last // used filter QSettings settings; // where we keep last used filter in // persistant state QString lastUsedFilter = settings.readEntry("/qgis/UI/" + filterName, QString::null, &haveLastUsedFilter); QString lastUsedDir = settings.readEntry("/qgis/UI/" + filterName + "Dir", "."); QString lastUsedEncoding = settings.readEntry("/qgis/UI/encoding");#ifdef QGISDEBUG std::cerr << "Opening vector file dialog with filters: " << filters.local8Bit() << std::endl;#endif QgsEncodingFileDialog* openFileDialog = new QgsEncodingFileDialog(lastUsedDir, filters, 0, QFileDialog::tr("open files dialog"), lastUsedEncoding); // allow for selection of more than one file openFileDialog->setMode(QFileDialog::ExistingFiles); openFileDialog->setCaption(title); if (haveLastUsedFilter) // set the filter to the last one used { openFileDialog->setSelectedFilter(lastUsedFilter); } if (openFileDialog->exec() == QDialog::Accepted) { selectedFiles = openFileDialog->selectedFiles(); enc = openFileDialog->encoding(); } settings.writeEntry("/qgis/UI/" + filterName, openFileDialog->selectedFilter()); settings.writeEntry("/qgis/UI/" + filterName + "Dir", openFileDialog->dirPath()); settings.writeEntry("/qgis/UI/encoding", openFileDialog->encoding()); delete openFileDialog;} // openFilesRememberingFilter_ | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/7596d4d2b4c345b8cefc8759b48d94eb031b00ca/qgisapp.cpp/buggy/src/qgisapp.cpp |
void decay(const timepair_t& now) { timepair_t el = now; | void decay() { utime_t el = g_clock.recent_now(); | void decay(const timepair_t& now) { timepair_t el = now; el -= last_decay; if (el.first > 1) { val = val * exp(timepair_to_double(el) * k); if (val < .01) val = 0; last_decay = now; } } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/8c7283a709cbd1031e4adc5c129a44d81b7a0f8d/DecayCounter.h/clean/ceph/common/DecayCounter.h |
if (el.first > 1) { val = val * exp(timepair_to_double(el) * k); | if (el.sec() >= 1) { val = val * exp((double)el * k); | void decay(const timepair_t& now) { timepair_t el = now; el -= last_decay; if (el.first > 1) { val = val * exp(timepair_to_double(el) * k); if (val < .01) val = 0; last_decay = now; } } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/8c7283a709cbd1031e4adc5c129a44d81b7a0f8d/DecayCounter.h/clean/ceph/common/DecayCounter.h |
last_decay = now; | last_decay = g_clock.recent_now(); | void decay(const timepair_t& now) { timepair_t el = now; el -= last_decay; if (el.first > 1) { val = val * exp(timepair_to_double(el) * k); if (val < .01) val = 0; last_decay = now; } } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/8c7283a709cbd1031e4adc5c129a44d81b7a0f8d/DecayCounter.h/clean/ceph/common/DecayCounter.h |
fprintf (stderr, "%d: ", gettid ()); | log_msg (int type, const char *fmt,...){ va_list ap;#ifndef HAVE_VSYSLOG char msg[512];#endif va_start (ap, fmt); if (debug_flag) { vfprintf (stderr, fmt, ap); fputc ('\n', stderr); } else {#ifndef HAVE_VSYSLOG vsnprintf (msg, 512, fmt, ap); syslog (type, "%s", msg);#else vsyslog (type, fmt, ap);#endif } va_end (ap);} | 5799 /local/tlutelli/issta_data/temp/c/2005_temp/2005/5799/ae2b65354c11405ebf8d8bb8f96cb40e91ad5c5b/log_msg.c/buggy/src/log_msg.c |
|
KApplication app(argc, argv, "kwelcome"); | KAboutData aboutData( "kwelcome", I18N_NOOP("KDE Welcome Dialog"), version, description, KAboutData::License_GPL, "(c) 1999-2000, Matthias Elter" ); aboutData.addAuthor( "Matthias Elter", 0, "[email protected]" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions(option); if ( KUniqueApplication::start() == false ) return 0; KUniqueApplication app; | int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for -kdestartup KConfig *conf = kapp->config(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (int i = 1; i < argc; i++) { QString arg = argv[i]; if ((arg == "-kdestartup") && (tmp != "true")) return 0; } KWelcome *toplevel = new KWelcome(); app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->show(); int rv = app.exec(); if (toplevel) delete toplevel; return rv;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/cbfb92a893c63fe3edcda110be7449c85ff1498b/main.cc/buggy/khelpcenter/kwelcome/main.cc |
QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); | bool autostart = conf->readBoolEntry( "AutostartOnKDEStartup", true); | int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for -kdestartup KConfig *conf = kapp->config(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (int i = 1; i < argc; i++) { QString arg = argv[i]; if ((arg == "-kdestartup") && (tmp != "true")) return 0; } KWelcome *toplevel = new KWelcome(); app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->show(); int rv = app.exec(); if (toplevel) delete toplevel; return rv;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/cbfb92a893c63fe3edcda110be7449c85ff1498b/main.cc/buggy/khelpcenter/kwelcome/main.cc |
for (int i = 1; i < argc; i++) { QString arg = argv[i]; if ((arg == "-kdestartup") && (tmp != "true")) return 0; } | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->isSet( "kdestartup" ) && !autostart ) return 0; | int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for -kdestartup KConfig *conf = kapp->config(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (int i = 1; i < argc; i++) { QString arg = argv[i]; if ((arg == "-kdestartup") && (tmp != "true")) return 0; } KWelcome *toplevel = new KWelcome(); app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->show(); int rv = app.exec(); if (toplevel) delete toplevel; return rv;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/cbfb92a893c63fe3edcda110be7449c85ff1498b/main.cc/buggy/khelpcenter/kwelcome/main.cc |
lpStruct->iImage = (*env)->GetIntField(env, lpObject, HDITEMFc.iImage); lpStruct->lParam = (*env)->GetIntField(env, lpObject, HDITEMFc.lParam); lpStruct->fmt = (*env)->GetIntField(env, lpObject, HDITEMFc.fmt); lpStruct->cchTextMax = (*env)->GetIntField(env, lpObject, HDITEMFc.cchTextMax); lpStruct->hbm = (HBITMAP)(*env)->GetIntField(env, lpObject, HDITEMFc.hbm); lpStruct->pszText = (LPTSTR)(*env)->GetIntField(env, lpObject, HDITEMFc.pszText); lpStruct->cxy = (*env)->GetIntField(env, lpObject, HDITEMFc.cxy); lpStruct->mask = (*env)->GetIntField(env, lpObject, HDITEMFc.mask); | HDITEM *getHDITEMFields(JNIEnv *env, jobject lpObject, HDITEM *lpStruct){ if (!HDITEMFc.cached) cacheHDITEMFields(env, lpObject); lpStruct->iOrder = (*env)->GetIntField(env, lpObject, HDITEMFc.iOrder); lpStruct->iImage = (*env)->GetIntField(env, lpObject, HDITEMFc.iImage); lpStruct->lParam = (*env)->GetIntField(env, lpObject, HDITEMFc.lParam); lpStruct->fmt = (*env)->GetIntField(env, lpObject, HDITEMFc.fmt); lpStruct->cchTextMax = (*env)->GetIntField(env, lpObject, HDITEMFc.cchTextMax); lpStruct->hbm = (HBITMAP)(*env)->GetIntField(env, lpObject, HDITEMFc.hbm); lpStruct->pszText = (LPTSTR)(*env)->GetIntField(env, lpObject, HDITEMFc.pszText); lpStruct->cxy = (*env)->GetIntField(env, lpObject, HDITEMFc.cxy); lpStruct->mask = (*env)->GetIntField(env, lpObject, HDITEMFc.mask); return lpStruct;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
bool supportsFeatureAddition(){return false;} | bool supportsFeatureAddition(){return true;} | bool supportsFeatureAddition(){return false;} | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/79ca0c6a17c3d0f250ddb6acac55c9f742b27f95/qgsgpxprovider.h/buggy/providers/gpx/qgsgpxprovider.h |
C_Client_Cond(Cond *cond, Mutex *mutex, int *rvalue) { this->cond = cond; this->mutex = mutex; this->rvalue = rvalue; this->finished = false; | C_Client_Cond(Cond *cond, Mutex *mutex, int *rvalue) { this->cond = cond; this->mutex = mutex; this->rvalue = rvalue; this->finished = false; | C_Client_Cond(Cond *cond, Mutex *mutex, int *rvalue) { this->cond = cond; this->mutex = mutex; this->rvalue = rvalue; this->finished = false; } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/fff39240db7cba67fed97cd3ceeb604586d2188a/Client.cc/clean/ceph/client/Client.cc |
in->inflight_buffers.erase(blist); delete blist; if (in->inflight_buffers.empty()) { for (list<Cond*>::iterator it = in->waitfor_flushed.begin(); it != in->waitfor_flushed.end(); it++) { (*it)->Signal(); } in->waitfor_flushed.clear(); } | *rvalue += r; finished = true; bh->miss_finish(); | void finish(int r) { in->inflight_buffers.erase(blist); delete blist; if (in->inflight_buffers.empty()) { // wake up flush waiters for (list<Cond*>::iterator it = in->waitfor_flushed.begin(); it != in->waitfor_flushed.end(); it++) { (*it)->Signal(); } in->waitfor_flushed.clear(); } } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/fff39240db7cba67fed97cd3ceeb604586d2188a/Client.cc/clean/ceph/client/Client.cc |
this->in = in; this->blist = blist; | this->in = in; this->blist = blist; | C_Client_WriteBuffer(Inode *in, bufferlist *blist) { this->in = in; this->blist = blist; } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/fff39240db7cba67fed97cd3ceeb604586d2188a/Client.cc/clean/ceph/client/Client.cc |
(*env)->SetIntField(env, lpObject, TVITEMFc.cChildren, (jint)lpStruct->cChildren); (*env)->SetIntField(env, lpObject, TVITEMFc.iSelectedImage, (jint)lpStruct->iSelectedImage); (*env)->SetIntField(env, lpObject, TVITEMFc.iImage, (jint)lpStruct->iImage); (*env)->SetIntField(env, lpObject, TVITEMFc.cchTextMax, (jint)lpStruct->cchTextMax); (*env)->SetIntField(env, lpObject, TVITEMFc.pszText, (jint)lpStruct->pszText); (*env)->SetIntField(env, lpObject, TVITEMFc.stateMask, (jint)lpStruct->stateMask); (*env)->SetIntField(env, lpObject, TVITEMFc.state, (jint)lpStruct->state); (*env)->SetIntField(env, lpObject, TVITEMFc.hItem, (jint)lpStruct->hItem); (*env)->SetIntField(env, lpObject, TVITEMFc.mask, (jint)lpStruct->mask); | void setTVITEMFields(JNIEnv *env, jobject lpObject, TVITEM *lpStruct){ if (!TVITEMFc.cached) cacheTVITEMFields(env, lpObject); (*env)->SetIntField(env, lpObject, TVITEMFc.lParam, (jint)lpStruct->lParam); (*env)->SetIntField(env, lpObject, TVITEMFc.cChildren, (jint)lpStruct->cChildren); (*env)->SetIntField(env, lpObject, TVITEMFc.iSelectedImage, (jint)lpStruct->iSelectedImage); (*env)->SetIntField(env, lpObject, TVITEMFc.iImage, (jint)lpStruct->iImage); (*env)->SetIntField(env, lpObject, TVITEMFc.cchTextMax, (jint)lpStruct->cchTextMax); (*env)->SetIntField(env, lpObject, TVITEMFc.pszText, (jint)lpStruct->pszText); (*env)->SetIntField(env, lpObject, TVITEMFc.stateMask, (jint)lpStruct->stateMask); (*env)->SetIntField(env, lpObject, TVITEMFc.state, (jint)lpStruct->state); (*env)->SetIntField(env, lpObject, TVITEMFc.hItem, (jint)lpStruct->hItem); (*env)->SetIntField(env, lpObject, TVITEMFc.mask, (jint)lpStruct->mask);} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
proto->callbackUsed = true; bool res = true; QString myUser, myPass; switch (type) { case ANSWER_USER_NAME: proto->loadBindings(); for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==QCString(optmessage).upper() && !it->login.isEmpty()) { if (user) delete user; user = new char[it->login.local8Bit().length()+1]; strcpy(user,it->login.local8Bit().data()); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: user=" << user << ", pass=" << pass << endl; havePass=true; return user; } } message = i18n("Authorization is required to access host %1").arg(optmessage); myUser = user?user:""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; proto->bserver = optmessage; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return user; | proto->callbackUsed = true; bool res = true; QString myUser, myPass; switch (type) { case ANSWER_USER_NAME: proto->loadBindings(); for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==QCString(optmessage).upper() && !it->login.isEmpty()) { if (user) delete user; user = new char[it->login.local8Bit().length()+1]; strcpy(user,it->login.local8Bit().data()); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: user=" << user << ", pass=" << pass << endl; havePass=true; return user; } } message = i18n("Authorization is required to access host %1").arg(optmessage); myUser = user?user:""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; proto->bserver = optmessage; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return user; | char *getAnswer(int type, const char *optmessage) { proto->callbackUsed = true; bool res = true; QString myUser, myPass; switch (type) { case ANSWER_USER_NAME: // look if we have it already proto->loadBindings(); // reload each time, to keep in sync for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==QCString(optmessage).upper() && !it->login.isEmpty()) { if (user) delete user; user = new char[it->login.local8Bit().length()+1]; strcpy(user,it->login.local8Bit().data()); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: user=" << user << ", pass=" << pass << endl; havePass=true; return user; } } message = i18n("Authorization is required to access host %1").arg(optmessage); myUser = user?user:""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; // Store the new binding info in case of success proto->bserver = optmessage; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return user; case ANSWER_USER_PASSWORD: if (havePass) return pass; message = i18n("Please enter password for user %1").arg(optmessage); myUser = optmessage; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, proto->currentHost); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; // Store the new binding info in case of success proto->bserver = proto->currentHost; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return pass; case ANSWER_SERVICE_PASSWORD:/* if (haveServicePass && !strcmp(service, optmessage)) return pass; // we have it already*/ // look if we have it in the bindings proto->loadBindings(); // reload each time, to keep in sync for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==proto->currentHost.local8Bit().upper() && it->share.local8Bit().upper()==QCString(optmessage).upper()) { if (service) delete service; service = new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: service=" << service << ", pass=" << pass << endl; haveServicePass=true; return pass; } } message = i18n("Please enter password for share %1 (user ignored)").arg(optmessage); myUser = ""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, "smbSHARE/" + proto->currentHost + QString("/") + optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; if (!res) { if (service) {delete service; service = 0;} if (pass) {delete pass; pass = 0;} haveServicePass=false; } else { if (service) delete service; service=new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: service=" << service << ", pass=" << pass << endl; haveServicePass=true; // Store the new binding info in case of success proto->bserver = proto->currentHost; proto->bshare = optmessage; proto->blogin = ""; proto->bpassword = pass; } return pass; } return 0; //??? } | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/39a40b82a2fc55ed7e977945ed4c332480807109/smb.cc/buggy/kioslave/smb/smb.cc |
case ANSWER_USER_PASSWORD: if (havePass) return pass; message = i18n("Please enter password for user %1").arg(optmessage); myUser = optmessage; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, proto->currentHost); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; proto->bserver = proto->currentHost; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return pass; | case ANSWER_USER_PASSWORD: if (havePass) return pass; message = i18n("Please enter password for user %1").arg(optmessage); myUser = optmessage; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, proto->currentHost); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; proto->bserver = proto->currentHost; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return pass; | char *getAnswer(int type, const char *optmessage) { proto->callbackUsed = true; bool res = true; QString myUser, myPass; switch (type) { case ANSWER_USER_NAME: // look if we have it already proto->loadBindings(); // reload each time, to keep in sync for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==QCString(optmessage).upper() && !it->login.isEmpty()) { if (user) delete user; user = new char[it->login.local8Bit().length()+1]; strcpy(user,it->login.local8Bit().data()); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: user=" << user << ", pass=" << pass << endl; havePass=true; return user; } } message = i18n("Authorization is required to access host %1").arg(optmessage); myUser = user?user:""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; // Store the new binding info in case of success proto->bserver = optmessage; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return user; case ANSWER_USER_PASSWORD: if (havePass) return pass; message = i18n("Please enter password for user %1").arg(optmessage); myUser = optmessage; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, proto->currentHost); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; // Store the new binding info in case of success proto->bserver = proto->currentHost; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return pass; case ANSWER_SERVICE_PASSWORD:/* if (haveServicePass && !strcmp(service, optmessage)) return pass; // we have it already*/ // look if we have it in the bindings proto->loadBindings(); // reload each time, to keep in sync for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==proto->currentHost.local8Bit().upper() && it->share.local8Bit().upper()==QCString(optmessage).upper()) { if (service) delete service; service = new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: service=" << service << ", pass=" << pass << endl; haveServicePass=true; return pass; } } message = i18n("Please enter password for share %1 (user ignored)").arg(optmessage); myUser = ""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, "smbSHARE/" + proto->currentHost + QString("/") + optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; if (!res) { if (service) {delete service; service = 0;} if (pass) {delete pass; pass = 0;} haveServicePass=false; } else { if (service) delete service; service=new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: service=" << service << ", pass=" << pass << endl; haveServicePass=true; // Store the new binding info in case of success proto->bserver = proto->currentHost; proto->bshare = optmessage; proto->blogin = ""; proto->bpassword = pass; } return pass; } return 0; //??? } | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/39a40b82a2fc55ed7e977945ed4c332480807109/smb.cc/buggy/kioslave/smb/smb.cc |
case ANSWER_SERVICE_PASSWORD: /* if (haveServicePass && !strcmp(service, optmessage)) return pass; proto->loadBindings(); for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==proto->currentHost.local8Bit().upper() && it->share.local8Bit().upper()==QCString(optmessage).upper()) { if (service) delete service; service = new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: service=" << service << ", pass=" << pass << endl; haveServicePass=true; return pass; } } message = i18n("Please enter password for share %1 (user ignored)").arg(optmessage); myUser = ""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, "smbSHARE/" + proto->currentHost + QString("/") + optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; if (!res) { if (service) {delete service; service = 0;} if (pass) {delete pass; pass = 0;} haveServicePass=false; } else { if (service) delete service; service=new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: service=" << service << ", pass=" << pass << endl; haveServicePass=true; proto->bserver = proto->currentHost; proto->bshare = optmessage; proto->blogin = ""; proto->bpassword = pass; } return pass; } return 0; } | case ANSWER_SERVICE_PASSWORD: /* if (haveServicePass && !strcmp(service, optmessage)) return pass; proto->loadBindings(); for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==proto->currentHost.local8Bit().upper() && it->share.local8Bit().upper()==QCString(optmessage).upper()) { if (service) delete service; service = new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: service=" << service << ", pass=" << pass << endl; haveServicePass=true; return pass; } } message = i18n("Please enter password for share %1 (user ignored)").arg(optmessage); myUser = ""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, "smbSHARE/" + proto->currentHost + QString("/") + optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; if (!res) { if (service) {delete service; service = 0;} if (pass) {delete pass; pass = 0;} haveServicePass=false; } else { if (service) delete service; service=new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: service=" << service << ", pass=" << pass << endl; haveServicePass=true; proto->bserver = proto->currentHost; proto->bshare = optmessage; proto->blogin = ""; proto->bpassword = pass; } return pass; } return 0; } | char *getAnswer(int type, const char *optmessage) { proto->callbackUsed = true; bool res = true; QString myUser, myPass; switch (type) { case ANSWER_USER_NAME: // look if we have it already proto->loadBindings(); // reload each time, to keep in sync for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==QCString(optmessage).upper() && !it->login.isEmpty()) { if (user) delete user; user = new char[it->login.local8Bit().length()+1]; strcpy(user,it->login.local8Bit().data()); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: user=" << user << ", pass=" << pass << endl; havePass=true; return user; } } message = i18n("Authorization is required to access host %1").arg(optmessage); myUser = user?user:""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; // Store the new binding info in case of success proto->bserver = optmessage; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return user; case ANSWER_USER_PASSWORD: if (havePass) return pass; message = i18n("Please enter password for user %1").arg(optmessage); myUser = optmessage; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, proto->currentHost); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; if (!res) { if (user) {delete user; user = 0;} if (pass) {delete pass; pass = 0;} havePass=false; } else { if (user) delete user; user=new char[myUser.local8Bit().length()+1]; strcpy(user,myUser.local8Bit().data()); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; havePass=true; // Store the new binding info in case of success proto->bserver = proto->currentHost; proto->bshare = ""; proto->blogin = user; proto->bpassword = pass; } return pass; case ANSWER_SERVICE_PASSWORD:/* if (haveServicePass && !strcmp(service, optmessage)) return pass; // we have it already*/ // look if we have it in the bindings proto->loadBindings(); // reload each time, to keep in sync for (SmbProtocol::Binding* it = proto->bindings.first(); (it); it = proto->bindings.next()) { if (it->server.local8Bit().upper()==proto->currentHost.local8Bit().upper() && it->share.local8Bit().upper()==QCString(optmessage).upper()) { if (service) delete service; service = new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass = new char[it->password.local8Bit().length()+1]; strcpy(pass,it->password.local8Bit().data()); kdDebug(7106) << "CallBack: use binding: service=" << service << ", pass=" << pass << endl; haveServicePass=true; return pass; } } message = i18n("Please enter password for share %1 (user ignored)").arg(optmessage); myUser = ""; myPass = ""; res = proto->openPassDlg(message, myUser, myPass, "smbSHARE/" + proto->currentHost + QString("/") + optmessage); kdDebug(7106) << "CallBack: res=" << (res?"true":"false") << endl; kdDebug(7106) << "CallBack: user=" << user << ", pass=" << pass << endl; if (!res) { if (service) {delete service; service = 0;} if (pass) {delete pass; pass = 0;} haveServicePass=false; } else { if (service) delete service; service=new char[strlen(optmessage)+1]; strcpy(service,optmessage); if (pass) delete pass; pass=new char[myPass.local8Bit().length()+1]; strcpy(pass,myPass.local8Bit().data()); kdDebug(7106) << "CallBack: service=" << service << ", pass=" << pass << endl; haveServicePass=true; // Store the new binding info in case of success proto->bserver = proto->currentHost; proto->bshare = optmessage; proto->blogin = ""; proto->bpassword = pass; } return pass; } return 0; //??? } | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/39a40b82a2fc55ed7e977945ed4c332480807109/smb.cc/buggy/kioslave/smb/smb.cc |
user(0), pass(0), service(0), havePass(false), haveServicePass(false) {} | user(0), pass(0), service(0), havePass(false), haveServicePass(false) {} | MyCallback(SmbProtocol *p) : proto(p), user(0), pass(0), service(0), havePass(false), haveServicePass(false) {} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/39a40b82a2fc55ed7e977945ed4c332480807109/smb.cc/buggy/kioslave/smb/smb.cc |
void setPostBody(QCString &inBody) { postMultipartBody = inBody; }; | void setPostBody(QCString &inBody) { postMultipartBody = inBody; contentLength = inBody.length();}; | void setPostBody(QCString &inBody) { postMultipartBody = inBody; }; | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/7f908fd90b627088fba9f47c997ed8ab1ef94ef2/mimeheader.h/clean/kioslave/imap4/mimeheader.h |
ftp.enablePASV( false ); | int check( Connection *_con );extern "C" { void sigalrm_handler(int);}int main( int, char ** ){ signal(SIGCHLD, IOProtocol::sigchld_handler); signal(SIGSEGV, IOProtocol::sigsegv_handler); // KProtocolManager manager; debug( "kio_ftp : Starting"); Connection parent( 0, 1 ); FtpProtocol ftp( &parent ); ftp.dispatchLoop(); debug( "kio_ftp : Done" );}/* * We'll use an alarm that will set this flag when transfer has timed out */char sigbreak = 0;void sigalrm_handler(int){ sigbreak = 1;} void setup_alarm(unsigned int timeout){ sigbreak = 0; alarm(timeout); signal(SIGALRM, sigalrm_handler);}FtpProtocol::FtpProtocol( Connection *_conn ) : IOProtocol( _conn ){ m_cmd = CMD_NONE; m_bIgnoreJobErrors = false; m_bCanResume = true; // most of ftp servers support resuming ?}void FtpProtocol::slotMkdir( const char *_url, int _mode ){ KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file in mkdir command" ); m_cmd = CMD_NONE; return; } // Connect to the ftp server if ( !ftp.isConnected() ) if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } FtpEntry* e = ftp.ftpStat( usrc ); if ( !e ) { if ( !ftp.ftpMkdir( usrc.path() ) ) { error( ERR_COULD_NOT_MKDIR, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } else { // set the desired attributes for dir if ( _mode != -1 ) if ( !ftp.ftpChmod( usrc.path(), _mode ) ) { error( ERR_CANNOT_CHMOD, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } finished(); ftp.ftpDisconnect(); return; } } if ( S_ISDIR( e->type ) ) { // !!! ok ? error( ERR_DOES_ALREADY_EXIST, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } error( ERR_COULD_NOT_MKDIR, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return;}void FtpProtocol::slotCopy( QStringList& _source, const char *_dest ){ doCopy( _source, _dest, false );}void FtpProtocol::slotCopy( const char* _source, const char *_dest ){ QStringList lst; lst.append( _source ); doCopy( lst, _dest, true );}void FtpProtocol::slotMove( QStringList& _source, const char *_dest ){ doCopy( _source, _dest, false, true );}void FtpProtocol::slotMove( const char* _source, const char *_dest ){ QStringList lst; lst.append( _source ); doCopy( lst, _dest, true, true );}void FtpProtocol::doCopy( QStringList& _source, const char *_dest, bool _rename, bool _move ){ if ( _rename ) assert( _source.count() == 1 ); debug( "kio_ftp : Making copy to %s", _dest ); // Check whether the URLs are wellformed QStringList::Iterator soit = _source.begin(); for( ; soit != _source.end(); ++soit ) { qDebug( "kio_ftp : Checking %s", (*soit).ascii() ); KURL usrc( *soit ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, (*soit) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } } qDebug( "kio_ftp : All URLs ok %s", _dest ); // Make a copy of the parameter. if we do IPC calls from here, then we overwrite // our argument. This is tricky! ( but saves memory and speeds things up ) QString dest = _dest; // Check wellformedness of the destination KURL udest( dest ); if ( udest.isMalformed() ) { error( ERR_MALFORMED_URL, dest ); m_cmd = CMD_NONE; return; } debug( "kio_ftp : Dest ok %s", dest.ascii() ); // Find IO server for destination QString exec = KProtocolManager::self().executable( udest.protocol() ); if ( exec.isEmpty() ) { error( ERR_UNSUPPORTED_PROTOCOL, udest.protocol() ); m_cmd = CMD_NONE; return; } // Is the right most protocol a filesystem protocol ? if ( KProtocolManager::self().outputType( udest.protocol() ) != KProtocolManager::T_FILESYSTEM ) { error( ERR_PROTOCOL_IS_NOT_A_FILESYSTEM, udest.protocol() ); m_cmd = CMD_NONE; return; } debug( "kio_ftp : IO server ok %s", dest.ascii() ); // Connect to the ftp server KURL usrc( _source.first() ); if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } // Find out, whether we are logged anonymously or not // Authorization has been already checked with ftp.ftpConnect( usrc ) bool b_user = false; if ( usrc.hasUser() ) b_user = true; // Get a list of all source files and directories QValueList<Copy> files; QValueList<CopyDir> dirs; int size = 0; debug( "kio_ftp : Iterating" ); soit = _source.begin(); debug( "kio_ftp : Looping" ); for( ; soit != _source.end(); ++soit ) { qDebug( "kio_ftp : Executing %s", (*soit).ascii() ); KURL usrc( *soit ); qDebug( "kio_ftp : Parsed URL" ); // Did an error occur ? int s; if ( ( s = listRecursive( usrc.path(), files, dirs, _rename ) ) == -1 ) { ftp.ftpDisconnect(); // Error message is already sent m_cmd = CMD_NONE; return; } // Sum up the total amount of bytes we have to copy size += s; } debug( "kio_ftp : Recursive 1 %s", dest.ascii() ); /* // Check wether we do not copy a directory in itself or one of its subdirectories struct stat buff2; if ( udest.isLocalFile() && stat( udest.path(), &buff2 ) == 0 ) { bool b_error = false; for( soit = _source.begin(); soit != _source.end(); ++soit ) { KURL usrc( *soit ); struct stat buff1; // Can we stat both the source, too ? ( Should always be the case ) if ( stat( usrc.path(), &buff1 ) == 0 ) { bool b_error = false; // Are source and dest equal ? => error if ( buff1.st_ino == buff2.st_ino ) b_error = true; } } if ( !b_error ) { // Iterate over all subdirectories QValueList<CopyDir>::iterator it = dirs.begin(); for( ; it != dirs.end() && !b_error; it++ ) if ( buff2.st_ino == (*it).m_ino ) b_error = true; } // Do we have a cylic copy now ? => error if ( b_error ) { error( ERR_CYCLIC_COPY, *soit ); m_cmd = CMD_NONE; return; } } */ qDebug( "kio_ftp : Recursive ok %s", dest.ascii() ); m_cmd = CMD_GET; // Start a server for the destination protocol Slave slave( exec ); if ( slave.pid() == -1 ) { error( ERR_CANNOT_LAUNCH_PROCESS, exec ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } // Put a protocol on top of the job FtpIOJob job( &slave, this ); qDebug( "kio_ftp : Job started ok %s", dest.ascii() ); // Tell our client what we 'r' gonna do totalSize( size ); totalFiles( files.count() ); totalDirs( dirs.count() ); int processed_files = 0; int processed_dirs = 0; int processed_size = 0; // Replace the relative destinations with absolut destinations // by prepending the destinations path QString tmp1 = udest.path( 1 ); // Strip '/' QString tmp1_stripped = udest.path( -1 ); QValueList<CopyDir>::Iterator dit = dirs.begin(); for( ; dit != dirs.end(); dit++ ) { QString tmp2 = (*dit).m_strRelDest; if ( _rename ) (*dit).m_strRelDest = tmp1_stripped; else (*dit).m_strRelDest = tmp1; (*dit).m_strRelDest += tmp2; } QValueList<Copy>::Iterator fit = files.begin(); for( ; fit != files.end(); fit++ ) { QString tmp2 = (*fit).m_strRelDest; if ( _rename ) // !!! && (*fit).m_strRelDest == "" ) (*fit).m_strRelDest = tmp1_stripped; else (*fit).m_strRelDest = tmp1; (*fit).m_strRelDest += tmp2; } qDebug( "kio_ftp : Destinations ok %s", dest.data() ); /***** * Make directories *****/ m_bIgnoreJobErrors = true; bool overwrite_all = false; bool auto_skip = false; bool resume_all = false; QStringList skip_list, overwrite_list; // Create all directories dit = dirs.begin(); for( ; dit != dirs.end(); dit++ ) { // Repeat until we got no error do { job.clearError(); KURL ud( udest ); ud.setPath( (*dit).m_strRelDest); QString d = ud.url(); // Is this URL on the skip list ? bool skip = false; QStringList::Iterator sit = skip_list.begin(); for( ; sit != skip_list.end() && !skip; sit++ ) // Is d a subdirectory of *sit ? if ( *sit==d ) skip = true; if ( skip ) continue; // Is this URL on the overwrite list ? bool overwrite = false; QStringList::Iterator oit = overwrite_list.begin(); for( ; oit != overwrite_list.end() && !overwrite; oit++ ) if ( *oit == d ) overwrite = true; if ( overwrite ) continue; // Tell what we are doing makingDir( d.data() ); // debug( "kio_ftp : Making remote dir %s", d ); // Create the directory job.mkdir( d.data(), (*dit).m_access ); while( !job.hasFinished() ) job.dispatch(); // Did we have an error ? if ( job.hasError() ) { // Can we prompt the user and ask for a solution ? if ( /* m_bGUI && */ job.errorId() == ERR_DOES_ALREADY_EXIST ) { QString old_path = udest.path( 1 ); QString old_url = udest.url( 1 ); // Should we skip automatically ? if ( auto_skip ) { job.clearError(); // We dont want to copy files in this directory, so we put it on the skip list. skip_list.append( old_url ); continue; } else if ( overwrite_all ) { job.clearError(); continue; } /* RenameDlg_Mode m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE ); if ( dirs.count() > 1 ) m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE ); */ RenameDlg_Mode m = (RenameDlg_Mode)( M_MULTI | M_SKIP | M_OVERWRITE ); QString tmp2 = udest.url(), n; RenameDlg_Result r = open_RenameDlg( (*dit).m_strAbsSource, tmp2, m, n ); if ( r == R_CANCEL ) { ftp.ftpDisconnect(); error( ERR_USER_CANCELED, "" ); m_cmd = CMD_NONE; return; } else if ( r == R_RENAME ) { KURL u( n ); // The Dialog should have checked this. if ( u.isMalformed() ) assert( 0 ); // The new path with trailing '/' QString tmp3 = u.path( 1 ); /////// // Replace old path with tmp3 /////// QValueList<CopyDir>::Iterator dit2 = dit; // Change the current one and strip the trailing '/' (*dit2).m_strRelDest = u.path( -1 ); // Change the name of all subdirectories dit2++; for( ; dit2 != dirs.end(); dit2++ ) if ( strncmp((*dit2).m_strRelDest, old_path, old_path.length())==0 ) (*dit2).m_strRelDest.replace( 0, old_path.length(), tmp3 ); // Change all filenames QValueList<Copy>::Iterator fit2 = files.begin(); for( ; fit2 != files.end(); fit2++ ) if ( strncmp( (*fit2).m_strRelDest, old_path, old_path.length() ) == 0 ) (*fit2).m_strRelDest.replace( 0, old_path.length(), tmp3 ); // Dont clear error => we will repeat the current command } else if ( r == R_SKIP ) { // Skip all files and directories that start with 'old_url' skip_list.append( old_url ); // Clear the error => The current command is not repeated => skipped job.clearError(); } else if ( r == R_AUTO_SKIP ) { // Skip all files and directories that start with 'old_url' skip_list.append( old_url ); // Clear the error => The current command is not repeated => skipped job.clearError(); auto_skip = true; } else if ( r == R_OVERWRITE ) { // Dont bother for subdirectories overwrite_list.append( old_url ); // Clear the error => The current command is not repeated => we will // overwrite every file in this directory or any of its subdirectories job.clearError(); } else if ( r == R_OVERWRITE_ALL ) { job.clearError(); overwrite_all = true; } else assert( 0 ); } // No need to ask the user, so raise an error else { error( job.errorId(), job.errorText() ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } } while( job.hasError() ); processedDirs( ++processed_dirs ); } debug( "kio_ftp : Created directories %s", dest.data() ); /***** * Server check - supports resuming ? *****/ if ( !ftp.ftpResume( 0 ) ) m_bCanResume = false; /***** * Copy files *****/ time_t t_start = time( 0L ); time_t t_last = t_start; fit = files.begin(); for( ; fit != files.end(); fit++ ) { bool overwrite = false; bool skip_copying = false; bool resume = false; unsigned long offset = 0; // Repeat until we got no error do { job.clearError(); KURL ud( dest ); ud.setPath( (*fit).m_strRelDest); QString d = ud.url(); // Is this URL on the skip list ? bool skip = false; QStringList::Iterator sit = skip_list.begin(); for( ; sit != skip_list.end() && !skip; sit++ ) // Is 'd' a file in directory '*sit' or one of its subdirectories ? if ( *sit==d ) skip = true; if ( skip ) continue; // emit sigCanResume( m_bCanResume ) canResume( m_bCanResume ); QString realpath = "ftp:"; realpath += (*fit).m_strAbsSource; copyingFile( realpath.ascii(), d.ascii() ); // debug( "kio_ftp : Writing to %s", d ); // Is this URL on the overwrite list ? QStringList::Iterator oit = overwrite_list.begin(); for( ; oit != overwrite_list.end() && !overwrite; oit++ ) if (*oit==d) overwrite = true; // implicitly set permissions rw-r--r-- for anonymous ftp int md = -1; // but when it's not anonymous ftp, set permissions as in original source if ( b_user ) md = (*fit).m_access; job.put( d, md, overwrite_all || overwrite, resume_all || resume, (*fit).m_size ); while( !job.isReady() && !job.hasFinished() ) job.dispatch(); // Did we have an error ? if ( job.hasError() ) { int currentError = job.errorId(); qDebug("################# COULD NOT PUT %d",currentError); // if ( /* m_bGUI && */ job.errorId() == ERR_WRITE_ACCESS_DENIED ) if ( /* m_bGUI && */ currentError != ERR_DOES_ALREADY_EXIST && currentError != ERR_DOES_ALREADY_EXIST_FULL ) { // Should we skip automatically ? if ( auto_skip ) { job.clearError(); skip_copying = true; continue; } QString tmp2 = ud.url(); SkipDlg_Result r; r = open_SkipDlg( tmp2, ( files.count() > 1 ) ); if ( r == S_CANCEL ) { error( ERR_USER_CANCELED, "" ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } else if ( r == S_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); skip_copying = true; continue; } else if ( r == S_AUTO_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); skip_copying = true; continue; } else assert( 0 ); } // Can we prompt the user and ask for a solution ? else if ( /* m_bGUI && */ currentError == ERR_DOES_ALREADY_EXIST || currentError == ERR_DOES_ALREADY_EXIST_FULL ) { // Should we skip automatically ? if ( auto_skip ) { job.clearError(); continue; } RenameDlg_Result r; QString n; if ( KProtocolManager::self().autoResume() && m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) { r = R_RESUME_ALL; } else { RenameDlg_Mode m; // ask for resume only if transfer can be resumed and if it is not // already fully downloaded if ( files.count() > 1 ){ if ( m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE | M_RESUME); else m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE); } else { if ( m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE | M_RESUME); else m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE); } QString tmp2 = ud.url(); r = open_RenameDlg( (*fit).m_strAbsSource, tmp2, m, n ); } if ( r == R_CANCEL ) { error( ERR_USER_CANCELED, "" ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } else if ( r == R_RENAME ) { KURL u( n ); // The Dialog should have checked this. if ( u.isMalformed() ) assert( 0 ); // Change the destination name of the current file (*fit).m_strRelDest = u.path( -1 ); // Dont clear error => we will repeat the current command } else if ( r == R_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); } else if ( r == R_AUTO_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); auto_skip = true; } else if ( r == R_OVERWRITE ) { overwrite = true; // Dont clear error => we will repeat the current command } else if ( r == R_OVERWRITE_ALL ) { overwrite_all = true; // Dont clear error => we will repeat the current command } else if ( r == R_RESUME ) { resume = true; offset = getOffset( ud.url() ); // Dont clear error => we will repeat the current command } else if ( r == R_RESUME_ALL ) { resume_all = true; offset = getOffset( ud.url() ); // Dont clear error => we will repeat the current command } else assert( 0 ); } // No need to ask the user, so raise an error else { error( currentError, job.errorText() ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } } while( job.hasError() ); if ( skip_copying ) continue; // add the offset to processed size if ( offset > 0 ) { processed_size += offset; debug( "kio_ftp : Offset = %ld", offset ); } KURL tmpurl( "ftp:/" ); tmpurl.setPath( (*fit).m_strAbsSource ); qDebug( "kio_ftp : Opening %s", (*fit).m_strAbsSource.ascii() ); if ( !ftp.ftpOpen( tmpurl, Ftp::READ, offset ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } // we want to know the processed size even before we read something // especially in case we overwrite file => this cleans size to zero processedSize( processed_size ); char buffer[ 4096 ]; int n; int read_size = 0; do { setup_alarm( KProtocolManager::self().readTimeout() ); // start timeout n = ftp.read( buffer, 2048 ); // !!! slow down loop for local testing // for ( int tmpi = 0; tmpi < 1000000; tmpi++ ) ; job.data( buffer, n ); processed_size += n; read_size += n; time_t t = time( 0L ); if ( t - t_last >= 1 ) { processedSize( processed_size ); speed( read_size / ( t - t_start ) ); t_last = t; } // Check parent while ( check( connection() ) ) dispatch(); // Check for error messages from slave while ( check( &slave ) ) job.dispatch(); // An error ? if ( job.hasFinished() ) { ftp.ftpDisconnect(); ftp.ftpClose(); finished(); m_cmd = CMD_NONE; return; } } while ( n > 0 ); job.dataEnd(); ftp.ftpClose(); while( !job.hasFinished() ) job.dispatch(); time_t t = time( 0L ); processedSize( processed_size ); if ( t - t_start >= 1 ) { speed( read_size / ( t - t_start ) ); t_last = t; } processedFiles( ++processed_files ); } debug( "kio_ftp : Copied files %s", dest.data() ); // slotDel() handles disconnecting by itself if ( _move ) { slotDel( _source ); } else ftp.ftpDisconnect(); finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotGet( const char *_url ){ KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file in get command" ); m_cmd = CMD_NONE; return; } if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } FtpEntry *e = ftp.ftpStat( usrc ); if ( !e ) { error( ERR_DOES_NOT_EXIST, strdup(_url) ); m_cmd = CMD_NONE; return; } /* if ( S_ISDIR( e->type ) ) { error( ERR_IS_DIRECTORY, strdup(_url) ); m_cmd = CMD_NONE; return; }*/ m_cmd = CMD_GET; if ( !ftp.open( usrc, Ftp::READ ) ) { error( ERR_CANNOT_OPEN_FOR_READING, strdup(_url) ); m_cmd = CMD_NONE; return; } ready(); gettingFile( _url ); totalSize( e->size ); int processed_size = 0; time_t t_start = time( 0L ); time_t t_last = t_start; char buffer[ 2048 ]; while( !ftp.atEOF() ) { int n = ftp.read( buffer, 2048 ); data( buffer, n ); processed_size += n; time_t t = time( 0L ); if ( t - t_last >= 1 ) { processedSize( processed_size ); speed( processed_size / ( t - t_start ) ); t_last = t; } } dataEnd(); ftp.ftpClose(); processedSize( e->size ); time_t t = time( 0L ); if ( t - t_start >= 1 ) speed( processed_size / ( t - t_start ) ); finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotGetSize( const char* _url ) { m_cmd = CMD_GET_SIZE; // Check wether URL is wellformed KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, _url ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } debug( "kio_ftp : URL is ok " ); if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } // Get a list of all source files and directories QValueList<Copy> files; QValueList<CopyDir> dirs; debug( "kio_ftp : Executing %s", _url ); // Did an error occur ? int s; if ( ( s = listRecursive( usrc.path(), files, dirs, false ) ) == -1 ) { ftp.ftpDisconnect(); // Error message is already sent m_cmd = CMD_NONE; return; } // Tell our client what we 'r' gonna do totalSize( s ); ftp.ftpDisconnect(); finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotPut( const char *_url, int _mode, bool _overwrite, bool _resume, int _size ){ QString url_orig = _url; QString url_part = url_orig + ".part"; ftp.enablePASV( false ); //Simon: disable PASV mode for uploads KURL udest_orig( url_orig ); KURL udest_part( url_part ); bool m_bMarkPartial = KProtocolManager::self().markPartial(); if ( udest_orig.isMalformed() ) { error( ERR_MALFORMED_URL, url_orig ); m_cmd = CMD_NONE; finished(); return; } if ( strcmp( udest_orig.protocol(), "ftp" ) != 0L ) { error(ERR_INTERNAL,"kio_ftp got non ftp file as as destination in put command" ); m_cmd = CMD_NONE; finished(); return; } // Connect to the ftp server, only if we are not connected // this prevents connecting twice in recursive copying ( mkdir connects first time ) if ( !ftp.isConnected() ) if ( !ftp.ftpConnect( udest_orig ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } m_cmd = CMD_PUT; // Find out, whether we are logged anonymously or not // Authorization has been already checked with ftp.ftpConnect( usrc ) bool b_user = false; if ( udest_orig.hasUser() ) b_user = true; FtpEntry* e; if ( ( e = ftp.ftpStat( udest_orig ) ) ) { // if original file exists, but we are using mark partial -> rename it to XXX.part if ( m_bMarkPartial ) ftp.ftpRename( udest_orig.path(), udest_part.path() ); if ( !_overwrite && !_resume ) { if ( e->size == _size ) error( ERR_DOES_ALREADY_EXIST_FULL, udest_orig.path() ); else error( ERR_DOES_ALREADY_EXIST, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } else if ( ( e = ftp.ftpStat( udest_part ) ) ) { // if file with extension .part exists but we are not using mark partial // -> rename XXX.part to original name if ( ! m_bMarkPartial ) ftp.ftpRename( udest_part.path(), udest_orig.path() ); if ( !_overwrite && !_resume ) { if ( e->size == _size ) error( ERR_DOES_ALREADY_EXIST_FULL, udest_orig.path() ); else error( ERR_DOES_ALREADY_EXIST, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } KURL udest; // if we are using marking of partial downloads -> add .part extension if ( m_bMarkPartial ) { debug( "kio_ftp : Adding .part extension to %s", udest_orig.path().ascii() ); udest = udest_part; } else udest = udest_orig; /* if ( access( udest.path(), W_OK ) == -1 ) { debug("Write Access denied for '%s' %d",udest.path(), errno ); error( ERR_WRITE_ACCESS_DENIED, url ); m_cmd = CMD_NONE; finished(); return; } */ unsigned long offset = 0; // set the mode according to offset if ( _resume ) { offset = e->size; debug( "kio_ftp : Offset = %ld", offset ); } if ( !ftp.ftpOpen( udest, Ftp::WRITE, offset ) ) { debug( "kio_ftp : ####################### COULD NOT WRITE %s", udest.path().ascii() ); error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } // We are ready for receiving data ready(); // Loop until we got 'dataEnd' while ( m_cmd == CMD_PUT && dispatch() ); ftp.ftpClose(); ftp.ftpDisconnect( true ); if ( (e = ftp.ftpStat( udest )) ) { if ( e->size == _size ) { // after full download rename the file back to original name if ( m_bMarkPartial ) { cerr << "kio_ftp renaming\n"; if ( !ftp.ftpRename( udest.path(), udest_orig.path() ) ) { error( ERR_CANNOT_RENAME, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } // do chmod only after full download if ( _mode != -1 ) { cerr << "kio_ftp chmoding\n"; // set the desired attributes for dir !!! how ? if ( !ftp.ftpChmod( udest_orig.path(), _mode ) ) { error( ERR_CANNOT_CHMOD, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } } // if the size is less then minimum -> delete the file else if ( e->size < KProtocolManager::self().minimumKeepSize() ) { ftp.ftpDelete( udest.path() ); } } ftp.ftpDisconnect( true ); ftp.enablePASV( true ); // We have done our job => finish finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotDel( QStringList& _source ){ // Check wether the URLs are wellformed QStringList::Iterator soit = _source.begin(); for( ; soit != _source.end(); ++soit ) { debug( "kio_ftp : Checking %s", (*soit).ascii() ); KURL usrc( *soit ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, *soit); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error(ERR_INTERNAL,"kio_ftp got non ftp file for delete command" ); m_cmd = CMD_NONE; return; } } qDebug( "kio_ftp : All URLs ok" ); // Get a list of all source files and directories QValueList<Copy> fs; QValueList<CopyDir> ds; int size = 0; qDebug( "kio_ftp : Iterating" ); soit = _source.begin(); qDebug( "kio_ftp : Looping" ); for( ; soit != _source.end(); ++soit ) { qDebug( "kio_ftp : Executing %s", (*soit).ascii() ); KURL usrc(*soit); qDebug( "kio_ftp : Parsed URL" ); // Did an error occur ?// int s;// if ( ( s = listRecursive( usrc.path(), fs, ds, false ) ) == -1 )// {// // Error message is already sent// ftp.ftpDisconnect();// m_cmd = CMD_NONE;// return;// } // Sum up the total amount of bytes we have to copy// size += s; } qDebug( "kio_ftp : Recursive ok" ); if ( fs.count() == 1 ) m_cmd = CMD_DEL; else m_cmd = CMD_MDEL; // Tell our client what we 'r' gonna do totalSize( size ); totalFiles( fs.count() ); totalDirs( ds.count() ); /***** * Delete files *****/ QValueList<Copy>::Iterator fit = fs.begin(); for( ; fit != fs.end(); fit++ ) { QString filename = (*fit).m_strAbsSource; qDebug( "kio_ftp : Deleting file %s", filename.ascii() ); deletingFile( filename ); if ( !ftp.ftpDelete( filename ) ) // !!! use unlink ? { error( ERR_CANNOT_DELETE, filename ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } /***** * Delete empty directories *****/ QValueList<CopyDir>::Iterator dit = ds.begin(); for( ; dit != ds.end(); dit++ ) { QString dirname = (*dit).m_strAbsSource; qDebug( "kio_ftp : Deleting directory %s", dirname.ascii() ); deletingFile( dirname ); if ( !ftp.ftpRmdir( dirname ) ) { error( ERR_COULD_NOT_RMDIR, dirname ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotData( void *_p, int _len ){ switch( m_cmd ) { case CMD_PUT: ftp.write( _p, _len ); break; }}void FtpProtocol::slotDataEnd(){ switch( m_cmd ) { case CMD_PUT: m_cmd = CMD_NONE; }}long FtpProtocol::listRecursive( const char *_path, QValueList<Copy>& _files, QValueList<CopyDir>& _dirs, bool _rename ){ m_bAutoSkip = false; // Check wether we have to copy the complete directory tree beginning by its root. int len = strlen( _path ); while( len >= 1 && _path[ len - 1 ] == '/' ) len--; if ( len == 0 ) { CopyDir c; c.m_strAbsSource = _path; if ( _rename ) c.m_strRelDest = ""; else c.m_strRelDest = ""; c.m_access = S_IRWXU | S_IRWXO | S_IRWXG; c.m_type = S_IFDIR; _dirs.append( c ); return listRecursive2( "/", c.m_strRelDest, _files, _dirs ); } QString p=_path; qDebug( "kio_ftp : ########## RECURSIVE LISTING %s", p.ascii() ); KURL tmpurl( "ftp:/" ); tmpurl.setPath( p ); FtpEntry* e = ftp.ftpStat( tmpurl ); if ( !e ) { error( ERR_DOES_NOT_EXIST, p); return -1; } KURL u( p ); // Should be checked before, but who knows if ( u.isMalformed() ) assert( 0 ); // Is the source not a directory ? => so just copy it and we are done. if ( !S_ISDIR( e->type ) ) { qDebug( "kio_ftp : not a dir" ); QString fname; if ( _rename ) fname = ""; else { fname = u.filename(); // Should be impossible, but who knows ... if ( fname.isEmpty() ) assert( 0 ); } Copy c; c.m_strAbsSource = p; c.m_strRelDest = fname; c.m_access = e->access; c.m_type = e->type; c.m_size = e->size; _files.append( c ); return e->size; } // The source is a directory. So we have to go into recursion here. QString tmp1; if ( _rename ) tmp1 = u.path( 0 ); else { tmp1 = u.directory( true ); tmp1 += "/"; } QString tmp2; if ( _rename ) tmp2 = ""; else tmp2 = u.filename(); CopyDir c; c.m_strAbsSource = p; c.m_strRelDest = tmp2; c.m_access = e->access; c.m_type = e->type; _dirs.append( c ); qDebug( "kio_ftp : ########### STARTING RECURSION with %s and %s",tmp1.ascii(), tmp2.ascii() ); return listRecursive2( tmp1, tmp2, _files, _dirs );}long FtpProtocol::listRecursive2( const char *_abs_path, const char *_rel_path, QValueList<Copy>& _files, QValueList<CopyDir>& _dirs ){ long size = 0; cerr << "listRecursive2 " << _abs_path << " " << _rel_path << endl; QString p = _abs_path; p += _rel_path; scanningDir( p ); KURL tmpurl( "ftp:/" ); tmpurl.setPath( p ); if ( !ftp.ftpOpenDir( tmpurl ) ) { if ( m_bAutoSkip ) return 0; SkipDlg_Result result = open_SkipDlg( p, true ); if ( result == S_CANCEL ) { // error( ERR_CANNOT_ENTER_DIRECTORY, p ); return -1; } else if ( result == S_AUTO_SKIP ) m_bAutoSkip = true; return 0; } QStringList recursion; qDebug( "kio_ftp : ##Listing" ); FtpEntry *e; while ( ( e = ftp.readdir() ) != 0L ) { qDebug( "kio_ftp : #%s", e->name.ascii() ); if ( e->name == "." || e->name == ".." ) continue; QString p2 = p; p2 += "/"; p2 += e->name; QString tmp = _rel_path; tmp += "/"; tmp += e->name; if ( !S_ISDIR( e->type ) ) { qDebug( "kio_ftp : Appending '%s' '%s'", p2.ascii(), tmp.ascii() ); Copy c; c.m_strAbsSource = p2; c.m_strRelDest = tmp; c.m_access = e->access; c.m_type = e->type; c.m_size = e->size; _files.append( c ); size += e->size; } else { CopyDir c; c.m_strAbsSource = p2; c.m_strRelDest = tmp; c.m_access = e->access; c.m_type = e->type; _dirs.append( c ); recursion.append( tmp ); } } if ( !ftp.ftpCloseDir() ) { // error( ERR_COULD_NOT_CLOSEDIR, p ); return -1; } QStringList::Iterator it = recursion.begin(); for( ; it != recursion.end(); ++it ) { long s; if ( ( s = listRecursive2( _abs_path, (*it).ascii(), _files, _dirs ) ) == -1 ) return -1; size += s; } return size;}void FtpProtocol::slotListDir( const char *_url ){ qDebug( "kio_ftp : =============== LIST %s ===============", _url ); KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } /* struct stat buff; if ( stat( usrc.path(), &buff ) == -1 ) { error( ERR_DOES_NOT_EXIST, url); m_cmd = CMD_NONE; return; } if ( !S_ISDIR( buff.st_mode ) ) { error( ERR_IS_FILE, url ); m_cmd = CMD_NONE; return; } */ m_cmd = CMD_LIST; if ( !ftp.opendir( usrc ) ) { error( ERR_CANNOT_ENTER_DIRECTORY, strdup(_url) ); m_cmd = CMD_NONE; return; } FtpEntry* e; while ( ( e = ftp.readdir() ) ) { if ( e->name == "." || e->name == ".." ) continue; debug( "kio_ftp : Listing %s", e->name.ascii() ); UDSEntry entry; UDSAtom atom; atom.m_uds = UDS_NAME; atom.m_str = e->name; entry.append( atom ); atom.m_uds = UDS_FILE_TYPE; atom.m_long = e->type; entry.append( atom ); atom.m_uds = UDS_SIZE; atom.m_long = e->size; entry.append( atom ); /* atom.m_uds = UDS_MODIFICATION_TIME; atom.m_long = buff.st_mtime; entry.append( atom ); */ atom.m_uds = UDS_ACCESS; atom.m_long = e->access; entry.append( atom ); atom.m_uds = UDS_USER; atom.m_str = e->owner; entry.append( atom ); atom.m_uds = UDS_GROUP; atom.m_str = e->group; entry.append( atom ); atom.m_uds = UDS_LINK_DEST; atom.m_str = e->link; entry.append( atom ); /* atom.m_uds = UDS_ACCESS_TIME; atom.m_long = buff.st_atime; entry.append( atom ); atom.m_uds = UDS_CREATION_TIME; atom.m_long = buff.st_ctime; entry.append( atom ); */ listEntry( entry ); } debug( "kio_ftp : ============= COMPLETED LIST ============" ); ftp.closedir(); debug( "kio_ftp : ============= COMPLETED LIST 2 ============" ); m_cmd = CMD_NONE; finished(); debug( "kio_ftp : =============== BYE ===========" );}void FtpProtocol::slotTestDir( const char *_url ){ KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } qDebug( "kio_ftp : =============== slotTestDir ==============" ); FtpEntry* e; if ( !( e = ftp.stat( usrc ) ) ) { debug( "kio_ftp : =========== ERROR ========" ); error( ERR_DOES_NOT_EXIST, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( S_ISDIR( e->type ) ) { qDebug( "kio_ftp : ========== DONE DIR ========= %s", _url ); isDirectory(); } else { qDebug( "kio_ftp : ========== DONE FILE ========= %s", _url ); isFile(); } finished();}void FtpProtocol::jobError( int _errid, const char *_txt ){ if ( !m_bIgnoreJobErrors ) error( _errid, _txt );}/************************************* * * FtpIOJob * *************************************/FtpIOJob::FtpIOJob( Connection *_conn, FtpProtocol *_Ftp ) : IOJob( _conn ){ m_pFtp = _Ftp;} void FtpIOJob::slotError( int _errid, const char *_txt ){ IOJob::slotError( _errid, _txt ); m_pFtp->jobError( _errid, _txt );}/************************************* * * Utilities * *************************************/int check( Connection *_con ){ int err; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; fd_set rfds; FD_ZERO( &rfds ); FD_SET( _con->inFD(), &rfds ); again: if ( ( err = select( _con->inFD(), &rfds, 0L, 0L, &tv ) ) == -1 && errno == EINTR ) goto again; // No error and something to read ? if ( err != -1 && err != 0 ) return 1; return 0;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/747850cee3cebb60d93bead6d4b7dbc056285a51/main.cc/buggy/kioslave/ftp/main.cc |
|
ftp.enablePASV( true ); | int check( Connection *_con );extern "C" { void sigalrm_handler(int);}int main( int, char ** ){ signal(SIGCHLD, IOProtocol::sigchld_handler); signal(SIGSEGV, IOProtocol::sigsegv_handler); // KProtocolManager manager; debug( "kio_ftp : Starting"); Connection parent( 0, 1 ); FtpProtocol ftp( &parent ); ftp.dispatchLoop(); debug( "kio_ftp : Done" );}/* * We'll use an alarm that will set this flag when transfer has timed out */char sigbreak = 0;void sigalrm_handler(int){ sigbreak = 1;} void setup_alarm(unsigned int timeout){ sigbreak = 0; alarm(timeout); signal(SIGALRM, sigalrm_handler);}FtpProtocol::FtpProtocol( Connection *_conn ) : IOProtocol( _conn ){ m_cmd = CMD_NONE; m_bIgnoreJobErrors = false; m_bCanResume = true; // most of ftp servers support resuming ?}void FtpProtocol::slotMkdir( const char *_url, int _mode ){ KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file in mkdir command" ); m_cmd = CMD_NONE; return; } // Connect to the ftp server if ( !ftp.isConnected() ) if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } FtpEntry* e = ftp.ftpStat( usrc ); if ( !e ) { if ( !ftp.ftpMkdir( usrc.path() ) ) { error( ERR_COULD_NOT_MKDIR, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } else { // set the desired attributes for dir if ( _mode != -1 ) if ( !ftp.ftpChmod( usrc.path(), _mode ) ) { error( ERR_CANNOT_CHMOD, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } finished(); ftp.ftpDisconnect(); return; } } if ( S_ISDIR( e->type ) ) { // !!! ok ? error( ERR_DOES_ALREADY_EXIST, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } error( ERR_COULD_NOT_MKDIR, strdup(_url) ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return;}void FtpProtocol::slotCopy( QStringList& _source, const char *_dest ){ doCopy( _source, _dest, false );}void FtpProtocol::slotCopy( const char* _source, const char *_dest ){ QStringList lst; lst.append( _source ); doCopy( lst, _dest, true );}void FtpProtocol::slotMove( QStringList& _source, const char *_dest ){ doCopy( _source, _dest, false, true );}void FtpProtocol::slotMove( const char* _source, const char *_dest ){ QStringList lst; lst.append( _source ); doCopy( lst, _dest, true, true );}void FtpProtocol::doCopy( QStringList& _source, const char *_dest, bool _rename, bool _move ){ if ( _rename ) assert( _source.count() == 1 ); debug( "kio_ftp : Making copy to %s", _dest ); // Check whether the URLs are wellformed QStringList::Iterator soit = _source.begin(); for( ; soit != _source.end(); ++soit ) { qDebug( "kio_ftp : Checking %s", (*soit).ascii() ); KURL usrc( *soit ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, (*soit) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } } qDebug( "kio_ftp : All URLs ok %s", _dest ); // Make a copy of the parameter. if we do IPC calls from here, then we overwrite // our argument. This is tricky! ( but saves memory and speeds things up ) QString dest = _dest; // Check wellformedness of the destination KURL udest( dest ); if ( udest.isMalformed() ) { error( ERR_MALFORMED_URL, dest ); m_cmd = CMD_NONE; return; } debug( "kio_ftp : Dest ok %s", dest.ascii() ); // Find IO server for destination QString exec = KProtocolManager::self().executable( udest.protocol() ); if ( exec.isEmpty() ) { error( ERR_UNSUPPORTED_PROTOCOL, udest.protocol() ); m_cmd = CMD_NONE; return; } // Is the right most protocol a filesystem protocol ? if ( KProtocolManager::self().outputType( udest.protocol() ) != KProtocolManager::T_FILESYSTEM ) { error( ERR_PROTOCOL_IS_NOT_A_FILESYSTEM, udest.protocol() ); m_cmd = CMD_NONE; return; } debug( "kio_ftp : IO server ok %s", dest.ascii() ); // Connect to the ftp server KURL usrc( _source.first() ); if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } // Find out, whether we are logged anonymously or not // Authorization has been already checked with ftp.ftpConnect( usrc ) bool b_user = false; if ( usrc.hasUser() ) b_user = true; // Get a list of all source files and directories QValueList<Copy> files; QValueList<CopyDir> dirs; int size = 0; debug( "kio_ftp : Iterating" ); soit = _source.begin(); debug( "kio_ftp : Looping" ); for( ; soit != _source.end(); ++soit ) { qDebug( "kio_ftp : Executing %s", (*soit).ascii() ); KURL usrc( *soit ); qDebug( "kio_ftp : Parsed URL" ); // Did an error occur ? int s; if ( ( s = listRecursive( usrc.path(), files, dirs, _rename ) ) == -1 ) { ftp.ftpDisconnect(); // Error message is already sent m_cmd = CMD_NONE; return; } // Sum up the total amount of bytes we have to copy size += s; } debug( "kio_ftp : Recursive 1 %s", dest.ascii() ); /* // Check wether we do not copy a directory in itself or one of its subdirectories struct stat buff2; if ( udest.isLocalFile() && stat( udest.path(), &buff2 ) == 0 ) { bool b_error = false; for( soit = _source.begin(); soit != _source.end(); ++soit ) { KURL usrc( *soit ); struct stat buff1; // Can we stat both the source, too ? ( Should always be the case ) if ( stat( usrc.path(), &buff1 ) == 0 ) { bool b_error = false; // Are source and dest equal ? => error if ( buff1.st_ino == buff2.st_ino ) b_error = true; } } if ( !b_error ) { // Iterate over all subdirectories QValueList<CopyDir>::iterator it = dirs.begin(); for( ; it != dirs.end() && !b_error; it++ ) if ( buff2.st_ino == (*it).m_ino ) b_error = true; } // Do we have a cylic copy now ? => error if ( b_error ) { error( ERR_CYCLIC_COPY, *soit ); m_cmd = CMD_NONE; return; } } */ qDebug( "kio_ftp : Recursive ok %s", dest.ascii() ); m_cmd = CMD_GET; // Start a server for the destination protocol Slave slave( exec ); if ( slave.pid() == -1 ) { error( ERR_CANNOT_LAUNCH_PROCESS, exec ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } // Put a protocol on top of the job FtpIOJob job( &slave, this ); qDebug( "kio_ftp : Job started ok %s", dest.ascii() ); // Tell our client what we 'r' gonna do totalSize( size ); totalFiles( files.count() ); totalDirs( dirs.count() ); int processed_files = 0; int processed_dirs = 0; int processed_size = 0; // Replace the relative destinations with absolut destinations // by prepending the destinations path QString tmp1 = udest.path( 1 ); // Strip '/' QString tmp1_stripped = udest.path( -1 ); QValueList<CopyDir>::Iterator dit = dirs.begin(); for( ; dit != dirs.end(); dit++ ) { QString tmp2 = (*dit).m_strRelDest; if ( _rename ) (*dit).m_strRelDest = tmp1_stripped; else (*dit).m_strRelDest = tmp1; (*dit).m_strRelDest += tmp2; } QValueList<Copy>::Iterator fit = files.begin(); for( ; fit != files.end(); fit++ ) { QString tmp2 = (*fit).m_strRelDest; if ( _rename ) // !!! && (*fit).m_strRelDest == "" ) (*fit).m_strRelDest = tmp1_stripped; else (*fit).m_strRelDest = tmp1; (*fit).m_strRelDest += tmp2; } qDebug( "kio_ftp : Destinations ok %s", dest.data() ); /***** * Make directories *****/ m_bIgnoreJobErrors = true; bool overwrite_all = false; bool auto_skip = false; bool resume_all = false; QStringList skip_list, overwrite_list; // Create all directories dit = dirs.begin(); for( ; dit != dirs.end(); dit++ ) { // Repeat until we got no error do { job.clearError(); KURL ud( udest ); ud.setPath( (*dit).m_strRelDest); QString d = ud.url(); // Is this URL on the skip list ? bool skip = false; QStringList::Iterator sit = skip_list.begin(); for( ; sit != skip_list.end() && !skip; sit++ ) // Is d a subdirectory of *sit ? if ( *sit==d ) skip = true; if ( skip ) continue; // Is this URL on the overwrite list ? bool overwrite = false; QStringList::Iterator oit = overwrite_list.begin(); for( ; oit != overwrite_list.end() && !overwrite; oit++ ) if ( *oit == d ) overwrite = true; if ( overwrite ) continue; // Tell what we are doing makingDir( d.data() ); // debug( "kio_ftp : Making remote dir %s", d ); // Create the directory job.mkdir( d.data(), (*dit).m_access ); while( !job.hasFinished() ) job.dispatch(); // Did we have an error ? if ( job.hasError() ) { // Can we prompt the user and ask for a solution ? if ( /* m_bGUI && */ job.errorId() == ERR_DOES_ALREADY_EXIST ) { QString old_path = udest.path( 1 ); QString old_url = udest.url( 1 ); // Should we skip automatically ? if ( auto_skip ) { job.clearError(); // We dont want to copy files in this directory, so we put it on the skip list. skip_list.append( old_url ); continue; } else if ( overwrite_all ) { job.clearError(); continue; } /* RenameDlg_Mode m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE ); if ( dirs.count() > 1 ) m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE ); */ RenameDlg_Mode m = (RenameDlg_Mode)( M_MULTI | M_SKIP | M_OVERWRITE ); QString tmp2 = udest.url(), n; RenameDlg_Result r = open_RenameDlg( (*dit).m_strAbsSource, tmp2, m, n ); if ( r == R_CANCEL ) { ftp.ftpDisconnect(); error( ERR_USER_CANCELED, "" ); m_cmd = CMD_NONE; return; } else if ( r == R_RENAME ) { KURL u( n ); // The Dialog should have checked this. if ( u.isMalformed() ) assert( 0 ); // The new path with trailing '/' QString tmp3 = u.path( 1 ); /////// // Replace old path with tmp3 /////// QValueList<CopyDir>::Iterator dit2 = dit; // Change the current one and strip the trailing '/' (*dit2).m_strRelDest = u.path( -1 ); // Change the name of all subdirectories dit2++; for( ; dit2 != dirs.end(); dit2++ ) if ( strncmp((*dit2).m_strRelDest, old_path, old_path.length())==0 ) (*dit2).m_strRelDest.replace( 0, old_path.length(), tmp3 ); // Change all filenames QValueList<Copy>::Iterator fit2 = files.begin(); for( ; fit2 != files.end(); fit2++ ) if ( strncmp( (*fit2).m_strRelDest, old_path, old_path.length() ) == 0 ) (*fit2).m_strRelDest.replace( 0, old_path.length(), tmp3 ); // Dont clear error => we will repeat the current command } else if ( r == R_SKIP ) { // Skip all files and directories that start with 'old_url' skip_list.append( old_url ); // Clear the error => The current command is not repeated => skipped job.clearError(); } else if ( r == R_AUTO_SKIP ) { // Skip all files and directories that start with 'old_url' skip_list.append( old_url ); // Clear the error => The current command is not repeated => skipped job.clearError(); auto_skip = true; } else if ( r == R_OVERWRITE ) { // Dont bother for subdirectories overwrite_list.append( old_url ); // Clear the error => The current command is not repeated => we will // overwrite every file in this directory or any of its subdirectories job.clearError(); } else if ( r == R_OVERWRITE_ALL ) { job.clearError(); overwrite_all = true; } else assert( 0 ); } // No need to ask the user, so raise an error else { error( job.errorId(), job.errorText() ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } } while( job.hasError() ); processedDirs( ++processed_dirs ); } debug( "kio_ftp : Created directories %s", dest.data() ); /***** * Server check - supports resuming ? *****/ if ( !ftp.ftpResume( 0 ) ) m_bCanResume = false; /***** * Copy files *****/ time_t t_start = time( 0L ); time_t t_last = t_start; fit = files.begin(); for( ; fit != files.end(); fit++ ) { bool overwrite = false; bool skip_copying = false; bool resume = false; unsigned long offset = 0; // Repeat until we got no error do { job.clearError(); KURL ud( dest ); ud.setPath( (*fit).m_strRelDest); QString d = ud.url(); // Is this URL on the skip list ? bool skip = false; QStringList::Iterator sit = skip_list.begin(); for( ; sit != skip_list.end() && !skip; sit++ ) // Is 'd' a file in directory '*sit' or one of its subdirectories ? if ( *sit==d ) skip = true; if ( skip ) continue; // emit sigCanResume( m_bCanResume ) canResume( m_bCanResume ); QString realpath = "ftp:"; realpath += (*fit).m_strAbsSource; copyingFile( realpath.ascii(), d.ascii() ); // debug( "kio_ftp : Writing to %s", d ); // Is this URL on the overwrite list ? QStringList::Iterator oit = overwrite_list.begin(); for( ; oit != overwrite_list.end() && !overwrite; oit++ ) if (*oit==d) overwrite = true; // implicitly set permissions rw-r--r-- for anonymous ftp int md = -1; // but when it's not anonymous ftp, set permissions as in original source if ( b_user ) md = (*fit).m_access; job.put( d, md, overwrite_all || overwrite, resume_all || resume, (*fit).m_size ); while( !job.isReady() && !job.hasFinished() ) job.dispatch(); // Did we have an error ? if ( job.hasError() ) { int currentError = job.errorId(); qDebug("################# COULD NOT PUT %d",currentError); // if ( /* m_bGUI && */ job.errorId() == ERR_WRITE_ACCESS_DENIED ) if ( /* m_bGUI && */ currentError != ERR_DOES_ALREADY_EXIST && currentError != ERR_DOES_ALREADY_EXIST_FULL ) { // Should we skip automatically ? if ( auto_skip ) { job.clearError(); skip_copying = true; continue; } QString tmp2 = ud.url(); SkipDlg_Result r; r = open_SkipDlg( tmp2, ( files.count() > 1 ) ); if ( r == S_CANCEL ) { error( ERR_USER_CANCELED, "" ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } else if ( r == S_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); skip_copying = true; continue; } else if ( r == S_AUTO_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); skip_copying = true; continue; } else assert( 0 ); } // Can we prompt the user and ask for a solution ? else if ( /* m_bGUI && */ currentError == ERR_DOES_ALREADY_EXIST || currentError == ERR_DOES_ALREADY_EXIST_FULL ) { // Should we skip automatically ? if ( auto_skip ) { job.clearError(); continue; } RenameDlg_Result r; QString n; if ( KProtocolManager::self().autoResume() && m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) { r = R_RESUME_ALL; } else { RenameDlg_Mode m; // ask for resume only if transfer can be resumed and if it is not // already fully downloaded if ( files.count() > 1 ){ if ( m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE | M_RESUME); else m = (RenameDlg_Mode)(M_MULTI | M_SKIP | M_OVERWRITE); } else { if ( m_bCanResume && currentError != ERR_DOES_ALREADY_EXIST_FULL ) m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE | M_RESUME); else m = (RenameDlg_Mode)( M_SINGLE | M_OVERWRITE); } QString tmp2 = ud.url(); r = open_RenameDlg( (*fit).m_strAbsSource, tmp2, m, n ); } if ( r == R_CANCEL ) { error( ERR_USER_CANCELED, "" ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } else if ( r == R_RENAME ) { KURL u( n ); // The Dialog should have checked this. if ( u.isMalformed() ) assert( 0 ); // Change the destination name of the current file (*fit).m_strRelDest = u.path( -1 ); // Dont clear error => we will repeat the current command } else if ( r == R_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); } else if ( r == R_AUTO_SKIP ) { // Clear the error => The current command is not repeated => skipped job.clearError(); auto_skip = true; } else if ( r == R_OVERWRITE ) { overwrite = true; // Dont clear error => we will repeat the current command } else if ( r == R_OVERWRITE_ALL ) { overwrite_all = true; // Dont clear error => we will repeat the current command } else if ( r == R_RESUME ) { resume = true; offset = getOffset( ud.url() ); // Dont clear error => we will repeat the current command } else if ( r == R_RESUME_ALL ) { resume_all = true; offset = getOffset( ud.url() ); // Dont clear error => we will repeat the current command } else assert( 0 ); } // No need to ask the user, so raise an error else { error( currentError, job.errorText() ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } } while( job.hasError() ); if ( skip_copying ) continue; // add the offset to processed size if ( offset > 0 ) { processed_size += offset; debug( "kio_ftp : Offset = %ld", offset ); } KURL tmpurl( "ftp:/" ); tmpurl.setPath( (*fit).m_strAbsSource ); qDebug( "kio_ftp : Opening %s", (*fit).m_strAbsSource.ascii() ); if ( !ftp.ftpOpen( tmpurl, Ftp::READ, offset ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } // we want to know the processed size even before we read something // especially in case we overwrite file => this cleans size to zero processedSize( processed_size ); char buffer[ 4096 ]; int n; int read_size = 0; do { setup_alarm( KProtocolManager::self().readTimeout() ); // start timeout n = ftp.read( buffer, 2048 ); // !!! slow down loop for local testing // for ( int tmpi = 0; tmpi < 1000000; tmpi++ ) ; job.data( buffer, n ); processed_size += n; read_size += n; time_t t = time( 0L ); if ( t - t_last >= 1 ) { processedSize( processed_size ); speed( read_size / ( t - t_start ) ); t_last = t; } // Check parent while ( check( connection() ) ) dispatch(); // Check for error messages from slave while ( check( &slave ) ) job.dispatch(); // An error ? if ( job.hasFinished() ) { ftp.ftpDisconnect(); ftp.ftpClose(); finished(); m_cmd = CMD_NONE; return; } } while ( n > 0 ); job.dataEnd(); ftp.ftpClose(); while( !job.hasFinished() ) job.dispatch(); time_t t = time( 0L ); processedSize( processed_size ); if ( t - t_start >= 1 ) { speed( read_size / ( t - t_start ) ); t_last = t; } processedFiles( ++processed_files ); } debug( "kio_ftp : Copied files %s", dest.data() ); // slotDel() handles disconnecting by itself if ( _move ) { slotDel( _source ); } else ftp.ftpDisconnect(); finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotGet( const char *_url ){ KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file in get command" ); m_cmd = CMD_NONE; return; } if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } FtpEntry *e = ftp.ftpStat( usrc ); if ( !e ) { error( ERR_DOES_NOT_EXIST, strdup(_url) ); m_cmd = CMD_NONE; return; } /* if ( S_ISDIR( e->type ) ) { error( ERR_IS_DIRECTORY, strdup(_url) ); m_cmd = CMD_NONE; return; }*/ m_cmd = CMD_GET; if ( !ftp.open( usrc, Ftp::READ ) ) { error( ERR_CANNOT_OPEN_FOR_READING, strdup(_url) ); m_cmd = CMD_NONE; return; } ready(); gettingFile( _url ); totalSize( e->size ); int processed_size = 0; time_t t_start = time( 0L ); time_t t_last = t_start; char buffer[ 2048 ]; while( !ftp.atEOF() ) { int n = ftp.read( buffer, 2048 ); data( buffer, n ); processed_size += n; time_t t = time( 0L ); if ( t - t_last >= 1 ) { processedSize( processed_size ); speed( processed_size / ( t - t_start ) ); t_last = t; } } dataEnd(); ftp.ftpClose(); processedSize( e->size ); time_t t = time( 0L ); if ( t - t_start >= 1 ) speed( processed_size / ( t - t_start ) ); finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotGetSize( const char* _url ) { m_cmd = CMD_GET_SIZE; // Check wether URL is wellformed KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, _url ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } debug( "kio_ftp : URL is ok " ); if ( !ftp.ftpConnect( usrc ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; return; } // Get a list of all source files and directories QValueList<Copy> files; QValueList<CopyDir> dirs; debug( "kio_ftp : Executing %s", _url ); // Did an error occur ? int s; if ( ( s = listRecursive( usrc.path(), files, dirs, false ) ) == -1 ) { ftp.ftpDisconnect(); // Error message is already sent m_cmd = CMD_NONE; return; } // Tell our client what we 'r' gonna do totalSize( s ); ftp.ftpDisconnect(); finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotPut( const char *_url, int _mode, bool _overwrite, bool _resume, int _size ){ QString url_orig = _url; QString url_part = url_orig + ".part"; ftp.enablePASV( false ); //Simon: disable PASV mode for uploads KURL udest_orig( url_orig ); KURL udest_part( url_part ); bool m_bMarkPartial = KProtocolManager::self().markPartial(); if ( udest_orig.isMalformed() ) { error( ERR_MALFORMED_URL, url_orig ); m_cmd = CMD_NONE; finished(); return; } if ( strcmp( udest_orig.protocol(), "ftp" ) != 0L ) { error(ERR_INTERNAL,"kio_ftp got non ftp file as as destination in put command" ); m_cmd = CMD_NONE; finished(); return; } // Connect to the ftp server, only if we are not connected // this prevents connecting twice in recursive copying ( mkdir connects first time ) if ( !ftp.isConnected() ) if ( !ftp.ftpConnect( udest_orig ) ) { error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } m_cmd = CMD_PUT; // Find out, whether we are logged anonymously or not // Authorization has been already checked with ftp.ftpConnect( usrc ) bool b_user = false; if ( udest_orig.hasUser() ) b_user = true; FtpEntry* e; if ( ( e = ftp.ftpStat( udest_orig ) ) ) { // if original file exists, but we are using mark partial -> rename it to XXX.part if ( m_bMarkPartial ) ftp.ftpRename( udest_orig.path(), udest_part.path() ); if ( !_overwrite && !_resume ) { if ( e->size == _size ) error( ERR_DOES_ALREADY_EXIST_FULL, udest_orig.path() ); else error( ERR_DOES_ALREADY_EXIST, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } else if ( ( e = ftp.ftpStat( udest_part ) ) ) { // if file with extension .part exists but we are not using mark partial // -> rename XXX.part to original name if ( ! m_bMarkPartial ) ftp.ftpRename( udest_part.path(), udest_orig.path() ); if ( !_overwrite && !_resume ) { if ( e->size == _size ) error( ERR_DOES_ALREADY_EXIST_FULL, udest_orig.path() ); else error( ERR_DOES_ALREADY_EXIST, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } KURL udest; // if we are using marking of partial downloads -> add .part extension if ( m_bMarkPartial ) { debug( "kio_ftp : Adding .part extension to %s", udest_orig.path().ascii() ); udest = udest_part; } else udest = udest_orig; /* if ( access( udest.path(), W_OK ) == -1 ) { debug("Write Access denied for '%s' %d",udest.path(), errno ); error( ERR_WRITE_ACCESS_DENIED, url ); m_cmd = CMD_NONE; finished(); return; } */ unsigned long offset = 0; // set the mode according to offset if ( _resume ) { offset = e->size; debug( "kio_ftp : Offset = %ld", offset ); } if ( !ftp.ftpOpen( udest, Ftp::WRITE, offset ) ) { debug( "kio_ftp : ####################### COULD NOT WRITE %s", udest.path().ascii() ); error( ftp.error(), ftp.errorText() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } // We are ready for receiving data ready(); // Loop until we got 'dataEnd' while ( m_cmd == CMD_PUT && dispatch() ); ftp.ftpClose(); ftp.ftpDisconnect( true ); if ( (e = ftp.ftpStat( udest )) ) { if ( e->size == _size ) { // after full download rename the file back to original name if ( m_bMarkPartial ) { cerr << "kio_ftp renaming\n"; if ( !ftp.ftpRename( udest.path(), udest_orig.path() ) ) { error( ERR_CANNOT_RENAME, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } // do chmod only after full download if ( _mode != -1 ) { cerr << "kio_ftp chmoding\n"; // set the desired attributes for dir !!! how ? if ( !ftp.ftpChmod( udest_orig.path(), _mode ) ) { error( ERR_CANNOT_CHMOD, udest_orig.path() ); ftp.ftpDisconnect( true ); m_cmd = CMD_NONE; finished(); return; } } } // if the size is less then minimum -> delete the file else if ( e->size < KProtocolManager::self().minimumKeepSize() ) { ftp.ftpDelete( udest.path() ); } } ftp.ftpDisconnect( true ); ftp.enablePASV( true ); // We have done our job => finish finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotDel( QStringList& _source ){ // Check wether the URLs are wellformed QStringList::Iterator soit = _source.begin(); for( ; soit != _source.end(); ++soit ) { debug( "kio_ftp : Checking %s", (*soit).ascii() ); KURL usrc( *soit ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, *soit); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error(ERR_INTERNAL,"kio_ftp got non ftp file for delete command" ); m_cmd = CMD_NONE; return; } } qDebug( "kio_ftp : All URLs ok" ); // Get a list of all source files and directories QValueList<Copy> fs; QValueList<CopyDir> ds; int size = 0; qDebug( "kio_ftp : Iterating" ); soit = _source.begin(); qDebug( "kio_ftp : Looping" ); for( ; soit != _source.end(); ++soit ) { qDebug( "kio_ftp : Executing %s", (*soit).ascii() ); KURL usrc(*soit); qDebug( "kio_ftp : Parsed URL" ); // Did an error occur ?// int s;// if ( ( s = listRecursive( usrc.path(), fs, ds, false ) ) == -1 )// {// // Error message is already sent// ftp.ftpDisconnect();// m_cmd = CMD_NONE;// return;// } // Sum up the total amount of bytes we have to copy// size += s; } qDebug( "kio_ftp : Recursive ok" ); if ( fs.count() == 1 ) m_cmd = CMD_DEL; else m_cmd = CMD_MDEL; // Tell our client what we 'r' gonna do totalSize( size ); totalFiles( fs.count() ); totalDirs( ds.count() ); /***** * Delete files *****/ QValueList<Copy>::Iterator fit = fs.begin(); for( ; fit != fs.end(); fit++ ) { QString filename = (*fit).m_strAbsSource; qDebug( "kio_ftp : Deleting file %s", filename.ascii() ); deletingFile( filename ); if ( !ftp.ftpDelete( filename ) ) // !!! use unlink ? { error( ERR_CANNOT_DELETE, filename ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } /***** * Delete empty directories *****/ QValueList<CopyDir>::Iterator dit = ds.begin(); for( ; dit != ds.end(); dit++ ) { QString dirname = (*dit).m_strAbsSource; qDebug( "kio_ftp : Deleting directory %s", dirname.ascii() ); deletingFile( dirname ); if ( !ftp.ftpRmdir( dirname ) ) { error( ERR_COULD_NOT_RMDIR, dirname ); ftp.ftpDisconnect(); m_cmd = CMD_NONE; return; } } finished(); m_cmd = CMD_NONE;}void FtpProtocol::slotData( void *_p, int _len ){ switch( m_cmd ) { case CMD_PUT: ftp.write( _p, _len ); break; }}void FtpProtocol::slotDataEnd(){ switch( m_cmd ) { case CMD_PUT: m_cmd = CMD_NONE; }}long FtpProtocol::listRecursive( const char *_path, QValueList<Copy>& _files, QValueList<CopyDir>& _dirs, bool _rename ){ m_bAutoSkip = false; // Check wether we have to copy the complete directory tree beginning by its root. int len = strlen( _path ); while( len >= 1 && _path[ len - 1 ] == '/' ) len--; if ( len == 0 ) { CopyDir c; c.m_strAbsSource = _path; if ( _rename ) c.m_strRelDest = ""; else c.m_strRelDest = ""; c.m_access = S_IRWXU | S_IRWXO | S_IRWXG; c.m_type = S_IFDIR; _dirs.append( c ); return listRecursive2( "/", c.m_strRelDest, _files, _dirs ); } QString p=_path; qDebug( "kio_ftp : ########## RECURSIVE LISTING %s", p.ascii() ); KURL tmpurl( "ftp:/" ); tmpurl.setPath( p ); FtpEntry* e = ftp.ftpStat( tmpurl ); if ( !e ) { error( ERR_DOES_NOT_EXIST, p); return -1; } KURL u( p ); // Should be checked before, but who knows if ( u.isMalformed() ) assert( 0 ); // Is the source not a directory ? => so just copy it and we are done. if ( !S_ISDIR( e->type ) ) { qDebug( "kio_ftp : not a dir" ); QString fname; if ( _rename ) fname = ""; else { fname = u.filename(); // Should be impossible, but who knows ... if ( fname.isEmpty() ) assert( 0 ); } Copy c; c.m_strAbsSource = p; c.m_strRelDest = fname; c.m_access = e->access; c.m_type = e->type; c.m_size = e->size; _files.append( c ); return e->size; } // The source is a directory. So we have to go into recursion here. QString tmp1; if ( _rename ) tmp1 = u.path( 0 ); else { tmp1 = u.directory( true ); tmp1 += "/"; } QString tmp2; if ( _rename ) tmp2 = ""; else tmp2 = u.filename(); CopyDir c; c.m_strAbsSource = p; c.m_strRelDest = tmp2; c.m_access = e->access; c.m_type = e->type; _dirs.append( c ); qDebug( "kio_ftp : ########### STARTING RECURSION with %s and %s",tmp1.ascii(), tmp2.ascii() ); return listRecursive2( tmp1, tmp2, _files, _dirs );}long FtpProtocol::listRecursive2( const char *_abs_path, const char *_rel_path, QValueList<Copy>& _files, QValueList<CopyDir>& _dirs ){ long size = 0; cerr << "listRecursive2 " << _abs_path << " " << _rel_path << endl; QString p = _abs_path; p += _rel_path; scanningDir( p ); KURL tmpurl( "ftp:/" ); tmpurl.setPath( p ); if ( !ftp.ftpOpenDir( tmpurl ) ) { if ( m_bAutoSkip ) return 0; SkipDlg_Result result = open_SkipDlg( p, true ); if ( result == S_CANCEL ) { // error( ERR_CANNOT_ENTER_DIRECTORY, p ); return -1; } else if ( result == S_AUTO_SKIP ) m_bAutoSkip = true; return 0; } QStringList recursion; qDebug( "kio_ftp : ##Listing" ); FtpEntry *e; while ( ( e = ftp.readdir() ) != 0L ) { qDebug( "kio_ftp : #%s", e->name.ascii() ); if ( e->name == "." || e->name == ".." ) continue; QString p2 = p; p2 += "/"; p2 += e->name; QString tmp = _rel_path; tmp += "/"; tmp += e->name; if ( !S_ISDIR( e->type ) ) { qDebug( "kio_ftp : Appending '%s' '%s'", p2.ascii(), tmp.ascii() ); Copy c; c.m_strAbsSource = p2; c.m_strRelDest = tmp; c.m_access = e->access; c.m_type = e->type; c.m_size = e->size; _files.append( c ); size += e->size; } else { CopyDir c; c.m_strAbsSource = p2; c.m_strRelDest = tmp; c.m_access = e->access; c.m_type = e->type; _dirs.append( c ); recursion.append( tmp ); } } if ( !ftp.ftpCloseDir() ) { // error( ERR_COULD_NOT_CLOSEDIR, p ); return -1; } QStringList::Iterator it = recursion.begin(); for( ; it != recursion.end(); ++it ) { long s; if ( ( s = listRecursive2( _abs_path, (*it).ascii(), _files, _dirs ) ) == -1 ) return -1; size += s; } return size;}void FtpProtocol::slotListDir( const char *_url ){ qDebug( "kio_ftp : =============== LIST %s ===============", _url ); KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } /* struct stat buff; if ( stat( usrc.path(), &buff ) == -1 ) { error( ERR_DOES_NOT_EXIST, url); m_cmd = CMD_NONE; return; } if ( !S_ISDIR( buff.st_mode ) ) { error( ERR_IS_FILE, url ); m_cmd = CMD_NONE; return; } */ m_cmd = CMD_LIST; if ( !ftp.opendir( usrc ) ) { error( ERR_CANNOT_ENTER_DIRECTORY, strdup(_url) ); m_cmd = CMD_NONE; return; } FtpEntry* e; while ( ( e = ftp.readdir() ) ) { if ( e->name == "." || e->name == ".." ) continue; debug( "kio_ftp : Listing %s", e->name.ascii() ); UDSEntry entry; UDSAtom atom; atom.m_uds = UDS_NAME; atom.m_str = e->name; entry.append( atom ); atom.m_uds = UDS_FILE_TYPE; atom.m_long = e->type; entry.append( atom ); atom.m_uds = UDS_SIZE; atom.m_long = e->size; entry.append( atom ); /* atom.m_uds = UDS_MODIFICATION_TIME; atom.m_long = buff.st_mtime; entry.append( atom ); */ atom.m_uds = UDS_ACCESS; atom.m_long = e->access; entry.append( atom ); atom.m_uds = UDS_USER; atom.m_str = e->owner; entry.append( atom ); atom.m_uds = UDS_GROUP; atom.m_str = e->group; entry.append( atom ); atom.m_uds = UDS_LINK_DEST; atom.m_str = e->link; entry.append( atom ); /* atom.m_uds = UDS_ACCESS_TIME; atom.m_long = buff.st_atime; entry.append( atom ); atom.m_uds = UDS_CREATION_TIME; atom.m_long = buff.st_ctime; entry.append( atom ); */ listEntry( entry ); } debug( "kio_ftp : ============= COMPLETED LIST ============" ); ftp.closedir(); debug( "kio_ftp : ============= COMPLETED LIST 2 ============" ); m_cmd = CMD_NONE; finished(); debug( "kio_ftp : =============== BYE ===========" );}void FtpProtocol::slotTestDir( const char *_url ){ KURL usrc( _url ); if ( usrc.isMalformed() ) { error( ERR_MALFORMED_URL, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) { error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" ); m_cmd = CMD_NONE; return; } qDebug( "kio_ftp : =============== slotTestDir ==============" ); FtpEntry* e; if ( !( e = ftp.stat( usrc ) ) ) { debug( "kio_ftp : =========== ERROR ========" ); error( ERR_DOES_NOT_EXIST, strdup(_url) ); m_cmd = CMD_NONE; return; } if ( S_ISDIR( e->type ) ) { qDebug( "kio_ftp : ========== DONE DIR ========= %s", _url ); isDirectory(); } else { qDebug( "kio_ftp : ========== DONE FILE ========= %s", _url ); isFile(); } finished();}void FtpProtocol::jobError( int _errid, const char *_txt ){ if ( !m_bIgnoreJobErrors ) error( _errid, _txt );}/************************************* * * FtpIOJob * *************************************/FtpIOJob::FtpIOJob( Connection *_conn, FtpProtocol *_Ftp ) : IOJob( _conn ){ m_pFtp = _Ftp;} void FtpIOJob::slotError( int _errid, const char *_txt ){ IOJob::slotError( _errid, _txt ); m_pFtp->jobError( _errid, _txt );}/************************************* * * Utilities * *************************************/int check( Connection *_con ){ int err; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; fd_set rfds; FD_ZERO( &rfds ); FD_SET( _con->inFD(), &rfds ); again: if ( ( err = select( _con->inFD(), &rfds, 0L, 0L, &tv ) ) == -1 && errno == EINTR ) goto again; // No error and something to read ? if ( err != -1 && err != 0 ) return 1; return 0;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/747850cee3cebb60d93bead6d4b7dbc056285a51/main.cc/buggy/kioslave/ftp/main.cc |
|
int m, n; for (m = 0; m < board_size; m++) for (n = 0; n < board_size; n++) if (p[m][n]) matchpat(m, n, attack_callback, OTHER_COLOR(p[m][n]), &attpat_db, NULL, NULL); | global_matchpat(attack_callback, ANCHOR_OTHER, &attpat_db, NULL, NULL); | find_attack_patterns(void){ int m, n; for (m = 0; m < board_size; m++) for (n = 0; n < board_size; n++) if (p[m][n]) matchpat(m, n, attack_callback, OTHER_COLOR(p[m][n]), &attpat_db, NULL, NULL);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/c40d4381e05746bd0adda4d6cbb6b2ef5de3a51c/worm.c/buggy/engine/worm.c |
kdDebug(130) << "storeInWallet: key=" << key << " reading existing map" << endl; if ( wallet->readMap( key, map ) == 0 ) { | QString walletKey = makeWalletKey( key, info.realmValue ); kdDebug(130) << "storeInWallet: walletKey=" << walletKey << " reading existing map" << endl; if ( wallet->readMap( walletKey, map ) == 0 ) { | static bool storeInWallet( KWallet::Wallet* wallet, const QString& key, const KIO::AuthInfo &info ){ if ( !wallet->hasFolder( KWallet::Wallet::PasswordFolder() ) ) if ( !wallet->createFolder( KWallet::Wallet::PasswordFolder() ) ) return false; wallet->setFolder( KWallet::Wallet::PasswordFolder() ); // Before saving, check if there's already an entry with this login. // If so, replace it (with the new password). Otherwise, add a new entry. typedef QMap<QString,QString> Map; int entryNumber = 1; Map map; kdDebug(130) << "storeInWallet: key=" << key << " reading existing map" << endl; if ( wallet->readMap( key, map ) == 0 ) { Map::ConstIterator end = map.end(); Map::ConstIterator it = map.find( "login" ); while ( it != end ) { Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == info.realmValue ) { if ( it.data() == info.username ) { break; // OK, overwrite this entry } } else { // this entry is for another realm, don't overwrite it kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; } it = map.find( QString( "login-" ) + QString::number( ++entryNumber ) ); } // If no entry was found, create a new entry - entryNumber is set already. } const QString loginKey = makeMapKey( "login", entryNumber ); const QString passwordKey = makeMapKey( "password", entryNumber ); kdDebug(130) << "storeInWallet: writing to " << loginKey << "," << passwordKey << endl; // note the overwrite=true by default map.insert( loginKey, info.username ); map.insert( passwordKey, info.password ); if ( !info.realmValue.isEmpty() ) { const QString realmKey = makeMapKey( "realm", entryNumber ); map.insert( realmKey, info.realmValue ); } wallet->writeMap( key, map ); return true;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/2f28e29c0a0e7d5766936e6d0376b614d9fcdea5/kpasswdserver.cpp/clean/kpasswdserver/kpasswdserver.cpp |
Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == info.realmValue ) { if ( it.data() == info.username ) { break; } } else { kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; | if ( it.data() == info.username ) { break; | static bool storeInWallet( KWallet::Wallet* wallet, const QString& key, const KIO::AuthInfo &info ){ if ( !wallet->hasFolder( KWallet::Wallet::PasswordFolder() ) ) if ( !wallet->createFolder( KWallet::Wallet::PasswordFolder() ) ) return false; wallet->setFolder( KWallet::Wallet::PasswordFolder() ); // Before saving, check if there's already an entry with this login. // If so, replace it (with the new password). Otherwise, add a new entry. typedef QMap<QString,QString> Map; int entryNumber = 1; Map map; kdDebug(130) << "storeInWallet: key=" << key << " reading existing map" << endl; if ( wallet->readMap( key, map ) == 0 ) { Map::ConstIterator end = map.end(); Map::ConstIterator it = map.find( "login" ); while ( it != end ) { Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == info.realmValue ) { if ( it.data() == info.username ) { break; // OK, overwrite this entry } } else { // this entry is for another realm, don't overwrite it kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; } it = map.find( QString( "login-" ) + QString::number( ++entryNumber ) ); } // If no entry was found, create a new entry - entryNumber is set already. } const QString loginKey = makeMapKey( "login", entryNumber ); const QString passwordKey = makeMapKey( "password", entryNumber ); kdDebug(130) << "storeInWallet: writing to " << loginKey << "," << passwordKey << endl; // note the overwrite=true by default map.insert( loginKey, info.username ); map.insert( passwordKey, info.password ); if ( !info.realmValue.isEmpty() ) { const QString realmKey = makeMapKey( "realm", entryNumber ); map.insert( realmKey, info.realmValue ); } wallet->writeMap( key, map ); return true;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/2f28e29c0a0e7d5766936e6d0376b614d9fcdea5/kpasswdserver.cpp/clean/kpasswdserver/kpasswdserver.cpp |
static bool storeInWallet( KWallet::Wallet* wallet, const QString& key, const KIO::AuthInfo &info ){ if ( !wallet->hasFolder( KWallet::Wallet::PasswordFolder() ) ) if ( !wallet->createFolder( KWallet::Wallet::PasswordFolder() ) ) return false; wallet->setFolder( KWallet::Wallet::PasswordFolder() ); // Before saving, check if there's already an entry with this login. // If so, replace it (with the new password). Otherwise, add a new entry. typedef QMap<QString,QString> Map; int entryNumber = 1; Map map; kdDebug(130) << "storeInWallet: key=" << key << " reading existing map" << endl; if ( wallet->readMap( key, map ) == 0 ) { Map::ConstIterator end = map.end(); Map::ConstIterator it = map.find( "login" ); while ( it != end ) { Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == info.realmValue ) { if ( it.data() == info.username ) { break; // OK, overwrite this entry } } else { // this entry is for another realm, don't overwrite it kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; } it = map.find( QString( "login-" ) + QString::number( ++entryNumber ) ); } // If no entry was found, create a new entry - entryNumber is set already. } const QString loginKey = makeMapKey( "login", entryNumber ); const QString passwordKey = makeMapKey( "password", entryNumber ); kdDebug(130) << "storeInWallet: writing to " << loginKey << "," << passwordKey << endl; // note the overwrite=true by default map.insert( loginKey, info.username ); map.insert( passwordKey, info.password ); if ( !info.realmValue.isEmpty() ) { const QString realmKey = makeMapKey( "realm", entryNumber ); map.insert( realmKey, info.realmValue ); } wallet->writeMap( key, map ); return true;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/2f28e29c0a0e7d5766936e6d0376b614d9fcdea5/kpasswdserver.cpp/clean/kpasswdserver/kpasswdserver.cpp |
||
if ( !info.realmValue.isEmpty() ) { const QString realmKey = makeMapKey( "realm", entryNumber ); map.insert( realmKey, info.realmValue ); } wallet->writeMap( key, map ); | wallet->writeMap( walletKey, map ); | static bool storeInWallet( KWallet::Wallet* wallet, const QString& key, const KIO::AuthInfo &info ){ if ( !wallet->hasFolder( KWallet::Wallet::PasswordFolder() ) ) if ( !wallet->createFolder( KWallet::Wallet::PasswordFolder() ) ) return false; wallet->setFolder( KWallet::Wallet::PasswordFolder() ); // Before saving, check if there's already an entry with this login. // If so, replace it (with the new password). Otherwise, add a new entry. typedef QMap<QString,QString> Map; int entryNumber = 1; Map map; kdDebug(130) << "storeInWallet: key=" << key << " reading existing map" << endl; if ( wallet->readMap( key, map ) == 0 ) { Map::ConstIterator end = map.end(); Map::ConstIterator it = map.find( "login" ); while ( it != end ) { Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == info.realmValue ) { if ( it.data() == info.username ) { break; // OK, overwrite this entry } } else { // this entry is for another realm, don't overwrite it kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; } it = map.find( QString( "login-" ) + QString::number( ++entryNumber ) ); } // If no entry was found, create a new entry - entryNumber is set already. } const QString loginKey = makeMapKey( "login", entryNumber ); const QString passwordKey = makeMapKey( "password", entryNumber ); kdDebug(130) << "storeInWallet: writing to " << loginKey << "," << passwordKey << endl; // note the overwrite=true by default map.insert( loginKey, info.username ); map.insert( passwordKey, info.password ); if ( !info.realmValue.isEmpty() ) { const QString realmKey = makeMapKey( "realm", entryNumber ); map.insert( realmKey, info.realmValue ); } wallet->writeMap( key, map ); return true;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/2f28e29c0a0e7d5766936e6d0376b614d9fcdea5/kpasswdserver.cpp/clean/kpasswdserver/kpasswdserver.cpp |
if ( wallet->readMap( key, map ) == 0 ) | if ( wallet->readMap( makeWalletKey( key, realm ), map ) == 0 ) | static bool readFromWallet( KWallet::Wallet* wallet, const QString& key, const QString& realm, QString& username, QString& password, bool userReadOnly, QMap<QString,QString>& knownLogins ){ //kdDebug(130) << "readFromWallet: key=" << key << " username=" << username << " password=" /*<< password*/ << " userReadOnly=" << userReadOnly << " realm=" << realm << endl; if ( wallet->hasFolder( KWallet::Wallet::PasswordFolder() ) ) { wallet->setFolder( KWallet::Wallet::PasswordFolder() ); QMap<QString,QString> map; if ( wallet->readMap( key, map ) == 0 ) { typedef QMap<QString,QString> Map; int entryNumber = 1; Map::ConstIterator end = map.end(); Map::ConstIterator it = map.find( "login" ); while ( it != end ) { //kdDebug(130) << "readFromWallet: found " << it.key() << "=" << it.data() << endl; Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == realm ) { Map::ConstIterator pwdIter = map.find( makeMapKey( "password", entryNumber ) ); if ( pwdIter != end ) { if ( it.data() == username ) password = pwdIter.data(); knownLogins.insert( it.data(), pwdIter.data() ); } } else { //kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; } it = map.find( QString( "login-" ) + QString::number( ++entryNumber ) ); } //kdDebug(130) << knownLogins.count() << " known logins" << endl; if ( !userReadOnly && !knownLogins.isEmpty() && username.isEmpty() ) { // Pick one, any one... username = knownLogins.begin().key(); password = knownLogins.begin().data(); //kdDebug(130) << "readFromWallet: picked the first one : " << username << endl; } return true; } } return false;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/2f28e29c0a0e7d5766936e6d0376b614d9fcdea5/kpasswdserver.cpp/clean/kpasswdserver/kpasswdserver.cpp |
Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == realm ) { Map::ConstIterator pwdIter = map.find( makeMapKey( "password", entryNumber ) ); if ( pwdIter != end ) { if ( it.data() == username ) password = pwdIter.data(); knownLogins.insert( it.data(), pwdIter.data() ); } } else { | Map::ConstIterator pwdIter = map.find( makeMapKey( "password", entryNumber ) ); if ( pwdIter != end ) { if ( it.data() == username ) password = pwdIter.data(); knownLogins.insert( it.data(), pwdIter.data() ); | static bool readFromWallet( KWallet::Wallet* wallet, const QString& key, const QString& realm, QString& username, QString& password, bool userReadOnly, QMap<QString,QString>& knownLogins ){ //kdDebug(130) << "readFromWallet: key=" << key << " username=" << username << " password=" /*<< password*/ << " userReadOnly=" << userReadOnly << " realm=" << realm << endl; if ( wallet->hasFolder( KWallet::Wallet::PasswordFolder() ) ) { wallet->setFolder( KWallet::Wallet::PasswordFolder() ); QMap<QString,QString> map; if ( wallet->readMap( key, map ) == 0 ) { typedef QMap<QString,QString> Map; int entryNumber = 1; Map::ConstIterator end = map.end(); Map::ConstIterator it = map.find( "login" ); while ( it != end ) { //kdDebug(130) << "readFromWallet: found " << it.key() << "=" << it.data() << endl; Map::ConstIterator realmIter = map.find( makeMapKey( "realm", entryNumber ) ); if ( realmIter == end || realmIter.data() == realm ) { Map::ConstIterator pwdIter = map.find( makeMapKey( "password", entryNumber ) ); if ( pwdIter != end ) { if ( it.data() == username ) password = pwdIter.data(); knownLogins.insert( it.data(), pwdIter.data() ); } } else { //kdDebug(130) << " ignoring entry for realm " << realmIter.data() << endl; } it = map.find( QString( "login-" ) + QString::number( ++entryNumber ) ); } //kdDebug(130) << knownLogins.count() << " known logins" << endl; if ( !userReadOnly && !knownLogins.isEmpty() && username.isEmpty() ) { // Pick one, any one... username = knownLogins.begin().key(); password = knownLogins.begin().data(); //kdDebug(130) << "readFromWallet: picked the first one : " << username << endl; } return true; } } return false;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/2f28e29c0a0e7d5766936e6d0376b614d9fcdea5/kpasswdserver.cpp/clean/kpasswdserver/kpasswdserver.cpp |
static char *fill_words(char *c, char *words[], int *n) | static char *fill_words(char *c, char *words[], int *n, bool newline) | static char *fill_words(char *c, char *words[], int *n){ char *sl=c; int slash=0; int skipspace=0; *n=0; words[*n]=sl; while (*sl && (*sl!='\n' || slash)) { if (!slash) { if (*sl=='"') { *sl='\a'; skipspace=!skipspace; } else if (*sl==escapesym) { slash=1; if (sl[1]=='\n') *sl='\a'; } else if ((*sl==' ' || *sl=='\t') && !skipspace) { *sl='\n'; if (words[*n]!=sl) (*n)++; words[*n]=sl+1; } } else { if (*sl=='"') { sl--; *sl='\n'; if (words[*n]!=sl) (*n)++; sl++; while (*sl && *sl !='\n') sl++; words[*n]=sl; sl--; } slash=0; } sl++; } if (sl!=words[*n]) (*n)++; return sl;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
*sl='\a'; skipspace=!skipspace; | if (skipspace && (*(sl+1)=='"')) *sl++ = '\a'; else { *sl='\a'; skipspace=!skipspace; } | static char *fill_words(char *c, char *words[], int *n){ char *sl=c; int slash=0; int skipspace=0; *n=0; words[*n]=sl; while (*sl && (*sl!='\n' || slash)) { if (!slash) { if (*sl=='"') { *sl='\a'; skipspace=!skipspace; } else if (*sl==escapesym) { slash=1; if (sl[1]=='\n') *sl='\a'; } else if ((*sl==' ' || *sl=='\t') && !skipspace) { *sl='\n'; if (words[*n]!=sl) (*n)++; words[*n]=sl+1; } } else { if (*sl=='"') { sl--; *sl='\n'; if (words[*n]!=sl) (*n)++; sl++; while (*sl && *sl !='\n') sl++; words[*n]=sl; sl--; } slash=0; } sl++; } if (sl!=words[*n]) (*n)++; return sl;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
*sl='\n'; | if (newline) *sl='\n'; | static char *fill_words(char *c, char *words[], int *n){ char *sl=c; int slash=0; int skipspace=0; *n=0; words[*n]=sl; while (*sl && (*sl!='\n' || slash)) { if (!slash) { if (*sl=='"') { *sl='\a'; skipspace=!skipspace; } else if (*sl==escapesym) { slash=1; if (sl[1]=='\n') *sl='\a'; } else if ((*sl==' ' || *sl=='\t') && !skipspace) { *sl='\n'; if (words[*n]!=sl) (*n)++; words[*n]=sl+1; } } else { if (*sl=='"') { sl--; *sl='\n'; if (words[*n]!=sl) (*n)++; sl++; while (*sl && *sl !='\n') sl++; words[*n]=sl; sl--; } slash=0; } sl++; } if (sl!=words[*n]) (*n)++; return sl;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
*sl='\n'; | if (newline) *sl='\n'; | static char *fill_words(char *c, char *words[], int *n){ char *sl=c; int slash=0; int skipspace=0; *n=0; words[*n]=sl; while (*sl && (*sl!='\n' || slash)) { if (!slash) { if (*sl=='"') { *sl='\a'; skipspace=!skipspace; } else if (*sl==escapesym) { slash=1; if (sl[1]=='\n') *sl='\a'; } else if ((*sl==' ' || *sl=='\t') && !skipspace) { *sl='\n'; if (words[*n]!=sl) (*n)++; words[*n]=sl+1; } } else { if (*sl=='"') { sl--; *sl='\n'; if (words[*n]!=sl) (*n)++; sl++; while (*sl && *sl !='\n') sl++; words[*n]=sl; sl--; } slash=0; } sl++; } if (sl!=words[*n]) (*n)++; return sl;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl=fill_words(c+j, wordlist, &words); | sl=fill_words(c+j, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
switch (get_request(c, nlen)) | switch (int request = get_request(c, nlen)) | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
case REQ_el: { | case REQ_el: { | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
if (ifelseval) { | if (ifelseval) { | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
} else | } else | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
case REQ_if: { | case REQ_if: { | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { | if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
} else | } else | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
trans_char(c,'"','\a'); | fill_words(c, wordlist, &words, false); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl=fill_words(c, wordlist, &words); | sl=fill_words(c, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
case REQ_Ft: case REQ_Fa: case REQ_BR: case REQ_BI: | case REQ_Ft: case REQ_Fa: case REQ_BR: case REQ_BI: | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
if (inFMode) { | if (inFMode) { | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl=fill_words(c, wordlist, &words); | sl=fill_words(c, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl=fill_words(c+j, wordlist, &words); | sl=fill_words(c+j, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl=fill_words(c+j, wordlist, &words); | sl=fill_words(c+j, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl = fill_words(c+j, wordlist, &words); | sl = fill_words(c+j, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl=fill_words(c+j, wordlist, &words); | sl=fill_words(c+j, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
sl = fill_words(c, wordlist, &words); | sl = fill_words(c, wordlist, &words, true); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: //for "Function definitions", mdoc package case REQ_Fn: //for "Function calls": brackets and commas have to be inserted automatically case REQ_Fo: case REQ_Fc: { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: //perhaps "Function return type" case REQ_Fa: //"Function argument" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* BSD mandoc */ case REQ_RS: sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* BSD mandoc */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* BSD mandoc */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* BSD mandoc */ mandoc_command = 1; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<div style=\"position : absolute; top : 125px; margin-left : 10px; margin-right : 10px;\">"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(scan_troff(wordlist[1], 0, NULL))); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; sl = fill_words(c, wordlist, &words); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = sl + 1; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* BSD mandoc */ case REQ_Ek: /* BSD mandoc */ case REQ_Dd: /* BSD mandoc */ case REQ_Os: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* BSD mandoc */ case REQ_Fx: /* BSD mandoc */ case REQ_Nx: /* BSD mandoc */ case REQ_Ox: /* BSD mandoc */ case REQ_Bx: /* BSD mandoc */ case REQ_Ux: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); else if (i==V('U','x')) out_html("UNIX "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Dl: /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* BSD mandoc */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pa: /* BSD mandoc */ case REQ_Pf: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* BSD mandoc */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case REQ_Dq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Op: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Pq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Sq: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ar: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* BSD mandoc */ case REQ_Em: /* BSD mandoc */ case REQ_Va: /* BSD mandoc */ case REQ_Xc: /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* BSD mandoc */ case REQ_Cm: /* BSD mandoc */ case REQ_Ic: /* BSD mandoc */ case REQ_Ms: /* BSD mandoc */ case REQ_Or: /* BSD mandoc */ case REQ_Sy: /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* BSD mandoc */ case REQ_Ev: /* BSD mandoc */ case REQ_Fr: /* BSD mandoc */ case REQ_Li: /* BSD mandoc */ case REQ_No: /* BSD mandoc */ case REQ_Ns: /* BSD mandoc */ case REQ_Tn: /* BSD mandoc */ case REQ_nN: /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* BSD mandoc biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/6a4c33861ea5b7084c8f7e337682c447b0aea44a/man2html.cpp/buggy/kioslave/man/man2html.cpp |
comp->test = xmlGetNsProp(inst, (const xmlChar *)"test", XSLT_NAMESPACE); | comp->test = xsltGetNsProp(inst, (const xmlChar *)"test", XSLT_NAMESPACE); | xsltIfComp(xsltStylesheetPtr style, xmlNodePtr inst) { xsltStylePreCompPtr comp; if ((style == NULL) || (inst == NULL)) return; comp = xsltNewStylePreComp(style, XSLT_FUNC_IF); if (comp == NULL) return; inst->_private = comp; comp->inst = inst; comp->test = xmlGetNsProp(inst, (const xmlChar *)"test", XSLT_NAMESPACE); if (comp->test == NULL) { xsltGenericError(xsltGenericErrorContext, "xslt:if : test is not defined\n"); style->errors++; return; } comp->comp = xmlXPathCompile(comp->test); if (comp->comp == NULL) { xsltGenericError(xsltGenericErrorContext, "xslt:if : could not compile test expression '%s'\n", comp->test); style->errors++; }} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/fd8a7f1b51439bbcf01b819d7cc964127181d210/preproc.c/buggy/kioslave/help/libxslt/preproc.c |
oldPos = ctxt->xpathCtxt->proximityPosition; oldSize = ctxt->xpathCtxt->contextSize; oldInst = ctxt->inst; | xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc, xsltKeyDefPtr keyd) { int i; xmlNodeSetPtr nodelist = NULL, keylist; xmlXPathObjectPtr res = NULL; xmlChar *str; xsltKeyTablePtr table; int oldPos, oldSize; xmlNodePtr oldInst; /* * Evaluate the nodelist */ if (keyd->comp == NULL) goto error; if (keyd->usecomp == NULL) goto error; oldPos = ctxt->xpathCtxt->proximityPosition; oldSize = ctxt->xpathCtxt->contextSize; oldInst = ctxt->inst; ctxt->document = doc; ctxt->xpathCtxt->node = (xmlNodePtr) doc->doc; ctxt->node = (xmlNodePtr) doc->doc; /* TODO : clarify the use of namespaces in keys evaluation */ ctxt->xpathCtxt->namespaces = NULL; ctxt->xpathCtxt->nsNr = 0; ctxt->inst = keyd->inst; res = xmlXPathCompiledEval(keyd->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldSize; ctxt->xpathCtxt->proximityPosition = oldPos; ctxt->inst = oldInst; if (res != NULL) { if (res->type == XPATH_NODESET) { nodelist = res->nodesetval;#ifdef WITH_XSLT_DEBUG_KEYS if (nodelist != NULL) xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluates to %d nodes\n", keyd->match, nodelist->nodeNr);#endif } else {#ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s is not a node set\n", keyd->match);#endif goto error; } } else {#ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluation failed\n", keyd->match);#endif goto error; } /* * for each node in the list evaluate the key and insert the node */ if ((nodelist == NULL) || (nodelist->nodeNr <= 0)) goto error; table = xsltNewKeyTable(keyd->name, keyd->nameURI); if (table == NULL) goto error; for (i = 0;i < nodelist->nodeNr;i++) { ctxt->node = nodelist->nodeTab[i]; str = xsltEvalXPathString(ctxt, keyd->usecomp); if (str != NULL) {#ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "xsl:key : node associated to(%s,%s)\n", keyd->name, str);#endif keylist = xmlHashLookup(table->keys, str); if (keylist == NULL) { keylist = xmlXPathNodeSetCreate(nodelist->nodeTab[i]); xmlHashAddEntry(table->keys, str, keylist); } else { xmlXPathNodeSetAdd(keylist, nodelist->nodeTab[i]); } nodelist->nodeTab[i]->_private = keyd; xmlFree(str);#ifdef WITH_XSLT_DEBUG_KEYS } else { xsltGenericDebug(xsltGenericDebugContext, "xsl:key : use %s failed to return a string\n", keyd->use);#endif } } table->next = doc->keys; doc->keys = table;error: if (res != NULL) xmlXPathFreeObject(res);} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/fd8a7f1b51439bbcf01b819d7cc964127181d210/keys.c/clean/kioslave/help/libxslt/keys.c |
|
ctxt->document = oldDoc; ctxt->xpathCtxt->doc = oldXDoc; | xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc, xsltKeyDefPtr keyd) { int i; xmlNodeSetPtr nodelist = NULL, keylist; xmlXPathObjectPtr res = NULL; xmlChar *str; xsltKeyTablePtr table; int oldPos, oldSize; xmlNodePtr oldInst; /* * Evaluate the nodelist */ if (keyd->comp == NULL) goto error; if (keyd->usecomp == NULL) goto error; oldPos = ctxt->xpathCtxt->proximityPosition; oldSize = ctxt->xpathCtxt->contextSize; oldInst = ctxt->inst; ctxt->document = doc; ctxt->xpathCtxt->node = (xmlNodePtr) doc->doc; ctxt->node = (xmlNodePtr) doc->doc; /* TODO : clarify the use of namespaces in keys evaluation */ ctxt->xpathCtxt->namespaces = NULL; ctxt->xpathCtxt->nsNr = 0; ctxt->inst = keyd->inst; res = xmlXPathCompiledEval(keyd->comp, ctxt->xpathCtxt); ctxt->xpathCtxt->contextSize = oldSize; ctxt->xpathCtxt->proximityPosition = oldPos; ctxt->inst = oldInst; if (res != NULL) { if (res->type == XPATH_NODESET) { nodelist = res->nodesetval;#ifdef WITH_XSLT_DEBUG_KEYS if (nodelist != NULL) xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluates to %d nodes\n", keyd->match, nodelist->nodeNr);#endif } else {#ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s is not a node set\n", keyd->match);#endif goto error; } } else {#ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "xsltInitCtxtKey: %s evaluation failed\n", keyd->match);#endif goto error; } /* * for each node in the list evaluate the key and insert the node */ if ((nodelist == NULL) || (nodelist->nodeNr <= 0)) goto error; table = xsltNewKeyTable(keyd->name, keyd->nameURI); if (table == NULL) goto error; for (i = 0;i < nodelist->nodeNr;i++) { ctxt->node = nodelist->nodeTab[i]; str = xsltEvalXPathString(ctxt, keyd->usecomp); if (str != NULL) {#ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "xsl:key : node associated to(%s,%s)\n", keyd->name, str);#endif keylist = xmlHashLookup(table->keys, str); if (keylist == NULL) { keylist = xmlXPathNodeSetCreate(nodelist->nodeTab[i]); xmlHashAddEntry(table->keys, str, keylist); } else { xmlXPathNodeSetAdd(keylist, nodelist->nodeTab[i]); } nodelist->nodeTab[i]->_private = keyd; xmlFree(str);#ifdef WITH_XSLT_DEBUG_KEYS } else { xsltGenericDebug(xsltGenericDebugContext, "xsl:key : use %s failed to return a string\n", keyd->use);#endif } } table->next = doc->keys; doc->keys = table;error: if (res != NULL) xmlXPathFreeObject(res);} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/fd8a7f1b51439bbcf01b819d7cc964127181d210/keys.c/clean/kioslave/help/libxslt/keys.c |
|
(*env)->SetIntField(env, lpObject, SIZEFc.cx, (jint)lpStruct->cx); | void setSIZEFields(JNIEnv *env, jobject lpObject, SIZE *lpStruct){ if (!SIZEFc.cached) cacheSIZEFields(env, lpObject); (*env)->SetIntField(env, lpObject, SIZEFc.cy, (jint)lpStruct->cy); (*env)->SetIntField(env, lpObject, SIZEFc.cx, (jint)lpStruct->cx);} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/clean/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
gprintf("%m : %s dragon size %d (%f), genus %d, half eyes %d, escape factor %d, status %s%s, matcher status %s, moyo size %d safety %s", | gprintf("%m : %s dragon size %d (%f), genus %d, half eyes %d, escape factor %d, status %s, matcher status %s, moyo size %d safety %s", | show_dragons(void){ static const char *cnames[] = {"(empty)", "white dragon", "black dragon", "gray-bordered cave", "black-bordered cave", "white-bordered cave"}; static const char *snames[] = {"dead", "alive", "critical", "unknown", "unchecked"}; static const char *safety_names[] = {"dead", "alive", "critical", "inessential", "tactically dead", "weak", "weakly_alive", "alive_in_seki", "strongly_alive", "invincible"}; int m, n; for (m = 0; m < board_size; m++) for (n = 0; n < board_size; n++) { struct worm_data *w = &(worm[m][n]); if (((w->origini)==m)&&((w->originj)==n)) { if (p[m][n]) { gprintf("%m : (dragon %m) %s string of size %d (%f), genus %d: (%d,%d,%d,%d)", m, n, dragon[m][n].origini, dragon[m][n].originj, color_to_string(p[m][n]), w->size, w->effective_size, w->genus, w->liberties, w->liberties2, w->liberties3, w->liberties4); if (w->cutstone == 1) gprintf ("%o - is a potential cutting stone\n"); else if (w->cutstone == 2) gprintf("%o - is a cutting stone\n"); else gprintf("%o\n"); if (w->cutstone2 > 0) gprintf("- cutstone2 = %d\n", w->cutstone2); if (w->attack_code != 0) gprintf("- attackable at %m, attack code = %d\n", w->attacki, w->attackj, w->attack_code); if (w->defend_code != 0) gprintf("- defendable at %m, defend code = %d\n", w->defendi, w->defendj, w->defend_code); if (w->lunchi != -1) gprintf("... adjacent worm %m is lunch\n", w->lunchi, w->lunchj); if (w->inessential) gprintf("- is inessential\n"); if (w->invincible) gprintf("- is invincible\n"); if (w->ko == 1) gprintf("- is a ko stone\n"); } else gprintf("%m : cavity of size %d\n",m,n,w->size); } } gprintf("%o\n"); for (m = 0; m < board_size; m++) for (n = 0; n < board_size; n++) { struct dragon_data *d = &(dragon[m][n]); struct dragon_data2 *d2 = &(dragon2[d->id]); int k; if (((d->origini)==m) && ((d->originj)==n)) { if (p[m][n]) { gprintf("%m : %s dragon size %d (%f), genus %d, half eyes %d, escape factor %d, status %s%s, matcher status %s, moyo size %d safety %s", m,n, p[m][n]==BLACK ? "B" : "W", d->size, d->effective_size, d->genus, d->heyes, d->escape_route, snames[d->status], snames[d->matcher_status], d2->moyo, safety_names[d2->safety]); gprintf(", owl status %s\n", snames[d->owl_status]); if (d->owl_status == CRITICAL) { gprintf("... owl attackable at %m\n", d->owl_attacki, d->owl_attackj); gprintf("... owl defendable at %m\n", d->owl_defendi, d->owl_defendj); } gprintf("... neighbors"); for (k = 0; k < d2->neighbors; k++) { int d = d2->adjacent[k]; gprintf(" %m", dragon2[d].origini, dragon2[d].originj); } gprintf("\n"); if (d->lunchi != -1) gprintf("... adjacent worm %m is lunch\n", d->lunchi, d->lunchj); } else { gprintf("%m : cave of size %d and border color %s\n", m,n, d->size, cnames[d->color]); if (d->color == BLACK_BORDER || d->color == WHITE_BORDER) { if (!worm[m][n].ko) gprintf("... surrounded by dragon at %m\n", d->borderi, d->borderj); else gprintf("... is a ko\n"); } } } }} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/c40d4381e05746bd0adda4d6cbb6b2ef5de3a51c/dragon.c/clean/engine/dragon.c |
void substr_of(bufferlist& other, int off, int len) { clear(); // skip off list<bufferptr>::iterator curbuf = other._buffers.begin(); while (off > 0) { assert(curbuf != _buffers.end()); if (off >= (*curbuf).length()) { // skip this buffer //cout << "skipping over " << *curbuf << endl; off -= (*curbuf).length(); curbuf++; } else { // somewhere in this buffer! //cout << "somewhere in " << *curbuf << endl; break; } } while (len > 0) { // partial? if (off + len < (*curbuf).length()) { //cout << "copying partial of " << *curbuf << endl; _buffers.push_back( bufferptr( *curbuf, len, off ) ); _len += len; break; } // hose the whole thing //cout << "copying end (all?) of " << *curbuf << endl; int howmuch = (*curbuf).length() - off; _buffers.push_back( bufferptr( *curbuf, howmuch, off ) ); _len += howmuch; len -= howmuch; off = 0; curbuf++; } } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/a9d737fbcdf7972b65bb037b79e45e773e1acfa5/bufferlist.h/clean/ceph/include/bufferlist.h |
||
void put() { ref--; assert(ref >= 0); } | void put() { assert(ref == 1); ref--; lru_unpin(); } | void put() { ref--; assert(ref >= 0); } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/c64cf759da6324c62222ce6aff1e12bf18ce13b6/Client.h/buggy/ceph/client/Client.h |
olddomainname *ypbindproc_olddomain_1_arg; | domainname ypbindproc_olddomain_1_arg; | ypbindprog_1 (struct svc_req *rqstp, register SVCXPRT *transp){ union { olddomainname *ypbindproc_olddomain_1_arg; ypbind_oldsetdom ypbindproc_oldsetdom_1_arg; } argument; union { ypbind_resp ypbindproc_olddomain_1_res; } result; bool_t retval; xdrproc_t xdr_argument, xdr_result; bool_t (*local) (char *, void *, struct svc_req *); switch (rqstp->rq_proc) { case YPBINDPROC_OLDNULL: xdr_argument = (xdrproc_t) xdr_void; xdr_result = (xdrproc_t) xdr_void; local = (bool_t (*)(char *, void *, struct svc_req *)) ypbindproc_oldnull_1_svc; break; case YPBINDPROC_OLDDOMAIN: xdr_argument = (xdrproc_t) ypbind_xdr_olddomainname; xdr_result = (xdrproc_t) ypbind_xdr_resp; local = (bool_t (*)(char *, void *, struct svc_req *)) ypbindproc_olddomain_1_svc; break; case YPBINDPROC_OLDSETDOM: xdr_argument = (xdrproc_t) ypbind_xdr_oldsetdom; xdr_result = (xdrproc_t) xdr_void; local = (bool_t (*)(char *, void *, struct svc_req *)) ypbindproc_oldsetdom_1_svc; break; default: svcerr_noproc (transp); return; } memset ((char *) &argument, 0, sizeof (argument)); if (!svc_getargs (transp, xdr_argument, (caddr_t) & argument)) { svcerr_decode (transp); return; } retval = (bool_t) (*local) ((char *) &argument, (void *) &result, rqstp); if (retval > 0 && !svc_sendreply (transp, xdr_result, (char *) &result)) { svcerr_systemerr (transp); } if (!svc_freeargs (transp, xdr_argument, (caddr_t) &argument)) log_msg (LOG_ERR, _("unable to free arguments")); if (!ypbindprog_1_freeresult (transp, xdr_result, (caddr_t) &result)) log_msg (LOG_ERR, _("unable to free results")); return;} | 5799 /local/tlutelli/issta_data/temp/c/2005_temp/2005/5799/59740f58b00d67eeb7429afa9e9944ba6829c699/ypbind_svc.c/clean/src/ypbind_svc.c |
xdr_argument = (xdrproc_t) ypbind_xdr_olddomainname; | xdr_argument = (xdrproc_t) ypbind_xdr_domainname; | ypbindprog_1 (struct svc_req *rqstp, register SVCXPRT *transp){ union { olddomainname *ypbindproc_olddomain_1_arg; ypbind_oldsetdom ypbindproc_oldsetdom_1_arg; } argument; union { ypbind_resp ypbindproc_olddomain_1_res; } result; bool_t retval; xdrproc_t xdr_argument, xdr_result; bool_t (*local) (char *, void *, struct svc_req *); switch (rqstp->rq_proc) { case YPBINDPROC_OLDNULL: xdr_argument = (xdrproc_t) xdr_void; xdr_result = (xdrproc_t) xdr_void; local = (bool_t (*)(char *, void *, struct svc_req *)) ypbindproc_oldnull_1_svc; break; case YPBINDPROC_OLDDOMAIN: xdr_argument = (xdrproc_t) ypbind_xdr_olddomainname; xdr_result = (xdrproc_t) ypbind_xdr_resp; local = (bool_t (*)(char *, void *, struct svc_req *)) ypbindproc_olddomain_1_svc; break; case YPBINDPROC_OLDSETDOM: xdr_argument = (xdrproc_t) ypbind_xdr_oldsetdom; xdr_result = (xdrproc_t) xdr_void; local = (bool_t (*)(char *, void *, struct svc_req *)) ypbindproc_oldsetdom_1_svc; break; default: svcerr_noproc (transp); return; } memset ((char *) &argument, 0, sizeof (argument)); if (!svc_getargs (transp, xdr_argument, (caddr_t) & argument)) { svcerr_decode (transp); return; } retval = (bool_t) (*local) ((char *) &argument, (void *) &result, rqstp); if (retval > 0 && !svc_sendreply (transp, xdr_result, (char *) &result)) { svcerr_systemerr (transp); } if (!svc_freeargs (transp, xdr_argument, (caddr_t) &argument)) log_msg (LOG_ERR, _("unable to free arguments")); if (!ypbindprog_1_freeresult (transp, xdr_result, (caddr_t) &result)) log_msg (LOG_ERR, _("unable to free results")); return;} | 5799 /local/tlutelli/issta_data/temp/c/2005_temp/2005/5799/59740f58b00d67eeb7429afa9e9944ba6829c699/ypbind_svc.c/clean/src/ypbind_svc.c |
if (!IS_STONE(str)) { | if (!IS_STONE(board[str])) { | do_atari_atari(int color, int *attack_point, int *defense_point, int last_friendly, int save_verbose, int minsize){ int other = OTHER_COLOR(color); int k; int num_attack_moves; int attack_moves[MAX_BOARD * MAX_BOARD]; int targets[MAX_BOARD * MAX_BOARD]; int num_defense_moves; int defense_moves[MAX_BOARD * MAX_BOARD]; int pos; SGFTree *save_sgf_dumptree; int save_count_variations; if (debug & DEBUG_ATARI_ATARI) { gprintf("%odo_atari_atari: "); dump_stack(); gprintf("%oforbidden moves: "); for (pos = BOARDMIN; pos < BOARDMAX; pos++) if (ON_BOARD(pos) && forbidden[pos]) gprintf("%o%1m ", pos); gprintf("\n"); } /* First look for strings adjacent to the last friendly move played * (or to another stone in the same string) which can be * unexpectedly attacked. If so, the combination attack * has succeeded. */ if (last_friendly != NO_MOVE) { int retval; save_sgf_dumptree = sgf_dumptree; save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; retval = atari_atari_succeeded(color, attack_point, defense_point, last_friendly, save_verbose, minsize); sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; if (retval != 0) { if (sgf_dumptree) /* FIXME: Better message. */ sgftreeAddComment(sgf_dumptree, NULL, "attack found"); return retval; } } if (stackp > aa_depth) return 0; /* Find attack moves. These are typically ataris but may also be * more general. */ save_sgf_dumptree = sgf_dumptree; save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; num_attack_moves = atari_atari_find_attack_moves(color, minsize, attack_moves, targets); sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; /* Try the attacking moves and let the opponent defend. Then call * ourselves recursively. */ for (k = 0; k < num_attack_moves; k++) { int aa_val; int str = targets[k]; int apos = attack_moves[k]; int bpos; int r; if (!trymove(apos, color, "do_atari_atari-A", str, EMPTY, NO_MOVE)) continue; if (!IS_STONE(str)) { /* Error situation. This could be caused by a wrong matcher status. */ if (save_verbose || (debug & DEBUG_ATARI_ATARI)) gprintf("%oError condition found by atari_atari\n", str, apos); popgo(); return 0; } /* Try to defend the stone (str) which is threatened. */ aa_val = countstones(str); /* Pick up defense moves. */ save_sgf_dumptree = sgf_dumptree; save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; num_defense_moves = atari_atari_find_defense_moves(str, defense_moves); sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; for (r = 0; r < num_defense_moves; r++) { bpos = defense_moves[r]; if (trymove(bpos, other, "do_atari_atari-B", str, EMPTY, NO_MOVE)) { int new_aa_val; /* These moves may have been irrelevant for later * reading, so in order to avoid horizon problems, we * need to temporarily increase the depth values. */ modify_depth_values(2); new_aa_val = do_atari_atari(color, NULL, defense_point, apos, save_verbose, minsize); modify_depth_values(-2); if (new_aa_val < aa_val) aa_val = new_aa_val; popgo(); } /* Defense successful, no need to try any further. */ if (aa_val == 0) break; } /* Undo the attacking move. */ popgo(); if (aa_val == 0) continue; /* atari_atari successful */ if (num_defense_moves == 0) { if (save_verbose || (debug & DEBUG_ATARI_ATARI)) { gprintf("%oThe worm %1m can be attacked at %1m after ", str, apos); dump_stack(); } if (sgf_dumptree) /* FIXME: Better message. */ sgftreeAddComment(sgf_dumptree, NULL, "attack found"); } if (attack_point) *attack_point = apos; if (defense_point) { save_sgf_dumptree = sgf_dumptree; save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (!find_defense(str, defense_point)) *defense_point = NO_MOVE; /* If no defense point is known and (apos) is a safe * move for other, it probably defends the combination. */ if ((*defense_point == NO_MOVE || !safe_move(*defense_point, other)) && safe_move(apos, other)) *defense_point = apos; sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; } DEBUG(DEBUG_ATARI_ATARI, "%oreturn value:%d (%1m)\n", aa_val, str); return aa_val; } /* No atari_atari attack. */ return 0;} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/32c9909f779117f41e48d22e741af0b0a9b12b59/combination.c/buggy/engine/combination.c |
void fakemessenger_wait(){ cout << "fakemessenger_wait waiting" << endl; void *ptr; pthread_join(thread_id, &ptr);} | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/8c7283a709cbd1031e4adc5c129a44d81b7a0f8d/FakeMessenger.cc/buggy/ceph/msg/FakeMessenger.cc |
||
void runRdb( uint flags ){ // Export colors to non-(KDE/Qt) apps (e.g. Motif, GTK+ apps) if (flags & KRdbExportColors) { KGlobal::dirs()->addResourceType("appdefaults", KStandardDirs::kde_default("data") + "kdisplay/app-defaults/"); QColorGroup cg = kapp->palette().active(); KGlobal::locale()->insertCatalogue("krdb"); createGtkrc( true, cg ); QString preproc; addColorDef(preproc, "FOREGROUND" , cg.foreground()); QColor backCol = cg.background(); addColorDef(preproc, "BACKGROUND" , backCol); addColorDef(preproc, "HIGHLIGHT" , backCol.light(100+(2*KGlobalSettings::contrast()+4)*16/1)); addColorDef(preproc, "LOWLIGHT" , backCol.dark(100+(2*KGlobalSettings::contrast()+4)*10)); addColorDef(preproc, "SELECT_BACKGROUND" , cg.highlight()); addColorDef(preproc, "SELECT_FOREGROUND" , cg.highlightedText()); addColorDef(preproc, "WINDOW_BACKGROUND" , cg.base()); addColorDef(preproc, "WINDOW_FOREGROUND" , cg.foreground()); addColorDef(preproc, "INACTIVE_BACKGROUND", KGlobalSettings::inactiveTitleColor()); addColorDef(preproc, "INACTIVE_FOREGROUND", KGlobalSettings::inactiveTitleColor()); addColorDef(preproc, "ACTIVE_BACKGROUND" , KGlobalSettings::activeTitleColor()); addColorDef(preproc, "ACTIVE_FOREGROUND" , KGlobalSettings::activeTitleColor()); //--------------------------------------------------------------- QStringList list; QStringList adPaths = KGlobal::dirs()->findDirs("appdefaults", ""); for (QStringList::ConstIterator it = adPaths.begin(); it != adPaths.end(); it++) { QDir dSys( *it ); if ( dSys.exists() ) { dSys.setFilter( QDir::Files ); dSys.setSorting( QDir::Name ); dSys.setNameFilter("*.ad"); list += dSys.entryList(); } } QString propString; KTempFile tmpFile; if (tmpFile.status() != 0) { kdDebug() << "Couldn't open temp file" << endl; exit(0); } QFile &tmp = *(tmpFile.file()); tmp.writeBlock( preproc.latin1(), preproc.length() ); for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++) copyFile(tmp, locate("appdefaults", *it ), true); // very primitive support for ~/.Xdefaults by appending it copyFile(tmp, QDir::homeDirPath() + "/.Xdefaults", true); tmpFile.close(); KProcess proc; proc << "xrdb" << tmpFile.name(); proc.start( KProcess::Block, KProcess::Stdin ); tmpFile.unlink(); applyGtkStyles(true); } else { applyGtkStyles(false); // Undo the property xrdb has placed on the root window (if any). Atom resource_manager; resource_manager = XInternAtom( qt_xdisplay(), "RESOURCE_MANAGER", True); if (resource_manager != None) XDeleteProperty( qt_xdisplay(), qt_xrootwin(), resource_manager); // Undo Qt's _qt_desktop_properties (do we need to do this?) // (we prefer x11_apply_settings as its more featureful)/* Atom qt_desktop_properties; qt_desktop_properties = XInternAtom( qt_xdisplay(), "_QT_DESKTOP_PROPERTIES", True); if (qt_desktop_properties != None) XDeleteProperty( qt_xdisplay(), qt_xrootwin(), resouce_manager); */ } /* Qt exports */ bool exportQtColors = flags & KRdbExportQtColors; bool exportQtSettings = flags & KRdbExportQtSettings; if ( exportQtColors || exportQtSettings ) { QSettings* settings = new QSettings; KSimpleConfig kglobals("kdeglobals", true); /* open read-only */ if ( exportQtColors ) applyQtColors( kglobals, *settings ); // For kcmcolors if ( exportQtSettings ) applyQtSettings( kglobals, *settings ); // For kcmstyle delete settings; QApplication::flushX(); // We let KIPC take care of ourselves, as we are in a KDE app with // QApp::setDesktopSettingsAware(false); // Instead of calling QApp::x11_apply_settings() directly, we instead // modify the timestamp which propagates the settings changes onto // Qt-only apps without adversely affecting ourselves. // Cheat and use the current timestamp, since we just saved to qtrc. QDateTime settingsstamp = QDateTime::currentDateTime(); static Atom qt_settings_timestamp = 0; if (!qt_settings_timestamp) { QString atomname("_QT_SETTINGS_TIMESTAMP_"); atomname += XDisplayName( 0 ); // Use the $DISPLAY envvar. qt_settings_timestamp = XInternAtom( qt_xdisplay(), atomname.latin1(), False); } QBuffer stamp; QDataStream s(stamp.buffer(), IO_WriteOnly); s << settingsstamp; XChangeProperty( qt_xdisplay(), qt_xrootwin(), qt_settings_timestamp, qt_settings_timestamp, 8, PropModeReplace, (unsigned char*) stamp.buffer().data(), stamp.buffer().size() ); QApplication::flushX(); }} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/e20f1c229d3c4133443b77a3db6f175cae81d9b0/krdb.cpp/clean/kcontrol/krdb/krdb.cpp |
||
inline void _unrope(string& s, crope& r, int& off) | inline void _unrope(set<int>& s, crope& r, int& off) | inline void _unrope(string& s, crope& r, int& off){ s = r.c_str() + off; off += s.length() + 1;} | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/8c7283a709cbd1031e4adc5c129a44d81b7a0f8d/types.h/buggy/ceph/include/types.h |
s = r.c_str() + off; off += s.length() + 1; | s.clear(); int n; r.copy(off, sizeof(n), (char*)&n); off += sizeof(n); for (int i=0; i<n; i++) { int v; r.copy(off, sizeof(v), (char*)&v); off += sizeof(v); s.insert(v); } assert(s.size() == (unsigned)n); | inline void _unrope(string& s, crope& r, int& off){ s = r.c_str() + off; off += s.length() + 1;} | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/8c7283a709cbd1031e4adc5c129a44d81b7a0f8d/types.h/buggy/ceph/include/types.h |
lpStruct->Blue = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Blue); lpStruct->Green = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Green); lpStruct->Red = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Red); lpStruct->y = (*env)->GetIntField(env, lpObject, TRIVERTEXFc.y); lpStruct->x = (*env)->GetIntField(env, lpObject, TRIVERTEXFc.x); | TRIVERTEX *getTRIVERTEXFields(JNIEnv *env, jobject lpObject, TRIVERTEX *lpStruct){ if (!TRIVERTEXFc.cached) cacheTRIVERTEXFields(env, lpObject); lpStruct->Alpha = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Alpha); lpStruct->Blue = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Blue); lpStruct->Green = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Green); lpStruct->Red = (*env)->GetShortField(env, lpObject, TRIVERTEXFc.Red); lpStruct->y = (*env)->GetIntField(env, lpObject, TRIVERTEXFc.y); lpStruct->x = (*env)->GetIntField(env, lpObject, TRIVERTEXFc.x); return lpStruct;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
#else CLEAR_STACKS(); #endif | play_move(int i, int j, int color){#if CHECK_HASHING Hash_data oldkey; /* Check the hash table to see if it corresponds to the cumulative one. */ hashdata_recalc(&oldkey, p, board_ko_i, board_ko_j); gg_assert(hashdata_diff_dump(&oldkey, &hashdata) == 0);#endif gg_assert(stackp == 0); last_moves_i[1] = last_moves_i[0]; last_moves_j[1] = last_moves_j[0]; last_moves_i[0] = i; last_moves_j[0] = j; board_ko_i = -1; board_ko_j = -1; hashdata_remove_ko(&hashdata); /* If the move is a pass, we can skip some steps. */ if (i != -1 || j != -1) { ASSERT_ON_BOARD(i, j); ASSERT(p[i][j] == EMPTY, i, j); /* Do play the move. */ do_play_move(i, j, color);#if CHECK_HASHING /* Check the hash table to see if it equals the previous one. */ hashdata_recalc(&oldkey, p, board_ko_i, board_ko_j); gg_assert(hashdata_diff_dump(&oldkey, &hashdata) == 0);#endif } movenum++; new_position();} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/2a5a6dbb2a697083e7683965c1293f04fe090706/board.c/buggy/engine/board.c |
|
(JNIEnv *env, jclass that, jboolean enable) | (JNIEnv *env, jclass that) | JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_Callback_getEnabled (JNIEnv *env, jclass that, jboolean enable){ return (jboolean)callbackEnabled;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/d9f645840361a6cbc2b2762d02a25c5269a30014/callback.c/buggy/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c |
if (arg3) setControlFontStyleRecFields(env, arg3, lparg3); if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); | JNIEXPORT jint JNICALL OS_NATIVE(CreateStaticTextControl) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2, jobject arg3, jintArray arg4){ Rect _arg1, *lparg1=NULL; ControlFontStyleRec _arg3, *lparg3=NULL; jint *lparg4=NULL; jint rc; NATIVE_ENTER(env, that, "CreateStaticTextControl\n") if (arg1) lparg1 = getRectFields(env, arg1, &_arg1); if (arg3) lparg3 = getControlFontStyleRecFields(env, arg3, &_arg3); if (arg4) lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL); rc = (jint)CreateStaticTextControl((WindowRef)arg0, lparg1, (CFStringRef)arg2, (const ControlFontStyleRec *)lparg3, (ControlRef *)lparg4); if (arg1) setRectFields(env, arg1, lparg1); if (arg3) setControlFontStyleRecFields(env, arg3, lparg3); if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); NATIVE_EXIT(env, that, "CreateStaticTextControl\n") return rc;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/94da855f41fcf4c3984df28bc19cafb1b6fdb530/os.c/clean/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os.c |
|
*/ return (jint) GetPixBaseAddr((PixMapHandle)pHandle); | JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS_getBaseAddr(JNIEnv *env, jclass zz, jint pHandle) { BitMap **bmh= (BitMap**) pHandle; return (jint) (*bmh)->baseAddr;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/9d55940214dd65b869b66fbd78328ac944c2a750/swt.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/swt.c |
|
delete m_dcopClient; | DevicesProtocol::~DevicesProtocol(){ delete m_dcopClient;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/a776e4d46653adc584e0d589926f210dc4955ffc/kio_devices.cc/clean/kioslave/devices/kio_devices.cc |
|
debug_influence_move(int i, int j) | debug_influence_move(int move) | debug_influence_move(int i, int j){ debug_influence = POS(i, j);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/73949d47dd1205d5582cfa4a208927ea34c19956/influence.c/buggy/engine/influence.c |
debug_influence = POS(i, j); | debug_influence = move; | debug_influence_move(int i, int j){ debug_influence = POS(i, j);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/73949d47dd1205d5582cfa4a208927ea34c19956/influence.c/buggy/engine/influence.c |
for(pass = 0; pass < 4; pass++) { | for (pass = 0; pass < 4; pass++) { | attack2(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int hpos; int xpos; int liberties, r; int libs[2]; int libs2[2]; int adj, adjs[MAXCHAIN]; int savemove = 0; int savecode = 0; int dcode; int k; int atari_possible = 0; struct reading_moves moves; int adjacent_liberties = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack2", str); reading_node_counter++; moves.num = 0; str = find_origin(str); ASSERT1(IS_STONE(board[str]), str); ASSERT1(countlib(str) == 2, str); RTRACE("checking attack on %1m with 2 liberties\n", str); for(pass = 0; pass < 4; pass++) { if (pass == 0) { /* The attack may fail if a boundary string is in atari and cannot * be defended. First we must try defending such a string. * * We start by trying to defend the boundary string by looking for an * adjacent string which is in atari. */ adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { /* if stackp > depth and any boundary chain is in atari, assume safe. * However, if the captured chain is only of size 1, there can still * be a working ladder, so continue if that is the case. */ if (stackp > depth && countstones(adjs[r]) > 1) { RETURN_RESULT(0, 0, move, "boundary in atari"); } /* Pick up moves breaking the second order chain. */ if (stackp <= depth) break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Get the two liberties of (str). */ liberties = findlib(str, 2, libs); ASSERT1(liberties == 2, str); if (libs[0] == SOUTH(libs[1]) || libs[0] == WEST(libs[1]) || libs[0] == NORTH(libs[1]) || libs[0] == EAST(libs[1])) adjacent_liberties = 1; for (k = 0; k < 2; k++) { int apos = libs[k]; if (!is_self_atari(apos, other)) atari_possible = 1; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || ((stackp <= depth || adjacent_liberties) && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); /* If there is a neighbor in atari, we also try back-capturing. */ for (r = 0; r < 4; r++) { int bpos = libs2[0] + delta[r]; if (board[bpos] == other && chainlinks2(bpos, adjs, 1) > 0) { /* FIXME: If there is more than one neighbor in atari, we * currently just take one randomly. This is maybe not good * enough. We might also want to check against snapback. */ findlib(adjs[0], 1, &xpos); ADD_CANDIDATE_MOVE(xpos, 0, moves); } } } } /* If we can't make a direct atari, look for edge blocking moves. */ if (!atari_possible) for (k = 0; k < 2; k++) edge_block_moves(str, libs[k], &moves); /* If one of the surrounding chains have only two liberties, which * coincide with the liberties of the attacked string, we try to * backcapture. */ adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int apos = adjs[r]; if (liberty_of_string(libs[0], apos) && liberty_of_string(libs[1], apos)) break_chain_moves(apos, &moves); } propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { if (stackp <= backfill_depth) { special_attack2_moves(str, libs, &moves); special_attack3_moves(str, libs, &moves); special_attack4_moves(str, libs, &moves); } } if (pass == 2) { find_cap_moves(str, &moves); } if (pass != 3) { order_moves(str, &moves, other, read_function_name, saved_num_moves); for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; int apos = moves.pos[k]; if (komaster_trymove(apos, other, "attack2-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = apos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If it is not possible to make a direct atari, we try filling * a liberty of the superstring. */ if (level >= 10 && stackp <= backfill_depth && (stackp <= superstring_depth || !atari_possible)) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; int liberty_cap = 2; if (stackp <= backfill2_depth) liberty_cap = 3; find_superstring_liberties(str, &ss_liberties, ss_libs, liberty_cap); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack2-C", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling. */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack2-D", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } if (savecode == 0) { RTRACE("ALIVE!!\n"); RETURN_RESULT(0, 0, move, NULL); } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
|| !is_self_atari(apos, other)) | || !is_self_atari(apos, other)) | attack2(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int hpos; int xpos; int liberties, r; int libs[2]; int libs2[2]; int adj, adjs[MAXCHAIN]; int savemove = 0; int savecode = 0; int dcode; int k; int atari_possible = 0; struct reading_moves moves; int adjacent_liberties = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack2", str); reading_node_counter++; moves.num = 0; str = find_origin(str); ASSERT1(IS_STONE(board[str]), str); ASSERT1(countlib(str) == 2, str); RTRACE("checking attack on %1m with 2 liberties\n", str); for(pass = 0; pass < 4; pass++) { if (pass == 0) { /* The attack may fail if a boundary string is in atari and cannot * be defended. First we must try defending such a string. * * We start by trying to defend the boundary string by looking for an * adjacent string which is in atari. */ adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { /* if stackp > depth and any boundary chain is in atari, assume safe. * However, if the captured chain is only of size 1, there can still * be a working ladder, so continue if that is the case. */ if (stackp > depth && countstones(adjs[r]) > 1) { RETURN_RESULT(0, 0, move, "boundary in atari"); } /* Pick up moves breaking the second order chain. */ if (stackp <= depth) break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Get the two liberties of (str). */ liberties = findlib(str, 2, libs); ASSERT1(liberties == 2, str); if (libs[0] == SOUTH(libs[1]) || libs[0] == WEST(libs[1]) || libs[0] == NORTH(libs[1]) || libs[0] == EAST(libs[1])) adjacent_liberties = 1; for (k = 0; k < 2; k++) { int apos = libs[k]; if (!is_self_atari(apos, other)) atari_possible = 1; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || ((stackp <= depth || adjacent_liberties) && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); /* If there is a neighbor in atari, we also try back-capturing. */ for (r = 0; r < 4; r++) { int bpos = libs2[0] + delta[r]; if (board[bpos] == other && chainlinks2(bpos, adjs, 1) > 0) { /* FIXME: If there is more than one neighbor in atari, we * currently just take one randomly. This is maybe not good * enough. We might also want to check against snapback. */ findlib(adjs[0], 1, &xpos); ADD_CANDIDATE_MOVE(xpos, 0, moves); } } } } /* If we can't make a direct atari, look for edge blocking moves. */ if (!atari_possible) for (k = 0; k < 2; k++) edge_block_moves(str, libs[k], &moves); /* If one of the surrounding chains have only two liberties, which * coincide with the liberties of the attacked string, we try to * backcapture. */ adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int apos = adjs[r]; if (liberty_of_string(libs[0], apos) && liberty_of_string(libs[1], apos)) break_chain_moves(apos, &moves); } propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { if (stackp <= backfill_depth) { special_attack2_moves(str, libs, &moves); special_attack3_moves(str, libs, &moves); special_attack4_moves(str, libs, &moves); } } if (pass == 2) { find_cap_moves(str, &moves); } if (pass != 3) { order_moves(str, &moves, other, read_function_name, saved_num_moves); for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; int apos = moves.pos[k]; if (komaster_trymove(apos, other, "attack2-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = apos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If it is not possible to make a direct atari, we try filling * a liberty of the superstring. */ if (level >= 10 && stackp <= backfill_depth && (stackp <= superstring_depth || !atari_possible)) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; int liberty_cap = 2; if (stackp <= backfill2_depth) liberty_cap = 3; find_superstring_liberties(str, &ss_liberties, ss_libs, liberty_cap); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack2-C", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling. */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack2-D", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } if (savecode == 0) { RTRACE("ALIVE!!\n"); RETURN_RESULT(0, 0, move, NULL); } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; | if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; | attack3(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int adj, adjs[MAXCHAIN]; int xpos; int liberties; int libs[3]; int r; int dcode = 0; int k; struct reading_moves moves; int savemove = 0; int savecode = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack3", str); reading_node_counter++; moves.num = 0; gg_assert(IS_STONE(board[str])); if (stackp > depth) RETURN_RESULT(0, 0, move, "stackp > depth"); for (pass = 0; pass < 4; pass++) { if (pass == 0) { adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { int hpos; break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Defend against double atari in the surrounding chain early. */ double_atari_chain2_moves(str, &moves); /* Get the three liberties of (str). */ liberties = findlib(str, 3, libs); ASSERT1(liberties == 3, str); for (k = 0; k < 3; k++) {#if 0 int libs2[2];#endif int apos = libs[k]; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || (stackp <= depth && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); edge_closing_backfill_moves(str, apos, &moves);#if 0 /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); }#endif /* Look for edge blocking moves. */ edge_block_moves(str, apos, &moves); } /* Pick up some edge moves. */ propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { /* The simple ataris didn't work. Try something more fancy. */ if (stackp <= backfill_depth) { find_cap_moves(str, &moves); } if (stackp <= fourlib_depth) { draw_back_moves(str, &moves); } } if (pass == 2) { /* Try to defend chain links with two liberties. */ if (stackp <= backfill2_depth) { adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int libs2[2]; findlib(adjs[r], 2, libs2); if (approxlib(libs2[0], other, 4, NULL) > 3 && approxlib(libs2[1], other, 4, NULL) > 3) continue; break_chain_moves(adjs[r], &moves); break_chain2_moves(adjs[r], &moves, 1); for (k = 0; k < 2; k++) ADD_CANDIDATE_MOVE(libs2[k], 0, moves); } } } if (pass == 0 || pass == 1 || pass == 2) { order_moves(str, &moves, other, read_function_name, saved_num_moves); /* Try the moves collected so far. */ for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; if (stackp >= branch_depth && k > 0) break; xpos = moves.pos[k]; if (komaster_trymove(xpos, other, "attack3-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = xpos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { | find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { | attack3(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int adj, adjs[MAXCHAIN]; int xpos; int liberties; int libs[3]; int r; int dcode = 0; int k; struct reading_moves moves; int savemove = 0; int savecode = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack3", str); reading_node_counter++; moves.num = 0; gg_assert(IS_STONE(board[str])); if (stackp > depth) RETURN_RESULT(0, 0, move, "stackp > depth"); for (pass = 0; pass < 4; pass++) { if (pass == 0) { adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { int hpos; break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Defend against double atari in the surrounding chain early. */ double_atari_chain2_moves(str, &moves); /* Get the three liberties of (str). */ liberties = findlib(str, 3, libs); ASSERT1(liberties == 3, str); for (k = 0; k < 3; k++) {#if 0 int libs2[2];#endif int apos = libs[k]; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || (stackp <= depth && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); edge_closing_backfill_moves(str, apos, &moves);#if 0 /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); }#endif /* Look for edge blocking moves. */ edge_block_moves(str, apos, &moves); } /* Pick up some edge moves. */ propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { /* The simple ataris didn't work. Try something more fancy. */ if (stackp <= backfill_depth) { find_cap_moves(str, &moves); } if (stackp <= fourlib_depth) { draw_back_moves(str, &moves); } } if (pass == 2) { /* Try to defend chain links with two liberties. */ if (stackp <= backfill2_depth) { adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int libs2[2]; findlib(adjs[r], 2, libs2); if (approxlib(libs2[0], other, 4, NULL) > 3 && approxlib(libs2[1], other, 4, NULL) > 3) continue; break_chain_moves(adjs[r], &moves); break_chain2_moves(adjs[r], &moves, 1); for (k = 0; k < 2; k++) ADD_CANDIDATE_MOVE(libs2[k], 0, moves); } } } if (pass == 0 || pass == 1 || pass == 2) { order_moves(str, &moves, other, read_function_name, saved_num_moves); /* Try the moves collected so far. */ for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; if (stackp >= branch_depth && k > 0) break; xpos = moves.pos[k]; if (komaster_trymove(xpos, other, "attack3-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = xpos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); | CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); | attack3(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int adj, adjs[MAXCHAIN]; int xpos; int liberties; int libs[3]; int r; int dcode = 0; int k; struct reading_moves moves; int savemove = 0; int savecode = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack3", str); reading_node_counter++; moves.num = 0; gg_assert(IS_STONE(board[str])); if (stackp > depth) RETURN_RESULT(0, 0, move, "stackp > depth"); for (pass = 0; pass < 4; pass++) { if (pass == 0) { adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { int hpos; break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Defend against double atari in the surrounding chain early. */ double_atari_chain2_moves(str, &moves); /* Get the three liberties of (str). */ liberties = findlib(str, 3, libs); ASSERT1(liberties == 3, str); for (k = 0; k < 3; k++) {#if 0 int libs2[2];#endif int apos = libs[k]; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || (stackp <= depth && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); edge_closing_backfill_moves(str, apos, &moves);#if 0 /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); }#endif /* Look for edge blocking moves. */ edge_block_moves(str, apos, &moves); } /* Pick up some edge moves. */ propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { /* The simple ataris didn't work. Try something more fancy. */ if (stackp <= backfill_depth) { find_cap_moves(str, &moves); } if (stackp <= fourlib_depth) { draw_back_moves(str, &moves); } } if (pass == 2) { /* Try to defend chain links with two liberties. */ if (stackp <= backfill2_depth) { adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int libs2[2]; findlib(adjs[r], 2, libs2); if (approxlib(libs2[0], other, 4, NULL) > 3 && approxlib(libs2[1], other, 4, NULL) > 3) continue; break_chain_moves(adjs[r], &moves); break_chain2_moves(adjs[r], &moves, 1); for (k = 0; k < 2; k++) ADD_CANDIDATE_MOVE(libs2[k], 0, moves); } } } if (pass == 0 || pass == 1 || pass == 2) { order_moves(str, &moves, other, read_function_name, saved_num_moves); /* Try the moves collected so far. */ for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; if (stackp >= branch_depth && k > 0) break; xpos = moves.pos[k]; if (komaster_trymove(xpos, other, "attack3-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = xpos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); | attack3(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int adj, adjs[MAXCHAIN]; int xpos; int liberties; int libs[3]; int r; int dcode = 0; int k; struct reading_moves moves; int savemove = 0; int savecode = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack3", str); reading_node_counter++; moves.num = 0; gg_assert(IS_STONE(board[str])); if (stackp > depth) RETURN_RESULT(0, 0, move, "stackp > depth"); for (pass = 0; pass < 4; pass++) { if (pass == 0) { adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { int hpos; break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Defend against double atari in the surrounding chain early. */ double_atari_chain2_moves(str, &moves); /* Get the three liberties of (str). */ liberties = findlib(str, 3, libs); ASSERT1(liberties == 3, str); for (k = 0; k < 3; k++) {#if 0 int libs2[2];#endif int apos = libs[k]; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || (stackp <= depth && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); edge_closing_backfill_moves(str, apos, &moves);#if 0 /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); }#endif /* Look for edge blocking moves. */ edge_block_moves(str, apos, &moves); } /* Pick up some edge moves. */ propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { /* The simple ataris didn't work. Try something more fancy. */ if (stackp <= backfill_depth) { find_cap_moves(str, &moves); } if (stackp <= fourlib_depth) { draw_back_moves(str, &moves); } } if (pass == 2) { /* Try to defend chain links with two liberties. */ if (stackp <= backfill2_depth) { adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int libs2[2]; findlib(adjs[r], 2, libs2); if (approxlib(libs2[0], other, 4, NULL) > 3 && approxlib(libs2[1], other, 4, NULL) > 3) continue; break_chain_moves(adjs[r], &moves); break_chain2_moves(adjs[r], &moves, 1); for (k = 0; k < 2; k++) ADD_CANDIDATE_MOVE(libs2[k], 0, moves); } } } if (pass == 0 || pass == 1 || pass == 2) { order_moves(str, &moves, other, read_function_name, saved_num_moves); /* Try the moves collected so far. */ for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; if (stackp >= branch_depth && k > 0) break; xpos = moves.pos[k]; if (komaster_trymove(xpos, other, "attack3-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = xpos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
|
} } | attack3(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int adj, adjs[MAXCHAIN]; int xpos; int liberties; int libs[3]; int r; int dcode = 0; int k; struct reading_moves moves; int savemove = 0; int savecode = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack3", str); reading_node_counter++; moves.num = 0; gg_assert(IS_STONE(board[str])); if (stackp > depth) RETURN_RESULT(0, 0, move, "stackp > depth"); for (pass = 0; pass < 4; pass++) { if (pass == 0) { adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { int hpos; break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Defend against double atari in the surrounding chain early. */ double_atari_chain2_moves(str, &moves); /* Get the three liberties of (str). */ liberties = findlib(str, 3, libs); ASSERT1(liberties == 3, str); for (k = 0; k < 3; k++) {#if 0 int libs2[2];#endif int apos = libs[k]; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || (stackp <= depth && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); edge_closing_backfill_moves(str, apos, &moves);#if 0 /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves); }#endif /* Look for edge blocking moves. */ edge_block_moves(str, apos, &moves); } /* Pick up some edge moves. */ propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { /* The simple ataris didn't work. Try something more fancy. */ if (stackp <= backfill_depth) { find_cap_moves(str, &moves); } if (stackp <= fourlib_depth) { draw_back_moves(str, &moves); } } if (pass == 2) { /* Try to defend chain links with two liberties. */ if (stackp <= backfill2_depth) { adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { int libs2[2]; findlib(adjs[r], 2, libs2); if (approxlib(libs2[0], other, 4, NULL) > 3 && approxlib(libs2[1], other, 4, NULL) > 3) continue; break_chain_moves(adjs[r], &moves); break_chain2_moves(adjs[r], &moves, 1); for (k = 0; k < 2; k++) ADD_CANDIDATE_MOVE(libs2[k], 0, moves); } } } if (pass == 0 || pass == 1 || pass == 2) { order_moves(str, &moves, other, read_function_name, saved_num_moves); /* Try the moves collected so far. */ for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; if (stackp >= branch_depth && k > 0) break; xpos = moves.pos[k]; if (komaster_trymove(xpos, other, "attack3-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = xpos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } if (pass == 3) { /* If nothing else works, we try filling a liberty of the * super_string. */ if (level >= 10 && stackp <= backfill2_depth) { int ss_liberties; int ss_libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &ss_liberties, ss_libs, 3); if (ss_liberties <= 5) { for (k = 0; k < ss_liberties; k++) { int apos = ss_libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack3-E", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, apos, move, "attack effective"); } else popgo(); } } } } } } } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
|
if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { | if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { | attack4(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int xpos; int r; int k; int liberties; int libs[4]; int adj, adjs[MAXCHAIN]; int dcode = 0; struct reading_moves moves; int savemove = 0; int savecode = 0; int pass; int saved_num_moves = 0; SETUP_TRACE_INFO("attack4", str); gg_assert(IS_STONE(board[str])); reading_node_counter++; moves.num = 0; if (stackp > depth) { SGFTRACE(0, 0, "stackp > depth"); return 0; } for (pass = 0; pass < 2; pass++) { if (pass == 0) { adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { int hpos; break_chain_moves(adjs[r], &moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves); } /* Defend against double atari in the surrounding chain early. */ double_atari_chain2_moves(str, &moves); /* Give a score bonus to the chain preserving moves. */ for (k = 0; k < moves.num; k++) moves.score[k] += 5; /* Get the four liberties of (str). */ liberties = findlib(str, 4, libs); ASSERT1(liberties == 4, str); for (k = 0; k < 4; k++) { int apos = libs[k]; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || (stackp <= depth && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves); edge_closing_backfill_moves(str, apos, &moves); /* Look for edge blocking moves. */ edge_block_moves(str, apos, &moves); } /* Pick up some edge moves. */ propose_edge_moves(str, libs, liberties, &moves, other); } if (pass == 1) { if (stackp <= backfill_depth) { find_cap_moves(str, &moves); } } if (pass == 0 || pass == 1) { order_moves(str, &moves, other, read_function_name, saved_num_moves); /* Try the moves collected so far. */ for (k = saved_num_moves; k < moves.num; k++) { int new_komaster; int new_kom_pos; int ko_move; if (stackp >= branch_depth && k > 0) break; xpos = moves.pos[k]; /* Conditional ko capture is disabled * because it seems too expensive. * */ if (komaster_trymove(xpos, other, "attack4-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, 0 && stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { popgo(); CHECK_RESULT(savecode, savemove, dcode, xpos, move, "attack effective"); } else popgo(); } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = xpos; savecode = KO_B; } popgo(); } } } saved_num_moves = moves.num; } } RETURN_RESULT(savecode, savemove, move, "saved move");} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/abc11423588186d21ff8a7e74d25043d4bb26820/reading.c/buggy/engine/reading.c |
lpStruct->hwndTrack = (HWND)(*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.hwndTrack); lpStruct->dwFlags = (*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.dwFlags); lpStruct->cbSize = (*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.cbSize); | TRACKMOUSEEVENT *getTRACKMOUSEEVENTFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpStruct){ if (!TRACKMOUSEEVENTFc.cached) cacheTRACKMOUSEEVENTFields(env, lpObject); lpStruct->dwHoverTime = (*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.dwHoverTime); lpStruct->hwndTrack = (HWND)(*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.hwndTrack); lpStruct->dwFlags = (*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.dwFlags); lpStruct->cbSize = (*env)->GetIntField(env, lpObject, TRACKMOUSEEVENTFc.cbSize); return lpStruct;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
extern "C" QgisPlugin * classFactory(){ return new QgisTestPlugin(); | extern "C" QgisPlugin * classFactory(QWidget *qgis){ return new QgisTestPlugin(qgis); | extern "C" QgisPlugin * classFactory(){ return new QgisTestPlugin();} | 1753 /local/tlutelli/issta_data/temp/c/2005_temp/2005/1753/917c05f525ac1e09cbe78373a6ae03fdd4b5b90a/qgistestplugin.cpp/buggy/plugins/qgistestplugin.cpp |
lpStruct->UpperLeft = (*env)->GetIntField(env, lpObject, GRADIENT_RECTFc.UpperLeft); | GRADIENT_RECT *getGRADIENT_RECTFields(JNIEnv *env, jobject lpObject, GRADIENT_RECT *lpStruct){ if (!GRADIENT_RECTFc.cached) cacheGRADIENT_RECTFields(env, lpObject); lpStruct->LowerRight = (*env)->GetIntField(env, lpObject, GRADIENT_RECTFc.LowerRight); lpStruct->UpperLeft = (*env)->GetIntField(env, lpObject, GRADIENT_RECTFc.UpperLeft); return lpStruct;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
size_t get_dirty_size() { return dirty_size; } | unsigned long long get_dirty_size() { return dirty_size; } | size_t get_dirty_size() { return dirty_size; } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/98d20ecf3abc9fcecac9169f9ccc60f8d1d235dd/Buffercache.h/buggy/ceph/client/Buffercache.h |
void clean_to_dirty(size_t size) { | void clean_to_dirty(unsigned long long size) { | void clean_to_dirty(size_t size) { clean_size -= size; assert(clean_size >= 0); dirty_size += size; } | 2690 /local/tlutelli/issta_data/temp/c/2005_temp/2005/2690/98d20ecf3abc9fcecac9169f9ccc60f8d1d235dd/Buffercache.h/buggy/ceph/client/Buffercache.h |
lpStruct->nGlyphs = (*env)->GetIntField(env, lpObject, GCP_RESULTSFc.nGlyphs); lpStruct->lpGlyphs = (LPWSTR)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpGlyphs); lpStruct->lpClass = (LPSTR)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpClass); lpStruct->lpCaretPos = (int *)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpCaretPos); lpStruct->lpDx = (int *)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpDx); lpStruct->lpOrder = (UINT *)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpOrder); lpStruct->lpOutString = (LPTSTR)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpOutString); lpStruct->lStructSize = (*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lStructSize); | GCP_RESULTS *getGCP_RESULTSFields(JNIEnv *env, jobject lpObject, GCP_RESULTS *lpStruct){ if (!GCP_RESULTSFc.cached) cacheGCP_RESULTSFields(env, lpObject); lpStruct->nMaxFit = (*env)->GetIntField(env, lpObject, GCP_RESULTSFc.nMaxFit); lpStruct->nGlyphs = (*env)->GetIntField(env, lpObject, GCP_RESULTSFc.nGlyphs); lpStruct->lpGlyphs = (LPWSTR)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpGlyphs); lpStruct->lpClass = (LPSTR)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpClass); lpStruct->lpCaretPos = (int *)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpCaretPos); lpStruct->lpDx = (int *)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpDx); lpStruct->lpOrder = (UINT *)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpOrder); lpStruct->lpOutString = (LPTSTR)(*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lpOutString); lpStruct->lStructSize = (*env)->GetIntField(env, lpObject, GCP_RESULTSFc.lStructSize); return lpStruct;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
lpStruct->dwLowDateTime = (*env)->GetIntField(env, lpObject, FILETIMEFc.dwLowDateTime); | FILETIME *getFILETIMEFields(JNIEnv *env, jobject lpObject, FILETIME *lpStruct){ if (!FILETIMEFc.cached) cacheFILETIMEFields(env, lpObject); lpStruct->dwHighDateTime = (*env)->GetIntField(env, lpObject, FILETIMEFc.dwHighDateTime); lpStruct->dwLowDateTime = (*env)->GetIntField(env, lpObject, FILETIMEFc.dwLowDateTime); return lpStruct;} | 11867 /local/tlutelli/issta_data/temp/c/2005_temp/2005/11867/87f953c8eda7bc7ceddf6227acc0065974196814/structs.c/buggy/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/structs.c |
|
struct local_owl_data saved_owl; | do_owl_defend(int m, int n, int *ui, int *uj, struct local_owl_data *owl, int komaster, int kom_i, int kom_j){ struct owl_move_data shape_moves[MAX_MOVES]; struct owl_move_data vital_moves[MAX_MOVES]; struct owl_move_data *moves; char mw[MAX_BOARD][MAX_BOARD]; int number_tried_moves = 0; int pass; struct local_owl_data saved_owl; int k; int savei = -1; int savej = -1; int savecode = 0; int true_genus = -1; int probable_min = -1; int probable_max = -1; int move_cutoff; int color = p[m][n]; int other = OTHER_COLOR(color); int acode; int found_read_result; Read_result * read_result; int this_variation_number = count_variations - 1; SETUP_TRACE_INFO("owl_defend", m, n); if ((stackp <= owl_branch_depth) && (hashflags & HASH_OWL_DEFEND)) { found_read_result = get_read_result(OWL_DEFEND, komaster, kom_i, kom_j, &m, &n, &read_result); if (found_read_result) { TRACE_CACHED_RESULT(*read_result); if (rr_get_result(*read_result) != 0) { if (ui) *ui = FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)); if (uj) *uj = FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)); } if (rr_get_result(*read_result) == WIN) TRACE("%oVariation %d: ALIVE (cached)\n", this_variation_number); else TRACE("%oVariation %d: DEAD (cached)\n", this_variation_number); SGFTRACE(FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)), FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)), rr_get_result(*read_result), "cached"); return rr_get_result(*read_result); } /* This data should always be recorded. */ if (read_result) { rr_set_compressed_data(*read_result, OWL_DEFEND, komaster, kom_i, kom_j, m, n, stackp); } } else read_result = NULL; /* In order to get a defense move even if we seem to already have * escaped and to reduce the impact of overestimated escape * possibilities, we don't declare escape victory on the first move. * * FIXME: Should introduce a new owl depth value rather than having * this hardwired value. */ if (stackp > 2 && owl_escape_route(owl) >= 5) { /* FIXME: We probably should make distinction in the returned * result whether the dragon lives by making two eyes or by * escaping. */ TRACE("%oVariation %d: ALIVE (escaped)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "escaped"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If (stackp > owl_reading_depth), interpret deep reading * conservatively as escape. */ if (stackp > owl_reading_depth) { TRACE("%oVariation %d: ALIVE (maximum reading depth reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "max reading depth reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If the owl node limit has been reached, assume the dragon has * managed to escape. */ if (owl->local_owl_node_counter >= owl_node_limit) { result_certain = 0; TRACE("%oVariation %d: ALIVE (owl node limit reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "owl node limit reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } memset(mw, 0, sizeof(mw)); owl->local_owl_node_counter++; global_owl_node_counter++; /* Always start with picking up the vital moves so we can see if * we already are safe. */ { SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (color == BLACK) true_genus = owl_determine_life(owl, owl->black_eye, BLACK, komaster, 0, vital_moves, &probable_min, &probable_max); else true_genus = owl_determine_life(owl, owl->white_eye, WHITE, komaster, 0, vital_moves, &probable_min, &probable_max); current_owl_data = owl; memset(owl_safe_move_cache, 0, sizeof(owl_safe_move_cache)); /* We don't care about the moves, just whether matches are found. * The content of shape_moves[] will be discarded when we call * owl_shapes(). */ for (k = 0; k < MAX_MOVES; k++) { shape_moves[k].i = -1; shape_moves[k].j = -1; shape_moves[k].value = -1; shape_moves[k].name = NULL; shape_moves[k].same_dragon = 1; } matches_found = 0; memset(found_matches, 0, sizeof(found_matches)); if (level >= 9) global_matchpat(owl_shapes_callback, other, &owl_vital_apat_db, shape_moves, owl->goal); true_genus -= matches_found; sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; if (true_genus >= 2 || (true_genus == 1 && probable_min >= 4) || (stackp > owl_distrust_depth && probable_min >= 2 && !matches_found)) { TRACE("%oVariation %d: ALIVE (2 or more secure eyes)\n", this_variation_number, true_genus); SGFTRACE(-1, -1, WIN, "2 or more secure eyes"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } } saved_owl = *owl; /* struct copy */ /* We try moves in four passes. * stackp==0 stackp>0 * 0. Vital moves in the interval [70..] [45..] * 1. Shape moves * 2. Vital moves in the interval [..69] [..44] * 3. Tactical defense moves */ for (pass = 0; pass < 4; pass++) { moves = NULL; move_cutoff = 1; /* Get the shape moves if we are in the right pass. */ if (pass == 1) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; owl_shapes(shape_moves, color, owl, &owl_defendpat_db); /* A move of value 100 is considered a win */ if (shape_moves[0].value >= 100) { /* to make sure this move is recorded in the sgf file */ if (trymove(shape_moves[0].i, shape_moves[0].j, color, shape_moves[0].name, m, n, komaster, kom_i, kom_j)) popgo(); TRACE("%oVariation %d: ALIVE (Winning owl_defendpat)\n", this_variation_number); SGFTRACE(shape_moves[0].i, shape_moves[0].j, WIN, "winning defense pattern"); READ_RETURN(read_result, ui, uj, shape_moves[0].i, shape_moves[0].j, WIN); } moves = shape_moves; } else if (pass == 0 || pass == 2) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; moves = vital_moves; if (pass == 0 || stackp > owl_distrust_depth) { if (stackp == 0) move_cutoff = 70; else if (true_genus + probable_min >= 3) move_cutoff = 25; else move_cutoff = 45; } if (probable_max < 2 && stackp > 2) move_cutoff = 99; /* Effectively disable vital moves. */ } else { /* Look for a tactical defense. This is primarily intended for * the case where the whole dragon is a single string, therefore * we only look at the string at the "origin". * * We only accept clearly effective tactical defenses here, * using a liberty heuristic. The reason for this is problems * with ineffective self ataris which do defend tactically but * have no strategical effect other than wasting owl nodes or * confusing the eye analysis. */ int di, dj; SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (attack_and_defend(m, n, NULL, NULL, NULL, NULL, &di, &dj) && (approxlib(di, dj, color, 2, NULL, NULL) > 1 || does_capture_something(di, dj, color))) { shape_moves[0].i = di; shape_moves[0].j = dj; shape_moves[0].value = 25; shape_moves[0].name = "tactical defense"; shape_moves[0].same_dragon = 2; shape_moves[1].value = 0; moves = shape_moves; } sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; } if (!moves) continue; /* For the up to MAX_MOVES best moves with value equal to * move_cutoff or higher, try to defend the dragon and see if it * can then be attacked. */ for (k = 0; k < MAX_MOVES; k++) { int mi, mj; int new_komaster, new_kom_i, new_kom_j; int ko_move = -1; if (moves[k].value < move_cutoff) break; mi = moves[k].i; mj = moves[k].j; ASSERT(ON_BOARD(mi, mj), mi, mj); /* Consider only the highest scoring move if we're deeper than * owl_branch_depth. */ if (stackp > owl_branch_depth && k > 0) break; gg_assert(mi != -1); /* Have we already tested this move? */ if (mw[mi][mj]) continue; /* Try to make the move. */ if (!komaster_trymove(mi, mj, color, moves[k].name, m, n, komaster, kom_i, kom_j, &new_komaster, &new_kom_i, &new_kom_j, &ko_move, savecode == 0)) continue; TRACE("Trying %C %m\n", color, mi, mj); /* We have now made a move. Analyze the new position. */ mw[mi][mj] = 1; number_tried_moves++; owl->lunches_are_current = 0; /* Add the stone just played to the goal dragon, unless the * pattern explicitly asked for not doing this. */ owl_update_goal(mi, mj, moves[k].same_dragon, owl); if (!ko_move) { acode = do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j); if (!acode) { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; popgo(); SGFTRACE(mi, mj, WIN, "defense effective - A"); READ_RETURN(read_result, ui, uj, mi, mj, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savei, savej, acode, mi, mj); } else { if (do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j) != WIN) { savei = mi; savej = mj; savecode = KO_B; } } /* Undo the tested move. */ { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; } popgo(); } } if (savecode) { SGFTRACE(savei, savej, savecode, "defense effective (ko) - B"); READ_RETURN(read_result, ui, uj, savei, savej, savecode); } if (number_tried_moves == 0 && probable_min >= 2) { SGFTRACE(-1, -1, WIN, "genus probably >= 2"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } if (true_genus == 1) { SGFTRACE(-1, -1, 0, "genus 1"); } else { SGFTRACE(-1, -1, 0, "genus 0"); } READ_RETURN0(read_result);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/d09fc69f7c667532f8c354dff921cd0f9d6a03fe/owl.c/clean/engine/owl.c |
|
saved_owl = *owl; /* struct copy */ | do_owl_defend(int m, int n, int *ui, int *uj, struct local_owl_data *owl, int komaster, int kom_i, int kom_j){ struct owl_move_data shape_moves[MAX_MOVES]; struct owl_move_data vital_moves[MAX_MOVES]; struct owl_move_data *moves; char mw[MAX_BOARD][MAX_BOARD]; int number_tried_moves = 0; int pass; struct local_owl_data saved_owl; int k; int savei = -1; int savej = -1; int savecode = 0; int true_genus = -1; int probable_min = -1; int probable_max = -1; int move_cutoff; int color = p[m][n]; int other = OTHER_COLOR(color); int acode; int found_read_result; Read_result * read_result; int this_variation_number = count_variations - 1; SETUP_TRACE_INFO("owl_defend", m, n); if ((stackp <= owl_branch_depth) && (hashflags & HASH_OWL_DEFEND)) { found_read_result = get_read_result(OWL_DEFEND, komaster, kom_i, kom_j, &m, &n, &read_result); if (found_read_result) { TRACE_CACHED_RESULT(*read_result); if (rr_get_result(*read_result) != 0) { if (ui) *ui = FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)); if (uj) *uj = FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)); } if (rr_get_result(*read_result) == WIN) TRACE("%oVariation %d: ALIVE (cached)\n", this_variation_number); else TRACE("%oVariation %d: DEAD (cached)\n", this_variation_number); SGFTRACE(FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)), FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)), rr_get_result(*read_result), "cached"); return rr_get_result(*read_result); } /* This data should always be recorded. */ if (read_result) { rr_set_compressed_data(*read_result, OWL_DEFEND, komaster, kom_i, kom_j, m, n, stackp); } } else read_result = NULL; /* In order to get a defense move even if we seem to already have * escaped and to reduce the impact of overestimated escape * possibilities, we don't declare escape victory on the first move. * * FIXME: Should introduce a new owl depth value rather than having * this hardwired value. */ if (stackp > 2 && owl_escape_route(owl) >= 5) { /* FIXME: We probably should make distinction in the returned * result whether the dragon lives by making two eyes or by * escaping. */ TRACE("%oVariation %d: ALIVE (escaped)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "escaped"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If (stackp > owl_reading_depth), interpret deep reading * conservatively as escape. */ if (stackp > owl_reading_depth) { TRACE("%oVariation %d: ALIVE (maximum reading depth reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "max reading depth reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If the owl node limit has been reached, assume the dragon has * managed to escape. */ if (owl->local_owl_node_counter >= owl_node_limit) { result_certain = 0; TRACE("%oVariation %d: ALIVE (owl node limit reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "owl node limit reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } memset(mw, 0, sizeof(mw)); owl->local_owl_node_counter++; global_owl_node_counter++; /* Always start with picking up the vital moves so we can see if * we already are safe. */ { SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (color == BLACK) true_genus = owl_determine_life(owl, owl->black_eye, BLACK, komaster, 0, vital_moves, &probable_min, &probable_max); else true_genus = owl_determine_life(owl, owl->white_eye, WHITE, komaster, 0, vital_moves, &probable_min, &probable_max); current_owl_data = owl; memset(owl_safe_move_cache, 0, sizeof(owl_safe_move_cache)); /* We don't care about the moves, just whether matches are found. * The content of shape_moves[] will be discarded when we call * owl_shapes(). */ for (k = 0; k < MAX_MOVES; k++) { shape_moves[k].i = -1; shape_moves[k].j = -1; shape_moves[k].value = -1; shape_moves[k].name = NULL; shape_moves[k].same_dragon = 1; } matches_found = 0; memset(found_matches, 0, sizeof(found_matches)); if (level >= 9) global_matchpat(owl_shapes_callback, other, &owl_vital_apat_db, shape_moves, owl->goal); true_genus -= matches_found; sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; if (true_genus >= 2 || (true_genus == 1 && probable_min >= 4) || (stackp > owl_distrust_depth && probable_min >= 2 && !matches_found)) { TRACE("%oVariation %d: ALIVE (2 or more secure eyes)\n", this_variation_number, true_genus); SGFTRACE(-1, -1, WIN, "2 or more secure eyes"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } } saved_owl = *owl; /* struct copy */ /* We try moves in four passes. * stackp==0 stackp>0 * 0. Vital moves in the interval [70..] [45..] * 1. Shape moves * 2. Vital moves in the interval [..69] [..44] * 3. Tactical defense moves */ for (pass = 0; pass < 4; pass++) { moves = NULL; move_cutoff = 1; /* Get the shape moves if we are in the right pass. */ if (pass == 1) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; owl_shapes(shape_moves, color, owl, &owl_defendpat_db); /* A move of value 100 is considered a win */ if (shape_moves[0].value >= 100) { /* to make sure this move is recorded in the sgf file */ if (trymove(shape_moves[0].i, shape_moves[0].j, color, shape_moves[0].name, m, n, komaster, kom_i, kom_j)) popgo(); TRACE("%oVariation %d: ALIVE (Winning owl_defendpat)\n", this_variation_number); SGFTRACE(shape_moves[0].i, shape_moves[0].j, WIN, "winning defense pattern"); READ_RETURN(read_result, ui, uj, shape_moves[0].i, shape_moves[0].j, WIN); } moves = shape_moves; } else if (pass == 0 || pass == 2) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; moves = vital_moves; if (pass == 0 || stackp > owl_distrust_depth) { if (stackp == 0) move_cutoff = 70; else if (true_genus + probable_min >= 3) move_cutoff = 25; else move_cutoff = 45; } if (probable_max < 2 && stackp > 2) move_cutoff = 99; /* Effectively disable vital moves. */ } else { /* Look for a tactical defense. This is primarily intended for * the case where the whole dragon is a single string, therefore * we only look at the string at the "origin". * * We only accept clearly effective tactical defenses here, * using a liberty heuristic. The reason for this is problems * with ineffective self ataris which do defend tactically but * have no strategical effect other than wasting owl nodes or * confusing the eye analysis. */ int di, dj; SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (attack_and_defend(m, n, NULL, NULL, NULL, NULL, &di, &dj) && (approxlib(di, dj, color, 2, NULL, NULL) > 1 || does_capture_something(di, dj, color))) { shape_moves[0].i = di; shape_moves[0].j = dj; shape_moves[0].value = 25; shape_moves[0].name = "tactical defense"; shape_moves[0].same_dragon = 2; shape_moves[1].value = 0; moves = shape_moves; } sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; } if (!moves) continue; /* For the up to MAX_MOVES best moves with value equal to * move_cutoff or higher, try to defend the dragon and see if it * can then be attacked. */ for (k = 0; k < MAX_MOVES; k++) { int mi, mj; int new_komaster, new_kom_i, new_kom_j; int ko_move = -1; if (moves[k].value < move_cutoff) break; mi = moves[k].i; mj = moves[k].j; ASSERT(ON_BOARD(mi, mj), mi, mj); /* Consider only the highest scoring move if we're deeper than * owl_branch_depth. */ if (stackp > owl_branch_depth && k > 0) break; gg_assert(mi != -1); /* Have we already tested this move? */ if (mw[mi][mj]) continue; /* Try to make the move. */ if (!komaster_trymove(mi, mj, color, moves[k].name, m, n, komaster, kom_i, kom_j, &new_komaster, &new_kom_i, &new_kom_j, &ko_move, savecode == 0)) continue; TRACE("Trying %C %m\n", color, mi, mj); /* We have now made a move. Analyze the new position. */ mw[mi][mj] = 1; number_tried_moves++; owl->lunches_are_current = 0; /* Add the stone just played to the goal dragon, unless the * pattern explicitly asked for not doing this. */ owl_update_goal(mi, mj, moves[k].same_dragon, owl); if (!ko_move) { acode = do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j); if (!acode) { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; popgo(); SGFTRACE(mi, mj, WIN, "defense effective - A"); READ_RETURN(read_result, ui, uj, mi, mj, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savei, savej, acode, mi, mj); } else { if (do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j) != WIN) { savei = mi; savej = mj; savecode = KO_B; } } /* Undo the tested move. */ { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; } popgo(); } } if (savecode) { SGFTRACE(savei, savej, savecode, "defense effective (ko) - B"); READ_RETURN(read_result, ui, uj, savei, savej, savecode); } if (number_tried_moves == 0 && probable_min >= 2) { SGFTRACE(-1, -1, WIN, "genus probably >= 2"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } if (true_genus == 1) { SGFTRACE(-1, -1, 0, "genus 1"); } else { SGFTRACE(-1, -1, 0, "genus 0"); } READ_RETURN0(read_result);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/d09fc69f7c667532f8c354dff921cd0f9d6a03fe/owl.c/clean/engine/owl.c |
|
int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; | pop_owl(owl); | do_owl_defend(int m, int n, int *ui, int *uj, struct local_owl_data *owl, int komaster, int kom_i, int kom_j){ struct owl_move_data shape_moves[MAX_MOVES]; struct owl_move_data vital_moves[MAX_MOVES]; struct owl_move_data *moves; char mw[MAX_BOARD][MAX_BOARD]; int number_tried_moves = 0; int pass; struct local_owl_data saved_owl; int k; int savei = -1; int savej = -1; int savecode = 0; int true_genus = -1; int probable_min = -1; int probable_max = -1; int move_cutoff; int color = p[m][n]; int other = OTHER_COLOR(color); int acode; int found_read_result; Read_result * read_result; int this_variation_number = count_variations - 1; SETUP_TRACE_INFO("owl_defend", m, n); if ((stackp <= owl_branch_depth) && (hashflags & HASH_OWL_DEFEND)) { found_read_result = get_read_result(OWL_DEFEND, komaster, kom_i, kom_j, &m, &n, &read_result); if (found_read_result) { TRACE_CACHED_RESULT(*read_result); if (rr_get_result(*read_result) != 0) { if (ui) *ui = FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)); if (uj) *uj = FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)); } if (rr_get_result(*read_result) == WIN) TRACE("%oVariation %d: ALIVE (cached)\n", this_variation_number); else TRACE("%oVariation %d: DEAD (cached)\n", this_variation_number); SGFTRACE(FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)), FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)), rr_get_result(*read_result), "cached"); return rr_get_result(*read_result); } /* This data should always be recorded. */ if (read_result) { rr_set_compressed_data(*read_result, OWL_DEFEND, komaster, kom_i, kom_j, m, n, stackp); } } else read_result = NULL; /* In order to get a defense move even if we seem to already have * escaped and to reduce the impact of overestimated escape * possibilities, we don't declare escape victory on the first move. * * FIXME: Should introduce a new owl depth value rather than having * this hardwired value. */ if (stackp > 2 && owl_escape_route(owl) >= 5) { /* FIXME: We probably should make distinction in the returned * result whether the dragon lives by making two eyes or by * escaping. */ TRACE("%oVariation %d: ALIVE (escaped)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "escaped"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If (stackp > owl_reading_depth), interpret deep reading * conservatively as escape. */ if (stackp > owl_reading_depth) { TRACE("%oVariation %d: ALIVE (maximum reading depth reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "max reading depth reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If the owl node limit has been reached, assume the dragon has * managed to escape. */ if (owl->local_owl_node_counter >= owl_node_limit) { result_certain = 0; TRACE("%oVariation %d: ALIVE (owl node limit reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "owl node limit reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } memset(mw, 0, sizeof(mw)); owl->local_owl_node_counter++; global_owl_node_counter++; /* Always start with picking up the vital moves so we can see if * we already are safe. */ { SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (color == BLACK) true_genus = owl_determine_life(owl, owl->black_eye, BLACK, komaster, 0, vital_moves, &probable_min, &probable_max); else true_genus = owl_determine_life(owl, owl->white_eye, WHITE, komaster, 0, vital_moves, &probable_min, &probable_max); current_owl_data = owl; memset(owl_safe_move_cache, 0, sizeof(owl_safe_move_cache)); /* We don't care about the moves, just whether matches are found. * The content of shape_moves[] will be discarded when we call * owl_shapes(). */ for (k = 0; k < MAX_MOVES; k++) { shape_moves[k].i = -1; shape_moves[k].j = -1; shape_moves[k].value = -1; shape_moves[k].name = NULL; shape_moves[k].same_dragon = 1; } matches_found = 0; memset(found_matches, 0, sizeof(found_matches)); if (level >= 9) global_matchpat(owl_shapes_callback, other, &owl_vital_apat_db, shape_moves, owl->goal); true_genus -= matches_found; sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; if (true_genus >= 2 || (true_genus == 1 && probable_min >= 4) || (stackp > owl_distrust_depth && probable_min >= 2 && !matches_found)) { TRACE("%oVariation %d: ALIVE (2 or more secure eyes)\n", this_variation_number, true_genus); SGFTRACE(-1, -1, WIN, "2 or more secure eyes"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } } saved_owl = *owl; /* struct copy */ /* We try moves in four passes. * stackp==0 stackp>0 * 0. Vital moves in the interval [70..] [45..] * 1. Shape moves * 2. Vital moves in the interval [..69] [..44] * 3. Tactical defense moves */ for (pass = 0; pass < 4; pass++) { moves = NULL; move_cutoff = 1; /* Get the shape moves if we are in the right pass. */ if (pass == 1) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; owl_shapes(shape_moves, color, owl, &owl_defendpat_db); /* A move of value 100 is considered a win */ if (shape_moves[0].value >= 100) { /* to make sure this move is recorded in the sgf file */ if (trymove(shape_moves[0].i, shape_moves[0].j, color, shape_moves[0].name, m, n, komaster, kom_i, kom_j)) popgo(); TRACE("%oVariation %d: ALIVE (Winning owl_defendpat)\n", this_variation_number); SGFTRACE(shape_moves[0].i, shape_moves[0].j, WIN, "winning defense pattern"); READ_RETURN(read_result, ui, uj, shape_moves[0].i, shape_moves[0].j, WIN); } moves = shape_moves; } else if (pass == 0 || pass == 2) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; moves = vital_moves; if (pass == 0 || stackp > owl_distrust_depth) { if (stackp == 0) move_cutoff = 70; else if (true_genus + probable_min >= 3) move_cutoff = 25; else move_cutoff = 45; } if (probable_max < 2 && stackp > 2) move_cutoff = 99; /* Effectively disable vital moves. */ } else { /* Look for a tactical defense. This is primarily intended for * the case where the whole dragon is a single string, therefore * we only look at the string at the "origin". * * We only accept clearly effective tactical defenses here, * using a liberty heuristic. The reason for this is problems * with ineffective self ataris which do defend tactically but * have no strategical effect other than wasting owl nodes or * confusing the eye analysis. */ int di, dj; SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (attack_and_defend(m, n, NULL, NULL, NULL, NULL, &di, &dj) && (approxlib(di, dj, color, 2, NULL, NULL) > 1 || does_capture_something(di, dj, color))) { shape_moves[0].i = di; shape_moves[0].j = dj; shape_moves[0].value = 25; shape_moves[0].name = "tactical defense"; shape_moves[0].same_dragon = 2; shape_moves[1].value = 0; moves = shape_moves; } sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; } if (!moves) continue; /* For the up to MAX_MOVES best moves with value equal to * move_cutoff or higher, try to defend the dragon and see if it * can then be attacked. */ for (k = 0; k < MAX_MOVES; k++) { int mi, mj; int new_komaster, new_kom_i, new_kom_j; int ko_move = -1; if (moves[k].value < move_cutoff) break; mi = moves[k].i; mj = moves[k].j; ASSERT(ON_BOARD(mi, mj), mi, mj); /* Consider only the highest scoring move if we're deeper than * owl_branch_depth. */ if (stackp > owl_branch_depth && k > 0) break; gg_assert(mi != -1); /* Have we already tested this move? */ if (mw[mi][mj]) continue; /* Try to make the move. */ if (!komaster_trymove(mi, mj, color, moves[k].name, m, n, komaster, kom_i, kom_j, &new_komaster, &new_kom_i, &new_kom_j, &ko_move, savecode == 0)) continue; TRACE("Trying %C %m\n", color, mi, mj); /* We have now made a move. Analyze the new position. */ mw[mi][mj] = 1; number_tried_moves++; owl->lunches_are_current = 0; /* Add the stone just played to the goal dragon, unless the * pattern explicitly asked for not doing this. */ owl_update_goal(mi, mj, moves[k].same_dragon, owl); if (!ko_move) { acode = do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j); if (!acode) { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; popgo(); SGFTRACE(mi, mj, WIN, "defense effective - A"); READ_RETURN(read_result, ui, uj, mi, mj, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savei, savej, acode, mi, mj); } else { if (do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j) != WIN) { savei = mi; savej = mj; savecode = KO_B; } } /* Undo the tested move. */ { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; } popgo(); } } if (savecode) { SGFTRACE(savei, savej, savecode, "defense effective (ko) - B"); READ_RETURN(read_result, ui, uj, savei, savej, savecode); } if (number_tried_moves == 0 && probable_min >= 2) { SGFTRACE(-1, -1, WIN, "genus probably >= 2"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } if (true_genus == 1) { SGFTRACE(-1, -1, 0, "genus 1"); } else { SGFTRACE(-1, -1, 0, "genus 0"); } READ_RETURN0(read_result);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/d09fc69f7c667532f8c354dff921cd0f9d6a03fe/owl.c/clean/engine/owl.c |
{ int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; } | pop_owl(owl); | do_owl_defend(int m, int n, int *ui, int *uj, struct local_owl_data *owl, int komaster, int kom_i, int kom_j){ struct owl_move_data shape_moves[MAX_MOVES]; struct owl_move_data vital_moves[MAX_MOVES]; struct owl_move_data *moves; char mw[MAX_BOARD][MAX_BOARD]; int number_tried_moves = 0; int pass; struct local_owl_data saved_owl; int k; int savei = -1; int savej = -1; int savecode = 0; int true_genus = -1; int probable_min = -1; int probable_max = -1; int move_cutoff; int color = p[m][n]; int other = OTHER_COLOR(color); int acode; int found_read_result; Read_result * read_result; int this_variation_number = count_variations - 1; SETUP_TRACE_INFO("owl_defend", m, n); if ((stackp <= owl_branch_depth) && (hashflags & HASH_OWL_DEFEND)) { found_read_result = get_read_result(OWL_DEFEND, komaster, kom_i, kom_j, &m, &n, &read_result); if (found_read_result) { TRACE_CACHED_RESULT(*read_result); if (rr_get_result(*read_result) != 0) { if (ui) *ui = FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)); if (uj) *uj = FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)); } if (rr_get_result(*read_result) == WIN) TRACE("%oVariation %d: ALIVE (cached)\n", this_variation_number); else TRACE("%oVariation %d: DEAD (cached)\n", this_variation_number); SGFTRACE(FIXUP_CACHED_VALUE(rr_get_result_i(*read_result)), FIXUP_CACHED_VALUE(rr_get_result_j(*read_result)), rr_get_result(*read_result), "cached"); return rr_get_result(*read_result); } /* This data should always be recorded. */ if (read_result) { rr_set_compressed_data(*read_result, OWL_DEFEND, komaster, kom_i, kom_j, m, n, stackp); } } else read_result = NULL; /* In order to get a defense move even if we seem to already have * escaped and to reduce the impact of overestimated escape * possibilities, we don't declare escape victory on the first move. * * FIXME: Should introduce a new owl depth value rather than having * this hardwired value. */ if (stackp > 2 && owl_escape_route(owl) >= 5) { /* FIXME: We probably should make distinction in the returned * result whether the dragon lives by making two eyes or by * escaping. */ TRACE("%oVariation %d: ALIVE (escaped)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "escaped"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If (stackp > owl_reading_depth), interpret deep reading * conservatively as escape. */ if (stackp > owl_reading_depth) { TRACE("%oVariation %d: ALIVE (maximum reading depth reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "max reading depth reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } /* If the owl node limit has been reached, assume the dragon has * managed to escape. */ if (owl->local_owl_node_counter >= owl_node_limit) { result_certain = 0; TRACE("%oVariation %d: ALIVE (owl node limit reached)\n", this_variation_number); SGFTRACE(-1, -1, WIN, "owl node limit reached"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } memset(mw, 0, sizeof(mw)); owl->local_owl_node_counter++; global_owl_node_counter++; /* Always start with picking up the vital moves so we can see if * we already are safe. */ { SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (color == BLACK) true_genus = owl_determine_life(owl, owl->black_eye, BLACK, komaster, 0, vital_moves, &probable_min, &probable_max); else true_genus = owl_determine_life(owl, owl->white_eye, WHITE, komaster, 0, vital_moves, &probable_min, &probable_max); current_owl_data = owl; memset(owl_safe_move_cache, 0, sizeof(owl_safe_move_cache)); /* We don't care about the moves, just whether matches are found. * The content of shape_moves[] will be discarded when we call * owl_shapes(). */ for (k = 0; k < MAX_MOVES; k++) { shape_moves[k].i = -1; shape_moves[k].j = -1; shape_moves[k].value = -1; shape_moves[k].name = NULL; shape_moves[k].same_dragon = 1; } matches_found = 0; memset(found_matches, 0, sizeof(found_matches)); if (level >= 9) global_matchpat(owl_shapes_callback, other, &owl_vital_apat_db, shape_moves, owl->goal); true_genus -= matches_found; sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; if (true_genus >= 2 || (true_genus == 1 && probable_min >= 4) || (stackp > owl_distrust_depth && probable_min >= 2 && !matches_found)) { TRACE("%oVariation %d: ALIVE (2 or more secure eyes)\n", this_variation_number, true_genus); SGFTRACE(-1, -1, WIN, "2 or more secure eyes"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } } saved_owl = *owl; /* struct copy */ /* We try moves in four passes. * stackp==0 stackp>0 * 0. Vital moves in the interval [70..] [45..] * 1. Shape moves * 2. Vital moves in the interval [..69] [..44] * 3. Tactical defense moves */ for (pass = 0; pass < 4; pass++) { moves = NULL; move_cutoff = 1; /* Get the shape moves if we are in the right pass. */ if (pass == 1) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; owl_shapes(shape_moves, color, owl, &owl_defendpat_db); /* A move of value 100 is considered a win */ if (shape_moves[0].value >= 100) { /* to make sure this move is recorded in the sgf file */ if (trymove(shape_moves[0].i, shape_moves[0].j, color, shape_moves[0].name, m, n, komaster, kom_i, kom_j)) popgo(); TRACE("%oVariation %d: ALIVE (Winning owl_defendpat)\n", this_variation_number); SGFTRACE(shape_moves[0].i, shape_moves[0].j, WIN, "winning defense pattern"); READ_RETURN(read_result, ui, uj, shape_moves[0].i, shape_moves[0].j, WIN); } moves = shape_moves; } else if (pass == 0 || pass == 2) { if (stackp > owl_branch_depth && number_tried_moves > 0) continue; moves = vital_moves; if (pass == 0 || stackp > owl_distrust_depth) { if (stackp == 0) move_cutoff = 70; else if (true_genus + probable_min >= 3) move_cutoff = 25; else move_cutoff = 45; } if (probable_max < 2 && stackp > 2) move_cutoff = 99; /* Effectively disable vital moves. */ } else { /* Look for a tactical defense. This is primarily intended for * the case where the whole dragon is a single string, therefore * we only look at the string at the "origin". * * We only accept clearly effective tactical defenses here, * using a liberty heuristic. The reason for this is problems * with ineffective self ataris which do defend tactically but * have no strategical effect other than wasting owl nodes or * confusing the eye analysis. */ int di, dj; SGFTree *save_sgf_dumptree = sgf_dumptree; int save_count_variations = count_variations; sgf_dumptree = NULL; count_variations = 0; if (attack_and_defend(m, n, NULL, NULL, NULL, NULL, &di, &dj) && (approxlib(di, dj, color, 2, NULL, NULL) > 1 || does_capture_something(di, dj, color))) { shape_moves[0].i = di; shape_moves[0].j = dj; shape_moves[0].value = 25; shape_moves[0].name = "tactical defense"; shape_moves[0].same_dragon = 2; shape_moves[1].value = 0; moves = shape_moves; } sgf_dumptree = save_sgf_dumptree; count_variations = save_count_variations; } if (!moves) continue; /* For the up to MAX_MOVES best moves with value equal to * move_cutoff or higher, try to defend the dragon and see if it * can then be attacked. */ for (k = 0; k < MAX_MOVES; k++) { int mi, mj; int new_komaster, new_kom_i, new_kom_j; int ko_move = -1; if (moves[k].value < move_cutoff) break; mi = moves[k].i; mj = moves[k].j; ASSERT(ON_BOARD(mi, mj), mi, mj); /* Consider only the highest scoring move if we're deeper than * owl_branch_depth. */ if (stackp > owl_branch_depth && k > 0) break; gg_assert(mi != -1); /* Have we already tested this move? */ if (mw[mi][mj]) continue; /* Try to make the move. */ if (!komaster_trymove(mi, mj, color, moves[k].name, m, n, komaster, kom_i, kom_j, &new_komaster, &new_kom_i, &new_kom_j, &ko_move, savecode == 0)) continue; TRACE("Trying %C %m\n", color, mi, mj); /* We have now made a move. Analyze the new position. */ mw[mi][mj] = 1; number_tried_moves++; owl->lunches_are_current = 0; /* Add the stone just played to the goal dragon, unless the * pattern explicitly asked for not doing this. */ owl_update_goal(mi, mj, moves[k].same_dragon, owl); if (!ko_move) { acode = do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j); if (!acode) { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; popgo(); SGFTRACE(mi, mj, WIN, "defense effective - A"); READ_RETURN(read_result, ui, uj, mi, mj, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savei, savej, acode, mi, mj); } else { if (do_owl_attack(m, n, NULL, NULL, owl, new_komaster, new_kom_i, new_kom_j) != WIN) { savei = mi; savej = mj; savecode = KO_B; } } /* Undo the tested move. */ { int nodes = owl->local_owl_node_counter; *owl = saved_owl; /* struct copy */ owl->local_owl_node_counter = nodes; } popgo(); } } if (savecode) { SGFTRACE(savei, savej, savecode, "defense effective (ko) - B"); READ_RETURN(read_result, ui, uj, savei, savej, savecode); } if (number_tried_moves == 0 && probable_min >= 2) { SGFTRACE(-1, -1, WIN, "genus probably >= 2"); READ_RETURN(read_result, ui, uj, -1, -1, WIN); } if (true_genus == 1) { SGFTRACE(-1, -1, 0, "genus 1"); } else { SGFTRACE(-1, -1, 0, "genus 0"); } READ_RETURN0(read_result);} | 6496 /local/tlutelli/issta_data/temp/c/2005_temp/2005/6496/d09fc69f7c667532f8c354dff921cd0f9d6a03fe/owl.c/clean/engine/owl.c |
#ifndef SIMPLE_MAN2HTML | void scan_man_page(const char *man_page){ if (!man_page) return;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start scanning man page" << endl;#endif // ## Do more init // Unlike man2html, we actually call this several times, hence the need to // properly cleanup all those static vars s_ifelseval.clear(); s_characterDefinitionMap.clear(); InitCharacterDefinitions(); s_stringDefinitionMap.clear(); InitStringDefinitions(); s_numberDefinitionMap.clear(); InitNumberDefinitions(); s_argumentList.clear(); section = 0; s_dollarZero = ""; // No macro called yet! output_possible = false; int strLength = qstrlen(man_page); char *buf = new char[strLength + 2]; qstrcpy(buf+1, man_page); buf[0] = '\n';#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Parse man page" << endl;#endif scan_troff(buf+1,0,NULL);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Man page parsed!" << endl;#endif while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } out_html(NEWLINE); if (section) { output_real("<div style=\"margin-left: 2cm\">\n"); section = 0; } if (output_possible) { output_real("</div>\n"); output_real("<div class=\"bannerBottom\" style=\"background-image: url("); output_real(cssPath); output_real("/bottom-middle.png); background-repeat: x-repeat; width: 100%; height: 100px; bottom:0pt;\">\n"); output_real("<div class=\"bannerBottomLeft\">\n"); output_real("<img src=\""); output_real(cssPath); output_real("/bottom-left.png\" style=\"margin: 0pt;\" alt=\"Bottom left of the banner\">\n"); output_real("</div>\n"); output_real("<div class=\"bannerBottomRight\">\n"); output_real("<img src=\""); output_real(cssPath); output_real("/bottom-right.png\" style=\"margin: 0pt\" alt=\"Bottom right of the banner\">\n"); output_real("</div>\n"); output_real("</div>\n"); output_real("</BODY>\n</HTML>\n"); } delete [] buf; // Release memory s_characterDefinitionMap.clear(); s_stringDefinitionMap.clear(); s_numberDefinitionMap.clear(); s_argumentList.clear(); // reinit static variables for reuse delete [] buffer; buffer = 0; escapesym='\\'; nobreaksym='\''; controlsym='.'; fieldsym=0; padsym=0; buffpos=0; buffmax=0; scaninbuff=false; itemdepth=0; for (int i = 0; i < 20; i++) dl_set[i] = 0; still_dd=false; for (int i = 0; i < 12; i++) tabstops[i] = (i+1)*8; maxtstop=12; curpos=0; mandoc_name_count = 0;} | 3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/buggy/kioslave/man/man2html.cpp |