[geany/geany] a52137: Grab uctags implementation of strlist

Jiří Techet git-noreply at xxxxx
Mon Dec 17 21:05:30 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:44 UTC
Commit:      a52137f414aaa3d3d9a160c8c061a51ce142ad33
             https://github.com/geany/geany/commit/a52137f414aaa3d3d9a160c8c061a51ce142ad33

Log Message:
-----------
Grab uctags implementation of strlist

Except missing mio_free() in stringListNewFromFile() which has been ported
to uctags.

Except the use of ptrarray for strlist implementation, there's nothing
interesting in the Geany version which would be worth preserving.


Modified Paths:
--------------
    ctags/main/strlist.c
    ctags/main/strlist.h

Modified: ctags/main/strlist.c
164 lines changed, 70 insertions(+), 94 deletions(-)
===================================================================
@@ -13,12 +13,11 @@
 #include "general.h"  /* must always come first */
 
 #include <string.h>
-#ifdef HAVE_FNMATCH_H
-# include <fnmatch.h>
-#endif
+#include <fnmatch.h>
 
-#include "routines.h"
+#include "debug.h"
 #include "read.h"
+#include "routines.h"
 #include "strlist.h"
 
 /*
@@ -27,53 +26,24 @@
 
 extern stringList *stringListNew (void)
 {
-	stringList* const result = xMalloc (1, stringList);
-	result->max   = 0;
-	result->count = 0;
-	result->list  = NULL;
-	return result;
+	return ptrArrayNew ((ptrArrayDeleteFunc)vStringDelete);
 }
 
 extern void stringListAdd (stringList *const current, vString *string)
 {
-	enum { incrementalIncrease = 10 };
-	Assert (current != NULL);
-	if (current->list == NULL)
-	{
-		Assert (current->max == 0);
-		current->count = 0;
-		current->max   = incrementalIncrease;
-		current->list  = xMalloc (current->max, vString*);
-	}
-	else if (current->count == current->max)
-	{
-		current->max += incrementalIncrease;
-		current->list = xRealloc (current->list, current->max, vString*);
-	}
-	current->list [current->count++] = string;
+	ptrArrayAdd (current, string);
 }
 
 extern void stringListRemoveLast (stringList *const current)
 {
-	Assert (current != NULL);
-	Assert (current->count > 0);
-	--current->count;
-	current->list [current->count] = NULL;
+	ptrArrayRemoveLast (current);
 }
 
 /* Combine list `from' into `current', deleting `from' */
 extern void stringListCombine (
 		stringList *const current, stringList *const from)
 {
-	unsigned int i;
-	Assert (current != NULL);
-	Assert (from != NULL);
-	for (i = 0  ;  i < from->count  ;  ++i)
-	{
-		stringListAdd (current, from->list [i]);
-		from->list [i] = NULL;
-	}
-	stringListDelete (from);
+	ptrArrayCombine (current, from);
 }
 
 extern stringList* stringListNewFromArgv (const char* const* const argv)
