tizen 2.3.1 release
[framework/uifw/embryo.git] / src / bin / embryo_cc_sc2.c
index 3548e43..9e80df2 100644 (file)
@@ -101,7 +101,8 @@ plungequalifiedfile(char *name)
          }                     /* if */
        ext_idx++;
      }
-   while (!fp && ext_idx < (sizeof extensions / sizeof extensions[0]));
+   while ((!fp) && 
+          (ext_idx < (int)(sizeof extensions / sizeof extensions[0])));
    if (!fp)
      {
        *ext = '\0';            /* restore filename */
@@ -197,11 +198,11 @@ doinclude(void)
      }                         /* if */
 
    i = 0;
-   while (*lptr != c && *lptr != '\0' && i < sizeof name - 1)  /* find the end of the string */
+   while ((*lptr != c) && (*lptr != '\0') && (i < (int)(sizeof(name) - 1))) /* find the end of the string */
       name[i++] = *lptr++;
    while (i > 0 && name[i - 1] <= ' ')
       i--;                     /* strip trailing whitespace */
-   assert(i >= 0 && i < sizeof name);
+   assert((i >= 0) && (i < (int)(sizeof(name))));
    name[i] = '\0';             /* zero-terminate the string */
 
    if (*lptr != c)
@@ -442,9 +443,9 @@ dtoi(cell * val, char *curptr)
 
    *val = 0;
    ptr = curptr;
-   if (!isdigit(*ptr))         /* should start with digit */
+   if (!sc_isdigit(*ptr))              /* should start with digit */
       return 0;
-   while (isdigit(*ptr) || *ptr == '_')
+   while (sc_isdigit(*ptr) || *ptr == '_')
      {
        if (*ptr != '_')
           *val = (*val * 10) + (*ptr - '0');
@@ -452,7 +453,7 @@ dtoi(cell * val, char *curptr)
      }                         /* while */
    if (alphanum(*ptr))         /* number must be delimited by non-alphanumerical */
       return 0;
-   if (*ptr == '.' && isdigit(*(ptr + 1)))
+   if (*ptr == '.' && sc_isdigit(*(ptr + 1)))
       return 0;                        /* but a fractional part must not be present */
    return (int)(ptr - curptr);
 }
@@ -470,18 +471,18 @@ htoi(cell * val, char *curptr)
 
    *val = 0;
    ptr = curptr;
