Exemplo n.º 1
0
int
main(int argc, char **argv)
{
	int c;
	int fd;
	SHA1_context ctx;
	struct sha1 digest;
	bool done;
	/* getopt() variables: */
	extern int optind;

	progstart(argc, argv);

	while ((c = getopt(argc, argv, "h")) != EOF) {
		switch (c) {
		case 'h':			/* show help */
		default:
			usage();
			break;
		}
	}

	if ((argc -= optind) != 1)
		usage();

	argv += optind;

	fd = file_open(argv[0], O_RDONLY, 0);
	if (-1 == fd)
		exit(EXIT_FAILURE);

	SHA1_reset(&ctx);

	for (done = FALSE; !done; /* empty */) {
		static char buf[128 * 1024];
		int r;

		r = read(fd, buf, sizeof buf);

		if (-1 == r)
			s_fatal_exit(EXIT_FAILURE, "read() error: %m");

		done = r != sizeof buf;
		SHA1_input(&ctx, buf, r);
	}

	SHA1_result(&ctx, &digest);
	close(fd);

	printf("%s\n", sha1_base16(&digest));
	return 0;
}
Exemplo n.º 2
0
int main (int argc, char **argv) {
  FILE *f;

  progstart(argc, argv);

  if (argc != 3) USAGE_ERROR;

  if ((f = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "couldn't open %s\n", argv[1]);
    exit(1);
  }
  read_floats(f);
  fclose(f);
  float_init();		/* Always run this to establish baseline */

  if (strcmp(argv[2], "base") == 0) {
    exit(0);
  }
  else if (strcmp(argv[2], "sprintf") == 0) {
    int n;
    double *fp;
    char s[32];

    for (n = nfloats, fp = floats; n > 0; n--) {
       sprintf(s,"%.17g", *fp++);
    }
  }
  else if (strcmp(argv[2], "printf") == 0) {
    int n;
    double *fp;
    for (n = nfloats, fp = floats; n > 0; n--)
      printf("%.17g\n", *fp++);
  }
  else if (strcmp(argv[2], "dragon") == 0) {
    int n, k;
    double *fp;
    char s[32];

    for (n = nfloats, fp = floats; n > 0; n--) {
      float_dragon(s, sizeof s, *fp++, &k);
      printf("%s %d\n", s, k);
    }
  }
  else if (strcmp(argv[2], "fixed") == 0) {
    int n, k;
    double *fp;
    char s[32];

    for (n = nfloats, fp = floats; n > 0; n--) {
      float_fixed(s, sizeof s, *fp++, 17, &k);
      printf(".%se%d\n", s, k+1);
    }
  }
  else if (strcmp(argv[2], "compare") == 0) {
    int n, k1, k2;
    double *fp;
    char s[32], buf[32];

    for (n = nfloats, fp = floats; n > 0; n--, fp++) {
       sprintf(s,"%.17g", *fp);
       k1 = convert(s, buf, 17);
       float_fixed(s, sizeof s, *fp, 17, &k2);
       if (s[17] == '5') {
         int i;
         char *p, c;
         s[17] = 0;
         if (k1 == k2 && strcmp(s, buf) == 0) continue;
         for (i = 17, p = &s[16]; i > 0; i--) {
           c = *p;
           if (c != '9') {
             *p = c+1;
             break;
           }
           *p-- = '0';
         }
         if (i == 0) {
           *++p = '1';
           k2++;
         }
       }
       if (k1 != k2 || strcmp(s, buf) != 0) {
         printf(".%se%d .%se%d\n", buf, k1+1, s, k2+1);
       }
    }
  }
  else
    USAGE_ERROR;

  return 0;
}