@@ -110,50 +80,28 @@ extern stringList* stringListNewFromFile (const char* const fileName)
 
 extern unsigned int stringListCount (const stringList *const current)
 {
-	Assert (current != NULL);
-	return current->count;
+	return ptrArrayCount (current);
 }
 
 extern vString* stringListItem (
 		const stringList *const current, const unsigned int indx)
 {
-	Assert (current != NULL);
-	return current->list [indx];
+	return ptrArrayItem (current, indx);
 }
 
 extern vString* stringListLast (const stringList *const current)
 {
-	Assert (current != NULL);
-	Assert (current->count > 0);
-	return current->list [current->count - 1];
+	return ptrArrayLast (current);
 }
 
 extern void stringListClear (stringList *const current)
 {
-	unsigned int i;
-	Assert (current != NULL);
-	for (i = 0  ;  i < current->count  ;  ++i)
-	{
-		vStringDelete (current->list [i]);
-		current->list [i] = NULL;
-	}
-	current->count = 0;
+	ptrArrayClear (current);
 }
 
 extern void stringListDelete (stringList *const current)
 {
-	if (current != NULL)
-	{
-		if (current->list != NULL)
-		{
-			stringListClear (current);
-			eFree (current->list);
-			current->list = NULL;
-		}
-		current->max   = 0;
-		current->count = 0;
-		eFree (current);
-	}
+	ptrArrayDelete (current);
 }
 
 static bool compareString (
@@ -178,8 +126,8 @@ static int stringListIndex (
 	Assert (current != NULL);
 	Assert (string != NULL);
 	Assert (test != NULL);
-	for (i = 0  ;  result == -1  &&  i < current->count  ;  ++i)
-		if ((*test)(string, current->list [i]))
+	for (i = 0  ;  result == -1  &&  i < ptrArrayCount (current)  ;  ++i)
+		if ((*test)(string, ptrArrayItem (current, i)))
 			result = i;
 	return result;
 }
@@ -193,6 +141,22 @@ extern bool stringListHas (
 	return result;
 }
 
+static vString* stringListFinds (
+		const stringList *const current, const char *const string,
+		bool (*test)(const char *s, vString *const vs))
+{
+	int i;
+
+	Assert (current != NULL);
+	Assert (string != NULL);
+
+	i = stringListIndex (current, string, test);
+	if (i == -1)
+		return NULL;
+	else
+		return stringListItem(current, i);
+}
+
 extern bool stringListHasInsensitive (
 		const stringList *const current, const char *const string)
 {
@@ -203,36 +167,29 @@ extern bool stringListHasInsensitive (
 	return result;
 }
 
-extern bool stringListHasTest (
-		const stringList *const current, bool (*test)(const char *s))
+extern bool stringListHasTest (const stringList *const current,
+				  bool (*test)(const char *s, void *userData),
+				  void *userData)
 {
 	bool result = false;
 	unsigned int i;
 	Assert (current != NULL);
-	for (i = 0  ;  ! result  &&  i < current->count  ;  ++i)
-		result = (*test)(vStringValue (current->list [i]));
+	for (i = 0  ;  ! result  &&  i < ptrArrayCount (current)  ;  ++i)
+		result = (*test)(vStringValue ((vString *)ptrArrayItem (current, i)), userData);
 	return result;
 }
 
-extern bool stringListRemoveExtension (
-		stringList* const current, const char* const extension)
+extern bool stringListDeleteItemExtension (stringList* const current, const char* const extension)
 {
-	bool result = false;
 	int where;
 #ifdef CASE_INSENSITIVE_FILENAMES
 	where = stringListIndex (current, extension, compareStringInsensitive);
 #else
 	where = stringListIndex (current, extension, compareString);
 #endif
 	if (where != -1)
-	{
-		memmove (current->list + where, current->list + where + 1,
-				(current->count - where) * sizeof (*current->list));
-		current->list [current->count - 1] = NULL;
-		--current->count;
-		result = true;
-	}
-	return result;
+		ptrArrayDeleteItem (current, where);
+	return where != -1;
 }
 
 extern bool stringListExtensionMatched (
@@ -245,33 +202,52 @@ extern bool stringListExtensionMatched (
 #endif
 }
 
+extern vString* stringListExtensionFinds (
+		const stringList* const current, const char* const extension)
+{
+#ifdef CASE_INSENSITIVE_FILENAMES
+	return stringListFinds (current, extension, compareStringInsensitive);
+#else
+	return stringListFinds (current, extension, compareString);
+#endif
+}
+
 static bool fileNameMatched (
 		const vString* const vpattern, const char* const fileName)
 {
 	const char* const pattern = vStringValue (vpattern);
-#if defined (HAVE_FNMATCH)
 	return (bool) (fnmatch (pattern, fileName, 0) == 0);
-#elif defined (CASE_INSENSITIVE_FILENAMES)
-	return (bool) (strcasecmp (pattern, fileName) == 0);
-#else
-	return (bool) (strcmp (pattern, fileName) == 0);
-#endif
 }
 
 extern bool stringListFileMatched (
+			const stringList* const current, const char* const fileName)
+{
+	return stringListFileFinds (current, fileName)? true: false;
+}
+
+extern vString* stringListFileFinds (
 		const stringList* const current, const char* const fileName)
 {
-	bool result = false;
+	vString* vstr = NULL;
+	bool matched = false;
 	unsigned int i;
-	for (i = 0  ;  ! result  &&  i < stringListCount (current)  ;  ++i)
-		result = fileNameMatched (stringListItem (current, i), fileName);
-	return result;
+	for (i = 0  ;  ! matched  &&  i < stringListCount (current)  ;  ++i)
+	{
+		vstr = stringListItem (current, i);
+		matched = fileNameMatched (vstr, fileName);
+	}
+	return matched? vstr: NULL;
 }
 
-extern void stringListPrint (const stringList *const current)
+extern void stringListPrint (const stringList *const current, FILE *fp)
 {
 	unsigned int i;
 	Assert (current != NULL);
-	for (i = 0  ;  i < current->count  ;  ++i)
-		printf ("%s%s", (i > 0) ? ", " : "", vStringValue (current->list [i]));
+	for (i = 0  ;  i < ptrArrayCount (current)  ;  ++i)
+		fprintf (fp, "%s%s", (i > 0) ? ", " : "", vStringValue ((vString *)ptrArrayItem (current, i)));
+}
+
+extern void stringListReverse (const stringList *const current)
+{
+	ptrArrayReverse (current);
 }


Modified: ctags/main/strlist.h
20 lines changed, 12 insertions(+), 8 deletions(-)
===================================================================
@@ -15,15 +15,14 @@
 #include "general.h"  /* must always come first */
 
 #include "vstring.h"
+#include "ptrarray.h"
+
+#include <stdio.h>
 
 /*
 *   DATA DECLARATIONS
 */
-typedef struct sStringList {
-	unsigned int max;
-	unsigned int count;
-	vString    **list;
-} stringList;
+typedef ptrArray stringList;
 
 /*
 *   FUNCTION PROTOTYPES
@@ -41,10 +40,15 @@ extern vString* stringListLast (const stringList *const current);
 extern void stringListDelete (stringList *const current);
 extern bool stringListHasInsensitive (const stringList *const current, const char *const string);
 extern bool stringListHas (const stringList *const current, const char *const string);
-extern bool stringListHasTest (const stringList *const current, bool (*test)(const char *s));
-extern bool stringListRemoveExtension (stringList* const current, const char* const extension);
+extern bool stringListHasTest (const stringList *const current,
+				  bool (*test)(const char *s, void *userData),
+				  void *userData);
+extern bool stringListDeleteItemExtension (stringList* const current, const char* const extension);
 extern bool stringListExtensionMatched (const stringList* const list, const char* const extension);
+extern vString* stringListExtensionFinds (const stringList* const list, const char* const extension);
 extern bool stringListFileMatched (const stringList* const list, const char* const str);
-extern void stringListPrint (const stringList *const current);
+extern vString* stringListFileFinds (const stringList* const list, const char* const str);
+extern void stringListPrint (const stringList *const current, FILE *fp);
+extern void stringListReverse (const stringList *const current);
 
 #endif  /* CTAGS_MAIN_STRLIST_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