home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDOPEN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-24
|
7KB
|
236 lines
/*
sdopen.c
% sed_ReallyOpen
Screen Editor
C-scape 3.2
Copyright (c) 1986-1989, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
written by stephen ng.
Sed (for "Screen EDitor") retrieves formatted input from the user.
Rep Invariant: the sed, from creation on, should always be at a valid
field and field position number. If a field has no valid positions (i.e.
it's a menu), then its position is -1.
Revision History:
-----------------
2/17/86 sng wrote it.
3/12/86 sng added sed_SetPosition.
3/14/86 sng added field update flag to sed_Go; added static function
RefreshFields to support it.
3/15/86 sng added vertical scrolling support.
3/22/86 sng fixed field dragging during scrolling so that fields
don't wrap around.
added sed_GetFieldCount.
3/23/86 sng sed_Go now extinguishes the selected field when it exits.
added sed_SetSides.
3/24/86 sng added sed_IncField, sed_DecField.
4/04/86 sng added passing starting field to sed_Go.
4/09/86 sng added sed_SetExitHigh.
4/10/86 sng added pull/push left/right field editing functions
4/14/86 sng added screen scrolling, fixed line scrolling.
4/22/86 sng added sed_GetSize, added #defines for some functions,
sed up, down, left, right
4/24/86 sng fixed push, pull bugs that affected fields with literals
in them, added sed_GetRecordPos.
4/28/86 sng added sed_MarkField.
5/02/86 sng added static version variable; added fieldno arg to
sed_GetRecord; made repaintfield a macro, and fixed a
bug in it.
5/05/86 sng fixed sed_GotoField not calling entry and exit functions.
5/14/86 sng fixed scrolling field tracking.
5/19/86 sng fixed sed_SetRecord bug that ignored field number,
cs_Assert checks for closed sed.
5/24/86 sng added s_enter, s_exit functions (type support).
6/15/86 sng added torch, and support routines, changed sed_Go.
6/18/86 sng added sed_GetPosition.
6/23/86 sng changed torch to baton.
6/29/86 sng fixed sed_Open bug that trashed field-less menus.
6/30/86 sng added sed_GetColors.
7/08/86 sng put cs_Asserts on one line to make egrep'ing easier.
7/09/86 sng #defined out xprint for size.
7/14/86 sng fixed bug in sed_SetHeight; field-less scrolling bug.
8/03/86 sng rearranged includes.
8/09/86 sng fractured files.
10/30/86 jmd removed ifdefs
11/06/86 jmd sed_Go() now returns baton when there are no fields
rewrote main loop of sed_Go()
11/07/86 jmd removed references to toggled_in_exit
11/25/86 jmd added sed->label
12/08/86 jmd moved the mdisplay to the sed.
12/29/86 jmd sed->baton is now initialized to -1.
1/21/87 jmd integrated new borders.
3/11/87 jmd added xoffset
3/28/87 jmd added cursor info and active flag
2/25/88 jmd split up GetR2M macro for UNIX compilers
4/05/88 jmd added special function to sed
4/08/88 jmd changed sed->fieldcount to sed_GetFieldCount()
4/12/88 jmd init'd field xoffset and added adjust_cur()
6/03/88 jmd removed fieldcount check before adjust_cur
6/23/88 jmd now initializes sed->data to NULL
6/29/88 jmd added windows
8/09/88 jmd revised to use new object stuff
8/12/88 jmd added explode flag
8/13/88 jmd added bord_Close
8/13/88 jmd turn off painting in sed_Close
8/16/88 jmd added calls to omalloc
8/23/88 jmd close sed before border
9/14/88 jmd removed cursor info
9/30/88 jmd removed size check
10/05/88 jmd added sedptr to menu
10/19/88 jdc added sed->bob
11/14/88 jmd removed border references, added prompt window
11/19/88 jmd made msg func into mouse func
11/25/88 jdc added sed_RewindTB function
11/28/88 jmd reorganized headers
12/02/88 jmd added nextwin
12/08/88 jmd added winclass arg, turned it into sed_ReallyOpen
12/15/88 jmd moved sed_Close to sdclose.c
12/16/88 jmd added currfield
3/24/89 jmd removed sed back color, added Aux function
3/29/89 jmd converted seds to 'pure' objects
4/06/89 jmd made default_move the boolean it was meant to be
4/11/89 jmd added single field paint optimization
4/13/89 jmd put field array into sed_xd as well
12/10/89 jdm added initialization of go func
12/14/89 jdc fixed default_move bug
1/24/90 jdc fixed default_move again
3/28/90 jmd ansi-fied
4/23/90 jmd changed class to winclass
5/11/90 jdc made sed_ReallyGo a conditional assignment (gofunc saved)
6/27/90 jdc preened the GoFunc code
9/27/90 jmd removed the GoFunc code
*/
#include "sed.h"
#include "tbpriv.h" /* For tb_Rewind() */
#include "winspriv.h" /* For win_SetGoHandle() */
/**** Static Declarations ****/
static char *_cscape = "C-scape: Copyright (c) 1986-1990 by Oakland Group, Inc.";
static char *_csver = "3.2";
/**** Operations *****/
sed_type sed_ReallyOpen(menu_type menu, class_fptr winclass)
/*
effects: creates an sed object associated with the given menu.
Creates the sed using 'class'
returns: if there is sufficient memory, the routine returns the new
sed object; otherwise it returns NULL.
*/
{
sed_type sed;
ocbox wcbox;
/* set the height and width of the sed */
wcbox.toprow = 0;
wcbox.leftcol = 0;
wcbox.botrow = int_min(menu_GetHeight(menu), disp_GetHeight()) - 1;
wcbox.rightcol = int_min(menu_GetWidth(menu), disp_GetWidth()) - 1;
if ((sed = win_Open(winclass, &wcbox)) == NULL) {
return(NULL);
}
if(!sed_Init(sed, menu)) {
obj_Close(sed);
return(NULL);
}
return(sed);
}
boolean sed_Init(obj_type sed, menu_type menu)
/*
effects: initializes a sed object for Open or Load
returns: TRUE, FALSE
*/
{
int i;
if (menu == NULL) {
return(FALSE);
}
/* Initialize sed_xd */
sed_SetMenu(sed, menu);
sed_SetFa(sed, menu_GetFa(menu)); /* short circuit menu to get fields */
if (menu_GetFieldCount(menu) > 0) {
sed_SetFieldNo(sed, 0);
sed_SetCurrField(sed, menu_GetField(menu, 0));
sed_SetRecordPos(sed, menu_GetFirstFieldPos(menu, 0));
menu_SetFieldXoffset(menu, 0, 0);
}
else {
sed_SetFieldNo(sed, -1);
sed_SetCurrField(sed, NULL);
sed_SetRecordPos(sed, NO_WRITEABLES);
}
sd_adjust_cur(sed);
/* Set the sed's field bob parent pointers */
for (i = 0; i < menu_GetBobCount(menu); i++) {
bob_SetParent(menu_GetBob(menu, i), sed);
}
/* point the menu's sedptr to the sed */
(sed_GetMenu(sed))->sedptr = sed;
return(TRUE);
}
/*----------------------------------------------------------------------------*/
boolean default_move(sed_type sed, int row, int col)
/*
A default cursor move method,
moves the ted cursor but doesn't refresh screen.
*/
{
tb_type tb;
tb = sed_GetTextbuf(sed);
if (tb_FindPosition(tb, row, col)) {
sed_SetTrow(sed, tb_GetRow(tb));
sed_SetTcol(sed, tb_GetCol(tb));
}
else {
sed_SetTrow(sed, row);
sed_SetTcol(sed, col);
}
return(TRUE);
}
void sed_RewindTB(sed_type sed)
/*
Move the sed cursor to the beginning of the sed.
*/
{
tb_Rewind(sed_GetTextbuf(sed));
sed_SetTrow(sed, 0);
sed_SetTcol(sed, 0);
}
/**** Misc ****/
field_type sed_GetField(sed_type sed, int fld)
/*
Extracts a field from the field array.
*/
{
return((field_type) xa_Get(sed_GetFa(sed), fld));
}