Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify read_table and read_my_table #504

Merged
merged 2 commits into from
Nov 20, 2017

Conversation

coldfix
Copy link
Collaborator

@coldfix coldfix commented Nov 17, 2017

This PR removes the read_my_table routine completely and changes read_table to honor the table command argument if specified. The READTABLE and READMYTABLE commands now do exactly the same.

The two routines were essentially the same, with two differences (see diff below):

  • read_table ignores the user-specified table command argument if a name is defined in the file.
  • read_my_table does not read the table summary

I don't think there is any backward-compatibility issue, since (1) the table option for READTABLE was so far undocumented, and (2) suddenly getting the table summary as well when using READMYTABLE shouldn't be an issue.

Rationale

The presence of a table parameter for the READTABLE command implies that you can specify the table name, which seems to work - as long as the file either doesn't specify a name or its name is the same as the one you specified by hand - until it doesn't work..

This means, you are forced to use READMYTABLE if you want to load a table reliably, but then the summary is not loaded.

Diff between the two functions

Modulo whitespace, the diff from read_my_table to read_table was:

--- read_my_table.c	2017-11-16 18:03:41.080862129 +0100
+++ read_table.c	2017-11-16 18:01:33.649025180 +0100
@@ -1,5 +1,5 @@
 struct table*
-read_my_table(struct in_cmd* cmd)
+read_table(struct in_cmd* cmd)
     /* reads and stores TFS table */
 {
     struct table* t = NULL;
@@ -8,7 +8,7 @@
     short sk;
     int i, k, error = 0;
     char *cc, *filename, *type = NULL, *tmp, *name;
-    double tmpd;
+
     char* namtab;
 
     if ((namtab = command_par_string("table",cmd->clone)) != NULL) {
@@ -36,6 +36,7 @@
     }
     while (fgets(aux_buff->c, aux_buff->max, tab_file))
     {
+        supp_char('\r', aux_buff->c);
         cc = strtok(aux_buff->c, " \"\n");
         if (*cc == '@')
         {
@@ -48,6 +49,14 @@
                         type = permbuff(stolower(name));
                 }
             }
+            else if (strcmp(tmp, "NAME") == 0)
+            {
+                if ((name = strtok(NULL, " \"\n")) != NULL) /* skip format */
+                {
+                    if ((name = strtok(NULL, " \"\n")) != NULL)
+                        namtab = permbuff(stolower(name));
+                }
+            }
         }
         else if (*cc == '*' && tnl == NULL)
         {
@@ -124,18 +133,12 @@
                 {
                     sscanf(cc, tmp, &sk); t->d_cols[i][t->curr] = sk;
                 }
-                else
-                {
-                    sscanf(cc, tmp, &tmpd);
-                    t->d_cols[i][t->curr] = tmpd;
-                }
-
-
+                else sscanf(cc, tmp, &t->d_cols[i][t->curr]);
                 if (i+1 < tnl->curr)
                 {
                     if ((cc =strtok(NULL, " \"\n")) == NULL)
                     {
-                        warning("read_my_table: incomplete table line starting with:", aux_buff->c);
+                        warning("read_table: incomplete table line starting with:", aux_buff->c);
                         return NULL;
                     }
                 }
@@ -144,6 +147,27 @@
         }
     }
     fclose(tab_file);
+    if ((tab_file = fopen(filename, "r")) == NULL)
+    {
+        warning("cannot open file:", filename); return NULL;
+    }
+    /* read & store table header */
+    t->header = new_char_p_array(50);
+    while (fgets(aux_buff->c, aux_buff->max, tab_file))
+    {
+        supp_char('\r', aux_buff->c);
+        if ((*aux_buff->c != ' ') &&
+                ((*aux_buff->c == '@') || (*aux_buff->c == '*')))
+        {
+            if (t->header->curr == t->header->max) grow_char_p_array(t->header);
+            int len = strlen(aux_buff->c)+1;
+            t->header->p[t->header->curr] = mymalloc_atomic("read_table", len * sizeof *t->header->p[0]);
+            strncpy(t->header->p[t->header->curr], aux_buff->c,len * sizeof *(aux_buff->c)-1);
+            //strcpy(t->header->p[t->header->curr], aux_buff->c);
+            t->header->curr++;
+        }
+    }
+    fclose(tab_file);
     t->origin = 1;
     add_to_table_list(t, table_register);
     return NULL;

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 66.855% when pulling 3fa6ffc on hibtc:read_table into 36df890 on MethodicalAcceleratorDesign:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 66.855% when pulling 3fa6ffc on hibtc:read_table into 36df890 on MethodicalAcceleratorDesign:master.

@ldeniau ldeniau merged commit 776964d into MethodicalAcceleratorDesign:master Nov 20, 2017
@coldfix coldfix deleted the read_table branch November 20, 2017 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants