/*
 * Copyright © 1994-1996 Marko Mäkelä and Olaf Seibert
 * Original Linux and Commodore 64/128/Vic-20 version by Marko Mäkelä
 * Ported to the PET and the Amiga series by Olaf Seibert
 *
 *     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 2 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, write to the Free Software
 *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <stdlib.h>

#include "prtrans.h"

void
getname(char *dest, char *env_file, char *def_file)
{
    char *dir, *file;

    dir = getenv("PRLINKDIR");
    if (dir == NULL)
	dir = "";
    file = getenv(env_file);
    if (file == NULL)
	file = def_file;
    sprintf(dest, "%s%s", dir, file);
}

/*
 * only deal with letters in upper/lowercase character set.
 * a-z = 0x41 - 0x5A
 * A-Z = 0xC1 - 0xDA
 * Punctuation 0x20 - 0x3F and 0x5B - 0x5F is virtually identical.
 */

void
ascii2petscii(unsigned char *p)
{
  while (p[0]) {
    if (p[0] == '\n') {
      p[0] = 13;
    } else if (p[0] >= 'A' && p[0] <= 'Z') {
      p[0] += -'A' + 0x41 + 0x80;
    } else if (p[0] >= 'a' && p[0] <= 'z') {
      p[0] += -'a' + 0x41;
    }
    p++;
  }
}

void
petscii2ascii(unsigned char *p)
{
  while (p[0]) {
    if (p[0] == 13) {
      p[0] = '\n';
    } else if (p[0] >= 0xC1 && p[0] <= 0xDA) {
      p[0] -= -'A' + 0x41 + 0x80;
    } else if (p[0] >= 0x41 && p[0] <= 0x5A) {
      p[0] -= -'a' + 0x41;
    }
    p++;
  }
}
