1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#ifdef RCSID
static char RCSid[] =
"$Header$";
#endif
/*
* Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved.
*
* Please see the accompanying license file, LICENSE.TXT, for information
* on using and copying this software.
*/
/*
Name
askf_os.cpp - OS-dialog-based implementation of askfile
Function
Implements file dialog using the OS-provided file dialog
Notes
Only one of askf_tx.c or askf_os.c should be included in a given
executable. For a text-only version, include askf_tx. For a version
where os_askfile() provides a file dialog, use askf_os instead.
We provide a choice of tio_askfile() implementations in the portable
code (rather than only through the OS code) so that we can call
the formatted text output routines in this version. An OS-layer
implementation could not call the formatted output routines (it would
have to call os_printf directly), which would result in poor prompt
formatting any time a prompt exceeded a single line of text.
Modified
09/27/99 MJRoberts - Creation
*/
#include "os.h"
#include "t3std.h"
#include "vmglob.h"
#include "vmconsol.h"
#include "charmap.h"
/*
* formatted text-only file prompt
*/
int CVmConsole::askfile(VMG_ const char *prompt, size_t prompt_len,
char *reply, size_t replen,
int dialog_type, os_filetype_t file_type,
int /*bypass_script*/)
{
int result;
size_t prompt_ui_len;
char prompt_ui[256];
char fname[OSFNMAX];
/* flush any pending output */
flush(vmg_ VM_NL_INPUT);
/* translate the prompt to the local UI character set */
prompt_ui_len = G_cmap_to_ui->map_utf8(prompt_ui, sizeof(prompt_ui) - 1,
prompt, prompt_len, 0);
/* null-terminate the translated prompt */
prompt_ui[prompt_ui_len] = '\0';
/* let the system handle it */
result = os_askfile(prompt, fname, sizeof(fname),
dialog_type, file_type);
/* if we were successful, translate the filename to UTF-8 */
if (result == OS_AFE_SUCCESS)
{
char *dst;
size_t dstlen;
/*
* The result string is in the local UI character set, so we
* must translate it to UTF-8 for the caller. Note that we
* reserve one byte of the result buffer for the null
* terminator.
*/
dst = reply;
dstlen = replen - 1;
G_cmap_from_ui->map(&dst, &dstlen, fname, strlen(fname));
/* null-terminate the result */
*dst = '\0';
}
/* return the result */
return result;
}
|