示例#1
0
文件: hex.c 项目: S010/misc
static void
hex(const char *s)
{
	unsigned long long i = 0;

	switch (s[0]) {
	case 'b':
	case 'B':
		i = read_bin(s + 1);
		break;
	case 'x':
	case 'X':
		i = read_hex(s + 1);
		break;
	case '0':
		if (s[1] == '\0')
			i = read_dec(s);
		else if (s[1] == 'x' || s[1] == 'X')
			i = read_hex(s + 2);
		else
			i = read_oct(s + 1);
		break;
	default:
		if (isdigit(*s))
			i = read_dec(s);
		else
			usage();
		break;
	}
	print_bin(i);
	print_chr(i);
	print_dec(i);
	print_hex(i);
	print_oct(i);
}
示例#2
0
int
main()
{
  char buf[512];
  struct tarhdr *hdr;
  unsigned int n, end = 0, off = 0;

  do {
    n = fread(buf, 1, sizeof(buf), stdin);
    off += n;
    if (off > end) {
      hdr = (struct tarhdr *)buf;
      if (hdr->name[0]) {
        end = off + ((read_oct(sizeof(hdr->size), hdr->size) + 511) & ~511);
        memset(hdr->checksum, ' ', sizeof(hdr->checksum));
        memset(hdr->uid, '0', sizeof(hdr->uid) - 1);
        memset(hdr->gid, '0', sizeof(hdr->gid) - 1);
        memset(hdr->uname, 0, sizeof(hdr->uname));
        memset(hdr->gname, 0, sizeof(hdr->gname));
        snprintf(hdr->uname, sizeof(hdr->uname), "root");
        snprintf(hdr->gname, sizeof(hdr->gname), "root");
        upd_cksum(hdr->checksum, buf);
      }
    }
    fwrite(buf, 1, n, stdout);
  } while (n == sizeof(buf));
  return 0;
}
示例#3
0
int		read_value(t_mem *mem, int addr, int size)
{
	int i;

	i = 0;
	if (i <= addr)
		while (i < addr - 1)
		{
			mem = mem->next;
			i++;
		}
	else
		while (i > addr + 1)
		{
			mem = mem->prev;
			i--;
		}
	if (size == 1)
		return (mem->oct);
	return (read_oct(mem, size));
}