From: Joey Schulze Date: Wed, 14 Oct 1998 22:43:41 +0000 (+0000) Subject: * While implementing zero-padded fields I've also implemented X-Git-Url: https://git.infodrom.org/?p=infodrom%2Fdtaus;a=commitdiff_plain;h=b8dadb70c45bbc74a9a2bc00932c438cc936bc0b * While implementing zero-padded fields I've also implemented clippings so numbers that are too big won't hurt the binary DTAUS file. * Added better support for zero-padded numbers. sprintf() from libc4 had no problems accepting `%08s' while this didn't produce zero-padded strings with libc5 and libc6. Now we've got our own routine to handle these. --- diff --git a/ChangeLog b/ChangeLog index 0a2e328..38d29e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +1998-10-15 Martin Schulze + + * Version 0.3 + + * While implementing zero-padded fields I've also implemented + clippings so numbers that are too big won't hurt the binary DTAUS + file. + + * Added better support for zero-padded numbers. sprintf() from + libc4 had no problems accepting `%08s' while this didn't produce + zero-padded strings with libc5 and libc6. Now we've got our own + routine to handle these. + Fri Jul 3 13:28:28 1998 Martin Schulze * Wrote a small manpage diff --git a/README b/README index 8800c8a..37416db 100644 --- a/README +++ b/README @@ -37,3 +37,5 @@ What needs to be done: Good luck! + Martin Schulze + diff --git a/dtaus.c b/dtaus.c index 6e86c8a..079bc2c 100644 --- a/dtaus.c +++ b/dtaus.c @@ -343,6 +343,28 @@ char *extract_ident (char *line) return line; } +/* + * Pads a string with zero's on the left side. + */ +char *padzeroclip (char *s, int len) +{ + char *p, *q; + + if (strlen(s) == len) return s; + if (strlen(s) > len) { + q=s+len; + *(q--) = '\0'; + return s; + } + + q=s+len; + *(q--) = '\0'; + for (p=s+strlen(s)-1;p>=s;p--) + *(q--)=*p; + for (;q>=s;) *(q--)='0'; + return s; +} + int rec_index(char *ident, int type) { int i; @@ -495,11 +517,11 @@ int dtaus_writeA(FILE *f, char **values) dtaus_prepareA(buf); buf[5] = values[A_TRANS][0]; buf[6] = values[A_TRANS][1]; - sprintf (tmp, "%08s", values[A_BLZ]); + sprintf (tmp, "%s", padzeroclip(values[A_BLZ],8)); for (i=0; i<8; i++) buf[recA[A_BLZ].pos+i] = tmp[i]; sprintf (tmp, "%-27s", upcase(values[A_NAME])); for (i=0; i<27; i++) buf[recA[A_NAME].pos+i] = tmp[i]; - sprintf (tmp, "%010s", values[A_KTO]); + sprintf (tmp, "%s", padzeroclip(values[A_KTO],10)); for (i=0; i<10; i++) buf[recA[A_KTO].pos+i] = tmp[i]; fputs(buf, f); @@ -548,21 +570,21 @@ int dtaus_writeC(FILE *f, char **valuesA, char **values) } for (i=0; i<5; i++) buf[recC[C_TRANS].pos+i] = tmp[i]; if (values[C_MYBLZ]) - sprintf (tmp, "%08s", values[C_MYBLZ]); + sprintf (tmp, "%s", padzeroclip(values[C_MYBLZ],8)); else - sprintf (tmp, "%08s", valuesA[A_BLZ]); + sprintf (tmp, "%s", padzeroclip(valuesA[A_BLZ],8)); for (i=0; i