menu: simplify usage for clients
[barebox-mini2440.git] / lib / process_escape_sequence.c
blob546edaa01fb88afd540170d8a6377a717fe3e7ff
1 /*
2 * process_esacpe_sequence.c
4 * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
6 * See file CREDITS for list of people who contributed to this
7 * project.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <common.h>
23 #include <fs.h>
25 int process_escape_sequence(const char *source, char *dest, int destlen)
27 int i = 0;
29 while (*source) {
30 if (*source == '\\') {
31 switch (*(source + 1)) {
32 case 0:
33 return 0;
34 case '\\':
35 dest[i++] = '\\';
36 break;
37 case 'a':
38 dest[i++] = '\a';
39 break;
40 case 'b':
41 dest[i++] = '\b';
42 break;
43 case 'n':
44 dest[i++] = '\n';
45 break;
46 case 'r':
47 dest[i++] = '\r';
48 break;
49 case 't':
50 dest[i++] = '\t';
51 break;
52 case 'f':
53 dest[i++] = '\f';
54 break;
55 case 'e':
56 dest[i++] = 0x1b;
57 break;
58 case 'h':
59 i += snprintf(dest + i, destlen - i, "%s", CONFIG_BOARDINFO);
60 break;
61 case 'w':
62 i += snprintf(dest + i, destlen - i, "%s", getcwd());
63 break;
64 default:
65 dest[i++] = '\\';
66 dest[i++] = *(source + 1);
68 source++;
69 } else
70 dest[i++] = *source;
71 source++;
72 if (!(destlen - i))
73 break;
75 dest[i] = 0;
76 return 0;