boolean enter_time(char key, time_t *sometime, char *buffer, unsigned *positionptr, boolean validate) { unsigned digit = char_to_digit(key); unsigned position = *positionptr; if (!isdigit(key)) { error_beep(); // Show that the entry is invalid. return false; } if (validate) { if ((position == 0 && digit > 2) || (position == 1 && buffer[position-1] == '2' && digit > 3) || (digit > 5 && position == 2)) { error_beep(); // Show that the entry is invalid. return false; } } buffer[position++] = key; buffer[position] = '\0'; if (position == 4) { *positionptr = 0; return true; } else { *positionptr = position; return false; } }
void keypress_clock_display(char key) { switch (key) { case '0': state = VIEW_MENU; break; default: error_beep(); break; } }
/* Handle stopwatch. */ void keypress_stopwatch(char key) { switch(key) { case '1': stopwatch_on = true; break; case '2': stopwatch_on = false; break; case '3': stopwatch.hours = 0; stopwatch.deci_seconds = 0; break; default: error_beep(); // Show that the entry is invalid. break; } }
/* Handle the menu. */ void keypress_menu(char key) { switch(key) { case 'A': state = VIEW_SET_ALARM; set_alarm_position = 0; break; case 'B': state = VIEW_SET_TIMER; break; case 'C': state = VIEW_SET_STOPWATCH; break; default: error_beep(); // Show that the entry is invalid. break; } }
/* called when we click ok */ static void mkrcp_ok_cb( GtkWidget *widget, gpointer dialog) { GtkWidget *window; struct gui_star_list *gsl; struct wcs *wcs; char *fn, *fn2, *comment, *target, *seq; int w = 0, h = 0; int flags; struct stf *rcp; FILE *rfp; char qu[1024]; struct image_channel *i_ch; GList *stars; window = g_object_get_data(G_OBJECT(dialog), "im_window"); g_return_if_fail(window != NULL); i_ch = g_object_get_data(G_OBJECT(window), "i_channel"); if (i_ch != NULL && i_ch->fr != NULL) { w = i_ch->fr->w; h = i_ch->fr->h; } wcs = g_object_get_data(G_OBJECT(window), "wcs_of_window"); if (wcs == NULL) { err_printf_sb2(window, "Cannot create a recipe without a wcs"); error_beep(); return; } gsl = g_object_get_data(G_OBJECT(window), "gui_star_list"); if (gsl == NULL || gsl->sl == NULL) { err_printf_sb2(window, "No stars to put in recipe"); error_beep(); return; } fn = named_entry_text(dialog, "recipe_file_entry"); if (fn == NULL || fn[0] == 0) { err_printf_sb2(window, "Please enter a recipe file name"); error_beep(); if (fn != NULL) g_free(fn); return; } fn2 = add_extension(fn, "rcp"); if (fn2 == NULL) fn2 = fn; else g_free(fn); if ((rfp = fopen(fn2, "r")) != NULL) { /* file exists */ snprintf(qu, 1023, "File %s exists\nOverwrite?", fn2); if (!modal_yes_no(qu, "gcx: file exists")) { free(fn2); fclose(rfp); return; } else { fclose(rfp); } } rfp = fopen(fn2, "w"); if (rfp == NULL) { err_printf_sb2(window, "Cannot create file %s (%s)", fn2, strerror(errno)); free(fn2); return; } comment = named_entry_text(dialog, "comments_entry"); target = named_entry_text(dialog, "tgt_entry"); seq = named_entry_text(dialog, "seq_entry"); flags = get_recipe_flags(dialog); rcp = create_recipe(gsl->sl, wcs, flags, comment, target, seq, w, h); if (rcp == NULL) { err_printf_sb2(window, "%s", last_err()); } else { g_object_set_data_full(G_OBJECT(window), "recipe", rcp, (GDestroyNotify)stf_free_all); stf_fprint(rfp, rcp, 0, 0); stars = stf_find_glist(rcp, 0, SYM_STARS); info_printf_sb2(window, "recipe", 10000, "Wrote %d star(s) to %s\n", g_list_length(stars), fn2); } fclose(rfp); free(fn2); g_free(comment); g_free(target); g_free(seq); if (rcp != NULL) gtk_widget_hide(dialog); }