Drop some more unused functions from routines.c/h

Also get the error() implementation from error.c/h (modified slightly to
make sure exit() isn't called and which doesn't call errorPrinter() as
this one should be set somewhere else in the code and it doesn't happen
now).
This commit is contained in:
Jiří Techet 2016-10-08 14:12:35 +02:00
parent d88a9dd3fc
commit 560107804c
6 changed files with 92 additions and 159 deletions

View File

@ -59,6 +59,8 @@ libctags_la_SOURCES = \
main/debug.h \
main/entry.c \
main/entry.h \
main/error.c \
main/error.h \
main/general.h \
main/keyword.c \
main/keyword.h \

59
ctags/main/error.c Normal file
View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2002-2003, Darren Hiebert
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* This module contains a lose assortment of shared functions.
*/
#include "general.h" /* must always come first */
#include <string.h>
#include <errno.h>
#include "error.h"
#include "options.h"
#define selected(var,feature) (((int)(var) & (int)(feature)) == (int)feature)
static errorPrintFunc errorPrinter;
static void *errorPrinterData;
extern void setErrorPrinter (errorPrintFunc printer, void *data)
{
errorPrinter = printer;
errorPrinterData = data;
}
extern bool stderrDefaultErrorPrinter (const errorSelection selection,
const char *const format,
va_list ap, void *data CTAGS_ATTR_UNUSED)
{
fprintf (stderr, "%s: %s", getExecutableName (),
selected (selection, WARNING) ? "Warning: " : "");
vfprintf (stderr, format, ap);
if (selected (selection, PERROR))
#ifdef HAVE_STRERROR
fprintf (stderr, " : %s", strerror (errno));
#else
perror (" ");
#endif
fputs ("\n", stderr);
return false;
}
extern void error (const errorSelection selection,
const char *const format, ...)
{
va_list ap;
bool shouldExit;
va_start (ap, format);
shouldExit = false;
va_end (ap);
if (shouldExit)
exit (1);
}

26
ctags/main/error.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2002-2003, Darren Hiebert
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* This module contains a lose assortment of shared functions.
*/
#ifndef CTAGS_MAIN_ERORR_H
#define CTAGS_MAIN_ERORR_H
#include "general.h" /* must always come first */
#include <stdarg.h>
#include "routines.h"
typedef bool (* errorPrintFunc) (const errorSelection selection, const char *const format,
va_list ap, void *data);
extern void setErrorPrinter (errorPrintFunc printer, void *data);
extern bool stderrDefaultErrorPrinter (const errorSelection selection, const char *const format, va_list ap,
void *data);
#endif

View File

@ -116,7 +116,7 @@ extern langType getNamedLanguage (const char *const name)
for (i = 0 ; i < LanguageCount && result == LANG_IGNORE ; ++i)
{
if (LanguageTable [i]->name != NULL)
if (stricmp (name, LanguageTable [i]->name) == 0)
if (strcasecmp (name, LanguageTable [i]->name) == 0)
result = i;
}
return result;

View File

