Ejemplo n.º 1
0
static short *matchname(short *s, short *str, int *len, int nolt)
{
    short *p = s;
    if (!p)
        return 0;
    while (*p)
    {
        if (p[0] == str[0])
        if (p == s || !issymchar(p[ - 1]))
        {
            int xlen =  *len;
            if (!tcmp(p, str, &xlen))
                if (!issymchar(p[xlen]))
            if (!nolt)
            {
                *len = xlen;
                return p;
            }
            else
            {
                char *t = p +  *len;
                while (isspace(*t))
                    t++;
                if (*t == '<')
                    return 0;
                *len = xlen;
                return p;
            }
        }
        p++;
    }
    return 0;
}
Ejemplo n.º 2
0
static int 
foundit(void)
{
	if (wordmode) {
		return (!issymchar(bufp[-1]) &&
		    !issymchar(bufp[-2 - s1l]) &&
		    !bcmp(bufp - 1 - s1l, str1, s1l));
	} else {
		return (!bcmp(bufp - s1l, str1, s1l));
	}
}
Ejemplo n.º 3
0
Archivo: parse.cpp Proyecto: shaurz/amp
Value
Parser::atom()
{
	if (c == '"')
		return string();
	if (isdigit(c) || (c == '-' && isdigit(c1)))
		return number();
	if (issymchar(c))
		return symbol();
	parse_error("unexpected character");
}
Ejemplo n.º 4
0
static uint32_t
count_symbols(char * file, vm_size_t file_size)
{
    uint32_t nsyms = 0;
    char *   scan;
    char *   eol;
    char *   next;

    for (scan = file; true; scan = next) {

        eol = memchr(scan, '\n', file_size - (scan - file));
        if (eol == NULL) {
            break;
        }
        next = eol + 1;

       /* Skip empty lines.
        */
        if (eol == scan) {
            continue;
        }

       /* Skip comment lines.
        */
        if (scan[0] == '#') {
            continue;
        }

       /* Scan past any non-symbol characters at the beginning of the line. */
        while ((scan < eol) && !issymchar(*scan)) {
            scan++;
        }

       /* No symbol on line? Move along.
        */
        if (scan == eol) {
            continue;
        }

       /* Skip symbols starting with '.'.
        */
        if (scan[0] == '.') {
            continue;
        }
        nsyms++;
    }
    
    return nsyms;
}
Ejemplo n.º 5
0
static uint32_t
count_symbols(char * file)
{
    char *   where;
    char *   eol;
    char *   next;
    uint32_t nsyms;

    for (nsyms = 0, where = file; true; where = next)
    {
	eol = strchr(where, '\n');
	if (!eol)
	    break;

	next = eol + 1;
	if (eol == where)
	    continue;
	if (where[0] == '#')
	    continue;

	while (!issymchar(*eol))
	    eol--;

	where = eol - 1;
	while (issymchar(*where))
	    where--;
	where++;

	if (where[0] == '.')
	    continue;

	nsyms++;
    }

    return nsyms;
}
Ejemplo n.º 6
0
Archivo: parse.cpp Proyecto: shaurz/amp
Value
Parser::symbol()
{
	char buf[256];
	unsigned len = 0;

	while (len < sizeof(buf) && issymchar(c))
		buf[len++] = read();
	if (len == sizeof(buf))
		parse_error("symbol too long");
	buf[len] = 0;

	if (strcmp(buf, "true") == 0)
		return _T;
	if (strcmp(buf, "false") == 0)
		return _F;
	if (strcmp(buf, "nil") == 0)
		return NIL;

	return make_symbol(buf);
}
Ejemplo n.º 7
0
/*
 *      getid - get an identifier.
 *
 *      identifiers are any isidch conglomerate
 *      that doesn't start with a numeric character.
 *      this set INCLUDES keywords.
 */
