Esempio n. 1
0
bool format_readable_mask(
    const struct filter_mask *mask, unsigned int fa_entry_count,
    char *string, size_t length)
{
    bool ok = true;
    bool in_range = false;
    bool first = true;
    unsigned int range_start = 0;
    *string = '\0';
    for (unsigned int id = 0; ok  &&  id < fa_entry_count; id ++)
    {
        bool set = test_mask_bit(mask, id);
        if (set  &&  !in_range)
        {
            /* Starting a new range of values.  Write the first number. */
            in_range = true;
            range_start = id;
        }
        else if (!set  &&  in_range)
        {
            /* End of range, now write it out. */
            ok = write_range(&string, &length, range_start, id - 1, first);
            in_range = false;
            first = false;
        }
    }
    if (ok  &&  in_range)
        ok = write_range(
            &string, &length, range_start, fa_entry_count - 1, first);
    return ok;
}
Esempio n. 2
0
void ptree::write_key(writable& out, const string& key) const 
{
	if (!m_root) {
		out.write(pid_eof);
	}
	uint64_t pos = key_position(key);
	write_range(out, pos, pos+1);
}
/* Start a new range, initialize SoBStatus.dat
 */
void sob_start_range(uint64_t pmin, uint64_t pmax)
{
  FILE *file;

  file = xfopen(sob_status_file_name,"w",error);
  write_range(pmin,pmax,file,sob_status_file_name);
  xfclose(file,sob_status_file_name);
}
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;
}
Esempio n. 5
0
static int init() {
	struct resource *p;
	int err = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
	resource_size_t p_last = -1;
#else
	__PTRDIFF_TYPE__ p_last = -1;
#endif

	DBG("Initilizing Dump...");

	if((err = setup())) {
		DBG("Setup Error");
		cleanup();
		return err;
	}

	for (p = iomem_resource.child; p ; p = p->sibling) {
		if (strcmp(p->name, LIME_RAMSTR))
			continue;

		if (mode == LIME_MODE_LIME && (err = write_lime_header(p))) {
			DBG("Error writing header 0x%lx - 0x%lx", (long) p->start, (long) p->end);
			break;
		} else if (mode == LIME_MODE_PADDED && (err = write_padding((size_t) ((p->start - 1) - p_last)))) {
			DBG("Error writing padding 0x%lx - 0x%lx", (long) p_last, (long) p->start - 1);
			break;
		}

		if ((err = write_range(p))) {
			DBG("Error writing range 0x%lx - 0x%lx", (long) p->start, (long) p->end);
			break;
		}

		p_last = p->end;
	}
	

	cleanup();

	return err;
}
Esempio n. 6
0
void cmd_write (char *cp)

