Beispiel #1
0
//--------------------------------------------------------------------------------------------------
static void ParseValue
(
    Parser_t* parserPtr,
    char c
)
//--------------------------------------------------------------------------------------------------
{
    // Throw away whitespace until something else comes along.
    if (!isspace(c))
    {
        if (c == '{')   // Start of an object.
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_OBJECT, GetEventHandler(parserPtr));
            parserPtr->next = EXPECT_MEMBER_OR_OBJECT_END;
            Report(parserPtr, LE_JSON_OBJECT_START);
        }
        else if (c == '[')  // Start of an array.
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_ARRAY, GetEventHandler(parserPtr));
            parserPtr->next = EXPECT_VALUE_OR_ARRAY_END;
            Report(parserPtr, LE_JSON_ARRAY_START);
        }
        else if (c == '"')
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_STRING, GetEventHandler(parserPtr));
            parserPtr->next = EXPECT_STRING;
        }
        else if (c == 't')
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_TRUE, GetEventHandler(parserPtr));
            AddToBuffer(parserPtr, c);
            parserPtr->next = EXPECT_TRUE;
        }
        else if (c == 'f')
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_FALSE, GetEventHandler(parserPtr));
            AddToBuffer(parserPtr, c);
            parserPtr->next = EXPECT_FALSE;
        }
        else if (c == 'n')
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_NULL, GetEventHandler(parserPtr));
            AddToBuffer(parserPtr, c);
            parserPtr->next = EXPECT_NULL;
        }
        else if (isdigit(c) || (c == '-'))
        {
            PushContext(parserPtr, LE_JSON_CONTEXT_NUMBER, GetEventHandler(parserPtr));
            AddToBuffer(parserPtr, c);
            parserPtr->next = EXPECT_NUMBER;
        }
        else
        {
            Error(parserPtr,
                  LE_JSON_SYNTAX_ERROR,
                  "Unexpected character at beginning of value.");
        }
    }
}
Beispiel #2
0
/* AppendParm: append the src file to current Buffer pb. Return appended len */
HTime AppendParm(char *src)
{  
   int i;
   char bf1[MAXSTRLEN]; 
   char bf2[MAXSTRLEN]; 
   short swidth[SMAX];
   Boolean eSep;
   ParmBuf b, cb;
   Observation o;
   BufferInfo info;

   if((b =  OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL)
      HError(1050,"AppendParm: Config parameters invalid");
   GetBufferInfo(b,&info);
   if(trace & T_KINDS ){
      printf("Appending file %s format: %s [%s]->[%s]\n",src,
             Format2Str(info.srcFF), ParmKind2Str(info.srcPK,bf1),
             ParmKind2Str(info.tgtPK,bf2));
   }
   if  (tgtSampRate != info.tgtSampRate)
      HError(1032,"AppendParm: Input file %s has inconsistent sample rate",src);
   if ( BaseParmKind(tgtPK) != BaseParmKind(info.tgtPK))
      HError(1032,"AppendParm: Input file %s has inconsistent tgt format",src);
   cb = (chopF)?ChopParm(b,st,en,info.tgtSampRate) : b;
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&iStack, swidth, info.tgtPK, saveAsVQ, eSep);
   for (i=0; i < ObsInBuffer(cb); i++){
      ReadAsTable(cb, i, &o);
      AddToBuffer(pb, o);
   }
   CloseBuffer(cb);
   return(i*info.tgtSampRate);
}
Beispiel #3
0
int
int_09_LAT(unsigned char code)
{
	/*Veo que teclas estan oprimidas y modifico las variables
		 *globales, en caso de ser las teclas scrolllock,capslock
		 *o numlock */
	   char ascii;
	    if( code==LSHIFT || code==RSHIFT)
			shift=1;
		else if( code==(LSHIFT | MASK) || code==(RSHIFT | MASK) )
			shift=0;
		else if( code==CAPSLOCK )
			caps=!caps;
		else if( code==NUMLOCK )
			numlock=!numlock;
		else if( code==SCROLLLOCK )
			scrolllock=!scrolllock;
	        else if( IS_NUMPAD_KEY(code) && !numlock)
	            return 0;
		else
		{
			if( IS_MAKE_CODE(code) && code<=CANT_KEYS)
			{
			    ascii=ToAsciiLAT(code);
			    if(IS_VALID_ASCII(ascii))
			        AddToBuffer(ascii);
			}
		}
		return 0;
}
Beispiel #4
0
void *ReadInterruptInThread(void *devh) {
	libusb_device_handle *device = (libusb_device_handle*)devh;
	int bytes_transferred, success;
	int i = 0;
	BYTE data[64];

	while (running) {
		//pthread_mutex_lock(&syncRoot);
		
		success = libusb_interrupt_transfer(
				device,
				INTERRUPT_IN_ENDPOINT,
				data,
				sizeof(data),
				&bytes_transferred,
				5000);
		
		//pthread_mutex_unlock(&syncRoot);

		if (success == LIBUSB_SUCCESS) {
			if (verbose) {
				//DumpBytes(data, sizeof(data));
				printf("HID SMBus Interrupt In: %u bytes transferred. ReportId: %02X\n", bytes_transferred, data[0]);
		 	}

		 	AddToBuffer(data, sizeof(data));
		}// else {
		//	fprintf(stderr, "ReadInterruptInThread: Error receiving interrupt report: %s (Bytes transferred: %d)\n", libusb_strerror(success), bytes_transferred);
		//}

		usleep(10 * 1000); // sleep for a sec to minimize lock contention
	}

	printf(BOLDGREEN "Receive thread stopped." RESET "\n");
}
Beispiel #5
0
static void ProcNonDiscardable( void )
/************************************/
{
    AddToBuffer( "nondiscardable", 14 );
    ImplyFormat( FMT_WINDOWS );
//    NotNecessary( "nondiscardable" );
}
int BufferedAnalogRead::Read()
{
  if(!IsEnabled) return Value;
  
  BaseAnalogRead::Read();
  AddToBuffer(Value);
  return Value;
}
Beispiel #7
0
void Scanner::AtIdentifier()  //判断其余字符
{
	while(isalnum(c) || c == '_')   //字母数字或下划线
	{
		AddToBuffer(c);          //加入
		ExtractChar();          //读取下一个字符,一直到不满足条件
	}
	IdentifyAndMake();
}
Beispiel #8
0
//--------------------------------------------------------------------------------------------------
static void ParseString
(
    Parser_t* parserPtr,
    char c
)
//--------------------------------------------------------------------------------------------------
{
    // See if this is a string terminating '"' character.
    if (c == '"')
    {
        if ((parserPtr->numBytes != 0) && (parserPtr->buffer[parserPtr->numBytes - 1] == '\\'))
        {
            // Escaped ", replace with ".
            parserPtr->buffer[parserPtr->numBytes - 1] = '"';
        }
        else
        {
            // Make we have a valid UTF-8 string.
            if (!le_utf8_IsFormatCorrect(parserPtr->buffer))
            {
                Error(parserPtr, LE_JSON_SYNTAX_ERROR, "String is not valid UTF-8.");
            }
            else
            {
                // Handling of the end of the string depends on the context.
                le_json_ContextType_t contextType = GetContext(parserPtr)->type;

                if (contextType == LE_JSON_CONTEXT_STRING)
                {
                    Report(parserPtr, LE_JSON_STRING);
                    PopContext(parserPtr);
                }
                else if (contextType == LE_JSON_CONTEXT_MEMBER)
                {
                    Report(parserPtr, LE_JSON_OBJECT_MEMBER);
                    parserPtr->next = EXPECT_COLON;
                }
                else
                {
                    LE_FATAL("Unexpected context '%s' for string termination.",
                             le_json_GetContextName(contextType));
                }
            }
        }
    }
    else
    {
        AddToBuffer(parserPtr, c);
    }
}
void FormatAppend(char* buffer,
                  size_t buffer_size,
                  const char* text,
                  size_t* cursor) {
  char const* next = text;
  char ch = *(next++);
  while (ch != '\0') {
    AddToBuffer(ch, buffer, buffer_size, cursor);
    ch = *(next++);
  }
  /* Be sure to null terminate the generated string. */
  if (buffer_size > 0) {
    buffer[SizeMin(*cursor, buffer_size - 1)] = '\0';
  }
}
Beispiel #10
0
void Scanner::AtInterger()
{
	while (isdigit(c))    //
	{
		AddToBuffer(c);
		ExtractChar();
	}
	/*if (tolower(c) == 'e' || (c == '.' && in.peek() != '.'))
	{
		AddToBuffer(c);
		ExtractChar();
		EatRealFractPart();
	}*/
	MakeToken(INT_CONST);          

}
Beispiel #11
0
static int __gz_lines_iterator (lua_State *L)
{
  gzFile zf = (gzFile) lua_topointer (L, lua_upvalueindex(1));
  int ch = '\0';
  char* ret;

  if (content_buffer_length == 0)
    ExtendBuffer ();
  else
    ResetBuffer ();

  #ifdef READ_LINE_ONE_BY_ONE

  while ( (ch = gzgetc(zf)) != -1 && ch != '\n') {
    AddToBuffer ((char) ch);
  }

  #else

  do {
    ret = gzgets (zf, content_buffer + BufferFill (), BufferFree ());
    if (ret == Z_NULL)
      break;
    int l = strlen (content_buffer);
    content_length = l;
    if (l > 0) {
      ch = content_buffer[l - 1];
      if (ch != '\n')
	ExtendBuffer ();
      else
	content_buffer[l-1] = '\0';
    }
  } while (ret && ch != '\n');

  #endif

  if (ch == '\n' || BufferFill () > 0) {
    if (ch == '\n')
      
    lua_pushstring (L, FinishBuffer ());
    return 1;
  } else {
    return pushresult(L, &zf, NULL);
  }
}
Beispiel #12
0
void Scanner::AtOperation()        //运算符的判断
{
	bool match = false;
	if (!in.eof() && !isalnum(c) && c != '_'&&!isspace(c))
	{
		AddToBuffer(c);
		if (TryToIdentify())   //判断关系操作符   for example   <=此时为真
		{
			match = true;
			ExtractChar();
		}
		else
			ReduceBuffer();

	}
	if (!match && !TryToIdentify())
		throw "illegal expression";
}
Beispiel #13
0
/* ChopParm: return parm chopped to st and end. end = 0 means all */
ParmBuf ChopParm(ParmBuf b, HTime start, HTime end, HTime sampRate)
{  
   int stObs, endObs, nObs, i;
   HTime length;
   short swidth[SMAX];
   Boolean eSep;
   ParmBuf cb;
   Observation o;
   BufferInfo info;

   length =  ObsInBuffer(b) * sampRate;
   ClampStEn(length,&start,&end);
   if(start >= length)
      HError(1030,"ChopParm: Src file too short to get data from %.0f",start);
   if(trace & T_SEGMENT)
      printf("ChopParm: Extracting segment %.0f to %.0f\n",start,end);
   stObs = (int) (start/sampRate);
   endObs = (int) (end/sampRate);
   nObs = endObs -stObs;
   if(nObs <= 0)
      HError(1030,"ChopParm: Truncation options result in zero-length file");
   GetBufferInfo(b,&info);
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&cStack, swidth, info.tgtPK, saveAsVQ, eSep);
   if (saveAsVQ){
      if (info.tgtPK&HASNULLE){
         info.tgtPK=DISCRETE+HASNULLE;
      }else{
         info.tgtPK=DISCRETE;
      }
   }
   cb =  EmptyBuffer(&cStack, nObs, o, info);
   for (i=stObs; i < endObs; i++){
      ReadAsTable(b, i, &o);
      AddToBuffer(cb, o);
   }
   CloseBuffer(b);
   if(chopF && labF) ChopLabs(tr,start,end);
   return(cb);
}
Beispiel #14
0
/* OpenParmFile: open source parm file and return length */
HTime OpenParmFile(char *src)
{
   int i;
   ParmBuf b, cb;
   short swidth[SMAX];
   Boolean eSep;
   Observation o;
   BufferInfo info;

   if((b =  OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL)
      HError(1050,"OpenParmFile: Config parameters invalid");
   GetBufferInfo(b,&info);
   srcSampRate = info.srcSampRate;
   tgtSampRate = info.tgtSampRate;
   srcPK = info.srcPK; tgtPK = info.tgtPK;
   cb = chopF?ChopParm(b,st,en,info.tgtSampRate):b;
   ZeroStreamWidths(swidth0,swidth);
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   o = MakeObservation(&oStack, swidth, info.tgtPK, saveAsVQ, eSep);
   if (saveAsVQ){
      if (info.tgtPK&HASNULLE){
         info.tgtPK=DISCRETE+HASNULLE;
      }else{
         info.tgtPK=DISCRETE;
      }
   }
   pb =  EmptyBuffer(&oStack, ObsInBuffer(cb), o, info);
   for(i=0; i < ObsInBuffer(cb); i++){
      ReadAsTable(cb, i, &o);
      AddToBuffer(pb, o);
   }
   CloseBuffer(cb);
   if( info.nSamples > 0 )
      return(info.nSamples*srcSampRate);
   else
      return(ObsInBuffer(pb)*info.tgtSampRate);
}
Beispiel #15
0
//--------------------------------------------------------------------------------------------------
static void ParseConstant
(
    Parser_t* parserPtr,
    char c,
    const char* expected
)
//--------------------------------------------------------------------------------------------------
{
    AddToBuffer(parserPtr, c);

    if (strncmp(parserPtr->buffer, expected, parserPtr->numBytes) != 0)
    {
        char msg[256];

        snprintf(msg,
                 sizeof(msg),
                 "Unexpected character '%c' (expected '%c' in '%s').",
                 c,
                 expected[parserPtr->numBytes - 1],
                 expected);

        Error(parserPtr, LE_JSON_SYNTAX_ERROR, msg);
    }
}
Beispiel #16
0
static void ProcReadOnly( void )
/******************************/
{
    AddToBuffer( "readonly", 8 );
}
Beispiel #17
0
static void ProcReadWrite( void )
/*******************************/
{
    AddToBuffer( "readwrite", 9 );
}
Beispiel #18
0
static void ProcDiscardable( void )
/*********************************/
{
    AddToBuffer( "discardable", 11 );
    ImplyFormat( FMT_WINDOWS );
}
Beispiel #19
0
static void ProcFixed( void )
/***************************/
{
    AddToBuffer( "fixed", 5 );
    ImplyFormat( FMT_WINDOWS );
}
Beispiel #20
0
static void ProcMoveable( void )
/*****************************/
{
    AddToBuffer( "moveable", 8 );
    ImplyFormat( FMT_WINDOWS );
}
Beispiel #21
0
static void ProcNonConforming( void )
/***********************************/
{
    AddToBuffer( "nonconforming", 13 );
}
Beispiel #22
0
static void ProcConforming( void )
/********************************/
{
    AddToBuffer( "conforming", 10 );
}
Beispiel #23
0
static void ProcNoIopl( void )
/****************************/
{
    AddToBuffer( "noiopl", 6 );
}
Beispiel #24
0
static void ProcIopl( void )
/**************************/
{
    AddToBuffer( "iopl", 4 );
}
Beispiel #25
0
static void ProcExecuteRead( void )
/*********************************/
{
    AddToBuffer( "executeread", 11 );
}
Beispiel #26
0
static void ProcNonShared( void )
/*******************************/
{
    AddToBuffer( "nonshared", 9 );
}
Beispiel #27
0
static void ProcShared( void )
/****************************/
{
    AddToBuffer( "shared", 6 );
}
Beispiel #28
0
static void ProcLoadOnCall( void )
/********************************/
{
    AddToBuffer( "loadoncall", 10 );
}
/*-----------------------------------------------------------------------------
-	FUNCTION:	PacketCheck
-
-	DATE:		November 21st, 2013
-
-	REVISIONS:	
-	2013/12/02 - Vincent - Created
-	
-
-	DESIGNER:	Vincent Lau
-
-	PROGRAMMER:	Vincent Lau
-				German Villarreal
-
-	INTERFACE:	BOOL PacketCheck(HWND hwnd, CHAR* packet)
-		
-	RETURNS:	void, nothing.
-				
-	PARAMETERS:	HWND hwnd - a dynamic char buffer that contains the whole file
-				CHAR* packet:  1024 bytes of data
-
-	NOTES:	This is a function that cecks the packet for data.
-			
-
-----------------------------------------------------------------------------*/
BOOL PacketCheck(HWND hwnd, CHAR* packet)
{
	char* data = (CHAR*) malloc(1020);
	data[1020] = '\0';
	int lengthOfData = strlen(data);
	
	 //Make sure we're getting our own packets, not some other packet
	switch (packet[0])
	{
	case SYN:
		break;
	default: // discard packet
		return FALSE;
	}

	switch (packet[1])
	{
	case ENQ:
		bENQReceived = TRUE;
		//SendControl(hComm, ACK);
		bWantToSendACK = TRUE;
		//	Set "what we're waiting for" flag to DC1
		waitForType = DC1;
	break;
	case ACK:
		// check if we wanted an ACK
		if (waitForType == ACK)
		{
			// check if we're actually bidding for the line
			if (bWantLine)
				ReleaseSemaphore(hWaitForLineSemaphore, 1, NULL);
			else
			// check if we're sending a file
				ReleaseSemaphore(hACKWaitSemaphore, 1, NULL);
		}
	break;

	case DC1:
		//if we're waiting for a DC2 packet

		if(waitForType == DC2 || !ErrorCheck(packet+2))//pass data+crcbits
		{
			SendControl(hComm, NAK);
			break;
		}
		waitForType = DC2;
		bWantToSendACK = TRUE;
		GetData(packet, data);
		AddToBuffer(data);
	break;
	case DC2:
		// if we're waiting for a DC1 packet
		if (waitForType == DC1 || !ErrorCheck(packet+2))
		{
			SendControl(hComm, NAK);
			break;
		}
		waitForType = DC1;
		bWantToSendACK = TRUE;
		GetData(packet, data);
		AddToBuffer(data);
	break;
	case NAK:
		//Set "What we're waiting for" flag to ACK
		waitForType = ACK;
		SendData(hComm, Packet); // send the previous packet
	break;
	case EOT:
		bENQReceived = FALSE;
		if (bENQToSend)
		{
			ReleaseSemaphore(hWaitForLineSemaphore, 1, NULL);
			break;
		}
	    // GO back to IDLE state
		waitForType = ENQ;
	break;
    }
	return TRUE;
}
Beispiel #30
0
static void ProcExecuteOnly( void )
/*********************************/
{
    AddToBuffer( "executeonly", 11 );
}