📄 r2protos.c
字号:
/* Create the new entry. */
/*-------------------------------------------------------------------------*/
if ((NewEntry = (TFListADT *) malloc (sizeof(TFListADT))) == NULL)
R2Err(gCurrentTrace->filePath[Index], Line, "Out of memory.");
NewEntry->Index = Index;
NewEntry->Line = Line;
NewEntry->prev = NULL;
NewEntry->next = NULL;
/*-------------------------------------------------------------------------*/
/* If the list is currently empty, make a new entry at the head */
/*-------------------------------------------------------------------------*/
if (head == NULL) {
(*ListEntries)++;
return NewEntry;
}
/*-------------------------------------------------------------------------*/
/* If the file index and line number are equal to the head, return. */
/*-------------------------------------------------------------------------*/
if ((Index == head->Index) &&
(Line == head->Line)) {
free(NewEntry);
return head;
}
/*-------------------------------------------------------------------------*/
/* If the new entry precedes the current head, insert it as the new head */
/*-------------------------------------------------------------------------*/
if ((Index < head->Index) ||
((Index == head->Index) && (Line < head->Line))) {
NewEntry->next = head;
head->prev = NewEntry;
(*ListEntries)++;
return NewEntry;
}
/*-------------------------------------------------------------------------*/
/* If the new entry is after the current head, but the head has no next */
/* value (currently only 1 entry), place the new entry at the end of */
/* the list. */
/*-------------------------------------------------------------------------*/
if (head->next == NULL) {
head->next = NewEntry;
NewEntry->prev = head;
(*ListEntries)++;
return head;
}
/*-------------------------------------------------------------------------*/
/* Perform a binary search to find where to put the new entry in the */
/* list. */
/*-------------------------------------------------------------------------*/
TempEntry = head;
for (JumpValue = (*ListEntries+1)/2; JumpValue > 0; JumpValue /= 2) {
if ((Index > TempEntry->Index) ||
((Index == TempEntry->Index) && (Line > TempEntry->Line))) {
for (i =0; i < JumpValue; i++) {
if (TempEntry->next != NULL)
TempEntry = TempEntry->next;
}
}
else if ((Index < TempEntry->Index) ||
((Index == TempEntry->Index) &&
(Line < TempEntry->Line))) {
for (i =0; i < JumpValue; i++) {
if (TempEntry->prev != NULL)
TempEntry = TempEntry->prev;
}
}
else {
free(NewEntry);
return head;
}
if ((JumpValue > 1) && (JumpValue%2 != 0))
JumpValue++;
}
/*-------------------------------------------------------------------------*/
/* At the end of the binary search, if the current file index and line */
/* number are the same, return. */
/*-------------------------------------------------------------------------*/
if ((TempEntry->Index == Index) &&
(TempEntry->Line == Line)) {
free(NewEntry);
return head;
}
/*-------------------------------------------------------------------------*/
/* The new entry needs to be inserted before or after the entry found */
/* in the binary search. */
/*-------------------------------------------------------------------------*/
(*ListEntries)++;
if ((NewEntry->Index < TempEntry->Index) ||
((NewEntry->Index == TempEntry->Index) &&
(NewEntry->Line < TempEntry->Line))) {
NewEntry->next = TempEntry;
NewEntry->prev = TempEntry->prev;
TempEntry->prev->next = NewEntry;
TempEntry->prev = NewEntry;
return head;
}
else if ((NewEntry->Index > TempEntry->Index) ||
((NewEntry->Index == TempEntry->Index) &&
(NewEntry->Line > TempEntry->Line))) {
NewEntry->prev = TempEntry;
NewEntry->next = TempEntry->next;
if (TempEntry->next != NULL) {
TempEntry->next->prev = NewEntry;
}
TempEntry->next = NewEntry;
return head;
}
return head; /* should never get here! */
}
/*=========================================================================*/
/* FUNCTION: NewSwitch */
/*=========================================================================*/
/* PURPOSE : Creates a new pointer to a SwitchListADT. */
/* */
/* SYSTEM : RECON II */
/* */
/* CALLS : None */
/* */
/* USED BY : SwitchListAdd, OutputSwitchList, FreeSwitchList */
/* */
/* HISTORY : */
/* VER DATE AUTHOR DESCRIPTION */
/* ?.?? 09 Mar 95 C. Casey Create NewSwitch */
/*-------------------------------------------------------------------------*/
static SwitchListADT *NewSwitch(void)
{
SwitchListADT *NSwitch;
NSwitch = (SwitchListADT *)malloc(sizeof(SwitchListADT));
if (NSwitch != NULL) {
NSwitch->Index = 0;
NSwitch->Line = 0;
NSwitch->ValuesFound = NULL;
NSwitch->next = NULL;
NSwitch->prev = NULL;
}
return NSwitch;
}
/*=========================================================================*/
/* FUNCTION: SwitchListAdd */
/*=========================================================================*/
/* PURPOSE : Adds a SwitchList entry to a SwitchListADT. */
/* */
/* SYSTEM : RECON II */
/* */
/* CALLS : NewSwitch, NewSwitchValue, R2Err */
/* */
/* USED BY : R2Switch */
/* */
/* HISTORY : */
/* VER DATE AUTHOR DESCRIPTION */
/* ?.?? 09 Mar 95 C. Casey Create SwitchListAdd */
/* 2.00 23 Mar 97 J. Ward Modified to base list on file index and */
/* line number, not a value composed of the */
/* two which limited the number of files */
/* to 999, per Tisk 17. */
/*-------------------------------------------------------------------------*/
static SwitchListADT *SwitchListAdd(SwitchListADT *head, int Index,
int Line, int switchvalue,
SwitchListADT *sladtentry)
{
int JumpValue, i;
SwitchListADT *TempList;
SwitchValueListADT *TempValue;
/*-------------------------------------------------------------------------*/
/* Create a new switch value list structure */
/*-------------------------------------------------------------------------*/
if ((TempValue = NewSwitchValue()) == NULL)
R2Err(gCurrentTrace->filePath[Index], Line, "Out of memory.");
TempValue->value = switchvalue;
/*-------------------------------------------------------------------------*/
/* If the list is currently empty, make the new entry the head */
/*-------------------------------------------------------------------------*/
if (head == NULL) {
sladtentry->ValuesFound = SwitchValueListAdd(sladtentry->ValuesFound, TempValue);
gCurrentTrace->SwitchListEntries++;
return sladtentry;
}
/*-------------------------------------------------------------------------*/
/* If the file index and line number are equal to the head, add the */
/* new switch value to the head. */
/*-------------------------------------------------------------------------*/
if ((sladtentry->Index == head->Index) &&
(sladtentry->Line == head->Line)) {
head->ValuesFound = SwitchValueListAdd(head->ValuesFound, TempValue);
FreeSwitchList(sladtentry);
return head;
}
/*-------------------------------------------------------------------------*/
/* If the new entry precedes the current head, insert it as the new head */
/*-------------------------------------------------------------------------*/
if ((sladtentry->Index < head->Index) ||
((sladtentry->Index == head->Index) &&
(sladtentry->Line < head->Line))) {
sladtentry->ValuesFound = SwitchValueListAdd(sladtentry->ValuesFound, TempValue);
sladtentry->next = head;
head->prev = sladtentry;
gCurrentTrace->SwitchListEntries++;
return sladtentry;
}
/*-------------------------------------------------------------------------*/
/* If the new entry is after the current head, but the head has no next */
/* value (currently only 1 entry), place the new entry at the end of */
/* the list. */
/*-------------------------------------------------------------------------*/
if (head->next == NULL) {
sladtentry->ValuesFound = SwitchValueListAdd(sladtentry->ValuesFound, TempValue);
sladtentry->next = head->next;
head->next = sladtentry;
sladtentry->prev = head;
gCurrentTrace->SwitchListEntries++;
return head;
}
/*-------------------------------------------------------------------------*/
/* Perform a binary search to find where to put the new entry in the */
/* list. */
/*-------------------------------------------------------------------------*/
TempList = head;
for (JumpValue = (gCurrentTrace->SwitchListEntries+1)/2; JumpValue > 0; JumpValue /= 2) {
if ((sladtentry->Index > TempList->Index) ||
((sladtentry->Index == TempList->Index) &&
(sladtentry->Line > TempList->Line))) {
for (i =0; i < JumpValue; i++) {
if (TempList->next != NULL)
TempList = TempList->next;
}
}
else if ((sladtentry->Index < TempList->Index) ||
((sladtentry->Index == TempList->Index) &&
(sladtentry->Line < TempList->Line))) {
for (i =0; i < JumpValue; i++) {
if (TempList->prev != NULL)
TempList = TempList->prev;
}
}
else {
TempList->ValuesFound = SwitchValueListAdd(TempList->ValuesFound, TempValue);
FreeSwitchList(sladtentry);
return head;
}
if ((JumpValue > 1) && (JumpValue%2 != 0))
JumpValue++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -