read: Add function to initialize common parts of input/source files and use it
Also correct input/source file usage in the file and initialize everything like in universal-ctags.
This commit is contained in:
parent
aafb127024
commit
f89e9f8014
@ -146,7 +146,7 @@ extern MIOPos getInputFilePositionForLine (int line)
|
|||||||
|
|
||||||
extern langType getInputLanguage (void)
|
extern langType getInputLanguage (void)
|
||||||
{
|
{
|
||||||
return File.source.language;
|
return File.input.language;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char *getInputLanguageName (void)
|
extern const char *getInputLanguageName (void)
|
||||||
@ -156,7 +156,7 @@ extern const char *getInputLanguageName (void)
|
|||||||
|
|
||||||
extern const char *getInputFileTagPath (void)
|
extern const char *getInputFileTagPath (void)
|
||||||
{
|
{
|
||||||
return vStringValue (File.source.tagPath);
|
return vStringValue (File.input.tagPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool isInputLanguage (langType lang)
|
extern bool isInputLanguage (langType lang)
|
||||||
@ -183,7 +183,7 @@ extern bool doesInputLanguageAllowNullTag (void)
|
|||||||
|
|
||||||
extern kindOption *getInputLanguageFileKind (void)
|
extern kindOption *getInputLanguageFileKind (void)
|
||||||
{
|
{
|
||||||
return getLanguageFileKind (File.input.language);
|
return getLanguageFileKind (getInputLanguage ());
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool doesInputLanguageRequestAutomaticFQTag (void)
|
extern bool doesInputLanguageRequestAutomaticFQTag (void)
|
||||||
@ -207,27 +207,39 @@ extern unsigned long getSourceLineNumber (void)
|
|||||||
return File.source.lineNumber;
|
return File.source.lineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void freeInputFileInfo (inputFileInfo *finfo)
|
||||||
|
{
|
||||||
|
if (finfo->name)
|
||||||
|
{
|
||||||
|
vStringDelete (finfo->name);
|
||||||
|
finfo->name = NULL;
|
||||||
|
}
|
||||||
|
if (finfo->tagPath)
|
||||||
|
{
|
||||||
|
vStringDelete (finfo->tagPath);
|
||||||
|
finfo->tagPath = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern void freeInputFileResources (void)
|
extern void freeInputFileResources (void)
|
||||||
{
|
{
|
||||||
vStringDelete (File.input.name);
|
if (File.path != NULL)
|
||||||
vStringDelete (File.path);
|
vStringDelete (File.path);
|
||||||
vStringDelete (File.source.name);
|
if (File.line != NULL)
|
||||||
vStringDelete (File.line);
|
vStringDelete (File.line);
|
||||||
|
freeInputFileInfo (&File.input);
|
||||||
|
freeInputFileInfo (&File.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input file access functions
|
* Input file access functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void setInputFileName (const char *const fileName)
|
static void setOwnerDirectoryOfInputFile (const char *const fileName)
|
||||||
{
|
{
|
||||||
const char *const head = fileName;
|
const char *const head = fileName;
|
||||||
const char *const tail = baseFilename (head);
|
const char *const tail = baseFilename (head);
|
||||||
|
|
||||||
if (File.input.name != NULL)
|
|
||||||
vStringDelete (File.input.name);
|
|
||||||
File.input.name = vStringNewInit (fileName);
|
|
||||||
|
|
||||||
if (File.path != NULL)
|
if (File.path != NULL)
|
||||||
vStringDelete (File.path);
|
vStringDelete (File.path);
|
||||||
if (tail == head)
|
if (tail == head)
|
||||||
@ -239,34 +251,49 @@ static void setInputFileName (const char *const fileName)
|
|||||||
vStringNCopyS (File.path, fileName, length);
|
vStringNCopyS (File.path, fileName, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void setSourceFileParameters (vString *const fileName, const langType language)
|
|
||||||
{
|
|
||||||
if (File.source.name != NULL)
|
|
||||||
vStringDelete (File.source.name);
|
|
||||||
if (File.input.name != NULL)
|
|
||||||
vStringDelete (File.input.name);
|
|
||||||
File.source.name = fileName;
|
|
||||||
File.input.name = vStringNewCopy(fileName);
|
|
||||||
|
|
||||||
if (File.source.tagPath != NULL)
|
static void setInputFileParametersCommon (inputFileInfo *finfo, vString *const fileName,
|
||||||
eFree (File.source.tagPath);
|
const langType language,
|
||||||
if (! Option.tagRelative || isAbsolutePath (vStringValue (fileName)))
|
stringList *holder)
|
||||||
File.source.tagPath = vStringNewCopy (fileName);
|
{
|
||||||
|
if (finfo->name != NULL)
|
||||||
|
vStringDelete (finfo->name);
|
||||||
|
finfo->name = fileName;
|
||||||
|
|
||||||
|
if (finfo->tagPath != NULL)
|
||||||
|
{
|
||||||
|
if (holder)
|
||||||
|
stringListAdd (holder, finfo->tagPath);
|
||||||
else
|
else
|
||||||
File.source.tagPath =
|
vStringDelete (finfo->tagPath);
|
||||||
|
}
|
||||||
|
if (! Option.tagRelative || isAbsolutePath (vStringValue (fileName)))
|
||||||
|
finfo->tagPath = vStringNewCopy (fileName);
|
||||||
|
else
|
||||||
|
finfo->tagPath =
|
||||||
vStringNewOwn (relativeFilename (vStringValue (fileName),
|
vStringNewOwn (relativeFilename (vStringValue (fileName),
|
||||||
getTagFileDirectory ()));
|
getTagFileDirectory ()));
|
||||||
|
|
||||||
if (vStringLength (fileName) > maxTagsLine ())
|
finfo->isHeader = isIncludeFile (vStringValue (fileName));
|
||||||
setMaxTagsLine (vStringLength (fileName));
|
|
||||||
|
|
||||||
File.source.isHeader = isIncludeFile (vStringValue (fileName));
|
|
||||||
File.input.isHeader = File.source.isHeader;
|
|
||||||
if (language != -1)
|
if (language != -1)
|
||||||
File.source.language = language;
|
finfo->language = language;
|
||||||
else
|
else
|
||||||
File.source.language = getFileLanguage (vStringValue (fileName));
|
finfo->language = getFileLanguage (vStringValue (fileName));
|
||||||
File.input.language = File.source.language;
|
}
|
||||||
|
|
||||||
|
static void setInputFileParameters (vString *const fileName, const langType language)
|
||||||
|
{
|
||||||
|
setInputFileParametersCommon (&File.input, fileName,
|
||||||
|
language,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setSourceFileParameters (vString *const fileName, const langType language)
|
||||||
|
{
|
||||||
|
setInputFileParametersCommon (&File.source, fileName,
|
||||||
|
language,
|
||||||
|
File.sourceTagPathHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool setSourceFileName (vString *const fileName)
|
static bool setSourceFileName (vString *const fileName)
|
||||||
@ -284,7 +311,7 @@ static bool setSourceFileName (vString *const fileName)
|
|||||||
vStringValue (File.path), vStringValue (fileName));
|
vStringValue (File.path), vStringValue (fileName));
|
||||||
pathName = vStringNewOwn (tmp);
|
pathName = vStringNewOwn (tmp);
|
||||||
}
|
}
|
||||||
setSourceFileParameters (pathName, -1);
|
setSourceFileParameters (pathName, language);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -461,21 +488,24 @@ extern bool openInputFile (const char *const fileName, const langType language,
|
|||||||
{
|
{
|
||||||
opened = true;
|
opened = true;
|
||||||
|
|
||||||
setInputFileName (fileName);
|
setOwnerDirectoryOfInputFile (fileName);
|
||||||
mio_getpos (File.mio, &StartOfLine);
|
mio_getpos (File.mio, &StartOfLine);
|
||||||
mio_getpos (File.mio, &File.filePosition);
|
mio_getpos (File.mio, &File.filePosition);
|
||||||
File.currentLine = NULL;
|
File.currentLine = NULL;
|
||||||
File.input.lineNumber = 0L;
|
|
||||||
|
|
||||||
if (File.line != NULL)
|
if (File.line != NULL)
|
||||||
vStringClear (File.line);
|
vStringClear (File.line);
|
||||||
|
|
||||||
|
setInputFileParameters (vStringNewInit (fileName), language);
|
||||||
|
File.input.lineNumberOrigin = 0L;
|
||||||
|
File.input.lineNumber = File.input.lineNumberOrigin;
|
||||||
setSourceFileParameters (vStringNewInit (fileName), language);
|
setSourceFileParameters (vStringNewInit (fileName), language);
|
||||||
File.source.lineNumber = 0L;
|
File.source.lineNumberOrigin = 0L;
|
||||||
|
File.source.lineNumber = File.source.lineNumberOrigin;
|
||||||
|
|
||||||
verbose ("OPENING %s as %s language %sfile\n", fileName,
|
verbose ("OPENING %s as %s language %sfile\n", fileName,
|
||||||
getLanguageName (language),
|
getLanguageName (language),
|
||||||
File.source.isHeader ? "include " : "");
|
File.input.isHeader ? "include " : "");
|
||||||
}
|
}
|
||||||
return opened;
|
return opened;
|
||||||
}
|
}
|
||||||
@ -508,7 +538,6 @@ extern void closeInputFile (void)
|
|||||||
fileStatus *status = eStat (vStringValue (File.input.name));
|
fileStatus *status = eStat (vStringValue (File.input.name));
|
||||||
addTotals (0, File.input.lineNumber - 1L, status->size);
|
addTotals (0, File.input.lineNumber - 1L, status->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
mio_free (File.mio);
|
mio_free (File.mio);
|
||||||
File.mio = NULL;
|
File.mio = NULL;
|
||||||
}
|
}
|
||||||
@ -584,7 +613,7 @@ static vString *iFileGetLine (void)
|
|||||||
|
|
||||||
if (Option.lineDirectives && vStringChar (File.line, 0) == '#')
|
if (Option.lineDirectives && vStringChar (File.line, 0) == '#')
|
||||||
parseLineDirective (vStringValue (File.line) + 1);
|
parseLineDirective (vStringValue (File.line) + 1);
|
||||||
matchRegex (File.line, File.source.language);
|
matchRegex (File.line, getInputLanguage ());
|
||||||
|
|
||||||
return File.line;
|
return File.line;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user