/*
dtaus.c - Belegloser Datenträgeraustausch mit einer Bank
- Copyright (c) 1996,8,2001 Martin Schulze <joey@infodrom.org>
+ Copyright (c) 1996,8,2001,2 Martin Schulze <joey@infodrom.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <time.h>
#include <malloc.h>
-/* #define DEFAULT_EURO */
+#define DEFAULT_EURO
#ifndef DEFAULT_EURO
int use_euro = 0;
#endif
size_t dtaus_nextrec (void **buf, FILE *f)
{
- bzero (buf, 128);
+ memset (buf, 0, 128);
return fread(buf, 128, 1, f);
}
char dtaus_char (void *buf, unsigned int pos)
{
static char res;
- char *bufp = buf;
+ char *bufp = (char *)buf;
bufp+=pos;
memcpy(&res, bufp, 1);
unsigned long int dtaus_int(void *buf, unsigned int pos, unsigned int len)
{
char tmp[30];
- char *bufp = buf;
+ char *bufp = (char *)buf;
static unsigned long int res;
bufp+=pos;
static char word[30];
if (strlen(line) > 0) {
- x = index (line, ' ');
- y = index (line, '\t');
+ x = strchr (line, ' ');
+ y = strchr (line, '\t');
if (!x && !y) {
strncpy(word, line, 29);
char *cp;
int i;
- bzero (line, sizeof(line));
- bzero (buf, len);
+ memset (line, 0, sizeof(line));
+ memset (buf, 0, len);
cp = line;
while (!strlen(line) && (cp = fgets(line, 100, f))) {
while (tmp[strlen(tmp)-1] != '\n' && (cp = fgets(tmp, 100, f)));
} else
line[strlen(line)-1] = '\0';
- if (line[strlen(line)-1] == '\r')
+ if (line[strlen(line)-1] == '\r')
line[strlen(line)-1] = '\0';
for (i=strlen(line);(line[i-1] == ' '||line[i-1] == '\t')&&i>0; i--)
line[i-1] = '\0';
struct tm *loctime;
char tmp[10];
- bzero (buf, 129);
+ memset (buf, 0, 129);
timer = time ( NULL );
loctime = localtime(&timer);
int i;
int appendix = 0;
- bzero (buf, 257);
+ memset (buf, 0, 257);
if (normaltext)
appendix = 1;
{
int i;
- bzero (buf, 129);
+ memset (buf, 0, 129);
buf[0] = '0';
buf[1] = '1';
buf[2] = '2';
fprintf(f, " %s\t%s\n", field, value);
}
+/*
+ * one date line, format it properly
+ */
+void printctlndate(FILE *f, char *field, char *value)
+{
+ char mydate[11];
+ int i;
+
+ if (!strlen(field) || !strlen(value))
+ return;
+
+ for (i=0;isspace (value[i]) && i<= strlen (value); i++);
+ if (i == strlen (value))
+ return;
+
+ memset (mydate, 0, sizeof (mydate));
+ if (strlen (value) == 6) {
+ mydate[0] = value[0];
+ mydate[1] = value[1];
+ mydate[2] = '.';
+ mydate[3] = value[2];
+ mydate[4] = value[3];
+ mydate[5] = '.';
+ mydate[6] = value[4];
+ mydate[7] = value[5];
+ fprintf(f, " %s\t%s\n", field, mydate);
+ } else if (strlen (value) == 8) {
+ mydate[0] = value[0];
+ mydate[1] = value[1];
+ mydate[2] = '.';
+ mydate[3] = value[2];
+ mydate[4] = value[3];
+ mydate[5] = '.';
+ mydate[6] = value[4];
+ mydate[7] = value[5];
+ mydate[8] = value[6];
+ mydate[9] = value[7];
+ fprintf(f, " %s\t%s\n", field, mydate);
+ } else {
+ fprintf (stderr, "Broken date field: %s\n", value);
+ fprintf(f, " %s\t%s\n", field, value);
+ }
+}
+
/*
* Third: Some high level routines
void dtaus2control (char *cdtaus, char *ccontrol)
{
FILE *fdtaus, *fcontrol;
- void *buf;
- void *bufp;
+ char *buf;
+ char *bufp;
char tmp[30];
char x[30];
int index;
#endif
bufp = buf + recA[index].pos;
memcpy(tmp, bufp, recA[index].len); tmp[recA[index].len] = '\0';
- printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
+ if (index == A_DATE || index == A_TODO)
+ printctlndate(fcontrol, recA[index].name, tmp);
+ else
+ printctln(fcontrol, recA[index].name, strip_zeros(strip_spaces(tmp)));
}
#ifndef DEFAULT_EURO
bufp = buf + recC[index].pos;
memcpy(tmp, bufp, recC[index].len); tmp[recC[index].len] = '\0';
#ifndef DEFAULT_EURO
- if (index == C_VAL || index == C_EUR)
-#else
- if (index == C_VAL)
+ if (index == C_EUR)
+ printctln(fcontrol, recC[C_VAL].name, strip_zeros(string2real(tmp)));
+ else
#endif
+ if (index == C_VAL)
printctln(fcontrol, recC[index].name, strip_zeros(string2real(tmp)));
else if (index == C_TRANS)
printctln(fcontrol, recC[index].name, strip_zeros(string2trans(tmp)));
}
}
if (dtaus_nextrec(buf, fdtaus) != 1)
- bzero (buf, sizeof(buf));
+ memset (buf, 0, sizeof(buf));
/*
* Are there extension records that we have to check?
}
}
if (dtaus_nextrec(buf, fdtaus) != 1)
- bzero (buf, sizeof(buf));
+ memset (buf, 0, sizeof(buf));
extC--;
}
fprintf(fcontrol, "}\n");
char **text = NULL;
char *cp;
int textindex = 0;
+ int len, i;
if (!cdtaus) {
if (!(fdtaus = fopen("dtaus0.txt", "w")))
/*
* Record A lesen
*/
- bzero(valA, sizeof(valA));
+ memset (valA, 0, sizeof(valA));
control_nextline ((void *)line, 100, fcontrol);
ident = extract_ident(line);
if (!strcmp(ident, "begin") && (line[0] == '{')) {
sum_val = bigint_int(0);
sum_blz = bigint_int(0);
sum_kto = bigint_int(0);
- bzero(valC, sizeof(valC));
+ memset (valC, 0, sizeof(valC));
control_nextline ((void *)line, 100, fcontrol);
if (line[0] == '{') {
while (strlen(line) && line[0] == '{') {
}
}
} else {
- if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
- strcpy(valC[recindex], line);
- else
- return 0;
+ len = strlen(line);
+ if (recindex == C_VAL) {
+ /* Convert commast to dots for later processing */
+ for (i=0; line[i]; i++) if (line[i] == ',') line[i] = '.';
+
+ if ((cp = index (line, '.')) == NULL) {
+ if (!(valC[recindex] = (char *)malloc (strlen(line)+4)))
+ return 0;
+ sprintf (valC[recindex], "%s.00", line);
+ } else if ( ((len = cp - line + 3)) < strlen (line)) {
+ if (!(valC[recindex] = (char *)malloc (len+1)))
+ return 0;
+ strncpy (valC[recindex], line, len);
+ valC[recindex][len] = '\0';
+ } else {
+ if (!(valC[recindex] = (char *)malloc (strlen(line)+1)))
+ return 0;
+ strcpy(valC[recindex], line);
+ }
+ } else {
+ if ((valC[recindex] = (char *)malloc (strlen(line)+1)))
+ strcpy(valC[recindex], line);
+ else
+ return 0;
+ }
}
}
control_nextline ((void *)line, 100, fcontrol);
for (recindex=0; recindex<C_LEN; recindex++)
if (valC[recindex])
free(valC[recindex]);
- bzero(valC, sizeof(valC));
+ memset (valC, 0, sizeof(valC));
control_nextline ((void *)line, 100, fcontrol);
}
} else {