Пример #1
0
TOKEN_T LexMacDef( STRM_T s )
/************************************
 * returns: MAC_TEXT, or MAC_WS up to EOL or $+
 */
{
    char    *cur;
    BOOLEAN onlyws;                 /* are we collecting ws?    */
    char    text[MAX_TOK_SIZE];     /* store stuff here temp.   */

    if( s == STRM_END ) {
        return( TOK_END );
    }
    if( s == STRM_MAGIC ) {
        return( TOK_MAGIC );
    }
    if( s == EOL ) {
        return( TOK_EOL );
    }

    assert( isascii( s ) );

    cur = text;

    if( s == DOLLAR ) {
        *cur++ = DOLLAR;
        s = PreGetCH();
        if( s == '+' ) {
            return( MAC_EXPAND_ON );
        }
    }

    onlyws = isws( s );

    while( cur - text < MAX_TOK_SIZE - 1 ) {
        *cur++ = s;

        s = PreGetCH();

        if(    s == STRM_END
            || s == STRM_MAGIC
            || s == EOL
            || s == DOLLAR
            || (onlyws && !isws( s ))
            || (!onlyws && isws( s )) ) {
            break;
        }
    }

    UnGetCH( s );

    *cur = NULLCHAR;
    CurAttr.u.ptr = StrDupSafe( text );

    if( onlyws ) {
        return( MAC_WS );
    }
    return( MAC_TEXT );
}
Пример #2
0
STATIC TOKEN_T lexSubString( STRM_T s )
/**************************************/
{
    char        text[MAX_TOK_SIZE];     /* temporary storage                */
    unsigned    pos;                    /* position in text                 */
    TOKEN_T     state;                  /* what are we collecting           */
    BOOLEAN     done;                   /* are we done collecting ?         */
    VECSTR      vec;                    /* build string here                */

    assert( isascii( s ) );

    vec = StartVec();

    if( ismacc( s ) ) {
        state = MAC_NAME;
    } else if( isws( s ) ) {
        state = MAC_WS;
    } else {
        state = MAC_PUNC;
    }

    pos = 0;
    done = FALSE;
    while( !done ) {
        text[pos++] = s;
        if( pos == MAX_TOK_SIZE - 1 ) {
            text[pos] = NULLCHAR;
            WriteVec( vec, text );
            pos = 0;
        }

        s = PreGetCH();
        switch( s ) {
        case EOL:               /* always stop on these characters */
        case STRM_END:
        case STRM_MAGIC:
        case ')':
        case DOLLAR:
            done = TRUE;
            break;
        default:
            switch( state ) {
            case MAC_NAME:  done = !ismacc( s );                break;
            case MAC_WS:    done = !isws( s );                  break;
            case MAC_PUNC:  done = ismacc( s ) || isws( s );    break;
            }
        }
    }
    UnGetCH( s );
    text[pos] = NULLCHAR;
    WriteVec( vec, text );

    CurAttr.u.ptr = FinishVec( vec );
    return( state );
}
Пример #3
0
STATIC BOOLEAN checkMacro( STRM_T s )
/*************************************
 * returns: TRUE    if the line WAS a macro defn
 *          FALSE   if it wasn't
 * recognizes:      {macc}+{ws}*"="{ws}*{defn}*"\n"
 *                  {macc}+{ws}*"+="{ws}*{defn}*"\n"
 * second gets translated from "macro += defn" to "macro=$+$(macro)$- defn"
 */
{
    char        mac[MAX_MAC_NAME];
    unsigned    pos;
    BOOLEAN     ws;

    pos = 0;
    while( pos < MAX_MAC_NAME && ismacc( s ) ) {
        mac[pos++] = s;
        s = PreGetCH();
    }
    if( pos == MAX_MAC_NAME ) {
        PrtMsgExit(( FTL | LOC | MAXIMUM_TOKEN_IS, MAX_MAC_NAME - 1 ));
    }
    mac[pos] = NULLCHAR;
    ws = isws( s );
    while( isws( s ) ) {
        s = PreGetCH();
    }
    if( s == '=' ) {
        DefMacro( mac );
        return( TRUE );          /* go around again */
    } else if( s == '+' ) {
        s = PreGetCH();
        if( s == '=' ) {
            InsString( ")$-", FALSE );
            InsString( mac, FALSE );
            InsString( "$+$(", FALSE );
            DefMacro( mac );
            return( TRUE );     /* go around again */
        }
        UnGetCH( s );
        s = '+';
    }


    UnGetCH( s );           /* not a macro line, put everything back*/
    if( ws ) {
        UnGetCH( SPACE );
    }
    InsString( StrDupSafe( mac + 1 ), TRUE );
    return( FALSE );
}
void evaluate(opmap_t *ops, const char *s, stack_t *stack)
{
	while(*s)
	{
		if(isws(*s))
		{
			/* skip whitespace */
			++s;
		}
		else if(isnum(*s))
		{
			/* lese eine zahl ein (siehe io.c)
			   und pushe sie auf den stack (siehe stack.c)
			*/
			if(stack_push(stack, read_number(&s)))
			{
				error(ERR_STACKFULL);
			}
		}
		else
		{
			/* eine buchstabengebunde funktion ist gefragt (siehe opmap.c) */
			op_fn cb = opmap_get(ops, *s++);

			if(!cb)
			{
				error(ERR_UNKNOWN);
			}

			cb(stack);
		}
	}
}
Пример #5
0
/*
 **************************************************************
 * Functions to read the input stream in an attempt to match incoming
 * data to the current pattern from the main loop of _doscan().
 **************************************************************
 */
