Example #1
0
int Eqv (Object x1, Object x2) {
    register int t1, t2;
    if (EQ(x1, x2))
        return 1;
    t1 = TYPE(x1);
    t2 = TYPE(x2);
    if (Numeric (t1) && Numeric (t2)) {
        /* r4rs 6.2 states that (eqv? 1 1.0) ==> #f */
        if((t1 == T_Flonum && t2 != T_Flonum)
            || (t1 != T_Flonum && t2 == T_Flonum))
            return 0;
        return Generic_Equal (x1, x2);
    }
    if (t1 != t2)
        return 0;
    switch (t1) {
    case T_String:
        return STRING(x1)->size == 0 && STRING(x2)->size == 0;
    case T_Vector:
        return VECTOR(x1)->size == 0 && VECTOR(x2)->size == 0;
    case T_Primitive:
        return strcmp (PRIM(x1)->name, PRIM(x2)->name) == 0;
    default:
        if (t1 < 0 || t1 >= Num_Types)
            Panic ("bad type in eqv");
        if (Types[t1].eqv == NOFUNC)
            return 0;
        return (Types[t1].eqv)(x1, x2);
    }
    /*NOTREACHED*/
}
Example #2
0
int Equal (Object x1, Object x2) {
    register int t1, t2;
    register unsigned int i;

again:
    if (EQ(x1, x2))
        return 1;
    t1 = TYPE(x1);
    t2 = TYPE(x2);
    if (Numeric (t1) && Numeric (t2))
        return Generic_Equal (x1, x2);
    if (t1 != t2)
        return 0;
    switch (t1) {
    case T_Boolean:
    case T_Character:
    case T_Compound:
    case T_Control_Point:
    case T_Promise:
    case T_Port:
    case T_Macro:
        return 0;
    case T_Primitive:
    case T_Environment:
        return Eqv (x1, x2);
    case T_Symbol: {
        struct S_Symbol *p1 = SYMBOL(x1), *p2 = SYMBOL(x2);
        return Equal (p1->name, p2->name) && Equal (p1->plist, p2->plist);
    }
    case T_Pair:
        if (!Equal (Car (x1), Car (x2)))
            return 0;
        x1 = Cdr (x1); x2 = Cdr (x2);
        goto again;
    case T_String: {
        struct S_String *p1 = STRING(x1), *p2 = STRING(x2);
        return p1->size == p2->size &&
            memcmp (p1->data, p2->data, p1->size) == 0;
    }
    case T_Vector: {
        struct S_Vector *p1 = VECTOR(x1), *p2 = VECTOR(x2);
        if (p1->size != p2->size)
            return 0;
        for (i = 0; i < p1->size; i++)
            if (!Equal (p1->data[i], p2->data[i]))
                return 0;
        return 1;
    }
    default:
        if (t1 < 0 || t1 >= Num_Types)
            Panic ("bad type in equal");
        if (Types[t1].equal == NOFUNC)
            return 0;
        return (Types[t1].equal)(x1, x2);
    }
    /*NOTREACHED*/
}
Example #3
0
static  void    AsnVal( PTYPE var_type ) {
//======================================

// Do data initialization.

    bool        issue_err;

    issue_err = ( DtFlags & DT_NO_MORE_CONSTS ) == 0;
    GetDataConst();
    if( DtFlags & DT_NO_MORE_CONSTS ) {
        if( issue_err ) {
            Error( DA_NOT_ENOUGH );
        }
    } else if( ( DtConstType == PT_NOTYPE ) ||
        ( ( var_type <= PT_LOG_4 ) && ( DtConstType <= PT_LOG_4 ) ) ||
        ( DtConstType == PT_CHAR ) ||
        ( ( var_type == PT_CHAR ) && IntType( DtConstType ) ) ||
        ( Numeric( var_type ) && Numeric( DtConstType ) ) ) {
        DoDataInit( var_type );
    } else {
        TypeNameTypeErr( DA_TYPE_MISMATCH, MapType[ var_type ], InitVar, MapType[ DtConstType ] );
    }
}
Example #4
0
	NumericFieldDef(const std::string &name, unsigned int size, unsigned int prec) :
			DB::FieldDef(name), m_default_value(Numeric(size, prec)), m_size(size), m_prec(prec) {
		validate(size, prec);
	}
Example #5
0
Numeric sqrt(Numeric n){
    long _num = sqrt(n.getNum());
    long _den = sqrt(n.getDen());
    return Numeric(_num,_den);
}
Example #6
0
Numeric fabs(Numeric n){
    long _num = fabs(n.getNum());
    long _den = fabs(n.getDen());
    return Numeric(_num,_den);
}
Example #7
0
File: HTTP.c Project: sonite/mGit
/*********************************************************************
 * Serve a single connection
 ********************************************************************/
