|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 5416 (0x1528)
Types: TextFile
Names: »screen.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦e83f91978⟧ »EurOpenD22/isode/osimis-2.0.tar.Z«
└─⟦d846658bd⟧
└─⟦this⟧ »osimis/smap/screen.c«
/*
* Copyright (c) 1988 University College London
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the Department of Computer Science, University College London.
* The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* Keeps track of which records are currently displayed in osimon display
* and allows that set to be manipulated
*/
/*
* Initially by Graham Knight, modified by George Pavlou
* October 1988
*/
#include <stdio.h>
#include "disp.h"
#include "recs.h"
/* routines to change the current screen delimiters */
static RECID fid; /* pointer to first record on screen */
static RECID lid; /* pointer to next record off screen */
/* both supposed to reflect reality */
RECID settop ();
RECID setbottom ();
RECID setmiddle ();
extern RECID validrec (); /* force a record id to be valid */
extern int LINES; /* max. number of lines on screen */
extern REC recs[];
extern RECID endrec;
static int gap;
/* initialise things */
screeninit (g)
int g;
{
gap = g;
}
/*
* return screen delimiters (ids of top and bottom recs on screen)
*/
delim (fp, lp)
RECID *fp, *lp;
{
*fp = fid;
*lp = lid;
}
/*
* arrange to point at a screen which includes rid. If rid is already
* on the screen then don't move and return 0
*/
lookat (rid)
RECID rid;
{
register RECID id;
id = fid; /* start of page */
settop (fid); /* in case a record has been removed (?) */
while (id != lid) {
if (id == rid)
return (0); /* already on display */
incr (id);
}
setmiddle (rid);
return (1);
}
/*
* get rid as near to the top of the screen as possible if recs is
* non-empty rid must identify a real record
*/
RECID settop (rid)
RECID rid;
{
register int nl = 0;
if (empty ()) {
fid = lid = first ();
return (fid);
}
nl = linecnt (rid);
fid = rid; /* sets top record pointer */
while (!pastend (incr (rid))) {
/*
* count how many recs will fit -
* there may be different lenghts
*/
if ((nl += (linecnt (rid) + gap)) > LINES - TTLNS) {
lid = rid;
decr (rid);
return (fid);
}
}
/* at end of records, try to add more to front */
lid = rid;
if (!atstart (fid))
setbottom (prev (rid));
return (fid);
}
/*
* get rid as near to the bottom of the screen as possible if recs is
* non-empty rid must identify a real record
*/
static RECID setbottom (rid)
RECID rid;
{
register int nl = 0;
if (empty ()) {
fid = lid = first ();
return (fid);
}
nl = linecnt (rid);
lid = next (rid); /* sets bottom record pointer */
while (!atstart (rid)) {
decr (rid);
if ((nl += (linecnt (rid) + gap)) > LINES - TTLNS) {
/*
* counts how many records will fit: might be able to fit
* further records at the bottom (it is rather used to
* avoid having a gap at the top)
*/
fid = next (rid);
return ((pastend (lid)) ? fid : settop (fid));
}
}
/* at start of records, try to add more to end */
fid = rid;
if (!pastend (lid))
settop (rid);
return (fid);
}
/* get rid as near to the middle of the screen as possible */
static RECID setmiddle (rid)
RECID rid;
{
register RECID mid, id;
rid = validrec (rid); /* get rid in range */
settop (rid);
mid = middle (fid, lid);
id = fid;
while (before (id, rid) && before (mid, lid)) {
incr (id);
incr (mid);
}
setbottom (mid);
return (fid);
}
/* move up/down one record if possible */
upone ()
{
if (atstart (fid))
return (0);
settop (prev (fid));
return (1);
}
downone ()
{
if (pastend (lid))
return (0);
setbottom (lid);
return (1);
}
/* move up/down one page if possible */
uppage ()
{
if (atstart (fid))
return (0);
setbottom (prev (fid));
return (1);
}
downpage ()
{
if (pastend (lid))
return (0);
settop (lid);
return (1);
}
/* go to extremes */
home ()
{
if (atstart (fid))
return (0);
settop (first ());
return (1);
}
fin ()
{
if (pastend (lid))
return (0);
setbottom (last ());
return (1);
}
pagelen ()
{
register int ln = 0;
register RECID id;
id = fid;
while (before (id, lid)) {
ln += (linecnt (id) + gap);
incr (id);
}
return ((ln < gap) ? 0 : ln - gap);
}
/* say whether rid is on page commencing with sid */
onpage (sid, rid)
RECID sid, rid;
{
register RECID id;
int nl = 0;
sid = validrec (sid);
rid = validrec (rid);
id = sid;
while ((!pastend (id)) &&
((nl += linecnt (rid)) <= LINES - TTLNS)) {
if (equal (id, rid))
return (1);
nl += gap;
incr (id);
}
return (0);
}