/***************************************************************************
 *   Copyright (C) 2004 by Christian Bucher                                *
 *   christian.bucher@amadyne.net                                          *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

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

#define  SRC_STRING_SIZE  1024
#define  DEST_STRING_SIZE (SRC_STRING_SIZE * 2)
// der Leet wird ja grösser
 
#include "stringutils.h"

// angelehnt an strncpy()
void leetXlate(char *dest, const char *src, size_t n);

int main(int argc, char *argv[])
{
  
  int i;
  char eingabe[SRC_STRING_SIZE];
  char ausgabe[DEST_STRING_SIZE];
  
  printf("Was soll uebersetzt werden: ");
  
  // Nein, wier SOLLEN diese Funktion EIGENTLICH  nicht verwenden :-)
  gets(eingabe); 
  
  leetXlate(ausgabe, eingabe, DEST_STRING_SIZE);
  
  printf("\nÜbersetzung: %s\n", ausgabe);
  
  return 0;
}

void leetXlate(char *dest, const char *src, size_t n)
{
int i;
char szHelp[4];

  // WICHTIG: Sicherstellen, dass dest LEER ist:
  dest[0] = '\0';
  
  // Hilfsstring nach einem Buchstaben terminieren (siehe default:)
  szHelp[1] = '\0';
  
  for (i = 0; src[i]; i++)
    {
    switch(toupper(src[i]))
      {
      case 'A':
        fh_strnscat(dest, "4", n);
        break;
      
      case 'C':
        // Sonderfall CK wird zu "x0"
        if ('K' == toupper(src[i+1]))
          {
          fh_strnscat(dest, "x0", n);
          i++;
          }
        else
          fh_strnscat(dest, "(", n);
        break;
        
      case 'E':
        fh_strnscat(dest, "3", n);
        break;
      case 'G':
        fh_strnscat(dest, "6", n);
        break;
      case 'I':
        fh_strnscat(dest, "|", n);
        break;
      case 'K':
        fh_strnscat(dest, "|<", n);
        break;
      case 'L':
        fh_strnscat(dest, "1", n);
        break;
      case 'M':
        fh_strnscat(dest, "|\\/|", n);
        break;
      case 'N':
        fh_strnscat(dest, "|\\|", n);
        break;
      case 'O':
        fh_strnscat(dest, "0", n);
        break;
      
      case 'S':
        // Sonderfall "s" am Wortende wird zu "z"
        if (' ' == src[i+1])
          fh_strnscat(dest, "z", n);
        else  
          fh_strnscat(dest, "5", n);
        break;
      case 'T':
        fh_strnscat(dest, "7", n);
        break;
      case 'V':
        fh_strnscat(dest, "\\/", n);
        break;
      case 'W':
        fh_strnscat(dest, "uu", n);
        break;
      case 'X':
        fh_strnscat(dest, "><", n);
        break;
        
      default:
        // hier müssen wir einen Hilfsstring erzeugen...
        szHelp[0] = src[i];
        fh_strnscat(dest, szHelp, n);
      }        
  }  
}

syntax highlighted by Code2HTML, v. 0.9.1