コード例 #1
0
ファイル: ml_functions.c プロジェクト: JevonQ/nfs-ganesha
char *get_token(char *line, char **token, int *len, bool optional,
		enum requires_more requires_more, const char *invalid)
{
	char *c = line;

	if (optional)
		c = SkipWhite(c, REQUIRES_EITHER, invalid);
	else
		c = SkipWhite(c, REQUIRES_MORE, invalid);

	if (c == NULL)
		return c;

	if (optional && (*c == '\0' || *c == '#')) {
		*token = NULL;
		return c;
	}

	/* Skip token */
	*token = c;
	while (*c != ' ' && *c != '\0' && *c != '#')
		c++;

	*len = c - *token;

	return c;
}
コード例 #2
0
ファイル: ml_functions.c プロジェクト: JevonQ/nfs-ganesha
char *get_command(char *line, enum commands *cmd)
{
	enum commands i;
	char *t;
	char *c;
	int len;

	*cmd = NUM_COMMANDS;

	c = get_token(line, &t, &len, false, REQUIRES_EITHER,
		      "Invalid command 1");

	if (c == NULL)
		return c;

	for (i = CMD_OPEN; i < NUM_COMMANDS; i++) {
		if (len == commands[i].cmd_len
		    && strncasecmp(t, commands[i].cmd_name,
				   commands[i].cmd_len) == 0) {
			*cmd = i;
			if (i == CMD_QUIT)
				return SkipWhite(c, REQUIRES_EITHER, "");
			else
				return SkipWhite(c, REQUIRES_MORE,
						 "Invalid command 2");
		}
	}

	strcpy(errdetail, "Invalid command 3");
	strcpy(badtoken, line);
	return NULL;
}
コード例 #3
0
ファイル: vicarkeywordhandler.cpp プロジェクト: garnertb/gdal
int VICARKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue ) {

    osName = "";
    osValue = "";

    if( !ReadWord( osName ) ) {
    return FALSE;}

    SkipWhite();

    // VICAR has no NULL string termination
    if( *pszHeaderNext == '\0') {
        osName="END";
        return TRUE;
    }

    pszHeaderNext++;

    SkipWhite();

    osValue = "";

    if( *pszHeaderNext == '(' && pszHeaderNext[1] == '\'' )
    {
        CPLString osWord;
        while( ReadWord( osWord ) )
        {
            osValue += osWord;
            if ( strlen(osWord) < 2 ) continue;
            if( osWord[strlen(osWord)-1] == ')' && osWord[strlen(osWord)-2] == '\'' ) break;
        }
    }

    else if( *pszHeaderNext == '(' && *pszHeaderNext-1 != '\'' )
    {
        CPLString osWord;

        while( ReadWord( osWord ) )
        {
            SkipWhite();

            osValue += osWord;
            if( osWord[strlen(osWord)-1] == ')'  ) break;
        }
    }

    else
    {
        if( !ReadWord( osValue ) ) return FALSE;

    }

    SkipWhite();

    return TRUE;
}
コード例 #4
0
ファイル: ml_functions.c プロジェクト: JevonQ/nfs-ganesha
char *get_client(char *line, struct client **pclient, bool create,
		 enum requires_more requires_more)
{
	char *c = line;
	char *t;
	struct client *client;
	int len;

	c = get_token(line, &t, &len, false, requires_more, "Invalid client");

	if (c == NULL)
		return c;

	for (client = client_list; client != NULL; client = client->c_next) {
		if (strlen(client->c_name) != len)
			continue;
		if (strncmp(t, client->c_name, len) == 0)
			break;
	}

	*pclient = client;

	if (client == NULL) {
		if (create) {
			client = malloc(sizeof(*client));
			if (client == NULL) {
				strcpy(errdetail, "Could not create client");
				errno = ENOMEM;
				strncpy(badtoken, t, len);
				badtoken[len] = '\0';
				return NULL;
			}
			memset(client, 0, sizeof(*client));
			memcpy(client->c_name, t, len);
			client->c_name[len] = '\0';
			*pclient = client;
			c = SkipWhite(c, requires_more, "get_client");
			if (c == NULL)
				free(client);
			else if (!quiet && !syntax)
				fprintf(output, "Created temp client %s\n",
					client->c_name);
			return c;
		} else {
			strcpy(errdetail, "Could not find client");
			errno = ENOENT;
			strncpy(badtoken, t, len);
			badtoken[len] = '\0';
			return NULL;
		}
	}

