Exemple #1
0
/*
** The next function tells whether a key or value can be cleared from
** a weak table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for userdata
** being finalized, keep them in keys, but not in values
*/
static int iscleared (const TValue *o, int iskey) {
  if (!iscollectable(o)) return 0;
  if (ttisstring(o)) {
    stringmark(rawtsvalue(o));  /* strings are `values', so are never weak */
    return 0;
  }
  return iswhite(gcvalue(o)) ||
    (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));
}
Exemple #2
0
static void
lex_white(fz_stream *f)
{
	int c;
	do {
		c = fz_read_byte(f);
	} while ((c <= 32) && (iswhite(c)));
	if (c != EOF)
		fz_unread_byte(f);
}
Exemple #3
0
void skipwhite(char **take)
{
char c;

	while((c=**take))
	{
		if(!iswhite(c)) break;
		++*take;
	}
}
Exemple #4
0
/*
** barrier that moves collector forward, that is, mark the white object
** being pointed by a black object. (If in sweep phase, clear the black
** object to white [sweep it] to avoid other barrier calls for this
** same object.)
*/
void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
  global_State *g = G(L);
  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
  if (keepinvariant(g))  /* must keep invariant? */
    reallymarkobject(g, v);  /* restore invariant */
  else {  /* sweep phase */
    lua_assert(issweepphase(g));
    makewhite(g, o);  /* mark main obj. as white to avoid other barriers */
  }
}
Exemple #5
0
static int check_standard(const char *judge, size_t jlen, const char *process, size_t plen) {
	size_t j = 0, p = 0;
	int nj, np;

	while (j < jlen && iswhite(judge[j])) ++j;
	while (p < plen && iswhite(process[p])) ++p;
	for (;;) {
		nj = np = 0;
		while (j < jlen && ((nj |= isline(judge[j])), iswhite(judge[j]))) ++j;
		while (p < plen && ((np |= isline(process[p])), iswhite(process[p]))) ++p;
		if (j == jlen || p == plen) return j == jlen && p == plen;
		if (nj != np) return 0;

		while (j < jlen && !iswhite(judge[j])) {
			if (p >= plen) return 0;
			if (judge[j++] != process[p++]) return 0;
		}
	}
}
int
oly_parse_cmd(struct command *c, char *s)
{

	c->cmd = 0;
	c->fuzzy = FALSE;
	c->use_skill = 0;

	while (iswhite(*s))
		s++;

	remove_comment(s);
	remove_ctrl_chars(s);

	if (c->line)
		my_free(c->line);
	c->line = str_save(s);

	if (*s == '&')
	{
		c->conditional = 1;
		s++;
	}
	else if (*s == '?')
	{
		c->conditional = 2;
		s++;
	}
	else
		c->conditional = 0;

	if (c->parsed_line)
		my_free(c->parsed_line);
	c->parsed_line = str_save(s);

	c->parse = parse_line(c->parse, c->parsed_line);

	if (ilist_len(c->parse) > 0)
	{
		int i;

		i = find_command(c->parse[0]);
		
		if (i > 0)
		{
			c->cmd = i;
			if (fuzzy_find)
				c->fuzzy = TRUE;
		}
		else
			return FALSE;
	}

	return TRUE;
}
Exemple #7
0
/* Find the method type in buf
   Returns a method number (see serve.h) or -1 if no/invalid method */
