gremlin/gremlin.in: Use `locale.getpreferredencoding'.
[autoys] / flaccrip / flaccrip-compute
1 #! /usr/bin/tcc -run
2 /* -*-c-*- */
3
4 #include <errno.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include <getopt.h>
10
11 int main(int argc, char *argv[])
12 {
13 unsigned long ck = 0, t = 0;
14 unsigned long ns = 0;
15 unsigned long x;
16 unsigned f = 0;
17 #define F_ROLLING 1u
18
19 for (;;) {
20 int opt = getopt(argc, argv, "b:r");
21 if (opt < 0) break;
22 switch (opt) {
23 case 'b': ns = strtoul(optarg, 0, 0); break;
24 case 'r': f |= F_ROLLING; break;
25 default: exit(1);
26 }
27 }
28 for (;;) {
29 unsigned char b[4];
30 if (!fread(b, 4, 1, stdin)) break;
31 x = (b[0] << 0) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
32 ck += x*++ns; t += x;
33 }
34 if (ferror(stdin)) {
35 fprintf(stderr, "%s: read error: %s\n", argv[0], strerror(errno));
36 exit(1);
37 }
38 printf("%08lx", ck & 0xffffffff);
39 if (f & F_ROLLING) printf(" %lu", t & 0xffffffff);
40 putchar('\n');
41 return (0);
42 }