Exemplo n.º 1
0
void LinkedSortedList<T>::clear() {
    for(iter = getListHead(); iter != NULL; iter = iter->next) {
        LinkedNode<T> * tmp = iter;
        if(tmp) delete tmp;
    }
    setListHead(NULL);
    iter = getListHead();
    size_ = 0;
}
Exemplo n.º 2
0
bool LinkedSortedList<T>::insert(LinkedNode<T> *node) {
    iter = getListHead();
    if(!iter) {			// First node becomes head.
        setListHead(node);

#ifdef DEBUG_LIST_INSERT
        cout << "Insert First node. "
             << node->getValue().getLastName() << endl;
#endif

        size_++;
        return true;
    }
    for(iter = getListHead(); iter; iter = iter->next) {
        if(*node <= *iter) {	// node is smaller, insert in front.

#ifdef DEBUG_LIST_INSERT
            cout << "Insert node: " << node->getValue().getLastName()
                 << " \tbefore: " << iter->getValue().getLastName() << endl;
#endif
            node->next = iter;
            node->prev = iter->prev;
            if(iter == getListHead()) { // insert to Head.
                setListHead(node);

#ifdef DEBUG_LIST_INSERT
                cout << "Set head to: " << node->getValue().getLastName() <<
                     endl;
#endif

            }	else {			// not head insert.
                iter->prev->next = node; // Head does not have this.
            }
            iter->prev = node;
            size_++;
            return true;

        } else if((*node > *iter) && (!(iter->next))) {//tail

#ifdef DEBUG_LIST_INSERT
            cout << "Insert tail: " << node->getValue().getLastName()
                 << " \tafter: " << iter->getValue().getLastName() << endl;
#endif

            iter->next = node;
            node->prev = iter;
            node->next = NULL;
            size_++;
            return true;
        }
    } // while
}
Exemplo n.º 3
0
/// Function name  : calculateGeneratorVariableIDFromName
// Description     : Returns the ID of the argument/variable in a ScriptGenerator with a given name.
//                    -> If the argument/variable does not already exist, it is created
// 
// SCRIPT_GENERATOR*  pGenerator  : [in] ScriptGenerator to search
// CONST TCHAR*       szVariable  : [in] Name of the argument/variable to search for
// 
// Return Value   : One-based Variable ID
// 
UINT  calculateGeneratorVariableIDFromName(SCRIPT_GENERATOR*  pGenerator, CONST TCHAR*  szVariable)
{
   VARIABLE_NAME*  pVariableName;      // Pre-existing VariableName or newly created VariableName

   /// Iterate through existing VariableNames for a match
   for (LIST_ITEM*  pIterator = getListHead(pGenerator->pVariablesList); pIterator; pIterator = pIterator->pNext)
   {
      // Prepare
      pVariableName = extractListItemPointer(pIterator, VARIABLE_NAME);

      // [CHECK] Does current VariableName match?
      if (utilCompareStringVariables(pVariableName->szName, szVariable))
         /// [FOUND] Return associated ID
         return pVariableName->iID;
   }

   /// [NOT FOUND] Create a new VariableName with a zero-based ID
   pVariableName = createVariableName(szVariable, getListItemCount(pGenerator->pVariablesList));

   // Append to Generators's VariableNames list
   appendObjectToList(pGenerator->pVariablesList, (LPARAM)pVariableName);

   /// [FOUND] Return ID of new VariableName
   return pVariableName->iID;
}
Exemplo n.º 4
0
/// Function name  : findXMLTreeNodeByName
// Description     : Finds a node within an XML tree by name.
// 
// XML_TREE_NODE*   pStartNode       : [in]  Node to start searching from
// CONST TCHAR*     szName           : [in]  Name of node to search for
// CONST BOOL       bRecurseChildren : [in]  Whether to search child nodes recursively or just search the immediate child nodes
// XML_TREE_NODE*  &pOutput          : [out] Desired node if found, otherwise NULL
// 
// Return Value   : TRUE if found, FALSE otherwise
// 
BearScriptAPI
BOOL  findXMLTreeNodeByName(CONST XML_TREE_NODE*  pStartNode, CONST TCHAR*  szName, CONST BOOL  bRecurseChildren, XML_TREE_NODE*  &pOutput)
{
   XML_TREE_NODE*  pCurrentNode; // Node within the list item currently being processed

   // [CHECK] Ensure start node exists
   ASSERT(pStartNode != NULL);

   // Prepare
   pOutput = NULL;

   /// Iterate through child node list
   for (LIST_ITEM*  pIterator = getListHead(&pStartNode->oChildren); pCurrentNode = extractListItemPointer(pIterator, XML_TREE_NODE); pIterator = pIterator->pNext)
   {
      // Check node name
      if (utilCompareStringVariables(pCurrentNode->szName, szName))
      {
         /// [FOUND-DIRECT] Set result and abort
         pOutput = pCurrentNode;
         break;
      }
      /// Recurse into children
      else if (bRecurseChildren AND findXMLTreeNodeByName(pCurrentNode, szName, bRecurseChildren, pOutput))
         /// [FOUND-INDIRECT] Abort...
         break;
   }

   /// Return TRUE if found, FALSE otherwise
   return (pOutput != NULL);
}
Exemplo n.º 5
0
/// Function name  : findNextXMLTreeNode
// Description     : Retrieve the next child or sibling of a specified node
// 
// XML_TREE_NODE*               pNode         : [in]  The input node, this will not be altered 
// CONST XML_NODE_RELATIONSHIP  eRelationship : [in]  Whether to find the first child or first sibling node
// XML_TREE_NODE*              &pOutput       : [out] Desired node if successful, otherwise NULL
// 
// Return Value   : TRUE if found, FALSE otherwise
// 
BearScriptAPI
BOOL  findNextXMLTreeNode(CONST XML_TREE_NODE*  pNode, CONST XML_NODE_RELATIONSHIP  eRelationship, XML_TREE_NODE*  &pOutput)
{
   LIST_ITEM*  pItem;

   // Prepare
   /*if (!pNode)
      return FALSE;*/

   // Examine relationship
   switch (eRelationship)
   {
   /// [CHILD] Return first child
   case XNR_CHILD:
      // Advance to the first child of the current node (if any)
      if (getXMLNodeCount(pNode))
      {
         pItem = getListHead(&pNode->oChildren);
         pOutput = extractListItemPointer(pItem, XML_TREE_NODE);
      }
      // [NOT FOUND] Set result to NULL
      else
         pOutput = NULL;
      break;

   /// [SIBLING] Return the next item within the list containing the input node
   case XNR_SIBLING:
      // [CHECK] Cannot perform on the root
      if (pNode->pItem == NULL)
         pOutput = NULL;

      // Advance to the node's next item
      else if (pNode->pItem->pNext)
      {
         pItem = pNode->pItem->pNext;
         pOutput = extractListItemPointer(pItem, XML_TREE_NODE);
      }
      // [NOT FOUND] Set result to NULL
      else
         pOutput = NULL;
      break;

   /// [PARENT] Return the input node's parent node (if any)
   case XNR_PARENT: 
      pOutput = (pNode->pParent ? pNode->pParent : NULL);
      break;
   }

   // Return TRUE if found, FALSE otherwise
   return (pOutput != NULL);
}
/// Function name  : onDependenciesLoadSelectedScripts
// Description     : Loads the selected script dependencies
// 
// PROPERTIES_DATA*  pSheetData   : [in] Properties sheet dialog data
// HWND              hPage        : [in] Window handle of the dependencies page
// 
VOID   onDependenciesPage_LoadSelectedScripts(HWND  hPage, SCRIPT_FILE*  pScriptFile, AVL_TREE*  pDependenciesTree)
{
   SCRIPT_DEPENDENCY*   pDependency;      // ScriptDependency associated with the selected item
   LOADING_OPTIONS      oOptions;         // Used for highlighting caller
   HWND                 hListView;        // Dependencies ListView
   TCHAR*               szFolder;         // Folder of input script
   LIST*                pDependencyList;  // List of selected ScriptDepdencies
   INT                  iSelected;        // Index of the selected item
            
   /// [CHECK] Are any dependencies selected?
   if (ListView_GetSelectedCount(hListView = GetDlgItem(hPage, IDC_DEPENDENCIES_LIST)) == 0)
      return;
   
   // [VERBOSE]
   CONSOLE_COMMAND();

   // Prepare
   utilZeroObject(&oOptions, LOADING_OPTIONS);
   pDependencyList = createList(NULL);
   
   /// Extract ScriptDependencies for selected scripts
   for (iSelected = ListView_GetSelected(hListView); findObjectInAVLTreeByIndex(pDependenciesTree, iSelected, (LPARAM&)pDependency); iSelected = ListView_GetNextItem(hListView, iSelected, LVNI_SELECTED))
   {
      appendObjectToList(pDependencyList, (LPARAM)pDependency);
      debugScriptDependency(pDependency);
   }

   // Clear selection
   ListView_SetItemState(hListView, -1, NULL, LVIS_SELECTED);
   szFolder = utilDuplicateFolderPath(pScriptFile->szFullPath);

   /// Attempt to open each selected script
   for (LIST_ITEM*  pIterator = getListHead(pDependencyList); pDependency = extractListItemPointer(pIterator, SCRIPT_DEPENDENCY); pIterator = pIterator->pNext)
   {
      //// Highlight Scriptcall on load
      //oOptions.bHighlight = TRUE;
      //StringCchCopy(oOptions.szSearchText, 256, pScriptFile->szScriptname);

      /// Attempt to open .pck / .xml version of script
      if (!commandLoadScriptDependency(getMainWindowData(), szFolder, pDependency, !pIterator->pNext, &oOptions))  // Activate the final document
         // [ERROR] "The script dependency '%s' could not be found in '%s'"
         displayMessageDialogf(hPage, IDS_GENERAL_DEPENDENCY_NOT_FOUND, MDF_OK WITH MDF_ERROR, pDependency->szScriptName, szFolder);
   }

   // Cleanup
   deleteList(pDependencyList);
   utilDeleteString(szFolder);
}
Exemplo n.º 7
0
/// Function name  : calculateGeneratorForEachCommandCount
// Description     : Counts the number of existing 'for each' commands already generated. This is used for assigning unique iterator variable names
// 
// SCRIPT_GENERATOR*  pGenerator : [in] ScriptGenerator
// 
// Return Value   : Zero-based count
// 
UINT  calculateGeneratorForEachCommandCount(SCRIPT_GENERATOR*  pGenerator)
{
   COMMAND*  pCommand;
   UINT      iCount = 0;

   /// Iterate through standard commands
   for (LIST_ITEM*  pIterator = getListHead(pGenerator->pOutputStream->pStandardList); pCommand = extractListItemPointer(pIterator, COMMAND); pIterator = pIterator->pNext)
   {
      // [FOR EACH IN ARRAY] Add to count
      if (isCommandID(pCommand, CMD_FOR_EACH))
         iCount++;
   }

   // Return result
   return iCount;
}
Exemplo n.º 8
0
/// Function name  : traverseXMLTree
// Description     : Traverse through an XML Tree, printing each node to the console
// 
// XML_TREE_NODE*  pStartNode : [in] Node to start traversal at
// 
BearScriptAPI
VOID  traverseXMLTree(XML_TREE_NODE*  pStartNode)
{
   XML_TREE_NODE*  pCurrentNode;

   // [CHECK] Ensure start node exists
   ASSERT(pStartNode != NULL);

   // Iterate through child node list
   for (LIST_ITEM*  pIterator = getListHead(&pStartNode->oChildren); pCurrentNode = extractListItemPointer(pIterator, XML_TREE_NODE); pIterator = pIterator->pNext)
   {
      // Print tag name
      CONSOLE("Node: '%s' (%u properties)", pCurrentNode->szName, pCurrentNode->oProperties.iCount);

      // Recurse into children
      traverseXMLTree(pCurrentNode);
   }
}
Exemplo n.º 9
0
/// Function name  : findXMLPropertyByName
// Description     : Search for a property within a node by name
// 
// CONST XML_TREE_NODE*  pNode      : [in] Node
// CONST TCHAR*          szProperty : [in] Property name
// XML_PROPERTY*        &pOutput    : [out] Property
// 
// Return Value   : TRUE/FALSE
// 
BOOL   findXMLPropertyByName(CONST XML_TREE_NODE*  pNode, CONST TCHAR*  szProperty, XML_PROPERTY*  &pOutput)
{
   XML_PROPERTY*  pProperty;

   // Prepare
   pOutput = NULL;

   /// Iterate through node properties
   for (LIST_ITEM*  pIterator = getListHead(&pNode->oProperties); !pOutput AND (pProperty = extractListItemPointer(pIterator, XML_PROPERTY)); pIterator = pIterator->pNext)
   {
      /// Determine whether property name matches
      if (utilCompareStringVariables(pProperty->szName, szProperty))
         // [FOUND] Set result and abort
         pOutput = pProperty;
   }

   // Return TRUE if found
   return pOutput != NULL;
}
Exemplo n.º 10
0
bool LinkedSortedList<T>::deleteNode(LinkedNode<T> *node) {
    if(!node) return false;	// node is NULL;
    // First, we need to release the node before deleting.
    if(getListHead() == node) {	// Head node.
        setListHead(node->next);
    } else if(node->next == NULL) {
        node->prev->next = NULL;
    } else {
        node->prev->next = node->next;
        node->next->prev = node->prev;
    }
    // Now, delete node.
#ifdef DEBUG_LIST_DELETE
    cout << "Deleted record for : "
         << node->getValue().getLastName()
         << "\t" << node->getValue().getEid() << endl;
#endif
    delete node;
    size_--;
    return true;
}
Exemplo n.º 11
0
CELL * p_join(CELL * params)
{
char * joint = NULL;
CELL * list;
size_t jointLen = 0;
int trailJoint = 0;

params = getListHead(params, &list);
if(list == nilCell)
	return(stuffString(""));

if(list->type != CELL_STRING)
	return(errorProcExt(ERR_STRING_EXPECTED, list));

if(params != nilCell)
	{
	params = getStringSize(params, &joint, &jointLen, TRUE);
	trailJoint = getFlag(params);
	}

return(appendString(list, list->next, joint, jointLen, trailJoint, FALSE));
}
Exemplo n.º 12
0
/// Function name  : isAnyDocumentModified
// Description     : Determines whether any document is modified
// 
// HWND  hTabCtrl : [in] Documents control
//
// Return Value   : TRUE if there is at least one modified document, otherwise FALSE
// 
BOOL   isAnyDocumentModified(HWND  hTabCtrl)
{
   DOCUMENTS_DATA*  pWindowData;     // Window data
   DOCUMENT*        pDocument;       // Current document
   BOOL             bModified;
   
   // Prepare
   pWindowData = getDocumentsControlData(hTabCtrl);
   bModified   = FALSE;
   
   /// [DOCUMENTS] Iterate through document list
   for (LIST_ITEM*  pIterator = getListHead(pWindowData->pDocumentList); !bModified AND (pDocument = extractListItemPointer(pIterator, DOCUMENT)); pIterator = pIterator->pNext)
      // [CHECK] Abort if document is modified...
      if (isModified(pDocument))
         bModified = TRUE;

   /// [PROJECT] Check project, if any
   if (!bModified)
      bModified = isModified(getActiveProject());
   
   // Return state
   return bModified;
}
Exemplo n.º 13
0
CELL * p_extend(CELL * params)
{
CELL * target;
CELL * head;
CELL * tail;
SYMBOL * symbolRef;
char * pStr;
size_t size;

params = getEvalDefault(params, &target);
if((symbolRef = symbolCheck))
	{
	if(isProtected(symbolRef->flags))
		return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolRef)));
	if(isNil((CELL *)symbolRef->contents))
		{
        deleteList((CELL*)symbolRef->contents);
		head = evaluateExpression(params);
		if(isList(head->type) || head->type == CELL_STRING)
			target = copyCell(head);
        symbolRef->contents = (UINT)target;
		params = params->next;
	    }
	}

if(isList(target->type))
	{
	tail = (CELL *)target->aux;
	target->aux = (UINT)nilCell;
	if(tail == nilCell)
		{
		tail = (CELL *)target->contents;
		while(tail->next != nilCell)
			tail = tail->next;
		}

	while(params != nilCell)
		{	
		params = getListHead(params, &head);
		if(head == nilCell) continue;
		if(target->contents == (UINT)nilCell)
			{
			target->contents = (UINT)copyList(head);
			tail = lastCellCopied;
			}
		else
			{
			tail->next = copyList(head);
			target->aux = (UINT)lastCellCopied;
			tail = (CELL *)target->aux;
			}
		}
		
	}	
else if(target->type == CELL_STRING)
	{
	while(params != nilCell)
		{
		params = getStringSize(params, &pStr, &size, TRUE);
		appendCellString(target, pStr, size);
		}
	}
else return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, target));

symbolCheck = symbolRef;
pushResultFlag = FALSE;
return(target);
}