-+-+-+-+-+-+-+-+ START OF PART 250 -+-+-+-+-+-+-+-+ X if (structlist->postings`5Bs`5D.priority == X structlist->postings`5Bprilist->index`5D.priority) X `7B X /* insert immediately after first entry in list */ X p->next = prilist->next; X p->distinct = FALSE; X prilist->next = p; X `7D`20 X else`20 X if (structlist->postings`5Bs`5D.priority <`20 X structlist->postings`5Bprilist->index`5D.priority)`20 X `7B X /* insert point at start of list */ X p->next = prilist; X p->distinct = TRUE; X prilist = p; X pricount++; X `7D`20 X else`20 X `7B X /* search down list until place is found */ X ptr = prilist; X placefound = FALSE; X while (ptr->next != NULL && !placefound)`20 X `7B X`09if (structlist->postings`5Bs`5D.priority == X structlist->postings`5Bptr->next->index`5D.priority) X `7B X`09 placefound = TRUE; X`09 /* insert priority 's' just after priority in list X`09 ** which is the same and don't increment 'pricount' X */ X`09 ptr = ptr->next; X`09 p->distinct = FALSE; X`09 continue; X`09`7D X`09if (structlist->postings`5Bs`5D.priority <`20 X structlist->postings`5Bptr->next->index`5D.priority)`20 X `7B X`09 placefound = TRUE; X`09 p->distinct = TRUE; X`09 pricount++; X`09 continue; X`09`7D X`09ptr = ptr->next; X`09/* skip over repeated priorities in the list */ X`09founddistinct = FALSE; X`09while (ptr->next != NULL && !founddistinct)`20 X `7B X`09 if (ptr->next->distinct) X`09 founddistinct = TRUE; X`09 else X`09 ptr = ptr->next; X`09`7D X `7D X if (!placefound)`20 X `7B X`09p->distinct = TRUE; X`09pricount++; X `7D X /* insert priority at current place in list */ X p->next = ptr->next; X ptr->next = p; X `7D X `7D /* for */ X /* 'pricount' now indicates how many distinct priorities there are, X ** if there are n distinct priorities then divide the range `5B0,1`5D into V n+1 X ** equal parts so that don't have to use priorities 0 and 1. X */ X pristep = 1.0 / (pricount + 1); X ptr = prilist; X currpriority = 0.0; X while (ptr != NULL)`20 X `7B X if (ptr->distinct) /* increase current priority by one step */ X currpriority += pristep; X structlist->postings`5Bptr->index`5D.priority = currpriority; X punpoststruct(ws, structlist->postings`5Bptr->index`5D.id); X ppoststruct(ws, structlist->postings`5Bptr->index`5D.id, currpriority); X p = ptr; X ptr = ptr->next; X free(p); X `7D X`7D /* ptk_redistributepriorities */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void ptk_findpriority(C(Pint) ws, C(Pvpri) relpriority,`20 X C(Pint) relstruct, C(Pfloat *) priority,`20 X C(Pint *) error) XPreANSI(Pint ws) XPreANSI(Pvpri relpriority) XPreANSI(Pint relstruct) XPreANSI(Pfloat *priority) XPreANSI(Pint *error) X/* X** \parambegin X** \param`7B`7D`7Bws`7D`7Bworkstation identifier`7D`7BIN`7D X** \param`7B`7D`7Brelpriority`7D`7Bpriority of posted structure relative to V ref structure`7D`7BIN`7D X** \param`7B`7D`7Brelstruct`7D`7Breference structure`7D`7BIN`7D X** \param`7B`7D`7Bpriority`7D`7Breturned priority value`7D`7BOUT`7D X** \param`7B`7D`7Berror`7D`7Berror code`7D`7BOUT`7D X** \paramend X** \blurb`7BThis is an internal procedure called by ptk_postrelative X** ptk_changepostpriority, to compute a structure priority given X** a reference structure and whether the new priority should be higher X** or lower than that of reference structure X** WARNING if the new priority requested can not be obtained, because X** of one of the following: X** 1. asking for a higher priority than 1 X** 2. asking for lower priority than 0 X** 3. there is insufficient gap between the priority of 'relstruct' and the X** next higher or lower priority to fit in a new priority X** X** all the priorities on the workstation will be redistributed to regular X** intervals over the range `5B0,1`5D. X** all the posted structures.`7D X*/ X`7B X Pint numstructs, s; X ptkboolean found, done; X Pint relstruct_index, nearest, ind; X Pfloat nearest_priority; X Pstructpostlst structlist; X X if (!ptk_structexists(relstruct))`20 X `7B X *error = 1; X return; X `7D X structlist.postings = NULL; X pinqpostedstruct(ws, 0, 0, error, &structlist, &numstructs); X structlist.postings = (Pstructpost *)calloc(numstructs,`20 X sizeof(Pstructpost)); X pinqpostedstruct(ws, numstructs, 0, error, &structlist, &numstructs); X X /* find position in array of 'relstruct'*/ X s = 0; X found = FALSE; X while ((s < numstructs) && (!found))`20 X `7B X found = (structlist.postings`5Bs`5D.id == relstruct); X if (!found) X s++; X `7D X if (!found)`20 X `7B X return; X `7D X *error = 0; X relstruct_index = s; X X /* first check whether requesting higher priority than highest possible X ** or lower priority than lowest possible. X */ X if ((relpriority == PLOWER) &&`20 X (structlist.postings`5Brelstruct_index`5D.priority == 0.0) `7C`7C`20 X ((relpriority == PHIGHER) && X (structlist.postings`5Brelstruct_index`5D.priority == 1.0)))`20 X `7B X /* redistribute all priorities on workstation to make room X ** for a lower or higher priority X */ X ptk_redistributepriorities(ws, &structlist); X /* new priority is half way between new priority for 'relstruct' X ** and 0 or 1, depending on 'relpriority'. X */ X if (relpriority == PLOWER) X *priority = structlist.postings`5Brelstruct_index`5D.priority / 2.0; X else X *priority = (structlist.postings`5Brelstruct_index`5D.priority + 1.0) V / 2.0; X return; X `7D X X nearest = 0; X X if (relpriority == PLOWER)`20 X `7B X nearest_priority = 0.0; X for (s = 0; s < numstructs; s++)`20 X `7B X if ((structlist.postings`5Bs`5D.priority <`20 X structlist.postings`5Brelstruct_index`5D.priority) && X`09 (structlist.postings`5Bs`5D.priority > nearest_priority))`20 X `7B X`09nearest = s; X`09nearest_priority = structlist.postings`5Bs`5D.priority; X `7D X `7D X `7D`20 X else`20 X `7B `20 X /* relpriority = PHIGHER */ X nearest_priority = 1.0; X for (s = 0; s < numstructs; s++)`20 X `7B X if ((structlist.postings`5Bs`5D.priority > X structlist.postings`5Brelstruct_index`5D.priority) && X`09 (structlist.postings`5Bs`5D.priority < nearest_priority))`20 X `7B X`09nearest = s; X`09nearest_priority = structlist.postings`5Bs`5D.priority; X `7D X `7D X `7D X X /* new priority will be half way between priority of X ** 'relstruct' and 'nearest_priority'. X */ X X *priority = (structlist.postings`5Brelstruct_index`5D.priority +`20 X nearest_priority) / 2.0; X X /* if distance between priority of 'relstruct' and X ** 'nearest_priority' is so small that new priority computed X ** is approx equal to priority of 'relstruct', redistribute X ** all priorities on workstation. X */ X if (!ptk_equal(*priority, structlist.postings`5Brelstruct_index`5D.priorit Vy)) X return; X ptk_redistributepriorities(ws, &structlist); X /* now recompute new priority as before, using new priorities X ** for 'relstruct' and 'nearest'. If a priority just higher X ** or lower than 'relstruct' was not found (in which case nearest X ** is still 0) use 'nearest_priority' rather than priority for X ** 'nearest' which will either be 0 or 1. X */ X if (nearest != 0) X *priority = (structlist.postings`5Brelstruct_index`5D.priority +`20 X structlist.postings`5Bnearest`5D.priority) / 2.0; X else X *priority = (structlist.postings`5Brelstruct_index`5D.priority +`20 X nearest_priority) / 2.0; X`7D /* ptk_findpriority */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_postrelative(C(Pint) ws, C(Pint) structid,`20 X C(Pvpri) relpriority, C(Pint) relstruct,`20 X C(Pint *) error) XPreANSI(Pint ws) XPreANSI(Pint structid) XPreANSI(Pvpri relpriority) XPreANSI(Pint relstruct) XPreANSI(Pint *error) X/* X** \parambegin X** \param`7BPint`7D`7Bws`7D`7Bworkstation identifier`7D`7BIN`7D X** \param`7BPint`7D`7Bstructid`7D`7Bstructure identifier`7D`7BIN`7D X** \param`7BPvpri`7D`7Brelpriority`7D`7Brelative priority`7D`7BIN`7D X** \param`7BPint`7D`7Brelstruct`7D`7Brelative structure identifier`7D`7BIN`7 VD X** \param`7BPint *`7D`7Berror`7D`7Berror code`7D`7BOUT`7D X** \paramend X** \blurb`7BThis function posts structure \pardesc`7Bstructid`7D at a priori Vty higher or X** lower than that of structure \pardesc`7Brelative structure identifier`7D, X** according to \pardesc`7Brelative priority`7D.`20 X** If \pardesc`7Brelative structure identifier`7D does not exist,`20 X** \pardesc`7Berror`7D is set to`20 X** 1. Otherwise, its value is 0.`7D X*/ X`7B X Pfloat priority; X X *error = 0; X if (!ptk_structexists(structid))`20 X `7B X printf("ptk_postrelative: %d doesn't exist\n", structid); X *error = 1; X `7D`20 X else`20 X `7B X ptk_findpriority(ws, relpriority, relstruct, &priority, error); X ppoststruct(ws, structid, priority); X `7D X`7D /* ptk_postrelative */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_changepostpriority(C(Pint) ws, C(Pint) structid, X C(Pvpri) relpriority, C(Pint) relstruct,`20 X C(Pint *) error) XPreANSI(Pint ws) XPreANSI(Pint structid) XPreANSI(Pvpri relpriority) XPreANSI(Pint relstruct) XPreANSI(Pint *error) X/* X** \parambegin X** \param`7BPint`7D`7Bws`7D`7Bworkstation identifier`7D`7BIN`7D X** \param`7BPint`7D`7Bstructid`7D`7Bstructure identifier`7D`7BIN`7D X** \param`7BPvpri`7D`7Brelpriority`7D`7Brelative priority`7D`7BIN`7D X** \param`7BPint`7D`7Brelstruct`7D`7Brelative structure identifier`7D`7BIN`7 VD X** \param`7BPint *`7D`7Berror`7D`7Berror code`7D`7BOUT`7D X** \paramend X** \blurb`7BThis function changes the priority of structure \pardesc`7Bstruc Vtid`7D X** to immediately higher or lower than that of \pardesc`7Brelstruct`7D, X** according to \pardesc`7Brelpriority`7D.`20 X** If \pardesc`7Bstructid`7D does not exist,`20 X** \pardesc`7Berror`7D is set to`20 X** 1. Otherwise, its value is 0.`7D X*/ X`7B X Pfloat priority; X X *error = 0; X if (!ptk_structexists(structid))`20 X `7B X printf("ptk_changepostpriority: %d doesn't exist\n", structid); X *error = 1; X return; X `7D X ptk_findpriority(ws, relpriority, relstruct, &priority, error); X punpoststruct(ws, structid); X ppoststruct(ws, structid, priority); X`7D /* ptk_changepostpriority */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_inqpostpriority(C(Pint) wsid, C(Pint) structid, X C(Pfloat *) priority, C(Pint *) err) XPreANSI(Pint wsid) XPreANSI(Pint structid) XPreANSI(Pfloat *priority) XPreANSI(Pint *err) X/* X** \parambegin X** \param`7BPint`7D`7Bwsid`7D`7Bworkstation identifier`7D`7BIN`7D X** \param`7BPint`7D`7Bstructid`7D`7Bstructure identifier`7D`7BIN`7D X** \param`7BPfloat *`7D`7Bpriority`7D`7Bpriority value`7D`7BIN`7D X** \param`7BPint *`7D`7Berr`7D`7Berror indicator`7D`7BOUT`7D X** \paramend X** \blurb`7BThis function may be used to obtain`20 X** the priority of posted structure \pardesc`7Bstructid`7D. X** If \pardesc`7Bstructid`7D does not exist,`20 X** \pardesc`7Berr`7D is set to`20 X** 1. If it is not posted to `7B\tt wsid`7D then `7B\tt err`7D is set to 2.` V7D X*/ X`7B X Pint numstructs, i; X ptkboolean found; X Pstructpostlst structlist; X X *err = 0; X if (!ptk_structexists(structid))`20 X `7B X *err = 1; X fprintf(stderr, "ptk_inqpostpriority: %d doesn't exist\n", structid); X return; X `7D X structlist.postings = NULL; X pinqpostedstruct(wsid, 0, 0, err, &structlist, &numstructs); X structlist.postings = (Pstructpost *)calloc(numstructs,`20 X sizeof(Pstructpost)); X pinqpostedstruct(wsid, numstructs, 0, err, &structlist, &numstructs); X i = 0; X found = FALSE; X while ((i < numstructs) && (!found))`20 X `7B X found = (structlist.postings`5Bi`5D.id == structid); X if (found) X *priority = structlist.postings`5Bi`5D.priority; X else X i++; X `7D X free(structlist.postings); X if (!found) X *err = 2; X`7D /* ptk_inqpostpriority */ X X/*-------------------------------------------------------------------------- V*/ X/*----------------------- Workstation Functions ---------------------------- V*/ X X/*function:external*/ Xextern void ptk_copycolourtable(C(Pint) sourcewsid, C(Pint) destwsid) XPreANSI(Pint sourcewsid) XPreANSI(Pint destwsid) X/* X** \parambegin X** \param`7BPint`7D`7Bsourcewsid`7D`7Bsource workstation identifier`7D`7BIN` V7D X** \param`7BPint`7D`7Bdestwsid`7D`7Bdestination workstation identifier`7D`7B VIN`7D X** \paramend X** \blurb`7BThis function copies the colour X** table from workstation \pardesc`7Bsourcewsid`7D to X** workstation \pardesc`7Bdestwsid`7D.`7D X*/ X`7B X Pintlst colourind; X Pint totlen, err, i, totsize, tablesize; X Pcobundl rep; X Pwstables lengths; X Pchar *buffer; X Pconnid connid; X Pwstype wstype; X X pinqwsconntype(destwsid, 0, &err, buffer, &connid, &totsize, &wstype); X buffer = (Pchar *)malloc(totsize); X pinqwsconntype(destwsid, totsize, &err, buffer, &connid, &totsize, &wstype V); X#ifdef VMS X pinqwssttable(wstype, &err, &lengths); X tablesize = lengths.colour; X#endif X#ifdef SUN X tablesize = (Pint)phigs_ws_type_get(wstype, PHIGS_COLOUR_TABLE_SIZE); X#endif X pinqcolourind(sourcewsid, 0, 0, &err, &colourind, &totlen); X colourind.integers = (Pint *)calloc(totlen, sizeof(Pint)); X colourind.number = totlen; X pinqcolourind(sourcewsid, totlen, 0, &err, &colourind, &totlen); X tablesize = MIN(colourind.number, tablesize); X for (i = 0; i < tablesize; i++) X `7B X pinqcolourrep(sourcewsid, colourind.integers`5Bi`5D, PSET, &err, &rep); X psetcolourrep(destwsid, colourind.integers`5Bi`5D, &rep); +-+-+-+-+-+-+-+- END OF PART 250 +-+-+-+-+-+-+-+-