[geany/geany-plugins] f369c8: lineoperations: cleaned up var names & unused vars

Sylvan Mostert git-noreply at xxxxx
Tue Jan 12 17:19:08 UTC 2016


Branch:      refs/heads/master
Author:      Sylvan Mostert <smostert.dev at gmail.com>
Committer:   Sylvan Mostert <smostert.dev at gmail.com>
Date:        Tue, 12 Jan 2016 17:19:08 UTC
Commit:      f369c8421022ac2e53edd003ba32ad48da92048b
             https://github.com/geany/geany-plugins/commit/f369c8421022ac2e53edd003ba32ad48da92048b

Log Message:
-----------
lineoperations: cleaned up var names & unused vars

The variable 'numlines' was removed since it was unnecessary.

Variable names and function are changed to have consistent naming.
Now they have underscore between each distinct word.


Modified Paths:
--------------
    lineoperations/src/linefunctions.c

Modified: lineoperations/src/linefunctions.c
294 lines changed, 143 insertions(+), 151 deletions(-)
===================================================================
@@ -23,34 +23,34 @@
 
 
 // isspace()
-gboolean issp(gchar c)
+gboolean is_sp(gchar c)
 {
 	return (c == ' ' || c == '\t' || c == '\f' ||
 			c == '\v' || c == '\r' || c == '\n');
 }
 
 
-// iswhitespaceline(gchar* line) checks if line is a whitespace line
-gboolean iswhitespaceline(gchar* line)
+// is_whitespace_line(gchar* line) checks if line is a whitespace line
+gboolean is_whitespace_line(gchar* line)
 {
 	gint i;
 
 	for(i = 0; line[i] != '\0'; i++)
-		if(!issp(line[i]))
+		if(!is_sp(line[i]))
 			return FALSE;
 	return TRUE;
 }
 
 
 // comparison function to be used in qsort
-static gint compareasc(const void * a, const void * b)
+static gint compare_asc(const void * a, const void * b)
 {
 	return strcmp(*(const gchar **) a, *(const gchar **) b);
 }
 
 
 // comparison function to be used in qsort
-static gint comparedesc(const void * a, const void * b)
+static gint compare_desc(const void * a, const void * b)
 {
 	return strcmp(*(const gchar **) b, *(const gchar **) a);
 }
