Exemplo n.º 1
0
char		*my_epur_str(char *str)
{
  t_uint	idx_str;
  t_uint	idx;
  char		*clean_str;
  int		first;

  if (str == NULL)
    return (NULL);
  clean_str = _init_variables(str, &idx, &idx_str, &first);
  while (str[idx_str])
    {
      if (str[idx_str] == ' ' || str[idx_str] == '\t')
	{
	  if (first == FALSE && _is_last(str + idx_str) == FALSE)
	    {
	      clean_str[idx] = ' ';
	      idx += 1;
	    }
	  while (str[idx_str] == ' ' || str[idx_str] == '\t')
	    idx_str += 1;
	}
      else
	clean_str[idx] = _get_char(str, &first, &idx, &idx_str);
    }
  clean_str[idx] = '\0';
  return (clean_str);
}
Exemplo n.º 2
0
/**
 *  \brief TOKENIZER of key-value protocol
 *
 *         Actual key-value TOKENIZER engine
 *
 *         TOKENIZER defines #Token enum to map recognized tokens to integer values.
 *
 *         <TOK_EOF>       ::= EOF (end of file)
 *         <TOK_OPEN>      ::= "{{"
 *         <TOK_CLOSE>     ::= "}}"
 *         <TOK_SEMICOLON> ::= ";"
 *         <TOK_STRING>    ::= [a-zA-Z0-9_-!@#$%^&*()]+    // See isstring() function *
 *
 *  \param out_str Output string with parsed token (string)
 *  \param str_size Size of str buffer we can use
 *
 *  \return Return #Token enum value used by parser to check for key-value occurrences
 *
 */
static int gettok(char *out_str, const int str_size) {
    static int LastChar = '!';
    static int str_idx = 0;

    // whitespace ::=
    while (isspace(LastChar)) {
        LastChar = _get_char();
    }

    // string ::= [a-zA-Z0-9_-!@#$%^&*()]+
    if (isstring(LastChar)) {
        str_idx = 0;
        if (out_str && str_idx < str_size - 1) {
            out_str[str_idx++] = LastChar;
        }

        while (isstring((LastChar = _get_char())))
            if (out_str && str_idx < str_size - 1) {
                out_str[str_idx++] = LastChar;
            }
        if (out_str && str_idx < str_size) {
            out_str[str_idx] = '\0';
        }

        return tok_string;
    }

    // semicolon ::= ';'
    if (LastChar == ';') {
        LastChar = _get_char();
        return tok_semicolon;
    }

    // open ::= '{{'
    if (LastChar == '{') {
        LastChar = _get_char();
        if (LastChar == '{') {
            LastChar = _get_char();
            return tok_open;
        }
    }

    // close ::= '}'
	if (LastChar == '}') {
		LastChar = _get_char();
		if (LastChar == '}') {
			//LastChar = _get_char();
			return tok_close;
		}
	}

    if (LastChar == EOF)
        return tok_eof;

    // Otherwise, just return the character as its ascii value.
    int ThisChar = LastChar;
    LastChar = _get_char();
    return ThisChar;
}
Exemplo n.º 3
0
int REM_pad_delete(void)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_DELETE);
    _get_char(&result);

    _hold_signals(0);

    return result;
}
Exemplo n.º 4
0
int REM_pad_current(char *name)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_CURRENT);
    _get_char(&result);
    _get_text(name);

    _hold_signals(0);

    return result;
}
Exemplo n.º 5
0
int REM_pad_delete_item(const char *name)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_DELETE_ITEM);
    _send_text(name);
    _get_char(&result);

    _hold_signals(0);

    return result;
}
Exemplo n.º 6
0
int REM_pad_create(const char *pad)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_CREATE);
    _send_text(pad);
    _get_char(&result);

    _hold_signals(0);

    return result;
}
Exemplo n.º 7
0
int REM_pad_select(const char *pad)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_SELECT);
    _send_text(pad);
    _get_char(&result);

    _hold_signals(0);

    return result;
}
Exemplo n.º 8
0
int REM_pad_set_item(const char *item, const char *value)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_SET_ITEM);
    _send_text(item);
    _send_text(value);
    _get_char(&result);

    _hold_signals(0);

    return result;
}
Exemplo n.º 9
0
int REM_pad_list_items(char ***list, int *count)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_LIST_ITEMS);
    _get_char(&result);
    if (result == OK)
	_get_list(list, count);

    _hold_signals(0);

    return result;
}
Exemplo n.º 10
0
int REM_pad_append_item(const char *item, const char *value, int replace)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_APPEND_ITEM);
    _send_text(item);
    _send_text(value);
    _send_int(&replace);
    _get_char(&result);

    _hold_signals(0);

    return result;
}
Exemplo n.º 11
0
int REM_pad_get_item(const char *item, char ***list, int *count)
{
    char result;

    _hold_signals(1);

    _send_ident(PAD_GET_ITEM);
    _send_text(item);
    _get_char(&result);

    if (result == OK)
	_get_list(list, count);

    _hold_signals(0);

    return result;
}