Index: pobyso.c
===================================================================
--- pobyso.c	(revision 127)
+++ pobyso.c	(revision 128)
@@ -17,6 +17,9 @@
 /* includes of project headers */
 
 /* includes of system headers */
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
 
 /* Other declarations */
 
@@ -39,13 +42,100 @@
   va_end(va);
 } /* End pobyso_autoprint. */
 
+/* @see pobyso.h#pobyso_parse*/
+pobyso_function_t
+pobyso_parse(const char* expression)
+{
+  int expressionLength, i;
+  char *expressionWithSemiCo;
+  sollya_obj_t expressionStringSa;
+  sollya_obj_t expressionSa;
+
+  /* Arguments check. */
+  if (expression == NULL)
+  {
+    pobyso_error_message("pobyso_parse",
+                        "NULL_POINTER_ARGUMENT",
+                        "The expression is a NULL pointer");
+    return(sollya_lib_error());
+  }
+  expressionLength = strlen(expression);
+  if (expressionLength == 0)
+  {
+    pobyso_error_message("pobyso_parse",
+                        "EMPTY_STRING_ARGUMENT",
+                        "The expression is an empty string");
+    return(sollya_lib_error());
+  }
+  /* Search from the last char of the expression until, whichever happens
+   * first:
+   * a ";" is found;
+   * a char  != ';' is found the the ";" is appended.
+   * If the head of the string is reached before any of these two events happens
+   * return an error.
+   */
+  for (i = expressionLength - 1 ; i >= 0 ; i--)
+  {
+    if (expression[i] == ';') /* Nothing special to do:
+                                 try to parse the string*/
+    {
+      /* This ugly cast comes from a deficient definition in Sollya:
+         sollya_lib_string does not take a const char * argument. */
+      expressionStringSa = sollya_lib_string((char*)expression);
+      expressionSa = sollya_lib_parse(expressionStringSa);
+      sollya_lib_free(expressionStringSa);
+      return(expressionSa);
+    }
+    else
+    {
+      if (expression[i] == ' ' || expression[i] == '\t') /* A blank,
+                                                           just continue. */
+      {
+        continue;
+      }
+      else /* a character != ';' and from a blank: create the ';'ed string. */
+      {
+        /* Create a new string for the expression, add the ";" and
+         * and call sollya_lib_parse_string. */
+        expressionWithSemiCo = calloc(i + 3, sizeof(char));
+        if (expressionWithSemiCo == NULL)
+        {
+          pobyso_error_message("pobyso_parse",
+                                "MEMORY_ALLOCATION_ERROR",
+                                "Could not allocate the expression string");
+          return(sollya_lib_error());
+        }
+        strncpy(expressionWithSemiCo, expression, i + 1);
+        expressionWithSemiCo[i + 1] = ';';
+        expressionWithSemiCo[i + 2] = '\0';
+        expressionStringSa = sollya_lib_string(expressionWithSemiCo);
+        expressionSa = sollya_lib_parse(expressionStringSa);
+        free(expressionWithSemiCo);
+        sollya_lib_free(expressionStringSa);
+        return(expressionSa);
+      } /* End character != ';' and from a blank. */
+    /* Create a new string for the expression, add the ";" and
+     * and call sollya_lib_parse_string. */
+    } /* End else. */
+  } /* End for. */
+  /* We get here, it is because we did not find any char == anything different
+   * from ' ' or '\t': the string is empty.
+   */
+  pobyso_error_message("pobyso_parse_string",
+                       "ONLY_BLANK_ARGUMENT",
+                        "The expression is only made of blanks");
+  return(sollya_lib_error());
+
+} /* pobyso_parse_string */
+
 /* @see pobyso.h#pobyso_parse_string*/
