Fix problems with unproperly recognized values like "10,03", "100.004"
[infodrom/dtaus] / dtaus.c
diff --git a/dtaus.c b/dtaus.c
index 7c7ea71..f3fc082 100644 (file)
--- a/dtaus.c
+++ b/dtaus.c
@@ -1027,6 +1027,7 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
   char **text = NULL;
   char *cp;
   int textindex = 0;
+  int len, i;
 
   if (!cdtaus) {
     if (!(fdtaus = fopen("dtaus0.txt", "w")))
@@ -1185,10 +1186,31 @@ int control2dtaus (char *ccontrol, char *cdtaus, char *cbeleg, char *ccheck)
                }
              }
            } 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);