Esempio n. 1
0
void
POL::getescape (        /* reads up to delim */
                char *s,
                int delim,
                int toksiz
                )
{
  int i, c;

  for (i = 0; (c = inchar()) != delim; i++) {
    if (c == NEWLINE) {
      sys_error (ERR_WARNING, "Missing closing delimiter.");
      break;
    }
    if (i >= toksiz) {
      sys_error (ERR_SEVERE, "string too long.");
      break;
    }
    if (c == EOF) {
      ungetch(c);
      sys_error (ERR_SEVERE, "end of file inside quotation");
      break;
    } else if (c == BSLASH) {   /* escape character */
      s[i++] = c;
      c = inchar();             /* get escaped character */
    }
    s[i] = c;
  }
  s[i] = EOS;
}
Esempio n. 2
0
/*===========================
 * lowyylex -- Lexer function
 *=========================*/
static int
lowyylex (PACTX pactx, YYSTYPE * lvalp)
{
	INT c=0, t=0;

	/* skip over whitespace or comments up to start of token */
	while (TRUE) {
		while ((t = chartype(c = inchar(pactx))) == WHITE)
			;
		if (c != '/') break;
		if ((c = inchar(pactx)) != '*') {
			unreadchar(pactx, c);
			return '/';
		}
		/* inside a comment -- advance til end */
		while (TRUE) {
			while ((c = inchar(pactx)) != '*' && c != EOF)
				;
			if (c == EOF) return 0;
			while ((c = inchar(pactx)) == '*')
				;
			if (c == '/') break;
			if (c == EOF) return 0;
		}
	}
	/* now read token */
	c = lextok(pactx, lvalp, c, t);
	return c;
}
Esempio n. 3
0
inline int inIntPos()
{
    int n=0, ch;
    while((ch = inchar()) < '0');
    n=(ch-'0');
    while((ch=inchar())>='0') n=(n<<3)+(n<<1)+(ch-'0');
    return n;
}
Esempio n. 4
0
static int
new_char(void)
{
  /*
     If the cache is full of newline, time to prime the look-ahead
     again.  If an EOF is found, fill the remainder of the queue with
     EOF's.
     */
  if (Char == '\n'  && Char1 == '\n' && Char2 == '\n' && Char3 == '\n')
    {				/* prime the pump again */
      Char = inchar(In_file);
      if (Char == EOF)
	{
	  Char1 = EOF;
	  Char2 = EOF;
	  Char3 = EOF;
	  return Char;
	}
      else if (Char == '\n')
	return Char;

      Char1 = inchar(In_file);
      if (Char1 == EOF)
	{
	  Char2 = EOF;
	  Char3 = EOF;
	  return Char;
	}
      else if (Char1 == '\n')
	return Char;

      Char2 = inchar(In_file);
      if (Char2 == EOF)
	{
	  Char3 = EOF;
	  return Char;
	}
      else if (Char2 == '\n')
	return Char;

      Char3 = inchar(In_file);
    }
  else
    {
      /*
	 Buffer not full of newline, shuffle the characters and
	 either get a new one or propagate a newline or EOF.
	 */
      Char = Char1;
      Char1 = Char2;
      Char2 = Char3;
      if (Char3 != '\n' && Char3 != EOF) {
	Char3 = inchar(In_file);
      }		
    }
  return Char;
}
Esempio n. 5
0
int
POL::gettok (TOKEN *tok)
{
  int c, toktype;
  int inum;
  double fnum;
  int toksiz = MAXTOK;          /* maximum length of token string */

  while ((c = inchar()) == BLANK || c == TAB)
    ;
  ungetch (c);

  c = lookchar();
  toktype = type(c);

  fnum = 0.0;
  inum = 0;

  if (c == BLANK || c == TAB) {                 /* skip white space */
    getblank(tok->tokstr, toksiz);
    toktype = TT_BLANK;
  } else if (toktype == LETTER) {
    toktype = getalpha (tok->tokstr, toksiz);
  } else if (c == meta.str) {                   /* quoted string */
    getquote (tok->tokstr, toksiz);
    toktype = TT_STRING;
  } else if (type(c) == DIGIT || c == PLUS || c == HYPHEN || c == PERIOD) {
    toktype = getnumber (tok->tokstr, toksiz, &fnum, &inum);
  } else if (c == EOF) {
    tok->tokstr[0] = EOS;
    toktype = TT_EOF;
  } else {
    c = inchar();
    tok->tokstr[0] = c;
    tok->tokstr[1] = EOS;
    toktype = TT_SPECLCHAR;
  }

  tok->type = toktype;
  tok->ready = true;
  if (tok->type == TT_REAL || tok->type == TT_INT) {
    tok->fnum = fnum;
    tok->inum = inum;
  } else {
    tok->fnum = 0.0;
    tok->inum = 0;
  }

  return (toktype);
}
Esempio n. 6
0
int
POL::getalpha (char *s, int toksiz)
{
  int i, chartype, alphatype;

  if (type(lookchar()) != LETTER) {
    s[0] = EOS;
    return (TT_ERROR);
  }

  alphatype = TT_ALPHA;
  for (i = 0; i < toksiz; i++) {                /* get alphanumeric token */
    s[i] = inchar();
    chartype = type (s[i]);
    if (chartype != LETTER && chartype != DIGIT)
      break;
    if (chartype == DIGIT)
      alphatype = TT_ALPNUM;
  }
  ungetch(s[i]);

  if (i >= toksiz)
    sys_error (ERR_SEVERE, "POL token too long.");

  s[i] = EOS;                   /* terminate token */
  return (alphatype);
}
Esempio n. 7
0
static int
tst_display(MENU_ARGS)
{
  int d, c = -1;

  vt_move(1, 1);
  display_head(stdout);
  println("");
  println("Press any key to display its soft-character.  Repeat a key to quit.");

  set_tty_raw(TRUE);
  set_tty_echo(FALSE);

  do {
    d = c;
    c = inchar();
    vt_move(6, 1);
    vt_clear(0);
    if (display_char(stdout, c)) {
      println("");
      printf("Render: %cN%c", ESC, c);  /* use SS2 to invoke G2 into GL */
    }
  } while (c != d);

  restore_ttymodes();
  return MENU_NOHOLD;
}
Esempio n. 8
0
/* have already gotten delimiter in qs[0] */
void
POL::getquote (char *qs, int toksiz)
{
  int delim;

  delim = inchar();                     /* char = delimiter */
  getescape(qs, delim, toksiz);
}
Esempio n. 9
0
int
POL::lookchar()
{
  int c;

  c = inchar();
  ungetch (c);
  return (c);
}
Esempio n. 10
0
File: compile.c Progetto: uarka/sed
/* Read the next non-blank character from the program.  */
static int
in_nonblank(void)
{
  int ch;
  do
    ch = inchar();
    while (ISBLANK(ch));
  return ch;
}
Esempio n. 11
0
int main()
{
    int t,i,j,ch,res;

    t=inIntPos();
    while(t--)
    {
        la=0;
        while((ch = inchar()) < '0');
        a[la++]=ch-'0';
        while((ch=inchar())>='0') a[la++]=ch-'0';

        if(la==1)
        {
            if(a[0]==0 || a[0]==1 || a[0]==2 || a[0]==3 || a[0]==5 || a[0]==8)
                printf("YES\n");
            else printf("NO\n");
            continue;
        }

        for(i=0; i<=la+1; ++i) f1[i]=f2[i]=f3[i]=0;
        a[la]=0;
        for(i=0,j=la-1; i<j; ++i,--j)
        {
            ch=a[i];
            a[i]=a[j];
            a[j]=ch;
        }
        f1[0]=0;
        lf1=1;
        f2[0]=1;
        lf2=1;
        f3[0]=1;
        lf3=1;
        res=1;
        while(lf3<la || (lf3 == la && (res=comp()) == 1))
        {
            update();
        }
        if(res==0) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
Esempio n. 12
0
function sceneManager() 
{
	createLetters() ; 
	
	while(1) // While game is running,... 
	{	// ..keep checking for keyboard input
		LetterPressedAscii = inchar( KeyboardInput ) ; // Convert input into ASCII and store in myVariable
	wait(1);		
	}  
}
Esempio n. 13
0
bool
POL::readText (char *str, int lim)
{
  int c;
  while ((c = inchar()) == BLANK || c == TAB)
    ;
  ungetch (c);
  if (c == EOF) {
    str[0] = 0;
    return false;
  }

  int i;
  for (i = 0; i < lim && (c = inchar()) != EOF && c != NEWLINE; i++)
    str[i] = c;
  ungetch (c);
  str[i] = 0;

  return true;
}
Esempio n. 14
0
void
POL::getblank (char *s, int toksiz)
{
  int c;

  while ((c = inchar()) == BLANK || c == TAB)
    ;
  ungetch(c);

  s[0] = BLANK;
  s[1] = EOS;
}
Esempio n. 15
0
/*
 * loads the font dictated by the troff input into the family
 * structure.  This doesn't do anything but make the name known.
 */
getfamily()
{
	register char *s;
	register c, i;

	/* skip over possible "ont", as in "font" */
	while ((c = inchar()) != ' ')
	    /* empty */;

	/* get mount position */
	i = inint();

	/*
	 * skip over what?  This probably exits immediately.
	 * But it gobbles one space.
	 */
	while ((c = inchar()) != ' ')
	    /* empty */;

	if (i >= NUMFAMILIES) {
#	    ifdef DEBUG
	    if (debug)
		fprintf (debug, "family number too large: %d\n", i);
#	    endif /* DEBUG */
	    /* eat up family name */
	    while ((c = inchar()) != '\n' && c != ' ')
		/* empty */;
	    return;
	}

	for (s = family[i]; (c = inchar()) != '\n' && c != ' '; *s++ = c)
	    /* empty */;

	*s = 0;

#	ifdef DEBUG
	    if (debug && verbose)
		fprintf (debug, "newfamily: is %s\n", family [i]);
#	endif /* DEBUG */
}
Esempio n. 16
0
File: compile.c Progetto: uarka/sed
/* Read an integer value from the program.  */
static countT
in_integer (int ch)
{
  countT num = 0;

  while (ISDIGIT(ch))
    {
      num = num * 10 + ch - '0';
      ch = inchar();
    }
  savchar(ch);
  return num;
}
Esempio n. 17
0
void
Input(REQUEST *request, RESPONSE *response)
{
    switch (request->option) {
    case char_option:
	response->reply.ch = inchar(request->fp);
	response->option = request->option;
	break;
    default:
	/* just ignore, since we don't want a million error messages */
	response->option = error_option;
	break;
    }
    return;
}
Esempio n. 18
0
lexlist* fsm::varproc(char c)
{
	lexlist *temp;

	if (inchar(c)) { buffer.write(c); return 0; }
	else if (inoperations(c))
	{
		varitem *item=new varitem(buffer.read());
		table.addnewvar(item);
		temp=addnewlex(Variable);
		temp->next=addnewlex(c,Operation);
		return temp;
	}
	else if (individers(c))
	{
		varitem *item=new varitem(buffer.read());
		table.addnewvar(item);
		temp=addnewlex(Variable);
		temp->next=addnewlex(c,Divider);
		return temp;
	}
	else if (inbrackets(c))
	{
		varitem *item=new varitem(buffer.read());
		table.addnewvar(item);
		temp=addnewlex(Variable);
		temp->next=addnewlex(c,Bracket);
		return temp;
	}
	else if (inspaces(c))
	{
		varitem *item=new varitem(buffer.read());
		table.addnewvar(item);
		temp=addnewlex(Variable);
		return temp;
	}
	else if (c=='=')
	{
		varitem *item=new varitem(buffer.read());
		table.addnewvar(item);
		temp=addnewlex(Variable);
		state=Equ;
		return temp;
	}
	buffer.write(c);
	buffer.write(": unexpected sequence of charecters\n");
	throw scanerr(buffer.read(),line);
}
Esempio n. 19
0
lexlist* fsm::funproc(char c)
{
	lexlist *temp;

	if (inchar(c)) { buffer.write(c); return 0; }
	else if (inspaces(c)) { temp=addnewlex(Function); return temp; }
	else if (inbrackets(c))
	{
		temp=addnewlex(Function);
		temp->next=addnewlex(c,Bracket);
		return temp;
	}
	buffer.write(c);
	buffer.write(": unexpected sequence of charecters\n");
	throw scanerr(buffer.read(),line);
}
Esempio n. 20
0
File: main.c Progetto: hharte/vttest
int
bug_d(MENU_ARGS)
{
  int i;
  char result;
  /* Make the bug appear */
  do {
    cup(14, 1);

    /* The original code in the article says
     * PRINT ESC$; "[13;1H"; CHR$(10%);
     * but I guess a cup(14,1); would do.
     * (To output a pure LF might be tricky).
     */

    deccolm(TRUE);  /* Make the bug visible */

    cup(1, 9);
    decdwl();
    println("You should see blinking text at the bottom line.");

    cup(3, 9);
    decdwl();
    println("Enter 0 to exit, 1 to try to invoke the bug again.");

    cup(max_lines, 9);
    decdwl();
    sgr("1;5;7");
    printf("If you can see this then the bug did not appear.");
    sgr("");

    cup(4, 9);
    decdwl();
    result = inchar();
    readnl();
    deccolm(FALSE);
  } while (result == '1');
  decsclm(TRUE);  /* Syrup scroll */
  cup(max_lines - 1, 1);
  for (i = 1; i <= 5; i++)
    println("If the bug is present, this should make things much worse!");
  holdit();
  decsclm(FALSE);   /* Jump scroll */
  return MENU_NOHOLD;
}
Esempio n. 21
0
lexlist* fsm::homeproc(char c)
{
	lexlist *temp;

	if (c=='$') { state=Var; return 0; }
	else if (c=='?') { state=Fun; return 0; }
	else if (c=='@') { state=Lab; return 0; }
	else if ((c>='0')&&(c<='9')) { state=Num; buffer.write(c); return 0; }
	else if (c=='"') { state=Str; return 0; }
	else if (inchar(c)) { state=Key; buffer.write(c); return 0; }
	//       ^ use only after numbers!!
	else if (inoperations(c)) { temp=addnewlex(c,Operation); return temp; }
	else if (inbrackets(c)) { temp=addnewlex(c,Bracket); return temp; }
	else if (individers(c)) { temp=addnewlex(c,Divider); return temp; }
	else if (inspaces(c)) return 0;
	else if (c=='=') { state=Equ; return 0; }
	char s[32];
	sprintf(s,"%c: unexpected character\n",c);
	throw scanerr(s,line);
}
Esempio n. 22
0
lexlist* fsm::labproc(char c)
{
	lexlist *temp;

	if (inchar(c)) { buffer.write(c); return 0; }
	else if (individers(c))
	{
		labitem *item=new labitem(buffer.read());
		table.addnewlab(item);
		temp=addnewlex(Label);
		temp->next=addnewlex(c,Divider);
		return temp;
	}
	else if (inspaces(c))
	{
		labitem *item=new labitem(buffer.read());
		table.addnewlab(item);
		temp=addnewlex(Label);
		return temp;
	}
	buffer.write(c);
	buffer.write(": unexpected sequence of charecters\n");
	throw scanerr(buffer.read(),line);
}
Esempio n. 23
0
int
POL::getnumber
(
 char str[],                            /* string to return token in */
 int strsize,                           /* maximum length of token string */
 double *fnum,                          /* floating point value of number read */
 int *inum                              /* integer value of number read */
 )
{
  int sp = 0;
  double sign = 1.0;
  bool isSigned = false;                /* true if number prefixed by '+' or '-' */
  *fnum = 0.0;
  *inum = 0;
  str[0] = EOS;

  int c = inchar();
  if (c == HYPHEN) {
    str[sp++] = c;
    isSigned = true;
    sign = -1.0;
  } else if (c == PLUS) {
    str[sp++] = c;
    isSigned = true;
    sign = 1.0;
  } else if (c == PERIOD) {
    if (type(lookchar()) != DIGIT) {
      str[0] = PERIOD;
      str[1] = EOS;
      return (TT_SPECLCHAR);
    } else
      ungetch (PERIOD);
  } else if (type(c) != DIGIT) {
    ungetch (c);
    return (TT_ERROR);
  } else
    ungetch (c);

  if (isSigned) {
    c = lookchar();
    if (c == PERIOD) {
      inchar();         /* get period */
      c = lookchar();           /* look at character past period */
      ungetch (PERIOD); /* put back period */
      if (type(c) != DIGIT) {
        str[sp] = EOS;
        return (TT_SPECLCHAR);
      }
    } else if (type (c) != DIGIT) {
      str[sp] = EOS;
      return (TT_SPECLCHAR);
    }
  }

  double whole = 0.0;
  while (type(c = inchar()) == DIGIT) {
    if (sp < strsize)
      str[sp++] = c;
    whole = 10.0 * whole + (c - '0');
  }
  ungetch (c);          /* put back non-numeric character */

  if (c != PERIOD && tolower(c) != 'e') {
    str[sp] = EOS;
    *fnum = whole * sign;
    if (*fnum < MIN_INT)
      *inum = MIN_INT;
    else if (*fnum > MAX_INT)
      *inum = MAX_INT;
    else
      *inum = (int) *fnum;
    return (TT_INT);
  }

  if (lookchar() == PERIOD) {
    inchar();
    if (sp < strsize)
      str[sp++] = PERIOD;
  }

  double frac = 0.0;
  double powerof10 = 10.0;

  while (type(c = inchar()) == DIGIT) {
    if (sp < strsize)
      str[sp++] = c;
    frac += (double) (c - '0') / powerof10;
    powerof10 *= 10.0;
  }
  ungetch (c);

  double exp = 0.0;
  double expsign = 1.0;
  c = inchar();
  if (tolower(c) != 'e')
    ungetch (c);
  else {
    if (sp < strsize)
      str[sp++] = c;
    if ((c = inchar()) == PLUS) {
      if (sp < strsize)
        str[sp++] = c;
      expsign = 1.0;
    } else if (c == HYPHEN) {
      if (sp < strsize)
        str[sp++] = c;
      expsign = -1.0;
    } else if (type(c) != DIGIT) {
      --sp;                             /* erase 'e' */
      ungetch (c);
      ungetch ('e');
      goto getnumexit;
    } else
      ungetch(c);

    exp = 0;
    while (type(c = inchar()) == DIGIT) {
      if (sp < strsize)
        str[sp++] = c;
      exp = 10 * exp + (c - '0');
    }
    ungetch (c);
  }

getnumexit:
  str[sp] = EOS;
  *fnum = sign * (whole + frac) * pow (10.0, expsign * exp);
  if (*fnum < MIN_INT)
    *inum = MIN_INT;
  else if (*fnum > MAX_INT)
    *inum = MAX_INT;
  else
    *inum = (int) *fnum;
  return (TT_REAL);
}
Esempio n. 24
0
int
__vfscanf (FILE *s, const char *format, va_list argptr)
#endif
{
  va_list arg = (va_list) argptr;

  register const char *f = format;
  register unsigned char fc;	/* Current character of the format.  */
  register size_t done = 0;	/* Assignments done.  */
  register size_t read_in = 0;	/* Chars read in.  */
  register int c = 0;		/* Last char read.  */
  register int width;		/* Maximum field width.  */
  register int flags;		/* Modifiers for current format element.  */

  /* Status for reading F-P nums.  */
  char got_dot, got_e, negative;
  /* If a [...] is a [^...].  */
  char not_in;
  /* Base for integral numbers.  */
  int base;
  /* Signedness for integral numbers.  */
  int number_signed;
  /* Decimal point character.  */
  wchar_t decimal;
  /* The thousands character of the current locale.  */
  wchar_t thousands;
  /* Integral holding variables.  */
  union
    {
      long long int q;
      unsigned long long int uq;
      long int l;
      unsigned long int ul;
    } num;
  /* Character-buffer pointer.  */
  char *str = NULL;
  wchar_t *wstr = NULL;
  char **strptr = NULL;
  size_t strsize = 0;
  /* We must not react on white spaces immediately because they can
     possibly be matched even if in the input stream no character is
     available anymore.  */
  int skip_space = 0;
  /* Workspace.  */
  char *tw;			/* Temporary pointer.  */
  char *wp = NULL;		/* Workspace.  */
  size_t wpmax = 0;		/* Maximal size of workspace.  */
  size_t wpsize;		/* Currently used bytes in workspace.  */
#define ADDW(Ch)							    \
  do									    \
    {									    \
      if (wpsize == wpmax)						    \
	{								    \
	  char *old = wp;						    \
	  wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax;	    \
	  wp = (char *) alloca (wpmax);					    \
	  if (old != NULL)						    \
	    memcpy (wp, old, wpsize);					    \
	}								    \
      wp[wpsize++] = (Ch);						    \
    }									    \
  while (0)

  ARGCHECK (s, format);

  /* Figure out the decimal point character.  */
  if (mbtowc (&decimal, _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT),
	      strlen (_NL_CURRENT (LC_NUMERIC, DECIMAL_POINT))) <= 0)
    decimal = (wchar_t) *_NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
  /* Figure out the thousands separator character.  */
  if (mbtowc (&thousands, _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP),
	      strlen (_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP))) <= 0)
    thousands = (wchar_t) *_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);

  /* Lock the stream.  */
  LOCK_STREAM (s);

  /* Run through the format string.  */
  while (*f != '\0')
    {
      unsigned int argpos;
      /* Extract the next argument, which is of type TYPE.
	 For a %N$... spec, this is the Nth argument from the beginning;
	 otherwise it is the next argument after the state now in ARG.  */
#if 0
      /* XXX Possible optimization.  */
# define ARG(type)	(argpos == 0 ? va_arg (arg, type) :		      \
			 ({ va_list arg = (va_list) argptr;		      \
			    arg = (va_list) ((char *) arg		      \
					     + (argpos - 1)		      \
					     * __va_rounded_size (void *));   \
			    va_arg (arg, type);				      \
			 }))
