Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
185
cde/lib/DtSearch/raima/mapchar.c
Normal file
185
cde/lib/DtSearch/raima/mapchar.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/* $XConsortium: mapchar.c /main/3 1996/10/01 16:39:53 drk $ */
|
||||
/*
|
||||
* COMPONENT_NAME: austext
|
||||
*
|
||||
* FUNCTIONS: bgets
|
||||
* ctb_init
|
||||
* ctbl_alloc
|
||||
* ctbl_free
|
||||
* d_mapchar
|
||||
* nextc
|
||||
*
|
||||
* ORIGINS: 157
|
||||
*
|
||||
* OBJECT CODE ONLY SOURCE MATERIALS
|
||||
*/
|
||||
#ifndef NO_COUNTRY
|
||||
/*-----------------------------------------------------------------------
|
||||
|
||||
mapchar.c -- db_VISTA character map module.
|
||||
|
||||
detailed description
|
||||
|
||||
AUTHOR: Guido Weischedel
|
||||
DATE: August, 1988
|
||||
PROJECT: International Character sets
|
||||
|
||||
Copyright (C) 1988 by Raima Corporation
|
||||
|
||||
-----------------------------------------------------------------------*/
|
||||
|
||||
/* ********************** EDIT HISTORY *******************************
|
||||
|
||||
SCR DATE INI DESCRIPTION
|
||||
----- --------- --- -----------------------------------------------------
|
||||
20-Sep-88 WLW MULTI_TASK changes
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* ********************** INCLUDE FILES ****************************** */
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "vista.h"
|
||||
#include "dbtype.h"
|
||||
|
||||
/* ********************** LOCAL VARIABLE DECLARATIONS **************** */
|
||||
static char buf[30];
|
||||
static int cptr = -1;
|
||||
static int buflen;
|
||||
|
||||
/* ********************** LOCAL FUNCTION DECLARATIONS **************** */
|
||||
static void bgets(P1(char *) Pi(int) Pi(int));
|
||||
static int nextc(P1(int));
|
||||
|
||||
/* Map ASCII-Characters for output and sorting
|
||||
*/
|
||||
int d_mapchar(inchar,outchar,sort_str,subsort TASK_PARM)
|
||||
unsigned char inchar; /* value of character to be mapped */
|
||||
unsigned char outchar; /* output character as ... */
|
||||
CONST char FAR *sort_str; /* sort string (max. len = 2) */
|
||||
unsigned char subsort; /* subsort value, to distinguish between two */
|
||||
/* equal values (e.g. 'a' and 'A', if necessary) */
|
||||
TASK_DECL
|
||||
{
|
||||
int indx;
|
||||
|
||||
DB_ENTER(NO_DB_ID TASK_ID LOCK_SET(RECORD_IO));
|
||||
|
||||
if ( strlen(sort_str) > 2 )
|
||||
RETURN( dberr(S_INVSORT) );
|
||||
|
||||
/* Is character-set table already installed? */
|
||||
if ( !db_global.ctbl_activ ) {
|
||||
if ( ctbl_alloc() != S_OKAY )
|
||||
RETURN( db_status );
|
||||
db_global.ctbl_activ = TRUE;
|
||||
}
|
||||
|
||||
/* Modify table for inchar specifications */
|
||||
indx = inchar;
|
||||
db_global.country_tbl.ptr[indx].out_chr = outchar;
|
||||
db_global.country_tbl.ptr[indx].sort_as1 = sort_str[0];
|
||||
db_global.country_tbl.ptr[indx].sort_as2 = sort_str[1];
|
||||
db_global.country_tbl.ptr[indx].sub_sort = subsort;
|
||||
|
||||
RETURN( db_status=S_OKAY );
|
||||
}
|
||||
|
||||
/* read MAP_FILE and make appropriate d_mapchar-calls
|
||||
*/
|
||||
int ctb_init()
|
||||
{
|
||||
int map_fd;
|
||||
unsigned char inchar, outchar, subsort;
|
||||
char loc_buf[21], sortas[3];
|
||||
short subs_i;
|
||||
char ctb_name[FILENMLEN*2];
|
||||
|
||||
strcpy( ctb_name, db_global.ctbpath );
|
||||
strcat( ctb_name, CTBNAME );
|
||||
|
||||
if ( (map_fd = open_b(ctb_name,O_RDONLY)) != -1 ) {
|
||||
while(bgets(loc_buf,20,map_fd), *loc_buf) {
|
||||
if ( strcmp( loc_buf, "ignorecase" ) == 0 ) {
|
||||
if ( d_on_opt( IGNORECASE CURRTASK_PARM ) != S_OKAY )
|
||||
break;
|
||||
}
|
||||
else {
|
||||
sscanf(loc_buf,"%c,%c,%hd,%2s",&inchar,&outchar,&subs_i,&sortas[0]);
|
||||
subsort = (unsigned char) subs_i;
|
||||
if (d_mapchar(inchar,outchar,sortas,subsort CURRTASK_PARM) != S_OKAY )
|
||||
break;
|
||||
}
|
||||
}
|
||||
close(map_fd);
|
||||
return( db_status );
|
||||
}
|
||||
return(db_status = S_OKAY);
|
||||
}
|
||||
|
||||
/* do an fgets from a binary file */
|
||||
static void bgets( s, len, fd )
|
||||
char *s;
|
||||
int len, fd;
|
||||
{
|
||||
int c;
|
||||
|
||||
len--;
|
||||
while ( len-- ) {
|
||||
do {
|
||||
c = nextc( fd );
|
||||
if ( c == -1 ) goto eof;
|
||||
c &= 0xff;
|
||||
} while ( c == '\r' );
|
||||
if ( c == '\n' ) break;
|
||||
*s++ = (char)c;
|
||||
}
|
||||
eof:
|
||||
*s = '\0';
|
||||
}
|
||||
|
||||
/* get one character from the file */
|
||||
static int nextc( fd )
|
||||
int fd;
|
||||
{
|
||||
int n;
|
||||
|
||||
if ( cptr < 0 || cptr >= buflen ) {
|
||||
n = read( fd, buf, 30 );
|
||||
if ( n == 0 ) {
|
||||
cptr = -1;
|
||||
return( -1 );
|
||||
}
|
||||
cptr = 0;
|
||||
buflen = n;
|
||||
}
|
||||
return( (int)buf[cptr++] );
|
||||
}
|
||||
|
||||
|
||||
/* Allocate and initialize country_table
|
||||
*/
|
||||
int ctbl_alloc()
|
||||
{
|
||||
if ((db_global.country_tbl.ptr = (CNTRY_TBL FAR *)
|
||||
ALLOC(&db_global.country_tbl,256*sizeof(CNTRY_TBL)+1,"country_tbl"))
|
||||
== NULL ) return( dberr(S_NOMEMORY) );
|
||||
|
||||
/* fill table with standard values */
|
||||
byteset(db_global.country_tbl.ptr, '\0', 256*sizeof(CNTRY_TBL)+1);
|
||||
|
||||
return( db_status = S_OKAY );
|
||||
}
|
||||
|
||||
/* Free country table
|
||||
*/
|
||||
void ctbl_free()
|
||||
{
|
||||
MEM_UNLOCK( &db_global.country_tbl );
|
||||
FREE( &db_global.country_tbl );
|
||||
db_global.ctbl_activ = FALSE;
|
||||
}
|
||||
|
||||
#endif /* NO_COUNTRY */
|
||||
/* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin mapchar.c */
|
||||
Reference in New Issue
Block a user