@@ -58,52 +58,50 @@ static gint comparedesc(const void * a, const void * b)
 
 // Remove Duplicate Lines, sorted
 void rmdupst(GeanyDocument *doc) {
-	gint  totalnumchars;    // number of characters in the document
-	gint  totalnumlines;    // number of lines in the document
+	gint  total_num_chars;  // number of characters in the document
+	gint  total_num_lines;  // number of lines in the document
 	gchar **lines;          // array to hold all lines in the document
-	gint  numlines;         // number of lines in **lines array
-	gchar *newfile;         // *final* string to replace current document
-	gint  nfposn;           // keeps track of the position of newfile string
+	gchar *new_file;        // *final* string to replace current document
+	gint  nfposn;           // keeps track of the position of new_file string
 	gint  i;                // iterator
 	gint  j;                // iterator
 	gint  k;                // iterator
 
-	totalnumchars = sci_get_length(doc->editor->sci);
-	totalnumlines = sci_get_line_count(doc->editor->sci);
-	lines         = g_malloc(sizeof(gchar *) * totalnumlines);
-	newfile       = g_malloc(sizeof(gchar) * (totalnumchars+1));
-	numlines      = 0;
-	nfposn        = 0;
-	k             = 0;
+	total_num_chars = sci_get_length(doc->editor->sci);
+	total_num_lines = sci_get_line_count(doc->editor->sci);
+	lines           = g_malloc(sizeof(gchar *) * total_num_lines);
+	new_file        = g_malloc(sizeof(gchar) * (total_num_chars+1));
+	nfposn          = 0;
+	k               = 0;
 
 
 
 	// copy *all* lines into **lines array
-	for(i = 0; i < totalnumlines; i++)
-		lines[numlines++] = sci_get_line(doc->editor->sci, i);
+	for(i = 0; i < total_num_lines; i++)
+		lines[i] = sci_get_line(doc->editor->sci, i);
 
-	qsort(lines, numlines, sizeof(gchar *), compareasc);
+	qsort(lines, total_num_lines, sizeof(gchar *), compare_asc);
 
-	if(numlines > 0)	// copy the first line into *newfile
+	if(total_num_lines > 0)	// copy the first line into *new_file
 		for(j = 0; lines[0][j] != '\0'; j++)
-			newfile[nfposn++] = lines[0][j];
+			new_file[nfposn++]  = lines[0][j];
 
-	for(i = 0; i < numlines; i++)	// copy 1st occurance of each line
-									// into *newfile
+	for(i = 0; i < total_num_lines; i++)	// copy 1st occurance of each line
+									// into *new_file
 		if(strcmp(lines[k], lines[i]) != 0)
 		{
 			for(j = 0; lines[i][j] != '\0'; j++)
-				newfile[nfposn++] = lines[i][j];
+				new_file[nfposn++]  = lines[i][j];
 			k = i;
 		}
 
-	newfile[nfposn] = '\0';
-	sci_set_text(doc->editor->sci, newfile);	// set new document
+	new_file[nfposn] = '\0';
+	sci_set_text(doc->editor->sci, new_file);	// set new document
 
 
 
 	// free used memory
-	for(i = 0; i < numlines; i++)
+	for(i = 0; i < total_num_lines; i++)
 		g_free(lines[i]);
 	g_free(lines);
 	g_free(new_file);
@@ -112,58 +110,56 @@ void rmdupst(GeanyDocument *doc) {
 
 // Remove Duplicate Lines, ordered
 void rmdupln(GeanyDocument *doc) {
-	gint  totalnumchars;    // number of characters in the document
-	gint  totalnumlines;    // number of lines in the document
+	gint  total_num_chars;  // number of characters in the document
+	gint  total_num_lines;  // number of lines in the document
 	gchar **lines;          // array to hold all lines in the document
-	gint  numlines;         // number of lines in lines
-	gchar *newfile;         // *final* string to replace current document
-	gint  nfposn;           // keeps track of the position of newfile string
+	gchar *new_file;        // *final* string to replace current document
+	gint  nfposn;           // keeps track of the position of new_file string
 	gint  i;                // iterator
 	gint  j;                // iterator
-	gboolean *toremove;     // flag to 'mark' which lines to remove
+	gboolean *to_remove;    // flag to 'mark' which lines to remove
 
-	totalnumchars = sci_get_length(doc->editor->sci);
-	totalnumlines = sci_get_line_count(doc->editor->sci);
-	lines         = g_malloc(sizeof(gchar *) * totalnumlines);
-	newfile       = g_malloc(sizeof(gchar) * (totalnumchars+1));
-	numlines      = 0;
-	nfposn        = 0;
-	toremove      = NULL;
+	total_num_chars = sci_get_length(doc->editor->sci);
+	total_num_lines = sci_get_line_count(doc->editor->sci);
+	lines           = g_malloc(sizeof(gchar *) * total_num_lines);
+	new_file        = g_malloc(sizeof(gchar) * (total_num_chars+1));
+	nfposn          = 0;
+	to_remove       = NULL;
 
 
 
 	// copy *all* lines into **lines array
-	for(i = 0; i < totalnumlines; i++)
-		lines[numlines++] = sci_get_line(doc->editor->sci, i);
+	for(i = 0; i < total_num_lines; i++)
+		lines[i] = sci_get_line(doc->editor->sci, i);
 
-	// allocate and set *toremove to all FALSE
-	toremove = g_malloc(sizeof(gboolean) * numlines);
-	for(i = 0; i < (numlines); i++)
-		toremove[i] = FALSE;
+	// allocate and set *to_remove to all FALSE
+	to_remove = g_malloc(sizeof(gboolean) * total_num_lines);
+	for(i = 0; i < (total_num_lines); i++)
+		to_remove[i] = FALSE;
 
 	// find which lines are duplicate
-	for(i = 0; i < numlines; i++)
+	for(i = 0; i < total_num_lines; i++)
 		// make sure that the line is not already duplicate
-		if(!toremove[i])
-			for(j = (i+1); j < numlines; j++)
-				if(!toremove[j])
+		if(!to_remove[i])
+			for(j = (i+1); j < total_num_lines; j++)
+				if(!to_remove[j])
 					if(strcmp(lines[i], lines[j]) == 0) {
-						toremove[j] = TRUE;   // this line is duplicate,
-						                      // mark to remove
-						//toremove[i] = TRUE; //remove all occurrances
+						to_remove[j] = TRUE;   // this line is duplicate,
+						                       // mark to remove
+						//to_remove[i] = TRUE; //remove all occurrances
 					}
 
-	// copy line into 'newfile' if it is not FALSE(not duplicate)
-	for(i = 0; i < numlines; i++)
+	// copy line into 'new_file' if it is not FALSE(not duplicate)
+	for(i = 0; i < total_num_lines; i++)
 	{
-		if(!toremove[i])
+		if(!to_remove[i])
 			for(j = 0; lines[i][j] != '\0'; j++)
-				newfile[nfposn++] = lines[i][j];
+				new_file[nfposn++]  = lines[i][j];
 		g_free(lines[i]);
 	}
 
-	newfile[nfposn] = '\0';
-	sci_set_text(doc->editor->sci, newfile);	// set new document
+	new_file[nfposn] = '\0';
+	sci_set_text(doc->editor->sci, new_file);	// set new document
 
 
 
@@ -176,58 +172,56 @@ void rmdupln(GeanyDocument *doc) {
 
 
 void rmunqln(GeanyDocument *doc) {
-	gint totalnumchars; // number of characters in the document
-	gint totalnumlines; // number of lines in the document
-	gchar **lines;      // array to hold all lines in the document
-	gint numlines;      // number of lines in lines
-	gchar *newfile;     // *final* string to replace current document
-	gint nfposn;        // keeps track of the position of newfile string
-	gint i;             // iterator
-	gint j;             // iterator
-	gboolean *toremove; // to 'mark' which lines to remove
-
-	totalnumchars = sci_get_length(doc->editor->sci);
-	totalnumlines = sci_get_line_count(doc->editor->sci);
-	lines         = g_malloc(sizeof(gchar *) * totalnumlines);
-	newfile       = g_malloc(sizeof(gchar) * (totalnumchars+1));
-	numlines      = 0;
-	nfposn        = 0;
-	toremove      = NULL;
+	gint total_num_chars; // number of characters in the document
+	gint total_num_lines; // number of lines in the document
+	gchar **lines;        // array to hold all lines in the document
+	gchar *new_file;      // *final* string to replace current document
+	gint nfposn;          // keeps track of the position of new_file string
+	gint i;               // iterator
+	gint j;               // iterator
+	gboolean *to_remove;  // to 'mark' which lines to remove
+
+	total_num_chars = sci_get_length(doc->editor->sci);
+	total_num_lines = sci_get_line_count(doc->editor->sci);
+	lines           = g_malloc(sizeof(gchar *) * total_num_lines);
+	new_file        = g_malloc(sizeof(gchar) * (total_num_chars+1));
+	nfposn          = 0;
+	to_remove       = NULL;
 
 
 	// copy *all* lines into **lines array
-	for(i = 0; i < totalnumlines; i++)
-		lines[numlines++] = sci_get_line(doc->editor->sci, i);
+	for(i = 0; i < total_num_lines; i++)
+		lines[i] = sci_get_line(doc->editor->sci, i);
 
-	// allocate and set *toremove to all TRUE
-	toremove = g_malloc(sizeof(gboolean) * numlines);
-	for(i = 0; i < (numlines); i++)
-		toremove[i] = TRUE;
+	// allocate and set *to_remove to all TRUE
+	to_remove = g_malloc(sizeof(gboolean) * total_num_lines);
+	for(i = 0; i < (total_num_lines); i++)
+		to_remove[i] = TRUE;
 
 	// set all unique rows to FALSE
-	// toremove[i] corresponds to lines[i]
-	for(i = 0; i < numlines; i++)
-		if(toremove[i])
-			for(j = (i+1); j < numlines; j++)
-				if(toremove[j])
+	// to_remove[i] corresponds to lines[i]
+	for(i = 0; i < total_num_lines; i++)
+		if(to_remove[i])
+			for(j = (i+1); j < total_num_lines; j++)
+				if(to_remove[j])
 					if(strcmp(lines[i], lines[j]) == 0)
 					{
-						toremove[i] = FALSE;
-						toremove[j] = FALSE;
+						to_remove[i] = FALSE;
+						to_remove[j] = FALSE;
 					}
 
 
-	// copy line into 'newfile' if it is not FALSE(unique)
-	for(i = 0; i < numlines; i++)
+	// copy line into 'new_file' if it is not FALSE(unique)
+	for(i = 0; i < total_num_lines; i++)
 	{
-		if(!toremove[i])
+		if(!to_remove[i])
 			for(j = 0; lines[i][j] != '\0'; j++)
-				newfile[nfposn++] = lines[i][j];
+				new_file[nfposn++]  = lines[i][j];
 		g_free(lines[i]);
 	}
 
-	newfile[nfposn] = '\0';
-	sci_set_text(doc->editor->sci, newfile);	// set new document
+	new_file[nfposn] = '\0';
+	sci_set_text(doc->editor->sci, new_file);	// set new document
 
 
 
@@ -240,29 +234,29 @@ void rmunqln(GeanyDocument *doc) {
 
 
 void rmemtyln(GeanyDocument *doc) {
-	gint  totalnumchars;    // number of characters in the document
-	gint  totalnumlines;    // number of lines in the document
+	gint  total_num_chars;  // number of characters in the document
+	gint  total_num_lines;  // number of lines in the document
 	gchar *line;            // temporary line
 	gint  linelen;          // length of *line
-	gchar *newfile;         // *final* string to replace current document
-	gint  nfposn;           // position to the last character in newfile
+	gchar *new_file;        // *final* string to replace current document
+	gint  nfposn;           // position to the last character in new_file
 	gint  i;                // temporary iterator number
 	gint j;                 // iterator
 
 
-	totalnumchars = sci_get_length(doc->editor->sci);
-	totalnumlines = sci_get_line_count(doc->editor->sci);
+	total_num_chars = sci_get_length(doc->editor->sci);
+	total_num_lines = sci_get_line_count(doc->editor->sci);
 	/*
 	 * Allocate space for the new document (same amount as open document.
 	 * If the document contains lines with only whitespace,
 	 * not all of this space will be used.)
 	*/
-	newfile   = g_malloc(sizeof(gchar) * (totalnumchars+1));
-	nfposn    = 0;
+	new_file   = g_malloc(sizeof(gchar) * (total_num_chars+1));
+	nfposn     = 0;
 
 
 
-	for(i = 0; i < totalnumlines; i++)    // loop through opened doc char by char
+	for(i = 0; i < total_num_lines; i++)    // loop through opened doc char by char
 	{
 		linelen = sci_get_line_length(doc->editor->sci, i);
 
@@ -271,52 +265,52 @@ void rmemtyln(GeanyDocument *doc) {
 			line = sci_get_line(doc->editor->sci, i);
 
 			if(line[0] != '\r')
-				// copy current line into *newfile
+				// copy current line into *new_file
 				for(j = 0; line[j] != '\0'; j++)
-					newfile[nfposn++] = line[j];
+					new_file[nfposn++] = line[j];
 		}
 		else if(linelen != 1)
 		{
 			line = sci_get_line(doc->editor->sci, i);
 
-			// copy current line into *newfile
+			// copy current line into *new_file
 			for(j = 0; line[j] != '\0'; j++)
-				newfile[nfposn++] = line[j];
+				new_file[nfposn++] = line[j];
 		}
 	}
-	newfile[nfposn] = '\0';
-	sci_set_text(doc->editor->sci, newfile);	// set new document
+	new_file[nfposn] = '\0';
+	sci_set_text(doc->editor->sci, new_file);	// set new document
 
 
 
-	g_free(newfile);
+	g_free(new_file);
 }
 
 
 
 // Remove Whitespace Lines
 void rmwhspln(GeanyDocument *doc) {
-	gint  totalnumchars;    // number of characters in the document
-	gint  totalnumlines;    // number of lines in the document
+	gint  total_num_chars;  // number of characters in the document
+	gint  total_num_lines;  // number of lines in the document
 	gchar *line;            // temporary line
 	gint  linelen;          // length of *line
-	gchar *newfile;         // *final* string to replace current document
-	gint  nfposn;           // position to the last character in newfile
+	gchar *new_file;        // *final* string to replace current document
+	gint  nfposn;           // position to the last character in new_file
 	gint  i;                // temporary iterator number
-	gint j;                 // iterator
+	gint  j;                // iterator
 
 
-	totalnumchars = sci_get_length(doc->editor->sci);
-	totalnumlines = sci_get_line_count(doc->editor->sci);
+	total_num_chars = sci_get_length(doc->editor->sci);
+	total_num_lines = sci_get_line_count(doc->editor->sci);
 	/*
 	 * Allocate space for the new document (same amount as open document.
 	 * If the document contains lines with only whitespace,
 	 * not all of this space will be used.)
 	*/
-	newfile   = g_malloc(sizeof(gchar) * (totalnumchars+1));
-	nfposn    = 0;
+	new_file = g_malloc(sizeof(gchar) * (total_num_chars+1));
+	nfposn   = 0;
 
-	for(i = 0; i < totalnumlines; i++)    // loop through opened doc
+	for(i = 0; i < total_num_lines; i++)    // loop through opened doc
 	{
 		linelen = sci_get_line_length(doc->editor->sci, i);
 
@@ -325,68 +319,66 @@ void rmwhspln(GeanyDocument *doc) {
 			line = sci_get_line(doc->editor->sci, i);
 
 			if(line[0] != '\r')
-				// copy current line into *newfile
+				// copy current line into *new_file
 				for(j = 0; line[j] != '\0'; j++)
-					newfile[nfposn++] = line[j];
+					new_file[nfposn++] = line[j];
 		}
 		else if(linelen != 1)
 		{
 			line = sci_get_line(doc->editor->sci, i);
 
-			if(!iswhitespaceline(line))
-				// copy current line into *newfile
+			if(!is_whitespace_line(line))
+				// copy current line into *new_file
 				for(j = 0; line[j] != '\0'; j++)
-					newfile[nfposn++] = line[j];
+					new_file[nfposn++] = line[j];
 		}
 
 	}
-	newfile[nfposn] = '\0';
-	sci_set_text(doc->editor->sci, newfile);	// set new document
+	new_file[nfposn] = '\0';
+	sci_set_text(doc->editor->sci, new_file);	// set new document
 
-	g_free(newfile);
+	g_free(new_file);
 }
 
 
 // Sort Lines Ascending and Descending
 void sortlines(GeanyDocument *doc, gboolean asc) {
-	gint  totalnumchars;    // number of characters in the document
-	gint  totalnumlines;    // number of lines in the document
+	gint  total_num_chars;  // number of characters in the document
+	gint  total_num_lines;  // number of lines in the document
 	gchar **lines;          // array to hold all lines in the document
-	gint  numlines;         // number of lines in **lines array
-	gchar *newfile;         // *final* string to replace current document
-	gint  nfposn;           // keeps track of the position of newfile string
+	gchar *new_file;        // *final* string to replace current document
+	gint  nfposn;           // keeps track of the position of new_file string
 	gint  i;                // iterator
 	gint  j;                // iterator
 
-	totalnumchars = sci_get_length(doc->editor->sci);
-	totalnumlines = sci_get_line_count(doc->editor->sci);
-	lines         = g_malloc(sizeof(gchar *) * totalnumlines);
-	newfile       = g_malloc(sizeof(gchar) * (totalnumchars+1));
-	numlines      = 0;
-	nfposn        = 0;
+	total_num_chars = sci_get_length(doc->editor->sci);
+	total_num_lines = sci_get_line_count(doc->editor->sci);
+	lines           = g_malloc(sizeof(gchar *) * total_num_lines);
+	new_file        = g_malloc(sizeof(gchar) * (total_num_chars+1));
+	nfposn          = 0;
 
 
 
 	// copy *all* lines into **lines array
-	for(i = 0; i < totalnumlines; i++)
-		lines[numlines++] = sci_get_line(doc->editor->sci, i);
+	for(i = 0; i < total_num_lines; i++)
+		lines[i] = sci_get_line(doc->editor->sci, i);
 
 	// sort **lines array
 	if(asc)
-		qsort(lines, numlines, sizeof(gchar *), compareasc);
+		qsort(lines, total_num_lines, sizeof(gchar *), compare_asc);
 	else
-		qsort(lines, numlines, sizeof(gchar *), comparedesc);
+		qsort(lines, total_num_lines, sizeof(gchar *), compare_desc);
 
-	// copy **lines array into *newfile
-	for(i = 0; i < numlines; i++)
+	// copy **lines array into *new_file
+	for(i = 0; i < total_num_lines; i++)
 	{
 		for(j = 0; lines[i][j] != '\0'; j++)
-			newfile[nfposn++] = lines[i][j];
+			new_file[nfposn++] = lines[i][j];
 
 		g_free(lines[i]);
 	}
-	newfile[nfposn] = '\0';
-	sci_set_text(doc->editor->sci, newfile);	// set new document
+	new_file[nfposn] = '\0';
+	sci_set_text(doc->editor->sci, new_file);	// set new document
 
 
 



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


More information about the Plugins-Commits mailing list