Branch: refs/heads/master Author: Sylvan Mostert smostert.dev@gmail.com Committer: Sylvan Mostert smostert.dev@gmail.com Date: Fri, 09 Sep 2016 05:48:18 UTC Commit: 11800f4889bf0a060d8b00a3b8e7fd47910fe6f4 https://github.com/geany/geany-plugins/commit/11800f4889bf0a060d8b00a3b8e7fd...
Log Message: ----------- lineoperations: minor formatting
Removed unreachable sci operation.
Modified Paths: -------------- lineoperations/src/linefunctions.c lineoperations/src/lineoperations.c
Modified: lineoperations/src/linefunctions.c 63 lines changed, 48 insertions(+), 15 deletions(-) =================================================================== @@ -40,12 +40,13 @@ compare_desc(const void * a, const void * b)
/* Remove Duplicate Lines, sorted */ -void +gint rmdupst(gchar **lines, gint num_lines, gchar *new_file) { - gchar *nf_end = new_file; /* points to last char of new_file */ - gchar *lineptr = (gchar *)""; /* temporary line pointer */ - gint i = 0; /* iterator */ + gchar *nf_end = new_file; /* points to last char of new_file */ + gchar *lineptr = (gchar *)" "; /* temporary line pointer */ + gint i = 0; /* iterator */ + gint changed = 0; /* number of lines removed */
/* sort **lines ascending */ qsort(lines, num_lines, sizeof(gchar *), compare_asc); @@ -55,21 +56,26 @@ rmdupst(gchar **lines, gint num_lines, gchar *new_file) { if(strcmp(lines[i], lineptr) != 0) { - lineptr = lines[i]; - nf_end = g_stpcpy(nf_end, lines[i]); + changed++; /* number of lines kept */ + lineptr = lines[i]; + nf_end = g_stpcpy(nf_end, lines[i]); } } + + /* return the number of lines deleted */ + return -(num_lines - changed); }
/* Remove Duplicate Lines, ordered */ -void +gint rmdupln(gchar **lines, gint num_lines, gchar *new_file) { gchar *nf_end = new_file; /* points to last char of new_file */ gint i = 0; /* iterator */ gint j = 0; /* iterator */ gboolean *to_remove = NULL; /* flag to 'mark' which lines to remove */ + gint changed = 0; /* number of lines removed */
/* allocate and set *to_remove to all FALSE @@ -96,21 +102,28 @@ rmdupln(gchar **lines, gint num_lines, gchar *new_file) /* copy **lines into 'new_file' if it is not FALSE (not duplicate) */ for(i = 0; i < num_lines; i++) if(!to_remove[i]) - nf_end = g_stpcpy(nf_end, lines[i]); + { + changed++; /* number of lines kept */ + nf_end = g_stpcpy(nf_end, lines[i]); + }
/* free used memory */ g_free(to_remove); + + /* return the number of lines deleted */ + return -(num_lines - changed); }
/* Remove Unique Lines */ -void +gint rmunqln(gchar **lines, gint num_lines, gchar *new_file) { gchar *nf_end = new_file; /* points to last char of new_file */ - gint i = 0; /* iterator */ - gint j = 0; /* iterator */ + gint i = 0; /* iterator */ + gint j = 0; /* iterator */ gboolean *to_remove = NULL; /* to 'mark' which lines to remove */ + gint changed = 0; /* number of lines removed */
/* allocate and set *to_remove to all TRUE @@ -133,17 +146,24 @@ rmunqln(gchar **lines, gint num_lines, gchar *new_file) /* copy **lines into 'new_file' if it is not FALSE(not duplicate) */ for(i = 0; i < num_lines; i++) if(!to_remove[i]) + { + changed++; /* number of lines kept */ nf_end = g_stpcpy(nf_end, lines[i]); + }
/* free used memory */ g_free(to_remove); + + /* return the number of lines deleted */ + return -(num_lines - changed); }
/* Remove Empty Lines */ -void +gint rmemtyln(ScintillaObject *sci, gint line_num, gint end_line_num) { + gint changed = 0; /* number of lines removed */
while(line_num <= end_line_num) /* loop through lines */ { @@ -158,17 +178,22 @@ rmemtyln(ScintillaObject *sci, gint line_num, gint end_line_num)
line_num--; end_line_num--; + changed++; } line_num++; } + + /* return the number of lines deleted */ + return -changed; }
/* Remove Whitespace Lines */ -void +gint rmwhspln(ScintillaObject *sci, gint line_num, gint end_line_num) { gint indent; /* indent position */ + gint changed = 0; /* number of lines removed */
while(line_num <= end_line_num) /* loop through lines */ { @@ -189,15 +214,19 @@ rmwhspln(ScintillaObject *sci, gint line_num, gint end_line_num)
line_num--; end_line_num--; + changed++; } line_num++;
} + + /* return the number of lines deleted */ + return -changed; }
/* Sort Lines Ascending */ -void +gint sortlnsasc(gchar **lines, gint num_lines, gchar *new_file) { gchar *nf_end = new_file; /* points to last char of new_file */ @@ -208,11 +237,13 @@ sortlnsasc(gchar **lines, gint num_lines, gchar *new_file) /* join **lines into one string (new_file) */ for(i = 0; i < num_lines; i++) nf_end = g_stpcpy(nf_end, lines[i]); + + return num_lines; }
/* Sort Lines Descending */ -void +gint sortlndesc(gchar **lines, gint num_lines, gchar *new_file) { gchar *nf_end = new_file; /* points to last char of new_file */ @@ -223,4 +254,6 @@ sortlndesc(gchar **lines, gint num_lines, gchar *new_file) /* join **lines into one string (new_file) */ for(i = 0; i < num_lines; i++) nf_end = g_stpcpy(nf_end, lines[i]); + + return num_lines; }
Modified: lineoperations/src/lineoperations.c 22 lines changed, 11 insertions(+), 11 deletions(-) =================================================================== @@ -58,18 +58,18 @@ select_lines(GeanyEditor *editor, struct lo_lines sel) static struct lo_lines get_current_sel_lines(ScintillaObject *sci) { - struct lo_lines sel = { 0, 0 }; + struct lo_lines sel = { FALSE, 0, 0 }; gint start_posn = 0; /* position of selection start */ gint end_posn = 0; /* position of selection end */
/* check for selection */ if(sci_has_selection(sci)) { - /* get the start and end positions */ + /* get the start and end *positions* */ start_posn = sci_get_selection_start(sci); end_posn = sci_get_selection_end (sci);
- /* get the line number of those positions */ + /* get the *line number* of those positions */ sel.start_line = scintilla_send_message(sci, SCI_LINEFROMPOSITION, start_posn, 0); @@ -106,6 +106,8 @@ ensure_final_newline(GeanyEditor *editor, gint *num_lines, struct lo_lines *sel) { const gchar *eol = editor_get_eol_char(editor); sci_insert_text(editor->sci, end_document, eol); + + /* re-adjust the selection */ (*num_lines)++; (*sel).end_line++; } @@ -123,9 +125,9 @@ user_indicate(GeanyEditor *editor, gint lines_affected, struct lo_lines sel)
/* select lines to indicate to user what lines were altered */ sel.end_line += lines_affected; - + if(sel.is_selection) - select_lines(editor, sel); + select_lines(editor, sel); } else if(lines_affected == 0) { @@ -142,7 +144,7 @@ user_indicate(GeanyEditor *editor, gint lines_affected, struct lo_lines sel)
/* select lines to indicate to user what lines were altered */ if(sel.is_selection) - select_lines(editor, sel); + select_lines(editor, sel); } }
@@ -184,7 +186,7 @@ action_indir_manip_item(GtkMenuItem *menuitem, gpointer gdata) gchar *new_file = g_malloc(sizeof(gchar) * (num_chars + 1)); new_file[0] = '\0';
- /* select lines to indicate to user what lines were altered */ + /* select lines that will be replaced with array */ select_lines(doc->editor, sel);
sci_start_undo_action(doc->editor->sci); @@ -195,11 +197,9 @@ action_indir_manip_item(GtkMenuItem *menuitem, gpointer gdata)
/* set new document */ - if(sci_has_selection(doc->editor->sci)) - sci_replace_sel(doc->editor->sci, new_file); - else - sci_set_text(doc->editor->sci, new_file); + sci_replace_sel(doc->editor->sci, new_file);
+ /* select affected lines and set statusbar message */ user_indicate(doc->editor, lines_affected, sel);
sci_end_undo_action(doc->editor->sci);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).