bjdwp: moved ".debug" parser library sources into main library
[barry.git] / src / dp_parser.cc
blobb1bda95f63831594a0d34add055f6be1d2918e32
1 /**
2 * @file parser.cc
3 * @author Nicolas VIVIEN
4 * @date 2009-08-01
6 * @note CopyRight Nicolas VIVIEN
8 * @brief COD debug file parser
9 * RIM's JDE generates several files when you build a COD application.
10 * Indeed, with the COD files for the device, we have a ".debug" file.
11 * This file is usefull to debug an application from JVM.
12 * This tool is a parser to understand these ".debug" files.
13 * Obviously, the file contents only some strings and 32 bits words.
15 * @par Modifications
16 * - 2009/08/01 : N. VIVIEN
17 * - First release
19 * @par Licences
20 * Copyright (C) 2009-2010, Nicolas VIVIEN
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31 * See the GNU General Public License in the COPYING file at the
32 * root directory of this project for more details.
37 #include <iostream>
39 #include <stdlib.h>
41 #include "parser.h"
44 using namespace std;
47 namespace Barry {
49 namespace JDG {
52 string ParseString(istream &input, const int length)
54 int i;
55 char *s;
56 string str;
58 s = (char *) malloc((length + 1) * sizeof(char));
60 for (i=0; i<length; i++) {
61 uint16_t value;
63 input.read((char *) &value, sizeof(uint16_t));
65 s[i] = (char) be_btohs(value);
68 s[i] = '\0';
70 str = string(s);
72 free(s);
74 return str;
78 uint32_t ParseInteger(istream &input)
80 uint32_t value;
82 input.read((char *) &value, sizeof(uint32_t));
84 return be_btohl(value);
88 } // namespace JDG
90 } // namespace Barry