Example #1
0
//--------------------------------------------------------------
void processPoint(const String& point, Uint32& v, Uint32& vt, Uint32& vn)
{
	Uint32 occ = point.countOccurrence('/');

	switch(occ)
	{
	case 0:
		sscanf(point.getValue(), "%u", &v);
		vt = 1;
		vn = 1;
	break;
	case 1:
		sscanf(point.getValue(), "%u/%u", &v, &vt);
		vn = 1;
	break;
	case 2:
		if(point.getChar(point.find('/')+1) == '/') // find "//" pattern
		{
			sscanf(point.getValue(), "%u//%u", &v, &vn);
			vt = 1;
		}
		else
		{
			sscanf(point.getValue(), "%u/%u/%u", &v, &vt, &vn);
		}
	break;
	default:
		fprintf(stdout, "wut?\n");
	break;
	}
}
Example #2
0
String String::operator+(String other)
{
  if (this == &other)
    return *this;
  append(other.getValue());
  return *this;
};
Example #3
0
const char *CyberNet::URLGetRelativeURL(const char *uri, std::string &buf, bool withParam)
{
	buf = uri;
	CyberUtil::String urlStr = uri;
	if (IsAbsoluteURL(uri) == false) {
		if (0 < urlStr.length() && urlStr.charAt(0) != '/') {
			buf = "/";
			buf += uri;
		}
	}
	else {
			URL url(uri);
			buf = url.getPath();
			if (withParam == true) {
				String queryStr = url.getQuery();
				if (!queryStr.equals("")){
					buf += "?";
					buf += queryStr.getValue();
				}
			}
			if (urlStr.endsWith("/")) {
				String substrBuf;
				buf = urlStr.substring(0,urlStr.length()-1, substrBuf);
			}
	}
	return buf.c_str();
}
Example #4
0
VOID MDIFrame::onOpen() {
  String tmpfile;
  OPENFILENAME l={sizeof(l),};
  l.lpstrFilter = "Image Files\0*.png;*.jpg\0";
  char *temp = (char *)GlobalAlloc(GMEM_FIXED,4096);
  temp[0] = 0;
  l.lpstrFile = temp;
  l.nMaxFile = 4095;
  l.lpstrTitle = "Load Image";
  l.lpstrDefExt = "";
  l.Flags = OFN_EXPLORER;
  if (GetOpenFileName(&l)) {
    tmpfile = temp;
  } else {
    GlobalFree(temp);
    return;
  }
  GlobalFree(temp);
  Bitmap *bmp = new Bitmap(tmpfile);
  if (bmp->isInvalid()) {
    MessageBox(gethWnd(), StringPrintf("Error loading %s", tmpfile.getValue()), "Error", 16);
    delete bmp;
  } else {
    MDIChild *child = new MDIChild(this, bmp);
    child->setName(tmpfile);
    child->setIcon(IDI_MDICHILD);
    addMDIChild(child); // self registers
  }
}
Example #5
0
String String::operator=(String other)
{
  if (this == &other)
    return *this;
  setValue(other.getValue());
  return *this;
};
Example #6
0
	// print()
	//
	Object *print( Interpreter *interpreter, Scope *scope, List *parameters )
	{

		if ( parameters->getLength() != 1 )
		{

			setRuntimeError( ERROR_FUNCTION_TAKES_X_PARAMETERS, "print", 1, parameters->getLength() );
			return 0;
		}

		Object *parameter = parameters->getElementInt( 0 ); // new reference

		// convert to string - relies on the fact that there is valid default
		//  behaviour for this call
		String *string = parameter->toString(); // new reference

		std::cout << string->getValue() << std::endl;

        // clean up
		parameter->decRef();
		string->decRef();

		none->addRef();
		return none;
	}
