int main() { location start_location = get_location(); start_location.distance = 0; unsigned int number = get_number_of_location(); location min, max; max = start_location; for (unsigned j = 0; j < number; j++) { location destination = get_location(); destination.distance = calculate_distance(start_location, destination); if (j==0) min = destination; if (destination.distance < min.distance) min = destination; if (destination.distance > max.distance) max = destination; } std::cout << "Start Location: " << print_location(start_location); std::cout << "Closest Location: " << print_location(min); std::cout << "Farthest Location: " << print_location(max); return 0; }
void error(Module *state, const char *format, ...) { va_list ap; va_start(ap, format); print_location(state); vprintf(format, ap); printf("\n"); }
void die(Module *state, const char *format, ...) { va_list ap; va_start(ap, format); print_location(state); vprintf(format, ap); printf("\n"); if(state) Module_destroy(state); exit(1); }
/* Function to get query the location of a competitor. */ void query_location(event_ptr event) { competitor *competitor; int number; printf("\nPlease enter in the competitor number you wish to query the location of: "); scanf("%d", &number); while ((competitor = get_competitor(event, number)) == NULL) { /* Check to make sure a valid competitor is entered. */ printf("\nPlease enter in a valid competitor number: "); scanf("%d", &number); } print_location(event, competitor); }
CAMLexport void caml_print_exception_backtrace(void) { int i; struct loc_info li; if (caml_debug_info == Val_emptylist) { fprintf(stderr, "(Cannot print stack backtrace: no debug information available)\n"); return; } for (i = 0; i < caml_backtrace_pos; i++) { extract_location_info(caml_backtrace_buffer[i], &li); print_location(&li, i); } }
void report_warning(const char* fmt, ...) { va_list ap; if (opt_console_output && !opt_no_warnings){ if (end_loc){ print_location(); } fprintf(stderr, "warning: "); va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); } }
void report_error(const char* fmt, ...) { va_list ap; met_error = 1; if (opt_console_output){ if (end_loc){ print_location(); } fprintf(stderr, "error: "); va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); } }
/* Set up for a diagnostic: print the file and line, bump the error counter, etc. SRC_LOC is the logical line number; zero means to print at the location of the previously lexed token, which tends to be the correct place by default. The column number can be specified either using COLUMN or (if COLUMN==0) extracting SOURCE_COLUMN from SRC_LOC. (This may seem redundant, but is useful when pre-scanning (cleaning) a line, when we haven't yet verified whether the current line_map has a big enough max_column_hint.) Returns 0 if the error has been suppressed. */ static int _cpp_begin_message (cpp_reader *pfile, int code, source_location src_loc, unsigned int column) { int level = CPP_DL_EXTRACT (code); switch (level) { case CPP_DL_WARNING: case CPP_DL_PEDWARN: if (cpp_in_system_header (pfile) && ! CPP_OPTION (pfile, warn_system_headers)) return 0; /* Fall through. */ case CPP_DL_WARNING_SYSHDR: if (CPP_OPTION (pfile, warnings_are_errors) || (level == CPP_DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors))) { if (CPP_OPTION (pfile, inhibit_errors)) return 0; level = CPP_DL_ERROR; pfile->errors++; } else if (CPP_OPTION (pfile, inhibit_warnings)) return 0; break; case CPP_DL_ERROR: if (CPP_OPTION (pfile, inhibit_errors)) return 0; /* ICEs cannot be inhibited. */ case CPP_DL_ICE: pfile->errors++; break; } print_location (pfile, src_loc, column); if (CPP_DL_WARNING_P (level)) fputs (_("warning: "), stderr); else if (level == CPP_DL_ICE) fputs (_("internal error: "), stderr); else fputs (_("error: "), stderr); return 1; }
CAMLexport void caml_print_exception_backtrace(void) { value events; int i; struct loc_info li; events = read_debug_info(); if (events == Val_false) { fprintf(stderr, "(Program not linked with -g, cannot print stack backtrace)\n"); return; } for (i = 0; i < caml_backtrace_pos; i++) { extract_location_info(events, caml_backtrace_buffer[i], &li); print_location(&li, i); } }
void report_fatal(const char *fmt, ...) { va_list ap; if (opt_console_output){ if (end_loc){ print_location(); } fprintf(stderr, "fatal error: "); va_start(ap, fmt); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); } clear_location(); exit(EXIT_FAILURE); }
/****************************************************************************** * @brief Print energy balance structure. *****************************************************************************/ void print_domain(domain_struct *domain, bool print_loc) { size_t i; fprintf(LOG_DEST, "domain:\n"); fprintf(LOG_DEST, "\tncells_total : %zd\n", domain->ncells_total); fprintf(LOG_DEST, "\tncells_active: %zd\n", domain->ncells_active); fprintf(LOG_DEST, "\tn_nx : %zd\n", domain->n_nx); fprintf(LOG_DEST, "\tn_ny : %zd\n", domain->n_ny); fprintf(LOG_DEST, "\tlocations : %p\n", domain->locations); if (print_loc) { for (i = 0; i < domain->ncells_active; i++) { print_location(&(domain->locations[i])); } } }
int main(void) { char *p; int i; /* IP-Adresse ermitteln */ p = getenv("REMOTE_ADDR"); if( p == NULL) { /* Fehler bei getenv-Abfrage */ print_status("500"); return EXIT_FAILURE; } for(i=0; forbidden[i] != NULL; i++) if(strcmp(p, forbidden[i]) == 0) { /* Diese IP hat keinen Zutritt */ print_status("403"); return EXIT_FAILURE; } /* Ok, der User wird auf die Willkommen-Seite weitergeleitet. * Die URL an Ihre Beduerfnisse anpassen */ print_location("http://localhost/welcome.html"); return EXIT_SUCCESS; }
void console::info_location(const metadb_handle_ptr & src) {print_location(src);}
void console::info_location(const playable_location & src) {print_location(src);}
void console::print_location(const metadb_handle_ptr & src) { print_location(src->get_location()); }
void os::print_register_info(outputStream *st, void *context) { if (context == NULL) return; ucontext_t *uc = (ucontext_t*)context; intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); st->print_cr("Register to memory mapping:"); st->cr(); // this is only for the "general purpose" registers st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON__G1]); st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON__G2]); st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON__G3]); st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON__G4]); st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON__G5]); st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON__G6]); st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON__G7]); st->cr(); st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON__O0]); st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON__O1]); st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON__O2]); st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON__O3]); st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON__O4]); st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON__O5]); st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON__O6]); st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON__O7]); st->cr(); st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); st->cr(); st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); st->cr(); }
int main(int argc, char *argv[]) { int r; #ifdef ENABLE_NLS /* Init locale */ setlocale(LC_CTYPE, ""); setlocale(LC_MESSAGES, ""); /* Internationalisation */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif /* Initialize settings to NULL values. */ char *config_filepath = NULL; /* Settings for day, night and transition. Initialized to indicate that the values are not set yet. */ transition_scheme_t scheme = { TRANSITION_HIGH, TRANSITION_LOW }; scheme.day.temperature = -1; scheme.day.gamma[0] = NAN; scheme.day.brightness = NAN; scheme.night.temperature = -1; scheme.night.gamma[0] = NAN; scheme.night.brightness = NAN; /* Temperature for manual mode */ int temp_set = -1; const gamma_method_t *method = NULL; char *method_args = NULL; const location_provider_t *provider = NULL; char *provider_args = NULL; int transition = -1; program_mode_t mode = PROGRAM_MODE_CONTINUAL; int verbose = 0; char *s; /* Flush messages consistently even if redirected to a pipe or file. Change the flush behaviour to line-buffered, without changing the actual buffers being used. */ setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); /* Parse command line arguments. */ int opt; while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:prt:vVx")) != -1) { switch (opt) { case 'b': parse_brightness_string(optarg, &scheme.day.brightness, &scheme.night.brightness); break; case 'c': free(config_filepath); config_filepath = strdup(optarg); break; case 'g': r = parse_gamma_string(optarg, scheme.day.gamma); if (r < 0) { fputs(_("Malformed gamma argument.\n"), stderr); fputs(_("Try `-h' for more" " information.\n"), stderr); exit(EXIT_FAILURE); } /* Set night gamma to the same value as day gamma. To set these to distinct values use the config file. */ memcpy(scheme.night.gamma, scheme.day.gamma, sizeof(scheme.night.gamma)); break; case 'h': print_help(argv[0]); exit(EXIT_SUCCESS); break; case 'l': /* Print list of providers if argument is `list' */ if (strcasecmp(optarg, "list") == 0) { print_provider_list(); exit(EXIT_SUCCESS); } char *provider_name = NULL; /* Don't save the result of strtof(); we simply want to know if optarg can be parsed as a float. */ errno = 0; char *end; strtof(optarg, &end); if (errno == 0 && *end == ':') { /* Use instead as arguments to `manual'. */ provider_name = "manual"; provider_args = optarg; } else { /* Split off provider arguments. */ s = strchr(optarg, ':'); if (s != NULL) { *(s++) = '\0'; provider_args = s; } provider_name = optarg; } /* Lookup provider from name. */ provider = find_location_provider(provider_name); if (provider == NULL) { fprintf(stderr, _("Unknown location provider" " `%s'.\n"), provider_name); exit(EXIT_FAILURE); } /* Print provider help if arg is `help'. */ if (provider_args != NULL && strcasecmp(provider_args, "help") == 0) { provider->print_help(stdout); exit(EXIT_SUCCESS); } break; case 'm': /* Print list of methods if argument is `list' */ if (strcasecmp(optarg, "list") == 0) { print_method_list(); exit(EXIT_SUCCESS); } /* Split off method arguments. */ s = strchr(optarg, ':'); if (s != NULL) { *(s++) = '\0'; method_args = s; } /* Find adjustment method by name. */ method = find_gamma_method(optarg); if (method == NULL) { /* TRANSLATORS: This refers to the method used to adjust colors e.g VidMode */ fprintf(stderr, _("Unknown adjustment method" " `%s'.\n"), optarg); exit(EXIT_FAILURE); } /* Print method help if arg is `help'. */ if (method_args != NULL && strcasecmp(method_args, "help") == 0) { method->print_help(stdout); exit(EXIT_SUCCESS); } break; case 'o': mode = PROGRAM_MODE_ONE_SHOT; break; case 'O': mode = PROGRAM_MODE_MANUAL; temp_set = atoi(optarg); break; case 'p': mode = PROGRAM_MODE_PRINT; break; case 'r': transition = 0; break; case 't': s = strchr(optarg, ':'); if (s == NULL) { fputs(_("Malformed temperature argument.\n"), stderr); fputs(_("Try `-h' for more information.\n"), stderr); exit(EXIT_FAILURE); } *(s++) = '\0'; scheme.day.temperature = atoi(optarg); scheme.night.temperature = atoi(s); break; case 'v': verbose = 1; break; case 'V': printf("%s\n", PACKAGE_STRING); exit(EXIT_SUCCESS); break; case 'x': mode = PROGRAM_MODE_RESET; break; case '?': fputs(_("Try `-h' for more information.\n"), stderr); exit(EXIT_FAILURE); break; } } /* Load settings from config file. */ config_ini_state_t config_state; r = config_ini_init(&config_state, config_filepath); if (r < 0) { fputs("Unable to load config file.\n", stderr); exit(EXIT_FAILURE); } free(config_filepath); /* Read global config settings. */ config_ini_section_t *section = config_ini_get_section(&config_state, "redshift"); if (section != NULL) { config_ini_setting_t *setting = section->settings; while (setting != NULL) { if (strcasecmp(setting->name, "temp-day") == 0) { if (scheme.day.temperature < 0) { scheme.day.temperature = atoi(setting->value); } } else if (strcasecmp(setting->name, "temp-night") == 0) { if (scheme.night.temperature < 0) { scheme.night.temperature = atoi(setting->value); } } else if (strcasecmp(setting->name, "transition") == 0) { if (transition < 0) { transition = !!atoi(setting->value); } } else if (strcasecmp(setting->name, "brightness") == 0) { if (isnan(scheme.day.brightness)) { scheme.day.brightness = atof(setting->value); } if (isnan(scheme.night.brightness)) { scheme.night.brightness = atof(setting->value); } } else if (strcasecmp(setting->name, "brightness-day") == 0) { if (isnan(scheme.day.brightness)) { scheme.day.brightness = atof(setting->value); } } else if (strcasecmp(setting->name, "brightness-night") == 0) { if (isnan(scheme.night.brightness)) { scheme.night.brightness = atof(setting->value); } } else if (strcasecmp(setting->name, "elevation-high") == 0) { scheme.high = atof(setting->value); } else if (strcasecmp(setting->name, "elevation-low") == 0) { scheme.low = atof(setting->value); } else if (strcasecmp(setting->name, "gamma") == 0) { if (isnan(scheme.day.gamma[0])) { r = parse_gamma_string(setting->value, scheme.day.gamma); if (r < 0) { fputs(_("Malformed gamma" " setting.\n"), stderr); exit(EXIT_FAILURE); } memcpy(scheme.night.gamma, scheme.day.gamma, sizeof(scheme.night.gamma)); } } else if (strcasecmp(setting->name, "gamma-day") == 0) { if (isnan(scheme.day.gamma[0])) { r = parse_gamma_string(setting->value, scheme.day.gamma); if (r < 0) { fputs(_("Malformed gamma" " setting.\n"), stderr); exit(EXIT_FAILURE); } } } else if (strcasecmp(setting->name, "gamma-night") == 0) { if (isnan(scheme.night.gamma[0])) { r = parse_gamma_string(setting->value, scheme.night.gamma); if (r < 0) { fputs(_("Malformed gamma" " setting.\n"), stderr); exit(EXIT_FAILURE); } } } else if (strcasecmp(setting->name, "adjustment-method") == 0) { if (method == NULL) { method = find_gamma_method( setting->value); if (method == NULL) { fprintf(stderr, _("Unknown" " adjustment" " method" " `%s'.\n"), setting->value); exit(EXIT_FAILURE); } } } else if (strcasecmp(setting->name, "location-provider") == 0) { if (provider == NULL) { provider = find_location_provider( setting->value); if (provider == NULL) { fprintf(stderr, _("Unknown" " location" " provider" " `%s'.\n"), setting->value); exit(EXIT_FAILURE); } } } else { fprintf(stderr, _("Unknown configuration" " setting `%s'.\n"), setting->name); } setting = setting->next; } } /* Use default values for settings that were neither defined in the config file nor on the command line. */ if (scheme.day.temperature < 0) { scheme.day.temperature = DEFAULT_DAY_TEMP; } if (scheme.night.temperature < 0) { scheme.night.temperature = DEFAULT_NIGHT_TEMP; } if (isnan(scheme.day.brightness)) { scheme.day.brightness = DEFAULT_BRIGHTNESS; } if (isnan(scheme.night.brightness)) { scheme.night.brightness = DEFAULT_BRIGHTNESS; } if (isnan(scheme.day.gamma[0])) { scheme.day.gamma[0] = DEFAULT_GAMMA; scheme.day.gamma[1] = DEFAULT_GAMMA; scheme.day.gamma[2] = DEFAULT_GAMMA; } if (isnan(scheme.night.gamma[0])) { scheme.night.gamma[0] = DEFAULT_GAMMA; scheme.night.gamma[1] = DEFAULT_GAMMA; scheme.night.gamma[2] = DEFAULT_GAMMA; } if (transition < 0) transition = 1; location_t loc = { NAN, NAN }; /* Initialize location provider. If provider is NULL try all providers until one that works is found. */ location_state_t location_state; /* Location is not needed for reset mode and manual mode. */ if (mode != PROGRAM_MODE_RESET && mode != PROGRAM_MODE_MANUAL) { if (provider != NULL) { /* Use provider specified on command line. */ r = provider_try_start(provider, &location_state, &config_state, provider_args); if (r < 0) exit(EXIT_FAILURE); } else { /* Try all providers, use the first that works. */ for (int i = 0; location_providers[i].name != NULL; i++) { const location_provider_t *p = &location_providers[i]; fprintf(stderr, _("Trying location provider `%s'...\n"), p->name); r = provider_try_start(p, &location_state, &config_state, NULL); if (r < 0) { fputs(_("Trying next provider...\n"), stderr); continue; } /* Found provider that works. */ printf(_("Using provider `%s'.\n"), p->name); provider = p; break; } /* Failure if no providers were successful at this point. */ if (provider == NULL) { fputs(_("No more location providers" " to try.\n"), stderr); exit(EXIT_FAILURE); } } /* Get current location. */ r = provider->get_location(&location_state, &loc); if (r < 0) { fputs(_("Unable to get location from provider.\n"), stderr); exit(EXIT_FAILURE); } provider->free(&location_state); if (verbose) { print_location(&loc); printf(_("Temperatures: %dK at day, %dK at night\n"), scheme.day.temperature, scheme.night.temperature); /* TRANSLATORS: Append degree symbols if possible. */ printf(_("Solar elevations: day above %.1f, night below %.1f\n"), scheme.high, scheme.low); } /* Latitude */ if (loc.lat < MIN_LAT || loc.lat > MAX_LAT) { /* TRANSLATORS: Append degree symbols if possible. */ fprintf(stderr, _("Latitude must be between %.1f and %.1f.\n"), MIN_LAT, MAX_LAT); exit(EXIT_FAILURE); } /* Longitude */ if (loc.lon < MIN_LON || loc.lon > MAX_LON) { /* TRANSLATORS: Append degree symbols if possible. */ fprintf(stderr, _("Longitude must be between" " %.1f and %.1f.\n"), MIN_LON, MAX_LON); exit(EXIT_FAILURE); } /* Color temperature */ if (scheme.day.temperature < MIN_TEMP || scheme.day.temperature > MAX_TEMP || scheme.night.temperature < MIN_TEMP || scheme.night.temperature > MAX_TEMP) { fprintf(stderr, _("Temperature must be between %uK and %uK.\n"), MIN_TEMP, MAX_TEMP); exit(EXIT_FAILURE); } /* Solar elevations */ if (scheme.high < scheme.low) { fprintf(stderr, _("High transition elevation cannot be lower than" " the low transition elevation.\n")); exit(EXIT_FAILURE); } } if (mode == PROGRAM_MODE_MANUAL) { /* Check color temperature to be set */ if (temp_set < MIN_TEMP || temp_set > MAX_TEMP) { fprintf(stderr, _("Temperature must be between %uK and %uK.\n"), MIN_TEMP, MAX_TEMP); exit(EXIT_FAILURE); } } /* Brightness */ if (scheme.day.brightness < MIN_BRIGHTNESS || scheme.day.brightness > MAX_BRIGHTNESS || scheme.night.brightness < MIN_BRIGHTNESS || scheme.night.brightness > MAX_BRIGHTNESS) { fprintf(stderr, _("Brightness values must be between %.1f and %.1f.\n"), MIN_BRIGHTNESS, MAX_BRIGHTNESS); exit(EXIT_FAILURE); } if (verbose) { printf(_("Brightness: %.2f:%.2f\n"), scheme.day.brightness, scheme.night.brightness); } /* Gamma */ if (!gamma_is_valid(scheme.day.gamma) || !gamma_is_valid(scheme.night.gamma)) { fprintf(stderr, _("Gamma value must be between %.1f and %.1f.\n"), MIN_GAMMA, MAX_GAMMA); exit(EXIT_FAILURE); } if (verbose) { /* TRANSLATORS: The string in parenthesis is either Daytime or Night (translated). */ printf(_("Gamma (%s): %.3f, %.3f, %.3f\n"), _("Daytime"), scheme.day.gamma[0], scheme.day.gamma[1], scheme.day.gamma[2]); printf(_("Gamma (%s): %.3f, %.3f, %.3f\n"), _("Night"), scheme.night.gamma[0], scheme.night.gamma[1], scheme.night.gamma[2]); } /* Initialize gamma adjustment method. If method is NULL try all methods until one that works is found. */ gamma_state_t state; /* Gamma adjustment not needed for print mode */ if (mode != PROGRAM_MODE_PRINT) { if (method != NULL) { /* Use method specified on command line. */ r = method_try_start(method, &state, &config_state, method_args); if (r < 0) exit(EXIT_FAILURE); } else { /* Try all methods, use the first that works. */ for (int i = 0; gamma_methods[i].name != NULL; i++) { const gamma_method_t *m = &gamma_methods[i]; if (!m->autostart) continue; r = method_try_start(m, &state, &config_state, NULL); if (r < 0) { fputs(_("Trying next method...\n"), stderr); continue; } /* Found method that works. */ printf(_("Using method `%s'.\n"), m->name); method = m; break; } /* Failure if no methods were successful at this point. */ if (method == NULL) { fputs(_("No more methods to try.\n"), stderr); exit(EXIT_FAILURE); } } } config_ini_free(&config_state); switch (mode) { case PROGRAM_MODE_ONE_SHOT: case PROGRAM_MODE_PRINT: { /* Current angular elevation of the sun */ double now; r = systemtime_get_time(&now); if (r < 0) { fputs(_("Unable to read system time.\n"), stderr); method->free(&state); exit(EXIT_FAILURE); } double elevation = solar_elevation(now, loc.lat, loc.lon); if (verbose) { /* TRANSLATORS: Append degree symbol if possible. */ printf(_("Solar elevation: %f\n"), elevation); } /* Use elevation of sun to set color temperature */ color_setting_t interp; interpolate_color_settings(&scheme, elevation, &interp); if (verbose || mode == PROGRAM_MODE_PRINT) { period_t period = get_period(&scheme, elevation); double transition = get_transition_progress(&scheme, elevation); print_period(period, transition); printf(_("Color temperature: %uK\n"), interp.temperature); printf(_("Brightness: %.2f\n"), interp.brightness); } if (mode == PROGRAM_MODE_PRINT) { exit(EXIT_SUCCESS); } /* Adjust temperature */ r = method->set_temperature(&state, &interp); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); exit(EXIT_FAILURE); } /* In Quartz (OSX) the gamma adjustments will automatically revert when the process exits. Therefore, we have to loop until CTRL-C is received. */ if (strcmp(method->name, "quartz") == 0) { fputs(_("Press ctrl-c to stop...\n"), stderr); pause(); } } break; case PROGRAM_MODE_MANUAL: { if (verbose) printf(_("Color temperature: %uK\n"), temp_set); /* Adjust temperature */ color_setting_t manual; memcpy(&manual, &scheme.day, sizeof(color_setting_t)); manual.temperature = temp_set; r = method->set_temperature(&state, &manual); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); exit(EXIT_FAILURE); } /* In Quartz (OSX) the gamma adjustments will automatically revert when the process exits. Therefore, we have to loop until CTRL-C is received. */ if (strcmp(method->name, "quartz") == 0) { fputs(_("Press ctrl-c to stop...\n"), stderr); pause(); } } break; case PROGRAM_MODE_RESET: { /* Reset screen */ color_setting_t reset = { NEUTRAL_TEMP, { 1.0, 1.0, 1.0 }, 1.0 }; r = method->set_temperature(&state, &reset); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); exit(EXIT_FAILURE); } /* In Quartz (OSX) the gamma adjustments will automatically revert when the process exits. Therefore, we have to loop until CTRL-C is received. */ if (strcmp(method->name, "quartz") == 0) { fputs(_("Press ctrl-c to stop...\n"), stderr); pause(); } } break; case PROGRAM_MODE_CONTINUAL: { r = run_continual_mode(&loc, &scheme, method, &state, transition, verbose); if (r < 0) exit(EXIT_FAILURE); } break; } /* Clean up gamma adjustment state */ method->free(&state); return EXIT_SUCCESS; }
void node(const osmium::Node& node) { print_title("NODE", node); print_meta(node); print_location(node); }
void os::print_register_info(outputStream *st, void *context) { if (context == NULL) return; ucontext_t *uc = (ucontext_t*)context; st->print_cr("Register to memory mapping:"); st->cr(); // this is horrendously verbose but the layout of the registers in the // context does not match how we defined our abstract Register set, so // we can't just iterate through the gregs area // this is only for the "general purpose" registers #ifdef BUILTIN_SIM st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]); st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]); st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]); st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]); st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]); st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]); st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]); st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]); st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]); st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]); st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]); st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]); st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]); st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]); st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]); st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]); #else for (int r = 0; r < 31; r++) st->print_cr( "R%d=" INTPTR_FORMAT, r, (int64_t)uc->uc_mcontext.regs[r]); #endif st->cr(); }
//Some thoughts: we don't need all these character classes //Some other thoughts: Understand how scan works in the //context of the entire program. void scan(location_t * loc, token_t * tok) { //an enumeration of the different possible states //also initializes "state" to "start," which is 0 enum { start, got_space, got_nl_space, got_other, done, /* numbers: */ got_dot, got_dec, got_fp_dot, /* operators: */ got_plus, got_minus, got_star, got_slash, got_pct, got_lparen, got_incr, got_decr, got_incr2, got_decr2, got_caret, got_bang } state = start; /* Standard way to recognize a token: put back lookahead character that isn't part of current token: */ #define ACCEPT_REUSE(t) \ *loc = loc_save; \ tok->length--; \ tok->tc = t; \ state = done; #define ACCEPT_SHIFT(t, i) \ move_location_back(loc, i); \ tok->length = tok->length - i; \ tok->tc = t; \ state = done; /* Shortcut to eliminate final states with no out transitions: go ahead and accept token in previous state, but don't put back the lookahead: it's actually part of the token: */ #define ACCEPT(t) \ tok->tc = t; \ state = done; //NOTE: the following code is NOT part of the ACCEPT(t) tok->location = *loc; tok->length = 0; while (state != done) { //Points to loc -- but if we update loc, we update loc_save location_t loc_save = *loc; //Gets the character, but also updates loc by incrementing it int c = get_character(loc); //I guess... we might be adding this character to the token? tok->length++; //WAIT A SECOND -- THIS WHOLE SWITCH-CASE IS A DFA. :O switch (state) { //If we're in the start state... case start: //... find out which character class the character is in switch (char_classes[c]) { case WHITE: state = got_space; break; case EOLN: state = got_nl_space; break; case DOT: state = got_dot; break; case DIG: state = got_dec; break; case PLUS: state = got_plus; break; case MINUS: state = got_minus; break; case STAR: state = got_star; break; case PCT: state = got_pct; break; case SLASH: state = got_slash; break; case CARET: state = got_caret; break; case BANG: state = got_bang; break; case LPAREN: state = got_lparen; break; case RPAREN: tok->terminal = t_RPAREN; ACCEPT(T_RPAREN); break; case SEMIC: tok->terminal = t_SEMIC; ACCEPT(T_SEMIC); break; case END: ACCEPT_REUSE(T_EOF); break; case OTHER: /* This will be an error. Eat as many bogus characters as possible. */ state = got_other; break; default: state = got_other; break; } break; case got_space: switch (char_classes[c]) { case WHITE: break; /* stay put */ case EOLN: state = got_nl_space; break; default: ACCEPT_REUSE(T_SPACE); break; } break; case got_nl_space: switch (char_classes[c]) { case WHITE: case EOLN: break; /* stay put */ default: ACCEPT_REUSE(T_NL_SPACE); break; } break; case got_other: switch (char_classes[c]) { case OTHER: case WHITE: case EOLN: break; /* stay put */ default: fprintf(stderr, "Invalid token"); print_location(tok); ACCEPT_REUSE(T_SPACE); /* most likely recovery? */ break; } break; //This, theoretically, should be unreachable -- state would have to change //outside of a switch statement, which, by current design is, dare I say, //impossible. But, this being a computer program prone to bugs, let's just //say "improbable." case done: fprintf(stderr, "scan: unexpected done in switch\n"); exit(-1); break; /* operators: */ //What about positive and negative? We want the scanner //to parse the positive and negative signs for me case got_plus: tok->terminal = t_PLUS; ACCEPT_REUSE(T_OPERATOR); // + break; case got_minus: tok->terminal = t_MINUS; ACCEPT_REUSE(T_OPERATOR); // - break; case got_star: tok->terminal = t_STAR; ACCEPT_REUSE(T_OPERATOR); // * break; case got_slash: tok->terminal = t_SLASH; ACCEPT_REUSE(T_OPERATOR); // / break; case got_pct: tok->terminal = t_PCT; ACCEPT_REUSE(T_OPERATOR); // % break; case got_caret: tok->terminal = t_CARET; ACCEPT_REUSE(T_OPERATOR); break; case got_bang: tok->terminal = t_BANG; ACCEPT_REUSE(T_OPERATOR); break; case got_lparen: switch(char_classes[c]){ case PLUS: state = got_incr; break; case MINUS: state = got_decr; break; default: tok->terminal = t_LPAREN; ACCEPT_REUSE(T_LPAREN); break; } break; case got_incr: switch(char_classes[c]){ case PLUS: state = got_incr2; break; case RPAREN: tok->terminal = t_PLUS_UNARY; ACCEPT(T_UNARY); break; default: tok->terminal = t_LPAREN; ACCEPT_SHIFT(T_LPAREN, 2); break; } break; case got_decr: switch(char_classes[c]){ case MINUS: state = got_decr2; break; case RPAREN: tok->terminal = t_MINUS_UNARY; ACCEPT(T_UNARY); break; default: tok->terminal = t_LPAREN; ACCEPT_SHIFT(T_LPAREN, 2); break; } break; case got_incr2: switch(char_classes[c]){ case RPAREN: tok->terminal = t_INCREMENT; ACCEPT(T_INCREMENT); break; default: tok->terminal = t_LPAREN; ACCEPT_SHIFT(T_LPAREN, 3); break; } break; case got_decr2: switch(char_classes[c]){ case RPAREN: tok->terminal = t_DECREMENT; ACCEPT(T_INCREMENT); break; default: tok->terminal = t_LPAREN; ACCEPT_SHIFT(T_LPAREN, 3); break; } break; /* numeric literals: */ //We assume that a dot means that it's a decimal case got_dot: state = got_fp_dot; break; case got_dec: switch (char_classes[c]) { case DIG: break; /* stay put */ case DOT: state = got_fp_dot; break; /*case LET_E: state = starting_exp; break;*/ default: tok->terminal = t_LITERAL; ACCEPT_REUSE(T_LITERAL); /* decimal integer */ break; } break; case got_fp_dot: switch (char_classes[c]) { case DIG: break; /* stay put */ default: tok->terminal = t_LITERAL; ACCEPT_REUSE(T_LITERAL); /* fp */ break; } break; } } }