示例#1
0
static int parse_section (section_t **section,scan_t *sc,char **lookahead)
{
   int result = OK;
   if (lookahead != NULL)
	 {
		result = parse_assignment (section,sc,lookahead,SECTION_START);
		while (result == OK)
		  {
			 SCAN();
			 if (result == '}') return (OK);
			 if (result != TOK_KEYWORD)
			   {
				  parse_error (sc,"'}', or TOK_KEYWORD",result);
				  return (ERR);
			   }
			 result = parse_assignment (section,sc,&sc->token.keyword,SECTION_END);
			 if (result == FIN)
			   {
				  parse_error (sc,"'}'",result);
				  return (ERR);
			   }
		  }
	 }
   else while (result == OK) result = parse_assignment (section,sc,NULL,0);
   return (result);
}
示例#2
0
instruction_ptr Parser::parse_instruction()
{
    if (!ErrorHandler::is_ok())
        return instruction_ptr();
    
    
    save();
    instruction_ptr result = parse_assignment();
    
    if (!result)
    {
        restore();
        result = parse_expression();
    }
    
    if (!result)
        result = parse_if_block();
    
    if (!result)
        result = parse_while_block();
    
    if (!result)
        result = parse_return();
    
    if (!result)
        result = parse_print();
    
    if (!result)
        result = parse_read();
    
    if (result)
        next_line();
    
    return result;
}
示例#3
0
void
StatusMessageList::LoadFile(TLineReader &reader)
{
  int ms; // Found ms for delay
  const TCHAR **location; // Where to put the data
  bool some_data; // Did we find some in the last loop...

  // Init first entry
  _init_Status(StatusMessageData_Size);
  some_data = false;

  /* Read from the file */
  TCHAR *buffer;
  const TCHAR *key, *value;
  while ((StatusMessageData_Size < MAXSTATUSMESSAGECACHE) &&
         (buffer = reader.read()) != NULL) {
    // Check valid line? If not valid, assume next record (primative, but works ok!)
    if (*buffer == _T('#') || !parse_assignment(buffer, key, value)) {
      // Global counter (only if the last entry had some data)
      if (some_data) {
        StatusMessageData_Size++;
        some_data = false;
        _init_Status(StatusMessageData_Size);
      }
    } else {
      location = NULL;

      if (_tcscmp(key, _T("key")) == 0) {
        some_data = true; // Success, we have a real entry
        location = &StatusMessageData[StatusMessageData_Size].key;
      } else if (_tcscmp(key, _T("sound")) == 0) {
        StatusMessageData[StatusMessageData_Size].doSound = true;
        location = &StatusMessageData[StatusMessageData_Size].sound;
      } else if (_tcscmp(key, _T("delay")) == 0) {
        TCHAR *endptr;
        ms = _tcstol(value, &endptr, 10);
        if (endptr > value)
          StatusMessageData[StatusMessageData_Size].delay_ms = ms;
      } else if (_tcscmp(key, _T("hide")) == 0) {
        if (_tcscmp(value, _T("yes")) == 0)
          StatusMessageData[StatusMessageData_Size].doStatus = false;
      }

      // Do we have somewhere to put this &&
      // is it currently empty ? (prevent lost at startup)
      if (location && (_tcscmp(*location, _T("")) == 0)) {
        // TODO code: this picks up memory lost from no entry, but not duplicates - fix.
        if (*location) {
          // JMW fix memory leak
          free((void*)*location);
        }
        *location = StringMallocParse(value);
      }
    }
  }

  // How many we really got (blank next just in case)
  StatusMessageData_Size++;
  _init_Status(StatusMessageData_Size);
}
示例#4
0
文件: parse.c 项目: jkdewar/rook
/*----------------------------------------------------------------------*/
static ast_statement_t *parse_statement(parse_state_t *p) {
    token_t *token;
    token = peek_token(p);
    if (token == NULL) {
        return NULL;
    } else if (test_token(token, TK_ELSE) ||
               test_token(token, TK_END)) {
        return NULL;
    } else if (test_token(token, TK_VAR)) {
        return parse_declare_var(p);
    } else if (test_token(token, TK_FUNCTION)) {
        return parse_define_function(p);
    } else if (test_token(token, TK_RETURN)) {
        return parse_return(p);
    } else if (test_token(token, TK_IF)) {
        return parse_if(p);
    } else if (test_token(token, TK_FOR)) {
        return parse_for(p);
    } else if (test_token(token, TK_IDENTIFIER)) {
        return parse_assignment(p);
    }
    next_token(p);
    error(p, "statement expected");
    return NULL; /* unreachable */
}
示例#5
0
int scan(FILE *target)
{
  hash_t *var_map = malloc(sizeof(hash_t));
  hash_init(var_map, 1024);

  write_header(target);

  int ret = 0;

  while(next() == true){

    if(is_alpha() == false){

      printf("An instruction can only start with a function call or assignment\n");
      return 1;
    }

    char *current_token = get_token();

    char *temp;
    strcpy(temp, current_token);

    if(next() == false){

      printf("Incomplete instruction\n");
      return 1;

    }

    if(is_left()){

      ret = parse_call(target, temp, var_map);  /* It is a call */

    } else if(is_assignment()){

      ret = parse_assignment(target, temp, var_map);  /* It is an assignment */

    } else {
      printf("Not a valid instruction\n");
      return 1;
    }

    if(ret == 1 ){
      printf("Syntax error\n");
      return 1;
    }

  }

  write_end(target);
  free(var_map);
  return ret;

}
示例#6
0
/****************************************************************************
 * op_cmos_set_one_param
 *
 * -w NAME=VALUE
 *
 * Set parameter NAME to VALUE.
 ****************************************************************************/