int method_type(const char *buf) {
  char *ptr, *end;
  int i;

  /* e.g. "GET /filename HTTP/1.1" */

  /* skip whitespace at start */
  for(ptr = (char*)buf; *ptr && iswhite(*ptr); ptr++);

  /* now find the end of the non-whitespace */
  for(end = ptr; *end && !iswhite(*end); end++);

  /* and now find the method number */
  for(i = 0; i < METHODS; i++) {
    if(strncasecmp(method[i], ptr, end-ptr) == 0) return i;
  }

  /* invalid method */
  return -1;
}
Exemple #8
0
void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
  global_State *g = G(L);
  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
  lua_assert(ttype(&o->gch) != LUA_TTABLE);
  /* must keep invariant? */
  if (g->gcstate == GCSpropagate)
    reallymarkobject(g, v);  /* restore invariant */
  else  /* don't mind */
    makewhite(g, o);  /* mark as white just to avoid other barriers */
}
Exemple #9
0
static void
xps_hacky_get_prop(fz_context *ctx, char *data, fz_obj *dict, char *name, char *tag_name)
{
	char *start, *end;
	fz_obj *value;

	start = strstr(data, tag_name);
	if (!start || start == data || start[-1] != '<')
		return;
	end = strstr(start + 1, tag_name);
	start = strchr(start, '>');
	if (!start || !end || start >= end || end[-2] != '<' || end[-1] != '/')
		return;

	for (start++; iswhite(*start); start++);
	for (end -= 3; iswhite(*end) && end > start; end--);

	value = fz_new_string(ctx, start, end - start + 1);
	fz_dict_puts(ctx, dict, name, value);
	fz_drop_obj(ctx, value);
}
Exemple #10
0
INTERNAL int
parse_args(char *args, char *argv[], int argc) {
	while (*args) {
		while (*args && iswhite(*args)) ++args;
		if (!*args) break;
		if (*args == '"') {
			argv[argc++] = ++args;
			while (*args && *args != '"') ++args;
			if (*args) *args++ = '\0';
		}
		else {
			argv[argc++] = args;
			while (*args && !iswhite(*args)) ++args;
			if (*args) *args++ = '\0';
		}
		if (Verbose) printf("%d: %s\n", argc-1, argv[argc-1]);
	}
	argv[argc] = NULL;

	return(argc);
}
Exemple #11
0
/*
** Traverse a prototype. (While a prototype is being build, its
** arrays can be larger than needed; the extra slots are filled with
** NULL, so the use of 'markobjectN')
*/
static int traverseproto (global_State *g, Proto *f) {
  int i;
  if (f->cache && iswhite(f->cache))
    f->cache = NULL;  /* allow cache to be collected */
  for (i = 0; i < f->sp->sizek; i++)  /* mark literals */
    markvalue(g, &f->k[i]);
  for (i = 0; i < f->sp->sizep; i++)  /* mark nested protos */
    markobjectN(g, f->p[i]);
  return sizeof(Proto) + sizeof(Proto *) * f->sp->sizep +
                         sizeof(TValue) * f->sp->sizek +
                         marksharedproto(g, f->sp);
}
Exemple #12
0
void xstring_array()
{
  char ch;
  int pi=0, si=0,ab_code;
  int stlen, x=line_ndx;
		
  pi = e_pos;
  pi = iswhite(pi);
  e_pos = pi;
  ch = p_string[pi];
		
  if(ch == ':')
  {
    return;
  }

  if(isalpha(ch))
  {
    return;
  }

  stlen = strlen(p_string);
  stlen++;
  if((ch != '\"') || (pi == stlen))
  {
    ab_code=9;
    a_bort(ab_code, x);
  }
  else
  {
    ch = ' ';		
    while((ch != '\"') && (pi < stlen))
    {
      si++;
      pi++;
      ch = p_string[pi];
    }

    if((si <= 1) && (pi < stlen))
    {
      ab_code=5;
      a_bort(ab_code, x);
    }
    else
    {
	if(pi >= stlen)
       {
         ab_code=6;
         a_bort(ab_code, x);
       }
    }
  }
}
static inline void
lexwhite(fz_stream *f)
{
	int c;
	while (1)
	{
		c = fz_peekbyte(f);
		if (!iswhite(c))
			break;
		fz_readbyte(f);
	}
}
Exemple #14
0
/* Increment *pos to the next non-whitespace character, and returns
 * 2 if a new line was seen, 1 if only spaces were seen, and 0 if no whitespace was seen */
static inline int skip_spaces(const char *str, int *pos, int length) {
	int saw_line = 0, saw_space = 0;
	while (*pos < length) {
		saw_line |= isline(str[*pos]);
		if (!iswhite(str[*pos])) {
			break;
		}
		++*pos;
		saw_space = 1;
	}
	return saw_line ? 2 : saw_space;
}
Exemple #15
0
/*
** barrier that moves collector forward, that is, mark the white object
** being pointed by a black object.
*/
void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
  global_State *g = G(L);
  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
  lua_assert(isgenerational(g) || g->gcstate != GCSpause);
  lua_assert(gch(o)->tt != LUA_TTABLE);
  if (keepinvariant(g))  /* must keep invariant? */
    reallymarkobject(g, v);  /* restore invariant */
  else {  /* sweep phase */
    lua_assert(issweepphase(g));
    makewhite(g, o);  /* mark main obj. as white to avoid other barriers */
  }
}
Exemple #16
0
static char	*istild(int *i, char *str, int start)
{
	char	*tmp;
	char	*result;

	++*i;
	while (!(iswhite(str[*i])) && !(isop(str[*i])) && str[*i])
		++*i;
	tmp = ft_strsub(str, start + 1, (*i - start - 1));
	result = ft_strjoin(find_value_envir(g_env, "HOME"), tmp);
	return (result);
}
Exemple #17
0
/* Returns a pointer to the place in buf where the HTTP version starts or NULL
   if none is found */
