1  /* echon.c - 2011-05-07
 2  The program displays a formated text in command-line.
 3  Update: http://myc01.free.fr/echon
 4  
 5  Licence: Common Public License Version 1.0 (CPL)
 6    http://www.opensource.org/licenses/cpl1.0.php
 7  
 8  Changelog:
 9  v1.1 - 2011-05-07
10    * change '//X' to '//X '
11  v1.0 - 2011-04-10
12    * initial version
13  */
14  
15  #include <windows.h>
16  #include <stdio.h>
17  
18  #define PROG_NAME  "Echon"
19  #define PROG_VERS  "1.1"
20  #define PROG_DATE  "2011-05-07"
21  #define PROG_LIC   "Public Domain Dedication (CC0 1.0)"
22  
23  
24  char* replace (char* szDst, const char* szOld, const char* szNew)
25  {
26      int nOld = strlen (szOld);
27      int nNew = strlen (szNew);
28  
29      if (!nOld) return szDst;
30  
31      char* szCurrent = szDst;
32      while ( (szCurrent = strstr (szCurrent, szOld)))
33      {
34          memmove (szCurrent + nNew, szCurrent + nOld, strlen (szCurrent + nOld) + 1);
35          memcpy  (szCurrent, szNew, nNew);
36          szCurrent += nNew;
37      }
38  
39      return szDst;
40  }  /* replace */
41  
42  
43  int main (int argc, char *argv[])
44  {
45      char *p, *c;
46  
47      if (argc < 2)
48      {
49          puts (PROG_NAME" v"PROG_VERS" ("PROG_DATE") - License: "PROG_LIC);
50          puts ("Usage: echon.exe text1 [//t ] text2 [//b ] [//n ] [//a ]\n"
51                "  '//a ' = sound signal (beep)\n"
52                "  '//b ' = back (backspace)\n"
53                "  '//n ' = newline\n"
54                "  '//t ' = tab");
55          return 1;
56      }
57  
58      c = GetCommandLine ();
59      p = strstr (c, argv[0]);
60      p += strlen (argv[0]) + (p - c) + 1;
61      replace (p, "//a ", "\a");
62      replace (p, "//b ", "\b");
63      replace (p, "//n ", "\n");
64      replace (p, "//t ", "\t");
65      CharToOem (p, p);
66      printf (p);
67  
68      return 0;
69  }  /* main */