Example #7
0
const char *WildcharsEnumerator::enumFile(int n) {
  String path = finddatalist.enumItem(n)->path;
  if (!path.isempty()) {
    enumFileString.printf("%s%s", path.getValue(), finddatalist.enumItem(n)->filename.getValue());
    return enumFileString;
  }
  return finddatalist.enumItem(n)->filename;
}
Example #8
0
int XmlApi::xmlreader_loadFile(const char *filename, XmlReaderCallback *only_this_object) {
  if (filename == NULL) return 0;
  String path;
  if(STRSTR(filename,"/") || STRSTR(filename,"\\")) {
    path=filename;
    char *p=(char *)path.getValue();
    *((char *)Std::scanstr_back(p,"/\\",p)+1)=0;
  }
  return XmlReader::loadFile(Std::filename(filename), path.vs(), only_this_object);
}
Example #9
0
const char *WasabiVersion::getVersionString() {
  if (appname.isempty()) appname="";
  if (version_string.isempty()) {
    if (!appname.isempty())
      version_string = appname.getValue();
    if (STRLEN(WASABI_VERSION)) {
      version_string.cat(" ");
      version_string.cat(WASABI_VERSION);
    }
  }
  return version_string;
}
Example #10
0
void Struct::read(Connection &stream)
  throw(ObjectCreationException, IOException) {
  uint32_t u32Length;

  stream >> u32Length;

  for (uint32_t i = 0; i < u32Length; i++) {
    String keyString;
    stream >> keyString;
    uint8_t u8TypeID;
    stream >> u8TypeID;
    const Object *objectPtr = TypesFactory::createObject(u8TypeID);
    stream >> (Object&)*objectPtr;
    mStructMap[keyString.getValue()] = objectPtr;
  }
}
Example #11
0
	// hasKey()
	//
	Object *hasKey( Interpreter *interpreter, Scope *scope, List *parameters )
	{

		if ( parameters->getLength() != 2 )
		{

            setRuntimeError( ERROR_FUNCTION_TAKES_X_PARAMETERS, "hasKey", 2, parameters->getLength() );
			return 0;
		}

		Object *parameter = parameters->getElementInt( 0 ); // new reference
		Map *map = dynamic_cast< Map * >( parameter ); // steals reference
		if ( !map )
		{

            // clean up
            parameter->decRef();

            setRuntimeError( ERROR_PARAMETER_X_MUST_BE_TYPE_Y, "hasKey", 1, "map" );
			return 0;
		}

		parameter = parameters->getElementInt( 1 ); // new reference
		String *key = dynamic_cast< String * >( parameter ); // steals reference
		if ( !key )
		{

            // clean up
            map->decRef();
            parameter->decRef();

            setRuntimeError( ERROR_PARAMETER_X_MUST_BE_TYPE_Y, "hasKey", 2, "string" );
			return 0;
		}

		Object *result;
		if ( map->hasKey( key->getValue() ) )
			result = new Integer( 1 ); // new reference
		else
			result = new Integer( 0 ); // new reference

        // clean up
        map->decRef();
        key->decRef();

		return result;
	}
Example #12
0
	// systemCall()
	//
	Object *systemCall( Interpreter *interpreter, Scope *scope, List *parameters )
	{

		if ( parameters->getLength() != 1 )
		{

			setRuntimeError( ERROR_FUNCTION_TAKES_X_PARAMETERS, "system", 1, parameters->getLength() );
			return 0;
		}

		Object *parameter = parameters->getElementInt( 0 ); // new reference
		String *string = parameter->toString(); // new reference

		int ret = system( ( string->getValue() ).c_str() );

        // clean up
		string->decRef();
		parameter->decRef();

		return new Integer( ret ); // new reference
	}
