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

#include "../global.h"

#define SPACE_SUBSTITUTE ':'
#define QUOTE_SUBSTITUTE '!'
#define APOS_SUBSTITUTE   '|'

void
escape_realname(char *escaped_realname, const char *realname)
{
 char *ptr;
 
 strncpy(escaped_realname, realname, MAX_NAME + 1);
 for(ptr=escaped_realname; *ptr; ptr++)
  switch(*ptr)
   {
    case ' ': *ptr = SPACE_SUBSTITUTE; break;
    case '"': *ptr = QUOTE_SUBSTITUTE; break;
    case '\'' : *ptr = APOS_SUBSTITUTE; break;
    default: break;
   }
}



void
unescape_realname(char *unescaped_realname, const char *realname)
{
 char *ptr;
 
 strncpy(unescaped_realname, realname, MAX_NAME + 1);
 for(ptr=unescaped_realname; *ptr; ptr++)
  switch(*ptr)
   {
    case SPACE_SUBSTITUTE: *ptr = ' '; break;
    case QUOTE_SUBSTITUTE: *ptr = '"'; break;
    case APOS_SUBSTITUTE:  *ptr = '\''; break;
    default: break;
   }
}



