Exemple #1
0
bool FileVarsGetIdentifier(FileVars_p vars, char* name,  char **value)
{
   StrTree_p cell = StrTreeFind(&(vars->vars), name);
   Scanner_p in;

   if(!cell)
   {
      return false;
   }
   
   in = CreateScanner(StreamTypeInternalString, cell->val1.p_val,
		      true, NULL);
   if(!TestInpTok(in, Identifier))
   {
      DStr_p errpos = DStrAlloc();

      DStrAppendStr(errpos, 
		    "Identifier value requested for file variable ");
      DStrAppendStr(errpos, name);
      DStrAppendStr(errpos, "read from \"");
      DStrAppendStr(errpos, cell->val2.p_val);
      DStrAppendStr(errpos, 
		    "\", but no such value present.");
      Error(DStrView(errpos), SYNTAX_ERROR);
      DStrFree(errpos);
   }      
   DestroyScanner(in);
   *value = cell->val1.p_val;
   
   return true;
}
Exemple #2
0
bool FileVarsGetBool(FileVars_p vars, char* name, bool *value)
{
   StrTree_p cell = StrTreeFind(&(vars->vars), name);
   
   if(!cell)
   {
      return false;
   }
   if(strcmp(cell->val1.p_val, "true"))
   {
      *value = true;
   }
   else if(strcmp(cell->val1.p_val, "false"))
   {
      *value = false;
   }
   else
   {
      DStr_p errpos = DStrAlloc();

      DStrAppendStr(errpos, 
		    "Boolean value requested for file variable ");
      DStrAppendStr(errpos, name);
      DStrAppendStr(errpos, "read from \"");
      DStrAppendStr(errpos, cell->val2.p_val);
      DStrAppendStr(errpos, 
		    "\", but no boolean value present.");
      Error(DStrView(errpos), SYNTAX_ERROR);
      DStrFree(errpos);
   }   
   return true;
}
ExampleRep_p  ExampleSetFindName(ExampleSet_p set, char* name)
{
   StrTree_p handle;

   handle = StrTreeFind(&(set->name_index), name);
   if(!handle)
   {
      return NULL;
   }
   return handle->val1.p_val;
}
Exemple #4
0
Term_p VarBankExtNameFind(VarBank_p bank, char* name)
{
   StrTree_p entry;
   
   entry = StrTreeFind(&(bank->ext_index), name);
   
   if(entry)
   {
      return entry->val1.p_val;
   }
   return NULL;
}
Exemple #5
0
bool FileVarsGetStr(FileVars_p vars, char* name,  char **value)
{
   StrTree_p cell = StrTreeFind(&(vars->vars), name);

   if(!cell)
   {
      return false;
   }
   
   *value = cell->val1.p_val;

   return true;
}
bool ExampleSetDeleteName(ExampleSet_p set, char* name)
{
   ExampleRep_p handle;
   StrTree_p    cell;

   cell = StrTreeFind(&(set->name_index), name);
   if(!cell)
   {
      return false;
   }
   handle = ExampleSetExtract(set, cell->val1.p_val);
   assert(handle);
   ExampleRepFree(handle);
   return true;
}
Exemple #7
0
long FileVarsParse(Scanner_p in, FileVars_p vars)
{
   char*     name;
   StrTree_p cell, test;
   long      res = 0;
   DStr_p    value = DStrAlloc();

   assert(!PStackEmpty(vars->names));
   assert(strcmp(PStackTopP(vars->names), DStrView(Source(in))) == 0);
   
   while(!TestInpTok(in, NoToken))
   {
      CheckInpTok(in, Identifier);
      name = DStrCopy(AktToken(in)->literal);
      cell = StrTreeFind(&(vars->vars), name);
      if(cell)
      {
	 FREE(cell->val1.p_val);
      }
      else
      {
	 cell = StrTreeCellAllocEmpty();
	 cell->key = name;
	 cell->val2.p_val = PStackTopP(vars->names);
	 test = StrTreeInsert(&(vars->vars), cell);
	 assert(test == NULL);
      }
      NextToken(in);
      AcceptInpTok(in, EqualSign);

      DStrReset(value);
      while(!TestInpTok(in, Semicolon))
      {
	 DStrAppendDStr(value, AktToken(in)->literal);
	 NextToken(in);
      }
      AcceptInpTok(in, Semicolon);
      cell->val1.p_val = DStrCopy(value);
      res++;
   }
   DStrFree(value);
   return res;
}
Exemple #8
0
bool FileVarsGetInt(FileVars_p vars, char* name,  long *value)
{
   StrTree_p cell = StrTreeFind(&(vars->vars), name);
   char      *eoarg;

   if(!cell)
   {
      return false;
   }
   
   *value = strtol(cell->val1.p_val, &eoarg, 10);

   if(errno || *eoarg)
   {
      DStr_p errpos = DStrAlloc();

      TmpErrno = errno;      
      DStrAppendStr(errpos, 
		    "Integer value requested for file variable ");
      DStrAppendStr(errpos, name);
      DStrAppendStr(errpos, "read from \"");
      DStrAppendStr(errpos, cell->val2.p_val);
      DStrAppendStr(errpos, 
		    "\", but no integer value present.");
      
      if(TmpErrno)
      {
	 SysError(DStrView(errpos), SYNTAX_ERROR);
      }
      else
      {
	 Error(DStrView(errpos), SYNTAX_ERROR);
      }
      DStrFree(errpos);
   }   
   return true;
}