-+-+-+-+-+-+-+-+ START OF PART 287 -+-+-+-+-+-+-+-+ X** \blurb`7BThis function scrolls the contents of the TERMINAL window X** either UP or DOWN by `7B\tt numlines`7D.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X switch (scrolldir) X `7B X case PTP_DOWN:`20 X windptr->term.visline -= numlines; `20 X break; X `20 X case PTP_UP: X windptr->term.visline += numlines; X break; X `20 X case PTP_LEFT: X break; X `20 X case PTP_RIGHT: X break; X `7D X setterminalline(); X `7D X `7D X`7D /* ptk_scrollterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_setterminaldata(C(Pint) windid, C(Pint) numlines, X C(Pint) txfont, C(Pint) txcolour) XPreANSI(Pint windid) XPreANSI(Pint numlines) XPreANSI(Pint txfont) XPreANSI(Pint txcolour) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPint`7D`7Bnumlines`7D`7Bnumber of lines in window`7D`7BIN`7D X** \param`7BPint`7D`7Bnumcolmns`7D`7Bnumber of columns in window`7D`7BIN`7D X** \param`7BPint`7D`7Btxfont`7D`7Btext font`7D`7BIN`7D X** \param`7BPint`7D`7Btxcolour`7D`7Btext colour`7D`7BIN`7D X** \paramend X** \blurb`7BThis function sets the number of lines to be displayed in a`20 X** TERMINAL window and which text font and colour to use.`7D X*/ X`7B X Pchar stname`5B30`5D; X Pint termnum; X Pfloat linespace, chrht, textheight, textwidth; X Ptxalign align; X Pint err, totsize; X Pchar *buffer; X Pconnid connid; X Prect rect; X Ppoint offset; X Pwstype wstype; X Pfloat wwidth, wheight, charheight, charwidth, lineheight; X X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X windptr->term.lines = numlines; X `20 X /* create structure with appropriate attr */ X pemptystruct(windptr->term.textstid); X ptk_openstruct(windptr->term.textstid); X `20 X /* user specified font*/ X windptr->term.txfont = txfont; X windptr->term.txcolour = txcolour; X psettextfont(txfont); X psettextcolourind(txcolour); X align.hor = PAH_NORMAL; X align.ver = PAV_BOTTOM; X psettextalign(&align); X /* size characters so they all fit within window */ X textwidth = windptr->windowsize.x * 0.99; X textheight = windptr->windowsize.y * 0.9; X linespace = (windptr->windowsize.y * 0.1)/(Pfloat)windptr->term.lines; V `20 X `20 X /* character height */ X pinqwsconntype(windptr->wsid, 0, &err, buffer, &connid, X &totsize, &wstype); X buffer = (Pchar *)malloc(totsize); X pinqwsconntype(windptr->wsid, totsize, &err, buffer, &connid, X &totsize, &wstype); X ptk_inqtextextent(wstype, txfont, 1.0, 0.0, 0.01, PTP_RIGHT,`20 X PAH_NORMAL, PAV_NORMAL, "W", &err, &rect, &offset); X `20 X wheight = rect.ur.y - rect.ll.y; X wwidth = rect.ur.x - rect.ll.x; X free(buffer); X `20 X lineheight = textheight / (Pfloat)numlines; X charheight = 0.01 * (lineheight / wheight); X charwidth = wwidth * (lineheight / wheight); X psetcharheight(charheight); X windptr->term.increment = textheight/(Pfloat)windptr->term.lines`20 X + linespace; X windptr->term.realcols = textwidth / charwidth; X windptr->term.columns = (Pint)windptr->term.realcols; X windptr->term.reallines = (Pfloat)numlines; X plabel(ptk_stringtoint("label", "$tm_starttext")); X /* put text elements here */ X plabel(ptk_stringtoint("label", "$tm_endtext")); X ptk_closestruct(); X `7D X `7D X`7D /* ptk_setterminaldata */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_inqterminaldata(C(Pint) windid, C(Pint *) numlines, X C(Pint *) numcolms, C(Pint *) txfont, C(Pint *) txcolour, X C(Pint *) err) XPreANSI(Pint windid) XPreANSI(Pint *numlines) XPreANSI(Pint *numcolms) XPreANSI(Pint *txfont) XPreANSI(Pint *txcolour) XPreANSI(Pint *err) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPint *`7D`7Bnumlines`7D`7Bnumber of lines in window`7D`7BOUT`7D X** \param`7BPint *`7D`7Bnumcolmns`7D`7Bnumber of columns in window`7D`7BOUT` V7D X** \param`7BPint *`7D`7Btxfont`7D`7Btext font`7D`7BOUT`7D X** \param`7BPint *`7D`7Btxcolour`7D`7Btext colour`7D`7BOUT`7D X** \param`7BPint *`7D`7Berr`7D`7Berror indicator`7D`7BOUT`7D X** \paramend X** \blurb`7BThis function may be used to obtain the number of lines X** displayed in a TERMINAL window and the number of characters in a line. X** Also the text font and colour used are returned in `7B\tt txfont`7D and X** `7B\tt txcolour`7D. The error code = 1 if `7B\tt windid`7D doesn't exist X** and = 2 if it is not a terminal window.`7D X*/ X`7B X *err = 0; X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X *numlines = windptr->term.lines; `20 X *numcolms = windptr->term.columns; `20 X *txfont = windptr->term.txfont; X *txcolour = windptr->term.txcolour; X `7D X else X *err = 2; X `7D X else X *err = 1; X`7D /* ptk_inqterminaldata */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_refreshterminal(C(Pint) windid) XPreANSI(Pint windid) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \paramend X** \blurb`7BThis function refreshes the TERMINAL window so that the X** last text line is visible.`7D X*/ X`7B X Pint linediff; X X /* show updates */ X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X linediff = windptr->term.curr_line - windptr->term.visline; X if (abs(linediff) >= windptr->term.lines) X `7B X windptr->term.visline = windptr->term.curr_line -`20 X windptr->term.lines + 1;`20 X setterminalline(); X `7D X `7D X `7D X`7D /* ptk_refreshterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_writeterminal(C(Pint) windid, C(Pchar *) str) XPreANSI(Pint windid) XPreANSI(Pchar *str) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPchar *`7D`7Bstr`7D`7Bstring to write to window`7D`7BIN`7D X** \paramend X** \blurb`7BThis function writes a character string to the current line X** of the TERMINAL window. A new line is started when the end of the X** current line is reached.`7D X*/ X`7B`20 X Pint wtlen, spaceleft, stringleft, allocsize; X Pint cpylen; X Pchar *templine; X Pint termnum; X Peditmode emode; X X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X templine = windptr->term.lastline; X `20 X /* length of string to write */ X wtlen = strlen(str); X `20 X /* number of character spaces left on current line */ X spaceleft = windptr->term.columns - windptr->term.curr_colm; X `20 X /* add into current line if possible */ X `20 X if (spaceleft > 0) X `7B X /* allocate space for line */ X if (wtlen > spaceleft) X /* spans more than one line */ X allocsize = windptr->term.columns + 1; X else X /* fits entirely on current line */ X allocsize = windptr->term.curr_colm + wtlen + 1; X if (templine == NULL) X `7B X templine = (Pchar *)malloc(allocsize); X emode = PEDIT_INSERT; X `7D X else X `7B X templine = (Pchar *)realloc(windptr->term.lastline, allocsize); X emode = PEDIT_REPLACE; X `7D X `20 X /* cpylen = min(wtlen, spaceleft) */ X cpylen = wtlen < spaceleft ? wtlen : spaceleft; X `20 X /* copy as much of str as possible into current line */ X strncpy(&templine`5Bwindptr->term.curr_colm`5D,`20 X str, cpylen); X `20 X windptr->term.curr_colm = allocsize - 1; X templine`5Ballocsize - 1`5D = '\0'; `20 X addline(templine, emode); X `7D X `20 X stringleft = wtlen - spaceleft; X `20 X while (stringleft > 0) X `7B X /* create a new line */ X /* allocate space for line */ X `20 X if (stringleft > windptr->term.columns) X allocsize = windptr->term.columns + 1; X else X allocsize = stringleft + 1; X free(templine); X templine = NULL; X templine = (Pchar *)malloc(sizeof(Pchar) * allocsize); X `20 X /* copy as much of string as possible */ X strncpy(templine, &str`5Bwtlen - stringleft`5D,`20 X allocsize);`20 X windptr->term.curr_line++; X windptr->term.curr_colm = allocsize - 1; X templine`5Ballocsize - 1`5D = '\0'; X stringleft -= windptr->term.columns; X addline(templine, PEDIT_INSERT); X `20 X `7D /* while */ X X windptr->term.lastline = templine; X X ptk_refreshterminal(windid); X `7D X `7D X`7D /* ptk_writeterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_writelnterminal(C(Pint) windid, C(Pchar *) str) XPreANSI(Pint windid) XPreANSI(Pchar *str) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPchar *`7D`7Bstr`7D`7Bstring to write to window`7D`7BIN`7D X** \paramend X** \blurb`7BThis function writes a character string to the current line X** of the TERMINAL window. A new line is started when the end of the current X** line is reached and at the next call to a TERMINAL write function.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B `20 X ptk_writeterminal(windid, str); X /* goto end of line */ X windptr->term.curr_colm = windptr->term.columns; X `7D X `7D X`7D /* ptk_writelnterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_printfterminal(C(Pint) windid, C(Pchar *) format, va_alist) XPreANSI(Pint windid) XPreANSI(Pchar *format) Xva_dcl X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPchar *`7D`7Bformat`7D`7Bformat string`7D`7BIN`7D X** \param`7B`7D`7Bva\_alist`7D`7Bvariable length argument list`7D`7BIN`7D X** \paramend X** \blurb`7BThis function writes to a TERMINAL window using a variable lengt Vh X** argument list and a format string like the C printf function.`7D X*/ X`7B X va_list args; X Pchar str`5B255`5D, line`5B255`5D; X Pchar *newline, *firstchar; X X va_start(args); X vsprintf(str, format, args); X va_end(args); X X firstchar = &str`5B0`5D; X while ((newline = strchr(firstchar, '\n')) != NULL) X `7B X strncpy(line, firstchar, (newline - firstchar));`20 X line`5Bnewline - firstchar`5D = '\0'; X ptk_writelnterminal(windid, line); X firstchar = newline + 1; X `7D X X if (firstchar != '\0') X ptk_writeterminal(windid, firstchar); X`7D /* ptk_printfterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_clearterminal(C(Pint) windid) XPreANSI(Pint windid) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \paramend X** \blurb`7BThis function empties the structure containing all the text X** written to the TERMINAL window.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X /* first clear out PHIGS structure */ X ptk_openstruct(windptr->term.textstid); X psetelemptr(0); X pdelelemslabels(ptk_stringtoint("label", "$tm_starttext"), X ptk_stringtoint("label", "$tm_endtext")); X ptk_closestruct(); X predrawallstruct(windptr->wsid, PALWAYS); X `20 X /* now clear out data structure */ X windptr->term.curr_line = 0; X windptr->term.curr_colm = windptr->term.columns; X windptr->term.visline = 0; X `20 X free(windptr->term.lastline); X windptr->term.lastline = NULL; X ptk_scrollterminal(windid, PTP_UP, 1); X `7D X `7D X`7D /* ptk_clearterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_writeintterminal(C(Pint) windid, C(Pint) number) XPreANSI(Pint windid) XPreANSI(Pint number) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPint`7D`7Bnumber`7D`7Binteger to write to window`7D`7BIN`7D X** \paramend X** \blurb`7BThis function writes an integer to a TERMINAL window.`7D X*/ X`7B X Pchar intstr`5B81`5D; X X sprintf(intstr, "%d", number); X ptk_writeterminal(windid, intstr); X`7D /* ptk_writeintterminal */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_writefloatterminal(C(Pint) windid, C(Pfloat) number) XPreANSI(Pint windid) XPreANSI(Pfloat number) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bterminal window identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bnumber`7D`7Bfloat number to write to window`7D`7BIN` V7D X** \paramend X** \blurb`7BThis function writes a floating point number to a TERMINAL windo Vw.`7D X*/ X`7B X Pchar floatstr`5B81`5D; X X setwindow(windid); X if (windptr != NULL) X `7B X if (windptr->windowtype == PTKETERMINALWINDOW) X `7B X sprintf(floatstr, windptr->term.floatformat, number); X ptk_writeterminal(windid, floatstr); X `7D X `7D X`7D /* ptk_writefloatterminal */ X +-+-+-+-+-+-+-+- END OF PART 287 +-+-+-+-+-+-+-+-