Example #13
0
void TimeFmt::printCustom(int sec, const char *buf, int bufsize, const char *str_sep, const char *str_seconds, const char *str_minutes, const char *str_hours, const char *str_days) {
  if (buf == NULL || bufsize == 0) return;
  char *p = (char *)buf;
  *p = 0;
  int days, hours, minutes;
  String s;

  if (str_days) {
    days = sec / (3600*24);
    sec -= days * (3600*24);
    if (days != 0) {
      s += StringPrintf("%d%s", days, str_days);
    }
  }
  if (str_hours) {
    hours = sec / 3600;
    sec -= hours * 3600;
    if (hours != 0) {
      if (!s.isempty()) s += str_sep;
      s += StringPrintf("%d%s", hours, str_hours);
    }
  }
  if (str_minutes) {
    minutes = sec / 60;
    sec -= minutes * 60;
    if (minutes != 0) {
      if (!s.isempty()) s += str_sep;
      s += StringPrintf("%d%s", minutes, str_minutes);
    }
  }
  if (str_seconds) {
    if (sec != 0) {
      if (!s.isempty()) s += str_sep;
      s += StringPrintf("%d%s", sec, str_seconds);
    }
  }
  STRNCPY(p, s.getValue(), bufsize);
  int l = s.len();
  if (l < bufsize) p[l] = 0;
}
Example #14
0
	// eval()
	//
	Object *eval( Interpreter *interpreter, Scope *scope, List *parameters )
	{

		if ( parameters->getLength() != 1 )
		{

            setRuntimeError( ERROR_FUNCTION_TAKES_X_PARAMETERS, "eval", 1, parameters->getLength() );
			return 0;
		}

		Object *parameter = parameters->getElementInt( 0 ); // new reference
		String *code = parameter->toString(); // new reference
		if ( !code )
		{

            // clean up
            parameter->decRef();

			return 0; // error already set
		}

		bool ret = interpreter->eval( code->getValue() );
		if ( !ret )
		{

            // clean up
            parameter->decRef();
			code->decRef();

			return 0; // error already set
		}

        // clean up
        parameter->decRef();
		code->decRef();

		none->addRef();
		return none;
	}
