Skip to content

Commit 4908767

Browse files
committed
[editors/ed] implement ! command
As far as i know, this is the last missing command here. I could contribute these to upstream BusyBox-W32, but i am not yet sure.
1 parent 04521f3 commit 4908767

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

editors/ed.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,37 @@ static void subCommand(const char *cmd, int num1, int num2)
794794
bb_error_msg("no substitutions found for \"%s\"", oldStr);
795795
}
796796

797+
/*
798+
* Execute a shell command.
799+
* Returns TRUE if successful.
800+
*/
801+
static int doShellEscape(const char *cmd)
802+
{
803+
int status;
804+
805+
const char *shell_cmd = skip_whitespace(cmd);
806+
807+
if (*shell_cmd == '\0') {
808+
bb_simple_error_msg("missing shell command");
809+
return FALSE;
810+
}
811+
812+
// Use system() to execute the command via the shell
813+
status = system(shell_cmd);
814+
815+
if (status == -1) {
816+
bb_simple_perror_msg("system call failed");
817+
return FALSE;
818+
}
819+
820+
// Print '!' again after the command finishes
821+
if (!(option_mask32 & OPT_s)) {
822+
puts("!");
823+
}
824+
825+
return TRUE;
826+
}
827+
797828
/*
798829
* Read commands until we are told to stop.
799830
*/
@@ -910,6 +941,10 @@ static void doCommands(void)
910941
printLines(num1, num2, FALSE, 1);
911942
break;
912943

944+
case '!':
945+
doShellEscape(cp);
946+
break;
947+
913948
case 'q':
914949
cp = skip_whitespace(cp);
915950
if (have1 || *cp) {

0 commit comments

Comments
 (0)