示例#1
0
/* Strip off any leading and trailing whitespace.  This function is called
   right after the initial scanning, therefore it assumes that every
   node in the list is a text reference node. */
static void
wordsplit_trimws (struct wordsplit *wsp)
{
  struct wordsplit_node *p;

  for (p = wsp->ws_head; p; p = p->next)
    {
      size_t n;

      if (p->flags & _WSNF_QUOTE)
	continue;

      /* Skip leading whitespace: */
      for (n = p->v.segm.beg; n < p->v.segm.end && ISWS (wsp->ws_input[n]);
	   n++)
	;
      p->v.segm.beg = n;
      /* Trim trailing whitespace */
      for (n = p->v.segm.end;
	   n > p->v.segm.beg && ISWS (wsp->ws_input[n - 1]); n--);
      p->v.segm.end = n;
      if (p->v.segm.beg == p->v.segm.end)
	p->flags |= _WSNF_NULL;
    }

  wsnode_nullelim (wsp);
}
示例#2
0
/*
 * Traverse over spaces and comments from the input stream,
 * Returns first non-space character.
 */
static int
fastspc(void)
{
	int ch;

	while ((ch = qcchar()), ISWS(ch))
		;
	return ch;
}
示例#3
0
int scriptfile_getnumber(scriptfile *sf, int *num)
{
	skipoverws(sf);
	if (sf->textptr >= sf->eof)
	{
		initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr));
		return -1;
	}

	while ((sf->textptr[0] == '0') && (sf->textptr[1] >= '0') && (sf->textptr[1] <= '9'))
		sf->textptr++; //hack to treat octal numbers like decimal
	
	sf->ltextptr = sf->textptr;
	(*num) = strtol((const char *)sf->textptr,&sf->textptr,0);
	if (!ISWS(*sf->textptr) && *sf->textptr) {
		char *p = sf->textptr;
		skipovertoken(sf);
		initprintf("Error on line %s:%d: expecting int, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p);
		return -2;
	}
	return 0;
}
示例#4
0
int scriptfile_getdouble(scriptfile *sf, double *num)
{
	skipoverws(sf);
	if (sf->textptr >= sf->eof)
	{
		initprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr));
		return -1;
	}
	
	sf->ltextptr = sf->textptr;

	// On Linux, locale settings interfere with interpreting x.y format numbers
	//(*num) = strtod((const char *)sf->textptr,&sf->textptr);
	(*num) = parsedouble(sf->textptr, &sf->textptr);
	
	if (!ISWS(*sf->textptr) && *sf->textptr) {
		char *p = sf->textptr;
		skipovertoken(sf);
		initprintf("Error on line %s:%d: expecting float, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p);
		return -2;
	}
	return 0;
}
示例#5
0
文件: qp.c 项目: baohaojun/dico
static int
dico_qp_decode(const char *iptr, size_t isize, char *optr, size_t osize,
	       size_t *pnbytes)
{
    char c;
    int last_char = 0;
    size_t consumed = 0;
    size_t wscount = 0;
    size_t nbytes = 0;
    
    while (consumed < isize && nbytes < osize) {
	c = *iptr++;

	if (ISWS(c)) {
	    wscount++;
	    consumed++;
	}
	else {
	    /* Octets with values of 9 and 32 MAY be
	       represented as US-ASCII TAB (HT) and SPACE characters,
	       respectively, but MUST NOT be so represented at the end
	       of an encoded line.  Any TAB (HT) or SPACE characters
	       on an encoded line MUST thus be followed on that line
	       by a printable character. */
	  
	    if (wscount) {
		if (c != '\r' && c != '\n') {
		    size_t sz;
		  
		    if (consumed >= isize)
			break;

		    if (nbytes + wscount > osize)
			sz = osize - nbytes;
		    else
			sz = wscount;
		    memcpy(optr, iptr - wscount - 1, sz);
		    optr += sz;
		    nbytes += sz;
		    if (wscount > sz) {
			wscount -= sz;
			break;
		    }
		}
		wscount = 0;
		if (nbytes == osize)
		    break;
	    }
		
	    if (c == '=') {
		/* There must be 2 more characters before I consume this.  */
		if (consumed + 2 >= isize)
		    break;
		else {
		    /* you get =XX where XX are hex characters.  */
		    char chr[3];
		    int new_c;

		    chr[2] = 0;
		    chr[0] = *iptr++;
		    /* Ignore LF.  */
		    if (chr[0] != '\n') {
			chr[1] = *iptr++;
			new_c = strtoul (chr, NULL, 16);
			*optr++ = new_c;
			nbytes++;
			consumed += 3;
		    } else
			consumed += 2;
		}
	    }
	    /* CR character.  */
	    else if (c == '\r') {
		/* There must be at least 1 more character before
		   I consume this.  */
		if (consumed + 1 >= isize)
		    break;
		else {
		    iptr++; /* Skip the CR character.  */
		    *optr++ = '\n';
		    nbytes++;
		    consumed += 2;
		}
	    } else {
		*optr++ = c;
		nbytes++;
		consumed++;
	    }
	}	  
	last_char = c;
    }
    *pnbytes = nbytes;
    return consumed - wscount;
}