mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Apply the BSD echo version submitted by Jonas Holmberg <jonas.holmberg@axis.com>
This commit is contained in:
parent
ddea368dbe
commit
8fff78d66e
@ -28,47 +28,86 @@
|
|||||||
extern int
|
extern int
|
||||||
echo_main(int argc, char** argv)
|
echo_main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
register char **ap;
|
|
||||||
char *p;
|
|
||||||
int c;
|
|
||||||
int nflag = 0;
|
int nflag = 0;
|
||||||
int eflag = 0;
|
int eflag = 0;
|
||||||
|
|
||||||
|
/* Skip argv[0]. */
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "neE")) != EOF) {
|
while (argc > 0 && *argv[0] == '-')
|
||||||
switch (c) {
|
{
|
||||||
case 'n':
|
register char *temp;
|
||||||
nflag = 1;
|
register int index;
|
||||||
break;
|
|
||||||
case 'e':
|
/*
|
||||||
eflag = 1;
|
* If it appears that we are handling options, then make sure
|
||||||
break;
|
* that all of the options specified are actually valid.
|
||||||
case 'E':
|
* Otherwise, the string should just be echoed.
|
||||||
eflag = 0;
|
*/
|
||||||
break;
|
temp = argv[0] + 1;
|
||||||
default:
|
|
||||||
usage(echo_usage);
|
for (index = 0; temp[index]; index++)
|
||||||
|
{
|
||||||
|
if (strrchr("neE", temp[index]) == 0)
|
||||||
|
goto just_echo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!*temp)
|
||||||
|
goto just_echo;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* All of the options in temp are valid options to echo.
|
||||||
|
* Handle them.
|
||||||
|
*/
|
||||||
|
while (*temp)
|
||||||
|
{
|
||||||
|
if (*temp == 'n')
|
||||||
|
nflag = 1;
|
||||||
|
else if (*temp == 'e')
|
||||||
|
eflag = 1;
|
||||||
|
else if (*temp == 'E')
|
||||||
|
eflag = 0;
|
||||||
|
else
|
||||||
|
goto just_echo;
|
||||||
|
|
||||||
|
temp++;
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ap = &argv[optind];
|
just_echo:
|
||||||
while ((p = *ap++) != NULL) {
|
while (argc > 0) {
|
||||||
while ((c = *p++) != '\0') {
|
char *arg = argv[0];
|
||||||
if (c == '\\' && eflag) {
|
register int c;
|
||||||
if (*p == 'c')
|
|
||||||
exit(0);
|
while ((c = *arg++)) {
|
||||||
else
|
|
||||||
c = process_escape_sequence(&p);
|
/* Check for escape sequence. */
|
||||||
|
if (c == '\\' && eflag && *arg) {
|
||||||
|
if (*arg == 'c') {
|
||||||
|
/* '\c' means cancel newline. */
|
||||||
|
nflag = 1;
|
||||||
|
arg++;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
c = process_escape_sequence(&arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar(c);
|
putchar(c);
|
||||||
}
|
}
|
||||||
if (*ap)
|
argc--;
|
||||||
|
argv++;
|
||||||
|
if (argc > 0)
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
}
|
}
|
||||||
if (! nflag)
|
if (!nflag)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return( 0);
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
@ -90,6 +129,7 @@ echo_main(int argc, char** argv)
|
|||||||
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
||||||
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
||||||
*
|
*
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
* 4. Neither the name of the University nor the names of its contributors
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
@ -108,5 +148,3 @@ echo_main(int argc, char** argv)
|
|||||||
*
|
*
|
||||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
96
echo.c
96
echo.c
@ -28,47 +28,86 @@
|
|||||||
extern int
|
extern int
|
||||||
echo_main(int argc, char** argv)
|
echo_main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
register char **ap;
|
|
||||||
char *p;
|
|
||||||
int c;
|
|
||||||
int nflag = 0;
|
int nflag = 0;
|
||||||
int eflag = 0;
|
int eflag = 0;
|
||||||
|
|
||||||
|
/* Skip argv[0]. */
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "neE")) != EOF) {
|
while (argc > 0 && *argv[0] == '-')
|
||||||
switch (c) {
|
{
|
||||||
case 'n':
|
register char *temp;
|
||||||
nflag = 1;
|
register int index;
|
||||||
break;
|
|
||||||
case 'e':
|
/*
|
||||||
eflag = 1;
|
* If it appears that we are handling options, then make sure
|
||||||
break;
|
* that all of the options specified are actually valid.
|
||||||
case 'E':
|
* Otherwise, the string should just be echoed.
|
||||||
eflag = 0;
|
*/
|
||||||
break;
|
temp = argv[0] + 1;
|
||||||
default:
|
|
||||||
usage(echo_usage);
|
for (index = 0; temp[index]; index++)
|
||||||
|
{
|
||||||
|
if (strrchr("neE", temp[index]) == 0)
|
||||||
|
goto just_echo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!*temp)
|
||||||
|
goto just_echo;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* All of the options in temp are valid options to echo.
|
||||||
|
* Handle them.
|
||||||
|
*/
|
||||||
|
while (*temp)
|
||||||
|
{
|
||||||
|
if (*temp == 'n')
|
||||||
|
nflag = 1;
|
||||||
|
else if (*temp == 'e')
|
||||||
|
eflag = 1;
|
||||||
|
else if (*temp == 'E')
|
||||||
|
eflag = 0;
|
||||||
|
else
|
||||||
|
goto just_echo;
|
||||||
|
|
||||||
|
temp++;
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ap = &argv[optind];
|
just_echo:
|
||||||
while ((p = *ap++) != NULL) {
|
while (argc > 0) {
|
||||||
while ((c = *p++) != '\0') {
|
char *arg = argv[0];
|
||||||
if (c == '\\' && eflag) {
|
register int c;
|
||||||
if (*p == 'c')
|
|
||||||
exit(0);
|
while ((c = *arg++)) {
|
||||||
else
|
|
||||||
c = process_escape_sequence(&p);
|
/* Check for escape sequence. */
|
||||||
|
if (c == '\\' && eflag && *arg) {
|
||||||
|
if (*arg == 'c') {
|
||||||
|
/* '\c' means cancel newline. */
|
||||||
|
nflag = 1;
|
||||||
|
arg++;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
c = process_escape_sequence(&arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar(c);
|
putchar(c);
|
||||||
}
|
}
|
||||||
if (*ap)
|
argc--;
|
||||||
|
argv++;
|
||||||
|
if (argc > 0)
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
}
|
}
|
||||||
if (! nflag)
|
if (!nflag)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return( 0);
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
@ -90,6 +129,7 @@ echo_main(int argc, char** argv)
|
|||||||
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
||||||
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
||||||
*
|
*
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
* 4. Neither the name of the University nor the names of its contributors
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
@ -108,5 +148,3 @@ echo_main(int argc, char** argv)
|
|||||||
*
|
*
|
||||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user