static void HTTP_Process(BOOL available)
{
    BYTE error;
	const struct HTTP_FileContent rom *content;

retry:
	switch(HTTP.StateMachine)
	{
	// Introduced explicit disconnect state handling in order to properly
	// finish all queries
	case SM_HTTP_IDLE:
		// Connections closed for any reason will automatically end up in
		// the disconnected state, so this is a good place to make sure
		// we don't leak files.
		if(HTTP.file)
		{
			FSfclose(HTTP.file);
			HTTP.file = NULL;
		}

		// Just wait for any connection to be made
		if(!TCPIsConnected(HTTP.socket))
			// Don't break for new connections.  There may be 
 			// an entire request in the buffer already.
			return;
		
		HTTP.StateMachine = SM_HTTP_PARSE_REQUEST;
		
		// Adjust the TCP FIFOs for optimal reception of 
		// the next HTTP request from the browser
		///while(!TCPAdjustFIFOSize(HTTP.socket, 1, 0, TCP_ADJUST_PRESERVE_RX | TCP_ADJUST_GIVE_REST_TO_RX));
		// Fallthrough
		// .
		// .
		// .
	case SM_HTTP_PARSE_REQUEST:
		// Verify the entire first line is in the FIFO and
		if(!HTTP_SetBuf(-1))
			break;

		// Check that the file system is mounted
		error = HTTP_ERR_NOT_AVAILABLE;

		if(available)
		{
			// Parse the request line
			error = HTTP_ERR_NOT_IMPLEMENTED;
			// Parses the first line for a file name and GET args 
			if(HTTP_Parse())
			{				
				static char read[] = FS_READ;
				
				error = HTTP_ERR_NOT_FOUND;
				// Open the file
				if(HTTP.file = FSfopen(HTTP_ParseName, read), HTTP.file)
					// Success!
					goto retry;
			}
		}

		HTTP.FileType = error;
		HTTP.StateMachine = SM_HTTP_ERROR;

		// Fallthrough
		// .
		// .
		// .
	case SM_HTTP_ERROR:
		if(TCPIsPutReady(HTTP.socket) >= strlenpgm((const char far rom *) HTTP_Errors[HTTP.FileType]))
		{
			TCPPutROMString(HTTP.socket, (ROM BYTE *) HTTP_Errors[HTTP.FileType]);
			TCPFlush(HTTP.socket);
			TCPDisconnect(HTTP.socket);
			HTTP.StateMachine = SM_HTTP_IDLE;
		}
		break;

	// Parse out the POST header lines
	case SM_HTTP_POST_HEADER:
		// Is the next line ready yet?
		while(HTTP_SetBuf(-1))
		{
			char ch;

			// Isolate the field name
			HTTP_Buffer.write = HTTP_Data;

			do
			{
				ch = HTTP_GetBuf();

				// The payload starts after the first empty line
				if(ch == '\0')
				{
					HTTP.StateMachine = SM_HTTP_POST_ARGUMENTS;
					goto retry;
				}

				HTTP_PutBuf(ch);
			}
			while(ch != ' ');

			HTTP_PutBuf('\0');

			// The content length is needed to know the length of the variable block
			if(!Cfg_StringCompare(HTTP_Data, (const char ROM *) HTTP_CONTENT_LENGTH_STRING))
			{
				unsigned int len = 0;

				while(ch = HTTP_GetBuf() - '0', (unsigned char) ch <= 9)
				{
					len *= 10;
					len += ch;
				}

				HTTP.length = len;
			}
		}
		break;

	case SM_HTTP_POST_ARGUMENTS:
		if(!HTTP_SetBuf(HTTP.length))
			break;

		if(HTTP_ParseAttribs())
		{
			Microchip_RefreshSettings();
			Microchip_RestoreSPI();
		};

		HTTP.StateMachine = SM_HTTP_PARSE_HEADERS;

		// Fallthrough
		// .
		// .
		// .
	case SM_HTTP_PARSE_HEADERS:
		content = &HTTP_FileContent[HTTP.FileType];
		
		// Write response string
		TCPPutROMString(HTTP.socket, HTTP_OK_STRING);
		TCPPutROMString(HTTP.socket, (ROM BYTE *) content->mime);

		// Generic cache control mechanism
		TCPPutROMString(HTTP.socket, content->cache ? HTTP_NL_DO_CACHE_STRING : HTTP_NL_NO_CACHE_STRING);

		//  Generate the content-length field so that dismount errors can be detected
		HTTP.dynamic = content->dynamic;

		if(!HTTP.dynamic)
		{
			Numeric(Num_Buffer, HTTP.file->size);
			TCPPutROMString(HTTP.socket, HTTP_NL_CONTENT_LENGTH_STRING);
			TCPPutString(HTTP.socket, (BYTE *) Num_Buffer);
		}

		TCPPutROMString(HTTP.socket, HTTP_NL_HEADER_END_STRING);

		HTTP.StateMachine = SM_HTTP_PROCESS_GET;

		// Fallthrough
		// .
		// .
		// .
	case SM_HTTP_PROCESS_GET:
		// Throw away any more data receieved - we aren't going to use it.
		TCPDiscard(HTTP.socket);

		if(HTTP_SendFile())
		{
			TCPFlush(HTTP.socket);
			TCPDisconnect(HTTP.socket);
			HTTP.StateMachine = SM_HTTP_IDLE;
		}
		break;
	}

	// Flush out any remaining line-buffered data
	HTTP_FlushBuf();

	// If, during handling of HTTP socket, it gets disconnected then forget
	// about any previous processing and return to the idle state.
	//
	// Do wait until as much processing as possible has been completed on
	// whatever data remains in the buffers however
	if(!TCPIsConnected(HTTP.socket))
		HTTP.StateMachine = SM_HTTP_IDLE;
}