[geany/geany] 2b8c7a: Sync the rest of routines.c/h

Jiří Techet git-noreply at xxxxx
Mon Dec 17 21:05:41 UTC 2018


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 08 Oct 2016 12:12:45 UTC
Commit:      2b8c7ae5ad0f8875b45472c2bdad5e022e270601
             https://github.com/geany/geany/commit/2b8c7ae5ad0f8875b45472c2bdad5e022e270601

Log Message:
-----------
Sync the rest of routines.c/h

Requires checking for errno.h limits.h in autoconf as there are ifdefs
around those in routines.c.


Modified Paths:
--------------
    configure.ac
    ctags/main/routines.c
    ctags/main/routines.h

Modified: configure.ac
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -38,7 +38,7 @@ AC_PROG_LN_S
 # autoscan start
 
 # Checks for header files.
-AC_CHECK_HEADERS([fcntl.h fnmatch.h glob.h stdlib.h sys/time.h])
+AC_CHECK_HEADERS([fcntl.h fnmatch.h glob.h stdlib.h sys/time.h errno.h limits.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_OFF_T


Modified: ctags/main/routines.c
193 lines changed, 189 insertions(+), 4 deletions(-)
===================================================================
@@ -12,8 +12,6 @@
 */
 #include "general.h"  /* must always come first */
 
-#include <errno.h>
-
 #ifdef HAVE_STDLIB_H
 # include <stdlib.h>  /* to declare malloc (), realloc () */
 #endif
@@ -138,7 +136,10 @@
 # if defined (_MSC_VER)
 #  define stat    _stat
 #  define getcwd  _getcwd
+#  define currentdrive() (_getdrive() + 'A' - 1)
 #  define PATH_MAX  _MAX_PATH
+# else
+#  define currentdrive() 'C'
 # endif
 #endif
 
@@ -150,8 +151,6 @@
  *  Miscellaneous macros
  */
 
-#define selected(var,feature)   (((int)(var) & (int)(feature)) == (int)feature)
-
 
 /*
 *   DATA DEFINITIONS
@@ -182,6 +181,11 @@ extern int lstat (const char *, struct stat *);
 *   FUNCTION DEFINITIONS
 */
 
+extern void freeRoutineResources (void)
+{
+	if (CurrentDirectory != NULL)
+		eFree (CurrentDirectory);
+}
 
 extern void setExecutableName (const char *const path)
 {
@@ -194,6 +198,14 @@ extern const char *getExecutableName (void)
 	return ExecutableName;
 }
 
+extern const char *getExecutablePath (void)
+{
+	return ExecutableProgram;
+}
+
+/*
+ *  Memory allocation functions
+ */
 
 extern void *eMalloc (const size_t size)
 {
@@ -235,6 +247,37 @@ extern void eFree (void *const ptr)
 		free (ptr);
 }
 
+/*
+ *  String manipulation functions
+ */
+
+/*
+ * Compare two strings, ignoring case.
+ * Return 0 for match, < 0 for smaller, > 0 for bigger
+ * Make sure case is folded to uppercase in comparison (like for 'sort -f')
+ * This makes a difference when one of the chars lies between upper and lower
+ * ie. one of the chars [ \ ] ^ _ ` for ascii. (The '_' in particular !)
+ */
+extern int struppercmp (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;
+}
+
+extern int strnuppercmp (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;
+}
+
 #ifndef HAVE_STRSTR
 extern char* strstr (const char *str, const char *substr)
 {
@@ -248,13 +291,32 @@ extern char* strstr (const char *str, const char *substr)
 }
 #endif
 
+extern char* strrstr (const char *str, const char *substr)
+{
+	const size_t length = strlen (substr);
+	const char *p;
+
+	for (p = str + strlen(str) - length  ;  p >= str  ;  --p)
+		if (strncmp (p, substr, length) == 0)
+			return (char*) p;
+	return NULL;
+}
+
 extern char* eStrdup (const char* str)
 {
 	char* result = xMalloc (strlen (str) + 1, char);
 	strcpy (result, str);
 	return result;
 }
 
+extern char* eStrndup (const char* str, size_t len)
+{
+	char* result = xMalloc (len + 1, char);
+	memset(result, 0, len + 1);
+	strncpy (result, str, len);
+	return result;
+}
+
 extern void toLowerString (char* str)
 {
 	while (*str != '\0')
@@ -297,6 +359,76 @@ extern char* newUpperString (const char* str)
 	return result;
 }
 
+/* Safe wrapper for strtoul
+ *
+ * The conversion result is placed in value and must only be used if the
+ * function returned true.
+ */
+extern bool strToULong(const char *const str, int base, unsigned long *value)
+{
+	char *endptr;
+
+	errno = 0;
+	*value = strtoul (str, &endptr, base);
+	return *endptr == '\0' && str != endptr && errno == 0;
+}
+
+/* Safe wrapper for strtol/atol
+ *
+ * The conversion result is placed in value and must only be used if the
+ * function returned true.
+ */
+extern bool strToLong(const char *const str, int base, long *value)
+{
+	char *endptr;
+
+	errno = 0;
+	*value = strtol (str, &endptr, base);
+	return *endptr == '\0' && str != endptr && errno == 0;
+}
+
+extern bool strToUInt(const char *const str, int base, unsigned int *value)
+{
+	unsigned long ulong_value;
+
+	if(!strToULong(str, base, &ulong_value) || ulong_value > UINT_MAX)
+		return false;
+
+	*value = (unsigned int) ulong_value;
+	return true;
+}
+
+extern bool strToInt(const char *const str, int base, int *value)
+{
+	long long_value;
+
+	if(!strToLong(str, base, &long_value) || long_value > INT_MAX || long_value < INT_MIN)
+		return false;
+
+	*value = (int) long_value;
+	return true;
+}
+
+/*
+ * File system functions
+ */
+
+extern void setCurrentDirectory (void)
+{
+	char* buf;
+	if (CurrentDirectory == NULL)
+		CurrentDirectory = xMalloc ((size_t) (PATH_MAX + 1), char);
+	buf = getcwd (CurrentDirectory, PATH_MAX);
+	if (buf == NULL)
+		perror ("");
+	if (CurrentDirectory [strlen (CurrentDirectory) - (size_t) 1] !=
+			PATH_SEPARATOR)
+	{
+		sprintf (CurrentDirectory + strlen (CurrentDirectory), "%c",
+				OUTPUT_PATH_SEPARATOR);
+	}
+}
+
 /* For caching of stat() calls */
 extern fileStatus *eStat (const char *const fileName)
 {
@@ -344,6 +476,12 @@ extern bool doesFileExist (const char *const fileName)
 	return status->exists;
 }
 
+extern bool doesExecutableExist (const char *const fileName)
+{
+	fileStatus *status = eStat (fileName);
+	return status->exists && status->isExecutable;
+}
+
 extern bool isRecursiveLink (const char* const dirName)
 {
 	bool result = false;
@@ -434,10 +572,26 @@ extern const char *baseFilename (const char *const filePath)
 	 */
 	for (i = 0  ;  i < strlen (PathDelimiters)  ;  ++i)
 	{
+# ifdef HAVE_MBLEN
+		const char *p;
+		int ml;
+
+		/* Some DBCS has letter contains 0x5C in trailing byte.
+		 * So skip to the trailing byte. */
+		for (p = filePath  ;  *p != '\0'  ;  ++p)
+		{
+			ml = mblen(p, MB_LEN_MAX);
+			if (ml > 1)
+				p += ml - 1;
+			else if (*p == PathDelimiters [i] && p > tail)
+				tail = p;
+		}
+# else
 		const char *sep = strrchr (filePath, PathDelimiters [i]);
 
 		if (sep > tail)
 			tail = sep;
+# endif
 	}
 #else
 	const char *tail = strrchr (filePath, PATH_SEPARATOR);
@@ -466,6 +620,24 @@ extern const char *fileExtension (const char *const fileName)
 	return extension;
 }
 
+extern char* baseFilenameSansExtensionNew (const char *const fileName,
+					   const char *const templateExt)
+{
+	const char *pDelimiter = NULL;
+	const char *const base = baseFilename (fileName);
+	char* shorten_base;
+
+	pDelimiter = strrchr (base, templateExt[0]);
+
+	if (pDelimiter && (strcmp (pDelimiter, templateExt) == 0))
+	{
+		shorten_base = eStrndup (base, pDelimiter - base);
+		return shorten_base;
+	}
+	else
+		return NULL;
+}
+
 extern bool isAbsolutePath (const char *const path)
 {
 	bool result = false;
@@ -531,7 +703,20 @@ extern char* absoluteFilename (const char *file)
 	char *slashp, *cp;
 	char *res = NULL;
 	if (isAbsolutePath (file))
+	{
+#ifdef MSDOS_STYLE_PATH
+		if (file [1] == ':')
+			res = eStrdup (file);
+		else
+		{
+			char drive [3];
+			sprintf (drive, "%c:", currentdrive ());
+			res = concat (drive, file, "");
+		}
+#else
 		res = eStrdup (file);
+#endif
+	}
 	else
 		res = concat (CurrentDirectory, file, "");
 


Modified: ctags/main/routines.h
17 lines changed, 17 insertions(+), 0 deletions(-)
===================================================================
@@ -26,6 +26,7 @@
 #define xRealloc(p,n,Type) (Type *)eRealloc((p), (n) * sizeof (Type))
 
 #define ARRAY_SIZE(X)      (sizeof (X) / sizeof (X[0]))
+#define ARRAY_AND_SIZE(X)  (X), ARRAY_SIZE(X)
 
 #define STRINGIFY(X) STRINGIFY_(X)
 #define STRINGIFY_(X) #X
@@ -89,8 +90,10 @@ typedef struct {
 /*
 *   FUNCTION PROTOTYPES
 */
+extern void freeRoutineResources (void);
 extern void setExecutableName (const char *const path);
 extern const char *getExecutableName (void);
+extern const char *getExecutablePath (void);
 extern void error (const errorSelection selection, const char *const format, ...) CTAGS_ATTR_PRINTF (2, 3);
 
 /* Memory allocation functions */
@@ -102,19 +105,31 @@ 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);
+
+/* String manipulation functions */
+extern int struppercmp (const char *s1, const char *s2);
+extern int strnuppercmp (const char *s1, const char *s2, size_t n);
 #ifndef HAVE_STRSTR
 extern char* strstr (const char *str, const char *substr);
 #endif
+extern char* strrstr (const char *str, const char *substr);
 extern char* eStrdup (const char* str);
+extern char* eStrndup (const char* str, size_t len);
 extern void toLowerString (char* str);
 extern void toUpperString (char* str);
 extern char* newLowerString (const char* str);
 extern char* newUpperString (const char* str);
+extern bool strToUInt(const char *const str, int base, unsigned int *value);
+extern bool strToULong(const char *string, int base, unsigned long *value);
+extern bool strToInt(const char *const str, int base, int *value);
+extern bool strToLong(const char *string, int base, long *value);
 
 /* File system functions */
+extern void setCurrentDirectory (void);
 extern fileStatus *eStat (const char *const fileName);
 extern void eStatFree (fileStatus *status);
 extern bool doesFileExist (const char *const fileName);
+extern bool doesExecutableExist (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);
@@ -126,4 +141,6 @@ extern char* absoluteDirname (char *file);
 extern char* relativeFilename (const char *file, const char *dir);
 extern MIO *tempFile (const char *const mode, char **const pName);
 
+extern char* baseFilenameSansExtensionNew (const char *const fileName, const char *const templateExt);
+
 #endif  /* CTAGS_MAIN_ROUTINES_H */



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list