static void op_cmos_set_one_param(void)
{
	const char *name, *value;

	get_cmos_layout();

	/* Separate 'NAME=VALUE' syntax into two strings representing NAME and
	 * VALUE.
	 */
	parse_assignment(nvramtool_op.param, &name, &value);

	set_one_param(name, value);
}
示例#7
0
	void Parser::scan_line()
	{
	    if (current_char == NEWLINE)
            return;

		std::string line = "";
		line += current_char;

		while (scan_char() && current_char != NEWLINE)
            line += current_char;

		getSection()->lines.push_back(
			parse_assignment(line));
	};
示例#8
0
文件: v7.c 项目: di3online/v7
//  declaration =   "var" identifier [ "=" expression ] [ "," { i [ "=" e ] } ]
static enum v7_err parse_declaration(struct v7 *v7) {
  int sp = v7_sp(v7);

  do {
    inc_stack(v7, sp - v7_sp(v7));  // Clean up the stack after prev decl
    TRY(parse_identifier(v7));
    if (*v7->cursor == '=') {
      if (!v7->no_exec) v7_make_and_push(v7, V7_UNDEF);
      TRY(parse_assignment(v7, &v7->scopes[v7->current_scope]));
    }
  } while (test_and_skip_char(v7, ','));

  return V7_OK;
}
示例#9
0
std::vector<reaver::despayre::assignment> reaver::despayre::_v1::parse(std::vector<reaver::despayre::token> tokens)
{
    std::vector<assignment> assignments;

    context ctx;
    ctx.begin = std::begin(tokens);
    ctx.end = std::end(tokens);

    while (ctx.begin != ctx.end)
    {
        assignments.push_back(parse_assignment(ctx));
    }

    return assignments;
}
示例#10
0
文件: v7.c 项目: di3online/v7
//  expression  =   term { add_op term } |
//                  expression "?" expression ":" expression
//                  expression logical_op expression
//                  variable "=" expression
//  add_op      =   "+" | "-"
static enum v7_err parse_expression(struct v7 *v7) {
#ifdef V7_DEBUG
  const char *stmt_str = v7->cursor;
#endif
  int op;

  v7->cur_obj = &v7->scopes[v7->current_scope];
  TRY(parse_term(v7));

  while (*v7->cursor == '-' || *v7->cursor == '+') {
    int ch = *v7->cursor;
    TRY(match(v7, ch));
    TRY(parse_term(v7));
    TRY(do_arithmetic_op(v7, ch));
  }

