Beispiel #1
0
/*
 * pdc_convert_filename_ext converts a file name as string of name type
 * (see function pdc_convert_name_ext) to a [EBCDIC-]UTF-8 string with or
 * without a BOM. If the compiler doesn't allow Unicode filenames
 * (see define PDC_UNICODE_FILENAME) the filename is Latin-1 encoded
 * if possible or an exception will be thrown.
 *
 * Returned string is temporary allocated.
 *
 */
const char *
pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len,
                         const char *paramname, pdc_encoding enc, int codepage,
                         int flags)
{
    char *fname = NULL;
    const char *outfilename = NULL;
    int i = 0;

    if (filename == NULL)
        pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0);

    /* temporary allocation will be enforced */
    flags |= PDC_CONV_TMPALLOC;

    fname = pdc_convert_name_ext(pdc, filename, len, enc, codepage, flags);

    if (fname == NULL || *fname == '\0')
        pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0);

    if (pdc_is_utf8_bytecode(fname))
    {
#if defined(PDC_UNICODE_FILENAME)
        i = 3;
#else
        fname = pdc_check_filename(pdc, fname);
#endif
    }

    outfilename = &fname[i];
    return outfilename;
}
Beispiel #2
0
/*
 * pdc_convert_filename_ext converts a file name as string of name type
 * (see function pdc_convert_name) to a [EBCDIC-]UTF-8 string with or
 * without a BOM. If the compiler doesn't allow Unicode filenames
 * (see define PDC_UNICODE_FILENAME) the filename is Latin-1 encoded
 * if possible or an exception will be thrown.
 *
 */
const char *
pdc_convert_filename_ext(pdc_core *pdc, const char *filename, int len,
                         const char *paramname, pdc_encoding enc, int codepage,
                         int flags)
{
    char *fname = NULL;
    const char *outfilename = NULL;
    int i = 0;

    if (filename == NULL)
        pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0);

    fname = pdc_convert_name_ext(pdc, filename, len, enc, codepage, flags);

    if (fname == NULL || *fname == '\0')
        pdc_error(pdc, PDC_E_ILLARG_EMPTY, paramname, 0, 0, 0);

    if (pdc_is_utf8_bytecode(fname))
    {
#if defined(PDC_UNICODE_FILENAME)
        i = 3;
#else
        fname = pdc_check_filename(pdc, fname);
#endif
    }

    outfilename = pdc_errprintf(pdc, "%s", &fname[i]);
    pdc_free(pdc, fname);

    return outfilename;
}
Beispiel #3
0
char *
pdf_convert_name(PDF *p, const char *name, int len, int flags)
{
    char *resname;
    char *newname;
    int newlen;
    pdc_encoding htenc;
    int htcp;

    pdf_prepare_name_string(p, name, len, PDC_SHRT_MAX,
                            &newname, &newlen, &htenc, &htcp);

    flags |= PDC_CONV_EBCDIC;
    if (pdc_logg_is_enabled(p->pdc, 3, trc_text))
        flags |= PDC_CONV_LOGGING;

    resname = pdc_convert_name_ext(p->pdc, newname, newlen, htenc, htcp, flags);
    if (newname != name)
        pdc_free(p->pdc, newname);

    return resname;
}