-   if (!isdigit(*ptr))         /* should start with digit */
+   if (!sc_isdigit(*ptr))              /* should start with digit */
       return 0;
    if (*ptr == '0' && *(ptr + 1) == 'x')
      {                         /* C style hexadecimal notation */
        ptr += 2;
-       while (isxdigit(*ptr) || *ptr == '_')
+       while (sc_isxdigit(*ptr) || *ptr == '_')
          {
             if (*ptr != '_')
               {
-                 assert(isxdigit(*ptr));
+                 assert(sc_isxdigit(*ptr));
                  *val = *val << 4;
-                 if (isdigit(*ptr))
+                 if (sc_isdigit(*ptr))
                     *val += (*ptr - '0');
                  else
                     *val += (tolower(*ptr) - 'a' + 10);
@@ -553,9 +554,9 @@ ftoi(cell * val, char *curptr)
    fnum = 0.0;
    dnum = 0L;
    ptr = curptr;
-   if (!isdigit(*ptr))         /* should start with digit */
+   if (!sc_isdigit(*ptr))              /* should start with digit */
       return 0;
-   while (isdigit(*ptr) || *ptr == '_')
+   while (sc_isdigit(*ptr) || *ptr == '_')
      {
        if (*ptr != '_')
          {
@@ -567,12 +568,12 @@ ftoi(cell * val, char *curptr)
    if (*ptr != '.')
       return 0;                        /* there must be a period */
    ptr++;
-   if (!isdigit(*ptr))         /* there must be at least one digit after the dot */
+   if (!sc_isdigit(*ptr))              /* there must be at least one digit after the dot */
       return 0;
    ffrac = 0.0;
    fmult = 1.0;
    ignore = FALSE;
-   while (isdigit(*ptr) || *ptr == '_')
+   while (sc_isdigit(*ptr) || *ptr == '_')
      {
        if (*ptr != '_')
          {
@@ -604,10 +605,10 @@ ftoi(cell * val, char *curptr)
          {
             sign = 1;
          }                     /* if */
-       if (!isdigit(*ptr))     /* 'e' should be followed by a digit */
+       if (!sc_isdigit(*ptr))  /* 'e' should be followed by a digit */
           return 0;
        exp = 0;
-       while (isdigit(*ptr))
+       while (sc_isdigit(*ptr))
          {
             exp = (exp * 10) + (*ptr - '0');
             ptr++;
@@ -720,7 +721,7 @@ static int
 preproc_expr(cell * val, int *tag)
 {
    int                 result;
-   int                 index;
+   int                 idx;
    cell                code_index;
    char               *term;
 
@@ -729,7 +730,7 @@ preproc_expr(cell * val, int *tag)
     * compilations. Reset the staging index, but keep the code
     * index.
     */
-   if (stgget(&index, &code_index))
+   if (stgget(&idx, &code_index))
      {
        error(57);              /* unfinished expression */
        stgdel(0, code_index);
@@ -741,7 +742,7 @@ preproc_expr(cell * val, int *tag)
     */
    assert(strlen(pline) < sLINEMAX);
    term = strchr(pline, '\0');
-   assert(!!term);
+   assert(term != NULL);
    chrcat(pline, PREPROC_TERM);        /* the "DEL" code (see SC.H) */
    result = constexpr(val, tag);       /* get value (or 0 on error) */
    *term = '\0';               /* erase the token (if still present) */
@@ -754,29 +755,29 @@ preproc_expr(cell * val, int *tag)
  * character that caused the input to be ended.
  */
 static char        *
-getstring(char *dest, int max, char *line)
+getstring(char *dest, int max)
 {
-   assert(!!dest && !!line);
+   assert(dest != NULL);
    *dest = '\0';
-   while (*line <= ' ' && *line != '\0')
-      line++;                  /* skip whitespace */
-   if (*line != '"')
+   while (*lptr <= ' ' && *lptr != '\0')
+      lptr++;                  /* skip whitespace */
+   if (*lptr != '"')
      {
        error(37);              /* invalid string */
      }
-   else if (*line == '\0')
+   else
      {
        int                 len = 0;
 
-       line++;                 /* skip " */
-       while (*line != '"' && *line != '\0')
+       lptr++;                 /* skip " */
+       while (*lptr != '"' && *lptr != '\0')
          {
             if (len < max - 1)
-               dest[len++] = *line;
-            line++;
+               dest[len++] = *lptr;
+            lptr++;
          }                     /* if */
        dest[len] = '\0';
-       if (*line == '"')
+       if (*lptr == '"')
           lptr++;              /* skip closing " */
        else
           error(37);           /* invalid string */
@@ -818,7 +819,7 @@ command(void)
    int                 tok, ret;
    cell                val;
    char               *str;
-   int                 index;
+   int                 idx;
    cell                code_index;
 
    while (*lptr <= ' ' && *lptr != '\0')
@@ -833,7 +834,7 @@ command(void)
    /* on a pending expression, force to return a silent ';' token and force to
     * re-read the line
     */
-   if (!sc_needsemicolon && stgget(&index, &code_index))
+   if (!sc_needsemicolon && stgget(&idx, &code_index))
      {
        lptr = term_expr;
        return CMD_TERM;
@@ -924,7 +925,7 @@ command(void)
          {
             char                pathname[PATH_MAX];
 
-            lptr = getstring(pathname, sizeof pathname, lptr);
+            lptr = getstring(pathname, sizeof pathname);
             if (pathname[0] != '\0')
               {
                  free(inpfname);
@@ -941,6 +942,22 @@ command(void)
             if (lex(&val, &str) != tNUMBER)
                error(8);       /* invalid/non-constant expression */
             fline = (int)val;
+
+            while (*lptr == ' ' && *lptr != '\0')
+               lptr++;                 /* skip whitespace */
+            if (*lptr == '"')
+               {
+                 char pathname[PATH_MAX];
+
+                 lptr = getstring(pathname, sizeof pathname);
+                 if (pathname[0] != '\0')
+                   {
+                      free(inpfname);
+                      inpfname = strdup(pathname);
+                      if (!inpfname)
+                         error(103);   /* insufficient memory */
+                   }           /* if */
+              }
          }                     /* if */
        check_empty(lptr);
        break;
@@ -983,13 +1000,15 @@ command(void)
                          lptr++;
                       if (*lptr == '"')
                         {
-                           lptr = getstring(name, sizeof name, lptr);
+                           lptr = getstring(name, sizeof name);
                         }
                       else
                         {
                            int                 i;
 
-                           for (i = 0; i < sizeof name && alphanum(*lptr);
+                           for (i = 0; 
+                                 (i < (int)(sizeof(name))) && 
+                                 (alphanum(*lptr));
                                 i++, lptr++)
                               name[i] = *lptr;
                            name[i] = '\0';
@@ -1022,9 +1041,11 @@ command(void)
                       int                 i;
 
                       /* first gather all information, start with the tag name */
-                      while (*lptr <= ' ' && *lptr != '\0')
+                      while ((*lptr <= ' ') && (*lptr != '\0'))
                          lptr++;
-                      for (i = 0; i < sizeof name && alphanum(*lptr);
+                      for (i = 0; 
+                            (i < (int)(sizeof(name)) - 1) &&
+                            (alphanum(*lptr));
                            i++, lptr++)
                          name[i] = *lptr;
                       name[i] = '\0';
@@ -1084,9 +1105,11 @@ command(void)
                       do
                         {
                            /* get the name */
-                           while (*lptr <= ' ' && *lptr != '\0')
+                           while ((*lptr <= ' ') && (*lptr != '\0'))
                               lptr++;
-                           for (i = 0; i < sizeof name && isalpha(*lptr);
+                           for (i = 0; 
+                                 (i < (int)(sizeof(name)) - 1) &&
+                                 (sc_isalpha(*lptr));
                                 i++, lptr++)
                               name[i] = *lptr;
                            name[i] = '\0';
@@ -1133,7 +1156,7 @@ command(void)
        if (skiplevel == 0)
          {
             check_empty(lptr);
-            assert(!!inpf);
+            assert(inpf != NULL);
             if (inpf != inpf_org)
                sc_closesrc(inpf);
             inpf = NULL;
@@ -1143,12 +1166,12 @@ command(void)
      case tpEMIT:
        {
           /* write opcode to output file */
-          char                name[40];
+          char                name[41];
           int                 i;
 
           while (*lptr <= ' ' && *lptr != '\0')
              lptr++;
-          for (i = 0; i < 40 && (isalpha(*lptr) || *lptr == '.'); i++, lptr++)
+          for (i = 0; i < 40 && (sc_isalpha(*lptr) || *lptr == '.'); i++, lptr++)
              name[i] = (char)tolower(*lptr);
           name[i] = '\0';
           stgwrite("\t");
@@ -1196,7 +1219,10 @@ command(void)
                        if (tok < 256)
                           sprintf(s2, "%c", (char)tok);
                        else
-                          strcpy(s2, sc_tokens[tok - tFIRST]);
+                         {
+                            strncpy(s2, sc_tokens[tok - tFIRST], 19);
+                            s2[19] = 0;
+                         }
                        error(1, sc_tokens[tSYMBOL - tFIRST], s2);
                        break;
                     }          /* case */
@@ -1230,7 +1256,7 @@ command(void)
                  }             /* while */
                end = lptr;
                /* check pattern to match */
-               if (!isalpha(*start) && *start != '_')
+               if (!sc_isalpha(*start) && *start != '_')
                  {
                     error(74); /* pattern must start with an alphabetic character */
                     break;
@@ -1249,7 +1275,7 @@ command(void)
                  }             /* while */
                pattern[count] = '\0';
                /* special case, erase trailing variable, because it could match anything */
-               if (count >= 2 && isdigit(pattern[count - 1])
+               if (count >= 2 && sc_isdigit(pattern[count - 1])
                    && pattern[count - 2] == '%')
                   pattern[count - 2] = '\0';
                /* find substitution string */
@@ -1290,7 +1316,7 @@ command(void)
                substitution[count] = '\0';
                /* check whether the definition already exists */
                for (prefixlen = 0, start = pattern;
-                    isalpha(*start) || isdigit(*start) || *start == '_';
+                    sc_isalpha(*start) || sc_isdigit(*start) || *start == '_';
                     prefixlen++, start++)
                   /* nothing */ ;
                assert(prefixlen > 0);
@@ -1461,7 +1487,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution)
    memset(args, 0, sizeof args);
 
    /* check the length of the prefix */
-   for (prefixlen = 0, s = pattern; isalpha(*s) || isdigit(*s) || *s == '_';
+   for (prefixlen = 0, s = pattern; sc_isalpha(*s) || sc_isdigit(*s) || *s == '_';
        prefixlen++, s++)
       /* nothing */ ;
    assert(prefixlen > 0);
@@ -1478,7 +1504,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution)
        if (*p == '%')
          {
             p++;               /* skip '%' */
-            if (isdigit(*p))
+            if (sc_isdigit(*p))
               {
                  arg = *p - '0';
                  assert(arg >= 0 && arg <= 9);
@@ -1573,7 +1599,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution)
        /* calculate the length of the substituted string */
        for (e = substitution, len = 0; *e != '\0'; e++)
          {
-            if (*e == '%' && isdigit(*(e + 1)))
+            if (*e == '%' && sc_isdigit(*(e + 1)))
               {
                  arg = *(e + 1) - '0';
                  assert(arg >= 0 && arg <= 9);
@@ -1597,7 +1623,7 @@ substpattern(char *line, size_t buffersize, char *pattern, char *substitution)
             strdel(line, (int)(s - line));
             for (e = substitution, s = line; *e != '\0'; e++)
               {
-                 if (*e == '%' && isdigit(*(e + 1)))
+                 if (*e == '%' && sc_isdigit(*(e + 1)))
                    {
                       arg = *(e + 1) - '0';
                       assert(arg >= 0 && arg <= 9);
@@ -1637,7 +1663,7 @@ substallpatterns(char *line, int buffersize)
        /* find the start of a prefix (skip all non-alphabetic characters),
         * also skip strings
         */
-       while (!isalpha(*start) && *start != '_' && *start != '\0')
+       while (!sc_isalpha(*start) && *start != '_' && *start != '\0')
          {
             /* skip strings */
             if (is_startstring(start))
@@ -1653,7 +1679,7 @@ substallpatterns(char *line, int buffersize)
        /* get the prefix (length), look for a matching definition */
        prefixlen = 0;
        end = start;
-       while (isalpha(*end) || isdigit(*end) || *end == '_')
+       while (sc_isalpha(*end) || sc_isdigit(*end) || *end == '_')
          {
             prefixlen++;
             end++;
@@ -2074,7 +2100,7 @@ lexclr(int clreol)
    if (clreol)
      {
        lptr = strchr(pline, '\0');
-       assert(!!lptr);
+       assert(lptr != NULL);
      }                         /* if */
 }
 
@@ -2150,13 +2176,19 @@ needtoken(int token)
        if (token < 256)
           sprintf(s1, "%c", (char)token);      /* single character token */
        else
-          strcpy(s1, sc_tokens[token - tFIRST]);       /* multi-character symbol */
+      {
+         strncpy(s1, sc_tokens[token - tFIRST], 19); /* multi-character symbol */
+         s1[19] = 0;
+      }
        if (!freading)
           strcpy(s2, "-end of file-");
        else if (_lextok < 256)
           sprintf(s2, "%c", (char)_lextok);
        else
-          strcpy(s2, sc_tokens[_lextok - tFIRST]);
+         {
+        strncpy(s2, sc_tokens[_lextok - tFIRST], 19);
+                s2[19] = 0;
+         }
        error(1, s1, s2);       /* expected ..., but found ... */
        return FALSE;
      }                         /* if */
@@ -2295,7 +2327,7 @@ litchar(char **lptr, int rawmode)
                  cptr += 1;
                  break;
               default:
-                 if (isdigit(*cptr))
+                 if (sc_isdigit(*cptr))
                    {           /* \ddd */
                       c = 0;
                       while (*cptr >= '0' && *cptr <= '9')     /* decimal! */
@@ -2323,7 +2355,7 @@ litchar(char **lptr, int rawmode)
 static int
 alpha(char c)
 {
-   return (isalpha(c) || c == '_' || c == PUBLIC_CHAR);
+   return (sc_isalpha(c) || c == '_' || c == PUBLIC_CHAR);
 }
 
 /*  alphanum
@@ -2333,7 +2365,7 @@ alpha(char c)
 int
 alphanum(char c)
 {
-   return (alpha(c) || isdigit(c));
+   return (alpha(c) || sc_isdigit(c));
 }
 
 /* The local variable table must be searched backwards, so that the deepest
@@ -2370,12 +2402,12 @@ free_symbol(symbol * sym)
    /* free all sub-symbol allocated memory blocks, depending on the
     * kind of the symbol
     */
-   assert(!!sym);
+   assert(sym != NULL);
    if (sym->ident == iFUNCTN)
      {
        /* run through the argument list; "default array" arguments
         * must be freed explicitly; the tag list must also be freed */
-       assert(!!sym->dim.arglist);
+       assert(sym->dim.arglist != NULL);
        for (arg = sym->dim.arglist; arg->ident != 0; arg++)
          {
             if (arg->ident == iREFARRAY && arg->hasdefault)
@@ -2384,12 +2416,12 @@ free_symbol(symbol * sym)
                      && ((arg->hasdefault & uSIZEOF) != 0
                          || (arg->hasdefault & uTAGOF) != 0))
                free(arg->defvalue.size.symname);
-            assert(!!arg->tags);
+            assert(arg->tags != NULL);
             free(arg->tags);
          }                     /* for */
        free(sym->dim.arglist);
      }                         /* if */
-   assert(!!sym->refer);
+   assert(sym->refer != NULL);
    free(sym->refer);
    free(sym);
 }
@@ -2405,7 +2437,7 @@ delete_symbol(symbol * root, symbol * sym)
    while (root->next != sym)
      {
        root = root->next;
-       assert(!!root);
+       assert(root != NULL);
      }                         /* while */
 
    /* unlink it, then free it */
@@ -2453,7 +2485,7 @@ delete_symbols(symbol * root, int level, int delete_labels,
             /* for user defined operators, also remove the "prototyped" flag, as
              * user-defined operators *must* be declared before use
              */
-            if (sym->ident == iFUNCTN && !isalpha(*sym->name)
+            if (sym->ident == iFUNCTN && !sc_isalpha(*sym->name)
                 && *sym->name != '_' && *sym->name != PUBLIC_CHAR)
                sym->usage &= ~uPROTOTYPED;
             root = sym;        /* skip the symbol */
@@ -2518,9 +2550,9 @@ refer_symbol(symbol * entry, symbol * bywhom)
 {
    int                 count;
 
-   assert(!!bywhom);   /* it makes no sense to add a "void" referrer */
-   assert(!!entry);
-   assert(!!entry->refer);
+   assert(bywhom != NULL);     /* it makes no sense to add a "void" referrer */
+   assert(entry != NULL);
+   assert(entry->refer != NULL);
 
    /* see if it is already there */
    for (count = 0; count < entry->numrefers && entry->refer[count] != bywhom;
@@ -2556,7 +2588,7 @@ refer_symbol(symbol * entry, symbol * bywhom)
      }                         /* if */
 
    /* add the referrer */
-   assert(!entry->refer[count]);
+   assert(entry->refer[count] == NULL);
    entry->refer[count] = bywhom;
    return TRUE;
 }
@@ -2612,7 +2644,7 @@ findconst(char *name)
       sym = find_symbol(&glbtab, name, fcurrent);
    if (!sym || sym->ident != iCONSTEXPR)
       return NULL;
-   assert(!sym->parent);       /* constants have no hierarchy */
+   assert(sym->parent == NULL);        /* constants have no hierarchy */
    return sym;
 }
 
@@ -2639,9 +2671,9 @@ addsym(char *name, cell addr, int ident, int vclass, int tag, int usage)
 
    /* global variables/constants/functions may only be defined once */
    assert(!(ident == iFUNCTN || ident == iCONSTEXPR) || vclass != sGLOBAL
-         || !findglb(name));
+         || findglb(name) == NULL);
    /* labels may only be defined once */
-   assert(ident != iLABEL || !findloc(name));
+   assert(ident != iLABEL || findloc(name) == NULL);
 
    /* create an empty referrer list */
    if (!(refer = (symbol **)malloc(sizeof(symbol *))))
@@ -2652,7 +2684,8 @@ addsym(char *name, cell addr, int ident, int vclass, int tag, int usage)
    *refer = NULL;
 
    /* first fill in the entry */
-   strcpy(entry.name, name);
+   strncpy(entry.name, name, sizeof(entry.name) - 1);
+   entry.name[sizeof(entry.name) - 1] = 0;
    entry.hash = namehash(name);
    entry.addr = addr;
    entry.vclass = (char)vclass;
@@ -2680,7 +2713,7 @@ addvariable(char *name, cell addr, int ident, int vclass, int tag,
    int                 level;
 
    /* global variables may only be defined once */
-   assert(vclass != sGLOBAL || !(sym = findglb(name))
+   assert(vclass != sGLOBAL || (sym = findglb(name)) == NULL
          || (sym->usage & uDEFINE) == 0);
 
    if (ident == iARRAY || ident == iREFARRAY)