#else
# define ARG(type)	(argpos == 0 ? va_arg (arg, type) :		      \
			 ({ unsigned int pos = argpos;			      \
			    va_list arg = (va_list) argptr;		      \
			    while (--pos > 0)				      \
			      (void) va_arg (arg, void *);		      \
			    va_arg (arg, type);				      \
			  }))
#endif

      if (!isascii (*f))
	{
	  /* Non-ASCII, may be a multibyte.  */
	  int len = mblen (f, strlen (f));
	  if (len > 0)
	    {
	      do
		{
		  c = inchar ();
		  if (c == EOF)
		    input_error ();
		  else if (c != *f++)
		    {
		      ungetc (c, s);
		      conv_error ();
		    }
		}
	      while (--len > 0);
	      continue;
	    }
	}

      fc = *f++;
      if (fc != '%')
	{
	  /* Remember to skip spaces.  */
	  if (isspace (fc))
	    {
	      skip_space = 1;
	      continue;
	    }

	  /* Read a character.  */
	  c = inchar ();

	  /* Characters other than format specs must just match.  */
	  if (c == EOF)
	    input_error ();

	  /* We saw white space char as the last character in the format
	     string.  Now it's time to skip all leading white space.  */
	  if (skip_space)
	    {
	      while (isspace (c))
		if (inchar () == EOF && errno == EINTR)
		  conv_error ();
	      skip_space = 0;
	    }

	  if (c != fc)
	    {
	      ungetc (c, s);
	      conv_error ();
	    }

	  continue;
	}

      /* This is the start of the conversion string. */
      flags = 0;

      /* Initialize state of modifiers.  */
      argpos = 0;

      /* Prepare temporary buffer.  */
      wpsize = 0;

      /* Check for a positional parameter specification.  */
      if (isdigit (*f))
	{
	  argpos = *f++ - '0';
	  while (isdigit (*f))
	    argpos = argpos * 10 + (*f++ - '0');
	  if (*f == '$')
	    ++f;
	  else
	    {
	      /* Oops; that was actually the field width.  */
	      width = argpos;
	      flags |= WIDTH;
	      argpos = 0;
	      goto got_width;
	    }
	}

      /* Check for the assignment-suppressing and the number grouping flag.  */
      while (*f == '*' || *f == '\'')
	switch (*f++)
	  {
	  case '*':
	    flags |= SUPPRESS;
	    break;
	  case '\'':
	    flags |= GROUP;
	    break;
	  }

      /* We have seen width. */
      if (isdigit (*f))
	flags |= WIDTH;

      /* Find the maximum field width.  */
      width = 0;
      while (isdigit (*f))
	{
	  width *= 10;
	  width += *f++ - '0';
	}
    got_width:
      if (width == 0)
	width = -1;

      /* Check for type modifiers.  */
      while (*f == 'h' || *f == 'l' || *f == 'L' || *f == 'a' || *f == 'q')
	switch (*f++)
	  {
	  case 'h':
	    /* int's are short int's.  */
	    if (flags & TYPEMOD)
	      /* Signal illegal format element.  */
	      conv_error ();
	    flags |= SHORT;
	    break;
	  case 'l':
	    if (flags & (SHORT|LONGDBL))
	      conv_error ();
	    else if (flags & LONG)
	      {
		/* A double `l' is equivalent to an `L'.  */
		flags &= ~LONG;
		flags |= LONGDBL;
	      }
	    else
	      /* int's are long int's.  */
	      flags |= LONG;
	    break;
	  case 'q':
	  case 'L':
	    /* double's are long double's, and int's are long long int's.  */
	    if (flags & TYPEMOD)
	      /* Signal illegal format element.  */
	      conv_error ();
	    flags |= LONGDBL;
	    break;
	  case 'a':
	    if (flags & TYPEMOD)
	      /* Signal illegal format element.  */
	      conv_error ();
	    /* String conversions (%s, %[) take a `char **'
	       arg and fill it in with a malloc'd pointer.  */
	    flags |= MALLOC;
	    break;
	  }

      /* End of the format string?  */
      if (*f == '\0')
	conv_error ();

      /* We must take care for EINTR errors.  */
      if (c == EOF && errno == EINTR)
	input_error ();

      /* Find the conversion specifier.  */
      fc = *f++;
      if (skip_space || (fc != '[' && fc != 'c' && fc != 'C' && fc != 'n'))
	{
	  /* Eat whitespace.  */
	  do
	    if (inchar () == EOF && errno == EINTR)
	      input_error ();
	  while (isspace (c));
	  ungetc (c, s);
	  skip_space = 0;
	}

      switch (fc)
	{
	case '%':	/* Must match a literal '%'.  */
	  c = inchar ();
	  if (c != fc)
	    {
	      ungetc (c, s);
	      conv_error ();
	    }
	  break;

	case 'n':	/* Answer number of assignments done.  */
	  /* Corrigendum 1 to ISO C 1990 describes the allowed flags
	     with the 'n' conversion specifier.  */
	  if (!(flags & SUPPRESS))
	    {
	      /* Don't count the read-ahead.  */
	      if (flags & LONGDBL)
		*ARG (long long int *) = read_in;
	      else if (flags & LONG)
		*ARG (long int *) = read_in;
	      else if (flags & SHORT)
		*ARG (short int *) = read_in;
	      else
		*ARG (int *) = read_in;

#ifdef NO_BUG_IN_ISO_C_CORRIGENDUM_1
	      /* We have a severe problem here.  The ISO C standard
		 contradicts itself in explaining the effect of the %n
		 format in `scanf'.  While in ISO C:1990 and the ISO C
		 Amendement 1:1995 the result is described as

		   Execution of a %n directive does not effect the
		   assignment count returned at the completion of
		   execution of the f(w)scanf function.

		 in ISO C Corrigendum 1:1994 the following was added:

		   Subclause 7.9.6.2
		   Add the following fourth example:
		     In:
		       #include <stdio.h>
		       int d1, d2, n1, n2, i;
		       i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
		     the value 123 is assigned to d1 and the value3 to n1.
		     Because %n can never get an input failure the value
		     of 3 is also assigned to n2.  The value of d2 is not
		     affected.  The value 3 is assigned to i.

		 We go for now with the historically correct code fro ISO C,
		 i.e., we don't count the %n assignments.  When it ever
		 should proof to be wrong just remove the #ifdef above.  */
	      ++done;
#endif
	    }
	  break;

	case 'c':	/* Match characters.  */
	  if ((flags & LONG) == 0)
	    {
	      if (!(flags & SUPPRESS))
		{
		  str = ARG (char *);
		  if (str == NULL)
		    conv_error ();
		}

	      c = inchar ();
	      if (c == EOF)
		input_error ();

	      if (width == -1)
		width = 1;

	      if (!(flags & SUPPRESS))
		{
		  do
		    *str++ = c;
		  while (--width > 0 && inchar () != EOF);
		}
	      else
		while (--width > 0 && inchar () != EOF);

	      if (width > 0)
		/* I.e., EOF was read.  */
		--read_in;

	      if (!(flags & SUPPRESS))
		++done;

	      break;
	    }
	  /* FALLTHROUGH */
	case 'C':
	  /* Get UTF-8 encoded wide character.  Here we assume (as in
	     other parts of the libc) that we only have to handle
	     UTF-8.  */
	  {
	    wint_t val;
	    size_t cnt = 0;
	    int first = 1;

	    if (!(flags & SUPPRESS))
	      {
		wstr = ARG (wchar_t *);
		if (str == NULL)
		  conv_error ();
	      }

	    do
	      {
#define NEXT_WIDE_CHAR(First)						      \
		c = inchar ();						      \
		if (c == EOF)						      \
		  /* EOF is only an error for the first character.  */	      \
		  if (First)						      \
		    input_error ();					      \
		  else							      \
		    {							      \
		      --read_in;					      \
		      break;						      \
		    }							      \
		val = c;						      \
		if (val >= 0x80)					      \
		  {							      \
		    if ((c & 0xc0) == 0x80 || (c & 0xfe) == 0xfe)	      \
		      encode_error ();					      \
		    if ((c & 0xe0) == 0xc0)				      \
		      {							      \
			/* We expect two bytes.  */			      \
			cnt = 1;					      \
			val &= 0x1f;					      \
		      }							      \
		    else if ((c & 0xf0) == 0xe0)			      \
		      {							      \
			/* We expect three bytes.  */			      \
			cnt = 2;					      \
			val &= 0x0f;					      \
		      }							      \
		    else if ((c & 0xf8) == 0xf0)			      \
		      {							      \
			/* We expect four bytes.  */			      \
			cnt = 3;					      \
			val &= 0x07;					      \
		      }							      \
		    else if ((c & 0xfc) == 0xf8)			      \
		      {							      \
			/* We expect five bytes.  */			      \
			cnt = 4;					      \
			val &= 0x03;					      \
		      }							      \
		    else						      \
		      {							      \
			/* We expect six bytes.  */			      \
			cnt = 5;					      \
			val &= 0x01;					      \
		      }							      \
		    							      \
		    do							      \
		      {							      \
			c = inchar ();					      \
			if (c == EOF					      \
			    || (c & 0xc0) == 0x80 || (c & 0xfe) == 0xfe)      \
			  encode_error ();				      \
			val <<= 6;					      \
			val |= c & 0x3f;				      \
		      }							      \
		    while (--cnt > 0);					      \
		  }							      \
									      \
		if (!(flags & SUPPRESS))				      \
		  *wstr++ = val;					      \
		first = 0

		NEXT_WIDE_CHAR (first);
	      }
	    while (--width > 0);

	    if (width > 0)
	      /* I.e., EOF was read.  */
	      --read_in;

	    if (!(flags & SUPPRESS))
	      ++done;
	  }
	  break;

	case 's':		/* Read a string.  */
	  if (flags & LONG)
	    /* We have to process a wide character string.  */
	    goto wide_char_string;

#define STRING_ARG(Str, Type)						      \
	  if (!(flags & SUPPRESS))					      \
	    {								      \
	      if (flags & MALLOC)					      \
		{							      \
		  /* The string is to be stored in a malloc'd buffer.  */     \
		  strptr = ARG (char **);				      \
		  if (strptr == NULL)					      \
		    conv_error ();					      \
		  /* Allocate an initial buffer.  */			      \
		  strsize = 100;					      \
		  *strptr = malloc (strsize * sizeof (Type));		      \
		  Str = (Type *) *strptr;				      \
		}							      \
	      else							      \
		Str = ARG (Type *);					      \
	      if (Str == NULL)						      \
		conv_error ();						      \
	    }
	  STRING_ARG (str, char);

	  c = inchar ();
	  if (c == EOF)
	    input_error ();

	  do
	    {
	      if (isspace (c))
		{
		  ungetc (c, s);
		  break;
		}
#define	STRING_ADD_CHAR(Str, c, Type)					      \
	      if (!(flags & SUPPRESS))					      \
		{							      \
		  *Str++ = c;						      \
		  if ((flags & MALLOC) && (char *) Str == *strptr + strsize)  \
		    {							      \
		      /* Enlarge the buffer.  */			      \
		      Str = realloc (*strptr, strsize * 2 * sizeof (Type));   \
		      if (Str == NULL)					      \
			{						      \
			  /* Can't allocate that much.  Last-ditch effort.  */\
			  Str = realloc (*strptr,			      \
					 (strsize + 1) * sizeof (Type));      \
			  if (Str == NULL)				      \
			    {						      \
			      /* We lose.  Oh well.			      \
				 Terminate the string and stop converting,    \
				 so at least we don't skip any input.  */     \
			      ((Type *) (*strptr))[strsize] = '\0';	      \
			      ++done;					      \
			      conv_error ();				      \
			    }						      \
			  else						      \
			    {						      \
			      *strptr = (char *) Str;			      \
			      Str = ((Type *) *strptr) + strsize;	      \
			      ++strsize;				      \
			    }						      \
			}						      \
		      else						      \
			{						      \
			  *strptr = (char *) Str;			      \
			  Str = ((Type *) *strptr) + strsize;		      \
			  strsize *= 2;					      \
			}						      \
		    }							      \
		}
	      STRING_ADD_CHAR (str, c, char);
	    } while ((width <= 0 || --width > 0) && inchar () != EOF);

	  if (c == EOF)
	    --read_in;

	  if (!(flags & SUPPRESS))
	    {
	      *str = '\0';
	      ++done;
	    }
	  break;

	case 'S':
	  /* Wide character string.  */
	wide_char_string:
	  {
	    wint_t val;
	    int first = 1;
	    STRING_ARG (wstr, wchar_t);

	    do
	      {
		size_t cnt = 0;
		NEXT_WIDE_CHAR (first);

		if (iswspace (val))
		  {
		    /* XXX We would have to push back the whole wide char
		       with possibly many bytes.  But since scanf does
		       not make a difference for white space characters
		       we can simply push back a simple <SP> which is
		       guaranteed to be in the [:space:] class.  */
		    ungetc (' ', s);
		    break;
		  }

		STRING_ADD_CHAR (wstr, val, wchar_t);
		first = 0;
	      }
	    while (width <= 0 || --width > 0);

	    if (!(flags & SUPPRESS))
	      {
		*wstr = L'\0';
		++done;
	      }
	  }
	  break;

	case 'x':	/* Hexadecimal integer.  */
	case 'X':	/* Ditto.  */
	  base = 16;
	  number_signed = 0;
	  goto number;

	case 'o':	/* Octal integer.  */
	  base = 8;
	  number_signed = 0;
	  goto number;

	case 'u':	/* Unsigned decimal integer.  */
	  base = 10;
	  number_signed = 0;
	  goto number;

	case 'd':	/* Signed decimal integer.  */
	  base = 10;
	  number_signed = 1;
	  goto number;

	case 'i':	/* Generic number.  */
	  base = 0;
	  number_signed = 1;

	number:
	  c = inchar ();
	  if (c == EOF)
	    input_error ();

	  /* Check for a sign.  */
	  if (c == '-' || c == '+')
	    {
	      ADDW (c);
	      if (width > 0)
		--width;
	      c = inchar ();
	    }

	  /* Look for a leading indication of base.  */
	  if (width != 0 && c == '0')
	    {
	      if (width > 0)
		--width;

	      ADDW (c);
	      c = inchar ();

	      if (width != 0 && tolower (c) == 'x')
		{
		  if (base == 0)
		    base = 16;
		  if (base == 16)
		    {
		      if (width > 0)
			--width;
		      c = inchar ();
		    }
		}
	      else if (base == 0)
		base = 8;
	    }

	  if (base == 0)
	    base = 10;

	  /* Read the number into workspace.  */
	  while (c != EOF && width != 0)
	    {
	      if (base == 16 ? !isxdigit (c) :
		  ((!isdigit (c) || c - '0' >= base) &&
		   !((flags & GROUP) && base == 10 && c == thousands)))
		break;
	      ADDW (c);
	      if (width > 0)
		--width;

	      c = inchar ();
	    }

	  /* The just read character is not part of the number anymore.  */
	  ungetc (c, s);

	  if (wpsize == 0 ||
	      (wpsize == 1 && (wp[0] == '+' || wp[0] == '-')))
	    /* There was no number.  */
	    conv_error ();

	  /* Convert the number.  */
	  ADDW ('\0');
	  if (flags & LONGDBL)
	    {
	      if (number_signed)
		num.q = __strtoq_internal (wp, &tw, base, flags & GROUP);
	      else
		num.uq = __strtouq_internal (wp, &tw, base, flags & GROUP);
	    }
	  else
	    {
	      if (number_signed)
		num.l = __strtol_internal (wp, &tw, base, flags & GROUP);
	      else
		num.ul = __strtoul_internal (wp, &tw, base, flags & GROUP);
	    }
	  if (wp == tw)
	    conv_error ();

	  if (!(flags & SUPPRESS))
	    {
	      if (! number_signed)
		{
		  if (flags & LONGDBL)
		    *ARG (unsigned LONGLONG int *) = num.uq;
		  else if (flags & LONG)
		    *ARG (unsigned long int *) = num.ul;
		  else if (flags & SHORT)
		    *ARG (unsigned short int *)
		      = (unsigned short int) num.ul;
		  else
		    *ARG (unsigned int *) = (unsigned int) num.ul;
		}
	      else
		{
		  if (flags & LONGDBL)
		    *ARG (LONGLONG int *) = num.q;
		  else if (flags & LONG)
		    *ARG (long int *) = num.l;
		  else if (flags & SHORT)
		    *ARG (short int *) = (short int) num.l;
		  else
		    *ARG (int *) = (int) num.l;
		}
	      ++done;
	    }
	  break;

	case 'e':	/* Floating-point numbers.  */
	case 'E':
	case 'f':
	case 'g':
	case 'G':
	  c = inchar ();
	  if (c == EOF)
	    input_error ();

	  /* Check for a sign.  */
	  if (c == '-' || c == '+')
	    {
	      negative = c == '-';
	      if (inchar () == EOF)
		/* EOF is only an input error before we read any chars.  */
		conv_error ();
	      if (width > 0)
		--width;
	    }
	  else
	    negative = 0;

	  got_dot = got_e = 0;
	  do
	    {
	      if (isdigit (c))
		ADDW (c);
	      else if (got_e && wp[wpsize - 1] == 'e'
		       && (c == '-' || c == '+'))
		ADDW (c);
	      else if (wpsize > 0 && !got_e && tolower (c) == 'e')
		{
		  ADDW ('e');
		  got_e = got_dot = 1;
		}
	      else if (c == decimal && !got_dot)
		{
		  ADDW (c);
		  got_dot = 1;
		}
	      else if ((flags & GROUP) && c == thousands && !got_dot)
		ADDW (c);
	      else
		break;
	      if (width > 0)
		--width;
	    }
	  while (inchar () != EOF && width != 0);

	  /* The last read character is not part of the number anymore.  */
	  ungetc (c, s);

	  if (wpsize == 0)
	    conv_error ();

	  /* Convert the number.  */
	  ADDW ('\0');
	  if (flags & LONGDBL)
	    {
	      long double d = __strtold_internal (wp, &tw, flags & GROUP);
	      if (!(flags & SUPPRESS) && tw != wp)
		*ARG (long double *) = negative ? -d : d;
	    }
	  else if (flags & LONG)
	    {
	      double d = __strtod_internal (wp, &tw, flags & GROUP);
	      if (!(flags & SUPPRESS) && tw != wp)
		*ARG (double *) = negative ? -d : d;
	    }
	  else
	    {
	      float d = __strtof_internal (wp, &tw, flags & GROUP);
	      if (!(flags & SUPPRESS) && tw != wp)
		*ARG (float *) = negative ? -d : d;
	    }

	  if (tw == wp)
	    conv_error ();

	  if (!(flags & SUPPRESS))
	    ++done;
	  break;

	case '[':	/* Character class.  */
	  if (flags & LONG)
	    {
	      STRING_ARG (wstr, wchar_t);
	      c = '\0';		/* This is to keep gcc quiet.  */
	    }
	  else
	    {
	      STRING_ARG (str, char);

	      c = inchar ();
	      if (c == EOF)
		input_error ();
	    }

	  if (*f == '^')
	    {
	      ++f;
	      not_in = 1;
	    }
	  else
	    not_in = 0;

	  /* Fill WP with byte flags indexed by character.
	     We will use this flag map for matching input characters.  */
	  if (wpmax < UCHAR_MAX)
	    {
	      wpmax = UCHAR_MAX;
	      wp = (char *) alloca (wpmax);
	    }
	  memset (wp, 0, UCHAR_MAX);

	  fc = *f;
	  if (fc == ']' || fc == '-')
	    {
	      /* If ] or - appears before any char in the set, it is not
		 the terminator or separator, but the first char in the
		 set.  */
	      wp[fc] = 1;
	      ++f;
	    }

	  while ((fc = *f++) != '\0' && fc != ']')
	    {
	      if (fc == '-' && *f != '\0' && *f != ']' &&
		  (unsigned char) f[-2] <= (unsigned char) *f)
		{
		  /* Add all characters from the one before the '-'
		     up to (but not including) the next format char.  */
		  for (fc = f[-2]; fc < *f; ++fc)
		    wp[fc] = 1;
		}
	      else
		/* Add the character to the flag map.  */
		wp[fc] = 1;
	    }
	  if (fc == '\0')
	    {
	      if (!(flags & LONG))
		ungetc (c, s);
	      conv_error();
	    }

	  if (flags & LONG)
	    {
	      wint_t val;
	      int first = 1;

	      do
		{
		  size_t cnt = 0;
		  NEXT_WIDE_CHAR (first);
		  if (val > 255 || wp[val] == not_in)
		    {
		      /* XXX We have a problem here.  We read a wide
			 character and this possibly took several
			 bytes.  But we can only push back one single
			 character.  To be sure we don't create wrong
			 input we push it back only in case it is
			 representable within one byte.  */
		      if (val < 0x80)
			ungetc (val, s);
		      break;
		    }
		  STRING_ADD_CHAR (wstr, val, wchar_t);
		  if (width > 0)
		    --width;
		  first = 0;
		}
	      while (width != 0);

	      if (first)
		conv_error ();

	      if (!(flags & SUPPRESS))
		{
		  *wstr = L'\0';
		  ++done;
		}
	    }
	  else
	    {
	      num.ul = read_in - 1; /* -1 because we already read one char.  */
	      do
		{
		  if (wp[c] == not_in)
		    {
		      ungetc (c, s);
		      break;
		    }
		  STRING_ADD_CHAR (str, c, char);
		  if (width > 0)
		    --width;
		}
	      while (width != 0 && inchar () != EOF);

	      if (read_in == num.ul)
		conv_error ();

	      if (!(flags & SUPPRESS))
		{
		  *str = '\0';
		  ++done;
		}
	    }
	  break;

	case 'p':	/* Generic pointer.  */
	  base = 16;
	  /* A PTR must be the same size as a `long int'.  */
	  flags &= ~(SHORT|LONGDBL);
	  flags |= LONG;
	  number_signed = 0;
	  goto number;
	}