	return SkipWhite(c, requires_more, "get_client");
}
コード例 #5
0
ファイル: TimeSpec.cpp プロジェクト: dyninc/OpenBFDD
TimeSpec::Unit TimeSpec::StringToUnit(const char *str)
{
  str = SkipWhite(str);

  if (TestString("nanoseconds",  str)
      || TestString("ns",  str))
    return Nanosec;

  if (TestString("microseconds",  str)
      || TestString("us",  str))
    return Microsec;

  if (TestString("milliseconds",  str)
      || TestString("ms",  str))
    return Millisec;

  if (TestString("seconds",  str)
      || TestString("sec",  str)
      || TestString("s",  str))
    return Seconds;

  if (TestString("minutes",  str)
      || TestString("min",  str)
      || TestString("m",  str))
    return Minutes;

  return None;
}
コード例 #6
0
ファイル: cmdline2.c プロジェクト: BuckRogers1965/Examples
// Get an Identifier
char * GetToken()
{
    int i=0, j, length;

    if (isspace(Look))
        Expected("Command String");

    while (!isspace(Look) && (Look != '\0') && (i < MAX_BUF))  {
        switch (Look) {
        case '"':
            GetQuotePart('"');
            length=strlen(QuotePart);
            for (j=0; j<length; j++)
                Token[i++]=QuotePart[j];
            continue;
        case '\'':
            GetQuotePart('\'');
            length=strlen(QuotePart);
            for (j=0; j<length; j++)
                Token[i++]=QuotePart[j];
            continue;
        case '\\':
            GetEscapePart();
            break;
        }

        Token[i]=Look;
        GetChar();
        i++;
    }

    Token[i]='\0';
    SkipWhite();
    return (Token);
}
コード例 #7
0
ファイル: vicarkeywordhandler.cpp プロジェクト: garnertb/gdal
int VICARKeywordHandler::ReadWord( CPLString &osWord )

