void check_case(FILE *in) { int params[MAX_M]; int n, m; int i, j; read_int(in, 2, params); n = params[0]; m = params[1]; check_int_range(n, 1, MAX_N, "n"); check_int_range(m, 1, MAX_M, "m"); check_EOL(in); char appeared[MAX_N+1]; for (j = 1; j <= n; j++) { appeared[j] = 0; } for (i = 0; i < m; i++) { int p, s; read_int(in, 2, params); p = params[0]; s = params[1]; check_int_range(p, 1, MAX_P, "p"); check_int_range(s, 1, n, "s"); match_char(in, ' '); read_int(in, s, params); char used[MAX_N+1]; for (j = 1; j <= n; j++) { used[j] = 0; } for (j = 0; j < s; j++) { check_int_range(params[j], 1, n, "si"); if (used[params[j]]) { fprintf(stderr, "Case %d: bundle %d has duplicate items\n", get_case(), i+1); exit(1); } used[params[j]] = 1; appeared[params[j]] = 1; } check_EOL(in); } for (j = 1; j <= n; j++) { if (!appeared[j]) { fprintf(stderr, "Case %d: item %d does not appear in any bundle.\n", get_case(), j); exit(1); } } }
static RGBcolour parse_RGB(void) { RGBcolour colour; start_parsing_value(); match_symbol_in_value('('); colour.red = parse_integer_in_value(); match_symbol_in_value(','); colour.green = parse_integer_in_value(); match_symbol_in_value(','); colour.blue = parse_integer_in_value(); match_symbol_in_value(')'); check_int_range("red component of colour", colour.red, 0, 255); check_int_range("green component of colour", colour.green, 0, 255); check_int_range("blue component of colour", colour.blue, 0, 255); stop_parsing_value(); return(colour); }
void put_prepare_int(const json_t *elem, uint32 *output, const int8 *name) { uint32 value; json_t *obj = NULL; obj = json_object_get(elem, name); if (obj != NULL) { value = json_integer_value(obj); if (TRUE == check_int_range(value, 0, FAN_THRESH_MAX)) *output = value; } }
void check_file(FILE *in) { int T; int i; init_checklib(); read_int(in, 1, &T); check_int_range(T, 1, MAX_T, "T"); check_EOL(in); for (i = 0; i < T; i++) { check_case(in); } check_EOF(in); }
int main (int argc, char * argv []) { PARAMS params = { 1.0, -1, -1, 0, 0, 0, NULL } ; const char * filename ; int k ; if (argc < 4) usage_exit (argv [0]) ; for (k = 1 ; k < argc - 3 ; k++) { if (strcmp (argv [k], "-from") == 0) { k++ ; params.start_freq = parse_double_or_die (argv [k], "from frequency") ; continue ; } ; if (strcmp (argv [k], "-to") == 0) { k++ ; params.end_freq = parse_double_or_die (argv [k], "to frequency") ; continue ; } ; if (strcmp (argv [k], "-amp") == 0) { k++ ; params.amplitude = strtod (argv [k], NULL) ; continue ; } ; if (argv [k][0] == '-') { params.sweep_func = parse_sweep_type (argv [k]) ; continue ; } ; printf ("\nUnknow option '%s'.\n\n", argv [k]) ; exit (1) ; } ; params.samplerate = parse_int_or_die (argv [argc - 3], "sample rate") ; params.seconds = parse_double_or_die (argv [argc - 2], "seconds") ; filename = argv [argc - 1] ; check_int_range ("sample rate", params.samplerate, 1000, 200 * 1000) ; check_double_range ("seconds", params.seconds, 0.1, 100.0) ; if (params.sweep_func == NULL) params.sweep_func = parse_sweep_type ("-log") ; if (params.start_freq <= 0.0) params.start_freq = 100.0 ; if (params.end_freq <= 0.0) params.end_freq = params.samplerate / 2.0 - 100.0 ; if (params.end_freq <= params.start_freq) { printf ("\nError : end frequency %g < start frequency %g.\n\n", params.end_freq, params.start_freq) ; exit (1) ; } ; params.format = guess_major_format (filename) | SF_FORMAT_FLOAT ; generate_file (filename, ¶ms) ; return 0 ; } /* main */
int ss_conf_getint(const ss_conf_data_t *conf, const char *name, int *value, const char *comment, const int *default_value) { if (NULL == conf || NULL == name || NULL == value) { return SS_CONF_NULL; } if (conf->build != SS_CONF_READCONF) { if (write_comment(conf->conf_file, comment) != SS_CONF_SUCCESS) { if (default_value != NULL) { fprintf(conf->conf_file, "#[default configure[int], %s : %d]\n%s : %d", name, *default_value, name, *default_value); return SS_CONF_DEFAULT; } else { fprintf(conf->conf_file, "%s : ", name); } return SS_CONF_SUCCESS; } return SS_CONF_NULL; } *value = 0; char conf_value_str[WORD_SIZE]; int ret; ret = load_str(conf, name, conf_value_str, sizeof(conf_value_str)); if (SS_CONF_LOST == ret) { if (default_value != NULL) { *value = *default_value; SS_LOG_WARNING("int [%s] no found, use default value [%d]", name, *default_value); return SS_CONF_DEFAULT; } return SS_CONF_LOST; } if (is_blank_str(conf_value_str, sizeof(conf_value_str))) { SS_LOG_WARNING("int [%s] is empty", name); return SS_CONF_CHECKFAIL; } long num; char *endptr; errno = 0; num = strtol(conf_value_str, &endptr, 10); if (errno == ERANGE || num < INT_MIN || num > INT_MAX) { SS_LOG_WARNING("int [%s] load error, [%s] overflow", name, conf_value_str); return SS_CONF_OVERFLOW; } if (!is_blank_str(endptr, sizeof(conf_value_str))) { SS_LOG_WARNING("int [%s] load error, [%s] is invalid", name, conf_value_str); return SS_CONF_CHECKFAIL; } if (check_int_range(conf, name, num) != SS_CONF_CHECKSUCCESS) { return SS_CONF_OVERFLOW; } *value = (int)num; SS_LOG_TRACE("get int value [%s : %d]", name, *value); return SS_CONF_SUCCESS; }