s32 build_deps (dictionary *dict, s32 A, s32 B, char *refstr, ocrMappable_t ***all_instances, ocrParamList_t ***inst_params) {
    s32 i, j, k;
    s32 low, high;
    s32 l, h;

    for (i = 0; i < iniparser_getnsec(dict); i++) {
        // Go thru the secnames looking for instances of A
        if (strncasecmp(inst_str[A], iniparser_getsecname(dict, i), strlen(inst_str[A]))==0) {
            // For each secname, look up corresponding instance of A through id
            read_range(dict, iniparser_getsecname(dict, i), "id", &low, &high);
            for (j = low; j <= high; j++) {
                // Parse corresponding dependences from secname
                read_range(dict, iniparser_getsecname(dict, i), refstr, &l, &h);
                // Connect A with B
                // Using a rough heuristic for now: if |from| == |to| then 1:1, else all:all TODO: What else makes sense here?
                if (h-l == high-low) {
                    k = l+j-low;
                    add_dependence(A, B, all_instances[A][j], inst_params[A][j], all_instances[B][k], inst_params[B][k], 0, 1);
                } else {
                    for (k = l; k <= h; k++) {
                        add_dependence(A, B, all_instances[A][j], inst_params[A][j], all_instances[B][k], inst_params[B][k], k-l, h-l+1);
                    }
                }
            }
        }
    }
    return 0;
}
Example #2
0
char *read_time_entry (char *buf, struct time_entry *res)
{
  char raw_dow[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  char *p = skip_irrelevant(buf);
  char *keyword;
  unsigned long len;
  int fulldom, fulldow;

  if (eoln(p)) return NULL;
  *res = EMPTY_TIME_ENTRY;
  if (*p == '@') {
    p++;
    keyword = p;
    while (*p && isalpha(*p)) p++;
    len = p - keyword;
    if      (!strncmp(keyword, "reboot",   len)) /* ignore, keep empty time_entry */ ;
    else if (!strncmp(keyword, "yearly",   len)) read_time_entry("0 0 1 1 *", res);
    else if (!strncmp(keyword, "annually", len)) read_time_entry("0 0 1 1 *", res);
    else if (!strncmp(keyword, "monthly",  len)) read_time_entry("0 0 1 * *", res);
    else if (!strncmp(keyword, "weekly",   len)) read_time_entry("0 0 * * 0", res);
    else if (!strncmp(keyword, "daily",    len)) read_time_entry("0 0 * * *", res);
    else if (!strncmp(keyword, "midnight", len)) read_time_entry("0 0 * * *", res);
    else if (!strncmp(keyword, "hourly",   len)) read_time_entry("0 * * * *", res);
    else /* invalid */
      return NULL;
    return p;
  }
  /* minutes */
  p = read_range(p, 0, 59, 0, NULL, NULL, res->m);
  if (!p) return NULL;
  /* hours */
  p = read_range(p, 0, 23, 0, NULL, NULL, res->h);
  if (!p) return NULL;
  /* dom */
  p = read_range(p, 1, 31, 1, NULL, NULL, res->dom);
  if (!p) return NULL;
  /* month */
  p = read_range(p, 1, 12, 1, get_month, get_month, res->mon);
  if (!p) return NULL;
  /* dow */
  p = read_range(p, 0, 7, 0, get_dow_1, get_dow_2, raw_dow);
  if (!p) return NULL;

  if (raw_dow[7]) raw_dow[0] = 1;
  memcpy(res->dow, raw_dow, 7);

  fulldom = all_full(res->dom, 31);
  fulldow = all_full(res->dow, 7);

  if      (fulldom && !fulldow) res->ignore = IGNORE_DOM;
  else if (fulldow && !fulldom) res->ignore = IGNORE_DOW;
  else res->ignore = IGNORE_NOTHING;

  return p;
}
Example #3
0
bool number(char **stream, int *result)
{
  int nbr;

  nbr = atoi(*stream);
  if (read_range(stream, '0', '9'))
    {
      *result = nbr;
      while (read_range(stream, '0', '9'));
      return (true);
    }
  return (false);
}
s32 get_key_value(dictionary *dict, char *sec, char *field, s32 offset) {
    char key[MAX_KEY_SZ];
    s32 lo, hi;
    s32 retval;
    static value_type key_value_type = TYPE_UNKNOWN;

    snprintf(key, MAX_KEY_SZ, "%s:%s", sec, field);
    if (key_value_type == TYPE_UNKNOWN) {
        if (INI_IS_CSV(key)) {
            key_value_type = TYPE_CSV;
        } else if (INI_IS_RANGE(key)) {
            key_value_type = TYPE_RANGE;
        } else {
            key_value_type = TYPE_INT; // Big assumption, could break
        }
    }

    if (key_value_type == TYPE_CSV) {
        retval = read_next_csv_value(dict, key);
        if (retval == -1) key_value_type = TYPE_UNKNOWN;        
    } else {
        read_range(dict, sec, field, &lo, &hi);
        retval = lo+offset;
        key_value_type = TYPE_UNKNOWN;        
    }

    return retval;
}
/* Read the range p0,p1 and checkpoint p from SoBStatus.dat.
   If no file exists or p0 != pmin or p1 != pmax, return pmin.
   If no checkpoint line exists, return pmax.
   If the range is complete, return pmax.
   Otherwise return p.
*/
uint64_t sob_read_checkpoint(uint64_t pmin, uint64_t pmax)
{
  FILE *file;
  const char *line;
  uint64_t p0, p1, p;

  p = pmin;
  if ((file = xfopen(sob_status_file_name,"r",NULL)) != NULL)
  {
    if (read_range(&p0,&p1,file,sob_status_file_name))
      if (p0 == pmin && p1 == pmax)
      {
        while ((line = read_line(file)) != NULL)
          if (sscanf(line,"pmin=%"SCNu64,&p) != 1)
            break;

        if (p < pmin || p > pmax)
          line_error("Invalid checkpoint",NULL,sob_status_file_name);

        if (line != NULL && !strncmp("Done",line,4))
          p = pmax;

        if (p > pmin && p < pmax)
          report(1,"Resuming from checkpoint pmin=%"PRIu64" in `%s'.",
                 p,sob_status_file_name);
      }
    xfclose(file,sob_status_file_name);
  }

  last_checkpoint_time = millisec_elapsed_time();
  last_checkpoint_prime = p;

  return p;
}
Example #6
0
bool update_forcefield(FILE *fplog,
                       int nfile,t_filenm fnm[],t_forcerec *fr,
                       int natoms,rvec x[],matrix box)
{
    static int ntry,ntried;
    int    i,j;
    bool   bDone;

    /* First time around we have to read the parameters */
    if (nparm == 0) {
        range = read_range(ftp2fn(efDAT,nfile,fnm),&nparm);
        if (nparm == 0)
            gmx_fatal(FARGS,"No correct parameter info in %s",ftp2fn(efDAT,nfile,fnm));
        snew(param_val,nparm);

        if (opt2bSet("-ga",nfile,fnm)) {
            /* Genetic algorithm time */
            ga = init_ga(fplog,opt2fn("-ga",nfile,fnm),nparm,range);
        }
        else {
            /* Determine the grid size */
            ntry = 1;
            for(i=0; (i<nparm); i++)
                ntry *= range[i].np;
            ntried = 0;

            fprintf(fplog,"Going to try %d different combinations of %d parameters\n",
                    ntry,nparm);
        }
    }
    if (ga) {
        update_ga(fplog,range,ga);
    }
    else {
        /* Increment the counter
         * Non-trivial, since this is nparm nested loops in principle
         */
        for(i=0; (i<nparm); i++) {
            if (param_val[i] < (range[i].np-1)) {
                param_val[i]++;
                for(j=0; (j<i); j++)
                    param_val[j] = 0;
                ntried++;
                break;
            }
        }
        if (i == nparm) {
            fprintf(fplog,"Finished with %d out of %d iterations\n",ntried+1,ntry);
            return TRUE;
        }
    }

    /* Now do the real updating */
    update_ff(fr,nparm,range,param_val);

    /* Update box and coordinates if necessary */
    scale_box(natoms,x,box);

    return FALSE;
}
int sob_next_range(uint64_t *pmin, uint64_t *pmax)
{
  FILE *file;
  uint64_t p0, p1;
  int done = 0;

  if ((file = xfopen(sob_range_file_name,"r",NULL)) != NULL)
  {
    if (read_range(&p0,&p1,file,sob_range_file_name))
    {
      uint64_t R0[MAX_RANGES], R1[MAX_RANGES];
      uint32_t i, j;

      for (j = 0; j < MAX_RANGES; j++)
        if (!read_range(R0+j,R1+j,file,sob_range_file_name))
          break;

      xfclose(file,sob_range_file_name);

      if (j >= MAX_RANGES)
        error("Too many ranges (max %"PRIu32") in `%s'",j,sob_range_file_name);

      file = xfopen(sob_range_file_name,"w",error);
      for (i = 0; i < j; i++)
        write_range(R0[i],R1[i],file,sob_range_file_name);

      done = 1;
    }
    xfclose(file,sob_range_file_name);
  }

  if (done)
  {
    sob_start_range(p0,p1);
    *pmin = p0;
    *pmax = p1;

    report(1,"Starting new range pmin=%"PRIu64",pmax=%"PRIu64" from `%s'.",
           p0,p1,sob_range_file_name);
  }

  return done;
}
/* Continue a range in SoBStatus.dat
   Return 1 if successful, 0 otherwise.
 */
int sob_continue_range(uint64_t *pmin, uint64_t *pmax)
{
  FILE *file;
  int ret = 0;

  if ((file = xfopen(sob_status_file_name,"r",NULL)) != NULL)
  {
    if ((ret = read_range(pmin,pmax,file,sob_status_file_name)) != 0)
      report(1,"Continuing with range pmin=%"PRIu64",pmax=%"PRIu64" in `%s'.",
             *pmin,*pmax,sob_status_file_name);
    xfclose(file,sob_status_file_name);
  }

  return ret;
}
Example #9
0
void	ldi_op(t_proc *proc, t_op_arg args[3])
{
	t_reg	*dst_reg;
	int		offset;
	int		a;
	int		b;

	a = get_value(proc, args, 0, 0);
	b = get_value(proc, args, 1, 0);
	if (g_corewar.reg_error)
		return ;
	offset = (a + b) % IDX_MOD;
	if ((dst_reg = get_register(proc->reg, args[2].value)))
		read_range((char *)dst_reg, proc->pc + offset, REG_SIZE);
}
s32 populate_inst(ocrParamList_t **inst_param, ocrMappable_t **instance, s32 *type_counts, char ***factory_names, void ***all_factories, ocrMappable_t ***all_instances, type_enum index, dictionary *dict, char *secname) {
    s32 i, low, high, j;
    char *inststr;
    char key[MAX_KEY_SZ];
    void *factory;
    s32 value;

    read_range(dict, secname, "id", &low, &high);

    snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "type");
    INI_GET_STR (key, inststr, "");

    for (i = 0; i < type_counts[index]; i++) {
        if (factory_names[index][i] && (0 == strncmp(factory_names[index][i], inststr, strlen(factory_names[index][i])))) break;
    }
    if (factory_names[index][i] == NULL || strncmp(factory_names[index][i], inststr, strlen(factory_names[index][i]))) {
        DPRINTF(DEBUG_LVL_WARN, "Unknown type %s\n", inststr);
        return 0;
    }

    // find factory based on i
    factory = all_factories[index][i];

    // Use the factory's instantiate() to create instance

    switch (index) {
    case guid_type:
        for (j = low; j<=high; j++) {
            ALLOC_PARAM_LIST(inst_param[j], paramListGuidProviderInst_t);
            instance[j] = (ocrMappable_t *)((ocrGuidProviderFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created guid provider of type %s, index %d\n", inststr, j);
        }
        break;
    case memplatform_type:
        for (j = low; j<=high; j++) {
            ALLOC_PARAM_LIST(inst_param[j], paramListMemPlatformInst_t);
            instance[j] = (ocrMappable_t *)((ocrMemPlatformFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created memplatform of type %s, index %d\n", inststr, j);
        }
        break;
    case memtarget_type:
        for (j = low; j<=high; j++) {
            ALLOC_PARAM_LIST(inst_param[j], paramListMemTargetInst_t);
            instance[j] = (ocrMappable_t *)((ocrMemTargetFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created memtarget of type %s, index %d\n", inststr, j);
        }
        break;
    case allocator_type:
        for (j = low; j<=high; j++) {
            ALLOC_PARAM_LIST(inst_param[j], paramListAllocatorInst_t);
            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "size");
            INI_GET_INT (key, value, -1);
            ((paramListAllocatorInst_t *)inst_param[j])->size = value;
            instance[j] = (ocrMappable_t *)((ocrAllocatorFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created allocator of type %s, index %d\n", inststr, j);
        }
        break;
    case compplatform_type:
        for (j = low; j<=high; j++) {

            compPlatformType_t mytype = -1;
            
            TO_ENUM (mytype, inststr, compPlatformType_t, compplatform_types, compPlatformMax_id);
            switch (mytype) {
                case compPlatformPthread_id: {
                    ALLOC_PARAM_LIST(inst_param[j], paramListCompPlatformPthread_t);
                    snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "ismasterthread");
                    INI_GET_BOOL (key, value, -1);
                    ((paramListCompPlatformPthread_t *)inst_param[j])->isMasterThread = value;

                    snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "stacksize");
                    INI_GET_INT (key, value, -1);
                    ((paramListCompPlatformPthread_t *)inst_param[j])->stackSize = (value==-1)?0:value;
                  
                    if (key_exists(dict, secname, "binding")) {
                       value = get_key_value(dict, secname, "binding", j-low);
                      // printf("Binding value for %s;%d is %d\n", secname, j-low, value);
                    } // else printf("No binding for %s\n", secname);
                }
                break;
                default:
                    ALLOC_PARAM_LIST(inst_param[j], paramListCompPlatformInst_t);
                break;
            }

            instance[j] = (ocrMappable_t *)((ocrCompPlatformFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created compplatform of type %s, index %d\n", inststr, j);
        }
        break;
    case comptarget_type:
        for (j = low; j<=high; j++) {
            ALLOC_PARAM_LIST(inst_param[j], paramListCompTargetInst_t);
            instance[j] = (ocrMappable_t *)((ocrCompTargetFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created comptarget of type %s, index %d\n", inststr, j);
        }
        break;
    case workpile_type:
        for (j = low; j<=high; j++) {
            ALLOC_PARAM_LIST(inst_param[j], paramListWorkpileInst_t);
            instance[j] = (ocrMappable_t *)((ocrWorkpileFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created workpile of type %s, index %d\n", inststr, j);
        }
        break;
    case worker_type:
        for (j = low; j<=high; j++) {

            workerType_t mytype = -1;
            TO_ENUM (mytype, inststr, workerType_t, worker_types, workerMax_id);
            switch (mytype) {
                case workerHc_id: {
                    ALLOC_PARAM_LIST(inst_param[j], paramListWorkerHcInst_t);
                    ((paramListWorkerHcInst_t *)inst_param[j])->workerId = j; // using "id" for now; TODO: decide if a separate key is needed
                }
                break;
                default:
                    ALLOC_PARAM_LIST(inst_param[j], paramListWorkerInst_t);
                break;
            }

            instance[j] = (ocrMappable_t *)((ocrWorkerFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created worker of type %s, index %d\n", inststr, j);
        }
        break;
    case scheduler_type:
        for (j = low; j<=high; j++) {
            schedulerType_t mytype = -1;
            TO_ENUM (mytype, inststr, schedulerType_t, scheduler_types, schedulerMax_id);
            switch (mytype) {
                case schedulerHc_id: {
                    ALLOC_PARAM_LIST(inst_param[j], paramListSchedulerHcInst_t);
                    snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "workeridfirst");
                    INI_GET_INT (key, value, -1);
                    ((paramListSchedulerHcInst_t *)inst_param[j])->workerIdFirst = value;
                }
                break;
                default:
                    ALLOC_PARAM_LIST(inst_param[j], paramListSchedulerInst_t);
                break;
            }

            instance[j] = (ocrMappable_t *)((ocrSchedulerFactory_t *)factory)->instantiate(factory, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created scheduler of type %s, index %d\n", inststr, j);
        }
        break;
    case policydomain_type:
        for (j = low; j<=high; j++) {
            ocrTaskFactory_t *tf;
            ocrTaskTemplateFactory_t *ttf;
            ocrDataBlockFactory_t *dbf;
            ocrEventFactory_t *ef;
            ocrPolicyCtxFactory_t *cf;
            ocrGuidProvider_t *gf;
            ocrLockFactory_t *lf;
            ocrAtomic64Factory_t *af;
            s32 low, high;

            s32 schedulerCount, workerCount, computeCount, workpileCount, allocatorCount, memoryCount;
            schedulerCount = read_range(dict, secname, "scheduler", &low, &high);
            workerCount = read_range(dict, secname, "worker", &low, &high);
            computeCount = read_range(dict, secname, "comptarget", &low, &high);
            workpileCount = read_range(dict, secname, "workpile", &low, &high);
            allocatorCount = read_range(dict, secname, "allocator", &low, &high);
            memoryCount = read_range(dict, secname, "memtarget", &low, &high);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "taskfactory");
            INI_GET_STR (key, inststr, "");
            tf = create_factory_task(inststr, NULL);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "tasktemplatefactory");
            INI_GET_STR (key, inststr, "");
            ttf = create_factory_tasktemplate(inststr, NULL);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "datablockfactory");
            INI_GET_STR (key, inststr, "");
            dbf = create_factory_datablock(inststr, NULL);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "eventfactory");
            INI_GET_STR (key, inststr, "");
            ef = create_factory_event(inststr, NULL);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "contextfactory");
            INI_GET_STR (key, inststr, "");
            cf = create_factory_context(inststr, NULL);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "sync");
            INI_GET_STR (key, inststr, "");
            lf = create_factory_lock(inststr, NULL);

            snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "sync");
            INI_GET_STR (key, inststr, "");
            af = create_factory_atomic64(inststr, NULL);

            // Ugly but special case
            read_range(dict, secname, "guid", &low, &high);
            ASSERT (low == high);  // We don't expect more than one guid provider
            gf = (ocrGuidProvider_t *)(all_instances[guid_type][low]);
            ASSERT (gf);

            ALLOC_PARAM_LIST(inst_param[j], paramListPolicyDomainInst_t);
            instance[j] = (ocrMappable_t *)((ocrPolicyDomainFactory_t *)factory)->instantiate(factory, schedulerCount,
                            workerCount, computeCount, workpileCount, allocatorCount, memoryCount,
                            tf, ttf, dbf, ef, cf, gf, lf, af, NULL, inst_param[j]);
            if (instance[j])
                DPRINTF(DEBUG_LVL_INFO, "Created policy domain of index %d\n", j);
            setBootPD((ocrPolicyDomain_t *)instance[j]);
        }
        break;
    default:
        DPRINTF(DEBUG_LVL_WARN, "Error: %d index unexpected\n", index);
        break;
    }
    return 0;
}
int play(int argc, char **argv) {
    int nMixer = -1, nDevice = -1;

    pcm_config cfg = {
        channels : 0,
        rate : 0,
        period_size : 1024,
        period_count : 4,
        format : PCM_FORMAT_S16_LE,
        start_threshold : 0,
        stop_threshold : 0,
        silence_threshold : 0,
    };

    if (argc == 6) {
        nMixer = atoi(argv[2]);
        nDevice = atoi(argv[3]);
        cfg.rate = atoi(argv[4]);
        cfg.channels = atoi(argv[5]);
    }

    if (argc != 6 || nMixer < 0 || nMixer > 7 || nDevice < 0 || 
            cfg.rate <= 0 || cfg.channels <= 0 || cfg.channels > 2) {
        printf("Usage: ainfo play <card number> <device number> <rate> <channels>\n"
               "where <card number> is between 0 and 7\n"
               "<device number> is the device to play on\n"
               "<rate> is the sampling rate\n"
               "<channels> is either 1 or 2\n"
               "NOTE The file to be played is read from stdin\n");
        return 0;
    }

    pcm *p = pcm_open(nMixer, nDevice, PCM_OUT, &cfg);

    if (!pcm_is_ready(p)) {
        printf("Device not ready. Probably due to invalid parameters.");
        pcm_close(p);
        return -1;
    }

    unsigned bufsize = pcm_get_buffer_size(p);
    char *data = new char[bufsize];

    if (!data) {
        printf("Could not allocate %d bytes.\n", bufsize);
        return -1;
    }

    while (read(0, data, bufsize) == bufsize) {
        printf(".");
        if (pcm_write(p, data, bufsize))
            break;
    }

    printf("\b.\nFinished.\n");
    delete [] data;
    pcm_close(p);
    return 0;
}

int main(int argc, char **argv) {
    if (argc >= 2) {
        if (!strcmp(argv[1], "list"))
            return list(argc, argv);
        else if (!strcmp(argv[1], "read"))
            return read(argc, argv);
        else if (!strcmp(argv[1], "read-range"))
            return read_range(argc, argv);
        else if (!strcmp(argv[1], "write"))
            return write(argc, argv);
        else if (!strcmp(argv[1], "write-percentage"))
            return write_percentage(argc, argv);
        else if (!strcmp(argv[1], "play"))
            return play(argc, argv);
    }

    printf("Usage: audiotest <command>\nwhere <command> is one of:\n"
           "list, read, read-range, write, write-percentage, play\n");
    return 0;
}
Example #12
0
int read_rules(const char *filename)
{
    char buf[1024];
    DCELL dLow, dHigh;
    CELL iLow, iHigh;
    int line, n, nrules = 0;
    int first = 1;
    DCELL dmin, dmax;
    CELL cmin, cmax;
    FILE *fp;

    if (strcmp(filename, "-") == 0)
        fp = stdin;
    else {
        fp = fopen(filename, "r");
        if (!fp)
            G_fatal_error(_("unable to open input file <%s>"), filename);
    }

    read_range();
    report_range();
    if (isatty(fileno(fp)))
        fprintf(stderr, _("\nEnter the rule or 'help' for the format description or 'end' to exit:\n"));
    Rast_quant_init(&quant_struct);
    for (line = 1;; line++) {
        if (isatty(fileno(fp)))
            fprintf(stderr, "> ");
        if (!G_getl2(buf, sizeof(buf), fp))
            break;
        for (n = 0; buf[n]; n++)
            if (buf[n] == ',')
                buf[n] = ' ';
        G_strip(buf);
        G_chop(buf);
        if (*buf == 0)
            continue;
        if (*buf == '#')
            continue;
        if (strcmp(buf, "end") == 0) {
            if (nrules == 0)
                break;		/* if no new rules have been specified */

            /* give warning when quant rules do not cover the whole range of map */
            Rast_quant_get_limits(&quant_struct, &dmin, &dmax, &cmin, &cmax);
            if ((dmin > old_dmin || dmax < old_dmax) && !first)
                G_warning(_("quant rules do not cover the whole range map"));
            break;
        }

        if (strcmp(buf, "help") == 0) {
            fprintf(stderr,
                    "Enter a rule in one of these formats:\n"
                    "float_low:float_high:int_low:int_high\n"
                    "float_low:float_high:int_val  (i.e. int_high == int_low)\n"
                    "*:float_val:int_val           (interval [inf, float_val])\n"
                    "float_val:*:int_val           (interval [float_val, inf])\n");
        }

        /* we read and record into quant table all values, even int as doubles
           we convert the range and domain values to the right format when we
           lookup the values in the quant table */
        switch (sscanf(buf, "%lf:%lf:%d:%d", &dLow, &dHigh, &iLow, &iHigh)) {
        case 3:
            Rast_quant_add_rule(&quant_struct, dLow, dHigh, iLow, iLow);
            nrules++;
            first = 0;
            break;

        case 4:
            Rast_quant_add_rule(&quant_struct, dLow, dHigh, iLow, iHigh);
            nrules++;
            first = 0;
            break;

        default:
            if (sscanf(buf, "%lf:*:%d", &dLow, &iLow) == 2) {
                Rast_quant_set_pos_infinite_rule(&quant_struct, dLow, iLow);
                nrules++;
                first = 0;
            }

            else if (sscanf(buf, "*:%lf:%d", &dHigh, &iLow) == 2) {
                Rast_quant_set_neg_infinite_rule(&quant_struct, dHigh, iLow);
                nrules++;
                first = 0;
            }

            else if (strcmp(buf, "help") == 0)
                break;

            else
                G_warning(_("%s is not a valid rule"), buf);
            break;
        }			/* switch */
    }				/* loop */

    if (fp != stdin)
        fclose(fp);

    return nrules;
}