static int
number(int stow, int type, int len, int size, FILE *iop, va_list *listp)
{
	char numbuf[64], inchar, lookahead;
	char *np = numbuf;
	int c, base;
	int digitseen = 0, floater = 0, negflg = 0;
	long lcval = 0;
	switch(type)
	{
	case 'e':
	case 'f':
	case 'g':
		floater++;
	case 'd':
	case 'u':
	case 'i':
		base = 10;
		break;
	case 'o':
		base = 8;
		break;
	case 'x':
		base = 16;
		break;
	default:
		return(0); /* unrecognized conversion character */
	}
	if (!flag_eof)
	{
		while (isws(c = locgetc()))
			;
	}
	else
		c = locgetc();
	if (c == EOF) {
		chcount--;
		return(-1);	/* EOF before match */
	}
        if (floater != 0) {     /* Handle floating point with
                                 * file_to_decimal. */
                decimal_mode    dm;
                decimal_record  dr;
                fp_exception_field_type efs;
                enum decimal_string_form form;
                char           *echar;
                int             nread, ic;
                char            buffer[1024];
                char           *nb = buffer;

                locungetc(c);
		if (len > 1024)
			len = 1024;
                file_to_decimal(&nb, len, 0, &dr, &form, &echar, iop, &nread);
                if (stow && (form != invalid_form)) {
                        dm.rd = fp_direction;
                        if (size == 'l') {      /* double */
                                decimal_to_double((double *) va_arg(*listp, double *), &dm, &dr, &efs);
                        } else if (size == 'L') {      /* quad */
Пример #6
0
static char *
skipws(char *s)
{
	while (isws(*s)) {
		s++;
	}
	return s;
}
Пример #7
0
/**
 * Skip all whitespaces
 * @param state
 * @return 
 */
static int skipWs(lex_state_t * state) {
    int someSpace = 0;
    while (!iseos(state) && isws(state->pos[0])) {
        state->pos++;
        someSpace++;
    }

    return someSpace;
}
Пример #8
0
char *SkipWS( char *p )
/*****************************
 * p is not const because the return value is usually used to write data.
 */
{
    while( isws( *p ) ) {
        ++p;
    }
    return( p );
}
static void XMLCALL text_proc(void* data, const char* text, int len)
{
    Data*                   p = (Data*)data;
    SkXMLPullParser::Curr*  c = p->fCurr;

    c->fName = dupstr(p->fAlloc, text, len);
    c->fIsWhitespace = isws(c->fName);

    c->fEventType = SkXMLPullParser::TEXT;
    XML_StopParser(p->fParser, true);
}
Пример #10
0
int main( void )
/***************/
{
    int     i;
    bool    noneyet;

    /*printf( "extern UINT8 IsArray[] = {\n" );*/
    printf( "/*STRM_MAGIC*/  0,\n" );
    printf( "/*STRM_END  */  0" );      /* note: no ",\n" !! */

    for( i = 0; i <= 255; i++ ) {
        noneyet = true;

        if( isprint( i ) ) {
            printf( ",\n/*   '%c'    */  ", i );
        } else {
            printf( ",\n/*   0x%02x   */  ", i );
        }

        if( isws( i ) ) {
            BAR( IS_WS    );
        }
        if( isprt( i ) ) {
            BAR( IS_PRINT );
        }
        if( isalpha( i ) ) {
            BAR( IS_ALPHA );
        }
        if( isextc( i ) ) {
            BAR( IS_EXTC  );
        }
        if( isdirc( i ) ) {
            BAR( IS_DIRC  );
        }
        if( isfilec( i ) ) {
            BAR( IS_FILEC );
        }
        if( ismacc( i ) ) {
            BAR( IS_MACC );
        }
        if( isbarf( i ) ) {
            BAR( IS_BARF );
        }

        if( noneyet ) {
            printf( "0" );
        }
    }

    /*printf("\n};\n");*/
    printf( "\n" );
    return( 0 );
}
Пример #11
0
/*****************************************************************
  * Simplistic and quite Standard, but a bit slow.  This should be
  * templatized on basic_string instead, or on a more generic StringT
  * that just happens to support ::size_type, .substr(), and so on.
  * I had hoped that "whitespace" would be a trait, but it isn't, so
  * the user must supply it.  Enh, this lets them break up strings on
  * different things easier than traits would anyhow.
   void stringtok (Container &l, std::string const &s, char const * const ws = " \t\n")

*/
  void string_to_vector(const std::string& s,std::vector<double>& l,const char *ws/*=" ,"*/)
  {
    const std::string::size_type  S = s.size();
    std::string::size_type  i = 0;

    while (i < S) {
      // eat leading whitespace
      while ((i < S) && (isws(s[i],ws)))  ++i;
      if (i == S)  return;  // nothing left but WS

      // find end of word
      std::string::size_type  j = i+1;
      while ((j < S) && (!isws(s[j],ws)))  ++j;

      // add word
      l.push_back(atof(s.substr(i,j-i).c_str()));

        // set up for next loop
      i = j+1;
    }
  }
Пример #12
0
void
stringtok (Container &l, std::string const &s, char const * const ws = " \t\n")
{
    const string::size_type  S = s.size();
          string::size_type  i = 0;

    while (i < S) {
        // eat leading whitespace
        while ((i < S) && (isws(s[i],ws)))  ++i;
        if (i == S)  return;  // nothing left but WS

        // find end of word
        string::size_type  j = i+1;
        while ((j < S) && (!isws(s[j],ws)))  ++j;

        // add word
        l.push_back(s.substr(i,j-i));

        // set up for next loop
        i = j+1;
    }
}
Пример #13
0
char *FindNextWS( char *str )
/***********************************
 * Finds next free white space character, allowing doublequotes to
 * be used to specify strings with white spaces.
 *
 * str is not const because the return value is usually used to write data.
 */
{
    char    string_open = 0;

    while( *str != NULLCHAR ) {
        if( *str == BACKSLASH ) {
            str++;
            if( *str != NULLCHAR ) {
                if( !string_open && isws ( *str ) ) {
                    break;
                }
                str++;
            }
        } else {
            if( *str == DOUBLEQUOTE ) {
                string_open = !string_open;
                str++;
            } else {
                if( string_open ) {
                    str++;
                } else {
                    if( isws( *str ) ) {
                        break;
                    }
                    str++;
                }
            }
        }
    }

    return( str );
}
Пример #14
0
int
_doscan(FILE *iop, unsigned char *fmt, va_list va_alist)
{
	char tab[NCHARS];
	int ch;
	int nmatch = 0, len, inchar, stow, size;
	chcount=0; flag_eof=0;

	/*******************************************************
	 * Main loop: reads format to determine a pattern,
	 *		and then goes to read input stream
	 *		in attempt to match the pattern.
	 *******************************************************/
	for ( ; ; )
	{
		if ( (ch = *fmt++) == '\0')
			return(nmatch); /* end of format */
		if (isws(ch))
		{
		  	if (!flag_eof) 
			{
			   while (isws(inchar = locgetc()))
				;
			   if (inchar == EOF) {
				chcount--;
				flag_eof = 1;
			   }
			   else if (locungetc(inchar) == EOF)
				flag_eof = 1;
			}
		  continue;
		}
		if (ch != '%' || (ch = *fmt++) == '%')
                {
			if ( (inchar = locgetc()) == ch )
				continue;
			if (inchar != EOF) {
				if (locungetc(inchar) != EOF)
					return(nmatch); /* failed to match input */
			} else {
				chcount--;
			}
			break;
		}
		if (ch == '*')
		{
			stow = 0;
			ch = *fmt++;
		}
		else
			stow = 1;

		for (len = 0; isdigit(ch); ch = *fmt++)
			len = len * 10 + ch - '0';
		if (len == 0)
			len = MAXINT;
		if ( (size = ch) == 'l' || (size == 'h') || (size == 'L') )
			ch = *fmt++;
		if (ch == '\0' ||
		    ch == '[' && (fmt = setup(fmt, tab)) == NULL)
			return(EOF); /* unexpected end of format */
		if (isupper(ch))  /* no longer documented */
		{
			/*
			 * The rationale behind excluding the size
			 * of 'L' is that the 'L' size specifier was
			 * introduced in ANSI/ISO-C.  If the user
			 * specifies a format of %LG, it can mean
			 * nothing other than "long double", be the
			 * code ANSI or not.  Mapping it to "double"
			 * makes no sense.
			 */
			if (size != 'L')
				size = 'l';
#ifdef S5EMUL
			ch = _tolower(ch);
#else
			ch = tolower(ch);
#endif
		}
		switch(ch)
		{
		 case 'c':
		 case 's':
		 case '[':
			  if ((size = string(stow,ch,len,tab,iop,&va_alist)) < 0)
				goto out;	/* EOF seen, nothing converted */
			  break;
                 case 'n':
			  if (stow == 0)
				continue;
			  if (size == 'h')
				*va_arg(va_alist, short *) = (short) chcount;
		          else if (size == 'l')
				*va_arg(va_alist, long *) = (long) chcount;
			  else
			  	*va_arg(va_alist, int *) = (int) chcount;
			  continue;
                 default:
			 if ((size = number(stow, ch, len, size, iop, &va_alist)) < 0)
				goto out;	/* EOF seen, nothing converted */
			 break;
                 }
		   if (size)
			nmatch += stow;
		   else 
			return((flag_eof && !nmatch) ? EOF : nmatch);
		continue;
	}
out:
	return (nmatch != 0 ? nmatch : EOF); /* end of input */
}
Пример #15
0
static int
argcv_scan (struct argcv_info *ap)
{
  int i = 0;
  int len = ap->len;
  const char *command = ap->command;
  const char *delim = ap->delim;
  const char *comment = ap->comment;
  
  for (;;)
    {
      i = ap->save;

      if (i >= len)
	return i + 1;

      /* Skip initial whitespace */
      while (i < len && isws (command[i]))
	i++;
      ap->start = i;

      if (!isdelim (command[i], delim))
	{
	  while (i < len)
	    {
	      if (command[i] == '\\')
		{
		  if (++i == len)
		    break;
		  i++;
		  continue;
		}
	      
	      if (command[i] == '\'' || command[i] == '"')
		{
		  int j;
		  for (j = i + 1; j < len && command[j] != command[i]; j++)
		    if (command[j] == '\\')
		      j++;
		  if (j < len)
		    i = j + 1;
		  else
		    i++;
		}
	      else if (isws (command[i]) || isdelim (command[i], delim))
		break;
	      else
		i++; /* skip the escaped character */
	    }
	  i--;
	}
      else if (!(ap->flags & DICO_ARGCV_RETURN_DELIMS))
	{
	  while (i < len && isdelim (command[i], delim))
	    i++;
	  ap->save = i;
	  continue;
	}
      

      ap->end = i;
      ap->save = ap->finish_pos = i + 1;

      /* If we have a token, and it starts with a comment character, skip
         to the newline and restart the token search. */
      if (ap->save <= len)
	{
	  if (strchr (comment, command[ap->start]) != NULL)
	    {
	      ap->finish_pos = ap->start;
	      i = ap->save;
	      while (i < len && command[i] != '\n')
		i++;

	      ap->save = i;
	      continue;
	    }
	}
      break;
    }
  return ap->save;
}
Пример #16
0
TOKEN_T LexPath( STRM_T s )
/*********************************
 * returns: ({filec}*";")+          TOK_PATH
 *          EOL                     EOL
 *          STRM_END                STRM_END
 */
{
    char        path[_MAX_PATH];
    char        string_open;
    unsigned    pos;
    VECSTR      vec;                /* we'll store file/path here */

    for( ;; ) {                     /* get first valid character */
        if( s == EOL || s == STRM_END ) {
            /* now we pass this to LexParser() so that it can reset */
            return( LexParser( s ) );
        }

        if( s == STRM_MAGIC ) {
            InsString( DeMacro( TOK_EOL ), TRUE );
        } else if( !isfilec( s ) && s != PATH_SPLIT && s != ';' && s != '\"' && !isws( s ) ) {
            PrtMsg( ERR | LOC | EXPECTING_M, M_PATH );
        } else if( !isws( s ) ) {
            break;
        }

        s = PreGetCH(); /* keep fetching characters */
    }
    /* just so you know what we've got now */
    assert( isfilec( s ) || s == PATH_SPLIT || s == ';' || s == '\"' );

    vec = StartVec();

    pos = 0;
    for( ;; ) {
        /*
         * Extract path from stream. If double quote is found, start string mode
         * and ignore all filename character specifiers and just copy all
         * characters. String mode ends with another double quote. Backslash can
         * be used to escape only double quotes, otherwise they are recognized
         * as path seperators.  If we are not in string mode character validity
         * is checked against isfilec().
         */

        string_open = 0;

        while( pos < _MAX_PATH && s != EOL && s != STRM_END ) {
            if( s == BACKSLASH ) {
                s = PreGetCH();

                if( s == DOUBLEQUOTE ) {
                    path[pos++] = DOUBLEQUOTE;
                } else if( s == EOL || s == STRM_END ) {
                    // Handle special case when backslash is placed at end of
                    // line or file
                    path[pos++] = BACKSLASH;
                } else {
                    path[pos++] = BACKSLASH;

                    // make sure we don't cross boundaries
                    if( pos < _MAX_PATH ) {
                        path[pos++] = s;
                    }
                }
            } else {
                if( s == DOUBLEQUOTE ) {
                    string_open = !string_open;
                } else {
                    if( string_open ) {
                        path[pos++] = s;
                    } else if( isfilec( s ) ) {
                        path[pos++] = s;
                    } else {
                        break; // not valid path character, break out.
                    }
                }
            }

            s = PreGetCH();
        }

        if( string_open ) {
            FreeSafe( FinishVec( vec ) );
            PrtMsgExit(( FTL | LOC | ERROR_STRING_OPEN ));
        }

        if( pos == _MAX_PATH ) {
            FreeSafe( FinishVec( vec ) );
            PrtMsgExit(( FTL | LOC | MAXIMUM_TOKEN_IS, _MAX_PATH - 1 )); // NOTREACHED
        }

        path[pos] = NULLCHAR;
        WriteVec( vec, path );

        if( s != PATH_SPLIT && s != ';' ) {
            break;
        }

        pos = 0;
        path[pos++] = PATH_SPLIT;
        s = PreGetCH();        /* use Pre here to allow path;&(nl)path */
    }
    UnGetCH( s );

    CurAttr.u.ptr = FinishVec( vec );

    return( TOK_PATH );
}
Пример #17
0
int evaluate(int t)
{
	int err = 0;

	/* switch on lookup */
	switch(t)
	{
		case '+':
		case '-':
		case '*':
		case '/':
			/* binaere rechenoperation */
			/* wenn fehlerwert zurueckgegeben wird
			   wird die fehlerroutine aufgerufen */
			if((err = binop_f(t))) error(err);
			break;
		/* stack metafunctionen */
		case 'p':
			if((err = p_f())) error(err);
			break;
		case 'f':
			if((err = f_f())) error(err);
			break;
		case 'c':
			if((err = c_f())) error(err);
			break;
		case 'd':
			if((err = d_f())) error(err);
			break;
		case 'r':
			if((err = r_f())) error(err);
			break;
		/* EOS fuer stdin oder 'q' -> quit */
		case EOF:
			printf("Reached end of input.\n");
		case 'q':
			printf("Goodbye.\n");
			return FALSE;
		default:
			/* wenn lookup whitespace ist, ignorieren */
			if(isws(t)) ;
			/* andernfalls wenn lookup eine ziffer ist
			   zahl einlesen und auf den stack legen */
			else if(isnum(t))
			{
				uint v = 0;

				if((err = read_int(&v)) || (err = stack_push(v)))
				{
					error(err);
				}

				/* recursion damit der lookup nach einlesen
				   der zahl nicht in main ueberschrieben wird. */
				return evaluate(lookup(NULL));
			}
			/* andernfalls ist ein unbekannter befehl eingelesen worden */
			else
			{
				error(ERR_MAIN_UNKNOWN);
			}
	}

	return TRUE;
}
Пример #18
0
static aqwin_param *parse_cfg(const char *cfg) {
	char *cp;
	aqwin_param *param;
	aqwin_tuple *last;

	if ((param = malloc(sizeof *param)) == NULL) {
		complain("aqwin_open: nomem param\n");
		goto e0_nomem_param;
	}
	memset(param, 0, sizeof *param);
	if ((param->buf = malloc(strlen(cfg))) == NULL) {
		complain("aqwin_open: nomem param buf\n");
		goto e1_nomem_parambuf;
	}
	strcpy(param->buf, cfg);
	if ((param->attr = malloc(sizeof *(param->attr))) == NULL) {
		complain("aqwin_open: nomem param attr\n");
		goto e2_nomem_paramattr;
	}
	memset(param->attr, 0, sizeof *(param->attr));
	
	last = param->attr;
	
	cp = param->buf;
	for(eatwhite(&cp); *cp; cp++) {
	skip_inc:
		if(*cp == '=' && last->key == NULL) {
			complain("aqwin_open: keys cannot begin with '='\n");
			goto e3_parse_error;
		} 
		else if(*cp == '=') {
			*cp = '\0';
			last->val = cp + 1;
		}
		else if(*cp == '\'') {
			*cp++ = '\0';
			if (last->val) {
				last->val = cp;
			} else {
				complain("aqwin_open: quoted key\n");
				goto e3_parse_error;
			}
			if (charff(&cp, '\'')) {
				*cp++ = '\0';
			} else {
				complain("aqwin_open: unterminated string\n");
				goto e3_parse_error;
			}
			eatwhite(&cp);
			if((last->next = malloc(sizeof *last)) == NULL) {
				complain("aqwin_open: nomem next param\n");
				goto e3_nomem_paramnext;
			}
			last = last->next;
			memset(last, 0, sizeof *last);
			goto skip_inc;
		}
		else if(isws(*cp)) {
			*cp = '\0';
			last->val = last->val ? last->val : cp;
			if (parse_attr(last)) {
				goto e3_parse_error;
			}
			cp++;
			eatwhite(&cp);
			if((last->next = malloc(sizeof *last)) == NULL) {
				complain("aqwin_open: nomem next param\n");
				goto e3_nomem_paramnext;
			}
			last = last->next;
			memset(last, 0, sizeof *last);
			goto skip_inc;
		}
		else if(last->key == NULL) {
			last->key = cp;
		}
	}
	return param;

e3_nomem_paramnext:
e3_parse_error:
	aqwin_tuple_free(param->attr);
e2_nomem_paramattr:
	free(param->buf);
e1_nomem_parambuf:
	free(param);
e0_nomem_param:
	return NULL;
}
Пример #19
0
char *RemoveDoubleQuotes( char *dst, size_t maxlen, const char *src )
/************************************************************************
 * Removes doublequote characters from string and copies other content
 * from src to dst. Only maxlen number of characters are copied to dst
 * including terminating NUL character.
 */
{
    char    *orgdst = dst;
    char    string_open = 0;
    size_t  pos = 0;
    int     t;

    assert( maxlen );

    // leave space for NUL terminator
    maxlen--;

    while( pos < maxlen ) {
        t = *src++;

        if( t == NULLCHAR ) {
            break;
        }

        if( t == BACKSLASH ) {
            t = *src++;

            if( t == DOUBLEQUOTE ) {
                *dst++ = DOUBLEQUOTE;
                pos++;
            } else {
                *dst++ = BACKSLASH;
                pos++;

                if( pos < maxlen ) {
                    *dst++ = t;
                    pos++;
                }
            }
        } else {
            if( t == DOUBLEQUOTE ) {
                string_open = !string_open;
            } else {
                if( string_open ) {
                    *dst++ = t;
                    pos++;
                } else
                if( isws( t ) ) {
                    break;
                } else {
                    *dst++ = t;
                    pos++;
                }
            }
        }
    }

    *dst = NULLCHAR;

    return( orgdst );
}
Пример #20
0
STATIC char *DeMacroDoubleQuote( BOOLEAN IsDoubleQuote )
/*******************************************************
 * This procedure takes care of double quotes in the stream
 * Note: each double quote must be paired with a double quote in the
 * input stream or this will expand until the EOL a backlash double
 * quote will be considered as a non-double quote.
 */
{
    char    buffer[_MAX_PATH];
    char    *current;
    char    *p;
    VECSTR  OutString;
    int     pos;
    STRM_T  s;
    BOOLEAN StartDoubleQuote;


    s = PreGetCH();
    UnGetCH( s );
    if( s == EOL || s == STRM_END || s == STRM_MAGIC ) {
        return( StrDupSafe( "" ) );
    }
    if( s == STRM_TMP_LEX_START ) {
        PreGetCH();  /* Eat STRM_TMP_LEX_START */
        pos = 0;
        for( s = PreGetCH(); s != STRM_MAGIC && pos < _MAX_PATH; s = PreGetCH() ) {
            assert( s != EOL || s != STRM_END );
            buffer[pos++] = s;
        }

        if( pos >= _MAX_PATH ) {
            PrtMsgExit(( FTL | LOC | MAXIMUM_TOKEN_IS, _MAX_PATH - 1 )); // NOTREACHED
        }

        buffer[pos] = NULLCHAR;
        p = StrDupSafe( buffer );
    } else {
        p = DeMacro( MAC_WS );
    }

    StartDoubleQuote = IsDoubleQuote;

    for( current = p; *current != NULLCHAR; ++current ) {
        if( *current == DOUBLEQUOTE ) {
            if( !IsDoubleQuote ) {
                /* Found the start of a Double Quoted String */
                if( current != p ) {
                    UnGetCH( STRM_MAGIC );
                    InsString( StrDupSafe( current ), TRUE );
                    UnGetCH( STRM_TMP_LEX_START );
                    *current = NULLCHAR;
                    return( p );
                }
                IsDoubleQuote = TRUE;
            } else {
                /* Found the end of the Double Quoted String */
                if( *(current + 1) != NULLCHAR) {
                    UnGetCH( STRM_MAGIC );
                    InsString( StrDupSafe( current + 1 ), TRUE );
                    UnGetCH( STRM_TMP_LEX_START );
                    *(current + 1) = NULLCHAR;
                }
                return( p );
            }
        }
    }

    if( !StartDoubleQuote && !IsDoubleQuote ) {
        /* there are no double quotes in the text */
        /* so return text as is */
        return( p );

    }
    pos = 0;
    s = PreGetCH();
    while( isws( s ) ) {
        buffer[pos++] = s;
        s = PreGetCH();
    }
    buffer[pos] = NULLCHAR;
    UnGetCH( s );
    OutString = StartVec();
    CatStrToVec( OutString, p );
    FreeSafe( p );
    CatStrToVec( OutString, buffer );
    p = DeMacroDoubleQuote( TRUE );
    CatStrToVec( OutString, p );
    FreeSafe( p );
    return( FinishVec( OutString ) );
}
Пример #21
0
static void
readdumpfile(struct quotahandle *qh, FILE *f, const char *path,
	     struct qklist *seenkeys)
{
	char buf[128];
	unsigned lineno;
	unsigned long version;
	char *s;
	char *fields[8];
	unsigned num;
	char *x;
	struct quotakey key;
	struct quotaval val;
	int ch;

	lineno = 0;
	if (fgets(buf, sizeof(buf), f) == NULL) {
		errx(EXIT_FAILURE, "%s: EOF before quotadump header", path);
	}
	lineno++;
	if (strncmp(buf, "@format netbsd-quota-dump v", 27) != 0) {
		errx(EXIT_FAILURE, "%s: Missing quotadump header", path);
	}
	s = buf+27;
	errno = 0;
	version = strtoul(s, &s, 10);
	if (errno) {
		errx(EXIT_FAILURE, "%s: Corrupted quotadump header", path);
	}
	s = skipws(s);
	if (*s != '\0') {
		errx(EXIT_FAILURE, "%s: Trash after quotadump header", path);
	}

	switch (version) {
	    case 1: break;
	    default:
		errx(EXIT_FAILURE, "%s: Unsupported quotadump version %lu",
		     path, version);
	}

	while (fgets(buf, sizeof(buf), f)) {
		lineno++;
		if (buf[0] == '#') {
			continue;
		}
		if (!strncmp(buf, "@end", 4)) {
			s = skipws(buf+4);
			if (*s != '\0') {
				errx(EXIT_FAILURE, "%s:%u: Invalid @end tag",
				     path, lineno);
			}
			break;
		}

		num = 0;
		for (s = strtok_r(buf, ws, &x);
		     s != NULL;
		     s = strtok_r(NULL, ws, &x)) {
			if (num < 8) {
				fields[num++] = s;
			} else {
				errx(EXIT_FAILURE, "%s:%u: Too many fields",
				     path, lineno);
			}
		}
		if (num < 8) {
			errx(EXIT_FAILURE, "%s:%u: Not enough fields",
			     path, lineno);
		}

		if (getidtype(fields[0], &key.qk_idtype)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid/unknown ID type %s",
			     path, lineno, fields[0]);
		}
		if (getid(fields[1], key.qk_idtype, &key.qk_id)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid ID number %s",
			     path, lineno, fields[1]);
		}
		if (getobjtype(fields[2], &key.qk_objtype)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid/unknown object "
			     "type %s",
			     path, lineno, fields[2]);
		}

		if (getlimit(fields[3], &val.qv_hardlimit)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid hard limit %s",
			     path, lineno, fields[3]);
		}
		if (getlimit(fields[4], &val.qv_softlimit)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid soft limit %s",
			     path, lineno, fields[4]);
		}
		if (getlimit(fields[5], &val.qv_usage)) {
			/*
			 * Make this nonfatal as it'll be ignored by
			 * quota_put() anyway.
			 */
			warnx("%s:%u: Invalid current usage %s",
			     path, lineno, fields[5]);
			val.qv_usage = 0;
		}
		if (gettime(fields[6], &val.qv_expiretime)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid expire time %s",
			     path, lineno, fields[6]);
		}
		if (gettime(fields[7], &val.qv_grace)) {
			errx(EXIT_FAILURE, "%s:%u: Invalid grace period %s",
			     path, lineno, fields[7]);
		}

		if (quota_put(qh, &key, &val)) {
			err(EXIT_FAILURE, "%s:%u: quota_put", path, lineno);
		}

		if (seenkeys != NULL) {
			qklist_add(seenkeys, &key);
		}
	}
	if (feof(f)) {
		return;
	}
	if (ferror(f)) {
		errx(EXIT_FAILURE, "%s: Read error", path);
	}
	/* not at EOF, not an error... what's left? */
	while (1) {
		ch = fgetc(f);
		if (ch == EOF)
			break;
		if (isws(ch)) {
			continue;
		}
		warnx("%s:%u: Trash after @end tag", path, lineno);
	}
}
Пример #22
0
static int
argcv_scan (int len, const char *command, const char *delim, const char *cmnt,
	    int *start, int *end, int *save)
{
  int i = 0;
  
  for (;;)
    {
      i = *save;

      if (i >= len)
	return i + 1;

      /* Skip initial whitespace */
      while (i < len && isws (command[i]))
	i++;
      *start = i;

      if (!isdelim (command[i], delim))
	{
	  while (i < len)
	    {
	      if (command[i] == '\\')
		{
		  if (++i == len)
		    break;
		  i++;
		  continue;
		}
	      
	      if (command[i] == '\'' || command[i] == '"')
		{
		  int j;
		  for (j = i+1; j < len && command[j] != command[i]; j++)
		    if (command[j] == '\\')
		      j++;
		  if (j < len)
		    i = j+1;
		  else
		    i++;
		}
	      else if (isws (command[i]) || isdelim (command[i], delim))
		break;
	      else
		i++; /* skip the escaped character */
	    }
	  i--;
	}

      *end = i;
      *save = i + 1;

      /* If we have a token, and it starts with a comment character, skip
         to the newline and restart the token search. */
      if (*save <= len)
	{
	  if (strchr (cmnt, command[*start]) != NULL)
	    {
	      i = *save;
	      while (i < len && command[i] != '\n')
		i++;

	      *save = i;
	      continue;
	    }
	}
      break;
    }
  return *save;
}
Пример #23
0
static void eatwhite(char **s) {
	while(isws(**s)) (*s)++;
}
Пример #24
0
TOKEN_T LexParser( STRM_T s )
/************************************
 * returns: next token for parser
 * remarks: possibly defines a macro
 */
{
    static BOOLEAN  atstart = TRUE;
    char            *p;

    for( ;; ) {

        if( atstart ) {
                /* atstart == TRUE if either of these succeed */
            if( isws( s ) ) {           /* cmd line */
                return( lexCmd() );
            }
            if( ismacc( s ) && checkMacro( s ) ) {  /* check if macro = body */
                s = PreGetCH();
                continue;
            }

            atstart = FALSE;
            UnGetCH( s );           /* put back our probe */
            s = STRM_MAGIC;         /* force macro expansion */
        }

        switch( s ) {
        case STRM_END:
            atstart = TRUE;
            return( TOK_END );
        case EOL:
            atstart = TRUE;
            return( TOK_EOL );
        case STRM_TMP_LEX_START:
        case STRM_MAGIC:
            p = DeMacroDoubleQuote( FALSE );  /* expand to next white space */
            if( *p == NULLCHAR ) {  /* already at ws */
                FreeSafe( p );
                s = PreGetCH();     /* eat the ws */
                while( isws( s ) ) {
                    s = PreGetCH();
                }
                if( s == EOL ) {
                    atstart = TRUE;
                    return( TOK_EOL );
                }
                if( s == STRM_END ) {
                    atstart = TRUE;
                    return( TOK_END );
                }
                UnGetCH( s );
                p = DeMacroDoubleQuote( FALSE );
            }
            UnGetCH( STRM_MAGIC );  /* mark spot we have to expand from nxt */
            InsString( p, TRUE );   /* put expansion in stream */
            break;
        case SPACE: /* fall through */
        case TAB:
            break;
        case L_CURL_PAREN:          /* could only be a sufsuf */
        case DOT:
            UnGetCH( s );
            return( lexDotName() ); /* could be a file... */
        case SEMI:                  /* treat semi-colon as {nl}{ws} */
            InsString( "\n ", FALSE );
            break;                  /* try again */
        case COLON:
            s = PreGetCH();
            if( s == COLON ) {
                return( TOK_DCOLON );
            }
            UnGetCH( s );
            return( TOK_SCOLON );
        default:
            if( isfilec( s ) || s == DOUBLEQUOTE ||
                ( (Glob.compat_nmake || Glob.compat_posix) &&  s == SPECIAL_TMP_DOL_C ) ) {
                return( lexFileName( s ) );
            }
            PrtMsg( WRN | LOC | UNKNOWN_TOKEN, s );
            break;
        }
        s = PreGetCH();             /* fetch a character */
    }
}