forked from aiolos/sasc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.h
117 lines (97 loc) · 3.6 KB
/
misc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Softcam plugin to VDR (C++)
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*/
#ifndef ___MISC_H
#define ___MISC_H
#include <alloca.h>
// ----------------------------------------------------------------
#define WORD(buffer,index,mask) (((buffer[(index)]<<8) + buffer[(index)+1]) & mask)
#define SCT_LEN(sct) (3+(((sct)[1]&0x0f)<<8)+(sct)[2])
#define MBC(a,b) (((a)<<8)+(b))
#define ADDC3(ab,c) ((ab)+((c)<<16))
#define MBC3(a,b,c) ADDC3(MBC((a),(b)),(c))
#define C2(x) (((x)>>8)&0xFF)
#define C3(x) (((x)>>16)&0xFF)
#define C2MASK 0xFFFF
// replacement for variable-sized arrays
#define AUTOARRAY(type,size) (type *)alloca(sizeof(type)*(size))
#define AUTOMEM(size) (unsigned char *)alloca(size)
// ----------------------------------------------------------------
const char *HexStr(char *str, const unsigned char *mem, int len);
#define KeyStr(str,key) HexStr(str,key,8)
void SetSctLen(unsigned char *data, int len);
int GetHex(const char * &line, unsigned char *store, int count, bool fixedLen=true);
int GetHexAsc(const char * &line, unsigned char *store, int count);
int GetChar(const char * &line, int *store, int count);
unsigned long long Bin2LongLong(unsigned char *mem, int len);
#define Bin2Int(mem,len) ((int)Bin2LongLong((mem),(len)))
bool CheckNull(const unsigned char *data, int len);
bool CheckFF(const unsigned char *data, int len);
unsigned char XorSum(const unsigned char *mem, int len);
unsigned int crc32_le(unsigned int crc, unsigned char const *p, int len);
char *bprintf(const char *fmt, ...) __attribute__ ((format (printf,1,2)));
// ----------------------------------------------------------------
class cLineBuff {
private:
int blockSize;
char *work;
int blen, wlen;
//
bool Check(int num);
protected:
char *Grab(void);
public:
cLineBuff(int blocksize);
~cLineBuff();
void Printf(const char *fmt, ...) __attribute__ ((format (printf,2,3)));
void Strcat(const char *str);
void Flush(void);
void Back(int n);
const char *Line(void) const { return work; }
int Length(void) const { return blen; }
};
// ----------------------------------------------------------------
class cSimpleListBase;
class cSimpleItem {
friend class cSimpleListBase;
private:
cSimpleItem *next;
public:
virtual ~cSimpleItem() {}
cSimpleItem *Next(void) const { return next; }
};
class cSimpleListBase {
protected:
cSimpleItem *first, *last;
int count;
public:
cSimpleListBase(void);
~cSimpleListBase();
void Add(cSimpleItem *Item, cSimpleItem *After=0);
void Ins(cSimpleItem *Item);
void Del(cSimpleItem *Item, bool Del=true);
void Clear(void);
int Count(void) const { return count; }
};
template<class T> class cSimpleList : public cSimpleListBase {
public:
T *First(void) const { return (T *)first; }
T *Last(void) const { return (T *)last; }
T *Next(const T *item) const { return (T *)item->cSimpleItem::Next(); }
};
#endif //___MISC_H