void getid()
{
    register int i;
    i = 0;
     /* Mangling */
    if (lastch == 'L')
    {
        lastid[i++] = 'L';
        getch();
        if (lastch == '\"')
        {
            getch();
            i = 0;
            while (lastch != '\"' && lastch)
            {
                *(((short*)(laststr)) + i++) = lastch;
                getch();
            }
            if ((lastch &0x7f) != '\"')
                generror(ERR_NEEDCHAR, '\"');
            else
                getch();
            *(((short*)(laststr)) + i) = 0;
            laststrlen = i;
            lastst = lsconst;
            return ;
        }
    }
    while (issymchar(lastch))
    {
        if (i < sizeof(lastid)/sizeof(lastid[0]))
            lastid[i++] = lastch;
        getch();
    }
    lastid[i] = '\0';
    lastst = ident;
}
Ejemplo n.º 8
0
static uint32_t
store_symbols(char * file, struct symbol * symbols, uint32_t idx, uint32_t max_symbols)
{
    char *   where;
    char *   eol;
    char *   next;
    uint32_t strtabsize;
    char *   indirect;
    uint32_t indirect_len;

    strtabsize = 0;

    for (where = file; true; where = next)
    {
	eol = strchr(where, '\n');
	if (!eol)
	    break;
	next = eol + 1;
	if (eol == where)
	    continue;
	if (where[0] == '#')
	    continue;

	while (!issymchar(*eol))
	    eol--;
	eol++;

	*eol = 0;

	where = eol - 1;
	indirect = NULL;
	indirect_len = 0;
	while (issymchar(*where)) {
	    if (':' == *where)
	    {
		indirect = where + 1;
		indirect_len = (eol - indirect + 1);
		eol = where;
		*eol = 0;
	    }
	    where--;
	}
	where++;

	if (where[0] == '.')
	    continue;

	if(idx >= max_symbols)
	{
	    fprintf(stderr, "symbol[%d] overflow %s\n", idx, where);
	    exit(1);
	}
	symbols[idx].name = where;
	symbols[idx].name_len = (eol - where + 1);
	symbols[idx].indirect = indirect;
	symbols[idx].indirect_len = indirect_len;
	strtabsize += symbols[idx].name_len + symbols[idx].indirect_len;
	idx++;
    }

    return strtabsize;
}
Ejemplo n.º 9
0
static uint32_t
store_symbols(char * file, vm_size_t file_size, struct symbol * symbols, uint32_t idx, uint32_t max_symbols)
{
    char *   scan;
    char *   line;
    char *   eol;
    char *   next;

    uint32_t strtabsize;

    strtabsize = 0;

    for (scan = file, line = file; true; scan = next, line = next) {

        char *       name = NULL;
        char *       name_term = NULL;
        unsigned int name_len = 0;
        char *       indirect = NULL;
        char *       indirect_term = NULL;
        unsigned int indirect_len = 0;
        char *       option = NULL;
        char *       option_term = NULL;
        unsigned int option_len = 0;
        char         optionstr[256];
        boolean_t    obsolete = 0;

        eol = memchr(scan, '\n', file_size - (scan - file));
        if (eol == NULL) {
            break;
        }
        next = eol + 1;

       /* Skip empty lines.
        */
        if (eol == scan) {
            continue;
        }

        *eol = '\0';

       /* Skip comment lines.
        */
        if (scan[0] == '#') {
            continue;
        }

       /* Scan past any non-symbol characters at the beginning of the line. */
        while ((scan < eol) && !issymchar(*scan)) {
            scan++;
        }

       /* No symbol on line? Move along.
        */
        if (scan == eol) {
            continue;
        }

       /* Skip symbols starting with '.'.
        */
        if (scan[0] == '.') {
            continue;
        }

        name = scan;

       /* Find the end of the symbol.
        */
        while ((*scan != '\0') && issymchar(*scan)) {
            scan++;
        }

       /* Note char past end of symbol.
        */
        name_term = scan;

       /* Stored length must include the terminating nul char.
        */
        name_len = name_term - name + 1;

       /* Now look for an indirect.
        */
        if (*scan != '\0') {
            while ((*scan != '\0') && iswhitespace(*scan)) {
                scan++;
            }
            if (*scan == ':') {
                scan++;
                while ((*scan != '\0') && iswhitespace(*scan)) {
                    scan++;
                }
                if (issymchar(*scan)) {
                    indirect = scan;

                   /* Find the end of the symbol.
                    */
                    while ((*scan != '\0') && issymchar(*scan)) {
                        scan++;
                    }

                   /* Note char past end of symbol.
                    */
                    indirect_term = scan;

                   /* Stored length must include the terminating nul char.
                    */
                    indirect_len = indirect_term - indirect + 1;

                } else if (*scan == '\0') {
		    fprintf(stderr, "bad format in symbol line: %s\n", line);
		    exit(1);
		}
            } else if (*scan != '\0' && *scan != '-') {
                fprintf(stderr, "bad format in symbol line: %s\n", line);
                exit(1);
            }
        }

        /* Look for options.
         */
        if (*scan != '\0') {
            while ((*scan != '\0') && iswhitespace(*scan)) {
                scan++;
            }

            if (*scan == '-') {
                scan++;

                if (isalpha(*scan)) {
                    option = scan;

                   /* Find the end of the option.
                    */
                    while ((*scan != '\0') && isalpha(*scan)) {
                        scan++;
                    }

                   /* Note char past end of option.
                    */
                    option_term = scan;
                    option_len = option_term - option;

                    if (option_len >= sizeof(optionstr)) {
                        fprintf(stderr, "option too long in symbol line: %s\n", line);
                        exit(1);
                    }
                    memcpy(optionstr, option, option_len);
                    optionstr[option_len] = '\0';

                    /* Find the option.
                     */
                    if (!strncmp(optionstr, "obsolete", option_len)) {
                        obsolete = TRUE;
                    }

                } else if (*scan == '\0') {
		    fprintf(stderr, "bad format in symbol line: %s\n", line);
		    exit(1);
		}

            }

        }

        if(idx >= max_symbols) {
            fprintf(stderr, "symbol[%d/%d] overflow: %s\n", idx, max_symbols, line);
            exit(1);
        }

        *name_term = '\0';
        if (indirect_term) {
            *indirect_term = '\0';
        }
        
        symbols[idx].name = name;
        symbols[idx].name_len = name_len;
        symbols[idx].indirect = indirect;
        symbols[idx].indirect_len = indirect_len;
        symbols[idx].flags = (obsolete) ? kObsolete : 0;

        strtabsize += symbols[idx].name_len + symbols[idx].indirect_len;
        idx++;
    }

    return strtabsize;
}
Ejemplo n.º 10
0
int preprocess_getc(void)
{
   int result = 0;
   int backslash = 0;

   do
   {
      int c;
      int haddigit;

      result = read_char();

      if (result != 0)
      {
         break;
      }

      c = Get();
      if (c == -1)
      {
         break;
      }
      if (backslash)
      {
         maybe_print(c);
         backslash = 0;
         continue;
      }
      if (!incldep && (isdigit((int) c) || (c == '.')))
      {
         haddigit = 0;
         while (isdigit((int) c) || (c == '.'))
         {
            haddigit |= isdigit((int) c);
            maybe_print(c);
            c = Get();
            if (c == -1)
            {
               return 0;
            }
         }
         if (haddigit && ((c == 'e') || (c == 'E')))
         {
            maybe_print(c);
            c = Get();
            if (c == -1)
            {
               return 0;
            }
            while (isdigit((int) c))
            {
               maybe_print(c);
               c = Get();
               if (c == -1)
               {
                  return 0;
               }
            }
         }
         Push(c);
         continue;
      }
      if (quote)
      {
         if (c == '\\')
         {
            maybe_print(c);
            backslash = 1;
            continue;
         }
         else if ((c == quote) || (c == '\n'))
         {
            maybe_print(c);
            quote = 0;
            continue;
         }
         else
         {
            maybe_print(c);
            continue;
         }
      }
      if (c == '\\') /* this weirdness is Reiser semantics.... */
      {
         backslash = 1;
         maybe_print(c);
         continue;
      }
      if ((c == '\'') || (c == '"'))
      {
         quote = c;
         maybe_print(c);
      }
      else if (linefirst && (c == '#'))
      {
         do_sharp();
      }
      else if (do_at_ctrls && (c == '@'))
      {
         do_at();
      }
      else if (! incldep)
      {
         if (isbsymchar(c) && !in_false_if())
         {
            char *cp;
            DEF *d;
            cp = init_accum();
            while (issymchar(c))
            {
               accum_char(cp, c);
               c = Get();
               if (c == -1)
               {
                  return 0;
               }
            }
            Push(c);
            cp = accum_result(cp);
#ifdef DEBUG_MAIN

            if (debugging)
            {
               outputs("<word:");
               outputs(cp);
               outputs(">");
            }
#endif
            d = find_def(cp);
            if (d)
            {
               expand_def(d);
            }
            else
            {
               for (;*cp;cp++)
               {
                  maybe_print(*cp);
               }
            }
         }
         else if (c == '/')
         {
            int d;
            d = Get();
            if (d == -1)
            {
               return 0;
            }
            if (d == '*')
            {
               d = '\0';
               if (keep_comments)
               {
                  maybe_print('/');
                  maybe_print('*');
               }
               do
               {
                  c = d;
                  d = Get();
                  if (d == -1)
                  {
                     return 0;
                  }
                  if ((d == '\n') || keep_comments)
                  {
                     maybe_print(d);
                  }
               }
               while ((c != '*') || (d != '/'));
            }
            else if (d == '/')
            {
               if (keep_comments)
               {
                  maybe_print('/');
                  maybe_print('/');
               }
               do
               {
                  c = Get();
                  if (c == -1)
                  {
                     return 0;
                  }
                  if ((c == '\n') || keep_comments)
                  {
                     maybe_print(c);
                  }
               }
               while (c != '\n');
            }
            else
            {
               Push(d);
               maybe_print(c);
            }
         }
         else
         {
            maybe_print(c);
         }
      }
   } while (result == 0);

   return result;
}