  if ((op = is_logical_op(v7->cursor)) > OP_XX) {
    v7->cursor += op == OP_LT || op == OP_GT ? 1 : 2;
    skip_whitespaces_and_comments(v7);
    TRY(parse_expression(v7));
    TRY(do_logical_op(v7, op));
  }

  // Parse assignment
  if (*v7->cursor == '=') {
    //printf("=> cur_obj: %p\n", cur_obj);
    TRY(parse_assignment(v7, v7->cur_obj));
  }

  // Parse ternary operator
  if (*v7->cursor == '?') {
    int condition_true = v7_is_true(v7_top(v7)[-1]);
    int old_no_exec = v7->no_exec;

    TRY(match(v7, '?'));
    v7->no_exec = old_no_exec || !condition_true;
    TRY(parse_expression(v7));
    TRY(match(v7, ':'));
    v7->no_exec = old_no_exec || condition_true;
    TRY(parse_expression(v7));
    v7->no_exec = old_no_exec;
  }

  return V7_OK;
}
示例#11
0
void
StatusMessageList::LoadFile(TLineReader &reader)
{
  // Init first entry
  StatusMessage current;
  current.Clear();

  /* Read from the file */
  TCHAR *buffer;
  const TCHAR *key, *value;
  while ((buffer = reader.ReadLine()) != NULL) {
    // Check valid line? If not valid, assume next record (primative, but works ok!)
    if (*buffer == _T('#') || !parse_assignment(buffer, key, value)) {
      // Global counter (only if the last entry had some data)
      if (!current.IsEmpty()) {
        list.append(current);
        current.Clear();

        if (list.full())
          break;
      }
    } else {
      if (_tcscmp(key, _T("key")) == 0) {
        if (current.key == NULL)
          current.key = UnescapeBackslash(value);
      } else if (_tcscmp(key, _T("sound")) == 0) {
        if (current.sound == NULL)
          current.sound = UnescapeBackslash(value);
      } else if (_tcscmp(key, _T("delay")) == 0) {
        TCHAR *endptr;
        unsigned ms = ParseUnsigned(value, &endptr);
        if (endptr > value)
          current.delay_ms = ms;
      } else if (_tcscmp(key, _T("hide")) == 0) {
        if (_tcscmp(value, _T("yes")) == 0)
          current.visible = false;
      }
    }
  }

  if (!current.IsEmpty())
    list.append(current);
}
示例#12
0
文件: main.c 项目: DoryuX/Xwell
int main( int argc, char *argv[] ) {
    char *filename = NULL;
    char *msg = NULL;

    if ( argc == 2 ) {
        filename = argv[ 1 ];

        switch ( utils_validate_filename( filename ) ) {
            case FILE_OK:
                printf( "Input File: %s\n", filename );
                
                parse_init( filename );
                parse_assignment();

                fclose( g_fptr );

                break;
            case BAD_EXTENSION:
                msg = "Expected a file in the format of '< filename >.xwell'";
                utils_error( msg, strlen( msg ) );
                break;
            default:
                msg = "Unknown FILECHECK_t Error";
                utils_error( msg, strlen( msg ) );
        }
    } else {
        char msgbf[ 100 ] = "\0";
        size_t n = sprintf( msgbf, "Usage - %s %s", argv[ 0 ], "< filename >.xwell" );
        utils_error( msgbf, n );
    }

    msg = NULL;
    filename = NULL;

    exit( EXIT_SUCCESS );
}
示例#13
0
文件: parser.c 项目: Saruta/a2c
struct instruction *parse_for(void)
{
  int decreasing = 0;
  eat(FOR);
  struct expr *lhs = parse_expression();
  struct assignment *a = parse_assignment(lhs);
  if (current_lang == LANG_EN && lookahead[0]->type == DECREASING)
  {
    decreasing = 1;
    eat(DECREASING);
  }
  else
    eat(UNTIL);
  struct expr *until = parse_expression();
  if (current_lang == LANG_FR && lookahead[0]->type == DECREASING)
  {
    decreasing = 1;
    eat(DECREASING);
  }
  eat(DO); eat(EOL);
  instructionlist_t block = parse_block();
  eat(END); eat(FOR); eat(EOL);
  return forblock(a, until, decreasing, block);
}
示例#14
0
void
StatusMessageList::LoadFile(TLineReader &reader)
{
  int ms; // Found ms for delay
  const TCHAR **location; // Where to put the data
  bool some_data; // Did we find some in the last loop...

  // Init first entry
  StatusMessageSTRUCT current;
  _init_Status(current);
  some_data = false;

  /* Read from the file */
  TCHAR *buffer;
  const TCHAR *key, *value;
  while ((buffer = reader.read()) != NULL) {
    // Check valid line? If not valid, assume next record (primative, but works ok!)
    if (*buffer == _T('#') || !parse_assignment(buffer, key, value)) {
      // Global counter (only if the last entry had some data)
      if (some_data) {
        StatusMessageData.append(current);
        some_data = false;
        _init_Status(current);

        if (StatusMessageData.full())
          break;
      }
    } else {
      location = NULL;

      if (_tcscmp(key, _T("key")) == 0) {
        some_data = true; // Success, we have a real entry
        location = &current.key;
      } else if (_tcscmp(key, _T("sound")) == 0) {
        current.doSound = true;
        location = &current.sound;
      } else if (_tcscmp(key, _T("delay")) == 0) {
        TCHAR *endptr;
        ms = _tcstol(value, &endptr, 10);
        if (endptr > value)
          current.delay_ms = ms;
      } else if (_tcscmp(key, _T("hide")) == 0) {
        if (_tcscmp(value, _T("yes")) == 0)
          current.doStatus = false;
      }

      // Do we have somewhere to put this &&
      // is it currently empty ? (prevent lost at startup)
      if (location && (_tcscmp(*location, _T("")) == 0)) {
        // TODO code: this picks up memory lost from no entry, but not duplicates - fix.
        if (*location) {
          // JMW fix memory leak
          free((void*)const_cast<TCHAR *>(*location));
        }
        *location = UnescapeBackslash(value);
      }
    }
  }

  if (some_data)
    StatusMessageData.append(current);
}
示例#15
0
/*-------------------------------------------------------------------------
 * Function:    parse_expr
 *
 * Purpose:     Parses an expression.
 *
 * Return:      Success:        The expression.
 *
 *              Failure:        &ErrorCell
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec  4 1996
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static obj_t
parse_expr (lex_t *f, int skipnl) {

   return parse_assignment (f, skipnl);
}
示例#16
0
void
ParseInputFile(InputConfig &config, TLineReader &reader)
{
  // TODO code - Safer sizes, strings etc - use C++ (can scanf restrict length?)

  TCHAR *new_label = NULL;

  // Init first entry

  // Did we find some in the last loop...
  bool some_data = false;
  // Multiple modes (so large string)
  TCHAR d_mode[1024] = _T("");
  TCHAR d_type[256] = _T("");
  TCHAR d_data[256] = _T("");
  unsigned event_id = 0;
  TCHAR d_label[256] = _T("");
  int d_location = 0;
  TCHAR d_event[256] = _T("");
  TCHAR d_misc[256] = _T("");

  int line = 0;

  // Read from the file
  // TODO code: What about \r - as in \r\n ?
  // TODO code: Note that ^# does not allow # in key - might be required (probably not)
  //   Better way is to separate the check for # and the scanf
  TCHAR *buffer;
  while ((buffer = reader.read()) != NULL) {
    TrimRight(buffer);
    line++;

    const TCHAR *key, *value;

    // experimental: if the first line is "#CLEAR" then the whole default config is cleared
    //               and can be overwritten by file
    if (line == 1 && _tcscmp(buffer, _T("#CLEAR")) == 0) {
      config.clear_all_events();
    } else if (buffer[0] == _T('\0')) {
      // Check valid line? If not valid, assume next record (primative, but works ok!)
      // General checks before continue...
      if (some_data && (d_mode != NULL) && (_tcscmp(d_mode, _T("")) != 0)) {

        TCHAR *token;

        // For each mode
        token = _tcstok(d_mode, _T(" "));

        // General errors - these should be true
        assert(d_location >= 0);
        assert(d_location < 1024); // Scott arbitrary limit
        assert(d_mode != NULL);
        assert(d_type != NULL);
        assert(d_label != NULL);

        // These could indicate bad data - thus not an ASSERT (debug only)
        // assert(_tcslen(d_mode) < 1024);
        // assert(_tcslen(d_type) < 1024);
        // assert(_tcslen(d_label) < 1024);

        while (token != NULL) {

          // All modes are valid at this point
          int mode_id = config.make_mode(token);
          assert(mode_id >= 0);

          // Make label event
          // TODO code: Consider Reuse existing entries...
          if (d_location > 0) {
            // Only copy this once per object - save string space
            if (!new_label) {
              new_label = StringMallocParse(d_label);
            }

            config.append_menu(mode_id, new_label, d_location, event_id);
          }

          // Make key (Keyboard input)
          // key - Hardware key or keyboard
          if (_tcscmp(d_type, _T("key")) == 0) {
            // Get the int key (eg: APP1 vs 'a')
            unsigned key = InputEvents::findKey(d_data);
            if (key > 0)
              config.Key2Event[mode_id][key] = event_id;
            else
              LogStartUp(_T("Invalid key data: %s at %i"), d_data, line);

          // Make gce (Glide Computer Event)
          // GCE - Glide Computer Event
          } else if (_tcscmp(d_type, _T("gce")) == 0) {
            // Get the int key (eg: APP1 vs 'a')
            int key = InputEvents::findGCE(d_data);
            if (key >= 0)
              config.GC2Event[mode_id][key] = event_id;
            else
              LogStartUp(_T("Invalid GCE data: %s at %i"), d_data, line);

          // Make ne (NMEA Event)
          // NE - NMEA Event
          } else if (_tcscmp(d_type, _T("ne")) == 0) {
            // Get the int key (eg: APP1 vs 'a')
            int key = InputEvents::findNE(d_data);
            if (key >= 0)
              config.N2Event[mode_id][key] = event_id;
            else
              LogStartUp(_T("Invalid GCE data: %s at %i"), d_data, line);

          // label only - no key associated (label can still be touch screen)
          } else if (_tcscmp(d_type, _T("label")) == 0) {
            // Nothing to do here...

          } else {
            LogStartUp(_T("Invalid type: %s at %i"), d_type, line);
          }

          token = _tcstok(NULL, _T(" "));
        }
      }

      // Clear all data.
      some_data = false;
      _tcscpy(d_mode, _T(""));
      _tcscpy(d_type, _T(""));
      _tcscpy(d_data, _T(""));
      event_id = 0;
      _tcscpy(d_label, _T(""));
      d_location = 0;
      new_label = NULL;

    } else if (string_is_empty(buffer) || buffer[0] == _T('#')) {
      // Do nothing - we probably just have a comment line
      // JG removed "void;" - causes warning (void is declaration and needs variable)
      // NOTE: Do NOT display buffer to user as it may contain an invalid stirng !

    } else if (parse_assignment(buffer, key, value)) {
      if (_tcscmp(key, _T("mode")) == 0) {
        if (_tcslen(value) < 1024) {
          some_data = true; // Success, we have a real entry
          _tcscpy(d_mode, value);
        }
      } else if (_tcscmp(key, _T("type")) == 0) {
        if (_tcslen(value) < 256)
          _tcscpy(d_type, value);
      } else if (_tcscmp(key, _T("data")) == 0) {
        if (_tcslen(value) < 256)
          _tcscpy(d_data, value);
      } else if (_tcscmp(key, _T("event")) == 0) {
        if (_tcslen(value) < 256) {
          _tcscpy(d_event, _T(""));
          _tcscpy(d_misc, _T(""));
          int ef;

          #if defined(__BORLANDC__)
          memset(d_event, 0, sizeof(d_event));
          memset(d_misc, 0, sizeof(d_event));
          if (_tcschr(value, ' ') == NULL) {
            _tcscpy(d_event, value);
          } else {
          #endif

          ef = _stscanf(value, _T("%[^ ] %[A-Za-z0-9 \\/().,]"), d_event,
              d_misc);

          #if defined(__BORLANDC__)
          }
          #endif

          // TODO code: Can't use token here - breaks
          // other token - damn C - how about
          // C++ String class ?

          // TCHAR *eventtoken;
          // eventtoken = _tcstok(value, _T(" "));
          // d_event = token;
          // eventtoken = _tcstok(value, _T(" "));

          if ((ef == 1) || (ef == 2)) {

            // TODO code: Consider reusing existing identical events

            pt2Event event = InputEvents::findEvent(d_event);
            if (event) {
              TCHAR *allocated = StringMallocParse(d_misc);
              event_id = config.append_event(event, allocated, event_id);

              /* not freeing the string, because
                 InputConfig::append_event() stores the string point
                 without duplicating it; strictly speaking, this is a
                 memory leak, but the input file is only loaded once
                 at startup, so this is acceptable; in return, we
                 don't have to duplicate the hard-coded defaults,
                 which saves some memory */
              //free(allocated);

            } else {
              LogStartUp(_T("Invalid event type: %s at %i"), d_event, line);
            }
          } else {
            LogStartUp(_T("Invalid event type at %i"), line);
          }
        }
      } else if (_tcscmp(key, _T("label")) == 0) {
        _tcscpy(d_label, value);
      } else if (_tcscmp(key, _T("location")) == 0) {
        d_location = _ttoi(value);

      } else {
        LogStartUp(_T("Invalid key/value pair %s=%s at %i"), key, value, line);
      }
    } else  {
      LogStartUp(_T("Invalid line at %i"), line);
    }

  } // end while
}
示例#17
0
void
ParseInputFile(InputConfig &config, TLineReader &reader)
{
  // TODO code - Safer sizes, strings etc - use C++ (can scanf restrict length?)

  // Multiple modes (so large string)
  EventBuilder current;
  current.clear();

  int line = 0;

  // Read from the file
  TCHAR *buffer;
  while ((buffer = reader.ReadLine()) != NULL) {
    TrimRight(buffer);
    line++;

    const TCHAR *key, *value;

    // experimental: if the first line is "#CLEAR" then the whole default config is cleared
    //               and can be overwritten by file
    if (line == 1 && StringIsEqual(buffer, _T("#CLEAR"))) {
      config.SetDefaults();
    } else if (buffer[0] == _T('\0')) {
      // Check valid line? If not valid, assume next record (primative, but works ok!)
      // General checks before continue...
      current.commit(config, line);

      // Clear all data.
      current.clear();

    } else if (StringIsEmpty(buffer) || buffer[0] == _T('#')) {
      // Do nothing - we probably just have a comment line
      // NOTE: Do NOT display buffer to user as it may contain an invalid stirng !

    } else if (parse_assignment(buffer, key, value)) {
      if (StringIsEqual(key, _T("mode"))) {
        current.mode = value;
      } else if (StringIsEqual(key, _T("type"))) {
        current.type = value;
      } else if (StringIsEqual(key, _T("data"))) {
        current.data = value;
      } else if (StringIsEqual(key, _T("event"))) {
        if (_tcslen(value) < 256) {
          TCHAR d_event[256] = _T("");
          TCHAR d_misc[256] = _T("");
          int ef;

          #if defined(__BORLANDC__)
          memset(d_event, 0, sizeof(d_event));
          memset(d_misc, 0, sizeof(d_event));
          if (_tcschr(value, ' ') == NULL) {
            _tcscpy(d_event, value);
          } else {
          #endif

          ef = _stscanf(value, _T("%[^ ] %[A-Za-z0-9 \\/().,]"), d_event,
              d_misc);

          #if defined(__BORLANDC__)
          }
          #endif

          if ((ef == 1) || (ef == 2)) {

            // TODO code: Consider reusing existing identical events

            pt2Event event = InputEvents::findEvent(d_event);
            if (event) {
              TCHAR *allocated = UnescapeBackslash(d_misc);
              current.event_id = config.AppendEvent(event, allocated,
                                                    current.event_id);

              /* not freeing the string, because
                 InputConfig::AppendEvent() stores the string point
                 without duplicating it; strictly speaking, this is a
                 memory leak, but the input file is only loaded once
                 at startup, so this is acceptable; in return, we
                 don't have to duplicate the hard-coded defaults,
                 which saves some memory */
              //free(allocated);

            } else {
              LogStartUp(_T("Invalid event type: %s at %i"), d_event, line);
            }
          } else {
            LogFormat("Invalid event type at %i", line);
          }
        }
      } else if (StringIsEqual(key, _T("label"))) {
        current.label = value;
      } else if (StringIsEqual(key, _T("location"))) {
        current.location = ParseUnsigned(value);

      } else {
        LogStartUp(_T("Invalid key/value pair %s=%s at %i"), key, value, line);
      }
    } else  {
      LogFormat("Invalid line at %i", line);
    }

  }

  current.commit(config, line);
}
示例#18
0
void handle_rr(struct session_info *s, struct gsm48_hdr *dtap, unsigned len, uint32_t fn)
{
	struct gsm48_system_information_type_6 *si6;
	struct tlv_parsed tp;

	s->rat = RAT_GSM;
	assert(s->new_msg);

	if (!len) {
		return;
	}

	switch (dtap->msg_type) {
	case GSM48_MT_RR_SYSINFO_1:
		SET_MSG_INFO(s, "SYSTEM INFO 1");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_2:
		SET_MSG_INFO(s, "SYSTEM INFO 2");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_2bis:
		SET_MSG_INFO(s, "SYSTEM INFO 2bis");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_2ter:
		SET_MSG_INFO(s, "SYSTEM INFO 2ter");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_2quater:
		SET_MSG_INFO(s, "SYSTEM INFO 2quater");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_3:
		SET_MSG_INFO(s, "SYSTEM INFO 3");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_4:
		SET_MSG_INFO(s, "SYSTEM INFO 4");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_5:
		SET_MSG_INFO(s, "SYSTEM INFO 5");
		rand_check((uint8_t *)dtap, 18, &s->si5, s->cipher);
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_5bis:
		SET_MSG_INFO(s, "SYSTEM INFO 5bis");
		rand_check((uint8_t *)dtap, 18, &s->si5bis, s->cipher);
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_5ter:
		SET_MSG_INFO(s, "SYSTEM INFO 5ter");
		rand_check((uint8_t *)dtap, 18, &s->si5ter, s->cipher);
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_6:
		SET_MSG_INFO(s, "SYSTEM INFO 6");
		rand_check((uint8_t *)dtap, 18, &s->si6, s->cipher);
		si6 = (struct gsm48_system_information_type_6 *) dtap;
		handle_lai(s, (uint8_t*)&si6->lai, htons(si6->cell_identity));
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_SYSINFO_13:
		SET_MSG_INFO(s, "SYSTEM INFO 13");
		handle_sysinfo(s, dtap, len);
		break;
	case GSM48_MT_RR_CHAN_REL:
		SET_MSG_INFO(s, "CHANNEL RELEASE");
		if (s->cipher && !s->fc.enc_rand)
			s->fc.predict++;

		s->release = 1;
		s->rr_cause = dtap->data[0];
		if ((len > 3) && ((dtap->data[1] & 0xf0) == 0xc0))
			s->have_gprs = 1;

		session_reset(&s[0], 0);
		if (auto_reset) {
			s[1].new_msg = NULL;
		}
		break;
	case GSM48_MT_RR_CLSM_ENQ:
		SET_MSG_INFO(s, "CLASSMARK ENQUIRY");
		break;
	case GSM48_MT_RR_MEAS_REP:
		SET_MSG_INFO(s, "MEASUREMENT REPORT");
		break;
	case GSM48_MT_RR_CLSM_CHG:
		SET_MSG_INFO(s, "CLASSMARK CHANGE");
		handle_classmark(s, &dtap->data[1], 2);
		break;
	case GSM48_MT_RR_PAG_REQ_1:
		SET_MSG_INFO(s, "PAGING REQ 1");
		handle_paging1(dtap, len);
		break;
	case GSM48_MT_RR_PAG_REQ_2:
		SET_MSG_INFO(s, "PAGING REQ 2");
		handle_paging2(dtap, len);
		break;
	case GSM48_MT_RR_PAG_REQ_3:
		SET_MSG_INFO(s, "PAGING REQ 3");
		handle_paging3();
		break;
	case GSM48_MT_RR_IMM_ASS:
		SET_MSG_INFO(s, "IMM ASSIGNMENT");
		break;
	case GSM48_MT_RR_IMM_ASS_EXT:
		SET_MSG_INFO(s, "IMM ASSIGNMENT EXT");
		break;
	case GSM48_MT_RR_IMM_ASS_REJ:
		SET_MSG_INFO(s, "IMM ASSIGNMENT REJECT");
		break;
	case GSM48_MT_RR_PAG_RESP:
		session_reset(s, 1);
		SET_MSG_INFO(s, "PAGING RESPONSE");
		handle_pag_resp(s, dtap->data);
		break;
	case GSM48_MT_RR_HANDO_CMD:
		SET_MSG_INFO(s, "HANDOVER COMMAND");
		parse_assignment(dtap, len, s->cell_arfcns, &s->ga);
		s->handover = 1;
		s->use_jump = 2;
		break;
	case GSM48_MT_RR_HANDO_COMPL:
		SET_MSG_INFO(s, "HANDOVER COMPLETE");
		break;
	case GSM48_MT_RR_ASS_CMD:
		SET_MSG_INFO(s, "ASSIGNMENT COMMAND");
		if ((s->fc.enc-s->fc.enc_null-s->fc.enc_si) == 1)
			s->forced_ho = 1;
		parse_assignment(dtap, len, s->cell_arfcns, &s->ga);
		s->assignment = 1;
		s->use_jump = 1;
		break;
	case GSM48_MT_RR_ASS_COMPL:
		SET_MSG_INFO(s, "ASSIGNMENT COMPLETE");
		s->assign_complete = 1;
		break;
	case GSM48_MT_RR_CIPH_M_COMPL:
		SET_MSG_INFO(s, "CIPHER MODE COMPLETE");
		if (s->cipher_missing < 0) {
			s->cipher_missing = 0;
		} else {
			s->cipher_missing = 1;
		}

		if (!s->cm_comp_first_fn) {
			if (fn) {
				s->cm_comp_first_fn = fn;
			} else {
				s->cm_comp_first_fn = GSM_MAX_FN;
			}
		}

		if (fn) {
			s->cm_comp_last_fn = fn;
		} else {
			s->cm_comp_last_fn = GSM_MAX_FN;
		}

		s->cm_comp_count++;

		if (dtap->data[0] == 0x2b)
			return;

		/* get IMEISV */
		tlv_parse(&tp, &gsm48_rr_att_tlvdef, dtap->data, len-2, 0, 0);
		if (TLVP_PRESENT(&tp, GSM48_IE_MOBILE_ID)) {
			uint8_t *v = (uint8_t *) TLVP_VAL(&tp, GSM48_IE_MOBILE_ID);
			handle_mi(s, &v[1], v[0], 0);
			s->cmc_imeisv = 1;
		}
		break;
	case GSM48_MT_RR_GPRS_SUSP_REQ:
		SET_MSG_INFO(s, "GPRS SUSPEND");
		s->have_gprs = 1;
		//tlli
		//rai (lai+rac)
		break;
	case GSM48_MT_RR_CIPH_M_CMD:
		if (!s->cm_cmd_fn) {
			if (fn) {
				s->cm_cmd_fn = fn;
			} else {
				s->cm_cmd_fn = GSM_MAX_FN;
			}
		}

		if (dtap->data[0] & 1) {
			s->cipher = 1 + ((dtap->data[0]>>1) & 7);
			if (!not_zero(s->key, 8))
				s->decoded = 0;
		}
		SET_MSG_INFO(s, "CIPHER MODE COMMAND, A5/%u", s->cipher);
		if (dtap->data[0] & 0x10) {
			s->cmc_imeisv = 1;

			if (s->cipher && !s->fc.enc_rand)
				s->fc.predict++;
		}
		s->cipher_missing = -1;
		break;
	case 0x60:
		SET_MSG_INFO(s, "UTRAN CLASSMARK");
		break;
	default:
		SET_MSG_INFO(s, "UNKNOWN RR (%02x)", dtap->msg_type);
		s->unknown = 1;
	}
示例#19
0
文件: parser.c 项目: Saruta/a2c
struct instruction *parse_assignment_instr(struct expr *lhs)
{
  struct assignment *a = parse_assignment(lhs);
  eat(EOL);
  return assigninstr(a);
}