void update_cd() { FILE *tracks_fp; char track_name[MAX_STRING]; int len; int track = 1; int screen_line = 1; WINDOW *box_window_ptr; WINDOW *sub_window_ptr; clear_all_screen(); mvprintw(PROMPT_LINE, 0, "Re-entering tracks for CD."); if (!get_confirm()) { return; } move(PROMPT_LINE, 0); clrtoeol(); remove_tracks(); mvprintw(MESSAGE_LINE, 0, "Enter a blank line to finish"); tracks_fp = fopen(TRACKS_FILE, "a"); /* Just to show how, enter the information in a scrolling, boxed, window. The trick is to set-up a sub-window, draw a box around the edge, then add a new, scrolling, sub-window just inside the boxed sub-window. */ box_window_ptr = subwin(stdscr, BOXED_LINES + 2, BOXED_ROWS + 2, BOX_LINE_POS - 1, BOX_ROW_POS - 1); if (!box_window_ptr) { return; } box(box_window_ptr, ACS_VLINE, ACS_HLINE); sub_window_ptr = subwin(stdscr, BOXED_LINES, BOXED_ROWS, BOX_LINE_POS, BOX_ROW_POS); if (!sub_window_ptr) { return; } scrollok(sub_window_ptr, TRUE); werase(sub_window_ptr); touchwin(stdscr); do { //todo mvprintw mvwprintw(sub_window_ptr, screen_line++, BOX_ROW_POS + 2, "Track %d: ", track); clrtoeol(); refresh(); wgetnstr(sub_window_ptr, track_name, MAX_STRING); len = strlen(track_name); if (len > 0 && track_name[len - 1 ] == '\n') { track_name[len - 1] = '\0'; } if (*track_name) { fprintf(tracks_fp, "%s,%d,%s\n", current_cat, track, track_name); } track++; if (screen_line > BOXED_LINES - 1) { /*time to start scrolling*/ scroll(sub_window_ptr); screen_line--; } } while (*track_name); delwin(sub_window_ptr); fclose(tracks_fp); }
// Functions from admin account void book_manage() { int day,sl,size=0,c=0,com,choice,menu_choice; int day_n,com_n,sl_n; char **options,buff[15],*user_id; char* menu[] = {"dDelete booking", "cChange booking", "bBack", 0, }; struct tm tim,today; time_t now= time(0); user_id= malloc(15*sizeof(char)); options= malloc(200*sizeof(char*)); for(c=0;c<100;c++) options[c]= malloc(20*sizeof(char)); today= tim = *(localtime(&now)); for(com=1;com<=MAX_COMP_P;com++) { now= time(0); tim= *(localtime(&now)); for(day=0;day<3;day++) { if(day!=0) now+= 60*60*24; tim= *(localtime(&now)); for(sl=0;sl<5;sl++) { user_id= user_free_compp(day,com,sl); strcpy(options[3*size],"Comp id: "); options[3*size][8]= com+48; strftime(buff,15,"%d/%m/%y" ,&tim); strcpy(options[3*size+1],"Slot no. "); options[3*size+1][8]= sl+49; strcat(options[3*size+1],buff); strcpy(options[3*size+2],"User: "******"What to do you want to do with selected computer",menu); switch(menu_choice){ case 'b': break; case 'd': if(!get_confirm()) return; else update_compp(com_n,"0",day_n,sl_n); break; case 'c': mvprintw(13,10,"Enter user name: "); scanw("%s",user_id); if(!get_confirm()) return; update_compp(com_n,user_id,day_n,sl_n); break; } endwin(); }
/* Update the tracks in a cd. Uses a boxed scrolling window, which is worth * a note: if you try to box a window and then sroll, the box itself will * scroll b/c it's inside the bounds. To deal with this, boxed windows that * need to scroll should be implemented as two nested windows. */ void update_cd() { FILE *tracks_fp; char track_name[MAX_STRING]; int len; int track_num = 1; int screen_line = 1; WINDOW *box_window; WINDOW *sub_window; clear_all_screen(); // get confirmation before we delete any old tracks and add new ones. mvprintw(PROMPT_LINE, 0, "Re-entering tracks for CD."); if (!get_confirm()) { return; } move(PROMPT_LINE, 0); clrtoeol(); clear_all_screen(); // go ahead and remove tracks, print prompt, and create the FILE remove_tracks(); mvprintw(MESSAGE_LINE, 0, "Enter a blank line to finish"); tracks_fp = fopen(TRACKS_FILE, "a"); // set up the nexted windows. Note the box has +2 on all dims // also note that the subwindow isn't impmlemented as a sub window of the // box_window, but rather of stdscr. Not sure if this matters. box_window = subwin(stdscr, BOXED_LINES + 2, BOXED_COLS + 2, BOX_LINE_POS - 1, BOX_COL_POS -1); if (!box_window) { // "error handling" lol return; } sub_window = subwin(stdscr, BOXED_LINES, BOXED_COLS, BOX_LINE_POS, BOX_COL_POS); if (!sub_window) { // more "error handling" return; } // initialize the windows box(box_window, ACS_VLINE, ACS_HLINE); scrollok(sub_window, TRUE); werase(sub_window); touchwin(stdscr); do { mvwprintw(sub_window, screen_line++, 3, "Track %d: ", track_num); clrtoeol(); refresh(); // get the track name and strip the '\n'. If they entered a blank line, // the first character will e '\0', which is key in the `ifs` to follow wgetnstr(sub_window, track_name, MAX_STRING); len = strlen(track_name); if (len > 0 && track_name[len - 1] == '\n') { track_name[len - 1] = '\0'; } // if the track name doesn't start with 0, write it to file. Then incr // track_num if (*track_name) { fprintf(tracks_fp, "%s,%d,%s\n", current_cat, track_num, track_name); } track_num++; // scroll down if need be (refresh in the next loop) if (screen_line > BOXED_LINES - 1) { scroll(sub_window); screen_line--; } } while (*track_name); // clean up delwin(sub_window); delwin(box_window); // the authors seem to have forgotten this fclose(tracks_fp); }