[geany/geany] 53f83e: read: add lineFposMap

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


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Tue, 11 Oct 2016 15:09:54 UTC
Commit:      53f83e7ceef29ba75472094b12a92df334c52874
             https://github.com/geany/geany/commit/53f83e7ceef29ba75472094b12a92df334c52874

Log Message:
-----------
read: add lineFposMap


Modified Paths:
--------------
    ctags/main/read.c

Modified: ctags/main/read.c
43 lines changed, 39 insertions(+), 4 deletions(-)
===================================================================
@@ -151,10 +151,8 @@ extern MIOPos getInputFilePosition (void)
 
 extern MIOPos getInputFilePositionForLine (int line)
 {
-	MIOPos pos;
-	return pos;
-/*	return File.lineFposMap.pos[(((File.lineFposMap.count > (line - 1)) \
-				      && (line > 0))? (line - 1): 0)];*/
+	return File.lineFposMap.pos[(((File.lineFposMap.count > (line - 1)) \
+				      && (line > 0))? (line - 1): 0)];
 }
 
 extern langType getInputLanguage (void)
@@ -244,6 +242,41 @@ extern void freeInputFileResources (void)
 	freeInputFileInfo (&File.source);
 }
 
+/*
+ * inputLineFposMap related functions
+ */
+static void freeLineFposMap (inputLineFposMap *lineFposMap)
+{
+	if (lineFposMap->pos)
+	{
+		free (lineFposMap->pos);
+		lineFposMap->pos = NULL;
+		lineFposMap->count = 0;
+		lineFposMap->size = 0;
+	}
+}
+
+static void allocLineFposMap (inputLineFposMap *lineFposMap)
+{
+#define INITIAL_lineFposMap_LEN 256
+	lineFposMap->pos = xCalloc (INITIAL_lineFposMap_LEN, MIOPos);
+	lineFposMap->size = INITIAL_lineFposMap_LEN;
+	lineFposMap->count = 0;
+}
+
+static void appendLineFposMap (inputLineFposMap *lineFposMap, MIOPos pos)
+{
+	if (lineFposMap->size == lineFposMap->count)
+	{
+		lineFposMap->size *= 2;
+		lineFposMap->pos = xRealloc (lineFposMap->pos,
+					     lineFposMap->size,
+					     MIOPos);
+	}
+	lineFposMap->pos [lineFposMap->count] = pos;
+	lineFposMap->count++;
+}
+
 /*
  *   Input file access functions
  */
@@ -540,6 +573,7 @@ extern bool openInputFile (const char *const fileName, const langType language,
 		setSourceFileParameters (vStringNewInit (fileName), language);
 		File.source.lineNumberOrigin = 0L;
 		File.source.lineNumber = File.source.lineNumberOrigin;
+		allocLineFposMap (&File.lineFposMap);
 
 		verbose ("OPENING %s as %s language %sfile\n", fileName,
 				getLanguageName (language),
@@ -580,6 +614,7 @@ extern void closeInputFile (void)
 		}
 		mio_free (File.mio);
 		File.mio = NULL;
+		freeLineFposMap (&File.lineFposMap);
 	}
 }
 



--------------
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