{
    osWord = "";

    SkipWhite();

    if( *pszHeaderNext == '\0')
        return TRUE;

    if( !( *pszHeaderNext != '='  && !isspace((unsigned char)*pszHeaderNext)) )
        return FALSE;

    if( *pszHeaderNext == '\'' )
    {
        pszHeaderNext++;
        while( *pszHeaderNext != '\'' )
        {
            //Skip Double Quotes
            if( *pszHeaderNext+1 == '\'' )
                continue;
            osWord += *(pszHeaderNext++);
        }
        pszHeaderNext++;
        return TRUE;
    }

    while( *pszHeaderNext != '=' && !isspace((unsigned char)*pszHeaderNext) )
    {
        osWord += *pszHeaderNext;
        pszHeaderNext++;
    }

    return TRUE;
}
コード例 #8
0
ファイル: ntasm.c プロジェクト: mingpen/OpenNT
ULONG
GetToken (PUCHAR inString, PUCHAR *outString, PUCHAR outToken, ULONG maxcnt)
{
    UCHAR   ch;
    ULONG   count = 0;

    inString = SkipWhite(&inString);

    while (count < maxcnt) {
        ch = (UCHAR)tolower(*inString);

	if (!((ch >= '0' && ch <= '9') ||
	      (ch >= 'a' && ch <= 'z') ||
              (ch == '$') ||
              (ch == '_') ||
              (ch == '#')))
		break;

	count++;
        *outToken++ = ch;
	inString++;
	}

    *outToken = '\0';
    *outString = inString;

    return (count >= maxcnt ? 0 : count);
}
コード例 #9
0
ファイル: config.c プロジェクト: spicavigo/elementtidy
Bool ParseRepeatAttr( TidyDocImpl* doc, const TidyOptionImpl* option )
{
    Bool status = yes;
    tmbchar buf[64] = {0};
    uint i = 0;

    TidyConfigImpl* cfg = &doc->config;
    tchar c = SkipWhite( cfg );

    while (i < sizeof(buf)-1 && c != EndOfStream && !IsWhite(c))
    {
        buf[i++] = (tmbchar) c;
        c = AdvanceChar( cfg );
    }
    buf[i] = '\0';

    if ( tmbstrcasecmp(buf, "keep-first") == 0 )
        cfg->value[ TidyDuplicateAttrs ].v = TidyKeepFirst;
    else if ( tmbstrcasecmp(buf, "keep-last") == 0 )
        cfg->value[ TidyDuplicateAttrs ].v = TidyKeepLast;
    else
    {
        ReportBadArgument( doc, option->name );
        status = no;
    }
    return status;
}
コード例 #10
0
ファイル: config.c プロジェクト: spicavigo/elementtidy
Bool ParseCharEnc( TidyDocImpl* doc, const TidyOptionImpl* option )
{
    tmbchar buf[64] = {0};
    uint i = 0;
    int enc = ASCII;
    Bool validEncoding = yes;
    tchar c = SkipWhite( &doc->config );

    while ( i < sizeof(buf)-2 && c != EndOfStream && !IsWhite(c) )
    {
        buf[i++] = (tmbchar) ToLower( c );
        c = AdvanceChar( &doc->config );
    }
    buf[i] = 0;

    enc = CharEncodingId( buf );

#ifdef TIDY_WIN32_MLANG_SUPPORT
    /* limit support to --input-encoding */
    if (option->id != TidyInCharEncoding && enc > WIN32MLANG)
        enc = -1;
#endif

    if ( enc < 0 )
    {
        validEncoding = no;
        ReportBadArgument( doc, option->name );
    }
    else
        SetOptionInt( doc, option->id, enc );

    if ( validEncoding && option->id == TidyCharEncoding )
        AdjustCharEncoding( doc, enc );
    return validEncoding;
}
コード例 #11
0
ファイル: config.c プロジェクト: spicavigo/elementtidy
/* #508936 - CSS class naming for -clean option */
Bool ParseCSS1Selector( TidyDocImpl* doc, const TidyOptionImpl* option )
{
    char buf[256] = {0};
    uint i = 0;
    uint c = SkipWhite( &doc->config );

    while ( i < sizeof(buf)-2 && c != EndOfStream && !IsWhite(c) )
    {
        buf[i++] = (tmbchar) c;
        c = AdvanceChar( &doc->config );
    }
    buf[i] = '\0';

    if ( i == 0 || !IsCSS1Selector(buf) ) {
        ReportBadArgument( doc, option->name );
        return no;
    }

    buf[i++] = '-';  /* Make sure any escaped Unicode is terminated */
    buf[i] = 0;      /* so valid class names are generated after */
                     /* Tidy appends last digits. */

    SetOptionValue( doc, option->id, buf );
    return yes;
}
コード例 #12
0
ファイル: config.c プロジェクト: spicavigo/elementtidy
/* cr, lf or crlf */
Bool ParseNewline( TidyDocImpl* doc, const TidyOptionImpl* entry )
{
    int nl = -1;
    tmbchar work[ 16 ] = {0};
    tmbstr cp = work, end = work + sizeof(work);
    TidyConfigImpl* cfg = &doc->config;
    tchar c = SkipWhite( cfg );

    while ( c!=EndOfStream && cp < end && !IsWhite(c) && c != '\r' && c != '\n' )
    {
        *cp++ = (tmbchar) c;
        c = AdvanceChar( cfg );
    }
    *cp = 0;

    if ( tmbstrcasecmp(work, "lf") == 0 )
        nl = TidyLF;
    else if ( tmbstrcasecmp(work, "crlf") == 0 )
        nl = TidyCRLF;
    else if ( tmbstrcasecmp(work, "cr") == 0 )
        nl = TidyCR;

    if ( nl < TidyLF || nl > TidyCR )
        ReportBadArgument( doc, entry->name );
    else
        SetOptionInt( doc, entry->id, nl );
    return ( nl >= TidyLF && nl <= TidyCR );
}
コード例 #13
0
/* initialize */
void Init()
{
    GetChar();
    SkipWhite();
    InitTable();
    ClearParams();
}
コード例 #14
0
ファイル: ml_functions.c プロジェクト: JevonQ/nfs-ganesha
char *get_longlong(char *line, long long int *value,
		   enum requires_more requires_more, const char *invalid)
{
	char *c;
	char *t;
	char *e;
	int len;