char *http_version(const char *buf) {
  char *ptr;
  char *p;

  /* eg. "GET /filename HTTP/1.1" */

  /* skip whitespace at start */
  for(ptr = (char*)buf; *ptr && iswhite(*ptr); ptr++);

  /* now find the end of the method */
  for(; *ptr && !iswhite(*ptr); ptr++);

  /* now skip more whitespace */
  for(; *ptr && iswhite(*ptr); ptr++);

  /* now find the end of the filename */
  for(; *ptr && !iswhite(*ptr); ptr++);

  /* and now skip over the last of the whitespace */
  for(; *ptr && iswhite(*ptr); ptr++);

  if(!*ptr) return NULL;

  /* copy the string */
  p = strdup(ptr);
  
  /* strip trailing whitespace */
  for(ptr = p; *ptr && !iswhite(*ptr); ptr++);
  *ptr = '\0';

  return p;
}
Exemple #18
0
void reallymarkobject (global_State *g, GCObject *o) {
#else
static void reallymarkobject (global_State *g, GCObject *o) {
#endif /* LUAPLUS_EXTENSIONS */
  lua_assert(iswhite(o) && !isdead(g, o));
  white2gray(o);
  switch (o->gch.tt) {
    case LUA_TSTRING: {
      return;
    }
#if LUA_WIDESTRING
    case LUA_TWSTRING: {
      return;
    }
#endif /* LUA_WIDESTRING */
    case LUA_TUSERDATA: {
      Table *mt = gco2u(o)->metatable;
      gray2black(o);  /* udata are never gray */
      if (mt) markobject(g, mt);
      markobject(g, gco2u(o)->env);
      return;
    }
    case LUA_TUPVAL: {
      UpVal *uv = gco2uv(o);
      markvalue(g, uv->v);
      if (uv->v == &uv->u.value)  /* closed? */
        gray2black(o);  /* open upvalues are never black */
      return;
    }
    case LUA_TFUNCTION: {
      gco2cl(o)->c.gclist = g->gray;
      g->gray = o;
      break;
    }
    case LUA_TTABLE: {
      gco2h(o)->gclist = g->gray;
      g->gray = o;
      break;
    }
    case LUA_TTHREAD: {
      gco2th(o)->gclist = g->gray;
      g->gray = o;
      break;
    }
    case LUA_TPROTO: {
      gco2p(o)->gclist = g->gray;
      g->gray = o;
      break;
    }
    default: lua_assert(0);
  }
}
Exemple #19
0
/* Extract a token from data_p and copy it into dest_p.
*/
static int httpd_token_cpy(const char *data_p, char *dest_p, int dest_len)
{
  int i = 0;
  
  //	ASSERT(data_p != NULL);
  
  while (!iswhite(*data_p) && i < dest_len && *data_p != '\0') {
    dest_p[i] = *data_p;
    i++;
    data_p++;
  }
  
  if (!iswhite(*data_p) && i == dest_len) {
    /* Token too long to fit in dest_len */
    return -kInProgressErr;
  }
  
  /* Add trailing \0 */
  dest_p[i] = 0;
  return kNoErr;
  
}
Exemple #20
0
lua_State *luaE_newthread (lua_State *L) {
  lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
  luaC_link(L, obj2gco(L1), LUA_TTHREAD);
  preinit_state(L1, G(L));
  stack_init(L1, L);  /* init stack */
  setobj2n(L, gt(L1), gt(L));  /* share table of globals */
  L1->hookmask = L->hookmask;
  L1->basehookcount = L->basehookcount;
  L1->hook = L->hook;
  resethookcount(L1);
  lua_assert(iswhite(obj2gco(L1)));
  return L1;
}
Exemple #21
0
void luaF_close (lua_State *L, StkId level) {
  UpVal *uv;
  while (L->openupval != NULL &&
        (uv = L->openupval, uplevel(uv) >= level)) {
    TValue *slot = &uv->u.value;  /* new position for value */
    luaF_unlinkupval(uv);
    setobj(L, slot, uv->v);  /* move value to upvalue slot */
    uv->v = slot;  /* now current value lives here */
    if (!iswhite(uv))
      gray2black(uv);  /* closed upvalues cannot be gray */
    luaC_barrier(L, uv, slot);
  }
}
int get_token()
{
	int tok;
	char *temp;
	(token_type) = 0;
	tok = 0;
	temp = (token);

	if (*(prog) == '\0')
	{
		*(token) = 0;
		tok = FINISHED;
		return ((token_type) = DELIMITER);
	}
	while (iswhite(*(prog))) ++(prog);
	if (isdelim(*(prog)))
	{
		char t=*temp = *(prog);
		(prog)++;
		temp++;
		if ((t == '>' || t == '<' || t == '!') && (*prog) && (*prog == '='))
		{
			*temp = *(prog);
			(prog)++;
			temp++;
		}
		*temp = 0;
		return ((token_type) = DELIMITER);
	}
	if (isdigit(*(prog)))
	{
		while (!isdelim(*(prog)))
			*temp++=*(prog)++;
		*temp = '\0';
		return ((token_type) = NUMBER);
	}
	if (isalpha2(*(prog)))
	{
		while (!isdelim(*(prog)))
			*temp++=*(prog)++;
		(token_type) = VARIABLE;
	}
	*temp = '\0';
	if ((token_type) == VARIABLE)
	{
		tok = look_up((token));
		if (tok)
			(token_type) = FUNCTION;
	}
	return (token_type);
}
Exemple #23
0
PWCHAR    GetGenText()
{
    PWCHAR       s;

    s = tokenbuf;

    /* skip white space */
    while (iswhite(curChar))
        OurGetChar();

    if (curChar == EOFMARK)  {
        token.type = EOFMARK;
        return NULL;
    }

    /* random symbol */
    if (curChar == SYMUSESTART)
        GetSymbol(TRUE, curChar);
    token.sym.name[0] = L'\0';

    /* read space delimited string */
    *s++ = curChar;
    while (( LitChar() != EOFMARK) && ( !iswhite(curChar)))
        *s++ = curChar;
    *s++ = 0;     /* put a \0 on the end of the string */

    OurGetChar();    /* read in the next character        */
    if (curChar == EOFMARK)
        token.type = EOFMARK;

    if (curChar == SYMUSESTART)
    {
        GetSymbol(TRUE, curChar);
        token.sym.nID = token.val;
    }

    return (tokenbuf);
}
Exemple #24
0
LPTSTR Help_FindCommand_Search (UNIXUTIL *puu, LPTSTR pszKeyword)
{
   // search for a usable keyword--skip "vos" or "bos" (etc).
   //
   while (*pszKeyword)
      {
      // strip any initial whitespace
      while (iswhite(*pszKeyword))
         ++pszKeyword;

      // find the end of this word
      LPTSTR pszNext;
      for (pszNext = pszKeyword; *pszNext && !iswhite(*pszNext); )
         ++pszNext;
      if (!*pszNext)  // last word?  Gotta use it.
         break;
      *pszNext = TEXT('\0');

      BOOL fSkip = FALSE;
      if (!lstrcmpi (pszKeyword, TEXT("pts")))
         {
         fSkip = TRUE;
         *puu = uuPTS;
         }
      if (!lstrcmpi (pszKeyword, TEXT("kas")))
         {
         fSkip = TRUE;
         *puu = uuKAS;
         }

      if (fSkip)
         pszKeyword = 1+pszNext;
      else
         break;
      }

   return pszKeyword;
}
Exemple #25
0
static int Parse()
{
   char* t;

   type = 0;
   t = token;
   while( iswhite( *expression ) )
      expression++;
   if( isdelim( *expression ) )
   {
      type = DEL;
      *t++ = *expression++;
   }
   else if( isnumer( *expression ) )
   {
      type = NUM;
      while( isnumer( *expression ) )
         *t++ = *expression++;
   }
   else if( isalpha( *expression ) )
   {
      type = VAR;
      while( isalpha( *expression ) )
        *t++ = *expression++;
      token[VARLEN] = 0;
   }
   else if( *expression )
   {
      *t++ = *expression++;
      *t = 0;
      return E_SYNTAX ;
   }
   *t = 0;
   while( iswhite( *expression ) )
      expression++;

   return E_OK;
}
Exemple #26
0
/* Extracts the filename from the request.
   new array. You must free the new array when you are done with it. */
char *requ_file(const char *buf) {
  char *ptr, *end;
  char *reqfile;

  /* eg. "GET /filename HTTP/1.1" */

  /* skip whitespace at start */
  for(ptr = (char*)buf; *ptr && iswhite(*ptr); ptr++);

  /* now find the end of the method */
  for(; *ptr && !iswhite(*ptr); ptr++);

  /* now skip more whitespace */
  for(; *ptr && iswhite(*ptr); ptr++);

  /* and find the end of the filename */
  for(end = ptr; *end && !iswhite(*end); end++);/* find space */

  /* allocate the path */
  reqfile = strdup2(ptr, end - ptr);

  return reqfile;
}
Exemple #27
0
/*
 * Take a blank separated list of tokens and turn it into a list of
 * individual nul-delimited strings.  Build a list of pointers at
 * token, which must have enough space for the tokens.  Return the
 * number of tokens, or -1 on error (typically a missing string
 * delimiter).
 */
int
tokenize(char *cptr, char *token[], int maxtoken)
{
    char delim;						    /* delimiter for searching for the partner */
    int tokennr;					    /* index of this token */

    for (tokennr = 0; tokennr < maxtoken;) {
	while (iswhite(*cptr))
	    cptr++;					    /* skip initial white space */
	if ((*cptr == '\0') || (*cptr == '\n') || (*cptr == '#')) /* end of line */
	    return tokennr;				    /* return number of tokens found */
	delim = *cptr;
	token[tokennr] = cptr;				    /* point to it */
	tokennr++;					    /* one more */
	if (tokennr == maxtoken)			    /* run off the end? */
	    return tokennr;
	if ((delim == '\'') || (delim == '"')) {	    /* delimitered */
	    for (;;) {
		cptr++;
		if ((*cptr == delim) && (cptr[-1] != '\\')) { /* found the partner */
		    cptr++;				    /* move on past */
		    if (!iswhite(*cptr))		    /* error, no space after closing quote */
			return -1;
		    *cptr++ = '\0';			    /* delimit */
		} else if ((*cptr == '\0') || (*cptr == '\n')) /* end of line */
		    return -1;
	    }
	} else {					    /* not quoted */
	    while ((*cptr != '\0') && (!iswhite(*cptr)) && (*cptr != '\n'))
		cptr++;
	    if (*cptr != '\0')				    /* not end of the line, */
		*cptr++ = '\0';				    /* delimit and move to the next */
	}
    }
    return maxtoken;					    /* can't get here */
}
Exemple #28
0
static void generate_text(fz_context *ctx, fz_html *box, const char *text)
{
	fz_html *flow = box;
	while (flow->type != BOX_FLOW)
		flow = flow->up;

	while (*text)
	{
		if (iswhite(*text))
		{
			++text;
			while (iswhite(*text))
				++text;
			add_flow_space(ctx, flow, &box->style);
		}
		if (*text)
		{
			const char *mark = text++;
			while (*text && !iswhite(*text))
				++text;
			add_flow_word(ctx, flow, &box->style, mark, text);
		}
	}
}
Exemple #29
0
static void Parse(void)
{
   char* t;

   type = 0;
   t = (char*)token;
   while( iswhite( *expression ) )
      expression++;
   if( isdelim( *expression ) )
   {
      type = DEL;
      *t++ = *expression++;
   }
   else if( isnumer( *expression ) )
   {
      type = NUM;
      while( isnumer( *expression ) )
         *t++ = *expression++;
   }
   else if( isalpha( *expression ) )
   {
      type = VAR;
      while( isalpha( *expression ) )
        *t++ = *expression++;
      token[VARLEN] = 0;
   }
   else if( *expression )
   {
      *t++ = *expression++;
      *t = 0;
      ERR( E_SYNTAX );
   }
   *t = 0;
   while( iswhite( *expression ) )
      expression++;
}
Exemple #30
0
static int traverseproto (global_State *g, Proto *f) {
  int i;
  if (f->cache && iswhite(obj2gco(f->cache)))
    f->cache = NULL;  /* allow cache to be collected */
  stringmark(f->source);
  for (i = 0; i < f->sizek; i++)  /* mark literals */
    markvalue(g, &f->k[i]);
  for (i = 0; i < f->sizeupvalues; i++)  /* mark upvalue names */
    stringmark(f->upvalues[i].name);
  for (i = 0; i < f->sizep; i++)  /* mark nested protos */
    markobject(g, f->p[i]);
  for (i = 0; i < f->sizelocvars; i++)  /* mark local-variable names */
    stringmark(f->locvars[i].varname);
  return TRAVCOST + f->sizek + f->sizeupvalues + f->sizep + f->sizelocvars;
}