/***************************************************************************** * get_status_string *****************************************************************************/ static char* get_status_string (const Service* serv, void* result_context, bool debug, const char* spacer) { ContentDir* const cds = (ContentDir*) serv; // Call superclass' method char* p = CLASS_METHOD (Service, get_status_string) (serv, result_context, debug, spacer); // Add ContentDir specific status if (spacer == NULL) spacer = ""; // Create a working context for temporary strings void* const tmp_ctx = talloc_new (NULL); tpr (&p, "%s+- Browse Cache\n", spacer); tpr (&p, "%s", Cache_GetStatusString (cds->cache, tmp_ctx, talloc_asprintf (tmp_ctx, "%s ", spacer))); // Delete all temporary strings talloc_free (tmp_ctx); return p; }
/* * replace the value stored for the terminfo string capability 'infoname' * with the newvalue. */ void putstr(char *infoname, char *newvalue) { int i; if (verbose > 1) { (void) fprintf(trace, "changing value for %s to ", infoname); tpr(trace, newvalue); (void) fprintf(trace, ".\n"); } i = search(strnames, strcount, infoname); if (i != -1) { if (verbose > 1) { (void) fprintf(trace, "value was:"); tpr(trace, strval[uselevel][i]); (void) fprintf(trace, ".\n"); } strval[uselevel][i] = nextstring; while (*newvalue) *nextstring++ = *newvalue++; *nextstring++ = '\0'; return; } (void) fprintf(stderr, "%s: TERM=%s: the string name '%s' was not " "found!\n", progname, term_name, infoname); }
/* * return the value of the terminfo string 'infoname' */ char * getinfostr(char *infoname) { int i; if (verbose > 1) (void) fprintf(trace, "looking for terminfo value of %s.\n", infoname); i = search(strnames, strcount, infoname); if (i != -1) { if (verbose > 1) { (void) fprintf(trace, "\tvalue is:"); tpr(trace, strval[uselevel][i]); (void) fprintf(trace, ".\n"); } return (strval[uselevel][i]); } if (verbose > 1) (void) fprintf(trace, "terminfo name '%s' not found.\n", infoname); return ((char *)NULL); }
/* Print out a string, or "NULL" if it's not defined. */ void PR(FILE *stream, char *string) { if (string == NULL) (void) fprintf(stream, "NULL"); else tpr(stream, string); }
/* * Return the value of the termcap string 'capname' as stored in our list. */ char * getcapstr(char *capname) { int i; if (verbose > 1) (void) fprintf(trace, "looking for termcap value of %s.\n", capname); /* Check the old termcap list. */ for (i = 0; ostrcodes[i]; i++) if (strcmp(ostrcodes[i], capname) == 0) { if (verbose > 1) { (void) fprintf(trace, "\tvalue is:"); tpr(trace, ostrval[uselevel][i]); (void) fprintf(trace, ".\n"); } return (ostrval[uselevel][i]); } if (verbose > 1) (void) fprintf(trace, "termcap name '%s' not found in " "ostrcodes.\n", capname); /* Check the terminfo list. */ for (i = 0; strcodes[i]; i++) if (strcmp(strcodes[i], capname) == 0) { if (verbose > 1) { (void) fprintf(trace, "\tvalue is:"); tpr(trace, strval[uselevel][i]); (void) fprintf(trace, ".\n"); } return (strval[uselevel][i]); } (void) fprintf(stderr, "%s: TERM=%s: termcap name '%s' not found.\n", progname, term_name, capname); return ((char *)NULL); }
/***************************************************************************** * Cache_GetStatusString *****************************************************************************/ char* Cache_GetStatusString (const Cache* const cache, void* result_context, const char* spacer) { if (cache == NULL) return NULL; // ----------> char* p = talloc_strdup (result_context, ""); if (spacer == NULL) spacer = ""; tpr (&p, "%s+- Cache size = %ld\n", spacer, (long) cache->size); tpr (&p, "%s+- Cache max age = ", spacer); if (cache->max_age > 0) tpr (&p, "%ld seconds\n", (long) cache->max_age); else tpr (&p, "disabled\n"); const long nb_cached = Cache_GetNrEntries (cache); tpr (&p, "%s+- Cached entries = %ld (%d%%)\n", spacer, nb_cached, (int) (nb_cached * 100 / cache->size)); tpr (&p, "%s+- Cache access = %d\n", spacer, cache->nr_access); if (cache->nr_access > 0) { tpr (&p, "%s +- hits = %d (%.1f%%)\n", spacer, cache->nr_hit, (float) (cache->nr_hit * 100.0 / cache->nr_access)); tpr (&p, "%s +- expired = %d (%.1f%%)\n", spacer, cache->nr_expired, (float) (cache->nr_expired * 100.0 / cache->nr_access)); #if CACHE_FIXED_SIZE tpr (&p, "%s +- collide = %d (%.1f%%)\n", spacer, cache->nr_collide, (float) (cache->nr_collide * 100.0 / cache->nr_access)); #endif } return p; }
/***************************************************************************** * UpnpUtil_GetEventString *****************************************************************************/ char* UpnpUtil_GetEventString (void* talloc_context, IN Upnp_EventType eventType, IN const void* event) { char* p = talloc_strdup (talloc_context, ""); // Create a working context for temporary strings void* const tmp_ctx = talloc_new (NULL); tpr (&p, "\n\n======================================================================\n"); const char* s = UpnpUtil_GetEventTypeString (eventType); if (s) tpr (&p, "%s\n", s); else tpr (&p, "** unknown Upnp_EventType %d **\n", (int) eventType); if (event == NULL) { tpr (&p, "(NULL EVENT BODY)\n"); } else { switch (eventType) { /* * SSDP */ case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: case UPNP_DISCOVERY_SEARCH_RESULT: { const struct Upnp_Discovery* const e = (struct Upnp_Discovery*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "Expires = %d\n", e->Expires); tpr (&p, "DeviceId = %s\n", NN(e->DeviceId)); tpr (&p, "DeviceType = %s\n", NN(e->DeviceType)); tpr (&p, "ServiceType = %s\n", NN(e->ServiceType)); tpr (&p, "ServiceVer = %s\n", NN(e->ServiceVer)); tpr (&p, "Location = %s\n", NN(e->Location)); tpr (&p, "OS = %s\n", NN(e->Os)); tpr (&p, "Date = %s\n", NN(e->Date)); tpr (&p, "Ext = %s\n", NN(e->Ext)); } break; case UPNP_DISCOVERY_SEARCH_TIMEOUT: // Nothing to print out here break; /* * SOAP */ case UPNP_CONTROL_ACTION_REQUEST: { const struct Upnp_Action_Request* const e = (struct Upnp_Action_Request*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "ErrStr = %s\n", NN(e->ErrStr)); tpr (&p, "ActionName = %s\n", NN(e->ActionName)); tpr (&p, "DevUDN = %s\n", NN(e->DevUDN)); tpr (&p, "ServiceID = %s\n", NN(e->ServiceID)); tpr (&p, "ActRequest = %s\n", XMLUtil_GetDocumentString (tmp_ctx, e->ActionRequest)); tpr (&p, "ActResult = %s\n", XMLUtil_GetDocumentString (tmp_ctx, e->ActionResult)); } break; case UPNP_CONTROL_ACTION_COMPLETE: { const struct Upnp_Action_Complete* const e = (struct Upnp_Action_Complete*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "CtrlUrl = %s\n", NN(e->CtrlUrl)); tpr (&p, "ActRequest = %s\n", XMLUtil_GetDocumentString (tmp_ctx, e->ActionRequest)); tpr (&p, "ActResult = %s\n", XMLUtil_GetDocumentString (tmp_ctx, e->ActionResult)); } break; case UPNP_CONTROL_GET_VAR_REQUEST: { const struct Upnp_State_Var_Request* const e = (struct Upnp_State_Var_Request*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "ErrStr = %s\n", NN(e->ErrStr)); tpr (&p, "DevUDN = %s\n", NN(e->DevUDN)); tpr (&p, "ServiceID = %s\n", NN(e->ServiceID)); tpr (&p, "StateVarName= %s\n", NN(e->StateVarName)); tpr (&p, "CurrentVal = %s\n", NN(e->CurrentVal)); } break; case UPNP_CONTROL_GET_VAR_COMPLETE: { const struct Upnp_State_Var_Complete* const e = (struct Upnp_State_Var_Complete*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "CtrlUrl = %s\n", NN(e->CtrlUrl)); tpr (&p, "StateVarName= %s\n", NN(e->StateVarName)); tpr (&p, "CurrentVal = %s\n", NN(e->CurrentVal)); } break; /* * GENA */ case UPNP_EVENT_SUBSCRIPTION_REQUEST: { const struct Upnp_Subscription_Request* const e = (struct Upnp_Subscription_Request*) event; tpr (&p, "ServiceID = %s\n", NN(e->ServiceId)); tpr (&p, "UDN = %s\n", NN(e->UDN)); tpr (&p, "SID = %s\n", NN(e->Sid)); } break; case UPNP_EVENT_RECEIVED: { const struct Upnp_Event* const e = (struct Upnp_Event*) event; tpr (&p, "SID = %s\n", NN(e->Sid)); tpr (&p, "EventKey = %d\n", e->EventKey); tpr (&p, "ChangedVars = %s\n", XMLUtil_GetDocumentString (tmp_ctx, e->ChangedVariables)); } break; case UPNP_EVENT_RENEWAL_COMPLETE: { const struct Upnp_Event_Subscribe* const e = (struct Upnp_Event_Subscribe*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "SID = %s\n", NN(e->Sid)); tpr (&p, "TimeOut = %d\n", e->TimeOut); } break; case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: { const struct Upnp_Event_Subscribe* const e = (struct Upnp_Event_Subscribe*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "SID = %s\n", NN(e->Sid)); tpr (&p, "PublisherURL= %s\n", NN(e->PublisherUrl)); tpr (&p, "TimeOut = %d\n", e->TimeOut); } break; case UPNP_EVENT_AUTORENEWAL_FAILED: case UPNP_EVENT_SUBSCRIPTION_EXPIRED: { const struct Upnp_Event_Subscribe* const e = (struct Upnp_Event_Subscribe*) event; tpr (&p, "ErrCode = %d\n", e->ErrCode); tpr (&p, "SID = %s\n", NN(e->Sid)); tpr (&p, "PublisherURL= %s\n", NN(e->PublisherUrl)); tpr (&p, "TimeOut = %d\n", e->TimeOut); } break; } } tpr (&p, "======================================================================\n\n"); // Delete all temporary strings talloc_free (tmp_ctx); return p; }
void CmEvaluation::Evaluate(CStr gtW, CStr &salDir, CStr &resName, vecS &des) { int NumMethod = des.size(); // Number of different methods vector<vecD> precision(NumMethod), recall(NumMethod), tpr(NumMethod), fpr(NumMethod); static const int CN = 21; // Color Number static const char* c[CN] = {"'k'", "'b'", "'g'", "'r'", "'c'", "'m'", "'y'", "':k'", "':b'", "':g'", "':r'", "':c'", "':m'", "':y'", "'--k'", "'--b'", "'--g'", "'--r'", "'--c'", "'--m'", "'--y'" }; FILE* f = fopen(_S(resName), "w"); CV_Assert(f != NULL); fprintf(f, "clear;\nclose all;\nclc;\n\n\n%%%%\nfigure(1);\nhold on;\n"); vecD thr(NUM_THRESHOLD); for (int i = 0; i < NUM_THRESHOLD; i++) thr[i] = i * STEP; PrintVector(f, thr, "Threshold"); fprintf(f, "\n"); vecD mae(NumMethod); for (int i = 0; i < NumMethod; i++) mae[i] = Evaluate_(gtW, salDir, "_" + des[i] + ".png", precision[i], recall[i], tpr[i], fpr[i]); //Evaluate(salDir + "*" + des[i] + ".png", gtW, val[i], recall[i], t); string leglendStr("legend("); vecS strPre(NumMethod), strRecall(NumMethod), strTpr(NumMethod), strFpr(NumMethod); for (int i = 0; i < NumMethod; i++){ strPre[i] = format("Precision_%s", _S(des[i])); strRecall[i] = format("Recall_%s", _S(des[i])); strTpr[i] = format("TPR_%s", _S(des[i])); strFpr[i] = format("FPR_%s", _S(des[i])); PrintVector(f, recall[i], strRecall[i]); PrintVector(f, precision[i], strPre[i]); PrintVector(f, tpr[i], strTpr[i]); PrintVector(f, fpr[i], strFpr[i]); fprintf(f, "plot(%s, %s, %s, 'linewidth', %d);\n", _S(strRecall[i]), _S(strPre[i]), c[i % CN], i < CN ? 2 : 1); leglendStr += format("'%s', ", _S(des[i])); } leglendStr.resize(leglendStr.size() - 2); leglendStr += ");"; string xLabel = "label('Recall');\n"; string yLabel = "label('Precision')\n"; fprintf(f, "hold off;\nx%sy%s\n%s\ngrid on;\naxis([0 1 0 1]);\ntitle('Precision recall curve');\n", _S(xLabel), _S(yLabel), _S(leglendStr)); fprintf(f, "\n\n\n%%%%\nfigure(2);\nhold on;\n"); for (int i = 0; i < NumMethod; i++) fprintf(f, "plot(%s, %s, %s, 'linewidth', %d);\n", _S(strFpr[i]), _S(strTpr[i]), c[i % CN], i < CN ? 2 : 1); xLabel = "label('False positive rate');\n"; yLabel = "label('True positive rate')\n"; fprintf(f, "hold off;\nx%sy%s\n%s\ngrid on;\naxis([0 1 0 1]);\n\n\n%%%%\nfigure(3);\ntitle('ROC curve');\n", _S(xLabel), _S(yLabel), _S(leglendStr)); double betaSqr = 0.3; // As suggested by most papers for salient object detection vecD areaROC(NumMethod, 0), avgFMeasure(NumMethod, 0), maxFMeasure(NumMethod, 0); for (int i = 0; i < NumMethod; i++){ CV_Assert(fpr[i].size() == tpr[i].size() && precision[i].size() == recall[i].size() && fpr[i].size() == precision[i].size()); for (size_t t = 0; t < fpr[i].size(); t++){ double fMeasure = (1+betaSqr) * precision[i][t] * recall[i][t] / (betaSqr * precision[i][t] + recall[i][t]); avgFMeasure[i] += fMeasure/fpr[i].size(); // Doing average like this might have strange effect as in: maxFMeasure[i] = max(maxFMeasure[i], fMeasure); if (t > 0){ areaROC[i] += (tpr[i][t] + tpr[i][t - 1]) * (fpr[i][t - 1] - fpr[i][t]) / 2.0; } } fprintf(f, "%%%5s: AUC = %5.3f, MeanF = %5.3f, MaxF = %5.3f, MAE = %5.3f\n", _S(des[i]), areaROC[i], avgFMeasure[i], maxFMeasure[i], mae[i]); } PrintVector(f, areaROC, "AUC"); PrintVector(f, avgFMeasure, "MeanFMeasure"); PrintVector(f, maxFMeasure, "MaxFMeasure"); PrintVector(f, mae, "MAE"); // methodLabels = {'AC', 'SR', 'DRFI', 'GU', 'GB'}; fprintf(f, "methodLabels = {'%s'", _S(des[0])); for (int i = 1; i < NumMethod; i++) fprintf(f, ", '%s'", _S(des[i])); fprintf(f, "};\n\nbar([MeanFMeasure; MaxFMeasure; AUC]');\nlegend('Mean F_\\beta', 'Max F_\\beta', 'AUC');xlim([0 %d]);\ngrid on;\n", NumMethod+1); fprintf(f, "xticklabel_rotate([1:%d],90, methodLabels,'interpreter','none');\n", NumMethod); fprintf(f, "\n\nfigure(4);\nbar(MAE);\ntitle('MAE');\ngrid on;\nxlim([0 %d]);", NumMethod+1); fprintf(f, "xticklabel_rotate([1:%d],90, methodLabels,'interpreter','none');\n", NumMethod); fclose(f); printf("%-70s\r", ""); }
void PhaseItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setRenderHint(QPainter::Antialiasing); QRectF rect = boundingRect(); int rounded = 15; QColor phaseColor = QColor(mData[STATE_COLOR_RED].toInt(), mData[STATE_COLOR_GREEN].toInt(), mData[STATE_COLOR_BLUE].toInt()); QColor fontColor = getContrastedColor(phaseColor); painter->setPen(Qt::NoPen); painter->setBrush(phaseColor); painter->drawRoundedRect(rect, rounded, rounded); if(mControlsVisible) { // Checked QRectF cRect = checkRect(); drawCheckBoxBox(*painter, cRect, mState, Qt::white, QColor(150, 150, 150)); // Eye QRectF eRect = eyeRect(); painter->setBrush(Qt::white); painter->setPen(Qt::black); painter->drawRoundedRect(eRect, 10, 10); if(mEyeActivated) { QPixmap eye(":eye.png"); painter->drawPixmap(eRect, eye, eye.rect()); } } // Name QRectF tr(rect.x() + mBorderWidth + 2*mEltsMargin + mTitleHeight, rect.y() + mBorderWidth + mEltsMargin, rect.width() - 2*mBorderWidth - 2*(mTitleHeight + 2*mEltsMargin), mTitleHeight); QFont font = qApp->font(); painter->setFont(font); QFontMetrics metrics(font); QString name = mData[STATE_NAME].toString(); name = metrics.elidedText(name, Qt::ElideRight, tr.width()); painter->setPen(fontColor); painter->drawText(tr, Qt::AlignCenter, name); // Change font font.setPointSizeF(pointSize(11.f)); painter->setFont(font); // Type (duration tau) QString tauStr = getTauString(); if(!tauStr.isEmpty()) { QRectF tpr(rect.x() + mBorderWidth + mEltsMargin, rect.y() + rect.height() - mBorderWidth - mEltsMargin - mEltsHeight, rect.width() - 2*mBorderWidth - 2*mEltsMargin, mEltsHeight); painter->setPen(Qt::black); painter->setBrush(Qt::white); painter->drawRect(tpr); painter->drawText(tpr, Qt::AlignCenter, tauStr); } // Events QRectF r(rect.x() + mBorderWidth + mEltsMargin, rect.y() + mBorderWidth + mEltsMargin + mTitleHeight + mEltsMargin, rect.width() - 2 * (mEltsMargin + mBorderWidth), mEltsHeight); QJsonArray events = getEvents(); double dy = mEltsMargin + mEltsHeight; for(int i=0; i<events.size(); ++i) { QJsonObject event = events[i].toObject(); QColor eventColor(event[STATE_COLOR_RED].toInt(), event[STATE_COLOR_GREEN].toInt(), event[STATE_COLOR_BLUE].toInt()); if(i > 0) r.adjust(0, dy, 0, dy); painter->fillRect(r, eventColor); painter->setPen(getContrastedColor(eventColor)); painter->drawText(r, Qt::AlignCenter, event[STATE_NAME].toString()); } // Border painter->setBrush(Qt::NoBrush); if(isSelected()) { painter->setPen(QPen(Qt::white, 5.f)); painter->drawRoundedRect(rect.adjusted(1, 1, -1, -1), rounded, rounded); painter->setPen(QPen(Qt::red, 3.f)); painter->drawRoundedRect(rect.adjusted(1, 1, -1, -1), rounded, rounded); } }
static void handlema(void) { char vichar; char cap[2]; int i, j, found; char *infostr; if (verbose > 1) (void) fprintf(trace, "working on termcap ma string.\n"); if (ostrval[uselevel][cap_ma] == NULL) return; cap[1] = '\0'; for (i = 0; ostrval[uselevel][cap_ma][i] != '\0'; ) { /* isolate the key's value */ cap[0] = ostrval[uselevel][cap_ma][i++]; if (verbose > 1) { (void) fprintf(trace, "key value is '"); tpr(trace, cap); (void) fprintf(trace, "'.\n"); } if (ostrval[uselevel][cap_ma][i] == '\0') break; /* isolate the vi key name */ vichar = ostrval[uselevel][cap_ma][i++]; if (verbose > 1) { (void) fprintf(trace, "the vi key is '"); prchar(trace, vichar); (void) fprintf(trace, "'.\n"); } /* match up the vi name in our list */ found = 0; for (j = 0; !found && ma_map[j].keyedinfoname != NULL; j++) { if (verbose > 1) { (void) fprintf(trace, "looking at vi " "character '"); prchar(trace, ma_map[j].vichar); (void) fprintf(trace, "'\n"); } if (vichar == ma_map[j].vichar) { infostr = getinfostr(ma_map[j].keyedinfoname); if (infostr == NULL) putstr(ma_map[j].keyedinfoname, cap); else if (strcmp(cap, infostr) != 0) { (void) fprintf(stderr, "%s: TERM=%s: " "the vi character '", progname, term_name); prchar(stderr, vichar); (void) fprintf(stderr, "' (info '%s') has the value '", ma_map[j].keyedinfoname); tpr(stderr, infostr); (void) fprintf(stderr, "', but 'ma' " "gives '"); prchar(stderr, cap[0]); (void) fprintf(stderr, "'.\n"); } found = 1; } } if (!found) { (void) fprintf(stderr, "%s: the unknown vi key '", progname); prchar(stderr, vichar); (void) fprintf(stderr, "' was\n"); (void) fprintf(stderr, "specified in the 'ma' termcap " "capability.\n"); } } }
/* * Work with the ko string. It is a comma separated list of keys for which * the keyboard has a key by the same name that emits the same sequence. * For example, ko = dc, im, ei means that there are keys called * delete-character, enter-insert-mode and exit-insert-mode on the keyboard, * and they emit the same sequences as specified in the dc, im and ei * capabilities. */ static void handleko(void) { char capname[3]; char *capstr; int i, j, found; char *infostr; if (verbose > 1) (void) fprintf(trace, "working on termcap ko string.\n"); if (ostrval[uselevel][cap_ko] == NULL) return; capname[2] = '\0'; for (i = 0; ostrval[uselevel][cap_ko][i] != '\0'; ) { /* isolate the termcap name */ capname[0] = ostrval[uselevel][cap_ko][i++]; if (ostrval[uselevel][cap_ko][i] == '\0') break; capname[1] = ostrval[uselevel][cap_ko][i++]; if (ostrval[uselevel][cap_ko][i] == ',') i++; if (verbose > 1) { (void) fprintf(trace, "key termcap name is '"); tpr(trace, capname); (void) fprintf(trace, "'.\n"); } /* match it up into our list */ found = 0; for (j = 0; !found && ko_map[j].keyedinfoname != NULL; j++) { if (verbose > 1) (void) fprintf(trace, "looking at termcap name %s.\n", ko_map[j].capname); if (capname[0] == ko_map[j].capname[0] && capname[1] == ko_map[j].capname[1]) { /* add the value to our database */ if ((capstr = getcapstr(capname)) != NULL) { infostr = getinfostr (ko_map[j].keyedinfoname); if (infostr == NULL) { /* skip any possible padding */ /* information */ while (ispadchar(*capstr)) capstr++; putstr(ko_map[j].keyedinfoname, capstr); } else if (strcmp(capstr, infostr) != 0) { (void) fprintf(stderr, "%s: TERM=%s: a function " "key for '%s' was " "specified with the " "value ", progname, term_name, capname); tpr(stderr, capstr); (void) fprintf(stderr, ", but it already has the " "value '"); tpr(stderr, infostr); (void) fprintf(stderr, "'.\n"); } } found = 1; } } if (!found) { (void) fprintf(stderr, "%s: TERM=%s: the unknown " "termcap name '%s' was\n", progname, term_name, capname); (void) fprintf(stderr, "specified in the 'ko' " "termcap capability.\n"); } } }
/* * Fill up the termcap tables. */ int filltables(void) { int i, tret; /* Retrieve the termcap entry. */ if ((tret = otgetent(bp, term_name)) != 1) { (void) fprintf(stderr, "%s: TERM=%s: tgetent failed with return code %d (%s).\n", progname, term_name, tret, (tret == 0) ? "non-existent or invalid entry" : (tret == -1) ? "cannot open $TERMCAP" : "unknown reason"); return (0); } if (verbose) { (void) fprintf(trace, "bp="); (void) cpr(trace, bp); (void) fprintf(trace, ".\n"); } if (uselevel == 0) checktermcap(); /* Retrieve the values that are in terminfo. */ /* booleans */ for (i = 0; boolcodes[i]; i++) { boolval[uselevel][i] = otgetflag(boolcodes[i]); if (verbose > 1) { (void) fprintf(trace, "boolcodes=%s, ", boolcodes[i]); (void) fprintf(trace, "boolnames=%s, ", boolnames[i]); (void) fprintf(trace, "flag=%d.\n", boolval[uselevel][i]); } } /* numbers */ for (i = 0; numcodes[i]; i++) { numval[uselevel][i] = otgetnum(numcodes[i]); if (verbose > 1) { (void) fprintf(trace, "numcodes=%s, ", numcodes[i]); (void) fprintf(trace, "numnames=%s, ", numnames[i]); (void) fprintf(trace, "num=%d.\n", numval[uselevel][i]); } } if (uselevel == 0) nextstring = capbuffer; /* strings */ for (i = 0; strcodes[i]; i++) { strval[uselevel][i] = otgetstr(strcodes[i], &nextstring); if (verbose > 1) { (void) fprintf(trace, "strcodes=%s, ", strcodes [i]); (void) fprintf(trace, "strnames=%s, ", strnames [i]); if (strval[uselevel][i]) { (void) fprintf(trace, "str="); tpr(trace, strval[uselevel][i]); (void) fprintf(trace, ".\n"); } else (void) fprintf(trace, "str=NULL.\n"); } /* remove zero length strings */ if (strval[uselevel][i] && (strval[uselevel][i][0] == '\0')) { (void) fprintf(stderr, "%s: TERM=%s: cap %s (info %s) is NULL: REMOVED\n", progname, term_name, strcodes[i], strnames[i]); strval[uselevel][i] = NULL; } } /* Retrieve the values not found in terminfo anymore. */ /* booleans */ for (i = 0; oboolcodes[i]; i++) { oboolval[uselevel][i] = otgetflag(oboolcodes[i]); if (verbose > 1) { (void) fprintf(trace, "oboolcodes=%s, ", oboolcodes[i]); (void) fprintf(trace, "flag=%d.\n", oboolval[uselevel][i]); } } /* numbers */ for (i = 0; onumcodes[i]; i++) { onumval[uselevel][i] = otgetnum(onumcodes[i]); if (verbose > 1) { (void) fprintf(trace, "onumcodes=%s, ", onumcodes[i]); (void) fprintf(trace, "num=%d.\n", onumval[uselevel][i]); } } /* strings */ for (i = 0; ostrcodes[i]; i++) { ostrval[uselevel][i] = otgetstr(ostrcodes[i], &nextstring); if (verbose > 1) { (void) fprintf(trace, "ostrcodes=%s, ", ostrcodes[i]); if (ostrval[uselevel][i]) { (void) fprintf(trace, "ostr="); tpr(trace, ostrval[uselevel][i]); (void) fprintf(trace, ".\n"); } else (void) fprintf(trace, "ostr=NULL.\n"); } /* remove zero length strings */ if (ostrval[uselevel][i] && (ostrval[uselevel][i][0] == '\0')) { (void) fprintf(stderr, "%s: TERM=%s: cap %s (no terminfo name) is NULL: " "REMOVED\n", progname, term_name, ostrcodes[i]); ostrval[uselevel][i] = NULL; } } return (1); }
/* * Change old style of doing calculations to the new stack style. * Note that this will not necessarily produce the most efficient string, * but it will work. */ void changecalculations() { int i, currentparm; char *from, *to = nextstring; int ch; int parmset, parmsaved; char padding[100], *saveto; for (i = 0; strnames[i]; i++) if (needscopying(strval[uselevel][i])) { if (verbose) { (void) fprintf(trace, "%s needs copying, " "was:", strnames [i]); tpr(trace, strval[uselevel][i]); (void) fprintf(trace, ".\n"); } from = strval[uselevel][i]; strval[uselevel][i] = to; currentparm = 1; parmset = 0; /* Handle padding information. Save it so that it can be */ /* placed at the end of the string where it should */ /* have been in the first place. */ if (ispadchar(*from)) { saveto = to; to = padding; to = caddstr(to, "$<"); while (isdigit(*from) || *from == '.') caddch(*from++); if (*from == '*') caddch(*from++); caddch('>'); caddch('\0'); to = saveto; } else padding[0] = '\0'; if (fancycap(from)) { to = caddstr(to, "%p1%Pa%p2%Pb"); parmsaved = 1; (void) fprintf(stderr, "%s: TERM=%s: Warning: the string " "produced for '%s' may be inefficient.\n", progname, term_name, strnames[i]); (void) fprintf(stderr, "It should be " "looked at by hand.\n"); } else parmsaved = 0; while ((ch = *from++) != '\0') if (ch != '%') caddch(ch); else switch (ch = *from++) { case '.': /* %. -> %p1%c */ case 'd': /* %d -> %p1%d */ case '2': /* %2 -> %p1%2.2d */ case '3': /* %3 -> %p1%3.3d */ case '+': /* %+x -> %p1%'x'%+%c */ case '>': /* %>xy -> %p1%Pc%?%'x'%> */ /* %t%gc%'y'%+ */ /* if current value > x, then add y. */ /* No output. */ case 'B': /* %B: BCD */ /* (16*(x/10))+(x%10) */ /* No output. */ /* (Adds Regent 100) */ case 'D': /* %D: Reverse coding */ /* (x-2*(x%16)) */ /* No output. */ /* (Delta Data) */ if (!parmset) if (parmsaved) { to = caddstr(to, "%g"); if (currentparm == 1) caddch('a'); else caddch('b'); } else { to = caddstr(to, "%p"); if (currentparm == 1) caddch('1'); else caddch('2'); } currentparm = 3 - currentparm; parmset = 0; switch (ch) { case '.': to = caddstr(to, "%c"); break; case 'd': to = caddstr(to, "%d"); break; case '2': case '3': #ifdef USG /* Vr2==USG, Vr3==SYSV. Use %02d for Vr2, %2.2d for Vr3 */ caddch('%'); caddch('0'); #else caddch('%'); caddch(ch); caddch('.'); #endif /* USG vs. SYSV */ caddch(ch); caddch('d'); break; case '+': to = caddstr(to, "%'"); caddch(*from++); to = caddstr(to, "'%+%c"); break; case '>': to = caddstr(to, "%Pc%?%'"); caddch(*from++); to = caddstr(to, "'%>%t%gc%'"); caddch(*from++); to = caddstr(to, "'%+"); parmset = 1; break; case 'B': to = caddstr(to, "%Pc%gc%{10}%/%{16}%*%gc%{10}%m%+"); parmset = 1; break; case 'D': to = caddstr(to, "%Pc%gc%gc%{16}%m%{2}%*%-"); parmset = 1; break; } break; /* %r reverses current parameter */ case 'r': currentparm = 3 - currentparm; break; /* %n: exclusive-or row AND column */ /* with 0140, 96 decimal, no output */ /* (Datamedia 2500, Exidy Sorceror) */ case 'n': to = caddstr(to, "%ga%'`'%^%Pa"); to = caddstr(to, "%gb%'`'%^%Pb"); break; /* assume %x means %x */ /* this includes %i and %% */ default: caddch('%'); caddch(ch); } to = caddstr(to, padding); caddch('\0'); if (verbose) { (void) fprintf(trace, "and has become:"); tpr(trace, strval[uselevel][i]); (void) fprintf(trace, ".\n"); } } nextstring = to; }