File: debug.cpp

package info (click to toggle)
bcpp 0.0.20210108-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 952 kB
  • sloc: cpp: 4,955; sh: 3,262; makefile: 237
file content (113 lines) | stat: -rw-r--r-- 4,107 bytes parent folder | download | duplicates (4)
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
//******************************************************************************
// Copyright 1996-2005,2009 by Thomas E. Dickey                                *
// All Rights Reserved.                                                        *
//                                                                             *
// Permission to use, copy, modify, and distribute this software and its       *
// documentation for any purpose and without fee is hereby granted, provided   *
// that the above copyright notice appear in all copies and that both that     *
// copyright notice and this permission notice appear in supporting            *
// documentation, and that the name of the above listed copyright holder(s)    *
// not be used in advertising or publicity pertaining to distribution of the   *
// software without specific, written prior permission. THE ABOVE LISTED       *
// COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,   *
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO      *
// EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY SPECIAL, *
// INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM  *
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE  *
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR   *
// PERFORMANCE OF THIS SOFTWARE.                                               *
//******************************************************************************
// $Id: debug.cpp,v 1.18 2009/06/28 12:50:50 tom Exp $
// Debug/trace functions for BCPP

#include <stdlib.h>
#include <stdarg.h>

#include "bcpp.h"

void trace(const char *format, ...)
{
    va_list ap;
    va_start(ap, format);
    vfprintf(stderr, format, ap);
    va_end(ap);
}

#if defined(DEBUG) || defined(DEBUG2)
static const char *traceDataType(DataTypes theType)
{
    const char *it;
    switch (theType)
    {
        case CCom:   it = "CCom";   break;
        case CppCom: it = "CppCom"; break;
        case Code:   it = "Code";   break;
        case OBrace: it = "OBrace"; break;
        case CBrace: it = "CBrace"; break;
        case PreP:   it = "PreP";   break;
        default:
        case ELine:  it = "ELine";  break;
    }
    return it;
}

static const char *traceIndentAttr(IndentAttr theType)
{
    const char *it;
    switch (theType)
    {
        case oneLine:   it = "oneLine";   break;
        case multiLine: it = "multiLine"; break;
        case blockLine: it = "blockLine"; break;
        default:        it = "noIndent";  break;
    }
    return it;
}

void traceInput(const char *file, int line, InputStruct *pIn)
{
    if (pIn != 0)
    {
        TRACE(("%s@%d, %s%s (col:%d)\n",
            file, line,
            traceDataType(pIn->dataType),
            pIn->comWcode ? " comWcode" : "",
            pIn->offset));
        if (pIn->pData  != 0) TRACE(("---- data:%s\n", pIn->pData));
        if (pIn->pState != 0) TRACE(("---- flag:%s\n", pIn->pState));
    }
}

void traceIndent(const char *file, int line, IndentStruct *pIn)
{
    if (pIn != 0)
    {
        TRACE(("%s@%d, Indent %s (pos:%d)\n",
            file, line,
            traceIndentAttr(pIn->attrib),
            pIn->pos));
    }
}

void traceOutput(const char *file, int line, OutputStruct *pOut)
{
    if (pOut != 0)
    {
        TRACE(("%s@%d, indent %d(%d:%d), fill %d, OUT #%d:%s:%s:%s:\n",
            file, line,
            pOut->bracesLevel,
            pOut->indentSpace,
            pOut->indentHangs,
            pOut->filler,
            pOut->thisToken,
            pOut->pCode ? "code" : "",
            pOut->pBrace ? "brace" : "",
            pOut->pComment ? "comment" : ""));
        if (pOut->pCode)    TRACE(("----- code:%s\n", pOut->pCode));
        if (pOut->pCFlag)   TRACE(("---- state:%s\n", pOut->pCFlag));
        if (pOut->pBrace)   TRACE(("---- brace:%s\n", pOut->pBrace));
        if (pOut->pBFlag)   TRACE(("---- state:%s\n", pOut->pBFlag));
        if (pOut->pComment) TRACE(("-- comment:%s\n", pOut->pComment));
    }
}
#endif