File: vrscan.cc

package info (click to toggle)
dcmtk 3.6.9-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,648 kB
  • sloc: ansic: 426,874; cpp: 318,177; makefile: 6,401; sh: 4,341; yacc: 1,026; xml: 482; lex: 321; perl: 277
file content (86 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download | duplicates (3)
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
/*
 *
 *  Copyright (C) 2010-2021, OFFIS e.V.
 *  All rights reserved.  See COPYRIGHT file for details.
 *
 *  This software and supporting documentation were developed by
 *
 *    OFFIS e.V.
 *    R&D Division Health
 *    Escherweg 2
 *    D-26121 Oldenburg, Germany
 *
 *
 *  Module:  dcmdata
 *
 *  Author:  Uli Schlachter
 *
 *  Purpose: Interface to the VR scanner.
 *
 */


#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#include "dcmtk/dcmdata/vrscan.h"
#include "dcmtk/ofstd/ofbmanip.h"
#include "dcmtk/ofstd/ofstd.h"        /* For OFString::strerror() */
#include "dcmtk/dcmdata/dctypes.h"    /* For DCMDATA_WARN() */
#include "dcmtk/ofstd/ofdiag.h"

BEGIN_EXTERN_C
#include "vrscani.h"
#include "vrscanl.h"
END_EXTERN_C

#include DCMTK_DIAGNOSTIC_PUSH
#include DCMTK_DIAGNOSTIC_IGNORE_VISUAL_STUDIO_OBJECT_DESTRUCTION_WARNING

int vrscan::scan(const OFString& vr, const char* const value, const size_t size)
{
    yyscan_t scanner;
    if (yylex_init(&scanner))
    {
        DCMDATA_WARN("Error while setting up lexer: "
                << OFStandard::getLastSystemErrorCode().message());
        return 16 /* UNKNOWN */;
    }

    struct cleanup_t
    {
        cleanup_t(yyscan_t& y) : t(y) {}
        ~cleanup_t() { yylex_destroy(t); }
        yyscan_t& t;
    }
    cleanup(scanner);

    OFString buffer;
    buffer.reserve(vr.size() + size + 2);
    buffer.append(vr);
    buffer.append(value, size);
    buffer.append("\0\0", 2); // yy_scan_buffer() requires this

    struct vrscan_error error;
    error.error_msg = "(Unknown error)";
    yyset_extra(&error, scanner);

    if (setjmp(error.setjmp_buffer)) // poor man's catch()
    {
        DCMDATA_WARN("Fatal error in lexer: " << error.error_msg);
        return 16 /* UNKNOWN */;
    }

    yy_scan_buffer(OFconst_cast(char*, buffer.data()), buffer.size(), scanner);
    const int result = yylex(scanner);
    if (yylex(scanner))
        return 16 /* UNKNOWN */;

    return result;
}

#include DCMTK_DIAGNOSTIC_POP

int vrscan::scan(const OFString& vr, const OFString& value)
{
    return scan(vr, value.data(), value.size());
}