コード例 #1
0
ファイル: object.c プロジェクト: entzel/GraphicsProject
static char* readline(FILE* f)
{
   char ch;  //  Character read
   int k=0;  //  Character count
   while ((ch = fgetc(f)) != EOF)
   {
      //  Allocate more memory for long strings
      if (k>=linelen)
      {
         linelen += 8192;
         line = (char*)realloc(line,linelen);
         if (!line) Fatal("Out of memory in readline\n");
      }
      //  End of Line
      if (CRLF(ch))
      {
         // Eat extra CR or LF characters (if any)
         while ((ch = fgetc(f)) != EOF)
           if (!CRLF(ch)) break;
         //  Stick back the overrun
         if (ch != EOF) ungetc(ch,f);
         //  Bail
         break;
      }
      //  Pad character to line
      else
         line[k++] = ch;
   }
   //  Terminate line if anything was read
   if (k>0) line[k] = 0;
   //  Return pointer to line or NULL on EOF
   return k>0 ? line : NULL;
}
コード例 #2
0
ファイル: xio_rs485.c プロジェクト: aldenhart/TinyG
int xio_putc_rs485(const char c, FILE *stream)
{
	BUFFER_T next_tx_buf_head;

	if ((next_tx_buf_head = (RSu.tx_buf_head)-1) == 0) { // adv. head & wrap
		next_tx_buf_head = TX_BUFFER_SIZE-1;	 // -1 avoids the off-by-one
	}
	while(next_tx_buf_head == RSu.tx_buf_tail) { // buf full. sleep or ret
		if (BLOCKING(RS.flags) != 0) {
			sleep_mode();
		} else {
			RS.signal = XIO_SIG_EAGAIN;
			return(_FDEV_ERR);
		}
	};
	// enable TX mode and write data to TX buffer
	_xio_enable_rs485_tx();							// enable for TX
	RSu.tx_buf_head = next_tx_buf_head;				// accept next buffer head
	RSu.tx_buf[RSu.tx_buf_head] = c;				// ...write char to buffer

	if ((CRLF(RS.flags) != 0) && (c == '\n')) {		// detect LF & add CR
		return RS.x_putc('\r', stream);				// recurse
	}
	// force a TX interupt to attempt to send the character
	RSu.usart->CTRLA = CTRLA_RXON_TXON;	// doesn't work if you just |= it
	return (XIO_OK);
}
コード例 #3
0
ファイル: xio_usart.c プロジェクト: rickmellor/TinyG
int xio_putc_usart(const uint8_t dev, const char c, FILE *stream)
{
#ifdef __DISABLE_TRANSMIT
    return (XIO_OK);
#endif

    BUFFER_T next_tx_buf_head;
    struct xioDEVICE *d = &ds[dev];				// init device struct ptr
    struct xioUSART *dx = ((struct xioUSART *)(ds[dev].x));	// USART ptr

    if ((next_tx_buf_head = (dx->tx_buf_head)-1) == 0) { // adv. head & wrap
        next_tx_buf_head = TX_BUFFER_SIZE-1; // -1 avoids the off-by-one
    }
    // detect TX buffer full
    while(next_tx_buf_head == dx->tx_buf_tail) { // sleep or return
        if (BLOCKING(d->flags) != 0) {
            sleep_mode();
        } else {
            d->signal = XIO_SIG_EAGAIN;
            return(_FDEV_ERR);
        }
    };
    // write to data register
    dx->tx_buf_head = next_tx_buf_head;			// accept next buffer head
    dx->tx_buf[dx->tx_buf_head] = c;			// ...write char to buffer

    if ((CRLF(d->flags) != 0) && (c == '\n')) {	// detect LF & add CR
        return d->x_putc('\r', stream);			// recurse
    }
    // force an interrupt to attempt to send the char
    dx->usart->CTRLA = CTRLA_RXON_TXON;			// doesn't work if you just |= it
    return (XIO_OK);
}
コード例 #4
0
ファイル: console.c プロジェクト: robfinch/Cores
void DisplayStringCRLF(char *s)
{
     DisplayString(s);
     CRLF();
}
コード例 #5
0
//look for previous character
BOOL pre4regexp()
{
 CHAR *p=mSp, c=*(--p);
 for(; TABSPC(c) || CRLF(c); c=*(--p));
 return (c==0 || strchr("(:=,;",c)!=NULL );
}
コード例 #6
0
void Minfy( CHAR* dst, CHAR* src, BOOL R0932, BOOL R1310, BOOL Rcmnt, BOOL Rsmrt )
{
 CHAR c,*u, q;
 BOOL b,z;
 UINT n13=0;
 mS1 = FALSE; mS2 = FALSE; mS3 = FALSE;
 mSp=src; mTp=dst; mPre = mSp;

 CkJS(); // is javascript
 
 for(mSp=src,c=*mSp; c!=0; c=*(++mSp) )
 {
  if(!mJS && startswith_all_case("<SCRIPT"))
   {
    mJS = TRUE; SkipTo('>'); mJS=(*(mSp-1)!='/'); continue;     // here the script starts
   }
  if(mJS && startswith_all_case("</SCRIPT"))
   {
    SkipTo('>'); mJS = FALSE; continue;               // script ends
   }
  if(!mJS)	// if html then do nothing
   {
   	*(mTp++)=c;
    continue;
   }

  if(c==39 && !mS2) mS1 = !mS1;   // '
  if(c==34 && !mS1) mS2 = !mS2;   // "

  if(!(mS1 || mS2 || mS3))
    {
    if(Rsmrt)
			{
			q = *mPre;
			if( q==';' )
			 {
			 	if( c==';' ) continue;
			 	if( c=='}' && *(mTp-1)==q ) { *(mTp-1)=c; continue; }  
			 }
			}

			// remove comments
    if(startswith("//"))
			{
			for(;c!=0 && !CRLF(c); c=*(++mSp)) if(!Rcmnt) *(mTp++)=c;
			if(!Rcmnt)		
			 {
			 	if(c==13) { *(mTp++)=c; c=*(++mSp); }	// skip LFs
			 	if(c==10) { *(mTp++)=c; c=*(++mSp); }
			 }		
			mSp--;
			continue;
			}

    if(startswith("/*"))
			{
			for(;c!=0; c=*(++mSp))
			 {
			 if(!Rcmnt) *(mTp++)=c;
			 if(c=='/' && *(mSp-1)=='*') break;
			 }
			continue;
			}
		
    if(c=='/')    // try skip regexp
			{
			if(pre4regexp())
				{
				SkipTo('/'); continue;
				}
			}
	

    // end of line
    if(R1310 && CRLF(c))
     {
		u = mSp; mSp = mPre+1;
		if(comesafter("else")) *(mTp++)=32;
		mSp = u; c=*mSp;
		z = (c==13);
     	b = (z && *(++mSp)==10);
     	if((++n13)<12)
     	 {
				if(z && !b) mSp--;
				continue;
     	 }    	
     	n13=0;
     }


	if(!(CRLF(c) || TABSPC(c))) mPre = mSp;

    if(TABSPC(c) && (!testINcase()))
     {
     	if(R0932) c=32;		// no tabs in result
     	
     	u = mSp; mSp = mPre+1;
			b =
        comesafter("function") ||
        comesafter("var") ||
        comesafter("typeof") ||
        comesafter("instanceof") ||
        comesafter("return") ||
        comesafter("case") ||
        comesafter("new") ||
        comesafter("else") ||
        comesafter("throw") ||
        comesafter("break") ||
        comesafter("continue");
      if(!b)
         {
         	if((mSp==u) && comesafter("in"))
         	 {
         	 	*(mTp++)=c;
         	 	continue;
         	 }
         }
      mSp = u; c=*mSp;
      if(!b)
        	{
        	for(; TABSPC(c) && (!testINcase()) ; c=*(++mSp))
         	 if(!R0932) *(mTp++)=c;
        	mSp--;
        	continue;
        	}
     }

    }

  *(mTp++)=c;
 }
*mTp=0;
}