list_element* insert_element(const char* value, const char* element_position_string){ list_element* insert_cursor=NULL; list_element* temp_cursor=NULL; int i; //find the element that has the element_position_string insert_cursor=search_list_value(element_position_string); //if found then, create the new element if(insert_cursor!=NULL){ temp_cursor=(list_element*) malloc(sizeof(list_element));; for(i=0;i<MAX_NODE_CHARS;i++) { if(*value!='\0') { //add to the graphics list temp_cursor->ListBoxStr[i]=*value; temp_cursor->node_data[i]=*value++; } else { temp_cursor->node_data[i]=0; temp_cursor->ListBoxStr[i]=0; } } // Set the node number of the list to pre-incremented list size head->node_number = list_size++; //copy the pointers to point to temp_cursor->next=insert_cursor->next; temp_cursor->prev=insert_cursor; insert_cursor->next=temp_cursor; temp_cursor->next->prev=temp_cursor; pLISTITEM=LbAddItem(pLb,insert_cursor->list_box_item,&temp_cursor->ListBoxStr,NULL,NULL,1); } }
/************************************************************************ Function: void FillNewElements(void) Overview: Fill the list box with the image and directory elements found in the thumb drive. Input: none Output: none ************************************************************************/ void FillNewElements(void) { SearchRec searchRecord; BYTE bCounter; BYTE bFound; void *pBitmap; NextSlide = 0; bNumElementsInFolder = 0; bFound = FindFirst("*", ATTR_DIRECTORY, &searchRecord); for(bCounter = 0; bCounter < MAX_ELEMENTS; bCounter++) { if(bFound == 0) { BYTE i; if(searchRecord.filename[0] == '.' && searchRecord.filename[1] == '\0') { bFound = FindNext(&searchRecord); continue; } aFolderElement[bNumElementsInFolder].blFolder = 1; aFolderElement[bNumElementsInFolder].blText = 0; for(i = 0; i < 13; i++) { aFolderElement[bNumElementsInFolder].Name[i] = searchRecord.filename[i]; aFolderElement[bNumElementsInFolder].XName[i] = searchRecord.filename[i]; } bNumElementsInFolder++; } else { break; } bFound = FindNext(&searchRecord); } bFound = FindFirst("*.jpg", ATTR_MASK ^ ATTR_DIRECTORY, &searchRecord); for(bCounter = 0; bCounter < MAX_ELEMENTS && bNumElementsInFolder < MAX_ELEMENTS; bCounter++) { if(bFound == 0) { BYTE i; aFolderElement[bNumElementsInFolder].blFolder = 0; aFolderElement[bNumElementsInFolder].blText = 0; aFolderElement[bNumElementsInFolder].ImgType = IMG_JPEG; for(i = 0; i < 13; i++) { aFolderElement[bNumElementsInFolder].Name[i] = searchRecord.filename[i]; aFolderElement[bNumElementsInFolder].XName[i] = searchRecord.filename[i]; } bNumElementsInFolder++; } else { break; } bFound = FindNext(&searchRecord); } bFound = FindFirst("*.bmp", ATTR_MASK ^ ATTR_DIRECTORY, &searchRecord); for(bCounter = 0; bCounter < MAX_ELEMENTS && bNumElementsInFolder < MAX_ELEMENTS; bCounter++) { if(bFound == 0) { BYTE i; aFolderElement[bNumElementsInFolder].blFolder = 0; aFolderElement[bNumElementsInFolder].blText = 0; aFolderElement[bNumElementsInFolder].ImgType = IMG_BMP; for(i = 0; i < 13; i++) { aFolderElement[bNumElementsInFolder].Name[i] = searchRecord.filename[i]; aFolderElement[bNumElementsInFolder].XName[i] = searchRecord.filename[i]; } bNumElementsInFolder++; } else { break; } bFound = FindNext(&searchRecord); } // fill the list box items bStartingElement = 0; // clear the list first LbDelItemsList(pListBox); for(bCounter = 0; (bStartingElement + bCounter) < bNumElementsInFolder; bCounter++) { // set the proper bitmap icon if(aFolderElement[bStartingElement + bCounter].blFolder == 1) { pBitmap = (void *) &FolderIcon; } else if(aFolderElement[bStartingElement + bCounter].ImgType == IMG_JPEG) { pBitmap = (void *) &JpegIcon; } else if(aFolderElement[bStartingElement + bCounter].ImgType == IMG_BMP) { pBitmap = (void *) &BitmapIcon; } else { pBitmap = NULL; } // assign the item to the list if(NULL == LbAddItem(pListBox, NULL, aFolderElement[bStartingElement + bCounter].XName, pBitmap, 0, bCounter)) break; else { // adjust the slider page and range SldSetRange(pSlider, bNumElementsInFolder); SldSetPage(pSlider, bNumElementsInFolder >> 1); // to completely redraw the object when GOLDraw() is executed. SetState(pSlider, DRAW); SetState(pListBox, DRAW); } } }
/** <b> add_element() <\b> takes a string, for i.e. add_element("Hi");, * and puts it onto the linked list on top of the current head pointer. It * then connects pointers in the old head to the current head. It also * connects the current head pointers to the previous head in memory. */ list_element* add_element(const char* value) { list_element* retval=NULL; BOOL null_check_temp=FALSE; const char* index; INT16 i; // Check to see if we are either adding a string without a NULL or // a string longer than the size of each node index=value; for(i=0;i<MAX_NODE_CHARS;i++) { if ((*index)=='\0') { null_check_temp=TRUE; } index++; } if (null_check_temp==FALSE) { error_code=MISSING_NULL; } if(list_size==0) { // We are creating a new linked list. Allocate memory and set the // head pointer to that memory head=(list_element*) malloc(sizeof(list_element)); //head->next=(list_element*) &tail; // BIG GOTCHA // Set the head's next pointer to the address contained at the // tail pointer address (dereference the tail pointer) //head->next=(list_element*) *(&tail); head->next=tail; // Set NULL's head->prev=NULL; tail->next=NULL; //tail->prev=(list_element*) &head; // BIG GOTCHA // Set the tail's previous pointer to the address contained at the // head pointer address (dereference the head pointer) tail->prev=head; //Initialize the list with data passed to the add_element() for(i=0;i<MAX_NODE_CHARS;i++) { if(*value!='\0') { //add to the graphics list head->ListBoxStr[i]=*value; //add to the node_data head->node_data[i]=*value++; } else { head->node_data[i]=0; head->ListBoxStr[i]=0; } } // Give the newly created node a number head->node_number = 1; // Increment the list_size variable used to track the link list's // number of members list_size++; } else { if(list_size<MAX_LIST_SIZE) { // We are adding to the new linked list. Make a backup of the // old head pointer because we will use it to make a new list // member. previous_pointer=head; // Allocate a list element. Return a pointer to the head location. head=(list_element*) malloc(sizeof(list_element)); //previous_pointer->prev=(list_element*) &head; //BIG GOTCHA //head->next=(list_element*) &previous_pointer; //BIG GOTCHA // The new list element had to be allocated before we could connect // it to the previous list element. However, doing so lost our // reference to the previous list element, hence the existence of the // previous_pointer variable. This connects the old prev value with // the new head pointer. previous_pointer->prev=head; // Connect the head pointer to the previous head of the list head->next=previous_pointer; // The new head is the top of the linked list, so make the prev // value NULL head->prev=NULL; //Initialize the list with data passed to this function for(i=0;i<MAX_NODE_CHARS;i++) { if(*value!='\0') { //add to the graphics list head->ListBoxStr[i]=*value; //add to node data head->node_data[i]=*value++; } else { head->node_data[i]=0; head->ListBoxStr[i]=0; } } // Set the node number of the list to pre-incremented list size head->node_number = ++list_size; } else { error_code=LIST_OVERFLOW; } } //add text to the Graphics listbox pLISTITEM=LbAddItem(pLb,pLISTITEM,&head->ListBoxStr,NULL,NULL,1); head->list_box_item=pLISTITEM; Nop(); Nop(); Nop(); return retval; }