Ejemplo n.º 1
0
static int count_headers(void *in_len, const char *key, const char *value)
{
    int *len = in_len;

    *len += strlen(FIELD_SEPARATOR);
    *len += count_string(key);
    *len += strlen(KEYVAL_SEPARATOR);
    *len += count_string(value);

    return 1;
}
Ejemplo n.º 2
0
void dir_pop_stbuf(struct stat* stbuf, string contents) {
  time_t current_time;
  time(&current_time);
  stbuf->st_mode=S_IFDIR | 0755;
  stbuf->st_nlink=count_string(contents)+2;
  stbuf->st_size=4096;
  stbuf->st_mtime=current_time;
}
char *string_concat(char *s1, char *s2) {
  int len;
  char *cPtr;

  len = count_string(s1) + count_string(s2);

  cPtr = malloc(sizeof(char) * len + 1);

  if (cPtr == NULL) {
    return NULL;
  }

  while (*s1 != '\0') {
    *cPtr++ = *s1++;
  }

  while (*s2 != '\0') {
    *cPtr++ = *s2++;
  }

  *cPtr = '\0';

  return &(cPtr[-len]);
}
string resolve_express_function(const string express) {
    if (!resolve_express_is_function(express)) return "";

    split_result split(split_string(express,"|"));
    string function(split.first),next_function(split.second);
    left_move_string(next_function,1);
    string result;

    while (!function.empty()) {
        if (!resolve_express_is_function(function)) return function;

        split=split_string(function,"(");
        string function_name(upper_string(split.first)),function_arg(separate_string(function,"(",")"));

        if (function_rnd==function_name) {
            function_arg=separate_string(function_arg,"[","]");
            string down,up;
            split=split_string(function_arg,"-");
            if (1<count_string(function_arg,"-")) {
                left_move_string(split.second,1);
                if (resolve_express_is_function(split.second)) {
                    down=split.first;
                    up=split.second;
                    left_move_string(up,1);
                } else {
                    split=split_string(function_arg,")");
                    down=split.first;
                    down+=")";
                    left_move_string(split.second,1);
                    split=split_string(split.second,"-");
                    left_move_string(split.second,1);
                    up=split.second;
                }
            } else {
                down=split.first;
                up=split.second;
                left_move_string(up,1);
            }

            if (down.empty() || up.empty())
                return "";

            if (resolve_express_is_function(down))
                down=resolve_express_function(down);
            if (resolve_express_is_function(up))
                up=resolve_express_function(up);

            long down_=string_to_number(down),up_=string_to_number(up);
            long rnd=ramdon(down_,up_);
            result+=number_to_string(rnd);
        } else if (function_time==function_name) {
        } else if (function_base64==function_name) {
            if (!resolve_express_is_function(function_arg)) {
                return base64_encode(function_arg.c_str(),function_arg.length());
            } else {
                string encode_string(resolve_express_function(function_arg));
                return base64_encode(encode_string.c_str(),encode_string.length());
            }
        } else if (function_len==function_name) {
            unsigned int length=function_arg.length();
            return number_to_string(length);
        }
        split=split_string(next_function,",");
        function=split.first;
        next_function=split.second;
        left_move_string(next_function,1);
    }
    return result;
}
Ejemplo n.º 5
0
lexeme read_token(buffer_reader *reader) {
  lexeme lex;
  rune c;

  lex.lexeme_type = LEXEME_UNKNOWN;

  do {
    lex.location = buffer_reader_get_current_pointer(reader);
    buffer_reader_skip(reader);
    c = *lex.location;
    // c = buffer_reader_read_rune(reader);
  } while(is_whitespace(c));

  if(is_special_symbol(c)) {
    lex.lexeme_type = LEXEME_ATOM;
    lex.size = 1;
  } else if(is_alpha(c)) {
    lex.lexeme_type = LEXEME_ATOM;
    lex.size = count_atom(reader);
  } else if(is_numeric(c)) {
    lex.lexeme_type = LEXEME_NUMBER;
    lex.size = count_number(reader);
  } else {
    switch(c) {
    case '\'':
      lex.lexeme_type = LEXEME_CHAR;
      lex.location++;
      lex.size = 1;
      check_char(reader);
      break;

    case '"':
      lex.lexeme_type = LEXEME_STRING;
      lex.location++;
      lex.size = count_string(reader);
      break;

    case '{':
      lex.lexeme_type = LEXEME_LEFT_BRACKET;
      lex.size = 1;
      break;

    case '}':
      lex.lexeme_type = LEXEME_RIGHT_BRACKET;
      lex.size = 1;
      break;

    case 0x2190: // left arrow
      lex.lexeme_type = LEXEME_LEFT_ARROW;
      lex.size = 1;
      break;

    case 0x235D: // up shoe jot
      lex.lexeme_type = LEXEME_COMMENT;
      lex.size = count_until(reader, '\n') + 1;
      break;

    default:
      printf("Unhandled character in lexer: %4x\n", c);
      lex.size = 1;
    }
  }

  return lex;
}