Exemplo n.º 1
0
static void kbd_buf_parse_string(const char *string)
{
    unsigned int i, j;
    size_t len;

    len = strlen(string);

    if (len > QUEUE_SIZE) {
        len = QUEUE_SIZE;
    }

    kbd_buf_string = lib_realloc(kbd_buf_string, len + 1);
    memset(kbd_buf_string, 0, len + 1);

    for (i = 0, j = 0; i < len; i++) {
        if (string[i] == '\\') {
            /* printf("esc:%s\n", &string[i]); */
            if((i < (len - 1)) && (string[i + 1] == '\\')) {
                /* escaped backslash "\\" */
                kbd_buf_string[j] = charset_p_topetcii('\\');
                i += 1;
                j++;
            } else if((i < (len - 1)) && (string[i + 1] == 'n')) {
                /* escaped line ending "\n" */
                kbd_buf_string[j] = charset_p_topetcii('\n');
                i += 1;
                j++;
            } else if((i < (len - 3)) && (string[i + 1] == 'x') && isxdigit((int)string[i + 2]) && isxdigit((int)string[i + 3])) {
                /* escaped hex value in c-style format "\x00" */
                char hexvalue[3];

                hexvalue[0] = string[i + 2];
                hexvalue[1] = string[i + 3];
                hexvalue[2] = '\0';

                kbd_buf_string[j] = (char)strtol(hexvalue, NULL, 16);
                i += 3;
                j++;
            }
        } else {
            /* printf("chr:%s\n", &string[i]); */
            /* regular character, convert to petscii */
            kbd_buf_string[j] = charset_p_topetcii(string[i]);
            j++;
        }
    }
}
Exemplo n.º 2
0
BYTE *charset_petconvstring(BYTE *c, int dir)
{
    BYTE *s = c, *d = c;
    int ch;

    switch (dir) {
      case 0: /* To petscii.  */
        while (*s) {
            if ((ch = test_lineend(s))) {
                *d++ = 0x0d; /* petscii CR */
                s += ch;
            } else {
                *d++ = charset_p_topetcii(*s);
                s++;
            }
        }
        break;

      case 1: /* To ascii. */
        while (*s) {
            *d++ = charset_p_toascii(*s, 0);
            s++;
        }
        break;

      case 2: /* To ascii, convert also screencodes. */
        while (*s) {
            *d++ = charset_p_toascii(*s, 1);
            s++;
        }
        break;
      default:
        log_error(LOG_DEFAULT, "Unkown conversion rule.");
    }

    *d = 0;

    return c;
}