	c = get_token(line, &t, &len, false, requires_more, invalid);
	if (c == NULL)
		return c;

	/* Extract value */
	if (*t == '*' && len == 1)
		*value = -1;
	else {
		*value = strtoll(t, &e, 0);
		if (e != NULL && e != c) {
			strcpy(errdetail, invalid);
			strncpy(badtoken, t, len);
			badtoken[len] = '\0';
			errno = EINVAL;
			return NULL;
		}
	}

	return SkipWhite(c, requires_more, invalid);
}
コード例 #15
0
ファイル: utils.cpp プロジェクト: Lennie/OpenBFDD
  bool StringToInt(const char *arg, uint64_t &value, const char **outNext)
  {
    uint64_t val = 0;
    const char *next;

    value = 0;
    if (!arg)
      return false;

    next = SkipWhite(arg);

    if (*next == '+')
      next++;
    else if (*next == '-')
      return false;

    if (!isdigit(*next))
      return false;

    for (; isdigit(*next); next++)
      val = val*10 + *next - '0';

    value = val;

    if (!::isspace(*next) && *next != '\0')
      return false;

    if (outNext)
      *outNext = next;

    return true;
  }
コード例 #16
0
ファイル: TaskFactory.cpp プロジェクト: danluu/BitFunnel
    std::string TaskFactory::GetNextToken(char const * & text)
    {
        std::string token;

        SkipWhite(text);

        if (*text == '"')
        {
            // Quoted string literal
            ++text;
            while (*text != '"')
            {
                if (*text == '\0')
                {
                    RecoverableError error("Expected closing \" in string literal.");
                    throw error;
                }
                token.push_back(*text);
                ++text;
            }
            Consume(text, '"');
        }
        else if (*text != '\0')
        {
            // Non-quoted literal.
            std::string s;
            while (!IsSpace(*text) && *text != '\0')
            {
                token.push_back(*text);
                ++text;
            }
        }

        return token;
    }
コード例 #17
0
ファイル: ml_functions.c プロジェクト: JevonQ/nfs-ganesha
char *get_str(char *line, char *str, long long int *len,
	      enum requires_more requires_more)
{
	char *c = line;
	char *t;
	int quoted;

	c = SkipWhite(c, REQUIRES_MORE, "get_str 1");
	if (c == NULL)
		return c;

	if (*c != '"') {
		if (requires_more != REQUIRES_NO_MORE) {
			errno = EINVAL;
			strcpy(errdetail, "Expected string");
			strcpy(badtoken, c);
			return NULL;
		}
		quoted = false;
	} else {
		c++;
		quoted = true;
	}

	t = c;

	if (quoted)
		while (*c != '"' && *c != '\0')
			c++;
	else
		while (*c != '\0')
			c++;

	if (quoted && *c == '\0') {
		errno = EINVAL;
		strcpy(errdetail, "Unterminated string");
		strcpy(badtoken, t - 1);
		return NULL;
	}
	*len = c - t;
	memcpy(str, t, *len);
	c++;

	return SkipWhite(c, requires_more, "get_str 2");
}
コード例 #18
0
ファイル: cradle3.c プロジェクト: BuckRogers1965/Examples
char GetName(){
   char GetName;
   if (!IsAlpha(Look[0]))
      Expected("Name");
   GetName = Look[0];
   GetChar();
   SkipWhite();
   return GetName;
}
コード例 #19
0
ファイル: cmdline2.c プロジェクト: BuckRogers1965/Examples
// Initialize
void Init(char * StringToParse) {

    Look = 0;
    LookOffset=-1;
    LookString = StringToParse;
    LookLength = strlen(LookString);

    GetChar();
    SkipWhite();
}
コード例 #20
0
void Decl() {
  GetName();
  Alloc(Value);
  SkipWhite();
  while (Look == ',') {
    Match(',');
    GetName();
    Alloc(Value);
  }
}
コード例 #21
0
void Match(char x)
{
    if(Look == x) {
        GetChar();
        SkipWhite();
    } else {
        sprintf(tmp, "' %c ' ",  x);
        Expected(tmp);
    }
}
コード例 #22
0
/* Get a number */
char GetNum(void)
{
    if (!IsDigit(Look)) {
        Expected("Integer");
    }
    char num = Look;
    GetChar();
    SkipWhite();
    return num;
}
コード例 #23
0
ファイル: utils.cpp プロジェクト: Lennie/OpenBFDD
  bool StringToInt(const char *arg, uint64_t &value)
  {
    const char *next;
    if (!StringToInt(arg, value, &next))
      return false;

    next = SkipWhite(next);

    return(*next == '\0');
  }
