2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: mapchar.c /main/3 1996/10/01 16:39:53 drk $ */
25 * COMPONENT_NAME: austext
36 * OBJECT CODE ONLY SOURCE MATERIALS
39 /*-----------------------------------------------------------------------
41 mapchar.c -- db_VISTA character map module.
45 AUTHOR: Guido Weischedel
47 PROJECT: International Character sets
49 Copyright (C) 1988 by Raima Corporation
51 -----------------------------------------------------------------------*/
53 /* ********************** EDIT HISTORY *******************************
55 SCR DATE INI DESCRIPTION
56 ----- --------- --- -----------------------------------------------------
57 20-Sep-88 WLW MULTI_TASK changes
62 /* ********************** INCLUDE FILES ****************************** */
68 /* ********************** LOCAL VARIABLE DECLARATIONS **************** */
73 /* ********************** LOCAL FUNCTION DECLARATIONS **************** */
74 static void bgets(P1(char *) Pi(int) Pi(int));
75 static int nextc(P1(int));
77 /* Map ASCII-Characters for output and sorting
79 int d_mapchar(inchar,outchar,sort_str,subsort TASK_PARM)
80 unsigned char inchar; /* value of character to be mapped */
81 unsigned char outchar; /* output character as ... */
82 CONST char FAR *sort_str; /* sort string (max. len = 2) */
83 unsigned char subsort; /* subsort value, to distinguish between two */
84 /* equal values (e.g. 'a' and 'A', if necessary) */
89 DB_ENTER(NO_DB_ID TASK_ID LOCK_SET(RECORD_IO));
91 if ( strlen(sort_str) > 2 )
92 RETURN( dberr(S_INVSORT) );
94 /* Is character-set table already installed? */
95 if ( !db_global.ctbl_activ ) {
96 if ( ctbl_alloc() != S_OKAY )
98 db_global.ctbl_activ = TRUE;
101 /* Modify table for inchar specifications */
103 db_global.country_tbl.ptr[indx].out_chr = outchar;
104 db_global.country_tbl.ptr[indx].sort_as1 = sort_str[0];
105 db_global.country_tbl.ptr[indx].sort_as2 = sort_str[1];
106 db_global.country_tbl.ptr[indx].sub_sort = subsort;
108 RETURN( db_status=S_OKAY );
111 /* read MAP_FILE and make appropriate d_mapchar-calls
116 unsigned char inchar, outchar, subsort;
117 char loc_buf[21], sortas[3];
119 char ctb_name[FILENMLEN*2];
121 strcpy( ctb_name, db_global.ctbpath );
122 strcat( ctb_name, CTBNAME );
124 if ( (map_fd = open_b(ctb_name,O_RDONLY)) != -1 ) {
125 while(bgets(loc_buf,20,map_fd), *loc_buf) {
126 if ( strcmp( loc_buf, "ignorecase" ) == 0 ) {
127 if ( d_on_opt( IGNORECASE CURRTASK_PARM ) != S_OKAY )
131 sscanf(loc_buf,"%c,%c,%hd,%2s",&inchar,&outchar,&subs_i,&sortas[0]);
132 subsort = (unsigned char) subs_i;
133 if (d_mapchar(inchar,outchar,sortas,subsort CURRTASK_PARM) != S_OKAY )
140 return(db_status = S_OKAY);
143 /* do an fgets from a binary file */
144 static void bgets( s, len, fd )
154 if ( c == -1 ) goto eof;
156 } while ( c == '\r' );
157 if ( c == '\n' ) break;
164 /* get one character from the file */
165 static int nextc( fd )
170 if ( cptr < 0 || cptr >= buflen ) {
171 n = read( fd, buf, 30 );
179 return( (int)buf[cptr++] );
183 /* Allocate and initialize country_table
187 if ((db_global.country_tbl.ptr = (CNTRY_TBL FAR *)
188 ALLOC(&db_global.country_tbl,256*sizeof(CNTRY_TBL)+1,"country_tbl"))
189 == NULL ) return( dberr(S_NOMEMORY) );
191 /* fill table with standard values */
192 byteset(db_global.country_tbl.ptr, '\0', 256*sizeof(CNTRY_TBL)+1);
194 return( db_status = S_OKAY );
197 /* Free country table
201 MEM_UNLOCK( &db_global.country_tbl );
202 FREE( &db_global.country_tbl );
203 db_global.ctbl_activ = FALSE;
206 #endif /* NO_COUNTRY */
207 /* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin mapchar.c */