gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] 03/04: fix loop logic


From: gnunet
Subject: [taler-anastasis] 03/04: fix loop logic
Date: Tue, 25 Aug 2020 14:48:53 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 9de107d71eacf24a4cd8747ca816276cbc988eca
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Aug 25 12:12:33 2020 +0200

    fix loop logic
---
 src/cli/anastasis-cli-splitter.c | 61 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index a7bb8cb..ada2db6 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -1015,9 +1015,57 @@ read_keyboard_command (void *cls)
             return;
           }
           tus->index = tu_states_length;
+
+          // memorize tu_states of policies before appending tu_state
+          bool tu_mem[pc_states_length][tu_states_length];
+          if (pc_states_length > 0)
+          {
+            for (unsigned int i = 0; i < pc_states_length; i++)
+            {
+              printf ("%i:", i);
+              for (unsigned int j = 0; j < tu_states_length; j++)
+              {
+                bool match = false;
+                for (unsigned int k = 0; k < pc_states[i].tu_states_len; k++)
+                {
+                  if (pc_states[i].tu_states[k]->index == j)
+                  {
+                    match = true;
+                    break;
+                  }
+                }
+                tu_mem[i][j] = match;
+                printf (" %d ", match);
+              }
+              printf ("\n");
+            }
+          }
           GNUNET_array_append (tu_states,
                                tu_states_length,
                                *tus);
+          // fix policies after appending tu_state
+          if (pc_states_length > 0)
+          {
+            for (unsigned int i = 0; i < pc_states_length; i++)
+            {
+              printf ("\n");
+              printf ("%i:", i);
+              unsigned int k = 0;
+              for (unsigned int j = 0; j < tu_states_length - 1; j++)
+              {
+                if (tu_mem[i][j] == true)
+                {
+                  pc_states[i].tu_states[k] = &tu_states[j];
+                  k++;
+                  printf (" 1 ");
+                }
+                else
+                  printf (" 0 ");
+              }
+              pc_states[i].tu_states_len = k;
+              printf ("\n");
+            }
+          }
           tus->tuo = ANASTASIS_truth_upload (ctx,
                                              servers[server_num].user_id,
                                              servers[server_num].backend_url,
@@ -1138,13 +1186,22 @@ read_keyboard_command (void *cls)
                     buffer,
                     strlen ("policy add")))
   {
+    if (characters == strlen ("policy add"))
+    {
+      printf ("Wrong argument: No truth given!\n");
+      printf (
+        "Example: policy add truth#0 truth#2\n");
+      free (buffer);
+      buffer = (char *) NULL;
+      start_read_keyboard ();
+      return;
+    }
     struct PolicyCreateState *pcs = GNUNET_new (struct PolicyCreateState);
     pcs->tu_states_len = 0;
     char *token_start = &buffer[strlen ("policy add ")];
     char *token = strtok (token_start, " ");
     while (token != NULL)
     {
-      unsigned int tus_index;
       if (0 != strncmp ("truth#",
                         token,
                         strlen ("truth#")))
@@ -1155,7 +1212,7 @@ read_keyboard_command (void *cls)
         start_read_keyboard ();
         return;
       }
-      tus_index = (int) token[strlen ("truth#")] - 48;
+      unsigned int tus_index = (int) token[strlen ("truth#")] - 48;
       if (tus_index < tu_states_length)
       {
         GNUNET_array_append (pcs->tu_states,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]