Esempio n. 25
0
int
X11_Input(REQUEST *request, RESPONSE *response)
{

    XEvent ev;
    int nfds;
    fd_set rfds;

    switch (request->option) {
	
	  case char_option:
		nfds = ConnectionNumber(display) > fileno(request->fp) ?
		    ConnectionNumber(display) :
		    fileno(request->fp);

		while (1) {

		      /* first read off the queue before doing the select */
		      while (XtPending()) {
			    XtNextEvent(&ev);
			    XtDispatchEvent(&ev);
		      }

		      /* block on ConnectionNumber and request->fp */
		      /* PN: added fd_set * casting */
		      FD_ZERO(&rfds);
		      FD_SET(fileno(request->fp), &rfds);
		      FD_SET(ConnectionNumber(display), &rfds);
		      select (nfds + 1,
			      &rfds,
			      (fd_set *)NULL,
			      (fd_set *)NULL,
			      NULL);
		      
		      /* handle X events first */
		      if (FD_ISSET (ConnectionNumber(display), &rfds)) {
			    /* handle ALL X events */
			    while (XtPending()) {
				  XtNextEvent(&ev);
				  XtDispatchEvent(&ev);
			    }
		      }

		      if (FD_ISSET (fileno(request->fp), &rfds)) {
			    response->reply.ch = inchar(request->fp);
			    goto out;
		      }

		}
		break;

	  case click_option:
		/* let's fake this */
		response->reply.graph = lasthardcopy;
		break;

	  case button_option:
		/* sit and handle events until get a button selection */
		internalerror("button_option not implemented");
		response->option = error_option;
		return 1;
		break;

	  case checkup_option:
		/* first read off the queue before doing the select */
		while (XtPending()) {
		    XtNextEvent(&ev);
		    XtDispatchEvent(&ev);
		}
		break;

	  default:
		internalerror("unrecognized input type");
		response->option = error_option;
		return 1;
		break;
    }

out:
    if (response)
	response->option = request->option;
    return 0;

}
Esempio n. 26
0
File: compile.c Progetto: uarka/sed
static int
add_then_next(struct buffer *b, int ch)
{
  add1_buffer(b, ch);
  return inchar();
}
Esempio n. 27
0
int
POL::getpol_tok (struct token_st *token)
{
  KeywordCodeEntry* sym;

  token->ready = false;
nexttok:
  gettok (token);

  if (token->type == TT_BLANK)
    goto nexttok;
  if (token->type == TT_SPECLCHAR) {
    if (strchr(m_szSkipChars, token->tokstr[0]) != NULL)
      goto nexttok;
    if (token->tokstr[0] == NEWLINE)
      goto nexttok;
    if (token->tokstr[0] == meta.cmd) {
      getcmd();
      goto nexttok;
    }
    if (token->tokstr[0] == meta.com) {         /* skip comment */
      eatline ();
      goto nexttok;
    }
    if (token->tokstr[0] == meta.out) {
      getescape(token->tokstr, meta.out, MAXTOK);
      fputs (token->tokstr, stderr);
      goto nexttok;
    }
    if (token->tokstr[0] == meta.con) {         /* continuation across NEWLINE */
      while (lookchar() == BLANK || lookchar() == TAB)
        inchar();
      if (lookchar() == NEWLINE)
        inchar();
    }
    if (token->tokstr[0] == meta.ter) {         /* get input from terminal */
      usefile (P_USE_FILE, "");
      tok (token);
      closefile();
      return (token->type);
    }
  }

  /* look for filler words */

  if (skiptable.lookup (token->tokstr) != NULL) /* ignore words in skip table */
    goto nexttok;

  /* look for user defined symbols */

  if ((sym = usertable.lookup (token->tokstr)) != NULL) {
    token->type = TT_USERTOK;
    token->code = sym->getCode();
  } else
    token->code = 0;

  if (m_bTrace)
    sys_error (ERR_TRACE, "POL read token '%s', type = %d\n", token->tokstr, token->type);

  return (token->type);
}
Esempio n. 28
0
/*===========================
 * lextok -- lex the next token
 *=========================*/
