Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libvcodex/Vcwindow/vcwdecode.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Phong Vo <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "vcwhdr.h"
21
22
/* Method to get a matching window while decoding.
23
** In this case, data must be VCD_SOURCEFILE or VCD_TARGETFILE.
24
**
25
** Written by Kiem-Phong Vo ([email protected])
26
*/
27
28
#if __STD_C
29
static Vcwmatch_t* decode(Vcwindow_t* vcw, Void_t* data, size_t size, Sfoff_t here)
30
#else
31
static Vcwmatch_t* decode(vcw, data, size, here)
32
Vcwindow_t* vcw; /* signature structure */
33
Void_t* data; /* target data to be matched */
34
size_t size; /* data size */
35
Sfoff_t here; /* current target position */
36
#endif
37
{
38
Sfio_t *sf;
39
40
if(!vcw || !vcw->disc || size <= 0 )
41
return NIL(Vcwmatch_t*);
42
43
if((vcw->match.type = TYPECAST(int,data)) == VCD_SOURCEFILE )
44
sf = vcw->disc->srcf;
45
else if(vcw->match.type == VCD_TARGETFILE)
46
sf = vcw->disc->tarf;
47
else sf = NIL(Sfio_t*);
48
49
if(!sf)
50
return NIL(Vcwmatch_t*);
51
52
if(sfseek(sf, here, SEEK_SET) != here)
53
return NIL(Vcwmatch_t*);
54
55
if(!(vcw->match.wdata = sfreserve(sf, size, 0)) || sfvalue(sf) < size )
56
return NIL(Vcwmatch_t*);
57
vcw->match.wsize = size;
58
vcw->match.wpos = here;
59
vcw->match.msize = size;
60
vcw->match.more = 0;
61
62
return &vcw->match;
63
}
64
65
static Vcwmethod_t _Vcwdecode =
66
{ decode,
67
0,
68
"decode"
69
};
70
71
Vcwmethod_t* Vcwdecode = &_Vcwdecode;
72
73