home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
MENUUNPF.C
< prev
next >
Wrap
Text File
|
1990-09-28
|
4KB
|
190 lines
/*
menuunpf.c 6/10/88
% menu_UnPrintf
C-scape 3.2
Copyright (c) 1988, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
12/14/88 jmd Now uses fields directly
3/29/89 jmd Added CSPRIV modifier
4/10/89 jmd rewrote without sprintf return dependency
4/21/89 jmd now uses @fD syntax
6/05/89 jmd Added dflag (switches between fD and fd)
7/26/89 jmd expandedd dflag, added bob support (dflag 2)
8/02/89 jdc Added @ quoting in field_GetSpec
12/17/89 jdc added field highlighted char
3/28/90 jmd ansi-fied
4/05/90 jdc added % quoting (menupriv.h)
4/19/90 jdc fixed quoting
9/28/90 jdc fixed a very old bug in field_GetSpec by adding "rlen--;"
*/
#include "menu.h"
OSTATIC int CSPRIV field_GetSpec(field_type field, char *s);
char *menu_UnPrintf(menu_type menu, int fieldno, char *buf, int row, int col, int dflag)
/*
Recreates a menu definition string for a field,
using @p[row, col] if row != -1.
Places the string in the scratch pad.
"@p[2,4]@f{name}w10pD3[#####]"
if dflag is TRUE, @fd is translated to @fD
dflag:
0 generate @fd
1 generate @fD
2 use @fd but no 'd' if only one NULL data pointer
also use @fb
tok buffer should be big enough to hold field + "@p[]@f..."
field_UnPrintf(field, buf);
*/
{
char *s, *name, wids[10], highs[10], dps[10];
field_type field;
field = menu_GetField(menu, fieldno);
name = menu_GetFieldName(menu, fieldno);
/* field width */
if (field_GetWidth(field) == field_GetMergeLen(field)) {
wids[0] = '\0';
}
else {
sprintf(wids, "w%d", field_GetWidth(field));
}
/* field highlighted char */
if (field_IsHiCharOn(field)) {
sprintf(highs, "h%d", field_GetHiChar(field));
}
else {
highs[0] = '\0';
}
/* data pointers */
if (field_GetDataCount(field) > 1) {
sprintf(dps, "%c%d", ((dflag == 1) ? 'D' : 'd'), field_GetDataCount(field));
}
else {
if (dflag == 2 && field_GetData(field, 0) == NULL) {
dps[0] = '\0';
}
else {
dps[0] = (dflag == 1) ? (char) 'D' : (char) 'd';
dps[1] = (char)'\0';
}
}
/* Create the field definition, part 1 */
/* { n } w p d b h */
sprintf(buf, "@p[%d,%d]@f%s%s%s%s%s%s%s%s[",
(row == -1) ? field_GetRow(field) : row,
(col == -1) ? field_GetCol(field) : col,
(name != NULL) ? "{" : "",
(name != NULL) ? name : "",
(name != NULL) ? "}" : "",
wids,
(field_GetProtected(field)) ? "p" : "",
dps,
(dflag == 2 && field_GetBob(field) != NULL) ? "b" : "",
highs);
/* part two */
s = buf + strlen(buf);
s += field_GetSpec(field, s);
*s++ = ']';
*s = '\0';
return(buf);
}
static int CSPRIV field_GetSpec(field_type field, char *s)
/*
build field spec
returns length of spec.
*/
{
char *merge;
char c, last;
int mpos, recpos, mlen, rlen, rcount, slen, len;
mlen = field_GetMergeLen(field);
rlen = field_GetRecordLen(field);
merge = field_GetMerge(field);
rcount = 0;
last = '\0';
for (mpos = 0, recpos = 0, slen = 0; mpos < mlen; mpos++) {
if (rlen > 0 && field_GetR2M(field, recpos) == mpos) {
c = (char) '#';
recpos++;
rlen--;
}
else {
c = merge[mpos];
}
/* see if we can use repeat */
if (last == '\0' || c == last) {
rcount++;
}
else if (rcount > 6) {
if (fspec_isquotable(last)) {
sprintf(s, "@[%d,@%c]", rcount, last);
}
else {
sprintf(s, "@[%d,%c]", rcount, last);
}
len = strlen(s);
slen += len;
s += len;
rcount = 1;
}
else {
while (rcount > 0) {
if (fspec_isquotable(last)) {
*s++ = '@';
slen++;
}
*s++ = last;
slen++;
rcount--;
}
rcount = 1;
}
last = c;
}
/* finish up */
if (rcount > 6) {
if (fspec_isquotable(last)) {
sprintf(s, "@[%d,@%c]", rcount, last);
}
else {
sprintf(s, "@[%d,%c]", rcount, last);
}
len = strlen(s);
slen += len;
s += len;
rcount = 0;
}
else {
while (rcount > 0) {
if (fspec_isquotable(last)) {
*s++ = '@';
slen++;
}
*s++ = last;
slen++;
rcount--;
}
}
return(slen);
}