int main(int argc, char * argv[]) { int i,fd = open("courses.txt", O_RDWR | O_CREAT, S_IRWXU); if( fd == -1 ){ return EXIT_FAILURE; } char name[COURSE_NAME_LEN]; Date date; float grade; for(i=0; i<5;i++){ lseek(fd, 0, SEEK_SET); scanf("%s %d/%d %f", name, &date.month, &date.year, &grade); printf("%s\n%d/%d\n%f\n", name, date.month, date.year, grade); AddCourse(fd, name, date, grade); } close(fd); return 0; }
Boolean CourseListHandleEvent(EventPtr event) { FormPtr frm=FrmGetActiveForm(); Boolean handled = false; ListType *lstP=GetObjectPtr(LIST_courses); Boolean categoryEdited, reDraw=false; UInt16 category, numRecords; ControlType *ctl; UInt32 *recordList; if (event->eType == ctlSelectEvent) { // button handling switch (event->data.ctlSelect.controlID) { case BUTTON_courselist_back: handled=true; FrmGotoForm(FORM_main); break; case BUTTON_courselist_del: handled=true; if (LstGetSelection(lstP) == noListSelection) { FrmAlert(ALERT_clist_noitem); } else { DeleteCourse(gCourseInd[LstGetSelection(lstP)]); CleanupCourselist(); DrawCourses(lstP); FrmDrawForm(FrmGetActiveForm()); } break; case BUTTON_courselist_add: handled=true; gMenuCurrentForm=FORM_courselist; AddCourse(); break; case BUTTON_courselist_edit: handled=true; if (LstGetSelection(lstP) == noListSelection) { FrmAlert(ALERT_clist_noitem); } else { gMenuCurrentForm=FORM_courselist; EditCourse(gCourseInd[LstGetSelection(lstP)]); } break; case BUTTON_courselist_beam: handled=true; if (LstGetSelection(lstP) == noListSelection) { FrmAlert(ALERT_clist_noitem); } else { BeamCourse(gCourseInd[LstGetSelection(lstP)]); } break; case LIST_cl_cat_trigger: handled=true; category=DatabaseGetCat(); numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY); recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32)); CatPreEdit(numRecords, recordList); categoryEdited = CategorySelect(DatabaseGetRef(), frm, LIST_cl_cat_trigger, LIST_cl_cat, false, &category, gCategoryName, 0, STRING_cat_edit); // categoryDefaultEditCategoryString if (categoryEdited || (category != DatabaseGetCat())) { reDraw=true; DatabaseSetCat(category); ctl = GetObjectPtr(LIST_cl_cat_trigger); CategoryGetName(DatabaseGetRef(), category, gCategoryName); CategorySetTriggerLabel(ctl, gCategoryName); } CatPostEdit(numRecords, recordList); if (reDraw) { CleanupCourselist(); DrawCourses(lstP); FrmDrawForm(FrmGetActiveForm()); } if (recordList != NULL) MemPtrFree((MemPtr)recordList); break; default: break; } } else if (event->eType == keyDownEvent) { // We have a hard button assigned and it was pressed if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) { if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) { FrmGotoForm(FORM_main); handled = true; } } else if (EvtKeydownIsVirtual(event)) { // Up or down keys pressed ListType *lst=GetObjectPtr(LIST_courses); switch (event->data.keyDown.chr) { case vchrPageUp: if (LstGetSelection(lst) == noListSelection) { LstSetSelection(lst, gNumCourses-1); CourseListHandleSelection(); } else if (LstGetSelection(lst) > 0) { LstSetSelection(lst, LstGetSelection(lst)-1); CourseListHandleSelection(); } handled=true; break; case vchrPageDown: if (LstGetSelection(lst) == noListSelection) { LstSetSelection(lst, 0); CourseListHandleSelection(); } else if (LstGetSelection(lst) < (gNumCourses-1)) { LstSetSelection(lst, LstGetSelection(lst)+1); CourseListHandleSelection(); } handled=true; break; default: break; } } } else if (event->eType == lstSelectEvent) { return CourseListHandleSelection(); } else if (event->eType == menuOpenEvent) { return HandleMenuOpenEvent(event); } else if (event->eType == menuEvent) { // forwarding of menu events return HandleMenuEvent(event->data.menu.itemID); } else if (event->eType == frmOpenEvent) { // initializes and draws the form ControlType *ctl; frm = FrmGetActiveForm(); lstP=GetObjectPtr(LIST_courses); FrmDrawForm (frm); DrawCourses(lstP); FrmDrawForm (frm); ctl = GetObjectPtr(LIST_cl_cat_trigger); CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); CategorySetTriggerLabel (ctl, gCategoryName); WinDrawLine(1, 140, 158, 140); handled = true; } else if (event->eType == frmUpdateEvent) { // redraws the form if needed CleanupCourselist(); DrawCourses(GetObjectPtr(LIST_courses)); FrmDrawForm (frm); WinDrawLine(1, 140, 158, 140); handled = false; } else if (event->eType == frmCloseEvent) { // this is done if form is closed CleanupCourselist(); } return (handled); }
/*********************************************************************** * handling for the main drop down menu actions ***********************************************************************/ Boolean HandleMenuEvent (UInt16 command) { Boolean handled = false; MenuEraseStatus(0); gMenuCurrentForm=FrmGetFormId(FrmGetActiveForm()); switch (command) { case MENUITEM_about: FrmDoDialog(FrmInitForm(FORM_about)); handled=true; break; case MENUITEM_course: AddCourse(); handled=true; break; case MENUITEM_time: if (CountCourses() != 0) { AddTime(); } else { FrmAlert(ALERT_nocourses); } handled=true; break; case MENUITEM_courselist: FrmGotoForm(FORM_courselist); handled=true; break; case MENUITEM_settings: FrmPopupForm(FORM_settings); handled=true; break; case MENUITEM_alarm: FrmPopupForm(FORM_alarm_sets); handled=true; break; case MENUITEM_exams: FrmGotoForm(FORM_exams); handled=true; break; case MENUITEM_beam: BeamSemester(DatabaseGetCat()); handled=true; break; case MENUITEM_chat: AppLaunchWithCommand(UNICHAT_APP_CREATOR, sysAppLaunchCmdNormalLaunch, NULL); handled=true; break; case MENUITEM_mensa: AppLaunchWithCommand(UNIMENSA_APP_CREATOR, sysAppLaunchCmdNormalLaunch, NULL); handled=true; break; default: break; } return handled; }
int NEAR PASCAL CommandHandler(WORD wParam, LONG lParam) { /* if (HIWORD(lParam) == EN_CHANGE) { if (focus(GetDlgCtrlID(LOWORD(lParam))) && players.player_numb > -1) bNeedSaveP = TRUE; else if (courses.course_numb > -1) bNeedSaveC = TRUE; } */ switch (wParam) { case IDOK: SendMessage(hWnd, WM_COMMAND, IDD_RLIST, MAKELONG(0, LBN_DBLCLK)); return NULL; case IDM_CONTENTS: case IDM_SEARCHON: case IDM_USE: MessageBox(hWnd, "Help to come soon!", szAppName, MB_OK | MB_ICONEXCLAMATION); return NULL; case IDM_ABOUT: /* display about dialog box */ lpfnGenericDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst); DialogBox(hInst, "ABOUT", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_HANDICAP: lpfnGenericDlgProc = MakeProcInstance((FARPROC)HandicapDlgProc, hInst); DialogBox(hInst, "HANDICAP", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_P_SEARCH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; /* fall through */ case IDM_C_SEARCH: if (!get_course(hWnd, &courses, c_index)) return NULL; wWhich = wParam; lpfnGenericDlgProc = MakeProcInstance((FARPROC)SearchDlgProc, hInst); DialogBox(hInst, "SEARCH", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_GRAPH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (!get_course(hWnd, &courses, c_index)) return NULL; if (IDYES == MessageBox(hWnd, "You must have Microsoft Excel\nto use this option. Continue?", szAppName, MB_YESNO | MB_ICONQUESTION)) GraphData(&(players).player[p_index].p_scores, &courses); return NULL; case IDM_NEW_P: /* save current file and clear viewport */ if (bNeedSaveP && IDCANCEL == AskAboutSave(hWnd, szFileTitleP, PLAYER_MARKER)) return FALSE; szFileTitleP[NULL] = '\0'; bNeedSaveP = FALSE; p_index = r_index = r_last = 0; players.player_numb = -1; clear_player(hWnd, hWndRList); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_NEW_C: if (bNeedSaveC && IDCANCEL == AskAboutSave(hWnd, szFileTitleC, COURSE_MARKER)) return FALSE; szFileTitleC[NULL] = '\0'; bNeedSaveC = FALSE; c_index = 0; courses.course_numb = -1; clear_course(hWnd); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_OPEN_P: /* open an existing file */ of_player.lpstrTitle = "Open Player"; of_player.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_player)) return FALSE; if (ReadFile(hWnd, szFileP, szFileTitleP, szFileTitleC, bNeedSaveP, &players, &courses, PLAYER_MARKER)) { bNeedSaveP = FALSE; p_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_OPEN_C: /* open an existing file */ of_course.lpstrTitle = "Open Course"; of_course.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_course)) return FALSE; if (ReadFile(hWnd, szFileC, szFileTitleP, szFileTitleC, bNeedSaveC, &players, &courses, COURSE_MARKER)) { bNeedSaveC = FALSE; c_index = 0; show_course(hWnd, &courses, &c_index); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_SAVE_P: /* write current file */ if (szFileTitleP[NULL]) { if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_P: /* change file name */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; of_player.lpstrTitle = "Save Player"; of_player.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_player)) return FALSE; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_SAVE_C: /* write current file */ if (szFileTitleC[NULL]) { if (!get_course(hWnd, &courses, c_index)) return NULL; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_C: /* change file name */ if (!get_course(hWnd, &courses, c_index)) return NULL; of_course.lpstrTitle = "Save Course"; of_course.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_course)) return FALSE; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_PRINT_P: /* Print current file */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleP[NULL] ? szFileTitleP : szUntitled); return NULL; case IDM_PRINT_C: /* Print current file */ if (!get_course(hWnd, &courses, c_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleC[NULL] ? szFileTitleC : szUntitled); return NULL; case IDM_EXIT: /* Send a close message, and exit the program */ SendMessage(hWnd, WM_CLOSE, NULL, 0L); return NULL; case IDM_UNDO: /* Check for undo status */ SendMessage(GetFocus(), WM_UNDO, 0, 0L); return 0; case IDM_CUT: /* Send cut message */ SendMessage(GetFocus(), WM_CUT, 0, 0L); return 0; case IDM_COPY: /* Send copy message */ SendMessage(GetFocus(), WM_COPY, 0, 0L); return 0; case IDM_PASTE: /* Send paste message */ SendMessage(GetFocus(), WM_PASTE, 0, 0L); return 0; case IDM_CLEAR: /* Send clear message */ SendMessage(GetFocus(), WM_CLEAR, 0, 0L); return 0; case IDM_P_ADD: if (AddPlayer(hWnd, &players, &p_index, &r_index)) bNeedSaveP = TRUE; return NULL; case IDM_R_ADD: if (AddRound(hWnd, &players, &p_index, &r_index, &r_last)) bNeedSaveP = TRUE; return NULL; case IDM_C_ADD: if (AddCourse(hWnd, &courses, &c_index)) bNeedSaveC = TRUE; return NULL; case IDM_P_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player, players.player_numb+1, sizeof(players.player[0]), compare_player); bNeedSaveP = TRUE; p_index = r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_R_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player[p_index].p_scores.history, players.player[p_index].p_scores.round_numb+1, sizeof(players.player[p_index].p_scores.history[0]), compare_round); bNeedSaveP = TRUE; r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_C_SORT: if (!get_course(hWnd, &courses, c_index)) return NULL; qsort(courses.course, courses.course_numb, sizeof(courses.course[0]), compare_course); bNeedSaveC = TRUE; c_index = 0; show_course(hWnd, &courses, &c_index); return NULL; case IDM_P_DELETE: if (players.player_numb > -1) { GetDlgItemText(hWnd, IDD_PLAST, (players).player[p_index].p_last, LAST_NAME_LENGTH+1); GetDlgItemText(hWnd, IDD_PFIRST, (players).player[p_index].p_first, FIRST_NAME_LENGTH+1); lstrcpy(szDelete, "Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_first); lstrcat(szDelete, " "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_last); if (IDYES == MessageBox(hWnd, szDelete, "Delete Player", MB_YESNO | MB_ICONQUESTION)) { bNeedSaveP = TRUE; delete_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); } } /* if */ return NULL; case IDM_R_DELETE: if (players.player[p_index].p_scores.round_numb > -1) { convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); lstrcpy(szDelete, (LPSTR)"Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lstrcat(szDelete, " "); lstrcat(szDelete, szDate); if (IDYES == MessageBox(hWnd, szDelete, "Delete Round", MB_YESNO | MB_ICONQUESTION)) { delete_round(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); bNeedSaveP = TRUE; } /* if */ } /* if */ return NULL; case IDM_C_DELETE: if (courses.course_numb > -1) { GetDlgItemText(hWnd, IDD_CNAME, (courses).course[c_index].c_name, COURSE_NAME_LENGTH+1); lstrcpy(szc_name, (courses).course[c_index].c_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)DeleteCourseDlgProc, hInst); DialogBox(hInst, "DELETEC", hWnd, lpfnGenericDlgProc); FreeProcInstance(DeleteCourseDlgProc); /* Release memory */ if (bYesNo == IDYES) { bNeedSaveC = TRUE; delete_course(&courses, &c_index); if (bDeleteRounds && delete_rounds(&players, szc_name)) { bNeedSaveP = TRUE; show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, TRUE); } /* if */ show_course(hWnd, &courses, &c_index); } /* if */ } /* if */ return NULL; case IDD_RLIST: switch(HIWORD(lParam)) { case LBN_DBLCLK: if ((players.player_numb == -1) || (players.player[p_index].p_scores.round_numb == -1)) return NULL; lstrcpy(szNDTitle, "Change Course / Name Date"); convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); get_date_elements(szDate, szmm, szdd, szyy); lstrcpy(szc_name, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)NameDateDlgProc, hInst); DialogBox(hInst, "NAMEDATE", hWnd, lpfnGenericDlgProc); FreeProcInstance(NameDateDlgProc); /* Release memory */ if (bNameDate == IDOK) { bNeedSaveP = TRUE; players.player[p_index].p_scores.history[r_index].date = string_to_date(szmm, szdd, szyy); lstrcpy((LPSTR)players.player[p_index].p_scores.history[r_index].course_name, szc_name); show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, FALSE); } /* if */ return NULL; case LBN_SELCHANGE: if ((int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L) == r_index) break; if (!get_round(hWnd, &players, p_index, r_index)) { SendMessage(hWndRList, LB_SETCURSEL, r_index, 0L); return NULL; } r_index = (int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L); if (r_index != LB_ERR && r_index != r_last) { show_round(hWnd, players.player[p_index].p_scores.history[r_index].score); r_last = r_index; } /* if */ return NULL; } /* switch (HIWORD(lParam)) */ return NULL; default: return FALSE; } /* switch (wParam) */ } /* CommandHandler */