void wdbExcGetEvent ( void * arg, WDB_EVT_DATA * pEvtData ) { wdbExcInfoNode_t * pNode; wdbExcInfoNode_t * pTmpNode; WDB_EXC_INFO * pExcInfo; int lockKey; /* get a node from the exception queue */ lockKey = intLock(); pNode = (wdbExcInfoNode_t *) dll_head (&wdbExcEvtList); dll_remove (&pNode->node); intUnlock (lockKey); /* give the node info to the host */ pExcInfo = (WDB_EXC_INFO *)&pEvtData->eventInfo; pEvtData->evtType = WDB_EVT_EXC; pExcInfo->numInts = 4; pExcInfo->context = pNode->context; pExcInfo->vec = pNode->excVector; pExcInfo->pEsf = (TGT_ADDR_T) pNode->pESF; /* mark the node invalid and put back in queue (after valid nodes) */ pNode->valid = FALSE; lockKey = intLock(); for (pTmpNode = (wdbExcInfoNode_t *) dll_head (&wdbExcEvtList); pTmpNode != (wdbExcInfoNode_t *) dll_end (&wdbExcEvtList); pTmpNode = (wdbExcInfoNode_t *) dll_next (&pTmpNode->node)) { if (pTmpNode->valid == FALSE) break; } pTmpNode = (wdbExcInfoNode_t *) dll_prev (&pTmpNode->node); dll_insert (&pNode->node, &pTmpNode->node); intUnlock (lockKey); }
int main ( void ) { DlList_T myList; myList = dll_create(); if( myList == 0 ) { fputs( "Cannot create list!\n", stderr ); return( 1 ); } printf( "Initial list is %s\n", dll_empty( myList ) ? "empty" : "not empty" ); char* one = (char*)malloc( 11 * sizeof(char) ); char* two = (char*)malloc( 12 * sizeof(char) ); char* three = (char*)malloc( 11 * sizeof(char) ); strcpy( one, "First Line" ); strcpy( two, "Second Line" ); strcpy( three, "Third Line" ); printf( "Checking cursor initialized null...\n"); if( dll_has_next( myList ) ) { printf( "Your possition is valid\n" ); } else { printf( "Your possition is NOT valid\n" ); } // Test append printf( "List size: %d\n", dll_size( myList ) ); printf( "Adding \"%s\"\n", one ); dll_append( myList, one ); printf( "List size: %d\n", dll_size( myList ) ); printf( "Adding \"%s\"\n", two ); dll_append( myList, two ); printf( "List size: %d\n", dll_size( myList ) ); printf( "Adding \"%s\"\n", three ); dll_append( myList, three ); printf( "List size: %d\n", dll_size( myList ) ); printf( "Checking cursor fixed with appends...\n"); if( dll_has_next( myList ) ) { printf( "Your possition is valid\n" ); } else { printf( "Your possition is NOT valid\n" ); } printf( "Test cursor movement...\n" ); if( dll_move_to( myList, 3 ) ) { printf( "You moved to an index you shouldn't be able to\n" ); } else { printf( "You can't move the cursor to 3\n" ); } if( dll_move_to( myList, 2 ) ) { printf( "moved to the last index\n" ); } else { printf( "movement problem to index 2\n" ); } if( dll_move_to( myList, 0 ) ) { printf( "moved to the first index\n" ); } else { printf( "movement problem to index 0\n" ); } printf( "Checking cursor still valid...\n" ); if( dll_has_next( myList ) ) { printf( "Your possition is valid\n" ); } else { printf( "Your possition is NOT valid\n" ); } printf( "Print state and test dll_next:\n" ); void* data = dll_next( myList ); int index = 0; // Index 0 printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_next( myList ); index++; // Index 1 printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_next( myList ); index++; // Index 2 printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_next( myList ); index++; // Index 3 (Should be the same as index 2 as it should not exist) printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_next( myList ); printf( "Lets work backwards:\n" ); data = dll_prev( myList ); index = dll_size( myList ) - 1; // Index 2 printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_prev( myList ); index--; // Index 1 printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_prev( myList ); index--; // Index 0 printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_prev( myList ); index--; // Index -1 (Should be same as index 0 as it should not exist) printf( "[%d] \"%s\"\n", index, (char*)data ); data = dll_prev( myList ); char* four = (char*)malloc( 12 * sizeof(char) ); char* five = (char*)malloc( 11 * sizeof(char) ); char* six = (char*)malloc( 11 * sizeof(char) ); char* seven = (char*)malloc( 13 * sizeof(char) ); char* eight = (char*)malloc( 12 * sizeof(char) ); strcpy( four, "Fourth Line" ); strcpy( five, "Fifth Line" ); strcpy( six, "Sixth Line" ); strcpy( seven, "Seventh Line" ); strcpy( eight, "Eighth Line" ); printf( "Testing inserts\n" ); dll_insert_at( myList, 0, six ); printf( "List size: %d\n", dll_size( myList ) ); dll_insert_at( myList, 2, seven ); printf( "List size: %d\n", dll_size( myList ) ); dll_insert_at( myList, 4, eight ); printf( "List size: %d\n", dll_size( myList ) ); printf( "Test full print and check inserts\n" ); index = 0; data = dll_get( myList, index ); while( data != NULL ) { printf( "[%d] \"%s\"\n", index, (char*)data ); index++; data = dll_get( myList, index ); } printf( "Test Sets\n" ); data = dll_set( myList, 0, five ); printf( "Switched \"%s\" with \"%s\"\n", (char*)data, five ); free( data ); data = dll_set( myList, 2, four ); printf( "Switched \"%s\" with \"%s\"\n", (char*)data, four ); free( data ); printf( "Test full print and check sets\n" ); index = 0; data = dll_get( myList, index ); while( data != NULL ) { printf( "[%d] \"%s\"\n", index, (char*)data ); index++; data = dll_get( myList, index ); } printf( "Testing popping\n" ); data = dll_pop( myList, dll_size( myList ) -1 ); printf( "Last element is: \"%s\"\n", (char*)data ); free( data ); data = dll_pop( myList, 2 ); printf( "Third element is: \"%s\"\n", (char*)data ); free( data ); printf( "Poping the rest...\n"); index = 0; data = dll_pop( myList, 0 ); while( data != NULL ) { printf( "[%d] \"%s\"\n", index, (char*)data ); free( data ); index++; data = dll_pop( myList, 0 ); } printf( "Destroying\n" ); dll_destroy( myList ); }
int main() { chk_msg("dll_init"); dll_t list; dll_init(&list); chk_dll_size(&list, 0); chk_msg("dll_push_back"); dll_push_back(&list); chk_dll_size(&list, 1); chk_msg("dll_push_front"); dll_push_front(&list); chk_dll_size(&list, 2); chk_msg("dll_destroy"); dll_destroy(&list); chk_dll_size(&list, 0); chk_msg("dll_push_front"); dll_push_front(&list); chk_dll_size(&list, 1); chk_msg("dll_pop_back"); dll_pop_back(&list); chk_dll_size(&list, 0); chk_msg("dll_destroy"); dll_destroy(&list); chk_dll_size(&list, 0); chk_msg("dll_destroy"); dll_destroy(&list); chk_dll_size(&list, 0); chk_msg("dll_push_back"); dll_item_t *item = dll_push_back(&list); chk_dll_size(&list, 1); chk_msg("dll_insert_before"); item = dll_insert_before(&list, item); chk_dll_size(&list, 2); chk_msg("dll_insert_after"); item = dll_insert_after(&list, item); chk_dll_size(&list, 3); #if TRIGGER_INV_BUG chk_msg("dll_remove"); dll_remove(&list, dll_next(dll_prev(dll_prev(dll_end(&list))))); chk_dll_size(&list, 2); #endif chk_msg("dll_pop_front"); dll_pop_front(&list); chk_dll_size(&list, 1); #if TRIGGER_INV_BUG chk_msg("dll_remove"); dll_remove(&list, dll_beg(&list)); chk_dll_size(&list, 0); #endif ___sl_plot(NULL); return 0; }
int main ( int argc, char* argv[] ) { DlList_T myList; // List buffer to keep track of inserting or appending DlList_T listBuff; myList = dll_create(); if( myList == 0 ) { fprintf( stderr, "Cannot create list!\n" ); return( 1 ); } listBuff = dll_create(); if( listBuff == 0 ) { fprintf( stderr, "Cannot create buffer!\n" ); return( 1 ); } // number of bytes for getline int nbytes = 80; // Set up a string to read user input and file char *str = NULL; // Set up name for saving files to char *saveFile = NULL; // Read in a file // Check to make sure there's arguments of the file to open if( argc == 2 ) { FILE* pFile = fopen(argv[1], "r"); if( !pFile ) { perror("open failed"); fprintf( stderr, "could not read file '%s'\n", argv[1] ); return( 1 ); } else { // The file has been opened. Go through // and fill the doubly linked list while( getline(&str, (size_t *) &nbytes, pFile) ) { // Kill the new line killNL(str); // Set up space char* toAdd = (char*)malloc( ( strlen(str) + 1 ) * sizeof(char) ); // Add the previous read in line to that space strcpy( toAdd, str ); // Add it to the list dll_append( myList, toAdd ); //Free 'str' free( str ); str = NULL; } fclose( pFile ); } } else { printf( "no file supplied\n" ); } // Keep track if we should stop or not bool running = true; // Keep track of changes bool buffChange = false; // Keeps track if we're appending or inserting bool grabText = false; char grabMode = 'a'; // Keeps track of the cursor movement void* lastData = NULL; while( running ) { // Read in the next line getline(&str, (size_t *) &nbytes, stdin); // Kill new line killNL(str); // We're either appending or inserting if( grabText ) { if( strlen( str ) == 1 && str[0] == '.' ) { // A single period was entered to stop the adding // Set grabText to false grabText = false; // If the mode was set to append if( grabMode == 'a' ) { // We go through and pop all the elements // off the buffer and append them to the list int index = 0; void* data = dll_pop( listBuff, 0 ); while( data != NULL ) { dll_append( myList, data ); index++; data = dll_pop( listBuff, 0 ); } } else if ( grabMode == 'i' ) { // We go through and pop all the elements // off the buffer and insert them to the list int index = 0; // Set the insert index as the current // pointer's index int insertIndex = getCursorIndex( myList ); void* data = dll_pop( listBuff, 0 ); while( data != NULL ) { dll_insert_at( myList, insertIndex, data ); index++; insertIndex++; data = dll_pop( listBuff, 0 ); } } } else { // Set up space char* toAdd = (char*)malloc( ( strlen(str) + 1 ) * sizeof(char) ); // Add the previous read in line to that space strcpy( toAdd, str ); // Add it to the list dll_append( listBuff, toAdd ); } } else if( str[0] == 'a' ) { grabText = true; grabMode = 'a'; buffChange = true; // Current line } else if( str[0] == '.' ) { // Print the index of the current line if( str[1] == '=' ) { printf( "%d\n", getCursorIndex( myList ) ); // Print the current line } else { printf( "%s\n", (char*)getCursorData( myList ) ); } // Advance cursor to the next line // String length of 1 means they hit enter } else if( strlen(str) == 0 || str[0] == '+' ) { // Try to advance the cursor void* data = dll_next( myList ); // If the cursor didn't advance, notify the user if( data == lastData ){ printf("?\n"); // Otherwise the cursor advanced, print the line } else { lastData = data; printf( "%s\n", (char*)data ); } // Advance the cursor to the previous line } else if( str[0] == '-' ) { // Try to advance the cursor void* data = dll_prev( myList ); // If the cursor didn't advance, notify the user if( data == lastData ){ printf("?\n"); // Otherwise the cursor advanced, print the line } else { lastData = data; printf( "%s\n", (char*)data ); } // Delete line } else if( str[0] == 'd' ) { if( dll_has_next( myList ) ){ int index = getCursorIndex( myList ); void* data = dll_pop( myList, index ); free( data ); buffChange = true; } } else if( str[0] == 'i' ) { grabText = true; grabMode = 'i'; buffChange = true; // Last element } else if( str[0] == '$' ) { // For both "$=" and "$" it prints a "?" upon // an empty list int size = dll_size( myList ); if( size == 0 ) { printf( "?\n" ); } else { // If the command was "$=" just print // the possition of the last element if( str[1] == '=' ) { printf( "%d\n", size ); // Otherwise move to the last position // and print the last element } else { dll_move_to( myList, size - 1 ); void* data = dll_get( myList, size - 1 ); printf( "%s\n", (char*)data ); } } // Print } else if( str[0] == 'p' ) { printList( myList ); // Save } else if( str[0] == 'w' ) { char grab[(strlen(str) + 1)]; // Check if a file name has beens pecified sscanf(str, "%*s %s", grab); // If the length is greater than '1' we set // it as the last acceptable saveFile if( strlen(grab) > 0 ) { if( saveFile != NULL ) { free( saveFile ); } saveFile = (char*)malloc( ( strlen(str) + 1 ) * sizeof(char) ); strcpy( saveFile, grab ); } // Check if a quit flag has been given bool quit = (str[1] == 'q'); if( saveFile == NULL || strlen(saveFile) <= 0 ) { // We don't have an acceptable file name to check continue; } // Open file to be saved FILE* pFile = fopen(saveFile, "w"); if( !pFile ) { perror("open failed: "); } else { printf( "file name: '%s'\n", saveFile ); // Go through each node of the doulby linked list int index = 0; void* data = dll_get( myList, index ); while( data != NULL ) { // Write to file fputs((char*)data, pFile); fputs("\n", pFile); index++; data = dll_get( myList, index ); } // Close fclose( pFile ); // If we want to quit afterwards if( quit ) { running = false; printf("\nBye\n"); } // reset the buffer flag buffChange = false; } // Soft quit } else if ( str[0] == 'q' ) { // If the buffer hasn't changed stop the program if( !buffChange ) { running = false; printf( "\nBye\n" ); // Otherwise warn that there's been changes } else { printf( "? buffer dirty.\n" ); } // Hard quit } else if ( str[0] == 'Q' ) { running = false; printf( "\nBye\n" ); } else { // Check if a number char* end; int checkNum = strtol( str, &end, 10 ); // If the conversion did not encounter a string // We know the number is good if( !*end ) { // If we can move to the requested index if( dll_move_to( myList, checkNum - 1 ) ) { // Print that index printf( "%s\n", (char*)getCursorData( myList ) ); } else { printf( "?\n" ); } } } // Free 'str' free( str ); // Set 'str' to NULL str = NULL; } // Destroy our list dll_destroy( myList ); // Destroy the buffer dll_destroy( listBuff ); }