{
  int rc;
  Line *line;
  Position beg_write, end_write;

  out_file  = NULL;
  linecount = 0;

  /* Get filename */

  out_name = cp;
  cp = uptospace (cp);
  if (*cp != 0) {
    *(cp ++) = 0;
    cp = skipspaces (cp);
  }

  /* Get optional range.  If not specified, use the whole current buffer. */

  if (*cp != 0) {
    rc = range_multiple (cp, &cp, write_range, out_name);
    if (rc == 0) eoltest (cp);
  } else {
    for (line = buffer_first_line (cur_position.buffer); line != NULL; line = line_next (line)) {
      rc = write_range (out_name, cur_position.buffer, line);
      if (rc != 0) break;
    }
  }

  /* Close output file */

  if (out_file == NULL) outerr (0, "no file created\n");
  else {
    if (linecount == 0) outerr (strlen (out_name), "no lines written to %s\n", out_name);
    else outerr (12 + strlen (out_name), "%u line%s written to %s\n", linecount, (linecount == 1) ? "" : "s", out_name);
    if (fclose (out_file) < 0) outerr (strlen (out_name) + strlen (strerror (errno)), "error closing file %s: %s\n", out_name, strerror (errno));
    out_file = NULL;
  }
}
Esempio n. 7
0
void ptree::write(writable& out) const
{
	write_range(out, 0, m_root->node_count());
}
Esempio n. 8
0
int process_file(FILE *ifp)
{
  char *ibuf, *config = NULL;
  byte **rom = NULL;       /* pointers to ROM images */
  byte *data = NULL;      /* data accumulators      */
  int line = 0, first = 1, nroms = 0, abits = 0, length = 0, res = 0;
  int ix;

  /* Allocate space to read strings into */
  if((ibuf = calloc(MAXLINE + 1, sizeof(char))) == NULL) {
    fprintf(stderr, "Insufficient memory to process file\n");
    return 1; /* out of memory */
  }

  /* Read strings from the input file */
  while(read_line(ifp, ibuf, MAXLINE)) {
    ++line;
    strip_comment(ibuf);

    /* Blank lines are skipped in all cases */
    if(is_blank(ibuf))
      continue;

    strip_whitespace(ibuf);

    /*
      When we see the first line, we need to accumulate some other
      info we're going to need later.  This includes the number of
      address bits (abits), and the number of ROMs (nroms).  We also
      need to save a copy of the configuration line for later, since
      ibuf will be overwritten with each line that is consumed.

      We also range-check the values of abits and nroms, and allocate
      memory for the ROM images we will build during the reading of
      the rest of the file.  We save the length of the configuration
      line (length) so that we can syntax check subsequent lines in
      an efficent manner.
     */
    if(first) {

      /* Check structural validity of configuration line */
      if(!valid_string(ibuf, "0123456789Aa")) {
        fprintf(stderr,
                "Line %d: invalid character in configuration\n",
                line);
        res = 1;
        goto CLEANUP;
      }

      /* Count number of ROM cells and address (state) bits */
      nroms = count_roms(ibuf);
      abits = count_addr(ibuf);

      /* Complain if we didn't get at least 1 ROM, or if we got too many */
      if(nroms < 1) {
        fprintf(stderr, "Line %d: must specify at least 1 ROM number\n",
                line);
        res = 2;
        goto CLEANUP;
      } else if(nroms > NUM_ROMS) {
        fprintf(stderr, "Line %d: cannot specify more than %d ROMs\n",
                line, NUM_ROMS);
        res = 2;
        goto CLEANUP;
      }

      /* Complain if we got no address bits, or more than MAXBITS */
      if(abits < 1 || abits > MAXBITS) {
        fprintf(stderr, "Line %d: must have between 1-%d state bits\n",
                line, MAXBITS);
        res = 3;
        goto CLEANUP;
      }

      /* Okay, the config is alright, save it for later ... */
      if((config = copy_string(ibuf)) == NULL) {
        fprintf(stderr, "Insufficient memory to process file\n");
        res = 1;
        goto CLEANUP;
      }

      /* Hang onto the length, we'll need it later */
      length = strlen(config);

      /* Allocate space for the ROMs and their accumulators */
      if(!alloc_roms(&rom, nroms, config, abits)) {
        fprintf(stderr, "Insufficient memory to process file\n");
        res = 1;
        goto CLEANUP;
      }
      if((data = calloc(nroms, sizeof(byte))) == NULL) {
        fprintf(stderr, "Insufficient memory to process file\n");
        res = 1;
        goto CLEANUP;
      }

      first = 0;
      continue;
    } /* end if(first) */

    /* Translate output "don't care" values to regular bits */
    translate(ibuf, OUTPUT_DC, g_odcv);

    /* Anything bad left in the string? */
    if(!valid_string(ibuf, "01Xx")) {
      fprintf(stderr, "Line %d: invalid character in data\n", line);
      res = 1;
      goto CLEANUP;
    }

    /* Make sure we got enough fields to satisfy the template */
    if(strlen(ibuf) != length) {
      fprintf(stderr,
              "Line %d: wrong number of fields (wanted %u, got %u)\n",
              line, (unsigned) length, (unsigned) strlen(ibuf));
      res = 4;
      goto CLEANUP;
    }

    /* Grab all the data out of the line, escaping on error */
    if(!parse_data(ibuf, line, config, abits, data)) {
      res = 5;
      goto CLEANUP;
    }

    /* Write the data into the ROM images.  We know which ROMs
       to use by checking the pointers in the ROM image array,
       and the accumulator is already set to go
     */
    for(ix = 0; ix < nroms; ix++) {
      if(rom[ix]) {
        write_range(rom[ix], ibuf, abits, data[ix]);
      }
    }

    /* Clear out accumulators for the next round */
    memset(data, 0, nroms);

  } /* end while(read_line(...)) */

  /* If we didn't get a first line at all, the file was logically
     empty (i.e., not even a configuration!) */
  if(first) {
    fprintf(stderr, "No configuration line was found\n");
    res = 7;

  } else {

    /* Having accumulated all the data into the ROM images, we now
       will dump them out into the appropriate files */
    if(!dump_roms(rom, nroms, abits, g_fmt))
      res = 6;
  }

 CLEANUP:
  free(ibuf);

  if(config)
    free(config);

  if(rom) {
    free_roms(rom, nroms);
    free(rom);
  }

  if(data)
    free(data);

  return res;

} /* end process_file() */