72 lines
1.2 KiB
C
72 lines
1.2 KiB
C
/* echo -- version one */
|
|
/* program to print its argument vector to stdout */
|
|
/* mostly SUS compliant */
|
|
|
|
|
|
#include "support.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int i, i2;
|
|
char escape = 0;
|
|
|
|
if(argc > 1)
|
|
for(i = 1; i < argc; i++)
|
|
{
|
|
for(i2 = 0; argv[i][i2] != '\0'; i2++)
|
|
{
|
|
if(escape)
|
|
switch(argv[i][i2])
|
|
{
|
|
case 'a':
|
|
escape = 0;
|
|
putchar('\a');
|
|
break;
|
|
case 'b':
|
|
escape = 0;
|
|
putchar('\b');
|
|
break;
|
|
case 'c': // Immediately stop execution.
|
|
goto end;
|
|
case 'f':
|
|
escape = 0;
|
|
putchar('\f');
|
|
break;
|
|
case 'n':
|
|
escape = 0;
|
|
putchar('\n');
|
|
break;
|
|
case 'r':
|
|
escape = 0;
|
|
putchar('\r');
|
|
break;
|
|
case 't':
|
|
escape = 0;
|
|
putchar('\t');
|
|
break;
|
|
case 'v':
|
|
escape = 0;
|
|
putchar('\v');
|
|
break;
|
|
case '\\':
|
|
escape = 0;
|
|
putchar('\\');
|
|
break;
|
|
case '0': // This is for octal values.
|
|
break;
|
|
}
|
|
else if(argv[i][i2] == '\\')
|
|
escape++;
|
|
else
|
|
putchar(argv[i][i2]);
|
|
}
|
|
if(i < (argc-1))
|
|
putchar(' ');
|
|
}
|
|
putchar('\n');
|
|
|
|
end:
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
o
|