Пример #1
0
static vhandle DoSetVariable( vhandle var_handle, const char *strval, char *vbl_name )
/************************************************************************************/
{
    a_variable  *tmp_variable;

    if( strval == NULL ) {
        strval = "";
    }
    if( var_handle != NO_VAR ) {
        tmp_variable = &GlobalVarList[var_handle];
        if( tmp_variable->has_value ) {
            if( strcmp( tmp_variable->strval, strval ) == 0 ) {
                if( tmp_variable->hook ) {
                    tmp_variable->hook( var_handle );
                }
                return( var_handle );
            }
            GUIMemFree( tmp_variable->strval );   // free the old string
        }
    } else {
        var_handle = NewVariable( vbl_name );
    }
    tmp_variable = &GlobalVarList[var_handle];
    GUIStrDup( strval, &tmp_variable->strval );
    tmp_variable->has_value = TRUE;
    if( tmp_variable->hook ) {
        tmp_variable->hook( var_handle );
    }
    return( var_handle );
}
Пример #2
0
extern vhandle AddVariable( char *vbl_name )
/******************************************/
{
    vhandle var_handle;

    var_handle = GetVariableByName( vbl_name );
    if( var_handle == NO_VAR )
        var_handle = NewVariable( vbl_name );
    return( var_handle );
}
Пример #3
0
void CallFunction(FunctionCall fc)
{
	int function = GetFunction(fc->function);
	
	switch (function)
	{
		case VAR : NewVariable(fc); break;
		case NMX : NewMatrix(fc); break;
		case ADD : Addition(fc); break;
		case SUB : Substraction(fc); break;
		case MUL : Multiplication(fc); break;
		case MSC : Scalar_Mult(fc); break;
		case EXP : Exponentiation(fc); break;
		case TRA : Transpose(fc); break;
		case DET : Determinant(fc); break;
		case DLU : Decomposition(fc); break;
		case SOL : Solve(fc); break;
		case INV : Inversion(fc); break;
		case RNK : Rank(fc); break;
		case DSP : Display(fc); break;
		case NOF : // default
		default :
		{
			if (GetFunction(fc->name)==SPT) SpeedTest(fc);
			else if (IndexVariable(fc->function)!=-1) NewVariable(fc);
			else if (IndexMatrix(fc->function)!=-1) NewMatrix(fc);
			else
			{
				printf("\t%s : Function Not Implemented\n", fc->function);
				fni++;
			}
			break;
		}
	}
	
	if (function!=NOF && function !=VAR) fni = 0;
}
Пример #4
0
void DFsScript::NewFunction(const char *name, void (FParser::*handler)() )
{
	NewVariable (name, svt_function)->value.handler = handler;
}
Пример #5
0
char *DFsScript::ProcessFindChar(char *datap, char find)
{
	while(*datap)
    {
		if(*datap==find) return datap;
		if(*datap=='\"')       // found a quote: ignore stuff in it
		{
			datap++;
			while(*datap && *datap != '\"')
			{
				// escape sequence ?
				if(*datap=='\\') datap++;
				datap++;
			}
			// error: end of script in a constant
			if(!*datap) return NULL;
		}
		
		// comments: blank out
		
		if(*datap=='/' && *(datap+1)=='*')        // /* -- */ comment
		{
			while(*datap && (*datap != '*' || *(datap+1) != '/') )
			{
				*datap=' '; datap++;
			}
			if(*datap)
				*datap = *(datap+1) = ' ';   // blank the last bit
			else
			{
				// script terminated in comment
				script_error("script terminated inside comment\n");
			}
		}
		if(*datap=='/' && *(datap+1)=='/')        // // -- comment
		{
			while(*datap != '\n')
			{
				*datap=' '; datap++;       // blank out
			}
		}
		
		/********** labels ****************/

		// labels are also found during the
		// preprocessing. these are of the form
		//
		//      label_name:
		//
		// and are used for the goto function.
		// goto labels are stored as variables.

		if(*datap==':' && scriptnum != -1) // not in global scripts
		{
			char *labelptr = datap-1;
			
			while(!isop(*labelptr)) labelptr--;

			FString labelname(labelptr+1, strcspn(labelptr+1, ":"));
			
			if (labelname.Len() == 0)
			{
				Printf(PRINT_BOLD,"Script %d: ':' encountrered in incorrect position!\n",scriptnum);
			}

			DFsVariable *newlabel = NewVariable(labelname, svt_label);
			newlabel->value.i = MakeIndex(labelptr);
		}
		
		if(*datap=='{')  // { -- } sections: add 'em
		{
			DFsSection *newsec = NewSection(datap);
			
			newsec->type = st_empty;
			// find the ending } and save
			char * theend = ProcessFindChar(datap+1, '}');
			if(!theend)
			{                // brace not found
				// This is fatal because it will cause a crash later
				// if the game isn't terminated.
				I_Error("Script %d: section error: no ending brace\n", scriptnum);
			}

			newsec->end_index = MakeIndex(theend);
			// continue from the end of the section
			datap = theend;
		}
		datap++;
    }
	return NULL;
}
Пример #6
0
int
SetVariableValue(char *varName, 
                 char operator,
                 char *varValues)
{
  Variable v;
  char *item;
  FILE *fd;

  if ((v = FindVariable(varName)) == NULL) {

    v = NewVariable(varName);
    
    if (v == NULL) {
      cqpmessage(Error, "Out of memory.");
      return 0;
    }
  }

  switch (operator) {
    
  case '+':                        /* += operator: extend */
    
    item = strtok(varValues, " \t\n");
    while (item) {
      VariableAddItem(v, item);
      item = strtok(NULL, " \t\n");
    }

    break;

  case '-':                        /* -= operator: substract */

    item = strtok(varValues, " \t\n");
    while (item) {
      VariableSubtractItem(v, item);
      item = strtok(NULL, " \t\n");
    }

    break;

  case '=':                        /* = operator: absolute setting */

    VariableDeleteItems(v);

    item = strtok(varValues, " \t\n");
    while (item) {
      VariableAddItem(v, item);
      item = strtok(NULL, " \t\n");
    }
    break;

  case '<':                        /* < operator: read from file */

    VariableDeleteItems(v);

    if ((fd = open_file(varValues, "r"))) {
      
      int l;
      char s[CL_MAX_LINE_LENGTH];

      while (fgets(s, CL_MAX_LINE_LENGTH, fd) != NULL) {

        l = strlen(s);

        if (l > 0 && s[l-1] == '\n') {

          /* strip trailing newline */
          s[l-1] = '\0'; l--;
        }

        if (l > 0)
          VariableAddItem(v, s);
      }
      fclose(fd);
    }
    else {
      perror(varValues);
      cqpmessage(Warning, "Can't open %s: no such file or directory",
                 varValues);
      return 0;
    }
    break;
    
  default:
    return 0;
    break;
  }

  return 1;
}