home *** CD-ROM | disk | FTP | other *** search
- #include <stream.h>
- #include <string.h>
-
-
- void usage ()
- {
- cout << "\ncout (c) by Harald Pehl in 1993\n"
- "Synthax: cout [string]\n"
- "Within the string you can use several control-characters\n\n"
- "\t\\a: Beep \\b: Backspace\n"
- "\t\\f: Form feed \\n: New line\n"
- "\t\\r: carrage return \\t: Tab\n"
- "\t\\v: Vertical-tab \\\\: print \'\\\'\n"
- "\t\\d: Bold on \\k: Italic on\n"
- "\t\\u: Underlined on \\i: Invers on\n"
- "\t\\x: Reset to defaults\n\n"
- "If there\'s no <string> cout prints an empty line.\n\n"
- }
-
-
- void main (int argc, char **argv)
- {
- if (argc == 2)
- {
- char *arg = *++argv;
-
- if (*arg == '?')
- {
- usage ();
- return;
- }
- char *str = 0;
- int a, s, size = strlen (arg);
-
- for (a = 0 ; a < size ; a++) // Calculate the length
- { // of arg = *++argv...
- if (*(arg+a) == 92)
- {
- switch (*(arg+a+1))
- {
- case 'd':
- case 'k':
- case 'u':
- case 'i':
- case 'x': size += 3;
- }
- }
- }
- str = new char[size]; // ...and ask for
- if (str == 0) // enough memory for
- { // the copy 'str'
- cout << "Zeichenkette zu lang !!\n";
- return;
- }
- for (a = 0, s = 0 ; a < size ; a++, s++) // Look for control-characters
- { // in arg and copy them to str
- if (*(arg+a) == 92)
- {
- switch (*(arg+a+1))
- {
- case 'a': *(str+s) = '\a'; a++; break;
- case 'b': *(str+s) = '\b'; a++; break;
- case 'f': *(str+s) = '\f'; a++; break;
- case 'n': *(str+s) = '\n'; a++; break;
- case 'r': *(str+s) = '\r'; a++; break;
- case 't': *(str+s) = '\t'; a++; break;
- case 'v': *(str+s) = '\v'; a++; break;
- case 92 : *(str+s) = '\\'; a++; break;
- case 'd': strcat (str, "\x9b""1m"); a++; s+=2; break;
- case 'k': strcat (str, "\x9b""3m"); a++; s+=2; break;
- case 'u': strcat (str, "\x9b""4m"); a++; s+=2; break;
- case 'i': strcat (str, "\x9b""7m"); a++; s+=2; break;
- case 'x': strcat (str, "\x9b""0m"); a++; s+=2; break;
- default : break;
- }
- }
- else
- *(str+s) = *(arg+a);
- }
- cout << str;
- delete [] str;
- }
- else if (argc == 1)
- cout << "\n";
- else
- usage ();
- }
-