Skip to content

Commit

Permalink
"valid_codepage_name"
Browse files Browse the repository at this point in the history
  • Loading branch information
Fish-Git committed Nov 9, 2018
1 parent 51b5c79 commit 5bbec7e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
13 changes: 11 additions & 2 deletions codepage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,12 +1062,21 @@ static CPCONV *codepage_conv = cpconv;
DLL_EXPORT unsigned char *h2g_tab() { return codepage_conv->h2g; }
DLL_EXPORT unsigned char *g2h_tab() { return codepage_conv->g2h; }

DLL_EXPORT char * query_codepage(void)
DLL_EXPORT const char* query_codepage()
{
return codepage_conv->name;
}

DLL_EXPORT void set_codepage(char *name)
DLL_EXPORT bool valid_codepage_name( const char* name )
{
const CPCONV* cp;
for(cp = cpconv; cp->name; cp++)
if (strcasecmp( name, cp->name ) == 0)
return true;
return false;
}

DLL_EXPORT void set_codepage( const char* name )
{
int dflt = FALSE;

Expand Down
5 changes: 3 additions & 2 deletions codepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

#include "hercules.h"

COD_DLL_IMPORT char* query_codepage(void);
COD_DLL_IMPORT void set_codepage(char *name);
COD_DLL_IMPORT const char* query_codepage();
COD_DLL_IMPORT bool valid_codepage_name( const char* name );
COD_DLL_IMPORT void set_codepage( const char *name);
COD_DLL_IMPORT int update_codepage(int argc, char *argv[], char *table );
COD_DLL_IMPORT unsigned char host_to_guest (unsigned char byte);
COD_DLL_IMPORT unsigned char guest_to_host (unsigned char byte);
Expand Down
33 changes: 14 additions & 19 deletions hsccmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4158,39 +4158,34 @@ int cp_updt_cmd(int argc, char *argv[], char *cmdline)
/* codepage xxxxxxxx command *** KEEP AFTER CP_UPDT_CMD *** */
/* Note: maint can never be a code page name */
/*-------------------------------------------------------------------*/
int codepage_cmd(int argc, char *argv[], char *cmdline)
int codepage_cmd( int argc, char* argv[], char* cmdline )
{
char *cp;
int rc = 0;
int rc = 0;

UNREFERENCED(cmdline);
UNREFERENCED( cmdline );
UPPER_ARGV_0( argv );

/* passthru to cp_updt_cmd */
if ( argc >= 2 && CMD(argv[1],maint,1) )
if (argc >= 2 && CMD( argv[1], MAINT, 1 ))
{
argc--;
argv++;
rc = cp_updt_cmd(argc, argv, NULL);
rc = cp_updt_cmd( argc, argv, NULL );
}
else if ( argc == 2 )
else if (argc == 2 && valid_codepage_name( argv[1] ))
{
/* Update codepage if operand is specified */
set_codepage(argv[1]);
/* Update codepage if valid operand is specified */
set_codepage( argv[1] );
}
else if ( argc == 1 )
else if (argc == 1)
{
cp = query_codepage();
if ( cp == NULL )
{
WRMSG( HHC01476, "I", "(NULL)" );
}
else
{
WRMSG( HHC01476, "I", cp );
}
const char* cp = query_codepage();
// "Codepage is %s"
WRMSG( HHC01476, "I", cp ? cp : "(NULL)" );
}
else
{
// "Invalid command usage. Type 'help %s' for assistance."
WRMSG( HHC02299, "E", argv[0] );
rc = -1;
}
Expand Down

0 comments on commit 5bbec7e

Please sign in to comment.