Add bjdwp tool to Barry project.
[barry/progweb.git] / bjdwp / utils / parser.h
blob2b9c54fcef9e1dfe39a0936644f6714c77d8dc6f
1 /**
2 * @file parser.h
3 * @author Nicolas VIVIEN
4 * @date 2009-08-01
6 * @note CopyRight Nicolas VIVIEN
8 * @brief COD debug file parser
10 * @par Modifications
11 * - 2009/08/01 : N. VIVIEN
12 * - First release
14 * @par Licences
15 * Copyright (C) 2009-2010, Nicolas VIVIEN
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 * See the GNU General Public License in the COPYING file at the
27 * root directory of this project for more details.
31 #ifndef __BARRYJDG_PARSER_H__
32 #define __BARRYJDG_PARSER_H__
34 #include <string>
35 #include <stdint.h>
38 namespace Barry {
40 namespace JDG {
42 // The following is a byteswap.h replacement, for systems like Mac OS X.
43 // It was taken from a patch to the GPL software cowpatty, patch
44 // by user gm2net.
45 // http://www.netstumbler.org/showpost.php?s=79764fd1526e4653d5cb4432225da6ee&p=190494&postcount=29
47 //#warning "byteswap.h is an unportable GNU extension! Don't use!"
49 static inline unsigned short bswap_16(unsigned short x) {
50 return (x>>8) | (x<<8);
53 static inline unsigned int bswap_32(unsigned int x) {
54 return (bswap_16(x&0xffff)<<16) | (bswap_16(x>>16));
57 static inline uint64_t bswap_64(uint64_t x) {
58 return (((uint64_t)bswap_32(x&0xffffffffull))<<32) | (bswap_32(x>>32));
61 #ifndef WORDS_BIGENDIAN
63 // For when Blackberry needs big endian (often in JavaLoader protocol)
64 #define be_btohs(x) bswap_16(x) // for uint16_t
65 #define be_btohl(x) bswap_32(x) // for uint32_t
66 #define be_btohll(x) bswap_64(x) // for uint64_t
67 #define be_htobs(x) bswap_16(x) // for uint16_t
68 #define be_htobl(x) bswap_32(x) // for uint32_t
69 #define be_htobll(x) bswap_64(x) // for uint64_t
71 #else
73 // For when Blackberry needs big endian (often in JavaLoader protocol)
74 #define be_btohs(x) x // for uint16_t
75 #define be_btohl(x) x // for uint32_t
76 #define be_btohll(x) x // for uint64_t
77 #define be_htobs(x) x // for uint16_t
78 #define be_htobl(x) x // for uint32_t
79 #define be_htobll(x) x // for uint64_t
81 #endif
84 std::string ParseString(std::istream &input, const int length);
85 uint32_t ParseInteger(std::istream &input);
87 } // namespace JDG
89 } // namespace Barry
91 #endif