home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
MENUNAME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-07
|
2KB
|
102 lines
/*
menuname.c
% menu field name routines
A name contains an integer (fieldno) and a string in one buffer.
C-scape 3.2
Copyright (c) 1988, by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
3/04/89 jdc rewrote for non class function symbols
8/09/89 jdc changed oslist_GetSym to oslist_Get
1/20/90 jdc speeded data retrieval (oslists)
1/21/90 jdc changed oslist stuff
1/22/90 jdc preened
3/28/90 jmd ansi-fied
8/22/90 jdc made menu_RemoveName a function
9/07/90 jmd renamed oslist funcs
*/
#include "menu.h"
int menu_AddName(menu_type menu, char *name, int fieldno)
/*
Add a name to the menu's name list.
return a handle to the name.
Initialize the name first time called.
Returns -1 if it fails.
*/
{
int nameno;
if (menu->namelist == NULL) {
/* create name array */
if ((menu->namelist = oslist_Open(4, sizeof(int))) == NULL) {
return(-1);
}
}
nameno = oslist_SetSym(menu->namelist, name, (VOID *)(&fieldno));
return(nameno);
}
void menu_SetFieldName(menu_type menu, int fieldno, char *name)
/*
Set a field's name name.
*/
{
int nameno;
if ((nameno = menu_GetFieldNameNo(menu, fieldno)) != OSLIST_BADNAME) {
/* remove old name */
menu_RemoveFieldName(menu, fieldno);
}
/* add name */
nameno = menu_AddName(menu, name, fieldno);
menu_SetFieldNameNo(menu, fieldno, nameno);
}
int menu_GetNameNo(menu_type menu, char *name)
{
int h;
if ((h = oslist_FindHandle(menu->namelist, name)) == OSLIST_BADNAME) {
return(-1);
}
return(*((int *)oslist_GetData(menu->namelist, h)));
}
boolean menu_RemoveFieldName(menu_type menu, int fld)
{
int nameno, i, *namedata;
if ((nameno = menu_GetFieldNameNo(menu, fld)) != OSLIST_BADNAME) {
/* remove field to name connection */
menu_SetFieldNameNo(menu, fld, OSLIST_BADNAME);
/* remove name to field connection, if necessary */
namedata = ((int *)oslist_GetData(menu->namelist, nameno));
if (*namedata == fld) {
*namedata = -1;
}
for (i = 0; i < menu_GetFieldCount(menu); i++) {
if (menu_GetFieldNameNo(menu, i) == nameno) {
/* can't delete name from list, used by another field */
return(FALSE);
}
}
oslist_Delete(menu->namelist, nameno);
}
return(TRUE);
}