@ -661,111 +661,6 @@ extern char* relativeFilename (const char *file, const char *dir)
return res;
}
extern long unsigned int getFileSize (const char *const name)
{
GStatBuf fileStatus;
unsigned long size = 0;
if (stat (name, &fileStatus) == 0)
size = fileStatus.st_size;
return size;
}
#if 0
static bool isSymbolicLink (const char *const name)
{
#if defined (WIN32)
return false;
#else
GStatBuf fileStatus;
bool result = false;
if (lstat (name, &fileStatus) == 0)
result = (bool) (S_ISLNK (fileStatus.st_mode));
return result;
#endif
}
static bool isNormalFile (const char *const name)
{
GStatBuf fileStatus;
bool result = false;
if (stat (name, &fileStatus) == 0)
result = (bool) (S_ISREG (fileStatus.st_mode));
return result;
}
#endif
extern bool isExecutable (const char *const name)
{
GStatBuf fileStatus;
bool result = false;
if (stat (name, &fileStatus) == 0)
result = (bool) ((fileStatus.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) != 0);
return result;
}
#ifdef HAVE_MKSTEMP
static bool isSetUID (const char *const name)
{
#if defined (WIN32)
return false;
#else
GStatBuf fileStatus;
bool result = false;
if (stat (name, &fileStatus) == 0)
result = (bool) ((fileStatus.st_mode & S_ISUID) != 0);
return result;
#endif
}
#endif
#if 0
static bool isDirectory (const char *const name)
{
bool result = false;
GStatBuf fileStatus;
if (stat (name, &fileStatus) == 0)
result = (bool) S_ISDIR (fileStatus.st_mode);
return result;
}
#endif
/*#ifndef HAVE_FGETPOS*/
/*
extern int fgetpos ( stream, pos )
FILE *const stream;
fpos_t *const pos;
{
int result = 0;
*pos = ftell (stream);
if (*pos == -1L)
result = -1;
return result;
}
extern int fsetpos ( stream, pos )
FILE *const stream;
fpos_t *const pos;
{
return fseek (stream, *pos, SEEK_SET);
}
*/
/*#endif*/
extern FILE *tempFile (const char *const mode, char **const pName)
{
char *name;
@ -815,44 +710,3 @@ extern FILE *tempFile (const char *const mode, char **const pName)
*pName = name;
return fp;
}
extern void error (const errorSelection selection,
const char *const format, ...)
{
va_list ap;
va_start (ap, format);
fprintf (errout, "%s: %s", getExecutableName (),
selected (selection, WARNING) ? "Warning: " : "");
vfprintf (errout, format, ap);
if (selected (selection, PERROR))
fprintf (errout, " : %s", g_strerror (errno));
fputs ("\n", errout);
va_end (ap);
if (selected (selection, FATAL))
exit (1);
}
#ifndef HAVE_STRICMP
extern int stricmp (const char *s1, const char *s2)
{
int result;
do
{
result = toupper ((int) *s1) - toupper ((int) *s2);
} while (result == 0 && *s1++ != '\0' && *s2++ != '\0');
return result;
}
#endif
#ifndef HAVE_STRNICMP
extern int strnicmp (const char *s1, const char *s2, size_t n)
{
int result;
do
{
result = toupper ((int) *s1) - toupper ((int) *s2);
} while (result == 0 && --n > 0 && *s1++ != '\0' && *s2++ != '\0');
return result;
}
#endif

View File

@ -102,6 +102,9 @@ extern void *eMalloc (const size_t size);
extern void *eCalloc (const size_t count, const size_t size);
extern void *eRealloc (void *const ptr, const size_t size);
extern void eFree (void *const ptr);
#ifndef HAVE_STRSTR
extern char* strstr (const char *str, const char *substr);
#endif
extern void toLowerString (char* str);
extern void toUpperString (char* str);
extern char* newLowerString (const char* str);
@ -114,24 +117,13 @@ extern bool doesFileExist (const char *const fileName);
extern bool isRecursiveLink (const char* const dirName);
extern bool isSameFile (const char *const name1, const char *const name2);
extern const char *baseFilename (const char *const filePath);
extern const char *fileExtension (const char *const fileName);
extern bool isAbsolutePath (const char *const path);
extern vString *combinePathAndFile (const char *const path, const char *const file);
extern char* absoluteFilename (const char *file);
extern char* absoluteDirname (char *file);
extern char* relativeFilename (const char *file, const char *dir);
extern FILE *tempFile (const char *const mode, char **const pName);
extern void processExcludeOption (const char *const option, const char *const parameter);
extern const char *fileExtension (const char *const fileName);
extern char* eStrdup (const char* str);
#ifndef HAVE_STRICMP
extern int stricmp (const char *s1, const char *s2);
#endif
#ifndef HAVE_STRNICMP
extern int strnicmp (const char *s1, const char *s2, size_t n);
#endif
#ifndef HAVE_STRSTR
extern char* strstr (const char *str, const char *substr);
#endif
#endif /* CTAGS_MAIN_ROUTINES_H */