-+-+-+-+-+-+-+-+ START OF PART 207 -+-+-+-+-+-+-+-+ X for (ind = 0; ind < toptable.numtables; ind++)`20 X `7B X tabentry = &toptable.tablelist`5Bind`5D; X if ((tabentry->tableptr) != NULL) X `7B`20 X *totalsize += sizeof(Pint) + sizeof(Pchar *) +`20 X (tabentry->stringlen + 1); X counter++; X `7D `20 X `7D X`20 X tablerec->listlen = counter; X /* if application buffer is big enough, copy in data */ X if (counter > 0) X `7B X if ((size >= *totalsize) && (strbuffer != NULL)) X `7B X /* pointers into application supplied buffer */ X strlenptr = tablerec->namelenlist = (Pint *)(strbuffer); X strptr = tablerec->tablenames = (Pchar **)(strbuffer +`20 X (counter * sizeof(Pint))); X stringptr = (Pchar *)(strptr + (counter * sizeof(Pchar *))); X for (ind = 0; ind < toptable.numtables; ind++) X `7B `20 X tabentry = &toptable.tablelist`5Bind`5D; `20 X if (tabentry->tableptr != NULL)`20 X `7B `20 X strncpy(stringptr, tabentry->strdata,`20 X (tabentry->stringlen + 1)); X *strptr = (Pchar *)stringptr; X strptr++; X stringptr += (tabentry->stringlen + 2);`20 X *strlenptr = (Pint)tabentry->stringlen; X strlenptr++; X `7D X `7D X `7D X `7D X`7D /* ptk_inqhashtables */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void outputfreeintlist(C(FILE *) f, C(ptksfreeint *) freeptr) XPreANSI(FILE *f) XPreANSI(ptksfreeint *freeptr) X/* X** \parambegin X** \param`7B `7D`7Bf`7D`7Bpointer to a file`7D`7BIN`7D X** \param`7B `7D`7Bfreeptr`7D`7Bfree identifier list`7D`7BIN`7D X** \paramend X** \blurb`7BOutputs the free identifier list to a file in`20 X** reverse order.`7D X*/ X`7B X if (freeptr != NULL) X `7B`20 X outputfreeintlist(f, freeptr->next); X fprintf(f, "%d\n", freeptr->freeint); X `7D X`7D /* outputfreeintlist */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_storehashtable(C(FILE *) fileptr, C(Pchar *) tablestr) XPreANSI(FILE *fileptr) XPreANSI(Pchar *tablestr) X/* X** \parambegin X** \param`7BFILE *`7D`7Bfileptr`7D`7Bpointer to a file`7D`7BIN`7D X** \param`7BPchar *`7D`7Btable`7D`7Bhashtable to store`7D`7BIN`7D X** \paramend X** \blurb`7BThe function writes the hashtable \pardesc`7Btablestr`7D to the X** file \pardesc`7Bfileptr`7D, which should be opened and writeable.`7D X*/ X`7B X Pint ind; X Pint numstrs; X ptksfreeint *freeptr; X ptksstridentry *strentry; X ptkshashtable *table; X X if ((table = ptk_stringtotable(tablestr)) != NULL) X `7B X fprintf(fileptr, "start\n"); X /* output structure identifier range */ X fprintf(fileptr, "%d\n", table->minuniqint); X fprintf(fileptr, "%d\n", table->maxuniqint); X numstrs = 0; X for (ind = 0; ind < table->numstrings; ind++)`20 X `7B X if ((table->stridtable + ind)->strdata != NULL)`20 X numstrs++; X `7D X fprintf(fileptr, "%d\n", numstrs); X /* output string table entries */ X for (ind = 0; ind < table->numstrings; ind++)`20 X `7B X if ((table->stridtable + ind)->strdata != NULL)`20 X `7B `20 X strentry = (table->stridtable + ind); X fprintf(fileptr, "%d\n", (strentry->stringlen + 1)); X fprintf(fileptr, "%s\n", strentry->strdata); X fprintf(fileptr, "%d\n", strentry->uniqint); X `7D X `7D X /* output free identifiers, in reverse order */ X freeptr = table->freeintlist; X outputfreeintlist(fileptr, freeptr); X /* terminate table store with `60end' */ X fprintf(fileptr, "end\n"); X `7D X`7D /* ptk_storehashtable */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_storeallhashtables(C(FILE *) fileptr) XPreANSI(FILE *fileptr) X/* X** \parambegin X** \param`7BFILE *`7D`7Bfileptr`7D`7Bpointer to a file`7D`7BIN`7D X** \paramend X** \blurb`7BThe function writes all the hashtables in the table of hashtable Vs X** to the X** file \pardesc`7Bfileptr`7D, which should be opened and writeable.`7D X*/ X`7B X Pint i, count; X X count = 0; X for (i = 0; i < toptable.numtables; i++) X if (toptable.tablelist`5Bi`5D.tableptr != NULL) `7Bcount++;`7D X X /* number of hashtables */ X fprintf(fileptr, "%d\n", count); X X /* for each hashtable */ X for (i = 0; i < toptable.numtables; i++) X `7B X if (toptable.tablelist`5Bi`5D.tableptr != NULL) X `7B X fprintf(fileptr, "%s\n", toptable.tablelist`5Bi`5D.strdata); X ptk_storehashtable(fileptr, toptable.tablelist`5Bi`5D.strdata); X `7D X `7D X`7D /* ptk_storeallhashtables */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void addstring(C(ptkshashtable *) table, C(Pint) strlength, X C(Pchar *) str, C(Pint) stid) XPreANSI(ptkshashtable *table) XPreANSI(Pint strlength) XPreANSI(Pchar *str) XPreANSI(Pint stid) X/* X** \parambegin X** \param`7B `7D`7Btable`7D`7Bhashtable`7D`7BIN`7D X** \param`7B `7D`7Bstrlength`7D`7Blength of string to add`7D`7BIN`7D X** \param`7B `7D`7Bstr`7D`7Bstring to be added in string table`7D`7BIN`7D X** \param`7B `7D`7Bstid`7D`7Bstring identifier allocated to string`7D`7BIN`7 VD X** \paramend X** \blurb`7BInserts the given parameters into a ptksstridentry X** structure and sets up the pointers from the hashtable to the string X** table and the clash pointers.`7D X*/ X`7B X Pint hashvalue; X ptkboolean found; X Pint foundentry; X Pint dumstid; X X hashvalue = hashstring(str, strlength); /* calc hashvalue */ X if (table->hashtable`5Bhashvalue - 1`5D == NIL) X `7B `20 X /* no collision, so add string */ X if (addstringtotable(table, str, &dumstid)) X `7B X table->hashtable`5Bhashvalue - 1`5D = dumstid - table->minuniqint; X table->stridtable`5Bdumstid - table->minuniqint`5D.uniqint = stid; X `7D X `7D`20 X else`20 X `7B X /* collision, so traverse clash pointers to first free position */ X searchforstring(str, table->hashtable`5Bhashvalue - 1`5D, X table, &foundentry, &found); X if (!found) X `7B `20 X /* add into table */ X if (addstringtotable(table, str, &dumstid)) X `7B X table->stridtable`5Bfoundentry`5D.clashptr = dumstid - table->minuni Vqint; X table->stridtable`5Bdumstid - table->minuniqint`5D.prevptr = founden Vtry; X table->stridtable`5Bdumstid - table->minuniqint`5D.uniqint = stid; X `7D X `7D X `7D /* else */ X`7D /* addstring */ X X/*-------------------------------------------------------------------------* V/ X X/*function:external*/ Xextern void ptk_restorehashtable(C(FILE *) fileptr, C(Pchar *) tablestr) XPreANSI(FILE *fileptr) XPreANSI(Pchar *tablestr) X/* X** \parambegin X** \param`7BFILE *`7D`7Bfileptr`7D`7Bpointer to a file`7D`7BIN`7D X** \param`7BPchar *`7D`7Btablestr`7D`7Bhashtable to insert data from file`7D V`7BIN`7D X** \paramend X** \blurb`7BThis function reads a hashtable from the file \pardesc`7Bfileptr V`7D, X** and creates it with the name \pardesc`7Btablestr`7D. If the hashtable alr Veady exists, X** it is deleted, and then recreated from the file. The file should be open V and X** readable when this function is called.`7D X*/ X`7B X#define LINELEN 80 X X Pint ind; X Pint minint, maxint; X Pint numstrs; X Pint stringlen, uniqint; X Pchar *strdata; X Pchar *str; X Pint id; X ptkshashtable *table; X X /* check if table exists */ X if (ptk_hashtableused(tablestr)) X `7B X ptk_delhashtable(tablestr); X `7D X str = (Pchar *)malloc(LINELEN); X fgets(str, LINELEN, fileptr); X X /* get structure identifier range */ X fgets(str, LINELEN, fileptr); X minint = atoi(str); X fgets(str, LINELEN, fileptr); X maxint = atoi(str); X X /* create table to be restored */ X ptk_createhashtable(tablestr, minint, maxint); X table = ptk_stringtotable(tablestr); X X /* get number of strings */ X fgets(str, LINELEN, fileptr); X numstrs = atoi(str); X X /* input string table entries */ X for (ind = 0; ind < numstrs; ind++) X `7B X fgets(str, LINELEN, fileptr); X stringlen = atoi(str); X strdata = (Pchar *)malloc(stringlen); X fgets(str, LINELEN, fileptr); X strncpy(strdata, str, stringlen); X strdata`5Bstringlen - 1`5D = '\0'; X fgets(str, LINELEN, fileptr); X uniqint = atoi(str); X addstring(table, (stringlen - 1), strdata, uniqint); X free(strdata); X `7D X /* input free identifiers (stored in reverse order) */ X fgets(str, LINELEN, fileptr); X id = atoi(str); X table->freeintlist->freeint = id; X fgets(str, LINELEN, fileptr); X while (strncmp(str, "end", 3) != 0) X `7B X id = atoi(str); X freestrid(&table->freeintlist, id); X fgets(str, LINELEN, fileptr); X `7D`20 X free(str); X`7D /* ptk_restorehashtable */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_restoreallhashtables(C(FILE *) fileptr) XPreANSI(FILE *fileptr) X/* X** \parambegin X** \param`7BFILE *`7D`7Bfileptr`7D`7Bpointer to a file`7D`7BIN`7D X** \paramend X** \blurb`7BThis function restores all hashtables from a file. Effectively, X** \pardesc`7Bptk\_restorehashtable`7D (q.v.) is called for each hashtable i Vn X** the file. The file should`20 X** be open and X** readable when this function is called.`7D X*/ X`7B X Pint i, numtables; X Pchar tablename`5B255`5D; X `20 X fscanf(fileptr, "%d\n", &numtables); X X /* for each hashtable in file */ X for (i = 0; i < numtables; i++) X `7B X fscanf(fileptr, "%s\n", tablename); X ptk_restorehashtable(fileptr, tablename); X `7D `20 X`7D /* ptk_restoreallhashtables */ X X/*-------------------------------------------------------------------------- V*/ X X/* end of hash.c */ $ CALL UNPACK [.SOURCE.LIBRARY]HASH.C;1 1327265634 $ create 'f' X/*-------------------------------------------------------------------------- V-- X XModule name: PHIGS menus utility X XAuthor: Karen Wyrwas X XFunction: This module contains the PHIGS utility routines Xfor menus and high level input tools. They are all built on top of PHIGS. X XExternal function list: ptk_createboxmenu, ptk_createboxmenuitem,`20 Xptk_createusermenu, ptk_createusermenuitem, ptk_drawmenu, ptk_erasemenu,`20 Xptk_scanmenus, ptk_delmenu, ptk_delmenuitem, ptk_createrotator. X XInternal function list: getmenu, getmenuid, ptk_findnextpickid,`20 Xfind_insertion_pt, find_item, shift_items, delete_item, point_in_menu,`20 Xfind_string, string_in_menu, pick_in_menu, disposemenus, get_tlboxcorner,`20 Xinsert_box_item, insert_user_item. X XHashtables used: "structureid", "name", "label". X XModification history: (Version), (Date), (Name), (Description). X X 1.0, 9th March 1988, Karen Wyrwas, First version. X X 1.1, 31st October 1988, Karen Wyrwas, Add rotator routines. X X 1.2, 1st November 1988, Karen Wyrwas, Port to VAX PHIGS. X X 2.0, 25th April 1991, Gareth Williams, Translated to C. X X 2.1, 16th May 1991, Gareth Williams, Functions getmenu, getmenuid, X disposemenus, ptk_inqpickmenus added. X X 2.2, 23rd May 1991, Gareth Williams, Built rotators on top of user menus. X X --------------------------------------------------------------------------- V*/ X X#include X#include X#include X#include X#include "ptk.h" X X/*-------------------------------------------------------------------------- V*/ X X#define PTKCPOSY 1 X#define PTKCNEGY 2 X#define PTKCPOSX 4 X#define PTKCNEGX 3 X#define PTKCPOSZ 5 X#define PTKCNEGZ 6 X X/*-------------------------------------------------------------------------- V*/ X Xtypedef struct ptksmenu X`7B X Pint menuid; X Pint menustid; X Pint wsid; X Pint highlight; X Pint font; X Pint menuname; X Pintlst posted; X X ptkemenutype menutype; X Ptxpath menupath; X Ppoint menuposition; X Pfloat charheight; X Pint maxitem; X Pchar longstr`5B255`5D; X Pint intcolour, edgecolour, tlcolour, brcolour, textcolour; X Pint htintcolour, htedgecolour, httlcolour, htbrcolour, httextcolour; X Ppoint framesize; X Ppoint boxsize; X X /* rotator */ X Ppoint bannercentre, bannerbox; X Pint arrowcolour, arrowedgecolour, bannercolour; X X struct ptksmenu *next; X`7D ptksmenu; X Xtypedef struct`20 X`7B X ptkboolean postedmenus; X ptksmenu *frontptr; X ptksmenu *backptr; X`7D ptkswsmenu; X X/*-------------------------------------------------------------------------- V*/ X Xstatic ptksmenu *menuptr = NULL; Xstatic ptksmenu *firstmenu = NULL; Xstatic ptksmenu *lastmenu = NULL; X Xstatic Pint numwsids = 0; Xstatic Pint wsids`5B10`5D; Xstatic ptkswsmenu wsmenus`5B10`5D; Xstatic Pint menucount = 0; X X/*-------------------------------------------------------------------------- V*/ X/* utility routines V */ X/*-------------------------------------------------------------------------- V*/ X Xstatic void setmenu(C(Pint) menuid) XPreANSI(Pint menuid) X`7B X ptksmenu *ptr; X X if (firstmenu == NULL) X `7B X menuptr = NULL; X return; X `7D X ptr = firstmenu; X while (ptr->menuid != menuid) X `7B X ptr = ptr->next; X if (ptr == NULL) X `7B X menuptr = NULL; X return; X `7D X `7D X menuptr = ptr; X`7D /* setmenu */ X X/*-------------------------------------------------------------------------* V/ X Xstatic void findwsid(C(Pint) wsid, C(Pint *) ind) XPreANSI(Pint wsid) XPreANSI(Pint *ind) X`7B X Pint i; X X *ind = -1; X for (i = 0; i < numwsids; i++) X if (wsids`5Bi`5D == wsid) X *ind = i; X`7D /* findwsid */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void checkws(C(Pint) wsid) XPreANSI(Pint wsid) X`7B X Pint ind; X X findwsid(wsid, &ind); X if (ind == -1) X `7B X wsids`5Bnumwsids`5D = wsid; X wsmenus`5Bnumwsids`5D.postedmenus = FALSE; X wsmenus`5Bnumwsids`5D.frontptr = NULL; X wsmenus`5Bnumwsids`5D.backptr = NULL; X numwsids++; X `7D X`7D /* checkws */ X +-+-+-+-+-+-+-+- END OF PART 207 +-+-+-+-+-+-+-+-