示例#1
0
文件: 15.c 项目: Kwonsoo/p16_unroll
int str_add_line_from_desc(str_t *str , int file_desc ) 
{ 
  int nchars ;
  char c ;

  {
#line 160
  nchars = 0;
#line 161
  c = (char)0;
#line 163
  if (! str) {
    {
#line 164
    str = str_make(str);
    }
  } else
#line 163
  if (! str->str) {
    {
#line 164
    str = str_make(str);
    }
  }
  {
#line 166
  while (1) {
    while_continue: /* CIL Label */ ;
    {
#line 168
    nchars = safe_read(file_desc, & c, 1);
    }
#line 170
    if (! nchars) {
#line 171
      return (2);
    }
#line 172
    if (nchars < 0) {
#line 173
      return (1);
    }
    {
#line 175
    str_add_char(str, c);
    }
#line 176
    if ((int )c == 10) {
#line 177
      goto while_break;
    }
  }
  while_break___0: /* CIL Label */ ;
  }
  while_break: ;
#line 180
  return (0);
}
}
示例#2
0
文件: 7.c 项目: Kwonsoo/p16_unroll
void str_add_str(str_t *str1 , str_t *str2 ) 
{ 
  int pos ;

  {
#line 113
  pos = 0;
#line 115
  if (! str2) {
#line 116
    return;
  } else
#line 115
  if (! str2->str) {
#line 116
    return;
  }
#line 117
  if (! str1) {
    {
#line 118
    str1 = str_make(str1);
    }
  } else
#line 117
  if (! str1->str) {
    {
#line 118
    str1 = str_make(str1);
    }
  }
  {
#line 120
  while (1) {
    while_continue: /* CIL Label */ ;

#line 120
    if (! (pos < str2->len)) {
#line 120
      goto while_break;
    }
    {
#line 121
    str_add_char(str1, *(str2->str + pos));
#line 120
    pos ++;
    }
  }
  while_break___0: /* CIL Label */ ;
  }
  while_break: ;
#line 122
  return;
}
}
示例#3
0
文件: 15.c 项目: Kwonsoo/p16_unroll
str_t *nstr_to_str(char *nstr ) 
{ 
  str_t *str ;
  int pos ;

  {
  {
#line 189
  str = (str_t *)0;
#line 190
  pos = 0;
#line 192
  str = str_make(str);
  }
#line 194
  if (! nstr) {
#line 195
    return (str);
  }
  {
#line 196
  while (1) {
    while_continue: /* CIL Label */ ;

#line 196
    if (! *(nstr + pos)) {
#line 196
      goto while_break;
    }
    {
#line 197
    str_add_char(str, *(nstr + pos));
#line 196
    pos ++;
    }
  }
  while_break___0: /* CIL Label */ ;
  }
  while_break: ;
#line 199
  return (str);
}
}
示例#4
0
文件: 15.c 项目: Kwonsoo/p16_unroll
str_t *int_to_str(int num ) 
{ 
  char c[2] ;
  int pos ;
  int rem ;
  str_t *rstr ;
  str_t *tmp ;
  str_t *str ;
  str_t *tmp___0 ;
  void *__cil_tmp9 ;
  char *__cil_tmp10 ;

  {
  {
#line 240
  pos = 0;
#line 241
  rem = 0;
#line 242
  tmp = str_make((str_t *)0);
#line 242
  rstr = tmp;
#line 243
  tmp___0 = str_make((str_t *)0);
#line 243
  str = tmp___0;
  }
  {
#line 247
  while (1) {
    while_continue: /* CIL Label */ ;

#line 247
    if (! (num > 0)) {
#line 247
      goto while_break;
    }
    {
#line 249
    rem = num % 10;
#line 250
    num /= 10;
#line 251
    sprintf((char */* __restrict  */)(c), (char const   */* __restrict  */)"%d", rem);
#line 252
    str_add_char(rstr, c[0]);
    }
  }
  while_break___1: /* CIL Label */ ;
  }
  while_break: 
#line 256
  pos = rstr->len - 1;
  {
#line 256
  while (1) {
    while_continue___0: /* CIL Label */ ;

#line 256
    if (! (pos >= 0)) {
#line 256
      goto while_break___0;
    }
    {
#line 257
    str_add_char(str, *(rstr->str + pos));
#line 256
    pos --;
    }
  }
  while_break___2: /* CIL Label */ ;
  }
  while_break___0: ;
#line 259
  return (str);
}
}
示例#5
0
文件: 15.c 项目: Kwonsoo/p16_unroll
int str_add_line(str_t *str , FILE *stream ) 
{ 
  register char c ;
  int tmp ;
  int tmp___0 ;

  {
#line 132
  if (! str) {
    {
#line 133
    str = str_make(str);
    }
  } else
#line 132
  if (! str->str) {
    {
#line 133
    str = str_make(str);
    }
  }
#line 134
  if (! stream) {
#line 135
    return (1);
  }
  {
#line 137
  while (1) {
    while_continue: /* CIL Label */ ;
    {
#line 139
    tmp = _IO_getc(stream);
#line 139
    c = (char )tmp;
    }
#line 141
    if ((int )c == -1) {
#line 142
      return (2);
    } else {
      {
#line 141
      tmp___0 = ferror(stream);
      }
#line 141
      if (tmp___0) {
#line 142
        return (2);
      }
    }
    {
#line 143
    str_add_char(str, c);
    }
#line 144
    if ((int )c == 10) {
#line 145
      goto while_break;
    }
  }
  while_break___0: /* CIL Label */ ;
  }
  while_break: ;
#line 148
  return (0);
}
}
/**
 * Vstavana funkcia read().
 * @param - miesto pre vysledok operacie.
 * @param - parameter funkcie read()
 * @return - v pripade, ze sa nenacil dany pocet znakov false
 */