static int
lextok (PACTX pactx, YYSTYPE * lvalp, INT c, INT t)
{
	INT retval, mul;
	extern INT Yival;
	extern FLOAT Yfval;
	static char tokbuf[512]; /* token buffer */
	STRING p = tokbuf;

	if (t == LETTER) {
		p = tokbuf;
		while (is_iden_char(c, t)) {
			if (p-tokbuf < (int)sizeof(tokbuf) - 3) {
				*p++ = c;
			} else {
				/* token overlong -- ignore end of it */
				/* TODO: How can we force a parse error from here ? */
			}
			t = chartype(c = inchar(pactx));
		}
		*p = 0;
		unreadchar(pactx, c);

		if (reserved(tokbuf, &retval))  return retval;
		/* IDEN values have to be passed from yacc.y to free_iden */
		*lvalp = (PNODE) strsave(tokbuf);
		return IDEN;
	}
	if (t == '-' || t == DIGIT || t == '.') {
		BOOLEAN whole = FALSE;
		BOOLEAN frac = FALSE;
		FLOAT fdiv;
		mul = 1;
		if (t == '-') {
			t = chartype(c = inchar(pactx));
			if (t != '.' && t != DIGIT) {
				unreadchar(pactx, c);
				return '-';
			}
			mul = -1;
		}
		Yival = 0;
		while (t == DIGIT) {
			whole = TRUE;
			Yival = Yival*10 + c - '0';
			t = chartype(c = inchar(pactx));
		}
		if (t != '.') {
			unreadchar(pactx, c);
			Yival *= mul;
			*lvalp = NULL;
			return ICONS;
		}
		t = chartype(c = inchar(pactx));
		Yfval = 0.0;
		fdiv = 1.0;
		while (t == DIGIT) {
			frac = TRUE;
			Yfval = Yfval*10 + c - '0';
			fdiv *= 10.;
			t = chartype(c = inchar(pactx));
		}
		unreadchar(pactx, c);
		if (!whole && !frac) {
			unreadchar(pactx, c);
			if (mul == -1) {
				unreadchar(pactx, '.');
				return '-';
			} else
				return '.';
		}
		Yfval = mul*(Yival + Yfval/fdiv);
		*lvalp = NULL;
		return FCONS;
	}
	if (c == '"') {
		INT start_line = pactx->lineno;
		p = tokbuf;
		while (TRUE) {
			while ((c = inchar(pactx)) != EOF && c != '"' && c != '\\') {
				if (p-tokbuf > sizeof(tokbuf)/sizeof(tokbuf[0]) - 3) {
					/* Overflowing tokbuf buffer */
					/* TODO: (Perry, 2006-06-30) I don't know how to fail gracefully from here inside parser */
					char msg[512];
					snprintf(msg, sizeof(msg)/sizeof(msg[0])
						, _("String constant overflowing internal buffer tokbuf len=%d, file: %s, start line: %ld")
						, sizeof(tokbuf)/sizeof(tokbuf[0])
						, pactx->fullpath
						, start_line + 1
						);
					FATAL2(msg);
					*p = c = 0;
				}
				*p++ = c;
			}
			if (c == 0 || c == '"') {
				*p = 0;
				*lvalp = make_internal_string_node(pactx, tokbuf);
				return SCONS;
			}
			switch (c = inchar(pactx)) {
			case 'n': *p++ = '\n'; break;
			case 't': *p++ = '\t'; break;
			case 'v': *p++ = '\v'; break;
			case 'r': *p++ = '\r'; break;
			case 'b': *p++ = '\b'; break;
			case 'f': *p++ = '\f'; break;
			case '"': *p++ = '"'; break;
			case '\\': *p++ = '\\'; break;
			case EOF:
				*p = 0;
				*lvalp = make_internal_string_node(pactx, tokbuf);
				return SCONS;
			default:
				*p++ = c; break;
			}
		}
	}
	if (c == EOF) return 0;
	return c;
}
Esempio n. 29
0
static void printIndent(UFILE *out, int32_t indent) {
    icu::UnicodeString inchar(indent, 0x20, indent);
    printString(out, inchar.getBuffer(), indent);
}
Esempio n. 30
0
/***********************************************************************
 *
 * Function:    read_field
 *
 * Summary:     Reach each field of the CSV during read_file
 *
 * Parameters:  dest    <-> Buffer for storing field contents
 *              in      --> Inbound filehandle
 *              length  --> Size of buffer
 *
 * Returns:     0 for end of line
 *              1 for , termination
 *              2 for ; termination
 *              3 for \t termination
 *             -1 on end of file
 *
 *              Note that these correspond to indexes in the tabledelims
 *              array, and should be preserved.
 *
 ***********************************************************************/
int read_field(char *dest, FILE *in, size_t length) {
	int 	c;

	if (length<=1) return -1;
	/* reserve space for trailing NUL */
	length--;

	do {	/* Absorb whitespace */
		c = getc(in);
		if(c == '\n') {
			*dest = 0;
			return term_newline;
		}

	} while ((c != EOF) && ((c == ' ') || (c == '\t') || (c == '\r')));

	if (c == '"') {
		c = inchar(in);

		while (c != EOF) {
			if (c == '"') {
				c = inchar(in);
				if (c != '"')
					break;
			}
			*dest++ = c;
			if (!(--length))
				break;
			c = inchar(in);
		}
	} else {
		while (c != EOF) {
			if ((c == '\n') || (c == tabledelims[tabledelim])) {
				break;
			}
			*dest++ = c;
			if (!(--length))
				break;
			c = inchar(in);
		}
	}
	*dest++ = '\0';

	/* Absorb whitespace */
	while ((c != EOF) && ((c == ' ') || (c == '\t')))
		c = getc(in);

	if (c == ',')
		return term_comma;

	else if (c == ';')
		return term_semi;

	else if (c == '\t')
		return term_tab;

	else if (c == EOF)
		return -1;	/* No more */
	else
		return term_newline;
}