#include <X/mit-copyright.h>
/* Copyright Massachusetts Institute of Technology 1984, 1985 */
static char *rcsid_util_c
= "$Header: util.c,v 10.11 86/04/28 15:05:29 jg Exp $";
* These routines are used for the jump scroll feature
register int height
= screen
->bot_marg
- screen
->top_marg
+ 1;
register int samount
= screen
->scroll_amt
;
register int ramount
= screen
->refresh_amt
;
register int scrolled
= samount
* screen
->f_height
;
register int refreshed
= ramount
* screen
->f_height
;
register int top
= screen
->top_marg
* screen
->f_height
+ screen
->border
;
rtop
= screen
->bot_marg
- ramount
+ 1;
if (screen
->multiscroll
&& samount
== 1 &&
screen
->top_marg
== 0 && screen
->bot_marg
== screen
->max_row
) {
if (screen
->incopy
< 0 && screen
->scrolls
== 0)
XMoveArea (screen
->window
,
screen
->border
, top
+ scrolled
, screen
->border
, top
,
screen
->width
, height
* screen
->f_height
- refreshed
);
XTileSet (screen
->window
, screen
->border
,
rtop
* screen
->f_height
+ screen
->border
,
screen
->width
, refreshed
, screen
->bgndtile
);
ScrnRefresh(screen
, rtop
, 0, ramount
, screen
->max_col
+ 1);
register int amount
= screen
->refresh_amt
;
register int row
= screen
->cur_row
;
if(row
== (bottom
= screen
->bot_marg
) - amount
) {
return(row
>= bottom
- amount
+ 1 && row
<= bottom
);
if(row
== (top
= screen
->top_marg
) + amount
) {
return(row
<= top
+ amount
- 1 && row
>= top
);
* scrolls the screen by amount lines, erases bottom, doesn't alter
* cursor position (i.e. cursor moves down amount relative to text).
* All done within the scrolling region, of course.
register int height
= screen
->bot_marg
- screen
->top_marg
+ 1;
register int border
= screen
->border
;
register int top
= screen
->top_marg
* screen
->f_height
+ border
;
if(screen
->scroll_amt
> 0) {
if(screen
->refresh_amt
+ amount
> height
)
screen
->scroll_amt
+= amount
;
screen
->refresh_amt
+= amount
;
if(screen
->scroll_amt
< 0)
screen
->scroll_amt
= amount
;
screen
->refresh_amt
= amount
;
covered
= amount
* screen
->f_height
;
&& screen
->bot_marg
==screen
->max_row
) {
if (screen
->incopy
<0 && screen
->scrolls
==0)
XMoveArea(screen
->window
, border
, top
+ covered
, border
, top
,
screen
->width
, height
* screen
->f_height
- covered
);
XTileSet(screen
->window
, border
,
(screen
->bot_marg
- amount
+ 1) * screen
->f_height
+ border
,
screen
->width
, covered
, screen
->bgndtile
);
ScrnDeleteLine(screen
->buf
, screen
->bot_marg
, screen
->top_marg
,
amount
, screen
->max_col
+ 1);
* Reverse scrolls the screen by amount lines, erases top, doesn't alter
* cursor position (i.e. cursor moves up amount relative to text).
* All done within the scrolling region, of course.
RevScroll(screen
, amount
)
register int height
= screen
->bot_marg
- screen
->top_marg
+ 1;
register int border
= screen
->border
;
register int top
= screen
->top_marg
* screen
->f_height
+ border
;
amount
= (amount
< height
) ? amount
: height
;
if(screen
->scroll_amt
< 0) {
if(-screen
->refresh_amt
+ amount
> height
)
screen
->scroll_amt
-= amount
;
screen
->refresh_amt
-= amount
;
if(screen
->scroll_amt
> 0)
screen
->scroll_amt
= -amount
;
screen
->refresh_amt
= -amount
;
covered
= amount
* screen
->f_height
;
XMoveArea (screen
->window
,
screen
->width
, height
* screen
->f_height
- covered
);
XTileSet (screen
->window
,
ScrnInsertLine (screen
->buf
, screen
->bot_marg
, screen
->top_marg
,
amount
, screen
->max_col
+ 1);
* If cursor not in scrolling region, returns. Else,
* inserts n blank lines at the cursor's position. Lines above the
* bottom margin are lost.
register int bottom
= screen
->bot_marg
;
if (screen
->cur_row
< screen
->top_marg
||
screen
->cur_row
> screen
->bot_marg
) return;
if (screen
->cur_row
+ n
- 1 > bottom
) n
= bottom
- screen
->cur_row
+ 1;
if(screen
->scroll_amt
<= 0&&screen
->cur_row
<= -screen
->refresh_amt
) {
if(-screen
->refresh_amt
+ n
> height
)
screen
->refresh_amt
-= n
;
} else if(screen
->scroll_amt
)
if(!screen
->scroll_amt
) {
height
= n
* screen
->f_height
;
XMoveArea(screen
->window
,
screen
->border
, CursorY (screen
),
screen
->border
, CursorY (screen
) + height
,
(bottom
+ 1 - screen
->cur_row
- n
) * screen
->f_height
);
screen
->border
, CursorY (screen
),
screen
->width
, height
, screen
->bgndtile
);
ScrnInsertLine(screen
->buf
, bottom
, screen
->cur_row
, n
,
* If cursor not in scrolling region, returns. Else, deletes n lines
* at the cursor's position, lines added at bottom margin are blank.
register int bottom
= screen
->bot_marg
;
if (screen
->cur_row
< screen
->top_marg
|| screen
->cur_row
> screen
->bot_marg
)
if (screen
->cur_row
+ n
- 1 > bottom
)
n
= bottom
- screen
->cur_row
+ 1;
if(screen
->scroll_amt
>= 0 && screen
->cur_row
== screen
->top_marg
) {
if(screen
->refresh_amt
+ n
> height
)
screen
->refresh_amt
+= n
;
} else if(screen
->scroll_amt
)
if(!screen
->scroll_amt
) {
height
= n
* screen
->f_height
;
XMoveArea(screen
->window
,
screen
->border
, CursorY (screen
) + height
,
screen
->border
, CursorY (screen
),
(bottom
+ 1 - screen
->cur_row
- n
) * screen
->f_height
);
(bottom
+ 1 - n
) * screen
->f_height
+ screen
->border
,
screen
->width
, height
, screen
->bgndtile
);
ScrnDeleteLine(screen
->buf
, bottom
, screen
->cur_row
, n
,
* Insert n blanks at the cursor's position, no wraparound.
register int width
= n
* screen
->f_width
;
if(!AddToRefresh(screen
)) {
XMoveArea(screen
->window
,
CursorX (screen
), CursorY (screen
),
CursorX (screen
) + width
, CursorY (screen
),
screen
->width
- (screen
->cur_col
+ n
) * screen
->f_width
,
CursorX (screen
), CursorY (screen
),
width
, screen
->f_height
, screen
->bgndtile
);
ScrnInsertChar(screen
->buf
, screen
->cur_row
, screen
->cur_col
, n
,
* Deletes n chars at the cursor's position, no wraparound.
if (screen
->cur_col
+ n
> screen
->max_col
+ 1)
n
= screen
->max_col
+ 1 - screen
->cur_col
;
if(!AddToRefresh(screen
)) {
width
= n
* screen
->f_width
;
XMoveArea(screen
->window
,
CursorX (screen
) + width
, CursorY (screen
),
CursorX (screen
), CursorY (screen
),
screen
->width
- (screen
->cur_col
+ n
) * screen
->f_width
,
XTileSet (screen
->window
,
screen
->border
+ screen
->width
- width
, CursorY (screen
),
width
, screen
->f_height
, screen
->bgndtile
);
ScrnDeleteChar (screen
->buf
, screen
->cur_row
, screen
->cur_col
, n
,
* Clear from cursor position to beginning of display, inclusive.
XTileSet(screen
->window
, screen
->border
, 0,
screen
->width
, CursorY (screen
), screen
->bgndtile
);
ClearBufRows(screen
, 0, screen
->cur_row
- 1);
* Clear from cursor position to end of display, inclusive.
register int sy
= CursorY (screen
) + screen
->f_height
;
XTileSet(screen
->window
, screen
->border
, sy
,
screen
->width
, screen
->height
- sy
+ screen
->border
,
ClearBufRows(screen
, screen
->cur_row
+ 1, screen
->max_row
);
* Clear last part of cursor's line, inclusive.
if(!AddToRefresh(screen
)) {
CursorX (screen
), CursorY (screen
),
screen
->width
-screen
->cur_col
* screen
->f_width
,screen
->f_height
,
bzero((char *)(screen
->buf
[screen
->cur_row
] + screen
->cur_col
),
sizeof (short) * (screen
->max_col
- screen
->cur_col
+ 1));
* Clear first part of cursor's line, inclusive.
if(!AddToRefresh(screen
)) {
XTileSet (screen
->window
,
screen
->border
, CursorY (screen
),
(screen
->cur_col
+ 1) * screen
->f_width
,
screen
->f_height
, screen
->bgndtile
);
bzero ((char *)screen
->buf
[screen
->cur_row
],
sizeof (short) * (screen
->cur_col
+ 1));
* Erase the cursor's line.
if(!AddToRefresh(screen
)) {
XTileSet (screen
->window
,
screen
->border
, CursorY (screen
),
screen
->width
, screen
->f_height
, screen
->bgndtile
);
bzero ((char *)screen
->buf
[screen
->cur_row
],
sizeof (short) * (screen
->max_col
+ 1));
ClearBufRows (screen
, 0, screen
->max_row
);
XWindowEvent (screen
->window
, ExposeRegion
|ExposeCopy
, &reply
);
if (((XExposeEvent
*)rep
)->detail
== ExposeCopy
&&
HandleExposure (screen
, &reply
);
if (screen
->incopy
<= 0 && screen
->scrolls
> 0)
if (screen
->scrolls
== 0) {
* This routine handles exposure events
HandleExposure (screen
, reply
)
register XExposeEvent
*reply
;
int toprow
, leftcol
, nrows
, ncols
;
extern Terminal term
; /* kludge */
XExposeRegionEvent event
;
toprow
= (reply
->y
- screen
->border
) / screen
->f_height
;
leftcol
= (reply
->x
- screen
->border
) / screen
->f_width
;
nrows
= (reply
->y
+ reply
->height
- 1 - screen
->border
) /
screen
->f_height
- toprow
+ 1;
ncols
= (reply
->x
+ reply
->width
- 1 - screen
->border
) /
screen
->f_width
- leftcol
+ 1;
toprow
-= screen
->scrolls
;
if (toprow
+ nrows
- 1 > screen
->max_row
)
nrows
= screen
->max_row
- toprow
+ 1;
if (leftcol
+ ncols
- 1 > screen
->max_col
)
ncols
= screen
->max_col
- leftcol
+ 1;
if (nrows
> 0 && ncols
> 0) {
if (screen
->TekEmu
&& reply
->detail
!= ExposeCopy
)
/* Clear to avoid possible dangling cursor */
XTileSet (screen
->window
,
leftcol
* screen
->f_width
+ screen
->border
,
toprow
* screen
->f_height
+ screen
->border
,
nrows
* screen
->f_height
,
ScrnRefresh (screen
, toprow
, leftcol
, nrows
, ncols
);
/* only do the tek refresh on the last refresh event */
XSync(0); /* make sure they are all here */
if (event
.type
!= ExposeRegion
) {
if (reply
->detail
!= ExposeCopy
)
if (reply
->detail
!= ExposeCopy
)
if (screen
->cur_row
>= toprow
&&
screen
->cur_row
< toprow
+ nrows
&&
screen
->cur_col
>= leftcol
&&
screen
->cur_col
< leftcol
+ ncols
)
fprintf(stderr
, "PANIC! ");
fprintf (stderr
, "Error %d: ", errno
);
* cleanup by sending SIGHUP to client processes
pgrp
= getpgrp(screen
->pid
);
if (pgrp
> 1) killpg(pgrp
, SIGHUP
);
* sets the value of var to be arg in the Unix 4.2 BSD environment env.
* Var should end with '=' (bindings are of the form "var=value").
* This procedure assumes the memory for the first level of environ
* was allocated using malloc.
register char *var
, *value
;
while (environ
[index
] != NULL
) {
if (strncmp (environ
[index
], var
, strlen (var
)) == 0) {
environ
[index
] = (char *) malloc (strlen (var
) + strlen (value
));
strcpy (environ
[index
], var
);
strcat (environ
[index
], value
);
if (debug
) printf ("expanding env\n");
environ
= (char **) realloc((char *)environ
, sizeof(char *) * (index
+2));
fprintf (stderr
, "Setenv: malloc out of memory\n");
environ
[index
] = (char *) malloc (strlen (var
) + strlen (value
));
strcpy (environ
[index
], var
);
strcat (environ
[index
], value
);
environ
[++index
] = NULL
;
* returns a pointer to the first occurrence of s2 in s1,
* or NULL if there are none.
while ((s3
=index(s1
, *s2
)) != NULL
) {
if (strncmp(s3
, s2
, strlen(s2
)) == 0)