int main() { // New list List<int> list; // Append nodes to the list list.Append(100); list.Print(); list.Append(200); list.Print(); list.Append(300); list.Print(); list.Append(400); list.Print(); list.Append(500); list.Print(); // Delete nodes from the list list.Delete(400); list.Print(); list.Delete(300); list.Print(); list.Delete(200); list.Print(); list.Delete(500); list.Print(); list.Delete(100); list.Print(); return 0; }
TEST(List, can_delete) { // List<int> list; list.AddToHead(1); list.AddToHead(2);//2,1 list.AddElementOrdered(3); ASSERT_NO_THROW(list.Delete()); }
// Тестовый пример void main() { // Создаем объект класса List List lst; // Тестовая строка char s[] = "Hello, World !!!\n"; // Выводим строку cout << s << "\n\n"; // Определяем длину строки int len = strlen(s); // Загоняем строку в список for(int i = 0; i < len; i++) lst.Add(s[i]); // Распечатываем содержимое списка lst.Print(); // Удаляем три элемента списка lst.Del(); lst.Del(); lst.Del(); //Распечатываем содержимое списка lst.Print(); //Вставляем 3-й символ, согласно нумерации массива с нуля lst.Insert('+',2); lst.Print(); //удаляем 3-й символ lst.Delete(2); lst.Print(); //находим позицию элемента 'l' cout<<"First position of 'l': "<<lst.Search('l')<<endl<<endl; }
void test(){ List * Head = new List(2); Head->Insert(2); Head->Insert(2); Head->Insert(15); Head->Insert(7); Head->Insert(15); Head->Insert(5); Head->Insert(5); Head->Print(); Head->Delete(5); Head->Delete(5); Head->Delete(5); Head->Delete(7); Head->Print(); }
//------------------------------------------------------------------------------ //Функция объединения двух упорядоченных списков с сохранением порядка List Concat(List list1,List list2) { if (list1.root==NULL || list2.root==NULL) { cout <<"Concat2:error: one or more lists is empty\n"; } TNode *temp1,*temp2; temp1=list1.last; temp2=list2.root; while (temp2!=NULL) { for (;;) { if ( (temp1->data < temp2->data) || (temp1->prev==NULL) ) break; temp1=temp1->prev; } if ( (temp1==list1.root) && (temp1->data > temp2->data) ) list1.AddBefore(temp1,temp2->data); else list1.AddAfter(temp1,temp2->data); temp1=list1.last; if (temp2->next==NULL) break; temp2=temp2->next; list2.Delete(list2.root); } return list1; }
int main( ) { // New list List list; // Append nodes to the list list.Append( 100 ); list.Print( ); list.Append( 200 ); list.Print( ); list.Append( 300 ); list.Print( ); list.Append( 400 ); list.Print( ); list.Append( 500 ); list.Print( ); // Delete nodes from the list list.Delete( 400 ); list.Print( ); list.Delete( 300 ); list.Print( ); list.Delete( 200 ); list.Print( ); list.Delete( 500 ); list.Print( ); list.Delete( 100 ); list.Print( ); std::list<int> myList; myList.push_back( 5 ); myList.push_front( 3 ); myList.push_back( 9 ); myList.remove( 5 ); for ( auto it = myList.begin(); it != myList.end(); it++ ) cout << ( *it ) << endl; return 0; }
void refresh_processes ( List &black_list , List &black_list_checks , List &processes ) { unsigned int cont; /* Walking the list */ for ( cont = 0 ; cont < black_list.Len () ; cont ++ ) { /* If the process DIED */ if ( processes.Find ( black_list.Get ( cont ) ) == FALSE ) { /* Deleting this OLD PID */ black_list.Delete ( cont ); black_list_checks.Delete ( cont ); /* Compensating the element extraction */ cont --; } } }
bool ListUnitTest() { List *t = new List(); List *s = NULL; List *u = NULL; List::Add(&t, new List()); List::Add(&t, new List()); List::Add(&t, new List()); t->Delete(&t); t->Delete(&t); t->Delete(&t); List::Add(&t, new List()); List::Add(&t, new List()); s = t->head->Extract(); u = t->tail->Extract(); return true; }
void main() { List t; int n; do{ cout<<"\n***********************主菜单*****************************"; cout<<"\n\n************** 1.增加城市; *******************"; cout<<"\n\n************** 2.删除城市; *******************"; cout<<"\n\n************** 3.查询城市信息; *******************"; cout<<"\n\n************** 4.修改城市信息; *******************"; cout<<"\n\n************** 5.查询某坐标附近的城市;*******************"; cout<<"\n\n************** 6.其他按键退出程序; *******************"; cout<<"\n\n**********************************************************"<<endl; cout<<"\n请输入你的选择操作:"; cin>>n; switch(n) { case 1: t.Insert();//1.增加城市 cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; _getch(); cout<<"\n"; break; case 2: t.Delete(); //2.删除城市 cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; _getch(); cout<<"\n"; break; case 3: t.Search(); //3.查询城市信息 cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; _getch(); cout<<"\n"; break; case 4: t.Change();//4.修改城市信息 cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; _getch(); cout<<"\n"; break; case 5: t.Nearcity();//5.查询某点附近的城市 cout<<"\n按任意键返回菜单>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; _getch(); cout<<"\n"; break; default: break; //6.其他按键退出程序 } }while(n>0&&n<6); }
int main() { List<int> list; for(int i=0;i<10;i++) list.Insert(i+1,i*(1+i)); int a[10],b[10]; for(int i=0;i<list.Length();i++) cout<<list.GetElem(1+i,a[i])<<endl; cout<<list.Length()<<endl; cout<<list.LocateElem(90)<<endl; list.NextElem(0,b[0]); cout<<b[0]<<endl; cout<<list.Delete(4,b[1])<<endl; for(int i=0;i<list.Length();i++) cout<<list.GetElem(1+i,a[i])<<endl; return 0; }
void menu(){ List * intList = new List; int choice=0; enum menuChoices {PRINT, INSERT, DELETE, EXIT}; cout << "Lab exercise for Chapter 6 Lists" << endl; while(choice!=4){ cout << "Please pick from the following options:" << endl; cout << "[1] Print current list" << endl; cout << "[2] Insert integer to list" << endl; cout << "[3] Delete integer from list" << endl; cout << "[4] Exit" << endl << endl; choice = getInt(); cout << endl; switch(choice-1){ case PRINT: intList->Print(); break; case INSERT: int newInt; cout << "Enter the new integer to be added" << endl << endl; newInt = getInt(); cout << endl; intList->Insert(newInt); break; case DELETE: int tarInt; cout << "Enter the integer to be deleted" << endl << endl; tarInt = getInt(); cout << endl; intList->Delete(tarInt); break; case EXIT: cout << "Goodbye." << endl << endl; delete intList; break; default: cout << "Please enter a valid option." << endl << endl; } } }
int GWindow::WillAccept(List<char> &Formats, GdcPt2 Pt, int KeyState) { int Status = DROPEFFECT_NONE; for (char *f=Formats.First(); f; ) { if (stricmp(f, LGI_FileDropFormat) == 0) { f = Formats.Next(); Status = DROPEFFECT_COPY; } else { Formats.Delete(f); DeleteArray(f); f = Formats.Current(); } } return Status; }
int main(){ //read("in.txt"); List l; int x,c; do{ c = prompt(); switch(c){ case 1: cout << "Please, Enter the number to be Inserted : \n"; cin >> x; l.Insert(x); break; case 2: cout << "Please, Enter the number to be Deleted : \n"; cin >> x; x = l.Delete(x); if (x == -1) cout << "Element not found!\n"; break; case 3: l.Print(); cout << "\n"; break; case 4: l.PrintRev(); cout << "\n"; break; case 5: cout << "Please, Enter the index of the element to be swapped with it's successor : \n"; cin >> x; l.Swap(x); break; case 6: l.Reverse(); break; default: return 0; } }while(c < 7); }
void operator delete[](void* p)throw() { if(p == NULL) return; MemManager.Delete(Node(reinterpret_cast<long>(p))); free(p); }
int main(){ // New list List list; Node *answer; // Add_End nodes to the list list.Add_End(111); list.Print(); list.Add_End(222); list.Print(); list.Add_End(333); list.Print(); list.Add_End(444); list.Print(); list.Add_End(555); list.Print(); cout << endl << endl; // Delete nodes from the list list.Delete(444); list.Print(); // list.Delete(333); // list.Print(); // list.Delete(222); // list.Print(); // list.Delete(555); // list.Print(); // list.Delete(111); // list.Print(); // cout<<endl<<endl; // // cout << "Testing Add_Front: and others"<<endl; // list.Add_Front(888); // list.Print(); // list.Add_Front(999); // list.Print(); // list.Add_Front(49); // list.Print(); // cout<<endl<<endl; // cout << "Checking find function"<<endl; // answer = list.Find(888); // cout<<"Value for node returned by find function call with 888 is "<<answer->Data()<<"."<<endl; // cout<<"Checking find function"<<endl; // answer = list.Find(999); // cout<<"Value for node returned by find function call with 888 is "<<answer->Data()<<"."<<endl; // // cout<<"Checking find function"<<endl; // answer = list.Find(49); // cout<<"Value for node returned by find function call with 888 is "<<answer->Data()<<"."<<endl; // cout<<"Call find function with value not in list."<<endl; // answer = list.Find(7); // if(answer == NULL) // { // cout<<"returned null pointer since 7 not found"<<endl; // // } // else // { // cout<< "in else of answer == NULL where Value for node returned by find function call with 7 is "<<answer->Data()<<"."<<endl; // } // // cout<<"testing delete_front: "<<endl; // list.Delete_Front(); // list.Print(); // cout<<"testing delete_end: "<<endl; // // list.Delete_End(); // list.Print(); return 0; }
bool ChooseAnImageFTP(int sx,int sy, char *ftp_dir, int slot, char **filename, bool *isdir, int *index_file) { /* Parameters: sx, sy - window size, ftp_dir - what FTP directory to use, slot - in what slot should an image go (common: #6 for 5.25' 140Kb floppy disks, and #7 for hard-disks). slot #5 - for 800Kb floppy disks, but we do not use them in Apple][? (They are as a rule with .2mg extension) index_file - from which file we should start cursor (should be static and 0 when changing dir) Out: filename - chosen file name (or dir name) isdir - if chosen name is a directory */ double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); SDL_Surface *my_screen; // for background struct ftpparse FTP_PARSE; // for parsing ftp directories #ifndef _WIN32 struct stat info; #endif if(font_sfc == NULL) if(!fonts_initialization()) return false; //if we don't have a fonts, we just can do none char tmpstr[512]; char ftpdirpath [MAX_PATH]; snprintf(ftpdirpath, MAX_PATH, "%s/%s%s", g_sFTPLocalDir, g_sFTPDirListing, md5str(ftp_dir)); // get path for FTP dir listing // printf("Dir: %s, MD5(dir)=%s\n",ftp_dir,ftpdirpath); List<char> files; // our files List<char> sizes; // and their sizes (or 'dir' for directories) int act_file; // current file int first_file; // from which we output files char ch = 0; // prepare screen SDL_Surface *tempSurface; if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background // ch = 0; #define NORMAL_LENGTH 60 if(strlen(ftp_dir) > NORMAL_LENGTH) { ch = ftp_dir[NORMAL_LENGTH]; ftp_dir[NORMAL_LENGTH] = 0;} //cut-off too long string font_print_centered(sx/2 ,5 * facy , ftp_dir, screen, 1.5 * facx, 1.3 * facy); if(ch) ftp_dir[NORMAL_LENGTH] = ch; //restore cut-off char font_print_centered(sx/2,20 * facy,"Connecting to FTP server... Please wait.", screen, 1 * facx, 1 * facy); SDL_Flip(screen); // show the screen bool OKI; #ifndef _WIN32 if(stat(ftpdirpath,&info) == 0 && info.st_mtime > time(NULL) - RENEW_TIME) { OKI = false; // use this file } else { OKI = ftp_get(ftp_dir,ftpdirpath); // get ftp dir listing } #else // in WIN32 let's use constant caching? -- need to be redone using file.mtime if(GetFileAttributes(ftpdirpath) != DWORD(-1)) OKI = false; else OKI = ftp_get(ftp_dir,ftpdirpath); // get ftp dir listing #endif if(OKI) { // error printf("Failed getting FTP directory %s to %s\n",ftp_dir,ftpdirpath); font_print_centered(sx/2,30 * facy, "Failure. Press any key!",screen, 1.4 * facx, 1.1 * facy); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(100); SDL_PollEvent(&event); } SDL_FreeSurface(my_screen); return false; } FILE *fdir = fopen(ftpdirpath,"r"); char *tmp; int i,j, B, N; // for cycles, beginning and end of list // build prev dir if(strcmp(ftp_dir, "ftp://")) { tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs while (tmp = fgets(tmpstr,512,fdir)) // first looking for directories { // clear and then try to fill in FTP_PARSE struct memset(&FTP_PARSE,0,sizeof(FTP_PARSE)); ftpparse(&FTP_PARSE, tmp, strlen(tmp)); int what = getstatFTP(&FTP_PARSE, NULL); if (strlen(FTP_PARSE.name) > 0 && what == 1) // is directory! { tmp = new char[strlen(FTP_PARSE.name)+1]; // add entity to list strcpy(tmp, FTP_PARSE.name); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } /* if */ } // sort directories. Please, don't laugh at my bubble sorting - it the simplest thing I've ever seen --bb if(files.Length() > 2) { N = files.Length() - 1; // B = 1; - defined above for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } B = files.Length(); // start for files (void) rewind (fdir); // to the start // now get all regular files while (tmp = fgets(tmpstr,512,fdir)) { int fsize; // clear and then try to fill in FTP_PARSE struct memset(&FTP_PARSE,0,sizeof(FTP_PARSE)); ftpparse(&FTP_PARSE, tmp, strlen(tmp)); if ((getstatFTP(&FTP_PARSE, &fsize) == 2)) // is normal file! { tmp = new char[strlen(FTP_PARSE.name)+1]; // add this entity to list strcpy(tmp, FTP_PARSE.name); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", fsize); sizes.Add(tmp); // add this size to list } /* if */ } (void) fclose (fdir); // do sorting for files if(files.Length() > 2 && B < files.Length()) { N = files.Length() - 1; // B = 1; for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } // Count out cursor position and file number output act_file = *index_file; if(act_file >= files.Length()) act_file = 0; // cannot be more than files in list first_file = act_file - (FILES_IN_SCREEN / 2); if (first_file < 0) first_file = 0; // cannot be negativ... // Show all directories (first) and files then // char *tmp; char *siz; // int i; while(true) { SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background font_print_centered(sx/2 ,5 * facy , ftp_dir, screen, 1.5 * facx, 1.3 * facy); if (slot == 6) font_print_centered(sx/2,20 * facy,"Choose image for floppy 140KB drive", screen, 1 * facx, 1 * facy); else if (slot == 7) font_print_centered(sx/2,20 * facy,"Choose image for Hard Disk", screen, 1 * facx, 1 * facy); else if (slot == 5) font_print_centered(sx/2,20 * facy,"Choose image for floppy 800KB drive", screen, 1 * facx, 1 * facy); else if (slot == 1) font_print_centered(sx/2,20 * facy,"Select file name for saving snapshot", screen, 1 * facx, 1 * facy); else if (slot == 0) font_print_centered(sx/2,20 * facy,"Select snapshot file name for loading", screen, 1 * facx, 1 * facy); font_print_centered(sx/2,30 * facy, "Press ENTER to choose, or ESC to cancel",screen, 1.4 * facx, 1.1 * facy); files.Rewind(); // from start sizes.Rewind(); i = 0; // printf("We've printed some messages, go to file list!\n"); // show all fetched dirs and files // topX of first fiel visible int TOPX = 45 * facy; while(files.Iterate(tmp)) { sizes.Iterate(siz); // also fetch size string if (i >= first_file && i < first_file + FILES_IN_SCREEN) { // FILES_IN_SCREEN items on screen // char tmp2[80],tmp3[256]; if (i == act_file) { // show item under cursor (in inverse mode) SDL_Rect r; r.x= 2; r.y= TOPX + (i-first_file) * 15 * facy - 1; if(strlen(tmp) > 46) r.w = 46 * 6 * 1.7 * facx + 2; else r.w= strlen(tmp) * 6 * 1.7 * facx + 2; // 6- FONT_SIZE_X r.h= 9 * 1.5 * facy; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format,255,0,0));// in RED } /* if */ // print file name with enlarged font ch = 0; if(strlen(tmp) > 46) { ch = tmp[46]; tmp[46] = 0;} //cut-off too long string font_print(4, TOPX + (i - first_file) * 15 * facy, tmp, screen, 1.7 * facx, 1.5 * facy); // show name font_print(sx - 70*facx, TOPX + (i - first_file) * 15 * facy, siz, screen, 1.7 * facx, 1.5 * facy);// show info (dir or size) if(ch) tmp[46] = ch; //restore cut-off char } /* if */ i++; // next item } /* while */ ///////////////////////////////////////////////////////////////////////////////////////////// // draw rectangles rectangle(screen, 0, TOPX - 5, g_ScreenWidth, 320 * facy, SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 480 * facx, TOPX - 5, 0, 320 * facy, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(10); SDL_PollEvent(&event); } // control cursor keyboard = SDL_GetKeyState(NULL); // get current state of pressed (and not pressed) keys if (keyboard[SDLK_UP] || keyboard[SDLK_LEFT]) { if (act_file>0) act_file--; // up one position if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_DOWN] || keyboard[SDLK_RIGHT]) { if (act_file < (files.Length() - 1)) act_file++; if (act_file >= (first_file + FILES_IN_SCREEN)) first_file=act_file - FILES_IN_SCREEN + 1; } /* if */ if (keyboard[SDLK_PAGEUP]) { act_file-=FILES_IN_SCREEN; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN]) { act_file+=FILES_IN_SCREEN; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+FILES_IN_SCREEN)) first_file=act_file-FILES_IN_SCREEN + 1; } /* if */ // choose an item? if (keyboard[SDLK_RETURN]) { // dup string from selected file name *filename = strdup(php_trim(files[act_file],strlen(files[act_file]))); // printf("files[act_file]=%s, *filename=%s\n\n", files[act_file], *filename); if(!strcmp(sizes[act_file], "<DIR>") || !strcmp(sizes[act_file], "<UP>")) *isdir = true; else *isdir = false; // this is directory (catalog in Apple][ terminology) *index_file = act_file; // remember current index files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return true; } /* if */ if (keyboard[SDLK_ESCAPE]) { files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return false; // ESC has been pressed } /* if */ if (keyboard[SDLK_HOME]) { // HOME? act_file=0; first_file=0; } /* if */ if (keyboard[SDLK_END]) { // END? act_file=files.Length() - 1; // go to the last possible file in list first_file=act_file - FILES_IN_SCREEN + 1; if(first_file < 0) first_file = 0; } /* if */ } } /* ChooseAnImageFTP */
int main(){ char choice; bool done = false; List alist; do { cout << endl << endl << endl; cout << " 1. Add Record To Back" << endl; cout << " 2. Insert a Record" << endl; cout << " 3. Erase a Record by Record Number" << endl; cout << " 5. Clear ALL Records" << endl; cout << " 6. Display ALL Records" << endl; cout << " 7. Display a Record" << endl; cout << " Q. Quit" << endl; cout << endl; cout << " => "; cin >> choice; choice = toupper(choice); node ch, content; char yesorno; string filename; int recno; switch( choice ) { case '1' : cout << "Character to add to back => "; cin >> ch; List.Insert( List.getLength() 1, ch ); break; case '2' : cout << "Record number to insert => "; cin >> recno; cout << "Character to insert => "; cin >> ch; List.Insert( recno, ch ); break; case '3' : cout << "Record number to erase => "; cin >> recno; alist.Delete( recno ); break; case '7' : cout << "Record number to retrieve"; cin >> recno; alist.Retrieve(recno); break; case 'Q' : done = true; break; default : cout << "Invalid choice" << endl; } } while ( !done ); cout << "Good Bye !!" << endl; }
void User::Del(List &list,string mobile) //调用List中的方法进行删除 { list.Delete(mobile); }
void User::Del(List &list,int num) //调用List中的方法进行删除 { list.Delete(num); }
bool state_replaymanager_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); refind_files=true; SUBSTATE2=0; } /* if */ if (refind_files) { refind_files=false; files.Delete(); #ifdef _WIN32 /* Find files: */ WIN32_FIND_DATA finfo; HANDLE h; if (replay_source==0) h=FindFirstFile("replays/*.rpl",&finfo); else h=FindFirstFile("high/*.rpl",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; if (replay_source==0) dp = opendir (replay_dir); else dp = opendir (high_dir); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-4]=='.' && ep->d_name[strlen(ep->d_name)-3]=='r' && ep->d_name[strlen(ep->d_name)-2]=='p' && ep->d_name[strlen(ep->d_name)-1]=='l') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); files.Add(tmp); } /* if */ } (void) closedir (dp); } #endif first_file=0; act_file=0; } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); if (replay_source==0) font_print_centered(sx/2,20,"REPLAY FILES [L - CHANGE SOURCE]:",screen); else font_print_centered(sx/2,20,"HIGH SCORE FILES [L - CHANGE SOURCE]:",screen); if (replay_source!=0) font_print_centered(sx/2,30,"PRESS FIRE TO VIEW OR R TO REBUILD",screen); { char *tmp; int i; files.Rewind(); i=0; while(files.Iterate(tmp)) { if (i>=first_file && i<first_file+18) { char *sname[3]={"SH.RNR.","PNTR.2","X-TRM."}; int ship,length; char tmp2[256],tmp3[256]; if (i==act_file) { SDL_Rect r; r.x=2; r.y=42+(i-first_file)*10-1; r.w=strlen(tmp)*6+2; r.h=9; SDL_FillRect(screen,&r,SDL_MapRGB(screen->format,255,0,0)); } /* if */ font_print(4,42+(i-first_file)*10,tmp,screen); if (replay_source==0) snprintf(tmp2, sizeof(tmp2), "%s/%s",replay_dir, tmp); else snprintf(tmp2, sizeof(tmp2), "%s/%s",high_dir, tmp); replay_parameters(tmp2,&ship,&length,tmp3); { int min,sec,dec; dec=(length*18)/10; sec=dec/100; dec=dec%100; min=sec/60; sec=sec%60; sprintf(tmp2,"%.2i:%.2i'%.2i %s",min,sec,dec,sname[ship]); font_print(220,42+(i-first_file)*10,tmp2,screen); } } /* if */ i++; } /* while */ } rectangle(screen,-1,40,321,185,SDL_MapRGB(screen->format,255,255,255)); rectangle(screen,214,40,0,185,SDL_MapRGB(screen->format,255,255,255)); if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { SDL_FreeSurface(image); image=0; if (SUBSTATE2==0) { STATE=1; SUBSTATE=0; } /* if */ if (SUBSTATE2==1) { int i; char tmp[256]; char levelname[256]; int v1,v2; int fuel; STATE=8; SUBSTATE=0; if (replay_source==0) snprintf(tmp,sizeof(tmp), "%s/%s", replay_dir, files[act_file]); else snprintf(tmp, sizeof(tmp), "%s/%s",high_dir, files[act_file]); replayfile=fopen(tmp,"rb"); v1=fgetc(replayfile); v2=fgetc(replayfile); // To maintain compatibility with a previous version level=0; for(i=0;i<256;i++) levelname[i]=fgetc(replayfile); fuel=fgetc(replayfile); ship_type=fgetc(replayfile); game=new TRANSBALL("graphics/","sound/","maps/",fuel,levelname,ship_type); timer=0; } /* if */ } /* if */ } /* if */ if (SUBSTATE==32) { if ((keyboard[SDLK_UP] && !old_keyboard[SDLK_UP]) || (keyboard[SDLK_LEFT] && !old_keyboard[SDLK_LEFT])) { if (act_file>0) act_file--; if (act_file<first_file) first_file=act_file; } /* if */ if ((keyboard[SDLK_DOWN] && !old_keyboard[SDLK_DOWN]) || (keyboard[SDLK_RIGHT] && !old_keyboard[SDLK_RIGHT])) { if (act_file<(files.Length()-1)) act_file++; if (act_file>=(first_file+18)) first_file=act_file-17; } /* if */ if (keyboard[SDLK_PAGEUP] && !old_keyboard[SDLK_PAGEUP]) { act_file-=18; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN] && !old_keyboard[SDLK_PAGEDOWN]) { act_file+=18; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+18)) first_file=act_file-17; } /* if */ if (keyboard[SDLK_LCTRL] && !old_keyboard[SDLK_LCTRL]) { SUBSTATE2=1; if (files.EmptyP()) SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_TAB] && !old_keyboard[SDLK_TAB]) { if (replay_source==0) replay_source=1; else replay_source=0; act_file=0; first_file=0; refind_files=true; } /* if */ if (keyboard[SDLK_BACKSPACE] && !old_keyboard[SDLK_BACKSPACE] && replay_source==1) { { List<char> replays; char *replay; char complete_replayname[256]; /* look for files: */ #ifdef _WIN32 WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile("replays/*.rpl",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); replays.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; dp = opendir (replay_dir); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-4]=='.' && ep->d_name[strlen(ep->d_name)-3]=='r' && ep->d_name[strlen(ep->d_name)-2]=='p' && ep->d_name[strlen(ep->d_name)-1]=='l') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); replays.Add(tmp); } /* if */ } (void) closedir (dp); } #endif /* Check if this replay is a highscore: */ replays.Rewind(); while(replays.Iterate(replay)) { int level; int ship,current_time,previous_high=-1; char levelname[256]; snprintf(complete_replayname, sizeof(complete_replayname), "%s/%s",replay_dir, replay); if (replay_parameters(complete_replayname,&ship,¤t_time,levelname)==2) { for(level=0;level<NLEVELS;level++) { if (strcmp(levelname,levelnames[level])==0) { /* the replay corresponds to level 'i' of the current level pack: */ /* UPDATE THE HIGHSCORES: */ int best_time=-1; int i,j; char highname[256],filename2[256]; previous_high=-1; j=0; snprintf(highname, sizeof(highname), "%s/", high_dir); j+=strlen(highname); for(i=0;levelpack[i]!='.' && levelpack[i]!=0;i++) highname[j++]=levelpack[i]; highname[j++]='-'; sprintf(highname+j,"%.3i",level); j+=3; highname[j++]='-'; if (ship==0) highname[j++]='S'; if (ship==0) highname[j++]='R'; if (ship==1) highname[j++]='V'; if (ship==1) highname[j++]='P'; if (ship==2) highname[j++]='X'; if (ship==2) highname[j++]='T'; highname[j++]='.'; highname[j++]='r'; highname[j++]='p'; highname[j++]='l'; highname[j++]=0; { int retval; int s,l; char levelname[256]; retval=replay_parameters(highname,&s,&l,levelname); if (retval==2) { previous_high=l; } /* if */ } if (previous_high==-1 || previous_high>current_time) { snprintf(filename2, sizeof(filename2), "%s/%s",replay_dir, replay); replay_copy(filename2,highname); } /* if */ } /* if */ } /* if */ } /* if */ } /* while */ } act_file=0; first_file=0; refind_files=true; } /* if */ } /* if */ return true; } /* state_replaymanager_cycle */
EC2Resource::BatchStatusResult EC2Resource::StartBatchStatus() { ASSERT( status_gahp ); // m_checkSpotNext starts out false if( ! m_checkSpotNext ) { StringList returnStatus; std::string errorCode; int rc = status_gahp->ec2_vm_status_all( resourceName, m_public_key_file, m_private_key_file, returnStatus, errorCode ); if( rc == GAHPCLIENT_COMMAND_PENDING ) { return BSR_PENDING; } if( rc != 0 ) { std::string errorString = status_gahp->getErrorString(); dprintf( D_ALWAYS, "Error doing batched EC2 status query: %s: %s.\n", errorCode.c_str(), errorString.c_str() ); return BSR_ERROR; } // // We have to let a job know if we can't find a status report for it. // List<EC2Job> myJobs; EC2Job * nextJob = NULL; BaseJob *nextBaseJob = NULL; registeredJobs.Rewind(); while ( (nextBaseJob = registeredJobs.Next()) ) { nextJob = dynamic_cast< EC2Job * >( nextBaseJob ); ASSERT( nextJob ); if ( !nextJob->m_client_token.empty() ) { myJobs.Append( nextJob ); } } returnStatus.rewind(); ASSERT( returnStatus.number() % 6 == 0 ); for( int i = 0; i < returnStatus.number(); i += 6 ) { std::string instanceID = returnStatus.next(); std::string status = returnStatus.next(); std::string clientToken = returnStatus.next(); std::string keyName = returnStatus.next(); std::string stateReasonCode = returnStatus.next(); std::string publicDNSName = returnStatus.next(); // Efficiency suggests we look via the instance ID first, // and then try to look things up via the client token // (or, for GT #3682, via the keypair ID). // We can't use BaseJob::JobsByRemoteId because OpenStack doesn't // include the client token in its status responses, and therefore // we can't always fully reconstruct the remoteJobID used as the key. EC2Job * job = NULL; rc = jobsByInstanceID.lookup( HashKey( instanceID.c_str() ), job ); if( rc == 0 ) { ASSERT( job ); dprintf( D_FULLDEBUG, "Found job object for '%s', updating status ('%s').\n", instanceID.c_str(), status.c_str() ); job->StatusUpdate( instanceID.c_str(), status.c_str(), stateReasonCode.c_str(), publicDNSName.c_str() ); myJobs.Delete( job ); continue; } // If we got a client token, use that to look up the job. We // don't use the instance ID because we may discover it in // this function. Since we need instance ID -based dispatch // code for OpenStack anyway, we'll just use it, rather than // trying the remoteJobID with the instance ID if we don't // find it using only the client token. if( ! clientToken.empty() && clientToken != "NULL" ) { std::string remoteJobID; formatstr( remoteJobID, "ec2 %s %s", resourceName, clientToken.c_str() ); BaseJob * tmp = NULL; rc = BaseJob::JobsByRemoteId.lookup( HashKey( remoteJobID.c_str() ), tmp ); if( rc == 0 ) { ASSERT( tmp ); EC2Job * job = dynamic_cast< EC2Job * >( tmp ); if( job == NULL ) { EXCEPT( "Found non-EC2Job identified by '%s'.", remoteJobID.c_str() ); } dprintf( D_FULLDEBUG, "Found job object via client token for '%s', updating status ('%s').\n", instanceID.c_str(), status.c_str() ); job->StatusUpdate( instanceID.c_str(), status.c_str(), stateReasonCode.c_str(), publicDNSName.c_str() ); myJobs.Delete( job ); continue; } } // Some servers (OpenStack, Eucalyptus) silently ignore client // tokens. So we need to use the ssh keypair to find jobs that // were submitted but which we don't have an instance ID for. // // TODO This code should be made more efficient. We can // do something better than a linear scan through all // jobs for each status result. Ideally, we'd parse the // ssh keypair name and if it looks like one we generated, // pluck out the job id. if ( !ClientTokenWorks() && !keyName.empty() && keyName != "NULL" ) { myJobs.Rewind(); while ( ( job = myJobs.Next() ) ) { if ( job->m_key_pair == keyName ) { dprintf( D_FULLDEBUG, "Found job object via ssh keypair for '%s', updating status ('%s').\n", instanceID.c_str(), status.c_str() ); job->StatusUpdate( instanceID.c_str(), status.c_str(), stateReasonCode.c_str(), publicDNSName.c_str() ); myJobs.Delete( job ); continue; } } } dprintf( D_FULLDEBUG, "Found unknown instance '%s'; skipping.\n", instanceID.c_str() ); continue; } myJobs.Rewind(); while( ( nextJob = myJobs.Next() ) ) { dprintf( D_FULLDEBUG, "Informing job %p it got no status.\n", nextJob ); nextJob->StatusUpdate( NULL, NULL, NULL, NULL ); } // Don't ask for spot results unless we know about a spot job. This // should prevent us from breaking OpenStack. if( spotJobsByRequestID.getNumElements() == 0 ) { m_checkSpotNext = false; return BSR_DONE; } else { m_checkSpotNext = true; } } if( m_checkSpotNext ) { StringList spotReturnStatus; std::string spotErrorCode; int spotRC = status_gahp->ec2_spot_status_all( resourceName, m_public_key_file, m_private_key_file, spotReturnStatus, spotErrorCode ); if( spotRC == GAHPCLIENT_COMMAND_PENDING ) { return BSR_PENDING; } if( spotRC != 0 ) { std::string errorString = status_gahp->getErrorString(); dprintf( D_ALWAYS, "Error doing batched EC2 spot status query: %s: %s.\n", spotErrorCode.c_str(), errorString.c_str() ); return BSR_ERROR; } List<EC2Job> mySpotJobs; EC2Job * nextSpotJob = NULL; spotJobsByRequestID.startIterations(); while( spotJobsByRequestID.iterate( nextSpotJob ) ) { mySpotJobs.Append( nextSpotJob ); } spotReturnStatus.rewind(); ASSERT( spotReturnStatus.number() % 5 == 0 ); for( int i = 0; i < spotReturnStatus.number(); i += 5 ) { std::string requestID = spotReturnStatus.next(); std::string state = spotReturnStatus.next(); /* std::string launchGroup = */ spotReturnStatus.next(); /* std::string instanceID = */ spotReturnStatus.next(); std::string statusCode = spotReturnStatus.next(); EC2Job * spotJob = NULL; spotRC = spotJobsByRequestID.lookup( HashKey( requestID.c_str() ), spotJob ); if( spotRC != 0 ) { dprintf( D_FULLDEBUG, "Found unknown spot request '%s'; skipping.\n", requestID.c_str() ); continue; } ASSERT( spotJob ); if( ! statusCode.empty() ) { state = statusCode; } dprintf( D_FULLDEBUG, "Found spot job object for '%s', updating status ('%s').\n", requestID.c_str(), state.c_str() ); spotJob->StatusUpdate( NULL, state.c_str(), NULL, NULL ); mySpotJobs.Delete( spotJob ); } mySpotJobs.Rewind(); while( ( nextSpotJob = mySpotJobs.Next() ) ) { dprintf( D_FULLDEBUG, "Informing spot job %p it got no status.\n", nextSpotJob ); nextSpotJob->StatusUpdate( NULL, NULL, NULL, NULL ); } m_checkSpotNext = false; return BSR_DONE; } // This should never happen (but the compiler hates you). return BSR_ERROR; }
int main() { List<int> MyList; int nSelected; bool IsQuit = false; while(!IsQuit) { cout << "请输入链表操作指令: " << endl; cout << "1. 打印链表节点数 " << endl; cout << "2. 打印链表所有节点数据 " << endl; cout << "3. 在指定ID的节点后插入一个新节点 " << endl; cout << "4. 删除指定的数据 " << endl; cout << "5. 在链表最后插入一个新节点" << endl; cout << "6. 清空链表" << endl; cout << "7. 链表排序" << endl; cout << "8. 退出 " << endl; cin >> nSelected; switch(nSelected) { case 1: cout << "链表当前长度为:" << endl; cout << MyList.Length() << endl; break; case 2: cout << "链表当前数据为:" << endl; for(int i = 1; i <= MyList.Length(); i++) { cout << MyList.FindPosition(i) << " "; } cout << endl; break; case 3: cout << "请输入需要插入的位置:" << endl; int new_position; cin >> new_position; cout << "请输入需要插入的数据:" << endl; int new_data; cin >> new_data; MyList.Insert(new_data, new_position); break; case 4: cout << "请输入删除的数据:" << endl; int del_data; cin >> del_data; MyList.Delete(del_data); break; case 5: cout << "请输入需要在链表末尾添加的数据:" << endl; int append_data; cin >> append_data; MyList.Append(append_data); break; case 6: cout << "清空链表" << endl; MyList.MakeEmpty(); break; case 7: cout << "链表排序" << endl; MyList.ListSort(); break; case 8: IsQuit = true; break; default: cout << "此操作无效,请重新选择!" <<endl; break; } } return 0; }
bool ChooseAnImage(int sx,int sy, char *incoming_dir, int slot, char **filename, bool *isdir, int *index_file) { /* Parameters: sx, sy - window size, incoming_dir - in what dir find files, slot - in what slot should an image go (common: #6 for 5.25' 140Kb floppy disks, and #7 for hard-disks). slot #5 - for 800Kb floppy disks, but we do not use them in Apple][? (They are as a rule with .2mg extension) index_file - from which file we should start cursor (should be static and 0 when changing dir) Out: filename - chosen file name (or dir name) isdir - if chosen name is a directory */ /* Surface: */ SDL_Surface *my_screen; // for background if(font_sfc == NULL) if(!fonts_initialization()) return false; //if we don't have a fonts, we just can do none List<char> files; // our files List<char> sizes; // and their sizes (or 'dir' for directories) int act_file; // current file int first_file; // from which we output files printf("Disckchoose! We are here: %s\n",incoming_dir); // files.Delete(); // sizes.Delete(); #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ DIR *dp; struct dirent *ep; dp = opendir (incoming_dir); // open and read incoming directory char *tmp; int i,j, B, N; // for cycles, beginning and end of list // build prev dir if(strcmp(incoming_dir, "/")) { tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs if (dp != NULL) { while (ep = readdir (dp)) // first looking for directories { int what = getstat(incoming_dir, ep->d_name, NULL); if (strlen(ep->d_name) > 0 && /*strcmp(ep->d_name,".")*/// omit "." (cur dir) ep->d_name[0] != '.'/*strcmp(ep->d_name,"..")*/ && what == 1) // is directory! { tmp = new char[strlen(ep->d_name)+1]; // add entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } /* if */ } } #else /* Windows specific functions of reading directory structure */ /* Find subdirs: */ if(strcmp(incoming_dir, "/")) { // we are not in upper direcory tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } } /* while */ } /* if */ #endif // sort directories. Please, don't laugh at my bubble sorting - it the simplest thing I've ever seen --bb if(files.Length() > 2) { N = files.Length() - 1; // B = 1;`- defined above for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } B = files.Length(); // start for files #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ (void) rewinddir (dp); // to the start // now get all regular files while (ep = readdir (dp)) { int fsize; if (strlen(ep->d_name) > 4 && ep->d_name[0] != '.' && (getstat(incoming_dir, ep->d_name, &fsize) == 2)) // is normal file! { tmp = new char[strlen(ep->d_name)+1]; // add this entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", fsize); sizes.Add(tmp); // add this size to list } /* if */ } (void) closedir (dp); #else /* Windows specific functions of reading directory structure */ /* Find files: */ h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { // char *tmp; - must be defined in previous section, when searching subdirs if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } } /* while */ } /* if */ #endif // do sorting for files if(files.Length() > 2 && B < files.Length()) { N = files.Length() - 1; // B = 1; for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } // Count out cursor position and file number output act_file = *index_file; if(act_file >= files.Length()) act_file = 0; // cannot be more than files in list first_file = act_file - (FILES_IN_SCREEN / 2); if (first_file < 0) first_file = 0; // cannot be negativ... // Show all directories (first) and files then // char *tmp; char *siz; // int i; // prepare screen double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); SDL_Surface *tempSurface = NULL; if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; if(tempSurface == NULL) tempSurface = screen; // use screen, if none available my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); while(true) { SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background font_print_centered(sx/2 ,5*facy , incoming_dir, screen, 1.5*facx, 1.3*facy); if (slot == 6) font_print_centered(sx/2,20*facy,"Choose image for floppy 140KB drive", screen, 1*facx, 1*facy); else if (slot == 7) font_print_centered(sx/2,20*facy,"Choose image for Hard Disk", screen, 1*facx, 1*facy); else if (slot == 5) font_print_centered(sx/2,20*facy,"Choose image for floppy 800KB drive", screen, 1*facx, 1*facy); else if (slot == 1) font_print_centered(sx/2,20*facy,"Select file name for saving snapshot", screen, 1*facx, 1*facy); else if (slot == 0) font_print_centered(sx/2,20*facy,"Select snapshot file name for loading", screen, 1*facx, 1*facy); font_print_centered(sx/2,30*facy, "Press ENTER to choose, or ESC to cancel",screen, 1.4*facx, 1.1*facy); files.Rewind(); // from start sizes.Rewind(); i = 0; // printf("We've printed some messages, go to file list!\n"); // show all fetched dirs and files // topX of first fiel visible int TOPX = int(45*facy); while(files.Iterate(tmp)) { sizes.Iterate(siz); // also fetch size string if (i >= first_file && i < first_file + FILES_IN_SCREEN) { // FILES_IN_SCREEN items on screen // char tmp2[80],tmp3[256]; if (i == act_file) { // show item under cursor (in inverse mode) SDL_Rect r; r.x= 2; r.y= TOPX + (i-first_file) * 15 * facy - 1; if(strlen(tmp) > 46) r.w = 46 * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; else r.w= strlen(tmp) * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; // 6- FONT_SIZE_X r.h= 9 * 1.5 * facy; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format,255,0,0));// in RED } /* if */ // print file name with enlarged font char ch; ch = 0; if(strlen(tmp) > 46) { ch = tmp[46]; tmp[46] = 0;} //cut-off too long string font_print(4, TOPX + (i - first_file) * 15 * facy, tmp, screen, 1.7*facx, 1.5*facy); // show name font_print(sx - 70 * facx, TOPX + (i - first_file) * 15 * facy, siz, screen, 1.7*facx, 1.5*facy);// show info (dir or size) if(ch) tmp[46] = ch; //restore cut-off char } /* if */ i++; // next item } /* while */ ///////////////////////////////////////////////////////////////////////////////////////////// // draw rectangles rectangle(screen, 0, TOPX - 5, sx, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 480*facx, TOPX - 5, 0, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(10); SDL_PollEvent(&event); } // control cursor keyboard = SDL_GetKeyState(NULL); // get current state of pressed (and not pressed) keys if (keyboard[SDLK_UP] || keyboard[SDLK_LEFT]) { if (act_file>0) act_file--; // up one position if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_DOWN] || keyboard[SDLK_RIGHT]) { if (act_file < (files.Length() - 1)) act_file++; if (act_file >= (first_file + FILES_IN_SCREEN)) first_file=act_file - FILES_IN_SCREEN + 1; } /* if */ if (keyboard[SDLK_PAGEUP]) { act_file-=FILES_IN_SCREEN; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN]) { act_file+=FILES_IN_SCREEN; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+FILES_IN_SCREEN)) first_file=act_file-FILES_IN_SCREEN + 1; } /* if */ // choose an item? if (keyboard[SDLK_RETURN]) { // dup string from selected file name *filename = strdup(files[act_file]); // printf("files[act_file]=%s, *filename=%s\n\n", files[act_file], *filename); if(!strcmp(sizes[act_file], "<DIR>") || !strcmp(sizes[act_file], "<UP>")) *isdir = true; else *isdir = false; // this is directory (catalog in Apple][ terminology) *index_file = act_file; // remember current index files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return true; } /* if */ if (keyboard[SDLK_ESCAPE]) { files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return false; // ESC has been pressed } /* if */ if (keyboard[SDLK_HOME]) { // HOME? act_file=0; first_file=0; } /* if */ if (keyboard[SDLK_END]) { // END? act_file=files.Length() - 1; // go to the last possible file in list first_file=act_file - FILES_IN_SCREEN + 1; if(first_file < 0) first_file = 0; } /* if */ } } /* ChooseAnImage */
bool state_changepack_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); { levelpacks.Delete(); #ifdef _WIN32 /* Find files: */ WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile("maps/*.lp",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); levelpacks.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); levelpacks.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; dp = opendir ("maps"); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-3]=='.' && ep->d_name[strlen(ep->d_name)-2]=='l' && ep->d_name[strlen(ep->d_name)-1]=='p') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); levelpacks.Add(tmp); } /* if */ } (void) closedir (dp); } #endif act_levelpack=0; } } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); font_print_centered(sx/2,(sy/2)-24,"CHOOSE LEVEL-PACK:",screen); { int i,y; char *tmp; i=0; y=(sy/2)-8; levelpacks.Rewind(); while(levelpacks.Iterate(tmp)) { if (i==act_levelpack) { SDL_Rect r; r.x=0; r.y=y; r.w=SCREEN_X; r.h=8; SDL_FillRect(screen,&r,SDL_MapRGB(screen->format,255,0,0)); } /* if */ font_print_centered(sx/2,y,tmp,screen); i++; y+=8; } /* while */ } if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE==32) { if (keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY]) { /* change level-pack: */ strcpy(levelpack,levelpacks[act_levelpack]); NLEVELS=-1; SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_UP] && !old_keyboard[SDLK_UP]) { if (act_levelpack>0) act_levelpack--; } /* if */ if (keyboard[SDLK_DOWN] && !old_keyboard[SDLK_DOWN]) { if (act_levelpack<(levelpacks.Length()-1)) act_levelpack++; } /* if */ } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { STATE=1; SUBSTATE=0; } /* if */ } /* if */ return true; } /* state_changepack_cycle */