utils.c revision a180a41bba1d50822df23fff0099e90b86638b89
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Generic utility functions
Copyright 2013 Henrik Andersson <hean01@cendio.se> for Cendio AB
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_ICONV_H
#include <iconv.h>
#endif
#include "rdesktop.h"
#ifdef HAVE_ICONV
extern char g_codepage[16];
#endif
char *
utils_string_escape(const char *str)
{
const char *p;
int cnt;
/* count indices */
cnt = 0;
p = str;
while (*(p++) != '\0')
if ((unsigned char) *p < 32 || *p == '%')
cnt++;
/* if no characters needs escaping return copy of str */
if (cnt == 0)
/* allocate new mem for result */
p = str;
while (*p != '\0')
{
if ((unsigned char) *p < 32 || *p == '%')
{
pe += 3;
}
else
{
*pe = *p;
pe++;
}
p++;
}
return e;
}
char *
utils_string_unescape(const char *str)
{
while (*ps != '\0')
{
/* check if found escaped character */
if (ps[0] == '%')
{
{
pd[0] = c;
ps += 3;
pd++;
continue;
}
}
/* just copy over the char */
ps++;
pd++;
}
pd[0] = '\0';
return ns;
}
int
{
int res = 0;
if (res == -1)
{
return -1;
}
return 0;
}
int
{
int res;
char *ptok;
{
return -1;
}
{
return -1;
}
res = 0;
do
{
if (res != 0)
return res;
}
return 0;
}
/* Convert from system locale string to utf-8 */
int
{
#ifdef HAVE_ICONV
goto pass_trough_as_is;
if (g_iconv_works == False)
goto pass_trough_as_is;
/* if not already initialize */
{
{
warning("utils_string_to_utf8: iconv_open[%s -> %s] fail %p\n",
goto pass_trough_as_is;
}
}
/* convert string */
{
goto pass_trough_as_is;
}
/* Out couldn't hold the entire convertion */
if (is != 0)
return -1;
#endif
/* can dest hold strcpy of src */
return -1;
return 0;
}