const char *uHTTP::HTTPHeaderGetValue(LineNumberReader *reader, const std::string &name, std::string &buf) {
  buf = "";
  String bigName = name;
  bigName.toUppderCase();
  const char *lineStr = reader->readLine();
  while (lineStr != NULL && 0 < StringLength(lineStr)) {
    HTTPHeader header(lineStr);
    if (header.hasName() == false) {
       lineStr = reader->readLine();
      continue;
    }
    String bigLineHeaderName(header.getName());
    bigLineHeaderName.toUppderCase();
    // Thanks for Jan Newmarch <*****@*****.**> (05/26/04)
    if (bigLineHeaderName.equals(bigName.getValue()) == false) {
       lineStr = reader->readLine();
       continue;
    }
    buf = header.getValue();
    break;
  }
  return buf.c_str();
}
Example #16
0
std::vector<Jumpropes::NetInterface> Jumpropes::ListNetworkInterfaces()
{
   std::vector<Jumpropes::NetInterface> List;

   String Computername;
   if (!TryToGetComputerName(&Computername))
   {
      return List;
   }

   struct addrinfo hints, *ifa;
   int err;

   memset(&hints, 0, sizeof(hints));
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_family = AF_INET;

   if ((err = getaddrinfo(Computername.getValue(), NULL, &hints, &ifa)) != 0) {
      return List;
   }

   for (; ifa != NULL; ifa = ifa->ai_next) {
      if (ifa->ai_addr == NULL)
         continue;

      Jumpropes::NetInterface netif;
      netif.Name = "";// ifa->ai_canonname;

      SetAndResolveIP(&netif.IP, ifa->ai_addr);

      List.push_back(netif);
   }

   freeaddrinfo(ifa);

   return List;
}
Example #17
0
Variable* assign(Variable* A, Variable* B)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in assignment.\n");
        return NULL;
    }
    if(!A->reference)
    {
        interpreter.error("Error: Assigning value to a non-reference variable.\n");
        return NULL;
    }

    TypeEnum a = A->getType();
    TypeEnum b = B->getType();

    bool mismatch = false;
    if(a == STRING)
    {
        if(b != STRING)
            mismatch = true;
        else
        {
            String* C = static_cast<String*>(A);
            String* D = static_cast<String*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == INT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Int* C = static_cast<Int*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(D->getValue());
            }
        }
    }
    else if(a == FLOAT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Float* C = static_cast<Float*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(D->getValue());
            }
        }
    }
    else if(a == BOOL)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Bool* C = static_cast<Bool*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(D->getValue());
            }
        }
    }
    else if(a == MACRO)
    {
        if(b != MACRO)
            mismatch = true;
        else
        {
            Macro* C = static_cast<Macro*>(A);
            Macro* D = static_cast<Macro*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == ARRAY)
    {
        if(b != ARRAY)
            mismatch = true;
        else
        {
            Array* C = static_cast<Array*>(A);
            Array* D = static_cast<Array*>(B);
            a = C->getValueType();
            b = D->getValueType();
            if(a != b)
            {
                interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
                return NULL;
            }
            C->setValue(D->getValue());
        }
    }
    else if(a == LIST)
    {
        if(b != LIST)
            mismatch = true;
        else
        {
            List* C = static_cast<List*>(A);
            List* D = static_cast<List*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == FUNCTION)
    {
        if(b != FUNCTION)
            mismatch = true;
        else
        {
            Function* C = static_cast<Function*>(A);
            Function* D = static_cast<Function*>(B);
            C->setValue(D->getValue());
        }
    }
    else if(a == PROCEDURE)
    {
        if(b != PROCEDURE)
            mismatch = true;
        else
        {
            Procedure* C = static_cast<Procedure*>(A);
            Procedure* D = static_cast<Procedure*>(B);
            C->setValue(D->getValue());
        }
    }

    if(mismatch)
    {
        interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    return A;
}
Example #18
0
Bool* comparison(Variable* A, Variable* B, OperatorEnum oper)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in assignment.\n");
        return NULL;
    }
    TypeEnum a = A->getType();
    TypeEnum b = B->getType();


    bool mismatch = false;
    if(a == STRING)
    {
        if(b != STRING)
            mismatch = true;
        else
        {
            String* C = static_cast<String*>(A);
            String* D = static_cast<String*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == INT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Int* C = static_cast<Int*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
        }
    }
    else if(a == FLOAT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Float* C = static_cast<Float*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
        }
    }
    else if(a == BOOL)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Bool* C = static_cast<Bool*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                switch(oper)
                {
                    case EQUALS:
                        return new Bool(C->getValue() == D->getValue());
                    case NOT_GREATER:
                    case LESS_EQUAL:
                        return new Bool(C->getValue() <= D->getValue());
                    case NOT_LESS:
                    case GREATER_EQUAL:
                        return new Bool(C->getValue() >= D->getValue());
                    case LESS:
                        return new Bool(C->getValue() < D->getValue());
                    case GREATER:
                        return new Bool(C->getValue() > D->getValue());
                    case AND:
                        return new Bool(C->getValue() && D->getValue());
                    case OR:
                        return new Bool(C->getValue() || D->getValue());
                    case NOT_EQUALS:
                        return new Bool(C->getValue() != D->getValue());
                    default:
                        UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                        return NULL;
                }
            }
        }
    }
    else if(a == MACRO)
    {
        if(b != MACRO)
            mismatch = true;
        else
        {
            Macro* C = static_cast<Macro*>(A);
            Macro* D = static_cast<Macro*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == ARRAY)
    {
        if(b != ARRAY)
            mismatch = true;
        else
        {
            Array* C = static_cast<Array*>(A);
            Array* D = static_cast<Array*>(B);
            a = C->getValueType();
            b = C->getValueType();
            if(a != b)
            {
                interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
                return NULL;
            }

            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == LIST)
    {
        if(b != LIST)
            mismatch = true;
        else
        {
            List* C = static_cast<List*>(A);
            List* D = static_cast<List*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == FUNCTION)
    {
        if(b != FUNCTION)
            mismatch = true;
        else
        {
            Function* C = static_cast<Function*>(A);
            Function* D = static_cast<Function*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }
    else if(a == PROCEDURE)
    {
        if(b != PROCEDURE)
            mismatch = true;
        else
        {
            Procedure* C = static_cast<Procedure*>(A);
            Procedure* D = static_cast<Procedure*>(B);
            switch(oper)
            {
                case EQUALS:
                    return new Bool(C->getValue() == D->getValue());
                case NOT_GREATER:
                case LESS_EQUAL:
                    return new Bool(C->getValue() <= D->getValue());
                case NOT_LESS:
                case GREATER_EQUAL:
                    return new Bool(C->getValue() >= D->getValue());
                case LESS:
                    return new Bool(C->getValue() < D->getValue());
                case GREATER:
                    return new Bool(C->getValue() > D->getValue());
                case NOT_EQUALS:
                    return new Bool(C->getValue() != D->getValue());
                default:
                    UI_debug_pile("Pile Error: Bad operator passed to comparison().\n");
                    return NULL;
            }
        }
    }

    //if(mismatch)
    {
        interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    return NULL;
}
Example #19
0
void TextFeed::dependent_onRegViewer(DependentViewer *viewer, int add) {
  if (add) {
    for (int i = 0; i < feeds.getNumItems(); i++) {
      String a = feeds.enumIndexByPos(i, String(""));
      Pair<String, String> sp("","");
      String b = feeds.enumItemByPos(i, sp).a;
      dependent_sendEvent(svc_textFeed::depend_getClassGuid(), Event_TEXTCHANGE, (int)a.getValue(), (void*)b.getValue(), b.len()+1, viewer);//send to this viewer only
    }
  }

  if (add) onRegClient();
  else onDeregClient();
}
Example #20
0
// TODO: rewrite met split()
void JumpropesCommon::HttpHeader::parse( String *sHeader ) {
   int iPosStart;
   int iPosEnd;
   int iValStart;
   int iValLen;
   int iSpacePos;
   String tmp;

   String dbg;

   resetVars();

   int iCrlfLen = strlen(crlf);

   // "HTTP/1.0 301 Moved Permanently\r\n"
   iPosStart = sHeader->pos( 0, httpNeedle, strlen(httpNeedle) );
   if ( iPosStart != -1 ) {
      iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
      if ( iPosEnd == -1 ) {
         iPosEnd = sHeader->getLength();
      }

      iValStart   = iPosStart + strlen( httpNeedle );
      iValLen     = iPosEnd - iValStart;

      tmp.setValue( sHeader->getPointer( iValStart ), iValLen );

      // tmp="1.0 301 Moved Permanently"
      char *ptr = tmp.getValue();

      iSpacePos = tmp.pos( 0, space, strlen(space) );
      ptr[iSpacePos] = 0;
      httpversion = atof( ptr );

      int iStatPos = iSpacePos + 1;
      iSpacePos = tmp.pos( 0, space, strlen(space) );
      ptr[iSpacePos] = 0;
      httpstatus = atoi( tmp.getPointer( iStatPos ) );

      statusstring.setValue( tmp.getPointer( iSpacePos + 1 ), tmp.getLength() - iSpacePos - 1 );
   }

   iPosStart = sHeader->pos( 0, contentLenNeedle, strlen(contentLenNeedle) );
   if ( iPosStart != -1 ) {
      iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
      if ( iPosEnd == -1 ) {
         iPosEnd = sHeader->getLength();
      }

      iValStart   = iPosStart + strlen( contentLenNeedle );
      iValLen     = iPosEnd - iValStart;

      tmp.setValue( sHeader->getPointer( iValStart ), iValLen );

      contentlength = atoi( tmp.getValue() );
   }

   iPosStart = sHeader->pos( 0, contentTypeNeedle, strlen(contentTypeNeedle) );
   if ( iPosStart != -1 ) {
      iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
      if ( iPosEnd == -1 ) {
         iPosEnd = sHeader->getLength();
      }

      iValStart   = iPosStart + strlen( contentTypeNeedle );
      iValLen     = iPosEnd - iValStart;

      tmp.setValue( sHeader->getPointer( iValStart ), iValLen );

      contenttype.setValue( &tmp );
   }

   iPosStart = sHeader->pos( 0, locationNeedle, strlen(locationNeedle) );
   if ( iPosStart != -1 ) {
      iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
      if ( iPosEnd == -1 ) {
         iPosEnd = sHeader->getLength();
      }

      iValStart   = iPosStart + strlen( locationNeedle );
      iValLen     = iPosEnd - iValStart;

      tmp.setValue( sHeader->getPointer( iValStart ), iValLen );

      location.setValue( &tmp );
   }

   iPosStart = sHeader->pos( 0, connectionNeedle, strlen(connectionNeedle) );
   if ( iPosStart != -1 ) {
      iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
      if ( iPosEnd == -1 ) {
         iPosEnd = sHeader->getLength();
      }

      iValStart   = iPosStart + strlen( connectionNeedle );
      iValLen     = iPosEnd - iValStart;

      tmp.setValue( sHeader->getPointer( iValStart ), iValLen );

      connection.setValue( &tmp );
   }

   iPosStart = sHeader->pos( 0, transferencNeedle, strlen(transferencNeedle) );
   if ( iPosStart != -1 ) {
      iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
      if ( iPosEnd == -1 ) {
         iPosEnd = sHeader->getLength();
      }

      iValStart   = iPosStart + strlen( transferencNeedle );
      iValLen     = iPosEnd - iValStart;

      tmp.setValue( sHeader->getPointer( iValStart ), iValLen );

      chunked = tmp.match( chunkedNeedle, strlen(chunkedNeedle) );
   }

   if ( chunked ) {
      contentlength = -1;
   }

   int iSetCookies = 0;
   int iSearchPos = 0;

   iPosStart = 0;
   while ( iPosStart != -1 ) {
      iPosStart = sHeader->pos( iSearchPos, setcookieNeedle, strlen(setcookieNeedle) );
      if ( iPosStart != -1 ) {
         iPosEnd = sHeader->pos( iPosStart, crlf, iCrlfLen );
         if ( iPosEnd == -1 ) {
            iPosEnd = sHeader->getLength();
         }

         iSearchPos = iPosEnd + strlen(crlf);

         iValStart   = iPosStart + strlen( setcookieNeedle );
         iValLen     = iPosEnd - iValStart;

         iSetCookies++;
         tmp.setValue( sHeader->getPointer( iValStart ), iValLen );
         String *cookie = new String();
         cookie->setValue( &tmp );
         cookies.addElement( cookie );
      }
   }
}
Example #21
0
Variable* add_assign(Variable* A, Variable* B)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in assignment.\n");
        return NULL;
    }
    if(!A->reference)
    {
        interpreter.error("Error: Assigning value to a non-reference variable.\n");
        return NULL;
    }

    TypeEnum a = A->getType();
    TypeEnum b = B->getType();

    bool mismatch = false;
    if(a == STRING)
    {
        if(b != STRING)
            mismatch = true;
        else
        {
            String* C = static_cast<String*>(A);
            String* D = static_cast<String*>(B);
            C->setValue(C->getValue() + D->getValue());
        }
    }
    else if(a == INT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Int* C = static_cast<Int*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
        }
    }
    else if(a == FLOAT)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Float* C = static_cast<Float*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
        }
    }
    else if(a == BOOL)
    {
        if(b != BOOL && b != INT && b != FLOAT)
            mismatch = true;
        else
        {
            Bool* C = static_cast<Bool*>(A);
            if(b == BOOL)
            {
                Bool* D = static_cast<Bool*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else if(b == INT)
            {
                Int* D = static_cast<Int*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
            else
            {
                Float* D = static_cast<Float*>(B);
                C->setValue(C->getValue() + D->getValue());
            }
        }
    }
    else if(a == MACRO)
    {
        interpreter.error("Error: Addition operation not defined for type 'macro'.\n");
        return NULL;
    }
    else if(a == ARRAY)
    {
        if(b == ARRAY)
        {
            Array* C = static_cast<Array*>(A);
            Array* D = static_cast<Array*>(B);
            a = C->getValueType();
            b = C->getValueType();
            if(a != b)
            {
                interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
                return NULL;
            }
            C->push_back(D->getValue());
        }
        else
        {
            Array* C = static_cast<Array*>(A);
            if(b == C->getValueType())
            {
                C->push_back(B);
            }
            else
                mismatch = true;
        }
    }
    else if(a == LIST)
    {
        // Lists must be concatenated a different way...
        List* C = static_cast<List*>(A);
        C->push_back(B);
    }
    else if(a == FUNCTION)
    {
        interpreter.error("Error: Addition operation not defined for type 'function'.\n");
        return NULL;
    }
    else if(a == PROCEDURE)
    {
        interpreter.error("Error: Addition operation not defined for type 'procedure'.\n");
        return NULL;
    }

    if(mismatch)
    {
        interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    return A;
}
Example #22
0
void Socket::Write(String data) {
    if(send(this->socket_, data.getValue().c_str(), data.getValue().size(), 0) < 0){
        throw SocketException("Erro ao escrever no Socket.");
    }
}
Example #23
0
Variable* add(Variable* A, Variable* B)
{
    if(A == NULL || B == NULL)
    {
        interpreter.error("Error: Void variable in addition.\n");
        return NULL;
    }
    TypeEnum a = A->getType();
    TypeEnum b = B->getType();
    if(a != b && !(a == FLOAT && b == INT) && !(b == FLOAT && a == INT))
    {
        interpreter.error("Error: Types do not match in addition: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str());
        return NULL;
    }
    if(a == STRING)
    {
        String* C = static_cast<String*>(A);
        String* D = static_cast<String*>(B);
        String* R = new String("<temp>");
        R->setValue(C->getValue() + D->getValue());
        return R;
    }
    else if(a == INT)
    {
        Int* C = static_cast<Int*>(A);
        if(b == INT)
        {
            Int* D = static_cast<Int*>(B);
            Int* R = new Int;
            R->setValue(C->getValue() + D->getValue());
            return R;
        }
        else
        {
            Float* D = static_cast<Float*>(B);
            Float* R = new Float;
            R->setValue(C->getValue() + D->getValue());
            return R;
        }
    }
    else if(a == FLOAT)
    {
        Float* C = static_cast<Float*>(A);
        Float* R = new Float;

        if(b == INT)
        {
            Int* D = static_cast<Int*>(B);
            R->setValue(C->getValue() + D->getValue());
        }
        else
        {
            Float* D = static_cast<Float*>(B);
            R->setValue(C->getValue() + D->getValue());
        }
        return R;
    }
    else if(a == BOOL)
    {
        interpreter.error("Error: Addition operation not defined for type 'bool'.\n");
        return NULL;
    }
    else if(a == MACRO)
    {
        Macro* C = static_cast<Macro*>(A);
        Macro* D = static_cast<Macro*>(B);
        Macro* R = new Macro;
        R->setValue(C->getValue() + D->getValue());
        return R;
    }
    else if(a == ARRAY)
    {
        Array* C = static_cast<Array*>(A);
        Array* D = static_cast<Array*>(B);
        a = C->getValueType();
        b = D->getValueType();
        if(a != b)
        {
            interpreter.error("Error: Types do not match in addition: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str());
            return NULL;
        }

        vector<Variable*> va = C->getValue();
        vector<Variable*>& vb = D->getValue();

        for(vector<Variable*>::iterator e = vb.begin(); e != vb.end(); e++)
        {
            va.push_back(*e);
        }

        Array* arr = new Array("<temp>", va, a);

        return arr;
    }
    else if(a == LIST)
    {
        List* C = static_cast<List*>(A);
        List* D = static_cast<List*>(B);
        list<Variable*> va = C->getValue();
        list<Variable*>& vb = D->getValue();

        for(list<Variable*>::iterator e = vb.begin(); e != vb.end(); e++)
        {
            va.push_back(*e);
        }

        List* lst = new List("<temp>", va);

        return lst;
    }
    else if(a == FUNCTION)
    {
        Function* C = static_cast<Function*>(A);
        Function* D = static_cast<Function*>(B);
        Function* R = new Function("<temp>", FN_NONE);
        R->setValue(C->getValue() + D->getValue());
        return R;
    }
    else if(a == PROCEDURE)
    {
        Procedure* C = static_cast<Procedure*>(A);
        Procedure* D = static_cast<Procedure*>(B);
        Procedure* R = new Procedure("<temp>");
        R->setValue(C->getValue() + D->getValue());
        return R;
    }
    return A;
}
Example #24
0
//--------------------------------------------------------------
String::String(const String& other)
{
	setValue(other.getValue());
}