/*
* Mimas conversion tools
*
* Copyright (C) 2010 Benjamin Moody
*
* This program is free software: you can redistribute it and/or
* modify 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 .
*/
#include
#include
#include
#include "utils.h"
#include "convert.h"
char *ti83p_to_ascii(const char *text)
{
int i, n;
char *s;
n = strlen(text);
s = xnew(char, n + 1);
for (i = 0; i < n; i++) {
if (text[i] == '[')
s[i] = '@';
else if (text[i] == '\301')
s[i] = '[';
else if (text[i] < ' ' || text[i] > '~')
s[i] = '?';
else
s[i] = text[i];
}
s[n] = 0;
return s;
}
char *ascii_to_ti83p(const char *text)
{
int i, n;
char *s;
n = strlen(text);
s = xnew(char, n + 1);
for (i = 0; i < n; i++) {
if (text[i] == '@')
s[i] = '[';
else if (text[i] == '[')
s[i] = '\301';
else if ((unsigned char) text[i] < ' ')
s[i] = ' ';
else if ((unsigned char) text[i] > '~')
s[i] = '?';
else
s[i] = text[i];
}
s[n] = 0;
return s;
}