bool getinteger(int *n)
{


	int value = 0;
	int sign = 1;
	char ch = 0;

	eatspaces();

	if((ch = getchar()) == '-')
	{
		sign = -1;
	}
	else if(isdigit(ch))
	{
		value = 10*value + (ch -'0');
	}
	else if(isalpha(ch))
	{
		ungetc(ch,stdin);
		return false;
	}

	while(isdigit(ch = getchar()))
	{
		value = 10 * value + (ch - '0');
	}
	ungetc(ch,stdin);
	*n = value*sign;
	return true;
}
Example #2
0
// Function to read an integer from standard input 
bool getinteger(int *n)
{
  eatspaces();
  int value = 0;
  int sign = 1;
  char ch = 0;

  // Check first character 
  if((ch = (char)getchar()) == '-')            // should be minus 
    sign = -1;
  else if(isdigit(ch))                 // ...or a digit   
   value = ch - '0';
  else  if(ch != '+')                  // ...or plus      
  {
    ungetc(ch, stdin);
    return false;                      // Not an integer 
  }

  // Find more digits 
  while(isdigit(ch = (char)getchar()))
    value = 10*value + (ch - '0');

   
  ungetc(ch,stdin);                    // Push back non-digit character
  *n = value*sign;                     // Set the sign                     
  return true;
}
/* Function to read an integer from standard input */
bool getinteger(int *n)
{
  eatspaces();
  int value = 0;
  int sign = 1;
  char ch = 0;

  /* Check first character */
  if((ch=getchar()) == '-')            /* should be minus */
    sign = -1;
  else if(isdigit(ch))                 /* ...or a digit   */
   value = 10*value + (ch - '0');
  else  if(ch != '+')                  /* ...or plus      */
  {
    ungetc(ch, stdin);
    return false;                      /* Not an integer  */
  }

  /* Find more digits */
  while(isdigit(ch = getchar()))
    value = 10*value + (ch - '0');

  /* Push back first non-digit character */
  ungetc(ch,stdin);
  *n = value*sign;
  return true;
}
Example #4
0
// Function to read an alphabetic name from input 
char* getname(char *name, size_t length)
{

  eatspaces();                         // Remove leading spaces
  size_t count = 0;
  char ch = 0;
  while(isalpha(ch = (char)getchar()))       // As long as there are letters...
  {
    name[count++] = ch;                // ...store them in name.
    if(count == length - 1)            // Check for name full
      break;
  }

  name[count] = '\0';                  // Append string terminator
  if(count < length - 1)               // If we didn't end for name full...
    ungetc(ch, stdin);                 // ...return non-letter to stream
  return name;
}
/* Function to read an alphabetic name from input */
char *getname(char *name, size_t length)
{

  eatspaces();                         /* Remove leading spaces */
  size_t count = 0;
  char ch = 0;
  while(isalpha(ch=getchar()))         /* As long as there are letters */
  {
    name[count++] = ch;                /* store them in name           */
    if(count == length-1)
      break;
  }

  name[count] = '\0';                  /* Append string terminator     */
  if(count < length-1)
    ungetc(ch, stdin);                 /* Return non-letter to stream  */
  return name;
}
char *getname(char *name,size_t length)
{
	eatspaces();
	size_t count = 0;
	char ch = 0;

	while(isalpha(ch = getchar()))
	{
		name[count++] = ch;
		if(count == length)
			break;
	}
	name[count] = '\0';
	if(count < length)
	{
		ungetc(ch,stdin);
	}
	return name;

}
Example #7
0
void XMLParser::parseTag(const char *tag, Properties *p){
   if (isempty(tag))
      return;

   size_t len = strlen(tag);
   size_t pos = 0;

   eatspaces();

   StringBuffer *sb1 = new StringBuffer();

   //Fixing bugs like <A>text< / A>
   if (tag[pos] == OFFTAGc){
      sb1->add(OFFTAGc);
      pos++;
      eatspaces();
   }

   for (; CLEN && !isspace(tag[pos]); pos++)
      sb1->add(tag[pos]);

   p->put(XMLTAGPARSEKEY, sb1->get());

   StringBuffer *sb2 = new StringBuffer();

   while (CLEN){
      sb1->clear();
      sb2->clear();

      eatspaces();

      for (; CLEN && tag[pos]!='=' && !isspace(tag[pos]); pos++)
         sb1->add(tag[pos]);

      eatspaces();

      //This affect tags like <checkbox checked name="punk_rock_song">
      if (tag[pos] == '='){
         pos++; //for =


         eatspaces();

         if (tag[pos]!='\"')
            for (; CLEN && !isspace(tag[pos]); pos++)
               sb2->add(tag[pos]);
         else{
            pos++; //for ""
            for (; CLEN && tag[pos]!='\"'; pos++){
               /*   The following code make escape of some
                 characters, This is no element of standard
                 XML/HTML, but is very useful and do not
                 affect to language...

                 Example:
                    <P position="colona \"X\"">
                 Instead:
                    <P position="colona &quot;X&quot;">

                 Note:
                    There are base "unescape" too
               */
               if (tag[pos] == '\\')
                  if (CLEN)
                     pos++;

               sb2->add(tag[pos]);
            }
         }
      }

      sb1->toUpperCase();
      p->put(sb1->get(), sb2->get());
   }
}