bool buildin_read(Tvariable * dst, const Tvariable * item)
{
    assert(dst);
    assert(item);

    static const char * READ_NUM     = "*n";
    static const char * READ_STR_LF  = "*l";
    static const char * READ_STR_EOF = "*a";

    Tstring str;
    int c;

    buildin_freestr(dst);
    if (item->type == VAR_NUM)
    {
        if (item->val.num < 0)
        {
            xerror_msg(ERR_INT_READ_OP);
            return set_error(RET_ERR_INT);
        }

        str_init(&str);
        for (unsigned i = 0; i < (unsigned) item->val.num; ++i)
        {
            c = getchar();
            if (c != EOF)
                str_add_char(&str, c);
        }

        dst->type = VAR_STR;
        dst->val.str = str_get_str(&str);
    }
    else if (item->type == VAR_STR)
    {
        if (! strncmp(item->val.str, READ_NUM, 2))
        {
            int i = scanf("%lf", &dst->val.num);
            if (i != 1 || isnan(dst->val.num) || isinf(dst->val.num))
            {
                dst->type = VAR_NIL;
            }
            else
                dst->type = VAR_NUM;
        }
        else if (! strncmp(item->val.str, READ_STR_LF, 2))
        {
            str_init(&str);
            while ((c = getchar()) != '\n' && c != EOF)
                str_add_char(&str, c);
            if (str.length == 0)
            {
                dst->type = VAR_NIL;
            }
            else
            {
                dst->type = VAR_STR;
                dst->val.str = str.str;
            }
        }
        else if (! strncmp(item->val.str, READ_STR_EOF, 2))
        {
            str_init(&str);
            while ((c = getchar()) != EOF)
                str_add_char(&str, c);
            dst->type = VAR_STR;
            dst->val.str = str.str;
        }
        else
        {
            /*
             * Chybny parameter read je semanticka chyba
             */
            xerror_msg(ERR_INT_READ_OP);
            return set_error(RET_ERR_INT);
        }
    }
    else
    {
        /*
         * V pripade inych parametrov je vrateny nil.
         */
        dst->type = VAR_NIL;
    }

    return true;
}