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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/*
* Copyright (c) 1996-2003, Darren Hiebert
*
* This source code is released into the public domain.
*
* This module contains functions for reading tag files.
*/
/*
* INCLUDE FILES
*/
#include "printtags.h"
#include <stdio.h>
/*
* DATA DEFINITIONS
*/
static tagPrintProcs printFILEProcs = {
.printStr = (int (*) (const char *, void *))fputs,
.printChar = (int (*) (int, void *))fputc,
};
/*
* FUNCTION DEFINITIONS
*/
static void ultostr (char dst [21], unsigned long d)
{
int o [20];
int i;
if (d == 0)
{
dst [0] = '0';
dst [1] = '\0';
return;
}
for (i = 0; d != 0; i++, d = d/10)
o [i] = d % 10;
for (int j = i - 1; j >= 0; j--)
dst [i - j - 1] = o[j] + '0';
dst [i] = '\0';
}
static void printValue (const char *val, int printingWithEscaping,
int (* print_str) (const char *, void *),
int (* print_char) (int, void *),
void *outfp)
{
if (printingWithEscaping)
{
for(; *val != '\0'; val++)
{
switch (*val)
{
case '\t': print_str ("\\t", outfp); break;
case '\r': print_str ("\\r", outfp); break;
case '\n': print_str ("\\n", outfp); break;
case '\\': print_str ("\\\\", outfp); break;
/* Universal-CTags extensions */
case '\a': print_str ("\\a", outfp); break;
case '\b': print_str ("\\b", outfp); break;
case '\v': print_str ("\\v", outfp); break;
case '\f': print_str ("\\f", outfp); break;
default:
if ((0x01 <= *val && *val <= 0x1F) || *val == 0x7F)
{
char c[5] = {
[0] = '\\',
[1] = 'x',
};
c [2] = (*val / 16) % 16;
#if 0
if (c [2] == 0)
{
c [2] = *val % 16;
c [2] += ( c [2] < 10 )? '0': 'A' - 9;
c [3] = '\0';
}
else
#endif
{
c [2] += ( c [2] < 10 )? '0': 'A' - 9;
c [3] = *val % 16;
c [3] += ( c [3] < 10 )? '0': 'A' - 9;
c [4] = '\0';
}
print_str (c, outfp);
}
else
print_char (*val, outfp);
}
}
}
else
print_str (val, outfp);
}
static void tagsPrintTag (const tagEntry *entry,
int printingExtensionFields,
int printingLineNumber,
int printingWithEscaping,
int pseudoTag,
int (* print_str) (const char *, void *),
int (* print_char) (int, void *),
void *outfp)
{
int i;
int first = 1;
const char* separator = ";\"";
const char* const empty = "";
/* "sep" returns a value only the first time it is evaluated */
#define sep (first ? (first = 0, separator) : empty)
if (entry->name == NULL
|| entry->file == NULL
|| entry->address.pattern == NULL)
return;
if (pseudoTag)
printValue (entry->name, printingWithEscaping,
print_str, print_char, outfp);
else if (*entry->name == '!' && printingWithEscaping)
{
print_str ("\\x21", outfp);
printValue (entry->name + 1, printingWithEscaping,
print_str, print_char, outfp);
}
else if (*entry->name == ' ' && printingWithEscaping)
{
print_str ("\\x20", outfp);
printValue (entry->name + 1, printingWithEscaping,
print_str, print_char, outfp);
}
else
printValue (entry->name, printingWithEscaping,
print_str, print_char, outfp);
print_char ('\t', outfp);
print_str (entry->file, outfp);
print_char ('\t', outfp);
print_str (entry->address.pattern, outfp);
if (printingExtensionFields)
{
if (entry->kind != NULL && entry->kind [0] != '\0')
{
print_str (sep, outfp);
print_str ("\tkind:", outfp);
printValue (entry->kind, printingWithEscaping,
print_str, print_char, outfp);
first = 0;
}
if (entry->fileScope)
{
print_str (sep, outfp);
print_str ("\tfile:", outfp);
first = 0;
}
if (printingLineNumber && entry->address.lineNumber > 0)
{
print_str (sep, outfp);
print_str ("\tline:", outfp);
char buf [20 + 1]; /* 20 comes from UINNT64_MAX, 1 is for \0. */
ultostr (buf, entry->address.lineNumber);
print_str (buf, outfp);
first = 0;
}
for (i = 0 ; i < entry->fields.count ; ++i)
{
if (entry->fields.list [i].key)
{
print_str (sep, outfp);
print_char ('\t', outfp);
print_str (entry->fields.list [i].key, outfp);
print_char (':', outfp);
if (entry->fields.list [i].value)
printValue (entry->fields.list [i].value,
printingWithEscaping, print_str, print_char, outfp);
first = 0;
}
}
}
print_char ('\n', outfp);
#undef sep
}
extern int tagsPrint (const tagEntry *entry,
tagPrintOptions *opt, tagPrintProcs *procs, void *outfp)
{
if (!procs)
procs = &printFILEProcs;
tagsPrintTag (entry,
opt->extensionFields,
opt->lineNumber,
opt->escaping,
0,
procs->printStr,
procs->printChar,
outfp);
return 1; /* TODO */
}
extern int tagsPrintPseudoTag (const tagEntry *entry,
tagPrintOptions *opt, tagPrintProcs *procs, void *outfp)
{
if (!procs)
procs = &printFILEProcs;
tagsPrintTag (entry,
opt->extensionFields,
opt->lineNumber,
opt->escaping,
1,
procs->printStr,
procs->printChar,
outfp);
return 1; /* TODO */
}
|