Skip to content

Commit

Permalink
split: ignore blank lines when IgnoreBlanks is selected.
Browse files Browse the repository at this point in the history
--ignore-blanks should ignore blank lines as well as spaces and tabs.

We don't ignore all newline characters, only those at the end of blank
lines.  We do this even in "line" mode.

This addresses github issue #27.

Signed-off-by: NeilBrown <[email protected]>
  • Loading branch information
neilbrown committed Jul 23, 2024
1 parent d86d2b8 commit 2e44491
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
34 changes: 32 additions & 2 deletions split.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* second from the end.
*
* We make two passes through the stream.
* Firstly we count the number of item so an array can be allocated,
* Firstly we count the number of items so an array can be allocated,
* then we store start and length of each item in the array
*
*/
Expand All @@ -53,17 +53,31 @@ static int wiggle_split_internal(char *start, char *end, int type,
struct elmnt *list)
{
int cnt = 0;
int sol = 1;

while (start < end) {
char *cp = start;
char *cp2;
int prefix = 0;

if (sol && (type & IgnoreBlanks)) {
/* Skip blank lines */
while (*cp == ' ' || *cp == '\t' || *cp == '\n') {
if (*cp == '\n') {
prefix += cp+1 - start;
start = cp+1;
}
sol = *cp == '\n';
cp += 1;
}
cp = start;
}
if ((type & ByWord) && (type & IgnoreBlanks))
while (cp < end &&
(*cp == ' ' || *cp == '\t')) {
prefix++;
cp++;
sol = 0;
}
start = cp;

Expand All @@ -78,6 +92,7 @@ static int wiggle_split_internal(char *start, char *end, int type,
cp++;
if (cp < end)
cp++;
sol = 1;
break;
case ByWord:
if (*cp == ' ' || *cp == '\t') {
Expand All @@ -98,16 +113,31 @@ static int wiggle_split_internal(char *start, char *end, int type,
|| *cp == '_'));
} else
cp++;
sol = cp[-1] == '\n';
break;
}
cp2 = cp;

if (sol && (type & IgnoreBlanks)) {
/* Skip blank lines */
char *cp3 = cp2;
while (*cp3 == ' ' || *cp3 == '\t' || *cp3 == '\n') {
if (*cp3 == '\n')
cp2 = cp3+1;
sol = *cp3 == '\n';
cp3 += 1;
}
}
if ((type & ByWord) && (type & IgnoreBlanks) &&
*start && *start != '\n')
while (cp2 < end &&
(*cp2 == ' ' || *cp2 == '\t' || *cp2 == '\n')) {
cp2++;
if (cp2[-1] == '\n')
if (cp2[-1] == '\n') {
sol = 1;
break;
}
sol = 0;
}
if (list) {
list->start = start;
Expand Down
53 changes: 53 additions & 0 deletions tests/contrib/termux-app/bmerge
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.termux.terminal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* The interface for communication between {@link TerminalSession} and its client. It is used to
* send callbacks to the client when {@link TerminalSession} changes or for sending other
* back data to the client like logs.
*/
public interface TerminalSessionClient {

void onTextChanged(@NonNull TerminalSession changedSession);

void onTitleChanged(@NonNull TerminalSession changedSession);

void onSessionFinished(@NonNull TerminalSession finishedSession);

void onCopyTextToClipboard(@NonNull TerminalSession session, String text);

void onPasteTextFromClipboard(@Nullable TerminalSession session);

void onBell(@NonNull TerminalSession session);

void onColorsChanged(@NonNull TerminalSession session);

void onTerminalCursorStateChange(boolean state);

void setTerminalShellPid(@NonNull TerminalSession session, int pid);



Integer getTerminalCursorStyle();

boolean shouldEnableDarkTheme();



void logError(String tag, String message);

void logWarn(String tag, String message);

void logInfo(String tag, String message);

void logDebug(String tag, String message);

void logVerbose(String tag, String message);

void logStackTraceWithMessage(String tag, String message, Exception e);

void logStackTrace(String tag, Exception e);

}
51 changes: 51 additions & 0 deletions tests/contrib/termux-app/orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.termux.terminal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* The interface for communication between {@link TerminalSession} and its client. It is used to
* send callbacks to the client when {@link TerminalSession} changes or for sending other
* back data to the client like logs.
*/
public interface TerminalSessionClient {

void onTextChanged(@NonNull TerminalSession changedSession);

void onTitleChanged(@NonNull TerminalSession changedSession);

void onSessionFinished(@NonNull TerminalSession finishedSession);

void onCopyTextToClipboard(@NonNull TerminalSession session, String text);

void onPasteTextFromClipboard(@Nullable TerminalSession session);

void onBell(@NonNull TerminalSession session);

void onColorsChanged(@NonNull TerminalSession session);

void onTerminalCursorStateChange(boolean state);

void setTerminalShellPid(@NonNull TerminalSession session, int pid);



Integer getTerminalCursorStyle();



void logError(String tag, String message);

void logWarn(String tag, String message);

void logInfo(String tag, String message);

void logDebug(String tag, String message);

void logVerbose(String tag, String message);

void logStackTraceWithMessage(String tag, String message, Exception e);

void logStackTrace(String tag, Exception e);

}
13 changes: 13 additions & 0 deletions tests/contrib/termux-app/patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/terminal-emulator/src/main/java/com/termux/terminal/TerminalSessionClient.java b/terminal-emulator/src/main/java/com/termux/terminal/TerminalSessionClient.java
index f6f6fdcc2d78..3531173032b4 100644
--- a/terminal-emulator/src/main/java/com/termux/terminal/TerminalSessionClient.java
+++ b/terminal-emulator/src/main/java/com/termux/terminal/TerminalSessionClient.java
@@ -30,6 +30,8 @@ public interface TerminalSessionClient {

Integer getTerminalCursorStyle();

+ boolean shouldEnableDarkTheme();
+
void logError(String tag, String message);

void logWarn(String tag, String message);

0 comments on commit 2e44491

Please sign in to comment.