/*
 *      _ s t r e a d d _ c
 *
 *  Support routine used by the strecpy() and streadd().
 *  Can alsobe used directly fromelsewhere withi the library.
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  29 Aug 94   DJW   - First version
 *
 *  24 Jan 95   DJW   - Missing 'const' keyword added to function definition.
 */

#define __LIBRARY__

#include <libgen.h>
#include <ctype.h>
#include <string.h>
#include <qdos.h>

char *  __streadd ( char *       output, 
                    const char * input,
                    const char * exceptions,
                    const char * escape)
{
    int c, i;

    do {
        c = (unsigned char)*input++;
        if (isprint(c))  {
            if (escape && (strchr(escape,c) != NULL)) {
                *output++ = '\\';
            }
            *output++ = (char)c;
            continue;
        }
        if (exceptions && strchr(exceptions, c)) {
            *output++ = (char)c;
            continue;
        }
        *output++ = '\\';
        if ((i=strpos((char *)_C_esc,c)) >= 0) {
            *output++ = _C_esc_a[i];
            continue;
        }
        *output++ = (char)('0' + (c >> 6));
        c &= 0x3f;
        *output++ = (char)('0' + (c >> 3));
        *output++ = (char)('0' + (c & 0x7));
    } while (*input);

    *output = '\0';
    return (output);
}

