www.pudn.com > IrDA.rar > rules.h


/*
  Copyright (C) 2002-2003 Gerd Rausch, BlauLogic (http://blaulogic.com)
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.

  3. Except as contained in this notice, neither the name of BlauLogic
     nor the name(s) of the author(s) may be used to endorse or promote
     products derived from this software without specific prior written
     permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHOR(S) OR BLAULOGIC BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef _RULES_H
#define _RULES_H

#include 

#if defined(__AVR_ATmega8__)
#define IRDIAL_SLOW_EEPROM
#endif

typedef struct Rule {
  uint8_t prefix_len, repl_len;
  uint8_t digit_count;
  uint8_t state_filter_mask, state_filter_value;
  uint8_t state_mod_mask, state_mod_toggle;
} Rule;

typedef enum Rules_Parse_State {
  RULES_PARSE_STATE_INITIAL,
  RULES_PARSE_STATE_WHITESPACE,
  RULES_PARSE_STATE_ACCESS_CODE,
  RULES_PARSE_STATE_DIGIT_COUNT,
  RULES_PARSE_STATE_FILTER,
  RULES_PARSE_STATE_PREFIX,
  RULES_PARSE_STATE_REPL,
  RULES_PARSE_STATE_MOD_TEST,
  RULES_PARSE_STATE_MOD,
  RULES_PARSE_STATE_DONE
} Rules_Parse_State;

typedef struct Rules_Parse_Context {
  uint8_t state;
  uint16_t access_code;
  uint16_t eeprom_addr;
  uint8_t mask_bit_on, mask_bit_shift;
  Rule rule;
#ifdef IRDIAL_SLOW_EEPROM
  uint8_t tmp_eeprom[E2END+1];
#endif
} Rules_Parse_Context;

void rules_apply(char *number, uint16_t size);
void rules_parse(Rules_Parse_Context *context_p, uint8_t *data, uint16_t size);
void rules_parse_finish(Rules_Parse_Context *context_p, uint8_t success);

#endif /* _RULES_H */