-sollya_obj_t
+pobyso_function_t
 pobyso_parse_string(const char* expression)
 {
-  int expressionLength;
+  int expressionLength, i;
   char *expressionWithSemiCo;
   sollya_obj_t expressionSa;
+
   /* Arguments check. */
   if (expression == NULL)
   {
@@ -60,44 +150,77 @@
     pobyso_error_message("pobyso_parse_string",
                         "EMPTY_STRING_ARGUMENT",
                         "The expression is an empty string");
+    return(sollya_lib_error());
   }
-  /* If the final ";" has been forgotten. */
-  if (expression[expressionLength-1] != ';')
+  /* Search from the last char of the expression until, whichever happens
+   * first:
+   * a ";" is found;
+   * a char  != ';' is found the the ";" is appended.
+   * If the head of the string is reached before any of these two events happens
+   * return an error.
+   */
+  for (i = expressionLength - 1 ; i >= 0 ; i--)
   {
-    expressionWithSemiCo = calloc(expressionLength + 2, sizeof(char));
-    if (expressionWithSemiCo == NULL)
+    if (expression[i] == ';') /* Nothing special to do:
+                                 try to parse the string*/
     {
-      pobyso_error_message("pobyso_parse_string",
-                            "MEMORY_ALLOCATION_ERROR",
-                            "Could not allocate the expression string");
-      return(sollya_lib_error());
+      expressionSa = sollya_lib_parse_string(expression);
+      return(expressionSa);
     }
-    expressionWithSemiCo = strcat(expressionWithSemiCo, expression);
-    expressionWithSemiCo = strcat(expressionWithSemiCo, ";");
-    expressionSa = sollya_lib_parse_string(expressionWithSemiCo);
-    free(expressionWithSemiCo);
-    return(expressionSa);
-  } /* End ";" forgotten */
-  else
-  {
-    return(sollya_lib_parse_string(expression));
-  }
+    else
+    {
+      if (expression[i] == ' ' || expression[i] == '\t') /* A blank,
+                                                           just continue. */
+      {
+        continue;
+      }
+      else /* a character != ';' and from a blank: create the ';'ed string. */
+      {
+        /* Create a new string for the expression, add the ";" and
+         * and call sollya_lib_parse_string. */
+        expressionWithSemiCo = calloc(i + 3, sizeof(char));
+        if (expressionWithSemiCo == NULL)
+        {
+          pobyso_error_message("pobyso_parse_string",
+                                "MEMORY_ALLOCATION_ERROR",
+                                "Could not allocate the expression string");
+          return(sollya_lib_error());
+        }
+        strncpy(expressionWithSemiCo, expression, i + 1);
+        expressionWithSemiCo[i + 1] = ';';
+        expressionWithSemiCo[i + 2] = '\0';
+        expressionSa = sollya_lib_parse_string(expressionWithSemiCo);
+        free(expressionWithSemiCo);
+        return(expressionSa);
+      } /* End character != ';' and from a blank. */
+    /* Create a new string for the expression, add the ";" and
+     * and call sollya_lib_parse_string. */
+    } /* End else. */
+  } /* End for. */
+  /* We get here, it is because we did not find any char == anything different
+   * from ' ' or '\t': the string is empty.
+   */
+  pobyso_error_message("pobyso_parse_string",
+                       "ONLY_BLANK_ARGUMENT",
+                        "The expression is only made of blanks");
+  return(sollya_lib_error());
+
 } /* pobyso_parse_string */
 
-void
-pobyso_set_verbosity_off(sollya_obj_t* currentVerbosityLevel)
+sollya_verbosity_t
+pobyso_set_verbosity_off()
 {
   sollya_obj_t verbosityLevelZero;
-  if (currentVerbosityLevel != NULL)
-  {
-     *currentVerbosityLevel = sollya_lib_get_verbosity();
-  }
+  sollya_obj_t currentVerbosityLevel = NULL;
+
+  currentVerbosityLevel = sollya_lib_get_verbosity();
   verbosityLevelZero = sollya_lib_constant_from_int(0);
   sollya_lib_set_verbosity(verbosityLevelZero);
   sollya_lib_clear_obj(verbosityLevelZero);
+  return(currentVerbosityLevel);
 } /* End of pobyso_set_verbosity_off. */
 
-void
+sollya_verbosity_t
 pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel)
 {
   if (newVerbosityLevel == NULL)
@@ -105,7 +228,7 @@
     pobyso_error_message("pobyso_set_verbosity_to",
                         "NULL_POINTER_ARGUMENT",
                         "The new verbosity level is a NULL pointer");
-    return;
+    return(sollya_lib_error());
   }
   sollya_lib_set_verbosity(newVerbosityLevel);
 } /* End of pobyso_set_verbosity_to. */