コード例 #24
0
/* Get an identifier */
char GetName(void)
{
    if (! IsAlpha(Look)) {
        Expected("Name");
    }
    char name = upcase(Look);
    GetChar();
    SkipWhite();
    return name;
}
コード例 #25
0
ファイル: scanner.c プロジェクト: pmprog/cc65
static void StringConst (void)
/* Parse a quoted string */
{
    /* String buffer */
    StrBuf S = AUTO_STRBUF_INITIALIZER;

    /* Assume next token is a string constant */
    NextTok.Tok  = TOK_SCONST;

    /* Concatenate strings. If at least one of the concenated strings is a wide
    ** character literal, the whole string is a wide char literal, otherwise
    ** it's a normal string literal.
    */
    while (1) {

        /* Check if this is a normal or a wide char string */
        if (CurC == 'L' && NextC == '\"') {
            /* Wide character literal */
            NextTok.Tok = TOK_WCSCONST;
            NextChar ();
            NextChar ();
        } else if (CurC == '\"') {
            /* Skip the quote char */
            NextChar ();
        } else {
            /* No string */
            break;
        }

        /* Read until end of string */
        while (CurC != '\"') {
            if (CurC == '\0') {
                Error ("Unexpected newline");
                break;
            }
            SB_AppendChar (&S, ParseChar ());
        }

        /* Skip closing quote char if there was one */
        NextChar ();

        /* Skip white space, read new input */
        SkipWhite ();

    }

    /* Terminate the string */
    SB_AppendChar (&S, '\0');

    /* Add the whole string to the literal pool */
    NextTok.SVal = AddLiteralStr (&S);

    /* Free the buffer */
    SB_Done (&S);
}
コード例 #26
0
ファイル: cradle3.c プロジェクト: BuckRogers1965/Examples
int GetNum (){
   int x=0;
   if (!IsDigit(Look[0]))
      Expected("Integer");
   while (IsDigit(Look[0])){
      x = x*10 + Look[0]-'0';
      GetChar();
   }
   SkipWhite();
   return x;
}
コード例 #27
0
/* match a specific input character */
void Match(char c)
{
    if (Look == c) {
        GetChar();
    } else {
        char tmp_buf[MAX_BUF];
        sprintf(tmp_buf, "'%c'", c);
        Expected(tmp_buf);
    }
    SkipWhite();
}
コード例 #28
0
void Scan()
{ 
    /* in Unix/Linux, Endline is CR instead of LF CR in MSDOS*/
    SkipWhite();   
    while(Look == '\n') {
        Fin();
    }

    GetName();
    int index = Lookup(KWList, Value, KWNum);
    Token = KWCode[index+1];
}
コード例 #29
0
ファイル: xml.c プロジェクト: BuckRogers1965/Examples
// Match a Specific Input Character
int Match( char x )
{
	char x1[2];
	x1[0]=x;
	x1[1]='\0';

	if (Look != x) 
		Expected(x1);

	GetChar();
	SkipWhite();
}
コード例 #30
0
ファイル: cradle3.c プロジェクト: BuckRogers1965/Examples
void Match(char x){
   if (Look[0] == x){
      GetChar();
      SkipWhite();
   } else {
      char error[4];
      error[0]='\'';
      error[0]=x;
      error[0]='\'';
      error[0]='\0';
      Expected(error);
   }
}