home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
MENUSAVE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-07
|
5KB
|
177 lines
/*
menusave.c
% sf_savemenu
C-scape 3.2
Copyright (c) 1988-1989 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
11/02/89 jdc fixed trailing '\n' color problem
11/02/89 jdc fixed the big one
1/20/90 jdc speeded data retrieval (oslists)
1/24/90 jdc fixed oslist stuff
3/28/90 jmd ansi-fied
9/07/90 jmd renamed oslist funcs
*/
#include "sed.h"
#include "sfile.h"
#include "sfilpriv.h"
#include "teddecl.h"
boolean sf_savemenu(sfile_type sfile, menu_type menu)
/*
*/
{
int i, j, dp_count, reg, sel, label, len, row, col, child;
tb_type tb;
obj_type bob;
bfile_type bfile;
iarray funcnamea;
char buf[22], *fstrs[3], *sbuf;
byte attr;
bblock_type b, ob;
bfile = sfile->bfile;
sbuf = sfile->buf;
tb = menu_GetTextbuf(menu);
funcnamea = menu->funcnamea;
/* menu info: fieldcount, textbuf size - 1, wrapwidth, tabsize, insert,
limit, maxsize, newlinechar, tabchar
*/
sprintf(sbuf, "%d %ld %d %d %d %d %ld %d %d\n",
menu->fieldcount, tb->size, tb->width, tb->tab_size,
tb->insert, tb->limit, tb->max_size, (int)(tb->newline_char),
(int)(tb->tab_char));
if (!bfile_Write(bfile, sbuf, strlen(sbuf))) {
return(FALSE);
}
/* field info
reg, sel, label (unused), data ptr count, child,
func sym, func type, var sym, m_UnPrintf, data strings
*/
for (i = 0; i < menu->fieldcount; i++) {
dp_count = menu_GetDataCount(menu, i);
child = label = 0;
row = col = -1;
if ((bob = menu_GetFieldBob(menu, i)) != NULL) {
child = TRUE;
/* the bob's virtual field position comes from the bob position
if it is dependent, the bob might have been moved since load
*/
if (bob_IsDepend(bob) && menu->sedptr != NULL) {
row = win_GetYmin(bob) + sed_GetYoffset(menu->sedptr);
col = win_GetXmin(bob) + sed_GetXoffset(menu->sedptr);
if ((row -= win_GetYmin(menu->sedptr)) < 0) row = 0;
if ((col -= win_GetXmin(menu->sedptr)) < 0) col = 0;
}
}
if (menu_IsMarked(menu, i)) {
reg = (int)menu_GetFieldRegAttr(menu, i);
sel = (int)menu_GetFieldSelAttr(menu, i);
}
else {
reg = sel = -1;
}
sprintf(sbuf, "%d %d %d %d %d\n", reg, sel, label, dp_count, child);
if (!bfile_Write(bfile, sbuf, strlen(sbuf))) {
return(FALSE);
}
/* if there is an funcname iarray pull names that way,
else search off func directly
*/
if (funcnamea == NULL) {
fstrs[0] = fsym_NullCheck(sfile_FindFieldFuncName(sfile, menu_GetFuncs(menu, i)));
fstrs[1] = fstrs[2] = FSYM_NULLSTR;
}
else {
fstrs[0] = fsym_NullCheck(menu_GetFieldFuncName(menu, sfile, i));
fstrs[1] = fsym_NullCheck(menu_GetFieldFuncType(menu, sfile, i));
fstrs[2] = fsym_NullCheck(menu_GetVarName(menu, i));
}
sprintf(sbuf, "%s\n%s\n%s\n%s\n", fstrs[0], fstrs[1], fstrs[2],
menu_UnPrintf(menu, i, menu_GetScratchPad(menu), row, col, 1));
if (!bfile_Write(bfile, sbuf, strlen(sbuf))) {
return(FALSE);
}
/* write the data pointers (strings only please) */
for (j = 0; j < dp_count; j++) {
sprintf(sbuf, "%s\n", fsym_NullCheck((char *) menu_GetFieldData(menu, i, j)));
if (!bfile_Write(bfile, sbuf, strlen(sbuf))) {
return(FALSE);
}
}
if (bob != NULL && !sf_saveobj(sfile, bob)) {
return(FALSE);
}
}
/* textbuffer */
tb_Rewind(tb);
for (ob = tb->bbc->b; ob != NULL; ) {
b = ob;
for (i = 0, attr = b->attr; b != NULL && b->attr == attr; b = b->next) {
if (i + bblen(b) > SFILE_BUFLEN) {
break;
}
i += bblen(b);
}
if (b == NULL) {
i--; /* supress last '\n' */
}
sprintf(buf, "%d %d\n", i, (int)attr);
if (!bfile_Write(bfile, buf, strlen(buf))) {
return(FALSE);
}
if (i == 0) {
break;
}
else {
for ( ; i > 0; ) {
len = (bblen(ob) > i) ? i : bblen(ob);
if (!bfile_Write(bfile, ob->start, len)) {
return(FALSE);
}
i -= len;
if (i <= 0) {
break;
}
ob = ob->next;
}
if (b == NULL) { /* last time, take care of '\n' */
sprintf(buf, "0 %d\n", (int)attr);
if (!bfile_Write(bfile, buf, strlen(buf))) {
return(FALSE);
}
break;
}
}
ob = ob->next;
}
return(TRUE);
}
char *sfile_GetFieldFuncType(sfile_type sfile, int ffhandle)
{
if (sfile->oslist_array[FSYM_TY] == NULL) {
return(NULL);
}
return(oslist_GetSym(sfile->oslist_array[FSYM_TY],
*((int *)((char *)oslist_GetData(sfile->oslist_array[FSYM_FF],
ffhandle) + FSYM_DATASIZE))));
}