fprintf(f, "R9");
fprintf(f, "%s", dec->cpf); /* CPF: 11 dígitos */
fprintf(f, "%-3.3s", ""); /* FILLER */
- fprintf(f, "%-10.10s", "0000000000"); /* FIXME: hash */
+ fprintf(f, "%010u", dec->rhash);
}
static void gera_rendimento(struct declaracao *dec, FILE *f)
typedef void (gera_linha)(struct declaracao *dec, FILE *f);
+static void update_hash(struct declaracao *dec, char *buf, size_t len)
+{
+ int r;
+ int linha;
+ r = sscanf(buf, "%2d", &linha);
+ if (r == 1 || !strncmp(buf, "T9", 2)) {
+ dec->hash = crc32(dec->hash, buf, len - 2);
+ dec->rhash = crc32(dec->rhash, buf, len - 2);
+ return;
+ } else if (strncmp(buf, "R9", 2) && strncmp(buf, "IRPF", 4)) {
+ dec->rhash = crc32(dec->rhash, buf, len - 2);
+ }
+}
+
static int wrap(gera_linha fn, struct declaracao *dec, FILE *f)
{
FILE *m;
if (r == 1 && linha >= 0 && linha < 100) {
dec->linhas[linha]++;
}
+ update_hash(dec, buf, bsize);
fwrite(buf, bsize, 1, f);
free(buf);
return 0;
struct pagamento *pagamento;
struct bem *bem;
+ dec->hash = crc32(0L, NULL, 0);
+ dec->rhash = crc32(0L, NULL, 0);
+
#define W(fn, dec, f) \
do { \
r = wrap(fn, dec, f); \