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
|
/*
* Copyright (c) 2009, Eric Forgeot
*
* Based on work by Jon Strait
*
* This source code is released for free distribution under the terms of the
* GNU General Public License.
*
* This module contains functions for generating tags for Txt2tags files.
*/
/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */
#include <ctype.h>
#include <string.h>
#include "parse.h"
#include "read.h"
#include "vstring.h"
/*
* DATA DEFINITIONS
*/
typedef enum {
K_SECTION = 0, K_HEADER
} Txt2tagsKind;
static kindOption Txt2tagsKinds[] = {
{ TRUE, 'm', "member", "sections" },
{ TRUE, 's', "struct", "header1"}
};
/*
* FUNCTION DEFINITIONS
*/
static void parse_title (vString* const name, const char control_char)
{
char *text = vStringValue(name);
char *p = text;
int offset_start = 0;
boolean in_or_after_title = FALSE;
while (p != NULL && *p != '\0')
{
if (*p == control_char)
{
if (in_or_after_title)
break;
else
offset_start++;
}
else
in_or_after_title = TRUE;
p++;
}
*p = '\0';
vStringCopyS(name, text + offset_start);
vStringStripLeading(name);
vStringStripTrailing(name);
}
static void makeTxt2tagsTag (const vString* const name, boolean name_before, Txt2tagsKind type)
{
tagEntryInfo e;
kindOption *kind = &Txt2tagsKinds[type];
initTagEntry (&e, vStringValue(name));
if (name_before)
e.lineNumber--; /* we want the line before the underline chars */
e.kindName = kind->name;
e.kind = kind->letter;
makeTagEntry(&e);
}
static void findTxt2tagsTags (void)
{
vString *name = vStringNew();
const unsigned char *line;
while ((line = fileReadLine()) != NULL)
{
/*int name_len = vStringLength(name);*/
/* underlines must be the same length or more */
/*if (name_len > 0 && (line[0] == '=' || line[0] == '-') && issame((const char*) line))
{
makeTxt2tagsTag(name, TRUE);
}*/
if (line[0] == '=' || line[0] == '+') {
/*vStringClear(name);*/
vStringCatS(name, (const char *) line);
vStringTerminate(name);
parse_title(name, line[0]);
makeTxt2tagsTag(name, FALSE, K_SECTION);
}
/* TODO what exactly should this match?
* K_HEADER ('struct') isn't matched in src/symbols.c */
else if (strcmp((char*)line, "°") == 0) {
/*vStringClear(name);*/
vStringCatS(name, (const char *) line);
vStringTerminate(name);
makeTxt2tagsTag(name, FALSE, K_HEADER);
}
else {
vStringClear (name);
if (! isspace(*line))
vStringCatS(name, (const char*) line);
vStringTerminate(name);
}
}
vStringDelete (name);
}
extern parserDefinition* Txt2tagsParser (void)
{
static const char *const patterns [] = { "*.t2t", NULL };
static const char *const extensions [] = { "t2t", NULL };
parserDefinition* const def = parserNew ("Txt2tags");
def->kinds = Txt2tagsKinds;
def->kindCount = KIND_COUNT (Txt2tagsKinds);
def->patterns = patterns;
def->extensions = extensions;
def->parser = findTxt2tagsTags;
return def;
}
|