home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
MENULOAD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-04
|
6KB
|
212 lines
/*
menuload.c
% sf_loadmenu
C-scape 3.2
Copyright (c) 1986-1989 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
8/16/89 jdc fixed adding unresolved funcs bug
11/02/89 jdc fixed trailing '\n' color problem
1/20/89 jdc speeded data retrieval (oslists)
1/23/89 jdc added default defines
2/07/90 jdc added child bob object naming
3/28/90 jmd ansi-fied
4/17/90 jdc renamed _bfile_gets to bf_gets
4/17/90 jdc fixed pointer math bug (chopped unlinked ffuncs names)
5/04/90 jdc added loaddefault_funcs
6/14/90 jdc added error check for menu_Printf
8/12/90 jdc added opendata arg to sf_loadobj
9/07/90 jmd renamed oslist funcs
10/04/90 jmd added test for menu_putTB failure
*/
#include "sed.h" /* sfile.h wants the whole shmear */
#include "tbpriv.h"
#include "menupriv.h"
#include "fndecl.h" /* for string_funcs */
#include "sfile.h"
#include "sfilpriv.h"
OGLOBAL field_funcs_ptr loaddefault_funcs = &string_funcs;
menu_type sf_loadmenu(sfile_type sfile)
/*
*/
{
unsigned int len, fldno;
int i, j, dpcount, fcount, insert, limit;
int tabchar, newlchar;
long size;
tb_type tb;
menu_type menu;
char *s, *fstrs[4], *sbuf;
int child, reg, sel, label, handle, is_lnf;
obj_type bob;
bfile_type bfile;
field_funcs_ptr funcs;
int attr, old_attr;
sbuf = sfile->buf;
if ((menu = menu_Open()) == NULL) {
return(NULL);
}
/* if in LNF then we keep track of ffunc types and varible names */
is_lnf = (sfile->oslist_array[FSYM_TY] == NULL) ? FALSE:TRUE;
if (is_lnf && ((menu->funcnamea = ia_Open(SED_FSYM_COUNT)) == NULL
|| (menu->varnamea = ia_Open(SED_FSYM_COUNT)) == NULL
|| (menu->functypea = ia_Open(SED_FSYM_COUNT)) == NULL)) {
goto ERROR;
}
/* data pointers AND variable names are stored here */
menu->dptrlist = oslist_Open(2, 0);
tb = menu_GetTextbuf(menu);
bfile = sfile->bfile;
if (bf_gets(bfile, sbuf, SFILE_BUFLEN, '\0') == 0) {
goto ERROR;
}
/* menu info: fieldcount, textbuf size - 1, wrapwidth, tabsize, insert,
limit, maxsize, newlinechar, tabchar
*/
sscanf(sbuf, "%d %ld %d %d %d %d %ld %d %d",
&fcount, &size, &(tb->width), &(tb->tab_size), &insert, &limit,
&(tb->max_size), &tabchar, &newlchar);
tb->limit = limit;
tb->tab_char = (byte)tabchar;
tb->newline_char = (byte)newlchar;
/* field info
reg, sel, label (unused), data ptr count, chile,
func sym, func type, var sym, m_UnPrintf, data strings
*/
for (i = 0; i < fcount; i++) {
if (bf_gets(bfile, sbuf, SFILE_BUFLEN, '\0') == 0) {
goto ERROR;
}
sscanf(sbuf, "%d %d %d %d %d", ®, &sel, &label, &dpcount, &child);
/* ffunc, ffunc type, var, field spec */
for (j = 0, s = sbuf; j < 4; j++, s += len) {
if ((len = bf_gets(bfile, s, SFILE_BUFLEN, '\0')) == 0) {
goto ERROR;
}
fstrs[j] = s;
}
/* Create the field */
if ((funcs = sfile_FindFieldFunc(sfile, fstrs[0], &handle)) == NULL) {
funcs = loaddefault_funcs;
}
if (!menu_Printf(menu, fstrs[3], NULL, funcs)) {
goto ERROR;
}
fldno = menu_GetFieldCount(menu) - 1;
if (is_lnf) {
if (handle == -1) {
handle = sfile_PutFieldFunc(sfile, fstrs[0], funcs, fstrs[1]);
}
/* Put the handle into the funcname array */
menu_SetFieldFuncHandle(menu, i, handle);
/* add the func type */
handle = menu_PutFieldFuncType(menu, sfile, fstrs[1]);
menu_SetFieldFuncTypeHandle(menu, i, handle);
/* add the varname */
handle = menu_PutVarName(menu, fstrs[2]);
menu_SetVarNameHandle(menu, i, handle);
}
/* data pointers */
for (j = 0; j < dpcount; j++) {
if (bf_gets(bfile, sbuf, SFILE_BUFLEN, '\0') == 0) {
goto ERROR;
}
if (!strcmp(sbuf, FSYM_NULLSTR)) {
s = NULL;
}
else {
s = menu_PutDPL(menu, sbuf);
}
menu_SetFieldData(menu, fldno, j, s);
}
if (reg > 0 || sel > 0) {
menu_MarkField(menu, fldno, (char)reg, (char)sel);
}
if (child) {
if ((bob = sf_loadobj(sfile, menu_GetFieldName(menu, fldno), NULL)) == NULL) {
goto ERROR;
}
menu_SetFieldBob(menu, i, bob);
}
}
/* textbuffer */
for (old_attr = -1; size > 0; old_attr = attr, size -= (long)len) {
if (bf_gets(bfile, sbuf, SFILE_BUFLEN, '\0') == 0) {
goto ERROR;
}
sscanf(sbuf, "%d %d\n", &len, &attr);
if (len <= 0) { /* color trailing '\n' */
if (attr != old_attr) {
bbc_Attr(tb->bbc, (long) tb->len - 1L, (byte) attr, 1L);
}
break;
}
else {
if (old_attr == -1) {
old_attr = attr;
}
if (bfile_Read(bfile, sbuf, len) == 0) {
goto ERROR;
}
if (!menu_putTB(menu, (int)tb->bbc->b->row, tb->col, sbuf, 0x00, len,
(byte)attr, (byte)old_attr, TB_COLOR)) {
goto ERROR;
}
}
}
tb_Rewind(tb);
/* fixes text calc of rowcount */
tb->insert = insert;
menu_Flush(menu);
return(menu);
ERROR:
menu_Destroy(menu);
return(NULL);
}
int sfile_PutFieldFunc(sfile_type sfile, char *funcname, field_funcs_ptr funcs, char *typename)
{
int ffhandle;
/* add the func sym */
ffhandle = oslist_SetSym(sfile->oslist_array[FSYM_FF], funcname, (VOID *)&funcs);
if (sfile->oslist_array[FSYM_TY] != NULL) {
/* add the type sym, if necessary */
*((int *)((char *)oslist_GetData(sfile->oslist_array[FSYM_FF], ffhandle)
+ FSYM_DATASIZE)) = oslist_SetSym(sfile->oslist_array[FSYM_TY], typename, NULL);
}
return(ffhandle);
}