From: chase Date: Sun, 5 Aug 2018 20:58:15 +0000 (-0500) Subject: Revert "dtudcfonted, dtudcexch: delete from repository" X-Git-Tag: 2.3.0a~26^2~24 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6b713f12b5ca93fcde11887518e86f8ac5004ff0;p=oweals%2Fcde.git Revert "dtudcfonted, dtudcexch: delete from repository" This reverts commit e0036e6167d9cdcb1c7803f23986a4c2e8593e90. --- diff --git a/cde/programs/dtudcexch/Imakefile b/cde/programs/dtudcexch/Imakefile new file mode 100644 index 00000000..93cf4743 --- /dev/null +++ b/cde/programs/dtudcexch/Imakefile @@ -0,0 +1,50 @@ +XCOMM $XConsortium: Imakefile /main/12 1996/10/17 01:48:11 cde-fuj $ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +FONTEDT_PATH1 = ../dtudcfonted +UDC_INC_PATH0 = -I./ +UDC_INC_PATH1 = -I$(FONTEDT_PATH1) +UDC_INC_PATH2 = -I$(FONTEDT_PATH1)/include +UDC_INC_PATH3 = -I$(FONTEDT_PATH1)/libfal +UDC_INC_PATH4 = -I$(FONTEDT_PATH1)/libfal/include +UDC_INC_PATH7 = -I$(FONTEDT_PATH1)/dtgpftobdf + + INCLUDES = \ + $(UDC_INC_PATH0)\ + $(UDC_INC_PATH1)\ + $(UDC_INC_PATH2)\ + $(UDC_INC_PATH3)\ + $(UDC_INC_PATH4)\ + $(UDC_INC_PATH7) + +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + +DEFINES = $(OPT2) + +DEPLIBS = $(DEPDTSVCLIB) $(DEPTTLIB) $(DEPXMLIB) $(DEPXTOOLLIB) \ + $(DEPXLIB) \ + $(FONTEDT_PATH1)/libfuty/liboakfuty.a \ + $(FONTEDT_PATH1)/libfal/libfal.a + +LOCAL_LIBRARIES = $(DTSVCLIB) $(TTLIB) $(XMLIB) $(XTOOLLIB) $(XLIB) \ + $(FONTEDT_PATH1)/libfuty/liboakfuty.a \ + $(FONTEDT_PATH1)/libfal/libfal.a + +SYS_LIBRARIES = DtClientSysLibs + + SRCS = udcexc.c udcexp.c udcimp.c getbdffn.c excutil.c\ + selectx.c exportbdf.c importbdf.c + + OBJS = udcexc.o udcexp.o udcimp.o getbdffn.o excutil.o\ + selectx.o exportbdf.o importbdf.o + +ComplexProgramTarget(dtudcexch) diff --git a/cde/programs/dtudcexch/README b/cde/programs/dtudcexch/README new file mode 100644 index 00000000..07db0960 --- /dev/null +++ b/cde/programs/dtudcexch/README @@ -0,0 +1,31 @@ +$XConsortium: README /main/3 1996/10/17 01:48:23 cde-fuj $ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +UDC data exchange utility README + +Source code and directory structure +$(TOP)/cde/dtudcexch: + Imakefile + udcexc.c + udcexp.c + udcimp.c + getbdffn.c + excutil.c + excutil.h + selectx.c + exportbdf.c + importbdf.c + +The dtudcexch command uses following commands. + dtaddcpf dtbdftocpf dtcpftobdf dtcpftogpf + dtcpgpf dtfonteditor dtgpftobdf dtgpftocpf + dtlsgpf + +The dtudcexch command uses following libraries. + libfal.a + liboakfuty.a diff --git a/cde/programs/dtudcexch/dtudcexch.msg b/cde/programs/dtudcexch/dtudcexch.msg new file mode 100644 index 00000000..fabd1677 --- /dev/null +++ b/cde/programs/dtudcexch/dtudcexch.msg @@ -0,0 +1,127 @@ +$ $XConsortium: dtudcfonted.msg +$ *************************************<+>************************************* +$ ***************************************************************************** +$ ** +$ ** File: dtudcexch.msg +$ ** +$ ** Project: Fujitsu DT UDC Exchange +$ ** +$ ** Description: +$ ** ----------- +$ ** This file is the source for the message catalog for dtudcexch +$ ** +$ ** +$ ***************************************************************************** +$ ** +$ ** (c) Copyright 1996 Fujitsu Ltd. +$ ** + +$set 2 +$ ***************************************************************************** +$ ** _DtMessage set for getbdffn.c +$ ***************************************************************************** + +2 BDF file selection +4 The selected file exists. Overwrite? +6 Failed to open the selected file. + +$set 4 +$ ***************************************************************************** +$ ** _DtMessage set for selectx.c +$ ***************************************************************************** + +2 This font has no user defined characters. +4 Failed to open the selected font. You do not have permission to access the font file, or the format of the file is incorrect. +6 The font file is in use by another UDC application. +8 There is no font +10 Open +12 Cancel +14 UDC data exchange utility +16 SelectItems +18 - Codeset: +20 - Style: +22 - Width: +24 - Height: + +$set 6 +$ ***************************************************************************** +$ ** _DtMessage set for selectxlfd.c +$ ***************************************************************************** + +2 Do you want to terminate UDC Exchange? +4 No UDCs exist in this font +6 XLFD name is not selected +8 Cannot open the font file +10 The font file is in use by another UDC application. + +$set 8 +$ ***************************************************************************** +$ ** _DtMessage set for udcexc.c +$ ***************************************************************************** + +2 UDC data exchange utility +4 Fatal error occurred. +6 Cannot open the font file. +8 Cannot read the font file. +10 There is no more memory. +12 Fatal error occurred. +14 The specified font file does not exist. +16 This font is not a pcf or snf font. +18 Cannot open the fonts.list file. +20 The format of the fonts.list file is incorrect. +22 The descriptions of the fonts.list file are incorrect. +24 The format of the fonts.list file is incorrect. +26 Cannot open the fonts.dir file. +28 Cannot read the fonts.dir file. +30 Cannot read the font properties. +32 Cannot get the FONT property. +34 Cannot get the FAMILY_NAME property. +36 This font file is already in use by another application. +38 Cannot lock the font file. +40 Cannot unlock the font file. +42 Cannot get lock information from the font file. +44 Cannot find the specified font file. +46 Cannot read the NLS database. +48 Cannot get charset names from the NLS database. +50 The charset name is not defined in the NLS database. +52 The specified font has not been opened. +54 A fatal error occurred. +56 XLFD name : +58 Original font (XLFD name) : +60 UDC code area : +62 Style : +64 Size (letter size) : +66 Open +68 Cancel +70 OK +72 cancel +74 Copy origin code(hex) : +76 Copy target code(hex) : +78 Copy +80 Overlay +82 export function +84 import function +86 Cancel + +$set 10 +$ ***************************************************************************** +$ ** _DtMessage set for udcexp.c +$ ***************************************************************************** + +2 Failed to create the BDF file +4 No indexes are selected +6 OK +8 Cancel +10 glyph indexes + +$set 12 +$ ***************************************************************************** +$ ** _DtMessage set for udcexp.c +$ ***************************************************************************** + +2 Glyph images in this BDF file cannot be added to the font. +4 Failed to open the selected BDF font. You do not have permission to access the font file, or the format of the file is incorrect. +6 One or more glyph images will be overwritten. Overwrite? +8 Failed to open the selected font. You do not have permission to access the font file, or the format of the file is incorrect. +10 Glyph images in this BDF file cannot be added to the font. +12 Registration of the font file failed. diff --git a/cde/programs/dtudcexch/excutil.c b/cde/programs/dtudcexch/excutil.c new file mode 100644 index 00000000..ff95ab6e --- /dev/null +++ b/cde/programs/dtudcexch/excutil.c @@ -0,0 +1,336 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: excutil.c /main/3 1996/04/08 15:51:03 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include "excutil.h" + +extern char *maintitle; + +Widget excCreatePushButton(Widget parent, String name, String label, + XtCallbackProc callback_func, + XtPointer client_data) +{ + Widget widget; + XmString xms; + Arg args[20]; + Cardinal n; + + n = 0; + xms = XmStringCreateLocalized(label); + XtSetArg(args[n], XmNlabelString, xms); n++; + widget = XmCreatePushButton(parent, name, args, n); + XmStringFree(xms); + XtAddCallback(widget, XmNactivateCallback, + (XtCallbackProc) callback_func, + (XtPointer) client_data); + XtManageChild(widget); + + return (widget); +} + +void excerror(Exc_data * ed, int excerrno, char * funcname, char * func) +{ + switch (excerrno) + { + case EXCERRMALLOC: + fprintf(stderr, "dtudcexch:memory allocation error\n"); + freeExcdata(ed); + exit (-1); + case EXCERRNOUDC: + fprintf(stderr, "dtudcexch:UDC is not defined in current locale\n"); + freeExcdata(ed); + exit (-1); + } +} + +void dialogokCB(Widget widget, int * ans, XtPointer call_data) +{ + /* ok button pushed */ + *ans = 1; +} + +void dialogcancelCB(Widget widget, int * ans, XtPointer call_data) +{ + /* cancel button pushed */ + *ans = 2; +} + +void AskUser(Widget parent, Exc_data * ed, char *msg, int *r, char * type) +/* If ok button pushed, *r = 1. */ +/* If cancel button pushed(if exists), *r = 2. */ +{ + XmString message; + Widget dialog; + int ans = 0; + Cardinal n; + Arg args[20]; + + n = 0; + message = XmStringCreateLocalized(msg); + XtSetArg(args[n], XmNmessageString, message); n++; + XtSetArg(args[n], XmNtitle, maintitle); n++; + XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++; + if (strcmp(type, "warning") == 0) { + dialog = XmCreateWarningDialog(parent, type, args, n); + } else if (strcmp(type, "error") == 0) { + dialog = XmCreateErrorDialog(parent, type, args, n); + XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON)); + } else if (strcmp(type, "information") == 0) { + dialog = XmCreateInformationDialog(parent, type, args, n); + XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON)); + } else if (strcmp(type, "question") == 0) { + dialog = XmCreateQuestionDialog(parent, type, args, n); + } else { + fprintf(stderr, "error in AskUser\n"); + } + XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON)); + XmStringFree(message); + XtAddCallback(dialog, XmNokCallback, (XtCallbackProc) dialogokCB, + (XtPointer) &ans); + XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc) dialogcancelCB, + (XtPointer) &ans); + XtManageChild(dialog); + while (ans == 0) { + XtAppProcessEvent(ed->app, XtIMAll); + XSync(XtDisplay(dialog), 0); + } + *r = ans; + XSync(XtDisplay(dialog), 0); + XmUpdateDisplay(dialog); +} + +int beki(int n, int num) +{ + int a,i; + + a = 1; + for (i=0; i=0;i--) + { + if (('0'<= *c)&&(*c <= '9')) + n = n + ((*c - '0')*beki(16,i)); + else if (('a' <= *c)&&(*c <= 'f')) + n = n + ((*c - 'a'+10)*beki(16,i)); + else + Ecs("error in c2h.here"); + c++; + } + } else + Ecs("error in c2h"); + + return n; +} +char * renge2num(char * renge) +{ + char * num; + + num = (char *) calloc(7, sizeof(char)); + + strncpy(num,renge,6); + + return num; +} + +void Ecs(char * string) +{ + fprintf(stderr,"%s\n",string); +} +void Ecd(int data) +{ + fprintf(stderr,"%d\n",data); +} + +void freecsrec(UDCcsREC *rec) +{ + if (rec->charset != NULL) + free(rec->charset); + if (rec->udcrenge != NULL) + free(rec->udcrenge); +} + +void freecslist(int n, UDCcsREC *rec) +{ + int i; + UDCcsREC *recp; + + recp = rec; + for (i = 0; i < n; i++) + { + if (recp != NULL) + { + freecsrec(recp); + recp++; + } else { + break; + } + } +} + +void freeExcdata(Exc_data *ed) +{ + if (ed == NULL) + return; + +/* Don't free ed->toplevel */ + + if (ed->locale != NULL) + free(ed->locale); + + if (ed->cslist != NULL) + free(ed->cslist); + + if (ed->xlfdname != NULL) + free(ed->xlfdname); + + if (ed->style != NULL) + free(ed->style); + + if (ed->size != NULL) + free(ed->size); + +/* Don't free ed->fontfile */ + + if (ed->bdffile != NULL) + XtFree(ed->bdffile); + + if (ed->udcrenge != NULL) + free(ed->udcrenge); + + if (ed->gpf_code_list != NULL) + free(ed->gpf_code_list); + + if (ed->bdf_code_list != NULL) + free(ed->bdf_code_list); + + if (ed->comment_list != NULL) + free(ed->comment_list); + + free(ed); +} + +void Ecss(char * s1, char * s2) +{ + fprintf(stderr,"%s is %s\n", s1, s2); +} +void Ecsd(char * s1, int i) +{ + fprintf(stderr,"%s = %d\n", s1, i); +} + +void checkdata(Exc_data *ed) +{ + if (ed == NULL) + return; + +/* Don't free ed->toplevel */ + + if (ed->locale != NULL) + Ecss("ed->locale", ed->locale); + + Ecsd("ed->csnum", ed->csnum); + + if (ed->xlfdname != NULL) + Ecss("ed->xlfdname",ed->xlfdname); + + if (ed->fontfile != NULL) + Ecss("ed->fontfile",ed->fontfile); + + if (ed->bdffile != NULL) + Ecss("ed->bdffile",ed->bdffile); + + if (ed->udcrenge != NULL) + Ecss("ed->udcrenge",ed->udcrenge); + + Ecsd("ed->code_num", ed->code_num); +} + +void excterminate(Exc_data * ed) +{ + freeExcdata(ed); + exit(0); +} + +void excexit(Exc_data * ed) +{ + excterminate(ed); +} + +void freeld(ListData *ld) +{ + int i; + char **cp; + + if (ld != NULL) { + if (ld->allcode != NULL) + free(ld->allcode); + if (ld->existcode != NULL) + free(ld->existcode); + if (ld->existcode_c != NULL) { + cp = ld->existcode_c; + for (i = 0; i < ld->existcode_num; i++) { + if (*cp != NULL) + free(*cp); + cp++; + } + free(ld->existcode_c); + } + free(ld); + } +} + +int bigger(int num1, int num2) +{ + if (num1 >= num2) + return (num1); + else + return (num2); +} + +int smaller(int num1, int num2) +{ + if (num1 < num2) + return (num1); + else + return (num2); +} diff --git a/cde/programs/dtudcexch/excutil.h b/cde/programs/dtudcexch/excutil.h new file mode 100644 index 00000000..0deada83 --- /dev/null +++ b/cde/programs/dtudcexch/excutil.h @@ -0,0 +1,137 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: excutil.h /main/6 1996/12/23 08:48:26 barstow $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include +#include +#include +#include +#include +#define EXPORT 1 +#define IMPORT 2 +#define EXCERRMALLOC 101 +#define EXCERRNOUDC 102 + +void Ecs(); +void Ecd(); +/*void getpcffn();*/ +void getbdffn(); +void selcharcd(); +void getcharcd(); +void createbdf(); +int bigger(); +int smaller(); +int c2h(); +char *renge2num(); +void freeExcdata(); +void checkdata(); +void excexit(); +void excterminate(); +void freeld(); +void getexistcode(); +void AskUser(); +void excerror(); +Widget excCreatePushButton(); + +typedef struct { + char * charset; + char * udcrenge; +} UDCcsREC; + +typedef struct { + int function; + XtAppContext app; + Widget toplevel; + char *locale; + int csnum; + UDCcsREC *cslist; + char *xlfdname; + char *style; + char *size; + char *fontfile; + char *bdffile; + char bdfmode[2]; + char *udcrenge; + int code_num; + int *gpf_code_list; + int *bdf_code_list; + int comment_num; + char **comment_list; +} Exc_data; + +typedef struct { + Widget list; + int allcode_num; + int *allcode; + int existcode_num; + int *existcode; + char **existcode_c; + Exc_data *ed; +} ListData; + +#ifndef NO_MESSAGE_CATALOG +# ifdef __ultrix +# define _CLIENT_CAT_NAME "dtudcexch.cat" +# else /* __ultrix */ +# define _CLIENT_CAT_NAME "dtudcexch" +# endif /* __ultrix */ +# ifdef _NO_PROTO +extern char *_DtGetMessage(); +# else /* _NO_PROTO */ +extern char *_DtGetMessage( + char *filename, + int set, + int n, + char *s ); +# endif /* _NO_PROTO */ +#define GETMESSAGE(set, number, string) GetMessage(set, number, string) +static char * +GetMessage(set, number, string) +int set, number; +char *string; +{ + char *tmp; + static char * point[100]; + static int first = True; + + if (first) { + memset(point, 0, sizeof(char *) * 100); + first = False; + } + if (point[number]) + return(point[number]); + tmp = _DtGetMessage(_CLIENT_CAT_NAME, set, number, string); + point[number] = (char *) malloc(strlen(tmp) + 1); + strcpy(point[number], tmp); + return (point[number]); +} +#else /* NO_MESSAGE_CATALOG */ +# define GETMESSAGE(set, number, string)\ + string +#endif /* NO_MESSAGE_CATALOG */ diff --git a/cde/programs/dtudcexch/exportbdf.c b/cde/programs/dtudcexch/exportbdf.c new file mode 100644 index 00000000..01c9a399 --- /dev/null +++ b/cde/programs/dtudcexch/exportbdf.c @@ -0,0 +1,366 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: exportbdf.c /main/4 1996/04/10 13:49:20 ageorge $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Authors: Seiya Miyazaki FUJITSU LIMITED + * Hiroyuki Chiba FUJITSU LIMITED + */ +#include +#include +#include +#include +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#endif +#include +#include +#include +#include +#include + +#include "bdfgpf.h" + +static int writeBdfHeader(); +static int readBdfToMemory(); +static void sigint_out(); +static char buf[BUFSIZE]; +static struct ptobhead w_bdf ; + +static void +sigint_out() +{ + fclose(w_bdf.output) ; + fclose(w_bdf.input) ; /* stream */ + exit( 0 ); +} + +int +expCheckCode( code, code_num, code_list ) +unsigned int code ; +int code_num ; +int *code_list ; +{ + int i ; + + if( code < MIN_CODE || code > MAX_CODE ) return -1 ; + for( i=0; isnf_file != NULL) { + if (pipe(fd) != 0) { + return PIPE_ERROR; + } + switch (chld_pid = fork()) { + case 0: + close(1); + if(dup(fd[1]) < 0) { + return(DUP_ERROR); + } + close(fd[0]); + close(fd[1]); + execl( oakgtobdf, oakgtobdf, head->snf_file, 0); + return EXEC_ERROR; + case -1: + return(FORK_ERROR); + default: + break; + } + close(fd[1]); + if((fp = (FILE *)fdopen(fd[0], "r")) == NULL) { + close( fd[0] ); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + return FDOPEN_ERROR; + } + } else { + return(BDF_OPEN_HEAD); + } + head->input = fp ; + getstat = 0; + comflg = 0 ; + + while ( 1 ) { + if (fgets(buf, BUFSIZE, fp) == NULL) { + fclose( fp ); + if (head->snf_file != NULL) { + close(fd[0]); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + return(BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p); + + if (!strncmp(p, CHARS, CHARSsz)) { + if ((sscanf(p, "CHARS %d", &(head->num_chars))) != 1 ){ + return(BDF_INVAL); + } + getstat |= 0x04; + break; + } + /* + * write user comments + */ + if ( !strncmp(p, "FONT", strlen("FONT")) + && comment_list && !comflg + ) { + int i ; + for( i=0; ioutput, "COMMENT %s\n", comment_list[i]); + } + fprintf(head->output, "COMMENT\n"); + comflg++ ; + } + + fprintf(head->output, "%s", buf); + + if (!strncmp(p, SIZE, SIZEsz)) { + if ((sscanf(p, "SIZE %f%d", + &(head->bdf_point), &(head->bdf_xdpi))) != 2) { + fclose(fp); + if (head->snf_file != NULL) { + close(fd[0]); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + return(BDF_INVAL); + } + getstat |= 0x01; + continue; + } + if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) { + if (( cnt = sscanf( p, "FONTBOUNDINGBOX %d%d%d%d", + &(head->bdf_width), &(head->bdf_height), + &(head->bdf_x), &(head->bdf_y))) != 4 + ) { + fclose(fp); + if (head->snf_file != NULL) { + close(fd[0]); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + return BDF_INVAL; + } + getstat |= 0x02; + continue; + } + get_charset_registry(head, p) ; + } + + if (getstat != 0x07) { + return BDF_INVAL; + } + + return 0; +} + + +static int +readBdfToMemory(head, buf, code_num, code_list, make_all) +struct btophead *head; +char *buf; +int code_num ; /* number of GPF code */ +int *code_list ; /* pointer to GPF code lists */ +int make_all ; /* convert whole GPF fomat file to BDF */ +{ + int code, mwidth, num_char, bsize, rtn; + char *ptn; + + num_char = 0; + mwidth = (head->bdf_width + 7) / 8; + bsize = mwidth * head->bdf_height; + while(1) { + if ((rtn = GetBdfCode(head, buf, &code)) < 0) { + return(rtn); /* contain BDF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + if ( !make_all ) { + if ( expCheckCode(code, code_num, code_list) ) { + continue; + } + } + + head->code[num_char] = code; + if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) { + return(MALLOC_ERROR); + } + + if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} diff --git a/cde/programs/dtudcexch/getbdffn.c b/cde/programs/dtudcexch/getbdffn.c new file mode 100644 index 00000000..7415084f --- /dev/null +++ b/cde/programs/dtudcexch/getbdffn.c @@ -0,0 +1,180 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: getbdffn.c /main/5 1996/10/14 14:44:32 barstow $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include "excutil.h" +#include +#include +#include +#include + +/* + * There is no public header file for this function (only an + * internal header XmStringI.h). + */ +extern XtPointer _XmStringUngenerate (XmString string, + XmStringTag tag, + XmTextType tag_type, + XmTextType output_type); + +void filesbokCB(); +void filesbcancelCB(); + +extern char *maintitle; + +void getbdffn(Exc_data * ed) +{ + Widget filesb; + Arg args[20]; + Cardinal n; + char *selectlabel; + XmString xms; + + selectlabel = GETMESSAGE(2, 2, "BDF file selection"); + n = 0; + XtSetArg(args[n], XmNtitle, maintitle); n++; + xms = XmStringCreateLocalized(selectlabel); + XtSetArg(args[n], XmNselectionLabelString, xms); n++; + filesb = XmCreateFileSelectionDialog(ed->toplevel, "filesb", args, n); + XtAddCallback(filesb, XmNokCallback, + (XtCallbackProc) filesbokCB, + (XtPointer) ed); + XtAddCallback(filesb, XmNcancelCallback, + (XtCallbackProc) filesbcancelCB, + (XtPointer) ed); + XtUnmanageChild(XmFileSelectionBoxGetChild(filesb, XmDIALOG_HELP_BUTTON)); + XtManageChild(filesb); +} + +int fopencheck(char *file, char *dir, char *mode) +/* + * when mode = "r", if fopen can open the file with read only mode, return 0 + * when mode = "w", if fopen can open the file with write mode, return 0 + * but if the file exists, return 1 + * otherwise return -1 + */ +{ + struct stat buf; + + if (strcmp(mode, "r") == 0) { + if (stat(file, &buf) == 0) + if ((buf.st_mode & S_IFMT) == S_IFREG) + return 0; /* readable regular file */ + } else if (strcmp(mode, "w") == 0) { + if (stat(file, &buf) == 0) { + if (((buf.st_mode & S_IFMT) == S_IFREG) && + (access(file, W_OK) == 0)) + return 1; /* writable existing file */ + } else { + if (stat(dir, &buf) == 0) { + if (((buf.st_mode & S_IFMT) == S_IFDIR) && + (access(dir, W_OK) == 0)) { + return 0; /* writable new file */ + } + } + } + } else + fprintf(stderr, "Unanticipatable error occurred in fopencheck.\n"); + return -1; +} + +void filesbcancelCB(Widget widget, Exc_data * ed, XtPointer call_data) +{ + excexit(ed); +} + +void freeStrings(char * dir, char * file) +{ + if (dir != NULL) + XtFree(dir); + if (file != NULL) + XtFree(file); +} + +void filesbokCB(Widget widget, Exc_data * ed, XtPointer call_data) +{ + XmFileSelectionBoxCallbackStruct *ptr; + char *file = NULL, *dir = NULL, *tmpfile; + int r, ans = 0; + char *msg1; + char *msg2; + + msg1 = GETMESSAGE(2, 4, "The selected file exists. Overwrite?"); + msg2 = GETMESSAGE(2, 6, "Failed to open the selected file."); + + ptr = (XmFileSelectionBoxCallbackStruct *) call_data; + + file = (char *) _XmStringUngenerate((XmString) ptr->value, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (!file) { + return; + } + + dir = (char *) _XmStringUngenerate((XmString) ptr->dir, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (!dir) { + return; + } else { + if (*file != '/') { + if ((tmpfile = XtMalloc(strlen(dir) + 1 + strlen(file) + 1)) + == NULL) { + excerror(ed, EXCERRMALLOC, "filesbokCB", "exit"); + } + sprintf(tmpfile, "%s/%s", dir, file); + XtFree(file); + file = tmpfile; + } + } + + r = fopencheck(file, dir, ed->bdfmode); + if (r == 0) {/* no problem */ + /*fprintf(stderr, "%s will be opened\n", file);*/ + } else if (r == 1) { /* file exist at export function */ + AskUser(widget, ed, msg1, &ans, "warning"); + if (ans != 1) { /* overwrite cancel */ + freeStrings(dir, file); + return; + } + } else { /* file will not be opened */ + AskUser(widget, ed, msg2, &ans, "error"); + freeStrings(dir, file); + return; + } + ed->bdffile = (char *) malloc(strlen(file) + 1); + strcpy(ed->bdffile, file); + freeStrings(dir, file); + XtUnmanageChild(widget); + if (ed->function == EXPORT) + { + createbdf(ed); + } else if (ed->function == IMPORT) + { + PopupSelectXLFD(ed->toplevel); + } +} diff --git a/cde/programs/dtudcexch/importbdf.c b/cde/programs/dtudcexch/importbdf.c new file mode 100644 index 00000000..aa818300 --- /dev/null +++ b/cde/programs/dtudcexch/importbdf.c @@ -0,0 +1,707 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: importbdf.c /main/5 1996/06/27 10:40:33 ageorge $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Authors: Seiya Miyazaki FUJITSU LIMITED + * Hiroyuki Chiba FUJITSU LIMITED + * + */ + + + +#include +#include +#include +#include +#include +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#endif + +#include + +#include +#include +#include "bdfgpf.h" +#include "FaLib.h" + +#include + +#define UNLINK_TMPFILE( file ){ \ + if ( unlink( file ) != 0 ) { \ + exit(-1) ; \ + } \ +} + +static impFileConvInit(); +static impGetGpfInf(); +static impReadBdfHeaderAndPut(); +static impMergePtn(); +static impModifyPtn(); +static impInsertPtn(); +static impWriteSnf(); +static int impWritePtnToBdf(); +static int impPutDefaultChars(); +static int impReadBdfToMemory(); + +extern int expCheckCode(); + + +static struct ptobhead WriteGpf; + +static char *targ_file = NULL; /* UDC_file_name */ + + +static void +sigint_out() +{ + if (WriteGpf.out_file) { + UNLINK_TMPFILE( WriteGpf.out_file ); + } + exit( 0 ); +} + + + + +int +ImpBDFCodeList( bdf_name, code_num, code_list ) +char *bdf_name ; +int *code_num ; +int **code_list ; +{ + int *glyph_list ; + FILE *bdfp ; + char *p ; + char buf[2048] ; + int cnt ; + + /* open BDF file */ + if( (bdfp = fopen( bdf_name, "r" )) == NULL ){ + return(-1); + } + + /* get number of characters in BDF file */ + while ( 1 ) { + if( fgets( buf, BUFSIZE, bdfp ) == NULL) { + return (BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP( p ) + if ( !strncmp( p, CHARS, (unsigned int)strlen( CHARS ) ) ) { + if ( ( sscanf( p, "CHARS %d", code_num ) ) != 1 ) { + return BDF_INVAL; + } + break ; + } + } + + /* alloc memory for codes */ + if( (glyph_list = (int *)calloc( *code_num, (unsigned int)sizeof(int) )) == NULL ){ + return(-1); + } + + /* get codes of BDF file */ + cnt = 0 ; + while( cnt < *code_num ) { + if (fgets(buf, BUFSIZE, bdfp ) == NULL) { + return (BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP( p ) + if (!strncmp(p, ENDFONT, (unsigned int)ENDFONTsz)) { + break; + }else if (!strncmp(p, ENCODING, (unsigned int)ENCODINGsz)) { + if ((sscanf(p, "ENCODING %d", &glyph_list[cnt] )) != 1) { + return(BDF_INVAL); + } + cnt ++ ; + } + } + if( cnt != *code_num ){ + return(-1) ; + } + + /* close BDF file */ + if( fclose( bdfp ) ){ + return(-1); + } + + *code_list = glyph_list ; + + return(0) ; +} + + + +int +ImpBDFCodeListFree( code_list ) +int **code_list ; +{ + free( *code_list ) ; + return(0) ; +} + + + +int +ImpBDFCheck( bdf_name, gpf_name ) +char *bdf_name ; /* BDF file name */ +char *gpf_name ; /* GPF file name */ +{ + /* parameter check */ + if( bdf_name == NULL || gpf_name == NULL ){ + return(-1) ; + } + return(0) ; +} + + + + +int +ImpBDFtoGpf( bdf_name, gpf_name, bdf_codenum, bdf_codelist) +char *bdf_name ; +char *gpf_name ; +int bdf_codenum ; +int *bdf_codelist ; +{ + int rtn ; + int exit_stat; + struct btophead ReadGpf; + struct btophead ReadUdc; + struct stat statbuf; + char buf[BUFSIZE]; + + int chk_fd; + + ReadGpf.in_file = ReadUdc.in_file = WriteGpf.out_file = NULL; + + if (!( bdftopcf = get_cmd_path( getenv( "PATH" ), BDFTOPCF_CMD ))) { + bdftopcf = BDFTOPCF; + } + if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) { + oakgtobdf = SNFTOBDF; + } + if (!( bdftosnf = get_cmd_path( getenv( "PATH" ), BDFTOSNF_CMD ))) { + bdftosnf = BDFTOSNF; + } + + /* + * set input/output file name + */ + + ReadUdc.in_file = bdf_name ; + ReadUdc.code_category = ALL_CODE ; + ReadUdc.start_code = MIN_CODE ; + ReadUdc.end_code = MAX_CODE ; + + ReadGpf.in_file = gpf_name ; + ReadGpf.code_category = ALL_CODE ; + ReadGpf.start_code = MIN_CODE ; + ReadGpf.end_code = MAX_CODE ; + + /* + * get real file name of GPF file + */ + if ((targ_file = GetRealFileName( ReadGpf.in_file )) == NULL){ + return(-1); + } + + /* + * WriteGpf.snf_file = ReadGpf.in_file + */ + WriteGpf.snf_file = targ_file; + + signal( SIGHUP , (void(*)())sigint_out ); + signal( SIGINT , (void(*)())sigint_out ); + signal( SIGQUIT, (void(*)())sigint_out ); + signal( SIGTERM, (void(*)())sigint_out ); + + /* + * impFileConvInit() + * + * SNFTOBDF, BDFTOSNF + * + * (ReadGpf.in_file) --> SNFTOBDF ==H + * H + * oakaddp <-- (ReadUdc.in_file) + * H + * (WriteGpf.out_file) <-- BDFTOSNF ==H + * + */ + + /* + * make a temporary file by BDF format corresponded to target GPF file + */ + if ( rtn = impFileConvInit( &ReadUdc, &ReadGpf, &WriteGpf ) ) { + if ( WriteGpf.out_file ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + } + return(-1) ; + } + + /* + * get informations from import file in BDF format + */ + if ( rtn = ReadBdfHeader( &ReadUdc, buf ) ) { + if ( WriteGpf.out_file ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + } + return(-1) ; + } + + /* + * get informations from target file in BDF format + */ + + if ( rtn = impGetGpfInf( &ReadGpf, &WriteGpf, buf, bdf_codenum ) ) { + if ( WriteGpf.out_file ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + } + return(-1) ; + } + + /* wait for dtgpftobdf */ + fclose( ReadGpf.input ); + wait( 0 ); + + /* + * merge the UDC glyphs into GPF file (in BDF format) + */ + if ( ( rtn = impMergePtn( &ReadUdc, &ReadGpf, buf, + bdf_codenum, bdf_codelist ) ) ) { + if ( WriteGpf.out_file ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + } + return(-1) ; + } + + /* + * write the UDC data into GPF output file (in BDF format) + */ + if ( ( rtn = impWriteSnf( &ReadGpf, &WriteGpf ) ) ) { + if ( WriteGpf.out_file ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + } + return(-1) ; + } + + /* + * convert temporary file into GPF format + */ + fclose( ReadUdc.input ); + fclose( WriteGpf.output ); + wait( &exit_stat ); +#if !defined( SVR4 ) && !defined( SYSV ) + if ( !WIFEXITED(exit_stat) ) { +#else + if ( ! ( WIFEXITED(exit_stat) && !WEXITSTATUS(exit_stat) ) ) { +#endif + UNLINK_TMPFILE( WriteGpf.out_file ); + return(-1) ; + } + signal( SIGHUP , SIG_IGN ); + signal( SIGINT , SIG_IGN ); + signal( SIGQUIT, SIG_IGN ); + signal( SIGTERM, SIG_IGN ); + + sleep( 1 ); + if ( ( stat( WriteGpf.out_file, &statbuf ) ) || ( statbuf.st_size == 0 ) + ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + return(-1) ; + } + if ( stat( WriteGpf.snf_file, &statbuf ) ) { + UNLINK_TMPFILE( WriteGpf.out_file ); + return( -1 ); + } + /* + * convert the temporary file to target file + */ + return( Make_NewFefFile( WriteGpf.snf_file, WriteGpf.out_file, + FONT_FILE_PARM, (uid_t)statbuf.st_uid, (gid_t)statbuf.st_gid, "ImpBDFtoGpf()" )); +} + + +/* +* sub functions +*/ + +static +impFileConvInit(r_udc, r_gpf, w_gpf ) +struct btophead *r_udc; +struct btophead *r_gpf; +struct ptobhead *w_gpf; +{ + int fd[2], snf_fd, permission; + char buf[BUFSIZE]; + int pfd[2], ofd; + + FontInfoRec *finf; + char *optlist[5] = {0,0,0,0,0}; + char *ep ; + int i ; + struct stat statbuf ; + + + + if ( ( r_udc->input = fopen(r_udc->in_file, "r")) == NULL ) { + return GPF_OPEN_IN; + } + + /* + * case of SNF file + */ + if ( ChkPcfFontFile( w_gpf->snf_file ) ) { + /* snf */ + if ( ( snf_fd = open( w_gpf->snf_file, O_RDONLY ) ) >= 0 ) { + COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) ; + if( permission < 0 ) { + return BDF_INVAL; + } + } else { + return BDF_OPEN_IN; + } + } + + if (pipe(fd) != 0) { + return PIPE_ERROR; + } + switch ( fork() ) { + case 0: + close( fd[0] ); + close( 1 ); + if ( dup( fd[1] ) < 0 ) { + return DUP_ERROR; + } + + close( fd[1] ); + + /* gpf -> bdf */ + execl( oakgtobdf, oakgtobdf, r_gpf->in_file, 0 ); + return EXEC_ERROR; + + case -1: + return FORK_ERROR; + + default: + break; + } + close( fd[1] ); + if ( ( r_gpf->input = (FILE *)fdopen( fd[0], "r" ) ) == NULL ) { + return FDOPEN_ERROR; + } + + if ( !( w_gpf->out_file = GetTmpPath( targ_file ) ) ) { + return MKTMP_ERROR; + } + + if ( pipe( pfd ) != 0 ) { + return PIPE_ERROR; + } + switch ( fork() ) { + case 0: + if ( ( ofd = open( w_gpf->out_file, O_WRONLY | O_CREAT, 0664 ) ) < 0 ) { + return BDF_OPEN_OUT; + } + close( 0 ); + if ( dup(pfd[0]) < 0 ) { + return DUP_ERROR; + } + close( pfd[0] ); + close( pfd[1] ); + close( 1 ); + if( dup( ofd ) < 0 ) { + return DUP_ERROR; + } + close( ofd ); + /* + * case of PCF file format + */ + if ( ChkPcfFontFile( w_gpf->snf_file ) == 0 ) { + execl( bdftopcf, bdftopcf, 0 ); + return EXEC_ERROR; + } + /* + * case of SNF file format + */ + COMM_SNF_EXECLBDFTOSNF( permission, buf, w_gpf->snf_file ) ; + return EXEC_ERROR; + + case -1: + return FORK_ERROR; + + default: + break; + } + close( pfd[0] ); + if ( ( w_gpf->output = (FILE *)fdopen( pfd[1], "w" ) ) == NULL ) { + return FDOPEN_ERROR; + } + return 0; +} + + + + + +static +impGetGpfInf( r_gpf, w_gpf, buf, bdf_codenum ) +struct btophead *r_gpf; +struct ptobhead *w_gpf; +char *buf; +int bdf_codenum ; +{ + int nchar, rtn; + + if ( ( rtn = impReadBdfHeaderAndPut( r_gpf, w_gpf, buf ) ) ) { + return rtn; + } + + nchar = r_gpf->num_chars + bdf_codenum ; + + if ( ( r_gpf->code = (int *)malloc( sizeof(int) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( ( r_gpf->ptn = (char **)malloc( sizeof(char *) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + return ReadBdfToMemory( r_gpf, buf ) ; +} + + + +static +impReadBdfHeaderAndPut(r_gpf, w_gpf, buf) +struct btophead *r_gpf; +struct ptobhead *w_gpf; +char *buf; +{ + char *p; + unsigned int getstat = 0; + + while ( 1 ) { + if ( fgets( buf, BUFSIZE, r_gpf->input ) == NULL ) { + return BDF_INVAL; + } + p = buf; + SCAN_TO_NONSP( p ) + if ( !strncmp( p, SIZE, (unsigned int)strlen( SIZE ) ) ) { + if ( ( sscanf( p, "SIZE %f%d", + &(r_gpf->bdf_point), &(r_gpf->bdf_xdpi))) != 2 ) { + return BDF_INVAL; + } + fprintf( w_gpf->output, "%s", buf ); + getstat |= 0x01; + + } else if ( !strncmp( p, FONTBOUNDINGBOX, (unsigned int)strlen( FONTBOUNDINGBOX ) ) ) { + if ( ( sscanf( p, "FONTBOUNDINGBOX %d %d %d %d", + &(r_gpf->bdf_width), &(r_gpf->bdf_height), + &(r_gpf->bdf_x), &(r_gpf->bdf_y) ) ) != 4 ) { + return BDF_INVAL; + } + fprintf( w_gpf->output, "%s", buf ); + getstat |= 0x02; + + } else if ( !strncmp( p, CHARS, (unsigned int)strlen( CHARS ) ) ) { + if ( ( sscanf( p, "CHARS %d", &( r_gpf->num_chars ) ) ) != 1 ) { + return BDF_INVAL; + } + getstat |= 0x04; + break; + } else { + fprintf( w_gpf->output, "%s", buf ); + } + } + + if ( getstat != 0x07 ) { + return BDF_INVAL; + } + return 0; +} + + +static +impMergePtn(r_udc, r_gpf, buf, bdf_codenum, bdf_codelist ) +struct btophead *r_udc; +struct btophead *r_gpf; +char *buf; +int bdf_codenum ; +int *bdf_codelist ; +{ + int code, rtn, msize, i, j; + char *ptn; + + if ( ( r_udc->bdf_width != r_gpf->bdf_width ) + || ( r_udc->bdf_height != r_gpf->bdf_height ) + ) { + r_udc->zoomf = 1; + + msize = ( r_udc->bdf_width + 7 ) / 8 * r_udc->bdf_height; + + if ( ( ptn = (char *)malloc( msize ) ) == NULL ) { + return MALLOC_ERROR; + } + r_udc->ptn = &ptn; + + } else { + r_udc->zoomf = 0; + } + + for ( i = 0; i < r_udc->num_chars; i++ ) { + if ( ( rtn = GetBdfCode( r_udc, buf, &code ) ) < 0 ) { + return rtn; + } else if ( rtn == FILE_END ) { + break; + } + + if( expCheckCode( code, bdf_codenum, bdf_codelist ) ) { + continue ; + } + + for ( j = 0; j < r_gpf->num_chars; j++ ) { + if ( r_gpf->code[j] == code ) { + if ( ( rtn = impModifyPtn( r_udc, r_gpf, buf, j ) ) ) { + return rtn; + } + break; + } else if ( r_gpf->code[j] > code ) { + if ( ( rtn = impInsertPtn( r_udc, r_gpf, buf, code, j ) ) ) { + return rtn; + } + break; + } + } + if ( j == r_gpf->num_chars ) { + if ( ( rtn = impInsertPtn( r_udc, r_gpf, buf, code, j ) ) ) { + return rtn; + } + } + } + return 0; +} + +static +impModifyPtn( r_udc, r_gpf, buf, ix ) +struct btophead *r_udc; +struct btophead *r_gpf; +char *buf; +int ix; +{ + int mwidth, msize, rtn; + + mwidth = ( r_udc->bdf_width + 7 ) / 8; + msize = mwidth * r_udc->bdf_height; + + if ( r_udc->zoomf ) { + if ( ( rtn = GetBdfPtn( r_udc, buf, r_udc->ptn[0], mwidth, msize ) ) ) { + return rtn; + } + if ( ( rtn = PtnZoom( r_gpf->ptn[ix], r_udc->ptn[0], + r_udc->bdf_width, r_udc->bdf_height, + r_gpf->bdf_width, r_gpf->bdf_height ) ) ) { + return rtn; + } + } else { + if ( ( rtn = GetBdfPtn( r_udc, buf, r_gpf->ptn[ix], mwidth, msize ) ) ) { + return rtn; + } + } + return 0; +} + +static +impInsertPtn( r_udc, r_gpf, buf, code, ix ) +struct btophead *r_udc; +struct btophead *r_gpf; +char *buf; +int code; +int ix; +{ + int mwidth, msize, rtn, i; + + for ( i = r_gpf->num_chars; i > ix; i-- ) { + r_gpf->code[i] = r_gpf->code[i-1]; + r_gpf->ptn[i] = r_gpf->ptn[i-1]; + } + r_gpf->code[ix] = code; + + r_gpf->num_chars++; + + mwidth = (r_gpf->bdf_width + 7) / 8; + msize = mwidth * r_gpf->bdf_height; + + if ( ( r_gpf->ptn[ix] = (char *)malloc( msize ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( r_udc->zoomf ) { + mwidth = (r_udc->bdf_width + 7) / 8; + msize = mwidth * r_udc->bdf_height; + if ( ( rtn = GetBdfPtn( r_udc, buf, r_udc->ptn[0], mwidth, msize ) ) ) { + return rtn; + } + if ( ( rtn = PtnZoom( r_gpf->ptn[ix], r_udc->ptn[0], + r_udc->bdf_width, r_udc->bdf_height, + r_gpf->bdf_width, r_gpf->bdf_height ) ) ) { + return rtn; + } + } else { + if ( ( rtn = GetBdfPtn( r_udc, buf, r_gpf->ptn[ix], mwidth, msize ) ) ) { + return rtn; + } + } + return(0); +} + +static +impWriteSnf( r_gpf, w_gpf ) +struct btophead *r_gpf; +struct ptobhead *w_gpf; +{ + w_gpf->zoomf = 0; + w_gpf->num_chars = r_gpf->num_chars; + w_gpf->code = r_gpf->code; + w_gpf->ptn = r_gpf->ptn; + w_gpf->bdf_width = r_gpf->bdf_width; + w_gpf->bdf_height = r_gpf->bdf_height; + w_gpf->bdf_x = r_gpf->bdf_x; + w_gpf->bdf_y = r_gpf->bdf_y; + w_gpf->bdf_point = r_gpf->bdf_point; + w_gpf->bdf_xdpi = r_gpf->bdf_xdpi; + + return WritePtnToBdf( w_gpf ); +} diff --git a/cde/programs/dtudcexch/selectx.c b/cde/programs/dtudcexch/selectx.c new file mode 100644 index 00000000..9a5ed9ec --- /dev/null +++ b/cde/programs/dtudcexch/selectx.c @@ -0,0 +1,1211 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* selectx.c 1.12 - Fujitsu source for CDEnext 96/03/01 09:34:52 */ +/* $TOG: selectx.c /main/5 1997/07/23 17:24:39 samborn $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include /* dtex add */ +#include /* dtex add */ +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "xoakufont.h" +#include "selectxlfd.h" +#include "excutil.h" /* dtex add */ + +/* + * There is no public header file for this function (only an + * internal header XmStringI.h). + */ +extern XtPointer _XmStringUngenerate (XmString string, + XmStringTag tag, + XmTextType tag_type, + XmTextType output_type); + +/*extern Resource resource ; dtex del*/ +/* dtex add */ +extern Exc_data *ed; +extern ListData *ld; +FalGlyphRegion *gr; +int num_gr; +FalFontID fid; +extern char *maintitle; +extern char **errmsg_org; + +/* + * parameters + */ + +FalFontData fullFontData; + +void PopupSelectXLFD() ; +static Widget CreateSelectXLFD() ; + +/*extern void xlfdPopupDialog() ; dtex del*/ +extern int GetListsOfItems() ; + +/* extern void ReadCB(); dtex del */ + +Widget xlfdDialog; +static Widget xlfdWform; + +#define CS0 "Codeset 0" +#define CS1 "Codeset 1" +#define CS2 "Codeset 2" +#define CS3 "Codeset 3" + +#define ERROR_1 errmsg_org[fal_utyerrno & 0xff] +/*#define ERROR_1 fal_errmsg_org[fal_utyerrno & 0xff]*/ +/*#define ERROR_2 fal_errmsg_func[fal_utyerrno >>8]*/ + +static Widget pull1, pull2, pull3, pull4, scrolllist; +static int xlf_count = 0; +static XmString *xlf=NULL; +static int udc_count = 0; +static Boolean udc_flag = False; +static int *udc=NULL; +static int udc_val; +static int sty_count = 0; +static Boolean sty_flag = False; +static char **sty=NULL; +static char *sty_val=NULL; +static int wls_count = 0; +static Boolean wls_flag = False; +static int *wls=NULL; +static int wls_val; +static int hls_count = 0; +static Boolean hls_flag = False; +static int *hls=NULL; +static int hls_val; +static Widget *button1=NULL; +static Widget *button2=NULL; +static Widget *button3=NULL; +static Widget *button4=NULL; + +/* + * util dtex + */ + +void +xlfdPopupDialog(w) +Widget w; +{ + if (! XtIsManaged(w)) + XtManageChild(w); + else + XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w))); +} + +void +ForcePopdownDialog(w) +Widget w; +{ + if (XtIsManaged(w)){ + XtUnmanageChild(w); + } +} + +int fontcheck(char *mode) +/* + * If fontfile can't be opend, return -1. + * If fontfile is editted by other UDC client, return 1. + * normary return 0. + */ +{ + int mask; + FalFontDataList *fulllist = NULL; + FalFontID fontid; + + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_GLYPH_INDEX | + FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_CODE_SET; + + if (strcmp(mode, "w") == 0) + mask |= FAL_FONT_MASK_UPDATE; + + fontid = FalOpenSysFont(&fullFontData, mask, &fulllist); + if (fontid == 0) { + if ((fal_utyerrno & 0xff) == 0x10)/*_FAL_ERR_LCKD*/ + return (1); + return (-1); + } + + FalCloseFont( fontid ); + return (0); +} + +void setallcode(ListData *ld) +{ + int i, code, codenum; + int *codep; + int code1, code2; + + codenum = 0; + for (i = 0; i < num_gr; i++) { + codenum += (abs(gr[i].end - gr[i].start) + 1); + } + + ld->allcode = (int *) calloc(codenum, sizeof(int)); + ld->allcode_num = codenum; + codep = ld->allcode; + for (i = 0; i < num_gr; i++) { + code1 = smaller(gr[i].start, gr[i].end); + code2 = bigger(gr[i].start, gr[i].end); + for (code = code1; code <= code2; code++) { + *codep = code; + codep++; + } + } +} + +FalFontID openfont() +{ + int mask; + FalFontDataList *fulllist = NULL; + FalFontID fontid; + char *fullpath=NULL; + + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_GLYPH_INDEX | + FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_CODE_SET; + fontid = FalOpenSysFont(&fullFontData, mask, &fulllist); + if (fontid == 0) { + return ( 0 ); + } + if (fullpath != NULL) + FalFree(fullpath); + if (FalFontIDToFileName(fontid, &fullpath) < 0){ + FalCloseFont(fontid); + fontid = NULL; + } + if ((ed->fontfile = strdup(fullpath)) == NULL) { + exit (-1); + } + return (fontid); +} + +void makelist(ListData *ld) +{ + char *pattern; + int code; + int *existcodep, *allcodep; + int existcode_num; + int i; + + ld->existcode = (int *) calloc(ld->allcode_num, sizeof(int)); + existcodep = ld->existcode ; + allcodep = ld->allcode; + existcode_num = 0; + for (i = 0; i < ld->allcode_num; i++) { + code = *allcodep; + pattern = FalReadFont(fid, code, 0, 0); + if (fal_utyexists == 0) { + *existcodep = *allcodep; + existcodep++; + existcode_num++; + } + allcodep++; + } + ld->existcode_num = existcode_num; +} + +void setexistcode(ListData *ld) +{ + fid = openfont(); + + makelist(ld); + +/* close font */ + if (fid != NULL) + FalCloseFont(fid); +} + + +char i2c(int num) +{ + char c; + + if ((0 <= num) && (num <= 9)) + c = '0' + num; + else if ((10 <= num) && (num <= 15)) + c = 'a' + (num - 10); + else + fprintf(stderr,"error in i2c\n"); + return c; +} + +char *i2s(int code) +{ + char buf[8]; + char *number; + char *cp; + int i; + int tmp; + int len; + + tmp = code; + for (i = 0; ; i++) { + if (tmp < 16) { + buf[i] = i2c(tmp); + buf[i+1] = 0; + break; + } + buf[i] = i2c(tmp % 16); + tmp = tmp / 16; + } + len = strlen(buf); + number = (char *) calloc(len+3, sizeof(char)); + cp = number; + memcpy(cp, "0x", 2); + cp += 2; + for (i = len - 1; i >= 0; i--) { + *cp = buf[i]; + cp++; + } + *cp = 0; + return (number); +} + +void setexistcode_c(ListData *ld) +{ + int i; + char **code_cp; + int *codep; + + if (ld->existcode_num == 0) { + return; + } + + ld->existcode_c = (char **) calloc(ld->existcode_num, sizeof(char *)); + code_cp = ld->existcode_c; + codep = ld->existcode; + for (i = 0; i < ld->existcode_num; i++) { + *code_cp = i2s(*codep); + code_cp++; + codep++; + } +} + +void getexistcode(ListData *ld) +{ + setallcode(ld); + setexistcode(ld); + setexistcode_c(ld); +} + +/**************************************************************** + * callbacks * + ***************************************************************/ + +void quit(w, client_data, call_data) /* dtex */ +Widget w; +caddr_t *client_data, *call_data; +{ + excterminate(ed); +} + +static char * +char_set(char *str) /* dtex */ +{ + int i, count; + char *p; + for (i=strlen(str),p=&(str[i]),count=0; i && count < 2; i--,p--) { + if (*p == '-') + count ++; + } + if (count == 2) + return(p + 2); + else + return(str); +} + +static char * +spc(str, ch, count) +char * str; +char ch; +int count; +{ + char *p; + p = str + strlen(str); + for(;count && (str < p);p--) { + if (*p == ch) + count --; + } + if (! count) + return(p+1); + else + return(NULL); +} + +static void OpenWindowCB() /* dtex change */ +{ + char *str, *p; + XmStringTable st; + /*dtex add */ + int r; + int ans; + char *msg; + char *msg2; + char *msg3; + char err[128]; + extern void selcharcd(); + char *locale; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED + | FAL_FONT_MASK_XLFDNAME; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + + msg = GETMESSAGE(4, 2, "This font has no user defined characters."); + msg2 = GETMESSAGE(4, 4, "Failed to open the selected font. You have no right to access for the font file, or the format of the file is not consistent."); + msg3 = GETMESSAGE(4, 6, "The font file is used by other UDC client."); + + XtVaGetValues(scrolllist, XmNselectedItems, &st, NULL); + if( st == NULL ){ + return ; + } + str = (char *) _XmStringUngenerate((XmString) st[0], + NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if ( str == NULL ) { + return; + } + + p = spc(str, '-', 4); + p++; + + if (*p == 'p' || *p == 'P') { + str = NULL; + } + + fullFontData.xlfdname = str; + if ((ed->xlfdname = strdup(str)) == NULL) { + exit (-1); + } + if(udc_flag == True) + fullFontData.cd_set = udc_val; + else { /* dtex change */ + memset(&key, 0x00, sizeof(FalFontData)); + key.xlfdname = fullFontData.xlfdname; + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) + return; + if (fontlist->num != 1) + return; + f = fontlist->list; + /*fullFontData.cd_set = -1;*/ + fullFontData.cd_set = f->cd_set; + FalFreeFontList(fontlist); + } + + if (ld != NULL) { + freeld(ld); + } + + if ((ld = (ListData *) malloc(sizeof(ListData))) == NULL) { + excerror(ed, EXCERRMALLOC, "selcharcd", "exit"); + } + memset(ld, 0x00, sizeof(ListData)); + ld->ed = ed; + locale = getenv("LANG"); + if (locale == NULL) + locale = "C"; + if (FalGetUDCGIArea(locale, fullFontData.cd_set, + char_set(fullFontData.xlfdname), &gr, &num_gr) + == FAL_ERROR) { + fprintf(stderr, "error in FalGetUDCGIArea\n"); + sprintf(err, "%s", ERROR_1); + AskUser(ed->toplevel, ed, err, &ans, "error"); + return; + } + if (ed->function == EXPORT) { + r = fontcheck("r"); + if (r == -1) { /* file open error */ + AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error"); + return; + } else if (r == 1) { /* file is being editted by other UDC client */ + AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error"); + return; + } + /* get existing UDC code */ + getexistcode(ld); + if (ld->existcode_num == 0) { + AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error"); + return; + } + XtUnmanageChild(xlfdDialog); + selcharcd(ld->ed); + } else if (ed->function == IMPORT) { + r = fontcheck("w"); + if (r == -1) { /* file open error */ + AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error"); + return; + } else if (r == 1) { /* file is being editted by other UDC client */ + AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error"); + return; + } + /* get existing UDC code */ + getexistcode(ld); + + XtUnmanageChild(xlfdDialog); + getcharcd(ed); + } +} + +/** + ** contents : "Cancel" button callback + ** ------------------------ + ** + ** + **/ + +/*ARGSUSED*/ +static void +OpenCancelCB( widget, clientData, callData ) /* dtex change */ +Widget widget; +caddr_t clientData; +caddr_t callData; +{ +/* extern void ForcePopdownDialog(); + if ( !editPtnW ){ + exit( 0 ); + } dtex del */ + ForcePopdownDialog(xlfdDialog); +} + + +/* +* create selection window view +*/ +void +PopupSelectXLFD( top ) +Widget top ; +{ + + if( xlfdDialog == NULL ){ + if( (xlfdDialog = CreateSelectXLFD( top )) == NULL ){ + exit( -1 ) ; + } + } + /* pop up select window */ + xlfdPopupDialog( xlfdDialog ); +} + + +static void +create_xlfd() +{ + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + int i; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + xlf_count = 0; + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + return; + } + if(fontlist->num == 0) { + FalFreeFontList(fontlist); + return; + } + if (xlf) { + for (i=0; i < xlf_count; i++) { + XmStringFree(xlf[i]); + } + XtFree((char *)xlf); + } + xlf = (XmString *)XtMalloc(sizeof(XmString) * fontlist->num); + for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) { + xlf[xlf_count++] = XmStringCreateLocalized(f->xlfdname); + } + FalFreeFontList(fontlist); +} + +static void +udc_call(w) +Widget w; +{ + XmString label; + char *moji; + + XtVaGetValues(w, XmNlabelString, &label, NULL); + + moji = (char *) _XmStringUngenerate((XmString) label, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (moji) { + if(strncmp(moji, "*", 1) == 0) { + udc_flag = False; + } else if(strcmp(moji, CS0) == 0) { + udc_val = FAL_FONT_CS0; + udc_flag = True; + } else if(strcmp(moji, CS1) == 0) { + udc_val = FAL_FONT_CS1; + udc_flag = True; + } else if(strcmp(moji, CS2) == 0) { + udc_val = FAL_FONT_CS2; + udc_flag = True; + } else if(strcmp(moji, CS3) == 0) { + udc_val = FAL_FONT_CS3; + udc_flag = True; + } else { + udc_flag = False; + } + XtFree(moji); + } else { + udc_flag = False; + } + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +sty_call(w) +Widget w; +{ + XmString label; + char *moji; + if (sty_val) { + XtFree(sty_val); + sty_val = NULL; + } + XtVaGetValues(w, XmNlabelString, &label, NULL); + + moji = (char *) _XmStringUngenerate((XmString) label, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (moji) { + if(strncmp(moji, "*", 1) == 0) { + sty_flag = False; + } + else { + sty_val = XtMalloc(sizeof(char) * (strlen(moji) + 1)); + strcpy(sty_val, moji); + sty_flag = True; + } + XtFree(moji); + } + + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +wls_call(w) +Widget w; +{ + XmString label; + char *moji; + + XtVaGetValues(w, XmNlabelString, &label, NULL); + + moji = (char *) _XmStringUngenerate((XmString) label, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (moji) { + if(strncmp(moji, "*", 1) == 0) { + wls_flag = False; + } + else { + wls_val = atoi(moji); + wls_flag = True; + } + XtFree(moji); + } + + XmStringFree(label); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +hls_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + + moji = (char *) _XmStringUngenerate((XmString) label, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (moji) { + if(strncmp(moji, "*", 1) == 0) { + hls_flag = False; + } + else { + hls_val = atoi(moji); + hls_flag = True; + } + XtFree(moji); + } + XmStringFree(label); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +button_set1() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(udc[j] == f->cd_set) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button1[j], False); + else + XtSetSensitive(button1[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set2() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(strcmp(sty[j], f->style.name) == 0) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button2[j], False); + else + XtSetSensitive(button2[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set3() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(wls[j] == f->size.w) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button3[j], False); + else + XtSetSensitive(button3[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set4() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(hls[j] == f->size.h) { + found = True; + break; + } + } + if (found == False) + XtSetSensitive(button4[j], False); + else + XtSetSensitive(button4[j], True); + } + FalFreeFontList(fontlist); +} + +void +data_sort(data, count) +int *data; +int count; +{ + int *p1, *p2, tmp, i; + + for (; count; count--) { + for (i=1, p1=data, p2=data+1; i < count; i++, p1++, p2++) { + if( *p1 > *p2) { + tmp = *p2; + *p2 = *p1; + *p1 = tmp; + } + } + } +} + + +static void +font_init() /* dtex change */ +{ + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + int i, j; + char tmp[16]; + char err[128]; + Widget button; + int ans; /* dtex add */ +/* extern void Error_message(); dtex del */ + char *p; + + p = GETMESSAGE(4, 8, "There is no font"); + xlf_count = udc_count = sty_count = wls_count = hls_count = 0; + if (FalGetFontList(NULL, FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED, &fontlist) == FAL_ERROR) { + sprintf(err, "%s", ERROR_1); +/* Error_message((Widget)NULL, err); dtex del */ + AskUser(ed->toplevel, ed, err, &ans, "error"); + return; + } + if(fontlist->num == 0) { + FalFreeFontList(fontlist); +/* strcpy(err, resource.mn_no_font); dtex change */ + strcpy(err, p); +/* Error_message((Widget)NULL, err); dtex del */ + AskUser(ed->toplevel, ed, err, &ans, "error"); + return; + } + udc = (int *)XtMalloc(sizeof(int) * fontlist->num); + sty = (char **)XtMalloc(sizeof(char *) * fontlist->num); + wls = (int *)XtMalloc(sizeof(int) * fontlist->num); + hls = (int *)XtMalloc(sizeof(int) * fontlist->num); + for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) { + for (j=0,found=False; jcd_set) { + found=True; + break; + } + } + if (found == False) { + udc[udc_count++] = f->cd_set; + } + for (j=0,found=False; jstyle.name) == 0) { + found=True; + break; + } + } + if (found == False) { + sty[sty_count] = XtMalloc(sizeof(char) * (strlen(f->style.name) + 1)); + strcpy(sty[sty_count++], f->style.name); + } + if (f->size.w != -1) { + for (j=0,found=False; jsize.w) { + found=True; + break; + } + } + if (found == False) { + wls[wls_count++] = f->size.w; + } + } + for (j=0,found=False; jsize.h) { + found=True; + break; + } + } + if (found == False) { + hls[hls_count++] = f->size.h; + } + } + FalFreeFontList(fontlist); + + data_sort(udc, udc_count); + data_sort(wls, wls_count); + data_sort(hls, hls_count); + + if (udc_count > 0) { + button1 = (Widget *) XtMalloc(sizeof(Widget) * udc_count); + } + if (sty_count > 0) { + button2 = (Widget *) XtMalloc(sizeof(Widget) * sty_count); + } + if (wls_count > 0) { + button3 = (Widget *) XtMalloc(sizeof(Widget) * wls_count); + } + if (hls_count > 0) { + button4 = (Widget *) XtMalloc(sizeof(Widget) * hls_count); + } + + button = XmCreatePushButton(pull1, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)udc_call, NULL); + for (i=0; i < udc_count; i++) { + if(udc[i] == FAL_FONT_CS0) + sprintf(tmp, CS0); + else if(udc[i] == FAL_FONT_CS1) + sprintf(tmp, CS1); + else if(udc[i] == FAL_FONT_CS2) + sprintf(tmp, CS2); + else if(udc[i] == FAL_FONT_CS3) + sprintf(tmp, CS3); + else + sprintf(tmp, "Codeset %x?", udc[i]); + button1[i] = XmCreatePushButton(pull1, tmp, NULL, 0); + XtManageChild(button1[i]); + XtAddCallback(button1[i], XmNactivateCallback, + (XtCallbackProc)udc_call, NULL); + } + + button = XmCreatePushButton(pull2, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)sty_call, NULL); + for (i=0; i < sty_count; i++) { + button2[i] = XmCreatePushButton(pull2, sty[i], NULL, 0); + XtManageChild(button2[i]); + XtAddCallback(button2[i], XmNactivateCallback, + (XtCallbackProc)sty_call, NULL); + } + + button = XmCreatePushButton(pull3, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)wls_call, NULL); + for (i=0; i < wls_count; i++) { + sprintf(tmp, "%d", wls[i]); + button3[i] = XmCreatePushButton(pull3, tmp, NULL, 0); + XtManageChild(button3[i]); + XtAddCallback(button3[i], XmNactivateCallback, + (XtCallbackProc)wls_call, NULL); + } + + button = XmCreatePushButton(pull4, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)hls_call, NULL); + for (i=0; i < hls_count; i++) { + sprintf(tmp, "%d", hls[i]); + button4[i] = XmCreatePushButton(pull4, tmp, NULL, 0); + XtManageChild(button4[i]); + XtAddCallback(button4[i], XmNactivateCallback, + (XtCallbackProc)hls_call, NULL); + } +} + + +static Widget +CreateSelectXLFD( top ) /* dtex change */ +Widget top ; +{ + + int n; + Arg args[16]; + XmString xms, xms1 ; + Widget editW ; + Widget frame, row1, label1, row2, cas1, cas2, cas3, cas4; + XmString str; + char *p; + udc_flag = sty_flag = wls_flag = hls_flag = False; + + /* + * create base window + */ + n = 0 ; + XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ; + XtSetArg( args[n], XmNtitle, maintitle ) ;n++ ; /* dtex add */ + XtSetArg( args[n], XmNnoResize, True ) ; n++ ; + XtSetArg( args[n], XmNminimizeButtons, True ) ; n++ ; +/* xms = XmStringCreateLocalized( resource.exec_label ) ; dtex change*/ + p = GETMESSAGE(4, 10, "Open"); + xms = XmStringCreateLocalized( p ) ; + XtSetArg( args[n], XmNokLabelString, xms ) ; n++ ; +/* xms1 = XmStringCreateLocalized( resource.quit_label) ; dtex change*/ + p = GETMESSAGE(4, 12, "Cancel"); + xms1 = XmStringCreateLocalized( p ) ; + XtSetArg( args[n], XmNhelpLabelString, xms1 ) ; n++ ; +/* editW = XmCreateTemplateDialog( top, "dtfonteditor - Open", args, n ); dtex change*/ + p = GETMESSAGE(4, 14, "UDC data exchange utility"); + editW = XmCreateTemplateDialog( top, p, args, n ); + + XmStringFree( xms ) ; + XmStringFree( xms1 ) ; + + n = 0; + pull1 = XmCreatePulldownMenu(toplevel, "pull", args, n); + pull2 = XmCreatePulldownMenu(toplevel, "pull", args, n); + pull3 = XmCreatePulldownMenu(toplevel, "pull", args, n); + pull4 = XmCreatePulldownMenu(toplevel, "pull", args, n); + + n = 0 ; + xlfdWform = XmCreateRowColumn( editW, "BaseForm", args, n ); + XtManageChild( xlfdWform ); + + n = 0; + frame = XmCreateFrame( xlfdWform, "frame", args, n); + XtManageChild( frame ); + + n = 0 ; + row1 = XmCreateRowColumn( frame, "row", args, n ); + XtManageChild( row1 ); + + p = GETMESSAGE(4, 16, "SelectItems"); + n = 0; + label1 = XmCreateLabel( row1, p, args, n); + XtManageChild( label1 ); + + n = 0 ; + row2 = XmCreateRowColumn( row1, "row", args, n ); + XtManageChild( row2 ); + + n = 0 ; + /*str = XmStringCreateLocalized(resource.l_codeset) ; dtex change */ + p = GETMESSAGE(4, 18, "- Codeset:"); + str = XmStringCreateLocalized( p ); + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull1); n++; + cas1 = XmCreateOptionMenu( row2, "CodeSet", args, n ); + XtManageChild( cas1 ); + XtAddCallback(XmOptionButtonGadget(cas1), XmNcascadingCallback, + (XtCallbackProc)button_set1, NULL); + XmStringFree(str); + + n = 0 ; + /*str = XmStringCreateLocalized(resource.l_style) ; dtex change */ + p = GETMESSAGE(4, 20, "- Style:"); + str = XmStringCreateLocalized( p ); + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull2); n++; + cas2 = XmCreateOptionMenu( row2, "Style", args, n ); + XtAddCallback(XmOptionButtonGadget(cas2), XmNcascadingCallback, + (XtCallbackProc)button_set2, NULL); + XtManageChild( cas2 ); + XmStringFree(str); + + n = 0 ; + /*str = XmStringCreateLocalized(resource.l_width) ; dtex change */ + p = GETMESSAGE(4, 22, "- Width:"); + str = XmStringCreateLocalized( p ); + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull3); n++; + cas3 = XmCreateOptionMenu( row2, "Width", args, n ); + XtManageChild( cas3 ); + XtAddCallback(XmOptionButtonGadget(cas3), XmNcascadingCallback, + (XtCallbackProc)button_set3, NULL); + XmStringFree(str); + + n = 0 ; + /*str = XmStringCreateLocalized(resource.l_height) ; dtex change */ + p = GETMESSAGE(4, 24, "- Height:"); + str = XmStringCreateLocalized( p ); + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull4); n++; + cas4 = XmCreateOptionMenu( row2, "Height", args, n ); + XtManageChild( cas4 ); + XtAddCallback(XmOptionButtonGadget(cas4), XmNcascadingCallback, + (XtCallbackProc)button_set4, NULL); + XmStringFree(str); + + font_init(); + create_xlfd(); + + n = 0; + XtSetArg(args[n], XmNvisibleItemCount, 10) ; n++ ; + XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT) ; n++ ; + XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC) ; n++ ; + XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT) ; n++ ; + XtSetArg(args[n], XmNitems, xlf) ; n++ ; + XtSetArg(args[n], XmNitemCount, xlf_count) ; n++ ; + scrolllist = XmCreateScrolledList(xlfdWform, "scrolllist", args, n); + XtManageChild(scrolllist); + + /* + * Error_Messege + */ + + XtAddCallback(editW, XmNokCallback, (XtCallbackProc)OpenWindowCB, NULL); +/* XtAddCallback(editW, XmNokCallback, (XtCallbackProc)ReadCB, NULL); dtex del */ + XtAddCallback(editW, XmNcancelCallback, (XtCallbackProc)quit, NULL); +/* XtAddCallback(editW, XmNhelpCallback, + (XtCallbackProc)OpenCancelCB, NULL); dtex del */ + XtAddCallback(editW, XmNhelpCallback, + (XtCallbackProc)quit, NULL); + + return( editW ) ; +} diff --git a/cde/programs/dtudcexch/selectxlfd.c b/cde/programs/dtudcexch/selectxlfd.c new file mode 100644 index 00000000..b4b63b42 --- /dev/null +++ b/cde/programs/dtudcexch/selectxlfd.c @@ -0,0 +1,1034 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: selectxlfd.c /main/3 1996/10/14 14:45:17 barstow $ */ +/* + * All Rights Reserved, Copyright (c) FUJITSU LIMITED 1995 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FaLib.h" +#include "falxlfd.h" +#include "selectxlfd.h" +#include "excutil.h" + +char *shell_n[] = { "pop0", "pop1", "pop2", "pop3" } ; +char *list_n[] = { "list0", "list1", "list2", "list3" } ; + +#ifdef DEBUG +#undef Dprintf +#define Dprintf fprintf +#else +#define Dprintf +#endif /* DEBUG */ + +/* + * There is no public header file for this function (only an + * internal header XmStringI.h). + */ +extern XtPointer _XmStringUngenerate (XmString string, + XmStringTag tag, + XmTextType tag_type, + XmTextType output_type); + +extern Rsrc resource; +extern Exc_data *ed; +extern ListData *ld; +extern fal_utyerror; +extern fal_utyderror; +extern fal_utyexists; +extern char *maintitle; + +FalFontID fid; + + +/* + * parameters + */ + +char *fullPathName = NULL ; + +FalFontDataList *font_L ; +FalxCodeList *CodeList ; +FalxStyleList *StyleList ; +FalxSizeList *SizeList ; +FalxUdcArea *UdcArea ; +int SelectedOffset ; +int UdcAreaCount ; +int getmask ; + +FalxFontDataBuff KeyBuff ; + + +void PopupSelectXLFD() ; + +Widget xlfdDialog, xlfdWform, + slctBLabel[BUTTONITEMS],slctBText[BUTTONITEMS], slctButton[BUTTONITEMS], + listPop[BUTTONITEMS], listW[BUTTONITEMS], + separatorW, errorMD, msgBox ; +extern Widget cpyDialog ; + +extern Widget toplevel; + + +/* + * tmp + */ + +int fontcheck(char *fontfile, char *mode) +/* + * If fontfile can't be opend, return -1. + * If fontfile is editted by other UDC client, return 1. + * normary return 0. + */ +{ + int chk_fd; + + if (strcmp(mode, "r") == 0) { + if ((chk_fd = open(fontfile, O_RDONLY)) < 0) { + return (-1); + } + } else if (strcmp(mode, "w") == 0) { + if ((chk_fd = open(fontfile, O_RDWR)) < 0) { + return (-1); + } + } + if (isLock(chk_fd) == 1) { + close(chk_fd); + return(1); + } + close(chk_fd); + return (0); +} + +void setallcode(ListData *ld) +{ + int i, code, codenum; + int *codep; + int code1, code2; + + codenum = 0; + for (i = 0; i < UdcAreaCount; i++) { + codenum += (abs(UdcArea[i].udc_end - UdcArea[i].udc_start) + 1); + } + + ld->allcode = (int *) calloc(codenum, sizeof(int)); + ld->allcode_num = codenum; + codep = ld->allcode; + for (i = 0; i < UdcAreaCount; i++) { + code1 = smaller(UdcArea[i].udc_start, UdcArea[i].udc_end); + code2 = bigger(UdcArea[i].udc_start, UdcArea[i].udc_end); + for (code = code1; code <= code2; code++) { + *codep = code; + codep++; + } + } +} + +FalFontID openfont() +{ + int protect_key = FAL_FONT_DISPLAY; + int codeset; + FalFontID fontid; + + fontid = NULL; + codeset = font_L->list[0].cd_set; + if ((fontid = FalOpenFont(fullPathName, protect_key, codeset)) + == FAL_ERROR) { + fprintf(stderr, "FalOpenFont error\n"); + return ((FalFontID) NULL); + } + return (fontid); +} + +void makelist(ListData *ld) +{ + char *pattern; + int code; + int *existcodep, *allcodep; + int existcode_num; + int i; +/* FalFontinfo fontinfo;*/ + +/* FalQueryFont(fid, &fontinfo);*/ + + ld->existcode = (int *) calloc(ld->allcode_num, sizeof(int)); + existcodep = ld->existcode ; + allcodep = ld->allcode; + existcode_num = 0; + for (i = 0; i < ld->allcode_num; i++) { + code = *allcodep; + pattern = FalReadFont(fid, code, NULL, NULL); + if (fal_utyexists == 0) { + *existcodep = *allcodep; + existcodep++; + existcode_num++; + } + allcodep++; + } + ld->existcode_num = existcode_num; +} + +void setexistcode(ListData *ld) +{ + int *codep, *allcodep; + int i; + +/* open font */ + fid = openfont(); + + makelist(ld); + +/* close font */ + if (fid != NULL) + FalCloseFont(fid); +} + + +char i2c(int num) +{ + char c; + + if ((0 <= num) && (num <= 9)) + c = '0' + num; + else if ((10 <= num) && (num <= 15)) + c = 'a' + (num - 10); + else + fprintf(stderr,"error in i2c\n"); + return c; +} + +char *i2s(int code) +{ + char buf[8]; + char *number; + char *cp; + int i; + int tmp; + int len; + + tmp = code; + for (i = 0; ; i++) { + if (tmp < 16) { + buf[i] = i2c(tmp); + buf[i+1] = NULL; + break; + } + buf[i] = i2c(tmp % 16); + tmp = tmp / 16; + } + len = strlen(buf); + number = (char *) calloc(len+3, sizeof(char)); + cp = number; + memcpy(cp, "0x", 2); + cp += 2; + for (i = len - 1; i >= 0; i--) { + *cp = buf[i]; + cp++; + } + *cp = NULL; + return (number); +} + +void setexistcode_c(ListData *ld) +{ + int i; + char **code_cp; + int *codep; + + if (ld->existcode_num == 0) { + return; + } + + ld->existcode_c = (char **) calloc(ld->existcode_num, sizeof(char *)); + code_cp = ld->existcode_c; + codep = ld->existcode; + for (i = 0; i < ld->existcode_num; i++) { + *code_cp = i2s(*codep); + code_cp++; + codep++; + } +} + +void getexistcode(ListData *ld) +{ + setallcode(ld); + setexistcode(ld); + setexistcode_c(ld); +} + + + +/**************************************************************** + * common functions * + ***************************************************************/ + +/* + * pop up and down dialog box + */ + +void +xlfdPopupDialog(w) +Widget w; +{ + if (! XtIsManaged(w)) + XtManageChild(w); + else + XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w))); +} + +void +xlfdPopdownDialog(w) +Widget w; +{ + if (XtIsManaged(w)){ + XtUnmanageChild(w); + } +} + + +/* +* get pixel width +*/ +Dimension +GetPixelWidth( w, columns, width ) +Widget w ; +int columns ; +Dimension *width ; +{ + Arg args[1] ; + XtSetArg( args[0], XmNwidth, width ) ; + XtGetValues( w , args, 1 ) ; + return( *width / (Dimension)columns ) ; +} + + +/**************************************************************** + * callbacks * + ***************************************************************/ + +void quit(w, client_data, call_data) +Widget w; +caddr_t *client_data, *call_data; +{ + char *msg; + int ans; + + msg = GETMESSAGE(6, 2, "Do you want to terminate udcexchange?"); + + AskUser(ed->toplevel, ed, msg, &ans, "question"); + if (ans == 1) {/* terminate ok */ + FalxFreeCodeList( CodeList ) ; + FalxFreeStyleList( StyleList ) ; + FalxFreeSizeList( SizeList ) ; + FalxFreeFontList( font_L ) ; + excterminate(ed); + } +} + + +/* + * Unmanage widgets + */ +int +ClearText( num, slctBText ) +int num ; +Widget *slctBText ; +{ + int i ; + /* toggle button unset */ + for( i=0; inum ){ + XmTextSetString( slctBText[i], "" ); + } + } + return ; +} + +int +ClearButtons( num, slctButton ) +int num ; +Widget *slctButton ; +{ + int i, cnt ; + Boolean isSet ; + Arg args[5] ; + /* toggle button unset */ + for( i=0; iitem, NULL, + XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if (str) { + XmTextSetString(slctBText[num], str); + } + +#if 0 + /* set key data */ + if( SetKeyBuff( num, str ) ){ + exit(-1) ; + } +#endif /* 0 */ + + if( XtIsManaged( listPop[num] ) ) XtUnmanageChild( listPop[num] ); + +} + + + + + +void OpenWindow(w, client_data, call_data) +Widget w; +caddr_t client_data, *call_data; +{ + int r ; + int i ; + int ans; + char *msg; + char *msg1; + char *msg2; + char *msg3; + char *str, buff[512] ; + + msg = GETMESSAGE(6, 4, "No UDCs exist in this font"); + msg1 = GETMESSAGE(6, 6, "XLFD name isn't selected"); + msg2 = GETMESSAGE(6, 8, "Can't open the font file"); + msg3 = GETMESSAGE(6, 10, "The font file is used by other UDC client."); + + /* get font file name (str: XLFD name) */ + str = XmTextGetString( slctBText[0] ); + if (( str == NULL ) || (strcmp(str, "") == 0)) { + AskUser(w, ed, msg1, &ans, "error"); + return; + } + if( fullPathName != NULL ){ + free( fullPathName ) ; + } + SelectedOffset = FalxSearchFontFileName( str, font_L, buff ) ; + if( SelectedOffset < 0 ){ + exit(-1) ; + } + if( (fullPathName = strdup( buff )) == NULL ){ + exit(-1) ; + } + UdcAreaCount = FalxGetGlyphIndexInfo( str, font_L, &UdcArea ) ; + if( UdcAreaCount < 0 ){ + exit(-1) ; + } + + if( fullPathName != NULL ){ + Dprintf( stderr, "OpenWindow() : full path name = %s\n", fullPathName ); + } + for( i=0; ixlfdname = strdup(str)) == NULL) { + exit (-1); + } + if ((ed->fontfile = strdup(fullPathName)) == NULL) { + exit (-1); + } +/* getxlfd(ed);*/ +/* initialize ld */ + if ((ld = (ListData *) malloc(sizeof(ListData))) == NULL) { + excerror(ed, EXCERRMALLOC, "selcharcd", "exit"); + } + memset(ld, 0x00, sizeof(ListData)); + ld->ed = ed; + + if (ed->function == EXPORT) { + r = fontcheck(ed->fontfile, "r"); + if (r == -1) { /* file open error */ + AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error"); + return; + } else if (r == 1) { /* file is being editted by other UDC client */ + AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error"); + return; + } + /* get existing UDC code */ + getexistcode(ld); + if (ld->existcode_num == 0) { + AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error"); + return; + } + XtUnmanageChild(xlfdDialog); + selcharcd(ed); + } else if (ed->function == IMPORT) { + r = fontcheck(ed->fontfile, "w"); + if (r == -1) { /* file open error */ + AskUser(ld->ed->toplevel, ld->ed, msg2, &ans, "error"); + return; + } else if (r == 1) { /* file is being editted by other UDC client */ + AskUser(ld->ed->toplevel, ld->ed, msg3, &ans, "error"); + return; + } + /* get existing UDC code */ + getexistcode(ld); + + XtUnmanageChild(xlfdDialog); + getcharcd(ed); + } +} + + + +/**************************************************************** + * functions for create window view +****************************************************************/ + +#define SetLabel( cnt ){ \ + switch( cnt ){ \ + case 0 : buf = resource.xlfd_label ; break ; \ + case 1 : buf = resource.code_label ; break ; \ + case 2 : buf = resource.style_label; break ; \ + case 3 : buf = resource.size_label ; break ; \ + } \ + xms = XmStringCreateLocalized( buf ); \ +} + + +int +CreateXLFDLabelAndText( owner, slctBLabel, slctBText, slctButton ) +Widget owner ; +Widget *slctBLabel ; +Widget *slctBText ; +Widget *slctButton ; +{ + + Widget _slctBLabel ; + Widget _slctBText ; + Widget _slctButton ; + int i, j; + Arg args[16]; + char *buf ; + XmString xms ; + + /* + * create XLFD titles + */ + i = 0; + XtSetArg( args[i], XmNx, 20 ) ; i++ ; + XtSetArg( args[i], XmNheight, 20 ) ; i++ ; + XtSetArg( args[i], XmNtopAttachment, XmATTACH_FORM ) ; i++ ; + XtSetArg( args[i], XmNtopOffset, 20 ) ; i++ ; +/* + _slctBLabel = XmCreateLabelGadget( owner , "xlfdlabel", args, i ); +*/ + _slctBLabel = XmCreateLabel( owner , "xlfdlabel", args, i ); + + XtManageChild( _slctBLabel ); + + /* + * create text fields to display XLFD font name + */ + i = 0; + XtSetArg( args[i], XmNleftAttachment, XmATTACH_FORM ) ; i++ ; + XtSetArg( args[i], XmNleftOffset, 20 ) ; i++ ; + XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET ); i++ ; + XtSetArg( args[i], XmNtopOffset, 5 ) ; i++ ; + XtSetArg (args[i], XmNtopWidget, _slctBLabel ); i++; + XtSetArg( args[i], XmNcolumns, XLFD_COLUMNS ) ; i++ ; + XtSetArg( args[i], XmNspacing, 0 ) ; i++ ; + XtSetArg( args[i], XmNeditMode, XmSINGLE_LINE_EDIT ) ; i++ ; + XtSetArg( args[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED ) ; i++ ; + XtSetArg( args[i], XmNscrollingPolicy, XmAPPLICATION_DEFINED ) ; i++ ; +/* + XtSetArg( args[i], XmNscrollingPolicy, XmAUTOMATIC ) ; i++ ; + XtSetArg( args[i], XmNlistSizePolicy, XmCONSTANT ) ; i++ ; + + XtSetArg( args[i], XmNwidth, 600 ) ; i++ ; + XtSetArg( args[i], XmNfontList, fixed ) ; i++ ; + XtSetArg( args[i], XmNeditable, True ) ; i++ ; + XtSetArg( args[i], XmNlistSizePolicy, XmVARIABLE ) ; i++ ; +*/ + _slctBText = XmCreateScrolledText( owner , "xlfdtext", args, i ); + + XtManageChild( _slctBText ); + + /* + * create XLFD select buttons + */ + i = 0; + XtSetArg( args[i], XmNindicatorType, XmONE_OF_MANY ) ; i++ ; + XtSetArg (args[i], XmNtopWidget, _slctBText ); i++; + XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; + XtSetArg( args[i], XmNtopOffset, 15 ) ; i++ ; + XtSetArg( args[i], XmNleftAttachment, XmATTACH_WIDGET ) ; i++ ; + XtSetArg( args[i], XmNleftWidget, _slctBText ) ; i++ ; + XtSetArg( args[i], XmNleftOffset, 5 ) ; i++ ; /* WIDTH */ + XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM ) ; i++ ; + XtSetArg( args[i], XmNrightOffset, 5 ) ; i++ ; /* WIDTH */ + xms = XmStringCreateLocalized( "" ); + XtSetArg( args[i], XmNlabelString, xms ) ; i++ ; +/* + _slctButton = XmCreateToggleButtonGadget( owner , "xlfdbtn", args, i); +*/ + _slctButton = XmCreateToggleButton( owner , "xlfdbtn", args, i); + + XtManageChild( _slctButton ); + + *slctBLabel = _slctBLabel ; + *slctBText = _slctBText ; + *slctButton = _slctButton ; + +} + + + + +int +CreateOtherLabelAndText( num, owner, baseForm, + slctBLabel, topW, slctBText, slctButton ) +int num ; +Widget owner ; +Widget baseForm ; +Widget *slctBLabel ; +Widget topW ; +Widget *slctBText ; +Widget *slctButton ; +{ + + Widget _slctBLabel ; + Widget _slctBText ; + Widget _slctButton ; + int i, j; + Arg args[16]; + char *buf ; + XmString xms ; + + + if( num < 1 ) return(0) ; + + /* + * create key titles + */ + i = 0; + XtSetArg ( args[i], XmNtopWidget, + (num==1) ? baseForm : topW ); i++; + XtSetArg( args[i], XmNx, 20 ) ; i++ ; + XtSetArg( args[i], XmNheight, 20 ) ; i++ ; + XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET ) ; i++ ; +/* DEBUG + XtSetArg( args[i], XmNtopOffset, 20 ) ; i++ ; +*/ + XtSetArg( args[i], XmNtopOffset, 36 ) ; i++ ; + SetLabel(num) ; + XtSetArg( args[i], XmNlabelString, xms ) ; i++ ; +/* + _slctBLabel = XmCreateLabelGadget( owner , "label", args, i); +*/ + _slctBLabel = XmCreateLabel( owner , "label", args, i); + + XtManageChild( _slctBLabel ); + + /* + * create text fields to display selected keys + */ + i = 0; + XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; + XtSetArg( args[i], XmNtopOffset, -5 ) ; i++ ; + XtSetArg (args[i], XmNtopWidget, _slctBLabel ); i++; + XtSetArg( args[i], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; + XtSetArg( args[i], XmNrightOffset, 0 ) ; i++ ; + XtSetArg (args[i], XmNrightWidget, baseForm ); i++; + XtSetArg( args[i], XmNcolumns, KEY_COLUMNS ) ; i++ ; + XtSetArg( args[i], XmNspacing, 0 ) ; i++ ; + XtSetArg( args[i], XmNeditMode, XmSINGLE_LINE_EDIT ) ; i++ ; + XtSetArg( args[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED ) ; i++ ; + XtSetArg( args[i], XmNscrollingPolicy, XmAPPLICATION_DEFINED ) ; i++ ; + /* + XtSetArg( args[i], XmNscrollingPolicy, XmAUTOMATIC ) ; i++ ; + XtSetArg( args[i], XmNlistSizePolicy, XmCONSTANT ) ; i++ ; + + XtSetArg( args[i], XmNfontList, fixed ) ; i++ ; + XtSetArg( args[i], XmNlistSizePolicy, XmVARIABLE ) ; i++ ; + */ + if( num==BUTTONITEMS-1 ) + _slctBText = XmCreateText( owner , "text" , args, i ); + else + _slctBText = XmCreateScrolledText( owner , "text" , args, i ); + + XtManageChild( _slctBText ); + + /* + * create select buttons + */ + i = 0; + XtSetArg( args[i], XmNindicatorType, XmONE_OF_MANY ) ; i++ ; + XtSetArg( args[i], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET ) ; i++ ; + XtSetArg( args[i], XmNtopOffset, 5 ) ; i++ ; + XtSetArg (args[i], XmNtopWidget, _slctBLabel ); i++; + XtSetArg( args[i], XmNleftAttachment, XmATTACH_WIDGET ) ; i++ ; + XtSetArg( args[i], XmNleftWidget, _slctBText ) ; i++ ; + XtSetArg( args[i], XmNleftOffset, 5 ) ; i++ ; /* WIDTH */ + xms = XmStringCreateLocalized( "" ); + XtSetArg( args[i], XmNlabelString, xms ) ; i++ ; +/* + _slctButton = XmCreateToggleButtonGadget( owner , "button", args, i); +*/ + _slctButton = XmCreateToggleButton( owner , "button", args, i); + + XtManageChild( _slctButton ); + + *slctBLabel = _slctBLabel ; + *slctBText = _slctBText ; + *slctButton = _slctButton ; +} + + + +/* +* create pop up lists +*/ + + +Widget +xlfdCreateScrolledList ( owner, name, args, n ) +Widget owner ; +char *name ; +Arg *args ; +int n ; +{ + Widget listW ; + + XtSetArg( args[n], XmNselectionPolicy, XmSINGLE_SELECT ) ;n++ ; + XtSetArg( args[n], XmNlistSpacing, 4 ) ; n++ ; + XtSetArg( args[n], XmNlistSizePolicy, XmCONSTANT ) ; n++ ; + XtSetArg( args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED ) ; n++ ; + listW = XmCreateScrolledList( owner, name, args, n ); + + XtManageChild( listW ); + + + return( listW ); +} + + + +/* +* create selection window view +*/ +void +PopupSelectXLFD( top ) +Widget top ; +{ + + int n, i, j; + Arg args[16]; + char *buf ; + XmString xms ; + Dimension pix, xwidth, kwidth ; + + if( xlfdDialog == NULL ){ + /* + * create base window + */ + n = 0 ; + XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ; + XtSetArg( args[n], XmNtitle, maintitle ) ; n++ ; + XtSetArg( args[n], XmNnoResize, True ) ; n++ ; + xms = XmStringCreateLocalized( resource.exec_label ) ; + XtSetArg( args[n], XmNokLabelString, xms ) ; n++ ; + xms = XmStringCreateLocalized( resource.quit_label) ; + XtSetArg( args[n], XmNhelpLabelString, xms ) ; n++ ; +Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: start\n" ) ; + xlfdDialog = XmCreateTemplateDialog( top, "SelectDialog", args, n ); +Dprintf( stdout, "(PopupSelectXLFD)XmCreateTemplateDialog: end\n" ) ; + + n = 0 ; + xlfdWform = XmCreateForm( xlfdDialog, "BaseForm", args, n ); + XtManageChild( xlfdWform ); + + + /* + * create XLFD columns + */ +Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : start\n" ) ; + CreateXLFDLabelAndText( xlfdWform , + &slctBLabel[0], &slctBText[0], &slctButton[0] ) ; + n = 0 ; + SetLabel(0) ; + XtSetArg( args[n], XmNlabelString, xms ) ; n++ ; + XtSetValues( slctBLabel[0], args, n ) ; +Dprintf( stdout, "(PopupSelectXLFD)CreateXLFDLabelAndText : end\n" ) ; + + /* + * create other key columns + */ +Dprintf( stdout, "(PopupSelectXLFD)CreateOtherLabelAndText :start\n" ) ; + for( j=1; j +#include +#include +#include +#include +void callexpCB(); +void callimpCB(); +void exitCB(); +void helpCB(); +void udcexp(); +void udcimp(); + +#define ERROR_1 errmsg_org[fal_utyerrno & 0xff] +/*#define ERROR_1 fal_errmsg_org[fal_utyerrno & 0xff]*/ +/*#define ERROR_2 fal_errmsg_func[fal_utyerrno >>8]*/ + +Widget toplevel, mainw; + +Exc_data *ed = NULL; +ListData *ld = NULL; +char *maintitle; +/*char *terminatemsg = "Do you want to terminate dtudcexch";*/ + +/* + * Error messages(by origin) + * fal_errmsg_org + */ +char *errmsg_org[0xff]; + +Rsrc resource ; + +#define Rchar(name, class, member,def){ \ + name, class, XtRString, sizeof(char *), \ + XtOffsetOf(Rsrc, member), XtRString, (XtPointer)def } + +Widget excCreateRadioButton(Widget parent, String name, String label, + XtCallbackProc callback_func, + XtPointer client_data) +{ + Widget widget; + XmString xms; + + widget = XtVaCreateManagedWidget(name, + xmToggleButtonWidgetClass, parent, + XmNindicatorType, XmONE_OF_MANY, + NULL); + XtAddCallback(widget, XmNvalueChangedCallback, + (XtCallbackProc) callback_func, + (XtPointer) client_data); + + xms = XmStringCreateLocalized(label); + XtVaSetValues(widget, + XmNlabelString, xms, + NULL); + + XmStringFree(xms); + + return (widget); +} + +int main(int argc, char * argv[]) +{ + XtAppContext app_context; + Widget row, expfunc, impfunc, exit/*, help*/; + Arg args[20]; + Cardinal n; + static char *explabel; + static char *implabel; + static char *exitlabel; +/* static char helplabel[] = "Help";*/ +/* char msg1[] = "Failed in the start of dtudcexch";*/ + char err[128]; + int ans; + + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + +/* appinitialize */ + XtSetLanguageProc(NULL,NULL,NULL); + _DtEnvControl(0); + n = 0; + toplevel = XtAppInitialize(&app_context, "UDCexchange", + (XrmOptionDescList) NULL, + 0, (int *) &argc, argv, (String *) NULL, + args, n); + + maintitle = GETMESSAGE(8, 2, "UDC data exchange utitlity"); + + errmsg_org[0] = GETMESSAGE(8, 4, "Fatal error occurred."); + errmsg_org[1] = GETMESSAGE(8, 6, "Cannot open the font file."); + errmsg_org[2] = GETMESSAGE(8, 8, "Cannot read the font file."); + errmsg_org[3] = GETMESSAGE(8, 10, "There is no more memory."); + errmsg_org[4] = GETMESSAGE(8, 12, "Fatal error occurred."); + errmsg_org[5] = GETMESSAGE(8, 14, "The specified font file does not exist."); + errmsg_org[6] = GETMESSAGE(8, 16, "This font is not a pcf or snf font."); + errmsg_org[7] = GETMESSAGE(8, 18, "Cannot open fonts.list file."); + errmsg_org[8] = GETMESSAGE(8, 20, "The format of fonts.list file is illegal."); + errmsg_org[9] = GETMESSAGE(8, 22, "The descriptions of the fonts.list file are incorrect."); + errmsg_org[10] = GETMESSAGE(8, 24, "The format of fonts.list file is illegal."); + errmsg_org[11] = GETMESSAGE(8, 26, "Cannot open fonts.dir file."); + errmsg_org[12] = GETMESSAGE(8, 28, "Cannot read fonts.dir file."); + errmsg_org[13] = GETMESSAGE(8, 30, "Cannot read font properties."); + errmsg_org[14] = GETMESSAGE(8, 32, "Cannot get FONT property."); + errmsg_org[15] = GETMESSAGE(8, 34, "Cannot get FAMILY_NAME property."); + errmsg_org[16] = GETMESSAGE(8, 36, "This font file is already opened by other application."); + errmsg_org[17] = GETMESSAGE(8, 38, "Cannot lock font file."); + errmsg_org[18] = GETMESSAGE(8, 40, "Cannot unlock font file."); + errmsg_org[19] = GETMESSAGE(8, 42, "Cannot get lock information from the font file."); + errmsg_org[20] = GETMESSAGE(8, 44, "Cannot find the specified font file."); + errmsg_org[21] = GETMESSAGE(8, 46, "Cannot read NLS database."); + errmsg_org[22] = GETMESSAGE(8, 48, "Cannot get charset names from NLS database."); + errmsg_org[23] = GETMESSAGE(8, 50, "Charset name not defined in NLS database."); + errmsg_org[24] = GETMESSAGE(8, 52, "The specified font has not been opened."); + errmsg_org[25] = GETMESSAGE(8, 54, "Fatal error occurred."); + + resource.xlfd_label = GETMESSAGE(8, 56, "XLFD name :" ), + resource.copy_xlfd_label = GETMESSAGE(8, 58, "Original font (XLFD name) :"); + resource.code_label = GETMESSAGE(8, 60, "UDC code area :"); + resource.style_label = GETMESSAGE(8, 62, "Style :"); + resource.size_label = GETMESSAGE(8, 64, "Size (letter size) :"); + resource.exec_label = GETMESSAGE(8, 66, "Open"); + resource.quit_label = GETMESSAGE(8, 68, "Cancel"); + resource.ok_label = GETMESSAGE(8, 70, "OK"); + resource.cancel_label = GETMESSAGE(8, 72, "cancel"); + resource.copy_orgin = GETMESSAGE(8, 74, "Copy orgin code(hex) :"); + resource.copy_target = GETMESSAGE(8, 76, "Copy target code(hex) :"); + resource.copy_label = GETMESSAGE(8, 78, "Copy"); + resource.overlay_label = GETMESSAGE(8, 80, "Overlay"); + + explabel = GETMESSAGE(8, 82, "export function"); + implabel = GETMESSAGE(8, 84, "import function"); + exitlabel = GETMESSAGE(8, 86, "Cancel"); + +/* initialize ed */ + if ((ed = (Exc_data *) malloc(sizeof(Exc_data))) == NULL) { + excerror(ed, EXCERRMALLOC, "main", "exit"); + } + memset(ed,0x00,sizeof(Exc_data)); + + ed->app = app_context; + ed->toplevel = toplevel; + + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + fprintf( stderr, "GetFontList Err\n" ); + sprintf(err, "%s", ERROR_1); + AskUser(ed->toplevel, ed, err, &ans, "error"); +/* AskUser(ed->toplevel, ed, msg1, &ans, "error");*/ + excexit(ed); + } + FalFreeFontList(fontlist); + + +/* make main window */ + n = 0; + XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ; + XtSetArg(args[n], XmNtitle, maintitle); n++; + mainw = XmCreateTemplateDialog(toplevel, "mainw", args, n); + + row = XtVaCreateManagedWidget("row", xmRowColumnWidgetClass, mainw, + XmNradioBehavior, True, + XmNradioAlwaysOne, True, + NULL); + expfunc = excCreateRadioButton(row, "expfunc", explabel, + (XtCallbackProc) callexpCB, (XtPointer) ed); + + impfunc = excCreateRadioButton(row, "impfunc", implabel, + (XtCallbackProc) callimpCB, (XtPointer) ed); + + exit = excCreatePushButton(mainw, "exit", exitlabel, + (XtCallbackProc) exitCB, (XtPointer) ed); + +/* help = excCreatePushButton(mainw, "help", helplabel, + (XtCallbackProc) helpCB, (XtPointer) ed); +*/ + XtVaSetValues(mainw, + XmNmessageWindow, exit, + NULL); + + XtManageChild(mainw); + +/* XtRealizeWidget(toplevel);*/ + + XtAppMainLoop(app_context); +} + +void callexpCB(Widget widget, Exc_data * ed, XtPointer call_data) +{ + XtUnmanageChild(mainw); + udcexp(ed); +} +void callimpCB(Widget widget, Exc_data * ed, XtPointer call_data) +{ + XtUnmanageChild(mainw); + udcimp(ed); +} +void exitCB(Widget widget, Exc_data * ed, XtPointer call_data) +{ + excexit(ed); +} +/*void helpCB(Widget widget, Exc_data * ed, XtPointer call_data) +{ +}*/ diff --git a/cde/programs/dtudcexch/udcexp.c b/cde/programs/dtudcexch/udcexp.c new file mode 100644 index 00000000..97444780 --- /dev/null +++ b/cde/programs/dtudcexch/udcexp.c @@ -0,0 +1,214 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: udcexp.c /main/5 1996/10/14 14:45:34 barstow $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include "excutil.h" +#include +#include +#include +#include +#include + +void setselectedcode(); + +extern char *maintitle; + +void udcexp(Exc_data * ed) +{ + ed->function = EXPORT; + strcpy(ed->bdfmode,"w"); + + PopupSelectXLFD(ed->toplevel); +} + +void createbdf(Exc_data * ed) +{ + int i = 0; + char *comment_list[] = {""}; + int comment_num = 0; + char *msg; + int ans; + + msg = GETMESSAGE(10, 2, "Failed to make the BDF file"); + + i = ExpGpftoBDF(ed->fontfile, ed->bdffile, + ed->code_num, ed->gpf_code_list, + comment_num, comment_list, 0); + if (i != 0) { + AskUser(ed->toplevel, ed, msg, &ans, "error"); + } + excterminate(ed); +} + +void selcharokCB(Widget widget, ListData * ld, XtPointer call_data) +{ + int num; + Exc_data *ed; + int ans; + char *msg; + + msg = GETMESSAGE(10, 4, "No indexes are selected"); + + XtVaGetValues(ld->list, XmNselectedItemCount, &num, NULL); + if (num == 0) { +/* AskUser(widget, ld->ed, msg, &ans, "error");*/ + return; + } else { + setselectedcode(ld); + XtUnmanageChild(XtParent(widget)); + ed = ld->ed; + freeld(ld); + getbdffn(ed); + } +} +void selcharcancelCB(Widget widget, ListData * ld, XtPointer call_data) +{ + Exc_data *ed; + + ed = ld->ed; + freeld(ld); + excterminate(ed); +} + +XmString * setxmslist(ListData * ld) +{ + char **cp; + XmString *xmslist, *xmsp; + int i; + + if ((xmslist = (XmString *) calloc(ld->existcode_num, sizeof(XmString *))) + == NULL) { + excerror(ld->ed, EXCERRMALLOC, "setxmslist", "exit"); + } + cp = ld->existcode_c; + xmsp = xmslist; + for (i = 0; i < ld->existcode_num; i++) { + *xmsp = XmStringCreateLocalized(*cp); + xmsp++; + cp++; + } + return (xmslist); +} + +void freexmslist(ListData * ld, XmString * xmslist) +{ + XmString *xmsp; + int i; + + if (xmslist != NULL) { + xmsp = xmslist; + for (i = 0; i < ld->existcode_num; i++) { + XmStringFree(*xmsp); + xmsp++; + } + free(xmslist); + } +} + +void selcharcd(Exc_data * ed) +{ + Widget mainw, selcd, ok, cancel; + Widget slctLabel, form; + Arg args[20]; + Cardinal n; + char *oklabel; + char *cancellabel; + XmString *xmslist; + extern ListData *ld; + char *p; + + oklabel = GETMESSAGE(10, 6, "OK"); + cancellabel = GETMESSAGE(10, 8, "Cancel"); + + n = 0; + XtSetArg(args[n], XmNautoUnmanage, False); n++; + XtSetArg(args[n], XmNtitle, maintitle); n++; + mainw = XmCreateTemplateDialog(ed->toplevel, "mainw", args, n); + + n = 0; + form = XmCreateForm( mainw, "form", args, n); + XtManageChild(form); + + p = GETMESSAGE(10, 10, "glyph indexes"); + n = 0; + XtSetArg( args[n], XmNx, 20 ) ; n++; + XtSetArg( args[n], XmNheight, 20 ) ; n++ ; + XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ; + XtSetArg( args[n], XmNtopOffset, 10 ) ; n++ ; + slctLabel = XmCreateLabel( form, p, args, n); + XtManageChild(slctLabel); + + n = 0; + xmslist = setxmslist(ld); + XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ; + XtSetArg( args[n], XmNleftOffset, 20 ) ; n++ ; + XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ); n++ ; + XtSetArg( args[n], XmNtopOffset, 5 ) ; n++ ; + XtSetArg( args[n], XmNwidth, 200 ) ; n++ ; + XtSetArg (args[n], XmNtopWidget, slctLabel ); n++; + XtSetArg(args[n], XmNitems, xmslist); n++; + XtSetArg(args[n], XmNitemCount, ld->existcode_num); n++; + XtSetArg(args[n], XmNvisibleItemCount, 10); n++; + XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++; + XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++; + XtSetArg(args[n], XmNselectionPolicy, XmEXTENDED_SELECT); n++; + selcd = XmCreateScrolledList(form, "Select codes", args, n); + freexmslist(ld, xmslist); + XtManageChild(selcd); + + ld->list = selcd; + + ok = excCreatePushButton(mainw, "ok", oklabel, + (XtCallbackProc) selcharokCB, (XtPointer) ld); + + cancel = excCreatePushButton(mainw, "cancel", cancellabel, + (XtCallbackProc) selcharcancelCB, + (XtPointer) ld); + + XtManageChild(mainw); +} + +void setselectedcode(ListData *ld) +{ + int *position_list; + int position_count; + int i; + int *codep; + + XmListGetSelectedPos(ld->list, &position_list, &position_count); + + ld->ed->code_num = position_count; + ld->ed->gpf_code_list = (int *) calloc(position_count, sizeof(int)); + codep = ld->ed->gpf_code_list; + + for (i = 0; i < position_count; i++) { + *codep = *((ld->existcode)+(position_list[i]-1)); + codep++; + } +} diff --git a/cde/programs/dtudcexch/udcimp.c b/cde/programs/dtudcexch/udcimp.c new file mode 100644 index 00000000..b6867598 --- /dev/null +++ b/cde/programs/dtudcexch/udcimp.c @@ -0,0 +1,210 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: udcimp.c /main/4 1996/09/02 18:51:02 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include "excutil.h" +#include "FaLib.h" +void addcharptn(); +void setcodelists(); + +extern ListData *ld; +extern int num_gr; +extern FalGlyphRegion *gr; +extern FalFontData fullFontData; + +void udcimp(Exc_data * ed) +{ + ed->function = IMPORT; + strcpy(ed->bdfmode,"r"); + getbdffn(ed); +} + +int checkcode(int code) +{ + int i, j; + int code1, code2; + + for (i = 0; i < num_gr; i++) { + code1 = smaller(gr[i].start, gr[i].end); + code2 = bigger(gr[i].start, gr[i].end); + if ((code >= code1) && (code <= code2)) { /*in udc area */ + for (j = 0; j < ld->existcode_num; j++) { + if (code == ld->existcode[j]) + return (1); /* the font has same glyph index */ + } + return (0); + } + } + return (-1); /* out of udc area */ +} + + +int checkcodes(int code_num, int * code_list) +{ + int *codep; + int i, ans; + int exist = 0; + + codep = code_list; + for (i = 0; i < code_num; i++) { + ans = checkcode(*codep); + if (ans == -1) { + return (-1); + } else if (ans == 1) { + exist = 1; + } + codep++; + } + return (exist); +} + +void getcharcd(Exc_data * ed) +{ + int code_num; + int *code_list; + int i; + char *msg; + char *msg2; + char *msg3; + int ans, ans2; + + msg = GETMESSAGE(12, 2, "Glyph images in this BDF file can't be added to the font."); + msg2 = GETMESSAGE(12, 4, "Failed to open the selected BDF font. You have no right to access for the font file, or the format of the file is not consistent."); + msg3 = GETMESSAGE(12, 6, "There are one or more glyph images being overwritten. Overwrite?"); + + i = ImpBDFCodeList(ed->bdffile, &code_num, &code_list); + + if (i != 0) { /* bad BDF format */ + AskUser(ed->toplevel, ed, msg2, &ans, "error"); + freeld(ld); + excterminate(ed); + } + + ans2 = checkcodes(code_num, code_list); + if (ans2 == -1) { /* out of UDC code exists */ + AskUser(ed->toplevel, ed, msg, &ans, "error"); + freeld(ld); + excterminate(ed); + } else if (ans2 == 1) { /* font file has same glyph index */ + AskUser(ed->toplevel, ed, msg3, &ans, "warning"); + if (ans != 1) { + freeld(ld); + excterminate(ed); + } + } + +/* set twe codelists */ + setcodelists(ld, code_num, code_list); + + if (ImpBDFCodeListFree(&code_list) != 0) { + fprintf(stderr,"error in ImpBDFCodeListFree\n"); + } + +/* add gryph images to font */ + addcharptn(ed); +} + +void addcharptn(Exc_data * ed) +{ + int i; + int ans; + char *msg; + char *msg2; + char *msg3; + + int mask; + FalFontDataList *fulllist = NULL; + FalFontID fontid; + + msg = GETMESSAGE(12, 8, "Failed to open the selected font. You have no right to access for the font file, or the format of the file is not consistent."); + msg2 = GETMESSAGE(12, 10, "Glyph images in this BDF file can't be added to the font."); + msg3 = GETMESSAGE(12, 12, "Failed in the registration of the font file."); + + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_GLYPH_INDEX | + FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UPDATE | + FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_CODE_SET; + + i = ImpBDFCheck(ed->bdffile, ed->fontfile); + if (i != 0) { + AskUser(ed->toplevel, ed, msg2, &ans, "error"); + excterminate(ed); + } + + fontid = FalOpenSysFont(&fullFontData, mask, &fulllist); + if (fontid == 0) { + AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error"); + excterminate(ed); + } + i = 0; + i = ImpBDFtoGpf(ed->bdffile, ed->fontfile, + ed->code_num, ed->bdf_code_list); + FalCloseFont( fontid ); + if (i != 0) { + AskUser(ed->toplevel, ed, msg3, &ans, "error"); + } + + excterminate(ed); +} + +void setcodelists(ListData *ld, int code_num, int *code_list) +{ + int *c1, *c2; + int i; + Exc_data *ed; + + ld->ed->code_num = code_num; + + if ((c1 = (int *) calloc(code_num, sizeof(int))) == NULL) { + ed = ld->ed; + freeld(ld); + excerror(ed, EXCERRMALLOC, "setcodelists", "exit"); + } + ld->ed->bdf_code_list = c1; + c2 = code_list; + for (i = 0; i < code_num; i++) + { + *c1 = *c2; + c1++; + c2++; + } + + if ((c1 = (int *) calloc(code_num, sizeof(int))) == NULL) { + ed = ld->ed; + freeld(ld); + excerror(ed, EXCERRMALLOC, "setcodelists", "exit"); + } + ld->ed->gpf_code_list = c1; + c2 = code_list; + for (i = 0; i < code_num; i++) + { + *c1 = *c2; + c1++; + c2++; + } +} diff --git a/cde/programs/dtudcexch/xlfdutil.c b/cde/programs/dtudcexch/xlfdutil.c new file mode 100644 index 00000000..811da2d4 --- /dev/null +++ b/cde/programs/dtudcexch/xlfdutil.c @@ -0,0 +1,339 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: xlfdutil.c /main/2 1996/10/14 14:45:50 barstow $ */ +/* + * All Rights Reserved, Copyright (c) FUJITSU LIMITED 1995 + * + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Authors: Seiya Miyazaki FUJITSU LIMITED + * Hiroyuki Chiba Fujitsu Basic Software Corporation + * + */ + + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FaLib.h" +#include "falxlfd.h" + +#include "selectxlfd.h" + +#ifdef DEBUG +#undef Dprintf +#define Dprintf fprintf +#else +#define Dprintf +#endif /* DEBUG */ + +/* + * parameters + */ +static char* skipSpace() ; + +extern FalFontDataList *font_L ; +extern FalxFontDataBuff KeyBuff ; +extern FalxCodeList *CodeList ; +extern FalxStyleList *StyleList ; +extern FalxSizeList *SizeList ; +extern int SelectedOffset ; +extern int getmask ; + +extern char *fullPathName ; + + +extern Widget toplevel ; +extern Widget + xlfdWform, cpyWform, + slctBLabel[BUTTONITEMS],slctBText[BUTTONITEMS], slctButton[BUTTONITEMS], + listPop[BUTTONITEMS], listW[BUTTONITEMS], + errorMD, msgBox ; + + +/**************************************************************** + * functions for get font infomation +****************************************************************/ + +int +GetXLFDInfomations() +{ + Dprintf( stdout, "GetXLFDInfomations()\n" ) ; + + /* initialize */ + getmask = 0 ; + SelectedOffset = 0 ; + fullPathName = NULL ; + FalxInitDataBuff( &KeyBuff ) ; + + /* get UDC informations */ + if( FalxGetFontList( &font_L, XtDisplayOfObject( toplevel ) ) ){ + Dprintf( stderr, "GetXLFDInfomations() : FalxGetFontList() error.\n" ) ; + return(-1); + } + + /* create code area list */ + if( FalxCreateCodeList( &CodeList, font_L ) ){ + Dprintf( stderr, "\nGetXLFDInfomations() : FalxCreateCodeList() error.\n" ) ; + return(-1); + } + + /* create style list */ + if( FalxCreateStyleList( &StyleList, font_L ) ){ + Dprintf( stderr, "\nGetXLFDInfomations() : FalxCreateStyleList() error.\n" ) ; + return(-1); + } + + /* create size list */ + if( FalxCreateSizeList( &SizeList, font_L ) ){ + Dprintf( stderr, "\nGetXLFDInfomations() : FalxCreateSizeList() error.\n" ) ; + return(-1); + } + + return(0) ; +} + + + + + +int +GetItemsToDisplay( num, itemcnt, xms_list ) +int num ; +int *itemcnt ; +XmString **xms_list ; +{ + int i, j, cnt ; + char *sp ,string[256], buf[256] ; + Arg args[1]; + int length, maxlength ; + FalxXlfdList *xlist ; + + int tmp_cnt ; + char **tmp_dlist, *str ; + XmString *xms ; + int rlen ; + int rtn ; + + + switch( num ){ + case 0 : /* XLFD */ + /* set key data */ + for( i=1; inum ; + tmp_dlist = xlist->list ; + break ; + case 1 : /* code area */ + tmp_cnt = CodeList->num ; + tmp_dlist = (char **)malloc( sizeof(char *) * tmp_cnt ) ; + if( tmp_dlist == NULL ) return(-1) ; + for( i=0; idlist[i]->fontset) ) ; + sp += rlen ; + for( j=0; jdlist[i]->code_area_num; j++ ){ + rlen = sprintf( sp, "%x - %x ", + CodeList->dlist[i]->alist[j]->udc_start, + CodeList->dlist[i]->alist[j]->udc_end ) ; + sp += rlen ; + } + if( (tmp_dlist[i] = strdup( string )) == NULL ){ + return(-1) ; + } + } + break ; + case 2 : /* style */ + tmp_cnt = StyleList->num ; + tmp_dlist = (char **)malloc( sizeof(char *) * tmp_cnt ) ; + for( i=0; ilist[i] )) == NULL ){ + return(-1) ; + } + } + break ; + case 3 : /* size */ + tmp_cnt = SizeList->num ; + tmp_dlist = (char **)malloc( sizeof(char *) * tmp_cnt ) ; + for( i=0; ilist[i] ) ; + if( (tmp_dlist[i] = strdup( string )) == NULL ){ + return(-1) ; + } + } + break ; + default : /* error */ + return(-1) ; + } + if( (xms = (XmString *)calloc( tmp_cnt, sizeof(XmString) )) == NULL ){ + return( -1 ) ; + } + + /* + * set list for display + */ + maxlength = 0 ; + for ( i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "falfont.h" +#include "xoakufont.h" + +#define NUM 0x80 + +static Display *display=NULL; +static int screen; +static Boolean open_font; +static Widget toggle[NUM]; +static Widget text; +static Window BaseW; +static Widget set_widget; +static Widget code_w=0; +static int font_w, font_h; +static unsigned long fg, bg; +static unsigned char *ptn, *clr; +static Pixmap no_pix; +static int len, code1; +static char *FontName=NULL; +static FalFontID fid; + +extern FalFontID font_id; +extern int CodePoint; +extern Resource resource; + +static void +OpenFont() +{ + int mask; + FalFontData font_data; + static FalFontDataList *copylist; + extern FalFontData fullFontData; + + if(strcmp(FontName, fullFontData.xlfdname) == 0) { + fid = font_id; + return; + } + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED; + font_data.xlfdname = FontName; + if (! CodePoint) { + mask |= FAL_FONT_MASK_GLYPH_INDEX; + } + + fid = FalOpenSysFont(&font_data, mask, ©list); +} + +static void +CloseFont() +{ + if (fid != font_id) { + FalCloseFont(fid); + fid = 0; + } +} + +static void +DrawCode(w, low_code) +Widget w; +int low_code; +{ + int hi_code; + char *f = NULL; + XImage image; + GC gc = XDefaultGC(display, 0); + + hi_code = (code1 & 0xff) << 8; + image.width = font_w; + image.height = font_h; + image.xoffset = 0; + image.format = XYBitmap; + image.byte_order = LSBFirst; + image.bitmap_unit = 8; + image.bitmap_bit_order = MSBFirst; + image.bitmap_pad = 8; + image.depth = 1; + image.bytes_per_line = (font_w - 1) / 8 + 1; + XSetForeground(display, gc, fg); + XSetBackground(display, gc, bg); + + if (open_font) { + f = (char *)FalReadFont(fid, hi_code | low_code, font_w, font_h); + if(f == NULL || f == (char *)FAL_ERROR) { + return; + } + if( EXISTS_FLAG == 0 ) { + memcpy(ptn, f, len); + image.data = (char *)ptn; + } else { + image.data = (char *)clr; + } + XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h); + } else { + if (ptnGet(hi_code | low_code, ptn) == 0) { + image.data = (char *)ptn; + } else { + image.data = (char *)clr; + } + XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h); + } +} + +static void +SetPixmap(start_code) +{ + int hi_code, low_code; + char *f = NULL; + XImage image; + GC gc = XDefaultGC(display, 0); + + hi_code = (start_code & 0xff) << 8; + image.width = font_w; + image.height = font_h; + image.xoffset = 0; + image.format = XYBitmap; + image.byte_order = LSBFirst; + image.bitmap_unit = 8; + image.bitmap_bit_order = MSBFirst; + image.bitmap_pad = 8; + image.depth = 1; + image.bytes_per_line = (font_w - 1) / 8 + 1; + XSetForeground(display, gc, fg); + XSetBackground(display, gc, bg); + + if (open_font) { + for (low_code=0; low_code < NUM; low_code++) { + f = (char *)FalReadFont(fid, hi_code | low_code, font_w, font_h); + if(f == NULL || f == (char *)FAL_ERROR) { + return; + } + if( EXISTS_FLAG == 0 ) { + memcpy(ptn, f, len); + image.data = (char *)ptn; + } else { + image.data = (char *)clr; + } + XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h); + } + } else { + for (low_code=0; low_code < NUM; low_code++) { + if (ptnGet(hi_code | low_code, ptn) == 0) { + image.data = (char *)ptn; + } else { + image.data = (char *)clr; + } + XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h); + } + } +} + +static void +Code1Call(w, start_code, data) +Widget w; +int start_code; +XmListCallbackStruct *data; +{ + code1 = start_code + data->item_position -1; + SetPixmap(code1); +} + +static void +Code2Call(w, code2, data) +Widget w; +int code2; +XmPushButtonCallbackStruct *data; +{ + char asc[16]; + sprintf(asc, "%2.2X%2.2X", code1, code2); + XtVaSetValues(text, XmNvalue, asc, NULL); + DrawCode(w, code2); +} + +static void +PrevPage(w, scroll) +Widget w, scroll; +{ + int *list; + int num; + if (XmListGetSelectedPos(scroll, &list, &num)) { + if(list[0] > 1) { + XmListSelectPos(scroll, list[0] - 1, True); + XmListSetPos(scroll, list[0] - 1); + } + } +} + +static void +NextPage(w, scroll) +Widget w, scroll; +{ + int *list; + int num, item; + XtVaGetValues(scroll, XmNitemCount, &item, NULL); + if (XmListGetSelectedPos(scroll, &list, &num)) { + if(list[0] < item) { + XmListSelectPos(scroll, list[0] + 1, True); + XmListSetBottomPos(scroll, list[0] + 1); + } + } +} + +static void +Cancel() +{ + XtUnmapWidget(XtParent(code_w)); +} + +static void +Apply() +{ + char *asc; + XtVaGetValues(text, XmNvalue, &asc, NULL); + XtVaSetValues(set_widget, XmNvalue, asc, NULL); + XtFree(asc); + Cancel(); +} + +static void +CreateItem(item, item_count, start_code) +XmString *item; +int *item_count; +int *start_code; +{ + int count; + int start, end; + char str[5]; + FalFontinfo finfo; + extern int begin_code, last_code; + + if (open_font) { + if (FalQueryFont(fid, &finfo) == FAL_ERROR) { + *item_count = 0; + CloseFont(); + return; + } + font_w = finfo.width; + font_h = finfo.height; + start = (finfo.top & 0xff00) >> 8; + end = (finfo.bottom & 0xff00) >> 8; + } else { + font_w = edg.width; + font_h = edg.height; + start = (begin_code & 0xff00) >> 8; + end = (last_code & 0xff00) >> 8; + } + if (CodePoint) { + if (start < 0x80) + start = 80; + if (end < 0x80) + start = 80; + } else { + if (start > 0x7f) + start = 0x7f; + if (end > 0x7f) + end = 0x7f; + } + *start_code = start; + for (count=0;start <= end; start++, count++) { + sprintf(str, "%X", start); + item[count] = XmStringCreateLocalized(str); + } + *item_count = count; +} + +static Widget +CreateCodeWindow(w) +Widget w; +{ + Widget top, base1, base2, base3, base4; + Widget frame, scroll, label, sep, form; + Widget push1, push2, push3, push4; + Arg args[16]; + int n, i; + XmString item[128]; + XmString xcs; + int item_count, start_code, add_c; + char add[9]; + + n = 0; + XtSetArg(args[n], XmNmwmFunctions, MWM_FUNC_ALL | MWM_FUNC_CLOSE | + MWM_FUNC_RESIZE); n++; + XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL); n++; + top = XmCreateFormDialog(w, "code", args, n); + + base1 = XtVaCreateManagedWidget("base1", xmRowColumnWidgetClass, top, + XmNorientation, XmVERTICAL, NULL); + + frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, base1, + NULL); + + base2 = XtVaCreateManagedWidget("base2", xmRowColumnWidgetClass, frame, + XmNorientation, XmHORIZONTAL, NULL); + + CreateItem(item, &item_count, &start_code); + code1 = start_code; + n = 0 ; + XtSetArg(args[n], XmNitems, item); n++; + XtSetArg(args[n], XmNitemCount, item_count); n++; + XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); n++; + scroll = XmCreateScrolledList(base2, "scroll", args, n); + XtManageChild(scroll); + XtAddCallback(scroll, XmNbrowseSelectionCallback, + (XtCallbackProc)Code1Call, (XtPointer) (intptr_t) start_code); + XtAddCallback(scroll, XmNdefaultActionCallback, + (XtCallbackProc)Code1Call, (XtPointer) (intptr_t) start_code); + XmListSelectPos(scroll, 1, False); + + base3 = XtVaCreateManagedWidget("base3", xmRowColumnWidgetClass, base2, + XmNorientation, XmHORIZONTAL, + XmNpacking, XmPACK_COLUMN, + XmNradioAlwaysOne, True, + XmNradioBehavior , True, + XmNmarginHeight, 0, + XmNmarginWidth, 0, + XmNspacing, 0, + XmNnumColumns, 9, NULL); + + + len = (font_w / 8 + 1) * font_h; + ptn = (unsigned char *) malloc(len); + clr = (unsigned char *) malloc(len); + memset(clr, 0, len); + XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL); + no_pix = XCreatePixmapFromBitmapData(display, BaseW, (char *)clr, + font_w, font_h, fg, bg, DefaultDepth(display, screen)); + + XtVaCreateManagedWidget("", xmLabelWidgetClass, base3, NULL); + for (i=0; i < 16; i++) { + sprintf(add, "%2.1X", i); + XtVaCreateManagedWidget(add, xmLabelWidgetClass, base3, NULL); + } + if (CodePoint) + add_c = 8; + else + add_c = 0; + for (i=0; i < NUM; i++) { + if ((i % 16) == 0) { + snprintf(add, sizeof(add), "%2.1X", add_c++); + XtVaCreateManagedWidget(add, xmLabelWidgetClass, base3, NULL); + } + toggle[i] = XtVaCreateWidget("toggle", + xmPushButtonWidgetClass, base3, + XmNwidth, font_w, + XmNheight, font_h, + XmNlabelType, XmPIXMAP, + XmNlabelPixmap, no_pix, NULL); + XtAddCallback(toggle[i], XmNactivateCallback, + (XtCallbackProc)Code2Call, (XtPointer) (intptr_t) i); + XtAddCallback(toggle[i], XmNarmCallback, + (XtCallbackProc)DrawCode, (XtPointer) (intptr_t) i); + XtAddCallback(toggle[i], XmNdisarmCallback, + (XtCallbackProc)DrawCode, (XtPointer) (intptr_t) i); + XtAddEventHandler(toggle[i], ExposureMask, False, + (XtEventHandler)DrawCode, (XtPointer) (intptr_t) i); + } + XtManageChildren(toggle, NUM); + + base4 = XtVaCreateManagedWidget("base4", xmFormWidgetClass, base1, NULL); + + xcs = XmStringCreateLocalized(resource.l_code); + label = XtVaCreateManagedWidget("code", xmLabelWidgetClass, base4, + XmNlabelString, xcs, + XmNleftAttachment, XmATTACH_POSITION, + XmNleftPosition, 30, NULL); + + text = XtVaCreateManagedWidget("text", xmTextWidgetClass, base4, + XmNeditable, False, + XmNcursorPositionVisible, False, + XmNcolumns, 4, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, label, NULL); + + sep = XtVaCreateManagedWidget("sep", xmSeparatorGadgetClass, base1, + XmNorientation, XmHORIZONTAL, NULL); + + form = XtVaCreateManagedWidget("sep", xmFormWidgetClass, base1, NULL); + + xcs = XmStringCreateLocalized(resource.previous); + push1 = XtVaCreateManagedWidget("PreviousPage", xmPushButtonWidgetClass, form, + XmNleftAttachment, XmATTACH_POSITION, + XmNlabelString, xcs, + XmNleftPosition, 10, NULL); + XtAddCallback(push1, XmNactivateCallback, + (XtCallbackProc)PrevPage, (XtPointer)scroll); + XmStringFree(xcs); + + xcs = XmStringCreateLocalized(resource.next); + push2 = XtVaCreateManagedWidget("NextPage", xmPushButtonWidgetClass, form, + XmNleftAttachment, XmATTACH_POSITION, + XmNlabelString, xcs, + XmNleftPosition, 35, NULL); + XtAddCallback(push2, XmNactivateCallback, + (XtCallbackProc)NextPage, (XtPointer)scroll); + XmStringFree(xcs); + + xcs = XmStringCreateLocalized(resource.apply); + push3 = XtVaCreateManagedWidget("Apply", xmPushButtonWidgetClass, form, + XmNleftAttachment, XmATTACH_POSITION, + XmNlabelString, xcs, + XmNleftPosition, 60, NULL); + XtAddCallback(push3, XmNactivateCallback, (XtCallbackProc)Apply, NULL); + XmStringFree(xcs); + + xcs = XmStringCreateLocalized(resource.l_cancel); + push4 = XtVaCreateManagedWidget("Cancel", xmPushButtonWidgetClass, form, + XmNleftAttachment, XmATTACH_POSITION, + XmNlabelString, xcs, + XmNleftPosition, 80, NULL); + XtAddCallback(push4, XmNactivateCallback, (XtCallbackProc)Cancel, NULL); + XmStringFree(xcs); + + return(top); +} + +void +CodeWindow(widget, font_name, load_font) + Widget widget; + char * font_name; + Boolean load_font; +{ + static Boolean old_load_font; + extern int CodePoint; + + set_widget = widget; + + BaseW = XtWindow(widget); + display = XtDisplay(widget); + screen = DefaultScreen(display); + if (FontName == NULL || strcmp(font_name, FontName) || + load_font != old_load_font) { + old_load_font = load_font; + if (code_w) { + XtDestroyWidget(code_w); + code_w = 0; + free(ptn); + free(clr); + if (fid != 0) { + CloseFont(); + } + } + if (FontName) + free(FontName); + FontName = (char *)malloc(strlen(font_name)+1); + strcpy(FontName, font_name); + + if (load_font) { + OpenFont(); + if (fid == 0) + return; + open_font = True; + } else { + open_font = False; + } + + code_w = CreateCodeWindow(widget); + XtManageChild(code_w); + } else { + XtMapWidget(XtParent(code_w)); + } +} diff --git a/cde/programs/dtudcfonted/comsub.c b/cde/programs/dtudcfonted/comsub.c new file mode 100644 index 00000000..62b8fab4 --- /dev/null +++ b/cde/programs/dtudcfonted/comsub.c @@ -0,0 +1,1612 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* comsub.c 1.36 - Fujitsu source for CDEnext 96/09/09 15:30:40 */ +/* $XConsortium: comsub.c /main/8 1996/09/19 19:36:37 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include + +#include +#include "fssxeg.h" +#include "falfont.h" +#include "ufontrsrc.h" + +static void writePtn(); +static void sig_receive(); +char *get_cmd_path() ; + +extern Resource resource; + +/*********************************************************************** + manage the character patterns + **********************************************************************/ + +#define GUADDPTNN 100 /* number of charcters for memory allocation */ +/* this structure corresopnds to single font file */ +typedef struct { /* area to manage character patterns */ + char flag; /* invalid(=0)/valid(=1) */ + int width; /* pattern width */ + int height; /* pattern height */ + int nptn; /* number of characters in editting */ + int nmaxptn; /* maximum number of characters in editting */ + int ptnsize; /* size per byte of single pattern */ + UINT ptnmemsize; /* size of memory of whole patterns */ + USHORT *ntoc; /* character list / relative code */ + USHORT *ctop; /* relative code / bitmap area */ + char *ptn; /* pointer to the bimap area */ + int cptnnum; /* current pattern number */ +} PATTERN_MNG; + +static PATTERN_MNG pm; /* Pattern_Manage */ + +/* selection window for XLFD */ +extern FalFontData fullFontData; +extern FalFontData copyFontData; +extern int CodePoint; + +char *fullpath=NULL; +int begin_code=0, last_code=0; + +FalCodeRegion CodeArea[10]; +char AreaStr[160]; + +#define FAL_ERROR_STR resource.falerrmsg[((fal_utyerrno & 0xff) > 25) ? 0 : (fal_utyerrno & 0xff)] + +FalFontID font_id; + +static char * +get_locale() +{ + char *loc; + + if ((loc = getenv("LANG")) != NULL) { + return(loc); + } else { + return("C"); + } +} + +/* contents : convert the sequential number in the editor into + * relative code in the system area + * values : -1 : terminated abnormally + * else : relative code + */ + +int +ptnSqToNo( num ) +int num; /* sequential number */ +{ + if( (pm.flag == 0) || (num >= pm.nptn) ) + return( -1 ); + + return( pm.ntoc[num] ); +} + + + + +/* contents : convert the relative code in the system area into + * sequential number in the editor + * values : -1 : terminated abnormally + * else : sequential number + */ + +int +ptnNoToSq( ncode ) +int ncode; /* relative code */ +{ + int sq; + + if( pm.flag == 0 ) + return( -1 ); + + for( sq=0 ; sq < pm.nptn ; sq++ ) { + if( pm.ntoc[sq] == ncode ) + return( sq ); + } + + return( -1 ); +} + + + + +/* + * contents : convert the character code into relative code + * values : relative code + * caution : There is no security against unusal character code. + */ + +int +codeToNo( code ) +int code; /* character code */ +{ + return( code - begin_code); +} + + + + +/* + * contents : convert the relative code into character code + * values : character code + * caution : There is no security against unusal character code. + */ + +int +noToCode( sno ) +int sno; /* relative code */ +{ + return( sno + begin_code); +} + + +/* + * contents : judge the input code with the system defined character area + * values : 0 : in the system defined area + * -1 : not in the system defined area + */ + +int +codeCheck( code ) +int code; +{ + if (code < begin_code || code > last_code) { + return( -1 ); + } + return( 0 ); +} + +/* + * contents : allocate memories for character patterns + * + * values : ID : sequential number of the area + * -1 : terminated abnormally + */ + +static int +ptnOpen(n, maxc, width, height) +int n; /* initial number of charcters */ +int maxc; +int width; /* pattern width */ +int height; /* pattern height */ +{ + int i; + int fpsize; + + if( (n < 0) || (width <= 0) || (height <= 0) ) + return( -1 ); + + if( pm.flag != 0 ) { + return( -1 ); + } + + pm.width = width; + pm.height = height; + pm.nptn = 0; + pm.nmaxptn = n + GUADDPTNN; + pm.ptnsize = height * ((width+7)/8); + fpsize = pm.ptnsize + 1; + pm.ptnmemsize = (UINT) ( fpsize * pm.nmaxptn ) ; + + if(( pm.ntoc = (USHORT *)calloc(maxc, sizeof(USHORT)) ) == NULL) { + return( -1 ); + } + if(( pm.ctop = (USHORT *)calloc(maxc, sizeof(USHORT)) ) == NULL ) { + free( pm.ntoc ); + return( -1 ); + } + if(( pm.ptn = (char *)malloc(fpsize*pm.nmaxptn) ) == NULL ) { + free( pm.ctop ); + free( pm.ntoc ); + return( -1 ); + } + + for( i=0 ; i < maxc ; i++ ) { + pm.ntoc[i] = 0xFFFF; + pm.ctop[i] = 0xFFFF; + } + /* set null to each character pattern area */ + for( i=0 ; i < pm.nmaxptn ; i++ ) { + pm.ptn[fpsize * i] = 0; + } + pm.cptnnum = 0; + pm.flag = 1; + + return( 0 ); +} + + + + +/* + * contents : set free memories for character patterns + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +ptnClose() +{ + if( pm.flag == 0 ) { + return( -1 ); + } + pm.flag = 0; + free( pm.ntoc ); + free( pm.ctop ); + free( pm.ptn ); + + return( 0 ); +} + + + + +/* + * contents : add character pattern to the character management area + * + * values : 0 : same code was exists and replaced it + * 1 : add new pattern + * -1 : terminated abnormally + */ + +int +ptnAdd( code, ptn ) +int code; /* code to be add */ +char *ptn; /* pointer to the pattern */ +{ + int fpsize; + int ncode; + USHORT pno; + char *pf; + char *pp; + int i; + char *re_ptn; + UINT re_ptnmemsize; + int cpn; + + if( pm.flag == 0 ) + return( -1 ); + + fpsize = pm.ptnsize + 1; + ncode = codeToNo( code ); + + if( (pno = pm.ctop[ncode]) != 0xFFFF ) { + pf = pm.ptn + fpsize*pno; + pp = pf + 1; + for( i=0 ; i < pm.ptnsize ; i++ ) + pp[i] = ptn[i]; + return( 0 ); + } + + if( pm.nptn >= pm.nmaxptn ) { + re_ptnmemsize = pm.ptnmemsize + GUADDPTNN*fpsize; + if(pm.ptn == NULL) { + re_ptn = malloc( re_ptnmemsize ); + } else { + re_ptn = realloc(pm.ptn, re_ptnmemsize); + } + if (re_ptn == NULL) { + return( -1 ); + } + pm.ptnmemsize = re_ptnmemsize; + pm.ptn = re_ptn; + for( i=pm.nmaxptn ; i < pm.nmaxptn + GUADDPTNN ; i++ ) { + pm.ptn[fpsize * i] = 0; + } + pm.nmaxptn += GUADDPTNN; + } + + cpn = pm.cptnnum + 1; + for( i=0 ; i < pm.nmaxptn ; i++, cpn++ ) { + if( cpn >= pm.nmaxptn ) { + cpn = 0; + } + if( pm.ptn[fpsize * cpn] == 0 ) { + break; + } + } + pm.cptnnum = cpn; + + pm.ctop[ncode] = (USHORT) cpn; + pf = pm.ptn + fpsize*cpn; + pp = pf + 1; + pf[0] = 1; + for( i=0 ; i < pm.ptnsize ; i++ ) + pp[i] = ptn[i]; + + for( i=pm.nptn ; i >=0 ; i-- ) { + if( ncode > (int)pm.ntoc[i] ) { + break; + } + pm.ntoc[i+1] = pm.ntoc[i]; + } + pm.ntoc[i+1] = (USHORT) ncode; + pm.nptn += 1; + + return( 1 ); +} + + +/* + * contents : get a character pattern from the character management area + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +ptnGet( code, ptn ) +int code; +char *ptn; +{ + int ncode; + int fpsize; + USHORT pno; + char *pf; + char *pp; + int i; + + if( (pm.flag == 0) || (codeCheck(code) == -1) ) + return( -1 ); + + ncode = codeToNo( code ); + fpsize = pm.ptnsize +1; + + if( (pno = pm.ctop[ncode]) == 0xFFFF ) + return( -1 ); + + pf = pm.ptn + pno*fpsize; + pp = pf +1; + + for( i=0 ; i < pm.ptnsize ; i++ ) + ptn[i] = pp[i]; + + return( 0 ); +} + + +/* + * contents : judge the character pattern exist or not + * values : 1 : exists + * 0 : not exists + * -1 : terminated abnormally + */ + +int +ptnSense( code ) +int code; +{ + if( (pm.flag == 0) || (codeCheck(code) == -1) ) + return( -1 ); + + if( pm.ctop[ codeToNo(code) ] == 0xFFFF ) + return( 0 ); + else + return( 1 ); +} + + +/* + * contents : delete the character pattern + * values : 1 : deleted + * 0 : the pattern does not exist + * -1 : terminated abnormally + */ + +int +ptnDel( code ) +int code; +{ + int ncode; + int fpsize; + USHORT pno; + char *pf; + int i; + + if( (pm.flag == 0) || (codeCheck(code) == -1) ) + return( -1 ); + + ncode = codeToNo( code ); + fpsize = pm.ptnsize +1; + + if( (pno = pm.ctop[ncode]) == 0xFFFF ) { + return( 0 ); + } + + pf = pm.ptn + pno*fpsize; + + pf[0] = 0; + pm.ctop[ncode] = 0xFFFF; + + for( i=0 ; i < pm.nptn ; i++ ) { + if( (int)pm.ntoc[i] == ncode ) + break; + } + for( ; i < pm.nptn ; i++ ) + pm.ntoc[i] = pm.ntoc[i+1]; + + pm.nptn --; + return( 1 ); +} + + +/* + * contents : get the infomation of the character + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +ptnGetInfo( n, width, height ) +int *n; /* the number of characters in editting */ +int *width; /* pattern width */ +int *height; /* pattern height */ +{ + if( pm.flag == 0 ) + return( -1 ); + + *n = pm.nptn; + *width = pm.width; + *height = pm.height; + + return( 0 ); +} + + +/******************************************************************** + * handle bit map file(1) * + ********************************************************************/ + +struct { /* infomation of character pattern */ + int width; /* pattern width */ + int height; /* pattern height */ + int xbytesize; +} bitInfo = { 16, 16 ,2 }; + + +/* + * contents : set infomation for handling bit-mapped files + */ + +static void +bitSetInfo( width, height) +int width; /* pattern width */ +int height; /* pattern height */ +{ + bitInfo.width = width; + bitInfo.height = height; + bitInfo.xbytesize = (width+7)/8; + + return; +} + + +/* + * contents : set the bit at specefied coordinate on + */ + +void +bitSet( ptn, cx, cy ) +char *ptn; +int cx; +int cy; +{ + if((cx < 0) || (bitInfo.width <= cx) || (cy < 0) || (bitInfo.height <= cy)) + return; + ptn[ bitInfo.xbytesize*cy + cx/8 ] |= (char)( 0x80 >> (cx%8) ); +} + + +/* + * contents : set the bit at specefied coordinate off + */ + +void +bitReset( ptn, cx, cy ) +char *ptn; +int cx; +int cy; +{ + if((cx < 0) || (bitInfo.width <= cx) || (cy < 0) || (bitInfo.height <= cy)) + return; + ptn[ bitInfo.xbytesize*cy + cx/8 ] &= ~(char)( 0x80 >> (cx%8) ); +} + + +/* + * contents : returns 1 ( bit on ) or 0 ( bit off ) + */ + +int +bitRead( ptn, cx, cy ) +char *ptn; +int cx; +int cy; +{ + if((cx < 0) || (bitInfo.width <= cx) || (cy < 0) || (bitInfo.height <= cy)) + return( 0 ); + return( ptn[ bitInfo.xbytesize*cy + cx/8 ] + & + (char)( 0x80 >> (cx%8) ) ? 1 : 0 + ); +} + + +/* + * contents : clear the specefied bitmap file + */ + +void +bitPtnClear( ptn ) +char *ptn; +{ + int i; + + for( i=0 ; i < bitInfo.height * bitInfo.xbytesize ; i++ ) + ptn[i] = 0; +} + + +/* + * contents : copy the bit-mapped file + */ + +void +bitPtnCopy( d_ptn, s_ptn ) +char *d_ptn; /* pointer of the destination file */ +char *s_ptn; /* pointer of the source file */ +{ + int i; + + for( i=0 ; i < bitInfo.height * bitInfo.xbytesize ; i++ ) + d_ptn[i] = s_ptn[i]; +} + + + +/************************************************************************ + * handle bit map file(2) * + * caution : You must call bitSetInfo() before use these functions. * + * * + ************************************************************************/ + +/* + * contents : draw lines between desired two points + * values : 0 : terminated normally + * -1 : outside of the edtting pane + */ + +int +bitDrawLine( ptn, x1, y1, x2, y2 ,mode ) +char *ptn; /* pointer of the bit map file */ +int x1; +int y1; +int x2; +int y2; +int mode; /* 0: erase 1: draw */ +{ + float dx, dy; + float x, y; + float delta; + int i; + + if( (x1 < 0) || (x2 < 0) || (y1 < 0) || (y2 < 0) || + (bitInfo.width <= x1) || (bitInfo.width <= x2) || + (bitInfo.height <= y1) || (bitInfo.height <= y2) ) + return( -1 ); + + dx = x2 - x1; + dy = y2 - y1; + x = x1 + 0.5; + y = y1 + 0.5; + + delta = abs((int)dx) > abs((int)dy) ? dx : dy; + if( delta < 0 ) + delta = -delta; + if( delta == 0) + delta = 0.75; + dx /= delta; + dy /= delta; + + for(i=0 ; i <= (int)delta ; i++ ) { + mode == 0 ? bitReset(ptn,(int)x,(int)y) : bitSet(ptn,(int)x,(int)y); + x += dx; + y += dy; + } + return( 0 ); +} + + +/* + * contents : draw circle + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawCircle( ptn, x1, y1, x2, y2, mode ) +char *ptn; +int x1; +int y1; +int x2; +int y2; +int mode; +{ + int dx, dy; + int i,x; + double rad, half; + + if( (x1 < 0) || (y1 < 0) || (x2 < 0.0) || ( y2 < 0.0) ) { + return( -1 ); + } + + dx = abs(x2 - x1); + dy = abs(y2 - y1); + rad = sqrt((double)(dx * dx + dy * dy)) + 0.5; + half = rad * sqrt(2.0)/2; + for (i = 0; i <= (int)half; i++) { + x = (int)sqrt(rad * rad - (double)(i*i)); + if( mode ) { + bitSet (ptn, x1 - x, y1 - i); + bitSet (ptn, x1 - x, y1 + i); + bitSet (ptn, x1 + x, y1 - i); + bitSet (ptn, x1 + x, y1 + i); + bitSet (ptn, x1 - i, y1 - x); + bitSet (ptn, x1 - i, y1 + x); + bitSet (ptn, x1 + i, y1 - x); + bitSet (ptn, x1 + i, y1 + x); + } else { + bitReset(ptn, x1 - x, y1 - i); + bitReset(ptn, x1 - x, y1 + i); + bitReset(ptn, x1 + x, y1 - i); + bitReset(ptn, x1 + x, y1 + i); + bitReset(ptn, x1 - i, y1 - x); + bitReset(ptn, x1 - i, y1 + x); + bitReset(ptn, x1 + i, y1 - x); + bitReset(ptn, x1 + i, y1 + x); + } + } + return( 0 ); +} + + +/* + * contents : draw rectangle + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawRect( ptn, x, y, width, height, mode ) +char *ptn; +int x; +int y; +int width; +int height; +int mode; +{ + int i; + + width --; + height --; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width <= width +x) || (bitInfo.height <= height +y) ) + return( -1 ); + + for( i=x ; i <= width+x ; i++ ) { + if( mode == 0 ) { + bitReset( ptn, i, y ); + bitReset( ptn, i, height+y ); + } + else { + bitSet( ptn, i, y ); + bitSet( ptn, i, height+y ); + } + } + for( i=y+1 ; i < height +y ; i++ ) { + if( mode == 0 ) { + bitReset( ptn, x, i ); + bitReset( ptn, x+width, i ); + } + else { + bitSet( ptn, x, i ); + bitSet( ptn, x +width, i ); + } + } + + return( 0 ); +} + + +/* + * contents : clear the inside of the specefied rectangle + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawCls( ptn, x, y, width, height ) +char *ptn; +int x; +int y; +int width; +int height; +{ + int i, j; + + width --; + height --; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width <= width +x) || (bitInfo.height <= height +y) ) + return( -1 ); + + for( i=x ; i <= width +x ; i++ ) { + for( j=y ; j <= height +y ; j++ ) + bitReset( ptn, i, j ); + } + + return( 0 ); +} + + +/* + * contents : paint out the inside of the desired rectangle + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawSet( ptn, x, y, width, height ) +char *ptn; +int x; +int y; +int width; +int height; +{ + int i, j; + + width --; + height --; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width <= width +x) || (bitInfo.height <= height +y) ) + return( -1 ); + + for( i=x ; i <= width +x ; i++ ) { + for( j=y ; j <= height +y ; j++ ) + bitSet( ptn, i, j ); + } + return(0); +} + + +/* + * contents : reverse the inside of the desired rectangle + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawRev( ptn, x, y, width, height ) +char *ptn; +int x; +int y; +int width; +int height; +{ + int i, j; + + width --; + height --; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width <= width +x) || (bitInfo.height <= height +y) ) + return( -1 ); + + for( i=x ; i <= width +x ; i++ ) { + for( j=y ; j <= height +y ; j++ ) { + if( bitRead( ptn, i, j ) == 0 ) + bitSet ( ptn, i, j ); + else + bitReset( ptn, i, j ); + } + } + + return( 0 ); +} + + +static char cut_buffer[MAXPTNBYTE]; +static int cut_buffer_w=0; +static int cut_buffer_h=0; +/* + * contents : copy the specified rectangle area + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawCpy(ptn, sx, sy, width, height, cut_flag) +char *ptn; +int sx; +int sy; +int width; +int height; +int cut_flag; +{ + int i, j; + + if ((sx < 0) || (sy < 0) || (width < 2) || (height < 2) || + (bitInfo.width < width +sx) || (bitInfo.height < height +sy)) + return( -1 ); + + cut_buffer_w = width; + cut_buffer_h = height; + + for (i=0; i < width; i++) { + for (j=0; j < height; j++) { + if (bitRead(ptn, i + sx, j + sy) != 0) + bitSet(cut_buffer, i, j); + else + bitReset(cut_buffer, i, j); + if (cut_flag) + bitReset(ptn, i + sx, j + sy); + } + } + return( 0 ); +} + +int +bitDrawPaste(ptn, dx, dy) +char *ptn; +int dx; +int dy; +{ + int i, j; + int width, height; + + if((dx < 0) || (dy < 0) || (cut_buffer == 0) || + (cut_buffer_w == 0) || (cut_buffer_h == 0)) + return( -1 ); + + width = (cut_buffer_w <= bitInfo.width - dx) + ? cut_buffer_w : bitInfo.width - dx; + height = (cut_buffer_h <= bitInfo.height - dy) + ? cut_buffer_h : bitInfo.height - dy; + + for (i=0; i < width; i++) { + for (j=0; j < height; j++) { + if( bitRead(cut_buffer, i, j) != 0 ) + bitSet (ptn, i + dx, j + dy); + else + bitReset(ptn, i + dx, j + dy); + } + } + return( 0 ); +} + + + +/* + * contents : rotate the inside of the area specified + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawRoll( ptn, x, y, width, height ) +char *ptn; +int x; +int y; +int width; +int height; +{ + char *point; + int xx, yy; + int count; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width < width +x) || (bitInfo.height < height +y) ) + return( -1 ); + + point = (char *)malloc((width * height) * sizeof(int)); + + for(count=0,yy=0; yy < height; yy++) { + for(xx=0; xx < width; xx++ ) { + point[count++] = bitRead(ptn, x + xx, y + yy); + bitReset(ptn, x + xx, y + yy); + } + } + + for(count=0,yy=0; yy < height; yy++) { + for(xx=0; xx < width; xx++ ) { + point[count++] == 0 ? bitReset(ptn, x + height - yy - 1, y + xx) + : bitSet(ptn, x + height - yy - 1, y + xx); + } + } + + free(point); + return( 0 ); +} + + +/* + * contents : reverse the top-bottom symmetry of the rectangle specified + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawSymV( ptn, x, y, width, height ) +char *ptn; +int x; +int y; +int width; +int height; +{ + int k, j; + int d1, d2; + + width --; + height --; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width <= width +x) || (bitInfo.height <= height +y) ) + return( -1 ); + + for( k=0 ; k <= width ; k++ ) { + for( j=0 ; j <(height+1)/2 ; j++ ) { + d1 = bitRead( ptn, x +k, y +j ); + d2 = bitRead( ptn, x +k, y + height -j ); + + d1 == 0 ? bitReset( ptn, x +k, y +height -j ) + : bitSet( ptn, x +k, y +height -j ); + d2 == 0 ? bitReset( ptn, x +k, y +j ) + : bitSet( ptn, x +k, y +j ); + } + } + return( 0 ); +} + + +/* + * contents : reverse the left-right symmetry of the rectangle specified + * values : 0 : terminated normally + * -1 : terminated abnormally + */ + +int +bitDrawSymH( ptn, x, y, width, height ) +char *ptn; +int x; +int y; +int width; +int height; +{ + int k, j; + int d1, d2; + + width --; + height --; + + if( (x < 0) || (y < 0) || (width < 0) || (height < 0) || + (bitInfo.width <= width +x) || (bitInfo.height <= height +y) ) + return( -1 ); + + for( k=0 ; k < (width+1)/2 ; k++ ) { + for( j=0 ; j <= height ; j++ ) { + d1 = bitRead( ptn, x +k, y +j ); + d2 = bitRead( ptn, x +width -k, y +j ); + + d1 == 0 ? bitReset( ptn, x +width -k, y +j ) + : bitSet( ptn, x +width -k, y +j ); + d2 == 0 ? bitReset( ptn, x +k, y +j ) + : bitSet( ptn, x +k, y +j ); + } + } + return( 0 ); +} + + +static char * +char_set(char *str) +{ + int i, count; + char *p; + for (i=strlen(str),p=&(str[i]),count=0; i && count < 2; i--,p--) { + if (*p == '-') + count ++; + } + if (count == 2) + return(p + 2); + else + return(str); +} + + +/**************************************************************** + * read and write SNF file * + * * + * * + ****************************************************************/ + +/* + * contents : read character patterns from specified SNF file + * values : number of the area that was allocated to manage font file + * -1 : terminated abnormally + * -2 : file is locked + */ +int +readSNF(fdata, width, height, err) +FalFontData **fdata; +int *width; +int *height; +char *err; +{ + FalFontinfo finfo; + int start, end; + int code; + int mask; + int i; + char *ptn; + static FalFontDataList *fulllist; + char *mes; + + FalGlyphRegion *gr, *gr_p; + int num_gr; + char tmp[16]; + unsigned int s, e; + + + if (fulllist) { + FalFreeFontList(fulllist); + fulllist = NULL; + } + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_UPDATE | + FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + if (fullFontData.cd_set != -1) { + mask |= FAL_FONT_MASK_CODE_SET; + } + if (! CodePoint) { + mask |= FAL_FONT_MASK_GLYPH_INDEX; + } + if (FalGetFontList(&fullFontData, mask, &fulllist) == FAL_ERROR) { + strcpy(err, FAL_ERROR_STR); + return(-1); + } + if(fulllist == NULL) { + strcpy(err, resource.mn_no_font); + return(-1); + } + if (fulllist->num != 1) { + FalFreeFontList(fulllist); + fulllist = NULL; + strcpy(err, resource.mn_plural_font); + return(-1); + } + *fdata = &(fulllist->list[0]); + font_id = FalOpenSysFont(&fullFontData, mask, &fulllist); + mes = 0; + if (font_id == 0 && (fal_utyerrno & 0xff) == FAL_ERR_FNT_OPN) { + mes = (char *) malloc(strlen(resource.mn_no_perm)+strlen(fal_err_file)+10); + if (mes == NULL) { + strcpy(err, resource.mn_no_mem); + FalFreeFontList(fulllist); + return( -1 ); + } + sprintf(mes, "%sfile: %s", resource.mn_no_perm, fal_err_file); + + mask &= ~FAL_FONT_MASK_UPDATE; + font_id = FalOpenSysFont(&fullFontData, mask, &fulllist); + if (font_id == 0) { + free(mes); + strcpy(err, FAL_ERROR_STR); + FalFreeFontList(fulllist); + return( -1 ); + } + } else if (font_id == 0) { + strcpy(err, FAL_ERROR_STR); + FalFreeFontList(fulllist); + return( -1 ); + } + if (fullpath != NULL) + FalFree(fullpath); + if (FalFontIDToFileName(font_id, &fullpath) == FAL_ERROR) { + strcpy(err, FAL_ERROR_STR); + if (mes) + free(mes); + return( -1 ); + } + + if( FalQueryFont( font_id, &finfo ) == FAL_ERROR ) { + strcpy(err, FAL_ERROR_STR); + FalCloseFont( font_id ); + if (mes) + free(mes); + return( -1 ); + } + *width = finfo.width; + *height = finfo.height; + + fullFontData.cd_set = (* fdata)->cd_set; + if (CodePoint) { + if (FalGetUDCCPArea(get_locale(),(* fdata)->cd_set, + char_set(( *fdata)->xlfdname), (FalCodeRegion **) &gr, &num_gr) == FAL_ERROR) { + strcpy(err, FAL_ERROR_STR); + FalCloseFont( font_id ); + if (mes) + free(mes); + return( -1 ); + } + } else { + if (FalGetUDCGIArea(get_locale(),(* fdata)->cd_set, + char_set(( *fdata)->xlfdname), &gr, &num_gr) == FAL_ERROR) { + strcpy(err, FAL_ERROR_STR); + FalCloseFont( font_id ); + if (mes) + free(mes); + return( -1 ); + } + } + if (! num_gr) { + FalCloseFont( font_id ); + strcpy(err, resource.mn_not_udc); + if (mes) + free(mes); + return( -1 ); + } + if (mes) { + Error_message2(NULL, mes); + free(mes); + fullFontData.prm = True; + } + start = gr->start; + end = gr->end; + for (i=0, gr_p=gr; i < num_gr; i++, gr_p++) { + CodeArea[i].start = gr_p->start; + CodeArea[i].end = gr_p->end; + s = (gr_p->start & 0xff00) >> 8; + e = (gr_p->end & 0xff00) >> 8; + if (i == 0) { + sprintf(tmp, "0x%x:0x%x", s, e); + strcpy(AreaStr, tmp); + } else { + sprintf(tmp, ",0x%x:0x%x", s, e); + strcat(AreaStr, tmp); + } + if (start > gr_p->start) + start = gr_p->start; + if (end < gr_p->end) + end = gr_p->end; + } + CodeArea[i].start = -1; + begin_code = start; + last_code = end; + + if (start > end) { + FalCloseFont( font_id ); + sprintf(err, "%s\nStart address = %x End address = %x\n", resource.mn_illegal_area, start, end); + return( -1 ); + } + + if( ptnOpen(1, end - start + 1, finfo.width, finfo.height) < 0 ) { + FalCloseFont( font_id ); + strcpy(err, resource.mn_no_mem); + return( -1 ); + } + bitSetInfo( finfo.width, finfo.height ); + + for (i=0, gr_p=gr; i < num_gr; i++, gr_p++) { + if (start > gr_p->start) + gr_p->start = start; + if (end < gr_p->end) + gr_p->end = end; + start = gr_p->end; + + if (! CodePoint) { + for (code=gr_p->start; code <= gr_p->end; code++) { + if (code & 0x80) { + code &= 0xff00; + code += 0x100; + continue; + } + + ptn = (char *)FalReadFont( font_id, code, finfo.width, finfo.height ); + if( ptn == (char *)FAL_ERROR ) { + strcpy(err, FAL_ERROR_STR); + FalFree(gr); + FalCloseFont( font_id ); + + ptnClose(); + return( -1 ); + } + if( EXISTS_FLAG == 0 ) { + if( ptnAdd( code, ptn ) != 1 ) { + FalFree(gr); + strcpy(err, resource.mn_no_read); + FalCloseFont( font_id ); + + ptnClose(); + return( -1 ); + } + } + } + } else { + for (code=gr_p->start; code <= gr_p->end; code++) { + if (! (code & 0x80)) { + code &= 0xff00; + code |= 0x80; + continue; + } + + ptn = (char *)FalReadFont( font_id, code, finfo.width, finfo.height ); + if( ptn == (char *)FAL_ERROR ) { + strcpy(err, FAL_ERROR_STR); + FalFree(gr); + FalCloseFont( font_id ); + + ptnClose(); + return( -1 ); + } + if( EXISTS_FLAG == 0 ) { + if( ptnAdd( code, ptn ) != 1 ) { + FalFree(gr); + strcpy(err, resource.mn_no_read); + FalCloseFont( font_id ); + + ptnClose(); + return( -1 ); + } + } + } + } + } + FalFree(gr); + *err = 0; + return( 0 ); +} + +static void +bicopy(s1, s2, size) +char *s1, *s2; +int size; +{ + register int i; + for(i=size; i; i--, s1++, s2++) + *s2 = *s1; +} + +int +copySNF(start, end, ptn, num, err) +int start; +int end; +char ***ptn; +int *num; +char *err; +{ + FalFontID fid; + int mask; + char ** _ptn, **p; + int i; + static FalFontDataList *copylist; + int count; + char *point; + int size; + + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED; + if (copyFontData.cd_set != -1) { + mask |= FAL_FONT_MASK_CODE_SET; + } + if (! CodePoint) { + mask |= FAL_FONT_MASK_GLYPH_INDEX; + } + + fid = FalOpenSysFont(©FontData, mask, ©list); + if (fid == 0) { + strcpy(err, FAL_ERROR_STR); + FalFreeFontList(copylist); + return( -1 ); + } + + _ptn = (char **)malloc(sizeof(char *) * (end - start + 1)); + if (! CodePoint) { + for (i = start, count = 0, p = _ptn; i <= end; i++) { + if (i & 0x80) { + i &= 0xff00; + i += 0x100; + continue; + } + point = (char *)FalReadFont( fid, i, pm.width, pm.height ); + if( point == (char *)FAL_ERROR ) { + strcpy(err, FAL_ERROR_STR); + FalCloseFont( fid ); + return( -1 ); + } + if (EXISTS_FLAG != 0) + continue; + size = pm.height * ((pm.width+7)/8); + *p = (char *) XtMalloc(size); + bicopy(point, *p, size); + count++; p++; + } + } else { + for (i = start, count = 0, p = _ptn; i <= end; i++) { + if (! (i & 0x80)) { + i &= 0xff00; + i |= 0x80; + continue; + } + point = (char *)FalReadFont( fid, i, pm.width, pm.height ); + if( point == (char *)FAL_ERROR ) { + strcpy(err, FAL_ERROR_STR); + FalCloseFont( fid ); + return( -1 ); + } + if (EXISTS_FLAG != 0) + continue; + size = pm.height * ((pm.width+7)/8); + *p = (char *) XtMalloc(size); + bicopy(point, *p, size); + count++; p++; + } + } + *num = count; + *ptn = _ptn; + FalCloseFont( fid ); + if (count == 0) { + strcpy(err, resource.mg_non_code); + return( -1 ); + } + return( 0 ); +} + +void +freeSNF(addr, count) +char **addr; +int count; +{ + char **p; + for (p=addr; count; count--, p++) + XtFree(*p); + XtFree((char *)addr); +} + +static int sig_flg = 0; /* flag for signal */ + +/* + * contents : write character patterns to the specified SNF file + * values : 0 : terminated normally + * -1 : terminated abnormally + * 1xxx : process is not completed ¡Êxxx:persents finished¡Ë + * + * + */ + +int +writeSNF( restart, err ) +int restart; /* ON:continue OFF:initial */ +int *err; /* errors : */ +{ + static int pfstdi[2]; + static FILE *fstdi; + static int nptn; + static int width, height; + static int n; + static int persents = 0; + char *argv[8]; + int code; + int endst; + int persents_; + + char ptn[MAXPTNBYTE]; + char code_set[2]; + + FalGIInf *gi; + int num_gi; + + char *command; + + /* get command path */ + if (!(command = (char *)get_cmd_path(getenv("PATH"), resource.l_ptog_cmd))){ + command = resource.l_ptog; + } + + if (fullFontData.cd_set == FAL_FONT_CS0) + sprintf(code_set, "0"); + else if (fullFontData.cd_set == FAL_FONT_CS1) + sprintf(code_set, "1"); + else if (fullFontData.cd_set == FAL_FONT_CS2) + sprintf(code_set, "2"); + else if (fullFontData.cd_set == FAL_FONT_CS3) + sprintf(code_set, "3"); + + /* signal set */ + signal( SIGPIPE, sig_receive ); + sig_flg = 0; + + if( restart == 0 ) { + + persents = 0; + + if( ptnGetInfo( &nptn, &width, &height ) != 0 ) { + *err = 100; + return( -1 ); + } + + if( pipe(pfstdi) !=0 ) { + *err = 101; + return( -1 ); + } + + switch( fork() ) { + case -1: + close( pfstdi[0] ); + close( pfstdi[1] ); + *err = 102; + return( -1 ); + case 0: + close( 0 ); /** 0 ... stdin **/ + + dup( pfstdi[0] ); + close( pfstdi[0] ); + close( pfstdi[1] ); + argv[0] = resource.l_ptog_cmd; + argv[1] = "-codeset"; + argv[2] = code_set; + argv[3] = "-xlfd"; + argv[4] = fullFontData.xlfdname; + argv[5] = "-init"; + argv[6] = "-f"; + argv[7] = NULL; + execv (command, argv ); + exit( 103 ); + } + + + close( pfstdi[0] ); + fstdi = (FILE *)fdopen( pfstdi[1], "w" ); + fprintf( fstdi, "numfonts:%d\n", nptn ); + fprintf( fstdi, "width:%d\n", width ); + fprintf( fstdi, "height:%d\n", height ); + + bitSetInfo( width, height ); + n = 0; + } + + while( (n < nptn) && ( sig_flg == 0) ) { + code = noToCode( ptnSqToNo(n) ); + if( ptnGet(code, ptn ) != 0 ) { + fclose( fstdi ); + close( pfstdi[1] ); + *err = 104; + return( -1 ); + } + + if (CodePoint) { + fal_code_to_glyph(get_locale(), code, &gi, &num_gi); + fprintf( fstdi, "code:0x%x\n", gi[0].glyph_index ); + FalFreeGI(gi, num_gi); + } else { + fprintf( fstdi, "code:0x%x\n", code ); + } + writePtn(ptn, width, height, fstdi); + + n++; + if ( sig_flg != 0 ) + break; + if( n == nptn ) { + persents = 0; + return( 1101 ); + } + if( (persents_ = (n*100)/nptn) != persents ) { + persents = persents_; + return( 1000 + persents ); + } + } + + if(sig_flg == 0 ) fprintf( fstdi, "enddata\n" ); + + fclose( fstdi ); + close( pfstdi[1] ); + + wait( &endst ); + + + if ( WIFEXITED(endst) && !WEXITSTATUS(endst) ) { + *err = 0; + return( 0 ); + } + else { + if ( WIFEXITED(endst) ) + *err = WEXITSTATUS(endst); + else{ + if ( WIFSTOPPED(endst) ) + *err = ( WTERMSIG(endst) << 8 ); + } + return( -1 ); + } +} + + +/* + * contents : set flag when dtudcfonted received signal + */ + +static void +sig_receive() +{ + sig_flg = 1; + return; +} + + +/* + * contents : convert bit map file into SNF file + */ + +static void +writePtn(ptn, width, height, fp) +char *ptn; +int width; +int height; +FILE *fp; +{ + int i, j, k; + int nbyte; + int tw; + char p, *pbuf; + static char buf[ (MAXPTNSIZE+1)*MAXPTNSIZE+1 ]; + + nbyte = (width + 7) / 8; + + pbuf = buf; + for (i=0 ; i < height ; i++) { + for (j=0, tw=width ; j < nbyte ; j++ ) { + p = *ptn++; + for ( k=0 ; (k < 8) && (tw > 0) ; k++, tw--) { + if (p & 0x80) + *pbuf++ = '0'; + else + *pbuf++ = '-'; + p = p << 1; + } + } + *pbuf++ = '\n'; + } + *pbuf = '\0'; + fprintf(fp, "%s", buf); +} diff --git a/cde/programs/dtudcfonted/cpyw.c b/cde/programs/dtudcfonted/cpyw.c new file mode 100644 index 00000000..2cae1422 --- /dev/null +++ b/cde/programs/dtudcfonted/cpyw.c @@ -0,0 +1,619 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* cpyw.c 1.9 - Fujitsu source for CDEnext 96/10/30 13:31:40 */ +/* $XConsortium: cpyw.c /main/7 1996/11/08 01:53:38 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#include + +#include + +#include "xoakufont.h" +#include "util.h" + + +extern Resource resource ; +extern Widget cpyDialog; + +/** + ** create and display the "User defined character ecitor :Copy" window + ** ================================================================== + **/ + +void PopdownCpyPtn(); +void DoCpyProc(); +void CpyPtnCB(); +void CpyCB(); + +/* static */ TextField SrcTf; +/* static */ TextField DestTf; + + +/** + ** contents : initialize the "Copy" window + ** -------------------- + ** + ** + **/ + +void +InitCpyPtn() +{ + /* initialize font infomation */ +} + + +/** + ** contents : create and pop up the "Copy" window + ** ---------------------------------- + ** + **/ + +void +CpyPtnCB() +{ + extern void CpyPtnXLFD(); + CpyPtnXLFD(); +} + + +/** + ** contents : pop down the "Copy" window + ** ---------------------- + **/ + +void +PopdownCpyPtn() +{ + ForcePopdownDialog(cpyDialog); +} + + +/** contents : + ** get the character strings of source code area from the input field + ** -------------------------------------- + **/ + +String +CpySrcCodeTfValue() +{ + return(GetTextFieldValue(&SrcTf)); +} + + +/** contents : + ** get the character strings of destination code area from input field + ** -------------------------------------- + **/ + +String +CpyDestCodeTfValue() +{ + return(GetTextFieldValue(&DestTf)); +} + + +/** + ** contents : pop up the copy confirmation window + ** -------------------------------- + **/ + +void +PopupCpyNotice( message ) +String message; +{ + char bmsg[512] = ""; + + static NoticeButton buttons[] = { + NBTNARGS( DoCpyProc, NULL, NULL, True, False ), + NBTNARGS( NULL, NULL, NULL, True, False ), + }; + static NButton BTN = NBUTTONS( buttons ); + + snprintf(bmsg, sizeof(bmsg), "%s%s", resource.mn_cpy_lost, message); + SetItemLabel(&BTN, 0, resource.l_ok); + SetItemLabel(&BTN, 1, resource.l_cancel); + PopupNotice( cpyPtnW, bmsg, D_WARNING, &BTN, False, resource.l_warning_title); +} + + +/** + ** contents : "Copy" button callback + ** ------------------------ + ** execute the copy processing + **/ + +/*ARGSUSED*/ +void +CpyCB(w, cdata) +Widget w; +XtPointer cdata; +{ + extern Boolean BeforeCpyCheck(); + if (BeforeCpyCheck(cdata)){ + PopdownCpyPtn(); + DoCpyProc(); + } +} + + + +/** + ** "Add/Delete" window + ** =================================================================== + **/ + +/** + ** contents : pop down the "Add/Delete" window + ** ------------------------------ + **/ + +static void +PopdownMngPtn() +{ + PopdownDialog(mngPtnW); +} + +/** + ** contents : "Add" button callback + ** ------------------------ + **/ + +static void +AddCB() +{ + int s_code, e_code; + extern Boolean BeforeMngCheck(); + extern void DoAddProc(); + + if (BeforeMngCheck(&s_code, &e_code)){ + DoAddProc(s_code, e_code); + PopdownMngPtn(); + } +} + +/** + ** contents : "Delete" button callback + ** ------------------------ + **/ + +static void +DelCB() +{ + int s_code, e_code; + extern void DoDelProc(); + extern Boolean BeforeMngCheck(); + + if (BeforeMngCheck(&s_code, &e_code)){ + DoDelProc(s_code, e_code); + } +} + +static ButtonItems add_btn[] = { + BTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) AddCB, NULL, NULL, True, True ), + BTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) DelCB, NULL, NULL, True, False ), + BTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) PopdownMngPtn, NULL, NULL, True, False ), +}; +static Button AddBTN = BUTTONS( add_btn ); + +static TextField MngCodeTf; + +/** + ** contents : create and pop up the "Add/Delete" window + ** ------------------------------------ + **/ + +void +MngPtnCB() +{ + if (! mngPtnW){ + Widget rowcol; + + SetItemLabel(&AddBTN, 0, resource.l_add); + SetItemLabel(&AddBTN, 1, resource.l_delete); + SetItemLabel(&AddBTN, 2, resource.l_cancel); + rowcol = + CreateDialogAndButtons( toplevel, resource.l_add_title, + + NULL, &AddBTN, XtNumber(add_btn), &mngPtnW); + + CreateTextField(rowcol, "wgkTxtF", + resource.l_manage_code, &MngCodeTf, 4); + } + PopupDialog(mngPtnW); +} + + + + +/** + ** contents : get the character strings of code for add or delete from the input field + ** -------------------------------------------- + **/ + +String +MngCodeTfValue() +{ + return(GetTextFieldValue(&MngCodeTf)); +} + + + +/** + ** the delete confirmation window + ** =================================================================== + **/ + +static Widget CreateDelNotice(); +static void drawDelPtn(); +static void drawDelCode(); +static void CBdnOblB_del(); +static void EHdnBulB_disp(); +void EHStaT_disp(); /* add 1995.09.20 */ + +static Widget dnStaT_code[D_MAX], dnBulB_disp[D_MAX], dnPopW; + +/** + ** contents : pop up the delete confirmation window + ** -------------------------- + **/ + +void +PopupDelNotice( owner ) +Widget owner; +{ + int i; + Widget delNoticeW = NULL; + + delNoticeW = CreateDelNotice(owner); + XtVaSetValues(XtParent(delNoticeW), XmNmappedWhenManaged, False, NULL); + XtManageChild(delNoticeW); + + for ( i=0 ; i < dn.disp_num ; i++ ) { + /* moved from paneDelNotice body */ + dl[i].disp_winID = XtWindow( dnBulB_disp[i] ); + + drawDelCode(i); + drawDelPtn(i); + } + XtVaSetValues(XtParent(delNoticeW), XmNmappedWhenManaged, True, NULL); + + XBell(XtDisplayOfObject(delNoticeW), 0); +} + + +/** + ** contents : clear the image of deleted character + ** ---------------------------------------------- + **/ + +static void +dstrypaneDelNotice() +{ + int i; + + for ( i=0; ibitmap_bit_order = MSBFirst; + dl[i].dispImage->byte_order = MSBFirst; + + } + XtManageChildren( itemform, dn.disp_num ); + return(dnPopW); +} + + +/** + ** contents : delete characters from editor + ** ----------------------------------------- + ** + **/ + +static void +CBdnOblB_del() +{ + int code; /* code number for check */ + int ncode; /* sequential number in the codeset system area */ + int sq_now; /* sequential number in the editor */ + char mode; /* notify the modification of the edit list */ + extern void chgEdCode(); + + XtSetSensitive( dnPopW, FALSE ); + mode = OFF; + for( sq_now=dn.sq_end ; sq_now >= dn.sq_start ; sq_now-- ) { + ncode = ptnSqToNo(sq_now); + if ( codeCheck( noToCode(ncode))) + continue; + if (ptnSense( noToCode(ncode) ) == 1) { + ptnDel( noToCode(ncode) ); + edlist.nptn--; + edg.flag = ON; + mode = ON; + } + } + + /* update the current character */ + + sq_now++; + for ( ; sq_now < (edlist.sqstart + edlist.nptn); sq_now++) { + ncode = ptnSqToNo(sq_now); + if (( ncode >= 0) && ( codeCheck( noToCode( ncode)) == 0)) + break; + } + if(sq_now > (edlist.sqstart + edlist.nptn -1)) { + sq_now--; + for ( ; sq_now >= edlist.sqstart; sq_now--) { + ncode = ptnSqToNo(sq_now); + if (( ncode >= 0) && ( codeCheck( noToCode( ncode)) == 0)) + break; + } + } + + /* check the existence of the current character */ + if( (sq_now != -1) && ((ncode = ptnSqToNo(sq_now)) != -1) ){ + code = noToCode( ncode ); + } else { + /* There is no characters on the editor, dtudcfonted does not + * display any character on the editing pane and forbid users + * to input. + * It can realize to put 0 to the first parameter of chgEdCode(). + */ + code = 0; + } + if(codeCheck( code )) { + code = 0; + } + + /* */ + if( ptnSense( edg.code ) == 1 ) { + ptnAdd( edg.code, edg.ptn ); + } + + /* renew the current character */ + if (mode == ON) { + chgEdCode( code, mode ); + } + XtSetSensitive( dnPopW, TRUE ); +} + + +/** + ** contents : display the image of the character to be deleted + ** ------------------------ + ** + **/ + +static void +drawDelPtn( i ) +int i; /* window number */ +{ + if ( RelToAbsSq( dn.sq_top, i) <= dn.sq_end) { + ptnGet( noToCode(ptnSqToNo(RelToAbsSq( dn.sq_top, i))), + dl[i].ptn ); + XPutImage(xl.display, dl[i].disp_winID, xl.borderGC, + dl[i].dispImage, 0,0,0,0, dn.ptn_w, dn.ptn_h ); + } else { + return; + } +} + + +/** + ** contents : display the code of the character to be deleted + ** ---------------------- + ** + **/ + +static void +drawDelCode( i ) +int i; /* window number */ +{ + char str[20]; + + if ( RelToAbsSq( dn.sq_top, i) <= dn.sq_end) { + sprintf(str, "%4x ", noToCode(ptnSqToNo(RelToAbsSq( dn.sq_top, i)))); + SetLabelString(dnStaT_code[i], str); + } else { + return; + } +} + + +/** + ** contents : re-display the code of the character to be deleted + ** -------------------------------------------------------------- + **/ + +/*ARGSUSED*/ +static void +EHdnBulB_disp( widget, i ) +Widget widget; +int i; /* widget that have some ivent */ +{ + drawDelPtn( i ); +} + + + +/** + ** notify error message + ** =================================================================== + ** + **/ + +/** + ** contents : inner functions of DispMngErrorMessage() + ** ---------------------------------- + **/ + +static void +DispErrorMessage( owner, title, msg ) +Widget owner; +String title; +String msg; +{ + static NoticeButton buttons[] = { + NBTNARGS( NULL, NULL, NULL, True, False ), + }; + static NButton BTN = NBUTTONS( buttons ); + + SetItemLabel(&BTN, 0, resource.l_ok); + PopupNotice( owner, msg, D_ERROR, &BTN, False, title ); +} + + +/** + ** contents : display "Add" or "Delete" error + ** -------------------------------- + **/ + +void +DispMngErrorMessage( msg ) +String msg; +{ + DispErrorMessage( mngPtnW, resource.l_error_title, msg ); +} + + +/** + ** contents : display "Copy" error + ** -------------------------- + **/ + +void +DispCpyErrorMessage( msg ) +String msg; +{ + DispErrorMessage( cpyPtnW, resource.l_error_title, msg ); +} diff --git a/cde/programs/dtudcfonted/cpyx.c b/cde/programs/dtudcfonted/cpyx.c new file mode 100644 index 00000000..957bf49c --- /dev/null +++ b/cde/programs/dtudcfonted/cpyx.c @@ -0,0 +1,944 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* cpyx.c 1.29 - Fujitsu source for CDEnext 96/10/30 13:13:45 */ +/* $XConsortium: cpyx.c /main/8 1996/11/08 01:52:55 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include + +#include +#include +#include + +#include + +/* + * There is no public header file for this function (only an + * internal header XmStringI.h). + */ +extern XtPointer _XmStringUngenerate (XmString string, + XmStringTag tag, + XmTextType tag_type, + XmTextType output_type); + +#include "util.h" +#include "selectxlfd.h" +#include "xoakufont.h" + +#include "xpm.h" +#ifdef XPM +#define ReadXpm XpmCreatePixmapFromData +#else +#define ReadXpm _DtXpmCreatePixmapFromData +#endif +#include "pixmaps/arrow.pm" + +static Widget CreateCopyXLFD() ; +static void CpyXLFDCB() ; + +extern int CreateOtherLabelAndText(); +extern Widget xlfdCreateScrolledList(); +extern int GetItemsToDisplay(); + +extern void xlfdPopupDialog(); + +extern void InitCpyPtn() ; +extern void _unmap(); +extern void CpyCB() ; +extern void PopdownCpyPtn() ; +extern void AddPopupProc() ; + +extern FalFontData fullFontData; + +/* + * parameters + */ + +FalFontData copyFontData; + +extern Widget toplevel ; +Widget cpyDialog=NULL; +static Widget codeLabel[COPYLABELS]; +static Widget codeText[COPYLABELS+1]; + +extern TextField SrcTf; +extern TextField DestTf; + +extern char AreaStr[160]; + +/* + * resource database + */ +extern Resource resource ; + +#define CS0 "Codeset 0" +#define CS1 "Codeset 1" +#define CS2 "Codeset 2" +#define CS3 "Codeset 3" + +#define FAL_ERROR_STR resource.falerrmsg[((fal_utyerrno & 0xff) > 25) ? 0 : (fal_utyerrno & 0xff)] + +static Widget pull1, pull2, pull3, pull4, scrolllist; +static int xlf_count = 0; +static XmString *xlf=NULL; +static int udc_count = 0; +static Boolean udc_flag = False; +static int *udc=NULL; +static int udc_val; +static int sty_count = 0; +static Boolean sty_flag = False; +static char **sty=NULL; +static char *sty_val=NULL; +static int wls_count = 0; +static Boolean wls_flag = False; +static int *wls=NULL; +static int wls_val; +static int hls_count = 0; +static Boolean hls_flag = False; +static int *hls=NULL; +static int hls_val; +static Widget *button1=NULL; +static Widget *button2=NULL; +static Widget *button3=NULL; +static Widget *button4=NULL; +static Widget focus_widget=NULL; + +/**************************************************************** + * callbacks * + ***************************************************************/ + + +/*ARGSUSED*/ +static void +CpyXLFDCB(w, client_data, call_data) +Widget w; +caddr_t client_data, *call_data; +{ + char *str; + XmStringTable st; + /* get font file name (str: XLFD name) */ + /* get font file name (str: XLFD name) */ + XtVaGetValues(scrolllist, XmNselectedItems, &st, NULL); + if( st == NULL ){ + copyFontData.xlfdname = NULL; + return ; + } + str = _XmStringUngenerate(st[0], NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + copyFontData.xlfdname = str; + if(udc_flag == True) + copyFontData.cd_set = udc_val; + else + copyFontData.cd_set = -1; +} + + +void +CpyPtnXLFD() +{ + if( cpyDialog == NULL ) + { + CreateCopyXLFD( toplevel ) ; + + /* + * add callbacks + */ + XtAddCallback(cpyDialog, XmNokCallback, (XtCallbackProc)_unmap, NULL); + XtAddCallback(cpyDialog, XmNokCallback, + (XtCallbackProc)CpyXLFDCB, NULL); + XtAddCallback(cpyDialog, XmNokCallback, (XtCallbackProc)CpyCB, NULL); + + XtAddCallback(cpyDialog, XmNcancelCallback, + (XtCallbackProc)_unmap, (XtPointer)1); + XtAddCallback(cpyDialog, XmNcancelCallback, + (XtCallbackProc)CpyXLFDCB, (XtPointer)1); + XtAddCallback(cpyDialog, XmNcancelCallback, + (XtCallbackProc)CpyCB, (XtPointer)1); + XtAddCallback(cpyDialog, XmNhelpCallback, (XtCallbackProc)_unmap, NULL); + XtAddCallback(cpyDialog, XmNhelpCallback, + (XtCallbackProc)PopdownCpyPtn, NULL); + + AddPopupProc( cpyDialog, InitCpyPtn ) ; + + SrcTf.w1 = codeText[0] ; + SrcTf.w2 = codeText[1] ; + DestTf.w1 = codeText[2] ; + DestTf.w2 = NULL; + + } + xlfdPopupDialog( cpyDialog ); +} + + +static void +create_xlfd() +{ + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + int i; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + xlf_count = 0; + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + return; + } + if(fontlist->num == 0) { + FalFreeFontList(fontlist); + return; + } + xlf = (XmString *)XtMalloc(sizeof(XmString) * fontlist->num); + for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) { + xlf[xlf_count++] = XmStringCreateLocalized(f->xlfdname); + } + FalFreeFontList(fontlist); +} + +static void +udc_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + udc_flag = False; + } else if(strcmp(moji, CS0) == 0) { + udc_val = FAL_FONT_CS0; + udc_flag = True; + } else if(strcmp(moji, CS1) == 0) { + udc_val = FAL_FONT_CS1; + udc_flag = True; + } else if(strcmp(moji, CS2) == 0) { + udc_val = FAL_FONT_CS2; + udc_flag = True; + } else if(strcmp(moji, CS3) == 0) { + udc_val = FAL_FONT_CS3; + udc_flag = True; + } else { + udc_flag = False; + } + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +sty_call(w) +Widget w; +{ + XmString label; + char *moji; + if (sty_val) { + XtFree(sty_val); + sty_val = NULL; + } + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + sty_flag = False; + } + else { + sty_val = XtMalloc(sizeof(char) * (strlen(moji) + 1)); + strcpy(sty_val, moji); + sty_flag = True; + } + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +wls_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + wls_flag = False; + } + else { + wls_val = atoi(moji); + wls_flag = True; + } + XmStringFree(label); + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +hls_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + hls_flag = False; + } + else { + hls_val = atoi(moji); + hls_flag = True; + } + XmStringFree(label); + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +button_set1() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + FalFreeFontList(fontlist); + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(udc[j] == f->cd_set) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button1[j], False); + else + XtSetSensitive(button1[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set2() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(strcmp(sty[j], f->style.name) == 0) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button2[j], False); + else + XtSetSensitive(button2[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set3() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(wls[j] == f->size.w) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button3[j], False); + else + XtSetSensitive(button3[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set4() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(hls[j] == f->size.h) { + found = True; + break; + } + } + if (found == False) + XtSetSensitive(button4[j], False); + else + XtSetSensitive(button4[j], True); + } + FalFreeFontList(fontlist); +} + + +static void +font_init() +{ + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + int i, j; + char tmp[16]; + char err[128]; + Widget button; + extern void data_sort(); + extern void Error_message(); + + xlf_count = udc_count = sty_count = wls_count = hls_count = 0; + if (FalGetFontList(NULL, FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED, &fontlist) == FAL_ERROR) { + snprintf(err, sizeof(err), "%s", FAL_ERROR_STR); + Error_message((Widget)NULL, err); + return; + } + if(fontlist->num == 0) { + FalFreeFontList(fontlist); + snprintf(err, sizeof(err), "%s", resource.mn_no_font); + Error_message((Widget)NULL, err); + return; + } + xlf = (XmString *)XtMalloc(sizeof(XmString) * fontlist->num); + udc = (int *)XtMalloc(sizeof(int) * fontlist->num); + sty = (char **)XtMalloc(sizeof(char *) * fontlist->num); + wls = (int *)XtMalloc(sizeof(int) * fontlist->num); + hls = (int *)XtMalloc(sizeof(int) * fontlist->num); + for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) { + xlf[xlf_count++] = XmStringCreateLocalized(f->xlfdname); + for (j=0,found=False; jcd_set) { + found=True; + break; + } + } + if (found == False) { + udc[udc_count++] = f->cd_set; + } + for (j=0,found=False; jstyle.name) == 0) { + found=True; + break; + } + } + if (found == False) { + sty[sty_count] = XtMalloc(sizeof(char) * (strlen(f->style.name) + 1)); + strcpy(sty[sty_count++], f->style.name); + } + if (f->size.w != -1) { + for (j=0,found=False; jsize.w) { + found=True; + break; + } + } + if (found == False) { + wls[wls_count++] = f->size.w; + } + } + for (j=0,found=False; jsize.h) { + found=True; + break; + } + } + if (found == False) { + hls[hls_count++] = f->size.h; + } + } + FalFreeFontList(fontlist); + + data_sort(udc, udc_count); + data_sort(wls, wls_count); + data_sort(hls, hls_count); + + button1 = (Widget *) XtMalloc(sizeof(Widget) * udc_count); + button2 = (Widget *) XtMalloc(sizeof(Widget) * sty_count); + button3 = (Widget *) XtMalloc(sizeof(Widget) * wls_count); + button4 = (Widget *) XtMalloc(sizeof(Widget) * hls_count); + + button = XmCreatePushButton(pull1, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)udc_call, NULL); + for (i=0; i < udc_count; i++) { + if(udc[i] == FAL_FONT_CS0) + snprintf(tmp, sizeof(tmp), "%s", CS0); + else if(udc[i] == FAL_FONT_CS1) + snprintf(tmp, sizeof(tmp), "%s", CS1); + else if(udc[i] == FAL_FONT_CS2) + snprintf(tmp, sizeof(tmp), "%s", CS2); + else if(udc[i] == FAL_FONT_CS3) + snprintf(tmp, sizeof(tmp), "%s", CS3); + else + snprintf(tmp, sizeof(tmp), "Codeset %x?", udc[i]); + button1[i] = XmCreatePushButton(pull1, tmp, NULL, 0); + XtManageChild(button1[i]); + XtAddCallback(button1[i], XmNactivateCallback, + (XtCallbackProc)udc_call, NULL); + } + + button = XmCreatePushButton(pull2, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)sty_call, NULL); + for (i=0; i < sty_count; i++) { + button2[i] = XmCreatePushButton(pull2, sty[i], NULL, 0); + XtManageChild(button2[i]); + XtAddCallback(button2[i], XmNactivateCallback, + (XtCallbackProc)sty_call, NULL); + } + + button = XmCreatePushButton(pull3, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)wls_call, NULL); + for (i=0; i < wls_count; i++) { + snprintf(tmp, sizeof(tmp), "%d", wls[i]); + button3[i] = XmCreatePushButton(pull3, tmp, NULL, 0); + XtManageChild(button3[i]); + XtAddCallback(button3[i], XmNactivateCallback, + (XtCallbackProc)wls_call, NULL); + } + + button = XmCreatePushButton(pull4, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)hls_call, NULL); + for (i=0; i < hls_count; i++) { + snprintf(tmp, sizeof(tmp), "%d", hls[i]); + button4[i] = XmCreatePushButton(pull4, tmp, NULL, 0); + XtManageChild(button4[i]); + XtAddCallback(button4[i], XmNactivateCallback, + (XtCallbackProc)hls_call, NULL); + } +} + +/*ARGSUSED*/ +static void +arrow_change(w, wid) +Widget w; +Widget wid; +{ + if (XtIsSensitive(wid)) { + XtSetSensitive(wid, False); + } else { + XtSetSensitive(wid, True); + } +} + +static void +focus(w) +Widget w; +{ + focus_widget = w; +} + +static void +code_input() +{ + char *str; + XmStringTable st; + extern void CodeWindow(); + XtVaGetValues(scrolllist, XmNselectedItems, &st, NULL); + if( st == NULL ){ + return ; + } + str = _XmStringUngenerate(st[0], NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + CodeWindow(focus_widget, str, True); +} + +static void +code_input2() +{ + extern void CodeWindow(); + CodeWindow(codeText[2], fullFontData.xlfdname, False); +} + +static Widget +CreateCopyXLFD( top ) +Widget top ; +{ + + int n; + Arg args[16]; + XmString xms, xms1, xms2 ; + Widget frame, row, label1, row1, row2, row3, row4, row5; + Widget sep, cas1, cas2, cas3, cas4; + Widget arrow, code; + XmString str; + extern Pixmap arrow_pix; + Display *disp; + Window root; + Pixmap mask; + XpmAttributes attr; + + udc_flag = sty_flag = wls_flag = hls_flag = False; + + /* + * create base window + */ + n = 0 ; + XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ; + xms = XmStringCreateLocalized( resource.l_copy ) ; + XtSetArg( args[n], XmNokLabelString, xms ) ; n++ ; + xms1 = XmStringCreateLocalized( resource.l_overlay ) ; + XtSetArg( args[n], XmNcancelLabelString, xms1 ) ; n++ ; + xms2 = XmStringCreateLocalized( resource.quit_label) ; + XtSetArg( args[n], XmNhelpLabelString, xms2 ) ; n++ ; + XtSetArg( args[n], XmNnoResize, True ) ; n++ ; + XtSetArg( args[n], XmNminimizeButtons, True ) ; n++ ; + XtSetArg( args[n], XmNtitle, resource.l_copy_title) ; n++ ; + cpyDialog = XmCreateTemplateDialog( top, "copy_dialog", args, n ); + + XmStringFree( xms ) ; + XmStringFree( xms1 ) ; + XmStringFree( xms2 ) ; + + n = 0; + pull1 = XmCreatePulldownMenu(top, "pull", args, n); + pull2 = XmCreatePulldownMenu(top, "pull", args, n); + pull3 = XmCreatePulldownMenu(top, "pull", args, n); + pull4 = XmCreatePulldownMenu(top, "pull", args, n); + + n = 0 ; + row = XmCreateRowColumn( cpyDialog, "BaseForm", args, n ); + XtManageChild( row ); + + n = 0; + frame = XmCreateFrame( row, "frame", args, n); + XtManageChild( frame ); + + n = 0 ; + row1 = XmCreateRowColumn( frame, "row", args, n ); + XtManageChild( row1 ); + + n = 0; + str = XmStringCreateLocalized(resource.l_selectitem) ; + XtSetArg(args[n], XmNlabelString, str); n++; + label1 = XmCreateLabel( row1, "SelectItems", args, n); + XtManageChild( label1 ); + XmStringFree(str); + + n = 0 ; + row2 = XmCreateRowColumn( row1, "row", args, n ); + XtManageChild( row2 ); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_codeset) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull1); n++; + cas1 = XmCreateOptionMenu( row2, "CodeSet", args, n ); + XtManageChild( cas1 ); + XtAddCallback(XmOptionButtonGadget(cas1), XmNcascadingCallback, + (XtCallbackProc)button_set1, NULL); + XmStringFree(str); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_style) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull2); n++; + cas2 = XmCreateOptionMenu( row2, "Style", args, n ); + XtAddCallback(XmOptionButtonGadget(cas2), XmNcascadingCallback, + (XtCallbackProc)button_set2, NULL); + XtManageChild( cas2 ); + XmStringFree(str); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_width) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull3); n++; + cas3 = XmCreateOptionMenu( row2, "Width", args, n ); + XtManageChild( cas3 ); + XtAddCallback(XmOptionButtonGadget(cas3), XmNcascadingCallback, + (XtCallbackProc)button_set3, NULL); + XmStringFree(str); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_height) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull4); n++; + cas4 = XmCreateOptionMenu( row2, "Height", args, n ); + XtManageChild( cas4 ); + XtAddCallback(XmOptionButtonGadget(cas4), XmNcascadingCallback, + (XtCallbackProc)button_set4, NULL); + XmStringFree(str); + + font_init(); + + n = 0; + XtSetArg(args[n], XmNvisibleItemCount, 10) ; n++ ; + XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT) ; n++ ; + XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC) ; n++ ; + XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT) ; n++ ; + XtSetArg(args[n], XmNitems, xlf) ; n++ ; + XtSetArg(args[n], XmNitemCount, xlf_count) ; n++ ; + scrolllist = XmCreateScrolledList(row, "scrolllist", args, n); + XtManageChild(scrolllist); + + n = 0; + sep = XmCreateSeparator(row, "sep", args, n); + XtManageChild(sep); + + n = 0 ; + row3 = XmCreateRowColumn( row, "row", args, n ); + XtManageChild( row3 ); + + if (! arrow_pix) { + disp = XtDisplay(row); + root = DefaultRootWindow(disp); + attr.valuemask = 0; + ReadXpm(disp, root, arrow_pm, &arrow_pix, &mask, &attr); + } + + n = 0 ; + XtSetArg(args[n], XmNorientation, XmHORIZONTAL) ; n++ ; + row4 = XmCreateRowColumn( row3, "row", args, n ); + XtManageChild( row4 ); + + xms = XmStringCreateLocalized(resource.l_copy_src_code); + n = 0; + XtSetArg(args[n], XmNlabelString, xms); n++ ; + codeLabel[0] = XmCreateLabel(row4 , "copylabel", args, n); + XtManageChild(codeLabel[0]); + XmStringFree( xms ) ; + + n = 0; + XtSetArg(args[n], XmNcolumns, 4); n++; + XtSetArg(args[n], XmNmaxLength, 4); n++; + XtSetArg(args[n], XmNeditable, True); n++; + XtSetArg(args[n], XmNcursorPositionVisible, True); n++; + focus_widget = codeText[0] = XmCreateText(row4 , "copytext", + args, n); + XtManageChild(codeText[0]); + + XtAddCallback(codeText[0], XmNfocusCallback, (XtCallbackProc)focus, NULL); + + n = 0; + XtSetArg(args[n], XmNlabelPixmap, arrow_pix); n++; + XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++; + XtSetArg(args[n], XmNindicatorOn, False); n++; + XtSetArg(args[n], XmNshadowThickness, 2); n++; + XtSetArg(args[n], XmNfillOnSelect, False); n++; + XtSetArg(args[n], XmNhighlightThickness, 0); n++; + arrow = XmCreateToggleButton(row4, "arrow", args, n); + XtManageChild(arrow); + + n = 0; + XtSetArg(args[n], XmNcolumns, 4); n++; + XtSetArg(args[n], XmNmaxLength, 4); n++; + XtSetArg(args[n], XmNeditable, True); n++; + XtSetArg(args[n], XmNcursorPositionVisible, True); n++; + codeText[1] = XmCreateText(row4 , "copytext", args, n); + XtManageChild(codeText[1]); + XtSetSensitive(codeText[1], False); + + XtAddCallback(codeText[1], XmNfocusCallback, (XtCallbackProc)focus, NULL); + + XtAddCallback(arrow, XmNvalueChangedCallback, + (XtCallbackProc)arrow_change, (XtPointer)codeText[1]); + + n = 0; + xms = XmStringCreateLocalized(resource.code) ; + XtSetArg(args[n], XmNlabelString, xms); n++; + XtSetArg(args[n], XmNhighlightThickness, 0); n++; + code = XmCreatePushButton(row4, "Code", args, n); + XtManageChild(code); + XmStringFree(xms); + + XtAddCallback(code, XmNactivateCallback, + (XtCallbackProc)code_input, (XtPointer)NULL); + + n = 0 ; + XtSetArg(args[n], XmNorientation, XmHORIZONTAL) ; n++ ; + row5 = XmCreateRowColumn( row3, "row", args, n ); + XtManageChild( row5 ); + + xms = XmStringCreateLocalized(resource.l_copy_dest_code); + + n = 0; + XtSetArg(args[n], XmNlabelString, xms); n++ ; + codeLabel[1] = XmCreateLabel(row5 , "copylabel", args, n); + XtManageChild(codeLabel[1]); + XmStringFree( xms ) ; + + n = 0; + XtSetArg(args[n], XmNcolumns, 4); n++; + XtSetArg(args[n], XmNmaxLength, 4); n++; + XtSetArg(args[n], XmNeditable, True); n++; + XtSetArg(args[n], XmNcursorPositionVisible, True); n++; + codeText[2] = XmCreateText(row5 , "copytext", args, n); + XtManageChild(codeText[2]); + + n = 0; + xms = XmStringCreateLocalized(resource.code) ; + XtSetArg(args[n], XmNlabelString, xms); n++; + XtSetArg(args[n], XmNhighlightThickness, 0); n++; + code = XmCreatePushButton(row5, "Code", args, n); + XtManageChild(code); + XmStringFree(xms); + + XtAddCallback(code, XmNactivateCallback, + (XtCallbackProc)code_input2, (XtPointer)NULL); + + return( cpyDialog ) ; +} diff --git a/cde/programs/dtudcfonted/dtaddcpf/Imakefile b/cde/programs/dtudcfonted/dtaddcpf/Imakefile new file mode 100644 index 00000000..444aa58b --- /dev/null +++ b/cde/programs/dtudcfonted/dtaddcpf/Imakefile @@ -0,0 +1,27 @@ +XCOMM $XConsortium: Imakefile /main/8 1996/09/09 11:19:28 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + INCLUDES = -I../include -I../libfal/include + + LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) -lc + + + SRCS = addcpf.c + + OBJS = addcpf.o + + SHLIBDIR = ../../../usr/bin + +ComplexProgramTarget(dtaddcpf) diff --git a/cde/programs/dtudcfonted/dtaddcpf/addcpf.c b/cde/programs/dtudcfonted/dtaddcpf/addcpf.c new file mode 100644 index 00000000..77149555 --- /dev/null +++ b/cde/programs/dtudcfonted/dtaddcpf/addcpf.c @@ -0,0 +1,957 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: addcpf.c /main/9 1996/11/08 02:00:29 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#endif + +#include +#include +#include + +#include "bdfgpf.h" + +#include +#include +#include "fontstruct.h" + +#include "FaLib.h" +#include "snfstruct.h" +#include "udcutil.h" + +#include + + +static int rw_init() ; +static int readSnf() ; +static int readSnf_with_init() ; +static int readSnfHeader() ; +static int readBdfHeaderAndPut() ; +static int mergePtn() ; +static int ModifyPtn() ; +static int InsertPtn() ; +static int writeSnf() ; +static void put_error_and_exit(); +static void put_help(); +static int readBdfToMemory_with_init() ; + +extern int fal_glyph_to_code() ; + +static struct ptobhead WriteSnf; + +static char *targ_file = NULL; /* UDC_file_name */ +static char *com = NULL; /* command_name */ +static char *spacing ; +static char *char_set ; +static char *util_locale ; + +static pid_t gtob_pid = 0; +static pid_t btop_pid = 0; +#if defined( SVR4 ) || defined( SYSV ) || defined(CSRG_BASED) || defined(__linux__) +static int chld_stat ; +#else +static union wait chld_stat ; +#endif + +static void +sigint_out() +{ + if (WriteSnf.out_file) { + Unlink_Tmpfile( WriteSnf.out_file, com ); + } + exit( 0 ); +} + +main( argc, argv ) +int argc; +char *argv[]; +{ + int code_area , init, modify, help, no_infile, no_style; + int fupd = 0 ; + int init_all, rtn, i; +#ifndef ROOT_ONLY + int exit_stat; +#endif + struct btophead ReadSnf; /* output file (GPF) */ + struct ptobhead ReadGpf; /* input file (CPF) */ + struct stat statbuf; + char snf_file[BUFSIZE] ; + char buf[BUFSIZE]; + char *style ; + char *xlfdname, *cbuf ; + int chk_fd; + FalGlyphRegion *gr ; + int num_gr ; + char *ep ; + + int code_no; + char *codeset = DEFAULT_CODESET; + + if( (util_locale = (char *)getenv( "LANG" )) == NULL ){ + util_locale = "C" ; + } + ReadSnf.in_file = ReadGpf.in_file = WriteSnf.out_file = NULL; + com = argv[0]; + COMM_SETDEFAULTSTYLE( style ) ; + cbuf = xlfdname = ep = '\0' ; + + gr = NULL ; + num_gr = 0 ; + spacing = char_set = NULL ; + + if (!( bdftopcf = get_cmd_path( getenv( "PATH" ), BDFTOPCF_CMD ))) { + bdftopcf = BDFTOPCF; + } + if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) { + oakgtobdf = SNFTOBDF; + } + if (!( bdftosnf = get_cmd_path( getenv( "PATH" ), BDFTOSNF_CMD ))) { + bdftosnf = BDFTOSNF; + } + + code_area = NORMAL; + init = modify = help = no_infile = no_style = init_all = 0; + + for ( i = 1; i < argc; i++ ) { + if ( !strcmp( argv[i], "-g" ) ) { + if ( ( i < argc-1) && (*argv[i+1] != '-' ) ) { + ReadSnf.in_file = argv[++i]; + } + } else if ( !strcmp( argv[i], "-p" ) ) { + if ( (i < argc-1) && (*argv[i+1] != '-') ){ + ReadGpf.in_file = argv[++i]; + } else { + no_infile = 1; + } + } else if ( !strcmp( argv[i], "-init" ) ) { + init = 1; + } else if ( !strcmp( argv[i], "-modify" ) ) { + modify = 1; + } else if ( !strcmp( argv[i], "-system" ) ) { + code_area |= SYSTM; + } else if ( !strcmp( argv[i], "-help" ) ) { + help = 1; + } else if ( !strcmp( argv[i], "-style" ) ) { + if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ){ + style = argv[++i]; + } else { + no_style = 1; + } + } else if ( !strcmp( argv[i], "-codeset" ) ) { + if ( ( i < argc - 1 ) && ( *argv[i+1] != '-' )){ + codeset = argv[++i]; + COMM_SET_CODESET( codeset, code_area ) ; + } + } else if ( !strcmp( argv[i], "-xlfd" ) ) { + if ( i < argc - 1 ){ + xlfdname = argv[++i]; + } + } else if ( COMM_SBOPT_STRCMP( argv, i ) ) { + COMM_SBOPT_SETSBOPT( code_area ) ; + } else if ( !strcmp( argv[i], "-f" ) ) { + fupd = 1; + } else { + put_help(argv[0]); + exit( 1 ); + } + } + + /* help_message */ + if ( help == 1 ) { + put_help( argv[0] ); + exit( 0 ); + } + COMM_SBOPT_CHECKSBOPT( argv[0], code_area ) ; + + if ( no_infile ) { + USAGE1("%s : The input file name following -p option cannot be omitted.\n", argv[0] ); + exit( 1 ); + } + + ep = (char *)strchr( codeset, '\0' ) ; + code_no = (int)strtol( codeset, &cbuf, 10 ) ; + if ( cbuf == codeset || cbuf != ep ) { + USAGE2("%s : The codeset number is not right.¡Ê %s ¡Ë\n", + argv[0], codeset ); + exit( 1 ); + } + + if ( no_style ) { + USAGE1("%s : The style is not specified.\n", argv[0] ) ; + exit( 1 ); + } + + if ( ReadSnf.in_file == NULL && xlfdname == NULL ) { + if ( code_area & SYSTM ) { + USAGE1("%s : The GPF output file name cannot be omitted.\n", argv[0] ); + } else { /* string of charcter size */ + USAGE1("%s : The character size specification cannot be omitted.\n", argv[0] ); + } + exit( 1 ); + } + + /* open GPF file */ + if ( !(code_area & SYSTM) ) { + if( xlfdname ) { + if ( GetUdcFileName( argv[0], code_no, xlfdname, snf_file ) ) { + USAGE1("%s : Failed to get font file. Terminates abnormally.\n", argv[0]); + exit( 1 ); + } + ReadSnf.in_file = snf_file ; + } else { + + + switch ( GetFileName( argv[0], ReadSnf.in_file, style, code_no, snf_file ) ) { + case 0: + ReadSnf.in_file = snf_file; + break; + case -1: + exit(1); + default: + USAGE1("%s : The font file name cannot be obtained. Terminates abnormally.\n", argv[0]); + exit(1); + } + } + if ( GetUdcRegion( argv[0], code_no, ReadSnf.in_file, &num_gr, &gr ) ) { + USAGE1("%s : This font cannot get UDC code region. Terminates abnormally.\n", argv[0]); + exit( 1 ); + } + } else { + num_gr = 1 ; + if( (gr = (FalGlyphRegion *)malloc( sizeof(FalGlyphRegion) * num_gr )) == NULL ) { + USAGE1("%s : malloc error. Terminates abnormally.\n", argv[0]); + exit( 1 ); + } + gr[0].start = MIN_CODE ; + gr[0].end = MAX_CODE ; + } + /* + * refuse proportional fonts + */ + if ( GetUdcFontName( ReadSnf.in_file, NULL, &xlfdname ) ) { + USAGE1("%s : This font cannot get XLFD. Terminates abnormally.\n", argv[0]); + exit( 1 ); + } + GETSPACINGSTR( spacing, xlfdname ) ; + if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) { + USAGE2("%s cannot edit proportional fonts.(SPACING \"%s\")\n", argv[0], spacing ); + exit( 1 ); + } + GETCHARSETSTR( char_set, xlfdname ) ; + + /* get ReadSnf.in_file */ + if ((targ_file = GetRealFileName( ReadSnf.in_file )) == NULL){ + USAGE2("%s : It was not possible to refer to the substance of the font file. \"%s\"\n", argv[0], ReadSnf.in_file); + exit(1); + } + WriteSnf.snf_file = targ_file; + + if ( ( chk_fd = open( targ_file, O_RDWR ) ) < 0 ) { + USAGE2("%s : The font file of substance \"%s\" cannot be opened.\n", argv[0] , targ_file ); + exit( 1 ); + } + if( !fupd ){ + if ( isLock( chk_fd ) == 1 ) { + USAGE1("%s : Editing by other application. \n", argv[0] ); + close( chk_fd ); + exit( 1 ); + } + } + close( chk_fd ); + + /* We read whole characters from gpf file. */ + ReadSnf.start_code = MIN_CODE; + ReadSnf.end_code = MAX_CODE; + ReadSnf.code_category = ALL_CODE; + + switch ( code_area ) { + case SYSTM: + ReadGpf.start_code = MIN_CODE; + ReadGpf.end_code = MAX_CODE; + ReadGpf.code_category = ALL_CODE; + break; + case SYSTM | CDSET1 : + ReadGpf.start_code = MIN_CODE; + ReadGpf.end_code = MAX_CODE; + ReadGpf.code_category = ALL_CODE; + break; + default: + COMM_SBFNT_SETUDCAREA( argv[0], ReadGpf, char_set, code_area, num_gr, gr ) ; + } + + COMM_SBFNT_CONVCODETOGI( char_set, ReadSnf ) ; + COMM_SBFNT_CONVCODETOGI( char_set, ReadGpf ) ; + + signal( SIGHUP , (void(*)())sigint_out ); + signal( SIGINT , (void(*)())sigint_out ); + signal( SIGQUIT, (void(*)())sigint_out ); + signal( SIGTERM, (void(*)())sigint_out ); + + + /* + * rw_init() + * + * GPFTOBDF, BDFTOGPF + * + * (ReadSnf.in_file) --> GPFTOBDF ==H + * H + * dtaddcpf <-- (ReadGpf.in_file) + * H + * (WriteSnf.out_file) <-- BDFTOGPF ==H + * + */ + if ( rtn = rw_init( &ReadGpf, &ReadSnf, &WriteSnf, init_all ) ) { + if ( WriteSnf.out_file ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + } + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, rtn, argv[0] ); + } + + if ( rtn = ReadGpfHeader( &ReadGpf, buf ) ) { + if ( WriteSnf.out_file ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + } + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, rtn, argv[0] ); + } + + if ( init_all ) { + /* We read only header of gpf file. */ + rtn = readSnfHeader( &ReadGpf, &ReadSnf, &WriteSnf, buf ); + } else if ( init ) { + /* We read characters in UDC area from gpf file. */ + rtn = readSnf_with_init( &ReadGpf, &ReadSnf, &WriteSnf, + init, buf, num_gr, gr ); + } else { + /* We read whole characters from gpf file. */ + rtn = readSnf( &ReadGpf, &ReadSnf, &WriteSnf, buf ); + } + if ( rtn ) { + if ( WriteSnf.out_file ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + } + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, rtn, argv[0] ); + } + + fclose( ReadSnf.input ); + WaitID( gtob_pid, chld_stat ) ; + + if ( ( rtn = mergePtn( argv[0], &ReadGpf, &ReadSnf, buf, code_area, modify, argv[0], num_gr, gr, code_no ) ) ) { + if ( WriteSnf.out_file ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + } + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, rtn, argv[0] ); + } + + /* write SNF output file */ + if ( ( rtn = writeSnf( &ReadSnf, &WriteSnf ) ) ) { + if ( WriteSnf.out_file ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + } + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, rtn, argv[0] ); + } + +#ifdef ROOT_ONLY + if ( pclose( WriteSnf.output ) ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, PCLOSE_ERROR, argv[0] ); + } +#else + fclose( WriteSnf.output ); + WaitID( btop_pid, chld_stat ) ; +#if !defined( SVR4 ) && !defined( SYSV ) && !defined(__FreeBSD__) + if ( !WIFEXITED(chld_stat) ) { +#else + if ( ! ( WIFEXITED(chld_stat) && !WEXITSTATUS(chld_stat) ) ) { +#endif + USAGE4("%s: The error occurred by %s (%08x). Cannot write %s\n", + argv[0], bdftopcf, chld_stat, WriteSnf.out_file); + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, + FATAL_ERROR, argv[0] ); + } +#endif + signal( SIGHUP , SIG_IGN ); + signal( SIGINT , SIG_IGN ); + signal( SIGQUIT, SIG_IGN ); + signal( SIGTERM, SIG_IGN ); + + if ( ( stat( WriteSnf.out_file, &statbuf ) ) || + ( statbuf.st_size == 0 ) + ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + put_error_and_exit( &ReadGpf, &ReadSnf, &WriteSnf, + BDF_WRITE, argv[0] ); + } + if ( stat( WriteSnf.snf_file, &statbuf ) ) { + Unlink_Tmpfile( WriteSnf.out_file, argv[0] ); + exit( 1 ); + } + exit( Make_NewFefFile( + WriteSnf.snf_file, WriteSnf.out_file, + FONT_FILE_PARM, + (uid_t)statbuf.st_uid, (gid_t)statbuf.st_gid, + argv[0] )); +} + +static +rw_init(r_gpf, r_snf, w_snf, init_all ) +struct ptobhead *r_gpf; +struct btophead *r_snf; +struct ptobhead *w_snf; +int init_all; +{ + FontInfoRec *finf; + int fd[2], snf_fd, permission; + char buf[BUFSIZE]; +#ifdef ROOT_ONLY + char command[BUFSIZE], *ep ; +#else + int pfd[2], ofd; +#endif + + if ( r_gpf->in_file == NULL ) { + r_gpf->input = stdin; + } else { + if ( ( r_gpf->input = fopen(r_gpf->in_file, "r")) == NULL ) { + return GPF_OPEN_IN; + } + } + + /* SNF format */ + if ( ChkPcfFontFile( w_snf->snf_file ) ) { + permission = 0 ; + if( (snf_fd = open( w_snf->snf_file, O_RDONLY ) ) >= 0 ) { + COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) ; + if ( permission < 0 ) { + return BDF_INVAL; + } + } else { + return BDF_OPEN_IN; + } + } + if (pipe(fd) != 0) { + return PIPE_ERROR; + } + switch (gtob_pid = fork()) { + case 0: + close( fd[0] ); + close( 1 ); + if ( dup( fd[1] ) < 0 ) { + return DUP_ERROR; + } + + close( fd[1] ); + + /* SNFTOBDF */ + execl( oakgtobdf, oakgtobdf, r_snf->in_file, 0 ); + return EXEC_ERROR; + + case -1: + return FORK_ERROR; + + default: + break; + } + close( fd[1] ); + if ( ( r_snf->input = fdopen( fd[0], "r" ) ) == NULL ) { + return FDOPEN_ERROR; + } + + if ( !( w_snf->out_file = GetTmpPath( targ_file ) ) ) { + return MKTMP_ERROR; + } + +#ifdef ROOT_ONLY + if( ChkPcfFontFile( w_snf->snf_file ) == 0 ) { + sprintf(command, "%s > %s", bdftopcf, w_snf->out_file) ; + } else { + COMM_SNF_POPEN( permission, w_snf->snf_file, w_snf->out_file, ep, buf, command ) ; + } + if ((w_snf->output = popen(command, "w")) == NULL) { + return(POPEN_ERROR); + } +#else /* ROOT_ONLY */ + if ( pipe( pfd ) != 0 ) { + return PIPE_ERROR; + } + switch (btop_pid = fork()) { + case 0: + if ( ( ofd = open( w_snf->out_file, O_WRONLY | O_CREAT, 0664 ) ) < 0 ) { + return BDF_OPEN_OUT; + } + close( 0 ); + if ( dup(pfd[0]) < 0 ) { + return DUP_ERROR; + } + close( pfd[0] ); + close( pfd[1] ); + close( 1 ); + if( dup( ofd ) < 0 ) { + close( ofd ); + return DUP_ERROR; + } + close( ofd ); + if ( ChkPcfFontFile( w_snf->snf_file ) == 0 ) { + execl( bdftopcf, bdftopcf, 0 ); + return PCFFONTC_ERROR; + } + + COMM_SNF_EXECLBDFTOSNF( permission, buf, w_snf->snf_file ) ; + return SNFFONTC_ERROR; + + case -1: + return FORK_ERROR; + + default: + break; + } + close( pfd[0] ); + if ( ( w_snf->output = fdopen( pfd[1], "w" ) ) == NULL ) { + return FDOPEN_ERROR; + } +#endif /* ROOT_ONLY */ + return 0; +} + + +static +readSnf(r_gpf, r_snf, w_snf, buf) +struct ptobhead *r_gpf; +struct btophead *r_snf; +struct ptobhead *w_snf; +char *buf; +{ + int nchar, rtn; + + if ( ( rtn = readBdfHeaderAndPut( r_snf, w_snf, buf ) ) ) { + return rtn; + } + + nchar = r_snf->num_chars + r_gpf->num_chars; + + if ( ( r_snf->code = (int *)malloc( sizeof(int) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( ( r_snf->ptn = (char **)malloc( sizeof(char *) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + return ReadBdfToMemory( r_snf, buf ) ; +} + +static +readSnf_with_init(r_gpf, r_snf, w_snf, init, buf, num_gr, gr ) +struct ptobhead *r_gpf; +struct btophead *r_snf; +struct ptobhead *w_snf; +int init; +char *buf; +int num_gr ; +FalGlyphRegion *gr ; +{ + int nchar, rtn; + + + if ( ( rtn = readBdfHeaderAndPut( r_snf, w_snf, buf ) ) ) { + return rtn; + } + + nchar = r_snf->num_chars + r_gpf->num_chars; + + if ( ( r_snf->code = (int *)malloc( sizeof(int) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( ( r_snf->ptn = (char **)malloc( sizeof(char *) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + return readBdfToMemory_with_init( r_snf, init, buf, num_gr, gr ) ; +} + + +static +readSnfHeader(r_gpf, r_snf, w_snf, buf) +struct ptobhead *r_gpf; +struct btophead *r_snf; +struct ptobhead *w_snf; +char *buf; +{ + int rtn; + + if ( ( rtn = readBdfHeaderAndPut( r_snf, w_snf, buf ) ) ) { + return rtn; + } + + r_snf->num_chars = 0; + + if ( ( r_snf->code = (int *)malloc( sizeof(int) * r_gpf->num_chars ) ) == NULL ) { + return MALLOC_ERROR; + } + if ( ( r_snf->ptn = (char **)malloc( sizeof(char *) * r_gpf->num_chars ) ) == NULL ) { + return MALLOC_ERROR; + } + return 0; +} + +static +readBdfHeaderAndPut(r_snf, w_snf, buf) +struct btophead *r_snf; +struct ptobhead *w_snf; +char *buf; +{ + char *p; + int getstat = 0; + + while ( 1 ) { + if ( fgets( buf, BUFSIZE, r_snf->input ) == NULL ) { + return BDF_INVAL; + } + p = buf; + SCAN_TO_NONSP( p ) + if ( !strncmp( p, SIZE, strlen( SIZE ) ) ) { + if ( ( sscanf( p, "SIZE %f%d", + &(r_snf->bdf_point), &(r_snf->bdf_xdpi))) != 2 ) { + return BDF_INVAL; + } + fprintf( w_snf->output, "%s", buf ); + getstat |= 0x01; + + } else if ( !strncmp( p, FONTBOUNDINGBOX, strlen( FONTBOUNDINGBOX ) ) ) { + if ( ( sscanf( p, "FONTBOUNDINGBOX %d%d%d%d", + &(r_snf->bdf_width), &(r_snf->bdf_height), + &(r_snf->bdf_x), &(r_snf->bdf_y) )) != 4) { + return BDF_INVAL; + } + fprintf( w_snf->output, "%s", buf ); + getstat |= 0x02; + + } else if ( !strncmp( p, CHARS, strlen( CHARS ) ) ) { + if ( ( sscanf( p, "CHARS %d", &( r_snf->num_chars ) ) ) != 1 ) { + return BDF_INVAL; + } + getstat |= 0x04; + break; + } else { + fprintf( w_snf->output, "%s", buf ); + } + } + + if ( getstat != 0x07 ) { + return BDF_INVAL; + } + return 0; +} + +#define DispCodePoint( command, char_set, gidx, dspcode, code_no, locale ){\ + if( COMM_SBFNT_ISSBFNT( (char_set) ) ){\ + dspcode = DISPCODEPOINT( (char_set), (gidx) ) ;\ + }else{\ + if( fal_glyph_to_code( (locale), (char_set), FALGETFALCODESET((code_no)), (gidx), &(dspcode) ) ){\ + USAGE3("%s : Failed to convert glyph index into code point.(0x%x charset: %s)\n", (command), (gidx), (char_set) ) ;\ + return -1 ;\ + }\ + }\ +} + +static +mergePtn(com, r_gpf, r_snf, buf, code_area, modify, prog_name, num_gr, gr, code_no) +char *com ; +struct ptobhead *r_gpf; +struct btophead *r_snf; +char *buf; +int code_area; +int modify; +char *prog_name; +int num_gr ; +FalGlyphRegion *gr ; +int code_no ; +{ + int code, rtn, msize, i, j, dspcode; + char *ptn; + + if ( ( r_gpf->p_width != r_snf->bdf_width ) + || ( r_gpf->p_height != r_snf->bdf_height ) + ) { + r_gpf->zoomf = 1; + + msize = ( r_gpf->p_width + 7 ) / 8 * r_gpf->p_height; + + if ( ( ptn = (char *)malloc( msize ) ) == NULL ) { + return MALLOC_ERROR; + } + r_gpf->ptn = &ptn; + + } else { + r_gpf->zoomf = 0; + } + + for ( i = 0; i < r_gpf->num_chars; i++ ) { + if ( ( rtn = GetGpfCode( r_gpf, buf, &code ) ) < 0 ) { + return rtn; + } else if ( rtn == FILE_END ) { + break; + } + if( COMM_SBFNT_ISSBFNT( char_set ) ) CONVGLYPHINDEX( code ) ; + if ( + ( code < r_gpf->start_code) || ( code > r_gpf->end_code ) + ||( !IN_CODE( r_gpf->code_category, SHIFT_ON( code ) ) ) + ||( + (r_gpf->code_category == ALL_CODE) && + !( code_area & SYSTM ) && + IsInRegion( code, num_gr, gr ) + ) + ) { + DispCodePoint( com, char_set, code, dspcode, code_no, util_locale ) ; + USAGE2("%s : The font of a specified code cannot be added/changed \"0x%x\".\n", prog_name, dspcode ); + fgets(buf, BUFSIZE, r_gpf->input); + continue; + } + + for ( j = 0; j < r_snf->num_chars; j++ ) { + if ( r_snf->code[j] == code ) { + if ( !modify ) { + DispCodePoint( com, char_set, code, dspcode, code_no, util_locale ) ; + USAGE2("%s : The font has already been registered in a specified code. \"0x%x\"\n", prog_name, dspcode ); + fgets( buf, BUFSIZE, r_gpf->input ); + break; + } + if ( ( rtn = ModifyPtn( r_gpf, r_snf, buf, j ) ) ) { + return rtn; + } + break; + } else if ( r_snf->code[j] > code ) { + if ( ( rtn = InsertPtn( r_gpf, r_snf, buf, code, j ) ) ) { + return rtn; + } + break; + } + } + if ( j == r_snf->num_chars ) { + if ( ( rtn = InsertPtn( r_gpf, r_snf, buf, code, j ) ) ) { + return rtn; + } + } + } + return 0; +} + + +static +ModifyPtn( r_gpf, r_snf, buf, ix ) +struct ptobhead *r_gpf; +struct btophead *r_snf; +char *buf; +int ix; +{ + int mwidth, msize, rtn; + + mwidth = ( r_gpf->p_width + 7 ) / 8; + msize = mwidth * r_gpf->p_height; + + if ( r_gpf->zoomf ) { + if ( ( rtn = GetGpfPtn( r_gpf, buf, r_gpf->ptn[0], mwidth, msize ) ) ) { + return rtn; + } + if ( ( rtn = PtnZoom( r_snf->ptn[ix], r_gpf->ptn[0], + r_gpf->p_width, r_gpf->p_height, + r_snf->bdf_width, r_snf->bdf_height ) ) ) { + return rtn; + } + } else { + if ( ( rtn = GetGpfPtn( r_gpf, buf, r_snf->ptn[ix], mwidth, msize ) ) ) { + return rtn; + } + } + return 0; +} + +static +InsertPtn( r_gpf, r_snf, buf, code, ix ) +struct ptobhead *r_gpf; +struct btophead *r_snf; +char *buf; +int code; +int ix; +{ + int mwidth, msize, rtn, i; + + for ( i = r_snf->num_chars; i > ix; i-- ) { + r_snf->code[i] = r_snf->code[i-1]; + r_snf->ptn[i] = r_snf->ptn[i-1]; + } + r_snf->code[ix] = code; + + r_snf->num_chars++; + + mwidth = (r_snf->bdf_width + 7) / 8; + msize = mwidth * r_snf->bdf_height; + + if ( ( r_snf->ptn[ix] = (char *)malloc( msize ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( r_gpf->zoomf ) { + mwidth = (r_gpf->p_width + 7) / 8; + msize = mwidth * r_gpf->p_height; + if ( ( rtn = GetGpfPtn( r_gpf, buf, r_gpf->ptn[0], mwidth, msize ) ) ) { + return rtn; + } + if ( ( rtn = PtnZoom( r_snf->ptn[ix], r_gpf->ptn[0], + r_gpf->p_width, r_gpf->p_height, + r_snf->bdf_width, r_snf->bdf_height ) ) ) { + return rtn; + } + } else { + if ( ( rtn = GetGpfPtn( r_gpf, buf, r_snf->ptn[ix], mwidth, msize ) ) ) { + return rtn; + } + } + return(0); +} + +static +writeSnf( r_snf, w_snf ) +struct btophead *r_snf; +struct ptobhead *w_snf; +{ + w_snf->zoomf = 0; + w_snf->num_chars = r_snf->num_chars; + w_snf->code = r_snf->code; + w_snf->ptn = r_snf->ptn; + w_snf->bdf_width = r_snf->bdf_width; + w_snf->bdf_height = r_snf->bdf_height; + + w_snf->bdf_x = r_snf->bdf_x; + w_snf->bdf_y = r_snf->bdf_y; + + w_snf->bdf_point = r_snf->bdf_point; + w_snf->bdf_xdpi = r_snf->bdf_xdpi; + + return WritePtnToBdf( w_snf ); +} + + + +static void +put_error_and_exit(ptob_in, btop, ptob_out, er_no, prog_name) +struct ptobhead *ptob_in; +struct btophead *btop; +struct ptobhead *ptob_out; +int er_no; +char *prog_name; +{ + ErrMsgTable_AndExit( er_no, ptob_in->in_file, ptob_out->out_file, + btop->in_file, NULL, + ptob_in->bdf_file, + prog_name + ); + return; +} + + + +static void +put_help( prog_name ) +char *prog_name; +{ + USAGE1("Usage: %s -xlfd xlfd_name \n", prog_name); + USAGE("\t\t[-g character_size][-p character_pattern_file_name]\n"); + USAGE("\t\t[-style style]"); + USAGE("\t\t[-init]\t(clear whole glyphs of gpf file that used for user defined characters)\n" ) ; + USAGE("\t\t[-modify]\t(permits the change of font)\n"); + COMM_HELP_MSG ; + USAGE1("%s can insert or modify glyphs in the following code area.\n", prog_name); + USAGE("codeset \t\tcode area\n"); + USAGE("----------------------------------------\n"); + DispUdcCpArea() ; + USAGE("The xlfd name and character size may be obtained using dtlsgpf command.\n"); + return; +} + + + +static int +readBdfToMemory_with_init(head, init, buf, num_gr, gr ) +struct btophead *head; +int init; +char *buf; +int num_gr ; +FalGlyphRegion *gr ; +{ + int code, mwidth, num_char, bsize, rtn ; + char *ptn; + + num_char = 0; + mwidth = (head->bdf_width + 7) / 8; + bsize = mwidth * head->bdf_height; + while(1) { + if ((rtn = GetBdfCode(head, buf, &code)) < 0) { + return(rtn); /* contain BDF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + rtn = IsInRegion( code, num_gr, gr ) ; + if ( + ( code < head->start_code) || ( code > head->end_code ) + ||( !IN_CODE( head->code_category, SHIFT_ON( code ) ) ) + ||( + (head->code_category == ALL_CODE) + && ( (init)? ((rtn)?0:1) : ((rtn)?1:0) ) + ||( COMM_ISDEFAULTCHAR( code ) ) + ) + ) { + continue; + } + head->code[num_char] = code; + if ((ptn = head->ptn[num_char++] = + (char *)malloc(bsize)) == NULL) { + return(MALLOC_ERROR); + } + if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} diff --git a/cde/programs/dtudcfonted/dtbdftocpf/Imakefile b/cde/programs/dtudcfonted/dtbdftocpf/Imakefile new file mode 100644 index 00000000..8dd75cb9 --- /dev/null +++ b/cde/programs/dtudcfonted/dtbdftocpf/Imakefile @@ -0,0 +1,24 @@ +XCOMM $XConsortium: Imakefile /main/8 1996/09/09 11:19:34 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + INCLUDES = -I../include -I../libfal/include + + LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) -lc + + SRCS = bdftocpf.c + + OBJS = bdftocpf.o + +ComplexProgramTarget(dtbdftocpf) diff --git a/cde/programs/dtudcfonted/dtbdftocpf/bdftocpf.c b/cde/programs/dtudcfonted/dtbdftocpf/bdftocpf.c new file mode 100644 index 00000000..d3bc2072 --- /dev/null +++ b/cde/programs/dtudcfonted/dtbdftocpf/bdftocpf.c @@ -0,0 +1,292 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: bdftocpf.c /main/6 1996/11/08 02:01:17 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "bdfgpf.h" +#include "udcutil.h" + +static void put_error(); +static void put_help() ; +static void Usage() ; +static void sigint_out() ; +static int CnvBDFtoGPF() ; + +static struct btophead Head; + +static void +sigint_out() +{ + if (Head.out_file) { + unlink(Head.out_file); + } + exit(0); +} + +main(argc, argv) +int argc; +char *argv[]; +{ + int rtn, i; + char *GetTmpPath(); + struct stat st; + + for (i=1; i MAX_FONT_WIDTH) || + (Head.p_width < MIN_FONT_WIDTH)) { + USAGE2("%s: The specification of the character width is improper.\"%s\"\n", + argv[0], argv[i+1]); + exit(PARAM_ERROR * (-1)); + } + } else if (!strcmp(argv[i], "-height")) { + Head.p_height = atoi(argv[i+1]); + if ((Head.p_height > MAX_FONT_HEIGHT) || + (Head.p_height < MIN_FONT_HEIGHT)) { + USAGE2("%s: The specification of the character height is improper.\"%s\"\n", + argv[0], argv[i+1]); + exit(PARAM_ERROR * (-1)); + } + } else { + Usage(argv[0]); + } + } + + if (Head.in_file == NULL) { + Head.input = stdin; + } else { + char *spacing ; + char *xlfdname ; + spacing = xlfdname = NULL ; + /* refuse proportional fonts */ + if ( GetUdcFontName( NULL, Head.in_file, &xlfdname ) ) { + USAGE1("%s : This font cannot get XLFD. Terminates abnormally.\n", argv[0]); + exit( 1 ); + } + GETSPACINGSTR( spacing, xlfdname ) ; + if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) { + USAGE2("%s cannot edit proportional fonts.(SPACING \"%s\")\n", argv[0], spacing ); + exit( 1 ); + } + if ((Head.input = fopen(Head.in_file, "r")) == NULL) { + USAGE2("%s: The BDF file cannot be opened.\"%s\"\n", + argv[0], Head.in_file); + exit(BDF_OPEN * (-1)); + } + } + + signal(SIGHUP, (void(*)())sigint_out); + signal(SIGINT, (void(*)())sigint_out); + signal(SIGQUIT, (void(*)())sigint_out); + signal(SIGTERM, (void(*)())sigint_out); + + if (Head.out_file == NULL) { + Head.output = stdout; + } else { + if (stat(Head.out_file, &st) != 0) { + if ((Head.output = fopen(Head.out_file, "w")) == NULL) { + USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", + argv[0], Head.out_file); + exit(GPF_OPEN *(-1)); + } + } else { + Head.text_file = Head.out_file; + if ((Head.out_file = GetTmpPath( Head.out_file )) == NULL) { + USAGE1("%s: Failed convert.\n", argv[0]); + exit(FATAL_ERROR * (-1)); + } + if ((Head.output = fopen(Head.out_file, "w")) == NULL) { + USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", + argv[0], Head.out_file); + exit(GPF_OPEN * (-1)); + } + } + } + + if ((rtn = CnvBDFtoGPF(&Head))) { + if (Head.in_file != NULL) { + fclose(Head.input); + } + if (Head.out_file != NULL) { + fclose(Head.output); + unlink(Head.out_file); + } + put_error(&Head, rtn, argv[0]); + exit(rtn * (-1)); + } + + if (Head.in_file != NULL) { + fclose(Head.input); + } + if (Head.out_file != NULL) { + fclose(Head.output); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + if (Head.text_file != NULL) { + Link_NewFile(Head.out_file, Head.text_file); + unlink(Head.out_file); + } + } + exit(0); +} + +static +CnvBDFtoGPF(head) +struct btophead *head; +{ + char bdfbuf[BUFSIZE]; + int rtn; + + if ((rtn = ReadBdfHeader(head, bdfbuf)) < 0) { + return(rtn); + } + + if (head->p_width == USE_ORG_SIZE) { + head->p_width = head->bdf_width; + } + if (head->p_height == USE_ORG_SIZE) { + head->p_height = head->bdf_height; + } + if ((head->p_width != head->bdf_width) || + (head->p_height != head->bdf_height)) { + head->zoomf = 1; + } else { + head->zoomf = 0; + } + + if ((head->code = (int *)malloc(sizeof(int)*head->num_chars)) == NULL) { + return(FATAL_ERROR); + } + + if ((head->ptn = (char **)malloc(sizeof(char *)*head->num_chars)) == NULL) { + return(FATAL_ERROR); + } + + if ((rtn = ReadBdfToMemory(head, bdfbuf))) { + return(rtn); + } + + WriteGpfHeader(head); + + if ((rtn = WritePtnToGpf(head))) { + return(rtn); + } + + return(0); +} + +static void +put_error(head, er_no, prog_name) +struct btophead *head; +int er_no; +char *prog_name; +{ + switch(er_no) { + case FATAL_ERROR : + USAGE1("%s: Failed convert.\n", prog_name); + break; + + case BDF_OPEN : + USAGE2("%s: The BDF file cannot be opened. \"%s\"\n", + prog_name, head->in_file); + break; + + case BDF_READ : + USAGE2("%s: The BDF file cannot be read. \"%s\"\n", + prog_name, head->in_file); + break; + + case BDF_INVAL : + USAGE2("%s: The format of the BDF file is illegal. \"%s\"\n", + prog_name, head->in_file); + break; + + case GPF_OPEN : + USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", + prog_name, head->out_file); + break; + + case GPF_WRITE : + USAGE2("%s: It is not possible to write to the character pattern file. \"%s\"\n", + prog_name, head->out_file); + break; + + default : + break; + } +} + +static void +put_help(prog_name) +char *prog_name; +{ + USAGE1("Usage: %s [-p character_pattern_file_name] [-bdf BDF_file_name]\n", prog_name); + USAGE("\t\t[-width character_width] [-height character_height] [-help]\n\n"); +} + +static void +Usage(prog_name) +char *prog_name; +{ + put_help(prog_name); + exit(PARAM_ERROR * (-1)); +} diff --git a/cde/programs/dtudcfonted/dtcpftobdf/Imakefile b/cde/programs/dtudcfonted/dtcpftobdf/Imakefile new file mode 100644 index 00000000..00d5a0ab --- /dev/null +++ b/cde/programs/dtudcfonted/dtcpftobdf/Imakefile @@ -0,0 +1,24 @@ +XCOMM $XConsortium: Imakefile /main/8 1996/09/09 11:19:37 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + INCLUDES = -I../include -I../libfal/include + + LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) -lc + + SRCS = cpftobdf.c + + OBJS = cpftobdf.o + +ComplexProgramTarget(dtcpftobdf) diff --git a/cde/programs/dtudcfonted/dtcpftobdf/cpftobdf.c b/cde/programs/dtudcfonted/dtcpftobdf/cpftobdf.c new file mode 100644 index 00000000..c98479b7 --- /dev/null +++ b/cde/programs/dtudcfonted/dtcpftobdf/cpftobdf.c @@ -0,0 +1,290 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: cpftobdf.c /main/6 1996/11/08 02:02:03 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include "bdfgpf.h" +#include "udcutil.h" + +static void put_error(); +static void put_help() ; +static void Usage() ; +static int CnvGPFtoBDF() ; +static void sigint_out() ; + +static struct ptobhead Head; + +static void +sigint_out() +{ + if ( Head.out_file ) { + unlink( Head.out_file ); + } + exit( 0 ); +} + +main( argc, argv ) +int argc; +char *argv[]; +{ + int rtn, i; + char *GetTmpPath(); + char *spacing ; + char *xlfdname ; + + for ( i = 1; i < argc; i++ ) { + if ( !strcmp( argv[i], "-help" ) ) { + put_help( argv[0] ); + exit( 0 ); + } + } + + if ( !( argc % 2 ) ) { + Usage(argv[0]); + } + + spacing = xlfdname = NULL ; + Head.in_file = Head.bdf_file = Head.snf_file = Head.out_file = NULL; + Head.start_code = MIN_CODE ; + Head.end_code = MAX_CODE ; + Head.code_category = ALL_CODE; + + if (!( bdftopcf = get_cmd_path( getenv( "PATH"), BDFTOPCF_CMD ))){ + bdftopcf = BDFTOPCF; + } + if (!( oakgtobdf = get_cmd_path( getenv( "PATH"), SNFTOBDF_CMD ))) { + oakgtobdf = SNFTOBDF; + } + + for ( i = 1; i < argc; i+=2 ) { + if ( !strcmp( argv[i], "-bdf" ) ) { + Head.bdf_file = argv[ i+1 ]; + } else if ( !strcmp( argv[i], "-p" ) ) { + Head.in_file = argv[i+1]; + } else if ( !strcmp( argv[i], "-g" ) ) { + Head.snf_file = argv[i+1]; + } else { + Usage( argv[0] ); + } + } + + if ( Head.in_file == NULL ) { + Head.input = stdin; + } else { + if ( ( Head.input = fopen( Head.in_file, "r" ) ) == NULL ) { + USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", argv[0], Head.in_file ); + exit( GPF_OPEN * (-1) ); + } + } + + signal( SIGHUP, (void(*)())sigint_out ); + signal( SIGINT, (void(*)())sigint_out ); + signal( SIGQUIT, (void(*)())sigint_out ); + signal( SIGTERM, (void(*)())sigint_out ); + + if ( Head.bdf_file == NULL ) { + if ( Head.snf_file == NULL ) { + USAGE1("%s: If the output is stdout, the user defined font file name cannot be omitted.\n", argv[0]); + exit(PARAM_ERROR * (-1)); + } + Head.output = stdout; + } else { + if ( ! ( Head.out_file = GetTmpPath( Head.bdf_file ) ) ) { + exit( FATAL_ERROR * ( -1 ) ); + } + + if ( ( Head.output = fopen( Head.out_file, "w" ) ) == NULL ) { + USAGE2("%s: The work file for the output cannot be opened. \"%s\"\n", argv[0], Head.out_file ); + exit( BDF_OPEN * (-1) ); + } + } + /* refuse proportional fonts */ + if ( GetUdcFontName( Head.snf_file, Head.bdf_file, &xlfdname ) ) { + USAGE1("%s : This font cannot get XLFD. Terminates abnormally.\n", argv[0]); + if ( Head.in_file != NULL ) { + fclose( Head.input ); + } + if ( Head.out_file != NULL ) { + fclose( Head.output ); + unlink( Head.out_file ); + } + exit( 1 ); + } + GETSPACINGSTR( spacing, xlfdname ) ; + if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) { + USAGE2("%s cannot edit proportional fonts.(SPACING \"%s\")\n", argv[0], spacing ); + if ( Head.in_file != NULL ) { + fclose( Head.input ); + } + if ( Head.out_file != NULL ) { + fclose( Head.output ); + unlink( Head.out_file ); + } + exit( 1 ); + } + + if ( ( rtn = CnvGPFtoBDF( &Head ) ) ) { + if ( Head.in_file != NULL ) { + fclose( Head.input ); + } + if ( Head.out_file != NULL ) { + fclose( Head.output ); + unlink( Head.out_file ); + } + put_error( &Head, rtn, argv[0] ); + exit( rtn * (-1) ); + } + + if ( Head.in_file != NULL ) { + fclose( Head.input ); + } + if ( Head.out_file != NULL ) { + fclose( Head.output ); + signal( SIGHUP, SIG_IGN ); + signal( SIGINT, SIG_IGN ); + signal( SIGQUIT, SIG_IGN ); + signal( SIGTERM, SIG_IGN ); + if ( Head.bdf_file != NULL ) { + Link_NewFile( Head.out_file, Head.bdf_file ); + unlink( Head.out_file ); + } + } + exit( 0 ); +} + +static +CnvGPFtoBDF( head ) +struct ptobhead *head; +{ + char textbuf[BUFSIZE] ; + int rtn ; + + if ( ( rtn = ReadGpfHeader( head, textbuf ) ) ) { + return rtn; + } + + if ( ( rtn = WriteBdfHeader( head ) ) ) { + return rtn; + } + + if ( ( head->p_width != head->bdf_width ) + || ( head->p_height != head->bdf_height ) + ) { + head->zoomf = 1; + } else { + head->zoomf = 0; + } + + if ( ( head->code = (int *)malloc( sizeof(int) * head->num_chars ) ) == NULL ) { + return FATAL_ERROR; + } + + if ( ( head->ptn = (char **)malloc( sizeof( char * ) * head->num_chars ) ) == NULL ) { + return FATAL_ERROR; + } + + if ( ( rtn = ReadGpfToMemory( head, textbuf ) ) ) { + return rtn; + } + + if ( ( rtn = WritePtnToBdf( head ) ) ) { + return rtn; + } + + return 0; +} + +static void +put_error( head, er_no, prog_name ) +struct ptobhead *head; +int er_no; +char *prog_name; +{ + switch( er_no ) { + case FATAL_ERROR: + USAGE1("%s: Failed convert.\n", prog_name ); + break; + + case BDF_OPEN: + USAGE2("%s: The BDF file cannot be opened. \"%s\"\n", prog_name, head->bdf_file ); + break; + + case BDF_READ: + USAGE2("%s: The BDF file cannot be read. \"%s\"\n", prog_name, head->bdf_file ); + break; + + case BDF_WRITE: + USAGE2("%s: It is not possible to write to the BDF file. \"%s\"\n", prog_name, head->out_file ); + break; + + case BDF_INVAL: + if ( head->snf_file ) { + USAGE2("%s: The information from the font file cannot be obtained.\"%s\"\n", prog_name, head->snf_file ); + } else { + USAGE2("%s: The format of the BDF file is illegal. \"%s\"\n", prog_name, head->bdf_file ); + } + break; + + case GPF_OPEN: + USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", prog_name, head->in_file ); + break; + + case GPF_READ: + USAGE2("%s: The character pattern file cannot be read. \"%s\"\n", prog_name, head->in_file ); + break; + + case GPF_INVAL: + USAGE2("%s: The format of the character pattern file is illegal. \"%s\"\n", prog_name, head->in_file ); + break; + + default: + break; + } +} + +static void +put_help( prog_name ) +char *prog_name; +{ + USAGE1("Usage: %s [-bdf BDF_file_name] [-p chracter_pattern_file_name]\n", prog_name); + USAGE("\t\t[-g user_defined_character_file_name] [-help]\n"); +} + +static void +Usage( prog_name ) +char *prog_name; +{ + put_help( prog_name ); + exit( PARAM_ERROR * (-1) ); +} diff --git a/cde/programs/dtudcfonted/dtcpftogpf/Imakefile b/cde/programs/dtudcfonted/dtcpftogpf/Imakefile new file mode 100644 index 00000000..0fd45d15 --- /dev/null +++ b/cde/programs/dtudcfonted/dtcpftogpf/Imakefile @@ -0,0 +1,24 @@ +XCOMM $XConsortium: Imakefile /main/8 1996/09/09 11:19:41 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + INCLUDES = -I../include -I../libfal/include + +LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) -lc + + SRCS = cpftogpf.c + + OBJS = cpftogpf.o + +ComplexProgramTarget(dtcpftogpf) diff --git a/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c b/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c new file mode 100644 index 00000000..4bd2646f --- /dev/null +++ b/cde/programs/dtudcfonted/dtcpftogpf/cpftogpf.c @@ -0,0 +1,466 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: cpftogpf.c /main/7 1996/11/08 02:02:48 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#endif +#include +#include + +#include + +#include +#include + +#include "bdfgpf.h" + +#include "snfstruct.h" +#include "fontstruct.h" + +#include "FaLib.h" +#include "udcutil.h" + +#include + + +static void sigint_out() ; +static void put_error_and_exit(); +static void put_help(); +static int CnvGPFtoBDF() ; + +static struct ptobhead Head; + +static char *targ_file = NULL; /* UDC character filename */ +static char *com = NULL; /* command name */ +static char *spacing ; +static char *char_set ; + + +static void +sigint_out() +{ + if (Head.out_file) { + Unlink_Tmpfile(Head.out_file, com); + } + exit(0); +} + +main( argc, argv ) +int argc; +char *argv[]; +{ + FontInfoRec *finf; + int help, no_infile, style_err, rtn, i; + struct stat statbuf; + char snf_file[BUFSIZE], buf[BUFSIZE]; + int pfd[2], fd, snf_fd, permission; + int exit_stat; + char *style ; /* style */ + int chk_fd; + pid_t chld_pid = 0; +#if defined( SVR4 ) || defined( SYSV ) || defined(CSRG_BASED) || defined(__linux__) + int chld_stat ; +#else + union wait chld_stat ; +#endif + int code_no, code_area ; + FalFontData key ; + char *xlfdname, *cbuf, *ep ; + char *codeset = DEFAULT_CODESET ; + + /* format */ + Head.in_file = Head.bdf_file = Head.snf_file = Head.out_file = NULL; + help = no_infile = style_err = 0; + com = argv[0]; + COMM_SETDEFAULTSTYLE( style ) ; + memset( &key, '\0', sizeof(FalFontData) ) ; + xlfdname = cbuf = ep = '\0' ; + spacing = char_set = NULL ; + code_no = code_area = 0 ; + + if (!( bdftopcf = get_cmd_path( getenv( "PATH" ), BDFTOPCF_CMD ))) { + bdftopcf = BDFTOPCF; + } + if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) { + oakgtobdf = SNFTOBDF; + } + if (!( bdftosnf = get_cmd_path( getenv( "PATH" ), BDFTOSNF_CMD ))) { + bdftosnf = BDFTOSNF; + } + + Head.code_category = ALL_CODE; + Head.start_code = MIN_CODE; + Head.end_code = MAX_CODE; + + for (i=1; i= 0 ) { + if ( ChkPcfFontFile( Head.snf_file) ) { + /* snf file */ + COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) ; + if( permission < 0 ) { + put_error_and_exit( &Head, BDF_INVAL, argv[0] ); + } + } else { + /* pcf */ + close( snf_fd ); + } + + } else { + put_error_and_exit( &Head, BDF_OPEN_IN, argv[0] ); + } + + + if ( pipe( pfd ) != 0 ) { + put_error_and_exit( &Head, PIPE_ERROR, argv[0] ); + } + + signal( SIGHUP , (void(*)())sigint_out ); + signal( SIGINT , (void(*)())sigint_out ); + signal( SIGQUIT, (void(*)())sigint_out ); + signal( SIGTERM, (void(*)())sigint_out ); + + switch ( chld_pid = fork() ) { + case 0: + if ( ( fd = open( Head.out_file, O_WRONLY | O_CREAT, 0664 ) ) < 0 ) { + put_error_and_exit( &Head, BDF_OPEN_OUT, argv[0] ); + } + close(0); + if ( dup( pfd[0] ) < 0 ) { + put_error_and_exit( &Head, DUP_ERROR, argv[0] ); + } + close( pfd[0] ); + close( pfd[1] ); + close( 1 ); + if ( dup( fd ) < 0 ) { + put_error_and_exit( &Head, DUP_ERROR, argv[0] ); + } + + + if ( ChkPcfFontFile( Head.snf_file ) == 0 ) { + execl( bdftopcf, bdftopcf, 0 ); + /* exec error */ + put_error_and_exit( &Head, PCFFONTC_ERROR, argv[0] ); + } + + COMM_SNF_EXECLBDFTOSNF( permission, buf, Head.snf_file ) ; + /* exec error */ + put_error_and_exit( &Head, SNFFONTC_ERROR, argv[0] ); + + case -1: + /* fork() error */ + put_error_and_exit( &Head, FORK_ERROR, argv[0] ); + + default: + break; + } + + close( pfd[0] ); + if ( ( Head.output = fdopen( pfd[1], "w" ) ) == NULL ) { + close( pfd[1] ); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + put_error_and_exit( &Head, FDOPEN_ERROR, argv[0] ); + } + + if ( ( rtn = CnvGPFtoBDF( &Head ) ) ) { + fclose( Head.input ); + fclose( Head.output ); + close( pfd[1] ); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + Unlink_Tmpfile( Head.out_file, argv[0] ); + put_error_and_exit( &Head, rtn, argv[0] ); + } + fclose( Head.output ); + close( pfd[1] ); + wait( &exit_stat ); +#if !defined( SVR4 ) && !defined( SYSV ) && !defined(__FreeBSD__) + if ( !WIFEXITED(exit_stat) ) { +#else + if (! ( WIFEXITED(exit_stat) && !WEXITSTATUS(exit_stat) ) ) { +#endif + USAGE3("%s: The error occurred by %s (%08x).\n", argv[0], bdftopcf, exit_stat ); + Unlink_Tmpfile( Head.out_file, argv[0] ); + exit( 1 ); + } + fclose( Head.input ); + signal( SIGHUP , SIG_IGN ); + signal( SIGINT , SIG_IGN ); + signal( SIGQUIT, SIG_IGN ); + signal( SIGTERM, SIG_IGN ); + + sleep(1) ; + if ( (stat( Head.out_file,&statbuf ) ) || + ( statbuf.st_size == 0 ) ) { + Unlink_Tmpfile( Head.out_file, argv[0] ); + put_error_and_exit( &Head, BDF_WRITE, argv[0] ); + } + if ( stat( targ_file, &statbuf ) ) { + Unlink_Tmpfile( Head.out_file, argv[0] ); + put_error_and_exit( &Head, BDF_WRITE, argv[0] ); + } + + exit ( Make_NewFefFile( targ_file, Head.out_file, + FONT_FILE_PARM, (uid_t)statbuf.st_uid, (gid_t)statbuf.st_gid, argv[0]) ); +} + + +static +CnvGPFtoBDF( head ) +struct ptobhead *head; +{ + int rtn; + char textbuf[BUFSIZE]; + + if ( ( rtn = ReadGpfHeader( head, textbuf ) ) ) { + return rtn; + } + + if ( ( rtn = WriteBdfHeader( head ) ) ) { + return rtn; + } + + if ( ( head->p_width != head->bdf_width ) || + ( head->p_height != head->bdf_height ) + ) { + head->zoomf = 1; + } else { + head->zoomf = 0; + } + + if ( ( head->code = (int *)malloc( sizeof(int) * head->num_chars ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( ( head->ptn = (char **)malloc( sizeof(char *)*head->num_chars ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( ( rtn = ReadGpfToMemory(head, textbuf ) ) ) { + return rtn; + } + + if ( ( rtn = WritePtnToBdf( head ) ) ) { + return rtn; + } + + return 0; +} + + +static void +put_error_and_exit( ptob, er_no, prog_name ) +struct ptobhead *ptob; +int er_no; +char *prog_name; +{ + ErrMsgTable_AndExit( er_no, ptob->snf_file, ptob->out_file, + ptob->in_file, NULL, + ptob->bdf_file, + prog_name + ); + return; +} + + +static void +put_help( prog_name ) +char *prog_name; +{ + USAGE1("Usage: %s -xlfd xlfd_name\n", prog_name); + USAGE("\t\t[-g character_size][-p character_pattern_file_name]\n" ); + USAGE("\t\t [-style style] \n"); + COMM_HELP_MSG ; + USAGE("The character size may be obtained using the dtlsgpf command.\n"); + USAGE("\n"); +} diff --git a/cde/programs/dtudcfonted/dtcpgpf/Imakefile b/cde/programs/dtudcfonted/dtcpgpf/Imakefile new file mode 100644 index 00000000..4b1dac89 --- /dev/null +++ b/cde/programs/dtudcfonted/dtcpgpf/Imakefile @@ -0,0 +1,28 @@ +XCOMM $XConsortium: Imakefile /main/8 1996/09/09 11:19:44 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + UDC_INC_PATH1 = -I../libfal/include + UDC_INC_PATH2 = -I../include + UDC_INC_PATH3 = -I./ + + INCLUDES = $(UDC_INC_PATH1) $(UDC_INC_PATH2) $(UDC_INC_PATH3) + +LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) -lc + + SRCS = cpgpf.c + + OBJS = cpgpf.o + +ComplexProgramTarget(dtcpgpf) diff --git a/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c b/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c new file mode 100644 index 00000000..715e0850 --- /dev/null +++ b/cde/programs/dtudcfonted/dtcpgpf/cpgpf.c @@ -0,0 +1,1209 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: cpgpf.c /main/6 1996/11/08 02:03:36 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#endif + +#include +#include +#include + +#include "bdfgpf.h" + +#include +#include +#include "fontstruct.h" + +#include "FaLib.h" +#include "snfstruct.h" +#include "udcutil.h" + +#include + +#define START_CODE 0 +#define END_CODE 1 +#define INPUT_FONT 0 +#define OUTPUT_FONT 1 + +#define RESIZE_BY_RATE( a, r ) ((int)( (float)(a) * (r))) +#define DEF_RESOLUTION ((78 / 72.27) * 100) + +static void put_error_and_exit(); +static void put_help(); +static void sigint_out() ; +static void getDefaultCh() ; +static void MkFontProp() ; + +static int CpyGpfInit() ; +static int writeGpf() ; +static int check_width() ; +static int check_height() ; +static int check_width_height() ; +static int getGpfFileName() ; +static int readGpf() ; +static int readBdfHeaderAndPut() ; +static int check_code() ; +static int readBdfToMemory() ; +static int cpg_atoi() ; +static int is_in_udcregion() ; + +extern int fal_code_to_glyph() ; + +static struct ptobhead WriteGpf; + +static char *targ_file = NULL; /* UDC_file_name */ +static char *com = NULL; /* command_name */ +static char create_font[BUFSIZE] ; +static int new_target = 0 ; +static unsigned int firstCol, lastCol, firstRow, lastRow ; +static char *locale ; +static char *spacing ; +static char *char_set ; +static char *xlfdname ; + + +static void +sigint_out() +{ + if (WriteGpf.out_file) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + } + exit( 0 ); +} + + +main( argc, argv ) +int argc; +char **argv ; +{ + int code_area , help, no_infile, no_style, type ; + int rtn, i, exit_code ; +#ifndef ROOT_ONLY + int exit_stat; +#endif + struct btophead InputGpf; /* input file */ + struct btophead OutputGpf; /* output file */ + struct stat statbuf; + char isnf_file[BUFSIZE] ; + char osnf_file[BUFSIZE] ; + char readbuf[BUFSIZE]; + char *istyle, *ostyle ; + char *ixlfdname, *oxlfdname ; + int chk_fd; + FalGlyphRegion *gr ; + int num_gr ; + char *start_code, *end_code ; + int startcode, endcode ; + + int code_no; + char *codeset = DEFAULT_CODESET; + + /* + * initiation of parameters + */ + com = argv[0]; + *create_font = '\0' ; + if( (locale = (char *)getenv( "LANG" )) == NULL ){ + locale = "C" ; + } + + memset( &InputGpf, 0, sizeof(struct btophead) ) ; + memset( &OutputGpf, 0, sizeof(struct btophead) ) ; + memset( &WriteGpf, 0, sizeof(struct ptobhead) ) ; + + COMM_SETDEFAULTSTYLE( istyle ) ; + COMM_SETDEFAULTSTYLE( ostyle ) ; + + InputGpf.in_file = OutputGpf.in_file = WriteGpf.out_file = NULL; + ixlfdname = oxlfdname = '\0' ; + spacing = char_set = xlfdname = NULL ; + + gr = NULL ; + num_gr = 0 ; + firstCol = firstRow = 0xff ; + lastCol = lastRow = 0 ; + + start_code = end_code = '\0' ; + startcode = MIN_CODE ; + endcode = MAX_CODE ; + + /* get full path of font compilers */ + if (!( bdftopcf = get_cmd_path( getenv( "PATH" ), BDFTOPCF_CMD ))) { + bdftopcf = BDFTOPCF; + } + if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) { + oakgtobdf = SNFTOBDF; + } + if (!( bdftosnf = get_cmd_path( getenv( "PATH" ), BDFTOSNF_CMD ))) { + bdftosnf = BDFTOSNF; + } + /***************************************************************** + * check options + *****************************************************************/ + code_area = NORMAL; + help = no_infile = no_style = type = 0; + + for ( i = 1; i < argc; i++ ) { + if ( *argv[i] != '-' ) { + if( !InputGpf.in_file ){ + InputGpf.in_file = argv[i] ; + }else if( !OutputGpf.in_file ){ + OutputGpf.in_file = argv[i] ; + } else { + put_help(com); + exit( 1 ); + } + }else if ( !strcmp( argv[i], "-ig" ) ) { + if ( ( i < argc-1) && (*argv[i+1] != '-' ) ) { + InputGpf.in_file = argv[++i]; + } else { + no_infile = 1; + } + } else if ( !strcmp( argv[i], "-og" ) ) { + if ( (i < argc-1) && (*argv[i+1] != '-') ){ + OutputGpf.in_file = argv[++i]; + } else { + no_infile = 2; + } + } else if ( !strcmp( argv[i], "-system" ) ) { + code_area |= SYSTM; + } else if ( !strcmp( argv[i], "-help" ) ) { + help = 1; + } else if ( !strcmp(argv[i], "-width") ) { + if ((i < argc-1) && (*argv[i+1] != '-')) { + OutputGpf.p_width = check_width( com, argv[++i]); + if (OutputGpf.p_width == 0) { + exit(1); + } + } else { + USAGE1("%s : The character width is not specified.\n", com); + exit( 1 ); + } + } else if ( !strcmp(argv[i], "-height") ) { + if ((i < argc-1) && (*argv[i+1] != '-')) { + OutputGpf.p_height = check_height( argv[0], argv[++i]); + if (OutputGpf.p_height == 0) { + exit(1); + } + } else { + USAGE1("%s : The character height is not specified.\n", com); + exit(1); + } + } else if ( !strcmp(argv[i], "-start") ) { + if ((i < argc-1) && (*argv[i+1] != '-')) { + start_code = argv[++i] ; + } else { + USAGE1("%s : The extract start code is not specified.\n", com); + exit( 1 ); + } + } else if ( !strcmp(argv[i], "-end" ) ) { + if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ) { + end_code = argv[++i] ; + } else { + USAGE1("%s : The extract end code is not specified.\n", com); + exit( 1 ); + } + } else if ( !strcmp( argv[i], "-istyle" ) ) { + if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ){ + istyle = argv[++i]; + } else { + no_style = 1; + } + } else if ( !strcmp( argv[i], "-ostyle" ) ) { + if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ){ + ostyle = argv[++i]; + } else { + no_style = 2; + } + } else if ( !strcmp( argv[i], "-codeset" ) ) { + if ( ( i < argc - 1 ) && ( *argv[i+1] != '-' )){ + codeset = argv[++i]; + COMM_SET_CODESET( codeset, code_area ) ; + } + } else if ( !strcmp( argv[i], "-ixlfd" ) ) { + if ( i < argc - 1 ){ + ixlfdname = argv[++i]; + } + } else if ( !strcmp( argv[i], "-oxlfd" ) ) { + if ( i < argc - 1 ){ + oxlfdname = argv[++i]; + } + } else if ( COMM_SBOPT_STRCMP( argv, i ) ) { + COMM_SBOPT_SETSBOPT( code_area ) ; + } else if ( COMM_TYPE_STRCMP( argv, i ) ) { + COMM_TYPE_SETTYPE( argc, argv, i, type ) ; + } else { + put_help(com); + exit( 1 ); + } + } + + /* help_message */ + if ( help == 1 ) { + put_help( com ); + exit( 0 ); + } + COMM_SBOPT_CHECKSBOPT( com, code_area ) ; + + if ( no_infile ) { + if ( no_infile == 1 ) + USAGE1("%s : The font file name for input cannot be omitted.\n", com ); + else + USAGE1("%s : The font file name for output cannot be omitted.\n", com ); + exit( 1 ); + } + + if ( (code_no = cpg_atoi( codeset)) == -1 ) { + USAGE1("%s : The code set number is illegal.\n", com ); + exit( 1 ); + } + + if ( no_style ) { + if ( no_style == 1 ) + USAGE1("%s : The style for input cannot be omitted.\n", com ); + else + USAGE1("%s : The style for output cannot be omitted.\n", com ); + USAGE1("%s : The style is not specified.\n", com ) ; + exit( 1 ); + } + + /***************************************************************** + * get file name + *****************************************************************/ + /* copy origin */ + if ( getGpfFileName( com, &InputGpf, code_area, code_no, ixlfdname, isnf_file, istyle ) ) { + exit( 1 ); + } + + /* copy target */ + if ( getGpfFileName( com, &OutputGpf, code_area, code_no, oxlfdname, osnf_file, ostyle ) ) { + exit( 1 ); + } + + /* + * refuse proportional fonts + */ + if( ( !stat( OutputGpf.in_file, &statbuf ) )){ + if ( GetUdcFontName( OutputGpf.in_file, NULL, &xlfdname ) ) { + USAGE2("%s : This font cannot get XLFD(%s). Terminates abnormally.\n", com, OutputGpf.in_file ); + exit( 1 ); + } + GETSPACINGSTR( spacing, xlfdname ) ; + if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) { + USAGE2("%s : cannot edit proportional fonts.(SPACING \"%s\")\n", com, spacing ); + exit( 1 ); + } + }else{ + /* new file */ + if( !(code_area & SYSTM) ){ + USAGE2("%s : \"%s\" does not exists.\n", com, OutputGpf.in_file ); + exit( 1 ); + } + } + if( xlfdname ) free( xlfdname ) ; + if ( GetUdcFontName( InputGpf.in_file, NULL, &xlfdname ) ) { + USAGE2("%s : This font cannot get XLFD(%s). Terminates abnormally.\n", com, InputGpf.in_file ); + exit( 1 ); + } + GETSPACINGSTR( spacing, xlfdname ) ; + if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) { + USAGE2("%s : cannot edit proportional fonts.(SPACING \"%s\")\n", com, spacing ); + exit( 1 ); + } + GETCHARSETSTR( char_set, xlfdname ) ; + + /***************************************************************** + * get UDC code region + *****************************************************************/ + if ( !(code_area & SYSTM) ) { + if ( GetUdcRegion( com, code_no, InputGpf.in_file, &num_gr, &gr ) ) { + USAGE1("%s : This font cannot get UDC code region. Terminates abnormally.\n", com); + exit( 1 ); + } + } else { + num_gr = 1 ; + if( (gr = (FalGlyphRegion *)malloc( sizeof(FalGlyphRegion) * num_gr )) == NULL ) { + USAGE1("%s : malloc error. Terminates abnormally.\n", com); + exit( 1 ); + } + gr[0].start = MIN_CODE ; + gr[0].end = MAX_CODE ; + } + + /* + * check specified code region + */ + if( start_code && end_code ) { + if( (startcode = check_code(com, start_code, START_CODE, char_set, num_gr, gr )) < 0 ) { + exit( 1 ); + } + if( (endcode = check_code(com, end_code, END_CODE, char_set, num_gr, gr )) < 0 ) { + exit( 1 ); + } + + if ( startcode > endcode ) { + USAGE1("%s : The specification of extract start/end code is improper.\n", com); + exit( 1 ); + } + + if( is_in_udcregion( startcode, endcode, num_gr, gr ) ){ + USAGE3("%s : The specified code \"%s-%s\" is outside of the UDC code region.\n", com, start_code, end_code ); + USAGE("The UDC code region of specified font is showed below.\n" ); + for( i=0; i GPFTOBDF ==H + * H + * (OutputGpf.in_file) --> GPFTOBDF ==H + * H + * dtcpgpf + * H + * (WriteGpf.out_file) <-- BDFTOGPF ==H + * + */ + + signal( SIGHUP , (void(*)())sigint_out ); + signal( SIGINT , (void(*)())sigint_out ); + signal( SIGQUIT, (void(*)())sigint_out ); + signal( SIGTERM, (void(*)())sigint_out ); + + if ( rtn = CpyGpfInit( &InputGpf, &OutputGpf, &WriteGpf, type ) ) { + if ( WriteGpf.out_file ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + } + put_error_and_exit( &InputGpf, &WriteGpf, rtn, com ); + } + + /* read copy origin */ + if ( (rtn = readGpf( &InputGpf, readbuf, startcode, endcode, num_gr, gr )) ){ + if ( WriteGpf.out_file ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + } + put_error_and_exit( &InputGpf, &WriteGpf, rtn, com ); + } + fclose( InputGpf.input ); + + /* read copy target */ + if( (rtn = readBdfHeaderAndPut(&OutputGpf, &WriteGpf, readbuf)) ) { + if ( WriteGpf.out_file ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + } + put_error_and_exit( &InputGpf, &WriteGpf, rtn, com ); + } + fclose( OutputGpf.input ); + wait( 0 ); + + /* + * write SNF output file + */ + if ( ( rtn = writeGpf( &InputGpf, &OutputGpf, &WriteGpf ) ) ) { + if ( WriteGpf.out_file ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + } + put_error_and_exit( &InputGpf, &WriteGpf, rtn, com ); + } + +#ifdef ROOT_ONLY + if ( pclose( WriteGpf.output ) ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + put_error_and_exit( &InputGpf, &WriteGpf, PCLOSE_ERROR, com ); + } +#else + fclose( WriteGpf.output ); + wait( &exit_stat ); +#if !defined( SVR4 ) && !defined( SYSV ) + if ( !WIFEXITED(exit_stat) ) { +#else + if ( ! ( WIFEXITED(exit_stat) && !WEXITSTATUS(exit_stat) ) ) { +#endif + USAGE3("%s: The error occurred by %s (%08x).\n", com, oakgtobdf, exit_stat); + Unlink_Tmpfile( WriteGpf.out_file, com ); + put_error_and_exit( &InputGpf, &WriteGpf, FATAL_ERROR, com ); + } +#endif + signal( SIGHUP , SIG_IGN ); + signal( SIGINT , SIG_IGN ); + signal( SIGQUIT, SIG_IGN ); + signal( SIGTERM, SIG_IGN ); + + sleep( 1 ); + if ( ( stat( WriteGpf.out_file, &statbuf ) ) || ( statbuf.st_size == 0 ) + ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + put_error_and_exit( &InputGpf, &WriteGpf, BDF_WRITE, com ); + } + if ( stat( WriteGpf.snf_file, &statbuf ) ) { + Unlink_Tmpfile( WriteGpf.out_file, com ); + exit( 1 ); + } + exit_code = Make_NewFefFile( WriteGpf.snf_file, WriteGpf.out_file, + FONT_FILE_PARM, (uid_t)statbuf.st_uid, (gid_t)statbuf.st_gid, com ) ; + + if( !exit_code ){ + if( *create_font != '\0' && new_target ) + fprintf( stdout, "%s : New font <%s> is created.\n", com, create_font ); + } + exit( exit_code ); +} + + +static int +getGpfFileName( com, gpfinf, code_area, code_no, xlfdname, snf_file, style ) +char *com ; +struct btophead *gpfinf ; +int code_area ; +int code_no ; +char *xlfdname ; +char *snf_file ; +char *style ; +{ + + + if ( gpfinf->in_file == NULL && xlfdname == NULL ) { + if ( code_area & SYSTM ) { + USAGE1("%s : The GPF output file name cannot be omitted.\n", com ); + } else { /* string of charcter size */ + USAGE1("%s : The character size specification cannot be omitted.\n", com ); + } + return -1 ; + } + + /* open GPF file */ + if ( !(code_area & SYSTM) ) { + if( xlfdname ) { + if ( GetUdcFileName( com, code_no, xlfdname, snf_file ) ) { + USAGE2("%s : Failed to get font file.( XLFD: %s ) Terminates abnormally.\n", com, xlfdname ); + return -1 ; + } + gpfinf->in_file = snf_file ; + } else { + + switch ( GetFileName( com, gpfinf->in_file, style, code_no, snf_file ) ) { + case 0: + gpfinf->in_file = snf_file; + break; + case -1: + return -1 ; + default: + USAGE1("%s : The font file name cannot be obtained. Terminates abnormally.\n", com); + return -1 ; + } + } + } + + return 0 ; +} + + +static +CpyGpfInit(i_gpf, o_gpf, w_gpf, type ) +struct btophead *i_gpf; +struct btophead *o_gpf; +struct ptobhead *w_gpf; +int type ; +{ + FontInfoRec *finf; + int ifd[2], ofd[2], snf_fd, permission; + char buf[BUFSIZE]; +#ifdef ROOT_ONLY + char command[BUFSIZE], *ep ; +#else + int pfd[2], out_fd ; +#endif + + /* SNF format */ + if( !new_target ){ + if ( ChkPcfFontFile( w_gpf->snf_file ) ) { + permission = 0 ; + if( (snf_fd = open( w_gpf->snf_file, O_RDONLY ) ) >= 0 ) { + COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) ; + if ( permission < 0 ) { + return BDF_INVAL; + } + } else { + return BDF_OPEN_IN; + } + } + }else{ + COMM_SNF_NEWTARGET( permission ) ; + } + + /* open pipe for copy origin gpf */ + if (pipe(ifd) != 0) { + return PIPE_ERROR; + } + switch ( fork() ) { + case 0: + close( ifd[0] ); + close( 1 ); + if ( dup( ifd[1] ) < 0 ) { + return DUP_ERROR; + } + close( ifd[1] ); + /* SNFTOBDF */ + execl( oakgtobdf, oakgtobdf, i_gpf->in_file, 0 ); + return EXEC_ERROR; + case -1: + return FORK_ERROR; + default: + break; + } + close( ifd[1] ); + if ( ( i_gpf->input = fdopen( ifd[0], "r" ) ) == NULL ) { + return FDOPEN_ERROR; + } + + /* open pipe for copy target gpf */ + if (pipe(ofd) != 0) { + return PIPE_ERROR; + } + switch ( fork() ) { + case 0: + close( ofd[0] ); + close( 1 ); + if ( dup( ofd[1] ) < 0 ) { + return DUP_ERROR; + } + close( ofd[1] ); + /* SNFTOBDF */ + if( !new_target ){ + execl( oakgtobdf, oakgtobdf, o_gpf->in_file, "-H", 0 ); + }else{ + execl( oakgtobdf, oakgtobdf, i_gpf->in_file, "-H", 0 ); + } + return EXEC_ERROR; + case -1: + return FORK_ERROR; + default: + break; + } + close( ofd[1] ); + if ( ( o_gpf->input = fdopen( ofd[0], "r" ) ) == NULL ) { + return FDOPEN_ERROR; + } + + /* open pipe for target gpf */ + if ( !( w_gpf->out_file = GetTmpPath( targ_file ) ) ) { + return MKTMP_ERROR; + } + +#ifdef ROOT_ONLY + if( ChkPcfFontFile( w_gpf->snf_file ) == 0 ) { + sprintf(command, "%s > %s", bdftopcf, w_gpf->out_file) ; + } else { + COMM_SNF_POPEN( permission, w_gpf->snf_file, w_gpf->out_file, ep, buf, command ) ; + } + if ((w_gpf->output = popen(command, "w")) == NULL) { + return(POPEN_ERROR); + } +#else /* ROOT_ONLY */ + if ( pipe( pfd ) != 0 ) { + return PIPE_ERROR; + } + switch ( fork() ) { + case 0: + if ( ( out_fd = open( w_gpf->out_file, O_WRONLY | O_CREAT, 0664 ) ) < 0 ) { + return BDF_OPEN_OUT; + } + close( 0 ); + if ( dup(pfd[0]) < 0 ) { + return DUP_ERROR; + } + close( pfd[0] ); + close( pfd[1] ); + close( 1 ); + if( dup( out_fd ) < 0 ) { + close( out_fd ); + return DUP_ERROR; + } + close( out_fd ); + /* pcf format */ + if ( ChkPcfFontFile( w_gpf->snf_file ) == 0 ) { + execl( bdftopcf, bdftopcf, 0 ); + return PCFFONTC_ERROR; + } + /* snf format */ + if( type ) permission = type ; + COMM_SNF_EXECLBDFTOSNF( permission, buf, w_gpf->snf_file ) ; + return SNFFONTC_ERROR; + + case -1: + return FORK_ERROR; + default: + break; + } + close( pfd[0] ); + if ( ( w_gpf->output = fdopen( pfd[1], "w" ) ) == NULL ) { + return FDOPEN_ERROR; + } +#endif /* ROOT_ONLY */ + return 0; +} + + + +static int +readGpf(i_gpf, buf, startcode, endcode, num_gr, gr) +struct btophead *i_gpf; +char *buf; +int startcode ; +int endcode ; +FalGlyphRegion *gr ; +{ + int nchar, rtn; + + if ( ( rtn = ReadBdfHeader( i_gpf, buf ) ) ) { + return rtn; + } + + nchar = i_gpf->num_chars ; + + if ( ( i_gpf->code = (int *)malloc( sizeof(int) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + if ( ( i_gpf->ptn = (char **)malloc( sizeof(char *) * nchar ) ) == NULL ) { + return MALLOC_ERROR; + } + + return readBdfToMemory( i_gpf, buf, startcode, endcode, num_gr, gr ) ; +} + + + +static int +readBdfHeaderAndPut(o_gpf, w_gpf, buf) +struct btophead *o_gpf; +struct ptobhead *w_gpf; +char *buf; +{ + FILE *fp ; + char *p; + int getstat, zoom, property ; + + getstat = zoom = property = 0 ; + + if( o_gpf->p_width || o_gpf->p_height ){ + zoom = 1 ; + } + if ( (fp = fopen( w_gpf->out_file, "w" )) == NULL ) { + return BDF_OPEN_HEAD ; + } + + while ( 1 ) { + if ( fgets( buf, BUFSIZE, o_gpf->input ) == NULL ) { + fclose(fp) ; + return BDF_INVAL; + } + p = buf; + SCAN_TO_NONSP( p ) + if ( !strncmp( p, SIZE, strlen( SIZE ) ) ) { + if ( ( sscanf( p, "SIZE %f%d", + &(o_gpf->bdf_point), &(o_gpf->bdf_xdpi))) != 2 ) { + fclose(fp) ; + return BDF_INVAL; + } + fprintf( fp, "%s", buf ); + getstat |= 0x01; + + } else if ( !strncmp( p, FONTBOUNDINGBOX, strlen( FONTBOUNDINGBOX ) ) ) { + if ( ( sscanf( p, "FONTBOUNDINGBOX %d%d%d%d", + &(o_gpf->bdf_width), &(o_gpf->bdf_height), + &(o_gpf->bdf_x), &(o_gpf->bdf_y) )) != 4) { + fclose(fp) ; + return BDF_INVAL; + } + /* -width / -height */ + if( zoom ){ + /* -width / -height */ + if( o_gpf->p_width ) o_gpf->bdf_width = o_gpf->p_width ; + if( o_gpf->p_height ) o_gpf->bdf_height = o_gpf->p_height ; + fprintf( fp, "FONTBOUNDINGBOX %d %d %d %d\n", + o_gpf->bdf_width, o_gpf->bdf_height, + o_gpf->bdf_x, o_gpf->bdf_y ); + }else{ + fprintf( fp, "%s", buf ); + } + getstat |= 0x02; + + } else if ( !strncmp( p, "ENDPROPERTIES", strlen( "ENDPROPERTIES" ) ) ) { + fprintf( fp, "%s", buf ); + fclose(fp) ; + getstat |= 0x04; + break; + } else { + + if( zoom ){ + if ( !strncmp( p, "STARTPROPERTIES", strlen( "STARTPROPERTIES" ) ) ) { + property = 1 ; + fprintf( fp, "%s", buf ); + } else if ( !strncmp( p, "FONT ", strlen( "FONT " ) ) ) { + char font[BUFSIZE] ; + if( property ){ + if( (sscanf( buf, "FONT \"%s\"", font )) != 1 ){ + fclose(fp) ; + return BDF_INVAL; + } + MkFontProp( o_gpf->bdf_height, font, create_font ) ; + fprintf( fp, "FONT \"%s\"\n", create_font ) ; + }else{ + if( (sscanf( buf, "FONT %s", font )) != 1 ){ + fclose(fp) ; + return BDF_INVAL; + } + MkFontProp( o_gpf->p_height, font, create_font ) ; + fprintf( fp, "FONT %s\n", create_font ) ; + } + } else if ( !strncmp( p, "PIXEL_SIZE ", strlen( "PIXEL_SIZE " ) ) ) { + fprintf( fp, "PIXEL_SIZE %d\n", o_gpf->bdf_height ) ; + } else if ( !strncmp( p, "AVERAGE_WIDTH ", strlen( "AVERAGE_WIDTH " ) ) ) { + fprintf( fp, "AVERAGE_WIDTH %d\n", o_gpf->bdf_height*10 ) ; + } else if ( !strncmp( p, "POINT_SIZE ", strlen( "POINT_SIZE " ) ) ) { + fprintf( fp, "POINT_SIZE %d\n", o_gpf->bdf_height*10 ); + } else if ( !strncmp( p, "RESOLUTION ", strlen( "RESOLUTION " ) ) ) { + int resol ; + if( (sscanf( buf, "RESOLUTION %d\n", &resol )) != 1 ){ + fclose(fp) ; + return BDF_INVAL; + } + fprintf( fp, "RESOLUTION %d\n", (int)((resol<0)?DEF_RESOLUTION:resol) ); + } else if ( !strncmp( p, "X_HEIGHT ", strlen( "X_HEIGHT " ) ) ) { + fprintf( fp, "X_HEIGHT %d\n", o_gpf->bdf_height ); + } else if ( !strncmp( p, "QUAD_WIDTH ", strlen( "QUAD_WIDTH " ) ) ) { + fprintf( fp, "QUAD_WIDTH %d\n", o_gpf->bdf_width ); + } else if ( !strncmp( p, "FONT_ASCENT ", strlen( "FONT_ASCENT " ) ) ) { + fprintf( fp, "FONT_ASCENT %d\n", (o_gpf->bdf_height + o_gpf->bdf_y) ); + } else if ( !strncmp( p, "FONT_DESCENT ", strlen( "FONT_DESCENT " ) ) ) { + fprintf( fp, "FONT_DESCENT %d\n", -(o_gpf->bdf_y) ); + } else if ( !strncmp( p, "DEFAULT_CHAR ", strlen( "DEFAULT_CHAR " ) ) ) { + fprintf( fp, "DEFAULT_CHAR %d\n", ((firstRow << 8) + firstCol) ); + } else { + fprintf( fp, "%s", buf ); + } + } else { /* zoom */ + fprintf( fp, "%s", buf ); + } + } + + } /* while loop */ + fclose(fp) ; + if ( getstat != 0x07 ) { + return BDF_INVAL; + } + + return 0; +} + + +static +writeGpf( i_gpf, o_gpf, w_gpf ) +struct btophead *i_gpf; +struct btophead *o_gpf; +struct ptobhead *w_gpf; +{ + FILE *fp ; + char rdbuf[BUFSIZE] ; + + /* put BDF header from temporary file */ + if ( (fp = fopen( w_gpf->out_file, "r" )) == NULL ) { + return BDF_OPEN_HEAD ; + } + while( fgets( rdbuf, BUFSIZE, fp ) != (char *)NULL ){ + fprintf( w_gpf->output, "%s", rdbuf ) ; + } + if( feof(fp) != 0 ){ + fclose(fp) ; + }else{ + fclose(fp) ; + return BDF_READ_HEAD ; + } + + /* set specified width or height */ + w_gpf->bdf_width = o_gpf->bdf_width ; + w_gpf->bdf_height = o_gpf->bdf_height ; + w_gpf->bdf_x = o_gpf->bdf_x; + w_gpf->bdf_y = o_gpf->bdf_y; + w_gpf->bdf_point = o_gpf->bdf_point; + w_gpf->bdf_xdpi = o_gpf->bdf_xdpi; + + w_gpf->p_width = i_gpf->bdf_width; + w_gpf->p_height = i_gpf->bdf_height; + + if( w_gpf->bdf_width != w_gpf->p_width || + w_gpf->bdf_height != w_gpf->p_height ) { + w_gpf->zoomf = 1; + }else{ + w_gpf->zoomf = 0; + } + + w_gpf->num_chars = i_gpf->num_chars; + w_gpf->code = i_gpf->code; + w_gpf->ptn = i_gpf->ptn; + + return WritePtnToBdf( w_gpf ); +} + + + +static int +check_width( prog_name, len_str ) +char *prog_name; +char *len_str; +{ + return( check_width_height( prog_name, len_str, 0) ); +} + + +static int +check_height( prog_name, len_str ) +char *prog_name; +char *len_str; +{ + return( check_width_height( prog_name, len_str, 1) ); +} + +static int +check_width_height( prog_name, len_str, mode ) +char *prog_name; +char *len_str; +int mode; /* width ... 0 , height ... 1 */ +{ + int ret; + char *tmp; + + ret = (int)strtol( len_str, &tmp, 10 ); /* <-- ret = atoi( len_str ) */ + if ((tmp == len_str) || (ret < MIN_FONT_WIDTH) || (ret > MAX_FONT_WIDTH)) { + switch( mode ) { + case 0: + USAGE2("%s : The specification of the character width is improper.\"%s\"¡¥\n", + prog_name, len_str); + break; + case 1: + USAGE2("%s : The specification of the character height is improper.\"%s\"¡¥\n", + prog_name, len_str); + break; + default: + break; + } + return(0); + } + return( ret ); +} + + + +static int +check_code( prog_name, code_str, mode, charset, num_gr, gr ) +char *prog_name; +char *code_str; +int mode; /* start_code ... 0, end_code ... 1 */ +char *charset ; +int num_gr ; +FalGlyphRegion *gr ; +{ + int err_flg = 0; + int code_num; + char *tmp; + FalGIInf *gi ; + int num_gi ; + int i, code ; + + code = (int)strtol(code_str, &tmp, 16); + if ( tmp == code_str ) { + err_flg = 1; + } + + if( COMM_SBFNT_ISSBFNT( charset ) ) { + code_num = code ; + CONVGLYPHINDEX( code_num ) ; + } else { + if( fal_code_to_glyph( locale, code, &gi, &num_gi) ) { + USAGE2("%s : Failed to convert code point into glyph index.\"%s\" \n", prog_name, code_str ) ; + err_flg = 1; + } + if( num_gi==1 ){ + code_num = gi[0].glyph_index ; + err_flg = 0 ; + }else{ + for( i=0; i= gr[i].start) && (code_num <= gr[i].end) ) + return( code_num ); + } + err_flg = 1 ; + } + if (err_flg) { + switch( mode ) { + case 0: + USAGE2("%s : The specification of the extract start code is improper.\"%s\"¡¥\n", + prog_name, code_str); + break; + case 1: + USAGE2("%s : The specification of the extract end code is improper.\"%s\"¡¥\n", + prog_name, code_str); + break; + default: + USAGE2("%s : The specification of the extract code is improper.\"%s\"¡¥\n", + prog_name, code_str); + } + return(-1); + } + return(-1); + +} + + + +static int +readBdfToMemory(head, buf, startcode, endcode, num_gr, gr) +struct btophead *head; +char *buf; +int startcode ; +int endcode ; +int num_gr ; +FalGlyphRegion *gr ; +{ + int code, mwidth, num_char, bsize, rtn; + char *ptn; + + num_char = 0; + mwidth = (head->bdf_width + 7) / 8; + bsize = mwidth * head->bdf_height; + while(1) { + if ((rtn = GetBdfCode(head, buf, &code)) < 0) { + return(rtn); /* contain BDF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + if ( !IsInRegion( code, num_gr, gr ) && + ( startcode > code || endcode < code ) + ){ + continue; + } + getDefaultCh( (unsigned int)code ) ; + + head->code[num_char] = code; + if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) { + return(MALLOC_ERROR); + } + if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} + + +static void +getDefaultCh( code ) +unsigned int code ; +{ + unsigned int cbuf ; + cbuf = code ; + if( (cbuf & 0xff) < firstCol ) firstCol = cbuf & 0xff ; + if( (cbuf >> 8) < firstRow ) firstRow = cbuf >> 8 ; + if( (cbuf & 0xff) > lastCol ) lastCol = cbuf & 0xff ; + if( (cbuf >> 8) > lastRow ) lastRow = cbuf >> 8 ; +} + + +static int +cpg_atoi( numstr ) +char *numstr ; +{ + int val ; + char *ep, *cbuf ; + + ep = (char *)strchr( numstr, '\0' ) ; + val = (int)strtol( numstr, &cbuf, 10 ) ; + if ( cbuf == numstr || cbuf != ep ) { + return -1 ; + } + return val ; +} + +static int +is_in_udcregion( start, end, num_gr, gr ) +int start, end, num_gr ; +FalGlyphRegion *gr ; +{ + int i ; + if( start < gr[0].start && end < gr[0].start ){ + return -1 ; + } + for( i=0; i gr[i].end && start < gr[i+1].start ) + && (end > gr[i].end && end < gr[i+1].start ) + ) + return -1 ; + } + if( start > gr[num_gr-1].end && end > gr[num_gr-1].end ){ + return -1 ; + } + return 0 ; +} + + +static void +MkFontProp(font_height, font, output) +int font_height ; +char *font; +char *output; +{ + char fbuf[BUFSIZE], split[BUFSIZE] ; + char *ep, *pix_sz, *point_sz, *rsl_x, *av_width, *char_set ; + + snprintf( fbuf, sizeof(fbuf), "%s", font ) ; + snprintf( split, sizeof(split), "%s", font ) ; + ep = fbuf ; + ep += strlen( fbuf ) ; + ep-- ; + if( *ep == '"' ) *ep = '\0' ; + POINTXLFDELM( pix_sz, fbuf, XLFD_ELM_PIXEL_SIZE ) ; + POINTXLFDELM( point_sz, split, XLFD_ELM_POINT_SIZE ) ; + POINTXLFDELM( rsl_x, split, XLFD_ELM_RESOLUTION_X ) ; + POINTXLFDELM( av_width, split, XLFD_ELM_AVERAGE_WIDTH ) ; + POINTXLFDELM( char_set, fbuf, XLFD_ELM_CHARSET_REGISTRY ) ; + *pix_sz = '\0' ; + *av_width = '\0' ; + + sprintf(output, "%s-%d-%s-%d%s", fbuf, + font_height, /* pixel size */ + rsl_x, + font_height*10, /* average width */ + char_set ); +} + + + +static void +put_error_and_exit(ptob_in, ptob_out, er_no, prog_name) +struct btophead *ptob_in; +struct ptobhead *ptob_out; +int er_no; +char *prog_name; +{ + ErrMsgTable_AndExit( er_no, ptob_in->in_file, ptob_out->out_file, + NULL, NULL, NULL, prog_name ); + return; +} + + + +static void +put_help( prog_name ) +char *prog_name; +{ + USAGE1("Usage: %s -ixlfd oxlfd -oxlfd oxlfd\n", prog_name); + USAGE("\t[in_character_size][out_character_size]\n"); + USAGE("\t[-start start_code][-end end_code]\n"); + USAGE("\t[-istyle ostyle][-ostyle ostyle]"); + COMM_HELP_MSG ; + USAGE1("%s can copy glyphs of gpf file in the following code area.\n", prog_name); + USAGE("codeset \t\tcode area\n"); + USAGE("----------------------------------------\n"); + DispUdcCpArea() ; + USAGE("If the -start and -end option is omitted, the start/end code of each extractive area is specified.\n"); + USAGE("The xlfd name and character size may be obtained using dtlsgpf command.\n"); + return; +} diff --git a/cde/programs/dtudcfonted/dtgpftobdf/Imakefile b/cde/programs/dtudcfonted/dtgpftobdf/Imakefile new file mode 100644 index 00000000..e4e5a80d --- /dev/null +++ b/cde/programs/dtudcfonted/dtgpftobdf/Imakefile @@ -0,0 +1,25 @@ +XCOMM $XConsortium: Imakefile /main/8 1996/09/09 11:19:48 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + INCLUDES = -I../libfal/include\ + -I../include + +LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) -lc + + SRCS = gpftobdf.c + + OBJS = gpftobdf.o + +ComplexProgramTarget(dtgpftobdf) diff --git a/cde/programs/dtudcfonted/dtgpftobdf/bdftosnf.h b/cde/programs/dtudcfonted/dtgpftobdf/bdftosnf.h new file mode 100644 index 00000000..f5f5f639 --- /dev/null +++ b/cde/programs/dtudcfonted/dtgpftobdf/bdftosnf.h @@ -0,0 +1,131 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: bdftosnf.h /main/4 1996/06/25 20:13:29 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include + +#ifndef MIN +#define MIN(a,b) ((a)>(b)?(b):(a)) +#endif +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + +typedef struct _GlyphMap { + char *bits; + int h; + int w; + int widthBytes; +} GlyphMap; + +/* + * a structure to hold all the pointers to make it easy to pass them all + * around. Much like the FONT structure in the server. + */ + +typedef struct _TempFont { + FontInfoPtr pFI; + CharInfoPtr pCI; + unsigned char *pGlyphs; + FontPropPtr pFP; + CharInfoPtr pInkCI; + CharInfoPtr pInkMin; + CharInfoPtr pInkMax; +} TempFont; /* not called font since collides with type in X.h */ + +#ifdef vax +# define DEFAULTGLPAD 1 /* default padding for glyphs */ +# define DEFAULTBITORDER LSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER LSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ + +#elif defined(sun) + +# if (sun386 || sun5) +# define DEFAULTGLPAD 4 /* default padding for glyphs */ +# define DEFAULTBITORDER LSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER LSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ +# else +# define DEFAULTGLPAD 4 /* default padding for glyphs */ +# define DEFAULTBITORDER MSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER MSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ +# endif + +#elif defined(ibm032) + +# define DEFAULTGLPAD 1 /* default padding for glyphs */ +# define DEFAULTBITORDER MSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER MSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ + +#elif defined(hpux) + +# define DEFAULTGLPAD 2 /* default padding for glyphs */ +# define DEFAULTBITORDER MSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER MSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ + +#elif defined(pegasus) + +# define DEFAULTGLPAD 4 /* default padding for glyphs */ +# define DEFAULTBITORDER MSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER MSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ + +#elif defined(mips) +# ifdef MIPSEL + +# define DEFAULTGLPAD 4 /* default padding for glyphs */ +# define DEFAULTBITORDER LSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER LSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ + +# else +# define DEFAULTGLPAD 4 /* default padding for glyphs */ +# define DEFAULTBITORDER MSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER MSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ +# endif + +#else +# define DEFAULTGLPAD 1 /* default padding for glyphs */ +# define DEFAULTBITORDER MSBFirst /* default bitmap bit order */ +# define DEFAULTBYTEORDER MSBFirst /* default bitmap byte order */ +# define DEFAULTSCANUNIT 1 /* default bitmap scan unit */ +#endif + +#define GLWIDTHBYTESPADDED(bits,nbytes) \ + ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ + :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ + :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ + :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ + : 0) diff --git a/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c b/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c new file mode 100644 index 00000000..25ae6867 --- /dev/null +++ b/cde/programs/dtudcfonted/dtgpftobdf/gpftobdf.c @@ -0,0 +1,1574 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: gpftobdf.c /main/5 1996/11/08 02:04:24 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "font.h" +#include "misc.h" +#include +#include +#include +#include +#include +#include "fontstruct.h" +#include "snfstruct.h" +#include +#include "bdftosnf.h" +#include +#if defined( SVR4 ) +#include +#endif + +#include "udccom.h" +#include "udcutil.h" + +#define GLYPHPADOPTIONS 4 +#define SIZEOF_COMPRESSED_METRIC 5 + +#include "gtobdf.h" +#include "pcf.h" + +typedef struct pcf_tmp { + FontInfoRec info; + int ntables; + PCFTablePtr tables; + int nprops; + FontPropPtr props; + char *isStringProp; + int str_length; + char *string; + int nbitmaps; + CARD32 bmp_fmt; /* bitOrder ,byteOrder, glyph, scan */ + CARD32 *offsets; + int sizebitmaps; + char *bitmaps; + CARD32 enc_fmt; + CARD16 *encodingOffsets; + size_t pcf_bufsz; + caddr_t pcf_buffer; + + /* scale width */ + CARD32 swd_fmt ; + int swd_num ; + CARD32 *swidth ; + + /* glyph name */ + CARD32 glyph_fmt ; + unsigned int glyphs ; + int *glyph_offset ; + char *glyph_name ; + + /* metrics */ + int compress ; + CARD32 mtr_fmt ; + int mtr_num ; + xCharInfo *metrics; + +} PcfTmp; + +typedef struct prop_tmp { + char *font_name; + FontPropRec psize; + FontPropRec resolution; +} PropTmp; + + + +static char *readfontfile(); +static void Anafprop(); +static void pSIZE(); +static void pPROPS(); +static void pCHARS(); +static void pfixCHARS(); +static int getarg(); + +static Bool seekToType() ; +static void getMetric() ; +static Bool getAccel() ; +static Bool getProperties() ; +static void putPtn() ; +static void ByteSwap() ; +static void invertBits() ; + +static int getINT16() ; +static int getINT32() ; +static CARD32 getLSB32(); +static char *make_toptn(); +static void pSIZE_pcf(); +static PcfTmp *openPcfFont(); +static void setProp(); +static void pPROPS_pcf(); +static void pCHARS_pcf(); +static void BitOrderInvert(); +static char *bufp,buf[2048]; + +extern int ChkPcfFontFile(); + + +main( argc,argv ) +int argc; +char *argv[]; +{ + int i,k; + + + char *fp; /* font */ + FontInfoRec *fip; /* font information */ + CharInfoRec *cip, *wkcip; /* character information */ + unsigned int glyphstotal; /* glyph */ + unsigned int charInfoNum ; /* character information's number */ + unsigned int charNum; /* define character number */ + char *glyphPtr; /* glyph */ + FontPropRec *fpropPtr,*fplistPtr; /* font property list */ + FontPropRec psprop; /* point size property */ + FontPropRec resprop; /* resolution property */ + char *fpropvnPtr; + + unsigned int fplistNum; /* font property number */ + char *fontname; /* fontname */ + time_t clock; + struct tm *tm; + char tmbuf[80] ; + + char fname[1024]; /* snf filename */ + int bitorder; /* bitorder */ + int byteorder; /* byteorder */ + int scanunit; /* scanunit */ + int glyphPad ; /* glyph */ + int outLevel; /* output information level */ + int fix; + + + int isPcf; + + PcfTmp *pcf; + PropTmp proptmp; + char *tmpfname; + extern char *GetRealFileName(); + + + if (getarg(argc,argv,fname,&bitorder,&byteorder,&scanunit,&glyphPad, + &outLevel,&fix) != 0) { + exit( -1 ); + } + + /* + * read to fontfile + */ + if ( ( tmpfname = GetRealFileName( fname ) ) == NULL ) { + USAGE("dtgpftobdf: cannot refer to substance file.\n" ); + exit( -1 ); + } + if ( strcmp( tmpfname, fname ) != 0 ){ + strcpy( fname, tmpfname ); + } + + if ( ChkPcfFontFile( fname ) == 0 ){ + /* pcf font */ + isPcf = 1; + if ( !( pcf = openPcfFont( fname ) ) ) { + USAGE("dtgpftobdf: cannot open font\n" ); + exit( -1 ); + } + } else { + /* snf font */ + isPcf = 0; + if ( ( fp = readfontfile( fname ) ) == (char *)-1 ) { + exit( -1 ); + } + } + + + if ( !isPcf ) { + /* SNF format */ + COMM_SNF_GETHEADER( fip, fp ) ; + /* font file check */ + if ((fip->version1 != fip->version2) || + (fip->version1 != FONT_FILE_VERSION)) { + USAGE("dtgpftobdf: illegal font version\n"); + exit( -1 ); + } + + cip = (CharInfoRec *)((char *)fip + sizeof(FontInfoRec)); + + charInfoNum = (fip->lastCol - fip->firstCol + 1) + *(fip->lastRow - fip->firstRow + 1); + glyphPtr = ((char *)cip) + ( charInfoNum * sizeof(CharInfoRec) ); + + charNum = charInfoNum ; + wkcip = cip ; + + glyphstotal = fip->maxbounds.byteOffset; + + glyphPad = (((fip->maxbounds.metrics.rightSideBearing + - fip->maxbounds.metrics.leftSideBearing)+31)/32)*4; + + if ( fix == TRUE ) { + for ( i = 0; i < charInfoNum; i++ ) { + if ( wkcip->exists == FALSE ) { + charNum-- ; + } + wkcip++; + } + } else { + glyphstotal = 0 ; + for ( i = 0; i < charInfoNum; i++ ) { + if (wkcip->exists == FALSE) { + charNum-- ; + wkcip++; + continue; + } + glyphstotal += (wkcip->metrics.ascent + + wkcip->metrics.descent) * glyphPad; + wkcip++; + } + } + + fpropPtr = (FontPropRec *)(glyphPtr + glyphstotal); + fpropvnPtr = ((char *)fpropPtr) + (fip->nProps) * sizeof(FontPropRec); + + } + + + if ( isPcf ) { + setProp( pcf, &proptmp ); + } else { + fontname = (char *)0; + Anafprop( + fip, fpropPtr, fpropvnPtr, + &fontname, &psprop, &resprop, + &fplistPtr, &fplistNum + ); + } + + /* + *¡¡output to BDF information + */ + bufp = buf; + memcpy(bufp,"STARTFONT 2.1\n",14); + bufp += 14; + memcpy(bufp,"COMMENT\n",8); + bufp += 8; + memcpy(bufp,"COMMENT This BDF was created by dtgpftobdf.\n",45 ); + bufp += 45 ; + memcpy(bufp,"COMMENT\n",8); + bufp += 8; + time(&clock); + tm = localtime(&clock); + + snprintf( tmbuf, sizeof(tmbuf), "%s", asctime(tm) ) ; + + k = sprintf(bufp,"COMMENT Created date : %s\n",tmbuf ); + bufp += k-1; + memcpy(bufp,"COMMENT\n",8); + bufp += 8; + + if ( isPcf ) { + k = sprintf(bufp,"FONT %s\n",proptmp.font_name); + bufp += k; + *bufp = '\0'; + fprintf( stdout,"%s",buf ); + pSIZE_pcf( &proptmp ); + fprintf( stdout,"FONTBOUNDINGBOX %d %d %d %d\n", + pcf->info.maxbounds.metrics.rightSideBearing + - pcf->info.maxbounds.metrics.leftSideBearing, + pcf->info.maxbounds.metrics.ascent + + pcf->info.maxbounds.metrics.descent, + pcf->info.maxbounds.metrics.leftSideBearing, + - ( pcf->info.maxbounds.metrics.descent ) + ); + pPROPS_pcf( pcf ); + if ( outLevel == FALSE ) { + pCHARS_pcf( pcf, fix ); + } + } else { + k = sprintf( bufp,"FONT %s\n",fontname ); + bufp += k; + *bufp = '\0'; + fprintf( stdout,"%s",buf ); + pSIZE( &psprop, &resprop ); + fprintf( stdout,"FONTBOUNDINGBOX %d %d %d %d\n", + cip->metrics.rightSideBearing + - cip->metrics.leftSideBearing, + cip->metrics.ascent + cip->metrics.descent, + cip->metrics.leftSideBearing, + -(cip->metrics.descent) + ); + pPROPS( fip,fplistPtr,fplistNum ); + if ( outLevel == FALSE ) { + if ( fix == TRUE ) { + pfixCHARS( fip,cip,glyphPtr,charNum, glyphPad ); + } else { + pCHARS(fip,cip,glyphPtr,charNum,glyphPad); + } + } + + } + + fprintf( stdout,"ENDFONT\n" ); + exit( 0 ); +} + +/* + * read to font file + * + */ +static char *readfontfile( fname ) +char *fname; +{ + int fd; + char *fp = NULL; + struct stat stat; + + fd = open( fname,O_RDONLY ); + if ( fd < 0 ) { + USAGE("dtgpftobdf: can't open file.\n" ); + return ( char * )-1; + } +#if defined( SVR4 ) + if ( fstat( fd,&stat ) == 0 ) { + fp = (char *)mmap( 0, stat.st_size, PROT_READ, MAP_SHARED, fd, 0 ); + if ( fp == (char *)-1 ) { + if ( ( fp = ( char * )malloc( stat.st_size ) ) == NULL ) { + USAGE("dtgpftobdf: malloc error.\n" ); + close( fd ); + return ( char * )-1; + } +/* if ( read( fd, fp, stat.st_size ) < 0 ) {*/ + if ( read( fd, fp, stat.st_size ) != stat.st_size ) { + USAGE("dtgpftobdf: can't read file.\n" ); + close( fd ); + return ( char * )-1; + } + } + } else { + USAGE("dtgpftobdf: can't read file\n" ); + close( fd ); + return ( char * )-1; + } + close( fd ); +#else /* pfa */ + if ( fstat(fd,&stat) == 0 ) { + if ( ( fp = (char *)malloc(stat.st_size) ) == NULL ) { + USAGE("dtgpftobdf: malloc error.\n" ); + close( fd ); + return ( char * )-1; + } + if ( read( fd, fp, stat.st_size ) < 0 ) { + USAGE("dtgpftobdf: can't read file.\n" ); + close( fd ); + free(fp); + return ( char * )-1; + } + } else { + USAGE("dtgpftobdf: can't read file\n" ); + close( fd ); + return ( char * )-1; + } + close( fd ); +#endif /* pfa */ + return fp; +} + + +#define getINT8( p ) ( *p++ ) ; + +static CARD32 +getLSB32( p ) +unsigned char *p; +{ + CARD32 c; + + c = *p++; + c |= (CARD32)(*p++) << 8; + c |= (CARD32)(*p++) << 16; + c |= (CARD32)(*p) << 24; + + return c; +} + + +static int +getINT32( p, format ) +unsigned char *p; +CARD32 format; +{ + CARD32 c; + + if ( PCF_BYTE_ORDER(format) == MSBFirst ) { + c = (CARD32)(*p++) << 24; + c |= (CARD32)(*p++) << 16; + c |= (CARD32)(*p++) << 8; + c |= (CARD32)(*p); + } else { + c = (CARD32)(*p++); + c |= (CARD32)(*p++) << 8; + c |= (CARD32)(*p++) << 16; + c |= (CARD32)(*p) << 24; + } + + return ( int )c; +} + +static int +getINT16( p, format ) +unsigned char *p; +CARD32 format; +{ + CARD32 c; + + if ( PCF_BYTE_ORDER(format) == MSBFirst ) { + c = (CARD32)(*p++) << 8; + c |= (CARD32)(*p); + } else { + c = (CARD32)(*p++); + c |= (CARD32)(*p) << 8; + } + + return ( int )c; +} + +static Bool +seekToType( tables, ntables, type, formatp, sizep, offsetp) +PCFTablePtr tables; +int ntables; +CARD32 type; +CARD32 *formatp; +CARD32 *sizep; +CARD32 *offsetp; +{ + int i; + + for ( i = 0; i < ntables; i++ ) { + if ( getLSB32( (unsigned char *)&tables[i].type) == type) { + *formatp = getLSB32( (unsigned char *)&tables[i].format); + *sizep = getLSB32( (unsigned char *)&tables[i].size); + *offsetp = getLSB32( (unsigned char *)&tables[i].offset); + return TRUE; + } + } + return FALSE; +} + + +static void +getMetric( buf, format, metric ) +caddr_t buf; +CARD32 format; +xCharInfo *metric; +{ + metric->leftSideBearing = getINT16( (unsigned char *)buf, format); + buf += 2; + metric->rightSideBearing = getINT16( (unsigned char *)buf, format); + buf += 2; + metric->characterWidth = getINT16( (unsigned char *)buf, format); + buf += 2; + metric->ascent = getINT16( (unsigned char *)buf, format); + buf += 2; + metric->descent = getINT16( (unsigned char *)buf, format); + buf += 2; + metric->attributes = getINT16( (unsigned char *)buf, format); + buf += 2; +} + +static Bool +getAccel( pFontInfo, maxink, buf_top, tables, ntables, type ) +FontInfoPtr pFontInfo; +xCharInfo *maxink; +caddr_t buf_top; +PCFTablePtr tables; +int ntables; +CARD32 type; +{ + CARD32 format; + CARD32 size; + CARD32 offset; + caddr_t buffer; + + if ( !seekToType( tables, ntables, type, &format, &size, &offset)) { + return FALSE; + } + + buffer = buf_top + offset; + format = getLSB32( (unsigned char *)buffer); + buffer += 4; + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) + && !PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) + ) { + return FALSE; + } + pFontInfo->noOverlap = *buffer++; + pFontInfo->constantMetrics = *buffer++; + pFontInfo->terminalFont = *buffer++; + pFontInfo->constantWidth = *buffer++; + pFontInfo->inkInside = *buffer++; + pFontInfo->inkMetrics = *buffer++; + pFontInfo->drawDirection = *buffer++; + /* natural alignment */ + + buffer++; + + pFontInfo->fontAscent = getINT32( (unsigned char *)buffer, format); + buffer += 4; + + pFontInfo->fontDescent = getINT32((unsigned char *)buffer, format); + buffer +=4; + + buffer += 4; + + getMetric(buffer, format, &pFontInfo->minbounds.metrics); + buffer += 12; + + getMetric(buffer, format, &pFontInfo->maxbounds.metrics); + buffer += 12; + + if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ) { + buffer += 12; + getMetric( buffer, format, maxink); + } else { + *maxink = pFontInfo->maxbounds.metrics; + } + + return TRUE; +} + +static Bool +getProperties( pcf, buf_top, tables, ntables) +PcfTmp *pcf; +caddr_t buf_top; +PCFTablePtr tables; +int ntables; +{ + CARD32 format; + CARD32 size; + CARD32 offset; + caddr_t buffer; + int i; + + if ( !seekToType( tables, ntables, (CARD32)PCF_PROPERTIES, &format, &size, &offset ) ) { + return FALSE; + } + + buffer = buf_top + offset; + format = getLSB32( (unsigned char *)buffer ); + buffer += 4; + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { + return FALSE; + } + pcf->nprops = getINT32((unsigned char *)buffer, format); + buffer += 4; + + if ( !( pcf->props = ( FontPropPtr )malloc( pcf->nprops * sizeof( FontPropRec ) ) ) ) { + return FALSE; + } + + if ( !( pcf->isStringProp = ( char * )malloc(pcf->nprops * sizeof( char ) ) ) ) { + return FALSE; + } + + for ( i = 0; i < pcf->nprops; i++ ) { + pcf->props[i].name = getINT32((unsigned char *)buffer, format); + buffer += 4; + pcf->isStringProp[i] = *buffer++; + pcf->props[i].value = getINT32((unsigned char *)buffer, format); + buffer += 4; + } + if ( pcf->nprops & 3 ) { + i = 4 - (pcf->nprops & 3); + buffer += i; + } + + pcf->str_length = getINT32((unsigned char *)buffer, format); + buffer += 4; + + pcf->string = (char *)buffer; + return TRUE; +} + + +static PcfTmp * +openPcfFont( fontname ) +char *fontname; +{ + PcfTmp *pcf_tmp; + + CARD32 format; + CARD32 size; + CARD32 offset; + CARD32 *bitmapSizes; + xCharInfo maxink; + caddr_t buffp; + struct stat st; + + pcf_tmp = ( PcfTmp * )calloc( 1, sizeof( PcfTmp ) ); + if ( !pcf_tmp ) { + USAGE("dtgpftobdf : calloc() error.\n" ) ; + goto Bail; + } + + if ( stat( fontname, &st ) ) { + goto Bail; + } + + if ( ( pcf_tmp->pcf_buffer = readfontfile( fontname)) == (char *)-1 ) { + goto Bail; + } + + pcf_tmp->pcf_bufsz = st.st_size; + + if ( (format = getLSB32( (unsigned char *)pcf_tmp->pcf_buffer )) != PCF_FILE_VERSION ) { + USAGE1("dtgpftobdf : pcf file version(0x%x) error.\n", format ) ; + goto Bail; + } + + pcf_tmp->ntables = getLSB32( (unsigned char *)(pcf_tmp->pcf_buffer + 4) ); + pcf_tmp->tables = (PCFTablePtr)(pcf_tmp->pcf_buffer + 8 ); + + if ( !getAccel( + &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer, + pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_BDF_ACCELERATORS + ) + ) { + if ( !getAccel( + &pcf_tmp->info, &maxink, pcf_tmp->pcf_buffer, + pcf_tmp->tables, pcf_tmp->ntables, (CARD32)PCF_ACCELERATORS + ) + ) { + USAGE("dtgpftobdf : Cannot get accelerators.\n" ) ; + goto Bail; + } + } + + if ( !getProperties( + pcf_tmp, pcf_tmp->pcf_buffer, + pcf_tmp->tables, pcf_tmp->ntables + ) + ) { + USAGE("dtgpftobdf : getProperties error.\n" ) ; + goto Bail; + } + if ( !seekToType( + pcf_tmp->tables, pcf_tmp->ntables, + (CARD32)PCF_BITMAPS, &format, &size, &offset + ) + ) { + USAGE("dtgpftobdf : PCF_BITMAPS error.\n" ) ; + goto Bail; + } + + buffp = pcf_tmp->pcf_buffer + offset; + + format = getLSB32( (unsigned char *)buffp); + buffp += 4; + + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { + USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BITMAPS)\n" ) ; + goto Bail; + } + + pcf_tmp->nbitmaps = getINT32( (unsigned char *)buffp, format); + buffp += 4; + pcf_tmp->offsets = (CARD32 *)buffp; + buffp += sizeof( *pcf_tmp->offsets) * pcf_tmp->nbitmaps; + + + bitmapSizes = (CARD32 *)buffp; + pcf_tmp->sizebitmaps + = getINT32( (unsigned char *)&bitmapSizes[PCF_GLYPH_PAD_INDEX(format)], format); + pcf_tmp->bmp_fmt = format; + buffp += sizeof( *bitmapSizes) * GLYPHPADOPTIONS; + pcf_tmp->bitmaps = buffp; + buffp += pcf_tmp->sizebitmaps; + + if ( !seekToType( + pcf_tmp->tables, pcf_tmp->ntables, + (CARD32)PCF_BDF_ENCODINGS, &format, &size, &offset + ) + ) { + USAGE("dtgpftobdf : error.(PCF_BDF_ENCODINGS)\n" ) ; + goto Bail; + } + + buffp = pcf_tmp->pcf_buffer + offset; + format = getLSB32( (unsigned char *)buffp); + buffp += 4; + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { + USAGE("dtgpftobdf : error.!PCF_FORMAT_MATCH(PCF_BDF_ENCODINGS)\n" ) ; + goto Bail; + } + + pcf_tmp->info.firstCol = getINT16( (unsigned char *)buffp, format); + buffp += 2; + pcf_tmp->info.lastCol = getINT16( (unsigned char *)buffp, format); + buffp += 2; + pcf_tmp->info.firstRow = getINT16( (unsigned char *)buffp, format); + buffp += 2; + pcf_tmp->info.lastRow = getINT16( (unsigned char *)buffp, format); + buffp += 2; + pcf_tmp->info.chDefault = getINT16( (unsigned char *)buffp, format); + buffp += 2; + + pcf_tmp->info.allExist = FALSE; + pcf_tmp->enc_fmt = format; + pcf_tmp->encodingOffsets = (CARD16 *)buffp; + + /* + * get scale width infomations + */ + if ( !seekToType( + pcf_tmp->tables, pcf_tmp->ntables, + (CARD32)PCF_SWIDTHS, &format, &size, &offset + ) + ) { + goto Bail; + } + + buffp = pcf_tmp->pcf_buffer + offset; + format = getLSB32( (unsigned char*)buffp); + buffp += 4; + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { + goto Bail; + } + pcf_tmp->swd_fmt = (CARD32)format ; + pcf_tmp->swd_num = getINT32( (unsigned char*)buffp, format ) ; + buffp += 4; + + pcf_tmp->swidth = (CARD32 *)buffp ; + + /* + * get glyph names + */ + if ( !seekToType( + pcf_tmp->tables, pcf_tmp->ntables, + (CARD32)PCF_GLYPH_NAMES, &format, &size, &offset + ) + ) { + goto Bail; + } + + buffp = pcf_tmp->pcf_buffer + offset; + format = getLSB32( (unsigned char*)buffp); + buffp += 4; + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { + goto Bail; + } + pcf_tmp->glyphs = getINT32( (unsigned char*)buffp, format ) ; + buffp += 4; + pcf_tmp->glyph_offset = (int *)buffp ; + buffp += 4 * (pcf_tmp->glyphs + 1) ; + pcf_tmp->glyph_name = (char *)buffp ; + pcf_tmp->glyph_fmt = (CARD32)format ; + + /* + * get metrics + */ + if ( !seekToType( + pcf_tmp->tables, pcf_tmp->ntables, + (CARD32)PCF_METRICS, &format, &size, &offset + ) + ) { + goto Bail; + } + + buffp = pcf_tmp->pcf_buffer + offset; + format = getLSB32( (unsigned char*)buffp); + buffp += 4; + if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) { + pcf_tmp->compress = 0 ; + pcf_tmp->mtr_num = getINT32( (unsigned char*)buffp, format ) ; + buffp += 4; + }else if ( PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ) { + pcf_tmp->compress = 1 ; + pcf_tmp->mtr_num = (int)getINT16( (unsigned char*)buffp, format ) ; + buffp += 2; + }else{ + goto Bail; + } + pcf_tmp->metrics = (xCharInfo *)buffp ; + pcf_tmp->mtr_fmt = (CARD32)format ; + + return pcf_tmp; + +Bail: + if ( pcf_tmp ) { + free( pcf_tmp ); + } + return NULL; +} + + +static void +Anafprop(fip,fpropPtr,fpropvnPtr,fontname,ps,res,fplistPtr,fplistNum) +FontInfoRec *fip; +FontPropRec *fpropPtr; +char *fpropvnPtr; +char **fontname; +FontPropRec **fplistPtr; +FontPropRec *ps; +FontPropRec *res; +unsigned int *fplistNum; +{ + FontPropRec *wkp ,*wklp; + int i, fpnL; + char *fpnp; + + *fplistNum = fip->nProps - 1; + *fplistPtr = (FontPropRec *)malloc(*fplistNum * sizeof(FontPropRec)); + wkp = fpropPtr; + wklp = *fplistPtr; + for (i = 0; i < fip->nProps; i++) { + fpnp = fpropvnPtr + wkp->name; + fpnL = strlen(fpnp); + if ((fpnL == 4) && (strncmp(fpnp,"FONT",4) == 0)) { + *fontname = fpropvnPtr + wkp->value; + wkp++; + continue; + } + if (fpnL == 10) { + if (strncmp(fpnp,"POINT_SIZE",10) == 0) { + ps->value = wkp->value; + } + if (strncmp(fpnp,"RESOLUTION",10) == 0) { + res->value = wkp->value; + } + } + wklp->name = (CARD32) (intptr_t) fpropvnPtr + wkp->name; + if (wkp->indirect == TRUE) { + wklp->value = (INT32) (intptr_t) fpropvnPtr + wkp->value; + } else { + wklp->value = wkp->value; + } + wklp->indirect = wkp->indirect; + wkp++; + wklp++; + } +} + + + +static void +setProp( pcf, proptmp ) +PcfTmp *pcf; +PropTmp *proptmp; +{ + int i, fpnL; + char *fpnp; + + for ( i = 0; i < pcf->nprops; i++ ) { + fpnp = pcf->string + pcf->props[i].name; + fpnL = strlen(fpnp); + if ( ( fpnL == 4 ) && ( strncmp( fpnp,"FONT", 4 ) == 0 ) ) { + proptmp->font_name = pcf->string + pcf->props[i].value; + continue; + } + if ( fpnL == 10 ) { + if ( strncmp( fpnp,"POINT_SIZE", 10 ) == 0 ) { + proptmp->psize.value = pcf->props[i].value; + } else if ( strncmp( fpnp, "RESOLUTION", 10 ) == 0 ) { + proptmp->resolution.value = pcf->props[i].value; + } + } + } +} + + + +/* + * output to SIZE (SIZE point resolutionX resolutionY) + * + */ +static void +pSIZE( ps, res ) +FontPropRec *ps, *res; +{ + int k; + float f; + char buf1[16], buf2[16]; + + f = ps->value / 10.0; + if ( ( ps->value % 10 ) != 0 ) { + sprintf( buf1, "%.1f", f ); + } else { + sprintf( buf1, "%.0f", f ); + } + k = ( ( res->value * 72.27 ) / 100.0 ) + 1; + sprintf( buf2, "%d %d", k, k ); + fprintf( stdout, "SIZE %s %s\n", buf1, buf2 ); + return; +} + + +/* output to SIZE of pcf font */ + +static void +pSIZE_pcf( proptmp ) +PropTmp *proptmp; +{ + int k; + float f; + char buf1[16],buf2[16]; + + f = proptmp->psize.value / 10.0; + if ( ( proptmp->psize.value % 10 ) != 0 ) { + snprintf( buf1, sizeof(buf1), "%.1f",f ); + } else { + snprintf( buf1, sizeof(buf1), "%.0f",f); + } + k = ( ( proptmp->resolution.value * 72.27 ) / 100.0 ) + 1; + snprintf( buf2, sizeof(buf2), "%d %d", k, k ); + fprintf( stdout,"SIZE %s %s\n", buf1, buf2 ); + return; +} + + + +static void +pPROPS( fip,fplistPtr,fplistNum ) +FontInfoRec *fip; +FontPropRec *fplistPtr; +unsigned int fplistNum; +{ + FontPropRec *wkp; + int i, k; + + bufp = buf; + k = snprintf( bufp, sizeof(buf), "STARTPROPERTIES %d\n", fplistNum+3 ); + bufp += k; + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_ASCENT %d\n", fip->fontAscent ); + bufp += k; + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "FONT_DESCENT %d\n", fip->fontDescent ); + bufp += k; + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "DEFAULT_CHAR %d\n", fip->chDefault ); + bufp += k; + wkp = fplistPtr; + for ( i = 0; i < fplistNum; i++ ) { + if ( wkp->indirect == TRUE ) { + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s \"%s\"\n", (char *) (intptr_t) wkp->name, (char *) (intptr_t) wkp->value ); + bufp += k; + } else { + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "%s %d\n", (char *) (intptr_t) wkp->name, wkp->value ); + bufp += k; + } + wkp++; + } + k = snprintf( bufp, sizeof(buf) - (bufp - buf), "ENDPROPERTIES\n" ); + bufp += k; + *bufp = '\0'; + fprintf( stdout, "%s", buf ); + return; + +} + + +/* output to font property information of pcf fontpcf */ +static void +pPROPS_pcf( pcf ) +PcfTmp *pcf; +{ + FontPropPtr wkp; + int i, k; + + bufp = buf; + k = sprintf( bufp, "STARTPROPERTIES %d\n", pcf->nprops+3 ); + bufp += k; + k = sprintf( bufp, "FONT_ASCENT %d\n", + (pcf->info.fontAscent >= pcf->info.maxbounds.metrics.ascent) + ? pcf->info.fontAscent : pcf->info.maxbounds.metrics.ascent + ); + bufp += k; + k = sprintf( bufp, "FONT_DESCENT %d\n", + (pcf->info.fontDescent >= pcf->info.maxbounds.metrics.descent) + ? pcf->info.fontDescent : pcf->info.maxbounds.metrics.descent + ); + bufp += k; + k = sprintf( bufp, "DEFAULT_CHAR %d\n", pcf->info.chDefault ); + bufp += k; + wkp = pcf->props; + for ( i = 0; i < pcf->nprops; i++ ) { + if ( pcf->isStringProp[i] ) { + k = sprintf(bufp,"%s \"%s\"\n", + pcf->string + wkp->name, pcf->string + wkp->value + ); + bufp += k; + } else { + k = sprintf(bufp,"%s %d\n", + pcf->string + wkp->name, wkp->value + ); + bufp += k; + } + wkp++; + } + k = sprintf( bufp, "ENDPROPERTIES\n" ); + bufp += k; + *bufp = '\0'; + fprintf( stdout,"%s",buf ); + return; + +} + + + +/* + * output to character information and patern + * + */ +static void +pCHARS(fip,cip,glyphPtr,charNum,glyphPad) +FontInfoRec *fip; +CharInfoRec *cip; +char *glyphPtr; +unsigned int charNum; +unsigned int glyphPad; + +{ + CharInfoRec *wkp; + int i, j; + unsigned int frow, lrow, row, fcol, lcol, col; + unsigned int bbw, bbh; + unsigned int bml; + char *glyph; + + fprintf( stdout, "CHARS %d\n", charNum ); + + frow = fip->firstRow; + lrow = fip->lastRow; + fcol = fip->firstCol; + lcol = fip->lastCol; + wkp = cip; + glyph = glyphPtr; + row = frow; + + for ( i = 0; i < 256; i++ ) { + cvtp[i] = &cvt[i]; + } + + for ( row = frow; row <= lrow; row++ ) { + for ( col = fcol; col <= lcol; col++ ) { + if ( wkp->exists == FALSE ) { + wkp++; + continue; + } + fprintf( stdout, "STARTCHAR %.2x%.2x\n", row,col ); + fprintf( stdout, "ENCODING %d\n", (row << 8) + col ); + fprintf( stdout, "SWIDTH 256 0\nDWIDTH %d %d\n", + wkp->metrics.characterWidth,0 ); + bbw = wkp->metrics.rightSideBearing + - wkp->metrics.leftSideBearing; + bbh = wkp->metrics.ascent + wkp->metrics.descent; + fprintf( stdout, "BBX %d %d %d %d\nBITMAP\n", bbw, bbh, + wkp->metrics.leftSideBearing, + - ( wkp->metrics.descent )); + bml = (bbw + 7) / 8; + for ( i = 0; i < bbh; i++ ) { + bufp = buf; + for ( j = 0; j < bml; j++ ) { + sprintf( bufp, "%s", (char *) cvtp[(unsigned char)glyph[j]] ); + bufp += 2; + } + fprintf( stdout, "%.*s\n", bml*2, buf ); + glyph += glyphPad; + } + fprintf( stdout,"ENDCHAR\n" ); + wkp++; + } + } + return; +} + + +/* + * output to character information and patern + * + */ +static void +pfixCHARS(fip,cip,glyphPtr,charNum,glyphPad) +FontInfoRec *fip; +CharInfoRec *cip; +char *glyphPtr; +unsigned int charNum; +unsigned int glyphPad; +{ + CharInfoRec *wkp; + register int i, j, k; + unsigned int frow,lrow,fcol,lcol; + register int row, col; + unsigned int bbw, bbh, bbox, bboy; + unsigned int xd, yd; + unsigned int bml; + register char *glyph; + char fixbuf[240], *fixbufp; + int fixdl; + + fprintf( stdout,"CHARS %d\n",charNum ); + + for ( i = 0; i < 256; i++ ) { + cvtp[i] = &cvt[i]; + } + + frow = fip->firstRow; + lrow = fip->lastRow; + fcol = fip->firstCol; + lcol = fip->lastCol; + xd = cip->metrics.characterWidth; + yd = 0; + bbw = cip->metrics.rightSideBearing - cip->metrics.leftSideBearing; + bbh = cip->metrics.ascent + cip->metrics.descent; + bbox = cip->metrics.leftSideBearing; + bboy = -(cip->metrics.descent); + + fixbufp = fixbuf; + fixdl = sprintf( fixbufp, "SWIDTH 256 0\nDWIDTH %d %d\n", xd, yd ); + fixbufp += fixdl; + k = sprintf(fixbufp,"BBX %d %d %d %d\nBITMAP\n", + bbw, bbh, bbox, bboy + ); + fixdl += k; + + bml = (bbw + 7) / 8; + wkp = cip; + glyph = glyphPtr; + for ( row = frow; row <= lrow; row++ ) { + for ( col = fcol; col <= lcol; col++ ) { + if ( wkp->exists == FALSE ) { + wkp++; + continue; + } + bufp = buf; + memcpy(bufp,"STARTCHAR ",10); + bufp += 10; + memcpy(bufp,cvtp[row],2); + bufp += 2; + memcpy(bufp,cvtp[col],3); + bufp += 3; + memcpy(bufp,"ENCODING ",9); + bufp += 9; + k = sprintf(bufp,"%d\n",(row << 8) + col); + bufp += k; + memcpy(bufp,fixbuf,fixdl); + bufp += fixdl; + for (i = 0; i < bbh; i++) { + for (j = 0; j < bml; j++) { + memcpy(bufp, cvtp[(unsigned char)glyph[j]],3); + bufp += 2; + } + bufp ++; + glyph += glyphPad; + } + memcpy( bufp, "ENDCHAR\n", 8 ); + bufp += 8; + *bufp = '\0'; + fprintf( stdout, "%s", buf ); + wkp++; + } + } + return; +} + + +static void +putPtn( bits, width, height) +unsigned char *bits; /* 1 byte boundary , no byte swap data */ +int width, height; +{ + int bytewidth; + int i, j; + + bytewidth = ( width + 7) / 8; + + for ( i = height; i-- > 0;) { + for ( j = bytewidth; j-- > 0; bits++) { + fprintf(stdout, "%.2x", *bits); + } + fprintf(stdout, "\n"); + } + +} + +static void +ByteSwap( p, scan) +char *p; +int scan; +{ + char w; + + switch( scan) { + case 1: + break; + case 2: + w = *p; + *p = *(p + 1); + *(p + 1) = w; + break; + case 4: + w = *p; + *p = *(p + 3); + *(p + 3) = w; + w = *(p + 1); + *(p + 1) = *(p + 2); + *(p + 2) = w; + break; + } +} + +static unsigned char _reverse_byte[0x100] = { + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff +}; + +static void +BitOrderInvert(buf, nbytes) +register unsigned char *buf; +register int nbytes; +{ + register unsigned char *rev = _reverse_byte; + + for (; --nbytes >= 0; buf++) + *buf = rev[*buf]; +} + +static void +invertBits( src, format, width, height, dest) +char *src; +CARD32 format; +int width, height; +char *dest; +{ + int bit, byte, glyph, scan; + int src_bytewidth, dest_bytewidth; + char work[8]; + int i, j; + + bit = PCF_BIT_ORDER( format); + byte = PCF_BYTE_ORDER( format); + glyph = PCF_GLYPH_PAD( format); + scan = PCF_SCAN_UNIT( format); + + src_bytewidth = (( width + ( 8 * glyph ) - 1)/( 8 * glyph)) * glyph; + dest_bytewidth = ( width + 7) /8; + + for ( i = 0; i < height; i++, src += src_bytewidth, + dest += dest_bytewidth) { + for ( j = 0; j < src_bytewidth; j += scan) { + memcpy( work, src + j, scan); + if ( bit == LSBFirst) + BitOrderInvert( (unsigned char *)work, scan); + if ( byte == LSBFirst) + ByteSwap( work, scan); + if (( j + scan) >= dest_bytewidth) { + memcpy( dest + j, work, dest_bytewidth - j); + break; + } + memcpy( dest + j, work, scan); + } + } + +} + +static void +pCHARS_pcf (pcf, fix) +PcfTmp *pcf; +int fix ; +{ + char *bmp_ptn = NULL; + char *bitmap = NULL; + int ptn_width = 0, ptn_height = 0; + int bmp_width = 0, bmp_height = 0; + int cpy_height = 0; + int row, col; + int row_width; + int encoding; + int encodingOffset; + int nencoding; + int bmp_adj = 0, ptn_adj = 0; + int adj_hi; + int width_bytes; + INT16 bl, br, ba, bd, bdw ; + unsigned char cl, cr, ca, cd, cdw ; + unsigned char *comp ; + int bbw, bbh, bbx, bby, dwidth ; + + fprintf(stdout,"CHARS %d\n",pcf->nbitmaps); + + row_width = pcf->info.lastCol - pcf->info.firstCol + 1; + nencoding = row_width * (pcf->info.lastRow - pcf->info.firstRow + 1); + + if( fix == TRUE ) { + bmp_width = pcf->info.maxbounds.metrics.leftSideBearing + + pcf->info.maxbounds.metrics.rightSideBearing ; + bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ; + ptn_width = bmp_width ; + ptn_height = pcf->info.maxbounds.metrics.ascent + + pcf->info.maxbounds.metrics.descent; + + if (!(bmp_ptn = make_toptn( ptn_width, ptn_height))) + return; + + if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.metrics.ascent ) > 0) { + width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt); + width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt); + bmp_adj = width_bytes * adj_hi; + ptn_adj = 0; + if (( cpy_height = bmp_height - adj_hi) > ptn_height) + cpy_height = ptn_height ; + } else if ( adj_hi < 0) { + adj_hi *= -1; + width_bytes = ( ptn_width + 7) / 8; + bmp_adj = 0; + ptn_adj = width_bytes * adj_hi; + if (( cpy_height = ptn_height - adj_hi) > bmp_height) + cpy_height = bmp_height ; + } else { + bmp_adj = 0; + ptn_adj = 0; + cpy_height = ptn_height ; + } + } + + + for ( encoding = 0; encoding < nencoding; encoding++) { + if(fix == TRUE) memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height); + encodingOffset = getINT16( (unsigned char *)(pcf->encodingOffsets + encoding), pcf->enc_fmt); + if (encodingOffset == 0xFFFF) continue; + + row = pcf->info.firstRow + encoding / row_width; + col = pcf->info.firstCol + encoding % row_width; + + fprintf(stdout,"STARTCHAR %s\n",pcf->glyph_name + + getINT32( (unsigned char*)&pcf->glyph_offset[encodingOffset], + pcf->glyph_fmt) ); + fprintf(stdout,"ENCODING %d\n",(row << 8) + col); + + fprintf( stdout,"SWIDTH %d 0\n", getINT32( (unsigned char*)(pcf->swidth + encodingOffset), pcf->swd_fmt) ); + + if( pcf->compress ){ + comp = (unsigned char*)pcf->metrics + + encodingOffset * SIZEOF_COMPRESSED_METRIC ; + cl = getINT8( comp ) ; + cr = getINT8( comp ) ; + cdw = getINT8( comp ) ; + ca = getINT8( comp ) ; + cd = getINT8( comp ) ; + + dwidth = (int)(cdw - 0x80) ; + bbw = (int)((cr - 0x80) - (cl - 0x80)) ; + bbh = (int)((ca - 0x80) + (cd - 0x80)) ; + bbx = (int)(cl - 0x80) ; + bby = (int)( -(cd - 0x80) ) ; + }else{ + bl = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].leftSideBearing, pcf->mtr_fmt ) ; + br = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].rightSideBearing, pcf->mtr_fmt ) ; + bdw = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].characterWidth, pcf->mtr_fmt ) ; + ba = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].ascent, pcf->mtr_fmt ) ; + bd = getINT16( (unsigned char *)&pcf->metrics[encodingOffset].descent, pcf->mtr_fmt ) ; + dwidth = bdw ; + bbw = br-bl ; + bbh = ba+bd ; + bbx = bl ; + bby = -bd ; + } + fprintf( stdout,"DWIDTH %d 0\n", dwidth ) ; + fprintf( stdout,"BBX %d %d %d %d\nBITMAP\n", bbw, bbh, bbx, bby ) ; + + if( fix == FALSE ) { + bmp_width = pcf->info.maxbounds.metrics.leftSideBearing + + pcf->info.maxbounds.metrics.rightSideBearing ; + bmp_height = pcf->info.fontAscent + pcf->info.fontDescent ; + ptn_width = bbw ; + ptn_height = bbh ; + + if (!(bmp_ptn = make_toptn( ptn_width, ptn_height))) + return; + + if ( ( adj_hi = pcf->info.fontAscent - pcf->info.maxbounds.metrics.ascent ) > 0) { + width_bytes = 8 * PCF_GLYPH_PAD( pcf->bmp_fmt); + width_bytes = (( width_bytes + bmp_width - 1)/width_bytes) * PCF_GLYPH_PAD( pcf->bmp_fmt); + bmp_adj = width_bytes * adj_hi; + ptn_adj = 0; + if (( cpy_height = bmp_height - adj_hi) > ptn_height) + cpy_height = ptn_height ; + } else if ( adj_hi < 0) { + adj_hi *= -1; + width_bytes = ( ptn_width + 7) / 8; + bmp_adj = 0; + ptn_adj = width_bytes * adj_hi; + if (( cpy_height = ptn_height - adj_hi) > bmp_height) + cpy_height = bmp_height ; + } else { + bmp_adj = 0; + ptn_adj = 0; + cpy_height = ptn_height ; + } + memset( bmp_ptn, '\0', (ptn_width + 7)/8 * ptn_height); + } + + bitmap = pcf->bitmaps + getINT32( (unsigned char *)(pcf->offsets + encodingOffset), + pcf->bmp_fmt); + /* Only do this if non-NULL... */ + if (bmp_ptn) + { + invertBits( bitmap + bmp_adj, pcf->bmp_fmt, + ptn_width, cpy_height, bmp_ptn + ptn_adj); + putPtn( (unsigned char *)bmp_ptn, ptn_width, ptn_height ); + } + else + { + fprintf(stderr, "%s: bmp_ptn is NULL", __FUNCTION__); + } + + fprintf(stdout,"ENDCHAR\n"); + if( fix == FALSE ) free(bmp_ptn); + } + if( fix == TRUE ) free(bmp_ptn); + return; +} + +static char * +make_toptn( width, height) +int width, height; +{ + int byte_width; + + byte_width = (width + 7)/8; + + return (char *)malloc( byte_width * height); +} + + + + +static int +getarg(argc,argv,fname,bitorder,byteorder,scanunit,glyphPad,outLevel,fix) +int argc; +char *argv[]; +char *fname; +int *bitorder; +int *byteorder; +int *scanunit; +int *glyphPad; +int *outLevel; +int *fix; +{ + int i; + int already; + char *arg; + char *usage="dtgpftobdf [-H] [-V] [-help] font_file_name"; + + *glyphPad = DEFAULTGLPAD; + *bitorder = DEFAULTBITORDER; + *scanunit = DEFAULTSCANUNIT; + *byteorder = DEFAULTBYTEORDER; + *outLevel = FALSE; + *fix = FALSE ; + already = 0 ; + + for (i = 1; i < argc; i++ ) { + arg = argv[i]; + if (*arg == '-') { + *arg++; + switch (*arg) { + case 'p' : + *glyphPad = atoi(arg+1) ; + if (*glyphPad != 1 && + *glyphPad != 2 && + *glyphPad != 4 && + *glyphPad != 8 ) { + USAGE("dtgpftobdf : illegal padding number (1/2/4/8)\n"); + return -1; + } + break; + case 'H' : + *outLevel = TRUE ; + break; + case 'h' : + USAGE1("usage: %s\n",usage); + return (-1); + case 'V' : + *fix = TRUE ; + break; + default : + USAGE1("dtgpftobdf : illegal option -- %s\n",arg); + USAGE1("usage: %s\n",usage); + return -1; + } + + } else { + if (already == FALSE) { + strcpy(fname,arg); + already = TRUE; + } else { + USAGE1("dtgpftobdf : extra parameter --- %s\n",arg); + USAGE1("usage: %s\n", usage ); + return -1; + } + } + } + if (already == FALSE) { + USAGE("dtgpftobdf : require file name\n"); + USAGE1("usage: %s\n",usage); + return -1; + } + return 0; +} diff --git a/cde/programs/dtudcfonted/dtgpftobdf/gtobdf.h b/cde/programs/dtudcfonted/dtgpftobdf/gtobdf.h new file mode 100644 index 00000000..22fe7eaf --- /dev/null +++ b/cde/programs/dtudcfonted/dtgpftobdf/gtobdf.h @@ -0,0 +1,84 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: gtobdf.h /main/3 1996/06/25 20:13:05 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +static +unsigned int + cvt[256]= +{0x30300a00,0x30310a00,0x30320a00,0x30330a00,0x30340a00,0x30350a00,0x30360a00, + 0x30370a00,0x30380a00,0x30390a00,0x30610a00,0x30620a00,0x30630a00,0x30640a00, + 0x30650a00,0x30660a00, + 0x31300a00,0x31310a00,0x31320a00,0x31330a00,0x31340a00,0x31350a00, + 0x31360a00,0x31370a00,0x31380a00,0x31390a00,0x31610a00,0x31620a00,0x31630a00, + 0x31640a00,0x31650a00,0x31660a00, + 0x32300a00,0x32310a00,0x32320a00,0x32330a00,0x32340a00,0x32350a00, + 0x32360a00,0x32370a00,0x32380a00,0x32390a00,0x32610a00,0x32620a00,0x32630a00, + 0x31640a00,0x32650a00,0x32660a00, + 0x33300a00,0x33310a00,0x33320a00,0x33330a00,0x33340a00,0x33350a00, + 0x33360a00,0x33370a00,0x33380a00,0x33390a00,0x33610a00,0x33620a00,0x33630a00, + 0x33640a00,0x33650a00,0x33660a00, + 0x34300a00,0x34310a00,0x34320a00,0x34330a00,0x34340a00,0x34350a00, + 0x34360a00,0x34370a00,0x34380a00,0x34390a00,0x34610a00,0x34620a00,0x34630a00, + 0x34640a00,0x34650a00,0x34660a00, + 0x35300a00,0x35310a00,0x35320a00,0x35330a00,0x35340a00,0x35350a00, + 0x35360a00,0x35370a00,0x35380a00,0x35390a00,0x35610a00,0x35620a00,0x35630a00, + 0x35640a00,0x35650a00,0x35660a00, + 0x36300a00,0x36310a00,0x36320a00,0x36330a00,0x36340a00,0x36350a00, + 0x36360a00,0x36370a00,0x36380a00,0x36390a00,0x36610a00,0x36620a00,0x36630a00, + 0x36640a00,0x36650a00,0x36660a00, + 0x37300a00,0x37310a00,0x37320a00,0x37330a00,0x37340a00,0x37350a00, + 0x37360a00,0x37370a00,0x37380a00,0x37390a00,0x37610a00,0x37620a00,0x37630a00, + 0x37640a00,0x37650a00,0x37660a00, + 0x38300a00,0x38310a00,0x38320a00,0x38330a00,0x38340a00,0x38350a00, + 0x38360a00,0x38370a00,0x38380a00,0x38390a00,0x38610a00,0x38620a00,0x38630a00, + 0x38640a00,0x38650a00,0x38660a00, + 0x39300a00,0x39310a00,0x39320a00,0x39330a00,0x39340a00,0x39350a00, + 0x39360a00,0x39370a00,0x39380a00,0x39390a00,0x39610a00,0x39620a00,0x39630a00, + 0x39640a00,0x39650a00,0x39660a00, + 0x61300a00,0x61310a00,0x61320a00,0x61330a00,0x61340a00,0x61350a00, + 0x61360a00,0x61370a00,0x61380a00,0x61390a00,0x61610a00,0x61620a00,0x61630a00, + 0x61640a00,0x61650a00,0x61660a00, + 0x62300a00,0x62310a00,0x62320a00,0x62330a00,0x62340a00,0x62350a00, + 0x62360a00,0x62370a00,0x62380a00,0x62390a00,0x62610a00,0x62620a00,0x62630a00, + 0x62640a00,0x62650a00,0x62660a00, + 0x63300a00,0x63310a00,0x63320a00,0x63330a00,0x63340a00,0x63350a00, + 0x63360a00,0x63370a00,0x63380a00,0x63390a00,0x63610a00,0x63620a00,0x63630a00, + 0x63640a00,0x63650a00,0x63660a00, + 0x64300a00,0x64310a00,0x64320a00,0x64330a00,0x64340a00,0x64350a00, + 0x64360a00,0x64370a00,0x64380a00,0x64390a00,0x64610a00,0x64620a00,0x64630a00, + 0x64640a00,0x64650a00,0x64660a00, + 0x65300a00,0x65310a00,0x65320a00,0x65330a00,0x65340a00,0x65350a00, + 0x65360a00,0x65370a00,0x65380a00,0x65390a00,0x65610a00,0x65620a00,0x65630a00, + 0x65640a00,0x65650a00,0x65660a00, + 0x66300a00,0x66310a00,0x66320a00,0x66330a00,0x66340a00,0x66350a00, + 0x66360a00,0x66370a00,0x66380a00,0x66390a00,0x66610a00,0x66620a00,0x66630a00, + 0x66640a00,0x66650a00,0x66660a00 }; +static +unsigned int *cvtp[256]; diff --git a/cde/programs/dtudcfonted/dtgpftocpf/Imakefile b/cde/programs/dtudcfonted/dtgpftocpf/Imakefile new file mode 100644 index 00000000..ef509928 --- /dev/null +++ b/cde/programs/dtudcfonted/dtgpftocpf/Imakefile @@ -0,0 +1,26 @@ +XCOMM $XConsortium: Imakefile /main/6 1996/09/09 11:19:51 drk $ + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) + + INCLUDES = -I../include -I../libfal/include + + DEPLIBS = ../libfuty/liboakfuty.a ../libfal/libfal.a $(DEPXLIB) +LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) + SYS_LIBRARIES = -lc + + SRCS = gpftocpf.c + + OBJS = gpftocpf.o + +ComplexProgramTarget(dtgpftocpf) diff --git a/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c b/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c new file mode 100644 index 00000000..218d0168 --- /dev/null +++ b/cde/programs/dtudcfonted/dtgpftocpf/gpftocpf.c @@ -0,0 +1,672 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: gpftocpf.c /main/6 1996/11/08 02:05:11 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include +#include +#include +#include +#include +#ifndef SVR4 +#if !defined ( SYSV ) +#include +#endif +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include "bdfgpf.h" + +#include +#include +#include "snfstruct.h" +#include "FaLib.h" +#include "udcutil.h" + +#define START_CODE 0 +#define END_CODE 1 + +static int CnvBDFtoGPF() ; +static int check_width() ; +static int check_height() ; +static int check_width_height() ; +static int check_code() ; +static int readBdfToMemory() ; +static void sigint_out() ; +static void put_error_and_exit(); +static void put_help(); +static void Usage(); + +extern int fal_code_to_glyph() ; + +static struct btophead Head; +static char *locale ; +static char *spacing ; +static char *char_set ; + + +static void +sigint_out() +{ + if ( Head.out_file ) { + unlink( Head.out_file ); + } + exit( 0 ); +} + +main( argc, argv ) +int argc; +char *argv[]; +{ + int help, code_area, fd[2], rtn, i; + struct stat st; + char snf_file[BUFSIZE]; + char *style ; + int code_no ; + int num_gr ; + FalGlyphRegion *gr ; + char *xlfdname, *cbuf, *ep ; + char *codeset = DEFAULT_CODESET ; + char *start_code, *end_code ; + + /* format */ + if( (locale = (char *)getenv( "LANG" )) == NULL ){ + locale = "C" ; + } + + Head.in_file = Head.out_file = Head.text_file = NULL; + Head.p_width = Head.p_height = USE_ORG_SIZE; + + Head.code_category = ALL_CODE ; + Head.start_code = MIN_CODE; + Head.end_code = MAX_CODE; + help = code_area = 0; + COMM_SETDEFAULTSTYLE( style ) ; + xlfdname = cbuf = start_code = end_code = ep = '\0' ; + spacing = char_set = NULL ; + gr = '\0' ; + num_gr = 0 ; + + if ( ! ( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ) ) ) { + oakgtobdf = SNFTOBDF; + } + /* + * check options + */ + for ( i = 1; i < argc; i++ ) { + if ( !strcmp(argv[i], "-help" ) ) { + help = 1; + } else if ( !strcmp(argv[i], "-system" ) ) { + code_area |= SYSTM; + } else if ( !strcmp( argv[i], "-codeset" ) ) { + if ( + ( (i+1) < argc ) && + ( strlen( argv[i+1] ) == 1 ) + ) { + if ( *argv[i+1] == '1' ) code_area |= CDSET1; + codeset = argv[++i] ; + } else { + put_help( argv[0] ); + exit( 1 ); + } + } else if ( COMM_SBOPT_STRCMP( argv, i ) ) { + COMM_SBOPT_SETSBOPT( code_area ) ; + } else { + continue ; + } + } + + if ( help ) { + put_help( argv[0] ); + exit( 0 ); + } + + ep = (char *)strchr( codeset, '\0' ) ; + code_no = (int)strtol( codeset, &cbuf, 10 ) ; + if( cbuf == codeset || cbuf != ep ) { + USAGE1("%s : The code set number is not right.\n", argv[0] ) ; + exit(1) ; + } + + COMM_SBOPT_CHECKSBOPT( argv[0], code_area ) ; + + /* + * get parameters + */ + for (i=1; i Head.end_code ) { + USAGE1("%s : The specification of extract start/end code is improper.\n", argv[0]); + exit( 1 ); + } + + COMM_SBFNT_CONVCODETOGI( char_set, Head ) ; + + /* open to output file */ + if ( Head.out_file == NULL ) { + Head.output = stdout; + } else { + if ( stat(Head.out_file, &st) != 0 ) { + if ((Head.output = fopen(Head.out_file, "w")) == NULL) { + put_error_and_exit( &Head, GPF_OPEN_OUT, argv[0] ); + } + } else { + Head.text_file = Head.out_file; + if ( ( Head.out_file = GetTmpPath( Head.out_file ) ) == NULL ) { + put_error_and_exit( &Head, MKTMP_ERROR, argv[0] ); + } + if ( ( Head.output = fopen( Head.out_file, "w" ) ) == NULL ) { + put_error_and_exit( &Head, GPF_OPEN_OUT, argv[0] ); + } + } + } + + if ( pipe( fd ) != 0 ) { + put_error_and_exit( &Head, PIPE_ERROR, argv[0] ); + } + + switch( fork() ) { + case 0: + close( fd[0] ); + close( 1 ); + if ( dup( fd[1] ) < 0 ) { + put_error_and_exit( &Head, DUP_ERROR, argv[0] ); + } + close( fd[1] ); + execl( oakgtobdf, oakgtobdf, Head.in_file, 0 ); + put_error_and_exit( &Head, EXEC_ERROR, argv[0] ); + + case -1: + /* fork fail */ + put_error_and_exit( &Head, FORK_ERROR, argv[0] ); + + default: + close( fd[1] ); + Head.input = fdopen( fd[0], "r" ); + } + + if ( rtn = CnvBDFtoGPF( &Head, num_gr, gr, code_area ) ) { + wait( 0 ); + fclose( Head.input ); + if ( Head.out_file ) { + unlink( Head.out_file ); + } + put_error_and_exit( &Head, rtn, argv[0] ); + } + wait(0); + fclose( Head.input ); + signal( SIGHUP, SIG_IGN ); + signal( SIGINT, SIG_IGN ); + signal( SIGQUIT, SIG_IGN ); + signal( SIGTERM, SIG_IGN ); + if ( Head.text_file ) { + fclose( Head.output ); + Link_NewFile( Head.out_file, Head.text_file ); + unlink( Head.out_file ); + } + exit( 0 ); +} + + +static int +CnvBDFtoGPF( head, num_gr, gr, code_area ) +struct btophead *head; +int num_gr ; +FalGlyphRegion *gr ; +int code_area ; +{ + int rtn; + char bdfbuf[BUFSIZE]; + + /* readto BDF head information */ + if ((rtn = ReadBdfHeader(head, bdfbuf))) { + return(rtn); + } + + if (head->p_width == USE_ORG_SIZE) { + head->p_width = head->bdf_width; + } + if (head->p_height == USE_ORG_SIZE) { + head->p_height = head->bdf_height; + } + + if ((head->p_width != head->bdf_width) || + (head->p_height != head->bdf_height)) { + head->zoomf = 1; + } else { + head->zoomf = 0; + } + + if ((head->code = (int *)malloc(sizeof(int)*head->num_chars)) == NULL) { + return(MALLOC_ERROR); + } + + if ((head->ptn = (char **)malloc(sizeof(char *)*head->num_chars)) == NULL) { + return(MALLOC_ERROR); + } + + if ((rtn = readBdfToMemory(head, bdfbuf, num_gr, gr, code_area))) { + return(rtn); + } + + WriteGpfHeader(head); + + if ((rtn = WritePtnToGpf(head))) { + return(rtn); + } + + return(0); +} + + +static void +put_error_and_exit(btop, er_no, prog_name) +struct btophead *btop; +int er_no; +char *prog_name; +{ + ErrMsgTable_AndExit( er_no, btop->in_file, NULL, + NULL, btop->out_file, + NULL, + prog_name + ); + return; +} + + + + + +static void +put_help(prog_name) +char *prog_name; +{ + USAGE1("Usage : %s -xlfd xlfd_name\n", prog_name); + USAGE("\t\t[-g character_size][-p character_pattern_file_name]\n"); + USAGE("\t\t[-style style]\n"); + USAGE("\t\t[-start start_code] [-end end_code]\n"); + USAGE("\t\t[-width character_width] [-height character_height]\n"); + COMM_HELP_MSG ; + USAGE1("%s can extract glyphs in cpf file format in the following code area.\n", prog_name); + USAGE("codeset \t\tcode area\n"); + USAGE("----------------------------------------\n"); + DispUdcCpArea() ; + USAGE("If the -start and -end option is omitted, the start/end code of each extractive area is specified.\n"); + USAGE("The xlfd name and character size may be obtained using dtlsgpf command.\n"); + return; +} + +static void +Usage(prog_name) +char *prog_name; +{ + put_help( prog_name ); + exit(1); +} + + +static int +check_width( prog_name, len_str ) +char *prog_name; +char *len_str; +{ + return( check_width_height( prog_name, len_str, 0) ); +} + + +static int +check_height( prog_name, len_str ) +char *prog_name; +char *len_str; +{ + return( check_width_height( prog_name, len_str, 1) ); +} + +static int +check_width_height( prog_name, len_str, mode ) +char *prog_name; +char *len_str; +int mode; /* width ... 0 , height ... 1 */ +{ + int ret; + char *tmp; + + ret = (int)strtol( len_str, &tmp, 10 ); /* <-- ret = atoi( len_str ) */ + if ((tmp == len_str) || (ret < MIN_FONT_WIDTH) || (ret > MAX_FONT_WIDTH)) { + switch( mode ) { + case 0: + USAGE2("%s : The specification of the character width is improper.\"%s\"¡¥\n", + prog_name, len_str); + break; + case 1: + USAGE2("%s : The specification of the character height is improper.\"%s\"¡¥\n", + prog_name, len_str); + break; + default: + break; + } + return(0); + } + return( ret ); +} + + + + + + +static int +check_code( prog_name, code_str, mode, charset, num_gr, gr ) +char *prog_name; +char *code_str; +int mode; /* start_code ... 0, end_code ... 1 */ +char *charset ; +int num_gr ; +FalGlyphRegion *gr ; +{ + int err_flg = 0; + int code_num; + char *tmp; + FalGIInf *gi = NULL; + int num_gi ; + int i, code ; + + code = (int)strtol(code_str, &tmp, 16); + if ( tmp == code_str ) { + err_flg = 1; + } + + if( COMM_SBFNT_ISSBFNT( charset ) ) { + code_num = code ; + CONVGLYPHINDEX( code_num ) ; + } else { + if( fal_code_to_glyph( locale, code, &gi, &num_gi) ) { + USAGE2("%s : Failed to convert code point into glyph index.\"%s\" \n", prog_name, code_str ) ; + err_flg = 1; + } + if( num_gi==1 ){ + code_num = gi[0].glyph_index ; + err_flg = 0 ; + }else{ + for( i=0; i= gr[i].start) && (code_num <= gr[i].end) ) + return( code_num ); + } + } + + switch( mode ) { + case 0: + USAGE2("%s : The specification of the extract start code is improper.\"%s\"¡¥\n", + prog_name, code_str); + break; + case 1: + USAGE2("%s : The specification of the extract end code is improper.\"%s\"¡¥\n", + prog_name, code_str); + break; + default: + USAGE2("%s : The specification of the extract code is improper.\"%s\"¡¥\n", + prog_name, code_str); + } + return(-1); +} + + +static int +readBdfToMemory(head, buf, num_gr, gr, code_area) +struct btophead *head; +char *buf; +int num_gr ; +FalGlyphRegion *gr ; +int code_area ; +{ + int code, mwidth, num_char, bsize, rtn; + char *ptn; + + num_char = 0; + mwidth = (head->bdf_width + 7) / 8; + bsize = mwidth * head->bdf_height; + while(1) { + if ((rtn = GetBdfCode(head, buf, &code)) < 0) { + return(rtn); /* contain BDF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + if ( + ( code < head->start_code) || ( code > head->end_code ) + ||( !IN_CODE( head->code_category, SHIFT_ON( code ) ) ) + ||( + (head->code_category == ALL_CODE) && + !( code_area & SYSTM ) && + IsInRegion( code, num_gr, gr ) + ) + ) { + continue; + } + + head->code[num_char] = code; + if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) { + return(MALLOC_ERROR); + } + if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} diff --git a/cde/programs/dtudcfonted/dtlsgpf/Imakefile b/cde/programs/dtudcfonted/dtlsgpf/Imakefile new file mode 100644 index 00000000..5937b80a --- /dev/null +++ b/cde/programs/dtudcfonted/dtlsgpf/Imakefile @@ -0,0 +1,31 @@ +XCOMM $XConsortium: Imakefile /main/6 1996/09/09 11:19:55 drk $ + + + DESTDIR = $(CDE_INSTALLATION_TOP) + BINDIR = /bin + FONTLIST = /config + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + OPT4 = -DDTUDCFONTSLISTDIR='"'$(CDE_INSTALLATION_TOP)$(FONTLIST)'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) $(OPT4) + + INCLUDES = -I../include\ + -I../libfal\ + -I../libfal/include + + DEPLIBS = ../libfuty/liboakfuty.a ../libfal/libfal.a $(DEPXLIB) +LOCAL_LIBRARIES = ../libfuty/liboakfuty.a ../libfal/libfal.a $(XLIB) + SYS_LIBRARIES = -lc + + SRCS = lsgpf.c + + OBJS = lsgpf.o + +ComplexProgramTarget(dtlsgpf) diff --git a/cde/programs/dtudcfonted/dtlsgpf/lsgpf.c b/cde/programs/dtudcfonted/dtlsgpf/lsgpf.c new file mode 100644 index 00000000..fc3ee4f5 --- /dev/null +++ b/cde/programs/dtudcfonted/dtlsgpf/lsgpf.c @@ -0,0 +1,927 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: lsgpf.c /main/7 1996/11/08 02:05:57 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include + +#include "FaLib.h" +#include "falfont.h" +#include "bdfgpf.h" +#include "udcutil.h" + + +static void dsp_info_list(); +static void dsp_title(); +static void dspinfo_1line(); +static void disp_no_fontslist(); +static void sort_offset_list() ; +static int sort_fontlist() ; +static void dsp_error_title() ; +static int dsp_error_files() ; + +static void put_help(); +static int search_fontfile_name() ; +static int get_new_target() ; + +static char *utillocale ; +static char *fontdir ; +static char *command_name ; + +typedef struct { + int num; + struct { + int start; + int end; + }entry[BUFSIZE]; +}MISS_ENTRY; + +/* request for sort */ +#define REQ_STYLE (1<<1) +#define REQ_CHARSIZE (1<<2) +#define REQ_LETTER (1<<3) +#define REQ_DELEQUAL (1<<16) + +/* error flag */ +#define NO_FONT (1<<1) +#define SAME_FONT (1<<2) +#define REDEFINED_FONT (1<<3) + +/* request flag */ +#define A_OPT (1<<1) +#define L_OPT (1<<2) +#define X_OPT (1<<3) +#define C_OPT (1<<4) + +int +main( argc, argv ) +int argc; +char *argv[]; +{ + FalFontDataList *lst_m; /* font information list struct */ + FalFontData key; /* font reference information creation struct */ + MISS_ENTRY unknown_m ; /* error */ + int i, j; + int code_sw; /* code set flag */ + + int mask; + int code_set ; + int errflg ; + int dsp_opt ; + + /* initialize */ + command_name = argv[0] ; + errflg = 0 ; + unknown_m.num = 0; + code_sw = 0; + dsp_opt = 0 ; + + /* get locale strings */ + if( (utillocale = (char *)getenv( "LANG" )) == NULL ){ + utillocale = "C" ; + } + + if( (fontdir = (char *)getenv( "DTUDCFONTS" )) == (char *)NULL ) { + fontdir = DTUDCFONTSLISTDIR ; + } + + /* + * dtlsgpf check on which options are required. + */ + for (i=1 ; i < argc ; i++) { + + if (!strcmp(argv[i], "-help")) { + put_help(argv[0]); + exit(0); + } + if (*argv[i] != '-') { + put_help(argv[0]); + exit(1); + } + + if ( !strcmp( argv[i], "-codeset" ) ) { + char *cbuf ; + if ( (i+1) >= argc ){ + put_help( argv[0] ); + exit( 1 ); + } + i++; + code_set = (int)strtol( argv[i], &cbuf, 10 ) ; + if( argv[i] == cbuf ) { + put_help( argv[0] ); + exit( 1 ); + } + code_sw = 1 ; + } + + for (j=1; argv[i][j] != '\0' ; j++) { + char req ; + req = argv[i][j] ; + if ( req == 'l') dsp_opt |= L_OPT ; + else if ( req == 'a') dsp_opt |= A_OPT ; + else if ( req == 'x') dsp_opt |= X_OPT ; + else if ( req == 'C') dsp_opt |= C_OPT ; + else { + put_help(argv[0]); + exit( 1 ); + } + } + } + + /* "-ax" -> "-a" */ + if( dsp_opt == ( A_OPT | X_OPT ) ) dsp_opt = A_OPT ; + + /* + * display information list of UDC code region + */ + if( dsp_opt & C_OPT ){ + fprintf(stdout ,"codeset\t\tcode area\n"); + fprintf(stdout ,"--------------------------------------------\n"); + if ( DispUdcCpArea( stdout ) == -1 ){ + ErrMsgTable_FalGetFontList( argv[0], fal_utyerror, fal_utyderror ); + exit( 1 ); + } + exit( 0 ); + } + + /* + * get an information list of UDC fonts + */ + mask = 0; + mask = FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED ; + if( code_sw ) { + mask |= FAL_FONT_MASK_CODE_SET ; + key.cd_set = FALGETFALCODESET( code_set ) ; + } + + /* get font information list */ + if ( FalGetFontList( &key, mask, &lst_m ) == FAL_ERROR ){ + ErrMsgTable_FalGetFontList( argv[0], fal_utyerror, fal_utyderror ); + exit( 1 ); + } + + /* sort element of font infomation list */ + if( sort_fontlist( lst_m ) == FAL_ERROR ) { + FalFreeFontList( lst_m ); + return FAL_ERROR ; + } + + /* + * dtlsgpf shows UDC informations as user's request. + */ + dsp_title( stdout, dsp_opt ); + if ( lst_m->num == 0) { + disp_no_fontslist( dsp_opt ) ; + } else { + dsp_info_list( argv[0], dsp_opt, lst_m, &unknown_m, &errflg ); + if (unknown_m.num != 0) { + if( dsp_opt & L_OPT ) { + dsp_error_title(argv[0], &errflg, dsp_opt ); + if( dsp_error_files( lst_m, &unknown_m ) ) { + exit( 1 ); + } + } + } + } + + FalFreeFontList( lst_m ); + exit( 0 ); +} + + + + +static void +dsp_info_list( com, dspopt, lst, unknown_file_lst, errflg ) +char *com; +int dspopt; +FalFontDataList *lst; +MISS_ENTRY *unknown_file_lst; +int *errflg ; +{ + FalFontDataList srt_lst; + int i, j ; + int entry, entry_end; + int ret; + char *filename; /* file base's name */ + char fname[BUFSIZE]; + char tmpfname[BUFSIZE]; + int srt_cnt, *sort_list, cnt, mask ; + + if( lst->num == 0 ){ + return ; + } + + srt_lst.num = lst->num ; + srt_lst.list = (FalFontData *)malloc( sizeof(FalFontData) * lst->num ) ; + if( srt_lst.list == NULL ) { + USAGE("dtlsgpf : malloc error.\n" ) ; + exit(1) ; + } + + for (i=0, srt_cnt=0 ; i < lst->num ; i++) { + int letter_cmp; + + entry = entry_end = i; + for (j=i ; + (j < lst->num) && + !strcmp(lst->list[j].style.name, lst->list[entry].style.name) && + (lst->list[j].size.h == lst->list[entry].size.h ) ; + j++) + { + if( (lst->list[j].letter.h == 0) || + (lst->list[j].letter.w == 0) ) break ; + entry_end = j; + } + + if ( entry == entry_end ) { + if ( dspopt & L_OPT || dspopt & X_OPT ) + dspinfo_1line( lst->list[entry], stdout, + unknown_file_lst, entry, + errflg, dspopt ); + else memmove( &(srt_lst.list[srt_cnt++]), + &(lst->list[entry]), + sizeof(FalFontData) ); + continue; + } + + letter_cmp = lst->list[entry].letter.h; + for (j=entry ; j <= entry_end ; j++) { + if (lst->list[j].letter.h != letter_cmp) { + break; + } + } + + if (j > entry_end) { + ret = GetDefaultFile( lst->list[entry].size.h, + lst->list[entry].style.name, fname); + if ( ret < 0 ) { + fname[0]='\0'; + for ( j = entry; j <= entry_end; j++ ) { + if ( dspopt & L_OPT || dspopt & X_OPT ) + dspinfo_1line( lst->list[j], stdout, + unknown_file_lst, j, + errflg, dspopt ); + else memmove( + &(srt_lst.list[srt_cnt++]), + &(lst->list[j]), + sizeof(FalFontData) ); + } + i = entry_end; + continue ; + } + for( j = entry; j <= entry_end; j++ ) { + ret = search_fontfile_name( + lst->list[j], tmpfname, + unknown_file_lst, j, errflg + ) ; + if( ret == -1 ) continue ; + else if( ret == -2 ) exit(1) ; + filename = falcom_get_base_name( tmpfname ) ; + if ( !strcmp( filename, fname ) ){ + if ( dspopt & L_OPT || dspopt & X_OPT ) + dspinfo_1line( lst->list[j], stdout, + unknown_file_lst, j, + errflg, dspopt ); + else memmove( + &(srt_lst.list[srt_cnt++]), + &(lst->list[j]), + sizeof(FalFontData) ); + break; + } + } + i = entry_end; + continue; + } + + + ret = GetDefaultFile( + lst->list[entry].size.h, + lst->list[entry].style.name, + fname + ); + if( ret ) { + switch ( ret ) { + case -1: + for ( j = entry; j <= entry_end; j++ ) { + if ( dspopt & L_OPT || dspopt & X_OPT ) + dspinfo_1line( + lst->list[j], stdout, + unknown_file_lst, j, + errflg, dspopt ); + else memmove( + &(srt_lst.list[srt_cnt++]), + &(lst->list[j]), + sizeof(FalFontData) ); + } + break ; + case -2: + unknown_file_lst->entry[ unknown_file_lst->num ].start = entry; + unknown_file_lst->entry[ unknown_file_lst->num ].end = entry_end; + unknown_file_lst->num++; + *errflg |= REDEFINED_FONT ; + break ; + case -3: + USAGE4("%s : The user defined character information file cannot be read.\"%s/%s/%s \"\n\n", + com, fontdir, utillocale, UDFLIST_DEF ); + exit(1) ; + case -4: + USAGE4("%s : The mistake is found in the description of the user defined character information file.\"%s/%s/%s \"\n\n", + com, utillocale, fontdir, UDFLIST_DEF ); + for ( j = entry; j <= entry_end; j++ ) { + if ( dspopt & L_OPT || dspopt & X_OPT ) + dspinfo_1line( lst->list[j], stdout, + unknown_file_lst, j, + errflg, dspopt ); + else memmove( + &(srt_lst.list[srt_cnt++]), + &(lst->list[j]), + sizeof(FalFontData) ); + } + break ; + } + i = entry_end; + continue; + } + + for ( j = entry; j <= entry_end; j++ ) { + ret = search_fontfile_name( + lst->list[j], tmpfname, + unknown_file_lst, j, errflg + ) ; + if( ret == -1 ) continue ; + else if( ret == -2 ) exit(1) ; + filename = falcom_get_base_name( tmpfname ) ; + if ( !strcmp( filename, fname ) ){ + if ( dspopt & L_OPT || dspopt & X_OPT ) + dspinfo_1line( lst->list[j], stdout, + unknown_file_lst, j, + errflg, dspopt ); + else memmove( + &(srt_lst.list[srt_cnt++]), + &(lst->list[j]), + sizeof(FalFontData) ); + break; + } + } + if ( j > entry_end ) { + unknown_file_lst->entry[ unknown_file_lst->num ].start = entry; + unknown_file_lst->entry[ unknown_file_lst->num ].end = entry_end; + unknown_file_lst->num++; + *errflg |= REDEFINED_FONT ; + } + i = entry_end; + } + + /* + * dtlsgpf displays the infomations of user defined characters. + */ + if ( !(dspopt & L_OPT) ) { /* display character size and style */ + srt_lst.num = srt_cnt ; + + if ( dspopt & A_OPT ) + mask = REQ_STYLE | REQ_CHARSIZE | REQ_LETTER | REQ_DELEQUAL ; + else + mask = REQ_CHARSIZE | REQ_DELEQUAL ; + + sort_offset_list( &srt_lst, mask, &sort_list, &cnt ) ; + + for (i=0 ; inum == 0 ){ + return 0; + } + for (i=0 ; inum ; i++) { + entry_start = unknown->entry[i].start; + entry_end = unknown->entry[i].end; + + USAGE1("\tcode set \t%d \n", + FALCODESETTONUM( lst->list[entry_start].cd_set ) ) ; + USAGE1("\tcharacter_size \t%d\n", + lst->list[entry_start].size.h ) ; + USAGE1("\tstyle \t\t%s \n", lst->list[entry_start].style.name ) ; + USAGE("\n" ); + for ( j = entry_start; j <= entry_end; j++ ) { + ret = search_fontfile_name( lst->list[j], tmp_fname, NULL, 0, 0 ) ; + if( ret == -1 ){ + USAGE("\t\tThere is no font file that is required." ); + USAGE1("\t%s\n", lst->list[j].xlfdname ); + continue ; + } else if( ret == -2 ){ + return -1 ; + } + filename = tmp_fname ; + USAGE1("\t\t%s", filename ); + USAGE1("\t%s\n", lst->list[j].xlfdname ); + } + USAGE("\n" ); + } + USAGE("\n" ); + return 0; +} + + + +#define SORTOFFSETNUM {\ + offset = size_offset_list[j] ;\ + size_offset_list[j] = size_offset_list[i] ;\ + size_offset_list[i] = offset ;\ +} + + +static void +sort_offset_list( flist, mask, sort_list, data_cnt ) +FalFontDataList *flist ; +int mask ; +int **sort_list ; +int *data_cnt ; +{ + int *size_offset_list ; + int cnt, i, j ; + int offset ; + int exist ; + + if( flist->num == 0 ){ + return ; + } + + if( (size_offset_list = (int *)malloc( flist->num * sizeof(int) )) == NULL ) + { + USAGE("dtlsgpf: malloc error.\n" ); + exit(1) ; + } + for( i=0 ; i < flist->num; i++ ) size_offset_list[i] = -1 ; + + for( i=0, cnt=0; i < flist->num; i++ ) { + if( mask & REQ_DELEQUAL ) { + exist = REQ_DELEQUAL ; + for( j=0; jlist[size_offset_list[j]].size.h == flist->list[i].size.h) + ) { + exist |= REQ_CHARSIZE ; + } + if( (mask & REQ_LETTER) && + (flist->list[size_offset_list[j]].letter.h == flist->list[i].letter.h) + ) { + exist |= REQ_LETTER ; + } + if( (mask & REQ_STYLE) && + !strcmp(flist->list[size_offset_list[j]].style.name, flist->list[i].style.name) + ) { + exist |= REQ_STYLE ; + } + if( exist == mask ) break ; + else exist = REQ_DELEQUAL ; + } /* size_offset_list */ + if( exist == mask ) continue ; + } /* REQ_DELEQUAL */ + size_offset_list[cnt++] = i ; + } /* flist */ + /* sort data */ + for( i=0; ilist[size_offset_list[i]].letter.h > + flist->list[size_offset_list[j]].letter.h) + { + SORTOFFSETNUM ; + } + } + if( mask & REQ_CHARSIZE ) { + if( flist->list[size_offset_list[i]].size.h > + flist->list[size_offset_list[j]].size.h) + { + SORTOFFSETNUM ; + } + } + if( mask & REQ_STYLE ) { + if( strcoll(flist->list[size_offset_list[i]].style.name, + flist->list[size_offset_list[j]].style.name) > 0 ) + { + SORTOFFSETNUM ; + } + } + } + } + *sort_list = size_offset_list ; + *data_cnt = cnt ; +} + + + +static void +dsp_title( fp, dspopt ) +FILE *fp; +int dspopt ; +{ + if( dspopt & L_OPT || dspopt & X_OPT ) { + fprintf(fp, "\n" ) ; + + if( dspopt & X_OPT ) fprintf(fp, " code set" ); + if( dspopt & L_OPT ) fprintf(fp, "\tfilename\t" ); + if( (dspopt != X_OPT) && (dspopt != (L_OPT | X_OPT)) ) + fprintf(fp, "character size\t" ); + COMM_DSP_LETTER_T ; + if( dspopt & A_OPT ) fprintf(fp, "style \t" ); + COMM_DSP_PRM ; + if( dspopt != X_OPT ) fprintf(fp, "\n" ) ; + if( dspopt & X_OPT ) fprintf(fp, "\tXLFD\n" ); + fprintf(fp ,"-----------------------------------------------------------------------------\n"); + } +} + + + + + +static void +dspinfo_1line( data, fp, unknown_file_lst, offset, errflg, dspopt ) +FalFontData data; +FILE *fp; +MISS_ENTRY *unknown_file_lst; +int offset ; +int *errflg ; +int dspopt ; +{ + int dsp_on ; + char *namep; + char tmp_fname[BUFSIZE]; + int ret ; + + dsp_on = 0; + + /* get font informations */ + ret = search_fontfile_name( data, tmp_fname, unknown_file_lst, offset, errflg ) ; + if( ret == -1 ) return ; + else if( ret == -2 ) exit(1) ; + namep = tmp_fname ; + + /* display font informations */ + if( dspopt & X_OPT ) fprintf( fp, "%d \t", FALCODESETTONUM( data.cd_set ) ); + + if( dspopt & L_OPT ) fprintf( fp, "%s\t", namep ); + + if( (dspopt != X_OPT) && + (dspopt != (L_OPT | X_OPT)) + ) { + fprintf( fp, "%d", data.size.h ); + } + + if( dspopt & A_OPT ) { + if( data.letter.h ) { + if( !(dspopt & L_OPT) ) + fprintf( fp, ".%d", data.letter.h ); + else + fprintf( fp, "\t%4d", data.letter.h ); + } + fprintf( fp, "\t" ); + fprintf( fp, "%s", data.style.name ); + } + + if( dspopt & L_OPT ) { + fprintf( fp, "\t" ); + if( data.prm & FAL_FONT_DISPLAY ) { + fprintf( fp, "display"); + dsp_on = 1; + } + if( data.prm & FAL_FONT_PRINTER ) { + if( dsp_on ) { + fprintf( fp, " & "); + } + fprintf( fp, "printer"); + } + } + if( dspopt != X_OPT ){ + fprintf( fp, "\n"); + if( dspopt & X_OPT ) fprintf( fp, "\t" ); + } + if( dspopt & X_OPT ) fprintf( fp, "%s\n", data.xlfdname ); + if( dspopt != X_OPT ){ + if( dspopt & X_OPT ) fprintf( fp, "\n" ); + } +} + + + + + +static void +disp_no_fontslist( dspopt ) +int dspopt ; +{ + fprintf( stdout, "\nThere are no fonts that are used for user defined character.\n" ) ; +} + + +static void +put_help( prog_name ) +char *prog_name; +{ + USAGE1("Usage : %s [-lax][-la][-lx][-C][-codeset number][-help]\n", prog_name); + USAGE("\t-l : display of file name and character size\n"); + USAGE("\t-a : display of style(FAMILY_NAME) information\n"); + USAGE("\t-x : display of XLFD information\n"); + USAGE("\t-C : display of code area informations\n"); + USAGE("\t-codeset : specification of the codeset\n"); + USAGE("\t-help : display of of the command parameter informations\n"); + + USAGE(" (If the option is not specified, only the character size are displayed.)\n"); +} + + + +static int +search_fontfile_name( data, fname, unknown_file_lst, offset, errflg ) +FalFontData data ; +char *fname ; +MISS_ENTRY *unknown_file_lst; +int offset ; +int *errflg ; +{ + FalFontID fid ; + FalFontDataList *flist ; + int mask ; + char *tmp_fname ; + + mask = + FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_XLFDNAME | + FAL_FONT_MASK_SIZE_H | + FAL_FONT_MASK_STYLE_NAME | FAL_FONT_MASK_CODE_SET + ; + + if( data.size.w >= 0 ) mask |= FAL_FONT_MASK_SIZE_W ; + if( data.letter.w ) mask |= FAL_FONT_MASK_LETTER_W ; + if( data.letter.h ) mask |= FAL_FONT_MASK_LETTER_H ; + if( data.letter.x ) mask |= FAL_FONT_MASK_LETTER_X ; + if( data.letter.y ) mask |= FAL_FONT_MASK_LETTER_Y ; + + if( data.style.def ) mask |= FAL_FONT_MASK_STYLE_DEF ; + if( data.shape.name ) mask |= FAL_FONT_MASK_SHAPE_NAME ; + if( data.shape.def ) mask |= FAL_FONT_MASK_SHAPE_DEF ; + COMM_SBCHR_SETFONTDATA( data, mask ) ; + if( data.prm ) mask |= FAL_FONT_MASK_PERMISSION ; + + fid = FalOpenSysFont( &data, mask, &flist ) ; + if( fid == 0 ) { + memset( fname, '\0', sizeof(fname) ) ; + if( flist ){ + FalFreeFontList( flist ) ; + if( unknown_file_lst ) { + unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ; + unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ; + unknown_file_lst->num++; + *errflg |= SAME_FONT ; + } + return(-1); + } else { + switch( fal_utyerror ) { + case _FAL_OPEN_ER : + case _FAL_READ_ER : + case _FAL_STAT_ER : + switch( fal_utyderror ) { + case EACCES : + case ENOENT : + if( unknown_file_lst ) { + unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ; + unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ; + unknown_file_lst->num++; + *errflg |= NO_FONT ; + } + return(-1) ; + default : + USAGE2("System call error occurred. fal_utyerror = %d fal_utyderror = %d\n", fal_utyerror, fal_utyderror ) ; + return(-2) ; + } + case _FAL_FONT_ER : + if( unknown_file_lst ) { + unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ; + unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ; + unknown_file_lst->num++; + *errflg |= NO_FONT ; + } + return(-1) ; + case _FAL_MALOC_ER : + USAGE("malloc error occurred.\n" ) ; + return(-2) ; + default : + USAGE1("%s : cannot get font information list.\n", command_name ) ; + return(-2) ; + } + } + } + if( FalFontIDToFileName( fid, &tmp_fname ) == FAL_ERROR ) { + USAGE1("%s : cannot get file name.\n", command_name ) ; + FalCloseFont( fid ) ; + return(-2) ; + } + strcpy( fname, tmp_fname ) ; + FalFree( tmp_fname ) ; + FalCloseFont( fid ) ; + return(0) ; +} + + + +static int +sort_fontlist( lst ) +FalFontDataList *lst; +{ + int i,j; + FalFontDataList srt; + FalFontData target; + int target_entry; + + if( lst->num == 0 ){ + return(0) ; + } + + srt.num = lst->num; + + if (( srt.list = (FalFontData *)malloc(sizeof(FalFontData) * srt.num)) == NULL) { + return FAL_ERROR; + } + memmove (srt.list, lst->list, sizeof(FalFontData) * srt.num); + /* start to sort */ + for ( i=0 ; i < srt.num -1 ; i++ ) { + + memmove( &target, &(srt.list[i]), sizeof(FalFontData)); + target_entry = i; + + for ( j=i+1 ; j < srt.num ; j++ ) { + if ( get_new_target( &target, &(srt.list[j]) ) ) { + memmove( &target, &(srt.list[j]), sizeof(FalFontData)); + target_entry = j; + } + } + if (target_entry != i) { + memmove( &target, &(srt.list[target_entry]), + sizeof(FalFontData) + ); + memmove( &(srt.list[i+1]), &(srt.list[i]), + sizeof(FalFontData)*(target_entry -i) + ); + memmove( &(srt.list[i]), &target, + sizeof(FalFontData) + ); + } + } + free(lst->list); + lst->list = srt.list; + return(0); +} + + +/* sort flag */ +/* return data ¡§ sort ... 1 */ +/* no sort ... 0 */ + +static int +get_new_target( target, choose ) +FalFontData *target; +FalFontData *choose; +{ + FalFontData diff; + DEF_STR_CHK ; + DEF_STR_SET ; + + diff.style.def = choose->style.def - target->style.def; + str_chk.style = strcmp( choose->style.name, target->style.name ) ; + + NEW_TARGET_SET( diff, choose, target, str_chk ) ; + + diff.shape.def = choose->shape.def - target->shape.def; + if( (choose->shape.name != NULL) && (target->shape.name != NULL) ) { + str_chk.shape = strcmp( choose->shape.name, target->shape.name ) ; + } + + diff.cd_set = choose->cd_set - target->cd_set; + diff.size.h = choose->size.h - target->size.h; + diff.size.w = choose->size.w - target->size.w; + diff.letter.h = choose->letter.h - target->letter.h; + diff.letter.w = choose->letter.w - target->letter.w; + + /* codeset */ + if ( diff.cd_set < 0 ) return 1; + if ( diff.cd_set > 0 ) return 0; + + /* character size height */ + if ( diff.size.h < 0 ) return 1; + if ( diff.size.h > 0 ) return 0; + + /* letter size height */ + if ( diff.letter.h < 0 ) return 1; + if ( diff.letter.h > 0 ) return 0; + + /* character size wide */ + if ( diff.size.w < 0 ) return 1; + if ( diff.size.w > 0 ) return 0; + + /* letter size wide */ + if ( diff.letter.w < 0 ) return 1; + if ( diff.letter.w > 0 ) return 0; + + /* style */ + if ( target->style.def == FAL_FONT_UNKNOWN ) { + if ( choose->style.def > 0 ) return 1; + /* style is FAL_FONT_UNKNOWN both "target" and "choose" */ + if ( str_chk.style < 0 ) return 1; + if ( str_chk.style > 0) return 0; + } else if ( choose->style.def == FAL_FONT_UNKNOWN ) { + return 0; + } + /* target->style.def and choose->style.def is not FAL_FONT_UNKNOWN */ + if ( diff.style.def < 0 ) return 1; + if ( diff.style.def > 0 ) return 0; + + NEW_TARGET_CHK( diff, choose, target, str_chk ) ; + + /* character style */ + if ( target->shape.def == FAL_FONT_UNKNOWN ) { + if ( choose->shape.def > 0 ) return 1; + if ( str_chk.shape < 0 ) return 1; + if ( str_chk.shape > 0 ) return 0; + } else if (choose->shape.def == FAL_FONT_UNKNOWN ) { + return 0; + } + if ( diff.shape.def < 0 ) return 1; + if ( diff.shape.def > 0 ) return 0; + + return 0; +} diff --git a/cde/programs/dtudcfonted/dtudcfonted.1 b/cde/programs/dtudcfonted/dtudcfonted.1 new file mode 100644 index 00000000..42bf5760 --- /dev/null +++ b/cde/programs/dtudcfonted/dtudcfonted.1 @@ -0,0 +1,71 @@ +.\" $XConsortium: dtudcfonted.1 /main/2 1996/10/29 15:41:16 drk $ +.\"--- +.\" (c) Copyright 1996 FUJITSU Ltd. +.\"--- +.TH dtudcfonted 1X "20 Feb. 1996"" +.BH "20 Feb. 1996"" +.SH NAME +dtudcfonted - the User Defined Characters (UDCs) Font Editor +.SH SYNOPSIS +dtudcfonted [options] +.SH DESCRIPTION +The UDCs Editor provides the facilities that enable the user to edit +User Defined Characters font. +.P +The UDCs Editor uses lines and geometric shape drawing tools in order +to create new User Defined Character or modify existing ones. +It support PCF (Portable Compoled Formet) and SNF (Server Natural Format) +formats. +.sp .5 +.SS Key Supported Tasks +.RS +.P +- Modify size of window. +.P +- Modify location of window. +.P +- Iconify window. +.P +- Edit a User Defined Character or existing icon. +.P +- Save the current font. +.P +- Undo the last operation. +.P +- Cut, copy, and paste areas within the UDCs Editor editing area. +.P +- Rotate selected area. +.P +- Copy User Defined Character. +.RE +.SH OPTIONS +The following options are available from the command line: +.sp 1.5 +.BI \-pane_size " pane_size" +.sp .5 +This option takes a size of UDCs Editor editing area. +.sp 1.5 +.BI \-codepoint +.sp .5 +This option specifies code format. +If you do not set this optiton, UDCs editor uses Glyph Index code. +If you do set this optiton, UDCs editor uses Code point code. +.sp 1.5 +.SH RETURN VALUE + Exit values are: +.IP "\f30\fP" .5i +Successful completion. +.IP "\f3>0\fP" .5i +Error condition occurred. +.sp 1.5 +.SH EXAMPLES +.IP "dtudcfonted" .5i +Starts the UDCs Editor. +.sp 1.5 +.IP NOTE: .5i +UDCs Editor uses with root user. +.sp 1.5 +.SH FILES +Files used by this component. +.IP "/.../dt/app-defaults/C/Dtudcfonted App-defaults file. " .5i +.IP "/.../dt/app-defaults/ja_JP/Dtudcfonted App-defaults file. " .5i diff --git a/cde/programs/dtudcfonted/dtudcfonted.msg b/cde/programs/dtudcfonted/dtudcfonted.msg new file mode 100644 index 00000000..4d810bb9 --- /dev/null +++ b/cde/programs/dtudcfonted/dtudcfonted.msg @@ -0,0 +1,186 @@ +$ $XConsortium: dtudcfonted.msg +$ *************************************<+>************************************* +$ ***************************************************************************** +$ ** +$ ** File: dtudcfonted.msg +$ ** +$ ** Project: Fujitsu DT UDC Font Editor +$ ** +$ ** Description: +$ ** ----------- +$ ** This file is the source for the message catalog for dtudcfonted +$ ** +$ ** +$ ***************************************************************************** +$ ** +$ ** (c) Copyright 1996 Fujitsu Ltd. +$ ** +$set 2 +$ ***************************************************************************** +$ ** _DtMessage set for ufont.c +$ ***************************************************************************** + +$ This is footer message when registration of the character. +2 Registration processing inside. + +$ Message4-8 are error messages when registration of the character. +4 Failed in the registration of the character. +6 Illegal code. +8 Because the memory allocation cannot be done, it is not possible to add. + +$ Message10-16 are error messages when copying of the character. +10 There is no character of the specified code. +12 The mistake is found in the specified copy origin code. +14 The mistake is found in the specified copy target code. +16 There is no character in the specified area. + +$ This is footer message. +18 Please wait for a while. + +$ This is error message when copying of the character. +20 No copy origin code file is specified. + +$ Message22-24 are error message of user defined character +22 Informations of user defined character cannot collect.\nThere is no font specified. +24 Informations of user defined character cannot collect.\nThere are plural fonts specified. + +$ UDC is User Defined Character. +26 The specified font do not have any UDCs areas. + +28 There are no memories any more. +30 The information of UDCs area is illegal. +32 The font file cannot read.\nPattern area was broken. + +$ Dtudcfonted is name of this application. +34 Dtudcfonted cannot edit proportional character font. + +36 There are unsaved edits.\nDo you want to save them before opening? +38 There are unsaved edits.\nDo you want to save them before exiting? +40 When the copy processing is done, the glyph\nimage within the following ranges is changed.\nDo you want to do the copy processing?\n\n +42 No write permission for this font. You should change the file access mode before saving.\n + +$ There are user-visible labels in font-open dialog. +100 Select Items +102 - CodeSet: +104 - Style: +106 - Width: +108 - Height: +110 Open +112 Quit + +$ There are user-visible labels in menubar. +114 Font +116 Edit +118 Character +120 Information + +$ There are user-visible labels in File menu. +122 Open... +124 Save +126 Exit + +$ There are user-visible labels in Edit menu. +$ Message135 is copy of cut© +128 Clear +130 Set +132 Reverse +134 Cut +135 Copy +136 Paste +138 Rotate +140 Vertical Roll +142 Horizontal Roll +144 Undo + +$ There are user-visible labels in Character menu. +$ Message148 is copy of character +146 Add/Delete... +148 Copy... + +$ There are user-visible labels in Information menu. +150 XLFD name... +152 Code Area... + +$ There are user-visible labels in add/delete dialog. +154 Add +156 Delete +158 Cancel + +$ There are user-visible labels in copy dialog. +$ Message166 is label of execute button +160 Code(hex): +162 Copy origin code(hex): +164 Copy target code(hex): +166 Copy +168 Overlay +170 OK + +$ There are user-visible labels in unsaved edits. +172 Save +174 Do not Save +176 Save and Exit +178 Do not Save and Exit + +$ There are user-visible labels in delete notice dialog. +$ This format is `Message180 (?? Message182)' and `Message184 (?? Message186)'. +$ These Message180 and Message182 are used in only one character. +$ These Message184 and Message186 are used in plural characters. +180 The following character will be deleted. +182 character +184 The following characters will be deleted. +186 characters +188 Register completed +190 Code : +192 Code range : + +$ There are footer message label. +194 Message : + +$ There are user-visible labels in code dialog. +196 code... +198 Page up +200 Page down +202 Apply + +$ There are title. +204 dtudcfonted - Question +206 dtudcfonted - Warning +208 dtudcfonted - Error +210 dtudcfonted - Copy +212 dtudcfonted - Open +214 dtudcfonted - Add/Delete +216 dtudcfonted - XLFD +218 dtudcfonted - CodeArea + +$ There are information message. +230 File name +232 XLFD name +234 Code area + +$ There are error message of libfal. +300 Fatal error occurred. +301 Cannot open the font file. +302 Cannot read the font file. +303 There is no more memory. +304 Fatal error occurred. +305 The specified font file does not exist. +306 This font is not a pcf or snf font. +307 Cannot open fonts.list file. +308 The format of fonts.list file is illegal. +309 The descriptions of the fonts.list file are incorrect. +310 The format of fonts.list file is illegal. +311 Cannot open fonts.dir file. +312 Cannot read fonts.dir file. +313 Cannot read font properties. +314 Cannot get FONT property. +315 Cannot get FAMILY_NAME property. +316 This font file is already opened by other application. +317 Cannot lock font file. +318 Cannot unlock font file. +319 Cannot get lock information from the font file. +320 Cannot find the specified font file. +321 Cannot read NLS database. +322 Cannot get charset names from NLS database. +323 Charset name not defined in NLS database. +324 The specified font has not been opened. +325 Fatal error occurred. diff --git a/cde/programs/dtudcfonted/fssxeg.h b/cde/programs/dtudcfonted/fssxeg.h new file mode 100644 index 00000000..fce1dad1 --- /dev/null +++ b/cde/programs/dtudcfonted/fssxeg.h @@ -0,0 +1,56 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* fssxeg.h 1.5 - Fujitsu source for CDEnext 96/07/18 13:19:30 */ +/* $XConsortium: fssxeg.h /main/4 1996/07/19 20:32:54 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#include "udccom.h" /* 1995.10.09 */ +#include "FaLib.h" + +typedef int INT; +typedef short int SHORT; +typedef long int LONG; +typedef char CHAR; +typedef unsigned int UINT; +typedef unsigned short USHORT; +typedef unsigned char UCHAR; + +#define ON 1 +#define OFF 0 + +#define MAXPTNSIZE 128 +#define MAXPTNBYTE MAXPTNSIZE*((MAXPTNSIZE+7)/8) + + +#define ERROR_VAL fal_utyerror +#define EXISTS_FLAG fal_utyexists + +#define EDPANE_SIZE 400 +#define EDLIST_MAX 30 diff --git a/cde/programs/dtudcfonted/include/FaLib.h b/cde/programs/dtudcfonted/include/FaLib.h new file mode 100644 index 00000000..ee974a8d --- /dev/null +++ b/cde/programs/dtudcfonted/include/FaLib.h @@ -0,0 +1,410 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: FaLib.h /main/5 1996/06/25 20:08:31 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#ifndef _FALIB_H +#define _FALIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define FAL_ERROR -1 + +extern int fal_utyerror; /* library error information */ +extern int fal_utyderror; /* library error information */ +extern int fal_utyexists; /* existence's flag of font pattern */ + +extern unsigned long fal_utyerrno ; /* library error information */ +extern char fal_err_file[] ; + +/* + * + * structure of the font information + * + */ + +/* + * the equipment of output permission + */ +#define FAL_FONT_DISPLAY 1 +#define FAL_FONT_PRINTER 2 + + +#define FAL_FONT_GLYPH_INDEX -1 +/* + * codeset + */ +#define FAL_FONT_CS0 1 +#define FAL_FONT_CS1 2 +#define FAL_FONT_CS2 3 +#define FAL_FONT_CS3 4 + +#define FAL_FONT_CS4 5 +#define FAL_FONT_CS5 6 +#define FAL_FONT_CS6 7 +#define FAL_FONT_CS7 8 +#define FAL_FONT_CS8 9 + +/* + * font search mask + */ +#define FAL_FONT_MASK_XLFDNAME (1L<<1) +#define FAL_FONT_MASK_SIZE_W (1L<<2) +#define FAL_FONT_MASK_SIZE_H (1L<<3) +#define FAL_FONT_MASK_LETTER_W (1L<<4) +#define FAL_FONT_MASK_LETTER_H (1L<<5) +#define FAL_FONT_MASK_LETTER_X (1L<<6) +#define FAL_FONT_MASK_LETTER_Y (1L<<7) +#define FAL_FONT_MASK_STYLE_DEF (1L<<8) +#define FAL_FONT_MASK_STYLE_NAME (1L<<9) +#define FAL_FONT_MASK_SHAPE_DEF (1L<<10) +#define FAL_FONT_MASK_SHAPE_NAME (1L<<11) + + +#define FAL_FONT_MASK_CODE_SET (1L<<14) +#define FAL_FONT_MASK_PERMISSION (1L<<15) +#define FAL_FONT_MASK_DEL_EQUALDATA (1L<<16) +#define FAL_FONT_MASK_CHECK_ALL 0x1FFFF + +#define FAL_FONT_MASK_GLYPH_INDEX (1L<<17) +#define FAL_FONT_MASK_UPDATE (1L<<18) +#define FAL_FONT_MASK_DEFINED (1L<<19) +#define FAL_FONT_MASK_UNDEFINED (1L<<20) + + +/* + * undefined the character style,shape + */ +#define FAL_FONT_UNKNOWN 0 + +/* + * definition's data of character style + */ +#define FAL_FONT_MINCHO 1 +#define FAL_FONT_STR_MINCHO "mincho" +#define FAL_FONT_GOTHIC 2 +#define FAL_FONT_STR_GOTHIC "gothic" +#define FAL_FONT_MARU_GOTHIC 3 +#define FAL_FONT_STR_MARU_GOTHIC "maru_gothic" +#define FAL_FONT_TEXTBOOK 4 +#define FAL_FONT_STR_TEXTBOOK "textbook" +#define FAL_FONT_BRASH_GYOU 5 +#define FAL_FONT_STR_BRASH_GYOU "brash_gyou" +#define FAL_FONT_BRASH_KAI 6 +#define FAL_FONT_STR_BRASH_KAI "brash_kai" +#define FAL_FONT_HANDWRITING 7 +#define FAL_FONT_STR_HANDWRITING "handwriting" + +/* + * definition's data of character shape + */ +#define FAL_FONT_ZENKAKU 1 +#define FAL_FONT_STR_ZENKAKU "zenkaku" +#define FAL_FONT_HANKAKU 2 +#define FAL_FONT_STR_HANKAKU "hankaku" +#define FAL_FONT_QUARTER 3 +#define FAL_FONT_STR_QUARTER "1/4kaku" + +/* + * structures for font informations + */ +typedef struct { + int width; /* width */ + int height; /* height */ + int top; /* the head code */ + int bottom; /* the final code */ +} FalFontinfo ; + +typedef struct { + int num; + char **path; +} FalFontPath; + +typedef struct { + int def; /* definition data */ + char *name; /* the information of the character line */ +}FalFontDB; + + +/* + * structure of the font information + */ +typedef struct { + char *xlfdname; /* xlfd name */ + struct { + int w; /* the width of the character size */ + int h; /* the height of the character size */ + }size; + struct { + int w; /* the width of the letter size */ + int h; /* the height of the letter size */ + int x; /* position x of the letter size */ + int y; /* position y of the letter size */ + }letter; + FalFontDB style; /* character style */ + FalFontDB shape; /* character shape */ + FalFontDB reserve ; /* reserve */ + int cd_set; /* codeset */ + int prm; /* the equipment of output permission */ +}FalFontData; + +typedef struct { + int num; /* the number of font data*/ + FalFontData *list; /* the pointer to the array of + FalFontData structure */ +}FalFontDataList; + +/* + * UDC infomations + */ +typedef struct _FalCodeRegion { + int start ; /* first code */ + int end ; /* last code */ +} FalCodeRegion ; + +typedef struct _FalGlyphRegion { + int start ; /* first glyph index */ + int end ; /* last glyph index */ +} FalGlyphRegion ; + +typedef struct _FalGIInf { + char *charset_str; /* charcter set */ + int glyph_index; /* glyph index */ +} FalGIInf; + +/* + * structure of the font identifier + */ +#include +#include +#include +#include +#include +#include + +#ifdef Bool +#undef Bool +#endif + +#include "snfstruct.h" +#include "fontstruct.h" +#include "pcf.h" + +struct pcf_inf { + FontInfoRec info; + xCharInfo org_bounds; + PCFTablePtr tables; + int ntables; + CARD32 bmp_fmt; /* bitOrder ,byteOrder, glyph, scan */ + int nbitmaps; + CARD32 *offsets; + int sizebitmaps; + char *bitmaps; + CARD32 enc_fmt; + CARD16 *encodingOffsets; +}; + +typedef struct _Oak_Finf { + int ismmap; /* used mmap()? */ + int fsize; /* file size */ + int fd; /* file descripter */ + int isFef; + char *buf; /* font file allocated on memory */ + char *fname; /* name of font file */ +/* added by Rudie */ + int isPcf; + struct pcf_inf pcfinf; +/* added by Rudie */ + FontInfoPtr pFinf; + CharInfoPtr pCinf; + unsigned char *pGlyphs; + unsigned int width; + unsigned int height; + unsigned int start; + unsigned int end; + int sptnBufL; + char *sptnBuf; + int dptnBufL; + char *dptnBuf; + int dbufL; + char *dbuf; +} Oak_FontInf; + +typedef Oak_FontInf * FalFontID; /* font distinction */ + +/* + * function prototypes + */ +extern FalFontID FalOpenSysFont( +#if NeedFunctionPrototypes + FalFontData* /* open_font_data */, + int /* font_data_mask */, + FalFontDataList** /* missing_font_list_return */ +#endif +) ; + +extern int FalGetFontList( +#if NeedFunctionPrototypes + FalFontData* /* key_data */, + int /* mask */, + FalFontDataList** /* list_ret */ +#endif +) ; + +extern int FalFreeFontList( +#if NeedFunctionPrototypes + FalFontDataList* /* list */ +#endif +) ; + +extern char * +FalReadFont( +#if NeedFunctionPrototypes + FalFontID /* fid */ , + int /* code */ , + int /* width */ , + int /* height */ +#endif +) ; + +extern int FalQueryFont( +#if NeedFunctionPrototypes + FalFontID /* fid */ , + FalFontinfo* /* fontinfo */ +#endif +) ; + +extern int FalFontOfFontID( +#if NeedFunctionPrototypes + FalFontID /* fid */, + FalFontData* /* fontdata */ +#endif +) ; + +extern int FalCloseFont( +#if NeedFunctionPrototypes + FalFontID /* fid */ +#endif +) ; + +extern int FalFontIDToFileName( +#if NeedFunctionPrototypes + FalFontID /* fid */ , + char** /* file_name */ +#endif +) ; + +extern int FalFree( +#if NeedFunctionPrototypes + void* /* list */ +#endif +) ; + +extern int FalGetUDCCPArea( +#if NeedFunctionPrototypes + char* /* locale */ , + int /* code_set */ , + char* /* charset_str */ , + FalCodeRegion** /* cr */ , + int* /* num_cr */ +#endif +) ; + +extern int FalGetUDCGIArea( +#if NeedFunctionPrototypes + char* /* locale */ , + int /* codeset */ , + char* /* charset_str */ , + FalGlyphRegion** /* gr */ , + int* /* num_gr */ +#endif +) ; + +extern FalFontID FalOpenFont() ; + +/* + * Code set + */ +#define FALGETFALCODESET( cd_set ) ( ((cd_set)==-1) ? FAL_FONT_GLYPH_INDEX : (cd_set)+1 ) + +#define FALCODESETTONUM( cd_set ) ( ((cd_set)==FAL_FONT_GLYPH_INDEX) ? -1 : (cd_set)-1 ) + +/* + * fal_utyerrno + */ +#define FAL_FUNCNUM_GFLST 0x0 +#define FAL_FUNCNUM_SRCHFNM 0x0 +#define FAL_FUNCNUM_OPNFNT 0x0 +#define FAL_FUNCNUM_FRFLST 0x0 +#define FAL_FUNCNUM_RDFNT 0x0 +#define FAL_FUNCNUM_QRY 0x0 +#define FAL_FUNCNUM_FID 0x0 +#define FAL_FUNCNUM_IDTOFNM 0x0 +#define FAL_FUNCNUM_CLSFNT 0x0 +#define FAL_FUNCNUM_CPA 0x0 +#define FAL_FUNCNUM_GIA 0x0 +#define FAL_FUNCNUM_FREE 0x0 + +#define FAL_ERR_NON 0x00 + +#define FAL_ERR_FNT_OPN 0x01 +#define FAL_ERR_FNT_RD 0x02 +#define FAL_ERR_MALLOC 0x03 +#define FAL_ERR_PARM 0x04 +#define FAL_ERR_STAT 0x05 +#define FAL_ERR_FONT 0x06 +#define FAL_ERR_FDATA_OPN 0x07 +#define FAL_ERR_FDATA_RD 0x08 +#define FAL_ERR_FDATA_DSC 0x09 +#define FAL_ERR_FPATH 0x0a + +#define FAL_ERR_FNTDIR_OPN 0x0b +#define FAL_ERR_FNTDIR_RD 0x0c +#define FAL_ERR_PROP_RD 0x0d +#define FAL_ERR_PROP_FONT 0x0e +#define FAL_ERR_PROP_FNAME 0x0f +#define FAL_ERR_LCKD 0x10 +#define FAL_ERR_FILELCK 0x11 +#define FAL_ERR_FILEUNLCK 0x12 +#define FAL_ERR_FILEGETLCK 0x13 +#define FAL_ERR_NOFONT 0x14 + +#define FAL_ERR_XLC_CRTDB 0x15 +#define FAL_ERR_XLC_GETCHARST 0x16 +#define FAL_ERR_XLC_NOCHARST 0x17 + +#define FAL_ERR_FID_RD 0x18 +#define FAL_ERR_FATAL 0x19 + + +#ifdef __cplusplus +} +#endif +#endif /* _FALIB_H */ diff --git a/cde/programs/dtudcfonted/include/bdfgpf.h b/cde/programs/dtudcfonted/include/bdfgpf.h new file mode 100644 index 00000000..196a5746 --- /dev/null +++ b/cde/programs/dtudcfonted/include/bdfgpf.h @@ -0,0 +1,616 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: bdfgpf.h /main/7 1996/06/25 20:08:09 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include "udccom.h" + +struct btophead { + char *in_file; + char *out_file; + char *text_file; + FILE *input; + FILE *output; + int num_chars; + int p_width; + int p_height; + int bdf_width; + int bdf_height; + + int bdf_x; + int bdf_y; + float bdf_point; + int bdf_xdpi; + int *code; + char **ptn; + int zoomf; + + int code_category; + int start_code; + int end_code; +}; + +struct ptobhead { + char *in_file; + char *out_file; + char *bdf_file; + char *snf_file; + FILE *input; + FILE *output; + int num_chars; + int p_width; + int p_height; + int bdf_width; + int bdf_height; + + int bdf_x; + int bdf_y; + float bdf_point; + int bdf_xdpi; + + int reserve ; + int *code; + char **ptn; + int zoomf; + + int code_category; + int start_code; + int end_code; + +}; + +#define MIN_CODE 0x0000 +#define MAX_CODE 0xFFFF + +#define ALL_CODE 0 + +extern char *oakgtobdf; +extern char *bdftosnf; +extern char *bdftopcf; + + + +#define TAB_CD 0x09 +#define USE_ORG_SIZE -1 +#define MAX_FONT_WIDTH 999 +#define MIN_FONT_WIDTH 2 +#define MAX_FONT_HEIGHT 999 +#define MIN_FONT_HEIGHT 2 + +#ifdef BUFSIZE +#undef BUFSIZE +#endif /* BUFSIZE */ +#define BUFSIZE 1024 + +/* KeyWord for BDF file */ + +#define STARTFONT "STARTFONT " +#define STARTFONTsz 10 +#define FONTBOUNDINGBOX "FONTBOUNDINGBOX " +#define FONTBOUNDINGBOXsz 16 +#define SIZE "SIZE " +#define SIZEsz 5 +#define CHARS "CHARS " +#define CHARSsz 6 +#define STARTCHAR "STARTCHAR " +#define STARTCHARsz 10 +#define ENCODING "ENCODING " +#define ENCODINGsz 9 +#define BITMAP "BITMAP" +#define BITMAPsz 6 +#define ENDCHAR "ENDCHAR" +#define ENDCHARsz 7 +#define ENDFONT "ENDFONT" +#define ENDFONTsz 7 + +#define CHARSET_REGISTRY "CHARSET_REGISTRY " +#define CHARSET_REGISTRYsz 17 + + +/* KeyWord for GPF file */ + +#define NUMFONTS "numfonts:" +#define NUMFONTSsz 9 +#define WIDTH "width:" +#define WIDTHsz 6 +#define HEIGHT "height:" +#define HEIGHTsz 7 +#define CODE "code:" +#define CODEsz 5 +#define ENDDATA "enddata" +#define ENDDATAsz 7 + +#define FILE_END 99 + +#define FATAL_ERROR -1 +#define BDF_OPEN -2 +#define BDF_OPEN_IN -2 +#define BDF_READ -3 +#define BDF_WRITE -4 +#define BDF_INVAL -5 +#define GPF_OPEN -6 +#define GPF_OPEN_IN -6 +#define GPF_READ -7 +#define GPF_WRITE -8 +#define GPF_INVAL -9 +#define PARAM_ERROR -10 + +#define BDF_OPEN_OUT -11 +#define GPF_OPEN_OUT -12 +#define BDF_OPEN_HEAD -13 +#define BDF_READ_HEAD -14 + +/* system_ call error */ +#define MALLOC_ERROR -15 +#define FORK_ERROR -16 +#define EXEC_ERROR -17 +#define PIPE_ERROR -18 +#define DUP_ERROR -19 +#define POPEN_ERROR -20 +#define PCLOSE_ERROR -21 +#define FDOPEN_ERROR -22 +#define STAT_ERROR -23 +#define MKTMP_ERROR -24 + +#define PCFFONTC_ERROR -25 +#define SNFFONTC_ERROR -26 + +#define SCAN_TO_NONSP(p) {\ + while (*(p) != 0) {\ + if ((*(p) == ' ') || (*(p) == TAB_CD) || (*(p) == 0xa1)) {\ + (p)++;\ + } else {\ + break;\ + }\ + }\ +} + +#define SCAN_TO_SP(p) {\ + while (*(p) != 0) {\ + if ((*(p) == ' ') || (*(p) == TAB_CD) || (*(p) == 0xa1)) {\ + break;\ + } else {\ + (p)++;\ + }\ + }\ +} + + +#if defined( SVR4 ) || defined( SYSV ) +#define WaitID( chld_pid, chld_stat ) waitpid( (chld_pid), &(chld_stat), WUNTRACED ) +#else +#define WaitID( chld_pid, chld_stat ) {\ + for(;;){\ + int rtn ;\ + rtn = wait3( &(chld_stat), WUNTRACED, NULL );\ + if( rtn == (chld_pid) ) break ;\ + if( rtn == -1 ){\ + if( errno == EINTR ) continue ;\ + else break ;\ + }\ + }\ +} +#endif + +#ifndef DEFAULT_CODESET +#define DEFAULT_CODESET "3" +#endif + +/* + * tempory file + */ +#define TempFileKey "XXXXXX" +#define TEMPFILEKEY TempFileKey +#ifndef DEFAULT_TMPPATH +#define DEFAULT_TMPPATH "/var/tmp/" +#endif /* DEFAULT_TMPPATH */ + +/* + * Function prototypes + */ +extern int falcom_atoi( +#if NeedFunctionPrototypes + char* /* str */, + char /* ed_cod */, + int* /* val */ +#endif +); + +extern int GetDefaultFile( +#if NeedFunctionPrototypes + int /* size */, + char* /* style */, + char* /* fname */ +#endif +); + +extern int get_default_file( +#if NeedFunctionPrototypes + FILE* /* fp */, + int /* size */, + char* /* style */, + char* /* fname */ +#endif +); + +extern char *falcom_get_base_name( +#if NeedFunctionPrototypes + char* /* str */ +#endif +); + +extern int GetFileName( +#if NeedFunctionPrototypes + char* /* com */, + char* /* size_str */, + char* /* style */, + int /* codeset */, + char* /* ofile */ +#endif +); + +extern void ErrMsgTable_FalGetFontList( +#if NeedFunctionPrototypes + char* /* com */, + int /* utyerr */, + int /* utyderr */ +#endif +); + +extern void fal_cut_tailslash( +#if NeedFunctionPrototypes + char* /* name */ +#endif +); + +extern char *GetRealFileName( +#if NeedFunctionPrototypes + char* /* name */ +#endif +); + +extern int IsInRegion( +#if NeedFunctionPrototypes + int /* code */, + int /* num_gr */, + FalGlyphRegion* /* gr */ +#endif +); + +extern int GetUdcFileName( +#if NeedFunctionPrototypes + char* /* com */, + int /* code_no */, + char* /* xlfdname */, + char* /* fname */ +#endif +); + +extern int GetUdcRegion( +#if NeedFunctionPrototypes + char* /* com */, + int /* codeset */, + char* /* gpf_file */, + int* /* num_gr */, + FalGlyphRegion** /* gr */ +#endif +); + +extern int DispUdcCpArea( +#if NeedFunctionPrototypes + FILE* /* fp */ +#endif +); + +extern int GetUdcFontName( +#if NeedFunctionPrototypes + char* /* gpf_file */, + char* /* bdf_file */, + char** /* fontname */ +#endif +); + +extern int FileLock( +#if NeedFunctionPrototypes + int /* fd */ +#endif +); + +extern int FileUnLock( +#if NeedFunctionPrototypes + int /* fd */ +#endif +); + +extern int isLock( +#if NeedFunctionPrototypes + int /* fd */ +#endif +); + +extern int ReadBdfHeader( +#if NeedFunctionPrototypes + struct btophead* /* head */, + char* /* buf */ +#endif +); + +extern int ReadGpfHeader( +#if NeedFunctionPrototypes + struct ptobhead* /* head */, + char* /* buf */ +#endif +); + +extern int WriteBdfHeader( +#if NeedFunctionPrototypes + struct ptobhead* /* head */ +#endif +); + +extern void WriteGpfHeader( +#if NeedFunctionPrototypes + struct btophead* /* head */ +#endif +); + +extern int WritePtnToBdf( +#if NeedFunctionPrototypes + struct ptobhead* /* head */ +#endif +); + +extern int putDefaultChars( +#if NeedFunctionPrototypes + struct ptobhead* /* head */ +#endif +); + +extern int WritePtnToGpf( +#if NeedFunctionPrototypes + struct btophead* /* head */ +#endif +); + +extern int ReadBdfToMemory( +#if NeedFunctionPrototypes + struct btophead* /* head */, + char* /* buf */ +#endif +); + +extern int ReadBdfToMemory_with_init( +#if NeedFunctionPrototypes + struct btophead* /* head */, + int /* init_start */, + int /* init_end */, + char* /* buf */ +#endif +); + +extern int GetBdfCode( +#if NeedFunctionPrototypes + struct btophead* /* head */, + char* /* buf */, + int* /* code */ +#endif +); + +extern int GetBdfPtn( +#if NeedFunctionPrototypes + struct btophead* /* head */, + char* /* buf */, + char* /* ptn */, + int /* mwidth */, + int /* bsize */ +#endif +); + +extern int ReadGpfToMemory( +#if NeedFunctionPrototypes + struct ptobhead* /* head */, + char* /* buf */ +#endif +); + +extern int GetGpfCode( +#if NeedFunctionPrototypes + struct ptobhead* /* head */, + char* /* buf */, + int* /* code */ +#endif +); + +extern int GetGpfPtn( +#if NeedFunctionPrototypes + struct ptobhead* /* head */, + char* /* buf */, + char* /* ptn */, + int /* mwidth */, + int /* bsize */ +#endif +); + +extern void GetBdfLinePtn( +#if NeedFunctionPrototypes + char* /* mem */, + char* /* buf */, + int /* width */ +#endif +); + +extern void GetGpfLinePtn( +#if NeedFunctionPrototypes + char* /* mem */, + char* /* buf */, + int /* width */ +#endif +); + +extern int PutBdfPtn( +#if NeedFunctionPrototypes + unsigned char* /* ptn */, + int /* width */, + int /* height */, + FILE* /* fp */ +#endif +); + +extern int PutGpfPtn( +#if NeedFunctionPrototypes + char* /* ptn */, + int /* width */, + int /* height */, + FILE* /* fp */ +#endif +); + +extern int PtnZoom( +#if NeedFunctionPrototypes + char* /* dmem */, + char* /* smem */, + int /* sw */, + int /* sh */, + int /* dw */, + int /* dh */ +#endif +); + +extern char *GetTmpPath( +#if NeedFunctionPrototypes + char* /* path */ +#endif +); + +extern int ChkNumString( +#if NeedFunctionPrototypes + char* /* str */ +#endif +); + +extern void ErrMsgTable_AndExit( +#if NeedFunctionPrototypes + int /* er_no */, + char* /* snf_in */, + char* /* snf_out */, + char* /* gpf_in */, + char* /* gpf_out */, + char* /* bdf_in */, + char* /* prog_name */ +#endif +); + +extern void fatal_err_msg( +#if NeedFunctionPrototypes + int /* er_no */, + char* /* prog_name */ +#endif +); + +extern void ChatchSig() ; + +extern void Put_File_Create_Err_Msg( +#if NeedFunctionPrototypes + int /* msg_level */, + char* /* org_name */, + char* /* tmp_name */, + char* /* save_name */, + char* /* com */ +#endif +); + +extern int Make_NewFefFile( +#if NeedFunctionPrototypes + char* /* org_name */, + char* /* tmp_name */, + mode_t /* mode */, + uid_t /* owner */, + gid_t /* group */, + char* /* com */ +#endif +); + +extern int Unlink_Tmpfile( +#if NeedFunctionPrototypes + char* /* file */, + char* /* com */ +#endif +); + +extern int Chmod_File ( +#if NeedFunctionPrototypes + char* /* fname */, + mode_t /* mode */, + char* /* com */ +#endif +); + +extern int Chown_File ( +#if NeedFunctionPrototypes + char* /* fname */, + uid_t /* owner */, + gid_t /* group */, + char* /* com */ +#endif +); + +extern int ChkPcfFontFile( +#if NeedFunctionPrototypes + char* /* filename */ +#endif +); + +extern int ChkSnfFontFile( +#if NeedFunctionPrototypes + char* /* filename */ +#endif +); + +extern char *get_cmd_path( +#if NeedFunctionPrototypes + char* /* path */, + char* /* cmd */ +#endif +); + +extern int SetCmdPath( +#if NeedFunctionPrototypes + char* /* com */, + char** /* path */, + char* /* dflt_path */, + char* /* cmd */ +#endif +); + +extern int +Link_NewFile( +#if NeedFunctionPrototypes + char * /* rd_file */, + char * /* wr_file */ +#endif +) ; diff --git a/cde/programs/dtudcfonted/include/snfstruct.h b/cde/programs/dtudcfonted/include/snfstruct.h new file mode 100644 index 00000000..c796bef3 --- /dev/null +++ b/cde/programs/dtudcfonted/include/snfstruct.h @@ -0,0 +1,121 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: snfstruct.h /main/2 1996/02/10 16:25:06 cde-fuj $ */ +/*********************************************************** +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, +and the Massachusetts Institute of Technology, Cambridge, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Digital or MIT not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +(c) Copyright 1995 FUJITSU LIMITED +This is source code modified by FUJITSU LIMITED under the Joint +Development Agreement for the CDEnext PST. +This is unpublished proprietary source code of FUJITSU LIMITED + +******************************************************************/ +#ifndef SNFSTRUCT_H +#define SNFSTRUCT_H 1 +#include "font.h" +#include "misc.h" +#include + +/* + * This file describes the Server Natural Font format. + * SNF fonts are both CPU-dependent and frame buffer bit order dependent. + * This file is used by: + * 1) the server, to hold font information read out of font files. + * 2) font converters + * + * Each font file contains the following + * data structures, with no padding in-between. + * + * 1) The XFONTINFO structure + * hand-padded to a two-short boundary. + * maxbounds.byteoffset is the total number of bytes in the + * glpyh array + * maxbounds.bitOffset is thetotal width of the unpadded font + * + * 2) The XCHARINFO array + * indexed directly with character codes, both on disk + * and in memory. + * + * 3) Character glyphs + * padded in the server-natural way, and + * ordered in the device-natural way. + * End of glyphs padded to 32-bit boundary. + * + * 4) nProps font properties + * + * 5) a sequence of null-terminated strings, for font properties + */ + +#define FONT_FILE_VERSION 4 + +typedef struct _FontProp { + CARD32 name; /* offset of string */ + INT32 value; /* number or offset of string */ + Bool indirect; /* value is a string offset */ +} FontPropRec; + +/* + * the following macro definitions describe a font file image in memory + */ +#define ADDRCharInfoRec( pfi) \ + ((CharInfoRec *) &(pfi)[1]) + +#define ADDRCHARGLYPHS( pfi) \ + (((char *) &(pfi)[1]) + BYTESOFCHARINFO(pfi)) + +/* + * pad out glyphs to a CARD32 boundary + */ +#define ADDRXFONTPROPS( pfi) \ + ((DIXFontProp *) ((char *)ADDRCHARGLYPHS( pfi) + BYTESOFGLYPHINFO(pfi))) + +#define ADDRSTRINGTAB( pfi) \ + ((char *)ADDRXFONTPROPS( pfi) + BYTESOFPROPINFO(pfi)) + +#define BYTESOFFONTINFO(pfi) (sizeof(FontInfoRec)) +#define BYTESOFCHARINFO(pfi) (sizeof(CharInfoRec) * n2dChars(pfi)) +#define BYTESOFPROPINFO(pfi) (sizeof(FontPropRec) * (pfi)->nProps) +#define BYTESOFSTRINGINFO(pfi) ((pfi)->lenStrings) +#define BYTESOFGLYPHINFO(pfi) (((pfi)->maxbounds.byteOffset+3) & ~0x3) +#define BYTESOFINKINFO(pfi) (sizeof(CharInfoRec) * (2 + n2dChars(pfi))) + +#endif /* SNFSTRUCT_H */ diff --git a/cde/programs/dtudcfonted/include/udccom.h b/cde/programs/dtudcfonted/include/udccom.h new file mode 100644 index 00000000..8e9dd4bb --- /dev/null +++ b/cde/programs/dtudcfonted/include/udccom.h @@ -0,0 +1,70 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: udccom.h /main/5 1996/07/19 20:31:51 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#include "udcopt.h" + +/* default path of dtaddcpf */ +#define DFLTPATH "/usr/dt/lib/dtudcfonted/dtaddcpf" +#define DFLTCMD "dtaddcpf" + +/* commands for exchange font format */ +#define SNFTOBDF_CMD "dtgpftobdf" +#define BDFTOPCF_CMD "bdftopcf" + +/* default path for commands */ +#define SNFTOBDF "/usr/dt/lib/dtudcfonted/dtgpftobdf" +#ifndef FONTC +#define BDFTOPCF "/usr/bin/X11/bdftopcf" +#else +#define BDFTOPCF FONTC +#endif +#define PCFTOBDF SNFTOBDF + +/* suffix of font file */ +#define BDFSUFFIX ".bdf" +#define PCFSUFFIX ".pcf" + +/* font information file */ +#define DTUDCFONTS "DTUDCFONTS" + +#ifndef DTUDCFONTSLISTDIR +#define DTUDCFONTSLISTDIR "/usr/dt/config" +#endif + +/* default font path */ +#ifndef DTUDCFONTPATH +#define DTUDCFONTPATH "/usr/lib/X11/fonts/misc" +#endif + +/* defines for UDC fonts */ +#define FONTS_LIST_FILE "fonts.list" +#define UDFLIST_DEF "udflist.def" + +#define FONTSDIR "fonts.dir" diff --git a/cde/programs/dtudcfonted/include/udcopt.h b/cde/programs/dtudcfonted/include/udcopt.h new file mode 100644 index 00000000..810d754e --- /dev/null +++ b/cde/programs/dtudcfonted/include/udcopt.h @@ -0,0 +1,269 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: udcopt.h /main/4 1996/11/08 01:59:43 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +/*********************************************************************** + * SNF format font + **********************************************************************/ +#define BDFTOSNF_CMD "bdftosnf" +#ifndef SNFFONTC +#define BDFTOSNF "/usr/bin/X11/bdftosnf" +#else +#define BDFTOSNF SNFFONTC +#endif +#define SNFSUFFIX ".snf" + +#define FONT_FILE_PARM 0 + +#define COMM_SNF_POPEN( permission, snf_file, out_file, ep, buf, command ) { \ + snprintf( (buf), sizeof((buf)), " -i " ) ; \ + snprintf( (command), sizeof((command)), "%s %s > %s", bdftosnf, (buf), (out_file) ); \ +} +#define COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) { \ + read( (snf_fd), (buf), sizeof(FontInfoRec) ); \ + close( (snf_fd) ); \ + (finf) = (FontInfoRec *) (buf) ; \ + if( \ + ((finf)->version1 != FONT_FILE_VERSION) || \ + ((finf)->version2 != FONT_FILE_VERSION) \ + ) \ + (permission) = -1 ; \ +} +#define COMM_SNF_NEWTARGET( permission ) (permission) = 0 +#define COMM_SNF_EXECLBDFTOSNF( permission, buf, snf_file ) { \ + execl( bdftosnf, bdftosnf, "-i", 0 ); \ +} +#define COMM_SNF_GETHEADER( fip, fp ) { \ + (fip) = (FontInfoRec *)(fp); \ +} + +#define FAL_FONT_PRM 0 +#define CHK_PROTECT_KEY( protect_key_data, openfontfile,\ + fal_utyerror, fal_utyderror ) +/* case of a snf former font */ +#define FAL_GET_SNF_HEADER( buf, protect_key_data, fal_utyerror, fal_utyderror, fd, finf, openfontfile ) { \ + (finf)->pFinf = ( FontInfoPtr )(buf); \ + if ( \ + ((finf)->pFinf->version1 != (finf)->pFinf->version2) || \ + ((finf)->pFinf->version1 != FONT_FILE_VERSION) \ + ) { \ + set_errfile_str( fal_err_file, (openfontfile) ) ; \ + (fal_utyerror) = _FAL_FONT_ER; \ + (fal_utyderror) = 0; \ + fal_utyerrno = FAL_ERR_FONT ; \ + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; \ + goto FalError01 ; \ + } else { \ + (finf)->isFef = TRUE ; \ + (finf)->isPcf = FALSE; \ + } \ +} + +/* falReadGpfProp() */ +#define FAL_READ_SNF_HEADER( finf, protect_key_data, fal_utyerror, fal_utyderror ) { \ + (finf)->isFef = TRUE; \ + (finf)->isPcf = FALSE; \ + (finf)->pFinf = ( FontInfoPtr )(finf)->buf ; \ + if ( /* not a snf or fef format */ \ + ((finf)->pFinf->version1 != (finf)->pFinf->version2) || \ + ((finf)->pFinf->version1 != FONT_FILE_VERSION) \ + ) { \ + return _FAL_TRY_NEXT ; \ + } \ +} + +#define ISOPTFONT( file ) 1 + +/*********************************************************************** + * glyph index + **********************************************************************/ +#define SHIFTMASK 0x7F7F +#define SHIFT_OFF(co) (co) +#define SHIFT_ON(co) (co) +#define DEFAULTCHAR 0x2121 +#define CONVGLYPHINDEX( code ) (code) + +#define DISPCODEPOINT( char_set, code ) (code) + +#define FAL_OPT_CONVGITOCP( codeset, code ) +#define FAL_OPT_CONVCPTOGI( codeset, code ) + +/*********************************************************************** + * options for commands + **********************************************************************/ +#define NORMAL 0 +#define SYSTM 1 + +#define CDSET1 (1<<2) + +/* UDC code area */ +#define IN_CODE( cc, co ) (( cc ) ? 1 : 1 ) + +/* libfuty */ +#define COMM_SBOPT_CHECKSBOPT( com, code_area ) + +#define COMM_SBOPT_STRCMP( argv, cnt ) (((argv)[(cnt)] ? 0 : 0 )) +#define COMM_SBOPT_SETSBOPT( codearea ) + +#define COMM_TYPE_STRCMP( argv, cnt ) ( ((argv)[(cnt)] ? 0 : 0 )) +#define COMM_TYPE_SETTYPE( argc, argv, cnt, type ) + +/*********************************************************************** + * options for commands + **********************************************************************/ +#define COMM_SETDEFAULTSTYLE( style ) (style) = (char *)NULL + +#define COMM_SETSTYLE_TO_FONTDATA( style, key, mask ) { \ + if( style ) { \ + char stylebuf[ BUFSIZE ] ; \ + snprintf( stylebuf, sizeof(stylebuf), "%s", style ) ; \ + key.style.name = stylebuf ; \ + mask |= FAL_FONT_MASK_STYLE_NAME ; \ + } \ +} +#define COMM_ISDEFAULTCHAR( code ) 0 + +#define get_charset_registry(head, p) +#define put_default_chars(head, nchar, rtn) {\ + if ( !(nchar) ) \ + {\ + (nchar)++;\ + fprintf( (head)->output, "CHARS %d\n", (nchar) );\ + if ( ( (rtn) = putDefaultChars( (head) ) ) != 0 ) {\ + return (rtn);\ + }\ + } else {\ + fprintf( (head)->output, "CHARS %d\n", (nchar) );\ + }\ +} +#define put_default_encode( head ) {\ + fprintf((head)->output, "STARTCHAR %04x\n", DEFAULTCHAR );\ + fprintf((head)->output, "ENCODING %d\n", DEFAULTCHAR );\ +} +#define put_default_bitmap(head, bytew, posbit, i, j, ptnbuf, ptnbuf2, tmp) { \ + for ((i) = 0; (i) < (bytew); (i)++) \ + *((ptnbuf) + (i)) = (unsigned char)0x00;\ + for ((j) = 0; (j) < (head)->bdf_height; (j)++) {\ + for ((i) = 0; (i) < (bytew); (i)++) \ + fprintf((head)->output, "%.2x", *((ptnbuf) + (i)));\ + fprintf((head)->output, "\n");\ + }\ +} +#define COMM_SBFNT_ISSBFNT( p ) 0 +#define COMM_SBFNT_CONVCODETOGI( char_set, head ) +#define COMM_SBFNT_SETUDCAREA( com, head, char_set, code_area, num_gr, gr ) { \ + (head).code_category = ALL_CODE ; \ + (head).start_code = (gr)[0].start ; \ + (head).end_code = (gr)[(num_gr)-1].end ; \ +} +#define COMM_SET_CODESET( codeset, code_area ) +#define COMM_SET_CODECATEGORY( char_set, code_area, head ) + +/* + * help message + */ +#define COMM_HELP_MSG { \ + USAGE(" [-codeset number] [-help]\n"); \ + USAGE("\n"); \ +} +#define COMM_DSP_LETTER_T +#define COMM_DSP_PRM +#define COMM_HELP_MSG_STYLE USAGE("style (The default value is mincho style.)\n") + +/*********************************************************************** + * Options for libfal + **********************************************************************/ +#define COMM_SBCHR_SETFONTDATA( data, mask ) +#define COMM_SBCHR_STRDUP_P( data, odata ) + +#define FAL_DB_OPTION static FalFontDB *fal_db_opt +#define CHK_KEY_STR_OPTION( mask, key, flg ) +#define FAL_FREE_FONTLIST_OPTION( list ) +#define FAL_CLEAR_DATA_OPTION( tmp ) +#define SET_STRUCT_OPTION( dup_p, elm, tmp_data, fal_utyerror, fal_db_group ) +#define FAL_EQ_DATA_OPTION( flg, data, tmp_data ) +#define FAL_CMP_DATA_OPTION( mask, op1, key ) +#define DEF_STR_CHK struct { int style, shape; }str_chk +#define DEF_STR_SET { \ + str_chk.style = 0; \ + str_chk.shape = 0; \ +} + +#define NEW_TARGET_SET( diff, choose, target, str_chk ) +#define NEW_TARGET_CHK( diff, choose, target, str_chk ) + + +/*********************************************************************** + * udflist.def + **********************************************************************/ +#define COMM_GET_DEFAULTFILE_ERROR( buf, com, ret, height, style, list_d, list_c, list_l, statbuf ) {\ + buf[0] = '\0' ;\ +} +#define COMM_DISPERRORFILE( com, lst, style, i, size_str ) {\ + USAGE1("%s : Two or more corresponding user defined characters exist.\n", com);\ + USAGE("\tcode set\tXLFD\n" );\ + USAGE("\t--------------------------------------------------\n" );\ + for ( i = 0 ; i < lst->num; i++ ) {\ + USAGE2("\t%d\t%s\n", lst->list[i].cd_set-1, lst->list[i].xlfdname );\ + }\ +} + +/*********************************************************************** + * fonts.list + **********************************************************************/ +#define GETLISTFILEPATH( locale, srch_path, list_d, list_c, list_l, list_file ) { \ + if ( ( (locale) = getenv( "FAL_LANG" ) ) == NULL ) { \ + if( ((locale) = (char *)getenv( "LANG" )) == NULL ){\ + (locale) = "C" ;\ + }\ + } \ + if ( ( (srch_path) = getenv( DTUDCFONTS ) ) == NULL ) { \ + snprintf( (list_d), sizeof(list_d), "%s/%s", DTUDCFONTSLISTDIR, (list_file) ); \ + snprintf( (list_c), sizeof(list_c), "%s/C/%s", DTUDCFONTSLISTDIR, (list_file) ); \ + snprintf( (list_l), sizeof(list_l), "%s/%s/%s", DTUDCFONTSLISTDIR, (locale), (list_file) ); \ + } else { \ + snprintf( (list_d), sizeof(list_d), "%s/%s", (srch_path), (list_file) ); \ + snprintf( (list_c), sizeof(list_c), "%s/C/%s", (srch_path), (list_file) ); \ + snprintf( (list_l), sizeof(list_l), "%s/%s/%s", (srch_path), (locale), (list_file) ); \ + } \ +} + +#define SET_EXECDEFAULT( mask, def, undef ) { \ + if( !((mask) & FAL_FONT_MASK_DEFINED) && !((mask) & FAL_FONT_MASK_UNDEFINED) ){ \ + (def) = FALSE ; \ + (undef) = TRUE ; \ + }else{ \ + if( (mask) & FAL_FONT_MASK_DEFINED ) (def) = TRUE ; \ + else (def) = FALSE ; \ + if( (mask) & FAL_FONT_MASK_UNDEFINED ) (undef) = TRUE ; \ + else (undef) = FALSE ; \ + } \ +} + +/*************************< end of udcopt.h >**************************/ diff --git a/cde/programs/dtudcfonted/include/udcutil.h b/cde/programs/dtudcfonted/include/udcutil.h new file mode 100644 index 00000000..d9cb9df2 --- /dev/null +++ b/cde/programs/dtudcfonted/include/udcutil.h @@ -0,0 +1,147 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: udcutil.h /main/3 1996/11/08 01:58:55 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#ifndef PRINT_USAGE +#define USAGE(a) +#define USAGE1(a, b) +#define USAGE2(a, b, c) +#define USAGE3(a, b, c, d) +#define USAGE4(a, b, c, d, e) +#else +#define USAGE(a) fprintf(stderr, a) +#define USAGE1(a, b) fprintf(stderr, a, b) +#define USAGE2(a, b, c) fprintf(stderr, a, b, c) +#define USAGE3(a, b, c, d) fprintf(stderr, a, b, c, d) +#define USAGE4(a, b, c, d, e) fprintf(stderr, a, b, c, d, e) +#endif + +#define UDC_LINE_MAX 2048 + +/* macro for get character strings */ + +#define AllocString( str, orgstr, rtn ){ \ + (str) = (char *)malloc( sizeof(char) * (strlen((orgstr))+1) ) ;\ + if( !(str) ){\ + return( (rtn) ) ;\ + }\ + strcpy( (str), (orgstr) ) ;\ +} + +#define AddString( str, addstr, rtn ){ \ + (str) = (char *)realloc( (str), sizeof(char) * ( strlen((str)) + strlen((addstr)) + 1 ) ) ;\ + if( !(str) ){\ + return( (rtn) ) ;\ + }\ + strcat( (str), (addstr) ) ;\ +} + +#define ResizeString( str, rtn ){ \ + (str) = (char *)realloc( (str), sizeof(char) * ( strlen((str)) + 1 ) ) ;\ + if( !(str) ){\ + return( (rtn) ) ;\ + }\ +} + +#define FreeString( str ){ \ + if( (str) ) {\ + free( (str) ) ;\ + }\ + (str) = NULL ;\ +} + +/* access to "fonts.dir" */ + +#define XLFD_ELM_CNT 14 + +#define XLFD_ELM_FOUNDRY 1 +#define XLFD_ELM_FAMILY_NAME 2 +#define XLFD_ELM_WEIGHT_NAME 3 +#define XLFD_ELM_SLANT 4 +#define XLFD_ELM_SETWIDTH_NAME 5 +#define XLFD_ELM_ADD_STYLE_NAME 6 +#define XLFD_ELM_PIXEL_SIZE 7 +#define XLFD_ELM_POINT_SIZE 8 +#define XLFD_ELM_RESOLUTION_X 9 +#define XLFD_ELM_RESOLUTION_Y 10 +#define XLFD_ELM_SPACING 11 +#define XLFD_ELM_AVERAGE_WIDTH 12 +#define XLFD_ELM_CHARSET_REGISTRY 13 +#define XLFD_ELM_CHARSET_ENCODING 14 + + +static int udc_font_elm_cnt ; +static char udc_font_str_buffer[UDC_LINE_MAX] ; +static char *udc_font_sp ; + +#define POINTXLFDELM( sp, xlfdname, elm_num ) { \ + udc_font_sp = (xlfdname) ; \ + udc_font_elm_cnt = 0 ;\ + while(*udc_font_sp){\ + if(*udc_font_sp == '-') udc_font_elm_cnt++ ;\ + if( udc_font_elm_cnt == (elm_num) ){\ + break ;\ + }\ + udc_font_sp++ ;\ + }\ + (sp) = udc_font_sp ;\ +} + +#define GETXLFDELMSTR( sp, xlfdname, elm_num ) { \ + snprintf( udc_font_str_buffer, sizeof(udc_font_str_buffer), "%s", (xlfdname) ) ; \ + udc_font_sp = udc_font_str_buffer ; \ + udc_font_elm_cnt = 0 ;\ + while(*udc_font_sp){\ + if(*udc_font_sp == '-') udc_font_elm_cnt++ ;\ + if( udc_font_elm_cnt == (elm_num) ){\ + udc_font_sp++ ;\ + break ;\ + }\ + udc_font_sp++ ;\ + }\ + (sp) = udc_font_sp ;\ + while(*udc_font_sp){\ + if(*udc_font_sp == '-') udc_font_elm_cnt++ ;\ + if( udc_font_elm_cnt == (elm_num)+1 ){\ + *udc_font_sp = '\0' ;\ + break ;\ + }\ + udc_font_sp++ ;\ + }\ +} + +#define GETCHARSETSTR( char_set, xlfdname ) { \ + snprintf( udc_font_str_buffer, sizeof(udc_font_str_buffer), "%s", (xlfdname) ) ; \ + POINTXLFDELM( (char_set), udc_font_str_buffer, XLFD_ELM_CHARSET_REGISTRY ) ; \ + (char_set)++ ; \ +} + +#define GETSPACINGSTR( spacing, xlfdname ) { \ + GETXLFDELMSTR( (spacing), (xlfdname), XLFD_ELM_SPACING ) ; \ +} diff --git a/cde/programs/dtudcfonted/libfal/Imakefile b/cde/programs/dtudcfonted/libfal/Imakefile new file mode 100644 index 00000000..c8bdcfb4 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/Imakefile @@ -0,0 +1,84 @@ +XCOMM $XConsortium: Imakefile /main/16 1996/09/09 11:45:13 drk $ +#define DoNormalLib YES +#define DoSharedLib NO +#define DoDebugLib NO +#define DoProfileLib NO +#define LibName fal +#define LibHeaders NO +#define LibInstall NO + + FALDESTDIR = $(CDE_INSTALLATION_TOP) + FONTLIST = config + XLOCALEDIR = $(XPROJECTROOT)/lib/X11/locale + XFONTDIR = $(XPROJECTROOT)/lib/X11/fonts + +UDCFONTPATH = $(XFONTDIR)/misc +FALOPT1 = -DDTUDCFONTPATH='"'$(XFONTDIR)/misc'"' +FALOPT2 = -DXLOCALEDIR='"'$(XLOCALEDIR)'"' +FALOPT3 = -DDTUDCFONTSLISTDIR='"'$(FALDESTDIR)/$(FONTLIST)'"' + +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + + DEPEND_DEFINES = $(DEPENDDEFINES) + DEFINES = $(FALOPT1) $(FALOPT2) $(OPT2) $(FALOPT3) + + UDC_INC_PATH1 = -I./include + UDC_INC_PATH2 = -I../include + UDC_INC_PATH3 = -I./ + + INCLUDES = \ + $(UDC_INC_PATH1)\ + $(UDC_INC_PATH2)\ + $(UDC_INC_PATH3) + +SRCS1 = falfont.c readpcf.c \ + syncx.c + +SRCS2 = _faludcInf.c \ + _fallcCT.c _fallcCharSet.c _fallcConv.c _fallcDB.c \ + _fallcDefConv.c _fallcDynamic.c _fallcEuc.c _fallcFile.c \ + _fallcGenConv.c _fallcGeneric.c _fallcInit.c _fallcPrTxt.c \ + _fallcPubWrap.c _fallcPublic.c _fallcRM.c _fallcSjis.c \ + _fallcStd.c _fallcTxtPr.c _fallcUTF.c _fallcUtil.c \ + _fallcWrap.c \ + _falomGeneric.c _falQuarks.c _falSetLocale.c _falrm.c + +SRCS3 = _falutilbitmap.c + +SRCS = $(SRCS1) $(SRCS2) $(SRCS3) + +OBJS = falfont.o readpcf.o \ + syncx.o \ + _faludcInf.o \ + _fallcCT.o _fallcCharSet.o _fallcConv.o _fallcDB.o \ + _fallcDefConv.o _fallcDynamic.o _fallcEuc.o _fallcFile.o \ + _fallcGenConv.o _fallcGeneric.o _fallcInit.o _fallcPrTxt.o \ + _fallcPubWrap.o _fallcPublic.o _fallcRM.o _fallcSjis.o \ + _fallcStd.o _fallcTxtPr.o _fallcUTF.o _fallcUtil.o \ + _fallcWrap.o _falomGeneric.o _falQuarks.o _falSetLocale.o \ + _falrm.o \ + _falutilbitmap.o + +all:: + $(RM) fonts.list;\ + $(CP) ./fonts.list.header ./fonts.list ;\ + chmod ug+w fonts.list;\ + key=`echo $(UDCFONTPATH) | sed -e 's/:/ /g'` ; \ + for dir in $$key ; \ + do \ + echo $$dir: >> ./fonts.list ;\ + done + +#include + +install:: + if [ -d $(DESTDIR)/$(FALDESTDIR)/$(FONTLIST) ]; then set +x; \ + else (set -x; $(MKDIRHIER) $(DESTDIR)/$(FALDESTDIR)/$(FONTLIST)); fi ; \ + (set -x ; $(CP) ./fonts.list $(DESTDIR)/$(FALDESTDIR)/$(FONTLIST) ; \ + chmod 0644 $(DESTDIR)/$(FALDESTDIR)/$(FONTLIST)/fonts.list ) + +DependTarget() diff --git a/cde/programs/dtudcfonted/libfal/_falQuarks.c b/cde/programs/dtudcfonted/libfal/_falQuarks.c new file mode 100644 index 00000000..41d412bb --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falQuarks.c @@ -0,0 +1,456 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* Quarks.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:31:17 */ +/* $XConsortium: _falQuarks.c /main/2 1996/09/09 13:20:21 rswiston $ */ + +/*********************************************************** +Copyright 1987, 1988, 1990 by Digital Equipment Corporation, Maynard, + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ +/* + +Copyright (c) 1987, 1988, 1990 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +#include "_fallibint.h" +#include + +/* Not cost effective, at least for vanilla MIT clients */ +/* #define PERMQ */ + +typedef unsigned long Signature; +typedef unsigned long Entry; +#ifdef PERMQ +typedef unsigned char Bits; +#endif + +static XrmQuark nextQuark = 1; /* next available quark number */ +static unsigned long quarkMask = 0; +static Entry zero = 0; +static Entry *quarkTable = &zero; /* crock */ +static unsigned long quarkRehash; +static XrmString **stringTable = NULL; +#ifdef PERMQ +static Bits **permTable = NULL; +#endif +static XrmQuark nextUniq = -1; /* next quark from falrmUniqueQuark */ + +#define QUANTUMSHIFT 8 +#define QUANTUMMASK ((1 << QUANTUMSHIFT) - 1) +#define CHUNKPER 8 +#define CHUNKMASK ((CHUNKPER << QUANTUMSHIFT) - 1) + +#define LARGEQUARK ((Entry)0x80000000L) +#define QUARKSHIFT 18 +#define QUARKMASK ((LARGEQUARK - 1) >> QUARKSHIFT) +#define XSIGMASK ((1L << QUARKSHIFT) - 1) + +#define STRQUANTSIZE (sizeof(XrmString) * (QUANTUMMASK + 1)) +#ifdef PERMQ +#define QUANTSIZE (STRQUANTSIZE + \ + (sizeof(Bits) * ((QUANTUMMASK + 1) >> 3)) +#else +#define QUANTSIZE STRQUANTSIZE +#endif + +#define HASH(sig) ((sig) & quarkMask) +#define REHASHVAL(sig) ((((sig) % quarkRehash) + 2) | 1) +#define REHASH(idx,rehash) ((idx + rehash) & quarkMask) +#define NAME(q) stringTable[(q) >> QUANTUMSHIFT][(q) & QUANTUMMASK] +#ifdef PERMQ +#define BYTEREF(q) permTable[(q) >> QUANTUMSHIFT][((q) & QUANTUMMASK) >> 3] +#define ISPERM(q) (BYTEREF(q) & (1 << ((q) & 7))) +#define SETPERM(q) BYTEREF(q) |= (1 << ((q) & 7)) +#define CLEARPERM(q) BYTEREF(q) &= ~(1 << ((q) & 7)) +#endif + +/* Permanent memory allocation */ + +#define WALIGN sizeof(unsigned long) +#define DALIGN sizeof(double) + +#define NEVERFREETABLESIZE ((8192-12) & ~(DALIGN-1)) +static char *neverFreeTable = NULL; +static int neverFreeTableSize = 0; + +static char *permalloc(length) + register unsigned int length; +{ + char *ret; + + if (neverFreeTableSize < length) { + if (length >= NEVERFREETABLESIZE) + return Xmalloc(length); + if (! (ret = Xmalloc(NEVERFREETABLESIZE))) + return (char *) NULL; + neverFreeTableSize = NEVERFREETABLESIZE; + neverFreeTable = ret; + } + ret = neverFreeTable; + neverFreeTable += length; + neverFreeTableSize -= length; + return(ret); +} + +#ifndef WORD64 +typedef struct {char a; double b;} TestType1; +typedef struct {char a; unsigned long b;} TestType2; +#endif + +#ifdef XTHREADS +static char *_falpermalloc(); + +char *falpermalloc(length) + unsigned int length; +{ + char *p; + + _XLockMutex(_Xglobal_lock); + p = _falpermalloc(length); + _XUnlockMutex(_Xglobal_lock); + return p; +} +#define falpermalloc _falpermalloc + +static +#endif /* XTHREADS */ +char *falpermalloc(length) + unsigned int length; +{ + int i; + + if (neverFreeTableSize && length < NEVERFREETABLESIZE) { +#ifndef WORD64 + if ((sizeof(TestType1) != + (sizeof(TestType2) - sizeof(unsigned long) + sizeof(double))) && + !(length & (DALIGN-1)) && + (i = (NEVERFREETABLESIZE - neverFreeTableSize) & (DALIGN-1))) { + neverFreeTableSize -= DALIGN - i; + neverFreeTable += DALIGN - i; + } else +#endif + if (i = (NEVERFREETABLESIZE - neverFreeTableSize) & (WALIGN-1)) { + neverFreeTableSize -= WALIGN - i; + neverFreeTable += WALIGN - i; + } + } + return permalloc(length); +} + +static Bool +ExpandQuarkTable() +{ + unsigned long oldmask, newmask; + register char c, *s; + register Entry *oldentries, *entries; + register Entry entry; + register int oldidx, newidx, rehash; + Signature sig; + XrmQuark q; + + oldentries = quarkTable; + if (oldmask = quarkMask) + newmask = (oldmask << 1) + 1; + else { + if (!stringTable) { + stringTable = (XrmString **)Xmalloc(sizeof(XrmString *) * + CHUNKPER); + if (!stringTable) + return False; + stringTable[0] = (XrmString *)NULL; + } +#ifdef PERMQ + if (!permTable) + permTable = (Bits **)Xmalloc(sizeof(Bits *) * CHUNKPER); + if (!permTable) + return False; +#endif + stringTable[0] = (XrmString *)falpermalloc(QUANTSIZE); + if (!stringTable[0]) + return False; +#ifdef PERMQ + permTable[0] = (Bits *)((char *)stringTable[0] + STRQUANTSIZE); +#endif + newmask = 0x1ff; + } + entries = (Entry *)Xmalloc(sizeof(Entry) * (newmask + 1)); + if (!entries) + return False; + bzero((char *)entries, sizeof(Entry) * (newmask + 1)); + quarkTable = entries; + quarkMask = newmask; + quarkRehash = quarkMask - 2; + for (oldidx = 0; oldidx <= oldmask; oldidx++) { + if (entry = oldentries[oldidx]) { + if (entry & LARGEQUARK) + q = entry & (LARGEQUARK-1); + else + q = (entry >> QUARKSHIFT) & QUARKMASK; + for (sig = 0, s = NAME(q); c = *s++; ) + sig = (sig << 1) + c; + newidx = HASH(sig); + if (entries[newidx]) { + rehash = REHASHVAL(sig); + do { + newidx = REHASH(newidx, rehash); + } while (entries[newidx]); + } + entries[newidx] = entry; + } + } + if (oldmask) + Xfree((char *)oldentries); + return True; +} + +#if NeedFunctionPrototypes +XrmQuark _falrmInternalStringToQuark( + register _Xconst char *name, register int len, register Signature sig, + Bool permstring) +#else +XrmQuark _falrmInternalStringToQuark(name, len, sig, permstring) + register XrmString name; + register int len; + register Signature sig; + Bool permstring; +#endif +{ + register XrmQuark q; + register Entry entry; + register int idx, rehash; + register int i; + register char *s1, *s2; + char *new; + + rehash = 0; + idx = HASH(sig); + _XLockMutex(_Xglobal_lock); + while (entry = quarkTable[idx]) { + if (entry & LARGEQUARK) + q = entry & (LARGEQUARK-1); + else { + if ((entry - sig) & XSIGMASK) + goto nomatch; + q = (entry >> QUARKSHIFT) & QUARKMASK; + } + for (i = len, s1 = (char *)name, s2 = NAME(q); --i >= 0; ) { + if (*s1++ != *s2++) + goto nomatch; + } + if (*s2) { +nomatch: if (!rehash) + rehash = REHASHVAL(sig); + idx = REHASH(idx, rehash); + continue; + } +#ifdef PERMQ + if (permstring && !ISPERM(q)) { + Xfree(NAME(q)); + NAME(q) = (char *)name; + SETPERM(q); + } +#endif + _XUnlockMutex(_Xglobal_lock); + return q; + } + if (nextUniq == nextQuark) + goto fail; + if ((nextQuark + (nextQuark >> 2)) > quarkMask) { + if (!ExpandQuarkTable()) + goto fail; + _XUnlockMutex(_Xglobal_lock); + return _falrmInternalStringToQuark(name, len, sig, permstring); + } + q = nextQuark; + if (!(q & QUANTUMMASK)) { + if (!(q & CHUNKMASK)) { + if (!(new = Xrealloc((char *)stringTable, + sizeof(XrmString *) * + ((q >> QUANTUMSHIFT) + CHUNKPER)))) + goto fail; + stringTable = (XrmString **)new; +#ifdef PERMQ + if (!(new = Xrealloc((char *)permTable, + sizeof(Bits *) * + ((q >> QUANTUMSHIFT) + CHUNKPER)))) + goto fail; + permTable = (Bits **)new; +#endif + } + new = falpermalloc(QUANTSIZE); + if (!new) + goto fail; + stringTable[q >> QUANTUMSHIFT] = (XrmString *)new; +#ifdef PERMQ + permTable[q >> QUANTUMSHIFT] = (Bits *)(new + STRQUANTSIZE); +#endif + } + if (!permstring) { + s2 = (char *)name; +#ifdef PERMQ + name = Xmalloc(len+1); +#else + name = permalloc(len+1); +#endif + if (!name) + goto fail; + for (i = len, s1 = (char *)name; --i >= 0; ) + *s1++ = *s2++; + *s1++ = '\0'; +#ifdef PERMQ + CLEARPERM(q); + } + else { + SETPERM(q); +#endif + } + NAME(q) = (char *)name; + if (q <= QUARKMASK) + entry = (q << QUARKSHIFT) | (sig & XSIGMASK); + else + entry = q | LARGEQUARK; + quarkTable[idx] = entry; + nextQuark++; + _XUnlockMutex(_Xglobal_lock); + return q; + fail: + _XUnlockMutex(_Xglobal_lock); + return NULLQUARK; +} + +#if NeedFunctionPrototypes +XrmQuark falrmStringToQuark( + _Xconst char *name) +#else +XrmQuark falrmStringToQuark(name) + XrmString name; +#endif +{ + register char c, *tname; + register Signature sig = 0; + + if (!name) + return (NULLQUARK); + + for (tname = (char *)name; c = *tname++; ) + sig = (sig << 1) + c; + + return _falrmInternalStringToQuark(name, tname-(char *)name-1, sig, False); +} + +#if NeedFunctionPrototypes +XrmQuark falrmPermStringToQuark( + _Xconst char *name) +#else +XrmQuark falrmPermStringToQuark(name) + XrmString name; +#endif +{ + register char c, *tname; + register Signature sig = 0; + + if (!name) + return (NULLQUARK); + + for (tname = (char *)name; c = *tname++; ) + sig = (sig << 1) + c; + + return _falrmInternalStringToQuark(name, tname-(char *)name-1, sig, True); +} + +XrmQuark falrmUniqueQuark() +{ + XrmQuark q; + + _XLockMutex(_Xglobal_lock); + if (nextUniq == nextQuark) + q = NULLQUARK; + else + q = nextUniq--; + _XUnlockMutex(_Xglobal_lock); + return q; +} + +XrmString falrmQuarkToString(quark) + register XrmQuark quark; +{ + XrmString s; + + _XLockMutex(_Xglobal_lock); + if (quark <= 0 || quark >= nextQuark) + s = NULLSTRING; + else { +#ifdef PERMQ + /* We have to mark the quark as permanent, since the caller might hold + * onto the string pointer forver. + */ + SETPERM(quark); +#endif + s = NAME(quark); + } + _XUnlockMutex(_Xglobal_lock); + return s; +} diff --git a/cde/programs/dtudcfonted/libfal/_falSetLocale.c b/cde/programs/dtudcfonted/libfal/_falSetLocale.c new file mode 100644 index 00000000..a34dfd03 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falSetLocale.c @@ -0,0 +1,242 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* SetLocale.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:31:29 */ +/* $XConsortium: _falSetLocale.c /main/1 1996/04/08 15:15:08 cde-fuj $ */ + +/* + * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, + * and Nippon Telegraph and Telephone Corporation + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of OMRON, NTT Software, and NTT + * not be used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. OMRON, NTT Software, + * and NTT make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * OMRON, NTT SOFTWARE, AND NTT, DISCLAIM ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, OR NTT, BE + * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Li Yuhong OMRON Corporation + * Tetsuya Kato NTT Software Corporation + * Hiroshi Kuribayashi OMRON Corporation + * + */ +/* + +Copyright (c) 1987 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +#include "_fallibint.h" +#include "_fallcint.h" +#include +#include + +#ifdef X_LOCALE + +/* alternative setlocale() for when the OS does not provide one */ + +#ifdef X_NOT_STDC_ENV +extern char *getenv(); +#endif + +#define MAXLOCALE 64 /* buffer size of locale name */ + +#if NeedFunctionPrototypes +char * +_falsetlocale( + int category, + _Xconst char *name +) +#else +char * +_falsetlocale(category, name) + int category; + char *name; +#endif +{ + static char *xsl_name; + char *old_name; + XrmMethods methods; + XPointer state; + + if (category != LC_CTYPE && category != LC_ALL) + return NULL; + if (!name) { + if (xsl_name) + return xsl_name; + return "C"; + } + if (!*name) + name = getenv("LC_CTYPE"); + if (!name || !*name) + name = getenv("LANG"); + if (!name || !*name) + name = "C"; + old_name = xsl_name; + xsl_name = (char *)name; + methods = _falrmInitParseInfo(&state); + xsl_name = old_name; + if (!methods) + return NULL; + name = (*methods->lcname)(state); + xsl_name = Xmalloc(strlen(name) + 1); + if (!xsl_name) { + xsl_name = old_name; + (*methods->destroy)(state); + return NULL; + } + strcpy(xsl_name, name); + if (old_name) + Xfree(old_name); + (*methods->destroy)(state); + return xsl_name; +} + +#else /* X_LOCALE */ + +/* + * _fallcMapOSLocaleName is an implementation dependent routine that derives + * the LC_CTYPE locale name as used in the sample implementation from that + * returned by setlocale. + * Should match the code in Xt ExtractLocaleName. + */ + +char * +_fallcMapOSLocaleName(osname, siname) + char *osname; + char *siname; +{ +#if defined(hpux) || defined(CSRG_BASED) || defined(sun) || defined(SVR4) || defined(sgi) || defined(AIXV3) || defined(ultrix) || defined(WIN32) +#ifdef hpux +#define SKIPCOUNT 2 +#define STARTCHAR ':' +#define ENDCHAR ';' +#else +#ifdef ultrix +#define SKIPCOUNT 2 +#define STARTCHAR '\001' +#define ENDCHAR '\001' +#else +#ifdef WIN32 +#define SKIPCOUNT 1 +#define STARTCHAR '=' +#define ENDCHAR ';' +#define WHITEFILL +#else +#if defined(AIXV3) +#define STARTCHAR ' ' +#define ENDCHAR ' ' +#else +#if !defined(sun) || defined(SVR4) +#define STARTCHAR '/' +#endif +#define ENDCHAR '/' +#endif +#endif +#endif +#endif + + char *start; + char *end; + int len; +#ifdef SKIPCOUNT + int n; +#endif + + start = osname; +#ifdef SKIPCOUNT + for (n = SKIPCOUNT; + --n >= 0 && start && (start = strchr (start, STARTCHAR)); + start++) + ; + if (!start) + start = osname; +#endif +#ifdef STARTCHAR + if (start && (start = strchr (start, STARTCHAR))) { + start++; +#endif + if (end = strchr (start, ENDCHAR)) { + len = end - start; + strncpy(siname, start, len); + *(siname + len) = '\0'; +#ifdef WHITEFILL + for (start = siname; start = strchr(start, ' '); ) + *start++ = '-'; +#endif + return siname; +#ifdef STARTCHAR + } +#endif + } +#ifdef WHITEFILL + if (strchr(osname, ' ')) { + strcpy(siname, osname); + for (start = siname; start = strchr(start, ' '); ) + *start++ = '-'; + return siname; + } +#endif +#undef STARTCHAR +#undef ENDCHAR +#undef WHITEFILL +#endif + return osname; +} + +#endif /* X_LOCALE */ diff --git a/cde/programs/dtudcfonted/libfal/_fallcCT.c b/cde/programs/dtudcfonted/libfal/_fallcCT.c new file mode 100644 index 00000000..dd94559c --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcCT.c @@ -0,0 +1,906 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcCT.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:33 */ +/* $XConsortium: _fallcCT.c /main/1 1996/04/08 15:15:33 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" +#include +#include + +typedef struct _StateRec { + XlcCharSet charset; + XlcCharSet GL_charset; + XlcCharSet GR_charset; + XlcCharSet ext_seg_charset; + int ext_seg_left; +} StateRec, *State; + +typedef struct _CTDataRec { + char *name; + char *encoding; /* Compound Text encoding */ +} CTDataRec, *CTData; + +typedef struct _CTInfoRec { + XlcCharSet charset; + int encoding_len; + char *encoding; /* Compound Text encoding */ + int ext_segment_len; + char *ext_segment; /* extended segment */ + struct _CTInfoRec *next; +} CTInfoRec, *CTInfo; + +static CTDataRec default_ct_data[] = +{ + { "ISO8859-1:GL", "\033(B" }, + { "ISO8859-1:GR", "\033-A" }, + { "ISO8859-2:GR", "\033-B" }, + { "ISO8859-3:GR", "\033-C" }, + { "ISO8859-4:GR", "\033-D" }, + { "ISO8859-7:GR", "\033-F" }, + { "ISO8859-6:GR", "\033-G" }, + { "ISO8859-8:GR", "\033-H" }, + { "ISO8859-5:GR", "\033-L" }, + { "ISO8859-9:GR", "\033-M" }, + { "JISX0201.1976-0:GL", "\033(J" }, + { "JISX0201.1976-0:GR", "\033)I" }, + + { "GB2312.1980-0:GL", "\033$(A" }, + { "GB2312.1980-0:GR", "\033$)A" }, + { "JISX0208.1983-0:GL", "\033$(B" }, + { "JISX0208.1983-0:GR", "\033$)B" }, + { "KSC5601.1987-0:GL", "\033$(C" }, + { "KSC5601.1987-0:GR", "\033$)C" }, +#ifdef notdef + { "JISX0212.1990-0:GL", "\033$(D" }, + { "JISX0212.1990-0:GR", "\033$)D" }, + { "CNS11643.1986-1:GL", "\033$(G" }, + { "CNS11643.1986-1:GR", "\033$)G" }, + { "CNS11643.1986-2:GL", "\033$(H" }, + { "CNS11643.1986-2:GR", "\033$)H" }, + + /* Non-Standard Character Set Encodings */ + { "TIS620.2533-1:GR", "\033-T"}, +#endif +} ; + +#define XctC0 0x0000 +#define XctHT 0x0009 +#define XctNL 0x000a +#define XctESC 0x001b +#define XctGL 0x0020 +#define XctC1 0x0080 +#define XctCSI 0x009b +#define XctGR 0x00a0 + +#define XctCntrlFunc 0x0023 +#define XctMB 0x0024 +#define XctOtherCoding 0x0025 +#define XctGL94 0x0028 +#define XctGR94 0x0029 +#define XctGR96 0x002d +#define XctNonStandard 0x002f +#define XctIgnoreExt 0x0030 +#define XctNotIgnoreExt 0x0031 +#define XctLeftToRight 0x0031 +#define XctRightToLeft 0x0032 +#define XctDirection 0x005d +#define XctDirectionEnd 0x005d + +#define XctGL94MB 0x2428 +#define XctGR94MB 0x2429 +#define XctExtSeg 0x252f +#define XctOtherSeg 0x2f00 + +#define XctESCSeq 0x1b00 +#define XctCSISeq 0x9b00 + +#define SKIP_I(str) while (*(str) >= 0x20 && *(str) <= 0x2f) (str)++; +#define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; + +typedef struct { + XlcSide side; + int char_size; + int set_size; + int ext_seg_length; + int version; + CTInfo ct_info; +} CTParseRec, *CTParse; + +static CTInfo ct_list = NULL; + +static CTInfo +_XlcGetCTInfoFromEncoding(encoding, length) + register char *encoding; + register int length; +{ + register CTInfo ct_info; + + for (ct_info = ct_list; ct_info; ct_info = ct_info->next) { + if (length >= ct_info->encoding_len) { + if (ct_info->ext_segment) { + if (!strncmp(ct_info->encoding, encoding, 4) && + !strncmp(ct_info->ext_segment, encoding + 6, + ct_info->ext_segment_len)) + return ct_info; + } else if (!strncmp(ct_info->encoding, encoding, + ct_info->encoding_len)) { + return ct_info; + } + } + } + + return (CTInfo) NULL; +} + +static unsigned int +_XlcParseCT(parse, text, length) + register CTParse parse; + char **text; + int *length; +{ + unsigned int ret = 0; + unsigned char ch; + register unsigned char *str = (unsigned char *) *text; + + bzero((char *) parse, sizeof(CTParseRec)); + + switch (ch = *str++) { + case XctESC: + if (*str == XctOtherCoding && *(str + 1) == XctNonStandard + && *(str + 2) >= 0x30 && *(str + 2) <= 0x3f && *length >= 6) { + + /* non-standard encodings */ + parse->side = XlcGLGR; + parse->set_size = 0; + str += 2; + if (*str <= 0x34) { + parse->char_size = *str - 0x30; + if (parse->char_size == 0) parse->char_size = 1; + ret = XctExtSeg; + parse->ct_info = _XlcGetCTInfoFromEncoding(*text, *length); + } else + ret = XctOtherSeg; + str++; + parse->ext_seg_length = (*str - 128) * 128 + *(str + 1) - 128; + str += 2; + + goto done; + } else if (*str == XctCntrlFunc && *length >= 4 && + *(str + 1) >= 0x20 && *(str + 1) <= 0x2f && + (*(str + 2) == XctIgnoreExt || + *(str + 2) == XctNotIgnoreExt)) { + + /* ignore extension or not */ + str++; + parse->version = *str++ - 0x20; + ret = *str++; + + goto done; + } + + if (*str == XctMB) { /* multiple-byte sets */ + parse->char_size = 2; + str++; + } else + parse->char_size = 1; + + switch (*str) { + case XctGL94: + parse->side = XlcGL; + parse->set_size = 94; + ret = (parse->char_size == 1) ? XctGL94 : XctGL94MB; + break; + case XctGR94: + parse->side = XlcGR; + parse->set_size = 94; + ret = (parse->char_size == 1) ? XctGR94 : XctGR94MB; + break; + case XctGR96: + if (parse->char_size == 1) { + parse->side = XlcGR; + parse->set_size = 96; + ret = XctGR96; + } + break; + } + if (ret) { + str++; + if (*str >= 0x24 && *str <= 0x2f) { /* non-standard */ + ret = 0; + str++; + } + } + + SKIP_I(str) + + if (ret && *str < 0x40) /* non-standard */ + ret = 0; + + if (*str < 0x30 || *str > 0x7e || (char *) str - *text >= *length) + break; + + if (ret == 0) + ret = XctESCSeq; + else { + if (parse->char_size == 2) { + if (*str >= 0x70) + parse->char_size = 4; + else if (*str >= 0x60) + parse->char_size = 3; + } + parse->ct_info = _XlcGetCTInfoFromEncoding(*text, *length); + } + str++; + goto done; + case XctCSI: + /* direction */ + if (*str == XctLeftToRight && *(str + 1) == XctDirection) { + ret = XctLeftToRight; + str += 2; + goto done; + } else if (*str == XctRightToLeft && *(str + 1) == XctDirection) { + ret = XctRightToLeft; + str += 2; + goto done; + } else if (*str == XctDirectionEnd) { + ret = XctDirectionEnd; + str++; + goto done; + } + + SKIP_P(str) + SKIP_I(str) + + if (*str < 0x40 && *str > 0x7e) + break; + + ret = XctCSISeq; + str++; + goto done; + } + + if (ch & 0x80) { + if (ch < 0xa0) + ret = XctC1; + else + ret = XctGR; + } else { + if (ch == XctHT || ch == XctNL) + ret = ch; + else if (ch < 0x20) + ret = XctC0; + else + ret = XctGL; + } + + return ret; + +done: + *length -= (char *) str - *text; + *text = (char *) str; + + return ret; +} + +XlcCharSet +_fallcAddCT(name, encoding) + char *name; + char *encoding; +{ + CTInfo ct_info; + XlcCharSet charset; + CTParseRec parse; + char *ct_ptr = encoding; + int length; + unsigned int type; + + length = strlen(encoding); + + switch (type = _XlcParseCT(&parse, &ct_ptr, &length)) { + case XctExtSeg: + case XctGL94: + case XctGL94MB: + case XctGR94: + case XctGR94MB: + case XctGR96: + if (parse.ct_info) /* existed */ + return parse.ct_info->charset; + break; + default: + return (XlcCharSet) NULL; + } + + charset = _fallcCreateDefaultCharSet(name, encoding); + if (charset == NULL) + return (XlcCharSet) NULL; + _fallcAddCharSet(charset); + + ct_info = (CTInfo) Xmalloc(sizeof(CTInfoRec)); + if (ct_info == NULL) + return (XlcCharSet) NULL; + + ct_info->charset = charset; + ct_info->encoding = charset->ct_sequence; + ct_info->encoding_len = strlen(ct_info->encoding); + if (type == XctExtSeg) { + ct_info->ext_segment = ct_info->encoding + 6; + ct_info->ext_segment_len = strlen(ct_info->ext_segment); + } else { + ct_info->ext_segment = NULL; + ct_info->ext_segment_len = 0; + } + ct_info->next = ct_list; + ct_list = ct_info; + + return charset; +} + +static CTInfo +_XlcGetCTInfoFromCharSet(charset) + register XlcCharSet charset; +{ + register CTInfo ct_info; + + for (ct_info = ct_list; ct_info; ct_info = ct_info->next) + if (ct_info->charset == charset) + return ct_info; + + return (CTInfo) NULL; +} + +Bool +_fallcParseCharSet(charset) + XlcCharSet charset; +{ + CTParseRec parse; + char *ptr, buf[BUFSIZ]; + unsigned int type; + int length; + + if (charset->ct_sequence == NULL) + return False; + + ptr = charset->ct_sequence; + length = strlen(ptr); + + type = _XlcParseCT(&parse, &ptr, &length); + + if (charset->name) { + charset->xrm_name = falrmStringToQuark(charset->name); + + snprintf(buf, sizeof(buf), "%s", charset->name); + if (ptr = strchr(buf, ':')) + *ptr = '\0'; + charset->xrm_encoding_name = falrmStringToQuark(buf); + charset->encoding_name = falrmQuarkToString(charset->xrm_encoding_name); + } else { + charset->xrm_name = 0; + charset->encoding_name = NULL; + charset->xrm_encoding_name = 0; + } + + charset->side = parse.side; + charset->char_size = parse.char_size; + charset->set_size = parse.set_size; + + return True; +} + +static void init_converter(); + +Bool +_fallcInitCTInfo() +{ + register XlcCharSet charset; + register CTData ct_data; + register int num; + + if (ct_list == NULL) { + num = sizeof(default_ct_data) / sizeof(CTDataRec); + for (ct_data = default_ct_data; num-- > 0; ct_data++) { + charset = _fallcAddCT(ct_data->name, ct_data->encoding); + if (charset == NULL) + continue; + } + init_converter(); + } + + return True; +} + + +static int +_XlcCheckCTSequence(state, ctext, ctext_len) + State state; + char **ctext; + int *ctext_len; +{ + XlcCharSet charset; + CTParseRec parse; + CTInfo ct_info; + int length; + + _XlcParseCT(&parse, ctext, ctext_len); + + ct_info = parse.ct_info; + if (parse.ext_seg_length > 0) { /* XctExtSeg or XctOtherSeg */ + if (ct_info) { + length = ct_info->ext_segment_len; + *ctext += length; + *ctext_len -= length; + state->ext_seg_left = parse.ext_seg_length - length; + state->ext_seg_charset = ct_info->charset; + } else { + state->ext_seg_left = parse.ext_seg_length; + state->ext_seg_charset = NULL; + } + } else if (ct_info) { + if (charset = ct_info->charset) { + if (charset->side == XlcGL) + state->GL_charset = charset; + else if (charset->side == XlcGR) + state->GR_charset = charset; + } + } + + return 0; +} + + +static void +init_state(conv) + XlcConv conv; +{ + State state = (State) conv->state; + static XlcCharSet GL_charset = NULL; + static XlcCharSet GR_charset = NULL; + + if (GL_charset == NULL) { + GL_charset = _fallcGetCharSet("ISO8859-1:GL"); + GR_charset = _fallcGetCharSet("ISO8859-1:GR"); + } + + state->GL_charset = state->charset = GL_charset; + state->GR_charset = GR_charset; + state->ext_seg_charset = NULL; + state->ext_seg_left = 0; +} + +static int +cttocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register State state = (State) conv->state; + register unsigned char ch; + int length; + XlcCharSet charset = NULL; + char *ctptr, *bufptr; + int ctext_len, buf_len; + + ctptr = *((char **) from); + bufptr = *((char **) to); + ctext_len = *from_left; + buf_len = *to_left; + + while (ctext_len > 0 && buf_len > 0) { + if (state->ext_seg_left > 0) { + length = min(state->ext_seg_left, ctext_len); + length = min(length, buf_len); + + ctext_len -= length; + state->ext_seg_left -= length; + + if (state->ext_seg_charset) { + charset = state->ext_seg_charset; + buf_len -= length; + if (charset->side == XlcGL) { + while (length-- > 0) + *bufptr++ = *ctptr++ & 0x7f; + } else if (charset->side == XlcGR) { + while (length-- > 0) + *bufptr++ = *ctptr++ | 0x80; + } else { + while (length-- > 0) + *bufptr++ = *ctptr++; + } + + if (state->ext_seg_left < 1) + state->ext_seg_charset = NULL; + } + break; + } + ch = *((unsigned char *) ctptr); + if (ch == 0x1b || ch == 0x9b) { + length = _XlcCheckCTSequence(state, &ctptr, &ctext_len); + if (length < 0) + return -1; + if (state->ext_seg_left > 0 && charset) + break; + } else { + if (charset) { + if (charset != (ch & 0x80 ? state->GR_charset : + state->GL_charset)) + break; + } else + charset = ch & 0x80 ? state->GR_charset : state->GL_charset; + + if ((ch < 0x20 && ch != '\0' && ch != '\n' && ch != '\t') || + (ch >= 0x80 && ch < 0xa0)) + return -1; + + *bufptr++ = *ctptr++; + ctext_len--; + buf_len--; + } + } + + if (charset) + state->charset = charset; + if (num_args > 0) + *((XlcCharSet *) args[0]) = state->charset; + + *from_left -= ctptr - *((char **) from); + *from = (XPointer) ctptr; + + *to_left -= bufptr - *((char **) to); + *to = (XPointer) bufptr; + + return 0; +} + +static int +cstoct(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XlcSide side; + unsigned char min_ch, max_ch; + register unsigned char ch; + int length; + CTInfo ct_info; + XlcCharSet charset; + char *csptr, *ctptr; + int csstr_len, ct_len; + + if (num_args < 1) + return -1; + + csptr = *((char **) from); + ctptr = *((char **) to); + csstr_len = *from_left; + ct_len = *to_left; + + charset = (XlcCharSet) args[0]; + + ct_info = _XlcGetCTInfoFromCharSet(charset); + if (ct_info == NULL) + return -1; + + side = charset->side; + + if (ct_info->ext_segment) { + if (charset != state->ext_seg_charset && state->ext_seg_left < 1) { + length = ct_info->encoding_len; + if (ct_len < length) + return -1; + strcpy(ctptr, ct_info->encoding); + ctptr[4] = ((ct_info->ext_segment_len + csstr_len) / 128) | 0x80; + ctptr[5] = ((ct_info->ext_segment_len + csstr_len) % 128) | 0x80; + ctptr += length; + ct_len -= length; + state->ext_seg_left = csstr_len; + } + length = min(state->ext_seg_left, csstr_len); + state->ext_seg_left -= length; + + if (side == XlcGL) { + while (length-- > 0) + *ctptr++ = *csptr++ & 0x7f; + } else if (side == XlcGR) { + while (length-- > 0) + *ctptr++ = *csptr++ | 0x80; + } else { + while (length-- > 0) + *ctptr++ = *csptr++; + } + state->ext_seg_charset = (state->ext_seg_left > 0) ? charset : NULL; + } else { + if ((side == XlcGR && charset != state->GR_charset) || + (side == XlcGL && charset != state->GL_charset)) { + + ct_len -= ct_info->encoding_len; + if (ct_len < 0) + return -1; + strcpy(ctptr, ct_info->encoding); + ctptr += ct_info->encoding_len; + } + + min_ch = 0x20; + max_ch = 0x7f; + + if (charset->set_size == 94) { + max_ch--; + if (charset->char_size > 1 || side == XlcGR) + min_ch++; + } + + while (csstr_len > 0 && ct_len > 0) { + ch = *((unsigned char *) csptr++) & 0x7f; + if (ch < min_ch || ch > max_ch) + if (ch != 0x00 && ch != 0x09 && ch != 0x0a && ch != 0x1b) + continue; /* XXX */ + if (side == XlcGL) + *ctptr++ = ch & 0x7f; + else if (side == XlcGR) + *ctptr++ = ch | 0x80; + else + *ctptr++ = ch; + csstr_len--; + ct_len--; + } + if (side == XlcGR) + state->GR_charset = charset; + else if (side == XlcGL) + state->GL_charset = charset; + } + + *from_left -= csptr - *((char **) from); + *from = (XPointer) csptr; + + *to_left -= ctptr - *((char **) to); + *to = (XPointer) ctptr; + + return 0; +} + +static int +strtocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + register char *src, *dst; + unsigned char side; + register length; + + src = (char *) *from; + dst = (char *) *to; + + length = min(*from_left, *to_left); + side = *((unsigned char *) src) & 0x80; + + while (side == (*((unsigned char *) src) & 0x80) && length-- > 0) + *dst++ = *src++; + + *from_left -= src - (char *) *from; + *from = (XPointer) src; + *to_left -= dst - (char *) *to; + *to = (XPointer) dst; + + if (num_args > 0) + *((XlcCharSet *)args[0]) = side ? state->GR_charset : state->GL_charset; + + return 0; +} + +static int +cstostr(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + char *csptr, *string_ptr; + int csstr_len, str_len; + unsigned char ch; + int unconv_num = 0; + + if (num_args < 1 || (state->GL_charset != (XlcCharSet) args[0] && + state->GR_charset != (XlcCharSet) args[0])) + return -1; + + csptr = *((char **) from); + string_ptr = *((char **) to); + csstr_len = *from_left; + str_len = *to_left; + + while (csstr_len-- > 0 && str_len > 0) { + ch = *((unsigned char *) csptr++); + if ((ch < 0x20 && ch != 0x00 && ch != 0x09 && ch != 0x0a) || + ch == 0x7f || ((ch & 0x80) && ch < 0xa0)) { + unconv_num++; + continue; + } + *((unsigned char *) string_ptr++) = ch; + str_len--; + } + + *from_left -= csptr - *((char **) from); + *from = (XPointer) csptr; + + *to_left -= string_ptr - *((char **) to); + *to = (XPointer) string_ptr; + + return unconv_num; +} + + +static void +close_converter(conv) + XlcConv conv; +{ + if (conv->state) + Xfree((char *) conv->state); + + Xfree((char *) conv); +} + +static XlcConv +create_conv(methods) + XlcConvMethods methods; +{ + register XlcConv conv; + + conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (conv == NULL) + return (XlcConv) NULL; + + conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + if (conv->state == NULL) + goto err; + + conv->methods = methods; + + init_state(conv); + + return conv; + +err: + close_converter(conv); + + return (XlcConv) NULL; +} + +static XlcConvMethodsRec cttocs_methods = { + close_converter, + cttocs, + init_state +} ; + +static XlcConv +open_cttocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&cttocs_methods); +} + +static XlcConvMethodsRec cstoct_methods = { + close_converter, + cstoct, + init_state +} ; + +static XlcConv +open_cstoct(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&cstoct_methods); +} + +static XlcConvMethodsRec strtocs_methods = { + close_converter, + strtocs, + init_state +} ; + +static XlcConv +open_strtocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&strtocs_methods); +} + +static XlcConvMethodsRec cstostr_methods = { + close_converter, + cstostr, + init_state +} ; + +static XlcConv +open_cstostr(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&cstostr_methods); +} + +static void +init_converter() +{ + _fallcSetConverter((XLCd) NULL, XlcNCompoundText, (XLCd) NULL, XlcNCharSet, + open_cttocs); + _fallcSetConverter((XLCd) NULL, XlcNString, (XLCd) NULL, XlcNCharSet, + open_strtocs); + + _fallcSetConverter((XLCd) NULL, XlcNCharSet, (XLCd) NULL, XlcNCompoundText, + open_cstoct); + _fallcSetConverter((XLCd) NULL, XlcNCharSet, (XLCd) NULL, XlcNString, + open_cstostr); +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcCharSet.c b/cde/programs/dtudcfonted/libfal/_fallcCharSet.c new file mode 100644 index 00000000..6063c238 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcCharSet.c @@ -0,0 +1,187 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcCharSet.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:33 */ +/* $XConsortium: _fallcCharSet.c /main/1 1996/04/08 15:15:44 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include +#include "_fallibint.h" +#include "_fallcPublic.h" + +#if NeedVarargsPrototypes +char * +_fallcGetCSValues(XlcCharSet charset, ...) +#else +char * +_fallcGetCSValues(charset, va_alist) + XlcCharSet charset; + va_dcl +#endif +{ + va_list var; + XlcArgList args; + char *ret; + int num_args; + + Va_start(var, charset); + _fallcCountVaList(var, &num_args); + va_end(var); + + Va_start(var, charset); + _fallcVaToArgList(var, num_args, &args); + va_end(var); + + if (args == (XlcArgList) NULL) + return (char *) NULL; + + if (charset->get_values) + ret = (*charset->get_values)(charset, args, num_args); + else + ret = args->name; + + Xfree(args); + + return ret; +} + +typedef struct _XlcCharSetListRec { + XlcCharSet charset; + struct _XlcCharSetListRec *next; +} XlcCharSetListRec, *XlcCharSetList; + +static XlcCharSetList charset_list = NULL; + +XlcCharSet +_fallcGetCharSet(name) + char *name; +{ + XlcCharSetList list; + XrmQuark xrm_name; + + xrm_name = falrmStringToQuark(name); + + for (list = charset_list; list; list = list->next) { + if (xrm_name == list->charset->xrm_name) + return (XlcCharSet) list->charset; + } + + return (XlcCharSet) NULL; +} + +Bool +_fallcAddCharSet(charset) + XlcCharSet charset; +{ + XlcCharSetList list; + + if (_fallcGetCharSet(charset->name)) + return False; + + list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec)); + if (list == NULL) + return False; + + list->charset = charset; + list->next = charset_list; + charset_list = list; + + return True; +} + +static XlcResource resources[] = { + { XlcNName, NULLQUARK, sizeof(char *), + XOffsetOf(XlcCharSetRec, name), XlcGetMask }, + { XlcNEncodingName, NULLQUARK, sizeof(char *), + XOffsetOf(XlcCharSetRec, encoding_name), XlcGetMask }, + { XlcNSide, NULLQUARK, sizeof(XlcSide), + XOffsetOf(XlcCharSetRec, side), XlcGetMask }, + { XlcNCharSize, NULLQUARK, sizeof(int), + XOffsetOf(XlcCharSetRec, char_size), XlcGetMask }, + { XlcNSetSize, NULLQUARK, sizeof(int), + XOffsetOf(XlcCharSetRec, set_size), XlcGetMask }, + { XlcNControlSequence, NULLQUARK, sizeof(char *), + XOffsetOf(XlcCharSetRec, ct_sequence), XlcGetMask } +}; + +static char * +get_values(charset, args, num_args) + register XlcCharSet charset; + register XlcArgList args; + register int num_args; +{ + if (resources[0].xrm_name == NULLQUARK) + _fallcCompileResourceList(resources, XlcNumber(resources)); + + return _fallcGetValues((XPointer) charset, resources, XlcNumber(resources), + args, num_args, XlcGetMask); +} + +XlcCharSet +_fallcCreateDefaultCharSet(name, ct_sequence) + char *name; + char *ct_sequence; +{ + XlcCharSet charset; + + charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec)); + if (charset == NULL) + return (XlcCharSet) NULL; + bzero((char *) charset, sizeof(XlcCharSetRec)); + + charset->name = (char *) Xmalloc(strlen(name) + strlen(ct_sequence) + 2); + if (charset->name == NULL) { + Xfree((char *) charset); + return (XlcCharSet) NULL; + } + strcpy(charset->name, name); + charset->ct_sequence = charset->name + strlen(name) + 1; + strcpy(charset->ct_sequence, ct_sequence); + charset->get_values = get_values; + + _fallcParseCharSet(charset); + + return (XlcCharSet) charset; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcConv.c b/cde/programs/dtudcfonted/libfal/_fallcConv.c new file mode 100644 index 00000000..c5ebd5a6 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcConv.c @@ -0,0 +1,356 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcConv.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:34 */ +/* $XConsortium: _fallcConv.c /main/1 1996/04/08 15:15:57 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" +#include + +typedef XlcConv (*XlcConverter)(); + +typedef struct _fallcConverterListRec { + XLCd from_lcd; + char *from; + XrmQuark from_type; + XLCd to_lcd; + char *to; + XrmQuark to_type; + XlcConverter converter; + struct _fallcConverterListRec *next; +} XlcConverterListRec, *XlcConverterList; + +static XlcConverterList conv_list = NULL; + +static void +close_converter(conv) + XlcConv conv; +{ + (*conv->methods->close)(conv); +} + +static XlcConv +get_converter(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + XrmQuark from_type; + XLCd to_lcd; + XrmQuark to_type; +{ + register XlcConverterList list, prev = NULL; + XlcConv conv; + + for (list = conv_list; list; list = list->next) { + if (list->from_lcd == from_lcd && list->to_lcd == to_lcd + && list->from_type == from_type && list->to_type == to_type) { + + if (prev && prev != conv_list) { /* XXX */ + prev->next = list->next; + list->next = conv_list; + conv_list = list; + } + + return (*list->converter)(from_lcd, list->from, to_lcd, list->to); + } + + prev = list; + } + + return (XlcConv) NULL; +} + +Bool +_fallcSetConverter(from_lcd, from, to_lcd, to, converter) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; + XlcOpenConverterProc converter; +{ + register XlcConverterList list; + register XrmQuark from_type, to_type; + + from_type = falrmStringToQuark(from); + to_type = falrmStringToQuark(to); + + for (list = conv_list; list; list = list->next) { + if (list->from_lcd == from_lcd && list->to_lcd == to_lcd + && list->from_type == from_type && list->to_type == to_type) { + + list->converter = converter; + return True; + } + } + + list = (XlcConverterList) Xmalloc(sizeof(XlcConverterListRec)); + if (list == NULL) + return False; + + list->from_lcd = from_lcd; + list->from = from; + list->from_type = from_type; + list->to_lcd = to_lcd; + list->to = to; + list->to_type = to_type; + list->converter = converter; + list->next = conv_list; + conv_list = list; + + return True; +} + +typedef struct _ConvRec { + XlcConv from_conv; + XlcConv to_conv; +} ConvRec, *Conv; + +static int +indirect_convert(lc_conv, from, from_left, to, to_left, args, num_args) + XlcConv lc_conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + Conv conv = (Conv) lc_conv->state; + XlcConv from_conv = conv->from_conv; + XlcConv to_conv = conv->to_conv; + XlcCharSet charset; + char buf[BUFSIZ], *cs; + XPointer tmp_args[1]; + int cs_left, ret, length, unconv_num = 0; + + if (from == NULL || *from == NULL) { + if (from_conv->methods->reset) + (*from_conv->methods->reset)(from_conv); + + if (to_conv->methods->reset) + (*to_conv->methods->reset)(to_conv); + + return 0; + } + + while (*from_left > 0) { + cs = buf; + cs_left = BUFSIZ; + tmp_args[0] = (XPointer) &charset; + + ret = (*from_conv->methods->convert)(from_conv, from, from_left, &cs, + &cs_left, tmp_args, 1); + if (ret < 0) + break; + + length = cs_left = cs - buf; + cs = buf; + + tmp_args[0] = (XPointer) charset; + + ret = (*to_conv->methods->convert)(to_conv, &cs, &cs_left, to, to_left, + tmp_args, 1); + if (ret < 0) { + unconv_num += length / charset->char_size; + continue; + } + + if (*to_left < 1) + break; + } + + return unconv_num; +} + +static void +close_indirect_converter(lc_conv) + XlcConv lc_conv; +{ + Conv conv = (Conv) lc_conv->state; + + if (conv) { + if (conv->from_conv) + close_converter(conv->from_conv); + if (conv->to_conv) + close_converter(conv->to_conv); + + Xfree((char *) conv); + } + + Xfree((char *) lc_conv); +} + +static void +reset_indirect_converter(lc_conv) + XlcConv lc_conv; +{ + Conv conv = (Conv) lc_conv->state; + + if (conv) { + if (conv->from_conv && conv->from_conv->methods->reset) + (*conv->from_conv->methods->reset)(conv->from_conv); + if (conv->to_conv && conv->to_conv->methods->reset) + (*conv->to_conv->methods->reset)(conv->to_conv); + } +} + +static XlcConvMethodsRec conv_methods = { + close_indirect_converter, + indirect_convert, + reset_indirect_converter +} ; + +static XlcConv +open_indirect_converter(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + XlcConv lc_conv, from_conv, to_conv; + Conv conv; + XrmQuark from_type, to_type; + static XrmQuark QChar, QCharSet, QCTCharSet = (XrmQuark) 0; + + if (QCTCharSet == (XrmQuark) 0) { + QCTCharSet = falrmStringToQuark(XlcNCTCharSet); + QCharSet = falrmStringToQuark(XlcNCharSet); + QChar = falrmStringToQuark(XlcNChar); + } + + from_type = falrmStringToQuark(from); + to_type = falrmStringToQuark(to); + + if (from_type == QCharSet || from_type == QChar || to_type == QCharSet || + to_type == QChar) + return (XlcConv) NULL; + + lc_conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (lc_conv == NULL) + return (XlcConv) NULL; + + lc_conv->methods = &conv_methods; + + lc_conv->state = (XPointer) Xmalloc(sizeof(ConvRec)); + if (lc_conv->state == NULL) + goto err; + + conv = (Conv) lc_conv->state; + + from_conv = get_converter(from_lcd, from_type, from_lcd, QCTCharSet); + if (from_conv == NULL) + from_conv = get_converter(from_lcd, from_type, from_lcd, QCharSet); + if (from_conv == NULL) + from_conv = get_converter((XLCd)NULL, from_type, (XLCd)NULL, QCharSet); + if (from_conv == NULL) + from_conv = get_converter(from_lcd, from_type, from_lcd, QChar); + if (from_conv == NULL) + goto err; + conv->from_conv = from_conv; + + to_conv = get_converter(to_lcd, QCTCharSet, to_lcd, to_type); + if (to_conv == NULL) + to_conv = get_converter(to_lcd, QCharSet, to_lcd, to_type); + if (to_conv == NULL) + to_conv = get_converter((XLCd) NULL, QCharSet, (XLCd) NULL, to_type); + if (to_conv == NULL) + goto err; + conv->to_conv = to_conv; + + return lc_conv; + +err: + close_indirect_converter(lc_conv); + + return (XlcConv) NULL; +} + +XlcConv +_fallcOpenConverter(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + XlcConv conv; + XrmQuark from_type, to_type; + + from_type = falrmStringToQuark(from); + to_type = falrmStringToQuark(to); + + if (conv = get_converter(from_lcd, from_type, to_lcd, to_type)) + return conv; + + return open_indirect_converter(from_lcd, from, to_lcd, to); +} + +void +_fallcCloseConverter(conv) + XlcConv conv; +{ + close_converter(conv); +} + +int +_fallcConvert(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + return (*conv->methods->convert)(conv, from, from_left, to, to_left, args, + num_args); +} + +void +_fallcResetConverter(conv) + XlcConv conv; +{ + if (conv->methods->reset) + (*conv->methods->reset)(conv); +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcDB.c b/cde/programs/dtudcfonted/libfal/_fallcDB.c new file mode 100644 index 00000000..6aa89546 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcDB.c @@ -0,0 +1,1280 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcDB.c 1.3 - Fujitsu source for CDEnext 96/02/29 18:02:53 */ +/* $XConsortium: _fallcDB.c /main/1 1996/04/08 15:16:07 cde-fuj $ */ +/* + * + * Copyright IBM Corporation 1993 + * + * All Rights Reserved + * + * License to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of IBM not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * + * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND + * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL + * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * +*/ +#ifndef NOT_X_ENV + +#include "syncx.h" +#include +#include "_fallibint.h" +#include "_fallcPubI.h" + +#else /* NOT_X_ENV */ + +#define Xmalloc malloc +#define Xrealloc realloc +#define Xfree free + +#endif /* NOT_X_ENV */ + +/* specifying NOT_X_ENV allows users to just use + the database parsing routine. */ +/* For UDC/VW */ +#ifndef BUFSIZE +#define BUFSIZE 2048 +#endif + +#ifdef COMMENT +#ifdef BUFSIZE +#undef BUFSIZE +#endif +#define BUFSIZE 6144 /* 2048*3 */ +#endif + +#include + +typedef struct _DatabaseRec { + char *category; + char *name; + char **value; + int value_num; + struct _DatabaseRec *next; +} DatabaseRec, *Database; + +typedef enum { + S_NULL, /* outside category */ + S_CATEGORY, /* inside category */ + S_NAME, /* has name, expecting values */ + S_VALUE +} ParseState; + +typedef enum { + T_NEWLINE, + T_COMMENT, + T_SEMICOLON, + T_DOUBLE_QUOTE, + T_LEFT_BRACE, + T_RIGHT_BRACE, + T_SPACE, + T_TAB, + T_BACKSLASH, + T_NUMERIC_HEX, + T_NUMERIC_DEC, + T_NUMERIC_OCT, + T_DEFAULT +} Token; + +typedef struct { + Token token; /* token id */ + char *name; /* token sequence */ + int len; /* length of token sequence */ + int (*parse_proc)(); /* parsing procedure */ +} TokenTable; + +static int f_newline(); +static int f_comment(); +static int f_semicolon(); +static int f_double_quote(); +static int f_left_brace(); +static int f_right_brace(); +static int f_white(); +static int f_backslash(); +static int f_numeric(); +static int f_default(); + +static TokenTable token_tbl[] = { + { T_NEWLINE, "\n", 1, f_newline }, + { T_COMMENT, "#", 1, f_comment }, + { T_SEMICOLON, ";", 1, f_semicolon }, + { T_DOUBLE_QUOTE, "\"", 1, f_double_quote }, + { T_LEFT_BRACE, "{", 1, f_left_brace }, + { T_RIGHT_BRACE, "}", 1, f_right_brace }, + { T_SPACE, " ", 1, f_white }, + { T_TAB, "\t", 1, f_white }, + { T_BACKSLASH, "\\", 1, f_backslash }, + { T_NUMERIC_HEX, "\\x", 2, f_numeric }, + { T_NUMERIC_DEC, "\\d", 2, f_numeric }, + { T_NUMERIC_OCT, "\\o", 2, f_numeric }, + { T_DEFAULT, " ", 1, f_default }, /* any character */ + 0 +}; + +#define SYM_NEWLINE '\n' +#define SYM_COMMENT '#' +#define SYM_SEMICOLON ';' +#define SYM_DOUBLE_QUOTE '"' +#define SYM_LEFT_BRACE '{' +#define SYM_RIGHT_BRACE '}' +#define SYM_SPACE ' ' +#define SYM_TAB '\t' +#define SYM_BACKSLASH '\\' + +/************************************************************************/ + +#define MAX_NAME_NEST 64 + +typedef struct { + ParseState pre_state; + char *category; + char *name[MAX_NAME_NEST]; + int nest_depth; + char **value; + int value_len; + int value_num; + int bufsize; /* bufMaxSize >= bufsize >= 0 */ + int bufMaxSize; /* default : BUFSIZE */ + char *buf; +} DBParseInfo; + +static DBParseInfo parse_info; + +static void init_parse_info() +{ + static int first = 1; + char *ptr; + int size; + if(first == 1){ + bzero(&parse_info, sizeof(DBParseInfo)); + parse_info.buf = (char *)Xmalloc(BUFSIZE); + parse_info.bufMaxSize = BUFSIZE; + first = 0; + return ; + } + ptr = parse_info.buf; + size = parse_info.bufMaxSize; + bzero(&parse_info, sizeof(DBParseInfo)); + parse_info.buf = ptr; + parse_info.bufMaxSize = size; +} + +static void +clear_parse_info() +{ + int i; + char *ptr; + int size; + parse_info.pre_state = S_NULL; + if(parse_info.category != NULL){ + Xfree(parse_info.category); + } + for(i = 0; i <= parse_info.nest_depth; ++i){ + if(parse_info.name[i]){ + Xfree(parse_info.name[i]); + } + } + if(parse_info.value){ + if(*parse_info.value){ + Xfree(*parse_info.value); + } + Xfree((char *)parse_info.value); + } + ptr = parse_info.buf; + size = parse_info.bufMaxSize; + bzero(&parse_info, sizeof(DBParseInfo)); + parse_info.buf = ptr; + parse_info.bufMaxSize = size; +} + +static Bool +realloc_parse_info(len) +int len; +{ + char *p; + + + parse_info.bufMaxSize = BUFSIZE * + ((parse_info.bufsize + len)/BUFSIZE + 1); + p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize); + if(p == NULL){ + return(False); + } + parse_info.buf = p; + + return(True); +} +/************************************************************************/ +typedef struct _Line { + char *str; + int cursize; + int maxsize; + int seq; +} Line; + +static void +free_line(line) + Line *line; +{ + if(line->str != NULL){ + Xfree(line->str); + } + bzero(line, sizeof(Line)); +} + +static int +realloc_line(line, size) + Line *line; + int size; +{ + char *str = line->str; + + if(str != NULL){ + str = (char *)Xrealloc(str, size); + }else{ + str = (char *)Xmalloc(size); + } + if(str == NULL){ + /* malloc error */ + bzero(line, sizeof(Line)); + return 0; + } + line->str = str; + line->maxsize = size; + return 1; +} + +#define iswhite(ch) ((ch) == SYM_SPACE || (ch) == SYM_TAB) + +static void +zap_comment(str, quoted) + char *str; + int *quoted; +{ + char *p = str; +#ifdef never + *quoted = 0; + if(*p == SYM_COMMENT){ + int len = strlen(str); + if(p[len - 1] == SYM_NEWLINE){ + *p++ = SYM_NEWLINE; + } + *p = '\0'; + } +#else + while(*p){ + if(*p == SYM_DOUBLE_QUOTE){ + if(p == str || p[-1] != SYM_BACKSLASH){ + /* unescaped double quote changes quoted state. */ + *quoted = *quoted ? 0 : 1; + } + } + if(*p == SYM_COMMENT && !*quoted){ + int pos = p - str; + if(pos == 0 || + iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH)){ + int len = strlen(p); + if(len > 0 && p[len - 1] == SYM_NEWLINE){ + /* newline is the identifier for finding end of value. + therefore, it should not be removed. */ + *p++ = SYM_NEWLINE; + } + *p = '\0'; + break; + } + } + ++p; + } +#endif +} + +static int +read_line(fd, line) + FILE *fd; + Line *line; +{ + char buf[BUFSIZE], *p; + int len; + int quoted = 0; /* quoted by double quote? */ + char *str; + int cur; + + str = line->str; + cur = line->cursize = 0; + + while((p = fgets(buf, BUFSIZE, fd)) != NULL){ + ++line->seq; + zap_comment(p, "ed); /* remove comment line */ + len = strlen(p); + if(len == 0){ + if(cur > 0){ + break; + } + continue; + } + if(cur + len + 1 > line->maxsize){ + /* need to reallocate buffer. */ + if(! realloc_line(line, line->maxsize + BUFSIZE)){ + goto err; /* realloc error. */ + } + str = line->str; + } + strncpy(str + cur, p, len); + + cur += len; + str[cur] = '\0'; + if(!quoted){ + if(cur > 1 && str[cur - 2] == SYM_BACKSLASH && + str[cur - 1] == SYM_NEWLINE){ + /* the line is ended backslash followed by newline. + need to concatinate the next line. */ + cur -= 2; + str[cur] = '\0'; + }else{ + break; + } + } + } + if(quoted){ + /* error. still in quoted state. */ + goto err; + } + return line->cursize = cur; + + err:; + return -1; +} + +/************************************************************************/ + +static Token +get_token(str) + char *str; +{ + switch(*str){ + case SYM_NEWLINE: return T_NEWLINE; + case SYM_COMMENT: return T_COMMENT; + case SYM_SEMICOLON: return T_SEMICOLON; + case SYM_DOUBLE_QUOTE: return T_DOUBLE_QUOTE; + case SYM_LEFT_BRACE: return T_LEFT_BRACE; + case SYM_RIGHT_BRACE: return T_RIGHT_BRACE; + case SYM_SPACE: return T_SPACE; + case SYM_TAB: return T_TAB; + case SYM_BACKSLASH: + switch(str[1]){ + case 'x': return T_NUMERIC_HEX; + case 'd': return T_NUMERIC_DEC; + case 'o': return T_NUMERIC_OCT; + } + return T_BACKSLASH; + default: + return T_DEFAULT; + } +} + +static int +get_word(str, word) + char *str; + char *word; +{ + char *p = str, *w = word; + Token token; + int token_len; + + while(*p != '\0'){ + token = get_token(p); + token_len = token_tbl[token].len; + if(token == T_BACKSLASH){ + p += token_len; + if(*p == '\0'){ + break; + } + token = get_token(p); + token_len = token_tbl[token].len; + }else if(token != T_COMMENT && + token != T_DEFAULT){ + break; + } + strncpy(w, p, token_len); + p += token_len; w += token_len; + } + *w = '\0'; + return p - str; /* return number of scanned chars */ +} + +static int +get_quoted_word(str, word) + char *str; + char *word; +{ + char *p = str, *w = word; + Token token; + int token_len; + + if(*p == SYM_DOUBLE_QUOTE){ + ++p; + } + while(*p != '\0'){ + token = get_token(p); + token_len = token_tbl[token].len; + if(token == T_DOUBLE_QUOTE){ + p += token_len; + goto found; + } + if(token == T_BACKSLASH){ + p += token_len; + if(*p == '\0'){ + break; + } + token = get_token(p); + token_len = token_tbl[token].len; + } + strncpy(w, p, token_len); + p += token_len; w += token_len; + } + /* error. cannot detect next double quote */ + return 0; + + found:; + *w = '\0'; + return p - str; +} + +/************************************************************************/ + +static int +append_value_list() +{ + char **value_list = parse_info.value; + char *value = NULL; + int value_num = parse_info.value_num; + int value_len = parse_info.value_len; + char *str = parse_info.buf; + int len = parse_info.bufsize; + char *p; + + if(len < 1){ + return 1; /* return with no error */ + } + + if(value_list == (char **)NULL){ + value_list = (char **)Xmalloc(sizeof(char *) * 2); + *value_list = NULL; + }else{ + value_list = (char **) + Xrealloc(value_list, sizeof(char *) * (value_num + 2)); + } + if(value_list == (char **)NULL){ + goto err; + } + + value = *value_list; + if(value == NULL){ + value = (char *)Xmalloc(value_len + len + 1); + }else{ + value = (char *)Xrealloc(value, value_len + len + 1); + } + if(value == NULL){ + goto err; + } + if(value != *value_list){ + int delta, i; + delta = value - *value_list; + *value_list = value; + for(i = 1; i < value_num; ++i){ + value_list[i] += delta; + } + } + + value_list[value_num] = p = &value[value_len]; + value_list[value_num + 1] = NULL; + strncpy(p, str, len); + p[len] = 0; + + parse_info.value = value_list; + parse_info.value_num = value_num + 1; + parse_info.value_len = value_len + len + 1; + parse_info.bufsize = 0; + return 1; + + err:; + if(value_list){ + Xfree((char **)value_list); + } + + Xfree(value); + + parse_info.value = (char **)NULL; + parse_info.value_num = 0; + parse_info.value_len = 0; + parse_info.bufsize = 0; + return 0; +} + +static int +construct_name(name) + char *name; +{ + register int i, len = 0; + char *p = name; + + for(i = 0; i <= parse_info.nest_depth; ++i){ + len += strlen(parse_info.name[i]) + 1; + } + + strcpy(p, parse_info.name[0]); + p += strlen(parse_info.name[0]); + for(i = 1; i <= parse_info.nest_depth; ++i){ + *p++ = '.'; + strcpy(p, parse_info.name[i]); + p += strlen(parse_info.name[i]); + } + return *name != '\0'; +} + +static int +store_to_database(db) + Database *db; +{ + Database new = (Database)NULL; + char name[BUFSIZE]; + + if(parse_info.pre_state == S_VALUE){ + if(! append_value_list()){ + goto err; + } + } + + if(parse_info.name[parse_info.nest_depth] == NULL){ + goto err; + } + + new = (Database)Xmalloc(sizeof(DatabaseRec)); + if(new == (Database)NULL){ + goto err; + } + bzero(new, sizeof(DatabaseRec)); + + new->category = (char *)Xmalloc(strlen(parse_info.category) + 1); + if(new->category == NULL){ + goto err; + } + strcpy(new->category, parse_info.category); + + if(! construct_name(name)){ + goto err; + } + new->name = (char *)Xmalloc(strlen(name) + 1); + if(new->name == NULL){ + goto err; + } + strcpy(new->name, name); + new->next = *db; + new->value = parse_info.value; + new->value_num = parse_info.value_num; + *db = new; + + Xfree(parse_info.name[parse_info.nest_depth]); + parse_info.name[parse_info.nest_depth] = NULL; + + parse_info.value = (char **)NULL; + parse_info.value_num = 0; + parse_info.value_len = 0; + + return 1; + + err:; + if(new){ + if(new->category){ + Xfree(new->category); + } + if(new->name){ + Xfree(new->name); + } + Xfree(new); + } + if(parse_info.value){ + if(*parse_info.value){ + Xfree(*parse_info.value); + } + Xfree((char **)parse_info.value); + parse_info.value = (char **)NULL; + parse_info.value_num = 0; + parse_info.value_len = 0; + } + return 0; +} + +#define END_MARK "END" +#define END_MARK_LEN 3 /*strlen(END_MARK)*/ + +static int +check_category_end(str) + char *str; +{ + char *p; + int len; + + p = str; + if(strncmp(p, END_MARK, END_MARK_LEN)){ + return 0; + } + p += END_MARK_LEN; + + while(iswhite(*p)){ + ++p; + } + len = strlen(parse_info.category); + if(strncmp(p, parse_info.category, len)){ + return 0; + } + p += len; + return p - str; +} + +/************************************************************************/ + +static int +f_newline(str, token, db) + char *str; + Token token; + Database *db; +{ + switch(parse_info.pre_state){ + case S_NULL: + case S_CATEGORY: + break; + case S_NAME: + goto err; /* no value */ + case S_VALUE: + if(!store_to_database(db)){ + goto err; + } + parse_info.pre_state = S_CATEGORY; + break; + default: + goto err; + } + return token_tbl[token].len; + + err:; + return 0; +} + +static int +f_comment(str, token, db) + char *str; + Token token; + Database *db; +{ + /* NOTE: comment is already handled in read_line(), + so this function is not necessary. */ + + char *p = str; + + while(*p != SYM_NEWLINE && *p != '\0'){ + ++p; /* zap to the end of line */ + } + return p - str; +} + +static int +f_white(str, token, db) + char *str; + Token token; + Database *db; +{ + char *p = str; + + while(iswhite(*p)){ + ++p; + } + return p - str; +} + +static int +f_semicolon(str, token, db) + char *str; + Token token; + Database *db; +{ + switch(parse_info.pre_state){ + case S_NULL: + case S_CATEGORY: + case S_NAME: + goto err; + case S_VALUE: + if(! append_value_list()){ + goto err; + } + parse_info.pre_state = S_VALUE; + break; + default: + goto err; + } + return token_tbl[token].len; + + err:; + return 0; +} + +static int +f_left_brace(str, token, db) + char *str; + Token token; + Database *db; +{ + switch(parse_info.pre_state){ + case S_NULL: + case S_CATEGORY: + goto err; + case S_NAME: + if(parse_info.name[parse_info.nest_depth] == NULL || + parse_info.nest_depth + 1 > MAX_NAME_NEST){ + goto err; + } + ++parse_info.nest_depth; + parse_info.pre_state = S_CATEGORY; + break; + case S_VALUE: + default: + goto err; + } + return token_tbl[token].len; + + err: + return 0; +} + +static int +f_right_brace(str, token, db) + char *str; + Token token; + Database *db; +{ + if(parse_info.nest_depth < 1){ + goto err; + } + + switch(parse_info.pre_state){ + case S_NULL: + case S_NAME: + goto err; + case S_VALUE: + if(! store_to_database(db)){ + goto err; + } + /* fall into next case */ + case S_CATEGORY: + if(parse_info.name[parse_info.nest_depth] != NULL){ + Xfree(parse_info.name[parse_info.nest_depth]); + parse_info.name[parse_info.nest_depth] = NULL; + } + --parse_info.nest_depth; + parse_info.pre_state = S_CATEGORY; + break; + default: + goto err; + } + return token_tbl[token].len; + + err:; + return 0; +} + +static int +f_double_quote(str, token, db) + char *str; + Token token; + Database *db; +{ + char word[BUFSIZE]; + int len = 0; + + switch(parse_info.pre_state){ + case S_NULL: + case S_CATEGORY: + goto err; + case S_NAME: + case S_VALUE: + len = get_quoted_word(str, word); + if(len < 1){ + goto err; + } + if( (parse_info.bufsize + (int)strlen(word) +1) + >= parse_info.bufMaxSize){ + if(realloc_parse_info(strlen(word) +1) == False){ + goto err; + } + } + strcpy(&parse_info.buf[parse_info.bufsize], word); + parse_info.bufsize += strlen(word); + parse_info.pre_state = S_VALUE; + break; + default: + goto err; + } + return len; /* including length of token */ + + err:; + return 0; +} + +static int +f_backslash(str, token, db) + char *str; + Token token; + Database *db; +{ + return f_default(str, token, db); +} + +static int +f_numeric(str, token, db) + char *str; + Token token; + Database *db; +{ + char word[BUFSIZE], *p; + int len; + int token_len; + + switch(parse_info.pre_state){ + case S_NULL: + case S_CATEGORY: + goto err; + case S_NAME: + case S_VALUE: + token_len = token_tbl[token].len; + p = str + token_len; + len = get_word(p, word); + if(len < 1){ + goto err; + } + if( (parse_info.bufsize + token_len + (int)strlen(word) +1) + >= parse_info.bufMaxSize){ + if(realloc_parse_info(token_len + strlen(word) +1) == False){ + goto err; + } + } + strncpy(&parse_info.buf[parse_info.bufsize], str, token_len); + strcpy(&parse_info.buf[parse_info.bufsize + token_len], word); + parse_info.bufsize += token_len + strlen(word); + parse_info.pre_state = S_VALUE; + break; + default: + goto err; + } + return len + token_len; + + err:; + return 0; +} + +static int +f_default(str, token, db) + char *str; + Token token; + Database *db; +{ + char word[BUFSIZE], *p; + int len; + + len = get_word(str, word); + if(len < 1){ + goto err; + } + + switch(parse_info.pre_state){ + case S_NULL: + if(parse_info.category != NULL){ + goto err; + } + p = (char *)Xmalloc(strlen(word) + 1); + if(p == NULL){ + goto err; + } + strcpy(p, word); + parse_info.category = p; + parse_info.pre_state = S_CATEGORY; + break; + case S_CATEGORY: + if(parse_info.nest_depth == 0){ + if(check_category_end(str)){ + /* end of category is detected. + clear context and zap to end of this line */ + clear_parse_info(); + len = strlen(str); + break; + } + } + p = (char *)Xmalloc(strlen(word) + 1); + if(p == NULL){ + goto err; + } + strcpy(p, word); + if(parse_info.name[parse_info.nest_depth] != NULL){ + Xfree(parse_info.name[parse_info.nest_depth]); + } + parse_info.name[parse_info.nest_depth] = p; + parse_info.pre_state = S_NAME; + break; + case S_NAME: + case S_VALUE: + if( (parse_info.bufsize + (int)strlen(word) +1 ) + >= parse_info.bufMaxSize){ + if(realloc_parse_info(strlen(word) +1) == False){ + goto err; + } + } + strcpy(&parse_info.buf[parse_info.bufsize], word); + parse_info.bufsize += strlen(word); + parse_info.pre_state = S_VALUE; + break; + default: + goto err; + } + return len; + + err:; + return 0; +} + +/************************************************************************/ + +#ifdef DEBUG +static void +PrintDatabase(db) + Database db; +{ + Database p = db; + int i = 0, j; + + printf("***\n*** BEGIN Database\n***\n"); + while(p){ + printf("%3d: ", i++); + printf("%s, %s, ", p->category, p->name); + printf("\t[%d: ", p->value_num); + for(j = 0; j < p->value_num; ++j){ + printf("%s, ", p->value[j]); + } + printf("]\n"); + p = p->next; + } + printf("***\n*** END Database\n***\n"); +} +#endif + +static void +DestroyDatabase(db) + Database db; +{ + Database p = db; + + while(p){ + if(p->category != NULL){ + Xfree(p->category); + } + if(p->name != NULL){ + Xfree(p->name); + } + if(p->value != (char **)NULL){ + if(*p->value != NULL){ + Xfree(*p->value); + } + Xfree((char *)p->value); + } + db = p->next; + Xfree((char *)p); + p = db; + } +} + +static int +CountDatabase(db) + Database db; +{ + Database p = db; + int cnt = 0; + + while(p){ + ++cnt; + p = p->next; + } + return cnt; +} + +static Database +CreateDatabase(dbfile) + char *dbfile; +{ + Database db = (Database)NULL; + FILE *fd; + Line line; + char *p; + Token token; + int token_len; + int len; + int error = 0; + + fd = fopen(dbfile, "r"); + if(fd == (FILE *)NULL){ + return NULL; + } + + bzero(&line, sizeof(Line)); + init_parse_info(); + + do { + int rc = read_line(fd, &line); + if(rc < 0){ + error = 1; + break; + }else if(rc == 0){ + break; + } + p = line.str; + while(*p){ + token = get_token(p); + len = (*token_tbl[token].parse_proc)(p, token, &db); + if(len < 1){ + error = 1; + break; + } + p += len; + } + } while (!error); + + if(parse_info.pre_state != S_NULL){ + clear_parse_info(); + error = 1; + } + if(error){ +#ifdef DEBUG + fprintf(stderr, "database format error at line %d.\n", line.seq); +#endif + DestroyDatabase(db); + db = (Database)NULL; + } + + fclose(fd); + free_line(&line); + +#ifdef DEBUG + PrintDatabase(db); +#endif + + return db; +} + +/************************************************************************/ + +#ifndef NOT_X_ENV + +/* locale framework functions */ + +typedef struct _XlcDatabaseRec { + XrmQuark category_q; + XrmQuark name_q; + Database db; + struct _XlcDatabaseRec *next; +} XlcDatabaseRec, *XlcDatabase; + +typedef struct _XlcDatabaseListRec { + XrmQuark name_q; + XlcDatabase lc_db; + Database database; + int ref_count; + struct _XlcDatabaseListRec *next; +} XlcDatabaseListRec, *XlcDatabaseList; + +/* database cache list (per file) */ +static XlcDatabaseList _db_list = (XlcDatabaseList)NULL; + +/************************************************************************/ +/* _fallcGetResource(lcd, category, class, value, count) */ +/*----------------------------------------------------------------------*/ +/* This function retrieves XLocale database information. */ +/************************************************************************/ +void +_fallcGetResource(lcd, category, class, value, count) + XLCd lcd; + char *category; + char *class; + char ***value; + int *count; +{ + XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd); + + (*methods->get_resource)(lcd, category, class, value, count); + return; +} + +/************************************************************************/ +/* _fallcGetLocaleDataBase(lcd, category, class, value, count) */ +/*----------------------------------------------------------------------*/ +/* This function retrieves XLocale database information. */ +/************************************************************************/ +void +_fallcGetLocaleDataBase(lcd, category, name, value, count) + XLCd lcd; + char *category; + char *name; + char ***value; + int *count; +{ + XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db); + XrmQuark category_q, name_q; + + category_q = falrmStringToQuark(category); + name_q = falrmStringToQuark(name); + for(; lc_db->db; ++lc_db){ + if(category_q == lc_db->category_q && name_q == lc_db->name_q){ + *value = lc_db->db->value; + *count = lc_db->db->value_num; + return; + } + } + *value = (char **)NULL; + *count = 0; +} + +/************************************************************************/ +/* _fallcDestroyLocaleDataBase(lcd) */ +/*----------------------------------------------------------------------*/ +/* This function destroy the XLocale Database that bound to the */ +/* specified lcd. If the XLocale Database is referred from some */ +/* other lcd, this function just decreases reference count of */ +/* the database. If no locale refers the database, this function */ +/* remove it from the cache list and free work area. */ +/************************************************************************/ +void +_fallcDestroyLocaleDataBase(lcd) + XLCd lcd; +{ + XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db); + XlcDatabaseList p, prev; + + for(p = _db_list, prev = (XlcDatabaseList)NULL; p; + prev = p, p = p->next){ + if(p->lc_db == lc_db){ + if((-- p->ref_count) < 1){ + if(p->lc_db != (XlcDatabase)NULL){ + Xfree((char *)p->lc_db); + } + DestroyDatabase(p->database); + if(prev == (XlcDatabaseList)NULL){ + _db_list = p->next; + }else{ + prev->next = p->next; + } + Xfree((char*)p); + } + break; + } + } + XLC_PUBLIC(lcd, xlocale_db) = (XPointer)NULL; +} + +/************************************************************************/ +/* _fallcCreateLocaleDataBase(lcd) */ +/*----------------------------------------------------------------------*/ +/* This function create an XLocale database which correspond to */ +/* the specified XLCd. */ +/************************************************************************/ +XPointer +_fallcCreateLocaleDataBase(lcd) + XLCd lcd; +{ + XlcDatabaseList list, new; + Database p, database = (Database)NULL; + XlcDatabase lc_db = (XlcDatabase)NULL; + XrmQuark name_q; + char pathname[256], *name; + int i, n; + + name = _fallcFileName(lcd, "locale"); + if(name == NULL){ + return (XPointer)NULL; + } + strcpy(pathname, name); + Xfree(name); + + name_q = falrmStringToQuark(pathname); + for(list = _db_list; list; list = list->next){ + if(name_q == list->name_q){ + list->ref_count++; + return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)list->lc_db; + } + } + + database = CreateDatabase(pathname); + if(database == (Database)NULL){ + return (XPointer)NULL; + } + n = CountDatabase(database); + lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1)); + if(lc_db == (XlcDatabase)NULL){ + goto err; + } + bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1)); + for(p = database, i = 0; p && i < n; p = p->next, ++i){ + lc_db[i].category_q = falrmStringToQuark(p->category); + lc_db[i].name_q = falrmStringToQuark(p->name); + lc_db[i].db = p; + } + + new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec)); + if(new == (XlcDatabaseList)NULL){ + goto err; + } + new->name_q = name_q; + new->lc_db = lc_db; + new->database = database; + new->ref_count = 1; + new->next = _db_list; + _db_list = new; + + return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)lc_db; + + err:; + DestroyDatabase(database); + if(lc_db != (XlcDatabase)NULL){ + Xfree((char *)lc_db); + } + return (XPointer)NULL; +} + +#endif /* NOT_X_ENV */ diff --git a/cde/programs/dtudcfonted/libfal/_fallcDefConv.c b/cde/programs/dtudcfonted/libfal/_fallcDefConv.c new file mode 100644 index 00000000..eaa92529 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcDefConv.c @@ -0,0 +1,387 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcDefConv.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:35 */ +/* $XConsortium: _fallcDefConv.c /main/1 1996/04/08 15:16:17 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" + +typedef struct _StateRec { + XlcCharSet charset; + XlcCharSet GL_charset; + XlcCharSet GR_charset; + XlcConv ct_conv; + int (*to_converter)(); +} StateRec, *State; + +static int +strtostr(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register char *src, *dst; + unsigned char side; + register length; + + if (from == NULL || *from == NULL) + return 0; + + src = (char *) *from; + dst = (char *) *to; + + length = min(*from_left, *to_left); + + if (num_args > 0) { + side = *((unsigned char *) src) & 0x80; + while (side == (*((unsigned char *) src) & 0x80) && length-- > 0) + *dst++ = *src++; + } else { + while (length-- > 0) + *dst++ = *src++; + } + + *from_left -= src - (char *) *from; + *from = (XPointer) src; + *to_left -= dst - (char *) *to; + *to = (XPointer) dst; + + if (num_args > 0) { + State state = (State) conv->state; + + *((XlcCharSet *)args[0]) = side ? state->GR_charset : state->GL_charset; + } + + return 0; +} + +static int +wcstostr(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register wchar_t *src, side; + register char *dst; + register length; + + if (from == NULL || *from == NULL) + return 0; + + src = (wchar_t *) *from; + dst = (char *) *to; + + length = min(*from_left, *to_left); + + if (num_args > 0) { + side = *src & 0x80; + while (side == (*src & 0x80) && length-- > 0) + *dst++ = *src++; + } else { + while (length-- > 0) + *dst++ = *src++; + } + + *from_left -= src - (wchar_t *) *from; + *from = (XPointer) src; + *to_left -= dst - (char *) *to; + *to = (XPointer) dst; + + if (num_args > 0) { + State state = (State) conv->state; + + *((XlcCharSet *)args[0]) = side ? state->GR_charset : state->GL_charset; + } + + return 0; +} + +static int +cstostr(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register char *src, *dst; + unsigned char side; + register length; + + if (from == NULL || *from == NULL) + return 0; + + if (num_args > 0) { + State state = (State) conv->state; + XlcCharSet charset = (XlcCharSet) args[0]; + + if (charset != state->GL_charset && charset != state->GR_charset) + return -1; + } + + src = (char *) *from; + dst = (char *) *to; + + length = min(*from_left, *to_left); + + if (num_args > 0) { + side = *((unsigned char *) src) & 0x80; + while (side == (*((unsigned char *) src) & 0x80) && length-- > 0) + *dst++ = *src++; + } else { + while (length-- > 0) + *dst++ = *src++; + } + + *from_left -= src - (char *) *from; + *from = (XPointer) src; + *to_left -= dst - (char *) *to; + *to = (XPointer) dst; + + if (num_args > 0) { + State state = (State) conv->state; + + *((XlcCharSet *)args[0]) = side ? state->GR_charset : state->GL_charset; + } + + return 0; +} + +static int +strtowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register char *src; + register wchar_t *dst; + register length; + + if (from == NULL || *from == NULL) + return 0; + + if (num_args > 0) { + State state = (State) conv->state; + XlcCharSet charset = (XlcCharSet) args[0]; + + if (charset != state->GL_charset && charset != state->GR_charset) + return -1; + } + + src = (char *) *from; + dst = (wchar_t *) *to; + + length = min(*from_left, *to_left); + + while (length-- > 0) + *dst++ = (wchar_t) *src++; + + *from_left -= src - (char *) *from; + *from = (XPointer) src; + *to_left -= dst - (wchar_t *) *to; + *to = (XPointer) dst; + + return 0; +} + + +static void +close_converter(conv) + XlcConv conv; +{ + if (conv->state) + Xfree((char *) conv->state); + + Xfree((char *) conv); +} + +static XlcConv +create_conv(methods) + XlcConvMethods methods; +{ + register XlcConv conv; + State state; + static XlcCharSet GL_charset = NULL; + static XlcCharSet GR_charset = NULL; + + if (GL_charset == NULL) { + GL_charset = _fallcGetCharSet("ISO8859-1:GL"); + GR_charset = _fallcGetCharSet("ISO8859-1:GR"); + } + + conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (conv == NULL) + return (XlcConv) NULL; + + conv->state = NULL; + + state = (State) Xmalloc(sizeof(StateRec)); + if (state == NULL) + goto err; + + state->GL_charset = state->charset = GL_charset; + state->GR_charset = GR_charset; + + conv->methods = methods; + conv->state = (XPointer) state; + + return conv; + +err: + close_converter(conv); + + return (XlcConv) NULL; +} + +static XlcConvMethodsRec strtostr_methods = { + close_converter, + strtostr, + NULL +} ; + +static XlcConv +open_strtostr(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&strtostr_methods); +} + +static XlcConvMethodsRec wcstostr_methods = { + close_converter, + wcstostr, + NULL +} ; + +static XlcConv +open_wcstostr(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&wcstostr_methods); +} + +static XlcConvMethodsRec cstostr_methods = { + close_converter, + cstostr, + NULL +} ; + +static XlcConv +open_cstostr(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&cstostr_methods); +} + +static XlcConvMethodsRec strtowcs_methods = { + close_converter, + strtowcs, + NULL +} ; + +static XlcConv +open_strtowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(&strtowcs_methods); +} + +XLCd +_fallcDefaultLoader(name) + char *name; +{ + XLCd lcd; + + if (strcmp(name, "C")) + return (XLCd) NULL; + + lcd = _fallcCreateLC(name, _fallcPublicMethods); + + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_strtowcs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_strtostr); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_strtostr); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_strtostr); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_strtostr);/* XXX */ + + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstostr); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstostr); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstostr); + + _fallcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtostr); + _fallcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs); + + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstostr); + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_strtowcs); + + return lcd; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcDynamic.c b/cde/programs/dtudcfonted/libfal/_fallcDynamic.c new file mode 100644 index 00000000..eaa7c0fb --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcDynamic.c @@ -0,0 +1,73 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: _fallcDynamic.c /main/3 1996/05/08 19:00:37 drk $ */ +/* lcDynamic.c 1.1 - Fujitsu source for CDEnext 95/12/07 10:56:55 */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietry source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ +#include +#include +#include "_fallibint.h" +#ifdef USE_DYNAMIC_LOADER + +#ifndef XLOCALEDIR +#define XLOCALEDIR "/usr/lib/X11/locale" +#endif + +#define LCLIBNAME "xi18n.so" + +extern void *dlopen(); +extern void *dlsym(); +extern int dlclose(); +extern char *dlerror(); + +#define LAZY 1 +#define NOW 2 +#define GLOBAL 0x100 + +XLCd +_fallcDynamicLoader(name) + char *name; +{ + char libpath[1024]; + XLCdMethods _fallcGenericMethods; + XLCd lcd; + void *nlshandler; + + sprintf(libpath,"%s/%s/%s", + XLOCALEDIR,name,LCLIBNAME); + nlshandler = dlopen(libpath,LAZY); + _fallcGenericMethods = (XLCdMethods)dlsym(nlshandler, + "genericMethods"); + lcd = _fallcCreateLC(name,_fallcGenericMethods); + + + return lcd; +} +#endif /* USE_DYNAMIC_LOADER */ diff --git a/cde/programs/dtudcfonted/libfal/_fallcEuc.c b/cde/programs/dtudcfonted/libfal/_fallcEuc.c new file mode 100644 index 00000000..2b79a71e --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcEuc.c @@ -0,0 +1,1492 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcEuc.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:36 */ +/* $XConsortium: _fallcEuc.c /main/1 1996/04/08 15:16:38 cde-fuj $ */ +/****************************************************************** + + Copyright 1992, 1993 by FUJITSU LIMITED + Copyright 1993 by Fujitsu Open Systems Solutions, Inc. + +Permission to use, copy, modify, distribute and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear +in supporting documentation, and that the name of FUJITSU LIMITED and +Fujitsu Open Systems Solutions, Inc. not be used in advertising or +publicity pertaining to distribution of the software without specific, +written prior permission. +FUJITSU LIMITED and Fujitsu Open Systems Solutions, Inc. makes no +representations about the suitability of this software for any purpose. +It is provided "as is" without express or implied warranty. + +FUJITSU LIMITED AND FUJITSU OPEN SYSTEMS SOLUTIONS, INC. DISCLAIMS ALL +WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU OPEN SYSTEMS +SOLUTIONS, INC. AND FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT +OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +OF THIS SOFTWARE. + + Authors: Shigeru Yamada (yamada@ossi.com) + Jeffrey Bloomfield (jeffb@ossi.com) + Yoshiyuki Segawa (segawa@ossi.com) + +*****************************************************************/ + +#include "_fallibint.h" +#include "_fallcGeneric.h" + +#include +#ifdef WIN32 +#define isascii __isascii +#endif + +#define CS0 codesets[0] /* Codeset 0 - 7-bit ASCII */ +#define CS1 codesets[1] /* Codeset 1 - Kanji */ +#define CS2 codesets[2] /* Codeset 2 - Half-Kana */ +#define CS3 codesets[3] /* Codeset 3 - User defined */ + +#define SS2 0x8e /* Single-shift char: CS2 */ +#define SS3 0x8f /* Single-shift char: CS3 */ + +#define ASCII_CODESET 0 +#define KANJI_CODESET 1 +#define KANA_CODESET 2 +#define USERDEF_CODESET 3 +#define MAX_CODESETS + +#define GR 0x80 /* begins right-side (non-ascii) region */ +#define GL 0x7f /* ends left-side (ascii) region */ + +#define isleftside(c) (((c) & GR) ? 0 : 1) +#define isrightside(c) (!isleftside(c)) + +#define BIT8OFF(c) ((c) & GL) +#define BIT8ON(c) ((c) | GR) + +typedef unsigned char Uchar; +typedef unsigned long Ulong; +typedef unsigned int Uint; + +static CodeSet GetCodeSetFromCharSet(); +static CodeSet wc_codeset(); + +#define BADCHAR(min_ch, c) (BIT8OFF(c) < (char)min_ch && BIT8OFF(c) != 0x0 && \ + BIT8OFF(c) != '\t' && BIT8OFF(c) != '\n' && \ + BIT8OFF(c) != 0x1b) + +/* + * Notes: + * 1. Defining FORCE_INDIRECT_CONVERTER (see _fallcEucLoader()) + * forces indirect (charset) conversions (e.g. wcstocs()<->cstombs()). + * 2. Using direct converters (e.g. mbstowcs()) decreases conversion + * times by 20-40% (depends on specific converter used). + */ + +static int +euc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + + XLCd lcd = (XLCd)conv->state; + + register Uchar ch; + register int chr_len = 0; + register int sshift = False; + register int shift_mult = 0; + register Uint chrcode; + + Uint wc_encode = 0; + Uint wc_tmp = 0; + + int cs0flg = False; + int cs1flg = False; + int length; + int num_conv; + int unconv_num = 0; + + Bool new_char; + + XPointer inbufptr = *from; + wchar_t *outbufptr = (wchar_t *) *to; + wchar_t *outbuf_base = outbufptr; + + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (new_char = True; *from_left > 0;) { + + ch = *inbufptr++; + + if (isleftside(ch)) { /* CS0 */ + if (ASCII_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + if( cs0flg == True) { + new_char = True; + cs0flg = False; + } + length = CS0->length; + *outbufptr++ = (wchar_t)ch; + (*from_left)--; + continue; + } + else if (ch == SS2) { /* CS2 */ + if (KANA_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + if (sshift == True || cs1flg == True) { + cs1flg = False; + unconv_num++; + continue; + } + length = CS2->length; + wc_encode = CS2->wc_encoding; + chrcode = 0; + sshift = True; + cs0flg = True; + (*from_left)--; + continue; + } + else if (ch == SS3) { /* CS3 */ + if (USERDEF_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + if (sshift == True || cs1flg == True) { + cs1flg = False; + unconv_num++; + continue; + } + length = CS3->length; + if (*from_left < 1 ) + unconv_num++; + wc_encode = CS3->wc_encoding; + chrcode = 0; + sshift = True; + cs0flg = True; + (*from_left)--; + continue; + + } else { /* CS1 */ + if (KANJI_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + if (sshift == False) { + length = CS1->length; + if (*from_left < 1) + unconv_num++; + wc_encode = CS1->wc_encoding; + } + chrcode = BIT8OFF(ch); + cs0flg = True; + cs1flg = True; + (*from_left)--; + } + + if (new_char) { /* begin new character */ + chr_len = length; + shift_mult = length - 1; + new_char = False; + } + + chrcode <<= (wc_shift * shift_mult); + shift_mult--; + wc_tmp |= chrcode; + + if (--chr_len == 0) { + wc_tmp |= wc_encode; + *outbufptr++ = wc_tmp; + + new_char = True; + sshift = False; + cs0flg = False; + cs1flg = False; + wc_tmp = (Uint)0; + } + + } /* end for */ + + *to = (XPointer)outbufptr; + + if (cs0flg == True || cs1flg == True) /* error check on last char */ + unconv_num++; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + *to_left = (*to_left) - num_conv; + + return unconv_num; +} + + +static int +euc_wcstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + wchar_t *inbufptr = (wchar_t *) *from; + register XPointer outbufptr = *to; + XPointer outbuf_base = outbufptr; + wchar_t wch; + register length; + Uchar tmp; + int num_conv; + int unconv_num = 0; + + XLCd lcd = (XLCd)conv->state; + CodeSet codeset; + Ulong wc_encoding_mask = XLC_GENERIC(lcd, wc_encode_mask); + Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); + Ulong wch_encode; + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (; *from_left > 0 ; (*from_left)-- ) { + + wch = *inbufptr++; + + if (!(codeset = wc_codeset(lcd, wch))) { + unconv_num++; + (*from_left)--; + continue; + } + + length = codeset->length; + wch ^= (wchar_t)codeset->wc_encoding; + + if (codeset->parse_info) /* put out SS2 or SS3 */ + *outbufptr++ = *codeset->parse_info->encoding; + + do { + length--; + tmp = (wch>>(wchar_t)(length * wc_shift)); + + if (codeset->side == XlcGR) + tmp = BIT8ON(tmp); + + *outbufptr++ = (Uchar)tmp; + } while (length); + } + + *to = (XPointer)outbufptr; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + *to_left -= num_conv; + + return unconv_num; +} + + +static int +euc_mbtocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + XlcCharSet charset; + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + int length; + int unconv_num = 0; + int min_ch = 0; + register char *src = *from, *dst = *to; + + + if (isleftside(*src)) { /* 7-bit (CS0) */ + if (ASCII_CODESET >= codeset_num) + return -1; + charset = *CS0->charset_list; + } + else if ((Uchar)*src == SS2) { /* half-kana (CS2) */ + if (KANA_CODESET >= codeset_num) + return -1; + charset = *CS2->charset_list; + src++; + (*from_left)--; + } + else if ((Uchar)*src == SS3) { /* user-def */ + if (USERDEF_CODESET >= codeset_num) + return -1; + charset = *CS3->charset_list; + src++; + (*from_left)--; + } + else { /* Kanji (CS1) */ + if (KANJI_CODESET >= codeset_num) + return -1; + charset = *CS1->charset_list; + } + + if(*from_left < charset->char_size || *to_left < charset->char_size) + return -1; + + min_ch = 0x20; + if (charset->set_size == 94) + if (charset->char_size > 1 || charset->side == XlcGR) + min_ch = 0x21; + + length = charset->char_size; + do { + if(BADCHAR(min_ch, *src)) { + unconv_num++; + break; + } + switch (charset->side) { + case XlcGL: + *dst++ = BIT8OFF(*src++); + break; + case XlcGR: + *dst++ = BIT8ON(*src++); + break; + default: + *dst++ = *src++; + break; + } + } while (--length); + + if (unconv_num) + src += charset->char_size - length; + + *to = dst; + *from = src; + *from_left -= charset->char_size; + *to_left -= charset->char_size; + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset; + + return unconv_num; +} + + +static int +euc_mbstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + char *tmp_from, *tmp_to; + int tmp_from_left, tmp_to_left; + XlcCharSet charset, tmp_charset; + XPointer tmp_args[1]; + int unconv_num = 0, ret; + + +/* Determine the charset of the segment and convert one characater: */ + + tmp_args[0] = (XPointer) &charset; /* charset from euc_mbtocs() */ + while + ((ret = euc_mbtocs(conv, from, from_left, to, to_left, tmp_args, 1)) > 0) + unconv_num += ret; + if ( ret < 0 ) + return ret; + + tmp_from = *from; + tmp_from_left = *from_left; + tmp_to_left = *to_left; + tmp_to = *to; + + +/* Convert remainder of the segment: */ + + tmp_args[0] = (XPointer) &tmp_charset; + while( (ret = euc_mbtocs(conv, &tmp_from, &tmp_from_left, &tmp_to, + &tmp_to_left, tmp_args, 1)) >= 0 ) { + + if (ret > 0) { + unconv_num += ret; + continue; + } + + if (tmp_charset != charset) /* quit on end of segment */ + break; + + *from = tmp_from; + *from_left = tmp_from_left; + *to = tmp_to; + *to_left = tmp_to_left; + } + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset; + + return unconv_num; +} + + +static int +euc_wcstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + wchar_t *wcptr = (wchar_t *) *from; + register char *bufptr = (char *) *to; + wchar_t wch; + char *tmpptr; + register length; + CodeSet codeset; + Ulong wc_encoding; + int unconv_num = 0; + int wcstr_len = *from_left, buf_len = *to_left; + + + if (!(codeset = wc_codeset(lcd, *wcptr))) + return -1; + + wc_encoding = codeset->wc_encoding; + + if (wcstr_len < buf_len / codeset->length) + buf_len = wcstr_len * codeset->length; + + for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) { + wch = *wcptr; + + if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding) + break; + + length = codeset->length; + + buf_len -= length; + bufptr += length; + tmpptr = bufptr - 1; + + while (length--) { + *tmpptr-- = codeset->length == 1 && codeset->side == XlcGR ? + BIT8ON(wch) : BIT8OFF(wch); + wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); + } + } + + if (num_args > 0) + *((XlcCharSet *) args[0]) = *codeset->charset_list; + + *from_left -= wcptr - (wchar_t *) *from; + *from = (XPointer) wcptr; + + *to_left -= bufptr - *to; + *to = bufptr; + + return 0; +} + + +static int +euc_cstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + register char *csptr = *from; + register char *bufptr = *to; + int csstr_len = *from_left; + register buf_len = *to_left; + int length; + CodeSet codeset; + int cvt_length; + + + if (num_args < 1) + return -1; + + if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) + return -1; + + cvt_length = 0; + csstr_len /= codeset->length; + buf_len /= codeset->length; + + if (codeset->parse_info) + csstr_len *= 2; + + if (csstr_len < buf_len) + buf_len = csstr_len; + + cvt_length += buf_len * codeset->length; + + if (bufptr) { + while (buf_len--) { + if (codeset->parse_info) /* put out SS2 or SS3 */ + *bufptr++ = *codeset->parse_info->encoding; + + length = codeset->length; + while (length--) + *bufptr++ = codeset->side == XlcGR ? + BIT8ON(*csptr++) : BIT8OFF(*csptr++); + } + } + + *from_left -= csptr - *from; + *from = csptr; + if (bufptr) + *to += cvt_length; + *to_left -= cvt_length; + + return 0; +} + + +static int +euc_cstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + register char *csptr = *from; + wchar_t *bufptr = (wchar_t *) *to; + wchar_t *toptr = (wchar_t *) *to; + int csstr_len = *from_left; + register buf_len = *to_left; + wchar_t wch; + int length; + Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); + CodeSet codeset; + + + if (num_args < 1) + return -1; + + if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) + return -1; + + csstr_len /= codeset->length; + if (csstr_len < buf_len) + buf_len = csstr_len; + *to_left -= buf_len; + + if (bufptr) { + + toptr += buf_len; + *to = (XPointer) toptr; + + while (buf_len--) { + + wch = (wchar_t) BIT8OFF(*csptr); + csptr++; + + length = codeset->length - 1; + while (length--) { + wch = (wch << wc_shift_bits) | BIT8OFF(*csptr); + csptr++; + } + *bufptr++ = wch | codeset->wc_encoding; + } + } + *from_left -= csptr - *from; + *from = csptr; + + return 0; +} + + +static CodeSet +wc_codeset(lcd, wch) + XLCd lcd; + wchar_t wch; +{ + + register CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + register int end = XLC_GENERIC(lcd, codeset_num); + register Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); + + for (; --end >= 0; codesets++) + if ( widech == (*codesets)->wc_encoding ) + return *codesets; + + return NULL; +} + + +static CodeSet +GetCodeSetFromCharSet(lcd, charset) + XLCd lcd; + XlcCharSet charset; +{ + register CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); + register XlcCharSet *charset_list; + register codeset_num, num_charsets; + + codeset_num = XLC_GENERIC(lcd, codeset_num); + + for ( ; codeset_num-- > 0; codeset++) { + num_charsets = (*codeset)->num_charsets; + charset_list = (*codeset)->charset_list; + + for ( ; num_charsets-- > 0; charset_list++) + if (*charset_list == charset) + return *codeset; + } + + return (CodeSet) NULL; +} + + +static XlcConv +create_conv(lcd, methods) + XLCd lcd; + XlcConvMethods methods; +{ + XlcConv conv; + + conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (conv == NULL) + return (XlcConv) NULL; + + conv->methods = methods; + conv->state = (XPointer) lcd; + return conv; +} + + +/* + * Stripped down Direct CT converters for EUC + * + */ + +typedef struct _CTDataRec { + int side; + int length; + char *name; + Ulong wc_encoding; + char sshift; + char *ct_encoding; + int ct_encoding_len; + int set_size; + Uchar min_ch; + Uchar ct_type; +} CTDataRec, *CTData; + +typedef struct _StateRec { + CTData GL_charset; + CTData GR_charset; + CTData charset; +} StateRec, *State; + +static enum { CT_STD, CT_NSTD, CT_DIR, CT_EXT0, CT_EXT1, CT_EXT2, CT_VER } + ct_types; + +static CTDataRec ctdata[] = +{ + { XlcGL, 1, "ISO8859-1:GL", 0, 0, "\033(B" , 3, 0, 0, CT_STD }, + { XlcGR, 1, "ISO8859-1:GR", 0, 0, "\033-A" , 3, 0, 0, CT_STD }, + { XlcGL, 1, "JISX0201.1976-0:GL", 0, 0, "\033(J" , 3, 0, 0, CT_STD }, + { XlcGR, 1, "JISX0201.1976-0:GR", 0, 0, "\033)I" , 3, 0, 0, CT_STD }, + { XlcGL, 2, "JISX0208.1983-0:GL", 0, 0, "\033$(B" , 4, 0, 0, CT_STD }, + { XlcGR, 2, "JISX0208.1983-0:GR", 0, 0, "\033$)B" , 4, 0, 0, CT_STD }, + { XlcGL, 2, "JISX0212.1990-0:GL", 0, 0, "\033$(D" , 4, 0, 0, CT_STD }, + { XlcGR, 2, "JISX0212.1990-0:GR", 0, 0, "\033$)D" , 4, 0, 0, CT_STD }, + { XlcUnknown, 0, "Ignore-Ext-Status?", 0, 0, "\033#" , 2, 0, 0, CT_VER }, + { XlcUnknown, 0, "NonStd-?-OctetChar", 0, 0, "\033%/0" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 1, "NonStd-1-OctetChar", 0, 0, "\033%/1" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 2, "NonStd-2-OctetChar", 0, 0, "\033%/2" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 3, "NonStd-3-OctetChar", 0, 0, "\033%/3" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 4, "NonStd-4-OctetChar", 0, 0, "\033%/4" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 0, "Extension-2" , 0, 0, "\033%/" , 3, 0, 0, CT_EXT2 }, + { XlcUnknown, 0, "Extension-0" , 0, 0, "\033" , 1, 0, 0, CT_EXT0 }, + { XlcUnknown, 0, "Begin-L-to-R-Text", 0, 0, "\2331]" , 3, 0, 0, CT_DIR }, + { XlcUnknown, 0, "Begin-R-to-L-Text", 0, 0, "\2332]" , 3, 0, 0, CT_DIR }, + { XlcUnknown, 0, "End-Of-String", 0, 0, "\233]" , 2, 0, 0, CT_DIR }, + { XlcUnknown, 0, "Extension-1" , 0, 0, "\233" , 1, 0, 0, CT_EXT1 }, +}; + +/* Note on above table: euc_ctstombs() and euc_ctstowcs() parser depends on + * certain table entries occurring in decreasing string length-- + * 1. CT_EXT2 and CT_EXT0 entries must occur after CT_NSTD entries. + * 2. CT_DIR and CT_EXT1 entries must occur after CT_DIR entries. + */ + +static CTData ctd_endp = ctdata + ((sizeof(ctdata) / sizeof(CTDataRec))) - 1; +static CTData ctdptr[sizeof(ctdata) / sizeof(CTDataRec)]; +static enum { Ascii, Kanji, Kana, Userdef } cs_nums; + + +/* + * initCTptr(): Set ctdptr[] to point at ctdata[], indexed by codeset_num. + */ +static void +initCTptr(lcd) + XLCd lcd; +{ + int num_codesets = XLC_GENERIC(lcd, codeset_num); + int num_charsets; + int i, j; + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + CodeSet codeset; + XlcCharSet charset; + CTData ctdp = ctdata; + + ctdptr[Ascii] = &ctdata[0]; /* failsafe */ + + for (i = 0; i < num_codesets; i++) { + + codeset = codesets[i]; + num_charsets = codeset->num_charsets; + + for (j = 0; j < num_charsets; j++) { + + charset = codeset->charset_list[j]; + + for (ctdp = ctdata; ctdp <= ctd_endp; ctdp++) + + if (! strcmp(ctdp->name, charset->name)) { + + ctdptr[codeset->cs_num] = ctdp; + + ctdptr[codeset->cs_num]->wc_encoding = codeset->wc_encoding; + + ctdptr[codeset->cs_num]->set_size = + charset->set_size; + + ctdptr[codeset->cs_num]->min_ch = + charset->set_size == 94 && + (ctdptr[codeset->cs_num]->length > 1 || + ctdptr[codeset->cs_num]->side == XlcGR) ? 0x21 : 0x20; + + if (codeset->parse_info) { + ctdptr[codeset->cs_num]->sshift = + *codeset->parse_info->encoding; + } + + break; + } + } + } +} + + +#define SKIP_I(str) while (*(str) >= 0x20 && *(str) <= 0x2f) (str)++; +#define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; + +static int +euc_ctstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); + register XPointer inbufptr = *from; + XPointer inbuf_base; + register wchar_t *outbufptr = (wchar_t *) *to; + wchar_t *outbuf_base = outbufptr; + register clen, length; + int num_conv; + int unconv_num = 0; + unsigned int ct_seglen = 0; + Uchar ct_type = 0; + register shift_mult; + wchar_t wc_tmp; + wchar_t wch; + Ulong wc_encoding; + CTData ctdp = ctdata; + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (length = ctdata[Ascii].length; *from_left > 0; (*from_left) -= length) + { + ct_type = CT_STD; + if (*inbufptr == '\033' || *inbufptr == (char)'\233') { + for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { + + if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) + { + inbufptr += ctdp->ct_encoding_len; + (*from_left) -= ctdp->ct_encoding_len; + if (ctdp->length) { + length = ctdp->length; + if( *from_left < length ) { + *to = (XPointer)outbufptr; + *to_left -= outbufptr - outbuf_base; + return( unconv_num + *from_left ); + } + } + ct_type = ctdp->ct_type; + break; + } + } + if (ctdp > ctd_endp) /* failed to match CT sequence */ + unconv_num++; + } + +/* The following code insures that non-standard encodings, direction, extension, + * and version strings are ignored; subject to change in future. + */ + switch (ct_type) { + case CT_STD: + break; + case CT_EXT2: + inbufptr++; + (*from_left)--; + case CT_NSTD: + ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; + inbufptr += ct_seglen; + (*from_left) -= ct_seglen; + continue; + case CT_EXT0: + inbuf_base = inbufptr; + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + *(from_left) -= ct_seglen; + continue; + case CT_EXT1: + inbuf_base = inbufptr; + SKIP_P(inbufptr); + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + *(from_left) -= ct_seglen; + continue; + case CT_DIR: + continue; + case CT_VER: + inbufptr += 2; + *(from_left) -= 2; + continue; + } + + wc_encoding = (ctdp == ctdptr[Kana] && isleftside(*inbufptr)) ? + ctdptr[Ascii]->wc_encoding: ctdp->wc_encoding; + + shift_mult = length - 1; + wch = (wchar_t)0; + clen = length; + + do { + wc_tmp = BIT8OFF(*inbufptr++) << (wc_shift_bits * shift_mult); + wch |= wc_tmp; + shift_mult--; + } while (--clen); + + *outbufptr++ = wch | wc_encoding; + } + + *to = (XPointer)outbufptr; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; + +} + + +#define byte1 (length == codeset->length - 1) +#define byte2 (byte1 == 0) +#define kanji (codeset->cs_num == 1) +#define kana (codeset->cs_num == 2) +#define userdef (codeset->cs_num == 3) + +static int +euc_wcstocts(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register ct_len = *to_left; + register wchar_t *inbufptr = (wchar_t *) *from; + register char *ctptr = *to; + XPointer ct_base = ctptr; + wchar_t wch; + register length; + register unconv_num = 0; + Uchar tmp; + Uchar t1 = 0, t2; + int num_conv; + + StateRec ct_state; + XLCd lcd = (XLCd)conv->state; + CTData charset; + CodeSet codeset; + Ulong wc_encoding_mask = XLC_GENERIC(lcd, wc_encode_mask); + Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); + + +/* Initial State: */ + ct_state.GL_charset = ctdptr[0]; /* Codeset 0 */ + ct_state.GR_charset = NULL; + + if (*from_left > *to_left) + *from_left = *to_left; + + for (; *from_left > 0 ; (*from_left)-- ) { + + wch = *inbufptr++; + + if (!(codeset = wc_codeset(lcd, wch))) { + unconv_num++; + (*from_left)--; + continue; + } + + charset = ctdptr[codeset->cs_num]; + + length = codeset->length; + wch ^= (wchar_t)codeset->wc_encoding; + + if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || + (charset->side == XlcGL && charset != ct_state.GL_charset) ) { + + ct_len -= ctdptr[codeset->cs_num]->ct_encoding_len; + + if (ct_len < 0) { + unconv_num++; + break; + } + + if (ctptr) { + strcpy(ctptr, ctdptr[codeset->cs_num]->ct_encoding); + ctptr += ctdptr[codeset->cs_num]->ct_encoding_len; + } + } + + if (charset->side == XlcGR) + ct_state.GR_charset = charset; + else if (charset->side == XlcGL) + ct_state.GL_charset = charset; + + do { + + length--; + tmp = wch>>(wchar_t)( (Ulong)length * wc_shift); + + if (kana) { + if (BADCHAR(charset->min_ch, (char)tmp)) { + unconv_num++; + break; + } + *ctptr++ = (char)BIT8ON(tmp); + } + + else if (byte1 && (kanji || userdef)) + t1 = tmp; + + else if (byte2 && (kanji || userdef)) { + if (BADCHAR(charset->min_ch, (char)t1) || + BADCHAR(charset->min_ch, (char)tmp)) { + unconv_num++; + break; + } + *ctptr++ = (char)t1; + *ctptr++ = (char)tmp; + } + + else { + if (BADCHAR(charset->min_ch, (char)tmp)) { + unconv_num++; + break; + } + *ctptr++ = (char)tmp; + } + + + } while (length); + + } /* end for */ + + *to = (XPointer)ctptr; + + if ((num_conv = (int)(ctptr - ct_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; +} +#undef byte1 +#undef byte2 +#undef kana +#undef kanji +#undef userdef + + +#define byte1 (ctdp->length == clen) +#define kana (ctdp == ctdptr[Kana] && isrightside(*inbufptr)) +#define kanji (ctdp == ctdptr[Kanji]) +#define userdef (ctdp == ctdptr[Userdef]) + +static int +euc_ctstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register XPointer inbufptr = *from; + register XPointer outbufptr = *to; + XPointer inbuf_base; + XPointer outbuf_base = outbufptr; + register clen, length; + int unconv_num = 0; + int num_conv; + unsigned int ct_seglen = 0; + Uchar ct_type = 0; + CTData ctdp = &ctdata[0]; /* default */ + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (length = ctdata[Ascii].length; *from_left > 0; (*from_left) -= length) + { + ct_type = CT_STD; + if (*inbufptr == '\033' || *inbufptr == (char)'\233') { + + for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { + + if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) + { + inbufptr += ctdp->ct_encoding_len; + (*from_left) -= ctdp->ct_encoding_len - 1; + if (ctdp->length) { + length = ctdp->length; + if( *from_left < length ) { + *to = (XPointer)outbufptr; + *to_left -= outbufptr - outbuf_base; + return( unconv_num + *from_left ); + } + } + ct_type = ctdp->ct_type; + break; + } + } + if (ctdp > ctd_endp) /* failed to match CT sequence */ + unconv_num++; + } + +/* The following code insures that non-standard encodings, direction, extension, + * and version strings are ignored; subject to change in future. + */ + switch (ct_type) { + case CT_STD: + break; + case CT_EXT2: + inbufptr++; + (*from_left)--; + case CT_NSTD: + ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; + inbufptr += ct_seglen; + (*from_left) -= ct_seglen; + continue; + case CT_EXT0: + inbuf_base = inbufptr; + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + *(from_left) -= ct_seglen; + continue; + case CT_EXT1: + inbuf_base = inbufptr; + SKIP_P(inbufptr); + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + *(from_left) -= ct_seglen; + continue; + case CT_DIR: + continue; + case CT_VER: + inbufptr += 2; + *(from_left) -= 2; + continue; + } + + clen = length; + do { + + if (byte1) + if (kanji) { + *inbufptr = BIT8ON(*inbufptr); + *(inbufptr+1) = BIT8ON(*(inbufptr+1)); + } + else if (kana || userdef) + *outbufptr++ = ctdp->sshift; + + *outbufptr++ = *inbufptr++; + + } while (--clen); + } + + *to = outbufptr; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; + +} +#undef byte1 +#undef kana +#undef kanji +#undef userdef + + +static int +euc_mbstocts(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register ct_len = *to_left; + int cs_num; + int clen, length; + int unconv_num = 0; + int num_conv; + XPointer inbufptr = *from; + register char *ctptr = *to; + XPointer ct_base = ctptr; + + StateRec ct_state; + CTData charset; + XLCd lcd = (XLCd) conv->state; + int codeset_num = XLC_GENERIC(lcd, codeset_num); + + +/* Initial State: */ + ct_state.GL_charset = ctdptr[Ascii]; + ct_state.GR_charset = NULL; + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (;*from_left > 0; (*from_left) -= length) { + + if (isleftside(*inbufptr)) { /* 7-bit (CS0) */ + if (ASCII_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Ascii; + charset = ctdptr[Ascii]; + } + else if ((Uchar)*inbufptr == SS2) { /* Kana */ + if (KANA_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Kana; + charset = ctdptr[Kana]; + inbufptr++; + (*from_left)--; + } + else if ((Uchar)*inbufptr == SS3) { /* Userdef */ + if (USERDEF_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Userdef; + charset = ctdptr[Userdef]; + inbufptr++; + (*from_left)--; + } + else { + if (KANJI_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Kanji; + charset = ctdptr[Kanji]; + } + + length = charset->length; + + if (BADCHAR(charset->min_ch, *inbufptr)) + continue; + + if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || + (charset->side == XlcGL && charset != ct_state.GL_charset) ) { + + ct_len -= ctdptr[cs_num]->ct_encoding_len; + if (ct_len < 0) { + unconv_num++; + break; + } + + if (ctptr) { + strcpy(ctptr, ctdptr[cs_num]->ct_encoding); + ctptr += ctdptr[cs_num]->ct_encoding_len; + } + } + + if (charset->side == XlcGR) + ct_state.GR_charset = charset; + else if (charset->side == XlcGL) + ct_state.GL_charset = charset; + + clen = length; + do { + *ctptr++ = charset == ct_state.GR_charset ? + BIT8ON(*inbufptr++) : BIT8OFF(*inbufptr++); + } while (--clen); + } + + *to = (XPointer)ctptr; + + if ((num_conv = (int)(ctptr - ct_base)) > 0) + (*to_left) -= num_conv; + return unconv_num; + +} + + +static void +close_converter(conv) + XlcConv conv; +{ + Xfree((char *) conv); +} + +enum { MBSTOCS, WCSTOCS, MBTOCS, CSTOMBS, CSTOWCS, MBSTOWCS, WCSTOMBS, + CTSTOWCS, CTSTOMBS, WCSTOCTS, MBSTOCTS }; + +static XlcConvMethodsRec conv_methods[] = { + {close_converter, euc_mbstocs, NULL }, + {close_converter, euc_wcstocs, NULL }, + {close_converter, euc_mbtocs, NULL }, + {close_converter, euc_cstombs, NULL }, + {close_converter, euc_cstowcs, NULL }, + {close_converter, euc_mbstowcs, NULL }, + {close_converter, euc_wcstombs, NULL }, + {close_converter, euc_ctstowcs, NULL }, + {close_converter, euc_ctstombs, NULL }, + {close_converter, euc_wcstocts, NULL }, + {close_converter, euc_mbstocts, NULL }, +}; + + +static XlcConv +open_mbstocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBSTOCS]); +} + +static XlcConv +open_wcstocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[WCSTOCS]); +} + +static XlcConv +open_mbtocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBTOCS]); +} + +static XlcConv +open_cstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CSTOMBS]); +} + +static XlcConv +open_cstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CSTOWCS]); +} + +static XlcConv +open_mbstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBSTOWCS]); +} + +static XlcConv +open_wcstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[WCSTOMBS]); +} + +static XlcConv +open_ctstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CTSTOWCS]); +} + +static XlcConv +open_ctstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CTSTOMBS]); +} + +static XlcConv +open_wcstocts(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[WCSTOCTS]); +} + +static XlcConv +open_mbstocts(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBSTOCTS]); +} + +XLCd +_fallcEucLoader(name) + char *name; +{ + XLCd lcd; + + lcd = _fallcCreateLC(name, _fallcGenericMethods); + if (lcd == NULL) + return lcd; + + + if ((_fallcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "euc"))) { + _fallcDestroyLC(lcd); + return (XLCd) NULL; + } + + initCTptr(lcd); + + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs); + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); + +#ifndef FORCE_INDIRECT_CONVERTER + _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs); + _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); +#endif + + return lcd; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcFile.c b/cde/programs/dtudcfonted/libfal/_fallcFile.c new file mode 100644 index 00000000..e994ba0d --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcFile.c @@ -0,0 +1,377 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcFile.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:36 */ +/* $XConsortium: _fallcFile.c /main/1 1996/04/08 15:16:48 cde-fuj $ */ +/* + * + * Copyright IBM Corporation 1993 + * + * All Rights Reserved + * + * License to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of IBM not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * + * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND + * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL + * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * +*/ +#include +#include +#include "_fallibint.h" +#include "_fallcPubI.h" +#include +#ifdef X_NOT_STDC_ENV +extern char *getenv(); +#endif + +/************************************************************************/ + +#define iscomment(ch) ((ch) == '#' || (ch) == '\0') +#define isreadable(f) ((access((f), R_OK) != -1) ? 1 : 0) +/* +#define isspace(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n') +*/ + +static int +parse_line(line, argv, argsize) + char *line; + char **argv; + int argsize; +{ + int argc = 0; + char *p = line; + + while(argc < argsize){ + while(isspace(*p)){ + ++p; + } + if(*p == '\0'){ + break; + } + argv[argc++] = p; + while(! isspace(*p) && *p != '\0'){ + ++p; + } + if(*p == '\0'){ + break; + } + *p++ = '\0'; + } + + return argc; +} + +#ifndef XLOCALEDIR +#define XLOCALEDIR "/usr/lib/X11/locale" +#endif + +static void +xlocaledir(path) + char *path; +{ + char *dir, *p = path; + int len; + + dir = getenv("XLOCALEDIR"); + if(dir != NULL){ + len = strlen(dir); + strcpy(p, dir); + p[len++] = ':'; + p += len; + } + strcpy(p, XLOCALEDIR); +} + +static int +parse_path(path, argv, argsize) + char *path; + char **argv; + int argsize; +{ + char *p = path; + int i, n; + + while((p = strchr(p, ':')) != NULL){ + *p = ' '; /* place space on delimter */ + } + n = parse_line(path, argv, argsize); + if(n == 0){ + return 0; + } + for(i = 0; i < n; ++i){ + int len; + p = argv[i]; + len = strlen(p); + if(p[len - 1] == '/'){ + /* eliminate slash */ + p[len - 1] = '\0'; + } + } + return n; +} + +enum { LtoR, RtoL }; + +static char * +_XlcResolveName(lc_name, file_name, direction) + char *lc_name; + char *file_name; + int direction; /* mapping direction */ +{ + FILE *fp; + char buf[BUFSIZE], *name = NULL; + + fp = fopen(file_name, "r"); + if(fp == (FILE *)NULL){ + return NULL; + } + + while(fgets(buf, BUFSIZE, fp) != NULL){ + char *p = buf; + int n; + char *args[2], *from, *to; + while(isspace(*p)){ + ++p; + } + if(iscomment(*p)){ + continue; + } + n = parse_line(p, args, 2); /* get first 2 fields */ + if(n != 2){ + continue; + } + if(direction == LtoR){ + from = args[0], to = args[1]; /* left to right */ + }else{ + from = args[1], to = args[0]; /* right to left */ + } + if(! strcmp(from, lc_name)){ + name = Xmalloc(strlen(to) + 1); + if(name != NULL){ + strcpy(name, to); + } + break; + } + } + if(fp != (FILE *)NULL){ + fclose(fp); + } + return name; +} + +/* +#define isupper(ch) ('A' <= (ch) && (ch) <= 'Z') +#define tolower(ch) ((ch) - 'A' + 'a') +*/ +static char * +lowercase(dst, src) + char *dst; + char *src; +{ + char *s, *t; + + for(s = src, t = dst; *s; ++s, ++t){ + *t = isupper(*s) ? tolower(*s) : *s; + } + *t = '\0'; + return dst; +} + +/************************************************************************/ +char * +_fallcFileName(lcd, category) + XLCd lcd; + char *category; +{ + char lc_name[BUFSIZE]; + char cat[BUFSIZE], dir[BUFSIZE]; + int i, n; + char *args[256]; + char *file_name = NULL; + + if(lcd == (XLCd)NULL){ + return NULL; + } + + if(! _fallcResolveLocaleName(XLC_PUBLIC(lcd, siname), lc_name, + NULL, NULL, NULL)){ + return NULL; + } + + lowercase(cat, category); + xlocaledir(dir); + n = parse_path(dir, args, 256); + for(i = 0; i < n; ++i){ + char buf[BUFSIZE], *name; + sprintf(buf, "%s/%s.dir", args[i], cat); + name = _XlcResolveName(lc_name, buf, RtoL); + if(name == NULL){ + continue; + } + if(*name == '/'){ + /* supposed to be absolute path name */ + file_name = name; + }else{ + sprintf(buf, "%s/%s", args[i], name); + Xfree(name); + file_name = Xmalloc(strlen(buf) + 1); + if(file_name == NULL){ + break; + } + strcpy(file_name, buf); + } + if(isreadable(file_name)){ + break; + } + Xfree(file_name); + file_name = NULL; + /* Then, try with next dir */ + } + return file_name; +} + +/************************************************************************/ +#ifndef LOCALE_ALIAS +#define LOCALE_ALIAS "locale.alias" +#endif + +int +_fallcResolveLocaleName(lc_name, full_name, language, territory, codeset) + char *lc_name; + char *full_name; + char *language; + char *territory; + char *codeset; +{ + char dir[BUFSIZE], buf[BUFSIZE], *name = NULL; + int i, n; + char *args[256]; + + xlocaledir(dir); + n = parse_path(dir, args, 256); + for(i = 0; i < n; ++i){ + sprintf(buf, "%s/%s", args[i], LOCALE_ALIAS); + name = _XlcResolveName(lc_name, buf, LtoR); + if(name != NULL){ + break; + } + } + + if(name != NULL){ + snprintf(buf, sizeof(buf), "%s", name); + Xfree(name); + }else{ + snprintf(buf, sizeof(buf), "%s", lc_name); + } + if(full_name != NULL){ + strcpy(full_name, buf); + } + + if(language || territory || codeset){ + char *ptr, *name_p; + /* + * Decompose locale name + */ + if(language) *language = '\0'; + if(territory) *territory = '\0'; + if(codeset) *codeset = '\0'; + + name_p = buf; + ptr = language; + while (1) { + if (*name_p == '_') { + if (ptr) + *ptr = '\0'; + ptr = territory; + } else if (*name_p == '.') { + if (ptr) + *ptr = '\0'; + ptr = codeset; + } else { + if (ptr) + *ptr++ = *name_p; + if (*name_p == '\0') + break; + } + name_p++; + } + } + + return (buf[0] != '\0') ? 1 : 0; +} + +/************************************************************************/ +#ifndef LOCALE_DIR +#define LOCALE_DIR "locale.dir" +#endif + +int +_fallcResolveDBName(lc_name, file_name) + char *lc_name; + char *file_name; +{ + char dir[BUFSIZE], buf[BUFSIZE], *name = NULL; + int i, n; + char *args[256]; + + xlocaledir(dir); + n = parse_path(dir, args, 256); + for(i = 0; i < n; ++i){ + sprintf(buf, "%s/%s", args[i], LOCALE_DIR); + name = _XlcResolveName(lc_name, buf, RtoL); + if(name != NULL){ + break; + } + } + if(name == NULL){ + return 0; + } + strcpy(buf, name); + Xfree(name); + if(file_name != NULL){ + strcpy(file_name, buf); + } + return 1; +} + +/************************************************************************/ +int +_fallcResolveI18NPath(path_name) + char *path_name; +{ + if(path_name != NULL){ + xlocaledir(path_name); + } + return 1; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcGenConv.c b/cde/programs/dtudcfonted/libfal/_fallcGenConv.c new file mode 100644 index 00000000..15358814 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcGenConv.c @@ -0,0 +1,2419 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcGenConv.c 1.5 - Fujitsu source for CDEnext 96/03/14 15:45:41 */ +/* $XConsortium: _fallcGenConv.c /main/1 1996/04/08 15:17:00 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Modifier: Masayoshi Shimamura FUJITSU LIMITED + * + */ + + +#include "_fallibint.h" +#include "_fallcGeneric.h" +#include + +typedef struct _CTDataRec { + char *name; + char *encoding; /* Compound Text encoding */ +} CTDataRec, *CTData; + +static CTDataRec default_ct_data[] = +{ + { "ISO8859-1:GL", "\033(B" }, + { "ISO8859-1:GR", "\033-A" }, + { "ISO8859-2:GR", "\033-B" }, + { "ISO8859-3:GR", "\033-C" }, + { "ISO8859-4:GR", "\033-D" }, + { "ISO8859-7:GR", "\033-F" }, + { "ISO8859-6:GR", "\033-G" }, + { "ISO8859-8:GR", "\033-H" }, + { "ISO8859-5:GR", "\033-L" }, + { "ISO8859-9:GR", "\033-M" }, + { "JISX0201.1976-0:GL", "\033(J" }, + { "JISX0201.1976-0:GR", "\033)I" }, + + { "GB2312.1980-0:GL", "\033$(A" }, + { "GB2312.1980-0:GR", "\033$)A" }, + { "JISX0208.1983-0:GL", "\033$(B" }, + { "JISX0208.1983-0:GR", "\033$)B" }, + { "KSC5601.1987-0:GL", "\033$(C" }, + { "KSC5601.1987-0:GR", "\033$)C" }, +#ifdef notdef + { "JISX0212.1990-0:GL", "\033$(D" }, + { "JISX0212.1990-0:GR", "\033$)D" }, + { "CNS11643.1986-1:GL", "\033$(G" }, + { "CNS11643.1986-1:GR", "\033$)G" }, + { "CNS11643.1986-2:GL", "\033$(H" }, + { "CNS11643.1986-2:GR", "\033$)H" }, + + /* Non-Standard Character Set Encodings */ + { "TIS620.2533-1:GR", "\033-T"}, +#endif +} ; + +static CTDataRec directionality_data[] = +{ + { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" }, + { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" }, + { "END_OF_STRING", "\233]" }, +}; + +typedef struct _StateRec { + XLCd lcd; + XlcCharSet charset; /* charset of current state */ + XlcCharSet GL_charset; /* charset of initial state in GL */ + XlcCharSet GR_charset; /* charset of initial state in GR */ +} StateRec, *State; + +#define GR 0x80 /* begins right-side (non-ascii) region */ +#define GL 0x7f /* ends left-side (ascii) region */ +#define ESC 0x1b +#define CSI 0x9b +#define STX 0x02 + +#define isleftside(c) (((c) & GR) ? 0 : 1) +#define isrightside(c) (!isleftside(c)) + +/* -------------------------------------------------------------------------- */ +/* Misc */ +/* -------------------------------------------------------------------------- */ + +static int +compare(src, encoding, length) + register char *src; + register char *encoding; + register int length; +{ + char *start = src; + + while (length-- > 0) { + if (*src++ != *encoding++) + return 0; + if (*encoding == '\0') + return src - start; + } + + return 0; +} + +static unsigned long +conv_to_dest(conv, code) + Conversion conv; + unsigned long code; +{ + int i; + int conv_num = conv->conv_num; + FontScope convlist = conv->convlist; + + for (i = 0; i < conv_num; i++) { + if (convlist[i].start <= code && code <= convlist[i].end) { + switch (convlist[i].shift_direction) { + case '+': + return(code + convlist[i].shift); + case '-': + return(code - convlist[i].shift); + default: + return(code); + } + } + } + + return(code); +} + +static unsigned long +conv_to_source(conv, code) + Conversion conv; + unsigned long code; +{ + int i; + int conv_num; + FontScope convlist; + unsigned long start_p; + unsigned long start_m; + unsigned long end_p; + unsigned long end_m; + + if (!conv) + return(code); + + conv_num = conv->conv_num; + convlist = conv->convlist; + + for (i = 0; i < conv_num; i++) { + start_p = convlist[i].start + convlist[i].shift; + start_m = convlist[i].start - convlist[i].shift; + end_p = convlist[i].end + convlist[i].shift; + end_m = convlist[i].end - convlist[i].shift; + + switch (convlist[i].shift_direction) { + case '+': + if (start_p <= code && code <= end_p) + return(code - convlist[i].shift); + break; + case '-': + if (start_m <= code && code <= end_m) + return(code + convlist[i].shift); + break; + default: + continue; + } + } + + return(code); +} + +static unsigned long +mb_to_gi(mb, codeset) + unsigned long mb; + CodeSet codeset; +{ + int i; + unsigned long mb_tmp, mask = 0; + + if (codeset->mbconv) { + mb_tmp = conv_to_dest(codeset->mbconv, mb); + if (mb_tmp != mb) + return(mb_tmp); + } + + if (codeset->side == XlcC0 || codeset->side == XlcGL || + codeset->side == XlcC1 || codeset->side == XlcGR) { + + for (i = 0; i < codeset->length; i++) + mask = (mask << 8) | GL; + mb = mb & mask; + } + + return(mb); +} + +static unsigned long +gi_to_mb(glyph_index, codeset) + unsigned long glyph_index; + CodeSet codeset; +{ + int i; + unsigned long mask = 0; + + if (codeset->side == XlcC1 || codeset->side == XlcGR) { + for (i = 0; i < codeset->length; i++) + mask = (mask << 8) | GR; + glyph_index = glyph_index | mask; + } + + if (codeset->mbconv) + return( conv_to_source(codeset->mbconv, glyph_index) ); + + return(glyph_index); +} + +static Bool +gi_to_wc(lcd, glyph_index, codeset, wc) + XLCd lcd; + unsigned long glyph_index; + CodeSet codeset; + wchar_t *wc; +{ + unsigned char mask = 0; + unsigned long wc_encoding = codeset->wc_encoding; + int i, length = codeset->length; + unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); + + for (i = wc_shift_bits; i > 0; i--) + mask = (mask << 1) | 0x01; + + for (*wc = 0, length--; length >= 0; length--) + *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask); + + *wc = *wc | wc_encoding; + + return(True); +} + +static Bool +wc_to_gi(lcd, wc, glyph_index, codeset) + XLCd lcd; + wchar_t wc; + unsigned long *glyph_index; + CodeSet *codeset; +{ + int i; + unsigned char mask = 0; + unsigned long wc_encoding; + unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask); + unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + + wc_encoding = wc & wc_encode_mask; + for (*codeset = NULL, i = 0; i < codeset_num; i++) { + if (wc_encoding == codeset_list[i]->wc_encoding) { + *codeset = codeset_list[i]; + break; + } + } + if (*codeset == NULL) + return(False); + + for (i = wc_shift_bits; i > 0; i--) + mask = (mask << 1) | 0x01; + + wc = wc & ~wc_encode_mask; + for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--) + *glyph_index = (*glyph_index << 8) | + ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask ); + + return(True); +} + +static CodeSet +byteM_parse_codeset(lcd, inbufptr) + XLCd lcd; + XPointer inbufptr; +{ + unsigned char ch; + CodeSet codeset; + ByteInfoList byteM; + ByteInfoListRec byteM_rec; + ByteInfo byteinfo; + ByteInfoRec byteinfo_rec; + Bool hit; + int i, j, k; + + int codeset_num = XLC_GENERIC(lcd, codeset_num); + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + + for (i = 0; i < codeset_num; i++) { + codeset = codeset_list[i]; + byteM = codeset->byteM; + if (codeset->side != XlcNONE || byteM == NULL) + continue; + + for (j = 0; j < codeset->length; j++) { + ch = *((unsigned char *)(inbufptr + j)); + byteM_rec = byteM[j]; + byteinfo = byteM_rec.byteinfo; + + for (hit=False,k=0; k < byteM_rec.byteinfo_num; k++) { + byteinfo_rec = byteinfo[k]; + if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) { + hit = True; + break; + } + } + + if (!hit) + break; + } + + if (hit) + return(codeset); + } + + return(NULL); +} + +static CodeSet +GLGR_parse_codeset(lcd, ch) + XLCd lcd; + unsigned char ch; +{ + int i; + CodeSet initial_state_GL = XLC_GENERIC(lcd, initial_state_GL); + CodeSet initial_state_GR = XLC_GENERIC(lcd, initial_state_GR); + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + + XlcSide side = XlcGL; + CodeSet codeset = initial_state_GL; + + if (isrightside(ch)) { + side = XlcGR; + codeset = initial_state_GR; + } + + if (codeset) + return(codeset); + + for (i = 0; i < codeset_num; i++) { + codeset = codeset_list[i]; + if (codeset->side == side) + return(codeset); + } + + return(NULL); +} + +static XlcCharSet +gi_parse_charset(glyph_index, codeset) + unsigned long glyph_index; + CodeSet codeset; +{ + int i; + size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]); + XlcCharSet *charset_list = codeset->charset_list; + int num_charsets = codeset->num_charsets; + ExtdSegment ctextseg = codeset->ctextseg; + XlcCharSet charset; + int area_num; + FontScope area; + + /* lockup ct sequence */ + for (i = 0; i < num_charsets; i++) { + charset = charset_list[i]; + if (*charset->ct_sequence != '\0') + break; + } + if (i >= num_charsets) + return(NULL); + + /* Standard Character Set Encoding ? */ + for (i = 0; i < table_size; i++) + if (compare(charset->ct_sequence, + default_ct_data[i].encoding, strlen(charset->ct_sequence))) + goto check_extended_seg; + + return(charset); + +check_extended_seg: + if (!ctextseg) + return(charset); + + area = ctextseg->area; + area_num = ctextseg->area_num; + + for (i = 0; i < area_num; i++) { + + if (area[i].start <= glyph_index && glyph_index <= area[i].end) { + + charset = ctextseg->charset; + + if (*charset->ct_sequence == '\0') + return(NULL); + + break; + } + } + + return(charset); +} + +static Bool +ct_parse_csi(inbufptr, ctr_seq_len) + XPointer inbufptr; + int *ctr_seq_len; +{ + int i; + int num = sizeof(directionality_data) / sizeof(directionality_data[0]); + + for (i = 0; i < num; i++) { + if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) ) + continue; + + if ( strncmp(inbufptr, directionality_data[i].encoding, + *ctr_seq_len) == 0) + return(True); + } + + return(False); +} + +static int +cmp_esc_sequence(inbufptr, ct_sequence, encoding_name) + XPointer inbufptr; + char *ct_sequence; + char *encoding_name; +{ + size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]); + int i, seq_len, name_len, total_len; + unsigned char byte_m, byte_l; + + /* check esc sequence */ + if ( !(seq_len = strlen(ct_sequence) ) ) + return(0); + if ( strncmp(inbufptr, ct_sequence, seq_len) != 0) + return(0); + + /* Standard Character Set Encoding ? */ + for (i = 0; i < table_size; i++) { + if (compare(ct_sequence, + default_ct_data[i].encoding, strlen(ct_sequence))) + return(seq_len); + } + + /* + * Non-Standard Character Set Encoding + * + * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+ + * | esc sequence | M | L | encoding name | STX | + * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+ + * 4bytes 1byte 1byte variable length 1byte + * | | + * +-----------------------------------------+ + * name length = ((M - 128) * 128) + (L - 128) + */ + + /* get length of encoding name */ + inbufptr += seq_len; + byte_m = *inbufptr++; + byte_l = *inbufptr++; + name_len = ((byte_m - 128) * 128) + (byte_l - 128); + total_len = seq_len + name_len; + + /* compare encoding names */ + if ( strncmp(inbufptr, encoding_name, name_len - 3) != 0 ) + return(0); + + /* check STX (Start of Text) */ + inbufptr = inbufptr + name_len - 3; + if ( *inbufptr != STX ) + return(0); + + return(total_len); +} + +static Bool +ct_parse_charset(lcd, inbufptr, charset, ctr_seq_len) + XLCd lcd; + XPointer inbufptr; + XlcCharSet *charset; + int *ctr_seq_len; +{ + int i, j; + ExtdSegment ctextseg; + int num_charsets; + XlcCharSet *charset_list; + CodeSet codeset; + int codeset_num = XLC_GENERIC(lcd, codeset_num); + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num); + SegConv segment_conv = XLC_GENERIC(lcd, segment_conv); + + + /* get charset from XLC_XLOCALE by escape sequence */ + + for (i = 0; i < codeset_num; i++) { + codeset = codeset_list[i]; + + num_charsets = codeset->num_charsets; + charset_list = codeset->charset_list; + ctextseg = codeset->ctextseg; + + for (j = 0; j < num_charsets; j++) { + *charset = charset_list[j]; + if ( *ctr_seq_len = cmp_esc_sequence(inbufptr, + (*charset)->ct_sequence, (*charset)->encoding_name) ) + return(True); + } + + if (ctextseg) { + *charset = ctextseg->charset; + if ( *ctr_seq_len = cmp_esc_sequence(inbufptr, + (*charset)->ct_sequence, (*charset)->encoding_name) ) + return(True); + } + } + + /* get charset from XLC_SEGMENTCONVERSION by escape sequence */ + + if (!segment_conv) + return(False); + + for (i = 0; i < segment_conv_num; i++) { + *charset = segment_conv[i].source; + if ( *ctr_seq_len = cmp_esc_sequence(inbufptr, + (*charset)->ct_sequence, (*charset)->encoding_name) ) + return(True); + *charset = segment_conv[i].dest; + if ( *ctr_seq_len = cmp_esc_sequence(inbufptr, + (*charset)->ct_sequence, (*charset)->encoding_name) ) + return(True); + } + + return(False); +} + +static Bool +segment_conversion(lcd, charset, glyph_index) + XLCd lcd; + XlcCharSet *charset; + unsigned long *glyph_index; +{ + int i; + int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num); + SegConv segment_conv = XLC_GENERIC(lcd, segment_conv); + FontScopeRec range; + ConversionRec conv_rec; + + if (!segment_conv) + return(True); + + for (i = 0; i < segment_conv_num; i++) { + if (segment_conv[i].source == *charset) + break; + } + + if (i >= segment_conv_num) + return(True); + + range = segment_conv[i].range; + if (*glyph_index < range.start || range.end < *glyph_index) + return(True); + + *charset = segment_conv[i].dest; + conv_rec.conv_num = segment_conv[i].conv_num; + conv_rec.convlist = segment_conv[i].conv; + *glyph_index = conv_to_dest(&conv_rec, *glyph_index); + + return(True); +} + +CodeSet +_fallcGetCodeSetFromName(lcd, name) + XLCd lcd; + char *name; +{ + int i, j; + XlcCharSet charset; + int num_charsets; + XlcCharSet *charset_list; + CodeSet codeset; + + int codeset_num = XLC_GENERIC(lcd, codeset_num); + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + + for (i = 0; i < codeset_num; i++) { + codeset = codeset_list[i]; + + num_charsets = codeset->num_charsets; + charset_list = codeset->charset_list; + + for (j = 0; j < num_charsets; j++) { + charset = charset_list[j]; + + if (!strlen(charset->name)) + continue; + if ( strcmp(charset->name, name) == 0) + return(codeset); + } + } + + return(NULL); +} + +static Bool +_XlcGetCodeSetFromCharSet(lcd, charset, codeset, glyph_index) + XLCd lcd; + XlcCharSet charset; + CodeSet *codeset; + unsigned long *glyph_index; +{ + int i, j, num; + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + XlcCharSet *charset_list; + int codeset_num, num_charsets; + Conversion ctconv; + unsigned long glyph_index_tmp; + ExtdSegment ctextseg; + size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]); + + codeset_num = XLC_GENERIC(lcd, codeset_num); + + for (num = 0 ; num < codeset_num; num++) { + *codeset = codeset_list[num]; + ctconv = (*codeset)->ctconv; + ctextseg = (*codeset)->ctextseg; + + num_charsets = (*codeset)->num_charsets; + charset_list = (*codeset)->charset_list; + + glyph_index_tmp = conv_to_source(ctconv, *glyph_index); + + /* Standard Character Set Encoding ? */ + for (i = 0; i < table_size; i++) { + if (compare(charset->ct_sequence, + default_ct_data[i].encoding, strlen(charset->ct_sequence))) + break; + } + + if (i < table_size) { + + /* Standard Character Set Encoding */ + if (glyph_index_tmp == *glyph_index) { + for (j = 0; j < num_charsets; j++) { + if (charset_list[j] == charset) { + goto end_loop; + } + } + } + + } else { + + /* Non-Standard Character Set Encoding */ + for (j = 0; j < num_charsets; j++) { + if (charset_list[j] == charset) { + goto end_loop; + } + } + + if (glyph_index_tmp != *glyph_index) { + if (ctextseg->charset == charset) { + goto end_loop; + } + } + + } + + } + +end_loop: + if (num < codeset_num) { + *glyph_index = glyph_index_tmp; + return(True); + } + + return(False); +} + +static Bool +check_string_encoding(codeset) + CodeSet codeset; +{ + int i; + XlcCharSet charset; + XlcCharSet *charset_list = codeset->charset_list; + int num_charsets = codeset->num_charsets; + + for (i = 0; i < num_charsets; i++) { + charset = charset_list[i]; + if ( strcmp(charset->encoding_name, "ISO8859-1") == 0 || + charset->string_encoding) + return(True); + } + + return(False); +} + +/* -------------------------------------------------------------------------- */ +/* Init */ +/* -------------------------------------------------------------------------- */ + +static void +init_state(conv) + XlcConv conv; +{ + register State state = (State) conv->state; + + /* for CT */ + state->charset = NULL; + state->GL_charset = _fallcGetCharSet("ISO8859-1:GL"); + state->GR_charset = _fallcGetCharSet("ISO8859-1:GR"); +} + +/* -------------------------------------------------------------------------- */ +/* Convert */ +/* -------------------------------------------------------------------------- */ + +static int +mbstowcs_org(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + unsigned char ch; + unsigned long mb = 0; + wchar_t wc; + + int length = 0, len_left = 0; + int unconv_num = 0; + int num; + Bool ss_flag = 0; + + CodeSet codeset = NULL; + ParseInfo parse_info; + + XPointer inbufptr = *from; + wchar_t *outbufptr = (wchar_t *) *to; + int from_size = *from_left; + + unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table); + ParseInfo *mb_parse_list = XLC_GENERIC(lcd, mb_parse_list); + + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + ch = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!ch) { + if (outbufptr) {*outbufptr++ = L'\0';} + (*to_left)--; + + /* error check */ + if (len_left) { + unconv_num += (length - len_left); + len_left = 0; + } + + continue; + } + + /* same mb char data */ + if (len_left) + goto output_one_wc; + + /* next mb char data for single shift ? */ + if (mb_parse_table) { + if ((num = mb_parse_table[ch]) > 0) { + parse_info = mb_parse_list[num - 1]; + + codeset = parse_info->codeset; + length = len_left = codeset->length; + mb = 0; + ss_flag = 1; + + continue; + } + } + + /* next mb char data for byteM ? */ + if (codeset = byteM_parse_codeset(lcd, (inbufptr - 1))) + goto next_mb_char; + + /* next mb char data for GL or GR side ? */ + if (codeset = GLGR_parse_codeset(lcd, ch)) + goto next_mb_char; + + /* can't find codeset for the ch */ + unconv_num++; + continue; + +next_mb_char: + length = len_left = codeset->length; + mb = 0; + ss_flag = 0; + +output_one_wc: + mb = (mb << 8) | ch; /* 1 byte left shift */ + len_left--; + + /* last of one mb char data */ + if (!len_left) { + gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc); + if (outbufptr) {*outbufptr++ = wc;} + (*to_left)--; + } + + } /* end of while */ + + /* error check on last char */ + if (len_left) { + inbufptr -= (length - len_left + ss_flag); + (*from_left) += (length - len_left + ss_flag); + unconv_num += (length - len_left + ss_flag); + } + + *from = *from + from_size; + *from_left = 0; + *to = (XPointer)outbufptr; + + return unconv_num; +} + +static int +wcstombs_org(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + char *encoding; + unsigned long mb, glyph_index; + wchar_t wc; + + int length; + int unconv_num = 0; + + CodeSet codeset; + + wchar_t *inbufptr = (wchar_t *) *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + char *default_string = XLC_PUBLIC(lcd, default_string); + int defstr_len = strlen(default_string); + + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + wc = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!wc) { + if (outbufptr) {*outbufptr++ = '\0';} + (*to_left)--; + + continue; + } + + /* convert */ + if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { + + /* output default_string of falDefaultString() */ + if (*to_left < defstr_len) + break; + if (outbufptr) {strncpy((char *)outbufptr, default_string, defstr_len);} + + if (outbufptr) {outbufptr += defstr_len;} + (*to_left) -= defstr_len; + + unconv_num++; + + } else { + mb = gi_to_mb(glyph_index, codeset); + if (codeset->parse_info) { + + /* output shift sequence */ + encoding = codeset->parse_info->encoding; + length = strlen(encoding); + if (*to_left < length) + break; + if (outbufptr) {strncpy((char *)outbufptr, encoding, length);} + + if (outbufptr) {outbufptr += length;} + (*to_left) -= length; + } + + /* output characters */ + length = codeset->length; + if (*to_left < length) + break; + if (outbufptr) {strncpy((char *)outbufptr, ((char *)&mb)+sizeof(mb)-length, length);} + + if (outbufptr) {outbufptr += length;} + (*to_left) -= length; + } + + } /* end of while */ + + *from = *from + from_size; + *from_left = 0; + *to = outbufptr; + + return unconv_num; +} + +static int +wcstocts(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + size_t table_size = sizeof(default_ct_data) / sizeof(default_ct_data[0]); + State state = (State) conv->state; + XLCd lcd = state->lcd; + + unsigned long glyph_index; + wchar_t wc; + + int i, total_len, seq_len, name_len; + int unconv_num = 0; + Bool first_flag = True, standard_flag; + XlcSide side; + + CodeSet codeset; + XlcCharSet charset, old_charset = NULL; + char *ct_sequence; + XPointer p; + + wchar_t *inbufptr = (wchar_t *) *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + wc = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!wc) { + if (outbufptr) {*outbufptr++ = '\0';} + (*to_left)--; + + continue; + } + + /* convert */ + if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { + unconv_num++; + continue; + } + + /* parse charset */ + if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) { + unconv_num++; + continue; + } + + /* Standard Character Set Encoding ? */ + standard_flag = False; + for (i = 0; i < table_size; i++) + if (compare(charset->ct_sequence, + default_ct_data[i].encoding, strlen(charset->ct_sequence))) + standard_flag = True; + + /* + * Non-Standard Character Set Encoding + * + * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+ + * | esc sequence | M | L | encoding name | STX | + * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+ + * 4bytes 1byte 1byte variable length 1byte + * | | + * +-----------------------------------------+ + * name length = ((M - 128) * 128) + (L - 128) + */ + + /* make encoding data */ + ct_sequence = charset->ct_sequence; + side = charset->side; + seq_len = strlen(charset->ct_sequence); + if (standard_flag) { + name_len = 0; + total_len = seq_len; + } else { + name_len = 2 + strlen(charset->encoding_name) + 1; + total_len = seq_len + name_len; + } + + /* output escape sequence of CT */ + if ( (charset != old_charset) && + !(first_flag && (strcmp(charset->encoding_name,"ISO8859-1")==0))) { + + if (*to_left < total_len + 1) { + unconv_num++; + break; + } + + if (outbufptr) { + strcpy((char *)outbufptr, charset->ct_sequence); + outbufptr += seq_len; + + if (!standard_flag) { + *outbufptr++ = name_len / 128 + 128; + *outbufptr++ = name_len % 128 + 128; + strcpy((char *)outbufptr, charset->encoding_name); + outbufptr = outbufptr + name_len - 2 - 1; + *outbufptr++ = STX; + } + } + + (*to_left) -= total_len; + + first_flag = False; + old_charset = charset; + } + + /* output glyph index */ + if (codeset->ctconv) + glyph_index = conv_to_dest(codeset->ctconv, glyph_index); + if (*to_left < charset->char_size) { + unconv_num++; + break; + } + + p = ((XPointer)&glyph_index) + sizeof(glyph_index) - charset->char_size; + for (i = 0; i < charset->char_size; i++) { + if (side == XlcC0 || side == XlcGL) { + if (outbufptr) {*outbufptr++ = *p++ & GL;} + } else if (side == XlcC1 || side == XlcGR) { + if (outbufptr) {*outbufptr++ = *p++ | GR;} + } else { + if (outbufptr) {*outbufptr++ = *p++;} + } + } + + (*to_left) -= charset->char_size; + + } /* end of while */ + + *from = *from + from_size; + *from_left = 0; + *to = outbufptr; + + return unconv_num; +} + +static int +ctstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + unsigned char ch; + unsigned long glyph_index = 0; + wchar_t wc; + + int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0; + int unconv_num = 0; + + CodeSet codeset = NULL; + XlcCharSet charset_tmp; + + XPointer inbufptr = *from; + wchar_t *outbufptr = (wchar_t *) *to; + int from_size = *from_left; + + + init_state(conv); + + if (from == NULL || *from == NULL) { + init_state(conv); + return( 0 ); + } + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + ch = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!ch) { + if (outbufptr) {*outbufptr++ = L'\0';} + (*to_left)--; + + /* error check */ + if (gi_len_left) { + unconv_num += (gi_len - gi_len_left); + gi_len_left = 0; + } + + continue; + } + + /* same glyph_index data */ + if (gi_len_left) + goto output_one_wc; + + /* control sequence ? */ + if (ch == CSI) { + if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) ) + goto skip_the_seg; + + if (*from_left < ctr_seq_len) { + inbufptr--; + (*from_left)++; + unconv_num += *from_left; + break; + } + + /* skip the control sequence */ + inbufptr += (ctr_seq_len - 1); + *from_left -= (ctr_seq_len - 1); + + continue; + } + + /* escape sequence ? */ + if (ch == ESC) { + if ( !ct_parse_charset(lcd, + inbufptr - 1, &state->charset, &ctr_seq_len) ) + goto skip_the_seg; + + if (*from_left < ctr_seq_len) { + inbufptr--; + (*from_left)++; + unconv_num += *from_left; + break; + } + + /* skip the escape sequence */ + inbufptr += (ctr_seq_len - 1); + *from_left -= (ctr_seq_len - 1); + + continue; + } + + /* check current state */ + if (state->charset) { + if (state->charset->side == XlcC0 || + state->charset->side == XlcGL) { + state->GL_charset = state->charset; + + } else if (state->charset->side == XlcC1 || + state->charset->side == XlcGR) { + state->GR_charset = state->charset; + } + } else { + if (isleftside(ch)) + state->charset = state->GL_charset; + else + state->charset = state->GR_charset; + } + + gi_len = gi_len_left = state->charset->char_size; + glyph_index = 0; + +output_one_wc: + if (state->charset->side == XlcC1 || state->charset->side == XlcGR) + glyph_index = (glyph_index << 8) | (ch & GL); + else + glyph_index = (glyph_index << 8) | ch; + + gi_len_left--; + + /* last of one glyph_index data */ + if (!gi_len_left) { + + /* segment conversion */ + charset_tmp = state->charset; + if ( !segment_conversion(lcd, &charset_tmp, &glyph_index) ) { + unconv_num += gi_len; + continue; + } + + /* get codeset */ + if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp, + &codeset, &glyph_index) ) { + unconv_num += gi_len; + continue; + } + + /* convert glyph index to wicd char */ + gi_to_wc(lcd, glyph_index, codeset, &wc); + if (outbufptr) {*outbufptr++ = wc;} + (*to_left)--; + } + + continue; + +skip_the_seg: + /* skip until next escape or control sequence */ + while ( *from_left ) { + ch = *inbufptr++; + (*from_left)--; + unconv_num++; + + if (ch == ESC || ch == CSI) { + inbufptr--; + (*from_left)++; + unconv_num--; + break; + } + } + + if ( !(*from_left) ) + break; + + } /* end of while */ + + /* error check on last char */ + if (gi_len_left) { + inbufptr -= (gi_len - gi_len_left); + (*from_left) += (gi_len - gi_len_left); + unconv_num += (gi_len - gi_len_left); + } + + *from = *from + from_size; + *from_left = 0; + *to = (XPointer)outbufptr; + + return unconv_num; +} + +static int +mbstocts(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t)); + XPointer buf_ptr1 = buf; + int buf_left1 = (*from_left); + XPointer buf_ptr2 = buf_ptr1; + int buf_left2; + int unconv_num; + + unconv_num = mbstowcs_org(conv, + from, from_left, &buf_ptr1, &buf_left1, args, num_args); + if (unconv_num < 0) + goto ret; + + buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t); + + unconv_num += wcstocts(conv, + &buf_ptr2, &buf_left2, to, to_left, args, num_args); + if (unconv_num < 0) + goto ret; + +ret: + if (buf) + Xfree((char *)buf); + + return unconv_num; +} + +static int +mbstostr(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + unsigned char ch; + unsigned long mb = 0; + + + int length = 0, len_left = 0; + int unconv_num = 0; + int num; + Bool ss_flag = 0; + + CodeSet codeset = NULL; + ParseInfo parse_info; + + XPointer inbufptr = *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table); + ParseInfo *mb_parse_list = XLC_GENERIC(lcd, mb_parse_list); + + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + ch = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!ch) { + if (outbufptr) {*outbufptr++ = '\0';} + (*to_left)--; + + /* error check */ + if (len_left) { + unconv_num += (length - len_left); + len_left = 0; + } + + continue; + } + + /* same mb char data */ + if (len_left) + goto output_one_mb; + + /* next mb char data for single shift ? */ + if (mb_parse_table) { + if ((num = mb_parse_table[ch]) > 0) { + parse_info = mb_parse_list[num - 1]; + + codeset = parse_info->codeset; + length = len_left = codeset->length; + mb = 0; + ss_flag = 1; + + continue; + } + } + + /* next char data : byteM ? */ + if (codeset = byteM_parse_codeset(lcd, (inbufptr - 1))) + goto next_mb_char; + + /* next char data : GL or GR side ? */ + if (codeset = GLGR_parse_codeset(lcd, ch)) + goto next_mb_char; + + /* can't find codeset for the ch */ + unconv_num++; + continue; + +next_mb_char: + length = len_left = codeset->length; + mb = 0; + ss_flag = 0; + +output_one_mb: + mb = (mb << 8) | ch; /* 1 byte left shift */ + len_left--; + + /* last of one mb char data */ + if (!len_left) { + if (check_string_encoding(codeset)) { + if (outbufptr) {*outbufptr++ = mb & 0xff;} + (*to_left)--; + } else { + unconv_num++; + } + } + + } /* end of while */ + + /* error check on last char */ + if (len_left) { + inbufptr -= (length - len_left + ss_flag); + (*from_left) += (length - len_left + ss_flag); + unconv_num += (length - len_left + ss_flag); + } + + *from = *from + from_size; + *from_left = 0; + *to = (XPointer)outbufptr; + + return unconv_num; +} + +static int +mbtocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + unsigned char ch; + unsigned long mb = 0; + unsigned long glyph_index; + + int length = 0, len_left = 0, char_len; + int unconv_num = 0; + int i, num; + XlcSide side; + + CodeSet codeset = NULL; + XlcCharSet charset = NULL; + ParseInfo parse_info; + XPointer p; + + XPointer inbufptr = *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + + unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table); + ParseInfo *mb_parse_list = XLC_GENERIC(lcd, mb_parse_list); + + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + ch = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!ch) { + unconv_num = 1; + if (len_left) + unconv_num += (length - len_left); + break; + } + + /* same mb char data */ + if (len_left) + goto output; + + /* next mb char data for single shift ? */ + if (mb_parse_table) { + if ((num = mb_parse_table[ch]) > 0) { + parse_info = mb_parse_list[num - 1]; + + codeset = parse_info->codeset; + length = len_left = codeset->length; + mb = 0; + + continue; + } + } + + /* next mb char data for byteM ? */ + if (codeset = byteM_parse_codeset(lcd, (inbufptr - 1))) + goto next_mb_char; + + /* next mb char data for GL or GR side ? */ + if (codeset = GLGR_parse_codeset(lcd, ch)) + goto next_mb_char; + + /* can't find codeset for the ch */ + unconv_num = 1; + break; + +next_mb_char: + length = len_left = codeset->length; + mb = 0; + +output: + mb = (mb << 8) | ch; /* 1 byte left shift */ + len_left--; + + /* last of one mb char data */ + if (!len_left) { + glyph_index = mb_to_gi(mb, codeset); + if (!(charset = gi_parse_charset(glyph_index, codeset))) { + unconv_num = length; + break; + } + char_len = charset->char_size; + side = charset->side; + + /* output glyph index */ + if (codeset->ctconv) + glyph_index = conv_to_dest(codeset->ctconv, glyph_index); + if (*to_left < char_len) { + unconv_num = length; + break; + } + + p = ((XPointer)&glyph_index) + sizeof(glyph_index) - char_len; + for (i = 0; i < char_len; i++) { + if (side == XlcC0 || side == XlcGL) { + if (outbufptr) {*outbufptr++ = *p++ & GL;} + } else if (side == XlcC1 || side == XlcGR) { + if (outbufptr) {*outbufptr++ = *p++ | GR;} + } else { + if (outbufptr) {*outbufptr++ = *p++;} + } + } + + (*to_left) -= char_len; + + break; + } + + } /* end of while */ + + /* error end */ + if (unconv_num) { + *from = *from + from_size; + *from_left = 0; + *to = outbufptr; + return -1; + } + + /* nomal end */ + *from = inbufptr; + *to = outbufptr; + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset; + + return 0; +} + +static int +mbstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + int ret; + XlcCharSet charset_old, charset = NULL; + XPointer tmp_args[1]; + + XPointer inbufptr; + int in_left; + XPointer outbufptr; + int out_left; + tmp_args[0] = (XPointer) &charset; + + ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1); + charset_old = charset; + inbufptr = *from; + in_left = *from_left; + outbufptr = *to; + out_left = *to_left; + + while ( ret == 0 && *from_left && *to_left && charset_old == charset ) { + charset_old = charset; + inbufptr = *from; + in_left = *from_left; + outbufptr = *to; + out_left = *to_left; + ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1); + } + + *from = inbufptr; + *from_left = in_left; + *to = outbufptr; + *to_left = out_left; + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset_old; + + /* error end */ + if (ret != 0) + return( -1 ); + + return(0); +} + +static int +wcstostr(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + char *encoding; + unsigned long mb, glyph_index; + wchar_t wc; + + int length; + int unconv_num = 0; + + CodeSet codeset; + + wchar_t *inbufptr = (wchar_t *) *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + char *default_string = XLC_PUBLIC(lcd, default_string); + int defstr_len = strlen(default_string); + + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + wc = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!wc) { + if (outbufptr) {*outbufptr++ = '\0';} + (*to_left)--; + + continue; + } + + /* convert */ + if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { + + /* output default_string of falDefaultString() */ + if (*to_left < defstr_len) + break; + if (outbufptr) {strncpy((char *)outbufptr, default_string, defstr_len);} + + if (outbufptr) {outbufptr += defstr_len;} + (*to_left) -= defstr_len; + + unconv_num++; + + } else { + mb = gi_to_mb(glyph_index, codeset); + if (codeset->parse_info) { + + /* output shift sequence */ + encoding = codeset->parse_info->encoding; + length = strlen(encoding); + if (*to_left < length) + break; + if (check_string_encoding(codeset)) { + if (outbufptr) {strncpy((char *)outbufptr, encoding, length);} + if (outbufptr) {outbufptr += length;} + (*to_left) -= length; + } + } + + /* output characters */ + length = codeset->length; + if (*to_left < length) + break; + if (check_string_encoding(codeset)) { + if (outbufptr) {strncpy((char *)outbufptr, + ((char *)&mb) + sizeof(mb) - length, length);} + if (outbufptr) {outbufptr += length;} + (*to_left) -= length; + } else { + unconv_num++; + } + } + + } /* end of while */ + + *from = *from + from_size; + *from_left = 0; + *to = outbufptr; + + return unconv_num; +} + +static int +wctocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + wchar_t wc; + unsigned long glyph_index; + + int i, char_len; + int unconv_num = 0; + XlcSide side; + + CodeSet codeset; + XlcCharSet charset; + XPointer p; + + wchar_t *inbufptr = (wchar_t *) *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + + + if (*from_left > *to_left) + *from_left = *to_left; + + if (*from_left && *to_left) { + + wc = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!wc) { + unconv_num = 1; + goto end; + } + + /* convert */ + if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { + unconv_num = 1; + goto end; + } + + if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) { + unconv_num = 1; + goto end; + } + char_len = charset->char_size; + side = charset->side; + + /* output glyph index */ + if (codeset->ctconv) + glyph_index = conv_to_dest(codeset->ctconv, glyph_index); + if (*to_left < char_len) { + unconv_num++; + goto end; + } + + p = ((XPointer)&glyph_index) + sizeof(glyph_index) - char_len; + for (i = 0; i < char_len; i++) { + if (side == XlcC0 || side == XlcGL) { + if (outbufptr) {*outbufptr++ = *p++ & GL;} + } else if (side == XlcC1 || side == XlcGR) { + if (outbufptr) {*outbufptr++ = *p++ | GR;} + } else { + if (outbufptr) {*outbufptr++ = *p++;} + } + } + + (*to_left) -= char_len; + + } + +end: + + /* error end */ + if (unconv_num) { + *from = *from + from_size; + *from_left = 0; + *to = outbufptr; + return -1; + } + + /* nomal end */ + *from = (XPointer)inbufptr; + *to = outbufptr; + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset; + + return 0; +} + +static int +wcstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + int ret; + XlcCharSet charset_old, charset = NULL; + XPointer tmp_args[1]; + + wchar_t *inbufptr; + int in_left; + XPointer outbufptr; + int out_left; + tmp_args[0] = (XPointer) &charset; + + ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1); + charset_old = charset; + inbufptr = (wchar_t *)(*from); + in_left = *from_left; + outbufptr = *to; + out_left = *to_left; + + while ( ret == 0 && *from_left && *to_left && charset_old == charset ) { + charset_old = charset; + inbufptr = (wchar_t *)(*from); + in_left = *from_left; + outbufptr = *to; + out_left = *to_left; + ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1); + } + + *from = (XPointer)inbufptr; + *from_left = in_left; + *to = outbufptr; + *to_left = out_left; + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset_old; + + /* error end */ + if (ret != 0) + return( -1 ); + + return(0); +} + +static int +ctstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t)); + XPointer buf_ptr1 = buf; + int buf_left1 = (*from_left); + XPointer buf_ptr2 = buf_ptr1; + int buf_left2; + int unconv_num; + + unconv_num = ctstowcs(conv, + from, from_left, &buf_ptr1, &buf_left1, args, num_args); + if (unconv_num < 0) + goto ret; + + buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t); + + unconv_num += wcstombs_org(conv, + &buf_ptr2, &buf_left2, to, to_left, args, num_args); + if (unconv_num < 0) + goto ret; + +ret: + if (buf) + Xfree((char *)buf); + + return unconv_num; +} + +static int +strtombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + char *encoding; + unsigned long mb, glyph_index; + unsigned char ch; + + int length; + int unconv_num = 0; + + CodeSet codeset; + + XPointer inbufptr = *from; + XPointer outbufptr = *to; + int from_size = *from_left; + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + ch = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!ch) { + if (outbufptr) {*outbufptr++ = '\0';} + (*to_left)--; + + continue; + } + + /* convert */ + if (isleftside(ch)) { + glyph_index = ch; + codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GL"); + } else { + glyph_index = ch & GL; + codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GR"); + } + + if (!codeset) { + unconv_num++; + continue; + } + + mb = gi_to_mb(glyph_index, codeset); + if (codeset->parse_info) { + + /* output shift sequence */ + encoding = codeset->parse_info->encoding; + length = strlen(encoding); + if (*to_left < length) + break; + if (outbufptr) {strncpy((char *)outbufptr, encoding, length);} + + if (outbufptr) {outbufptr += length;} + (*to_left) -= length; + } + + /* output characters */ + length = codeset->length; + if (*to_left < length) + break; + if (outbufptr) {strncpy((char *)outbufptr, ((char *)&mb)+sizeof(mb)-length, length);} + + if (outbufptr) {outbufptr += length;} + (*to_left) -= length; + + } /* end of while */ + + *from = *from + from_size; + *from_left = 0; + *to = outbufptr; + + return unconv_num; +} + +static int +strtowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + State state = (State) conv->state; + XLCd lcd = state->lcd; + + unsigned char ch; + unsigned long glyph_index; + wchar_t wc; + + int unconv_num = 0; + CodeSet codeset; + + XPointer inbufptr = *from; + wchar_t *outbufptr = (wchar_t *)*to; + int from_size = *from_left; + + if (*from_left > *to_left) + *from_left = *to_left; + + while (*from_left && *to_left) { + + ch = *inbufptr++; + (*from_left)--; + + /* null ? */ + if (!ch) { + if (outbufptr) {*outbufptr++ = L'\0';} + (*to_left)--; + + continue; + } + + /* convert */ + if (isleftside(ch)) { + glyph_index = ch; + codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GL"); + } else { + glyph_index = ch & GL; + codeset = _fallcGetCodeSetFromName(lcd, "ISO8859-1:GR"); + } + + if (!codeset) { + unconv_num++; + continue; + } + + gi_to_wc(lcd, glyph_index, codeset, &wc); + if (outbufptr) {*outbufptr++ = wc;} + (*to_left)--; + + } /* end of while */ + + *from = *from + from_size; + *from_left = 0; + *to = (XPointer)outbufptr; + + return unconv_num; +} + +/* -------------------------------------------------------------------------- */ +/* Close */ +/* -------------------------------------------------------------------------- */ + +static void +close_converter(conv) + XlcConv conv; +{ + if (conv->state) { + Xfree((char *) conv->state); + } + + if (conv->methods) { + Xfree((char *) conv->methods); + } + + Xfree((char *) conv); +} + +/* -------------------------------------------------------------------------- */ +/* Open */ +/* -------------------------------------------------------------------------- */ + +static XlcConv +create_conv(lcd, methods) + XLCd lcd; + XlcConvMethods methods; +{ + XlcConv conv; + State state; + + conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (conv == NULL) + return (XlcConv) NULL; + + conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec)); + if (conv->methods == NULL) + goto err; + *conv->methods = *methods; + if (XLC_PUBLIC(lcd, is_state_depend)) + conv->methods->reset = init_state; + + conv->state = (XPointer) Xmalloc(sizeof(StateRec)); + if (conv->state == NULL) + goto err; + bzero((char *) conv->state, sizeof(StateRec)); + + state = (State) conv->state; + state->lcd = lcd; + init_state(conv); + + return conv; + +err: + close_converter(conv); + + return (XlcConv) NULL; +} + +static XlcConvMethodsRec mbstowcs_methods = { + close_converter, + mbstowcs_org, + NULL +} ; + +static XlcConv +open_mbstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &mbstowcs_methods); +} + +static XlcConvMethodsRec mbstocts_methods = { + close_converter, + mbstocts, + NULL +} ; + +static XlcConv +open_mbstocts(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &mbstocts_methods); +} + +static XlcConvMethodsRec mbstostr_methods = { + close_converter, + mbstostr, + NULL +} ; + +static XlcConv +open_mbstostr(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &mbstostr_methods); +} + +static XlcConvMethodsRec mbstocs_methods = { + close_converter, + mbstocs, + NULL +} ; + +static XlcConv +open_mbstocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &mbstocs_methods); +} + +static XlcConvMethodsRec mbtocs_methods = { + close_converter, + mbtocs, + NULL +} ; + +static XlcConv +open_mbtocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &mbtocs_methods); +} + +static XlcConvMethodsRec wcstombs_methods = { + close_converter, + wcstombs_org, + NULL +} ; + +static XlcConv +open_wcstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &wcstombs_methods); +} + +static XlcConvMethodsRec wcstocts_methods = { + close_converter, + wcstocts, + NULL +} ; + +static XlcConv +open_wcstocts(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &wcstocts_methods); +} + +static XlcConvMethodsRec wcstostr_methods = { + close_converter, + wcstostr, + NULL +} ; + +static XlcConv +open_wcstostr(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &wcstostr_methods); +} + +static XlcConvMethodsRec wcstocs_methods = { + close_converter, + wcstocs, + NULL +} ; + +static XlcConv +open_wcstocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &wcstocs_methods); +} + +static XlcConvMethodsRec wctocs_methods = { + close_converter, + wctocs, + NULL +} ; + +static XlcConv +open_wctocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &wctocs_methods); +} + +static XlcConvMethodsRec ctstombs_methods = { + close_converter, + ctstombs, + NULL +} ; + +static XlcConv +open_ctstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &ctstombs_methods); +} + +static XlcConvMethodsRec ctstowcs_methods = { + close_converter, + ctstowcs, + NULL +} ; + +static XlcConv +open_ctstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &ctstowcs_methods); +} + +static XlcConvMethodsRec strtombs_methods = { + close_converter, + strtombs, + NULL +} ; + +static XlcConv +open_strtombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &strtombs_methods); +} + +static XlcConvMethodsRec strtowcs_methods = { + close_converter, + strtowcs, + NULL +} ; + +static XlcConv +open_strtowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &strtowcs_methods); +} + +/* -------------------------------------------------------------------------- */ +/* Loader */ +/* -------------------------------------------------------------------------- */ + +XLCd +_fallcGenericLoader(name) + char *name; +{ + XLCd lcd; + + lcd = _fallcCreateLC(name, _fallcGenericMethods); + if (lcd == NULL) + return lcd; + + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); + + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_wctocs); + + _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs); + _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs); + + _fallcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs); + _fallcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs); + + return lcd; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcGeneric.c b/cde/programs/dtudcfonted/libfal/_fallcGeneric.c new file mode 100644 index 00000000..0a792a31 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcGeneric.c @@ -0,0 +1,1195 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcGeneric.c 1.4 - Fujitsu source for CDEnext 96/02/29 18:02:54 */ +/* $XConsortium: _fallcGeneric.c /main/2 1996/09/27 19:03:31 drk $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietry source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ + +#include +#include "_fallibint.h" +#include "_fallcGeneric.h" + +static XLCd create(); +static Bool initialize(); +static void destroy(); + +static XLCdPublicMethodsRec genericMethods = { + { NULL }, /* use default methods */ + { + NULL, + create, + initialize, + destroy, + NULL + } +}; + +XLCdMethods _fallcGenericMethods = (XLCdMethods) &genericMethods; + +static XLCd +create(name, methods) + char *name; + XLCdMethods methods; +{ + XLCd lcd; + XLCdPublicMethods new; + + lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + if (lcd == NULL) + return (XLCd) NULL; + bzero((char *) lcd, sizeof(XLCdRec)); + + lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec)); + if (lcd->core == NULL) + goto err; + bzero((char *) lcd->core, sizeof(XLCdGenericRec)); + + new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); + if (new == NULL) + goto err; + *new = *((XLCdPublicMethods) methods); + lcd->methods = (XLCdMethods) new; + + return lcd; + +err: + Xfree(lcd); + return (XLCd) NULL; +} + +static Bool +string_to_encoding(str, encoding) + char *str; + char *encoding; +{ + char *next; + long value; + int base; + + while (*str) { + if (*str == '\\') { + switch (*(str + 1)) { + case 'x': + case 'X': + base = 16; + break; + default: + base = 8; + break; + } + value = strtol(str + 2, &next, base); + if (str + 2 != next) { + *((unsigned char *) encoding++) = (unsigned char) value; + str = next; + continue; + } + } + *encoding++ = *str++; + } + + *encoding = '\0'; + + return True; +} + +static Bool +string_to_ulong(str, value) +char *str; +unsigned long *value; +{ + char *tmp1 = str; + int base; + + if(*tmp1++ != '\\'){ + tmp1--; + base = 10; + }else{ + switch(*tmp1++){ + case 'x': + base = 16; + break; + case 'o': + base = 8; + break; + case 'd': + base = 10; + break; + default: + return(False); + } + } + *value = (unsigned) strtol(tmp1, NULL, base); + return(True); +} + + +static Bool +add_charset(codeset, charset) + CodeSet codeset; + XlcCharSet charset; +{ + XlcCharSet *new_list; + int num; + + if (num = codeset->num_charsets) + new_list = (XlcCharSet *) Xrealloc(codeset->charset_list, + (num + 1) * sizeof(XlcCharSet)); + else + new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet)); + + if (new_list == NULL) + return False; + + new_list[num] = charset; + codeset->charset_list = new_list; + codeset->num_charsets = num + 1; + + return True; +} + +static CodeSet +add_codeset(gen) + XLCdGenericPart *gen; +{ + CodeSet new, *new_list; + int num; + + new = (CodeSet) Xmalloc(sizeof(CodeSetRec)); + if (new == NULL) + return NULL; + bzero((char *) new, sizeof(CodeSetRec)); + + if (num = gen->codeset_num) + new_list = (CodeSet *) Xrealloc(gen->codeset_list, + (num + 1) * sizeof(CodeSet)); + else + new_list = (CodeSet *) Xmalloc(sizeof(CodeSet)); + + if (new_list == NULL) + goto err; + + new_list[num] = new; + gen->codeset_list = new_list; + gen->codeset_num = num + 1; + + return new; + +err: + Xfree(new); + + return NULL; +} + +static Bool +add_parse_list(gen, type, encoding, codeset) + XLCdGenericPart *gen; + EncodingType type; + char *encoding; + CodeSet codeset; +{ + ParseInfo new, *new_list; + char *str; + unsigned char ch; + int num; + + str = (char *) Xmalloc(strlen(encoding) + 1); + if (str == NULL) + return False; + strcpy(str, encoding); + + new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec)); + if (new == NULL) + goto err; + bzero((char *) new, sizeof(ParseInfoRec)); + + if (gen->mb_parse_table == NULL) { + gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */ + if (gen->mb_parse_table == NULL) + goto err; + bzero((char *) gen->mb_parse_table, 256); + } + + if (num = gen->mb_parse_list_num) + new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list, + (num + 2) * sizeof(ParseInfo)); + else { + new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo)); + } + + if (new_list == NULL) + goto err; + + new_list[num] = new; + new_list[num + 1] = NULL; + gen->mb_parse_list = new_list; + gen->mb_parse_list_num = num + 1; + + ch = (unsigned char) *str; + if (gen->mb_parse_table[ch] == 0) + gen->mb_parse_table[ch] = num + 1; + + new->type = type; + new->encoding = str; + new->codeset = codeset; + + if (codeset->parse_info == NULL) + codeset->parse_info = new; + + return True; + +err: + Xfree(str); + if (new) + Xfree(new); + + return False; +} + +static void +free_charset(lcd) + XLCd lcd; +{ + XLCdGenericPart *gen = XLC_GENERIC_PART(lcd); + CodeSet *codeset; + ParseInfo *parse_info; + int num; + + if (gen->mb_parse_table) + Xfree(gen->mb_parse_table); + if (num = gen->mb_parse_list_num) { + for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) { + if ((*parse_info)->encoding) + Xfree((*parse_info)->encoding); + Xfree(*parse_info); + } + Xfree(gen->mb_parse_list); + } + + if (num = gen->codeset_num) + Xfree(gen->codeset_list); +} +/* For VW/UDC */ + +#define FORWARD (unsigned long)'+' +#define BACKWARD (unsigned long)'-' + +static char *getscope(str,scp) +char *str; +FontScope scp; +{ + char buff[256],*next; + unsigned long start=0,end=0,dest=0,shift=0,direction=0; + sscanf(str,"[\\x%lx,\\x%lx]->\\x%lx", &start, &end, &dest); + if( dest ){ + if(dest >= start ){ + shift = dest - start; + direction = FORWARD ; + } else { + shift = start - dest; + direction = BACKWARD; + } + } + scp->start = start ; + scp->end = end ; + scp->shift = shift ; + scp->shift_direction + = direction ; + /* .......... */ + while(*str){ + if(*str == ',' && *(str+1) == '['){ + break; + } + str++; + } + next = str+1 ; + return(next); +} +static int count_scopemap(str) +char *str; +{ + char *ptr; + int num=0; + for(ptr=str;*ptr;ptr++){ + if(*ptr == ']'){ + num ++; + } + } + return(num); +} +FontScope falparse_scopemaps(str,size) +char *str; +int *size; +{ + int num=0,i; + FontScope scope,sc_ptr; + char *str_sc; + num = count_scopemap(str); + scope = (FontScope )Xmalloc(num * sizeof(FontScopeRec)); + if(scope == NULL) { + return (NULL); + } + for (i=0,str_sc=str,sc_ptr=scope; + i < num; i++,sc_ptr++){ + str_sc = getscope(str_sc,sc_ptr); + } + *size = num; + return (scope); +} + +void +dbg_printValue(str,value,num) +char *str; +char **value; +int num; +{ +/* + int i; + for(i=0;i 0) { + snprintf(cset_name, sizeof(cset_name), "%s", value[0]); + snprintf(name, sizeof(name), "%s.%s", csd , "side"); + _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + if( !_fallcNCompareISOLatin1(value[0], "none", 4) ){ + side = XlcNONE ; + strcat(cset_name,":none"); + } else + if( !_fallcNCompareISOLatin1(value[0], "GL", 2) ){ + side = XlcGL ; + strcat(cset_name,":GL"); + } else { + side = XlcGR ; + strcat(cset_name,":GR"); + } + if (charsetd == NULL && + (charsetd = srch_charset_define(cset_name,&new)) == NULL) + return 0; + } + } else { + if(i == 0){ + continue ; + } else { + break ; + } + } + if(new){ + tmp = (char *)Xmalloc(strlen(cset_name)+1); + if(tmp == NULL){ + return 0; + } + strcpy(tmp,cset_name); + charsetd->name = tmp; + } + /* side */ + charsetd->side = side ; + /* length */ + snprintf(name, sizeof(name), "%s.%s", csd , "length"); + _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + charsetd->char_size = atoi(value[0]); + } + /* gc_number */ + snprintf(name, sizeof(name), "%s.%s", csd , "gc_number"); + _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + charsetd->set_size = atoi(value[0]); + } + /* string_encoding */ + snprintf(name, sizeof(name), "%s.%s", csd , "string_encoding"); + _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + if(!strcmp("False",value[0])){ + charsetd->string_encoding = False; + } else { + charsetd->string_encoding = True; + } + } + /* sequence */ + snprintf(name, sizeof(name), "%s.%s", csd , "sequence"); + _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); +/* + if(charsetd->ct_sequence){ + Xfree(charsetd->ct_sequence); + } +*/ + tmp = (char *)Xmalloc(strlen(value[0])+1); + if(tmp == NULL){ + return 0; + } + charsetd->ct_sequence = tmp; + string_to_encoding(value[0],tmp); + } + /* encoding_name */ + snprintf(name, sizeof(name), "%s.%s", csd , "encoding_name"); + _fallcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); +/* + if(charsetd->encoding_name){ + Xfree(charsetd->encoding_name); + } +*/ + tmp = (char *)Xmalloc(strlen(value[0]) + 1); + strcpy(tmp,value[0]); + charsetd->encoding_name = tmp; + charsetd->xrm_encoding_name = + falrmStringToQuark(tmp); + } + } + return 1; +} + +SegConv +faladd_conversion(gen) +XLCdGenericPart *gen; +{ + SegConv new_list; + int num; + + if (num = gen->segment_conv_num){ + new_list = (SegConv) Xrealloc(gen->segment_conv, + (num + 1) * sizeof(SegConvRec)); + } else { + new_list = (SegConv) Xmalloc(sizeof(SegConvRec)); + } + + if (new_list == NULL) + return False; + + gen->segment_conv = new_list; + gen->segment_conv_num = num + 1; + + return (&new_list[num]); + +} +static int +read_segmentconversion(lcd,gen) +XLCd lcd; +XLCdGenericPart *gen; +{ + int i=0; + char conv[16]; + char name[BUFSIZ]; + char **value; + int num,new; + SegConv conversion; + for(i=0 ; ; i++){ /* loop start */ + conversion = 0; + sprintf(conv, "conv%d", i); + + /* length */ + sprintf(name, "%s.%s", conv , "length"); + _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); + if (num > 0) { + char *tmp; + if (conversion == NULL && + (conversion = faladd_conversion(gen)) == NULL) { + return 0; + } + dbg_printValue(name,value,num); + } else { + if(i == 0){ + continue; + } else { + break ; + } + } + conversion->length = atoi(value[0]); + + /* source_encoding */ + sprintf(name, "%s.%s", conv , "source_encoding"); + _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); + if (num > 0) { + char *tmp; + dbg_printValue(name,value,num); + tmp = (char *)Xmalloc(strlen(value[0])+1); + if(tmp == NULL){ + return 0; + } + strcpy(tmp,value[0]); + conversion->source_encoding = tmp; + conversion->source = srch_charset_define(tmp,&new); + if(new){ + tmp = (char *)Xmalloc(strlen(conversion->source_encoding)+1); + if(tmp == NULL){ + return 0; + } + strcpy(tmp,conversion->source_encoding); + conversion->source->name = tmp; + } + } + /* destination_encoding */ + sprintf(name, "%s.%s", conv , "destination_encoding"); + _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); + if (num > 0) { + char *tmp; + dbg_printValue(name,value,num); + tmp = (char *)Xmalloc(strlen(value[0])+1); + if(tmp == NULL){ + return 0; + } + strcpy(tmp,value[0]); + conversion->destination_encoding = tmp; + conversion->dest = srch_charset_define(tmp,&new); + if(new){ + tmp = (char *)Xmalloc( + strlen(conversion->destination_encoding)+1); + if(tmp == NULL){ + return 0; + } + strcpy(tmp,conversion->destination_encoding); + conversion->dest->name = tmp; + } + } + /* range */ + sprintf(name, "%s.%s", conv , "range"); + _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); + if (num > 0) { + char *tmp; + dbg_printValue(name,value,num); + sscanf(value[0],"\\x%lx,\\x%lx", + &(conversion->range.start), + &(conversion->range.end)); + } + /* conversion */ + sprintf(name, "%s.%s", conv , "conversion"); + _fallcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num); + if (num > 0) { + char *tmp; + dbg_printValue(name,value,num); + conversion->conv = + falparse_scopemaps(value[0],&conversion->conv_num); + } + } /* loop end */ + + return 1; +} + +static ExtdSegment create_ctextseg(value,num) +char **value; +int num; +{ + ExtdSegment ret; + char side_str[128],*ptr; + char cset_name[128],*tmp; + int i,new; + FontScope scope; + ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec)); + if(ret == NULL){ + return (0); + } + if(strchr(value[0],':')){ + ret->name = (char *)Xmalloc(strlen(value[0])+1); + if(ret->name == NULL){ + XFree(ret); + return(NULL); + } + strcpy(ret->name,value[0]); + ptr = strchr(ret->name,':'); + *ptr = 0; + ptr++; + if( !_fallcNCompareISOLatin1(ptr, "none", 4) ){ + ret->side = XlcNONE ; + snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"none"); + } else + if( !_fallcNCompareISOLatin1(ptr, "GL", 2) ){ + ret->side = XlcGL ; + snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"GL"); + } else { + ret->side = XlcGR ; + snprintf(cset_name,sizeof(cset_name),"%s:%s",ret->name,"GR"); + } + } else { + ret->name = (char *)Xmalloc(strlen(value[0])+1); + if(ret->name == NULL){ + XFree(ret); + return(NULL); + } + strcpy(ret->name,value[0]); + } + ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec)); + if(ret->area == NULL){ + XFree(ret->name); + XFree(ret); + return(NULL); + } + ret->area_num = num - 1; + scope = ret->area ; + for(i=1;icharset = srch_charset_define(cset_name,&new); + if(new){ + tmp = (char *)Xmalloc(strlen(cset_name)+1); + if(tmp == NULL){ + XFree(ret->area); + XFree(ret->name); + XFree(ret); + return NULL; + } + strcpy(tmp,cset_name); + ret->charset->name = tmp; + } + return(ret); +} +/* For VW/UDC end */ + +static Bool +load_generic(lcd) + XLCd lcd; +{ + XLCdGenericPart *gen = XLC_GENERIC_PART(lcd); + char **value; + int num; + unsigned long l; + int i; + int M,ii; + + gen->codeset_num = 0; + + /***** wc_encoding_mask *****/ + _fallcGetResource(lcd, "XLC_XLOCALE", "wc_encoding_mask", &value, &num); + if (num > 0) { + if (string_to_ulong(value[0], &l) == False) + goto err; + gen->wc_encode_mask = l; + } + /***** wc_shift_bits *****/ + _fallcGetResource(lcd, "XLC_XLOCALE", "wc_shift_bits", &value, &num); + if (num > 0) + gen->wc_shift_bits = atoi(value[0]); + if (gen->wc_shift_bits < 1) + gen->wc_shift_bits = 8; +#ifndef X_NOT_STDC_ENV + /***** use_stdc_env *****/ + _fallcGetResource(lcd, "XLC_XLOCALE", "use_stdc_env", &value, &num); + if (num > 0 && !_fallcCompareISOLatin1(value[0], "True")) + gen->use_stdc_env = True; + else + gen->use_stdc_env = False; + /***** force_convert_to_mb *****/ + _fallcGetResource(lcd, "XLC_XLOCALE", "force_convert_to_mb", &value, &num); + if (num > 0 && !_fallcCompareISOLatin1(value[0], "True")) + gen->force_convert_to_mb = True; + else + gen->force_convert_to_mb = False; +#endif + + for (i = 0; ; i++) { + CodeSetRec *codeset = NULL; + char cs[16]; + char name[BUFSIZ]; + + sprintf(cs, "cs%d", i); + + /***** codeset.side *****/ + sprintf(name, "%s.%s", cs , "side"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + char *tmp; + + if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) + goto err; + + /* 3.4.1 side */ + if( !_fallcNCompareISOLatin1(value[0], "none", 4) ){ + codeset->side = XlcNONE ; + } else + if( !_fallcNCompareISOLatin1(value[0], "GL", 2) ){ + codeset->side = XlcGL ; + } else { + codeset->side = XlcGR ; + } + + tmp = strrchr(value[0], ':'); + if (tmp != NULL && !_fallcCompareISOLatin1(tmp + 1, "Default")) { + if (codeset->side == XlcGR) + gen->initial_state_GR = codeset; + else + gen->initial_state_GL = codeset; + } + } + + /***** codeset.length *****/ + sprintf(name, "%s.%s", cs , "length"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) + goto err; + codeset->length = atoi(value[0]); + if (codeset->length < 1) + codeset->length = 1; + } + + /***** codeset.mb_encoding *****/ + sprintf(name, "%s.%s", cs, "mb_encoding"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + static struct { + char *str; + int type; + } shifts[] = { + {"", E_SS}, + {"", E_LSL}, + {"", E_LSR}, + 0 + }; + int j; + + if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) + goto err; + for ( ; num-- > 0; value++) { + char encoding[256]; + char *tmp = *value; + int type = E_SS; /* for BC */ + for (j = 0; shifts[j].str; j++) { + if (!_fallcNCompareISOLatin1(tmp, shifts[j].str, + strlen(shifts[j].str))) { + type = shifts[j].type; + tmp += strlen(shifts[j].str); + break; + } + } + if (string_to_encoding(tmp, encoding) == False) + goto err; + add_parse_list(gen, type, encoding, codeset); + } + } + + /***** codeset.wc_encoding *****/ + sprintf(name, "%s.%s", cs, "wc_encoding"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) + goto err; + if (string_to_ulong(value[0], &l) == False) + goto err; + codeset->wc_encoding = l; + } + + /***** codeset.ct_encoding *****/ + sprintf(name, "%s.%s", cs, "ct_encoding"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + XlcCharSet charset; + char *encoding; + + if (codeset == NULL && (codeset = add_codeset(gen)) == NULL) + goto err; + for ( ; num-- > 0; value++) { + string_to_encoding(*value, name); + charset = NULL; + if ((encoding = strchr(name, ':')) && + (encoding = strchr(encoding + 1, ':'))) { + *encoding++ = '\0'; + charset = _fallcAddCT(name, encoding); + } + if (charset == NULL) { + charset = _fallcGetCharSet(name); + if (charset == NULL && + (charset = _fallcCreateDefaultCharSet(name, ""))) { + charset->side = codeset->side; + charset->char_size = codeset->length; + _fallcAddCharSet(charset); + } + } + if (charset) { + if (add_charset(codeset, charset) == False) + goto err; + } + } + } + + if (codeset == NULL) + break; + codeset->cs_num = i; + /* For VW/UDC */ + /***** 3.4.2 byteM (1 <= M <= length)*****/ + for(M=1; M-1 < codeset->length; M++){ + long start,end; + ByteInfo tmpb; + + sprintf(name,"%s.%s%d",cs,"byte",M); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + + if( M == 1){ + if(num < 1) { + codeset->byteM = NULL ; + break ; + } + codeset->byteM = + (ByteInfoListRec *)Xmalloc( + (codeset->length)*sizeof(ByteInfoListRec)); + if(codeset->byteM == NULL){ + goto err; + } + } + + if(num > 0){ + dbg_printValue(name,value,num); + (codeset->byteM)[M-1].M = M; + (codeset->byteM)[M-1].byteinfo_num = num; + (codeset->byteM)[M-1].byteinfo = + (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec)); + for(ii = 0 ; ii < num ; ii++){ + char tmp[128]; + tmpb = (codeset->byteM)[M-1].byteinfo ; + /* default 0x00 - 0xff */ + sscanf(value[ii], "\\x%lx,\\x%lx", (long unsigned *) &start, (long unsigned *) &end); + tmpb[ii].start = (unsigned char)start; + tmpb[ii].end = (unsigned char)end; + } + } + /* .... */ + } + + + /***** codeset.mb_conversion *****/ + sprintf(name, "%s.%s", cs, "mb_conversion"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + codeset->mbconv = Xmalloc(sizeof(ConversionRec)); + codeset->mbconv->convlist = + falparse_scopemaps(value[0],&(codeset->mbconv->conv_num)); + dmpscope("mb_conv",codeset->mbconv->convlist, + codeset->mbconv->conv_num); + /* [\x%x,\x%x]->\x%x,... */ + } + /***** codeset.ct_conversion *****/ + sprintf(name, "%s.%s", cs, "ct_conversion"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + codeset->ctconv = Xmalloc(sizeof(ConversionRec)); + codeset->ctconv->convlist = + falparse_scopemaps(value[0],&(codeset->ctconv->conv_num)); + dmpscope("ctconv",codeset->ctconv->convlist, + codeset->ctconv->conv_num); + /* [\x%x,\x%x]->\x%x,... */ + } + /***** codeset.ct_conversion_file *****/ + sprintf(name, "%s.%s", cs, "ct_conversion_file"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + /* [\x%x,\x%x]->\x%x,... */ + } + /***** codeset.ct_extended_segment *****/ + sprintf(name, "%s.%s", cs, "ct_extended_segment"); + _fallcGetResource(lcd, "XLC_XLOCALE", name, &value, &num); + if (num > 0) { + dbg_printValue(name,value,num); + codeset->ctextseg = create_ctextseg(value,num); + /* [\x%x,\x%x]->\x%x,... */ + } + /* For VW/UDC end */ + + } + + read_charset_define(lcd,gen); /* For VW/UDC */ + read_segmentconversion(lcd,gen); /* For VW/UDC */ + + return True; + +err: + free_charset(lcd); + + return False; +} + +static Bool +initialize(lcd) + XLCd lcd; +{ + XLCdPublicMethods superclass = (XLCdPublicMethods) _fallcPublicMethods; + + XLC_PUBLIC_METHODS(lcd)->superclass = superclass; + + if (superclass->pub.initialize) { + if ((*superclass->pub.initialize)(lcd) == False) + return False; + } + + if(load_generic(lcd) == False) + return False; + + return True; +} +/* VW/UDC start 95.01.08 */ +static void +freeByteM(codeset) + CodeSet codeset; +{ + int i; + ByteInfoList blst; + if(codeset->byteM == NULL) { + return ; + } + blst = codeset->byteM; + for(i=0;ilength;i++){ + if(blst[i].byteinfo){ + Xfree(blst[i].byteinfo); + blst[i].byteinfo = NULL; + } + } + Xfree(codeset->byteM); + codeset->byteM = NULL; +} +static void +freeConversion(codeset) + CodeSet codeset; +{ + int i; + Conversion mbconv,ctconv; + if( codeset->mbconv ) { + mbconv = codeset->mbconv; + /* ... */ + if(mbconv->convlist){ + Xfree(mbconv->convlist); + mbconv->convlist = NULL; + } + Xfree(mbconv); + codeset->mbconv = NULL; + } + if( codeset->ctconv ) { + ctconv = codeset->ctconv; + /* ... */ + if(ctconv->convlist){ + Xfree(ctconv->convlist); + ctconv->convlist = NULL; + } + Xfree(ctconv); + codeset->ctconv = NULL; + } +} +static void +freeExtdSegment(codeset) + CodeSet codeset; +{ + int i; + ExtdSegment ctextseg; + if(codeset->ctextseg == NULL) { + return ; + } + ctextseg = codeset->ctextseg; + if(ctextseg->name){ + Xfree(ctextseg->name); + ctextseg->name = NULL; + } + if(ctextseg->area){ + Xfree(ctextseg->area); + ctextseg->area = NULL; + } + Xfree(codeset->ctextseg); + codeset->ctextseg = NULL; +} +static void +freeParseInfo(codeset) + CodeSet codeset; +{ + int i; + ParseInfo parse_info; + if(codeset->parse_info == NULL) { + return ; + } + parse_info = codeset->parse_info; + if(parse_info->encoding){ + Xfree(parse_info->encoding); + parse_info->encoding = NULL; + } + Xfree(codeset->parse_info); + codeset->parse_info = NULL; +} +static void +destroy_CodeSetList(gen) + XLCdGenericPart *gen ; +{ + CodeSet *codeset = gen->codeset_list; + int i; + if(gen->codeset_num == 0) { + return; + } + for(i=0;icodeset_num;i++){ + freeByteM(codeset[i]); + freeConversion(codeset[i]); + freeExtdSegment(codeset[i]); + freeParseInfo(codeset[i]); + if(codeset[i]->charset_list){ + Xfree(codeset[i]->charset_list); + codeset[i]->charset_list = NULL; + } + Xfree(codeset[i]); codeset[i]=NULL; + } + Xfree(codeset); gen->codeset_list = NULL; +} +/* */ +static void +destroy_SegConv(gen) + XLCdGenericPart *gen ; +{ + SegConv seg = gen->segment_conv; + int i; + if(gen->segment_conv_num == 0) { + return; + } + for(i=0;isegment_conv_num;i++){ + if(seg[i].source_encoding){ + Xfree(seg[i].source_encoding); + seg[i].source_encoding = NULL; + } + if(seg[i].destination_encoding){ + Xfree(seg[i].destination_encoding); + seg[i].destination_encoding = NULL; + } + if(seg[i].conv){ + Xfree(seg[i].conv); seg[i].conv = NULL; + } + } + Xfree(seg); gen->segment_conv = NULL; +} + +static void +destroy_gen(lcd) + XLCd lcd; +{ + XLCdGenericPart *gen = XLC_GENERIC_PART(lcd); + destroy_SegConv(gen); + destroy_CodeSetList(gen); + if(gen->mb_parse_table){ + Xfree(gen->mb_parse_table); + gen->mb_parse_table = NULL; + } + if(gen->mb_parse_list){ + Xfree(gen->mb_parse_list); + gen->mb_parse_list = NULL; + } +} +/* VW/UDC end 95.01.08 */ +static void +destroy(lcd) + XLCd lcd; +{ + XLCdPublicMethods superclass = XLC_PUBLIC_METHODS(lcd)->superclass; + + destroy_gen(lcd); /* ADD 1996.01.08 */ + if (superclass && superclass->pub.destroy) + (*superclass->pub.destroy)(lcd); +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcGeneric.h b/cde/programs/dtudcfonted/libfal/_fallcGeneric.h new file mode 100644 index 00000000..bacb3454 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcGeneric.h @@ -0,0 +1,170 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* XlcGeneric.h 1.3 - Fujitsu source for CDEnext 95/12/07 10:53:07 */ +/* $XConsortium: _fallcGeneric.h /main/1 1996/04/08 15:17:24 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietry source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ + +#ifndef _XLCGENERIC_H_ +#define _XLCGENERIC_H_ + +#include "_fallcPubI.h" + +typedef struct _ByteInfo { + unsigned char start,end; +} ByteInfoRec, *ByteInfo; + +typedef struct _ByteInfoList { + int M; /* 1 <= M <= length */ + int byteinfo_num; + ByteInfo byteinfo; +} ByteInfoListRec, *ByteInfoList; + +/* conversion_type values */ +#define LOCALCONV 1 +#define FILECONV 2 +#define FUNCTIONCONV 4 + +typedef struct _Conversion { + unsigned long conversion_type; + int conv_num; + FontScope convlist; + char *cnv_file; + XlcConv cnvfunc; +} ConversionRec, *Conversion; + +typedef struct _ExtdSegment { + char *name; + XlcSide side; + FontScope area; + int area_num; + XlcCharSet charset; +} ExtdSegmentRec, *ExtdSegment; + +typedef struct _SegConvRec { + int length; + char *source_encoding; + XlcCharSet source; + char *destination_encoding; + XlcCharSet dest; + FontScopeRec range; + int conv_num; + FontScope conv; +} SegConvRec, *SegConv; + +typedef struct _ParseInfoRec *ParseInfo; + +typedef struct _CodeSetRec { + XlcCharSet *charset_list; + int num_charsets; + int cs_num; + XlcSide side; + int length; + ByteInfoList byteM; + Conversion mbconv; + Conversion ctconv; + ExtdSegment ctextseg; + ParseInfo parse_info; + unsigned long wc_encoding; +} CodeSetRec, *CodeSet; + +typedef enum { + E_GL, /* GL encoding */ + E_GR, /* GR encoding */ + E_SS, /* single shift */ + E_LSL, /* locking shift left */ + E_LSR, /* locking shift right */ + E_LAST +} EncodingType; + +typedef struct _ParseInfoRec { + EncodingType type; + char *encoding; + CodeSet codeset; +} ParseInfoRec; + +/* + * XLCd private data + */ + +#define XLC_GENERIC(lcd, x) (((XLCdGeneric) lcd->core)->gen.x) +#define XLC_GENERIC_PART(lcd) (&(((XLCdGeneric) lcd->core)->gen)) + +typedef struct _XLCdGenericPart { + int codeset_num; + CodeSet *codeset_list; + unsigned char *mb_parse_table; + int mb_parse_list_num; + ParseInfo *mb_parse_list; + unsigned long wc_encode_mask; + unsigned long wc_shift_bits; + CodeSet initial_state_GL; + CodeSet initial_state_GR; + int segment_conv_num; /* UDC */ + SegConv segment_conv; /* UDC */ +#ifndef X_NOT_STDC_ENV + Bool use_stdc_env; + Bool force_convert_to_mb; +#endif +} XLCdGenericPart; + +typedef struct _XLCdGenericRec { + XLCdCoreRec core; + XLCdPublicPart pub; + XLCdGenericPart gen; +} XLCdGenericRec, *XLCdGeneric; + +extern XLCdMethods _fallcGenericMethods; + +#endif /* _XLCGENERIC_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_fallcInit.c b/cde/programs/dtudcfonted/libfal/_fallcInit.c new file mode 100644 index 00000000..661ea690 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcInit.c @@ -0,0 +1,186 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcInit.c 1.4 - Fujitsu source for CDEnext 96/03/11 17:13:15 */ +/* $XConsortium: _fallcInit.c /main/1 1996/04/08 15:17:36 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Modifier: Masayoshi Shimamura FUJITSU LIMITED + * + */ + +#include "_fallibint.h" +#include "_fallcint.h" + +#define USE_GENERIC_LOADER +#define USE_DEFAULT_LOADER +/*** #define USE_EUC_LOADER ***/ +/*** #define USE_SJIS_LOADER ***/ +/*** #define USE_JIS_LOADER ***/ +/*** #define USE_UTF_LOADER ***/ + +extern XLCd _fallcDefaultLoader( +#if NeedFunctionPrototypes + char* +#endif +); + +#ifdef DYNAMIC_LOAD +#ifdef sun +extern XLCd _falsunOsDynamicLoad( +#if NeedFunctionPrototypes + char* +#endif +); +#endif /* sun */ + +#ifdef AIXV3 +extern XLCd _falaixOsDynamicLoad( +#if NeedFunctionPrototypes + char* +#endif +); +#endif /* AIXV3 */ +#endif + +#ifdef USE_GENERIC_LOADER +extern XLCd _fallcGenericLoader( +#if NeedFunctionPrototypes + char* +#endif +); +#endif + +#ifdef USE_UTF_LOADER +extern XLCd _fallcUtfLoader( +#if NeedFunctionPrototypes + char* +#endif +); +#endif + +#ifdef USE_EUC_LOADER +extern XLCd _fallcEucLoader( +#if NeedFunctionPrototypes + char* +#endif +); +#endif + +#ifdef USE_SJIS_LOADER +extern XLCd _fallcSjisLoader( +#if NeedFunctionPrototypes + char* +#endif +); +#endif + +#ifdef USE_JIS_LOADER +extern XLCd _XlcJisLoader( +#if NeedFunctionPrototypes + char* +#endif +); +#endif + +#ifdef USE_DYNAMIC_LOADER +extern XLCd _fallcDynamicLoader( +#if NeedFunctionPrototypes + char* +#endif +); +#endif + +/* + * The _fallcInitLoader function initializes the locale object loader list + * with vendor specific manner. + */ + +void +_fallcInitLoader() +{ +#ifdef USE_GENERIC_LOADER + _fallcAddLoader(_fallcGenericLoader, XlcHead); +#endif + +#ifdef USE_DEFAULT_LOADER + _fallcAddLoader(_fallcDefaultLoader, XlcHead); +#endif + +#ifdef USE_EUC_LOADER + _fallcAddLoader(_fallcEucLoader, XlcHead); +#endif + +#ifdef USE_SJIS_LOADER + _fallcAddLoader(_fallcSjisLoader, XlcHead); +#endif + +#ifdef USE_JIS_LOADER + _fallcAddLoader(_XlcJisLoader, XlcHead); +#endif + +#ifdef USE_UTF_LOADER + _fallcAddLoader(_fallcUtfLoader, XlcHead); +#endif + +#ifdef DYNAMIC_LOAD +#ifdef sun + _fallcAddLoader(_falsunOsDynamicLoad, XlcHead); +#endif /* sun */ + +#ifdef AIXV3 + _fallcAddLoader(_falaixOsDynamicLoad, XlcHead); +#endif /* AIXV3 */ +#endif /* DYNAMIC_LOAD */ + +#ifdef USE_DYNAMIC_LOADER + _fallcAddLoader(_fallcDynamicLoader, XlcHead); +#endif +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcPrTxt.c b/cde/programs/dtudcfonted/libfal/_fallcPrTxt.c new file mode 100644 index 00000000..cd647983 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcPrTxt.c @@ -0,0 +1,267 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcPrTxt.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:38 */ +/* $XConsortium: _fallcPrTxt.c /main/1 1996/04/08 15:17:49 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" +#include "_falutil.h" +#include + +static XPointer * +alloc_list(is_wide_char, count, nitems) + Bool is_wide_char; + int count; + int nitems; +{ + if (is_wide_char) { + wchar_t **wstr_list; + + wstr_list = (wchar_t **) Xmalloc(count * sizeof(wchar_t *)); + if (wstr_list == NULL) + return (XPointer *) NULL; + + *wstr_list = (wchar_t *) Xmalloc(nitems * sizeof(wchar_t)); + if (*wstr_list == NULL) { + Xfree(wstr_list); + return (XPointer *) NULL; + } + + return (XPointer *) wstr_list; + } else { + char **str_list; + + str_list = (char **) Xmalloc(count * sizeof(char *)); + if (str_list == NULL) + return (XPointer *) NULL; + + *str_list = (char *) Xmalloc(nitems); + if (*str_list == NULL) { + Xfree(str_list); + return (XPointer *) NULL; + } + + return (XPointer *) str_list; + } +} + +static void +copy_list(is_wide_char, text, list, count) + Bool is_wide_char; + XPointer text; + XPointer *list; + int count; +{ + int length; + + if (is_wide_char) { + wchar_t *wc_text, *wstr, **wstr_list; + + wc_text = (wchar_t *) text; + wstr_list = (wchar_t **) list; + + for (wstr = *wstr_list; count > 0; count--, wstr_list++) { + _falwcscpy(wstr, wc_text); + *wstr_list = wstr; + length = _falwcslen(wstr) + 1; + wstr += length; + wc_text += length; + } + } else { + char *mb_text, *str, **str_list; + + mb_text = (char *) text; + str_list = (char **) list; + + for (str = *str_list; count > 0; count--, str_list++) { + strcpy(str, mb_text); + *str_list = str; + length = strlen(str) + 1; + str += length; + mb_text += length; + } + } +} + +static int +_XTextPropertyToTextList(lcd, dpy, text_prop, to_type, list_ret, count_ret) + XLCd lcd; + Display *dpy; + XTextProperty *text_prop; + char *to_type; + XPointer **list_ret; + int *count_ret; +{ + XlcConv conv; + char *from_type; + XPointer from, to, buf; + char *str_ptr, *last_ptr; + Atom encoding; + int from_left, to_left, buf_len, ret; + int unconv_num, nitems = text_prop->nitems; + Bool is_wide_char = False; + + if (strcmp(XlcNWideChar, to_type) == 0) + is_wide_char = True; + + if (nitems <= 0) { + *list_ret = NULL; + *count_ret = 0; + return Success; + } + + if (text_prop->format != 8) + return XConverterNotFound; + + encoding = text_prop->encoding; + if (encoding == XA_STRING) + from_type = XlcNString; + else if (encoding == falInternAtom(dpy, "COMPOUND_TEXT", False)) + from_type = XlcNCompoundText; + else if (encoding == falInternAtom(dpy, XLC_PUBLIC(lcd, encoding_name), False)) + from_type = XlcNMultiByte; + else + return XConverterNotFound; + + if (is_wide_char) { + buf_len = text_prop->nitems + 1; + buf = (XPointer) Xmalloc(buf_len * sizeof(wchar_t)); + } else { + buf_len = text_prop->nitems * XLC_PUBLIC(lcd, mb_cur_max) + 1; + buf = (XPointer) Xmalloc(buf_len); + } + if (buf == NULL) + return XNoMemory; + to = buf; + to_left = buf_len; + + conv = _fallcOpenConverter(lcd, from_type, lcd, to_type); + if (conv == NULL) { + Xfree(buf); + return XConverterNotFound; + } + + last_ptr = str_ptr = (char *) text_prop->value; + unconv_num = *count_ret = 0; + + while (1) { + if (nitems == 0 || *str_ptr == 0) { + if (nitems) + str_ptr++; + from = (XPointer) last_ptr; + from_left = str_ptr - last_ptr; + last_ptr = str_ptr; + + ret = _fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0); + + if (ret < 0) + continue; + + unconv_num += ret; + (*count_ret)++; + + if (nitems == 0) + break; + _fallcResetConverter(conv); + } else + str_ptr++; + + nitems--; + } + + _fallcCloseConverter(conv); + + if (is_wide_char) + *((wchar_t *) to) = (wchar_t) 0; + else + *((char *) to) = '\0'; + to_left--; + + *list_ret = alloc_list(is_wide_char, *count_ret, buf_len - to_left); + if (*list_ret) + copy_list(is_wide_char, buf, *list_ret, *count_ret); + + Xfree(buf); + + return unconv_num; +} + +int +_falmbTextPropertyToTextList(lcd, dpy, text_prop, list_ret, count_ret) + XLCd lcd; + Display *dpy; + XTextProperty *text_prop; + char ***list_ret; + int *count_ret; +{ + return _XTextPropertyToTextList(lcd, dpy, text_prop, XlcNMultiByte, + (XPointer **) list_ret, count_ret); +} + +int +_falwcTextPropertyToTextList(lcd, dpy, text_prop, list_ret, count_ret) + XLCd lcd; + Display *dpy; + XTextProperty *text_prop; + wchar_t ***list_ret; + int *count_ret; +{ + return _XTextPropertyToTextList(lcd, dpy, text_prop, XlcNWideChar, + (XPointer **) list_ret, count_ret); +} + +void +_falwcFreeStringList(lcd, list) + XLCd lcd; + wchar_t **list; +{ + if (list) { + if (*list) + Xfree(*list); + Xfree(list); + } +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcPubI.h b/cde/programs/dtudcfonted/libfal/_fallcPubI.h new file mode 100644 index 00000000..5d1cac8f --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcPubI.h @@ -0,0 +1,277 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* XlcPubI.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:05 */ +/* $XConsortium: _fallcPubI.h /main/1 1996/04/08 15:17:59 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#ifndef _XLCPUBLICI_H_ +#define _XLCPUBLICI_H_ + +#include "_fallcPublic.h" + +#define XLC_PUBLIC(lcd, x) (((XLCdPublic) lcd->core)->pub.x) +#define XLC_PUBLIC_PART(lcd) (&(((XLCdPublic) lcd->core)->pub)) +#define XLC_PUBLIC_METHODS(lcd) (&(((XLCdPublicMethods) lcd->methods)->pub)) + +/* + * XLCd public methods + */ + +typedef struct _XLCdPublicMethodsRec *XLCdPublicMethods; + +typedef XLCd (*XlcPubCreateProc)( +#if NeedFunctionPrototypes + char* /* name */, + XLCdMethods /* methods */ +#endif +); + +typedef Bool (*XlcPubInitializeProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +typedef void (*XlcPubDestroyProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +typedef char* (*XlcPubGetValuesProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +typedef void (*XlcPubGetResourceProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + char* /* category */, + char* /* class */, + char*** /* value */, + int* /* count */ +#endif +); + +typedef struct _XLCdPublicMethodsPart { + XLCdPublicMethods superclass; + XlcPubCreateProc create; + XlcPubInitializeProc initialize; + XlcPubDestroyProc destroy; + XlcPubGetValuesProc get_values; + XlcPubGetResourceProc get_resource; +} XLCdPublicMethodsPart; + +typedef struct _XLCdPublicMethodsRec { + XLCdMethodsRec core; + XLCdPublicMethodsPart pub; +} XLCdPublicMethodsRec; + +/* + * XLCd public data + */ + +typedef struct _XLCdPublicPart { + char *siname; /* for _fallcMapOSLocaleName() */ + char *language; /* language part of locale name */ + char *territory; /* territory part of locale name */ + char *codeset; /* codeset part of locale name */ + char *encoding_name; /* encoding name */ + int mb_cur_max; /* ANSI C MB_CUR_MAX */ + Bool is_state_depend; /* state-depend encoding */ + char *default_string; /* for falDefaultString() */ + XPointer xlocale_db; +} XLCdPublicPart; + +typedef struct _XLCdPublicRec { + XLCdCoreRec core; + XLCdPublicPart pub; +} XLCdPublicRec, *XLCdPublic; + +extern XLCdMethods _fallcPublicMethods; + +_XFUNCPROTOBEGIN + +extern XLCd _fallcCreateLC( +#if NeedFunctionPrototypes + char* /* name */, + XLCdMethods /* methods */ +#endif +); + +extern void _fallcDestroyLC( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +extern Bool _fallcParseCharSet( +#if NeedFunctionPrototypes + XlcCharSet /* charset */ +#endif +); + +extern XlcCharSet _fallcCreateDefaultCharSet( +#if NeedFunctionPrototypes + char* /* name */, + char* /* control_sequence */ +#endif +); + +extern XlcCharSet _fallcAddCT( +#if NeedFunctionPrototypes + char* /* name */, + char* /* control_sequence */ +#endif +); + +extern XrmMethods _falrmDefaultInitParseInfo( +#if NeedFunctionPrototypes + XLCd /* lcd */, + XPointer* /* state */ +#endif +); + +extern int _falmbTextPropertyToTextList( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* dpy */, + XTextProperty* /* text_prop */, + char*** /* list_ret */, + int* /* count_ret */ +#endif +); + +extern int _falwcTextPropertyToTextList( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* dpy */, + XTextProperty* /* text_prop */, + wchar_t*** /* list_ret */, + int* /* count_ret */ +#endif +); + +extern int _falmbTextListToTextProperty( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* dpy */, + char** /* list */, + int /* count */, + XICCEncodingStyle /* style */, + XTextProperty* /* text_prop */ +#endif +); + +extern int _falwcTextListToTextProperty( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* dpy */, + wchar_t** /* list */, + int /* count */, + XICCEncodingStyle /* style */, + XTextProperty* /* text_prop */ +#endif +); + +extern void _falwcFreeStringList( +#if NeedFunctionPrototypes + XLCd /* lcd */, + wchar_t** /* list */ +#endif +); + +extern int _fallcResolveLocaleName( +#if NeedFunctionPrototypes + char* /* lc_name */, + char* /* full_name */, + char* /* language */, + char* /* territory */, + char* /* codeset */ +#endif +); + +extern int _fallcResolveDBName( +#if NeedFunctionPrototypes + char* /* lc_name */, + char* /* file_name */ +#endif +); + +extern int _fallcResolveI18NPath( +#if NeedFunctionPrototypes + char* /* path_name */ +#endif +); + +extern XPointer _fallcCreateLocaleDataBase( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +extern void _fallcDestroyLocaleDataBase( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +extern void _fallcGetLocaleDataBase( +#if NeedFunctionPrototypes + XLCd /* lcd */, + char* /* category */, + char* /* name */, + char*** /* value */, + int* /* count */ +#endif +); + +_XFUNCPROTOEND + +#endif /* _XLCPUBLICI_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_fallcPubWrap.c b/cde/programs/dtudcfonted/libfal/_fallcPubWrap.c new file mode 100644 index 00000000..e69c4da1 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcPubWrap.c @@ -0,0 +1,127 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcPubWrap.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:39 */ +/* $XConsortium: _fallcPubWrap.c /main/1 1996/04/08 15:18:09 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" + +#if NeedVarargsPrototypes +char * +_falGetLCValues(XLCd lcd, ...) +#else +char * +_falGetLCValues(lcd, va_alist) + XLCd lcd; + va_dcl +#endif +{ + va_list var; + XlcArgList args; + char *ret; + int num_args; + XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd); + + Va_start(var, lcd); + _fallcCountVaList(var, &num_args); + va_end(var); + + Va_start(var, lcd); + _fallcVaToArgList(var, num_args, &args); + va_end(var); + + if (args == (XlcArgList) NULL) + return (char *) NULL; + + ret = (*methods->get_values)(lcd, args, num_args); + + Xfree(args); + + return ret; +} + +void +_fallcDestroyLC(lcd) + XLCd lcd; +{ + XLCdPublicMethods methods = (XLCdPublicMethods) lcd->methods; + + (*methods->pub.destroy)(lcd); +} + +XLCd +_fallcCreateLC(name, methods) + char *name; + XLCdMethods methods; +{ + XLCdPublicMethods pub_methods = (XLCdPublicMethods) methods; + XLCd lcd; + + lcd = (*pub_methods->pub.create)(name, methods); + if (lcd == NULL) + return (XLCd) NULL; + + if (lcd->core->name == NULL) { + lcd->core->name = (char*) Xmalloc(strlen(name) + 1); + if (lcd->core->name == NULL) + goto err; + strcpy(lcd->core->name, name); + } + + if (lcd->methods == NULL) + lcd->methods = methods; + + if ((*pub_methods->pub.initialize)(lcd) == False) + goto err; + + return lcd; + +err: + _fallcDestroyLC(lcd); + + return (XLCd) NULL; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcPublic.c b/cde/programs/dtudcfonted/libfal/_fallcPublic.c new file mode 100644 index 00000000..12447f88 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcPublic.c @@ -0,0 +1,325 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcPublic.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:39 */ +/* $XConsortium: _fallcPublic.c /main/1 1996/04/08 15:18:20 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include +#include "_fallibint.h" +#include "_fallcPubI.h" + +static char *default_string(); + +static XLCd create(); +static Bool initialize(); +static void destroy(); +static char *get_values(); + +static XLCdPublicMethodsRec publicMethods = { + { + destroy, + _fallcDefaultMapModifiers, + NULL, + NULL, + _falrmDefaultInitParseInfo, + _falmbTextPropertyToTextList, + _falwcTextPropertyToTextList, + _falmbTextListToTextProperty, + _falwcTextListToTextProperty, + _falwcFreeStringList, + default_string, + NULL, + NULL + }, + { + NULL, + create, + initialize, + destroy, + get_values, + _fallcGetLocaleDataBase + } +}; + +XLCdMethods _fallcPublicMethods = (XLCdMethods) &publicMethods; + +static char * +default_string(lcd) + XLCd lcd; +{ + return XLC_PUBLIC(lcd, default_string); +} + +static XLCd +create(name, methods) + char *name; + XLCdMethods methods; +{ + XLCd lcd; + XLCdPublicMethods new; + + lcd = (XLCd) Xmalloc(sizeof(XLCdRec)); + if (lcd == NULL) + return (XLCd) NULL; + bzero((char *) lcd, sizeof(XLCdRec)); + + lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec)); + if (lcd->core == NULL) + goto err; + bzero((char *) lcd->core, sizeof(XLCdPublicRec)); + + new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec)); + if (new == NULL) + goto err; + *new = *((XLCdPublicMethods) methods); + lcd->methods = (XLCdMethods) new; + + return lcd; + +err: + Xfree(lcd); + return (XLCd) NULL; +} + +static Bool +load_public(lcd) + XLCd lcd; +{ + XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd); + char **values, *str; + int num; + + if(_fallcCreateLocaleDataBase(lcd) == NULL) + return False; + + _fallcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num); + if (num > 0) { + pub->mb_cur_max = atoi(values[0]); + if (pub->mb_cur_max < 1) + pub->mb_cur_max = 1; + } else + pub->mb_cur_max = 1; + + _fallcGetResource(lcd, "XLC_XLOCALE", "state_dependent", &values, &num); + if (num > 0 && !_fallcCompareISOLatin1(values[0], "True")) + pub->is_state_depend = True; + else + pub->is_state_depend = False; + + _fallcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num); + str = (num > 0) ? values[0] : "STRING"; + pub->encoding_name = (char*) Xmalloc(strlen(str) + 1); + if (pub->encoding_name == NULL) + return False; + strcpy(pub->encoding_name, str); + + return True; +} + +static Bool +initialize_core(lcd) + XLCd lcd; +{ + XLCdMethods methods = lcd->methods; + XLCdMethods core = &publicMethods.core; + + if (methods->close == NULL) + methods->close = core->close; + + if (methods->map_modifiers == NULL) + methods->map_modifiers = core->map_modifiers; + + if (methods->open_om == NULL) + _falInitOM(lcd); + + if (methods->init_parse_info == NULL) + methods->init_parse_info = core->init_parse_info; + + if (methods->mb_text_prop_to_list == NULL) + methods->mb_text_prop_to_list = core->mb_text_prop_to_list; + + if (methods->wc_text_prop_to_list == NULL) + methods->wc_text_prop_to_list = core->wc_text_prop_to_list; + + if (methods->mb_text_list_to_prop == NULL) + methods->mb_text_list_to_prop = core->mb_text_list_to_prop; + + if (methods->wc_text_list_to_prop == NULL) + methods->wc_text_list_to_prop = core->wc_text_list_to_prop; + + if (methods->wc_free_string_list == NULL) + methods->wc_free_string_list = core->wc_free_string_list; + + if (methods->default_string == NULL) + methods->default_string = core->default_string; + + return True; +} + +extern Bool _fallcInitCTInfo(); + +static Bool +initialize(lcd) + XLCd lcd; +{ + XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd); + XLCdPublicMethodsPart *pub_methods = &publicMethods.pub; + XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd); + char lang[128], terr[128], code[128], *str; + char *name; +#if !defined(X_NOT_STDC_ENV) && !defined(X_LOCALE) + char siname[256]; + char *_fallcMapOSLocaleName(); +#endif + + _fallcInitCTInfo(); + + if (initialize_core(lcd) == False) + return False; + + name = lcd->core->name; +#if !defined(X_NOT_STDC_ENV) && !defined(X_LOCALE) + name = _fallcMapOSLocaleName(name, siname); +#endif + + if (_fallcResolveLocaleName(name, NULL, lang, terr, code) == 0) + return False; + + str = (char*) Xmalloc(strlen(name) + strlen(lang) + strlen(terr) + + strlen(code) + 4); + if (str == NULL) + return False; + + strcpy(str, name); + pub->siname = str; + str += strlen(str) + 1; + + strcpy(str, lang); + pub->language = str; + str += strlen(str) + 1; + + strcpy(str, terr); + pub->territory = str; + str += strlen(str) + 1; + + strcpy(str, code); + pub->codeset = str; + + if (pub->default_string == NULL) + pub->default_string = ""; + + if (methods->get_values == NULL) + methods->get_values = pub_methods->get_values; + + if (methods->get_resource == NULL) + methods->get_resource = pub_methods->get_resource; + + return load_public(lcd); +} + +static void +destroy_core(lcd) + XLCd lcd; +{ + if (lcd->core) { + if (lcd->core->name) + Xfree(lcd->core->name); + Xfree(lcd->core); + } + + if (lcd->methods) + Xfree(lcd->methods); + + Xfree(lcd); +} + +static void +destroy(lcd) + XLCd lcd; +{ + XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd); + + _fallcDestroyLocaleDataBase(lcd); + + if (pub->siname) + Xfree(pub->siname); + if (pub->encoding_name) + Xfree(pub->encoding_name); + + destroy_core(lcd); +} + +static XlcResource resources[] = { + { XlcNCodeset, NULLQUARK, sizeof(char *), + XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask }, + { XlcNDefaultString, NULLQUARK, sizeof(char *), + XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask }, + { XlcNEncodingName, NULLQUARK, sizeof(char *), + XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask }, + { XlcNLanguage, NULLQUARK, sizeof(char *), + XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask }, + { XlcNMbCurMax, NULLQUARK, sizeof(int), + XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask }, + { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool), + XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask }, + { XlcNTerritory, NULLQUARK, sizeof(char *), + XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask } +}; + +static char * +get_values(lcd, args, num_args) + register XLCd lcd; + register XlcArgList args; + register int num_args; +{ + XLCdPublic pub = (XLCdPublic) lcd->core; + + if (resources[0].xrm_name == NULLQUARK) + _fallcCompileResourceList(resources, XlcNumber(resources)); + + return _fallcGetValues((XPointer) pub, resources, XlcNumber(resources), args, + num_args, XlcGetMask); +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcPublic.h b/cde/programs/dtudcfonted/libfal/_fallcPublic.h new file mode 100644 index 00000000..07af5cc6 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcPublic.h @@ -0,0 +1,311 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* XlcPublic.h 1.3 - Fujitsu source for CDEnext 95/12/07 10:53:08 */ +/* $XConsortium: _fallcPublic.h /main/1 1996/04/08 15:18:31 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietry source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ + +#ifndef _XLCPUBLIC_H_ +#define _XLCPUBLIC_H_ + +#include "_fallcint.h" + +#define XlcNCharSize "charSize" +#define XlcNCodeset "codeset" +#define XlcNControlSequence "controlSequence" +#define XlcNDefaultString "defaultString" +#define XlcNEncodingName "encodingName" +#define XlcNLanguage "language" +#define XlcNMbCurMax "mbCurMax" +#define XlcNName "name" +#define XlcNSetSize "setSize" +#define XlcNSide "side" +#define XlcNStateDependentEncoding "stateDependentEncoding" +#define XlcNTerritory "territory" + +typedef enum { + XlcUnknown, XlcC0, XlcGL, XlcC1, XlcGR, XlcGLGR, XlcOther, XlcNONE +} XlcSide; + +typedef struct _FonScope { + unsigned long start; + unsigned long end; + unsigned long shift; + unsigned long shift_direction; +} FontScopeRec, *FontScope; + +typedef struct _UDCArea { + unsigned long start,end; +} UDCAreaRec, *UDCArea; + +typedef struct _XlcCharSetRec *XlcCharSet; + +typedef char* (*XlcGetCSValuesProc)( +#if NeedFunctionPrototypes + XlcCharSet /* charset */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +typedef struct _XlcCharSetRec { + char *name; /* character set name */ + XrmQuark xrm_name; + char *encoding_name; /* XLFD encoding name */ + XrmQuark xrm_encoding_name; + XlcSide side; /* GL, GR or others */ + int char_size; /* number of bytes per character */ + int set_size; /* graphic character sets */ + char *ct_sequence; /* control sequence of CT */ + XlcGetCSValuesProc get_values; + /* UDC */ + Bool string_encoding; + UDCArea udc_area; + int udc_area_num; +} XlcCharSetRec; + +/* + * conversion methods + */ + +typedef struct _XlcConvRec *XlcConv; + +typedef XlcConv (*XlcOpenConverterProc)( +#if NeedFunctionPrototypes + XLCd /* from_lcd */, + char* /* from_type */, + XLCd /* to_lcd */, + char* /* to_type */ +#endif +); + +typedef void (*XlcCloseConverterProc)( +#if NeedFunctionPrototypes + XlcConv /* conv */ +#endif +); + +typedef int (*XlcConvertProc)( +#if NeedFunctionPrototypes + XlcConv /* conv */, + XPointer* /* from */, + int* /* from_left */, + XPointer* /* to */, + int* /* to_left */, + XPointer* /* args */, + int /* num_args */ +#endif +); + +typedef void (*XlcResetConverterProc)( +#if NeedFunctionPrototypes + XlcConv /* conv */ +#endif +); + +typedef struct _XlcConvMethodsRec{ + XlcCloseConverterProc close; + XlcConvertProc convert; + XlcResetConverterProc reset; +} XlcConvMethodsRec, *XlcConvMethods; + +/* + * conversion data + */ + +#define XlcNMultiByte "multiByte" +#define XlcNWideChar "wideChar" +#define XlcNCompoundText "compoundText" +#define XlcNString "string" +#define XlcNCharSet "charSet" +#define XlcNCTCharSet "CTcharSet" +#define XlcNChar "char" + +typedef struct _XlcConvRec { + XlcConvMethods methods; + XPointer state; +} XlcConvRec; + + +_XFUNCPROTOBEGIN + +extern Bool _falInitOM( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +extern Bool _XInitIM( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +extern char *_falGetLCValues( +#if NeedVarargsPrototypes + XLCd /* lcd */, + ... +#endif +); + +extern XlcCharSet _fallcGetCharSet( +#if NeedFunctionPrototypes + char* /* name */ +#endif +); + +extern Bool _fallcAddCharSet( +#if NeedFunctionPrototypes + XlcCharSet /* charset */ +#endif +); + +extern char *_fallcGetCSValues( +#if NeedVarargsPrototypes + XlcCharSet /* charset */, + ... +#endif +); + +extern XlcConv _fallcOpenConverter( +#if NeedFunctionPrototypes + XLCd /* from_lcd */, + char* /* from_type */, + XLCd /* to_lcd */, + char* /* to_type */ +#endif +); + +extern void _fallcCloseConverter( +#if NeedFunctionPrototypes + XlcConv /* conv */ +#endif +); + +extern int _fallcConvert( +#if NeedFunctionPrototypes + XlcConv /* conv */, + XPointer* /* from */, + int* /* from_left */, + XPointer* /* to */, + int* /* to_left */, + XPointer* /* args */, + int /* num_args */ +#endif +); + +extern void _fallcResetConverter( +#if NeedFunctionPrototypes + XlcConv /* conv */ +#endif +); + +extern Bool _fallcSetConverter( +#if NeedFunctionPrototypes + XLCd /* from_lcd */, + char* /* from_type */, + XLCd /* to_lcd */, + char* /* to_type */, + XlcOpenConverterProc /* open_converter */ +#endif +); + +extern void _fallcGetResource( +#if NeedFunctionPrototypes + XLCd /* lcd */, + char* /* category */, + char* /* class */, + char*** /* value */, + int* /* count */ +#endif +); + +extern char *_fallcFileName( +#if NeedFunctionPrototypes + XLCd /* lcd */, + char* /* category */ +#endif +); + +extern int _falwcslen( +#if NeedFunctionPrototypes + wchar_t* /* wstr */ +#endif +); + +extern wchar_t *_falwcscpy( +#if NeedFunctionPrototypes + wchar_t* /* wstr1 */, + wchar_t* /* wstr2 */ +#endif +); + +extern int _fallcCompareISOLatin1( +#if NeedFunctionPrototypes + char* /* str1 */, + char* /* str2 */ +#endif +); + +extern int _fallcNCompareISOLatin1( +#if NeedFunctionPrototypes + char* /* str1 */, + char* /* str2 */, + int /* len */ +#endif +); + +_XFUNCPROTOEND + +#endif /* _XLCPUBLIC_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_fallcRM.c b/cde/programs/dtudcfonted/libfal/_fallcRM.c new file mode 100644 index 00000000..f5cffd2f --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcRM.c @@ -0,0 +1,145 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcRM.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:40 */ +/* $XConsortium: _fallcRM.c /main/1 1996/04/08 15:18:41 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" +#include + +typedef struct _StateRec { + XLCd lcd; + XlcConv conv; +} StateRec, *State; + +static void +mbinit(state) + XPointer state; +{ + _fallcResetConverter(((State) state)->conv); +} + +static char +mbchar(state, str, lenp) + XPointer state; + char *str; + int *lenp; +{ + XlcConv conv = ((State) state)->conv; + XlcCharSet charset; + char *from, *to, buf[BUFSIZ]; + int from_left, to_left; + XPointer args[1]; + + from = str; + *lenp = from_left = XLC_PUBLIC(((State) state)->lcd, mb_cur_max); + to = buf; + to_left = BUFSIZ; + args[0] = (XPointer) &charset; + + _fallcConvert(conv, (XPointer *) &from, &from_left, (XPointer *) &to, + &to_left, args, 1); + + *lenp -= from_left; + + /* XXX */ + return buf[0]; +} + +static void +mbfinish(state) + XPointer state; +{ +} + +static char * +lcname(state) + XPointer state; +{ + return ((State) state)->lcd->core->name; +} + +static void +destroy(state) + XPointer state; +{ + _fallcCloseConverter(((State) state)->conv); + _falCloseLC(((State) state)->lcd); + Xfree((char *) state); +} + +static XrmMethodsRec rm_methods = { + mbinit, + mbchar, + mbfinish, + lcname, + destroy +} ; + +XrmMethods +_falrmDefaultInitParseInfo(lcd, rm_state) + XLCd lcd; + XPointer *rm_state; +{ + State state; + + state = (State) Xmalloc(sizeof(StateRec)); + if (state == NULL) + return (XrmMethods) NULL; + + state->lcd = lcd; + state->conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNChar); + if (state->conv == NULL) { + Xfree((char *) state); + + return (XrmMethods) NULL; + } + + *rm_state = (XPointer) state; + + return &rm_methods; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcSjis.c b/cde/programs/dtudcfonted/libfal/_fallcSjis.c new file mode 100644 index 00000000..18ac8799 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcSjis.c @@ -0,0 +1,1575 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcSjis.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:40 */ +/* $XConsortium: _fallcSjis.c /main/1 1996/04/08 15:18:51 cde-fuj $ */ +/**************************************************************** + + Copyright 1992, 1993 by FUJITSU LIMITED + Copyright 1993 by Fujitsu Open Systems Solutions, Inc. + Copyright 1994 by Sony Corporation + +Permission to use, copy, modify, distribute and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear +in supporting documentation, and that the name of FUJITSU LIMITED, +Fujitsu Open Systems Solutions, Inc. and Sony Corporation not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. +FUJITSU LIMITED, Fujitsu Open Systems Solutions, Inc. and +Sony Corporation make no representations about the suitability of +this software for any purpose. It is provided "as is" without +express or implied warranty. + +FUJITSU LIMITED, FUJITSU OPEN SYSTEMS SOLUTIONS, INC. AND SONY +CORPORATION DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +IN NO EVENT SHALL FUJITSU OPEN SYSTEMS SOLUTIONS, INC., FUJITSU LIMITED +AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE +OR PERFORMANCE OF THIS SOFTWARE. + + Authors: Jeffrey Bloomfield (jeffb@ossi.com) + Shigeru Yamada (yamada@ossi.com) + Yoshiyuki Segawa (segawa@ossi.com) + Modifier:Makoto Wakamatsu Sony Corporation + makoto@sm.sony.co.jp + +*****************************************************************/ + +#include "_fallibint.h" +#include "_fallcGeneric.h" + +#include +#ifdef WIN32 +#define isascii __isascii +#endif + +#define CS0 codesets[0] /* Codeset 0 - 7-bit ASCII */ +#define CS1 codesets[1] /* Codeset 1 - Kanji */ +#define CS2 codesets[2] /* Codeset 2 - Half-Kana */ +#define CS3 codesets[3] /* Codeset 3 - User defined */ + +#define ascii (codeset->cs_num == 0) +#define kanji (codeset->cs_num == 1) +#define kana (codeset->cs_num == 2) +#define userdef (codeset->cs_num == 3) + +#define ASCII_CODESET 0 +#define KANJI_CODESET 1 +#define KANA_CODESET 2 +#define USERDEF_CODESET 3 +#define MAX_CODESETS 4 + +#define GR 0x80 /* begins right-side (non-ascii) region */ +#define GL 0x7f /* ends left-side (ascii) region */ + +#define isleftside(c) (((c) & GR) ? 0 : 1) +#define isrightside(c) (!isleftside(c)) + +typedef unsigned char Uchar; +typedef unsigned long Ulong; +typedef unsigned int Uint; + +/* Acceptable range for 2nd byte of SJIS multibyte char */ +#define VALID_MULTIBYTE(c) \ + ((0x40<=((Uchar)c) && ((Uchar)c)<=0x7e) \ + || (0x80<=((Uchar)c) && ((Uchar)c)<=0xfc)) + +#ifndef iskanji +#define iskanji(c) ((0x81<=((Uchar)c) && ((Uchar)c)<=0x9f) \ + || (0xe0<=((Uchar)c) && ((Uchar)c)<=0xef)) +#endif /* !iskanji */ + +#ifndef iskana +#define iskana(c) (0xa1<=((Uchar)c) && ((Uchar)c)<=0xdf) +#endif /* !iskana */ + +#define isuserdef(c) (0xf0<=((Uchar)c) && ((Uchar)c)<=0xfc) + +#define BIT8OFF(c) ((c) & GL) +#define BIT8ON(c) ((c) | GR) + + +static void jis_to_sjis(); +static void sjis_to_jis(); +static CodeSet wc_codeset(); + + +/* + * Notes: + * 1. 16-bit widechar format is limited to 14 data bits. Since the 2nd byte + * of SJIS multibyte chars are in the ranges of 0x40 - 7E and 0x80 - 0xFC, + * SJIS cannot map directly into 16 bit widechar format within the confines + * of a single codeset. Therefore, for SJIS widechar conversion, SJIS Kanji + * is mapped into the JIS codeset. (The algorithms used in jis_to_sjis() + * and sjis_to_jis() are from Ken Lunde (lunde@mv.us.adobe.com) and are in + * the public domain.) + * 2. Defining FORCE_INDIRECT_CONVERTER (see _fallcEucLoader()) + * forces indirect (charset) conversions (e.g. wcstocs()<->cstombs()). + * 3. Using direct converters (e.g. mbstowcs()) decreases conversion + * times by 20-40% (depends on specific converter used). + */ + + +static int +sjis_mbstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + + XLCd lcd = (XLCd)conv->state; + + register int chr_len = 0; + register int outbuf = 0; + register int shift_mult = 0; + register Uint chrcode = 0; + + Uchar ch, ch2; + Uint wc_encode = 0; + Uint wc_tmp = 0; + + Bool new_char; + + int firstbyte; + int length; + int num_conv; + int unconv_num = 0; + + XPointer inbufptr = *from; + wchar_t *outbufptr = (wchar_t *) *to; + wchar_t *outbuf_base = outbufptr; + + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (new_char = True, firstbyte = True; *from_left > 0; (*from_left)--) { + + ch = *inbufptr++; + + if (firstbyte) { + if (ASCII_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + if (isascii(ch)) { + length = CS0->length; + *outbufptr++ = (wchar_t)ch; + continue; + } + else if (iskanji(ch)) { + if (KANJI_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + firstbyte = False; + length = CS1->length; + if (*from_left < length || *to_left < length) + return -1; + wc_encode = CS1->wc_encoding; + ch2 = *inbufptr; + sjis_to_jis(&ch, &ch2); + chrcode = ch; + } + else if (iskana(ch)) { + if (KANA_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + length = CS2->length; + wc_encode = CS2->wc_encoding; + chrcode = BIT8OFF(ch); + } + else if (isuserdef(ch)) { + if (USERDEF_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + firstbyte = False; + length = CS3->length; + if (*from_left < length || *to_left < length) + return -1; + wc_encode = CS3->wc_encoding; + ch2 = *inbufptr; + sjis_to_jis(&ch, &ch2); + chrcode = ch; + } + else /* unknown */ { + unconv_num++; + (*from_left)--; + continue; + } + } else { /* 2nd byte of multibyte char */ + if (!VALID_MULTIBYTE((Uchar) *(inbufptr-1))) { + unconv_num++; + firstbyte = True; + } + chrcode = ch2; + } + + if (new_char) { + chr_len = length; + shift_mult = length - 1; + new_char = False; + } + + chrcode <<= (wc_shift * shift_mult); + shift_mult--; + wc_tmp |= chrcode; + if (--chr_len == 0) { + wc_tmp |= wc_encode; + *outbufptr++ = wc_tmp; + + firstbyte = True; + new_char = True; + wc_tmp = (Uint)0; + } + + } /* end for */ + + *to = (XPointer)outbufptr; + + if ((num_conv = outbufptr - outbuf_base) > 0) + (*to_left) -= num_conv; + + return unconv_num; +} + + +#define byte1 (length == codeset->length - 1) +#define byte2 (byte1 == 0) + +static int +sjis_wcstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register wchar_t *inbufptr = (wchar_t *) *from; + register XPointer outbufptr = *to; + XPointer outbuf_base = outbufptr; + wchar_t wch; + register length; + Uchar tmp; + Uchar t1, t2; + int num_conv; + int unconv_num = 0; + + XLCd lcd = (XLCd)conv->state; + CodeSet codeset; + Ulong wc_encoding_mask = XLC_GENERIC(lcd, wc_encode_mask); + Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); + + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (; *from_left > 0 ; (*from_left)-- ) { + + wch = *inbufptr++; + + if (!(codeset = wc_codeset(lcd, wch))) { + unconv_num++; + (*from_left)--; + continue; + } + + length = codeset->length; + wch ^= (wchar_t)codeset->wc_encoding; + + do { + length--; + tmp = wch>>(wchar_t)( (Ulong)length * wc_shift); + + if (kana) + tmp = BIT8ON(tmp); + + else if (byte1 && (kanji || userdef)) { + t1 = BIT8OFF(tmp); + continue; + } + + else if (byte2 && (kanji || userdef)) { + t2 = BIT8OFF(tmp); + jis_to_sjis(&t1, &t2); + *outbufptr++ = (char)t1; + tmp = t2; + } + + *outbufptr++ = (char)tmp; + } while (length); + + } /* end for */ + + *to = (XPointer)outbufptr; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; +} +#undef byte1 +#undef byte2 + +/* + * sjis<->jis conversion for widechar kanji (See Note at top of file) + */ +static void +sjis_to_jis(p1, p2) + Uchar *p1; + Uchar *p2; +{ + register Uchar c1 = *p1; + register Uchar c2 = *p2; + register Uchar adjust = c2 < 0x9f; + register Uchar rowOffset = c1 < 0xa0 ? 0x70 : 0xb0; + register Uchar cellOffset = adjust ? (0x1f + (c2 > 0x7f)) : 0x7e; + + *p1 = ((c1 - rowOffset) << 1) - adjust; + *p2 -= cellOffset; +} + +static void +jis_to_sjis(p1, p2) + Uchar *p1; + Uchar *p2; +{ + register Uchar c1 = *p1; + register Uchar c2 = *p2; + register Uchar rowOffset = c1 < 0x5f ? 0x70 : 0xb0; + register Uchar cellOffset = c1 % 2 ? 0x1f + (c2 > 0x5f) : 0x7e; + + *p1 = ((Uchar)(c1 + 1) >> 1) + rowOffset; + *p2 = c2 + cellOffset; +} + +static CodeSet +wc_codeset(lcd, wch) + XLCd lcd; + wchar_t wch; +{ + register CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); +#if !defined(__sony_news) || defined(SVR4) + register int end = XLC_GENERIC(lcd, codeset_num); + register Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); + + for (; --end >= 0; codesets++) + if ( widech == (*codesets)->wc_encoding ) + return *codesets; + + return NULL; +#else + if( iskanji(wch >> 8) ) + return( codesets[1] ); + if( iskana(wch & 0xff) ) + return( codesets[2] ); + return( codesets[0] ); +#endif +} + + +static int +sjis_mbtocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + XlcCharSet charset = NULL; + int char_size = 0; + int unconv_num = 0; + register char *src = *from, *dst = *to; + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + + + if (iskanji(*src)) { + if (KANJI_CODESET >= codeset_num) + return -1; + charset = *CS1->charset_list; + char_size = charset->char_size; + + if (*from_left >= char_size && *to_left >= char_size) { + *dst++ = *src++; + *dst++ = *src++; + if (!VALID_MULTIBYTE((Uchar) *(src-1))) /* check 2nd byte */ + unconv_num++; + sjis_to_jis((Uchar *)(dst-2), (Uchar *)(dst-1)); + } else + return -1; + } + else if (isuserdef(*src)) { + if (USERDEF_CODESET >= codeset_num) + return -1; + charset = *CS3->charset_list; + char_size = charset->char_size; + + if (*from_left >= char_size && *to_left >= char_size) { + *dst++ = *src++; + *dst++ = *src++; + if (!VALID_MULTIBYTE((Uchar) *(src-1))) /* check 2nd byte */ + unconv_num++; + sjis_to_jis((Uchar *)(dst-2), (Uchar *)(dst-1)); + } else + return -1; + } + else if (isascii(*src)) { + if (ASCII_CODESET >= codeset_num) + return -1; + charset = *CS0->charset_list; + char_size = charset->char_size; + + if (*from_left >= char_size && *to_left >= char_size) + *dst++ = *src++; + else + return -1; + } + else if (iskana(*src)) { + if (KANA_CODESET >= codeset_num) + return -1; + charset = *CS2->charset_list; + char_size = charset->char_size; + + if (*from_left >= char_size && *to_left >= char_size) + *dst++ = *src++; + else + return -1; + } + else /* unknown */ + return -1; + + *from_left -= char_size; + *to_left -= char_size; + + *to = dst; + *from = src; + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset; + + return unconv_num; +} + + +static int +sjis_mbstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd) conv->state; + char *tmp_from, *tmp_to; + int tmp_from_left, tmp_to_left; + XlcCharSet charset, tmp_charset; + XPointer tmp_args[1]; + int unconv_num = 0, ret; + + + +/* Determine the charset of the segment and convert one characater: */ + + tmp_args[0] = (XPointer) &charset; /* charset from sjis_mbtocs() */ + while + ((ret = sjis_mbtocs(conv, from, from_left, to, to_left, tmp_args, 1)) > 0) + unconv_num += ret; + if ( ret < 0 ) + return ret; + + tmp_from = *from; + tmp_from_left = *from_left; + tmp_to_left = *to_left; + tmp_to = *to; + +/* Convert remainder of the segment: */ + + tmp_args[0] = (XPointer) &tmp_charset; + while( (ret = sjis_mbtocs(conv, &tmp_from, &tmp_from_left, &tmp_to, + &tmp_to_left, tmp_args, 1)) >= 0 ) { + + if (ret > 0) { + unconv_num += ret; + continue; + } + + if (tmp_charset != charset) /* quit on end of segment */ + break; + + *from = tmp_from; + *from_left = tmp_from_left; + *to = tmp_to; + *to_left = tmp_to_left; + } + + if (num_args > 0) + *((XlcCharSet *) args[0]) = charset; + + return unconv_num; +} + +static int +sjis_wcstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd) conv->state; + wchar_t *wcptr = *((wchar_t **)from); + register char *bufptr = *((char **) to); + wchar_t wch; + char *tmpptr; + register length; + CodeSet codeset; + Ulong wc_encoding; + int buf_len = *to_left; + int unconv_num = 0; + int wcstr_len = *from_left; + + + if (!(codeset = wc_codeset(lcd, *wcptr))) + return -1; + + if (wcstr_len < buf_len / codeset->length) + buf_len = wcstr_len * codeset->length; + +#if !defined(__sony_news) || defined(SVR4) + wc_encoding = codeset->wc_encoding; + + for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) { + wch = *wcptr; + + if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding) + break; + + length = codeset->length; + + buf_len -= length; + bufptr += length; + tmpptr = bufptr - 1; + + while (length--) { + *tmpptr-- = kana ? BIT8ON(wch) : BIT8OFF(wch); + wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits); + } + } +#else + length = codeset->length; + for( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len-- ) { + wch = *wcptr; + if( codeset != wc_codeset( lcd, wch ) ) + break; + + buf_len -= length; + if( length == 2 ) { + unsigned short code; + + code = sjis2jis( wch & 0xffff ); + *bufptr++ = code >> 8; + *bufptr++ = code & 0xff; + } + else + *bufptr++ = wch & 0xff; + } +#endif + + if (num_args > 0) + *((XlcCharSet *) args[0]) = *codeset->charset_list; + + *from_left -= wcptr - (wchar_t *) *from; + *from = (XPointer) wcptr; + + *to_left -= bufptr - *to; + *to = bufptr; + + return 0; +} + +static CodeSet +GetCodeSetFromCharSet(lcd, charset) + XLCd lcd; + XlcCharSet charset; +{ + register CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); + register XlcCharSet *charset_list; + register codeset_num, num_charsets; + + codeset_num = XLC_GENERIC(lcd, codeset_num); + + for ( ; codeset_num-- > 0; codeset++) { + num_charsets = (*codeset)->num_charsets; + charset_list = (*codeset)->charset_list; + + for ( ; num_charsets-- > 0; charset_list++) + if (*charset_list == charset) + return *codeset; + } + + return (CodeSet) NULL; +} + + +static int +sjis_cstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + char **from; + int *from_left; + char **to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd) conv->state; + register char *csptr = *from; + register char *bufptr = *to; + int csstr_len = *from_left; + register buf_len = *to_left; + int length; + CodeSet codeset; + EncodingType type; + int cvt_length = 0; + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + + + if (num_args < 1) + return -1; + + if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) + return -1; + + csstr_len /= codeset->length; + buf_len /= codeset->length; + if (csstr_len < buf_len) + buf_len = csstr_len; + + cvt_length += buf_len * codeset->length; + + if (bufptr) { + while (buf_len--) { + length = codeset->length; + while (length--) + *bufptr++ = codeset->length == 1 && codeset->side == XlcGR ? + BIT8ON(*csptr++) : BIT8OFF(*csptr++); + + if (codeset->length == 2) + jis_to_sjis((Uchar *)(bufptr-2), (Uchar *)(bufptr-1)); + } + } + + *from_left -= csptr - *from; + *from = csptr; + + if (bufptr) + *to += cvt_length; + *to_left -= cvt_length; + + + return 0; +} + +static int +sjis_cstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd) conv->state; + register char *csptr = (char *) *from; + wchar_t *bufptr = (wchar_t *) *to; + wchar_t *toptr = (wchar_t *) *to; + int csstr_len = *from_left; + register buf_len = *to_left; + wchar_t wch; + int length; + Ulong wc_shift_bits = (int)XLC_GENERIC(lcd, wc_shift_bits); + CodeSet codeset; + + + if (num_args < 1) + return -1; + + if (!(codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]))) + return -1; + + csstr_len /= codeset->length; + if (csstr_len < buf_len) + buf_len = csstr_len; + + *to_left -= buf_len; + + if (bufptr) { + + toptr += buf_len; + *to = (XPointer) toptr; + + while (buf_len--) { + wch = (wchar_t) BIT8OFF(*csptr); + csptr++; + + length = codeset->length - 1; + while (length--) { + wch = (wch << wc_shift_bits) | BIT8OFF(*csptr); + csptr++; + } + *bufptr++ = wch | codeset->wc_encoding; + } + } + + *from_left -= csptr - *from; + *from = csptr; + + return 0; +} + + +/* + * Stripped down Direct CT converters for SJIS + * + */ + +#define BADCHAR(min_ch, c) (BIT8OFF(c) < (char)min_ch && BIT8OFF(c) != 0x0 && \ + BIT8OFF(c) != '\t' && BIT8OFF(c) != '\n' && \ + BIT8OFF(c) != 0x1b) + +typedef struct _CTDataRec { + int side; + int length; + char *name; + Ulong wc_encoding; + char *ct_encoding; + int ct_encoding_len; + int set_size; + Uchar min_ch; + Uchar ct_type; +} CTDataRec, *CTData; + +typedef struct _StateRec { + CTData GL_charset; + CTData GR_charset; + CTData charset; +} StateRec, *State; + +static enum { CT_STD, CT_NSTD, CT_DIR, CT_EXT0, CT_EXT1, CT_EXT2, CT_VER } + ct_types; + +static CTDataRec ctdata[] = +{ + { XlcGL, 1, "ISO8859-1:GL", 0, "\033(B" , 3, 0, 0, CT_STD }, + { XlcGR, 1, "ISO8859-1:GR", 0, "\033-A" , 3, 0, 0, CT_STD }, + { XlcGL, 1, "JISX0201.1976-0:GL", 0, "\033(J" , 3, 0, 0, CT_STD }, + { XlcGR, 1, "JISX0201.1976-0:GR", 0, "\033)I" , 3, 0, 0, CT_STD }, + { XlcGL, 2, "JISX0208.1983-0:GL", 0, "\033$(B" , 4, 0, 0, CT_STD }, + { XlcGR, 2, "JISX0208.1983-0:GR", 0, "\033$)B" , 4, 0, 0, CT_STD }, + { XlcGL, 2, "JISX0212.1990-0:GL", 0, "\033$(D" , 4, 0, 0, CT_STD }, + { XlcGR, 2, "JISX0212.1990-0:GR", 0, "\033$)D" , 4, 0, 0, CT_STD }, + { XlcUnknown, 0, "Ignore-Ext-Status?", 0, "\033#" , 2, 0, 0, CT_VER }, + { XlcUnknown, 0, "NonStd-?-OctetChar", 0, "\033%/0" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 1, "NonStd-1-OctetChar", 0, "\033%/1" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 2, "NonStd-2-OctetChar", 0, "\033%/2" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 3, "NonStd-3-OctetChar", 0, "\033%/3" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 4, "NonStd-4-OctetChar", 0, "\033%/4" , 4, 0, 0, CT_NSTD }, + { XlcUnknown, 0, "Extension-2" , 0, "\033%/" , 3, 0, 0, CT_EXT2 }, + { XlcUnknown, 0, "Extension-0" , 0, "\033" , 1, 0, 0, CT_EXT0 }, + { XlcUnknown, 0, "Begin-L-to-R-Text", 0, "\2331]" , 3, 0, 0, CT_DIR }, + { XlcUnknown, 0, "Begin-R-to-L-Text", 0, "\2332]" , 3, 0, 0, CT_DIR }, + { XlcUnknown, 0, "End-Of-String", 0, "\233]" , 2, 0, 0, CT_DIR }, + { XlcUnknown, 0, "Extension-1" , 0, "\233" , 1, 0, 0, CT_EXT1 }, +}; + +/* Note on above table: sjis_ctstombs() and sjis_ctstowcs() parser depends on + * certain table entries occurring in decreasing string length-- + * 1. CT_EXT2 and CT_EXT0 entries must occur after CT_NSTD entries. + * 2. CT_DIR and CT_EXT1 entries must occur after CT_DIR entries. + */ + +static CTData ctdptr[sizeof(ctdata) / sizeof(CTDataRec)]; +static CTData ctd_endp = ctdata + ((sizeof(ctdata) / sizeof(CTDataRec))) - 1; +static enum { Ascii, Kanji, Kana, Userdef } cs_nums; + + +/* + * initCTptr(): Set ctptr[] to point at ctdata[], indexed by codeset_num. + */ +static void +initCTptr(lcd) + XLCd lcd; +{ + int num_codesets = XLC_GENERIC(lcd, codeset_num); + int num_charsets; + int i, j; + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + CodeSet codeset; + XlcCharSet charset; + CTData ctdp = ctdata; + + ctdptr[Ascii] = &ctdata[0]; /* failsafe */ + + for (i = 0; i < num_codesets; i++) { + + codeset = codesets[i]; + num_charsets = codeset->num_charsets; + + for (j = 0; j < num_charsets; j++) { + + charset = codeset->charset_list[j]; + + for (ctdp = ctdata; ctdp <= ctd_endp; ctdp++) + + if (! strcmp(ctdp->name, charset->name)) { + + ctdptr[codeset->cs_num] = ctdp; + + ctdptr[codeset->cs_num]->wc_encoding = codeset->wc_encoding; + + ctdptr[codeset->cs_num]->set_size = + charset->set_size; + + ctdptr[codeset->cs_num]->min_ch = + charset->set_size == 94 && + (ctdptr[codeset->cs_num]->length > 1 || + ctdptr[codeset->cs_num]->side == XlcGR) ? 0x21 : 0x20; + + break; + } + } + } +} + + +static int +sjis_mbstocts(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register ct_len = *to_left; + int cs_num; + int clen; + int unconv_num = 0; + int num_conv; + XPointer inbufptr = *from; + register char *ctptr = *to; + XPointer ct_base = ctptr; + + StateRec ct_state; + CTData charset; + XLCd lcd = (XLCd) conv->state; + int codeset_num = XLC_GENERIC(lcd, codeset_num); + + +/* Initial State: */ + + ct_state.GL_charset = ctdptr[Ascii]; + ct_state.GR_charset = NULL; + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (;*from_left > 0; (*from_left) -= charset->length) { + + if (iskanji(*inbufptr)) { + if (KANJI_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Kanji; + charset = ctdptr[Kanji]; + if (!VALID_MULTIBYTE((Uchar) *(inbufptr+1))) + unconv_num++; + } + else if (isuserdef(*inbufptr)) { + if (USERDEF_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Userdef; + charset = ctdptr[Userdef]; + if (!VALID_MULTIBYTE((Uchar) *(inbufptr+1))) + unconv_num++; + } + else if (isascii(*inbufptr)) { + if (ASCII_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Ascii; + charset = ctdptr[Ascii]; + } + else if (iskana(*inbufptr)) { + if (KANA_CODESET >= codeset_num) { + unconv_num++; + (*from_left)--; + continue; + } + cs_num = Kana; + charset = ctdptr[Kana]; + } + else { /* unknown */ + unconv_num++; + (*from_left)--; + continue; + } + + if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || + (charset->side == XlcGL && charset != ct_state.GL_charset) ) { + + ct_len -= ctdptr[cs_num]->ct_encoding_len; + if (ct_len < 0) { + unconv_num++; + break; + } + + if (ctptr) { + strcpy(ctptr, ctdptr[cs_num]->ct_encoding); + ctptr += ctdptr[cs_num]->ct_encoding_len; + } + } + + clen = charset->length; + do { + *ctptr++ = *inbufptr++; + } while (--clen); + + if (charset->length >= 2) { + sjis_to_jis((Uchar *)(ctptr-2), (Uchar *)(ctptr-1)); + if (BADCHAR(charset->min_ch, *(ctptr-2)) || + BADCHAR(charset->min_ch, *(ctptr-1))) { + unconv_num++; + continue; + } + } + else + if (BADCHAR(charset->min_ch, *(ctptr-1))) { + unconv_num++; + continue; + } + + if (charset->side == XlcGR) + ct_state.GR_charset = charset; + else if (charset->side == XlcGL) + ct_state.GL_charset = charset; + } + + *to = (XPointer)ctptr; + + if ((num_conv = (int)(ctptr - ct_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; + +} + + +#define byte1 (length == codeset->length - 1) +#define byte2 (byte1 == 0) + +static int +sjis_wcstocts(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register ct_len = *to_left; + register wchar_t *inbufptr = (wchar_t *) *from; + register char *ctptr = *to; + XPointer ct_base = ctptr; + wchar_t wch; + register length; + Uchar tmp; + Uchar t1 = 0, t2; + int num_conv; + + StateRec ct_state; + XLCd lcd = (XLCd)conv->state; + CTData charset; + CodeSet codeset; + int unconv_num = 0; + Ulong wc_encoding_mask = XLC_GENERIC(lcd, wc_encode_mask); + Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); + + +/* Initial State: */ + ct_state.GL_charset = ctdptr[0]; /* Codeset 0 */ + ct_state.GR_charset = NULL; + + if (*from_left > *to_left) + *from_left = *to_left; + + for (; *from_left > 0 ; (*from_left)-- ) { + + wch = *inbufptr++; + + if (!(codeset = wc_codeset(lcd, wch))) { + unconv_num++; + (*from_left)--; + continue; + } + + charset = ctdptr[codeset->cs_num]; + + length = codeset->length; + wch ^= (wchar_t)codeset->wc_encoding; + + if ( (charset->side == XlcGR && charset != ct_state.GR_charset) || + (charset->side == XlcGL && charset != ct_state.GL_charset) ) { + + ct_len -= ctdptr[codeset->cs_num]->ct_encoding_len; + if (ct_len < 0) { + unconv_num++; + break; + } + + if (ctptr) { + strcpy(ctptr, ctdptr[codeset->cs_num]->ct_encoding); + ctptr += ctdptr[codeset->cs_num]->ct_encoding_len; + } + + } + + if (charset->side == XlcGR) + ct_state.GR_charset = charset; + else if (charset->side == XlcGL) + ct_state.GL_charset = charset; + + do { + length--; + tmp = wch>>(wchar_t)( (Ulong)length * wc_shift); + + if (kana) { + if (BADCHAR(charset->min_ch, (char)tmp)) { + unconv_num++; + break; + } + *ctptr++ = (char)BIT8ON(tmp); + } + + else if (byte1 && (kanji || userdef)) { + t1 = tmp; + } + + else if (byte2 && (kanji || userdef)) { + if (BADCHAR(charset->min_ch, (char)t1) || + BADCHAR(charset->min_ch, (char)tmp)) { + unconv_num++; + break; + } + + *ctptr++ = (char)BIT8OFF(t1); + *ctptr++ = (char)BIT8OFF(tmp); + } + + else { + if (BADCHAR(charset->min_ch, (char)tmp)) { + unconv_num++; + break; + } + *ctptr++ = (char)tmp; + } + } while (length); + + } /* end for */ + + *to = (XPointer)ctptr; + + if ((num_conv = (int)(ctptr - ct_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; +} +#undef byte1 +#undef byte2 + +#define SKIP_I(str) while (*(str) >= 0x20 && *(str) <= 0x2f) (str)++; +#define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; + +static int +sjis_ctstombs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + register XPointer inbufptr = *from; + register XPointer outbufptr = *to; + XPointer inbuf_base; + XPointer outbuf_base = outbufptr; + register clen, length; + int unconv_num = 0; + int num_conv; + unsigned int ct_seglen = 0; + Uchar ct_type; + CTData ctdp = ctdata; /* default */ + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (length = ctdata[Ascii].length; *from_left > 0 ; (*from_left) -= length) + { + ct_type = CT_STD; + if (*inbufptr == '\033' || *inbufptr == (char)'\233') { + + for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { + + if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) + { + inbufptr += ctdp->ct_encoding_len; + (*from_left) -= ctdp->ct_encoding_len; + if( ctdp->length ) { + length = ctdp->length; + if( *from_left < length ) { + *to = (XPointer)outbufptr; + *to_left -= outbufptr - outbuf_base; + return( unconv_num + *from_left ); + } + } + ct_type = ctdp->ct_type; + break; + } + } + if (ctdp > ctd_endp) /* failed to match CT sequence */ + unconv_num++; + } + +/* The following code insures that non-standard encodings, direction, extension, + * and version strings are ignored; subject to change in future. + */ + switch (ct_type) { + case CT_STD: + break; + case CT_EXT2: + inbufptr++; + (*from_left)--; + case CT_NSTD: + ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; + inbufptr += ct_seglen; + (*from_left) -= ct_seglen; + continue; + case CT_EXT0: + inbuf_base = inbufptr; + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + (*from_left) -= ct_seglen; + continue; + case CT_EXT1: + inbuf_base = inbufptr; + SKIP_P(inbufptr); + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + (*from_left) -= ct_seglen; + continue; + case CT_DIR: + continue; + case CT_VER: + inbufptr += 2; + (*from_left) -= 2; + continue; + } + + clen = length; + do { + *outbufptr++ = *inbufptr++; + } while (--clen); + + if (length >= 2) + jis_to_sjis((Uchar *)(outbufptr-2), (Uchar *)(outbufptr-1)); + } + + *to = (XPointer)outbufptr; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + (*to_left) -= num_conv; + + return unconv_num; +} + + +static int +sjis_ctstowcs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XLCd lcd = (XLCd)conv->state; + Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); + register XPointer inbufptr = *from; + XPointer inbuf_base; + register wchar_t *outbufptr = (wchar_t *) *to; + wchar_t *outbuf_base = outbufptr; + register clen, length; + int num_conv; + int unconv_num = 0; + unsigned int ct_seglen = 0; + Uchar ct_type = 0; + register shift_mult; + wchar_t wc_tmp; + wchar_t wch; + Ulong wc_encoding; + CTData ctdp = ctdata; + + + if (*from_left > *to_left) + *from_left = *to_left; + + for (length = ctdata[Ascii].length; *from_left > 0; (*from_left) -= length ) + { + ct_type = CT_STD; + if (*inbufptr == '\033' || *inbufptr == (char)'\233') { + for (ctdp = ctdata; ctdp <= ctd_endp ; ctdp++) { + + if(!strncmp(inbufptr, ctdp->ct_encoding, ctdp->ct_encoding_len)) + { + inbufptr += ctdp->ct_encoding_len; + (*from_left) -= ctdp->ct_encoding_len; + if( ctdp->length ) { + length = ctdp->length; + if( *from_left < length ) { + *to = (XPointer)outbufptr; + *to_left -= outbufptr - outbuf_base; + return( unconv_num + *from_left ); + } + } + ct_type = ctdp->ct_type; + break; + } + } + if (ctdp > ctd_endp) /* failed to match CT sequence */ + unconv_num++; + } + +/* The following block of code insures that non-standard encodings, direction, + * extension, and version strings are ignored; subject to change in future. + */ + switch (ct_type) { + case CT_STD: + break; + case CT_EXT2: + inbufptr++; + (*from_left)--; + case CT_NSTD: + ct_seglen = (BIT8OFF(*inbufptr) << 7) + BIT8OFF(*(inbufptr+1)) + 2; + inbufptr += ct_seglen; + (*from_left) -= ct_seglen; + continue; + case CT_EXT0: + inbuf_base = inbufptr; + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + (*from_left) -= ct_seglen; + continue; + case CT_EXT1: + inbuf_base = inbufptr; + SKIP_P(inbufptr); + SKIP_I(inbufptr); + inbufptr++; + ct_seglen = (unsigned)(inbufptr - inbuf_base); + (*from_left) -= ct_seglen; + continue; + case CT_DIR: + continue; + case CT_VER: + inbufptr += 2; + (*from_left) -= 2; + continue; + } +#if !defined(__sony_news) || defined(SVR4) + wc_encoding = (ctdp == ctdptr[Kana] && isleftside(*inbufptr)) ? + ctdptr[Ascii]->wc_encoding : ctdp->wc_encoding; + + shift_mult = length - 1; + wch = (wchar_t)0; + clen = length; + + do { + wc_tmp = BIT8OFF(*inbufptr++) << (wc_shift_bits * shift_mult); + wch |= wc_tmp; + shift_mult--; + } while (--clen); + *outbufptr++ = wch | wc_encoding; +#else + if( length == 1 ) + *outbufptr++ = (unsigned char)*inbufptr++; + else if( length == 2 ) { + unsigned short code; + code = (*inbufptr << 8) | *(inbufptr+1); + *outbufptr++ = jis2sjis( code ); + inbufptr += 2; + } +#endif + } + *to = (XPointer)outbufptr; + + if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) + (*to_left) -= num_conv ; + + return unconv_num; + +} +#undef BADCHAR + +static void +close_converter(conv) + XlcConv conv; +{ + Xfree((char *) conv); +} + + +static XlcConv +create_conv(lcd, methods) + XLCd lcd; + XlcConvMethods methods; +{ + XlcConv conv; + + conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (conv == NULL) + return (XlcConv) NULL; + + conv->methods = methods; + conv->state = (XPointer) lcd; + return conv; +} + + +enum { MBSTOCS, WCSTOCS, MBTOCS, CSTOMBS, CSTOWCS, MBSTOWCS, WCSTOMBS, + WCSTOCTS, MBSTOCTS, CTSTOMBS, CTSTOWCS }; + +static XlcConvMethodsRec conv_methods[] = { + {close_converter, sjis_mbstocs, NULL }, + {close_converter, sjis_wcstocs, NULL }, + {close_converter, sjis_mbtocs, NULL }, + {close_converter, sjis_cstombs, NULL }, + {close_converter, sjis_cstowcs, NULL }, + {close_converter, sjis_mbstowcs, NULL }, + {close_converter, sjis_wcstombs, NULL }, + {close_converter, sjis_wcstocts, NULL }, + {close_converter, sjis_mbstocts, NULL }, + {close_converter, sjis_ctstombs, NULL }, + {close_converter, sjis_ctstowcs, NULL }, +}; + + +static XlcConv +open_mbstocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBSTOCS]); +} + +static XlcConv +open_wcstocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[WCSTOCS]); +} + +static XlcConv +open_mbtocs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBTOCS]); +} + +static XlcConv +open_cstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CSTOMBS]); +} + +static XlcConv +open_cstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CSTOWCS]); +} + +static XlcConv +open_mbstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBSTOWCS]); +} + +static XlcConv +open_wcstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[WCSTOMBS]); +} + +static XlcConv +open_wcstocts(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[WCSTOCTS]); +} + +static XlcConv +open_mbstocts(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[MBSTOCTS]); +} + +static XlcConv +open_ctstombs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CTSTOMBS]); +} + +static XlcConv +open_ctstowcs(from_lcd, from_type, to_lcd, to_type) + XLCd from_lcd; + char *from_type; + XLCd to_lcd; + char *to_type; +{ + return create_conv(from_lcd, &conv_methods[CTSTOWCS]); +} + +XLCd +_fallcSjisLoader(name) + char *name; +{ + XLCd lcd; + CodeSet *codeset_list; + + lcd = _fallcCreateLC(name, _fallcGenericMethods); + if (lcd == NULL) + return lcd; + + if ((_fallcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "sjis"))) { + _fallcDestroyLC(lcd); + return (XLCd) NULL; + } + + initCTptr(lcd); + + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs); + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); + +#ifndef FORCE_INDIRECT_CONVERTER + _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs); + _fallcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts); + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); +#endif + + + return lcd; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcStd.c b/cde/programs/dtudcfonted/libfal/_fallcStd.c new file mode 100644 index 00000000..7e15afe2 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcStd.c @@ -0,0 +1,328 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcStd.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:41 */ +/* $XConsortium: _fallcStd.c /main/1 1996/04/08 15:19:02 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" + +int +_fallcmbtowc(lcd, wstr, str, len) + XLCd lcd; + wchar_t *wstr; + char *str; + int len; +{ + static XLCd last_lcd = NULL; + static XlcConv conv = NULL; + XPointer from, to; + int from_left, to_left; + wchar_t tmp_wc; + + if (lcd == NULL) { + lcd = _fallcCurrentLC(); + if (lcd == NULL) + return -1; + } + if (str == NULL) + return XLC_PUBLIC(lcd, is_state_depend); + + if (conv && lcd != last_lcd) { + _fallcCloseConverter(conv); + conv = NULL; + } + + last_lcd = lcd; + + if (conv == NULL) { + conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); + if (conv == NULL) + return -1; + } + + from = (XPointer) str; + from_left = len; + to = (XPointer) (wstr ? wstr : &tmp_wc); + to_left = 1; + + if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) + return -1; + + return (len - from_left); +} + +int +_fallcwctomb(lcd, str, wc) + XLCd lcd; + char *str; + wchar_t wc; +{ + static XLCd last_lcd = NULL; + static XlcConv conv = NULL; + XPointer from, to; + int from_left, to_left, length; + + if (lcd == NULL) { + lcd = _fallcCurrentLC(); + if (lcd == NULL) + return -1; + } + if (str == NULL) + return XLC_PUBLIC(lcd, is_state_depend); + + if (conv && lcd != last_lcd) { + _fallcCloseConverter(conv); + conv = NULL; + } + + last_lcd = lcd; + + if (conv == NULL) { + conv = _fallcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte); + if (conv == NULL) + return -1; + } + + from = (XPointer) &wc; + from_left = 1; + to = (XPointer) str; + length = to_left = XLC_PUBLIC(lcd, mb_cur_max); + + if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) + return -1; + + return (length - to_left); +} + +int +_fallcmbstowcs(lcd, wstr, str, len) + XLCd lcd; + wchar_t *wstr; + char *str; + int len; +{ + XlcConv conv; + XPointer from, to; + int from_left, to_left, ret; + + if (lcd == NULL) { + lcd = _fallcCurrentLC(); + if (lcd == NULL) + return -1; + } + + conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); + if (conv == NULL) + return -1; + + from = (XPointer) str; + from_left = strlen(str); + to = (XPointer) wstr; + to_left = len; + + if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) + ret = -1; + else { + ret = len - to_left; + if (wstr && to_left > 0) + wstr[ret] = (wchar_t) 0; + } + + _fallcCloseConverter(conv); + + return ret; +} + +int +_fallcwcstombs(lcd, str, wstr, len) + XLCd lcd; + char *str; + wchar_t *wstr; + int len; +{ + XlcConv conv; + XPointer from, to; + int from_left, to_left, ret; + + if (lcd == NULL) { + lcd = _fallcCurrentLC(); + if (lcd == NULL) + return -1; + } + + conv = _fallcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte); + if (conv == NULL) + return -1; + + from = (XPointer) wstr; + from_left = _falwcslen(wstr); + to = (XPointer) str; + to_left = len; + + if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) + ret = -1; + else { + ret = len - to_left; + if (str && to_left > 0) + str[ret] = '\0'; + } + + _fallcCloseConverter(conv); + + return ret; +} + + +int +_falmbtowc(wstr, str, len) + wchar_t *wstr; + char *str; + int len; +{ + return _fallcmbtowc((XLCd) NULL, wstr, str, len); +} + +int +_falmblen(str, len) + char *str; + int len; +{ + return _falmbtowc((wchar_t *) NULL, str, len); +} + +int +_falwctomb(str, wc) + char *str; + wchar_t wc; +{ + return _fallcwctomb((XLCd) NULL, str, wc); +} + +int +_falmbstowcs(wstr, str, len) + wchar_t *wstr; + char *str; + int len; +{ + return _fallcmbstowcs((XLCd) NULL, wstr, str, len); +} + +int +_falwcstombs(str, wstr, len) + char *str; + wchar_t *wstr; + int len; +{ + return _fallcwcstombs((XLCd) NULL, str, wstr, len); +} + +wchar_t * +_falwcscpy(wstr1, wstr2) + register wchar_t *wstr1, *wstr2; +{ + wchar_t *wstr_tmp = wstr1; + + while (*wstr1++ = *wstr2++) + ; + + return wstr_tmp; +} + +wchar_t * +_falwcsncpy(wstr1, wstr2, len) + register wchar_t *wstr1, *wstr2; + register len; +{ + wchar_t *wstr_tmp = wstr1; + + while (len-- > 0) + if (!(*wstr1++ = *wstr2++)) + break; + + while (len-- > 0) + *wstr1++ = (wchar_t) 0; + + return wstr_tmp; +} + +int +_falwcslen(wstr) + register wchar_t *wstr; +{ + register wchar_t *wstr_ptr = wstr; + + while (*wstr_ptr) + wstr_ptr++; + + return wstr_ptr - wstr; +} + +int +_falwcscmp(wstr1, wstr2) + register wchar_t *wstr1, *wstr2; +{ + for ( ; *wstr1 && *wstr2; wstr1++, wstr2++) + if (*wstr1 != *wstr2) + break; + + return *wstr1 - *wstr2; +} + +int +_falwcsncmp(wstr1, wstr2, len) + register wchar_t *wstr1, *wstr2; + register len; +{ + for ( ; *wstr1 && *wstr2 && len > 0; wstr1++, wstr2++, len--) + if (*wstr1 != *wstr2) + break; + + if (len <= 0) + return 0; + + return *wstr1 - *wstr2; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcTxtPr.c b/cde/programs/dtudcfonted/libfal/_fallcTxtPr.c new file mode 100644 index 00000000..4e5923bb --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcTxtPr.c @@ -0,0 +1,255 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcTxtPr.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:41 */ +/* $XConsortium: _fallcTxtPr.c /main/1 1996/04/08 15:19:12 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include "_fallibint.h" +#include "_fallcPubI.h" +#include "_falutil.h" +#include +#include + +static int +get_buf_size(is_wide_char, list, count) + Bool is_wide_char; + XPointer list; + int count; +{ + register length = 0; + register char **mb_list; + register wchar_t **wc_list; + + if (list == NULL) + return 0; + + if (is_wide_char) { + wc_list = (wchar_t **) list; + for ( ; count-- > 0; wc_list++) { + if (*wc_list) + length += _falwcslen(*wc_list) + 1; + } + length *= 5; /* XXX */ + } else { + mb_list = (char **) list; + for ( ; count-- > 0; mb_list++) { + if (*mb_list) + length += strlen(*mb_list) + 1; + } + length *= 3; /* XXX */ + } + length = (length / BUFSIZ + 1) * BUFSIZ; /* XXX */ + + return length; +} + +static int +_XTextListToTextProperty(lcd, dpy, from_type, list, count, style, text_prop) + XLCd lcd; + Display *dpy; + char *from_type; + XPointer list; + int count; + XICCEncodingStyle style; + XTextProperty *text_prop; +{ + Atom encoding; + XlcConv conv; + char *to_type; + char **mb_list; + wchar_t **wc_list; + XPointer from; + char *to, *buf, *value; + int from_left, to_left, buf_len, nitems, unconv_num, ret, i; + Bool is_wide_char = False; + + if (strcmp(XlcNWideChar, from_type) == 0) + is_wide_char = True; + + buf_len = get_buf_size(is_wide_char, list, count); + if ((buf = (char *) Xmalloc(buf_len)) == NULL) + return XNoMemory; + + switch (style) { + case XStringStyle: + case XStdICCTextStyle: + encoding = XA_STRING; + to_type = XlcNString; + break; + case XCompoundTextStyle: + encoding = falInternAtom(dpy, "COMPOUND_TEXT", False); + to_type = XlcNCompoundText; + break; + case XTextStyle: + encoding = falInternAtom(dpy, XLC_PUBLIC(lcd, encoding_name), False); + to_type = XlcNMultiByte; + if (is_wide_char == False) { + nitems = 0; + mb_list = (char **) list; + to = buf; + for (i = 0; i < count; i++) { + strcpy(to, *mb_list); + from_left = strlen(*mb_list) + 1; + nitems += from_left; + to += from_left; + mb_list++; + } + unconv_num = 0; + goto done; + } + break; + default: + Xfree(buf); + return XConverterNotFound; + } + + if (count < 1) { + nitems = 0; + goto done; + } + +retry: + conv = _fallcOpenConverter(lcd, from_type, lcd, to_type); + if (conv == NULL) { + Xfree(buf); + return XConverterNotFound; + } + + if (is_wide_char) + wc_list = (wchar_t **) list; + else + mb_list = (char **) list; + + to = buf; + to_left = buf_len; + + unconv_num = 0; + + for (i = 1; to_left > 0; i++) { + if (is_wide_char) { + from = (XPointer) *wc_list; + from_left = _falwcslen(*wc_list); + wc_list++; + } else { + from = (XPointer) *mb_list; + from_left = strlen(*mb_list); + mb_list++; + } + + ret = _fallcConvert(conv, &from, &from_left, (XPointer *) &to, &to_left, + NULL, 0); + + if (ret < 0) + continue; + + if (ret > 0 && style == XStdICCTextStyle && encoding == XA_STRING) { + _fallcCloseConverter(conv); + encoding = falInternAtom(dpy, "COMPOUND_TEXT", False); + to_type = XlcNCompoundText; + goto retry; + } + + unconv_num += ret; + *to++ = '\0'; + to_left--; + + if (i >= count) + break; + + _fallcResetConverter(conv); + } + + _fallcCloseConverter(conv); + + nitems = to - buf; +done: + if (nitems <= 0) + nitems = 1; + value = (char *) Xmalloc(nitems); + if (value == NULL) { + Xfree(buf); + return XNoMemory; + } + if (nitems == 1) + *value = 0; + else + memcpy(value, buf, nitems); + nitems--; + Xfree(buf); + + text_prop->value = (unsigned char *) value; + text_prop->encoding = encoding; + text_prop->format = 8; + text_prop->nitems = nitems; + + return unconv_num; +} + +int +_falmbTextListToTextProperty(lcd, dpy, list, count, style, text_prop) + XLCd lcd; + Display *dpy; + char **list; + int count; + XICCEncodingStyle style; + XTextProperty *text_prop; +{ + return _XTextListToTextProperty(lcd, dpy, XlcNMultiByte, (XPointer) list, + count, style, text_prop); +} + +int +_falwcTextListToTextProperty(lcd, dpy, list, count, style, text_prop) + XLCd lcd; + Display *dpy; + wchar_t **list; + int count; + XICCEncodingStyle style; + XTextProperty *text_prop; +{ + return _XTextListToTextProperty(lcd, dpy, XlcNWideChar, (XPointer) list, + count, style, text_prop); +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcUTF.c b/cde/programs/dtudcfonted/libfal/_fallcUTF.c new file mode 100644 index 00000000..60e753d8 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcUTF.c @@ -0,0 +1,1566 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcUTF.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:41 */ +/* $XConsortium: _fallcUTF.c /main/2 1996/09/27 19:03:38 drk $ */ +/****************************************************************** + + Copyright 1993 by SunSoft, Inc. + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear +in supporting documentation, and that the name of SunSoft, Inc. +not be used in advertising or publicity pertaining to distribution +of the software without specific, written prior permission. +SunSoft, Inc. makes no representations about the suitability of +this software for any purpose. It is provided "as is" without +express or implied warranty. + +SunSoft Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +IN NO EVENT SHALL SunSoft, Inc. BE LIABLE FOR ANY SPECIAL, INDIRECT +OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE +OR PERFORMANCE OF THIS SOFTWARE. + + Author: Hiromu Inukai (inukai@Japan.Sun.COM) SunSoft, inc. + +******************************************************************/ +#include "_fallcUTF.h" + +static long getutfrune(); +static void our_wctomb( +#if NeedFunctionPrototypes + unsigned short r, + char **bufptr, + int *buf_len +#endif +); +static int our_mbtowc( +#if NeedFunctionPrototypes + unsigned long *p, + char *s, + size_t n +#endif +); +static void latin2rune( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif +); +static void jis02012rune( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif +); +static void jis02082rune( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif +); +static void ksc2rune( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif +); +static void gb2rune( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif +); +static void init_latin1tab(); +static void init_latin2tab(); +static void init_latin3tab(); +static void init_latin4tab(); +static void init_latin5tab(); +static void init_latin6tab(); +static void init_latin7tab(); +static void init_latin8tab(); +static void init_latin9tab(); +static void init_jis0201tab(); +static void init_jis0208tab(); +static void init_ksc5601tab(); +static void init_gb2312tab(); + + +static char *int_locale = NULL; +static long *tabkuten = NULL; +static long *tabksc5601 = NULL; +static long *tabgb = NULL; + +static UtfData utfdata_list = (UtfData)NULL; + +static XlcUTFDataRec default_utf_data[] = +{ + {"ISO8859-1", XlcGL, init_latin1tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin1tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin2tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin2tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin3tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin3tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin4tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin4tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin5tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin5tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin6tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin6tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin7tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin7tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin8tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin8tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGL, init_latin9tab, latin2rune, N11n_none, 0x20}, + {"ISO8859-1", XlcGR, init_latin9tab, latin2rune, N11n_none, 0x20}, + {"JISX0201.1976-0", XlcGL, init_jis0201tab, jis02012rune, N11n_none, 0x20}, + {"JISX0201.1976-0", XlcGR, init_jis0201tab, jis02012rune, N11n_none, 0x20}, + {"JISX0208.1983-0", XlcGL, init_jis0208tab, jis02082rune, N11n_ja, 0x2222}, + {"JISX0208.1983-0", XlcGR, init_jis0208tab, jis02082rune, N11n_ja, 0x2222}, + {"KSC5601.1987-0", XlcGL, init_ksc5601tab, ksc2rune, N11n_ko, 0x2160}, + {"KSC5601.1987-0", XlcGR, init_ksc5601tab, ksc2rune, N11n_ko, 0x2160}, + {"GB2312.1980-0", XlcGL, init_gb2312tab, gb2rune, N11n_zh, 0x2175}, + {"GB2312.1980-0", XlcGR, init_gb2312tab, gb2rune, N11n_zh, 0x2175}, +}; + + +static void +set_latin_nop(table, default_val) +long *table; +long default_val; +{ + register int i; + for(i = 0; i < 0x1fff; i++) + table[i] = default_val; + return; +} + +static void +set_latin_tab(fptr, table, fb_default) +FILE *fptr; +long *table; +long fb_default; +{ + int i = 0; + int j = 0; + int rv = 0; + long value; + + for(i = 0; i < NRUNE; i++) + table[i] = -1; + while((rv = fscanf(fptr, "%lx", (long unsigned *) &value)) != EOF) { + if(rv != 0 && value >= 0) { + table[value] = j++; + } else { + set_latin_nop(table, fb_default); + return; + } + } +} + +extern int _fallcResolveI18NPath(); +#define TBL_DATA_DIR "tbl_data" + +static void +init_latin1tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp = NULL; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_1); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin2tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_2); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin3tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_3); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin4tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_4); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin5tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_5); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin6tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_6); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin7tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_7); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin8tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_8); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_latin9tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, tab8859_9); + fp = fopen(filename, "r"); + if(fp) { + set_latin_tab(fp, tbl, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_latin_nop(tbl, fb_default); + } +} + +static void +init_jis0201tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + int i; + for(i = 0; i < NRUNE; i++) + tbl[i] = -1; +} + +static void +set_cjk_nop(to_tbl, to_max, default_val) +long **to_tbl; +long default_val; +int to_max; +{ + register int i; + for(i = 0; i < to_max; i++) + (*to_tbl)[i] = default_val; + return; +} + +static void +set_table(fptr, to_tbl, from_tbl, to_max, fb_default) +FILE *fptr; +long **to_tbl, *from_tbl; +int to_max; +long fb_default; +{ + register int i = 0; + int j = 0; + int rv = 0; + long value; + + for(i = 0; i < NRUNE; i++) + from_tbl[i] = -1; + while((rv = fscanf(fptr, "%lx", (long unsigned *) &value)) != EOF) { + if(rv != 0) { + (*to_tbl)[j++] = value; + } else { + set_cjk_nop(to_tbl, to_max, fb_default); + break; + } + } + for(i = 0; i < to_max; i++) { + if((value = (*to_tbl)[i]) != -1){ + from_tbl[abs(value)] = i; + } + } +} + + + +static void +init_jis0208tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + if((tabkuten = (long *)Xmalloc(KUTENMAX * sizeof(long))) == NULL) { + return; + } + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, jis0208); + fp = fopen(filename, "r"); + if(fp) { + set_table(fp, &tabkuten, tbl, KUTENMAX, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_cjk_nop(&tabkuten, KUTENMAX, fb_default); + } +} + +static void +init_ksc5601tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + if((tabksc5601 = (long *)Xmalloc(KSCMAX * sizeof(long))) == NULL) { + return; + } + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, ksc5601); + fp = fopen(filename, "r"); + if(fp) { + set_table(fp, &tabksc5601, tbl, KSCMAX, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_cjk_nop(&tabksc5601, KSCMAX, fb_default); + } +} + +static void +init_gb2312tab(tbl, fb_default) +long *tbl; +long fb_default; +{ + FILE *fp; + char dirname[BUFSIZE]; + char filename[BUFSIZE]; + char *p, *q; + + if((tabgb = (long *)Xmalloc(GBMAX * sizeof(long))) == NULL) { + return; + } + _fallcResolveI18NPath(dirname); + p = dirname; + while(p) { + q = strchr(p, ':'); + if(q) { + *q = '\0'; + } + sprintf(filename, "%s/%s/%s", p, TBL_DATA_DIR, gb2312); + fp = fopen(filename, "r"); + if(fp) { + set_table(fp, &tabgb, tbl, GBMAX, fb_default); + fclose(fp); + return; + } + if(q) { + p = q + 1; + } else { + p = q; + } + } + if(!fp) { + set_cjk_nop(&tabgb, GBMAX, fb_default); + } +} + +static UtfData +make_entry() +{ + UtfData tmp = (UtfData)Xmalloc(sizeof(UtfDataRec)); + bzero(tmp, sizeof(UtfDataRec)); + return tmp; +} + +static int once = 0; +static int +_XlcInitUTFInfo(lcd) +XLCd lcd; +{ + if(!once) { + int i; + CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list); + int codeset_num = XLC_GENERIC(lcd, codeset_num); + UtfData pdata; + + if(!utfdata_list) { + utfdata_list = make_entry(); + } + pdata = utfdata_list; + for(i=0; i < codeset_num; i++) { + XlcCharSet charset = *codeset_list[i]->charset_list; + while(pdata->next) { + if(charset == pdata->charset) { + break; + } + pdata = pdata->next; + } + if(pdata->next) { + continue; + } else { + int j; + for(j = 0; j < MAX_UTF_CHARSET; j++) { + if(_fallcCompareISOLatin1(charset->encoding_name, default_utf_data[j].name) || + charset->side != default_utf_data[j].side) { + continue; + } else { + pdata->initialize = default_utf_data[j].initialize; + pdata->fromtbl = (long *)Xmalloc(NRUNE * sizeof(long)); + (*pdata->initialize)(pdata->fromtbl, default_utf_data[j].fallback_value); + pdata->already_init = True; + pdata->charset = charset; + pdata->cstorune = default_utf_data[j].cstorune; + pdata->type = default_utf_data[j].type; + pdata->next = make_entry(); + break; + } + } + } + } + once = 1; + } + return 1; +} + +static int +utftocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + char **from; + int *from_left; + char **to; + int *to_left; + XPointer *args; + int num_args; +{ + char *utfptr; + char *bufptr; + int utf_len, buf_len; + long l; + XlcCharSet tmpcharset = (XlcCharSet)NULL; + UtfData pdata = utfdata_list; + + if (from == NULL || *from == NULL) + return 0; + + utfptr = *from; + bufptr = *to; + utf_len = *from_left; + buf_len = *to_left; + + while(utf_len > 0 && buf_len > 0) { + char *p = utfptr; + if((l = getutfrune(&p, &utf_len)) == -2) { + return -1; + } else { + while(pdata->next) { + long r; + long *tbl; + + tbl = pdata->fromtbl; + tbl += l; + if((r = *tbl) == -1) { + if(tmpcharset) { + goto end; + } else { + pdata = pdata->next; + continue; + } + } else { + utfptr = p; + if(!tmpcharset) tmpcharset = pdata->charset; + } + if(r < 128) { + *bufptr++ = r; + buf_len--; + } else { + switch(pdata->type) { + case N11n_ja: + *bufptr++ = (r/100 + ' '); + *bufptr++ = (r%100 + ' '); + break; + case N11n_ko: + *bufptr++ = (r/94 + 0x21); + *bufptr++ = (r%94 + 0x21); + break; + case N11n_zh: + *bufptr++ = 0x20 + (r/100); + *bufptr++ = 0x20 + (r%100); + break; + default: + break; + } + buf_len -= 2; + } + break; + } + if(!tmpcharset) return (-1); /* Unknown Codepoint */ + } + } +end: + if((num_args > 0) && tmpcharset) + *((XlcCharSet *) args[0]) = tmpcharset; + + *from_left -= utfptr - *from; + *from = utfptr; + + *to_left -= bufptr - *to; + *to = bufptr; + + return 0; +} + +static int +utf1tocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + char **from; + int *from_left; + char **to; + int *to_left; + XPointer *args; + int num_args; +{ + char **ptr = NULL; + char char_ptr[UTFmax]; + int i = 0; + unsigned long dummy = (unsigned long)0; + + if (from == NULL || *from == NULL) + return utftocs(conv, from, from_left, to, to_left, args, num_args); + + ptr = from; + for(i = 0; i < UTFmax; char_ptr[i++] = *(*ptr)++); + i=0; + while(our_mbtowc(&dummy, (char*)&char_ptr[0], i) <= 0) + i++; + utftocs(conv, from, &i, to, to_left, args, num_args); +} + +static int +ucstocs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + XPointer *from; + int *from_left; + char **to; + int *to_left; + XPointer *args; + int num_args; +{ + wchar_t *ucsptr; + char *bufptr; + int ucs_len, buf_len; + XlcCharSet tmpcharset = (XlcCharSet)NULL; + UtfData pdata = utfdata_list; + + if (from == NULL || *from == NULL) + return 0; + + ucsptr = (wchar_t *)*from; + bufptr = *to; + ucs_len = *from_left; + buf_len = *to_left; + + while(ucs_len > 0 && buf_len > 0) { + while(pdata->next) { + long r; + long *tbl; + + tbl = pdata->fromtbl; + tbl += *ucsptr; + if((r = *tbl) == -1) { + if(tmpcharset) { + goto end; + } else { + pdata = pdata->next; + continue; + } + } else { + if(!tmpcharset) tmpcharset = pdata->charset; + } + ucsptr++; + if(r < 128) { + *bufptr++ = r; + ucs_len--; + buf_len--; + } else { + switch(pdata->type) { + case N11n_ja: + *bufptr++ = (r/100 + ' '); + *bufptr++ = (r%100 + ' '); + break; + case N11n_ko: + *bufptr++ = (r/94 + 0x21); + *bufptr++ = (r%94 + 0x21); + break; + case N11n_zh: + *bufptr++ = 0x20 + (r/100); + *bufptr++ = 0x20 + (r%100); + break; + default: + break; + } + ucs_len--; + buf_len -= 2; + } + break; + } + if(!tmpcharset) return (-1); /* Unknown Codepoint */ + } +end: + if((num_args > 0) && tmpcharset) + *((XlcCharSet *) args[0]) = tmpcharset; + + *from_left -= ucsptr - (wchar_t *)*from; + *from = (XPointer)ucsptr; + + *to_left -= bufptr - *to; + *to = bufptr; + + return 0; +} + +static long +#if NeedFunctionPrototypes +getutfrune(char **read_from, int *from_len) +#else +getutfrune(read_from, from_len) +char **read_from; +int *from_len; +#endif +{ + int c, i; + char str[UTFmax]; /* MB_LEN_MAX really */ + unsigned long l; + int n; + + str[0] = '\0'; + for(i = 0; i <= UTFmax;) { + c = **read_from; + (*read_from)++; + str[i++] = c; + n = our_mbtowc(&l, str, i); + if(n == -1) + return(-2); + if(n > 0) { + *from_len -= n; + return(l); + } + } + return(-2); +} + +static +cstoutf(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + char **from; + int *from_left; + char **to; + int *to_left; + XPointer *args; + int num_args; +{ + XlcCharSet charset; + char *csptr, *utfptr; + int csstr_len, utf_len; + int cmp_len = 0; + void (*putrune)( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif + ) = NULL; + Rune r = (Rune)0; + UtfData pdata = utfdata_list; + + if (from == NULL || *from == NULL) + return 0; + + if (num_args < 1) + return -1; + + csptr = *from; + utfptr = *to; + csstr_len = *from_left; + utf_len = *to_left; + + charset = (XlcCharSet)args[0]; + cmp_len = strchr(charset->name, ':') - charset->name; + while(pdata->next) { + if(!_fallcNCompareISOLatin1(charset->name, pdata->charset->name, cmp_len)) { + putrune = pdata->cstorune; + break; + } else { + pdata = pdata->next; + } + } + if(!putrune) + return -1; + + while(csstr_len-- > 0 && utf_len > 0) { + (*putrune)(*csptr++, &r); + if(!r) { + continue; + } + our_wctomb(r, &utfptr, &utf_len); + r = 0; + } + + *from_left -= csptr - *from; + *from = csptr; + + *to_left -= utfptr - *to; + *to = utfptr; + + return 0; +} + +static +cstoucs(conv, from, from_left, to, to_left, args, num_args) + XlcConv conv; + char **from; + int *from_left; + XPointer *to; + int *to_left; + XPointer *args; + int num_args; +{ + XlcCharSet charset; + char *csptr; + wchar_t *ucsptr; + int csstr_len, ucs_len; + int cmp_len = 0; + void (*putrune)( +#if NeedFunctionPrototypes + unsigned char c, + Rune *r +#endif + ) = NULL; + Rune r = (Rune)0; + UtfData pdata = utfdata_list; + + if (from == NULL || *from == NULL) + return 0; + + if (num_args < 1) + return -1; + + csptr = *from; + ucsptr = (wchar_t *)*to; + csstr_len = *from_left; + ucs_len = *to_left; + charset = (XlcCharSet)args[0]; + cmp_len = strchr(charset->name, ':') - charset->name; + + while(pdata->next) { + if(!_fallcNCompareISOLatin1(charset->name, pdata->charset->name, cmp_len)) { + putrune = pdata->cstorune; + break; + } else { + pdata = pdata->next; + } + } + if(!putrune) + return -1; + + while(csstr_len-- > 0 && ucs_len > 0) { + (*putrune)(*csptr++, &r); + if(!r) { + continue; + } + *ucsptr = (long)r; + ucsptr++; + ucs_len--; + r = 0; + } + + *from_left -= csptr - *from; + *from = csptr; + + *to_left -= ucsptr - (wchar_t *)*to; + *to = (XPointer)ucsptr; + + return 0; +} + +static void +#if NeedFunctionPrototypes +our_wctomb(Rune r, char **utfptr, int *utf_len) +#else +our_wctomb(r, utfptr, utf_len) +Rune r; +char **utfptr; +int *utf_len; +#endif +{ + long l = (long)r; + + if(!utfptr || !*utfptr) + return; /* no shift states */ + if(l & ~Wchar2) { + if(l & ~Wchar4) { + if(l & ~Wchar5) { + /* 6 bytes */ + *(*utfptr)++ = T6 | ((l >> 5*Bitx) & Mask6); + *(*utfptr)++ = Tx | ((l >> 4*Bitx) & Maskx); + *(*utfptr)++ = Tx | ((l >> 3*Bitx) & Maskx); + *(*utfptr)++ = Tx | ((l >> 2*Bitx) & Maskx); + *(*utfptr)++ = Tx | ((l >> 1*Bitx) & Maskx); + *(*utfptr)++ = Tx | (l & Maskx); + *utf_len -= 6; + return; + } + /* 5 bytes */ + *(*utfptr)++ = T5 | (l >> 4*Bitx); + *(*utfptr)++ = Tx | ((l >> 3*Bitx) & Maskx); + *(*utfptr)++ = Tx | ((l >> 2*Bitx) & Maskx); + *(*utfptr)++ = Tx | ((l >> 1*Bitx) & Maskx); + *(*utfptr)++ = Tx | (l & Maskx); + *utf_len -= 5; + return; + } + if(l & ~Wchar3) { + /* 4 bytes */ + *(*utfptr)++ = T4 | (l >> 3*Bitx); + *(*utfptr)++ = Tx | ((l >> 2*Bitx) & Maskx); + *(*utfptr)++ = Tx | ((l >> 1*Bitx) & Maskx); + *(*utfptr)++ = Tx | (l & Maskx); + *utf_len -= 4; + return; + } + /* 3 bytes */ + *(*utfptr)++ = T3 | (l >> 2*Bitx); + *(*utfptr)++ = Tx | ((l >> 1*Bitx) & Maskx); + *(*utfptr)++ = Tx | (l & Maskx); + *utf_len -= 3; + return; + } + if(l & ~Wchar1) { + /* 2 bytes */ + *(*utfptr)++ = T2 | (l >> 1*Bitx); + *(*utfptr)++ = Tx | (l & Maskx); + *utf_len -= 2; + return; + } + /* 1 byte */ + *(*utfptr)++ = T1 | l; + *utf_len -= 1; + return; +} + +static void +#if NeedFunctionPrototypes +latin2rune(unsigned char c, Rune *r) +#else +latin2rune(c, r) +unsigned char c; +Rune *r; +#endif +{ + *r = (Rune)c; + return; +} + +static void +#if NeedFunctionPrototypes +ksc2rune(unsigned char c, Rune *r) +#else +ksc2rune(c, r) +unsigned char c; +Rune *r; +#endif +{ + static enum { init, cs1last} state = init; + static int korean646 = 1; /* fixed to 1 for now. */ + static int lastc; + unsigned char ch = (c|0x80); /* XXX */ + int n; + long l; + + switch(state) + { + case init: + if (ch < 128){ + if(korean646 && (ch=='\\')){ + emit(0x20A9); + } else { + emit(ch); + } + }else{ + lastc = ch; + state = cs1last; + } + return; + + case cs1last: /* 2nd byte of codeset 1 (KSC 5601) */ + n = ((lastc&0x7f)-33)*94 + (ch&0x7f)-33; + if((l = tabksc5601[n]) == 0){ + emit(BADMAP); + } else { + emit(l); + } + state = init; + return; + } +} + +static void +#if NeedFunctionPrototypes +jis02012rune(unsigned char c, Rune *r) +#else +jis02012rune(c, r) +unsigned char c; +Rune *r; +#endif +{ +/* To Be Implemented */ +} + +static void +#if NeedFunctionPrototypes +gb2rune(unsigned char c, Rune *r) +#else +gb2rune(c, r) +unsigned char c; +Rune *r; +#endif +{ + static enum { state0, state1 } state = state0; + static int lastc; + long n, ch; + unsigned char ch1 = (c|0x80); /* XXX */ + +again: + switch(state) + { + case state0: /* idle state */ + if(ch1 >= 0xA1){ + lastc = ch1; + state = state1; + return; + } + emit(ch1); + return; + + case state1: /* seen a font spec */ + if(ch1 >= 0xA1) + n = (lastc-0xA0)*100 + (ch1-0xA0); + else { + emit(BADMAP); + state = state0; + return; + } + ch = tabgb[n]; + if(ch < 0){ + emit(BADMAP); + } else + emit(ch); + state = state0; + } +} + +static void +#if NeedFunctionPrototypes +jis02082rune(unsigned char c, Rune *r) +#else +jis02082rune(c, r) +unsigned char c; +Rune *r; +#endif +{ + static enum { state0, state1} state = state0; + static int lastc; + unsigned char ch = (c|0x80); /* XXX */ + int n; + long l; + +again: + switch(state) + { + case state0: /* idle state */ + lastc = ch; + state = state1; + return; + + case state1: /* two part char */ + if((lastc&0x80) != (ch&0x80)){ + emit(lastc); + state = state0; + goto again; + } + if(CANS2J(lastc, ch)){ + int h = lastc, l = ch; + S2J(h, l); + n = h*100 + l - 3232; + } else + n = (lastc&0x7F)*100 + (ch&0x7f) - 3232; /* kuten */ + if((l = tabkuten[n]) == -1){ + emit(BADMAP); + } else { + if(l < 0){ + l = -l; + } + emit(l); + } + state = state0; + } +} + +static int +#if NeedFunctionPrototypes +our_mbtowc(unsigned long *p, char *s, size_t n) +#else +our_mbtowc(p, s, n) +unsigned long *p; +char *s; +size_t n; +#endif +{ + unsigned char *us; + int c0, c1, c2, c3, c4, c5; + unsigned long wc; + + if(s == 0) + return 0; /* no shift states */ + + if(n < 1) + goto badlen; + us = (unsigned char*)s; + c0 = us[0]; + if(c0 >= T3) { + if(n < 3) + goto badlen; + c1 = us[1] ^ Tx; + c2 = us[2] ^ Tx; + if((c1|c2) & T2) { + goto bad; + } + if(c0 >= T5) { + if(n < 5) + goto badlen; + c3 = us[3] ^ Tx; + c4 = us[4] ^ Tx; + if((c3|c4) & T2) { + goto bad; + } + if(c0 >= T6) { + /* 6 bytes */ + if(n < 6) + goto badlen; + c5 = us[5] ^ Tx; + if(c5 & T2) { + goto bad; + } + wc = ((((((((((c0 & Mask6) << Bitx) | + c1) << Bitx) | c2) << Bitx) | + c3) << Bitx) | c4) << Bitx) | c5; + if(wc <= Wchar5) { + goto bad; + } + *p = wc; + return 6; + } + /* 5 bytes */ + wc = ((((((((c0 & Mask5) << Bitx) | + c1) << Bitx) | c2) << Bitx) | + c3) << Bitx) | c4; + if(wc <= Wchar4) { + goto bad; + } + *p = wc; + return 5; + } + if(c0 >= T4) { + /* 4 bytes */ + if(n < 4) + goto badlen; + c3 = us[3] ^ Tx; + if(c3 & T2) { + goto bad; + } + wc = ((((((c0 & Mask4) << Bitx) | + c1) << Bitx) | c2) << Bitx) | + c3; + if(wc <= Wchar3) { + goto bad; + } + *p = wc; + return 4; + } + /* 3 bytes */ + wc = ((((c0 & Mask3) << Bitx) | + c1) << Bitx) | c2; + if(wc <= Wchar2) { + goto bad; + } + *p = wc; + return 3; + } + if(c0 >= T2) { + /* 2 bytes */ + if(n < 2) + goto badlen; + c1 = us[1] ^ Tx; + if(c1 & T2) { + goto bad; + } + wc = ((c0 & Mask2) << Bitx) | + c1; + if(wc <= Wchar1) { + goto bad; + } + *p = wc; + return 2; + } + /* 1 byte */ + if(c0 >= Tx) { + goto bad; + } + *p = c0; + return 1; + +bad: + errno = EILSEQ; + return -1; +badlen: + return -2; +} + +static void +close_converter(conv) + XlcConv conv; +{ + Xfree((char *) conv); +} + +static XlcConv +create_conv(lcd, methods) + XLCd lcd; + XlcConvMethods methods; +{ + XlcConv conv; + + conv = (XlcConv) Xmalloc(sizeof(XlcConvRec)); + if (conv == (XlcConv) NULL) + return (XlcConv) NULL; + + conv->methods = methods; + + conv->state = NULL; + _XlcInitUTFInfo(lcd); + + return conv; + +err: + close_converter(conv); + + return (XlcConv) NULL; +} + +static XlcConvMethodsRec mbtocs_methods = { + close_converter, + utf1tocs, + NULL +}; + +static XlcConv +open_mbtocs(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + return create_conv(from_lcd, &mbtocs_methods); +} + +static XlcConvMethodsRec mbstocs_methods = { + close_converter, + utftocs, + NULL +}; + +static XlcConv +open_mbstocs(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + return create_conv(from_lcd, &mbstocs_methods); +} + +static XlcConvMethodsRec wcstocs_methods = { + close_converter, + ucstocs, + NULL +}; + +static XlcConv +open_wcstocs(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + return create_conv(from_lcd, &wcstocs_methods); +} + +static XlcConvMethodsRec cstombs_methods = { + close_converter, + cstoutf, + NULL +}; + +static XlcConv +open_cstombs(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + return create_conv(from_lcd, &cstombs_methods); +} + +static XlcConvMethodsRec cstowcs_methods = { + close_converter, + cstoucs, + NULL +}; + +static XlcConv +open_cstowcs(from_lcd, from, to_lcd, to) + XLCd from_lcd; + char *from; + XLCd to_lcd; + char *to; +{ + return create_conv(from_lcd, &cstowcs_methods); +} + + +XLCd +_fallcUtfLoader(name) + char *name; +{ + XLCd lcd; + + lcd = _fallcCreateLC(name, _fallcGenericMethods); + if (lcd == (XLCd) NULL) + return lcd; + + if ((_fallcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "utf"))) { + _fallcDestroyLC(lcd); + return (XLCd) NULL; + } + + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs); + _fallcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs); + + _fallcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs); + + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs); + _fallcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs); + + return lcd; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcUTF.h b/cde/programs/dtudcfonted/libfal/_fallcUTF.h new file mode 100644 index 00000000..853de961 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcUTF.h @@ -0,0 +1,195 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* XlcUTF.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:06 */ +/* $XConsortium: _fallcUTF.h /main/1 1996/04/08 15:19:33 cde-fuj $ */ +/****************************************************************** + + Copyright 1993 by SunSoft, Inc. + +Permission to use, copy, modify, distribute, and sell this software +and its documentation for any purpose is hereby granted without fee, +provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear +in supporting documentation, and that the name of SunSoft, Inc. +not be used in advertising or publicity pertaining to distribution +of the software without specific, written prior permission. +SunSoft, Inc. makes no representations about the suitability of +this software for any purpose. It is provided "as is" without +express or implied warranty. + +SunSoft Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, +IN NO EVENT SHALL SunSoft, Inc. BE LIABLE FOR ANY SPECIAL, INDIRECT +OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE +OR PERFORMANCE OF THIS SOFTWARE. + + Author: Hiromu Inukai (inukai@Japan.Sun.COM) SunSoft, inc. + +******************************************************************/ +#include "_fallibint.h" +#include "_fallcGeneric.h" +#include +#include + +typedef unsigned short Rune; /* 16 bits */ +#define Runeerror 0x80 /* decoding error in UTF */ +#define Runeself 0x80 /* rune and UTF sequences are the same (<) */ +#define UTFmax 3 /* maximum bytes per rune */ + +#define BADMAP (0xFFFD) +#define ESC 033 +#define NRUNE 65536 +#define NLATIN 0x6ff +#define LATINMAX 256 +#define KUTENMAX 8407 +#define KSCMAX 8743 +#define GBMAX 8795 +#define tab8859_1 "tab8859_1" +#define tab8859_2 "tab8859_2" +#define tab8859_3 "tab8859_3" +#define tab8859_4 "tab8859_4" +#define tab8859_5 "tab8859_5" +#define tab8859_6 "tab8859_6" +#define tab8859_7 "tab8859_7" +#define tab8859_8 "tab8859_8" +#define tab8859_9 "tab8859_9" +#define jis0208 "jis0208" +#define ksc5601 "ksc5601" +#define gb2312 "gb2312" + +#define emit(x) *r = (Rune)x; + +typedef enum { + N11n_none, /* No need to normalize (1byte) */ + N11n_ja, /* Normalize for ja */ + N11n_ko, /* Normalize for ko */ + N11n_zh /* Normalize for zh */ +} NormalizeType; + +typedef struct _UtfDataRec { + XlcCharSet charset; + void (*initialize)( /* Table Initializer */ +#if NeedNestedPrototypes + long *tbl, + long fallback +#endif + ); + long *fromtbl; /* UTF -> CharSet */ + NormalizeType type; /* Normalize type */ + void (*cstorune)( /* CharSet -> UTF */ +#if NeedNestedPrototypes + unsigned char c, + Rune *r +#endif + ); + Bool already_init; + struct _UtfDataRec *next; /* next entry */ +} UtfDataRec, *UtfData; + +typedef struct _XlcUTFDataRec { + char *name; + XlcSide side; + void (*initialize)(); + void (*cstorune)( +#if NeedNestedPrototypes + unsigned char c, + Rune *r +#endif + ); + NormalizeType type; + long fallback_value; +} XlcUTFDataRec, *XlcUTFData; + +typedef struct _StateRec { + XlcCharSet charset; + XlcCharSet GL_charset; + XlcCharSet GR_charset; +} StateRec, *State; + +#define MAX_UTF_CHARSET (sizeof(default_utf_data)/sizeof(XlcUTFDataRec)) + +#define Char1 Runeself +#define Rune1 Runeself +#define Char21 0xA1 +#define Rune21 0x0100 +#define Char22 0xF6 +#define Rune22 0x4016 +#define Char3 0xFC +#define Rune3 0x10000 /* really 0x38E2E */ +#define Esc 0xBE +#define Bad Runeerror + +#define T1 0x00 +#define Tx 0x80 +#define T2 0xC0 +#define T3 0xE0 +#define T4 0xF0 +#define T5 0xF8 +#define T6 0xFC + +#define Bit1 7 +#define Bitx 6 +#define Bit2 5 +#define Bit3 4 +#define Bit4 3 +#define Bit5 2 +#define Bit6 2 + +#define Mask1 (1<> 40-9d,9e-fb >> 40-7e,(skip 7f),80-fc */ \ + if (((_l) += (((_h)-- % 2) ? 0x1f : 0x7d)) > 0x7e) (_l)++; \ + /* upper: 21-7e >> 81-af >> 81-9f,(skip a0-df),e0-ef */ \ + if (((_h) = ((_h) / 2 + 0x71)) > 0x9f) (_h) += 0x40; \ +} +#define S2J(_h, _l) { \ + /* lower: 40-7e,80-fc >> 21-5f,61-dd >> 21-7e,7f-dc */ \ + if (((_l) -= 0x1f) > 0x60) (_l)--; \ + /* upper: 81-9f,e0-ef >> 00-1e,5f-6e >> 00-2e >> 21-7d */ \ + if (((_h) -= 0x81) > 0x5e) (_h) -= 0x40; (_h) *= 2, (_h) += 0x21; \ + /* upper: ,21-7d >> ,22-7e ; lower: ,7f-dc >> ,21-7e */ \ + if ((_l) > 0x7e) (_h)++, (_l) -= 0x5e; \ +} +#define ISJKANA(_b) (0xa0 <= (_b) && (_b) < 0xe0) +#define CANS2JH(_h) ((0x81 <= (_h) && (_h) < 0xf0) && !ISJKANA(_h)) +#define CANS2JL(_l) (0x40 <= (_l) && (_l) < 0xfd && (_l) != 0x7f) +#define CANS2J(_h, _l) (CANS2JH(_h) && CANS2JL(_l)) diff --git a/cde/programs/dtudcfonted/libfal/_fallcUtil.c b/cde/programs/dtudcfonted/libfal/_fallcUtil.c new file mode 100644 index 00000000..6c67134c --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcUtil.c @@ -0,0 +1,101 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcUtil.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:42 */ +/* $XConsortium: _fallcUtil.c /main/1 1996/04/08 15:19:43 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ + +#include +#include +#include +#include "_fallibint.h" + +#ifdef X_NOT_STDC_ENV +#ifndef toupper +#define toupper(c) ((int)(c) - 'a' + 'A') +#endif +#endif + +int +_fallcCompareISOLatin1(str1, str2) + char *str1, *str2; +{ + register char ch1, ch2; + + for ( ; (ch1 = *str1) && (ch2 = *str2); str1++, str2++) { + if (islower(ch1)) + ch1 = toupper(ch1); + if (islower(ch2)) + ch2 = toupper(ch2); + + if (ch1 != ch2) + break; + } + + return *str1 - *str2; +} + +int +_fallcNCompareISOLatin1(str1, str2, len) + char *str1, *str2; + int len; +{ + register char ch1, ch2; + + for ( ; (ch1 = *str1) && (ch2 = *str2) && len; str1++, str2++, len--) { + if (islower(ch1)) + ch1 = toupper(ch1); + if (islower(ch2)) + ch2 = toupper(ch2); + + if (ch1 != ch2) + break; + } + + if (len == 0) + return 0; + + return *str1 - *str2; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcWrap.c b/cde/programs/dtudcfonted/libfal/_fallcWrap.c new file mode 100644 index 00000000..fd6ef9cb --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcWrap.c @@ -0,0 +1,637 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* lcWrap.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:42 */ +/* $XConsortium: _fallcWrap.c /main/1 1996/04/08 15:19:54 cde-fuj $ */ +/* + +Copyright (c) 1991 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ +/* + * Copyright 1991 by the Open Software Foundation + * Copyright 1993 by the TOSHIBA Corp. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of Open Software Foundation and TOSHIBA + * not be used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. Open Software + * Foundation and TOSHIBA make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * OPEN SOFTWARE FOUNDATION AND TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL OPEN SOFTWARE FOUNDATIONN OR TOSHIBA BE + * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * M. Collins OSF + * + * Katsuhisa Yano TOSHIBA Corp. + */ + +#include +#include "_fallibint.h" +#include "_fallcint.h" +#if defined(__linux__) +#include +#else +#include +#endif +#include +#ifdef WIN32 +#undef close +#endif +#include "_falutil.h" + +#ifdef __STDC__ +#define Const const +#else +#define Const /**/ +#endif + +#ifdef X_NOT_STDC_ENV +extern char *getenv(); +#endif + +extern void _fallcInitLoader( +#if NeedFunctionPrototypes + void +#endif +); + +#ifdef XTHREADS +LockInfoPtr _Xi18n_lock; +#endif + +#if NeedFunctionPrototypes +char * +falSetLocaleModifiers( + _Xconst char *modifiers +) +#else +char * +falSetLocaleModifiers(modifiers) + char *modifiers; +#endif +{ + XLCd lcd = _fallcCurrentLC(); + char *user_mods; + + if (!lcd) + return (char *) NULL; + if (!modifiers) + return lcd->core->modifiers; + user_mods = getenv("XMODIFIERS"); + modifiers = (*lcd->methods->map_modifiers) (lcd, + user_mods, (char *)modifiers); + if (modifiers) { + if (lcd->core->modifiers) + Xfree(lcd->core->modifiers); + lcd->core->modifiers = (char *)modifiers; + } + return (char *)modifiers; +} + +Bool +falSupportsLocale() +{ + return _fallcCurrentLC() != (XLCd)NULL; +} + +Bool _fallcValidModSyntax(mods, valid_mods) + char *mods; + char **valid_mods; +{ + int i; + char **ptr; + + while (mods && (*mods == '@')) { + mods++; + if (*mods == '@') + break; + for (ptr = valid_mods; *ptr; ptr++) { + i = strlen(*ptr); + if (strncmp(mods, *ptr, i) || ((mods[i] != '=') +#ifdef WIN32 + && (mods[i] != '#') +#endif + )) + continue; + mods = strchr(mods+i+1, '@'); + break; + } + } + return !mods || !*mods; +} + +static Const char *im_valid[] = {"im", (char *)NULL}; + +/*ARGSUSED*/ +char * +_fallcDefaultMapModifiers (lcd, user_mods, prog_mods) + XLCd lcd; + char *user_mods; + char *prog_mods; +{ + int i; + char *mods; + + if (!_fallcValidModSyntax(prog_mods, (char **)im_valid)) + return (char *)NULL; + if (!_fallcValidModSyntax(user_mods, (char **)im_valid)) + return (char *)NULL; + i = strlen(prog_mods) + 1; + if (user_mods) + i += strlen(user_mods); + mods = Xmalloc(i); + if (mods) { + strcpy(mods, prog_mods); + if (user_mods) + strcat(mods, user_mods); +#ifdef WIN32 + { + char *s; + for (s = mods; s = strchr(s, '@'); s++) { + for (s++; *s && *s != '='; s++) { + if (*s == '#') { + *s = '='; + break; + } + } + } + } +#endif + } + return mods; +} + +typedef struct _XLCdListRec { + struct _XLCdListRec *next; + XLCd lcd; + int ref_count; +} XLCdListRec, *XLCdList; + +static XLCdList lcd_list = NULL; + +typedef struct _XlcLoaderListRec { + struct _XlcLoaderListRec *next; + XLCdLoadProc proc; +} XlcLoaderListRec, *XlcLoaderList; + +static XlcLoaderList loader_list = NULL; + +void +_fallcRemoveLoader(proc) + XLCdLoadProc proc; +{ + XlcLoaderList loader, prev; + + if (loader_list == NULL) + return; + + prev = loader = loader_list; + if (loader->proc == proc) { + loader_list = loader->next; + Xfree(loader); + return; + } + + while (loader = loader->next) { + if (loader->proc == proc) { + prev->next = loader->next; + Xfree(loader); + return; + } + prev = loader; + } + + return; +} + +Bool +_fallcAddLoader(proc, position) + XLCdLoadProc proc; + XlcPosition position; +{ + XlcLoaderList loader, last; + + _fallcRemoveLoader(proc); /* remove old loader, if exist */ + + loader = (XlcLoaderList) Xmalloc(sizeof(XlcLoaderListRec)); + if (loader == NULL) + return False; + + loader->proc = proc; + + if (loader_list == NULL) + position = XlcHead; + + if (position == XlcHead) { + loader->next = loader_list; + loader_list = loader; + } else { + last = loader_list; + while (last->next) + last = last->next; + + loader->next = NULL; + last->next = loader; + } + + return True; +} + +XLCd +_falOpenLC(name) + char *name; +{ + XLCd lcd; + XlcLoaderList loader; + XLCdList cur; +#if !defined(X_NOT_STDC_ENV) && !defined(X_LOCALE) + char siname[256]; + char *_fallcMapOSLocaleName(); +#endif + + if (name == NULL) { + name = setlocale (LC_CTYPE, (char *)NULL); +#if !defined(X_NOT_STDC_ENV) && !defined(X_LOCALE) + name = _fallcMapOSLocaleName (name, siname); +#endif + } + + _XLockMutex(_Xi18n_lock); + + /* + * search for needed lcd, if found return it + */ + for (cur = lcd_list; cur; cur = cur->next) { + if (!strcmp (cur->lcd->core->name, name)) { + lcd = cur->lcd; + cur->ref_count++; + goto found; + } + } + + if (!loader_list) + _fallcInitLoader(); + + /* + * not there, so try to get and add to list + */ + for (loader = loader_list; loader; loader = loader->next) { + lcd = (*loader->proc)(name); + if (lcd) { + cur = (XLCdList) Xmalloc (sizeof(XLCdListRec)); + if (cur) { + cur->lcd = lcd; + cur->ref_count = 1; + cur->next = lcd_list; + lcd_list = cur; + } else { + (*lcd->methods->close)(lcd); + lcd = (XLCd) NULL; + } + break; + } + } + +found: + _XUnlockMutex(_Xi18n_lock); + return lcd; +} + +void +_falCloseLC(lcd) + XLCd lcd; +{ + XLCdList cur, *prev; + + for (prev = &lcd_list; cur = *prev; prev = &cur->next) { + if (cur->lcd == lcd) { + if (--cur->ref_count < 1) { + (*lcd->methods->close)(lcd); + *prev = cur->next; + Xfree(cur); + } + break; + } + } +} + +/* + * Get the XLCd for the current locale + */ + +XLCd +_fallcCurrentLC() +{ + XLCd lcd; + static XLCd last_lcd = NULL; + + lcd = _falOpenLC((char *) NULL); + + if (last_lcd) + _falCloseLC(last_lcd); + + last_lcd = lcd; + + return lcd; +} + +XrmMethods +_falrmInitParseInfo(state) + XPointer *state; +{ + XLCd lcd = _falOpenLC((char *) NULL); + + if (lcd == (XLCd) NULL) + return (XrmMethods) NULL; + + return (*lcd->methods->init_parse_info)(lcd, state); +} + +int +falmbTextPropertyToTextList(dpy, text_prop, list_ret, count_ret) + Display *dpy; + XTextProperty *text_prop; + char ***list_ret; + int *count_ret; +{ + XLCd lcd = _fallcCurrentLC(); + + if (lcd == NULL) + return XLocaleNotSupported; + + return (*lcd->methods->mb_text_prop_to_list)(lcd, dpy, text_prop, list_ret, + count_ret); +} + +int +falwcTextPropertyToTextList(dpy, text_prop, list_ret, count_ret) + Display *dpy; + XTextProperty *text_prop; + wchar_t ***list_ret; + int *count_ret; +{ + XLCd lcd = _fallcCurrentLC(); + + if (lcd == NULL) + return XLocaleNotSupported; + + return (*lcd->methods->wc_text_prop_to_list)(lcd, dpy, text_prop, list_ret, + count_ret); +} + +int +falmbTextListToTextProperty(dpy, list, count, style, text_prop) + Display *dpy; + char **list; + int count; + XICCEncodingStyle style; + XTextProperty *text_prop; +{ + XLCd lcd = _fallcCurrentLC(); + + if (lcd == NULL) + return XLocaleNotSupported; + + return (*lcd->methods->mb_text_list_to_prop)(lcd, dpy, list, count, style, + text_prop); +} + +int +falwcTextListToTextProperty(dpy, list, count, style, text_prop) + Display *dpy; + wchar_t **list; + int count; + XICCEncodingStyle style; + XTextProperty *text_prop; +{ + XLCd lcd = _fallcCurrentLC(); + + if (lcd == NULL) + return XLocaleNotSupported; + + return (*lcd->methods->wc_text_list_to_prop)(lcd, dpy, list, count, style, + text_prop); +} + +void +falwcFreeStringList(list) + wchar_t **list; +{ + XLCd lcd = _fallcCurrentLC(); + + if (lcd == NULL) + return; + + (*lcd->methods->wc_free_string_list)(lcd, list); +} + +char * +falDefaultString() +{ + XLCd lcd = _fallcCurrentLC(); + + if (lcd == NULL) + return (char *) NULL; + + return (*lcd->methods->default_string)(lcd); +} + +void +_fallcCopyFromArg(src, dst, size) + char *src; + register char *dst; + register int size; +{ + if (size == sizeof(long)) + *((long *) dst) = (long) src; +#ifdef LONG64 + else if (size == sizeof(int)) + *((int *) dst) = (int) (intptr_t) src; +#endif + else if (size == sizeof(short)) + *((short *) dst) = (short) (intptr_t) src; + else if (size == sizeof(char)) + *((char *) dst) = (char) (intptr_t) src; + else if (size == sizeof(XPointer)) + *((XPointer *) dst) = (XPointer) src; + else if (size > sizeof(XPointer)) + memcpy(dst, (char *) src, size); + else + memcpy(dst, (char *) &src, size); +} + +void +_fallcCopyToArg(src, dst, size) + register char *src; + register char **dst; + register int size; +{ + if (size == sizeof(long)) + *((long *) *dst) = *((long *) src); + else if (size == sizeof(short)) + *((short *) *dst) = *((short *) src); + else if (size == sizeof(char)) + *((char *) *dst) = *((char *) src); + else if (size == sizeof(XPointer)) + *((XPointer *) *dst) = *((XPointer *) src); + else + memcpy(*dst, src, size); +} + +void +_fallcCountVaList(var, count_ret) + va_list var; + int *count_ret; +{ + register int count; + + for (count = 0; va_arg(var, char *); count++) + va_arg(var, XPointer); + + *count_ret = count; +} + +void +_fallcVaToArgList(var, count, args_ret) + va_list var; + register int count; + XlcArgList *args_ret; +{ + register XlcArgList args; + + *args_ret = args = (XlcArgList) Xmalloc(sizeof(XlcArg) * count); + if (args == (XlcArgList) NULL) + return; + + for ( ; count-- > 0; args++) { + args->name = va_arg(var, char *); + args->value = va_arg(var, XPointer); + } +} + +void +_fallcCompileResourceList(resources, num_resources) + register XlcResourceList resources; + register int num_resources; +{ + for ( ; num_resources-- > 0; resources++) + resources->xrm_name = falrmPermStringToQuark(resources->name); +} + +char * +_fallcGetValues(base, resources, num_resources, args, num_args, mask) + XPointer base; + XlcResourceList resources; + int num_resources; + XlcArgList args; + int num_args; + unsigned long mask; +{ + XlcResourceList res; + XrmQuark xrm_name; + int count; + + for ( ; num_args-- > 0; args++) { + res = resources; + count = num_resources; + xrm_name = falrmPermStringToQuark(args->name); + + for ( ; count-- > 0; res++) { + if (xrm_name == res->xrm_name && (mask & res->mask)) { + _fallcCopyToArg(base + res->offset, &args->value, res->size); + break; + } + } + + if (count < 0) + return args->name; + } + + return NULL; +} + +char * +_fallcSetValues(base, resources, num_resources, args, num_args, mask) + XPointer base; + XlcResourceList resources; + int num_resources; + XlcArgList args; + int num_args; + unsigned long mask; +{ + XlcResourceList res; + XrmQuark xrm_name; + int count; + + for ( ; num_args-- > 0; args++) { + res = resources; + count = num_resources; + xrm_name = falrmPermStringToQuark(args->name); + + for ( ; count-- > 0; res++) { + if (xrm_name == res->xrm_name && (mask & res->mask)) { + _fallcCopyFromArg(args->value, base + res->offset, res->size); + break; + } + } + + if (count < 0) + return args->name; + } + + return NULL; +} diff --git a/cde/programs/dtudcfonted/libfal/_fallcint.h b/cde/programs/dtudcfonted/libfal/_fallcint.h new file mode 100644 index 00000000..a1260128 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallcint.h @@ -0,0 +1,1034 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* Xlcint.h 1.4 - Fujitsu source for CDEnext 95/12/07 10:53:09 */ +/* $XConsortium: _fallcint.h /main/1 1996/04/08 15:20:05 cde-fuj $ */ +/* + +Copyright (c) 1991 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +/* + * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, + * and Nippon Telegraph and Telephone Corporation + * Copyright 1991 by the Open Software Foundation + * Copyright 1993 by the TOSHIBA Corp. + * Copyright 1993, 1994 by Sony Corporation + * Copyright 1993, 1994 by the FUJITSU LIMITED + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of OMRON, NTT Software, NTT, Open + * Software Foundation, and Sony Corporation not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. OMRON, NTT Software, NTT, Open Software + * Foundation, and Sony Corporation make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * OMRON, NTT SOFTWARE, NTT, OPEN SOFTWARE FOUNDATION, AND SONY + * CORPORATION DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT + * SHALL OMRON, NTT SOFTWARE, NTT, OPEN SOFTWARE FOUNDATION, OR SONY + * CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: Li Yuhong OMRON Corporation + * Tatsuya Kato NTT Software Corporation + * Hiroshi Kuribayashi OMRON Coproration + * Muneiyoshi Suzuki Nippon Telegraph and Telephone Co. + * + * M. Collins OSF + * Katsuhisa Yano TOSHIBA Corp. + * Makoto Wakamatsu Sony Corporation + * Takashi Fujiwara FUJITSU LIMITED + */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#ifndef _XLCINT_H_ +#define _XLCINT_H_ + +#include +#include "_falutil.h" +#include "_falvarargs.h" + +typedef Bool (*XFilterEventProc)( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* window */, + XEvent* /* event */, + XPointer /* client_data */ +#endif +); + +typedef struct _XIMFilter { + struct _XIMFilter *next; + Window window; + unsigned long event_mask; + int start_type, end_type; + XFilterEventProc filter; + XPointer client_data; +} XFilterEventRec, *XFilterEventList; + +typedef struct { + char *name; + XPointer value; +} XIMArg; + +#ifdef offsetof +#define XOffsetOf(s_type,field) offsetof(s_type,field) +#else +#define XOffsetOf(s_type,field) ((unsigned int)&(((s_type*)NULL)->field)) +#endif + +#define XIMNumber(arr) ((unsigned int) (sizeof(arr) / sizeof(arr[0]))) + +/* + * define secondary data structs which are part of Input Methods + * and Input Context + */ +typedef struct { + char *resource_name; /* Resource string */ + XrmQuark xrm_name; /* Resource name quark */ + int resource_size; /* Size in bytes of data */ + long resource_offset; /* Offset from base */ + unsigned short mode; /* Read Write Permission */ + unsigned short id; /* Input Method Protocol */ +} XIMResource, *XIMResourceList; + +/* + * data block describing the visual attributes associated with + * an input context + */ +typedef struct { + XRectangle area; + XRectangle area_needed; + XPoint spot_location; + Colormap colormap; + Atom std_colormap; + unsigned long foreground; + unsigned long background; + Pixmap background_pixmap; + XFontSet fontset; + int line_spacing; + Cursor cursor; + XIMCallback start_callback; + XIMCallback done_callback; + XIMCallback draw_callback; + XIMCallback caret_callback; + XIMPreeditState preedit_state; + XIMCallback state_notify_callback; +} ICPreeditAttributes, *ICPreeditAttributesPtr; + +typedef struct { + XRectangle area; + XRectangle area_needed; + Colormap colormap; + Atom std_colormap; + unsigned long foreground; + unsigned long background; + Pixmap background_pixmap; + XFontSet fontset; + int line_spacing; + Cursor cursor; + XIMCallback start_callback; + XIMCallback done_callback; + XIMCallback draw_callback; +} ICStatusAttributes, *ICStatusAttributesPtr; + +/* + * Methods for Xrm parsing + */ + +typedef void (*XmbInitProc)( +#if NeedFunctionPrototypes + XPointer /* state */ +#endif +); + +typedef char (*XmbCharProc)( +#if NeedFunctionPrototypes + XPointer /* state */, + char* /* str */, + int* /* lenp */ +#endif +); + +typedef void (*XmbFinishProc)( +#if NeedFunctionPrototypes + XPointer /* state */ +#endif +); + +typedef char* (*XlcNameProc)( +#if NeedFunctionPrototypes + XPointer /* state */ +#endif +); + +typedef void (*XrmDestroyProc)( +#if NeedFunctionPrototypes + XPointer /* state */ +#endif +); + +typedef struct { + XmbInitProc mbinit; + XmbCharProc mbchar; + XmbFinishProc mbfinish; + XlcNameProc lcname; + XrmDestroyProc destroy; +} XrmMethodsRec, *XrmMethods; + +typedef struct _XLCd *XLCd; /* need forward reference */ + +/* + * define an LC, it's methods, and data. + */ + +typedef void (*XCloseLCProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +typedef char* (*XlcMapModifiersProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + char* /* user_mods */, + char* /* prog_mods */ +#endif +); + +typedef XOM (*XOpenOMProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + XrmDatabase /* rdb */, + _Xconst char* /* res_name */, + _Xconst char* /* res_class */ +#endif +); + +typedef XIM (*XOpenIMProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + XrmDatabase /* rdb */, + char* /* res_name */, + char* /* res_class */ +#endif +); + +typedef Bool (*XRegisterIMInstantiateCBProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + XrmDatabase /* rdb */, + char* /* res_name */, + char* /* res_class */, + XIMProc /* callback */, + XPointer* /* client_data */ +#endif +); + +typedef Bool (*XUnregisterIMInstantiateCBProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + XrmDatabase /* rdb */, + char* /* res_name */, + char* /* res_class */, + XIMProc /* callback */, + XPointer* /* client_data */ +#endif +); + +typedef XrmMethods (*XrmInitParseInfoProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + XPointer* /* state */ +#endif +); + +typedef int (*falmbTextPropertyToTextListProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + XTextProperty* /* text_prop */, + char*** /* list_return */, + int* /* count_return */ +#endif +); + +typedef int (*falwcTextPropertyToTextListProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + XTextProperty* /* text_prop */, + wchar_t*** /* list_return */, + int* /* count_return */ +#endif +); + +typedef int (*falmbTextListToTextPropertyProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + char** /* list */, + int /* count */, + XICCEncodingStyle /* style */, + XTextProperty* /* text_prop_return */ +#endif +); + +typedef int (*falwcTextListToTextPropertyProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* display */, + wchar_t** /* list */, + int /* count */, + XICCEncodingStyle /* style */, + XTextProperty* /* text_prop_return */ +#endif +); + +typedef void (*falwcFreeStringListProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */, + wchar_t** /* list */ +#endif +); + +typedef char* (*falDefaultStringProc)( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +typedef struct { + XCloseLCProc close; + XlcMapModifiersProc map_modifiers; + XOpenOMProc open_om; + XOpenIMProc open_im; + XrmInitParseInfoProc init_parse_info; + falmbTextPropertyToTextListProc mb_text_prop_to_list; + falwcTextPropertyToTextListProc wc_text_prop_to_list; + falmbTextListToTextPropertyProc mb_text_list_to_prop; + falwcTextListToTextPropertyProc wc_text_list_to_prop; + falwcFreeStringListProc wc_free_string_list; + falDefaultStringProc default_string; + XRegisterIMInstantiateCBProc register_callback; + XUnregisterIMInstantiateCBProc unregister_callback; +} XLCdMethodsRec, *XLCdMethods; + + +typedef struct { + char* name; /* name of this LC */ + char* modifiers; /* modifiers of locale */ +} XLCdCoreRec, *XLCdCore; + + +typedef struct _XLCd { + XLCdMethods methods; /* methods of this LC */ + XLCdCore core; /* data of this LC */ + XPointer opaque; /* LDX specific data */ +} XLCdRec; + +typedef int XlcPosition; + +#define XlcHead 0 +#define XlcTail -1 + +typedef struct { + char *name; + XPointer value; +} XlcArg, *XlcArgList; + +typedef struct _XlcResource { + char *name; + XrmQuark xrm_name; + int size; + int offset; + unsigned long mask; +} XlcResource, *XlcResourceList; + +#define XlcCreateMask (1L<<0) +#define XlcDefaultMask (1L<<1) +#define XlcGetMask (1L<<2) +#define XlcSetMask (1L<<3) +#define XlcIgnoreMask (1L<<4) + +#define XlcNumber(arr) (sizeof(arr) / sizeof(arr[0])) + +typedef Status (*XCloseOMProc)( +#if NeedFunctionPrototypes + XOM /* om */ +#endif +); + +typedef char* (*XSetOMValuesProc)( +#if NeedFunctionPrototypes + XOM /* om */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +typedef char* (*XGetOMValuesProc)( +#if NeedFunctionPrototypes + XOM /* om */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +typedef XOC (*XCreateOCProc)( +#if NeedFunctionPrototypes + XOM /* om */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +typedef struct _XOMMethodsRec { + XCloseOMProc close; + XSetOMValuesProc set_values; + XGetOMValuesProc get_values; + XCreateOCProc create_oc; +} XOMMethodsRec, *XOMMethods; + +typedef struct _XOMCoreRec { + XLCd lcd; /* lcd */ + Display *display; /* display */ + XrmDatabase rdb; /* database */ + char *res_name; /* resource name */ + char *res_class; /* resource class */ + XOC oc_list; /* xoc list */ + XlcResourceList resources; /* xom resources */ + int num_resources; /* number of xom resources */ + XOMCharSetList required_charset; /* required charset list */ + XOMOrientation orientation_list; /* orientation list */ + Bool directional_dependent; /* directional-dependent */ + Bool contextual_drawing; /* contextual drawing */ + Bool context_dependent; /* context-dependent drawing */ +} XOMCoreRec, *XOMCore; + +typedef struct _XOM { + XOMMethods methods; + XOMCoreRec core; +} XOMRec; + +typedef void (*XDestroyOCProc)( +#if NeedFunctionPrototypes + XOC /* oc */ +#endif +); + +typedef char* (*XSetOCValuesProc)( +#if NeedFunctionPrototypes + XOC /* oc */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +typedef char* (*XGetOCValuesProc)( +#if NeedFunctionPrototypes + XOC /* oc */, + XlcArgList /* args */, + int /* num_args */ +#endif +); + +/* + * X Font Sets are an instantiable object, so we define it, the + * object itself, a method list and data + */ + +/* + * XFontSet object method list + */ + +typedef int (*XmbTextEscapementProc)( +#if NeedFunctionPrototypes + XFontSet /* font_set */, + _Xconst char* /* text */, + int /* text_len */ +#endif +); + +typedef int (*XmbTextExtentsProc)( +#if NeedFunctionPrototypes + XFontSet /* font_set */, + _Xconst char* /* text */, + int /* text_len */, + XRectangle* /* overall_ink_extents */, + XRectangle* /* overall_logical_extents */ +#endif +); + +typedef Status (*XmbTextPerCharExtentsProc)( +#if NeedFunctionPrototypes + XFontSet /* font_set */, + _Xconst char* /* text */, + int /* text_len */, + XRectangle* /* ink_extents_buffer */, + XRectangle* /* logical_extents_buffer */, + int /* buffer_size */, + int* /* num_chars */, + XRectangle* /* max_ink_extents */, + XRectangle* /* max_logical_extents */ +#endif +); + +typedef int (*XmbDrawStringProc)( +#if NeedFunctionPrototypes + Display* /* display */, + Drawable /* drawable */, + XFontSet /* font_set */, + GC /* gc */, + int /* x */, + int /* y */, + _Xconst char* /* text */, + int /* text_len */ +#endif +); + +typedef void (*XmbDrawImageStringProc)( +#if NeedFunctionPrototypes + Display* /* display */, + Drawable /* drawable */, + XFontSet /* font_set */, + GC /* gc */, + int /* x */, + int /* y */, + _Xconst char* /* text */, + int /* text_len */ +#endif +); + +typedef int (*XwcTextEscapementProc)( +#if NeedFunctionPrototypes + XFontSet /* font_set */, + _Xconst wchar_t* /* text */, + int /* text_len */ +#endif +); + +typedef int (*XwcTextExtentsProc)( +#if NeedFunctionPrototypes + XFontSet /* font_set */, + _Xconst wchar_t* /* text */, + int /* text_len */, + XRectangle* /* overall_ink_extents */, + XRectangle* /* overall_logical_extents */ +#endif +); + +typedef Status (*XwcTextPerCharExtentsProc)( +#if NeedFunctionPrototypes + XFontSet /* font_set */, + _Xconst wchar_t* /* text */, + int /* text_len */, + XRectangle* /* ink_extents_buffer */, + XRectangle* /* logical_extents_buffer */, + int /* buffer_size */, + int* /* num_chars */, + XRectangle* /* max_ink_extents */, + XRectangle* /* max_logical_extents */ +#endif +); + +typedef int (*XwcDrawStringProc)( +#if NeedFunctionPrototypes + Display* /* display */, + Drawable /* drawable */, + XFontSet /* font_set */, + GC /* gc */, + int /* x */, + int /* y */, + _Xconst wchar_t* /* text */, + int /* text_len */ +#endif +); + +typedef void (*XwcDrawImageStringProc)( +#if NeedFunctionPrototypes + Display* /* display */, + Drawable /* drawable */, + XFontSet /* font_set */, + GC /* gc */, + int /* x */, + int /* y */, + _Xconst wchar_t* /* text */, + int /* text_len */ +#endif +); + +typedef struct { + XDestroyOCProc destroy; + XSetOCValuesProc set_values; + XGetOCValuesProc get_values; + + /* multi-byte text drawing methods */ + + XmbTextEscapementProc mb_escapement; + XmbTextExtentsProc mb_extents; + XmbTextPerCharExtentsProc mb_extents_per_char; + XmbDrawStringProc mb_draw_string; + XmbDrawImageStringProc mb_draw_image_string; + + /* wide character text drawing methods */ + + XwcTextEscapementProc wc_escapement; + XwcTextExtentsProc wc_extents; + XwcTextPerCharExtentsProc wc_extents_per_char; + XwcDrawStringProc wc_draw_string; + XwcDrawImageStringProc wc_draw_image_string; +} XOCMethodsRec, *XOCMethods; + + +/* + * XOC independent data + */ + +typedef struct { + XOM om; /* XOM */ + XOC next; /* next XOC */ + XlcResourceList resources; /* xoc resources */ + int num_resources; /* number of xoc resources */ + char *base_name_list; /* base font name list */ + Bool om_automatic; /* OM Automatic */ + XOMFontInfo font_info; /* font info */ + XFontSetExtents font_set_extents; /* font set extents */ + char *default_string; /* default string */ + XOMCharSetList missing_list; /* missing charset list */ + XOrientation orientation; /* orientation */ + char *res_name; /* resource name */ + char *res_class; /* resource class */ +} XOCCoreRec, *XOCCore; + +typedef struct _XOC { + XOCMethods methods; + XOCCoreRec core; +} XOCRec; + + +/* current Ultrix compiler gets horribly confused */ +#if defined(FUNCPROTO) && defined(ultrix) +#undef NeedFunctionPrototypes +#endif + + +/* + * X Input Managers are an instantiable object, so we define it, the + * object itself, a method list and data. + */ + +/* + * an Input Manager object method list + */ +typedef struct { + Status (*close)( +#if NeedFunctionPrototypes + XIM +#endif + ); + char* (*set_values)( +#if NeedFunctionPrototypes + XIM, XIMArg* +#endif + ); + char* (*get_values)( +#if NeedFunctionPrototypes + XIM, XIMArg* +#endif + ); + XIC (*create_ic)( +#if NeedFunctionPrototypes + XIM, XIMArg* +#endif + ); + int (*ctstombs)( +#if NeedFunctionPrototypes + XIM, char*, int, char*, int, Status * +#endif + ); + int (*ctstowcs)( +#if NeedFunctionPrototypes + XIM, char*, int, wchar_t*, int, Status * +#endif + ); +} XIMMethodsRec, *XIMMethods; + +/* + * Input Manager LC independent data + */ +typedef struct { + XLCd lcd; /* LC of this input method */ + XIC ic_chain; /* list of ICs for this IM */ + + Display * display; /* display */ + XrmDatabase rdb; + char * res_name; + char * res_class; + + XIMValuesList *im_values_list; + XIMValuesList *ic_values_list; + XIMStyles *styles; + XIMCallback destroy_callback; + char * im_name; /* XIMMODIFIER name */ + XIMResourceList im_resources; /* compiled IM resource list */ + unsigned int im_num_resources; + XIMResourceList ic_resources; /* compiled IC resource list */ + unsigned int ic_num_resources; + Bool visible_position; +} XIMCoreRec, *XIMCore; + + + +/* + * An X Input Manager (IM). Implementations may need to extend this data + * structure to accommodate additional data, state information etc. + */ +typedef struct _XIM { + XIMMethods methods; /* method list of this IM */ + XIMCoreRec core; /* data of this IM */ +} XIMRec; + + + +/* + * X Input Contexts (IC) are an instantiable object, so we define it, the + * object itself, a method list and data for this object + */ + +/* + * Input Context method list + */ +typedef struct { + void (*destroy)( +#if NeedFunctionPrototypes + XIC +#endif + ); + void (*set_focus)( +#if NeedFunctionPrototypes + XIC +#endif + ); + void (*unset_focus)( +#if NeedFunctionPrototypes + XIC +#endif + ); + char* (*set_values)( +#if NeedFunctionPrototypes + XIC, XIMArg* +#endif + ); + char* (*get_values)( +#if NeedFunctionPrototypes + XIC, XIMArg* +#endif + ); + char* (*mb_reset)( +#if NeedFunctionPrototypes + XIC +#endif + ); + wchar_t* (*wc_reset)( +#if NeedFunctionPrototypes + XIC +#endif + ); + int (*mb_lookup_string)( +#if NeedFunctionPrototypes + XIC, XKeyEvent*, char*, int, KeySym*, Status* +#endif + ); + int (*wc_lookup_string)( +#if NeedFunctionPrototypes + XIC, XKeyEvent*, wchar_t*, int, KeySym*, Status* +#endif + ); +} XICMethodsRec, *XICMethods; + + +/* + * Input Context LC independent data + */ +typedef struct { + XIM im; /* XIM this IC belongs too */ + XIC next; /* linked list of ICs for IM */ + + Window client_window; /* window IM can use for */ + /* display or subwindows */ + XIMStyle input_style; /* IM's input style */ + Window focus_window; /* where key events go */ + unsigned long filter_events; /* event mask from IM */ + XIMCallback geometry_callback; /* client callback */ + char * res_name; + char * res_class; + + XIMCallback destroy_callback; + XIMCallback string_conversion_callback; + XIMStringConversionText string_conversion; + XIMResetState reset_state; + XIMHotKeyTriggers *hotkey; + XIMHotKeyState hotkey_state; + + ICPreeditAttributes preedit_attr; /* visuals of preedit area */ + ICStatusAttributes status_attr; /* visuals of status area */ +} XICCoreRec, *XICCore; + + +/* + * an Input Context. Implementations may need to extend this data + * structure to accommodate additional data, state information etc. + */ +typedef struct _XIC { + XICMethods methods; /* method list of this IC */ + XICCoreRec core; /* data of this IC */ +} XICRec; + +/* current Ultrix compiler gets horribly confused */ +#if !defined(NeedFunctionPrototypes) && defined(FUNCPROTO) +#define NeedFunctionPrototypes 1 +#endif + +typedef XLCd (*XLCdLoadProc)( +#if NeedFunctionPrototypes + char* +#endif +); + +_XFUNCPROTOBEGIN + +extern XLCd _falOpenLC( +#if NeedFunctionPrototypes + char* /* name */ +#endif +); + +extern void _falCloseLC( +#if NeedFunctionPrototypes + XLCd /* lcd */ +#endif +); + +extern XLCd _fallcCurrentLC( +#if NeedFunctionPrototypes + void +#endif +); + +extern Bool _fallcValidModSyntax( +#if NeedFunctionPrototypes + char* /* mods */, + char** /* valid */ +#endif +); + +extern char *_fallcDefaultMapModifiers( +#if NeedFunctionPrototypes + XLCd /* lcd */, + char* /* user_mods */, + char* /* prog_mods */ +#endif +); + +extern void _XIMCompileResourceList( +#if NeedFunctionPrototypes + XIMResourceList /* res */, + unsigned int /* num_res */ +#endif +); + +extern void _XCopyToArg( +#if NeedFunctionPrototypes + XPointer /* src */, + XPointer* /* dst */, + unsigned int /* size */ +#endif +); + +extern char ** _falParseBaseFontNameList( +#if NeedFunctionPrototypes + char* /* str */, + int* /* num */ +#endif +); + +extern XrmMethods _falrmInitParseInfo( +#if NeedFunctionPrototypes + XPointer* /* statep */ +#endif +); + +extern void _XRegisterFilterByMask( +#if NeedFunctionPrototypes + Display* /* dpy */, + Window /* window */, + unsigned long /* event_mask */, + Bool (*)( +#if NeedNestedPrototypes + Display* /* display */, + Window /* window */, + XEvent* /* event */, + XPointer /* client_data */ +#endif + ) /* filter */, + XPointer /* client_data */ +#endif +); + +extern void _XRegisterFilterByType( +#if NeedFunctionPrototypes + Display* /* dpy */, + Window /* window */, + int /* start_type */, + int /* end_type */, + Bool (*)( +#if NeedNestedPrototypes + Display* /* display */, + Window /* window */, + XEvent* /* event */, + XPointer /* client_data */ +#endif + ) /* filter */, + XPointer /* client_data */ +#endif +); + +extern void _XUnregisterFilter( +#if NeedFunctionPrototypes + Display* /* dpy */, + Window /* window */, + Bool (*)( +#if NeedNestedPrototypes + Display* /* display */, + Window /* window */, + XEvent* /* event */, + XPointer /* client_data */ +#endif + ) /* filter */, + XPointer /* client_data */ +#endif +); + +extern void _fallcCountVaList( +#if NeedFunctionPrototypes + va_list /* var */, + int* /* count_return */ +#endif +); + +extern void _fallcVaToArgList( +#if NeedFunctionPrototypes + va_list /* var */, + int /* count */, + XlcArgList* /* args_return */ +#endif +); + +extern void _fallcCompileResourceList( +#if NeedFunctionPrototypes + XlcResourceList /* resources */, + int /* num_resources */ +#endif +); + +extern char *_fallcGetValues( +#if NeedFunctionPrototypes + XPointer /* base */, + XlcResourceList /* resources */, + int /* num_resources */, + XlcArgList /* args */, + int /* num_args */, + unsigned long /* mask */ +#endif +); + +extern char *_fallcSetValues( +#if NeedFunctionPrototypes + XPointer /* base */, + XlcResourceList /* resources */, + int /* num_resources */, + XlcArgList /* args */, + int /* num_args */, + unsigned long /* mask */ +#endif +); + +extern Bool _fallcAddLoader( +#if NeedFunctionPrototypes + XLCdLoadProc /* proc */, + XlcPosition /* position */ +#endif +); + +extern void _fallcRemoveLoader( +#if NeedFunctionPrototypes + XLCdLoadProc /* proc */ +#endif +); + +_XFUNCPROTOEND + +#endif /* _XLCINT_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_fallibint.h b/cde/programs/dtudcfonted/libfal/_fallibint.h new file mode 100644 index 00000000..7c795154 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallibint.h @@ -0,0 +1,1244 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* Xlibint.h 1.2 - Fujitsu source for CDEnext 95/12/07 10:53:12 */ +/* $XConsortium: _fallibint.h /main/1 1996/04/08 15:21:22 cde-fuj $ */ + +/* + +Copyright (c) 1984, 1985, 1987, 1989 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +/* + * Xlibint.h - Header definition and support file for the internal + * support routines used by the C subroutine interface + * library (Xlib) to the X Window System. + * + * Warning, there be dragons here.... + */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietry source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ + + +#if !defined(NEED_EVENTS) && !NeedFunctionPrototypes +#define _XEVENT_ +#endif + +#include "syncx.h" + +#ifdef WIN32 +#define _XFlush _XFlushIt +#endif + +struct _XGC +{ + XExtData *ext_data; /* hook for extension to hang data */ + GContext gid; /* protocol ID for graphics context */ + Bool rects; /* boolean: TRUE if clipmask is list of rectangles */ + Bool dashes; /* boolean: TRUE if dash-list is really a list */ + unsigned long dirty;/* cache dirty bits */ + XGCValues values; /* shadow structure of values */ +}; + +struct _XDisplay +{ + XExtData *ext_data; /* hook for extension to hang data */ + struct _XFreeFuncs *free_funcs; /* internal free functions */ + int fd; /* Network socket. */ + int conn_checker; /* ugly thing used by _XEventsQueued */ + int proto_major_version;/* maj. version of server's X protocol */ + int proto_minor_version;/* minor version of server's X protocol */ + char *vendor; /* vendor of the server hardware */ + XID resource_base; /* resource ID base */ + XID resource_mask; /* resource ID mask bits */ + XID resource_id; /* allocator current ID */ + int resource_shift; /* allocator shift to correct bits */ + XID (*resource_alloc)(); /* allocator function */ + int byte_order; /* screen byte order, LSBFirst, MSBFirst */ + int bitmap_unit; /* padding and data requirements */ + int bitmap_pad; /* padding requirements on bitmaps */ + int bitmap_bit_order; /* LeastSignificant or MostSignificant */ + int nformats; /* number of pixmap formats in list */ + ScreenFormat *pixmap_format; /* pixmap format list */ + int vnumber; /* Xlib's X protocol version number. */ + int release; /* release of the server */ + struct _XSQEvent *head, *tail; /* Input event queue. */ + int qlen; /* Length of input event queue */ + unsigned long last_request_read; /* seq number of last event read */ + unsigned long request; /* sequence number of last request. */ + char *last_req; /* beginning of last request, or dummy */ + char *buffer; /* Output buffer starting address. */ + char *bufptr; /* Output buffer index pointer. */ + char *bufmax; /* Output buffer maximum+1 address. */ + unsigned max_request_size; /* maximum number 32 bit words in request*/ + struct _XrmHashBucketRec *db; + int (*synchandler)(); /* Synchronization handler */ + char *display_name; /* "host:display" string used on this connect*/ + int default_screen; /* default screen for operations */ + int nscreens; /* number of screens on this server*/ + Screen *screens; /* pointer to list of screens */ + unsigned long motion_buffer; /* size of motion buffer */ + unsigned long flags; /* internal connection flags */ + int min_keycode; /* minimum defined keycode */ + int max_keycode; /* maximum defined keycode */ + KeySym *keysyms; /* This server's keysyms */ + XModifierKeymap *modifiermap; /* This server's modifier keymap */ + int keysyms_per_keycode;/* number of rows */ + char *xdefaults; /* contents of defaults from server */ + char *scratch_buffer; /* place to hang scratch buffer */ + unsigned long scratch_length; /* length of scratch buffer */ + int ext_number; /* extension number on this display */ + struct _XExten *ext_procs; /* extensions initialized on this display */ + /* + * the following can be fixed size, as the protocol defines how + * much address space is available. + * While this could be done using the extension vector, there + * may be MANY events processed, so a search through the extension + * list to find the right procedure for each event might be + * expensive if many extensions are being used. + */ + Bool (*event_vec[128])(); /* vector for wire to event */ + Status (*wire_vec[128])(); /* vector for event to wire */ + KeySym lock_meaning; /* for XLookupString */ + struct _XLockInfo *lock; /* multi-thread state, display lock */ + struct _XInternalAsync *async_handlers; /* for internal async */ + unsigned long bigreq_size; /* max size of big requests */ + struct _XLockPtrs *lock_fns; /* pointers to threads functions */ + void (*idlist_alloc)(); /* XID list allocator function */ + /* things above this line should not move, for binary compatibility */ + struct _XKeytrans *key_bindings; /* for XLookupString */ + Font cursor_font; /* for XCreateFontCursor */ + struct _XDisplayAtoms *atoms; /* for falInternAtom */ + unsigned int mode_switch; /* keyboard group modifiers */ + unsigned int num_lock; /* keyboard numlock modifiers */ + struct _XContextDB *context_db; /* context database */ + Bool (**error_vec)(); /* vector for wire to error */ + /* + * Xcms information + */ + struct { + XPointer defaultCCCs; /* pointer to an array of default XcmsCCC */ + XPointer clientCmaps; /* pointer to linked list of XcmsCmapRec */ + XPointer perVisualIntensityMaps; + /* linked list of XcmsIntensityMap */ + } cms; + struct _XIMFilter *im_filters; + struct _XSQEvent *qfree; /* unallocated event queue elements */ + unsigned long next_event_serial_num; /* inserted into next queue elt */ + struct _XExten *flushes; /* Flush hooks */ + struct _XConnectionInfo *im_fd_info; /* _XRegisterInternalConnection */ + int im_fd_length; /* number of im_fd_info */ + struct _XConnWatchInfo *conn_watchers; /* XAddConnectionWatch */ + int watcher_count; /* number of conn_watchers */ + XPointer filedes; /* struct pollfd cache for _XWaitForReadable */ + int (*savedsynchandler)(); /* user synchandler when Xlib usurps */ + XID resource_max; /* allocator max ID */ + int xcmisc_opcode; /* major opcode for XC-MISC */ + struct _XkbInfoRec *xkb_info; /* XKB info */ + struct _XtransConnInfo *trans_conn; /* transport connection object */ +}; + +#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n) + +/* + * define the following if you want the Data macro to be a procedure instead + */ +#ifdef CRAY +#define DataRoutineIsProcedure +#endif /* CRAY */ + +#ifndef _XEVENT_ +/* + * _QEvent datatype for use in input queueing. + */ +typedef struct _XSQEvent +{ + struct _XSQEvent *next; + XEvent event; + unsigned long qserial_num; /* so multi-threaded code can find new ones */ +} _XQEvent; +#endif + +#ifdef XTHREADS /* for xReply */ +#define NEED_REPLIES +#endif + +#if NeedFunctionPrototypes /* prototypes require event type definitions */ +#define NEED_EVENTS +#define NEED_REPLIES +#endif +#include +#include +#define _XBCOPYFUNC _Xbcopy +#include +#include + +/* Utek leaves kernel macros around in include files (bleah) */ +#ifdef dirty +#undef dirty +#endif + +#ifndef X_NOT_STDC_ENV +#include +#include +#else +char *malloc(), *realloc(), *calloc(); +void exit(); +#ifdef SYSV +#include +#else +#include +#endif +#endif + +/* + * The following definitions can be used for locking requests in multi-threaded + * address spaces. + */ +#ifdef XTHREADS +/* Author: Stephen Gildea, MIT X Consortium + * + * declarations for C Threads locking + */ + +#include + +struct _XLockPtrs { + /* used by all, including extensions; do not move */ + void (*lock_display)(); + void (*unlock_display)(); +}; + +typedef struct _LockInfoRec *LockInfoPtr; + +#if defined(WIN32) && !defined(_XLIBINT_) +#define _XCreateMutex_fn (*_XCreateMutex_fn_p) +#define _XFreeMutex_fn (*_XFreeMutex_fn_p) +#define _XLockMutex_fn (*_XLockMutex_fn_p) +#define _XUnlockMutex_fn (*_XUnlockMutex_fn_p) +#define _Xglobal_lock (*_Xglobal_lock_p) +#endif + +/* in XlibInt.c */ +extern void (*_XCreateMutex_fn)( +#if NeedFunctionPrototypes + LockInfoPtr /* lock */ +#endif +); +extern void (*_XFreeMutex_fn)( +#if NeedFunctionPrototypes + LockInfoPtr /* lock */ +#endif +); +extern void (*_XLockMutex_fn)( +#if NeedFunctionPrototypes + LockInfoPtr /* lock */ +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) + , char * /* file */ + , int /* line */ +#endif +#endif +); +extern void (*_XUnlockMutex_fn)( +#if NeedFunctionPrototypes + LockInfoPtr /* lock */ +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) + , char * /* file */ + , int /* line */ +#endif +#endif +); + +extern LockInfoPtr _Xglobal_lock; + +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) +#define LockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->lock_display)((d),__FILE__,__LINE__) +#define UnlockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)((d),__FILE__,__LINE__) +#define _XLockMutex(lock) if (_XLockMutex_fn) (*_XLockMutex_fn)(lock,__FILE__,__LINE__) +#define _XUnlockMutex(lock) if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock,__FILE__,__LINE__) +#else +/* used everywhere, so must be fast if not using threads */ +#define LockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->lock_display)(d) +#define UnlockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)(d) +#define _XLockMutex(lock) if (_XLockMutex_fn) (*_XLockMutex_fn)(lock) +#define _XUnlockMutex(lock) if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock) +#endif +#define _XCreateMutex(lock) if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock); +#define _XFreeMutex(lock) if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock); + +#else /* XTHREADS */ +#define LockDisplay(dis) +#define _XLockMutex(lock) +#define _XUnlockMutex(lock) +#define UnlockDisplay(dis) +#define _XCreateMutex(lock) +#define _XFreeMutex(lock) +#endif + +#define Xfree(ptr) free((ptr)) + +/* + * Note that some machines do not return a valid pointer for malloc(0), in + * which case we provide an alternate under the control of the + * define MALLOC_0_RETURNS_NULL. This is necessary because some + * Xlib code expects malloc(0) to return a valid pointer to storage. + */ +#ifdef MALLOC_0_RETURNS_NULL + +# define Xmalloc(size) malloc(((size) == 0 ? 1 : (size))) +# define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size))) +# define Xcalloc(nelem, elsize) calloc(((nelem) == 0 ? 1 : (nelem)), (elsize)) + +#else + +# define Xmalloc(size) malloc((size)) +# define Xrealloc(ptr, size) realloc((ptr), (size)) +# define Xcalloc(nelem, elsize) calloc((nelem), (elsize)) + +#endif + +#ifndef NULL +#define NULL 0 +#endif +#define LOCKED 1 +#define UNLOCKED 0 + +#ifdef X_NOT_STDC_ENV +extern int errno; /* Internal system error number. */ +#endif + +#ifndef BUFSIZE +#define BUFSIZE 2048 /* X output buffer size. */ +#endif +#ifndef PTSPERBATCH +#define PTSPERBATCH 1024 /* point batching */ +#endif +#ifndef WLNSPERBATCH +#define WLNSPERBATCH 50 /* wide line batching */ +#endif +#ifndef ZLNSPERBATCH +#define ZLNSPERBATCH 1024 /* thin line batching */ +#endif +#ifndef WRCTSPERBATCH +#define WRCTSPERBATCH 10 /* wide line rectangle batching */ +#endif +#ifndef ZRCTSPERBATCH +#define ZRCTSPERBATCH 256 /* thin line rectangle batching */ +#endif +#ifndef FRCTSPERBATCH +#define FRCTSPERBATCH 256 /* filled rectangle batching */ +#endif +#ifndef FARCSPERBATCH +#define FARCSPERBATCH 256 /* filled arc batching */ +#endif +#ifndef CURSORFONT +#define CURSORFONT "cursor" /* standard cursor fonts */ +#endif + +/* + * Display flags + */ +#define XlibDisplayIOError (1L << 0) +#define XlibDisplayClosing (1L << 1) +#define XlibDisplayNoXkb (1L << 2) +#define XlibDisplayPrivSync (1L << 3) +#define XlibDisplayProcConni (1L << 4) /* in _XProcessInternalConnection */ +#define XlibDisplayReadEvents (1L << 5) /* in _XReadEvents */ +#define XlibDisplayReply (1L << 5) /* in _XReply */ +#define XlibDisplayWriting (1L << 6) /* in _XFlushInt, _XSend */ + +/* + * X Protocol packetizing macros. + */ + +/* Need to start requests on 64 bit word boundaries + * on a CRAY computer so add a NoOp (127) if needed. + * A character pointer on a CRAY computer will be non-zero + * after shifting right 61 bits of it is not pointing to + * a word boundary. + */ +#ifdef WORD64 +#define WORD64ALIGN if ((long)dpy->bufptr >> 61) {\ + dpy->last_req = dpy->bufptr;\ + *(dpy->bufptr) = X_NoOperation;\ + *(dpy->bufptr+1) = 0;\ + *(dpy->bufptr+2) = 0;\ + *(dpy->bufptr+3) = 1;\ + dpy->request++;\ + dpy->bufptr += 4;\ + } +#else /* else does not require alignment on 64-bit boundaries */ +#define WORD64ALIGN +#endif /* WORD64 */ + + +/* + * GetReq - Get the next available X request packet in the buffer and + * return it. + * + * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc. + * "req" is the name of the request pointer. + * + */ + +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define GetReq(name, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ + req->reqType = X_##name;\ + req->length = (SIZEOF(x##name##Req))>>2;\ + dpy->bufptr += SIZEOF(x##name##Req);\ + dpy->request++ + +#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ +#define GetReq(name, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ + req->reqType = X_/**/name;\ + req->length = (SIZEOF(x/**/name/**/Req))>>2;\ + dpy->bufptr += SIZEOF(x/**/name/**/Req);\ + dpy->request++ +#endif + +/* GetReqExtra is the same as GetReq, but allocates "n" additional + bytes after the request. "n" must be a multiple of 4! */ + +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define GetReqExtra(name, n, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ + req->reqType = X_##name;\ + req->length = (SIZEOF(x##name##Req) + n)>>2;\ + dpy->bufptr += SIZEOF(x##name##Req) + n;\ + dpy->request++ +#else +#define GetReqExtra(name, n, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ + req->reqType = X_/**/name;\ + req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\ + dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\ + dpy->request++ +#endif + + +/* + * GetResReq is for those requests that have a resource ID + * (Window, Pixmap, GContext, etc.) as their single argument. + * "rid" is the name of the resource. + */ + +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define GetResReq(name, rid, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\ + req->reqType = X_##name;\ + req->length = 2;\ + req->id = (rid);\ + dpy->bufptr += SIZEOF(xResourceReq);\ + dpy->request++ +#else +#define GetResReq(name, rid, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\ + req->reqType = X_/**/name;\ + req->length = 2;\ + req->id = (rid);\ + dpy->bufptr += SIZEOF(xResourceReq);\ + dpy->request++ +#endif + +/* + * GetEmptyReq is for those requests that have no arguments + * at all. + */ +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define GetEmptyReq(name, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (xReq *) (dpy->last_req = dpy->bufptr);\ + req->reqType = X_##name;\ + req->length = 1;\ + dpy->bufptr += SIZEOF(xReq);\ + dpy->request++ +#else +#define GetEmptyReq(name, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (xReq *) (dpy->last_req = dpy->bufptr);\ + req->reqType = X_/**/name;\ + req->length = 1;\ + dpy->bufptr += SIZEOF(xReq);\ + dpy->request++ +#endif + +#ifdef WORD64 +#define MakeBigReq(req,n) \ + { \ + char _BRdat[4]; \ + unsigned long _BRlen = req->length - 1; \ + req->length = 0; \ + memcpy(_BRdat, ((char *)req) + (_BRlen << 2), 4); \ + memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \ + memcpy(((char *)req) + 4, _BRdat, 4); \ + Data32(dpy, (long *)&_BRdat, 4); \ + } +#else +#define MakeBigReq(req,n) \ + { \ + long _BRdat; \ + unsigned long _BRlen = req->length - 1; \ + req->length = 0; \ + _BRdat = ((long *)req)[_BRlen]; \ + memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \ + ((unsigned long *)req)[1] = _BRlen + n + 2; \ + Data32(dpy, &_BRdat, 4); \ + } +#endif + +#define SetReqLen(req,n,badlen) \ + if ((req->length + n) > (unsigned)65535) { \ + if (dpy->bigreq_size) { \ + MakeBigReq(req,n) \ + } else { \ + n = badlen; \ + req->length += n; \ + } \ + } else \ + req->length += n + +#define SyncHandle() \ + if (dpy->synchandler) (*dpy->synchandler)(dpy) + +#define FlushGC(dpy, gc) \ + if ((gc)->dirty) _XFlushGCCache((dpy), (gc)) +/* + * Data - Place data in the buffer and pad the end to provide + * 32 bit word alignment. Transmit if the buffer fills. + * + * "dpy" is a pointer to a Display. + * "data" is a pinter to a data buffer. + * "len" is the length of the data buffer. + */ +#ifndef DataRoutineIsProcedure +#define Data(dpy, data, len) \ + if (dpy->bufptr + (len) <= dpy->bufmax) {\ + memcpy(dpy->bufptr, data, (int)len);\ + dpy->bufptr += ((len) + 3) & ~3;\ + } else\ + _XSend(dpy, data, len) +#endif /* DataRoutineIsProcedure */ + + +/* Allocate bytes from the buffer. No padding is done, so if + * the length is not a multiple of 4, the caller must be + * careful to leave the buffer aligned after sending the + * current request. + * + * "type" is the type of the pointer being assigned to. + * "ptr" is the pointer being assigned to. + * "n" is the number of bytes to allocate. + * + * Example: + * xTextElt *elt; + * BufAlloc (xTextElt *, elt, nbytes) + */ + +#define BufAlloc(type, ptr, n) \ + if (dpy->bufptr + (n) > dpy->bufmax) \ + _XFlush (dpy); \ + ptr = (type) dpy->bufptr; \ + dpy->bufptr += (n); + +#ifdef WORD64 +#define Data16(dpy, data, len) _XData16(dpy, (short *)data, len) +#define Data32(dpy, data, len) _XData32(dpy, (long *)data, len) +#else +#define Data16(dpy, data, len) Data((dpy), (char *)(data), (len)) +#define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len)) +#define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len)) +#ifdef LONG64 +#define Data32(dpy, data, len) _XData32(dpy, (long *)data, len) +#else +#define Data32(dpy, data, len) Data((dpy), (char *)(data), (len)) +#define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len)) +#endif +#endif /* not WORD64 */ + +#define PackData16(dpy,data,len) Data16 (dpy, data, len) +#define PackData32(dpy,data,len) Data32 (dpy, data, len) + +/* Xlib manual is bogus */ +#define PackData(dpy,data,len) PackData16 (dpy, data, len) + +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define max(a,b) (((a) > (b)) ? (a) : (b)) + +#define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \ + (((cs)->rbearing|(cs)->lbearing| \ + (cs)->ascent|(cs)->descent) == 0)) + +/* + * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit + * character. If the character is in the column and exists, then return the + * appropriate metrics (note that fonts with common per-character metrics will + * return min_bounds). If none of these hold true, try again with the default + * char. + */ +#define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \ +{ \ + cs = def; \ + if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \ + if (fs->per_char == NULL) { \ + cs = &fs->min_bounds; \ + } else { \ + cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \ + if (CI_NONEXISTCHAR(cs)) cs = def; \ + } \ + } \ +} + +#define CI_GET_DEFAULT_INFO_1D(fs,cs) \ + CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs) + + + +/* + * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and + * column. This is used for fonts that have more than row zero. + */ +#define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \ +{ \ + cs = def; \ + if (row >= fs->min_byte1 && row <= fs->max_byte1 && \ + col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \ + if (fs->per_char == NULL) { \ + cs = &fs->min_bounds; \ + } else { \ + cs = &fs->per_char[((row - fs->min_byte1) * \ + (fs->max_char_or_byte2 - \ + fs->min_char_or_byte2 + 1)) + \ + (col - fs->min_char_or_byte2)]; \ + if (CI_NONEXISTCHAR(cs)) cs = def; \ + } \ + } \ +} + +#define CI_GET_DEFAULT_INFO_2D(fs,cs) \ +{ \ + unsigned int r = (fs->default_char >> 8); \ + unsigned int c = (fs->default_char & 0xff); \ + CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \ +} + + +#ifdef MUSTCOPY + +/* for when 32-bit alignment is not good enough */ +#define OneDataCard32(dpy,dstaddr,srcvar) \ + { dpy->bufptr -= 4; Data32 (dpy, (char *) &(srcvar), 4); } + +#else + +/* srcvar must be a variable for large architecture version */ +#define OneDataCard32(dpy,dstaddr,srcvar) \ + { *(CARD32 *)(dstaddr) = (srcvar); } + +#endif /* MUSTCOPY */ + +typedef struct _XInternalAsync { + struct _XInternalAsync *next; + Bool (*handler)(); + XPointer data; +} _XAsyncHandler; + +typedef struct _XAsyncEState { + unsigned long min_sequence_number; + unsigned long max_sequence_number; + unsigned char error_code; + unsigned char major_opcode; + unsigned short minor_opcode; + unsigned char last_error_received; + int error_count; +} _XAsyncErrorState; + +#define DeqAsyncHandler(dpy,handler) { \ + if (dpy->async_handlers == (handler)) \ + dpy->async_handlers = (handler)->next; \ + else \ + _XDeqAsyncHandler(dpy, handler); \ + } + +/* + * This structure is private to the library. + */ +typedef struct _XFreeFuncs { + void (*atoms)(); /* _XFreeAtomTable */ + int (*modifiermap)(); /* XFreeModifierMap */ + void (*key_bindings)(); /* _XFreeKeyBindings */ + void (*context_db)(); /* _XFreeContextDB */ + void (*defaultCCCs)(); /* _XcmsFreeDefaultCCCs */ + void (*clientCmaps)(); /* _XcmsFreeClientCmaps */ + void (*intensityMaps)(); /* _XcmsFreeIntensityMaps */ + void (*im_filters)(); /* _XFreeIMFilters */ + void (*xkb)(); /* _XkbFreeInfo */ +} _XFreeFuncRec; + +/* + * This structure is private to the library. + */ +typedef struct _XExten { /* private to extension mechanism */ + struct _XExten *next; /* next in list */ + XExtCodes codes; /* public information, all extension told */ + int (*create_GC)(); /* routine to call when GC created */ + int (*copy_GC)(); /* routine to call when GC copied */ + int (*flush_GC)(); /* routine to call when GC flushed */ + int (*free_GC)(); /* routine to call when GC freed */ + int (*create_Font)(); /* routine to call when Font created */ + int (*free_Font)(); /* routine to call when Font freed */ + int (*close_display)(); /* routine to call when connection closed */ + int (*error)(); /* who to call when an error occurs */ + char *(*error_string)(); /* routine to supply error string */ + char *name; /* name of this extension */ + void (*error_values)(); /* routine to supply error values */ + void (*before_flush)(); /* routine to call when sending data */ + struct _XExten *next_flush; /* next in list of those with flushes */ +} _XExtension; + +/* extension hooks */ + +_XFUNCPROTOBEGIN + +#ifdef DataRoutineIsProcedure +extern void Data(); +#endif +extern int _XError( +#if NeedFunctionPrototypes + Display* /* dpy */, + xError* /* rep */ +#endif +); +extern int _XIOError( +#if NeedFunctionPrototypes + Display* /* dpy */ +#endif +); +extern int (*_XIOErrorFunction)( +#if NeedNestedPrototypes + Display* /* dpy */ +#endif +); +extern int (*_XErrorFunction)( +#if NeedNestedPrototypes + Display* /* dpy */, + XErrorEvent* /* error_event */ +#endif +); +extern void _XEatData( +#if NeedFunctionPrototypes + Display* /* dpy */, + unsigned long /* n */ +#endif +); +extern char *_XAllocScratch( +#if NeedFunctionPrototypes + Display* /* dpy */, + unsigned long /* nbytes */ +#endif +); +extern char *_XAllocTemp( +#if NeedFunctionPrototypes + Display* /* dpy */, + unsigned long /* nbytes */ +#endif +); +extern void _XFreeTemp( +#if NeedFunctionPrototypes + Display* /* dpy */, + char* /* buf */, + unsigned long /* nbytes */ +#endif +); +extern Visual *_XVIDtoVisual( +#if NeedFunctionPrototypes + Display* /* dpy */, + VisualID /* id */ +#endif +); +extern unsigned long _XSetLastRequestRead( +#if NeedFunctionPrototypes + Display* /* dpy */, + xGenericReply* /* rep */ +#endif +); +extern int _XGetHostname( +#if NeedFunctionPrototypes + char* /* buf */, + int /* maxlen */ +#endif +); +extern Screen *_XScreenOfWindow( +#if NeedFunctionPrototypes + Display* /* dpy */, + Window /* w */ +#endif +); +extern Bool _XAsyncErrorHandler( +#if NeedFunctionPrototypes + Display* /* dpy */, + xReply* /* rep */, + char* /* buf */, + int /* len */, + XPointer /* data */ +#endif +); +extern char *_XGetAsyncReply( +#if NeedFunctionPrototypes + Display* /* dpy */, + char* /* replbuf */, + xReply* /* rep */, + char* /* buf */, + int /* len */, + int /* extra */, + Bool /* discard */ +#endif +); +extern _XFlush( +#if NeedFunctionPrototypes + Display* /* dpy */ +#endif +); +extern int _XEventsQueued( +#if NeedFunctionPrototypes + Display* /* dpy */, + int /* mode */ +#endif +); +extern _XReadEvents( +#if NeedFunctionPrototypes + Display* /* dpy */ +#endif +); +extern _XRead( +#if NeedFunctionPrototypes + Display* /* dpy */, + char* /* data */, + long /* size */ +#endif +); +extern _XReadPad( +#if NeedFunctionPrototypes + Display* /* dpy */, + char* /* data */, + long /* size */ +#endif +); +extern _XSend( +#if NeedFunctionPrototypes + Display* /* dpy */, + _Xconst char* /* data */, + long /* size */ +#endif +); +extern Status _XReply( +#if NeedFunctionPrototypes + Display* /* dpy */, + xReply* /* rep */, + int /* extra */, + Bool /* discard */ +#endif +); +extern _XEnq( +#if NeedFunctionPrototypes + Display* /* dpy */, + xEvent* /* event */ +#endif +); +extern _XDeq( +#if NeedFunctionPrototypes + Display* /* dpy */, + _XQEvent* /* prev */, + _XQEvent* /* qelt */ +#endif +); + +extern int (*XESetCreateGC( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, GC, XExtCodes* +#endif +); + +extern int (*XESetCopyGC( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, GC, XExtCodes* +#endif +); + +extern int (*XESetFlushGC( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, GC, XExtCodes* +#endif +); + +extern int (*XESetFreeGC( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, GC, XExtCodes* +#endif +); + +extern int (*XESetCreateFont( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XFontStruct* /* fs */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XFontStruct*, XExtCodes* +#endif +); + +extern int (*XESetFreeFont( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XFontStruct* /* fs */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XFontStruct*, XExtCodes* +#endif +); + +extern int (*XESetCloseDisplay( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XExtCodes* /* codes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XExtCodes* +#endif +); + +extern int (*XESetError( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + int (*) ( +#if NeedNestedPrototypes + Display* /* display */, + xError* /* err */, + XExtCodes* /* codes */, + int* /* ret_code */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, xError*, XExtCodes*, int* +#endif +); + +extern char* (*XESetErrorString( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + char* (*) ( +#if NeedNestedPrototypes + Display* /* display */, + int /* code */, + XExtCodes* /* codes */, + char* /* buffer */, + int /* nbytes */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, int, XExtCodes*, char*, int +#endif +); + +extern void (*XESetPrintErrorValues ( +#if NeedFunctionPrototypes + Display* /* display */, + int /* extension */, + void (*)( +#if NeedNestedPrototypes + Display* /* display */, + XErrorEvent* /* ev */, + void* /* fp */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XErrorEvent*, void* +#endif +); + +extern Bool (*XESetWireToEvent( +#if NeedFunctionPrototypes + Display* /* display */, + int /* event_number */, + Bool (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XEvent* /* re */, + xEvent* /* event */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XEvent*, xEvent* +#endif +); + +extern Status (*XESetEventToWire( +#if NeedFunctionPrototypes + Display* /* display */, + int /* event_number */, + Status (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XEvent* /* re */, + xEvent* /* event */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XEvent*, xEvent* +#endif +); + +extern Bool (*XESetWireToError( +#if NeedFunctionPrototypes + Display* /* display */, + int /* error_number */, + Bool (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XErrorEvent* /* he */, + xError* /* we */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XErrorEvent*, xError* +#endif +); + +extern void (*XESetBeforeFlush( +#if NeedFunctionPrototypes + Display* /* display */, + int /* error_number */, + void (*) ( +#if NeedNestedPrototypes + Display* /* display */, + XExtCodes* /* codes */, + char* /* data */, + long /* len */ +#endif + ) /* proc */ +#endif +))( +#if NeedNestedPrototypes + Display*, XExtCodes*, char*, long +#endif +); + +/* internal connections for IMs */ + +typedef void (*_XInternalConnectionProc)( +#if NeedFunctionPrototypes + Display* /* dpy */, + int /* fd */, + XPointer /* call_data */ +#endif +); + + +extern Status _XRegisterInternalConnection( +#if NeedFunctionPrototypes + Display* /* dpy */, + int /* fd */, + _XInternalConnectionProc /* callback */, + XPointer /* call_data */ +#endif +); + +extern void _XUnregisterInternalConnection( +#if NeedFunctionPrototypes + Display* /* dpy */, + int /* fd */ +#endif +); + +/* Display structure has pointers to these */ + +struct _XConnectionInfo { /* info from _XRegisterInternalConnection */ + int fd; + _XInternalConnectionProc read_callback; + XPointer call_data; + XPointer *watch_data; /* set/used by XConnectionWatchProc */ + struct _XConnectionInfo *next; +}; + +struct _XConnWatchInfo { /* info from XAddConnectionWatch */ + XConnectionWatchProc fn; + XPointer client_data; + struct _XConnWatchInfo *next; +}; + +extern int XTextHeight( +#if NeedFunctionPrototypes + XFontStruct* /* font_struct */, + _Xconst char* /* string */, + int /* count */ +#endif +); + +extern int XTextHeight16( +#if NeedFunctionPrototypes + XFontStruct* /* font_struct */, + _Xconst XChar2b* /* string */, + int /* count */ +#endif +); + +_XFUNCPROTOEND diff --git a/cde/programs/dtudcfonted/libfal/_fallocking.h b/cde/programs/dtudcfonted/libfal/_fallocking.h new file mode 100644 index 00000000..6235ea40 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_fallocking.h @@ -0,0 +1,197 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* locking.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:43 */ +/* $XConsortium: _fallocking.h /main/1 1996/04/08 15:21:32 cde-fuj $ */ +/* + +Copyright (c) 1992 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +*/ + +/* + * Author: Stephen Gildea, MIT X Consortium + * + * locking.h - data types for C Threads locking. + * Used by XlibInt.c, locking.c, LockDis.c + */ + +#ifndef _X_locking_H_ +#define _X_locking_H_ + +#define xmalloc(s) Xmalloc(s) +#define xfree(s) Xfree(s) +#include + +struct _XCVList { + xcondition_t cv; + xReply *buf; + struct _XCVList *next; +}; + +extern xthread_t (*_Xthread_self_fn)( /* in XlibInt.c */ +#if NeedFunctionPrototypes + void +#endif +); + +/* Display->lock is a pointer to one of these */ + +struct _XLockInfo { + xmutex_t mutex; /* mutex for critical sections */ + int reply_bytes_left; /* nbytes of the reply still to read */ + Bool reply_was_read; /* _XReadEvents read a reply for _XReply */ + struct _XCVList *reply_awaiters; /* list of CVs for _XReply */ + struct _XCVList **reply_awaiters_tail; + struct _XCVList *event_awaiters; /* list of CVs for _XReadEvents */ + struct _XCVList **event_awaiters_tail; + Bool reply_first; /* who may read, reply queue or event queue */ + /* for XLockDisplay */ + int locking_level; /* how many times into XLockDisplay we are */ + xthread_t locking_thread; /* thread that did XLockDisplay */ + xcondition_t cv; /* wait if another thread has XLockDisplay */ + xthread_t reading_thread; /* cache */ + xthread_t conni_thread; /* thread in XProcessInternalConnection */ + xcondition_t writers; /* wait for writable */ + int num_free_cvls; + struct _XCVList *free_cvls; + /* used only in XlibInt.c */ + void (*pop_reader)( +#if NeedNestedPrototypes + Display* /* dpy */, + struct _XCVList** /* list */, + struct _XCVList*** /* tail */ +#endif + ); + struct _XCVList *(*push_reader)( +#if NeedNestedPrototypes + Display * /* dpy */, + struct _XCVList*** /* tail */ +#endif + ); + void (*condition_wait)( +#if NeedNestedPrototypes + xcondition_t /* cv */, + xmutex_t /* mutex */ +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) + , char* /* file */, + int /* line */ +#endif +#endif + ); + void (*internal_lock_display)( +#if NeedNestedPrototypes + Display* /* dpy */, + Bool /* wskip */ +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) + , char* /* file */, + int /* line */ +#endif +#endif + ); + /* used in XlibInt.c and locking.c */ + void (*condition_signal)( +#if NeedNestedPrototypes + xcondition_t /* cv */ +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) + , char* /* file */, + int /* line */ +#endif +#endif + ); + void (*condition_broadcast)( +#if NeedNestedPrototypes + xcondition_t /* cv */ +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) + , char* /* file */, + int /* line */ +#endif +#endif + ); + /* used in XlibInt.c and XLockDis.c */ + void (*lock_wait)( +#if NeedNestedPrototypes + Display* /* dpy */ +#endif + ); + void (*user_lock_display)( +#if NeedNestedPrototypes + Display* /* dpy */ +#endif + ); + void (*user_unlock_display)( +#if NeedNestedPrototypes + Display* /* dpy */ +#endif + ); + struct _XCVList *(*create_cvl)( +#if NeedNestedPrototypes + Display * /* dpy */ +#endif + ); +}; + +#define UnlockNextEventReader(d) if ((d)->lock) \ + (*(d)->lock->pop_reader)((d),&(d)->lock->event_awaiters,&(d)->lock->event_awaiters_tail) + +#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE) +#define ConditionWait(d,c) if ((d)->lock) \ + (*(d)->lock->condition_wait)(c, (d)->lock->mutex,__FILE__,__LINE__) +#define ConditionSignal(d,c) if ((d)->lock) \ + (*(d)->lock->condition_signal)(c,__FILE__,__LINE__) +#define ConditionBroadcast(d,c) if ((d)->lock) \ + (*(d)->lock->condition_broadcast)(c,__FILE__,__LINE__) +#else +#define ConditionWait(d,c) if ((d)->lock) \ + (*(d)->lock->condition_wait)(c, (d)->lock->mutex) +#define ConditionSignal(d,c) if ((d)->lock) \ + (*(d)->lock->condition_signal)(c) +#define ConditionBroadcast(d,c) if ((d)->lock) \ + (*(d)->lock->condition_broadcast)(c) +#endif + +typedef struct _LockInfoRec { + xmutex_t lock; +} LockInfoRec; + +#endif /* _X_locking_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_falomGeneric.c b/cde/programs/dtudcfonted/libfal/_falomGeneric.c new file mode 100644 index 00000000..f1d309a8 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falomGeneric.c @@ -0,0 +1,1944 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* omGeneric.c 1.9 - Fujitsu source for CDEnext 96/04/26 11:20:11 */ +/* $XConsortium: _falomGeneric.c /main/4 1996/09/27 19:03:50 drk $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ + +#include "_fallibint.h" +#include "_falomGeneric.h" +#include +#include +#include +#include +#include + +#define MAXFONTS 100 +#define PIXEL_SIZE_FIELD 7 +#define POINT_SIZE_FIELD 8 +#define CHARSET_ENCODING_FIELD 14 + +extern int _falmbDefaultTextEscapement(), _falwcDefaultTextEscapement(); +extern int _falmbDefaultTextExtents(), _falwcDefaultTextExtents(); +extern Status _falmbDefaultTextPerCharExtents(), _falwcDefaultTextPerCharExtents(); +extern int _falmbDefaultDrawString(), _falwcDefaultDrawString(); +extern void _falmbDefaultDrawImageString(), _falwcDefaultDrawImageString(); + +extern int _falmbGenericTextEscapement(), _falwcGenericTextEscapement(); +extern int _falmbGenericTextExtents(), _falwcGenericTextExtents(); +extern Status _falmbGenericTextPerCharExtents(), _falwcGenericTextPerCharExtents(); +extern int _falmbGenericDrawString(), _falwcGenericDrawString(); +extern void _falmbGenericDrawImageString(), _falwcGenericDrawImageString(); + +extern void dbg_printValue(char *str, char **value, int num); + +/* For VW/UDC start */ + +static FontData +init_fontdata(font_data, font_data_count) + FontData font_data; + int font_data_count; +{ + FontData fd; + int i; + + fd = (FontData)Xmalloc(sizeof(FontDataRec) * font_data_count); + if(fd == (FontData) NULL) + return False; + + memset(fd, 0x00, sizeof(FontData) * font_data_count); + for(i = 0 ; i < font_data_count ; i++) + fd[i] = font_data[i]; + + return fd; +} + +static VRotate +init_vrotate(font_data, font_data_count, type, code_range, code_range_num) + FontData font_data; + int font_data_count; + int type; + CodeRange code_range; + int code_range_num; +{ + VRotate vrotate; + int i; + + if(type == VROTATE_NONE) + return (VRotate)NULL; + + vrotate = (VRotate)Xmalloc(sizeof(VRotateRec) * font_data_count); + if(vrotate == (VRotate) NULL) + return False; + + memset(vrotate, 0x00, sizeof(VRotateRec) * font_data_count); + for(i = 0 ; i < font_data_count ; i++) { + vrotate[i].charset_name = font_data[i].name; + vrotate[i].side = font_data[i].side; + if(type == VROTATE_PART) { + vrotate[i].num_cr = code_range_num; + vrotate[i].code_range = code_range; + } + } + + return vrotate; +} + +static Bool +init_fontset(oc) + XOC oc; +{ + XOCGenericPart *gen; + FontSet font_set; + OMData data; + int count; + + count = XOM_GENERIC(oc->core.om)->data_num; + data = XOM_GENERIC(oc->core.om)->data; + + font_set = (FontSet) Xmalloc(sizeof(FontSetRec) * count); + if (font_set == NULL) + return False; + memset((char *) font_set, 0x00, sizeof(FontSetRec) * count); + + gen = XOC_GENERIC(oc); + gen->font_set_num = count; + gen->font_set = font_set; + + for ( ; count-- > 0; data++, font_set++) { + font_set->charset_count = data->charset_count; + font_set->charset_list = data->charset_list; + + if((font_set->font_data = init_fontdata(data->font_data, + data->font_data_count)) == NULL) + goto err; + font_set->font_data_count = data->font_data_count; + if((font_set->substitute = init_fontdata(data->substitute, + data->substitute_num)) == NULL) + goto err; + font_set->substitute_num = data->substitute_num; + if((font_set->vmap = init_fontdata(data->vmap, + data->vmap_num)) == NULL) + goto err; + font_set->vmap_num = data->vmap_num; + + if(data->vrotate_type != VROTATE_NONE) { + /* A vrotate member is specified primary font data */ + /* as initial value. */ + if((font_set->vrotate = init_vrotate(data->font_data, + data->font_data_count, + data->vrotate_type, + data->vrotate, + data->vrotate_num)) == NULL) + goto err; + font_set->vrotate_num = data->font_data_count; + } + } + return True; + +err: + if(font_set->font_data) + Xfree(font_set->font_data); + if(font_set->substitute) + Xfree(font_set->substitute); + if(font_set->vmap) + Xfree(font_set->vmap); + if(font_set->vrotate) + Xfree(font_set->vrotate); + if(font_set) + Xfree(font_set); + gen->font_set = (FontSet) NULL; + gen->font_set_num = 0; + return False; +} + +/* For VW/UDC end */ + +static char * +get_prop_name(dpy, fs) + Display *dpy; + XFontStruct *fs; +{ + unsigned long fp; + + if (falGetFontProperty(fs, XA_FONT, &fp)) + return falGetAtomName(dpy, fp); + + return (char *) NULL; +} + +static FontData +check_charset(font_set, font_name) + FontSet font_set; + char *font_name; +{ + FontData font_data; + char *last; + int count, length, name_len; + + name_len = strlen(font_name); + last = font_name + name_len; + + count = font_set->font_data_count; + font_data = font_set->font_data; + for ( ; count-- > 0; font_data++) { + length = strlen(font_data->name); + if (length > name_len) + continue; + + if (_fallcCompareISOLatin1(last - length, font_data->name) == 0) + return font_data; + } + + return (FontData) NULL; +} + +static int +check_fontname(oc, name, found_num) + XOC oc; + char *name; + int found_num; +{ + Display *dpy = oc->core.om->core.display; + XOCGenericPart *gen = XOC_GENERIC(oc); + FontData data; + FontSet font_set; + XFontStruct *fs_list; + char **fn_list, *fname, *prop_fname = NULL; + int list_num, font_set_num, i; + int list2_num; + char **fn2_list = NULL; + + fn_list = falListFonts(dpy, name, MAXFONTS, &list_num); + if (fn_list == NULL) + return found_num; + + for (i = 0; i < list_num; i++) { + fname = fn_list[i]; + + font_set = gen->font_set; + font_set_num = gen->font_set_num; + + for ( ; font_set_num-- > 0; font_set++) { + if (font_set->font_name) + continue; + + if ((data = check_charset(font_set, fname)) == NULL) { + if ((fn2_list = falListFontsWithInfo(dpy, name, MAXFONTS, + &list2_num, &fs_list)) + && (prop_fname = get_prop_name(dpy, fs_list)) + && (data = check_charset(font_set, prop_fname))) + fname = prop_fname; + } + if (data) { + font_set->side = data->side; + font_set->font_name = (char *) Xmalloc(strlen(fname) + 1); + if (font_set->font_name) { + strcpy(font_set->font_name, fname); + found_num++; + } + } + if (fn2_list) { + falFreeFontInfo(fn2_list, fs_list, list2_num); + fn2_list = NULL; + if (prop_fname) { + Xfree(prop_fname); + prop_fname = NULL; + } + } + if (found_num == gen->font_set_num) + break; + } + } + falFreeFontNames(fn_list); + return found_num; +} + + +/* For VW/UDC start */ + +static Bool +load_fontdata(oc, font_data, font_data_num) + XOC oc; + FontData font_data; + int font_data_num; +{ + Display *dpy = oc->core.om->core.display; + FontData fd = font_data; + + for( ; font_data_num-- ; fd++) { + if(fd->xlfd_name != (char *) NULL && fd->font == NULL) { + fd->font = falLoadQueryFont(dpy, fd->xlfd_name); + if (fd->font == NULL) + return False; + } + } + return True; +} + +static Bool +load_font(oc) + XOC oc; +{ + int i; + XOCGenericPart *gen = XOC_GENERIC(oc); + FontSet font_set = gen->font_set; + int num = gen->font_set_num; + + for ( ; num-- > 0; font_set++) { + if (font_set->font_name == NULL) + continue; + + if(load_fontdata(oc, font_set->font_data, + font_set->font_data_count) != True) + return False; + + if(load_fontdata(oc, font_set->substitute, + font_set->substitute_num) != True) + return False; + + if(font_set->font_data_count > 0 && font_set->font_data->font) { + font_set->font = font_set->font_data->font; + } else if(font_set->substitute_num > 0 ) { + for(i=0;isubstitute_num;i++){ + if(font_set->substitute[i].font != NULL){ + font_set->font = font_set->substitute[i].font; + } + } + } + + load_fontdata(oc, font_set->vmap, font_set->vmap_num); + load_fontdata(oc, (FontData) font_set->vrotate, + font_set->vrotate_num); + + if (font_set->font->min_byte1 || font_set->font->max_byte1) + font_set->is_xchar2b = True; + else + font_set->is_xchar2b = False; + } + + return True; +} + +/* For VW/UDC end */ + +static Bool +load_font_info(oc) + XOC oc; +{ + Display *dpy = oc->core.om->core.display; + XOCGenericPart *gen = XOC_GENERIC(oc); + FontSet font_set = gen->font_set; + char **fn_list; + int fn_num, num = gen->font_set_num; + + for ( ; num-- > 0; font_set++) { + if (font_set->font_name == NULL) + continue; + + if (font_set->info == NULL) { + fn_list = falListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num, + &font_set->info); + if (font_set->info == NULL) + return False; + + falFreeFontNames(fn_list); + } + } + + return True; +} + +/* For Vertical Writing start */ + +static void +check_fontset_extents(overall, logical_ascent, logical_descent, font) + XCharStruct *overall; + int *logical_ascent, *logical_descent; + XFontStruct *font; +{ + overall->lbearing = min(overall->lbearing, font->min_bounds.lbearing); + overall->rbearing = max(overall->rbearing, font->max_bounds.rbearing); + overall->ascent = max(overall->ascent, font->max_bounds.ascent); + overall->descent = max(overall->descent, font->max_bounds.descent); + overall->width = max(overall->width, font->max_bounds.width); + *logical_ascent = max(*logical_ascent, font->ascent); + *logical_descent = max(*logical_descent, font->descent); +} + +/* For Vertical Writing end */ + +static void +set_fontset_extents(oc) + XOC oc; +{ + XRectangle *ink = &oc->core.font_set_extents.max_ink_extent; + XRectangle *logical = &oc->core.font_set_extents.max_logical_extent; + XFontStruct **font_list, *font; + XCharStruct overall; + int logical_ascent, logical_descent; + int num = oc->core.font_info.num_font; + + font_list = oc->core.font_info.font_struct_list; + font = *font_list++; + overall = font->max_bounds; + overall.lbearing = font->min_bounds.lbearing; + logical_ascent = font->ascent; + logical_descent = font->descent; + + /* For Vertical Writing start */ + + while (--num > 0) { + font = *font_list++; + check_fontset_extents(&overall, &logical_ascent, &logical_descent, + font); + } + + { + XOCGenericPart *gen = XOC_GENERIC(oc); + FontSet font_set = gen->font_set; + FontData font_data; + int font_set_num = gen->font_set_num; + int font_data_count; + + for( ; font_set_num-- ; font_set++) { + if(font_set->vmap_num > 0) { + font_data = font_set->vmap; + font_data_count = font_set->vmap_num; + for( ; font_data_count-- ; font_data++) { + if(font_data->font != NULL) { + check_fontset_extents(&overall, &logical_ascent, + &logical_descent, + font_data->font); + } + } + } + +#ifndef COMMENT + if(font_set->vrotate_num > 0) { + font_data = (FontData) font_set->vrotate; + font_data_count = font_set->vrotate_num; + for( ; font_data_count-- ; font_data++) { + if(font_data->font != NULL) { + check_fontset_extents(&overall, &logical_ascent, + &logical_descent, + font_data->font); + } + } + } +#endif /* COMMENT */ + } + } + + /* For Vertical Writing start */ + + ink->x = overall.lbearing; + ink->y = -(overall.ascent); + ink->width = overall.rbearing - overall.lbearing; + ink->height = overall.ascent + overall.descent; + + logical->x = 0; + logical->y = -(logical_ascent); + logical->width = overall.width; + logical->height = logical_ascent + logical_descent; +} + +static Bool +init_core_part(oc) + XOC oc; +{ + XOCGenericPart *gen = XOC_GENERIC(oc); + FontSet font_set; + int font_set_num; + XFontStruct **font_struct_list; + char **font_name_list, *font_name_buf; + int count, length; + + font_set = gen->font_set; + font_set_num = gen->font_set_num; + count = length = 0; + + for ( ; font_set_num-- > 0; font_set++) { + if (font_set->font_name == NULL) + continue; + + length += strlen(font_set->font_name) + 1; + count++; + } + if (count == 0) + return False; + + font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *) * count); + if (font_struct_list == NULL) + return False; + + font_name_list = (char **) Xmalloc(sizeof(char *) * count); + if (font_name_list == NULL) + goto err; + + font_name_buf = (char *) Xmalloc(length); + if (font_name_buf == NULL) + goto err; + + oc->core.font_info.num_font = count; + oc->core.font_info.font_name_list = font_name_list; + oc->core.font_info.font_struct_list = font_struct_list; + + font_set = gen->font_set; + font_set_num = gen->font_set_num; + + for (count = 0; font_set_num-- > 0; font_set++, count++) { + if (font_set->font_name == NULL) + continue; + + font_set->id = count; + if (font_set->font) + *font_struct_list++ = font_set->font; + else + *font_struct_list++ = font_set->info; + strcpy(font_name_buf, font_set->font_name); + Xfree(font_set->font_name); + *font_name_list++ = font_set->font_name = font_name_buf; + font_name_buf += strlen(font_name_buf) + 1; + } + + set_fontset_extents(oc); + + return True; + +err: + if (font_name_list) + Xfree(font_name_list); + Xfree(font_struct_list); + + return False; +} + +static char * +get_font_name(oc, pattern) + XOC oc; + char *pattern; +{ + char **list, *name; + int count = 0; + + list = falListFonts(oc->core.om->core.display, pattern, 1, &count); + if (list == NULL) + return NULL; + + name = (char *) Xmalloc(strlen(*list) + 1); + if (name) + strcpy(name, *list); + + falFreeFontNames(list); + + return name; +} + +/* For VW/UDC start*/ + +static char +*get_rotate_fontname(font_name) + char *font_name; +{ + char *pattern = NULL, *ptr = NULL; + char *fields[CHARSET_ENCODING_FIELD]; + char str_pixel[32], str_point[4]; + char rotate_font[256]; + char *rotate_font_ptr = NULL; + int pixel_size = 0; + int field_num = 0, len = 0; + + if(font_name == (char *) NULL || (len = strlen(font_name)) <= 0) + return NULL; + + pattern = (char *)Xmalloc(len + 1); + if(!pattern) + return NULL; + strcpy(pattern, font_name); + + memset(fields, 0, sizeof(char *) * 14); + ptr = pattern; + while(isspace(*ptr)) { + ptr++; + } + if(*ptr == '-') + ptr++; + + for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && ptr && *ptr ; + ptr++, field_num++) { + fields[field_num] = ptr; + + if(ptr = strchr(ptr, '-')) { + *ptr = '\0'; + } + } + + if(field_num < CHARSET_ENCODING_FIELD) { + Xfree(pattern); + return NULL; + } + + /* Pixel Size field : fields[6] */ + for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) { + if(!isdigit(*ptr)) { + Xfree(pattern); + return NULL; + } + } + pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]); + snprintf(str_pixel, sizeof(str_pixel), "[ 0 ~%d %d 0 ]", pixel_size, pixel_size); + fields[6] = str_pixel; + + /* Point Size field : fields[7] */ + strcpy(str_point, "*"); + fields[POINT_SIZE_FIELD - 1] = str_point; + + rotate_font[0] = '\0'; + for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && + fields[field_num] ; field_num++) { + snprintf(rotate_font, sizeof(rotate_font), "%s-%s", rotate_font, fields[field_num]); + } + + if(pattern) + Xfree(pattern); + + rotate_font_ptr = (char *)Xmalloc(strlen(rotate_font) + 1); + if(!rotate_font_ptr) + return NULL; + strcpy(rotate_font_ptr, rotate_font); + + return rotate_font_ptr; +} + +static Bool +is_match_charset(font_data, font_name) + FontData font_data; + char *font_name; +{ + char *last; + int length, name_len; + + name_len = strlen(font_name); + last = font_name + name_len; + + length = strlen(font_data->name); + if (length > name_len) + return False; + + if (_fallcCompareISOLatin1(last - length, font_data->name) == 0) + return True; + + return False; +} + +static int +parse_all_name(oc, font_data, pattern) + XOC oc; + FontData font_data; + char *pattern; +{ + + if(is_match_charset(font_data, pattern) != True) + return False; + + font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1); + if(font_data->xlfd_name == NULL) + return (-1); + + strcpy(font_data->xlfd_name, pattern); + return True; +} + +static int +parse_omit_name(oc, font_data, pattern) + XOC oc; + FontData font_data; + char *pattern; +{ + char *font_name = (char *) NULL; + char *last = (char *) NULL; + char buf[BUFSIZE]; + int length = 0; + + if(is_match_charset(font_data, pattern) == True) { + strcpy(buf, pattern); + if (font_name = get_font_name(oc, buf)) { + font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1); + if(font_data->xlfd_name == NULL) { + Xfree(font_name); + return (-1); + } + strcpy(font_data->xlfd_name, font_name); + Xfree(font_name); + return True; + } + } + + snprintf(buf, sizeof(buf), "%s", pattern); + length = strlen(pattern); + last = buf + length - 1; + if (length > 1 && *last == '*' && *(last - 1) == '-') { + if (length > 3 && *(last - 2) == '*' && *(last - 3) == '-') + last -= 2; + } else { + ++last; + *last++ = '-'; + } + + strcpy(last, font_data->name); + if (font_name = get_font_name(oc, buf)) { + font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1); + if(font_data->xlfd_name == NULL) { + Xfree(font_name); + return (-1); + } + strcpy(font_data->xlfd_name, font_name); + Xfree(font_name); + return True; + } + + *last = '*'; + *(last + 1) = '-'; + strcpy(last + 2, font_data->name); + if (font_name = get_font_name(oc, buf)) { + font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1); + if(font_data->xlfd_name == NULL) { + Xfree(font_name); + return (-1); + } + strcpy(font_data->xlfd_name, font_name); + Xfree(font_name); + return True; + } + + return False; +} + + +typedef enum{C_PRIMARY, C_SUBSTITUTE, C_VMAP, C_VROTATE } ClassType; + +static int +parse_fontdata(oc, font_data, font_data_count, name_list, name_list_count, + class) + XOC oc; + FontData font_data; + int font_data_count; + char **name_list; + int name_list_count; + ClassType class; +{ + char **cur_name_list = name_list; + char *font_name = (char *) NULL; + char *pattern = (char *) NULL; + int found_num = 0, ret = 0; + int fd_count = font_data_count; + int count = name_list_count; + Bool is_found = False; + + if(name_list == NULL || count <= 0) { + return False; + } + + if(font_data == NULL || font_data_count <= 0) { + return False; + } + + for ( ; font_data_count-- > 0; font_data++) { + is_found = False; + font_name = (char *) NULL; + count = name_list_count; + cur_name_list = name_list; + while (count-- > 0) { + pattern = *cur_name_list++; + if (pattern == NULL || *pattern == '\0') + continue; + + /* When the font name is specified a full name. */ + if (strchr(pattern, '*') == NULL && + (font_name = get_font_name(oc, pattern))) { + ret = parse_all_name(oc, font_data, font_name); + Xfree(font_name); + if(ret == -1) + return ret; + else if (ret == True) { + found_num++; + is_found = True; + break; + } else + continue; + } + + /* When the font name is specified a omited name. */ + ret = parse_omit_name(oc, font_data, pattern); + if(ret == -1) + return ret; + else if (ret == True) { + found_num++; + is_found = True; + break; + } else + continue; + } + + switch(class) { + case C_PRIMARY: + if(is_found != True) + return False; + break; + case C_SUBSTITUTE: + case C_VMAP: + if(is_found == True) + return True; + break; + case C_VROTATE: + if(is_found == True) { + char *rotate_name; + + if((rotate_name = get_rotate_fontname(font_data->xlfd_name)) != + NULL) { + Xfree(font_data->xlfd_name); + font_data->xlfd_name = rotate_name; + return True; + } + Xfree(font_data->xlfd_name); + return False; + } + } + } + + if(class == C_PRIMARY && found_num == fd_count) + return True; + + return False; +} + + +static int +parse_vw(oc, font_set, name_list, count) + XOC oc; + FontSet font_set; + char **name_list; + int count; +{ + FontData vmap = font_set->vmap; + VRotate vrotate = font_set->vrotate; + int vmap_num = font_set->vmap_num; + int vrotate_num = font_set->vrotate_num; + int ret = 0, i = 0; + + if(vmap_num > 0) { + if(parse_fontdata(oc, vmap, vmap_num, name_list, count, C_VMAP) == -1) + return (-1); + } + + if(vrotate_num > 0) { + ret = parse_fontdata(oc, (FontData) vrotate, vrotate_num, + name_list, count, C_VROTATE); + if(ret == -1) { + return (-1); + } else if(ret == False) { + CodeRange code_range; + int num_cr; + int sub_num = font_set->substitute_num; + + code_range = vrotate[i].code_range; + num_cr = vrotate[i].num_cr; + for(i = 0 ; i < vrotate_num ; i++) { + if(vrotate[i].xlfd_name) + Xfree(vrotate[i].xlfd_name); + } + Xfree(vrotate); + + if(sub_num > 0) { + vrotate = font_set->vrotate = (VRotate)Xmalloc + (sizeof(VRotateRec) * sub_num); + if(font_set->vrotate == (VRotate)NULL) + return (-1); + + for(i = 0 ; i < sub_num ; i++) { + vrotate[i].charset_name = font_set->substitute[i].name; + vrotate[i].side = font_set->substitute[i].side; + vrotate[i].code_range = code_range; + vrotate[i].num_cr = num_cr; + } + vrotate_num = font_set->vrotate_num = sub_num; + } else { + font_set->vrotate = (VRotate)NULL; + } + + ret = parse_fontdata(oc, (FontData) vrotate, vrotate_num, + name_list, count, C_VROTATE); + if(ret == -1) + return (-1); + } + } + + return True; +} + +static int +parse_fontname(oc) + XOC oc; +{ + XOCGenericPart *gen = XOC_GENERIC(oc); + FontSet font_set; + char *base_name, **name_list; + int font_set_num = 0; + int found_num = 0; + int count = 0; + int ret; + int i; + + name_list = _falParseBaseFontNameList(oc->core.base_name_list, &count); + if (name_list == NULL) + return -1; + + font_set = gen->font_set; + font_set_num = gen->font_set_num; + + for( ; font_set_num-- > 0 ; font_set++) { + if(font_set->font_name) + continue; + + if(font_set->font_data_count > 0) { + ret = parse_fontdata(oc, font_set->font_data, + font_set->font_data_count, + name_list, count, C_PRIMARY); + if(ret == -1) { + goto err; + } else if(ret == True) { + font_set->font_name = (char *)Xmalloc + (strlen(font_set->font_data->xlfd_name) + 1); + if(font_set->font_name == (char *) NULL) + goto err; + strcpy(font_set->font_name, font_set->font_data->xlfd_name); + font_set->side = font_set->font_data->side; + + if(parse_vw(oc, font_set, name_list, count) == -1) + goto err; + found_num++; + + /* The substitute font is serched, when the primary fonts */ + /* is not found. */ + } else { + /* The primary information is free from FontSet structure */ + font_set->font_data_count = 0; + if(font_set->font_data) { + Xfree(font_set->font_data); + font_set->font_data = (FontData) NULL; + } + + /* A vrotate member is replaced to substitute information */ + /* from primary information. */ + font_set->vrotate_num = 0; + if(font_set->vrotate) { + Xfree(font_set->vrotate); + font_set->vrotate = (VRotate) NULL; + } + + ret = parse_fontdata(oc, font_set->substitute, + font_set->substitute_num, + name_list, count, C_SUBSTITUTE); + if(ret == -1) { + goto err; + } else if(ret == True) { + for(i=0;isubstitute_num;i++){ + if(font_set->substitute[i].xlfd_name != NULL){ + break; + } + } + font_set->font_name = (char *)Xmalloc + (strlen(font_set->substitute[i].xlfd_name) + 1); + if(font_set->font_name == (char *) NULL) + goto err; + strcpy(font_set->font_name,font_set->substitute[i].xlfd_name); + font_set->side = font_set->substitute[i].side; + if(parse_vw(oc, font_set, name_list, count) == -1) + goto err; + found_num++; + } + } + } else if(font_set->substitute_num > 0) { + ret = parse_fontdata(oc, font_set->substitute, + font_set->substitute_num, + name_list, count, C_SUBSTITUTE); + if(ret == -1) { + goto err; + } else if(ret == True) { + for(i=0;isubstitute_num;i++){ + if(font_set->substitute[i].xlfd_name != NULL){ + break; + } + } + font_set->font_name = (char *)Xmalloc + (strlen(font_set->substitute[i].xlfd_name) + 1); + if(font_set->font_name == (char *) NULL) + goto err; + strcpy(font_set->font_name,font_set->substitute[i].xlfd_name); + font_set->side = font_set->substitute[i].side; + if(parse_vw(oc, font_set, name_list, count) == -1) + goto err; + + found_num++; + } + } + } + + base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + if (base_name == NULL) + goto err; + + strcpy(base_name, oc->core.base_name_list); + oc->core.base_name_list = base_name; + + falFreeStringList(name_list); + + return found_num; + +err: + falFreeStringList(name_list); + + return -1; +} + +/* For VW/UDC end*/ + +static Bool +set_missing_list(oc) + XOC oc; +{ + XOCGenericPart *gen = XOC_GENERIC(oc); + FontSet font_set; + char **charset_list, *charset_buf; + int count, length, font_set_num; + + font_set = gen->font_set; + font_set_num = gen->font_set_num; + count = length = 0; + + for ( ; font_set_num-- > 0; font_set++) { + if (font_set->info || font_set->font) + continue; + + /* Change 1996.01.23 start */ + if(font_set->font_data_count <= 0 || + font_set->font_data == (FontData)NULL) { + if(font_set->substitute_num <= 0 || + font_set->substitute == (FontData)NULL) + if(font_set->charset_list != NULL){ + length += + strlen(font_set->charset_list[0]->encoding_name) + 1; + } else { + length += 1; + } + else + length += strlen(font_set->substitute->name) + 1; + } else { + length += strlen(font_set->font_data->name) + 1; + } + /* Change 1996.01.23 end */ + count++; + } + + if (count < 1) + return True; + + charset_list = (char **) Xmalloc(sizeof(char *) * count); + if (charset_list == NULL) + return False; + + charset_buf = (char *) Xmalloc(length); + if (charset_buf == NULL) { + Xfree(charset_list); + return False; + } + + oc->core.missing_list.charset_list = charset_list; + oc->core.missing_list.charset_count = count; + + font_set = gen->font_set; + font_set_num = gen->font_set_num; + + for ( ; font_set_num-- > 0; font_set++) { + if (font_set->info || font_set->font) + continue; + + /* Change 1996.01.23 start */ + if(font_set->font_data_count <= 0 || + font_set->font_data == (FontData)NULL) { + if(font_set->substitute_num <= 0 || + font_set->substitute == (FontData)NULL) + if(font_set->charset_list != NULL){ + strcpy(charset_buf, + font_set->charset_list[0]->encoding_name); + } else { + strcpy(charset_buf, ""); + } + else + strcpy(charset_buf, font_set->substitute->name); + } else { + strcpy(charset_buf, font_set->font_data->name); + } + /* Change 1996.01.23 end */ + *charset_list++ = charset_buf; + charset_buf += strlen(charset_buf) + 1; + } + + return True; +} + +static Bool +create_fontset(oc) + XOC oc; +{ + XOMGenericPart *gen = XOM_GENERIC(oc->core.om); + int found_num; + + if (init_fontset(oc) == False) + return False; + + found_num = parse_fontname(oc); + if (found_num <= 0) { + if (found_num == 0) + set_missing_list(oc); + return False; + } + + if (gen->on_demand_loading == True) { + if (load_font_info(oc) == False) + return False; + } else { + if (load_font(oc) == False) + return False; + } + + if (init_core_part(oc) == False) + return False; + + if (set_missing_list(oc) == False) + return False; + + return True; +} + +/* For VW/UDC start */ +static void +free_fontdataOC(dpy,font_data, font_data_count) + Display *dpy; + FontData font_data; + int font_data_count; +{ + for( ; font_data_count-- ; font_data++) { + if(font_data->xlfd_name){ + Xfree(font_data->xlfd_name); + font_data->xlfd_name = NULL; + } + if(font_data->font){ /* ADD 1996.01.7 */ + if(font_data->font->fid) /* Add 1996.01.23 */ + falFreeFont(dpy,font_data->font); /* ADD 1996.01.7 */ + else /* Add 1996.01.23 */ + falFreeFontInfo(NULL, font_data->font, 1);/* Add 1996.01.23 */ + font_data->font = NULL; + } +/* XOM to kyoutuu shite shiyou sushiteiru ryouiki + kokoha free_fontdataOM() de free sareru + + if(font_data->scopes){ + Xfree(font_data->scopes); + font_data->scopes = NULL; + } + if(font_data->name){ + Xfree(font_data->name); + font_data->name = NULL; + } +*/ + } +} + +static void +destroy_fontdata(gen,dpy) + XOCGenericPart *gen ; + Display *dpy ; +{ + FontSet font_set = (FontSet) NULL; + int font_set_num = 0; + + if (gen->font_set) { + font_set = gen->font_set; + font_set_num = gen->font_set_num; + for( ; font_set_num-- ; font_set++) { + if(font_set->font_data) { + free_fontdataOC(dpy, + font_set->font_data, font_set->font_data_count); + Xfree(font_set->font_data); + font_set->font_data = NULL; + } + if(font_set->substitute) { + free_fontdataOC(dpy, + font_set->substitute, font_set->substitute_num); + Xfree(font_set->substitute); + font_set->substitute = NULL; + } + if(font_set->vmap) { + free_fontdataOC(dpy, + font_set->vmap, font_set->vmap_num); + Xfree(font_set->vmap); + font_set->vmap = NULL; + } + if(font_set->vrotate) { + free_fontdataOC(dpy, + (FontData)font_set->vrotate, + font_set->vrotate_num); + Xfree(font_set->vrotate); + font_set->vrotate = NULL; + } + } + Xfree(gen->font_set); + gen->font_set = NULL; + } +} +/* For VW/UDC end */ + +static void +destroy_oc(oc) + XOC oc; +{ + Display *dpy = oc->core.om->core.display; + XOCGenericPart *gen = XOC_GENERIC(oc); + XFontStruct **font_list, *font; + FontSet font_set = (FontSet) NULL; + int font_set_num = 0; + int count = 0; + + if (gen->mbs_to_cs) + _fallcCloseConverter(gen->mbs_to_cs); + + if (gen->wcs_to_cs) + _fallcCloseConverter(gen->wcs_to_cs); + +/* For VW/UDC start */ /* Change 1996.01.8 */ + destroy_fontdata(gen,dpy); +/* +*/ +/* For VW/UDC end */ + + if (oc->core.base_name_list) + Xfree(oc->core.base_name_list); + + if (oc->core.font_info.font_name_list) + falFreeStringList(oc->core.font_info.font_name_list); + + if (font_list = oc->core.font_info.font_struct_list) { + Xfree(oc->core.font_info.font_struct_list); + } + + if (oc->core.missing_list.charset_list) + falFreeStringList(oc->core.missing_list.charset_list); + +#ifdef notdef + if (oc->core.res_name) + Xfree(oc->core.res_name); + if (oc->core.res_class) + Xfree(oc->core.res_class); +#endif + + Xfree(oc); +} + +static char * +set_oc_values(oc, args, num_args) + XOC oc; + XlcArgList args; + int num_args; +{ + if (oc->core.resources == NULL) + return NULL; + + return _fallcSetValues((XPointer) oc, oc->core.resources, + oc->core.num_resources, args, num_args, XlcSetMask); +} + +static char * +get_oc_values(oc, args, num_args) + XOC oc; + XlcArgList args; + int num_args; +{ + if (oc->core.resources == NULL) + return NULL; + + return _fallcGetValues((XPointer) oc, oc->core.resources, + oc->core.num_resources, args, num_args, XlcGetMask); +} + +static XOCMethodsRec oc_default_methods = { + destroy_oc, + set_oc_values, + get_oc_values, + _falmbDefaultTextEscapement, + _falmbDefaultTextExtents, + _falmbDefaultTextPerCharExtents, + _falmbDefaultDrawString, + _falmbDefaultDrawImageString, + _falwcDefaultTextEscapement, + _falwcDefaultTextExtents, + _falwcDefaultTextPerCharExtents, + _falwcDefaultDrawString, + _falwcDefaultDrawImageString +}; + +static XOCMethodsRec oc_generic_methods = { + destroy_oc, + set_oc_values, + get_oc_values, + _falmbGenericTextEscapement, + _falmbGenericTextExtents, + _falmbGenericTextPerCharExtents, + _falmbGenericDrawString, + _falmbGenericDrawImageString, + _falwcGenericTextEscapement, + _falwcGenericTextExtents, + _falwcGenericTextPerCharExtents, + _falwcGenericDrawString, + _falwcGenericDrawImageString +}; + +typedef struct _XOCMethodsListRec { + char *name; + XOCMethods methods; +} XOCMethodsListRec, *XOCMethodsList; + +static XOCMethodsListRec oc_methods_list[] = { + { "default", &oc_default_methods }, + { "generic", &oc_generic_methods } +}; + +static XlcResource oc_resources[] = { + { XNBaseFontName, NULLQUARK, sizeof(char *), + XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask }, + { XNOMAutomatic, NULLQUARK, sizeof(Bool), + XOffsetOf(XOCRec, core.om_automatic), XlcGetMask }, + { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList), + XOffsetOf(XOCRec, core.missing_list), XlcGetMask }, + { XNDefaultString, NULLQUARK, sizeof(char *), + XOffsetOf(XOCRec, core.default_string), XlcGetMask }, + { XNOrientation, NULLQUARK, sizeof(XOrientation), + XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask }, + { XNResourceName, NULLQUARK, sizeof(char *), + XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask }, + { XNResourceClass, NULLQUARK, sizeof(char *), + XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask }, + { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo), + XOffsetOf(XOCRec, core.font_info), XlcGetMask } +}; + +static XOC +create_oc(om, args, num_args) + XOM om; + XlcArgList args; + int num_args; +{ + XOC oc; + XOMGenericPart *gen = XOM_GENERIC(om); + XOCMethodsList methods_list = oc_methods_list; + int count; + + oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + if (oc == NULL) + return (XOC) NULL; + bzero((char *) oc, sizeof(XOCGenericRec)); + + oc->core.om = om; + + if (oc_resources[0].xrm_name == NULLQUARK) + _fallcCompileResourceList(oc_resources, XlcNumber(oc_resources)); + + if (_fallcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources), + args, num_args, XlcCreateMask | XlcDefaultMask)) + goto err; + + if (oc->core.base_name_list == NULL) + goto err; + + oc->core.resources = oc_resources; + oc->core.num_resources = XlcNumber(oc_resources); + + if (create_fontset(oc) == False) + goto err; + + oc->methods = &oc_generic_methods; + + if (gen->object_name) { + count = XlcNumber(oc_methods_list); + + for ( ; count-- > 0; methods_list++) { + if (!_fallcCompareISOLatin1(gen->object_name, methods_list->name)) { + oc->methods = methods_list->methods; + break; + } + } + } + + return oc; + +err: + destroy_oc(oc); + + return (XOC) NULL; +} + +static void +free_fontdataOM(font_data, font_data_count) + FontData font_data; + int font_data_count; +{ + for( ; font_data_count-- ; font_data++) { + if(font_data->name){ + Xfree(font_data->name); + font_data->name = NULL; + } + if(font_data->scopes){ + Xfree(font_data->scopes); + font_data->scopes = NULL; + } + } +} + +static Status +close_om(om) + XOM om; +{ + XOMGenericPart *gen = XOM_GENERIC(om); + OMData data; + int count; + + if (data = gen->data) { + for (count = gen->data_num; count-- > 0; data++) { + if (data->charset_list){ + Xfree(data->charset_list); + data->charset_list = NULL; + } + /* free font_data for om */ + if (data->font_data) { + free_fontdataOM(data->font_data,data->font_data_count); + Xfree(data->font_data); + data->font_data = NULL; + } + /* free substitute for om */ + if (data->substitute) { + free_fontdataOM(data->substitute,data->substitute_num); + Xfree(data->substitute); + data->substitute = NULL; + } + /* free vmap for om */ + if (data->vmap) { + free_fontdataOM(data->vmap,data->vmap_num); + Xfree(data->vmap); + data->vmap = NULL; + } + /* free vrotate for om */ + if (data->vrotate) { +#ifdef COMMENT + free_fontdataOM(data->vrotate,data->vrotate_num); +#endif /* COMMENT */ + Xfree(data->vrotate); + data->vrotate = NULL; + } + } + Xfree(gen->data); + gen->data = NULL; + } + + if (gen->object_name){ + Xfree(gen->object_name); + gen->object_name = NULL; + } + + if (om->core.res_name){ + Xfree(om->core.res_name); + om->core.res_name = NULL; + } + if (om->core.res_class){ + Xfree(om->core.res_class); + om->core.res_class = NULL; + } + if (om->core.required_charset.charset_list && + om->core.required_charset.charset_count > 0){ + falFreeStringList(om->core.required_charset.charset_list); + om->core.required_charset.charset_list = NULL; + } else { + Xfree((char*)om->core.required_charset.charset_list); + om->core.required_charset.charset_list = NULL; + } + if (om->core.orientation_list.orientation){ + Xfree(om->core.orientation_list.orientation); + om->core.orientation_list.orientation = NULL; + } + + Xfree(om); + + return 0; +} + +static char * +set_om_values(om, args, num_args) + XOM om; + XlcArgList args; + int num_args; +{ + if (om->core.resources == NULL) + return NULL; + + return _fallcSetValues((XPointer) om, om->core.resources, + om->core.num_resources, args, num_args, XlcSetMask); +} + +static char * +get_om_values(om, args, num_args) + XOM om; + XlcArgList args; + int num_args; +{ + if (om->core.resources == NULL) + return NULL; + + return _fallcGetValues((XPointer) om, om->core.resources, + om->core.num_resources, args, num_args, XlcGetMask); +} + +static XOMMethodsRec methods = { + close_om, + set_om_values, + get_om_values, + create_oc +}; + +static XlcResource om_resources[] = { + { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList), + XOffsetOf(XOMRec, core.required_charset), XlcGetMask }, + { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation), + XOffsetOf(XOMRec, core.orientation_list), XlcGetMask }, + { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool), + XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask }, + { XNContextualDrawing, NULLQUARK, sizeof(Bool), + XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask } +}; + +static XOM +create_om(lcd, dpy, rdb, res_name, res_class) + XLCd lcd; + Display *dpy; + XrmDatabase rdb; + char *res_name; + char *res_class; +{ + XOM om; + + om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + if (om == NULL) + return (XOM) NULL; + bzero((char *) om, sizeof(XOMGenericRec)); + + om->methods = &methods; + om->core.lcd = lcd; + om->core.display = dpy; + om->core.rdb = rdb; + if (res_name) { + om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1); + if (om->core.res_name == NULL) + goto err; + strcpy(om->core.res_name, res_name); + } + if (res_class) { + om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1); + if (om->core.res_class == NULL) + goto err; + strcpy(om->core.res_class, res_class); + } + + if (om_resources[0].xrm_name == NULLQUARK) + _fallcCompileResourceList(om_resources, XlcNumber(om_resources)); + + om->core.resources = om_resources; + om->core.num_resources = XlcNumber(om_resources); + + return om; + +err: + close_om(om); + + return (XOM) NULL; +} + +static OMData +add_data(om) + XOM om; +{ + XOMGenericPart *gen = XOM_GENERIC(om); + OMData new; + int num; + + if (num = gen->data_num) + new = (OMData) Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec)); + else + new = (OMData) Xmalloc(sizeof(OMDataRec)); + + if (new == NULL) + return NULL; + + gen->data_num = num + 1; + gen->data = new; + + new += num; + bzero((char *) new, sizeof(OMDataRec)); + + return new; +} + +/* For VW/UDC */ +FontData +falread_EncodingInfo(count,value) +int count; +char **value; +{ + FontData font_data,ret; + char *buf, *bufptr,*scp; + FontScope scope; + int len; + extern FontScope falparse_scopemaps(); + font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + if (font_data == NULL) + return NULL; + bzero((char *) font_data, sizeof(FontDataRec) * count); + + ret = font_data; + for ( ; count-- > 0; font_data++) { +/* + strcpy(buf, *value++); +*/ + buf = *value; value++; + if (bufptr = strchr(buf, ':')){ + len = (int)(bufptr - buf); + bufptr++ ; + } + font_data->name = (char *) Xmalloc(len + 1); + if (font_data->name == NULL) { + XFree(font_data); + return NULL; + } + strncpy(font_data->name, buf,len); + font_data->name[len] = 0; + if (bufptr && _fallcCompareISOLatin1(bufptr, "GL") == 0) + font_data->side = XlcGL; + else if (bufptr && _fallcCompareISOLatin1(bufptr, "GR") == 0) + font_data->side = XlcGR; + else + font_data->side = XlcGLGR; + + if (bufptr && (scp = strchr(bufptr, '['))){ + font_data->scopes = falparse_scopemaps(scp,&(font_data->scopes_num)); + } + } + return(ret); +} + +static CodeRange read_vrotate(count,value,type,vrotate_num) +int count; +char **value; +int *type; +int *vrotate_num; +{ + FontData font_data,ret; + char *buf, *bufptr,*scp; + CodeRange range; + extern FontScope falparse_scopemaps(); + if(!strcmp(value[0],"all")){ + *type = VROTATE_ALL ; + *vrotate_num = 0 ; + return (NULL); + } else if(*(value[0]) == '['){ + *type = VROTATE_PART ; + range = (CodeRange)falparse_scopemaps(value[0],vrotate_num); + return (range); + } else { + *type = VROTATE_NONE ; + *vrotate_num = 0 ; + return (NULL); + } +} + +static void +read_vw(lcd,font_set,num) +XLCd lcd; +OMData font_set; +int num; +{ + char **value, buf[BUFSIZ], *bufptr; + int count,i; + + snprintf(buf, sizeof(buf), "fs%d.font.vertical_map", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count > 0){ + dbg_printValue(buf,value,count); + font_set->vmap_num = count; + font_set->vmap = falread_EncodingInfo(count,value); + } + + snprintf(buf, sizeof(buf), "fs%d.font.vertical_rotate", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count > 0){ + dbg_printValue(buf,value,count); + font_set->vrotate = read_vrotate(count,value,&(font_set->vrotate_type), + &(font_set->vrotate_num)); + } +} +/* VW/UDC end */ +static Bool +init_om(om) + XOM om; +{ + XLCd lcd = om->core.lcd; + XOMGenericPart *gen = XOM_GENERIC(om); + OMData data; + XlcCharSet *charset_list; + FontData font_data; + char **required_list; + XOrientation *orientation; + char **value, buf[BUFSIZ], *bufptr; + int count = 0, num = 0, length = 0; + + _fallcGetResource(lcd, "XLC_FONTSET", "on_demand_loading", &value, &count); + if (count > 0 && _fallcCompareISOLatin1(*value, "True") == 0) + gen->on_demand_loading = True; + + _fallcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count); + if (count > 0) { + gen->object_name = (char *) Xmalloc(strlen(*value) + 1); + if (gen->object_name == NULL) + return False; + strcpy(gen->object_name, *value); + } + + for (num = 0; ; num++) { + + snprintf(buf, sizeof(buf), "fs%d.charset.name", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + + if( count < 1){ + snprintf(buf, sizeof(buf), "fs%d.charset", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count < 1) + break; + } + + data = add_data(om); + if (data == NULL) + return False; + + charset_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet) * count); + if (charset_list == NULL) + return False; + data->charset_list = charset_list; + data->charset_count = count; + + while (count-- > 0){ + *charset_list++ = _fallcGetCharSet(*value++); + } + snprintf(buf, sizeof(buf), "fs%d.charset.udc_area", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if( count > 0){ + UDCArea udc; + int i,flag = 0; + udc = (UDCArea)Xmalloc(count * sizeof(UDCAreaRec)); + if (udc == NULL) + return False; + for(i=0;icharset_count;i++){ + if(data->charset_list[i]->udc_area == NULL){ + data->charset_list[i]->udc_area = udc; + data->charset_list[i]->udc_area_num = count; + flag = 1; + } + } + if(flag == 0){ + Xfree(udc); + } + } + + snprintf(buf, sizeof(buf), "fs%d.font.primary", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count < 1){ + snprintf(buf, sizeof(buf), "fs%d.font", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count < 1) + return False; + } + + font_data = falread_EncodingInfo(count,value); + if (font_data == NULL) + return False; + + data->font_data = font_data; + data->font_data_count = count; + + snprintf(buf, sizeof(buf), "fs%d.font.substitute", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count > 0){ + font_data = falread_EncodingInfo(count,value); + if (font_data == NULL) + return False; + data->substitute = font_data; + data->substitute_num = count; + } else { + snprintf(buf, sizeof(buf), "fs%d.font", num); + _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count); + if (count < 1) { + data->substitute = NULL; + data->substitute_num = 0; + } else { + font_data = falread_EncodingInfo(count,value); + data->substitute = font_data; + data->substitute_num = count; + } + } + read_vw(lcd,data,num); + length += strlen(data->font_data->name) + 1; + } + + /* required charset list */ + required_list = (char **) Xmalloc(sizeof(char *) * gen->data_num); + if (required_list == NULL) + return False; + + bufptr = (char *) Xmalloc(length); + if (bufptr == NULL) { + Xfree(required_list); + return False; + } + + om->core.required_charset.charset_list = required_list; + om->core.required_charset.charset_count = gen->data_num; + + count = gen->data_num; + data = gen->data; + + for ( ; count-- > 0; data++) { + strcpy(bufptr, data->font_data->name); + *required_list++ = bufptr; + bufptr += strlen(bufptr) + 1; + } + + /* orientation list */ + orientation = (XOrientation *) Xmalloc(sizeof(XOrientation) * 2); + if (orientation == NULL) + return False; + + orientation[0] = XOMOrientation_LTR_TTB; + orientation[1] = XOMOrientation_TTB_RTL; + om->core.orientation_list.orientation = orientation; + om->core.orientation_list.num_orientation = 2; + + /* directional dependent drawing */ + om->core.directional_dependent = False; + + /* contexual drawing */ + om->core.contextual_drawing = False; + + /* context dependent */ + om->core.context_dependent = False; + + return True; +} + +XOM +#if NeedFunctionPrototypes +_falomGenericOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, + _Xconst char *res_name, _Xconst char *res_class) +#else +_falomGenericOpenOM(lcd, dpy, rdb, res_name, res_class) + XLCd lcd; + Display *dpy; + XrmDatabase rdb; + char *res_name; + char *res_class; +#endif +{ + XOM om; + + om = create_om(lcd, dpy, rdb, res_name, res_class); + if (om == NULL) + return (XOM) NULL; + + if (init_om(om) == False) + goto err; + + return om; + +err: + close_om(om); + + return (XOM) NULL; +} + +Bool +_falInitOM(lcd) + XLCd lcd; +{ + lcd->methods->open_om = _falomGenericOpenOM; + + return True; +} diff --git a/cde/programs/dtudcfonted/libfal/_falomGeneric.h b/cde/programs/dtudcfonted/libfal/_falomGeneric.h new file mode 100644 index 00000000..0a27a418 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falomGeneric.h @@ -0,0 +1,204 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* XomGeneric.h 1.6 - Fujitsu source for CDEnext 96/02/29 18:02:52 */ +/* $XConsortium: _falomGeneric.h /main/1 1996/04/08 15:20:29 cde-fuj $ */ +/* + * Copyright 1992, 1993 by TOSHIBA Corp. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of TOSHIBA not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. TOSHIBA make no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Author: Katsuhisa Yano TOSHIBA Corp. + * mopi@osa.ilab.toshiba.co.jp + */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ + +#ifndef _XOMGENERIC_H_ +#define _XOMGENERIC_H_ + +#include "_fallcPublic.h" + +#define XOM_GENERIC(om) (&((XOMGeneric) om)->gen) +#define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen) + +/* For VW/UDC */ +typedef struct _CodeRangeRec { + unsigned long start; + unsigned long end; + unsigned long dmy1; + unsigned long dmy2; +} CodeRangeRec, *CodeRange; + +typedef struct _VRotateRec { + char *charset_name; /* Charset name */ + XlcSide side; /* Encoding side */ + int num_cr; + CodeRange code_range; + char *xlfd_name; + XFontStruct *font; +} VRotateRec, *VRotate; + +typedef enum { + XOMMultiByte, + XOMWideChar +} XOMTextType; + +typedef struct _FontDataRec { + char *name; + XlcSide side; + /* For VW/UDC */ + int scopes_num; + FontScope scopes; + char *xlfd_name; + XFontStruct *font; +} FontDataRec, *FontData; + +#define VROTATE_NONE 0 +#define VROTATE_PART 1 +#define VROTATE_ALL 2 + +typedef struct _OMDataRec { + int charset_count; + XlcCharSet *charset_list; + int font_data_count; + FontData font_data; + /* For VW/UDC */ + int substitute_num; + FontData substitute; + /* Vertical Writing */ + int vmap_num; + FontData vmap; + int vrotate_type; + int vrotate_num; + CodeRange vrotate; +} OMDataRec, *OMData; + +typedef struct _XOMGenericPart { + int data_num; + OMData data; + Bool on_demand_loading; + char *object_name; +} XOMGenericPart; + +typedef struct _XOMGenericRec { + XOMMethods methods; + XOMCoreRec core; + XOMGenericPart gen; +} XOMGenericRec, *XOMGeneric; + +/* + * XOC dependent data + */ + +typedef struct _FontSetRec { + int id; + int charset_count; + XlcCharSet *charset_list; + int font_data_count; + FontData font_data; + char *font_name; + XFontStruct *info; + XFontStruct *font; + XlcSide side; + Bool is_xchar2b; + /* For VW/UDC */ + int substitute_num; + FontData substitute; + /* Vertical Writing */ + int vmap_num; + FontData vmap; + int vrotate_num; + VRotate vrotate; +} FontSetRec, *FontSet; + +typedef struct _XOCGenericPart { + XlcConv mbs_to_cs; + XlcConv wcs_to_cs; + int font_set_num; + FontSet font_set; +} XOCGenericPart; + +typedef struct _XOCGenericRec { + XOCMethods methods; + XOCCoreRec core; + XOCGenericPart gen; +} XOCGenericRec, *XOCGeneric; + +_XFUNCPROTOBEGIN + +extern XOM _falomGenericOpenOM( +#if NeedFunctionPrototypes + XLCd /* lcd */, + Display* /* dpy */, + XrmDatabase /* rdb */, + _Xconst char* /* res_name */, + _Xconst char* /* res_class */ +#endif +); + +extern XlcConv _XomInitConverter( +#if NeedFunctionPrototypes + XOC /* oc */, + XOMTextType /* type */ +#endif +); + +extern int _XomConvert( +#if NeedFunctionPrototypes + XOC /* oc */, + XlcConv /* conv */, + XPointer* /* from */, + int* /* from_left */, + XPointer* /* to */, + int* /* to_left */, + XPointer* /* args */, + int /* num_args */ +#endif +); + +_XFUNCPROTOEND + +#endif /* _XOMGENERIC_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_falrm.c b/cde/programs/dtudcfonted/libfal/_falrm.c new file mode 100644 index 00000000..38573d48 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falrm.c @@ -0,0 +1,2624 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* Xrm.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:11 */ +/* $XConsortium: _falrm.c /main/1 1996/04/08 15:21:43 cde-fuj $ */ + +/*********************************************************** +Copyright 1987, 1988, 1990 by Digital Equipment Corporation, Maynard + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ +/* + +Copyright (c) 1987, 1988, 1990 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +#include +#include +#include "_fallibint.h" +#include +#include "_fallcint.h" +#ifdef XTHREADS +#include "_falloking.h" +#endif +#include "_falrmI.h" +#include + +#ifdef __STDC__ +#define Const const +#else +#define Const /**/ +#endif +#if defined(__STDC__) && !defined(NORCONST) +#define RConst const +#else +#define RConst /**/ +#endif + +/* + +These Xrm routines allow very fast lookup of resources in the resource +database. Several usage patterns are exploited: + +(1) Widgets get a lot of resources at one time. Rather than look up each from +scratch, we can precompute the prioritized list of database levels once, then +search for each resource starting at the beginning of the list. + +(2) Many database levels don't contain any leaf resource nodes. There is no +point in looking for resources on a level that doesn't contain any. This +information is kept on a per-level basis. + +(3) Sometimes the widget instance tree is structured such that you get the same +class name repeated on the fully qualified widget name. This can result in the +same database level occurring multiple times on the search list. The code below +only checks to see if you get two identical search lists in a row, rather than +look back through all database levels, but in practice this removes all +duplicates I've ever observed. + +Joel McCormack + +*/ + +/* + +The Xrm representation has been completely redesigned to substantially reduce +memory and hopefully improve performance. + +The database is structured into two kinds of tables: LTables that contain +only values, and NTables that contain only other tables. + +Some invariants: + +The next pointer of the top-level node table points to the top-level leaf +table, if any. + +Within an LTable, for a given name, the tight value always precedes the +loose value, and if both are present the loose value is always right after +the tight value. + +Within an NTable, all of the entries for a given name are contiguous, +in the order tight NTable, loose NTable, tight LTable, loose LTable. + +Bob Scheifler + +*/ + +typedef unsigned long Signature; + +static XrmQuark XrmQString, XrmQANY; + +typedef Bool (*DBEnumProc)( +#if NeedNestedPrototypes /* this is Nested on purpose, to match Xlib.h */ + XrmDatabase* /* db */, + XrmBindingList /* bindings */, + XrmQuarkList /* quarks */, + XrmRepresentation* /* type */, + XrmValue* /* value */, + XPointer /* closure */ +#endif +); + +typedef struct _VEntry { + struct _VEntry *next; /* next in chain */ + XrmQuark name; /* name of this entry */ + unsigned int tight:1; /* 1 if it is a tight binding */ + unsigned int string:1; /* 1 if type is String */ + unsigned int size:30; /* size of value */ +} VEntryRec, *VEntry; + + +typedef struct _DEntry { + VEntryRec entry; /* entry */ + XrmRepresentation type; /* representation type */ +} DEntryRec, *DEntry; + +/* the value is right after the structure */ +#define StringValue(ve) (XPointer)((ve) + 1) +#define RepType(ve) ((DEntry)(ve))->type +/* the value is right after the structure */ +#define DataValue(ve) (XPointer)(((DEntry)(ve)) + 1) +#define RawValue(ve) (char *)((ve)->string ? StringValue(ve) : DataValue(ve)) + +typedef struct _NTable { + struct _NTable *next; /* next in chain */ + XrmQuark name; /* name of this entry */ + unsigned int tight:1; /* 1 if it is a tight binding */ + unsigned int leaf:1; /* 1 if children are values */ + unsigned int hasloose:1; /* 1 if has loose children */ + unsigned int hasany:1; /* 1 if has ANY entry */ + unsigned int pad:4; /* unused */ + unsigned int mask:8; /* hash size - 1 */ + unsigned int entries:16; /* number of children */ +} NTableRec, *NTable; + +/* the buckets are right after the structure */ +#define NodeBuckets(ne) ((NTable *)((ne) + 1)) +#define NodeHash(ne,q) NodeBuckets(ne)[(q) & (ne)->mask] + +/* leaf tables have an extra level of indirection for the buckets, + * so that resizing can be done without invalidating a search list. + * This is completely ugly, and wastes some memory, but the Xlib + * spec doesn't really specify whether invalidation is OK, and the + * old implementation did not invalidate. + */ +typedef struct _LTable { + NTableRec table; + VEntry *buckets; +} LTableRec, *LTable; + +#define LeafHash(le,q) (le)->buckets[(q) & (le)->table.mask] + +/* An XrmDatabase just holds a pointer to the first top-level table. + * The type name is no longer descriptive, but better to not change + * the Xresource.h header file. This type also gets used to define + * XrmSearchList, which is a complete crock, but we'll just leave it + * and caste types as required. + */ +typedef struct _XrmHashBucketRec { + NTable table; + XPointer mbstate; + XrmMethods methods; +#ifdef XTHREADS + LockInfoRec linfo; +#endif +} XrmHashBucketRec; + +/* closure used in get/put resource */ +typedef struct _VClosure { + XrmRepresentation *type; /* type of value */ + XrmValuePtr value; /* value itself */ +} VClosureRec, *VClosure; + +/* closure used in get search list */ +typedef struct _SClosure { + LTable *list; /* search list */ + int idx; /* index of last filled element */ + int limit; /* maximum index */ +} SClosureRec, *SClosure; + +/* placed in XrmSearchList to indicate next table is loose only */ +#define LOOSESEARCH ((LTable)1) + +/* closure used in enumerate database */ +typedef struct _EClosure { + XrmDatabase db; /* the database */ + DBEnumProc proc; /* the user proc */ + XPointer closure; /* the user closure */ + XrmBindingList bindings; /* binding list */ + XrmQuarkList quarks; /* quark list */ + int mode; /* XrmEnum */ +} EClosureRec, *EClosure; + +/* predicate to determine when to resize a hash table */ +#define GrowthPred(n,m) ((unsigned)(n) > (((m) + 1) << 2)) + +#define GROW(prev) \ + if (GrowthPred((*prev)->entries, (*prev)->mask)) \ + GrowTable(prev) + +/* pick a reasonable value for maximum depth of resource database */ +#define MAXDBDEPTH 100 + +/* macro used in get/search functions */ + +/* find an entry named ename, with leafness given by leaf */ +#define NFIND(ename) \ + q = ename; \ + entry = NodeHash(table, q); \ + while (entry && entry->name != q) \ + entry = entry->next; \ + if (leaf && entry && !entry->leaf) { \ + entry = entry->next; \ + if (entry && !entry->leaf) \ + entry = entry->next; \ + if (entry && entry->name != q) \ + entry = (NTable)NULL; \ + } + +/* resourceQuarks keeps track of what quarks have been associated with values + * in all LTables. If a quark has never been used in an LTable, we don't need + * to bother looking for it. + */ + +static unsigned char *resourceQuarks = (unsigned char *)NULL; +static XrmQuark maxResourceQuark = -1; + +/* determines if a quark has been used for a value in any database */ +#define IsResourceQuark(q) ((q) > 0 && (q) <= maxResourceQuark && \ + resourceQuarks[(q) >> 3] & (1 << ((q) & 7))) + +typedef unsigned char XrmBits; + +#define BSLASH ((XrmBits) (1 << 5)) +#define NORMAL ((XrmBits) (1 << 4)) +#define EOQ ((XrmBits) (1 << 3)) +#define SEP ((XrmBits) (1 << 2)) +#define ENDOF ((XrmBits) (1 << 1)) +#define SPACE (NORMAL|EOQ|SEP|(XrmBits)0) +#define RSEP (NORMAL|EOQ|SEP|(XrmBits)1) +#define EOS (EOQ|SEP|ENDOF|(XrmBits)0) +#define EOL (EOQ|SEP|ENDOF|(XrmBits)1) +#define BINDING (NORMAL|EOQ) +#define ODIGIT (NORMAL|(XrmBits)1) + +#define next_char(ch,str) xrmtypes[(unsigned char)((ch) = *(++(str)))] +#define next_mbchar(ch,len,str) xrmtypes[(unsigned char)(ch = (*db->methods->mbchar)(db->mbstate, str, &len), str += len, ch)] + +#define is_space(bits) ((bits) == SPACE) +#define is_EOQ(bits) ((bits) & EOQ) +#define is_EOF(bits) ((bits) == EOS) +#define is_EOL(bits) ((bits) & ENDOF) +#define is_binding(bits) ((bits) == BINDING) +#define is_odigit(bits) ((bits) == ODIGIT) +#define is_separator(bits) ((bits) & SEP) +#define is_nonpcs(bits) (!(bits)) +#define is_normal(bits) ((bits) & NORMAL) +#define is_simple(bits) ((bits) & (NORMAL|BSLASH)) +#define is_special(bits) ((bits) & (ENDOF|BSLASH)) + +/* parsing types */ +static XrmBits Const xrmtypes[256] = { + EOS,0,0,0,0,0,0,0, + 0,SPACE,EOL,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + SPACE,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,BINDING,NORMAL,NORMAL,NORMAL,BINDING,NORMAL, + ODIGIT,ODIGIT,ODIGIT,ODIGIT,ODIGIT,ODIGIT,ODIGIT,ODIGIT, + NORMAL,NORMAL,RSEP,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,BSLASH,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL, + NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,NORMAL,0 + /* The rest will be automatically initialized to zero. */ +}; + +void falrmInitialize() +{ + XrmQString = falrmPermStringToQuark("String"); + XrmQANY = falrmPermStringToQuark("?"); +} + +XrmDatabase falrmGetDatabase(display) + Display *display; +{ + XrmDatabase retval; + LockDisplay(display); + retval = display->db; + UnlockDisplay(display); + return retval; +} + +void falrmSetDatabase(display, database) + Display *display; + XrmDatabase database; +{ + LockDisplay(display); + display->db = database; + UnlockDisplay(display); +} + +#if NeedFunctionPrototypes +void falrmStringToQuarkList( + register _Xconst char *name, + register XrmQuarkList quarks) /* RETURN */ +#else +void falrmStringToQuarkList(name, quarks) + register char *name; + register XrmQuarkList quarks; /* RETURN */ +#endif +{ + register XrmBits bits; + register Signature sig = 0; + register char ch, *tname; + register int i = 0; + + if (tname = (char *)name) { + tname--; + while (!is_EOF(bits = next_char(ch, tname))) { + if (is_binding (bits)) { + if (i) { + /* Found a complete name */ + *quarks++ = _falrmInternalStringToQuark(name,tname - name, + sig, False); + i = 0; + sig = 0; + } + name = tname+1; + } + else { + sig = (sig << 1) + ch; /* Compute the signature. */ + i++; + } + } + *quarks++ = _falrmInternalStringToQuark(name, tname - name, sig, False); + } + *quarks = NULLQUARK; +} + +#if NeedFunctionPrototypes +void falrmStringToBindingQuarkList( + register _Xconst char *name, + register XrmBindingList bindings, /* RETURN */ + register XrmQuarkList quarks) /* RETURN */ +#else +void falrmStringToBindingQuarkList(name, bindings, quarks) + register char *name; + register XrmBindingList bindings; /* RETURN */ + register XrmQuarkList quarks; /* RETURN */ +#endif +{ + register XrmBits bits; + register Signature sig = 0; + register char ch, *tname; + register XrmBinding binding; + register int i = 0; + + if (tname = (char *)name) { + tname--; + binding = XrmBindTightly; + while (!is_EOF(bits = next_char(ch, tname))) { + if (is_binding (bits)) { + if (i) { + /* Found a complete name */ + *bindings++ = binding; + *quarks++ = _falrmInternalStringToQuark(name, tname - name, + sig, False); + + i = 0; + sig = 0; + binding = XrmBindTightly; + } + name = tname+1; + + if (ch == '*') + binding = XrmBindLoosely; + } + else { + sig = (sig << 1) + ch; /* Compute the signature. */ + i++; + } + } + *bindings = binding; + *quarks++ = _falrmInternalStringToQuark(name, tname - name, sig, False); + } + *quarks = NULLQUARK; +} + +#ifdef DEBUG + +static void PrintQuarkList(quarks, stream) + XrmQuarkList quarks; + FILE *stream; +{ + Bool firstNameSeen; + + for (firstNameSeen = False; *quarks; quarks++) { + if (firstNameSeen) { + (void) fprintf(stream, "."); + } + firstNameSeen = True; + (void) fputs(falrmQuarkToString(*quarks), stream); + } +} /* PrintQuarkList */ + +#endif /* DEBUG */ + +/*ARGSUSED*/ +static void mbnoop(state) + XPointer state; +{ +} + +/*ARGSUSED*/ +static char mbchar(state, str, lenp) + XPointer state; + char *str; + int *lenp; +{ + *lenp = 1; + return *str; +} + +/*ARGSUSED*/ +static char *lcname(state) + XPointer state; +{ + return "C"; +} + +static RConst XrmMethodsRec mb_methods = { + mbnoop, + mbchar, + mbnoop, + lcname, + mbnoop +}; + +static XrmDatabase NewDatabase() +{ + register XrmDatabase db; + + db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec)); + if (db) { + _XCreateMutex(&db->linfo); + db->table = (NTable)NULL; + db->methods = _falrmInitParseInfo(&db->mbstate); + if (!db->methods) + db->methods = (XrmMethods)&mb_methods; + } + return db; +} + +/* move all values from ftable to ttable, and free ftable's buckets. + * ttable is quaranteed empty to start with. + */ +static void MoveValues(ftable, ttable) + LTable ftable; + register LTable ttable; +{ + register VEntry fentry, nfentry; + register VEntry *prev; + register VEntry *bucket; + register VEntry tentry; + register int i; + + for (i = ftable->table.mask, bucket = ftable->buckets; i >= 0; i--) { + for (fentry = *bucket++; fentry; fentry = nfentry) { + prev = &LeafHash(ttable, fentry->name); + tentry = *prev; + *prev = fentry; + /* chain on all with same name, to preserve invariant order */ + while ((nfentry = fentry->next) && nfentry->name == fentry->name) + fentry = nfentry; + fentry->next = tentry; + } + } + Xfree((char *)ftable->buckets); +} + +/* move all tables from ftable to ttable, and free ftable. + * ttable is quaranteed empty to start with. + */ +static void MoveTables(ftable, ttable) + NTable ftable; + register NTable ttable; +{ + register NTable fentry, nfentry; + register NTable *prev; + register NTable *bucket; + register NTable tentry; + register int i; + + for (i = ftable->mask, bucket = NodeBuckets(ftable); i >= 0; i--) { + for (fentry = *bucket++; fentry; fentry = nfentry) { + prev = &NodeHash(ttable, fentry->name); + tentry = *prev; + *prev = fentry; + /* chain on all with same name, to preserve invariant order */ + while ((nfentry = fentry->next) && nfentry->name == fentry->name) + fentry = nfentry; + fentry->next = tentry; + } + } + Xfree((char *)ftable); +} + +/* grow the table, based on current number of entries */ +static void GrowTable(prev) + NTable *prev; +{ + register NTable table; + register int i; + + table = *prev; + i = table->mask; + if (i == 255) /* biggest it gets */ + return; + while (i < 255 && GrowthPred(table->entries, i)) + i = (i << 1) + 1; + i++; /* i is now the new size */ + if (table->leaf) { + register LTable ltable; + LTableRec otable; + + ltable = (LTable)table; + /* cons up a copy to make MoveValues look symmetric */ + otable = *ltable; + ltable->buckets = (VEntry *)Xmalloc(i * sizeof(VEntry)); + if (!ltable->buckets) { + ltable->buckets = otable.buckets; + return; + } + ltable->table.mask = i - 1; + bzero((char *)ltable->buckets, i * sizeof(VEntry)); + MoveValues(&otable, ltable); + } else { + register NTable ntable; + + ntable = (NTable)Xmalloc(sizeof(NTableRec) + i * sizeof(NTable)); + if (!ntable) + return; + *ntable = *table; + ntable->mask = i - 1; + bzero((char *)NodeBuckets(ntable), i * sizeof(NTable)); + *prev = ntable; + MoveTables(table, ntable); + } +} + +/* merge values from ftable into *pprev, destroy ftable in the process */ +static void MergeValues(ftable, pprev, override) + LTable ftable; + NTable *pprev; + Bool override; +{ + register VEntry fentry, tentry; + register VEntry *prev; + register LTable ttable; + VEntry *bucket; + int i; + register XrmQuark q; + + ttable = (LTable)*pprev; + if (ftable->table.hasloose) + ttable->table.hasloose = 1; + for (i = ftable->table.mask, bucket = ftable->buckets; + i >= 0; + i--, bucket++) { + for (fentry = *bucket; fentry; ) { + q = fentry->name; + prev = &LeafHash(ttable, q); + tentry = *prev; + while (tentry && tentry->name != q) + tentry = *(prev = &tentry->next); + /* note: test intentionally uses fentry->name instead of q */ + /* permits serendipitous inserts */ + while (tentry && tentry->name == fentry->name) { + /* if tentry is earlier, skip it */ + if (!fentry->tight && tentry->tight) { + tentry = *(prev = &tentry->next); + continue; + } + if (fentry->tight != tentry->tight) { + /* no match, chain in fentry */ + *prev = fentry; + prev = &fentry->next; + fentry = *prev; + *prev = tentry; + ttable->table.entries++; + } else if (override) { + /* match, chain in fentry, splice out and free tentry */ + *prev = fentry; + prev = &fentry->next; + fentry = *prev; + *prev = tentry->next; + /* free the overridden entry */ + Xfree((char *)tentry); + /* get next tentry */ + tentry = *prev; + } else { + /* match, discard fentry */ + prev = &tentry->next; + tentry = fentry; /* use as a temp var */ + fentry = fentry->next; + /* free the overpowered entry */ + Xfree((char *)tentry); + /* get next tentry */ + tentry = *prev; + } + if (!fentry) + break; + } + /* at this point, tentry cannot match any fentry named q */ + /* chain in all bindings together, preserve invariant order */ + while (fentry && fentry->name == q) { + *prev = fentry; + prev = &fentry->next; + fentry = *prev; + *prev = tentry; + ttable->table.entries++; + } + } + } + Xfree((char *)ftable->buckets); + Xfree((char *)ftable); + /* resize if necessary, now that we're all done */ + GROW(pprev); +} + +/* merge tables from ftable into *pprev, destroy ftable in the process */ +static void MergeTables(ftable, pprev, override) + NTable ftable; + NTable *pprev; + Bool override; +{ + register NTable fentry, tentry; + NTable nfentry; + register NTable *prev; + register NTable ttable; + NTable *bucket; + int i; + register XrmQuark q; + + ttable = *pprev; + if (ftable->hasloose) + ttable->hasloose = 1; + if (ftable->hasany) + ttable->hasany = 1; + for (i = ftable->mask, bucket = NodeBuckets(ftable); + i >= 0; + i--, bucket++) { + for (fentry = *bucket; fentry; ) { + q = fentry->name; + prev = &NodeHash(ttable, q); + tentry = *prev; + while (tentry && tentry->name != q) + tentry = *(prev = &tentry->next); + /* note: test intentionally uses fentry->name instead of q */ + /* permits serendipitous inserts */ + while (tentry && tentry->name == fentry->name) { + /* if tentry is earlier, skip it */ + if ((fentry->leaf && !tentry->leaf) || + (!fentry->tight && tentry->tight && + (fentry->leaf || !tentry->leaf))) { + tentry = *(prev = &tentry->next); + continue; + } + nfentry = fentry->next; + if (fentry->leaf != tentry->leaf || + fentry->tight != tentry->tight) { + /* no match, just chain in */ + *prev = fentry; + *(prev = &fentry->next) = tentry; + ttable->entries++; + } else { + if (fentry->leaf) + MergeValues((LTable)fentry, prev, override); + else + MergeTables(fentry, prev, override); + /* bump to next tentry */ + tentry = *(prev = &(*prev)->next); + } + /* bump to next fentry */ + fentry = nfentry; + if (!fentry) + break; + } + /* at this point, tentry cannot match any fentry named q */ + /* chain in all bindings together, preserve invariant order */ + while (fentry && fentry->name == q) { + *prev = fentry; + prev = &fentry->next; + fentry = *prev; + *prev = tentry; + ttable->entries++; + } + } + } + Xfree((char *)ftable); + /* resize if necessary, now that we're all done */ + GROW(pprev); +} + +void falrmCombineDatabase(from, into, override) + XrmDatabase from, *into; + Bool override; +{ + register NTable *prev; + register NTable ftable, ttable, nftable; + + if (!*into) { + *into = from; + } else if (from) { + _XLockMutex(&from->linfo); + _XLockMutex(&(*into)->linfo); + if (ftable = from->table) { + prev = &(*into)->table; + ttable = *prev; + if (!ftable->leaf) { + nftable = ftable->next; + if (ttable && !ttable->leaf) { + /* both have node tables, merge them */ + MergeTables(ftable, prev, override); + /* bump to into's leaf table, if any */ + ttable = *(prev = &(*prev)->next); + } else { + /* into has no node table, link from's in */ + *prev = ftable; + *(prev = &ftable->next) = ttable; + } + /* bump to from's leaf table, if any */ + ftable = nftable; + } else { + /* bump to into's leaf table, if any */ + if (ttable && !ttable->leaf) + ttable = *(prev = &ttable->next); + } + if (ftable) { + /* if into has a leaf, merge, else insert */ + if (ttable) + MergeValues((LTable)ftable, prev, override); + else + *prev = ftable; + } + } + (from->methods->destroy)(from->mbstate); + _XFreeMutex(&from->linfo); + Xfree((char *)from); + _XUnlockMutex(&(*into)->linfo); + } +} + +void falrmMergeDatabases(from, into) + XrmDatabase from, *into; +{ + falrmCombineDatabase(from, into, True); +} + +/* store a value in the database, overriding any existing entry */ +static void PutEntry(db, bindings, quarks, type, value) + XrmDatabase db; + XrmBindingList bindings; + XrmQuarkList quarks; + XrmRepresentation type; + XrmValuePtr value; +{ + register NTable *pprev, *prev; + register NTable table; + register XrmQuark q; + register VEntry *vprev; + register VEntry entry; + NTable *nprev, *firstpprev; + +#define NEWTABLE(q,i) \ + table = (NTable)Xmalloc(sizeof(LTableRec)); \ + if (!table) \ + return; \ + table->name = q; \ + table->hasloose = 0; \ + table->hasany = 0; \ + table->mask = 0; \ + table->entries = 0; \ + if (quarks[i]) { \ + table->leaf = 0; \ + nprev = NodeBuckets(table); \ + } else { \ + table->leaf = 1; \ + if (!(nprev = (NTable *)Xmalloc(sizeof(VEntry *)))) \ + return; \ + ((LTable)table)->buckets = (VEntry *)nprev; \ + } \ + *nprev = (NTable)NULL; \ + table->next = *prev; \ + *prev = table + + if (!db || !*quarks) + return; + table = *(prev = &db->table); + /* if already at leaf, bump to the leaf table */ + if (!quarks[1] && table && !table->leaf) + table = *(prev = &table->next); + pprev = prev; + if (!table || (quarks[1] && table->leaf)) { + /* no top-level node table, create one and chain it in */ + NEWTABLE(NULLQUARK,1); + table->tight = 1; /* arbitrary */ + prev = nprev; + } else { + /* search along until we need a value */ + while (quarks[1]) { + q = *quarks; + table = *(prev = &NodeHash(table, q)); + while (table && table->name != q) + table = *(prev = &table->next); + if (!table) + break; /* not found */ + if (quarks[2]) { + if (table->leaf) + break; /* not found */ + } else { + if (!table->leaf) { + /* bump to leaf table, if any */ + table = *(prev = &table->next); + if (!table || table->name != q) + break; /* not found */ + if (!table->leaf) { + /* bump to leaf table, if any */ + table = *(prev = &table->next); + if (!table || table->name != q) + break; /* not found */ + } + } + } + if (*bindings == XrmBindTightly) { + if (!table->tight) + break; /* not found */ + } else { + if (table->tight) { + /* bump to loose table, if any */ + table = *(prev = &table->next); + if (!table || table->name != q || + !quarks[2] != table->leaf) + break; /* not found */ + } + } + /* found that one, bump to next quark */ + pprev = prev; + quarks++; + bindings++; + } + if (!quarks[1]) { + /* found all the way to a leaf */ + q = *quarks; + entry = *(vprev = &LeafHash((LTable)table, q)); + while (entry && entry->name != q) + entry = *(vprev = &entry->next); + /* if want loose and have tight, bump to next entry */ + if (entry && *bindings == XrmBindLoosely && entry->tight) + entry = *(vprev = &entry->next); + if (entry && entry->name == q && + (*bindings == XrmBindTightly) == entry->tight) { + /* match, need to override */ + if ((type == XrmQString) == entry->string && + entry->size == value->size) { + /* update type if not String, can be different */ + if (!entry->string) + RepType(entry) = type; + /* identical size, just overwrite value */ + memcpy(RawValue(entry), (char *)value->addr, value->size); + return; + } + /* splice out and free old entry */ + *vprev = entry->next; + Xfree((char *)entry); + (*pprev)->entries--; + } + /* this is where to insert */ + prev = (NTable *)vprev; + } + } + /* keep the top table, because we may have to grow it */ + firstpprev = pprev; + /* iterate until we get to the leaf */ + while (quarks[1]) { + /* build a new table and chain it in */ + NEWTABLE(*quarks,2); + if (*quarks++ == XrmQANY) + (*pprev)->hasany = 1; + if (*bindings++ == XrmBindTightly) { + table->tight = 1; + } else { + table->tight = 0; + (*pprev)->hasloose = 1; + } + (*pprev)->entries++; + pprev = prev; + prev = nprev; + } + /* now allocate the value entry */ + entry = (VEntry)Xmalloc(((type == XrmQString) ? + sizeof(VEntryRec) : sizeof(DEntryRec)) + + value->size); + if (!entry) + return; + entry->name = q = *quarks; + if (*bindings == XrmBindTightly) { + entry->tight = 1; + } else { + entry->tight = 0; + (*pprev)->hasloose = 1; + } + /* chain it in, with a bit of type cast ugliness */ + entry->next = *((VEntry *)prev); + *((VEntry *)prev) = entry; + entry->size = value->size; + if (type == XrmQString) { + entry->string = 1; + } else { + entry->string = 0; + RepType(entry) = type; + } + /* save a copy of the value */ + memcpy(RawValue(entry), (char *)value->addr, value->size); + (*pprev)->entries++; + /* this is a new leaf, need to remember it for search lists */ + if (q > maxResourceQuark) { + unsigned oldsize = (maxResourceQuark + 1) >> 3; + unsigned size = ((q | 0x7f) + 1) >> 3; /* reallocate in chunks */ + if (resourceQuarks) + resourceQuarks = (unsigned char *)Xrealloc((char *)resourceQuarks, + size); + else + resourceQuarks = (unsigned char *)Xmalloc(size); + if (resourceQuarks) { + bzero((char *)&resourceQuarks[oldsize], size - oldsize); + maxResourceQuark = (size << 3) - 1; + } else { + maxResourceQuark = -1; + } + } + if (q > 0 && resourceQuarks) + resourceQuarks[q >> 3] |= 1 << (q & 0x7); + GROW(firstpprev); + +#undef NEWTABLE +} + +void falrmQPutResource(pdb, bindings, quarks, type, value) + XrmDatabase *pdb; + XrmBindingList bindings; + XrmQuarkList quarks; + XrmRepresentation type; + XrmValuePtr value; +{ + if (!*pdb) *pdb = NewDatabase(); + _XLockMutex(&(*pdb)->linfo); + PutEntry(*pdb, bindings, quarks, type, value); + _XUnlockMutex(&(*pdb)->linfo); +} + +#if NeedFunctionPrototypes +void falrmPutResource( + XrmDatabase *pdb, + _Xconst char *specifier, + _Xconst char *type, + XrmValuePtr value) +#else +void falrmPutResource(pdb, specifier, type, value) + XrmDatabase *pdb; + char *specifier; + char *type; + XrmValuePtr value; +#endif +{ + XrmBinding bindings[MAXDBDEPTH+1]; + XrmQuark quarks[MAXDBDEPTH+1]; + + if (!*pdb) *pdb = NewDatabase(); + _XLockMutex(&(*pdb)->linfo); + falrmStringToBindingQuarkList(specifier, bindings, quarks); + PutEntry(*pdb, bindings, quarks, falrmStringToQuark(type), value); + _XUnlockMutex(&(*pdb)->linfo); +} + +#if NeedFunctionPrototypes +void falrmQPutStringResource( + XrmDatabase *pdb, + XrmBindingList bindings, + XrmQuarkList quarks, + _Xconst char *str) +#else +void falrmQPutStringResource(pdb, bindings, quarks, str) + XrmDatabase *pdb; + XrmBindingList bindings; + XrmQuarkList quarks; + char *str; +#endif +{ + XrmValue value; + + if (!*pdb) *pdb = NewDatabase(); + value.addr = (XPointer) str; + value.size = strlen(str)+1; + _XLockMutex(&(*pdb)->linfo); + PutEntry(*pdb, bindings, quarks, XrmQString, &value); + _XUnlockMutex(&(*pdb)->linfo); +} + +/* Function Name: GetDatabase + * Description: Parses a string and stores it as a database. + * Arguments: db - the database. + * str - a pointer to the string containing the database. + * filename - source filename, if any. + * doall - whether to do all lines or just one + */ + +/* + * This function is highly optimized to inline as much as possible. + * Be very careful with modifications, or simplifications, as they + * may adversely affect the performance. + * + * Chris Peterson, MIT X Consortium 5/17/90. + */ + +#define LIST_SIZE 101 +#define BUFFER_SIZE 100 + +static void GetIncludeFile(); + +static void GetDatabase(db, str, filename, doall) + XrmDatabase db; + register char *str; + char *filename; + Bool doall; +{ + register char *ptr; + register XrmBits bits = 0; + register char c; + int len; + register Signature sig; + register char *ptr_max; + register XrmQuarkList t_quarks; + register XrmBindingList t_bindings; + + int alloc_chars = BUFSIZ; + char buffer[BUFSIZ], *value_str; + XrmQuark quarks[LIST_SIZE]; + XrmBinding bindings[LIST_SIZE]; + XrmValue value; + Bool only_pcs; + Bool dolines; + + if (!db) + return; + + if (!(value_str = Xmalloc(sizeof(char) * alloc_chars))) + return; + + (*db->methods->mbinit)(db->mbstate); + str--; + dolines = True; + while (!is_EOF(bits) && dolines) { + dolines = doall; + + /* + * First: Remove extra whitespace. + */ + + do { + bits = next_char(c, str); + } while is_space(bits); + + /* + * Ignore empty lines. + */ + + if (is_EOL(bits)) + continue; /* start a new line. */ + + /* + * Second: check the first character in a line to see if it is + * "!" signifying a comment, or "#" signifying a directive. + */ + + if (c == '!') { /* Comment, spin to next newline */ + while (is_simple(bits = next_char(c, str))) {} + if (is_EOL(bits)) + continue; + while (!is_EOL(bits = next_mbchar(c, len, str))) {} + str--; + continue; /* start a new line. */ + } + + if (c == '#') { /* Directive */ + /* remove extra whitespace */ + only_pcs = True; + while (is_space(bits = next_char(c, str))) {}; + /* only "include" directive is currently defined */ + if (!strncmp(str, "include", 7)) { + str += (7-1); + /* remove extra whitespace */ + while (is_space(bits = next_char(c, str))) {}; + /* must have a starting " */ + if (c == '"') { + char *fname = str+1; + len = 0; + do { + if (only_pcs) { + bits = next_char(c, str); + if (is_nonpcs(bits)) + only_pcs = False; + } + if (!only_pcs) + bits = next_mbchar(c, len, str); + } while (c != '"' && !is_EOL(bits)); + /* must have an ending " */ + if (c == '"') + GetIncludeFile(db, filename, fname, str - len - fname); + } + } + /* spin to next newline */ + if (only_pcs) { + while (is_simple(bits)) + bits = next_char(c, str); + if (is_EOL(bits)) + continue; + } + while (!is_EOL(bits)) + bits = next_mbchar(c, len, str); + str--; + continue; /* start a new line. */ + } + + /* + * Third: loop through the LHS of the resource specification + * storing characters and converting this to a Quark. + * + * If the number of quarks is greater than LIST_SIZE - 1. This + * function will trash your memory. + * + * If the length of any quark is larger than BUFSIZ this function + * will also trash memory. + */ + + t_bindings = bindings; + t_quarks = quarks; + + sig = 0; + ptr = buffer; + *t_bindings = XrmBindTightly; + for(;;) { + if (!is_binding(bits)) { + while (!is_EOQ(bits)) { + *ptr++ = c; + sig = (sig << 1) + c; /* Compute the signature. */ + bits = next_char(c, str); + } + + *t_quarks++ = _falrmInternalStringToQuark(buffer, ptr - buffer, + sig, False); + + if (is_separator(bits)) { + if (!is_space(bits)) + break; + + /* Remove white space */ + do { + *ptr++ = c; + sig = (sig << 1) + c; /* Compute the signature. */ + } while (is_space(bits = next_char(c, str))); + + /* + * The spec doesn't permit it, but support spaces + * internal to resource name/class + */ + + if (is_separator(bits)) + break; + t_quarks--; + continue; + } + + if (c == '.') + *(++t_bindings) = XrmBindTightly; + else + *(++t_bindings) = XrmBindLoosely; + + sig = 0; + ptr = buffer; + } + else { + /* + * Magic unspecified feature #254. + * + * If two separators appear with no Text between them then + * ignore them. + * + * If anyone of those separators is a '*' then the binding + * will be loose, otherwise it will be tight. + */ + + if (c == '*') + *t_bindings = XrmBindLoosely; + } + + bits = next_char(c, str); + } + + *t_quarks = NULLQUARK; + + /* + * Make sure that there is a ':' in this line. + */ + + if (c != ':') { + char oldc; + + /* + * A parsing error has occurred, toss everything on the line + * a new_line can still be escaped with a '\'. + */ + + while (is_normal(bits)) + bits = next_char(c, str); + if (is_EOL(bits)) + continue; + bits = next_mbchar(c, len, str); + do { + oldc = c; + bits = next_mbchar(c, len, str); + } while (c && (c != '\n' || oldc == '\\')); + str--; + continue; + } + + /* + * I now have a quark and binding list for the entire left hand + * side. "c" currently points to the ":" separating the left hand + * side for the right hand side. It is time to begin processing + * the right hand side. + */ + + /* + * Fourth: Remove more whitespace + */ + + for(;;) { + if (is_space(bits = next_char(c, str))) + continue; + if (c != '\\') + break; + bits = next_char(c, str); + if (c == '\n') + continue; + str--; + bits = BSLASH; + c = '\\'; + break; + } + + /* + * Fifth: Process the right hand side. + */ + + ptr = value_str; + ptr_max = ptr + alloc_chars - 4; + only_pcs = True; + len = 1; + + for(;;) { + + /* + * Tight loop for the normal case: Non backslash, non-end of value + * character that will fit into the allocated buffer. + */ + + if (only_pcs) { + while (is_normal(bits) && ptr < ptr_max) { + *ptr++ = c; + bits = next_char(c, str); + } + if (is_EOL(bits)) + break; + if (is_nonpcs(bits)) { + only_pcs = False; + bits = next_mbchar(c, len, str); + } + } + while (!is_special(bits) && ptr + len <= ptr_max) { + len = -len; + while (len) + *ptr++ = str[len++]; + bits = next_mbchar(c, len, str); + } + + if (is_EOL(bits)) { + str--; + break; + } + + if (c == '\\') { + /* + * We need to do some magic after a backslash. + */ + Bool read_next = True; + + if (only_pcs) { + bits = next_char(c, str); + if (is_nonpcs(bits)) + only_pcs = False; + } + if (!only_pcs) + bits = next_mbchar(c, len, str); + + if (is_EOL(bits)) { + if (is_EOF(bits)) + continue; + } else if (c == 'n') { + /* + * "\n" means insert a newline. + */ + *ptr++ = '\n'; + } else if (c == '\\') { + /* + * "\\" completes to just one backslash. + */ + *ptr++ = '\\'; + } else { + /* + * pick up to three octal digits after the '\'. + */ + char temp[3]; + int count = 0; + while (is_odigit(bits) && count < 3) { + temp[count++] = c; + if (only_pcs) { + bits = next_char(c, str); + if (is_nonpcs(bits)) + only_pcs = False; + } + if (!only_pcs) + bits = next_mbchar(c, len, str); + } + + /* + * If we found three digits then insert that octal code + * into the value string as a character. + */ + + if (count == 3) { + *ptr++ = (unsigned char) ((temp[0] - '0') * 0100 + + (temp[1] - '0') * 010 + + (temp[2] - '0')); + } + else { + int tcount; + + /* + * Otherwise just insert those characters into the + * string, since no special processing is needed on + * numerics we can skip the special processing. + */ + + for (tcount = 0; tcount < count; tcount++) { + *ptr++ = temp[tcount]; /* print them in + the correct order */ + } + } + read_next = False; + } + if (read_next) { + if (only_pcs) { + bits = next_char(c, str); + if (is_nonpcs(bits)) + only_pcs = False; + } + if (!only_pcs) + bits = next_mbchar(c, len, str); + } + } + + /* + * It is important to make sure that there is room for at least + * four more characters in the buffer, since I can add that + * many characters into the buffer after a backslash has occurred. + */ + + if (ptr + len > ptr_max) { + char * temp_str; + + alloc_chars += BUFSIZ/10; + temp_str = Xrealloc(value_str, sizeof(char) * alloc_chars); + + if (!temp_str) { + Xfree(value_str); + (*db->methods->mbfinish)(db->mbstate); + return; + } + + ptr = temp_str + (ptr - value_str); /* reset pointer. */ + value_str = temp_str; + ptr_max = value_str + alloc_chars - 4; + } + } + + /* + * Lastly: Terminate the value string, and store this entry + * into the database. + */ + + *ptr++ = '\0'; + + /* Store it in database */ + value.size = ptr - value_str; + value.addr = (XPointer) value_str; + + PutEntry(db, bindings, quarks, XrmQString, &value); + } + + Xfree(value_str); + (*db->methods->mbfinish)(db->mbstate); +} + +#if NeedFunctionPrototypes +void falrmPutStringResource( + XrmDatabase *pdb, + _Xconst char*specifier, + _Xconst char*str) +#else +void falrmPutStringResource(pdb, specifier, str) + XrmDatabase *pdb; + char *specifier; + char *str; +#endif +{ + XrmValue value; + XrmBinding bindings[MAXDBDEPTH+1]; + XrmQuark quarks[MAXDBDEPTH+1]; + + if (!*pdb) *pdb = NewDatabase(); + falrmStringToBindingQuarkList(specifier, bindings, quarks); + value.addr = (XPointer) str; + value.size = strlen(str)+1; + _XLockMutex(&(*pdb)->linfo); + PutEntry(*pdb, bindings, quarks, XrmQString, &value); + _XUnlockMutex(&(*pdb)->linfo); +} + + +#if NeedFunctionPrototypes +void falrmPutLineResource( + XrmDatabase *pdb, + _Xconst char*line) +#else +void falrmPutLineResource(pdb, line) + XrmDatabase *pdb; + char *line; +#endif +{ + if (!*pdb) *pdb = NewDatabase(); + _XLockMutex(&(*pdb)->linfo); + GetDatabase(*pdb, line, (char *)NULL, False); + _XUnlockMutex(&(*pdb)->linfo); +} + +#if NeedFunctionPrototypes +XrmDatabase falrmGetStringDatabase( + _Xconst char *data) +#else +XrmDatabase falrmGetStringDatabase(data) + char *data; +#endif +{ + XrmDatabase db; + + db = NewDatabase(); + _XLockMutex(&db->linfo); + GetDatabase(db, data, (char *)NULL, True); + _XUnlockMutex(&db->linfo); + return db; +} + +/* Function Name: ReadInFile + * Description: Reads the file into a buffer. + * Arguments: filename - the name of the file. + * Returns: An allocated string containing the contents of the file. + */ + +static char * +ReadInFile(filename) +char * filename; +{ + register int fd, size; + char * filebuf; + + if ( (fd = OpenFile(filename)) == -1 ) + return (char *)NULL; + + GetSizeOfFile(filename, size); + + if (!(filebuf = Xmalloc(size + 1))) { /* leave room for '\0' */ + close(fd); + return (char *)NULL; + } + + size = ReadFile(fd, filebuf, size); + if (size < 0) { + CloseFile(fd); + Xfree(filebuf); + return (char *)NULL; + } + CloseFile(fd); + + filebuf[size] = '\0'; /* NULL terminate it. */ + return filebuf; +} + +static void +GetIncludeFile(db, base, fname, fnamelen) + XrmDatabase db; + char *base; + char *fname; + int fnamelen; +{ + int len; + char *str; + char realfname[BUFSIZ]; + + if (fnamelen <= 0 || fnamelen >= BUFSIZ) + return; + if (*fname != '/' && base && (str = strrchr(base, '/'))) { + len = str - base + 1; + if (len + fnamelen >= BUFSIZ) + return; + strncpy(realfname, base, len); + strncpy(realfname + len, fname, fnamelen); + realfname[len + fnamelen] = '\0'; + } else { + strncpy(realfname, fname, fnamelen); + realfname[fnamelen] = '\0'; + } + if (!(str = ReadInFile(realfname))) + return; + GetDatabase(db, str, realfname, True); + Xfree(str); +} + +#if NeedFunctionPrototypes +XrmDatabase falrmGetFileDatabase( + _Xconst char *filename) +#else +XrmDatabase falrmGetFileDatabase(filename) + char *filename; +#endif +{ + XrmDatabase db; + char *str; + + if (!(str = ReadInFile(filename))) + return (XrmDatabase)NULL; + + db = NewDatabase(); + _XLockMutex(&db->linfo); + GetDatabase(db, str, filename, True); + _XUnlockMutex(&db->linfo); + Xfree(str); + return db; +} + +#if NeedFunctionPrototypes +Status falrmCombineFileDatabase( + _Xconst char *filename, + XrmDatabase *target, + Bool override) +#else +Status falrmCombineFileDatabase(filename, target, override) + char *filename; + XrmDatabase *target; + Bool override; +#endif +{ + XrmDatabase db; + char *str; + + if (!(str = ReadInFile(filename))) + return 0; + if (override) { + db = *target; + if (!db) + *target = db = NewDatabase(); + } else + db = NewDatabase(); + _XLockMutex(&db->linfo); + GetDatabase(db, str, filename, True); + _XUnlockMutex(&db->linfo); + Xfree(str); + if (!override) + falrmCombineDatabase(db, target, False); + return 1; +} + +/* call the user proc for every value in the table, arbitrary order. + * stop if user proc returns True. level is current depth in database. + */ +/*ARGSUSED*/ +static Bool EnumLTable(table, names, classes, level, closure) + LTable table; + XrmNameList names; + XrmClassList classes; + register int level; + register EClosure closure; +{ + register VEntry *bucket; + register int i; + register VEntry entry; + XrmValue value; + XrmRepresentation type; + Bool tightOk; + + closure->bindings[level] = (table->table.tight ? + XrmBindTightly : XrmBindLoosely); + closure->quarks[level] = table->table.name; + level++; + tightOk = !*names; + closure->quarks[level + 1] = NULLQUARK; + for (i = table->table.mask, bucket = table->buckets; + i >= 0; + i--, bucket++) { + for (entry = *bucket; entry; entry = entry->next) { + if (entry->tight && !tightOk) + continue; + closure->bindings[level] = (entry->tight ? + XrmBindTightly : XrmBindLoosely); + closure->quarks[level] = entry->name; + value.size = entry->size; + if (entry->string) { + type = XrmQString; + value.addr = StringValue(entry); + } else { + type = RepType(entry); + value.addr = DataValue(entry); + } + if ((*closure->proc)(&closure->db, closure->bindings+1, + closure->quarks+1, &type, &value, + closure->closure)) + return True; + } + } + return False; +} + +static Bool EnumAllNTable(table, level, closure) + NTable table; + register int level; + register EClosure closure; +{ + register NTable *bucket; + register int i; + register NTable entry; + XrmQuark empty = NULLQUARK; + + if (level >= MAXDBDEPTH) + return False; + for (i = table->mask, bucket = NodeBuckets(table); + i >= 0; + i--, bucket++) { + for (entry = *bucket; entry; entry = entry->next) { + if (entry->leaf) { + if (EnumLTable((LTable)entry, &empty, &empty, level, closure)) + return True; + } else { + closure->bindings[level] = (entry->tight ? + XrmBindTightly : XrmBindLoosely); + closure->quarks[level] = entry->name; + if (EnumAllNTable(entry, level+1, closure)) + return True; + } + } + } + return False; +} + +/* recurse on every table in the table, arbitrary order. + * stop if user proc returns True. level is current depth in database. + */ +static Bool EnumNTable(table, names, classes, level, closure) + NTable table; + XrmNameList names; + XrmClassList classes; + register int level; + register EClosure closure; +{ + register NTable entry; + register XrmQuark q; + register unsigned int leaf; + Bool (*get)(); + Bool bilevel; + +/* find entries named ename, leafness leaf, tight or loose, and call get */ +#define ITIGHTLOOSE(ename) \ + NFIND(ename); \ + if (entry) { \ + if (leaf == entry->leaf) { \ + if (!leaf && !entry->tight && entry->next && \ + entry->next->name == q && entry->next->tight && \ + (bilevel || entry->next->hasloose) && \ + EnumLTable((LTable)entry->next, names+1, classes+1, \ + level, closure)) \ + return True; \ + if ((*get)(entry, names+1, classes+1, level, closure)) \ + return True; \ + if (entry->tight && (entry = entry->next) && \ + entry->name == q && leaf == entry->leaf && \ + (*get)(entry, names+1, classes+1, level, closure)) \ + return True; \ + } else if (entry->leaf) { \ + if ((bilevel || entry->hasloose) && \ + EnumLTable((LTable)entry, names+1, classes+1, level, closure))\ + return True; \ + if (entry->tight && (entry = entry->next) && \ + entry->name == q && (bilevel || entry->hasloose) && \ + EnumLTable((LTable)entry, names+1, classes+1, level, closure))\ + return True; \ + } \ + } + +/* find entries named ename, leafness leaf, loose only, and call get */ +#define ILOOSE(ename) \ + NFIND(ename); \ + if (entry && entry->tight && (entry = entry->next) && entry->name != q) \ + entry = (NTable)NULL; \ + if (entry) { \ + if (leaf == entry->leaf) { \ + if ((*get)(entry, names+1, classes+1, level, closure)) \ + return True; \ + } else if (entry->leaf && (bilevel || entry->hasloose)) { \ + if (EnumLTable((LTable)entry, names+1, classes+1, level, closure))\ + return True; \ + } \ + } + + if (level >= MAXDBDEPTH) + return False; + closure->bindings[level] = (table->tight ? + XrmBindTightly : XrmBindLoosely); + closure->quarks[level] = table->name; + level++; + if (!*names) { + if (EnumAllNTable(table, level, closure)) + return True; + } else { + if (names[1] || closure->mode == XrmEnumAllLevels) { + get = EnumNTable; /* recurse */ + leaf = 0; + bilevel = !names[1]; + } else { + get = EnumLTable; /* bottom of recursion */ + leaf = 1; + bilevel = False; + } + if (table->hasloose && closure->mode == XrmEnumAllLevels) { + NTable *bucket; + int i; + XrmQuark empty = NULLQUARK; + + for (i = table->mask, bucket = NodeBuckets(table); + i >= 0; + i--, bucket++) { + q = NULLQUARK; + for (entry = *bucket; entry; entry = entry->next) { + if (!entry->tight && entry->name != q && + entry->name != *names && entry->name != *classes) { + q = entry->name; + if (entry->leaf) { + if (EnumLTable((LTable)entry, &empty, &empty, + level, closure)) + return True; + } else { + if (EnumNTable(entry, &empty, &empty, + level, closure)) + return True; + } + } + } + } + } + + ITIGHTLOOSE(*names); /* do name, tight and loose */ + ITIGHTLOOSE(*classes); /* do class, tight and loose */ + if (table->hasany) { + ITIGHTLOOSE(XrmQANY); /* do ANY, tight and loose */ + } + if (table->hasloose) { + while (1) { + names++; + classes++; + if (!*names) + break; + if (!names[1] && closure->mode != XrmEnumAllLevels) { + get = EnumLTable; /* bottom of recursion */ + leaf = 1; + } + ILOOSE(*names); /* loose names */ + ILOOSE(*classes); /* loose classes */ + if (table->hasany) { + ILOOSE(XrmQANY); /* loose ANY */ + } + } + names--; + classes--; + } + } + /* now look for matching leaf nodes */ + entry = table->next; + if (!entry) + return False; + if (entry->leaf) { + if (entry->tight && !table->tight) + entry = entry->next; + } else { + entry = entry->next; + if (!entry || !entry->tight) + return False; + } + if (!entry || entry->name != table->name) + return False; + /* found one */ + level--; + if ((!*names || entry->hasloose) && + EnumLTable((LTable)entry, names, classes, level, closure)) + return True; + if (entry->tight && entry == table->next && (entry = entry->next) && + entry->name == table->name && (!*names || entry->hasloose)) + return EnumLTable((LTable)entry, names, classes, level, closure); + return False; + +#undef ITIGHTLOOSE +#undef ILOOSE +} + +/* call the proc for every value in the database, arbitrary order. + * stop if the proc returns True. + */ +Bool falrmEnumerateDatabase(db, names, classes, mode, proc, closure) + XrmDatabase db; + XrmNameList names; + XrmClassList classes; + int mode; + DBEnumProc proc; + XPointer closure; +{ + XrmBinding bindings[MAXDBDEPTH+2]; + XrmQuark quarks[MAXDBDEPTH+2]; + register NTable table; + EClosureRec eclosure; + Bool retval = False; + + if (!db) + return False; + _XLockMutex(&db->linfo); + eclosure.db = db; + eclosure.proc = proc; + eclosure.closure = closure; + eclosure.bindings = bindings; + eclosure.quarks = quarks; + eclosure.mode = mode; + table = db->table; + if (table && !table->leaf && !*names && mode == XrmEnumOneLevel) + table = table->next; + if (table) { + if (!table->leaf) + retval = EnumNTable(table, names, classes, 0, &eclosure); + else + retval = EnumLTable((LTable)table, names, classes, 0, &eclosure); + } + _XUnlockMutex(&db->linfo); + return retval; +} + +static void PrintBindingQuarkList(bindings, quarks, stream) + XrmBindingList bindings; + XrmQuarkList quarks; + FILE *stream; +{ + Bool firstNameSeen; + + for (firstNameSeen = False; *quarks; bindings++, quarks++) { + if (*bindings == XrmBindLoosely) { + (void) fprintf(stream, "*"); + } else if (firstNameSeen) { + (void) fprintf(stream, "."); + } + firstNameSeen = True; + (void) fputs(falrmQuarkToString(*quarks), stream); + } +} + +/* output out the entry in correct file syntax */ +/*ARGSUSED*/ +static Bool DumpEntry(db, bindings, quarks, type, value, data) + XrmDatabase *db; + XrmBindingList bindings; + XrmQuarkList quarks; + XrmRepresentation *type; + XrmValuePtr value; + XPointer data; +{ + FILE *stream = (FILE *)data; + register unsigned int i; + register char *s; + register char c; + + if (*type != XrmQString) + (void) putc('!', stream); + PrintBindingQuarkList(bindings, quarks, stream); + s = value->addr; + i = value->size; + if (*type == XrmQString) { + (void) fputs(":\t", stream); + if (i) + i--; + } + else + (void) fprintf(stream, "=%s:\t", XrmRepresentationToString(*type)); + if (i && (*s == ' ' || *s == '\t')) + (void) putc('\\', stream); /* preserve leading whitespace */ + while (i--) { + c = *s++; + if (c == '\n') { + if (i) + (void) fputs("\\n\\\n", stream); + else + (void) fputs("\\n", stream); + } else if (c == '\\') + (void) fputs("\\\\", stream); + else if ((c < ' ' && c != '\t') || + ((unsigned char)c >= 0x7f && (unsigned char)c < 0xa0)) + (void) fprintf(stream, "\\%03o", (unsigned char)c); + else + (void) putc(c, stream); + } + (void) putc('\n', stream); + return ferror(stream) != 0; +} + +#ifdef DEBUG + +void falPrintTable(table, file) + NTable table; + FILE *file; +{ + XrmBinding bindings[MAXDBDEPTH+1]; + XrmQuark quarks[MAXDBDEPTH+1]; + EClosureRec closure; + XrmQuark empty = NULLQUARK; + + closure.db = (XrmDatabase)NULL; + closure.proc = DumpEntry; + closure.closure = (XPointer)file; + closure.bindings = bindings; + closure.quarks = quarks; + closure.mode = XrmEnumAllLevels; + if (table->leaf) + EnumLTable((LTable)table, &empty, &empty, 0, &closure); + else + EnumNTable(table, &empty, &empty, 0, &closure); +} + +#endif /* DEBUG */ + +#if NeedFunctionPrototypes +void falrmPutFileDatabase( + XrmDatabase db, + _Xconst char *fileName) +#else +void falrmPutFileDatabase(db, fileName) + XrmDatabase db; + char *fileName; +#endif +{ + FILE *file; + XrmQuark empty = NULLQUARK; + + if (!db) return; + if (!(file = fopen(fileName, "w"))) return; + if (falrmEnumerateDatabase(db, &empty, &empty, XrmEnumAllLevels, + DumpEntry, (XPointer) file)) + unlink((char *)fileName); + fclose(file); +} + +/* macros used in get/search functions */ + +/* find entries named ename, leafness leaf, tight or loose, and call get */ +#define GTIGHTLOOSE(ename,looseleaf) \ + NFIND(ename); \ + if (entry) { \ + if (leaf == entry->leaf) { \ + if (!leaf && !entry->tight && entry->next && \ + entry->next->name == q && entry->next->tight && \ + entry->next->hasloose && \ + looseleaf((LTable)entry->next, names+1, classes+1, closure)) \ + return True; \ + if ((*get)(entry, names+1, classes+1, closure)) \ + return True; \ + if (entry->tight && (entry = entry->next) && \ + entry->name == q && leaf == entry->leaf && \ + (*get)(entry, names+1, classes+1, closure)) \ + return True; \ + } else if (entry->leaf) { \ + if (entry->hasloose && \ + looseleaf((LTable)entry, names+1, classes+1, closure)) \ + return True; \ + if (entry->tight && (entry = entry->next) && \ + entry->name == q && entry->hasloose && \ + looseleaf((LTable)entry, names+1, classes+1, closure)) \ + return True; \ + } \ + } + +/* find entries named ename, leafness leaf, loose only, and call get */ +#define GLOOSE(ename,looseleaf) \ + NFIND(ename); \ + if (entry && entry->tight && (entry = entry->next) && entry->name != q) \ + entry = (NTable)NULL; \ + if (entry) { \ + if (leaf == entry->leaf) { \ + if ((*get)(entry, names+1, classes+1, closure)) \ + return True; \ + } else if (entry->leaf && entry->hasloose) { \ + if (looseleaf((LTable)entry, names+1, classes+1, closure)) \ + return True; \ + } \ + } + +/* add tight/loose entry to the search list, return True if list is full */ +/*ARGSUSED*/ +static Bool AppendLEntry(table, names, classes, closure) + LTable table; + XrmNameList names; + XrmClassList classes; + register SClosure closure; +{ + /* check for duplicate */ + if (closure->idx >= 0 && closure->list[closure->idx] == table) + return False; + if (closure->idx == closure->limit) + return True; + /* append it */ + closure->idx++; + closure->list[closure->idx] = table; + return False; +} + +/* add loose entry to the search list, return True if list is full */ +/*ARGSUSED*/ +static Bool AppendLooseLEntry(table, names, classes, closure) + LTable table; + XrmNameList names; + XrmClassList classes; + register SClosure closure; +{ + /* check for duplicate */ + if (closure->idx >= 0 && closure->list[closure->idx] == table) + return False; + if (closure->idx >= closure->limit - 1) + return True; + /* append it */ + closure->idx++; + closure->list[closure->idx] = LOOSESEARCH; + closure->idx++; + closure->list[closure->idx] = table; + return False; +} + +/* search for a leaf table */ +static Bool SearchNEntry(table, names, classes, closure) + NTable table; + XrmNameList names; + XrmClassList classes; + SClosure closure; +{ + register NTable entry; + register XrmQuark q; + register unsigned int leaf; + Bool (*get)(); + + if (names[1]) { + get = SearchNEntry; /* recurse */ + leaf = 0; + } else { + get = AppendLEntry; /* bottom of recursion */ + leaf = 1; + } + GTIGHTLOOSE(*names, AppendLooseLEntry); /* do name, tight and loose */ + GTIGHTLOOSE(*classes, AppendLooseLEntry); /* do class, tight and loose */ + if (table->hasany) { + GTIGHTLOOSE(XrmQANY, AppendLooseLEntry); /* do ANY, tight and loose */ + } + if (table->hasloose) { + while (1) { + names++; + classes++; + if (!*names) + break; + if (!names[1]) { + get = AppendLEntry; /* bottom of recursion */ + leaf = 1; + } + GLOOSE(*names, AppendLooseLEntry); /* loose names */ + GLOOSE(*classes, AppendLooseLEntry); /* loose classes */ + if (table->hasany) { + GLOOSE(XrmQANY, AppendLooseLEntry); /* loose ANY */ + } + } + } + /* now look for matching leaf nodes */ + entry = table->next; + if (!entry) + return False; + if (entry->leaf) { + if (entry->tight && !table->tight) + entry = entry->next; + } else { + entry = entry->next; + if (!entry || !entry->tight) + return False; + } + if (!entry || entry->name != table->name) + return False; + /* found one */ + if (entry->hasloose && + AppendLooseLEntry((LTable)entry, names, classes, closure)) + return True; + if (entry->tight && entry == table->next && (entry = entry->next) && + entry->name == table->name && entry->hasloose) + return AppendLooseLEntry((LTable)entry, names, classes, closure); + return False; +} + +Bool falrmQGetSearchList(db, names, classes, searchList, listLength) + XrmDatabase db; + XrmNameList names; + XrmClassList classes; + XrmSearchList searchList; /* RETURN */ + int listLength; +{ + register NTable table; + SClosureRec closure; + + if (listLength <= 0) + return False; + closure.list = (LTable *)searchList; + closure.idx = -1; + closure.limit = listLength - 2; + if (db) { + _XLockMutex(&db->linfo); + table = db->table; + if (*names) { + if (table && !table->leaf) { + if (SearchNEntry(table, names, classes, &closure)) { + _XUnlockMutex(&db->linfo); + return False; + } + } else if (table && table->hasloose && + AppendLooseLEntry((LTable)table, names, classes, + &closure)) { + _XUnlockMutex(&db->linfo); + return False; + } + } else { + if (table && !table->leaf) + table = table->next; + if (table && + AppendLEntry((LTable)table, names, classes, &closure)) { + _XUnlockMutex(&db->linfo); + return False; + } + } + _XUnlockMutex(&db->linfo); + } + closure.list[closure.idx + 1] = (LTable)NULL; + return True; +} + +Bool falrmQGetSearchResource(searchList, name, class, pType, pValue) + XrmSearchList searchList; + register XrmName name; + register XrmClass class; + XrmRepresentation *pType; /* RETURN */ + XrmValue *pValue; /* RETURN */ +{ + register LTable *list; + register LTable table; + register VEntry entry; + int flags; + +/* find tight or loose entry */ +#define VTIGHTLOOSE(q) \ + entry = LeafHash(table, q); \ + while (entry && entry->name != q) \ + entry = entry->next; \ + if (entry) \ + break + +/* find loose entry */ +#define VLOOSE(q) \ + entry = LeafHash(table, q); \ + while (entry && entry->name != q) \ + entry = entry->next; \ + if (entry) { \ + if (!entry->tight) \ + break; \ + if ((entry = entry->next) && entry->name == q) \ + break; \ + } + + list = (LTable *)searchList; + /* figure out which combination of name and class we need to search for */ + flags = 0; + if (IsResourceQuark(name)) + flags = 2; + if (IsResourceQuark(class)) + flags |= 1; + if (!flags) { + /* neither name nor class has ever been used to name a resource */ + table = (LTable)NULL; + } else if (flags == 3) { + /* both name and class */ + while (table = *list++) { + if (table != LOOSESEARCH) { + VTIGHTLOOSE(name); /* do name, tight and loose */ + VTIGHTLOOSE(class); /* do class, tight and loose */ + } else { + table = *list++; + VLOOSE(name); /* do name, loose only */ + VLOOSE(class); /* do class, loose only */ + } + } + } else { + /* just one of name or class */ + if (flags == 1) + name = class; + while (table = *list++) { + if (table != LOOSESEARCH) { + VTIGHTLOOSE(name); /* tight and loose */ + } else { + table = *list++; + VLOOSE(name); /* loose only */ + } + } + } + if (table) { + /* found a match */ + if (entry->string) { + *pType = XrmQString; + pValue->addr = StringValue(entry); + } else { + *pType = RepType(entry); + pValue->addr = DataValue(entry); + } + pValue->size = entry->size; + return True; + } + *pType = NULLQUARK; + pValue->addr = (XPointer)NULL; + pValue->size = 0; + return False; + +#undef VTIGHTLOOSE +#undef VLOOSE +} + +/* look for a tight/loose value */ +static Bool GetVEntry(table, names, classes, closure) + LTable table; + XrmNameList names; + XrmClassList classes; + VClosure closure; +{ + register VEntry entry; + register XrmQuark q; + + /* try name first */ + q = *names; + entry = LeafHash(table, q); + while (entry && entry->name != q) + entry = entry->next; + if (!entry) { + /* not found, try class */ + q = *classes; + entry = LeafHash(table, q); + while (entry && entry->name != q) + entry = entry->next; + if (!entry) + return False; + } + if (entry->string) { + *closure->type = XrmQString; + closure->value->addr = StringValue(entry); + } else { + *closure->type = RepType(entry); + closure->value->addr = DataValue(entry); + } + closure->value->size = entry->size; + return True; +} + +/* look for a loose value */ +static Bool GetLooseVEntry(table, names, classes, closure) + LTable table; + XrmNameList names; + XrmClassList classes; + VClosure closure; +{ + register VEntry entry; + register XrmQuark q; + +#define VLOOSE(ename) \ + q = ename; \ + entry = LeafHash(table, q); \ + while (entry && entry->name != q) \ + entry = entry->next; \ + if (entry && entry->tight && (entry = entry->next) && entry->name != q) \ + entry = (VEntry)NULL; + + /* bump to last component */ + while (names[1]) { + names++; + classes++; + } + VLOOSE(*names); /* do name, loose only */ + if (!entry) { + VLOOSE(*classes); /* do class, loose only */ + if (!entry) + return False; + } + if (entry->string) { + *closure->type = XrmQString; + closure->value->addr = StringValue(entry); + } else { + *closure->type = RepType(entry); + closure->value->addr = DataValue(entry); + } + closure->value->size = entry->size; + return True; + +#undef VLOOSE +} + +/* recursive search for a value */ +static Bool GetNEntry(table, names, classes, closure) + NTable table; + XrmNameList names; + XrmClassList classes; + VClosure closure; +{ + register NTable entry; + register XrmQuark q; + register unsigned int leaf; + Bool (*get)(); + NTable otable; + + if (names[2]) { + get = GetNEntry; /* recurse */ + leaf = 0; + } else { + get = GetVEntry; /* bottom of recursion */ + leaf = 1; + } + GTIGHTLOOSE(*names, GetLooseVEntry); /* do name, tight and loose */ + GTIGHTLOOSE(*classes, GetLooseVEntry); /* do class, tight and loose */ + if (table->hasany) { + GTIGHTLOOSE(XrmQANY, GetLooseVEntry); /* do ANY, tight and loose */ + } + if (table->hasloose) { + while (1) { + names++; + classes++; + if (!names[1]) + break; + if (!names[2]) { + get = GetVEntry; /* bottom of recursion */ + leaf = 1; + } + GLOOSE(*names, GetLooseVEntry); /* do name, loose only */ + GLOOSE(*classes, GetLooseVEntry); /* do class, loose only */ + if (table->hasany) { + GLOOSE(XrmQANY, GetLooseVEntry); /* do ANY, loose only */ + } + } + } + /* look for matching leaf tables */ + otable = table; + table = table->next; + if (!table) + return False; + if (table->leaf) { + if (table->tight && !otable->tight) + table = table->next; + } else { + table = table->next; + if (!table || !table->tight) + return False; + } + if (!table || table->name != otable->name) + return False; + /* found one */ + if (table->hasloose && + GetLooseVEntry((LTable)table, names, classes, closure)) + return True; + if (table->tight && table == otable->next) { + table = table->next; + if (table && table->name == otable->name && table->hasloose) + return GetLooseVEntry((LTable)table, names, classes, closure); + } + return False; +} + +Bool falrmQGetResource(db, names, classes, pType, pValue) + XrmDatabase db; + XrmNameList names; + XrmClassList classes; + XrmRepresentation *pType; /* RETURN */ + XrmValuePtr pValue; /* RETURN */ +{ + register NTable table; + VClosureRec closure; + + if (db && *names) { + _XLockMutex(&db->linfo); + closure.type = pType; + closure.value = pValue; + table = db->table; + if (names[1]) { + if (table && !table->leaf) { + if (GetNEntry(table, names, classes, &closure)) { + _XUnlockMutex(&db->linfo); + return True; + } + } else if (table && table->hasloose && + GetLooseVEntry((LTable)table, names, classes, &closure)) { + _XUnlockMutex (&db->linfo); + return True; + } + } else { + if (table && !table->leaf) + table = table->next; + if (table && GetVEntry((LTable)table, names, classes, &closure)) { + _XUnlockMutex(&db->linfo); + return True; + } + } + _XUnlockMutex(&db->linfo); + } + *pType = NULLQUARK; + pValue->addr = (XPointer)NULL; + pValue->size = 0; + return False; +} + +#if NeedFunctionPrototypes +Bool falrmGetResource(db, name_str, class_str, pType_str, pValue) + XrmDatabase db; + _Xconst char *name_str; + _Xconst char *class_str; + XrmString *pType_str; /* RETURN */ + XrmValuePtr pValue; /* RETURN */ +#else +Bool falrmGetResource(db, name_str, class_str, pType_str, pValue) + XrmDatabase db; + XrmString name_str; + XrmString class_str; + XrmString *pType_str; /* RETURN */ + XrmValuePtr pValue; /* RETURN */ +#endif +{ + XrmName names[MAXDBDEPTH+1]; + XrmClass classes[MAXDBDEPTH+1]; + XrmRepresentation fromType; + Bool result; + + XrmStringToNameList(name_str, names); + XrmStringToClassList(class_str, classes); + result = falrmQGetResource(db, names, classes, &fromType, pValue); + (*pType_str) = falrmQuarkToString(fromType); + return result; +} + +/* destroy all values, plus table itself */ +static void DestroyLTable(table) + LTable table; +{ + register int i; + register VEntry *buckets; + register VEntry entry, next; + + buckets = table->buckets; + for (i = table->table.mask; i >= 0; i--, buckets++) { + for (next = *buckets; entry = next; ) { + next = entry->next; + Xfree((char *)entry); + } + } + Xfree((char *)table->buckets); + Xfree((char *)table); +} + +/* destroy all contained tables, plus table itself */ +static void DestroyNTable(table) + NTable table; +{ + register int i; + register NTable *buckets; + register NTable entry, next; + + buckets = NodeBuckets(table); + for (i = table->mask; i >= 0; i--, buckets++) { + for (next = *buckets; entry = next; ) { + next = entry->next; + if (entry->leaf) + DestroyLTable((LTable)entry); + else + DestroyNTable(entry); + } + } + Xfree((char *)table); +} + +char *falrmLocaleOfDatabase(db) + XrmDatabase db; +{ + char* retval; + _XLockMutex(&db->linfo); + retval = (*db->methods->lcname)(db->mbstate); + _XUnlockMutex(&db->linfo); + return retval; +} + +void falrmDestroyDatabase(db) + XrmDatabase db; +{ + register NTable table, next; + + if (db) { + _XLockMutex(&db->linfo); + for (next = db->table; table = next; ) { + next = table->next; + if (table->leaf) + DestroyLTable((LTable)table); + else + DestroyNTable(table); + } + _XFreeMutex(&db->linfo); + (*db->methods->destroy)(db->mbstate); + Xfree((char *)db); + } +} diff --git a/cde/programs/dtudcfonted/libfal/_falrmI.h b/cde/programs/dtudcfonted/libfal/_falrmI.h new file mode 100644 index 00000000..6f7be90f --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falrmI.h @@ -0,0 +1,79 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* XrmI.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:12 */ +/* $XConsortium: _falrmI.h /main/1 1996/04/08 15:22:08 cde-fuj $ */ +/* + +Copyright (c) 1990 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + + +/* + * Macros to abstract out reading the file, and getting its size. + * + * You may need to redefine these for various other operating systems. + */ + +#include +#include + +#ifdef WIN32 +#define OpenFile(name) open((name), O_RDONLY|O_TEXT) +#else +#define OpenFile(name) open((name), O_RDONLY) +#endif +#define CloseFile(fd) close((fd)) +#define ReadFile(fd,buf,size) read((fd), (buf), (size)) +#define GetSizeOfFile(name,size) \ +{ \ + struct stat status_buffer; \ + if ( (stat((name), &status_buffer)) == -1 ) \ + size = -1; \ + else \ + size = status_buffer.st_size; \ +} diff --git a/cde/programs/dtudcfonted/libfal/_faludcInf.c b/cde/programs/dtudcfonted/libfal/_faludcInf.c new file mode 100644 index 00000000..349cab28 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_faludcInf.c @@ -0,0 +1,692 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: _faludcInf.c /main/4 1996/10/15 10:28:13 drk $ */ +/* udcInf.c 1.4 - Fujitsu source for CDEnext 96/03/19 13:41:00 */ +/* + * Copyright 1995 by FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietry source code of FUJITSU LIMITED + * + * Modifier: Takanori Tateno FUJITSU LIMITED + * + */ +#include +#include +#include +#include "syncx.h" +#include "_fallibint.h" +#include "_fallcint.h" +#include "_fallcPubI.h" +#include "_fallcGeneric.h" +#include "_falomGeneric.h" + +/* + external symbols +*/ +extern FontData falread_EncodingInfo(); +extern int fal_get_codeset(); + +extern int fal_utyderror ; +extern int fal_utyerror ; + +extern unsigned long fal_utyerrno ; + +#define FAL_ERROR -1 + + +/* + UDC structure define +*/ +typedef struct _FalGlyphRegion { + unsigned long start; + unsigned long end; +} FalGlyphRegion ; + +/* + * "code" no jyoui "i" byte me wo "unsigned char" toshite kaesu. + */ +static unsigned char getbyte(code,i) +unsigned long code; +int i; +{ + unsigned long byteL; + unsigned char byte; + byteL = code >> (8*(3-i)); + byte = (unsigned char)(0x000000ff & byteL); + return(byte); +} +/* + get codeset which described by charset_str and locale. + for examples ... + locale : ja_JP + charset_str : JISX0208.1983-0 +*/ + +fal_get_codeset(locale,charset_str,codeset,num_codeset) +char *locale; +char *charset_str; +int **codeset; +int *num_codeset; +{ + XLCdRec lcdrec; + XLCd lcd; + XLCdPublicRec xlcdp; + XPointer rdb; + int num = 0,count,num_ret=0,i,*ret; + char **value,buf[128],*ptr; + + + fal_utyderror = 0; + fal_utyerror = 0; + + if((locale == NULL) || (charset_str == NULL)){ + fal_utyerror = 5; + fal_utyderror = 1; + fal_utyerrno = 0x04 ; + return(FAL_ERROR); + } + if(codeset == NULL){ + fal_utyerror = 5; + fal_utyderror = 2; + fal_utyerrno = 0x04 ; + return(FAL_ERROR); + } + + /* create XLCd */ + xlcdp.pub.siname = locale; + lcdrec.core = (XLCdCore)&xlcdp; + lcd = &lcdrec; + /* create X RDB (X NLS DB) */ + rdb = _fallcCreateLocaleDataBase(lcd); + if(rdb == NULL){ + fal_utyerror = 1; + fal_utyerrno = 0x15 ; + return(FAL_ERROR); + } + + for(num=0;;num++){ + /* XLC_FONTSET */ + sprintf(buf, "fs%d.font.primary", num); + _fallcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); + if(count < 1){ + break ; + } + for(i=0;ishift_direction == (unsigned long)'+'){ + gi -= scope->shift; + } else { + gi += scope->shift; + } + if(gi >= scope->start && gi <= scope->end){ + *vgi = gi; + return(True); + } + return(False); +} + +static void shift_area(udc,scope) +FalGlyphRegion *udc; +FontScope scope; +{ + if(scope->shift_direction == (unsigned long)'+'){ + udc->start += scope->shift; + udc->end += scope->shift; + } else { + udc->start -= scope->shift; + udc->end -= scope->shift; + } +} + +/* + get UDC area with glyph index. + for examples ... + locale : ja_JP + charset_str : JISX0208.1983-0 +*/ +FalGetUDCGIArea(locale,codeset,charset_str,gr,num_gr) +char *locale; +int codeset; +char *charset_str; +FalGlyphRegion **gr; +int *num_gr; +{ + XLCdRec lcdrec; + XLCd lcd; + XLCdPublicRec xlcdp; + XPointer rdb; + FalGlyphRegion *udc; + int num = 0,count,num_ret=0; + int i,j,k; + char **value,buf[128],ptr; + FontData font_data; + + + fal_utyderror = 0; + fal_utyerror = 0; + fal_utyerrno = 0x00 ; + + if((locale == NULL) || (charset_str == NULL)){ + fal_utyerror = 5; + fal_utyderror = 1; + fal_utyerrno = 0x04; + fal_utyerrno |= (0x0b<<8) ; + return(FAL_ERROR); + } + if(gr == NULL){ + fal_utyerror = 5; + fal_utyderror = 1; + fal_utyerrno = 0x04; + fal_utyerrno |= (0x0b<<8) ; + return(FAL_ERROR); + } + if(num_gr == NULL){ + fal_utyerror = 5; + fal_utyderror = 2; + fal_utyerrno = 0x04; + fal_utyerrno |= (0x0b<<8) ; + return(FAL_ERROR); + } + + /* create XLCd */ + xlcdp.pub.siname = locale; + lcdrec.core = (XLCdCore)&xlcdp; + lcd = &lcdrec; + /* create X RDB (X NLS DB) */ + rdb = _fallcCreateLocaleDataBase(lcd); + if(rdb == NULL){ + fal_utyerror = 1; + fal_utyerrno = 0x15 ; + fal_utyerrno |= (0x0b<<8) ; + return(FAL_ERROR); + } + udc = NULL; + + /* XLC_FONTSET */ + sprintf(buf, "fs%d.charset.udc_area", codeset-1); + _fallcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); + if(count > 0){ + udc = (FalGlyphRegion *)Xmalloc(count * sizeof(FalGlyphRegion)); + if(udc == NULL){ + fal_utyerrno = 0x03 ; + fal_utyerrno |= (0x0b<<8) ; + return(FAL_ERROR); + } + for(i=0;i 0){ + font_data = falread_EncodingInfo(count,value); + for(i=0;i 0){ + strcpy(charsetname,value[0]); + } + sprintf(buf, "fs%d.font.primary", codeset-1); + _fallcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); + if(count > 0){ + font_data = falread_EncodingInfo(count,value); + for(i=0;ict_sequence == NULL){ + return(False); + } + for(i=0;;i++){ + sprintf(buf, "csd%d.charset_name", i); + _fallcGetLocaleDataBase(lcd, "XLC_CHARSET_DEFINE", buf, &value, &count); + if(count > 0){ + if(!_fallcNCompareISOLatin1(value[0], + charset->name,strlen(value[0])) ){ + return(True); + } + } else { + return(False); + } + } +} + +void +falmake_none_standard(from,charset,src) +char *from; +XlcCharSet charset; +char *src; +{ + int name_len,seq_len,i; + name_len = 2 + strlen(charset->encoding_name) + 1; + seq_len = strlen(charset->ct_sequence); + strcpy(from,charset->ct_sequence); + from[seq_len] = name_len / 128 + 128; + from[seq_len+1] = name_len % 128 + 128; + strcpy(&from[seq_len + 2],charset->encoding_name); + from[seq_len+name_len-1] = 0x02; /* STX */ + strcpy(&from[seq_len + name_len],src); +} +int +fal_glyph_to_code(locale,charset_str,codeset,glyph_index,codepoint) +char *locale; +char *charset_str; +int codeset; +unsigned long glyph_index; +unsigned long *codepoint; +{ + XLCd lcd; + unsigned char *from; int from_left; + unsigned char *to ; int to_left = 10; + unsigned char *dst; + unsigned char byte; + unsigned long from32[25]; + unsigned long to32[25]; + int i,j; + char tmp[256],charsetname[256],src[10]; + XlcConv conv; + XlcCharSet charset; + XPointer args[2]; + + from = (unsigned char *)from32; + to = (unsigned char *)to32; + dst = (unsigned char *)to32; + + memset(dst,0,25); + + lcd = (XLCd) (uintptr_t) _fallcGenericLoader(locale); + + fal_gi_to_vgi(lcd,locale,charset_str,codeset, + glyph_index,&glyph_index,charsetname); + + for(i=0,j=0;i<4;i++){ + byte = getbyte(glyph_index,i); + if(byte){ + src[j] = byte; + j ++; + } + } + src[j] = 0; + + + /* get charset */ +/* + sprintf(tmp,"%s%s",charset_str,":GL"); + charset_name = strdup(tmp); +*/ + charset = _fallcGetCharSet(charsetname); + if(charset == NULL){ + fal_utyerrno = 0x16 ; + return(FAL_ERROR); + } + /* make ct */ + if( falnon_standard(lcd,charset)) { + falmake_none_standard(from,charset,src); + } else if(charset->ct_sequence){ + snprintf((char *)from, sizeof(from32), "%s%s", charset->ct_sequence,src); + } else { + snprintf((char *)from, sizeof(from32), "%s", src); + } + /* compound text -> multi byte */ + conv = _fallcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte); + from_left = strlen((char *)from); + _fallcConvert(conv,(XPointer *)&from,&from_left, + (XPointer *)&to, &to_left,args,0); + _fallcCloseConverter(conv); + _fallcDestroyLC(lcd); + + *codepoint = 0; + for(i=0;dst[i];i++){ + *codepoint = ((*codepoint << 8) | dst[i]) ; + } + return(0); +} + +typedef struct _FalCodeRegion { + unsigned long start,end; +} FalCodeRegion ; + +int +FalGetUDCCPArea(locale,codeset,charset_str,cr,num_cr) +char *locale; +int codeset; +char *charset_str; +FalCodeRegion **cr; +int *num_cr; +{ + int i,num_gr,ret; + FalGlyphRegion *gr; + FalCodeRegion *crr; + + fal_utyerror = 0; + fal_utyderror = 0; + + if(cr == NULL){ + fal_utyerror = 5; + fal_utyderror = 1; + fal_utyerrno = 0x04 ; + fal_utyerrno |= (0x0a<<8) ; + return(FAL_ERROR); + } + if(num_cr == NULL){ + fal_utyerror = 5; + fal_utyderror = 2; + fal_utyerrno = 0x04 ; + fal_utyerrno |= (0x0a<<8) ; + return(FAL_ERROR); + } + + ret = FalGetUDCGIArea(locale,codeset,charset_str,&gr,&num_gr); + if(ret == FAL_ERROR){ + fal_utyerrno &= 0xff ; + fal_utyerrno |= (0x0a<<8) ; + return(ret); + } + + crr = (FalCodeRegion *)Xmalloc(num_gr*sizeof(FalCodeRegion)); + if(crr == NULL){ + Xfree(gr); + fal_utyerrno = 0x03 ; + fal_utyerrno |= (0x0a<<8) ; + return(FAL_ERROR); + } + + for(i=0;i= scope->start && vgi <= scope->end){ + if(scope->shift_direction == (unsigned long)'+'){ + *gi = vgi + scope->shift; + } else { + *gi = vgi - scope->shift; + } + return(True); + } + return(False); +} +/* + * + * + */ +static Bool +fal_vgi_to_gi(lcd,locale,vglyph,glyph,charset,charsetname) +XLCd lcd; +char *locale; +unsigned long vglyph; +unsigned long *glyph; +XlcCharSet charset; +char *charsetname; +{ + int num = 0,count,num_ret=0; + int i,j,k; + char **value,buf[128],ptr; + FontData font_data = NULL; + CodeSet cs; + + + for(i=0;;i++){ + sprintf(buf, "fs%d.charset.name",i); + _fallcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); + if(count > 0){ + if(!_fallcNCompareISOLatin1(charset->name,value[0], + strlen(charset->name))){ + break; + } + } else { + fal_utyerrno = 0x17 ; + return(False); + } + } +/* + sprintf(buf, "fs%d.charset.name", codeset-1); + _fallcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); + if(count > 0){ + strcpy(charsetname,value[0]); + } +*/ + sprintf(buf, "fs%d.font.primary", i); + _fallcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count); + if(count > 0){ + font_data = falread_EncodingInfo(count,value); + for(i=0;i vgi */ + conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet); + from_left = strlen((char *)from); + args[0] = (XPointer) &charset; + _fallcConvert(conv,(XPointer *)&from,&from_left, + (XPointer *)&to, &to_left,args,1); + + /* vgi -> gi */ + vglyph = 0; + for(i=0;dst[i];i++){ + vglyph = ((vglyph << 8) | dst[i]) ; + } + if(fal_vgi_to_gi(lcd,locale,vglyph,&glyph,charset,charsetname)==False){ + _fallcCloseConverter(conv); + _fallcDestroyLC(lcd); + *num_gi = 0; + return(0); + } + + _fallcCloseConverter(conv); + _fallcDestroyLC(lcd); + + *gi = (FalGIInf *)Xmalloc(sizeof(FalGIInf)); + if(*gi == NULL){ + fal_utyerrno = 0x03 ; + return(FAL_ERROR); + } + (*gi)->charset_str = (char *)Xmalloc(strlen(charsetname)+1); + strcpy((*gi)->charset_str,charsetname); + (*gi)->glyph_index = glyph; + + *num_gi = 1; + return(0); +} diff --git a/cde/programs/dtudcfonted/libfal/_falutil.h b/cde/programs/dtudcfonted/libfal/_falutil.h new file mode 100644 index 00000000..5bc2c3ed --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falutil.h @@ -0,0 +1,930 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* Xutil.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:12 */ +/* $XConsortium: _falutil.h /main/1 1996/04/08 15:20:39 cde-fuj $ */ + +/*********************************************************** + +Copyright (c) 1987 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + + +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ + +#ifndef _XUTIL_H_ +#define _XUTIL_H_ + +/* You must include "syncx.h" before including this file */ + +/* + * Bitmask returned by XParseGeometry(). Each bit tells if the corresponding + * value (x, y, width, height) was found in the parsed string. + */ +#define NoValue 0x0000 +#define XValue 0x0001 +#define YValue 0x0002 +#define WidthValue 0x0004 +#define HeightValue 0x0008 +#define AllValues 0x000F +#define XNegative 0x0010 +#define YNegative 0x0020 + +/* + * new version containing base_width, base_height, and win_gravity fields; + * used with WM_NORMAL_HINTS. + */ +typedef struct { + long flags; /* marks which fields in this structure are defined */ + int x, y; /* obsolete for new window mgrs, but clients */ + int width, height; /* should set so old wm's don't mess up */ + int min_width, min_height; + int max_width, max_height; + int width_inc, height_inc; + struct { + int x; /* numerator */ + int y; /* denominator */ + } min_aspect, max_aspect; + int base_width, base_height; /* added by ICCCM version 1 */ + int win_gravity; /* added by ICCCM version 1 */ +} XSizeHints; + +/* + * The next block of definitions are for window manager properties that + * clients and applications use for communication. + */ + +/* flags argument in size hints */ +#define USPosition (1L << 0) /* user specified x, y */ +#define USSize (1L << 1) /* user specified width, height */ + +#define PPosition (1L << 2) /* program specified position */ +#define PSize (1L << 3) /* program specified size */ +#define PMinSize (1L << 4) /* program specified minimum size */ +#define PMaxSize (1L << 5) /* program specified maximum size */ +#define PResizeInc (1L << 6) /* program specified resize increments */ +#define PAspect (1L << 7) /* program specified min and max aspect ratios */ +#define PBaseSize (1L << 8) /* program specified base for incrementing */ +#define PWinGravity (1L << 9) /* program specified window gravity */ + +/* obsolete */ +#define PAllHints (PPosition|PSize|PMinSize|PMaxSize|PResizeInc|PAspect) + + + +typedef struct { + long flags; /* marks which fields in this structure are defined */ + Bool input; /* does this application rely on the window manager to + get keyboard input? */ + int initial_state; /* see below */ + Pixmap icon_pixmap; /* pixmap to be used as icon */ + Window icon_window; /* window to be used as icon */ + int icon_x, icon_y; /* initial position of icon */ + Pixmap icon_mask; /* icon mask bitmap */ + XID window_group; /* id of related window group */ + /* this structure may be extended in the future */ +} XWMHints; + +/* definition for flags of XWMHints */ + +#define InputHint (1L << 0) +#define StateHint (1L << 1) +#define IconPixmapHint (1L << 2) +#define IconWindowHint (1L << 3) +#define IconPositionHint (1L << 4) +#define IconMaskHint (1L << 5) +#define WindowGroupHint (1L << 6) +#define AllHints (InputHint|StateHint|IconPixmapHint|IconWindowHint| \ +IconPositionHint|IconMaskHint|WindowGroupHint) +#define XUrgencyHint (1L << 8) + +/* definitions for initial window state */ +#define WithdrawnState 0 /* for windows that are not mapped */ +#define NormalState 1 /* most applications want to start this way */ +#define IconicState 3 /* application wants to start as an icon */ + +/* + * Obsolete states no longer defined by ICCCM + */ +#define DontCareState 0 /* don't know or care */ +#define ZoomState 2 /* application wants to start zoomed */ +#define InactiveState 4 /* application believes it is seldom used; */ + /* some wm's may put it on inactive menu */ + + +/* + * new structure for manipulating TEXT properties; used with WM_NAME, + * WM_ICON_NAME, WM_CLIENT_MACHINE, and WM_COMMAND. + */ +typedef struct { + unsigned char *value; /* same as Property routines */ + Atom encoding; /* prop type */ + int format; /* prop data format: 8, 16, or 32 */ + unsigned long nitems; /* number of data items in value */ +} XTextProperty; + +#define XNoMemory -1 +#define XLocaleNotSupported -2 +#define XConverterNotFound -3 + +typedef enum { + XStringStyle, /* STRING */ + XCompoundTextStyle, /* COMPOUND_TEXT */ + XTextStyle, /* text in owner's encoding (current locale)*/ + XStdICCTextStyle /* STRING, else COMPOUND_TEXT */ +} XICCEncodingStyle; + +typedef struct { + int min_width, min_height; + int max_width, max_height; + int width_inc, height_inc; +} XIconSize; + +typedef struct { + char *res_name; + char *res_class; +} XClassHint; + +/* + * These macros are used to give some sugar to the image routines so that + * naive people are more comfortable with them. + */ +#define XDestroyImage(ximage) \ + ((*((ximage)->f.destroy_image))((ximage))) +#define XGetPixel(ximage, x, y) \ + ((*((ximage)->f.get_pixel))((ximage), (x), (y))) +#define XPutPixel(ximage, x, y, pixel) \ + ((*((ximage)->f.put_pixel))((ximage), (x), (y), (pixel))) +#define XSubImage(ximage, x, y, width, height) \ + ((*((ximage)->f.sub_image))((ximage), (x), (y), (width), (height))) +#define XAddPixel(ximage, value) \ + ((*((ximage)->f.add_pixel))((ximage), (value))) + +/* + * Compose sequence status structure, used in calling XLookupString. + */ +typedef struct _XComposeStatus { + XPointer compose_ptr; /* state table pointer */ + int chars_matched; /* match state */ +} XComposeStatus; + +/* + * Keysym macros, used on Keysyms to test for classes of symbols + */ +#define IsKeypadKey(keysym) \ + (((KeySym)(keysym) >= XK_KP_Space) && ((KeySym)(keysym) <= XK_KP_Equal)) + +#define IsPrivateKeypadKey(keysym) \ + (((KeySym)(keysym) >= 0x11000000) && ((KeySym)(keysym) <= 0x1100FFFF)) + +#define IsCursorKey(keysym) \ + (((KeySym)(keysym) >= XK_Home) && ((KeySym)(keysym) < XK_Select)) + +#define IsPFKey(keysym) \ + (((KeySym)(keysym) >= XK_KP_F1) && ((KeySym)(keysym) <= XK_KP_F4)) + +#define IsFunctionKey(keysym) \ + (((KeySym)(keysym) >= XK_F1) && ((KeySym)(keysym) <= XK_F35)) + +#define IsMiscFunctionKey(keysym) \ + (((KeySym)(keysym) >= XK_Select) && ((KeySym)(keysym) <= XK_Break)) + +#define IsModifierKey(keysym) \ + ((((KeySym)(keysym) >= XK_Shift_L) && ((KeySym)(keysym) <= XK_Hyper_R)) \ + || ((KeySym)(keysym) == XK_Mode_switch) \ + || ((KeySym)(keysym) == XK_Num_Lock)) +/* + * opaque reference to Region data type + */ +typedef struct _XRegion *Region; + +/* Return values from XRectInRegion() */ + +#define RectangleOut 0 +#define RectangleIn 1 +#define RectanglePart 2 + + +/* + * Information used by the visual utility routines to find desired visual + * type from the many visuals a display may support. + */ + +typedef struct { + Visual *visual; + VisualID visualid; + int screen; + int depth; +#if defined(__cplusplus) || defined(c_plusplus) + int c_class; /* C++ */ +#else + int class; +#endif + unsigned long red_mask; + unsigned long green_mask; + unsigned long blue_mask; + int colormap_size; + int bits_per_rgb; +} XVisualInfo; + +#define VisualNoMask 0x0 +#define VisualIDMask 0x1 +#define VisualScreenMask 0x2 +#define VisualDepthMask 0x4 +#define VisualClassMask 0x8 +#define VisualRedMaskMask 0x10 +#define VisualGreenMaskMask 0x20 +#define VisualBlueMaskMask 0x40 +#define VisualColormapSizeMask 0x80 +#define VisualBitsPerRGBMask 0x100 +#define VisualAllMask 0x1FF + +/* + * This defines a window manager property that clients may use to + * share standard color maps of type RGB_COLOR_MAP: + */ +typedef struct { + Colormap colormap; + unsigned long red_max; + unsigned long red_mult; + unsigned long green_max; + unsigned long green_mult; + unsigned long blue_max; + unsigned long blue_mult; + unsigned long base_pixel; + VisualID visualid; /* added by ICCCM version 1 */ + XID killid; /* added by ICCCM version 1 */ +} XStandardColormap; + +#define ReleaseByFreeingColormap ((XID) 1L) /* for killid field above */ + + +/* + * return codes for XReadBitmapFile and XWriteBitmapFile + */ +#define BitmapSuccess 0 +#define BitmapOpenFailed 1 +#define BitmapFileInvalid 2 +#define BitmapNoMemory 3 + +/**************************************************************** + * + * Context Management + * + ****************************************************************/ + + +/* Associative lookup table return codes */ + +#define XCSUCCESS 0 /* No error. */ +#define XCNOMEM 1 /* Out of memory */ +#define XCNOENT 2 /* No entry in table */ + +typedef int XContext; + +#define XUniqueContext() ((XContext) falrmUniqueQuark()) +#define XStringToContext(string) ((XContext) falrmStringToQuark(string)) + +_XFUNCPROTOBEGIN + +/* The following declarations are alphabetized. */ + +extern XClassHint *XAllocClassHint ( +#if NeedFunctionPrototypes + void +#endif +); + +extern XIconSize *XAllocIconSize ( +#if NeedFunctionPrototypes + void +#endif +); + +extern XSizeHints *XAllocSizeHints ( +#if NeedFunctionPrototypes + void +#endif +); + +extern XStandardColormap *XAllocStandardColormap ( +#if NeedFunctionPrototypes + void +#endif +); + +extern XWMHints *XAllocWMHints ( +#if NeedFunctionPrototypes + void +#endif +); + +extern XClipBox( +#if NeedFunctionPrototypes + Region /* r */, + XRectangle* /* rect_return */ +#endif +); + +extern Region XCreateRegion( +#if NeedFunctionPrototypes + void +#endif +); + +extern char *falDefaultString( +#if NeedFunctionPrototypes + void +#endif +); + +extern int XDeleteContext( +#if NeedFunctionPrototypes + Display* /* display */, + XID /* rid */, + XContext /* context */ +#endif +); + +extern XDestroyRegion( +#if NeedFunctionPrototypes + Region /* r */ +#endif +); + +extern XEmptyRegion( +#if NeedFunctionPrototypes + Region /* r */ +#endif +); + +extern XEqualRegion( +#if NeedFunctionPrototypes + Region /* r1 */, + Region /* r2 */ +#endif +); + +extern int XFindContext( +#if NeedFunctionPrototypes + Display* /* display */, + XID /* rid */, + XContext /* context */, + XPointer* /* data_return */ +#endif +); + +extern Status XGetClassHint( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XClassHint* /* class_hints_return */ +#endif +); + +extern Status XGetIconSizes( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XIconSize** /* size_list_return */, + int* /* count_return */ +#endif +); + +extern Status XGetNormalHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints_return */ +#endif +); + +extern Status XGetRGBColormaps( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XStandardColormap** /* stdcmap_return */, + int* /* count_return */, + Atom /* property */ +#endif +); + +extern Status XGetSizeHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints_return */, + Atom /* property */ +#endif +); + +extern Status XGetStandardColormap( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XStandardColormap* /* colormap_return */, + Atom /* property */ +#endif +); + +extern Status XGetTextProperty( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* window */, + XTextProperty* /* text_prop_return */, + Atom /* property */ +#endif +); + +extern XVisualInfo *XGetVisualInfo( +#if NeedFunctionPrototypes + Display* /* display */, + long /* vinfo_mask */, + XVisualInfo* /* vinfo_template */, + int* /* nitems_return */ +#endif +); + +extern Status XGetWMClientMachine( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop_return */ +#endif +); + +extern XWMHints *XGetWMHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */ +#endif +); + +extern Status XGetWMIconName( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop_return */ +#endif +); + +extern Status XGetWMName( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop_return */ +#endif +); + +extern Status XGetWMNormalHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints_return */, + long* /* supplied_return */ +#endif +); + +extern Status XGetWMSizeHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints_return */, + long* /* supplied_return */, + Atom /* property */ +#endif +); + +extern Status XGetZoomHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* zhints_return */ +#endif +); + +extern XIntersectRegion( +#if NeedFunctionPrototypes + Region /* sra */, + Region /* srb */, + Region /* dr_return */ +#endif +); + +extern void XConvertCase( +#if NeedFunctionPrototypes + KeySym /* sym */, + KeySym* /* lower */, + KeySym* /* upper */ +#endif +); + +extern int XLookupString( +#if NeedFunctionPrototypes + XKeyEvent* /* event_struct */, + char* /* buffer_return */, + int /* bytes_buffer */, + KeySym* /* keysym_return */, + XComposeStatus* /* status_in_out */ +#endif +); + +extern Status XMatchVisualInfo( +#if NeedFunctionPrototypes + Display* /* display */, + int /* screen */, + int /* depth */, + int /* class */, + XVisualInfo* /* vinfo_return */ +#endif +); + +extern XOffsetRegion( +#if NeedFunctionPrototypes + Region /* r */, + int /* dx */, + int /* dy */ +#endif +); + +extern Bool XPointInRegion( +#if NeedFunctionPrototypes + Region /* r */, + int /* x */, + int /* y */ +#endif +); + +extern Region XPolygonRegion( +#if NeedFunctionPrototypes + XPoint* /* points */, + int /* n */, + int /* fill_rule */ +#endif +); + +extern int XRectInRegion( +#if NeedFunctionPrototypes + Region /* r */, + int /* x */, + int /* y */, + unsigned int /* width */, + unsigned int /* height */ +#endif +); + +extern int XSaveContext( +#if NeedFunctionPrototypes + Display* /* display */, + XID /* rid */, + XContext /* context */, + _Xconst char* /* data */ +#endif +); + +extern XSetClassHint( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XClassHint* /* class_hints */ +#endif +); + +extern XSetIconSizes( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XIconSize* /* size_list */, + int /* count */ +#endif +); + +extern XSetNormalHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints */ +#endif +); + +extern void XSetRGBColormaps( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XStandardColormap* /* stdcmaps */, + int /* count */, + Atom /* property */ +#endif +); + +extern XSetSizeHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints */, + Atom /* property */ +#endif +); + +extern XSetStandardProperties( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + _Xconst char* /* window_name */, + _Xconst char* /* icon_name */, + Pixmap /* icon_pixmap */, + char** /* argv */, + int /* argc */, + XSizeHints* /* hints */ +#endif +); + +extern void XSetTextProperty( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop */, + Atom /* property */ +#endif +); + +extern void XSetWMClientMachine( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop */ +#endif +); + +extern XSetWMHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XWMHints* /* wm_hints */ +#endif +); + +extern void XSetWMIconName( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop */ +#endif +); + +extern void XSetWMName( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* text_prop */ +#endif +); + +extern void XSetWMNormalHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints */ +#endif +); + +extern void XSetWMProperties( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XTextProperty* /* window_name */, + XTextProperty* /* icon_name */, + char** /* argv */, + int /* argc */, + XSizeHints* /* normal_hints */, + XWMHints* /* wm_hints */, + XClassHint* /* class_hints */ +#endif +); + +extern void XmbSetWMProperties( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + _Xconst char* /* window_name */, + _Xconst char* /* icon_name */, + char** /* argv */, + int /* argc */, + XSizeHints* /* normal_hints */, + XWMHints* /* wm_hints */, + XClassHint* /* class_hints */ +#endif +); + +extern void XSetWMSizeHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* hints */, + Atom /* property */ +#endif +); + +extern XSetRegion( +#if NeedFunctionPrototypes + Display* /* display */, + GC /* gc */, + Region /* r */ +#endif +); + +extern void XSetStandardColormap( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XStandardColormap* /* colormap */, + Atom /* property */ +#endif +); + +extern XSetZoomHints( +#if NeedFunctionPrototypes + Display* /* display */, + Window /* w */, + XSizeHints* /* zhints */ +#endif +); + +extern XShrinkRegion( +#if NeedFunctionPrototypes + Region /* r */, + int /* dx */, + int /* dy */ +#endif +); + +extern Status XStringListToTextProperty( +#if NeedFunctionPrototypes + char** /* list */, + int /* count */, + XTextProperty* /* text_prop_return */ +#endif +); + +extern XSubtractRegion( +#if NeedFunctionPrototypes + Region /* sra */, + Region /* srb */, + Region /* dr_return */ +#endif +); + +extern int falmbTextListToTextProperty( +#if NeedFunctionPrototypes + Display* /* display */, + char** /* list */, + int /* count */, + XICCEncodingStyle /* style */, + XTextProperty* /* text_prop_return */ +#endif +); + +extern int falwcTextListToTextProperty( +#if NeedFunctionPrototypes + Display* /* display */, + wchar_t** /* list */, + int /* count */, + XICCEncodingStyle /* style */, + XTextProperty* /* text_prop_return */ +#endif +); + +extern void falwcFreeStringList( +#if NeedFunctionPrototypes + wchar_t** /* list */ +#endif +); + +extern Status XTextPropertyToStringList( +#if NeedFunctionPrototypes + XTextProperty* /* text_prop */, + char*** /* list_return */, + int* /* count_return */ +#endif +); + +extern int falmbTextPropertyToTextList( +#if NeedFunctionPrototypes + Display* /* display */, + XTextProperty* /* text_prop */, + char*** /* list_return */, + int* /* count_return */ +#endif +); + +extern int falwcTextPropertyToTextList( +#if NeedFunctionPrototypes + Display* /* display */, + XTextProperty* /* text_prop */, + wchar_t*** /* list_return */, + int* /* count_return */ +#endif +); + +extern XUnionRectWithRegion( +#if NeedFunctionPrototypes + XRectangle* /* rectangle */, + Region /* src_region */, + Region /* dest_region_return */ +#endif +); + +extern XUnionRegion( +#if NeedFunctionPrototypes + Region /* sra */, + Region /* srb */, + Region /* dr_return */ +#endif +); + +extern int XWMGeometry( +#if NeedFunctionPrototypes + Display* /* display */, + int /* screen_number */, + _Xconst char* /* user_geometry */, + _Xconst char* /* default_geometry */, + unsigned int /* border_width */, + XSizeHints* /* hints */, + int* /* x_return */, + int* /* y_return */, + int* /* width_return */, + int* /* height_return */, + int* /* gravity_return */ +#endif +); + +extern XXorRegion( +#if NeedFunctionPrototypes + Region /* sra */, + Region /* srb */, + Region /* dr_return */ +#endif +); + +_XFUNCPROTOEND + +#endif /* _XUTIL_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/_falutilbitmap.c b/cde/programs/dtudcfonted/libfal/_falutilbitmap.c new file mode 100644 index 00000000..8c59d610 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falutilbitmap.c @@ -0,0 +1,210 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: _falutilbitmap.c /main/1 1996/04/08 15:22:19 cde-fuj $ */ + +/* + +Copyright (c) 1990, 1994 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +*/ + +/* + * Author: Keith Packard, MIT X Consortium + */ + +/* Utility functions for reformating font bitmaps */ + +static unsigned char _reverse_byte[0x100] = { + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff +}; + +/* + * Invert bit order within each BYTE of an array. + */ +void +BitOrderInvert(buf, nbytes) + register unsigned char *buf; + register int nbytes; +{ + register unsigned char *rev = _reverse_byte; + + for (; --nbytes >= 0; buf++) + *buf = rev[*buf]; +} + +/* + * Invert byte order within each 16-bits of an array. + */ +void +TwoByteSwap(buf, nbytes) + register unsigned char *buf; + register int nbytes; +{ + register unsigned char c; + + for (; nbytes > 0; nbytes -= 2, buf += 2) + { + c = buf[0]; + buf[0] = buf[1]; + buf[1] = c; + } +} + +/* + * Invert byte order within each 32-bits of an array. + */ +void +FourByteSwap(buf, nbytes) + register unsigned char *buf; + register int nbytes; +{ + register unsigned char c; + + for (; nbytes > 0; nbytes -= 4, buf += 4) + { + c = buf[0]; + buf[0] = buf[3]; + buf[3] = c; + c = buf[1]; + buf[1] = buf[2]; + buf[2] = c; + } +} + +/* + * Repad a bitmap + */ + +int +RepadBitmap (pSrc, pDst, srcPad, dstPad, width, height) + char *pSrc, *pDst; + unsigned srcPad, dstPad; + int width, height; +{ + int srcWidthBytes,dstWidthBytes; + int row,col; + char *pTmpSrc,*pTmpDst; + + switch (srcPad) { + case 1: + srcWidthBytes = (width+7)>>3; + break; + case 2: + srcWidthBytes = ((width+15)>>4)<<1; + break; + case 4: + srcWidthBytes = ((width+31)>>5)<<2; + break; + case 8: + srcWidthBytes = ((width+63)>>6)<<3; + break; + default: + return 0; + } + switch (dstPad) { + case 1: + dstWidthBytes = (width+7)>>3; + break; + case 2: + dstWidthBytes = ((width+15)>>4)<<1; + break; + case 4: + dstWidthBytes = ((width+31)>>5)<<2; + break; + case 8: + dstWidthBytes = ((width+63)>>6)<<3; + break; + default: + return 0; + } + + width = srcWidthBytes; + if (width > dstWidthBytes) + width = dstWidthBytes; + pTmpSrc= pSrc; + pTmpDst= pDst; + for (row = 0; row < height; row++) + { + for (col = 0; col < width; col++) + *pTmpDst++ = *pTmpSrc++; + while (col < dstWidthBytes) + { + *pTmpDst++ = '\0'; + col++; + } + pTmpSrc += srcWidthBytes - width; + } + return dstWidthBytes * height; +} diff --git a/cde/programs/dtudcfonted/libfal/_falvarargs.h b/cde/programs/dtudcfonted/libfal/_falvarargs.h new file mode 100644 index 00000000..65f945b3 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/_falvarargs.h @@ -0,0 +1,95 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* Xvarargs.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:13 */ +/* $XConsortium: _falvarargs.h /main/1 1996/04/08 15:22:42 cde-fuj $ */ +/* + +Copyright (c) 1985, 1986, 1987, 1988, 1989 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +*/ + +#ifndef _XVARARGS_H_ +#define _XVARARGS_H_ + +#ifdef __HIGHC__ +#ifndef _STDARG_H +#define _STDARG_H + +typedef char *va_list; + +/* Amount of space required in an argument list for an arg of type TYPE. + TYPE may alternatively be an expression whose type is used. */ + +#define __va_rounded_size(TYPE) \ + (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) + +#define va_start(AP, LASTARG) \ + (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG))) + +#define va_end(AP) + +#define va_arg(AP, TYPE) \ + (AP += __va_rounded_size (TYPE), \ + *((TYPE *) (AP - __va_rounded_size (TYPE)))) + +#endif /* _STDARG_H */ + +#define Va_start(a,b) va_start(a,b) + +#else /* !__HIGHC__ */ + +#if NeedVarargsPrototypes +# include +# define Va_start(a,b) va_start(a,b) +#else +# include +# define Va_start(a,b) va_start(a) +#endif + +#endif /* __HIGHC__ */ + +#endif /* _XVARARGS_H_ */ diff --git a/cde/programs/dtudcfonted/libfal/falfont.c b/cde/programs/dtudcfonted/libfal/falfont.c new file mode 100644 index 00000000..77feec3d --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/falfont.c @@ -0,0 +1,3239 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: falfont.c /main/8 1996/07/04 02:35:37 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "FaLib.h" +#include "falfont.h" +#include "udcutil.h" + + +#define MKFONTLIST (1<<1) +#define SRCHFNAME (1<<2) +#define FONTOFID (1<<3) + +typedef struct _FontIDInfo { + FalFontID fid ; + int cd_set ; + int dspcode ; + int islock ; +} FontIDInfo ; + +typedef struct _MngFontID { + int num ; + FontIDInfo **finf ; +} MngFontID ; + +/*** structures for UDC fontpath ***/ +static FalFontPath orgn = { 0, NULL }; /* for libfal */ +static FalFontPath copy = { 0, NULL }; /* report to the user */ +static FalFontPath wpath = { 0, NULL }; /* for libfal */ + +/***** Variables for notice kind of error *****/ +int fal_utyerror; +int fal_utyderror; +int fal_utyexists; +unsigned long fal_utyerrno ; +char fal_err_file[ FAL_LINE_MAX+1 ] ; + +char fal_err_file_buf[ sizeof(fal_err_file) ] ; + +#define fal_seterrcode( uty, der, errno, func ) { \ + fal_utyerror = (uty); \ + fal_utyderror = (der) ; \ + fal_utyerrno = (errno) ; \ + fal_utyerrno |= ((func)<<8) ; \ +} + +/***** flags *****/ +static int execDefined ; +static int execUndefined ; +static int IsDefaultPath = FALSE ; +static MngFontID mngfid = { 0, NULL } ; +static int tmp_codeset = 0 ; +static char *fal_locale = NULL ; +static char *charset_str_buf = NULL ; +static int *codeset_list_sav = NULL ; +static int codeset_list_num = 0 ; + +/* declaration of inner functions */ +char *fal_get_base_name(); + +static FILE *open_fonts_list() ; +static int falGetGlyph() ; +static int falGetCharIndex() ; +static int falZoom() ; +static int exline() ; +static char falGetMask() ; +static int chk_key_str() ; +static int fal_make_fontlist() ; +static int fal_sort_fontlist() ; +static int set_default_path() ; +static int cpy_default_path() ; +static int comp_default_path() ; +static int fal_clear_font_path() ; +static int set_font_pathlist() ; + +static int fal_split_data() ; +static int fal_clear_data() ; +static int CR_to_NULL() ; +static int fal_cmp_data() ; +static int new_target() ; + +int set_struct() ; +int fal_eq_data() ; + +void set_errfile_str() ; + +static int fal_init() ; +static int fal_add_fidinf() ; +static int fal_read_fidinf() ; +static int fal_del_fidinf() ; +static int fal_conv_code_to_glyph() ; +static int fal_conv_glyph_to_code() ; +static int falReadFontInfoLists() ; +static int fal_get_def_fontdata() ; +static int falgetfontlist() ; +static int fal_get_undef_fontdata() ; +static void clear_charset_info() ; +static int make_default_path() ; +static int file_lock() ; +static int file_unlock() ; +static int is_lock() ; + +extern int falReadFontProp() ; +extern int falReadGpfProp() ; +extern int falInitReadPcfProp() ; +extern int fal_get_codeset() ; +extern int falInitReadPcf() ; +extern void falGetPcfGSize() ; +extern int falPcfGlyph() ; +extern int fal_code_to_glyph() ; +extern int fal_glyph_to_code() ; + + + +static int +fal_init() +{ + memset( fal_err_file, '\0', sizeof(fal_err_file) ) ; + memset( fal_err_file_buf, '\0', sizeof(fal_err_file_buf) ) ; + + if ( !fal_locale ){ + char *lcl ; + if( (lcl = (char *)getenv( "LANG" )) == NULL ){ + lcl = "C" ; + } + if( (fal_locale = (char *)strdup( lcl )) == NULL ){ + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR; + } + } + return 0 ; +} + +void +set_errfile_str( obuf, ibuf ) +char *obuf ; +char *ibuf ; +{ + char *sp ; + + if( (strlen(ibuf)+1) > sizeof(fal_err_file) ){ + sp = ibuf ; + sp += ((strlen(ibuf)+1) - sizeof(fal_err_file)) ; + strcpy( obuf, sp ) ; + }else{ + strcpy( obuf, ibuf ) ; + } +} + +/* + * open a fontfile by "RDONLY" + */ +FalFontID +FalOpenFont( file, protect_key_data, codeset ) +char *file; +int protect_key_data; +int codeset; +{ + FalFontID __FalOpenFont(); + + return __FalOpenFont( file, protect_key_data, codeset, 0 ); +} + +/* + * open a fontfile by "RDWR" + * + * + * lock flag + * 1: ON --- open mode "RDWR" + * 0: OFF -- for "FalOpenFont()" + */ +FalFontID +__FalOpenFont( file, protect_key_data, codeset, lockflag ) +char *file; +int protect_key_data; +int codeset; +int lockflag; +{ + int fd ; + char *buf; + char *openfontfile; + struct stat st; + Oak_FontInf *finf; + + if ( !(openfontfile = (char *)malloc( strlen( file ) + 1 )) ) { + fal_seterrcode( _FAL_MALOC_ER, 0, + FAL_ERR_MALLOC , FAL_FUNCNUM_OPNFNT ) ; + return (FalFontID)FAL_ERROR; + } + strcpy( openfontfile, file ); + + /* read a condition of a fontfile */ + if ( stat( openfontfile, &st ) < 0 ) { + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + fal_utyerror = _FAL_STAT_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_STAT ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + return (FalFontID)FAL_ERROR; + } + + CHK_PROTECT_KEY( protect_key_data, openfontfile, fal_utyerror, fal_utyderror ) ; + + if ( st.st_size < sizeof( FontInfoRec ) ) { + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + fal_utyerror = _FAL_FONT_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_FONT ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + return (FalFontID)FAL_ERROR; + } + + /* open a fontfile */ + if ( lockflag == 1 ) { + int ret ; + if ( (fd = open( openfontfile, O_RDWR )) < 0 ) { + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + fal_utyerror = _FAL_OPEN_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FNT_OPN ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + return (FalFontID)FAL_ERROR; + } + ret = is_lock( fd ) ; + if( ret != 0 ){ + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + fal_utyerror = _FAL_OPEN_ER; + fal_utyderror = errno; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + close( fd ); + return (FalFontID)FAL_ERROR; + } + } else { + if ( (fd = open( openfontfile, O_RDONLY)) < 0 ) { + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + fal_utyerror = _FAL_OPEN_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FNT_OPN ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + return (FalFontID)FAL_ERROR; + } + } + + /* read a fontfile */ + if ( !(finf = ( Oak_FontInf * )malloc(sizeof( Oak_FontInf ) )) ) { + free( openfontfile ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + close( fd ); + return (FalFontID)FAL_ERROR; + } + + +#if defined( SVR4 ) + /* use "mmap()" */ + buf = (char *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if ( buf != (char *)-1 ) { + /* if "mmap" is normal end */ + if ( lockflag == 0 ) { + close( fd ); + } + finf->ismmap = TRUE; + finf->fsize = st.st_size; + } else { +#endif + /* if "mmap" is abnormal end , try "read()" */ + finf->ismmap = FALSE; + if ( !(buf = (char *)malloc(st.st_size)) ) { + free( openfontfile ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + free( finf ); + close( fd ); + return (FalFontID)FAL_ERROR; + } + if ( read(fd, buf, st.st_size) != st.st_size ) { + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + fal_utyerror = _FAL_READ_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FNT_RD ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + free( finf ); + free( buf ); + close( fd ); + return (FalFontID)FAL_ERROR; + } +#if defined( SVR4 ) + } +#endif + + if ( !(finf->fname = (char *)strdup( openfontfile )) ) { + fal_seterrcode( _FAL_MALOC_ER, 0, + FAL_ERR_MALLOC , FAL_FUNCNUM_OPNFNT ) ; + free( openfontfile ); + free( finf ); + free( buf ); + close( fd ); + return (FalFontID)FAL_ERROR; + } + + /* case of a pcf font */ + if ( strcmp( FILE_SUFFIX( openfontfile ), PCFSUFFIX ) == 0 ) { + if ( falInitReadPcf( &finf->pcfinf, buf ) ) { + fal_utyerror = _FAL_PKEY_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_FONT ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + goto FalError01 ; + } + finf->isFef = FALSE; + finf->isPcf = TRUE; + finf->pFinf = &finf->pcfinf.info; + } else { + FAL_GET_SNF_HEADER( buf, protect_key_data, fal_utyerror, fal_utyderror, fd, finf, openfontfile ) ; + } + finf->buf = buf; + + if ( finf->isFef ){ + finf->pCinf + = (CharInfoPtr)( (char *)finf->pFinf + + sizeof( FontInfoRec ) ); + finf->pGlyphs + = (unsigned char *)((char *)finf->pCinf + + (sizeof(CharInfoRec) * GETNUMCHARS(finf->pFinf))); + finf->width + = finf->pFinf->maxbounds.metrics.rightSideBearing + - finf->pFinf->maxbounds.metrics.leftSideBearing; + finf->height + = finf->pFinf->maxbounds.metrics.ascent + + finf->pFinf->maxbounds.metrics.descent; + } else if ( finf->isPcf ) { + finf->pCinf = NULL; + finf->pGlyphs = NULL; + falGetPcfGSize( &finf->pcfinf, &finf->width, &finf->height); + } else { + fal_utyerror = _FAL_FONT_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_FONT ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + goto FalError01 ; + } + + finf->start = (finf->pFinf->firstRow << 8) | finf->pFinf->firstCol; + finf->end = (finf->pFinf->lastRow << 8) | finf->pFinf->lastCol; + + finf->fd = fd; + finf->sptnBufL = 0; + finf->sptnBuf = (char *)0; + finf->dptnBufL = 0; + finf->dptnBuf = (char *)0; + finf->dbufL = 0; + finf->dbuf = (char *)0; + + finf->sptnBufL = ((finf->width + 7) / 8) * (finf->height); + finf->sptnBuf = (char *)malloc(finf->sptnBufL); + if ( finf->sptnBuf == NULL ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + goto FalError01 ; + } + + /* Save font information */ + if( fal_add_fidinf( (FalFontID)finf, codeset, + ((tmp_codeset)?tmp_codeset:codeset), + lockflag ) == FAL_ERROR ) + { + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + goto FalError01 ; + } + + /* Lock the font file */ + if ( lockflag == 1 ) { + if ( file_lock( finf->fd ) == FAL_ERROR ) { + set_errfile_str( fal_err_file, openfontfile ) ; + fal_utyerror = _FAL_OPEN_ER; + fal_utyderror = errno; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + goto FalError01 ; + } + } + free( openfontfile ); + + return( ( FalFontID ) finf ); + +FalError01: + +#if defined( SVR4 ) + if ( finf->ismmap == TRUE ) { + munmap( buf, finf->fsize ); + } else { + free( buf ); + close( fd ); + } +#else + free( buf ); + close( fd ); +#endif + set_errfile_str( fal_err_file, openfontfile ) ; + free( openfontfile ); + free( finf->fname ); + finf->fname = NULL; + free(finf); + + return (FalFontID)FAL_ERROR; +} + + + +#if NeedFunctionPrototypes +FalCloseFont( + FalFontID fid ) +#else +FalCloseFont( fid ) +FalFontID fid; +#endif +{ + int __FalCloseFont(); + FontIDInfo fontid_inf ; + + if( fal_read_fidinf( fid, &fontid_inf ) == FAL_ERROR ) { + fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ; + return FAL_ERROR; + } + + return __FalCloseFont( fid, fontid_inf.islock ); +} + + +/* + * close a fontfile + * + * + * lock flag + * 1: ON --- open a font by "RDWR" mode + * 0: OFF -- for "FalOpenFont()" + */ +__FalCloseFont( fid, lockflag ) +FalFontID fid; +int lockflag; +{ + Oak_FontInf *finf; + + finf = ( Oak_FontInf * )fid; + + if ( finf == NULL ) { + fal_utyerror = _FAL_PARM_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ; + return FAL_ERROR; + } + + set_errfile_str( fal_err_file_buf, finf->fname ) ; + free( finf->fname ); + if ( finf->buf != NULL ) { +#if defined( SVR4 ) + if ( finf->ismmap == TRUE ) { + munmap( finf->buf, finf->fsize ); + if ( lockflag == 1 ) { + close( finf->fd ); + } + } else { + free( finf->buf ); + close( finf->fd ); + } +#else + free( finf->buf ); + close( finf->fd ); +#endif + + free( finf->sptnBuf ); + free( finf->dptnBuf ); + free( finf->dbuf ); + + free ( finf ); + } + if ( lockflag == 1 ) { + if ( file_unlock( finf->fd ) == FAL_ERROR ) { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ; + return FAL_ERROR; + } + } + + if ( fal_del_fidinf( fid ) == FAL_ERROR ) { + fal_utyerrno |= (FAL_FUNCNUM_CLSFNT<<8) ; + return FAL_ERROR; + } + + return _FAL_OK; +} + +#if NeedFunctionPrototypes +FalQueryFont( + FalFontID fid, + FalFontinfo *fontinfo ) +#else +FalQueryFont( fid, fontinfo ) +FalFontID fid; +FalFontinfo *fontinfo; +#endif +{ + Oak_FontInf *finf; + unsigned int inner_start, inner_end ; + FontIDInfo fontid_inf ; + + if( fal_read_fidinf( fid, &fontid_inf ) == FAL_ERROR ){ + fal_utyerrno |= (FAL_FUNCNUM_QRY<<8) ; + return FAL_ERROR; + } + finf = ( Oak_FontInf * )fid; + if ( finf == NULL || fontinfo == NULL ) { + fal_utyerror = _FAL_PARM_ER; + if (finf == NULL) { + fal_utyderror = _FAL_Q_P_FINF_DER; + } else { + fal_utyderror = _FAL_Q_P_FONT_DER; + } + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_QRY<<8) ; + return FAL_ERROR; + } + + fontinfo->width = (int)finf->width; + fontinfo->height = (int)finf->height; + + if( (fal_conv_glyph_to_code( finf, fontid_inf.dspcode, + fontid_inf.cd_set, finf->start, &inner_start ) == FAL_ERROR ) || + (fal_conv_glyph_to_code( finf, fontid_inf.dspcode, + fontid_inf.cd_set, finf->end, &inner_end ) == FAL_ERROR )) + { + fal_utyerrno |= (FAL_FUNCNUM_QRY<<8) ; + return FAL_ERROR; + } + + fontinfo->top = inner_start ; + fontinfo->bottom = inner_end ; + + return _FAL_OK; +} + +#if NeedFunctionPrototypes +char * +FalReadFont( + FalFontID fid, + int code, + int width, + int height ) +#else +char * +FalReadFont( fid, code, width, height ) +FalFontID fid; +int code ; +int width ; +int height ; +#endif +{ + Oak_FontInf *finf; + int zoom_on ; + char *toglyph; + int ptnBsize; + unsigned int inner_code; /* an inside code of a file */ + + finf = ( Oak_FontInf * )fid; + + if ( finf == NULL ) { + fal_utyerror = _FAL_PARM_ER; + fal_utyderror = _FAL_R_P_FINF_DER; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ; + return (char *)FAL_ERROR; + } + if (width < 0) { + fal_utyerror = _FAL_PARM_ER; + fal_utyderror = _FAL_R_P_W_DER; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ; + return (char *)FAL_ERROR; + } + if (height < 0) { + fal_utyerror = _FAL_PARM_ER; + fal_utyderror = _FAL_R_P_H_DER; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ; + return (char *)FAL_ERROR; + } + + if (width == 0) { + width = finf->width; + } + if (height == 0) { + height = finf->height; + } + if ( (width != finf->width) || (height != finf->height) ) { + zoom_on = TRUE; + } else { + zoom_on = FALSE; + } + + memset(finf->sptnBuf, 0, finf->sptnBufL); + + if( fal_conv_code_to_glyph( fid, code, &inner_code ) == FAL_ERROR ) { + fal_utyexists = 1; + fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ; + return (char *)0; + } + + if ( finf->isPcf) { + /* case of a pcf font */ + falPcfGlyph( finf->sptnBuf, finf, inner_code ); + } else { + /* case of a snf font */ + falGetGlyph( finf->sptnBuf, finf, inner_code ); + } + if ( zoom_on == TRUE ) { + ptnBsize = ((width + 7)/8)*height; + if ( ptnBsize > finf->dptnBufL ) { + if ( finf->dptnBuf == NULL ) { + toglyph = (char *)malloc( ptnBsize ); + } else { + toglyph = (char *)realloc( finf->dptnBuf, ptnBsize ); + } + if ( toglyph == NULL ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ; + return (char *)FAL_ERROR; + } + finf->dptnBufL = ptnBsize; + finf->dptnBuf = toglyph; + } + ptnBsize = (width + 7) / 8; + if ( ptnBsize > finf->dbufL ) { + if ( finf->dbuf == NULL ) { + toglyph = (char *)malloc( ptnBsize ); + } else { + toglyph = (char *)realloc( finf->dbuf, ptnBsize ); + } + if ( toglyph == NULL ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_RDFNT<<8) ; + return (char *)FAL_ERROR; + } + finf->dbufL = ptnBsize; + finf->dbuf = toglyph; + } + falZoom( + finf->dptnBuf, finf->sptnBuf, + finf->width, finf->height, width, height, finf->dbuf + ); + return( finf->dptnBuf ); + } else { + return finf->sptnBuf; + } +} + +static +falGetGlyph( glyph, finf, code ) +char *glyph; +Oak_FontInf *finf; +int code; +{ + int in_dwidth, out_dwidth, ix, i, j; + char *glyph_p, *inp, p_mask, falGetMask(); + CharInfoPtr CharInfP; + int codeRow, codeCol; + unsigned int inner_code; /* an inside code of a file */ + + inner_code = code; + codeCol = inner_code & 0xff; /* a lower byte of an inside code */ + codeRow = (inner_code >> 8) & 0xff; /* a upper byte of a code */ + + /* code check */ + if ( + ((code < finf->start) || (code > finf->end)) || + ((codeCol < finf->pFinf->firstCol) || + (codeCol > finf->pFinf->lastCol)) || + ((codeRow < finf->pFinf->firstRow) || + (codeRow > finf->pFinf->lastRow)) + ) { + fal_utyexists = 1; + return 0; + } + + /* Get a character index */ + ix = falGetCharIndex( finf, inner_code ); + CharInfP = finf->pCinf; + + if ( !CharInfP[ix].exists ) { + fal_utyexists = 1; + return 0; + } else { + fal_utyexists = 0; + } + + in_dwidth + = (finf->width + SNF_BOUND - 1) + / SNF_BOUND * (SNF_BOUND / 8); + out_dwidth = (finf->width + 7) / 8; + + p_mask = falGetMask( finf->width ); + + glyph_p = (char *)finf->pGlyphs + CharInfP[ix].byteOffset; + for ( i = 0; i < finf->height; i++ ) { + inp = glyph_p + ( in_dwidth * i ); + for ( j = 0; j < out_dwidth-1; j++ ) { + *glyph++ = *inp++; + } + *glyph++ = *inp++ & p_mask; + } + return 0; +} + +static +falGetCharIndex( finf, code ) +Oak_FontInf *finf; +int code; /* an inside code of a file */ +{ + int nColperRow, nRow, nCol; + + nColperRow = finf->pFinf->lastCol - finf->pFinf->firstCol + 1; + nRow = ((code >> 8) & 0xff) - finf->pFinf->firstRow; + nCol = (code & 0xff) - finf->pFinf->firstCol; + + return ( nRow * nColperRow + nCol ); +} + +static +falZoom( dmem, smem, sw, sh, dw, dh, dbuf ) +char *dmem; +char *smem; +int sw; +int sh; +int dw; +int dh; +char *dbuf; +{ + int swidth; + int dwidth; + int i, lcnt; + char *sp, *dp; + + swidth = (sw + 7) / 8; + dwidth = (dw + 7) / 8; + + lcnt = 0; + sp = smem; + dp = dmem; + for ( i=0; i < sh; i++ ) { + lcnt += dh; + if ( lcnt >= sh ) { + exline( sp, dbuf, sw, dw ); + sp += swidth; + lcnt -= sh; + memcpy( dp, dbuf, dwidth ); + dp += dwidth; + for ( ; lcnt >= sh; lcnt -= sh ) { + memcpy( dp, dbuf, dwidth ); + dp += dwidth; + } + } else { + sp += swidth; + } + } + return 0; +} + +static +exline( sp, dbuf, sw, dw ) +char *sp; +char *dbuf; +int sw; +int dw; +{ + int i, bit, sval, dval, dcnt, bcnt; + + bcnt = dval = 0; + dcnt = 8; + + for ( i = 0; i < sw; i++ ) { + if ( i % 8 == 0 ) { + sval = *sp++; + } + bit = ( (sval & 0x80) ? 1 : 0 ); + sval <<= 1; + for ( bcnt += dw; bcnt >= sw; bcnt -= sw ) { + dval = ( dval << 1 ) | bit; + if ( --dcnt == 0 ) { + *dbuf++ = (char)dval; + dval = 0; + dcnt = 8; + } + } + } + if ( dcnt != 8 ) { + dval <<= dcnt; + *dbuf = (char)dval; + } + return 0; +} + +static unsigned char _Fal_Mask_Tab[8] = { + 0xff, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe +}; + +static char +falGetMask( width ) +int width; +{ + int ix = width % 8; + return _Fal_Mask_Tab[ix]; +} + + +/* a difinition of a style */ +static FalFontDB fal_db_style[] = { + { FAL_FONT_MINCHO, FAL_FONT_STR_MINCHO }, + { FAL_FONT_GOTHIC, FAL_FONT_STR_GOTHIC }, + { FAL_FONT_MARU_GOTHIC, FAL_FONT_STR_MARU_GOTHIC }, + { FAL_FONT_TEXTBOOK, FAL_FONT_STR_TEXTBOOK }, + { FAL_FONT_BRASH_GYOU, FAL_FONT_STR_BRASH_GYOU }, + { FAL_FONT_BRASH_KAI, FAL_FONT_STR_BRASH_KAI }, + { FAL_FONT_HANDWRITING, FAL_FONT_STR_HANDWRITING }, + { FAL_FONT_UNKNOWN, ""} +}; + +/* a difinition of a shape */ +static FalFontDB fal_db_shape[] = { + { FAL_FONT_ZENKAKU, FAL_FONT_STR_ZENKAKU }, + { FAL_FONT_HANKAKU, FAL_FONT_STR_HANKAKU }, + { FAL_FONT_QUARTER, FAL_FONT_STR_QUARTER }, + { FAL_FONT_UNKNOWN, ""} +}; + +FAL_DB_OPTION ; + +/*********************************************************/ +/* make a font information list and carry to user */ +/*********************************************************/ + +#if NeedFunctionPrototypes +int +FalGetFontList( + FalFontData *key_data, + int mask, + FalFontDataList **list_ret ) +#else +int +FalGetFontList( key_data, mask, list_ret ) +FalFontData *key_data; /* a structure of a searching information */ +int mask; /* a mask */ +FalFontDataList **list_ret; /* maked a address of a structure */ +#endif +{ + + FalFontDataList *fls; /* a pointer of a structure of "FalFontDataList()" */ + + /* clear an error's data */ + fal_utyerror = 0; + fal_utyderror = 0; + fal_utyerrno = 0 ; + + /* change mode */ + SET_EXECDEFAULT( mask, execDefined, execUndefined ) ; + + /* interface check */ + if ( list_ret == NULL ) { + fal_utyerror = _FAL_PARM_ER; + fal_utyderror = _FAL_L_P_LST_DER; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ; + return FAL_ERROR ; + } + + /* character check */ + if ( chk_key_str( key_data, mask ) == FAL_ERROR ) { + fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ; + return FAL_ERROR; + } + + /* error check */ + if ( orgn.path == NULL ) { + if ( set_default_path() == FAL_ERROR ) { + fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ; + return FAL_ERROR ; + } + } + + /* make an structure of "FalFontDataList()" */ + if ((fls = (FalFontDataList *)malloc( sizeof( FalFontDataList ))) == NULL){ + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ; + return FAL_ERROR ; + } + + /* inital set for search */ + fls->num = 0; + fls->list = NULL; + + /* make font infomation list */ + if ( fal_make_fontlist( fls, key_data, mask ) == FAL_ERROR) { + switch( fal_utyerror ) { + case _FAL_FLST_ER : + case _FAL_DATA_OPEN_ER : + fal_utyderror = 1; + } + FalFreeFontList( fls ); + fal_utyerrno &= 0xff; + fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ; + return FAL_ERROR; + } + /* sort element of font infomation list */ + if( fal_sort_fontlist( fls ) == FAL_ERROR ) { + FalFreeFontList( fls ); + fal_utyerrno &= 0xff; + fal_utyerrno |= (FAL_FUNCNUM_GFLST<<8) ; + return FAL_ERROR ; + } + + *list_ret = fls; + return 0; +} + + + +/***********************************************************************/ +/* search a character "key" of a structure */ +/***********************************************************************/ + +static int +chk_key_str( key, mask ) +FalFontData *key; /* a structure of saerching information */ +int mask; /* a mask */ +{ + int flg = 0; + + if( key == NULL ) { + return 0 ; + } + + /* check a character of setting a mask */ + /* xlfd name */ + if ((mask & FAL_FONT_MASK_XLFDNAME) && (key->xlfdname == NULL)) { + flg++; + } + /* style */ + if ((mask & FAL_FONT_MASK_STYLE_NAME) && (key->style.name == NULL)) { + flg++; + } + /* shape */ + if ((mask & FAL_FONT_MASK_SHAPE_NAME) && (key->shape.name == NULL)) { + flg++; + } + CHK_KEY_STR_OPTION( mask, key, flg ) ; + /* error check */ + if ( flg ) { + fal_utyerror = _FAL_PARM_ER; + fal_utyderror = _FAL_L_P_KEY_DER; + fal_utyerrno = FAL_ERR_PARM ; + return FAL_ERROR ; + } + return 0 ; +} + + +/***************************************************************/ +/* read a font information and add a list or make a list */ +/***************************************************************/ + + +static int +fal_make_fontlist( fls, key, mask ) +FalFontDataList *fls; /* a pointer of a structure of a font information list */ +FalFontData *key; /* a structure of searching information */ +int mask; /* a mask for a saerch */ +{ + return falReadFontInfoLists(MKFONTLIST, + key, mask, fls, + NULL, NULL, + NULL, NULL) ; +} + + +/**************************************************/ +/* free a structure of "FalFontDataList()" */ +/**************************************************/ + +#if NeedFunctionPrototypes +int +FalFreeFontList( + FalFontDataList *list ) +#else +int +FalFreeFontList( list ) +FalFontDataList *list; +#endif +{ + int i; + + /* parametter check */ + if ( list == NULL ) { + fal_utyerror = _FAL_PARM_ER; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_FRFLST<<8) ; + return FAL_ERROR; + } + /* free a structure's array of "FalFontData()" */ + if ( list->list != NULL ) { + for ( i = 0; i < list->num; i++ ) { + /* free a structure's character of "FalFontData()" */ + free( list->list[i].xlfdname ); + free( list->list[i].style.name ); + free( list->list[i].shape.name ); + FAL_FREE_FONTLIST_OPTION( list ) ; + } + /* free a structure's array of "FalFontData()" */ + free( list->list ); + } + list->num = 0 ; + list->list = NULL ; + + /* free a structure of " FalFontDataList()" */ + free( list ); + return 0; +} + + +/***********************************************************************/ +/* split string for "FalFontData()" */ +/***********************************************************************/ + +static int +fal_split_data( buf, elm_num, elm) +char *buf; +int elm_num; +char *elm[]; +{ + int cnt; + int strtop_flg; + + /* check a comment */ + if ((*buf == '#') || (*buf == '\0')) { + return _FAL_TRY_NEXT; + } + /* check a pathname */ + if ( *buf == '/' ) { + return _FAL_TRY_NEXT; + } + /* divide a data */ + for ( cnt = 0, strtop_flg = 1 ; *buf != '\0'; buf++ ){ + if ( strtop_flg ) { + elm[cnt] = buf; + cnt++; + strtop_flg = 0; + } + if ( *buf == ':' ) { + *buf = '\0'; + strtop_flg++; + } + } + if ( cnt != elm_num ) { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_FLST_ER; + fal_utyerrno = FAL_ERR_FDATA_DSC ; + return FAL_ERROR; + } + return 0; +} + +/***********************************************************************/ +/* clear a structure of "FalFontData()" */ +/***********************************************************************/ + +static int +fal_clear_data(tmp) +FalFontData *tmp; +{ + /* search a character */ + free(tmp->xlfdname); + free(tmp->style.name); + free(tmp->shape.name); + FAL_CLEAR_DATA_OPTION( tmp ) ; + memset(tmp, 0, sizeof(*tmp)); + return 0 ; +} + +static int +fal_check_already_exist( data, lst ) +FalFontData *data; +FalFontDataList *lst; +{ + int i; + int mask ; + + mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_STYLE_NAME + | FAL_FONT_MASK_SIZE_H | FAL_FONT_MASK_CODE_SET ; + + for ( i=0 ; i < lst->num ; i++ ){ + switch ( fal_cmp_data( &(lst->list[i]), data, mask ) ) { + case 0: + return(i); + default: + continue; + } + } + return(-1); +} + + + +static int +fal_sort_fontlist( lst ) +FalFontDataList *lst; +{ + int i,j; + FalFontDataList srt; + FalFontData target; + int target_entry; + + if( lst->num == 0 ){ + return 0 ; + } + + srt.num = lst->num; + + if (( srt.list = malloc(sizeof(FalFontData) * srt.num)) == NULL) { + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR; + } + memmove (srt.list, lst->list, sizeof(FalFontData) * srt.num); + /* start to sort */ + for ( i=0 ; i < srt.num -1 ; i++ ) { + + memmove( &target, &(srt.list[i]), sizeof(FalFontData)); + target_entry = i; + + for ( j=i+1 ; j < srt.num ; j++ ) { + if ( new_target( &target, &(srt.list[j]) ) ) { + memmove( &target, &(srt.list[j]), sizeof(FalFontData)); + target_entry = j; + } + } + if (target_entry != i) { + memmove( &target, &(srt.list[target_entry]), + sizeof(FalFontData) + ); + memmove( &(srt.list[i+1]), &(srt.list[i]), + sizeof(FalFontData)*(target_entry -i) + ); + memmove( &(srt.list[i]), &target, + sizeof(FalFontData) + ); + } + } + free(lst->list); + lst->list = srt.list; + return 0 ; +} + + + +/***************************************/ +/* change a character for a number */ +/***************************************/ + +static int +fal_atoi(str, val) +char *str; +int *val; +{ + char *ptr; + char *str_end; + int tmp; + + str_end = strchr( str, '\0' ); + + tmp = (int)strtol(str, &ptr, 10); + + /* error check */ + if ((ptr == str) || (ptr != str_end)) { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_FLST_ER; + fal_utyerrno = FAL_ERR_FDATA_DSC ; + return(FAL_ERROR); + } + *val = tmp; + return 0 ; +} + +/*******************************/ +/* get a codeset */ +/*******************************/ + +static int +fal_set_cs(str, cs) +char *str; +int *cs; +{ + if (!strcmp(str, "CS0")) { + *cs = FAL_FONT_CS0; + } else if (!strcmp(str, "CS1")) { + *cs = FAL_FONT_CS1; + } else if (!strcmp(str, "CS2")) { + *cs = FAL_FONT_CS2; + } else if (!strcmp(str, "CS3")) { + *cs = FAL_FONT_CS3; + } else { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_FLST_ER; + fal_utyerrno = FAL_ERR_FDATA_DSC ; + return(FAL_ERROR); + } + return(0); +} + + +/******************************************/ +/* get a equipment of an output permission*/ +/******************************************/ + + +static int +fal_set_prm(str, prm) +char *str; +int *prm; +{ + int tmp = 0; + for ( ; *str != '\0' ; str++) { + if( *str == 'P' ) { + tmp |= FAL_FONT_PRINTER; + } else if( *str == 'D' ) { + tmp |= FAL_FONT_DISPLAY; + } else { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_FLST_ER; + fal_utyerrno = FAL_ERR_FDATA_DSC ; + return FAL_ERROR ; + } + } + *prm = tmp; + return 0 ; +} + +static int fal_read_db( str, db ) +char *str; +FalFontDB *db; +{ + int i; + + for(i=0 ; db[i].def != FAL_FONT_UNKNOWN ; i++) { + if (!strcmp(str, db[i].name)) { + return(db[i].def); + } + } + return FAL_FONT_UNKNOWN ; +} + + +/***************************************/ +/* make a structure of "FalFontPath()" */ +/***************************************/ + +int +FalGetFontPath( dlist_ret ) +FalFontPath **dlist_ret; +{ + + /* clear an error data */ + fal_utyerror = 0; + fal_utyderror = 0; + fal_utyerrno = 0 ; + + /* get current locale */ + if( fal_init() ) return FAL_ERROR ; + + /* parametter check */ + if ( dlist_ret == NULL ) { + fal_utyerror = _FAL_PARM_ER; + fal_utyerrno = FAL_ERR_PARM ; + return FAL_ERROR; + } + if ( orgn.path == NULL ) { + if ( set_default_path() == FAL_ERROR ) { + return FAL_ERROR; + } + if ( cpy_default_path( © ) == FAL_ERROR ){ + return FAL_ERROR; + } + } else if ( copy.path == NULL ) { + if ( cpy_default_path(©) == FAL_ERROR ){ + return FAL_ERROR; + } + } else { + + if ( comp_default_path( © ) == FAL_ERROR ) { + fal_clear_font_path( © ); + if ( cpy_default_path(©) == FAL_ERROR ){ + return FAL_ERROR; + } + } + } + *dlist_ret = © + return 0; +} + +static int +set_default_path() +{ + return set_font_pathlist(&orgn, 0) ; +} + +static int +cpy_default_path( p ) +FalFontPath *p; +{ + int i; + FalFontPath tmp; + + if ((orgn.num == 0) || (orgn.path == NULL)) { + p->num = 0; + p->path = NULL; + return 0; + } + + if ( + (tmp.path = (char **)malloc(sizeof(char *) * (orgn.num) )) + == NULL + ){ + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR; + } + tmp.num = 0; + for ( i = 0 ; i< orgn.num ; i++ ) { + char *tmp_str; + /* malloc & copy in strdup */ + if ((tmp_str = (char *)strdup((orgn.path)[i])) == NULL) { + fal_clear_font_path( &tmp ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + tmp.path[i] = tmp_str; + tmp.num++; + } + p->num = tmp.num; + p->path = tmp.path; + return 0; +} + +static int +comp_default_path(p) +FalFontPath *p; +{ + int i; + + if ( p->num != orgn.num ) { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerrno = FAL_ERR_FPATH ; + return FAL_ERROR; + } + for ( i = 0; i < p->num; i++ ) { + if( strcmp( p->path[i], orgn.path[i] ) ) { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerrno = FAL_ERR_FPATH ; + return FAL_ERROR; + } + } + return 0; +} + + +static int +fal_clear_font_path( ls ) +FalFontPath *ls; +{ + int i; + + if (ls->path != NULL) { + /* free a fontpath character */ + for (i=0 ; i < ls->num ; i++) { + if ((ls->path[i] != NULL) && (ls->path[i] == orgn.path[i])) { + free(ls->path[i]); + } + } + /* free a character pointer array */ + free( ls->path ); + ls->path = NULL; + } + ls->num = 0; + + return 0; +} + + +/* access number */ +#define FAL_FONT_ELM_FILENAME 0 +#define FAL_FONT_ELM_SIZE_W 1 +#define FAL_FONT_ELM_SIZE_H 2 +#define FAL_FONT_ELM_LETTER_W 3 +#define FAL_FONT_ELM_LETTER_H 4 +#define FAL_FONT_ELM_LETTER_X 5 +#define FAL_FONT_ELM_LETTER_Y 6 +#define FAL_FONT_ELM_STYLE_NAME 7 +#define FAL_FONT_ELM_SHAPE_NAME 8 + +#define FAL_FONT_ELM_CODE_SET 10 +#define FAL_FONT_ELM_PERMISSION 11 +#define FAL_FONT_ELM_XLFDNAME 12 + +int +set_struct( tmp_data, elm ) +FalFontData *tmp_data; +char *elm[]; +{ + char *dup_p; + + /* data information */ + + /* a width of a character size */ + if ( fal_atoi( + elm[FAL_FONT_ELM_SIZE_W], &(tmp_data->size.w ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* a height of a character size */ + if ( fal_atoi( + elm[FAL_FONT_ELM_SIZE_H], &(tmp_data->size.h ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* a width of a letter size */ + if ( fal_atoi( + elm[FAL_FONT_ELM_LETTER_W], &(tmp_data->letter.w ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* a height of a letter size */ + if ( fal_atoi( + elm[FAL_FONT_ELM_LETTER_H], &(tmp_data->letter.h ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* position x of a letter size */ + if ( fal_atoi( + elm[FAL_FONT_ELM_LETTER_X], &(tmp_data->letter.x ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* position y of a letter size */ + if ( fal_atoi( + elm[FAL_FONT_ELM_LETTER_Y], &(tmp_data->letter.y ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* codeset */ + if ( fal_set_cs( + elm[FAL_FONT_ELM_CODE_SET], &(tmp_data->cd_set ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + /* a equipment of an output permission */ + if ( fal_set_prm( + elm[FAL_FONT_ELM_PERMISSION], &(tmp_data->prm ) + ) == FAL_ERROR + ) { + goto FalError02 ; + } + + /* character information */ + + /* xlfd name */ + if ( ( dup_p = (char *)strdup( elm[FAL_FONT_ELM_XLFDNAME] ) ) == NULL ) { + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR; + } + tmp_data->xlfdname = dup_p; + + /* character style (character) */ + if ( ( dup_p = (char *)strdup( elm[FAL_FONT_ELM_STYLE_NAME] ) ) == NULL) { + free( tmp_data->xlfdname ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR; + } + tmp_data->style.name = dup_p; + + /* character style (numerical) */ + tmp_data->style.def + = fal_read_db( tmp_data->style.name, (FalFontDB *)&fal_db_style ); + + /* character shape (character) */ + if ( ( dup_p = (char *)strdup( elm[FAL_FONT_ELM_SHAPE_NAME] ) ) == NULL ) { + free( tmp_data->style.name ); + free( tmp_data->xlfdname ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR; + } + tmp_data->shape.name = dup_p; + + /* character shape (numerical) */ + tmp_data->shape.def + = fal_read_db( tmp_data->shape.name, (FalFontDB *)&fal_db_shape ); + + SET_STRUCT_OPTION( dup_p, elm, tmp_data, fal_utyerror, fal_db_group ) ; + return 0; + +FalError02: + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerrno = FAL_ERR_FDATA_DSC ; + return FAL_ERROR; +} + +/* get a full path name */ +int searchFontFileName( data, fullPathName ) +FalFontData data; +char *fullPathName; +{ + int rtn ; + rtn = falReadFontInfoLists(SRCHFNAME, + NULL, NULL, NULL, + data, fullPathName, + NULL, NULL) ; + if( fal_utyerrno != 0 ){ + fal_utyerrno |= (FAL_FUNCNUM_SRCHFNM<<8) ; + } + return rtn ; +} + + +int fal_eq_data( data, tmp_data ) +FalFontData data; +FalFontData tmp_data; +{ + int flg = 0; + + /* xlfd name */ + if ( strcmp( data.xlfdname, tmp_data.xlfdname ) != 0 ) { + flg++; + } + + /* a width of a character size */ + if ( ( flg == 0 ) && ( data.size.h != tmp_data.size.h ) ) { + flg++; + } + + /* a height of a character size */ + if ( ( flg == 0 ) && ( data.size.w != tmp_data.size.w ) ) { + flg++; + } + /* a height of a letter size */ + if ( ( flg == 0 ) && ( data.letter.h != tmp_data.letter.h ) ) { + flg++; + } + + /* a width of a letter size */ + if ( ( flg == 0 ) && ( data.letter.w != tmp_data.letter.w ) ) { + flg++; + } + + /* position x of a letter size */ + if ( ( flg == 0 ) && ( data.letter.x != tmp_data.letter.x ) ) { + flg++; + } + + /* position y of a letter size */ + if ( ( flg == 0 ) && ( data.letter.y != tmp_data.letter.y ) ) { + flg++; + } + + /* a definition data of a character style */ + if ( ( flg == 0 ) && ( data.style.def != tmp_data.style.def ) ) { + flg++; + } + + /* character style */ + if ( (data.style.name != NULL) && (tmp_data.style.name != NULL) ) { + if ( ( flg == 0 ) && ( strcmp( data.style.name, tmp_data.style.name ) != 0 ) ) { + flg++; + } + } + + /* a definition data of a character shape */ + if ( ( flg == 0 ) && ( data.shape.def != tmp_data.shape.def ) ) { + flg++; + } + + /* character shape */ + if ( (data.shape.name != NULL) && (tmp_data.shape.name != NULL) ) { + if ( ( flg == 0 ) && ( strcmp( data.shape.name, tmp_data.shape.name ) != 0 ) ) { + flg++; + } + } + + FAL_EQ_DATA_OPTION( flg, data, tmp_data ) ; + + /* code set */ + if ( ( flg == 0 ) && ( data.cd_set != tmp_data.cd_set ) ) { + flg++; + } + + /* an equipment of an output permission */ + if ( ( flg == 0 ) && ( data.prm != tmp_data.prm ) ) { + flg++; + } + + if ( flg == 0 ) { + return 0; + } else if ( flg != 0 ) { + return _FAL_TRY_NEXT; + } else { + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerrno = FAL_ERR_FDATA_DSC ; + return FAL_ERROR; + } +} + + +static int +CR_to_NULL(buf) +char *buf; +{ + for( ; *buf != '\0'; buf++ ) { + if (*buf == '\n') { + *buf = '\0'; + break; + } + } + return 0 ; +} + +char *fal_get_base_name( str ) +char *str; +{ + char *str_slash; + + str_slash = strrchr( str, '/'); + if ( str_slash == NULL ) { + return( str ); + } + return( ++str_slash ); +} + + +static int +fal_cmp_data( op1, key, mask ) +FalFontData *op1; +FalFontData *key; +int mask ; +{ + if ( mask == 0 ) { + return(0); + } + + if ( key == NULL ) { + return(0); + } + + if ( + ( mask & FAL_FONT_MASK_XLFDNAME ) + && strcmp( op1->xlfdname, key->xlfdname ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_SIZE_W ) + && (op1->size.w != key->size.w ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_SIZE_H ) + && (op1->size.h != key->size.h ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_LETTER_W ) + && ( op1->letter.w != key->letter.w ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_LETTER_H ) + && ( op1->letter.h != key->letter.h ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_LETTER_X ) + && ( op1->letter.x != key->letter.x ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_LETTER_Y ) + && ( op1->letter.y != key->letter.y ) + ) { + return _FAL_TRY_NEXT; + } + if ( + ( mask & FAL_FONT_MASK_STYLE_DEF ) + && ( op1->style.def != key->style.def ) + ) { + return _FAL_TRY_NEXT; + } + if( (op1->style.name != NULL) && (key->style.name != NULL) ) { + if ( + ( mask & FAL_FONT_MASK_STYLE_NAME ) + && strcmp( op1->style.name, key->style.name ) + ) { + return _FAL_TRY_NEXT; + } + } + if ( + ( mask & FAL_FONT_MASK_SHAPE_DEF ) + && ( op1->shape.def != key->shape.def ) + ) { + return _FAL_TRY_NEXT; + } + if( (op1->shape.name != NULL) && (key->shape.name != NULL) ) { + if ( + ( mask & FAL_FONT_MASK_SHAPE_NAME ) + && strcmp( op1->shape.name, key->shape.name ) + ) { + return _FAL_TRY_NEXT; + } + } + FAL_CMP_DATA_OPTION( mask, op1, key ) ; + if ( + ( mask & FAL_FONT_MASK_CODE_SET ) + && ( op1->cd_set != key->cd_set ) + ) { + return _FAL_TRY_NEXT; + } + if ( mask & FAL_FONT_MASK_PERMISSION ) { + int cmp_prm; + cmp_prm = key->prm & (FAL_FONT_DISPLAY | FAL_FONT_PRINTER); + if ( ( op1->prm & cmp_prm ) != cmp_prm ) { + return _FAL_TRY_NEXT; + } + } + return 0; +} + + +/* sort flag */ +/* return data ¡§ sort ... 1 */ +/* no sort ... 0 */ + +static int +new_target( target, choose ) +FalFontData *target; +FalFontData *choose; +{ + FalFontData diff; + DEF_STR_CHK ; + + DEF_STR_SET ; + + diff.style.def = choose->style.def - target->style.def; + if( (choose->style.name != NULL) && (target->style.name != NULL) ) { + str_chk.style = strcmp( choose->style.name, target->style.name ) ; + } + + NEW_TARGET_SET( diff, choose, target, str_chk ) ; + + diff.shape.def = choose->shape.def - target->shape.def; + if( (choose->shape.name != NULL) && (target->shape.name != NULL) ) { + str_chk.shape = strcmp( choose->shape.name, target->shape.name ) ; + } + + diff.cd_set = choose->cd_set - target->cd_set; + diff.size.h = choose->size.h - target->size.h; + diff.size.w = choose->size.w - target->size.w; + diff.letter.h = choose->letter.h - target->letter.h; + diff.letter.w = choose->letter.w - target->letter.w; + + /* style */ + if ( target->style.def == FAL_FONT_UNKNOWN ) { + if ( choose->style.def > 0 ) { + return 1; + } + /* style is FAL_FONT_UNKNOWN both "target" and "choose" */ + if ( str_chk.style < 0 ) { + return 1; + } + if ( str_chk.style > 0) { + return 0; + } + } else if ( choose->style.def == FAL_FONT_UNKNOWN ) { + return 0; + } + /* target->style.def and choose->style.def is not FAL_FONT_UNKNOWN */ + if (diff.style.def < 0) { + return 1; + } + if ( diff.style.def > 0) { + return 0; + } + + NEW_TARGET_CHK( diff, choose, target, str_chk ) ; + + /* character shape */ + if ( target->shape.def == FAL_FONT_UNKNOWN ) { + if ( choose->shape.def > 0 ) { + return 1; + } + if ( str_chk.shape < 0 ) { + return 1; + } + if ( str_chk.shape > 0 ) { + return 0; + } + } else if (choose->shape.def == FAL_FONT_UNKNOWN ) { + return 0; + } + if ( diff.shape.def < 0 ) { + return 1; + } + if ( diff.shape.def > 0 ) { + return 0; + } + + /* codeset */ + if ( diff.cd_set < 0 ) { + return 1; + } + if (diff.cd_set > 0) { + return 0; + } + + /* character size height */ + if ( diff.size.h < 0 ) { + return 1; + } + if ( diff.size.h > 0 ) { + return 0; + } + + /* letter size height */ + if ( diff.letter.h < 0 ) { + return 1; + } + if ( diff.letter.h > 0 ) { + return 0; + } + + /* character size wide */ + if ( diff.size.w < 0 ) { + return 1; + } + if ( diff.size.w > 0 ) { + return 0; + } + + /* letter size wide */ + if ( diff.letter.w < 0 ) { + return 1; + } + if ( diff.letter.w > 0 ) { + return 0; + } + + return 0; +} + +#if NeedFunctionPrototypes +int FalFontOfFontID( + FalFontID fid, + FalFontData *fontdata ) +#else +int FalFontOfFontID( fid, fontdata ) +FalFontID fid; +FalFontData *fontdata; +#endif +{ + int rtn ; + rtn = falReadFontInfoLists(FONTOFID, + NULL, NULL, NULL, + NULL, NULL, + fid, fontdata) ; + if( fal_utyerrno != 0 ){ + fal_utyerrno |= (FAL_FUNCNUM_FID<<8) ; + } + return rtn ; +} + +#if NeedFunctionPrototypes +FalFontID +FalOpenSysFont( + FalFontData *open_font_data, + int font_data_mask, + FalFontDataList **missing_font_list_return ) +#else +FalFontID +FalOpenSysFont( open_font_data, font_data_mask, missing_font_list_return ) +FalFontData *open_font_data; +int font_data_mask; +FalFontDataList **missing_font_list_return; +#endif +{ + int retFL; /* return a data of FontList */ + FalFontID retOF; /* return a data of OpenFont */ + char fname[FAL_LINE_MAX]; + + /* follow "font_data_mask" and call "FalGetFontList()" */ + retFL = FalGetFontList( + open_font_data, font_data_mask, missing_font_list_return + ); + /* case of an abnormal end */ + if ( retFL != 0 ) { + *missing_font_list_return = NULL; + return 0; + } + + if ( (*missing_font_list_return)->num > 1 ) { + return 0; + } else if ( (*missing_font_list_return)->num == 1 ) { + /* investigator an font file name */ + int slct_cdset, prm, islock, dspcode ; + if ( + searchFontFileName( + (*missing_font_list_return)->list[0], fname + ) == FAL_ERROR + ){ + FalFreeFontList( *missing_font_list_return ); + fal_utyerrno &= 0xff ; + fal_utyerrno |= (FAL_FUNCNUM_SRCHFNM<<8) ; + *missing_font_list_return = NULL; + return 0; + } + /* open a font by "__FalOpenFont()" */ + slct_cdset = (*missing_font_list_return)->list[0].cd_set ; + dspcode = ( font_data_mask & FAL_FONT_MASK_GLYPH_INDEX )? + FAL_FONT_GLYPH_INDEX : slct_cdset ; + prm = ((*missing_font_list_return)->list[0].prm ) ? + (*missing_font_list_return)->list[0].prm : + FAL_FONT_DISPLAY | FAL_FONT_PRINTER ; + islock = (( font_data_mask & FAL_FONT_MASK_UPDATE )? 1 : 0 ); + retOF = __FalOpenFont( fname, prm, dspcode, islock ); + + if ( retOF == (FalFontID)FAL_ERROR ) { + /* abnomal end */ + FalFreeFontList( *missing_font_list_return ); + fal_utyerrno &= 0xff ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + *missing_font_list_return = NULL; + return 0; + } else { + /* normal end ( return retOF ) */ + *missing_font_list_return = NULL; + FalFreeFontList( *missing_font_list_return ); + if( fal_add_fidinf( retOF, + dspcode, slct_cdset, islock ) == FAL_ERROR ){ + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + return 0 ; + } + return retOF; + } + } else if ( (*missing_font_list_return)->num == 0 ) { + /* + * set NULL in "missing_font_list_return" + */ + FalFreeFontList( *missing_font_list_return ); + *missing_font_list_return = NULL; + return 0; + } else { + /* case abnormal */ + *missing_font_list_return = NULL; + fal_utyerrno = FAL_ERR_FATAL ; + fal_utyerrno |= (FAL_FUNCNUM_OPNFNT<<8) ; + return 0; + } +} + + +/******************************************************** +* function to access fonts.list +********************************************************/ +static +FILE *open_fonts_list() +{ + + FILE *fp; + char *locale = NULL ; + char *fal_search_path = NULL ; + char flist_d[FAL_LINE_MAX] ; + char flist_c[FAL_LINE_MAX] ; + char flist_l[FAL_LINE_MAX] ; + + GETLISTFILEPATH( locale, fal_search_path, flist_d, flist_c, flist_l, FONTS_LIST_FILE ) ; + + if ( ( fp = fopen( flist_l, "r" ) ) == NULL ) { + if( (fp = fopen( flist_c, "r" )) == NULL ) { + if( (fp = fopen( flist_d, "r" )) == NULL ) { + set_errfile_str( fal_err_file, flist_d ) ; + set_errfile_str( fal_err_file_buf, flist_d ) ; + fal_utyerror = _FAL_DATA_OPEN_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FDATA_OPN ; + }else{ + /* Save full path of fonts.list. */ + set_errfile_str( fal_err_file_buf, flist_d ) ; + if( IsDefaultPath == TRUE ) IsDefaultPath = FALSE ; + } + }else{ + /* Save full path of fonts.list. */ + set_errfile_str( fal_err_file_buf, flist_c ) ; + if( IsDefaultPath == TRUE ) IsDefaultPath = FALSE ; + } + }else{ + /* Save full path of fonts.list. */ + set_errfile_str( fal_err_file_buf, flist_l ) ; + if( IsDefaultPath == TRUE ) IsDefaultPath = FALSE ; + } + + return( fp ) ; +} + + + +/* + * functions to read "fonts.dir" files + */ + +/***************************************************************/ +/* read a font information and add a list or make a list */ +/***************************************************************/ + + +static int +set_font_pathlist(pathlist, nodef) +FalFontPath *pathlist ; +int nodef ; +{ + FILE *fp; + char buf[FAL_LINE_MAX]; + char *font_path = NULL ; + char **tmp_list ; + int num; + + errno = 0; + /* open a font directory information file */ + if ((fp = open_fonts_list()) == NULL) { + /* Make default path list */ + if( errno == ENOENT || errno == EACCES || errno == EISDIR ){ + if ( make_default_path(pathlist) ) { + return FAL_ERROR ; + } + return 0 ; + } + return FAL_ERROR ; + } + memset( buf, '\0', sizeof(buf) ) ; + + while ( fgets( buf, FAL_LINE_MAX, fp ) != (char *)NULL ){ + struct stat statbuf ; + char *ep ; + + CR_to_NULL(buf); + + if( buf[0] == '#' ){ /* comments */ + continue ; + }else if( buf[0] == '/' ){ /* font path */ + + /* add font_path to pathlist */ + if( font_path ){ + num = pathlist->num; + if (pathlist->path == NULL) { + tmp_list = (char **)malloc(sizeof(char *)*(num +1)); + } else { + tmp_list = (char **)realloc(pathlist->path, sizeof(char *)*(num+1)); + } + if (tmp_list == NULL) { + fclose( fp ); + free( font_path ); + fal_clear_font_path( pathlist ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + pathlist->path = tmp_list; + pathlist->path[num] = font_path; + pathlist->num++; + } + + /* get font_path */ + if ((font_path = (char *)strdup(buf)) == NULL) { + fclose( fp ); + fal_clear_font_path( pathlist ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + ep = font_path + strlen( font_path ) - 1 ; + *ep = '/'; /* ':' -> '/' */ + if( *(ep-1) == '/' ) *ep = '\0'; + + if( stat( font_path, &statbuf ) ) { + free( font_path ) ; + font_path = NULL ; + continue; + } + if( !(statbuf.st_mode & S_IFDIR) ) { + free( font_path ) ; + font_path = NULL ; + continue; + } + + }else{ /* font file */ + if( nodef ){ + if( font_path ){ + free( font_path ) ; + font_path = NULL ; + } + } + continue ; + } + + } + /* add font_path to pathlist */ + if( font_path ){ + num = pathlist->num; + if (pathlist->path == NULL) { + tmp_list = (char **)malloc(sizeof(char *)*(num +1)); + } else { + tmp_list = (char **)realloc(pathlist->path, sizeof(char *)*(num+1)); + } + if (tmp_list == NULL) { + fclose( fp ); + free( font_path ); + fal_clear_font_path( pathlist ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + pathlist->path = tmp_list; + pathlist->path[num] = font_path; + pathlist->num++; + } + + if ( feof(fp) != 0 ){ + fclose(fp); + return 0 ; + } + fclose(fp); + fal_clear_font_path( pathlist ); + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_READ_PATH_ER; + fal_utyerrno = FAL_ERR_FPATH ; + return FAL_ERROR; +} + + + +static int +make_default_path(pathlist) +FalFontPath *pathlist ; +{ + struct stat statbuf ; + char pbuf[FAL_LINE_MAX], *dir, *p ; + char *path, **plist ; + char *sp, *ep ; + int len, num; + + memset( pbuf, '\0', sizeof(pbuf) ) ; + + p = pbuf ; + if( (dir = getenv( "DTUDCFONTPATH" )) != NULL ) { + len = strlen( dir ) ; + strcpy( p, dir ) ; + p[len++] = ':' ; + p += len ; + } + strcpy( p, DTUDCFONTPATH ) ; + strcat( p, ":" ) ; + + sp = pbuf ; + while ( (ep = strchr( sp, ':' )) != (char *)NULL ){ + + /* get path */ + *ep = '\0' ; + if ((path = (char *)malloc(sizeof(char) * (strlen(sp)+2))) == NULL) { + fal_clear_font_path( pathlist ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + strcpy( path, sp ) ; + len = strlen( sp ) ; + path[len++] = '/' ; + path[len] = '\0' ; + if( path[len-2] == '/' ) path[len-1] = '\0'; + + if( stat(path, &statbuf) ) { + free( path ) ; + sp = ep + 1 ; + continue; + } + if( !(statbuf.st_mode & S_IFDIR) ) { + free( path ) ; + sp = ep + 1 ; + continue; + } + + /* add path to pathlist */ + num = pathlist->num; + if (pathlist->path == NULL) { + plist = (char **)malloc(sizeof(char *)*(num +1)); + } else { + plist = (char **)realloc(pathlist->path, sizeof(char *)*(num+1)); + } + if (plist == NULL) { + fal_clear_font_path( pathlist ); + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + free(path); + return FAL_ERROR ; + } + pathlist->path = plist; + pathlist->path[num] = path; + pathlist->num++; + sp = ep + 1 ; + } + if( execDefined == TRUE ) execDefined = FALSE ; + if( IsDefaultPath == FALSE ) IsDefaultPath = TRUE ; + fal_utyerror = 0 ; + fal_utyderror = 0 ; + fal_utyerrno = 0 ; + return 0 ; +} + + + + +static int +falReadFontInfoLists(func, lstkey, mask, fls, fnkey, fullpath, fid, fdata) +int func ; + /* parameters for FalGetFontList */ +FalFontData *lstkey; +int mask; +FalFontDataList *fls; + /* parameters for searchFontFileName */ +FalFontData fnkey; +char *fullpath; + /* parameters for FalFontOfFontID */ +FalFontID fid ; +FalFontData *fdata; +{ + FILE *fp; + char pname[ FAL_LINE_MAX ] ; + Oak_FontInf *finf; + + FalFontData tmp_data; + FontIDInfo fontid_inf; + char *elm[FAL_DATA_ELM * 3]; + char buf[FAL_LINE_MAX * 3]; + + struct stat statbuf ; + char *keyfname, *fontFileName, *fonts_list_file ; + int i, j ; + int fontnum ; + int codeset_num, *codeset_list ; + + keyfname = fontFileName = fonts_list_file = NULL ; + codeset_num = 0 ; + codeset_list = NULL ; + if( func & FONTOFID ){ + finf = (Oak_FontInf *)fid ; + keyfname = finf->fname ; + } + + /* get current locale */ + if( fal_init() ) return FAL_ERROR ; + + /* get font path list */ + if( wpath.path==NULL ) { + if( set_font_pathlist( &wpath, 1 ) ) { + return FAL_ERROR ; + } + } + /* + * If execDefined is true, this function read detail informations + * of the fonts descripted in fonts.list. + */ + if( execDefined == TRUE && IsDefaultPath == FALSE ) { + /* open an information file */ + if ((fp = open_fonts_list()) == NULL) { + return FAL_ERROR ; + } + memset( pname, 0, sizeof( pname ) ); + + while ( fgets( buf, FAL_LINE_MAX, fp ) != ( char * ) NULL ) { + int eq; + + /* clear an area */ + memset( elm, 0, sizeof( elm ) ); + memset( &tmp_data, 0, sizeof( tmp_data ) ); + CR_to_NULL( buf ); + + /* + * get font information of a font + */ + switch( fal_get_def_fontdata(func, pname, buf, elm, &tmp_data, keyfname ) ) { + case _FAL_TRY_NEXT: + if( buf[0] == '/' ) { + buf[strlen( buf ) -1] = '/' ; + strcpy( pname, buf ) ; + } + continue; + case 0: + break; + case FAL_ERROR: + default: + goto FalError ; + } + + switch( func ) { + case MKFONTLIST : /* FalGetFontList */ + switch( falgetfontlist(&tmp_data, lstkey, mask, fls, 1) ){ + case _FAL_TRY_NEXT : + continue ; + case 0: + break; + case FAL_ERROR: + default: + goto FalError ; + } + break ; + case SRCHFNAME : /* searchFontFileName */ + eq = fal_eq_data( fnkey, tmp_data ) ; + switch ( eq ) { + case 0 : + sprintf( fullpath, "%s%s", pname, elm[ FAL_FONT_ELM_FILENAME ] ); + fal_clear_data( &tmp_data ) ; + fclose(fp) ; + return 0 ; + case _FAL_TRY_NEXT : + fal_clear_data( &tmp_data ) ; + break ; + default : /* FAL_ERROR */ + goto FalError ; + } + break ; + case FONTOFID : /* FalFontOfFontID */ + memmove( fdata, &tmp_data, sizeof(FalFontData) ) ; + fclose(fp) ; + return 0 ; + default : + fal_utyerrno = FAL_ERR_PARM ; + goto FalError ; + } + + } /* end of while loop */ + /* EOF */ + if ( feof( fp ) != 0 ) { + fclose( fp ); + }else{ + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_DATA_READ_ER; + fal_utyerrno = FAL_ERR_FDATA_RD ; + fclose( fp ); + return FAL_ERROR ; + } + + if( (func & SRCHFNAME) && (execUndefined == FALSE) ){ + fal_utyerrno = FAL_ERR_NOFONT ; + return FAL_ERROR ; + } + + } /* execDefined */ + + /* + * If execUnefined is true, this function read list of font path, + * and get the name of font file from fonts.dir. + */ + if( execUndefined == TRUE ) { + + /* + * search font path + */ + for( i=0; ilist == NULL ) { + p_bak = (FalFontData *)malloc(sizeof(FalFontData) * (fls->num + fontnum)); + } else { + p_bak = (FalFontData *)realloc(fls->list, sizeof(FalFontData)*(fls->num + fontnum)); + } + if ( p_bak == NULL ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + fls->list = p_bak ; + } + + memset( buf, 0, sizeof(buf)); + + while( fgets( buf, FAL_LINE_MAX, fp ) != (char *)NULL ) { + int tmp_num, eq ; + char *ep, *xlfd ; + + /* set FalFontData */ + CR_to_NULL(buf); /* '\n' -> '\0' */ + memset( &tmp_data, 0, sizeof(FalFontData)); + + /* parse string of font file */ + if( (ep = strchr( buf, ' ' )) == (char *)NULL ) continue ; + else *ep = 0 ; + /* refuse font file (not gpf) */ + if( + ( strcmp( FILE_SUFFIX(buf), PCFSUFFIX ) != 0 ) && + ( strcmp( FILE_SUFFIX(buf), SNFSUFFIX ) != 0 ) && + ( ISOPTFONT(buf) != 0 ) + ){ + continue ; + } + + /* get string of font file */ + if( (func & SRCHFNAME) || (func & FONTOFID) ){ + fontFileName = (char *)malloc( sizeof(char) * ( strlen(wpath.path[i]) + strlen(buf) + 1 ) ) ; + if( fontFileName == (char *)NULL ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + sprintf( fontFileName, "%s%s", wpath.path[i], buf ) ; + } + + /* read font file and get properties */ + xlfd = ++ep ; + switch( fal_get_undef_fontdata(func, fontFileName, xlfd, &tmp_data, keyfname, &codeset_num, &codeset_list) ) + { + case _FAL_TRY_NEXT : + if( (func & SRCHFNAME) || (func & FONTOFID) ) FreeString( fontFileName ) ; + fal_clear_data( &tmp_data ); + memset( buf, 0, sizeof(buf)); + continue ; + case 0: + if( (func & FONTOFID) ) FreeString( fontFileName ) ; + break; + case FAL_ERROR: + default: + if( (func & SRCHFNAME) || (func & FONTOFID) ) FreeString( fontFileName ) ; + goto FalError ; + } + + if( !(func & FONTOFID) && (codeset_num == 0) ){ + if( (func & SRCHFNAME) ) FreeString( fontFileName ) ; + fal_clear_data( &tmp_data ); + memset( buf, 0, sizeof(buf)); + continue ; + } + + switch( func ) { + case MKFONTLIST : /* FalGetFontList */ + tmp_num = fls->num ; + case SRCHFNAME : /* searchFontFileName */ + /* set font data */ + for( j=0; j= 0 ) { + continue; + } + + switch( falgetfontlist(&tmp_data, lstkey, mask, fls, 1) ){ + case _FAL_TRY_NEXT : + continue ; + case 0: + break; + case FAL_ERROR: + default: + goto FalError ; + } + } + if( func & SRCHFNAME ){ /* searchFontFileName */ + eq = fal_eq_data( fnkey, tmp_data ) ; + switch ( eq ) { + case 0 : + strcpy( fullpath, fontFileName ); + fal_clear_data( &tmp_data ) ; + FreeString( fontFileName ) ; + tmp_codeset = tmp_data.cd_set ; + fclose(fp) ; + /* clear code set informations */ + clear_charset_info() ; + return 0 ; + case _FAL_TRY_NEXT : + break ; + default : /* FAL_ERROR */ + FreeString( fontFileName ) ; + goto FalError ; + } + } + } /* for loop */ + if( func & MKFONTLIST ){ /* FalGetFontList */ + if( fls->num == tmp_num ) fal_clear_data( &tmp_data ) ; + } + if( func & SRCHFNAME ){ /* searchFontFileName */ + fal_clear_data( &tmp_data ) ; + FreeString( fontFileName ) ; /* _FAL_TRY_NEXT */ + } + break ; + + case FONTOFID : /* FalFontOfFontID */ + memmove( fdata, &tmp_data, sizeof(FalFontData) ) ; + if( fal_read_fidinf( fid, &fontid_inf ) != FAL_ERROR ) + fdata->cd_set = fontid_inf.cd_set ; + else { + fdata->cd_set = 0 ; + goto FalError ; + } + fclose(fp) ; + return 0 ; + + default : + goto FalError ; + } + + memset(buf, 0, sizeof(buf)); + } /* while loop */ + + if ( feof(fp) != 0 ) { + fclose(fp); + }else{ + set_errfile_str( fal_err_file, fal_err_file_buf ) ; + fal_utyerror = _FAL_DATA_READ_ER; + fal_utyerrno = FAL_ERR_FNTDIR_RD ; + fclose(fp); + return FAL_ERROR; + } + + } /* for loop */ + + /* clear code set informations */ + clear_charset_info() ; + + if( (func & SRCHFNAME) || (func & FONTOFID) ){ + fal_utyerrno = FAL_ERR_NOFONT ; + return FAL_ERROR ; + } + + } /* execUndefined */ + + return 0 ; + +FalError: + + clear_charset_info() ; + fal_clear_data( &tmp_data ) ; + fclose(fp) ; + return FAL_ERROR ; + +} + + +/* clear code set informations */ +static void +clear_charset_info() +{ + if( charset_str_buf ) free( charset_str_buf ) ; + charset_str_buf = NULL ; + if( codeset_list_sav ) free( codeset_list_sav ) ; + codeset_list_sav = NULL ; + codeset_list_num = 0 ; +} + + +static int +fal_get_def_fontdata(func, pname, buf, elm, tmp_data, key_fname) +int func ; +char *pname ; /* font path */ +char *buf ; /* buffer for fgets() */ +char **elm ; +FalFontData *tmp_data ; +char *key_fname ; +{ + int rtn ; + char tmp_fname[FAL_LINE_MAX] ; + + if( (rtn = fal_split_data( buf, FAL_DATA_ELM, elm )) ) { + return rtn ; + } + + if( func & FONTOFID ){ + sprintf( tmp_fname, "%s%s", pname, elm[ FAL_FONT_ELM_FILENAME ] ); + if( strcmp( tmp_fname, key_fname ) ) return _FAL_TRY_NEXT ; + } + + /* set informations to structrue */ + if ( set_struct( tmp_data, elm ) == FAL_ERROR ) { + return FAL_ERROR; + } + return 0 ; +} + + + +static int +falgetfontlist(tmp_data, key, mask, fls, fontnum) +FalFontData *tmp_data ; +FalFontData *key ; +int mask ; +FalFontDataList *fls ; +int fontnum ; +{ + FalFontData *p_bak ; + + if( fontnum == 0 ){ + return _FAL_TRY_NEXT ; + } + + /* compare with key data */ + if ( fal_cmp_data(tmp_data, key, mask) == _FAL_TRY_NEXT ) { + return _FAL_TRY_NEXT ; + } + + if ( fls->list == NULL ) { + p_bak = malloc(sizeof(FalFontData) * (fls->num + fontnum)); + } else { + p_bak = realloc(fls->list, sizeof(FalFontData)*(fls->num + fontnum)); + } + if ( p_bak == NULL ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + fls->list = p_bak; + memmove(&(fls->list[fls->num]), tmp_data, sizeof(FalFontData)); + fls->num++; /* update number of fonts */ + + return 0 ; +} + + + +static int +fal_get_undef_fontdata(func, full_path, xlfd, tmp_data, key_fname, codeset_num, codeset_list) +int func ; +char *full_path ; +char *xlfd ; +FalFontData *tmp_data ; +char *key_fname ; +int *codeset_num ; +int **codeset_list ; +{ + int rtn, pix ; + char *char_set ; + char xlfdname[ FAL_LINE_MAX ], *family, *pixsize ; + char *cbuf, *ep ; + + /* FalFontOfFontID() */ + if( func & FONTOFID ){ + if( strcmp( full_path, key_fname ) ) return _FAL_TRY_NEXT ; + } + + /* + * parse XLFD and get font informations + */ + cbuf = ep = family = pixsize = NULL ; + /* XLFD */ + strcpy( xlfdname, xlfd ) ; + /* pixel size */ + GETXLFDELMSTR( pixsize, xlfd, XLFD_ELM_PIXEL_SIZE ) ; + ep = (char *)strchr( pixsize, '\0' ) ; + pix = (int)strtol( pixsize, &cbuf, 10 ) ; + if( cbuf == pixsize || cbuf != ep ){ + return _FAL_TRY_NEXT ; + } + /* family name */ + GETXLFDELMSTR( family, xlfd, XLFD_ELM_FAMILY_NAME ) ; + + /* set font data */ + if( (tmp_data->style.name = (char *)strdup( family )) == NULL ) { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + if( (tmp_data->xlfdname = (char *)strdup( xlfdname )) == NULL ) { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + tmp_data->size.h = pix ; + tmp_data->size.w = -1 ; + + /* FalGetFontList() and searchFontFilename() */ + if( (func & MKFONTLIST) || (func & SRCHFNAME) ){ + GETCHARSETSTR( char_set, tmp_data->xlfdname ) ; + /* code set infomations exist */ + if( charset_str_buf && !strcmp( charset_str_buf, char_set ) ) { + *codeset_num = codeset_list_num ; + *codeset_list = codeset_list_sav ; + }else{ + /* clear code set infomations */ + clear_charset_info() ; + /* get code set infomations */ + if( (rtn = fal_get_codeset( fal_locale, char_set, codeset_list, codeset_num )) ){ + return rtn ; + } + /* save code set infomations */ + if( (charset_str_buf = (char *)strdup( char_set )) == NULL ) { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + codeset_list_num = *codeset_num ; + codeset_list_sav = *codeset_list ; + } + } + return 0 ; +} + + + +/* + * get file name of fonts + */ + +#if NeedFunctionPrototypes +int +FalFontIDToFileName( + FalFontID fid, + char **file_name ) +#else +int +FalFontIDToFileName( fid, file_name ) +FalFontID fid; +char **file_name; +#endif +{ + char *fname ; + Oak_FontInf *finf ; + if( fid == NULL ) { + fal_utyerror = _FAL_PARM_ER ; + fal_utyderror = _FAL_R_P_FINF_DER ; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_IDTOFNM<<8) ; + return FAL_ERROR ; + } + if( file_name == NULL ) { + fal_utyerror = _FAL_PARM_ER ; + fal_utyderror = _FAL_R_P_W_DER ; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_IDTOFNM<<8) ; + return FAL_ERROR ; + } + finf = (Oak_FontInf *)fid ; + if( (fname = (char *)strdup( finf->fname )) == NULL ) { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + fal_utyerrno |= (FAL_FUNCNUM_IDTOFNM<<8) ; + return FAL_ERROR ; + } + *file_name = fname ; + return 0 ; +} + + +#if NeedFunctionPrototypes +int +FalFree( + void *list ) +#else +int +FalFree( list ) +void *list ; +#endif +{ + if( list == NULL ) { + fal_utyerror = _FAL_PARM_ER ; + fal_utyerrno = FAL_ERR_PARM ; + fal_utyerrno |= (FAL_FUNCNUM_FREE<<8) ; + return FAL_ERROR ; + } + free( list ) ; + return 0 ; +} + + + +int +FalFreeGI( ginf, num ) +FalGIInf *ginf ; +int num ; +{ + int i ; + if( ginf == NULL ) { + fal_utyerror = _FAL_PARM_ER ; + fal_utyerrno = FAL_ERR_PARM ; + return FAL_ERROR ; + } + for( i=0; ifid ) { + exist++ ; + mngfid.finf[i]->dspcode = dspcode ; + mngfid.finf[i]->cd_set = cd_set ; + mngfid.finf[i]->islock = islock ; + break ; + } + } + /* add new data */ + if( !exist ) { + if( mngfid.finf == NULL ) { + cnt = 0 ; + if( (flist = (FontIDInfo **)malloc( sizeof(FontIDInfo *) )) == NULL ) { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + } else { + cnt = mngfid.num ; + if( (flist = (FontIDInfo **)realloc( + mngfid.finf, sizeof(FontIDInfo *) * (cnt + 1) )) == NULL ) + { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + } + if( (flist[cnt] = (FontIDInfo *)malloc( sizeof(FontIDInfo) )) == NULL ) { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + free(flist); + return FAL_ERROR ; + } + flist[cnt]->fid = fid ; + flist[cnt]->cd_set = cd_set ; + flist[cnt]->dspcode = dspcode ; + flist[cnt]->islock = islock ; + + mngfid.num = cnt + 1 ; + mngfid.finf = flist ; + } + + return 0 ; +} + +static int +fal_read_fidinf( fid, fontid_inf ) +FalFontID fid ; +FontIDInfo *fontid_inf; +{ + int i ; + if( fid == NULL ) { + fal_utyerror = _FAL_PARM_ER ; + fal_utyerrno = FAL_ERR_PARM ; + return FAL_ERROR ; + } + for( i=0; ifid == fid ) { + fontid_inf->fid = fid ; + fontid_inf->cd_set = mngfid.finf[i]->cd_set ; + fontid_inf->dspcode = mngfid.finf[i]->dspcode ; + fontid_inf->islock = mngfid.finf[i]->islock ; + return 0 ; + } + } + fal_utyerror = _FAL_PARM_ER ; + fal_utyerrno = FAL_ERR_FID_RD ; + return FAL_ERROR ; +} + + +static int +fal_del_fidinf( fid ) +FalFontID fid ; +{ + int i, cnt, target ; + FontIDInfo **flist ; + + for( i=0; ifid == fid ) { + target = i ; + break ; + } + } + cnt = mngfid.num - 1 ; + free( mngfid.finf[target] ) ; + for( i=target; i 0 ) { + if( (flist = (FontIDInfo **)realloc( + mngfid.finf, sizeof(FontIDInfo *) * cnt )) == NULL ) + { + fal_utyerror = _FAL_MALOC_ER ; + fal_utyerrno = FAL_ERR_MALLOC ; + return FAL_ERROR ; + } + mngfid.num = cnt ; + mngfid.finf = flist ; + } else { + free( mngfid.finf ) ; + mngfid.num = 0 ; + mngfid.finf = NULL ; + } + return 0 ; +} + +/* + * convert codepoint into glyph index + */ + +static int +fal_conv_code_to_glyph( fid, code, glidx ) +FalFontID fid ; +unsigned int code ; +unsigned int *glidx ; +{ + Oak_FontInf *finf ; + FalFontData tmp_data ; + FalGIInf *gi ; + FontIDInfo fontid_inf ; + int gnum ; + int i ; + int inner_code = 0 ; + char *char_set ; + static FalFontID cmpfid = 0 ; + static char charset_name[FAL_LINE_MAX] ; + + finf = (Oak_FontInf *)fid ; + /* + * get code set number + */ + if( fal_read_fidinf( fid, &fontid_inf ) == FAL_ERROR ) { + return FAL_ERROR; + } + + if( fontid_inf.dspcode != FAL_FONT_GLYPH_INDEX ){ + /* + * get string of "CHARSET_REGISTRY" + */ + memset( &tmp_data, 0, sizeof(FalFontData) ) ; + + if( cmpfid != fid ){ + if( falReadGpfProp( FAL_READ_FONTINFO, finf, FAL_FONT_PRM, &tmp_data ) ) { + fal_clear_data( &tmp_data ) ; + return FAL_ERROR; + } + GETCHARSETSTR( char_set, tmp_data.xlfdname ) ; + snprintf( charset_name, sizeof(charset_name), "%s", char_set ) ; + } + + /* + * convert codepoint into glyph index + */ + if( COMM_SBFNT_ISSBFNT( charset_name ) ) { + inner_code = code ; + FAL_OPT_CONVCPTOGI( fontid_inf.dspcode, inner_code ) ; + } else { + if( fal_code_to_glyph( fal_locale, code, &gi, &gnum ) ) { + fal_clear_data( &tmp_data ) ; + return FAL_ERROR; + } + if( gnum==1 ){ + inner_code = gi[0].glyph_index ; + }else{ + for( i=0; i*********************************/ diff --git a/cde/programs/dtudcfonted/libfal/falfont.h b/cde/programs/dtudcfonted/libfal/falfont.h new file mode 100644 index 00000000..43947891 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/falfont.h @@ -0,0 +1,88 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: falfont.h /main/5 1996/06/25 20:05:39 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#define GETNUMCHARS(pFinf) \ + (((pFinf)->lastCol - (pFinf)->firstCol + 1) * \ + ((pFinf)->lastRow - (pFinf)->firstRow + 1)) + +#define GETHIGHT(pCinf) \ + ((pCinf)->metrics.ascent + (pCinf)->metrics.descent) + +#define _FAL_OK 1 +/* fal_utyerror */ +#define _FAL_OPEN_ER 1 +#define _FAL_DIR_NOACCSS 1 +#define _FAL_READ_ER 2 +#define _FAL_READ_PATH_ER 2 +#define _FAL_MALOC_ER 3 +#define _FAL_PKEY_ER 4 +#define _FAL_PARM_ER 5 +#define _FAL_STAT_ER 6 +#define _FAL_FONT_ER 7 +#define _FAL_FLST_ER 7 +#define _FAL_DATA_OPEN_ER 8 +#define _FAL_DATA_READ_ER 9 + +/* fal_utyderror */ +/* FalOpenFont */ +#define _FAL_O_P_PKEY_DER 1 +#define _FAL_O_P_CS_DER 2 +/* FalQueryFont */ +#define _FAL_Q_P_FINF_DER 1 +#define _FAL_Q_P_FONT_DER 2 +/* FalReadFont */ +#define _FAL_R_P_FINF_DER 1 +#define _FAL_R_P_W_DER 2 +#define _FAL_R_P_H_DER 3 + +/* FalGetFontList */ +#define _FAL_L_P_LST_DER 1 +#define _FAL_L_P_KEY_DER 2 + +#define _FAL_TRY_NEXT 0xFF + +#include "udccom.h" + +#define SNF_BOUND 32 + + +#define FILE_SUFFIX( file ) \ + ( strrchr( file, '.' ) ? strrchr( file, '.' ) : "" ) + + +#define FAL_DATA_ELM 13 +#define FAL_LINE_MAX 1024 + +/* update _Oak_Finf */ +#define FAL_UPDATE_FONTINFO 1 +#define FAL_READ_FONTINFO 0 + +/* Buffer of file name */ +extern char fal_err_file_buf[] ; diff --git a/cde/programs/dtudcfonted/libfal/fonts.list.header b/cde/programs/dtudcfonted/libfal/fonts.list.header new file mode 100644 index 00000000..d3db1648 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/fonts.list.header @@ -0,0 +1,26 @@ +############################################################################# +##### ##### +##### fonts.list ##### +##### ##### +##### All Rights Reserved, Copyright (C) FUJITSU LIMITED 1995 ##### +##### ##### +############################################################################# +# +# This file is referenced by : +# +# dtudcfonted +# dtudcexch +# dtaddcpf +# dtcpgpf +# dtgpftocpf +# dtcpftogpf +# dtgpftobdf +# dtbdftocpf +# dtcpftobdf +# and dtlsgpf. +# +# font path ==> path1: +# path2: +# : +# pathN: +# diff --git a/cde/programs/dtudcfonted/libfal/include/font.h b/cde/programs/dtudcfonted/libfal/include/font.h new file mode 100644 index 00000000..59211e38 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/include/font.h @@ -0,0 +1,116 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: font.h /main/1 1995/09/14 20:54:34 cde-fuj2 $ */ +/*********************************************************** +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, +and the Massachusetts Institute of Technology, Cambridge, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Digital or MIT not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +(c) Copyright 1995 FUJITSU LIMITED +This is source code modified by FUJITSU LIMITED under the Joint +Development Agreement for the CDEnext PST. +This is unpublished proprietary source code of FUJITSU LIMITED + +******************************************************************/ +#ifndef FONT_H +#define FONT_H 1 + +#include "servermd.h" + +#define NullCharInfo ((CharInfoPtr)0) +#define NullFontInfo ((FontInfoPtr)0) +#define LeftToRight 0 +#define RightToLeft 1 +/* + * for linear char sets + */ +#define n1dChars(pfi) ((pfi)->lastCol - (pfi)->firstCol + 1) +#define chFirst firstCol /* usage: pfi->chFirst */ +#define chLast lastCol /* usage: pfi->chLast */ + +/* + * for 2D char sets + */ +#define n2dChars(pfi) (((pfi)->lastCol - (pfi)->firstCol + 1) * \ + ((pfi)->lastRow - (pfi)->firstRow + 1)) + +#define ADDRXTHISCHARINFO( pf, ch ) \ + ((CharInfoRec *) &((pf)->pCI[(ch) - (pf)->pFI->chFirst])) + +#define GLWIDTHPIXELS(pci) \ + ((pci)->metrics.rightSideBearing - (pci)->metrics.leftSideBearing) +#define GLHEIGHTPIXELS(pci) \ + ((pci)->metrics.ascent + (pci)->metrics.descent) + + +#define GLYPHWIDTHBYTES(pci) (((GLYPHWIDTHPIXELS(pci))+7) >> 3) +#define GLYPHHEIGHTPIXELS(pci) (pci->metrics.ascent + pci->metrics.descent) +#define GLYPHWIDTHPIXELS(pci) (pci->metrics.rightSideBearing \ + - pci->metrics.leftSideBearing) +#define GLWIDTHPADDED( bc) ((bc+7) & ~0x7) + +#if GLYPHPADBYTES == 0 || GLYPHPADBYTES == 1 +#define GLYPHWIDTHBYTESPADDED(pci) (GLYPHWIDTHBYTES(pci)) +#define PADGLYPHWIDTHBYTES(w) (((w)+7)>>3) +#endif + +#if GLYPHPADBYTES == 2 +#define GLYPHWIDTHBYTESPADDED(pci) ((GLYPHWIDTHBYTES(pci)+1) & ~0x1) +#define PADGLYPHWIDTHBYTES(w) (((((w)+7)>>3)+1) & ~0x1) +#endif + +#if GLYPHPADBYTES == 4 +#define GLYPHWIDTHBYTESPADDED(pci) ((GLYPHWIDTHBYTES(pci)+3) & ~0x3) +#define PADGLYPHWIDTHBYTES(w) (((((w)+7)>>3)+3) & ~0x3) +#endif + +#if GLYPHPADBYTES == 8 /* for a cray? */ +#define GLYPHWIDTHBYTESPADDED(pci) ((GLYPHWIDTHBYTES(pci)+7) & ~0x7) +#define PADGLYPHWIDTHBYTES(w) (((((w)+7)>>3)+7) & ~0x7) +#endif + +typedef struct _FontProp *FontPropPtr; +typedef struct _CharInfo *CharInfoPtr; +typedef struct _FontInfo *FontInfoPtr; +typedef unsigned int DrawDirection; +typedef struct _ExtentInfo *ExtentInfoPtr; + + +#endif /* FONT_H */ diff --git a/cde/programs/dtudcfonted/libfal/include/fontstruct.h b/cde/programs/dtudcfonted/libfal/include/fontstruct.h new file mode 100644 index 00000000..215bbfe0 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/include/fontstruct.h @@ -0,0 +1,122 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: fontstruct.h /main/3 1996/04/08 15:58:01 cde-fuj $ */ +/*********************************************************** +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, +and the Massachusetts Institute of Technology, Cambridge, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Digital or MIT not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +(c) Copyright 1995 FUJITSU LIMITED +This is source code modified by FUJITSU LIMITED under the Joint +Development Agreement for the CDEnext PST. +This is unpublished proprietary source code of FUJITSU LIMITED + +******************************************************************/ +#ifndef FONTSTRUCT_H +#define FONTSTRUCT_H 1 +#include "font.h" +#include "misc.h" + +typedef struct _CharInfo { + xCharInfo metrics; /* info preformatted for Queries */ + unsigned byteOffset:24; /* byte offset of the raster from pGlyphs */ + Bool exists:1; /* true iff glyph exists for this char */ + unsigned pad:7; /* must be zero for now */ +} CharInfoRec; + +typedef struct _FontInfo { + unsigned int version1; /* version stamp */ + unsigned int allExist; + unsigned int drawDirection; + unsigned int noOverlap; /* true if: + * max(rightSideBearing-characterWidth) + * <= minbounds->metrics.leftSideBearing + */ + unsigned int constantMetrics; + unsigned int terminalFont; /* Should be deprecated! true if: + constant metrics && + leftSideBearing == 0 && + rightSideBearing == characterWidth && + ascent == fontAscent && + descent == fontDescent + */ + unsigned int linear:1; /* true if firstRow == lastRow */ + unsigned int constantWidth:1; /* true if minbounds->metrics.characterWidth + * == maxbounds->metrics.characterWidth + */ + unsigned int inkInside:1; /* true if for all defined glyphs: + * leftSideBearing >= 0 && + * rightSideBearing <= characterWidth && + * -fontDescent <= ascent <= fontAscent && + * -fontAscent <= descent <= fontDescent + */ + unsigned int inkMetrics:1; /* ink metrics != bitmap metrics */ + /* used with terminalFont */ + /* see font's pInk{CI,Min,Max} */ + unsigned int padding:28; + unsigned int firstCol; + unsigned int lastCol; + unsigned int firstRow; + unsigned int lastRow; + unsigned int nProps; + unsigned int lenStrings; /* length in bytes of string table */ + unsigned int chDefault; /* default character */ + int fontDescent; /* minimum for quality typography */ + int fontAscent; /* minimum for quality typography */ + CharInfoRec minbounds; /* MIN of glyph metrics over all chars */ + CharInfoRec maxbounds; /* MAX of glyph metrics over all chars */ + unsigned int pixDepth; /* intensity bits per pixel */ + unsigned int glyphSets; /* number of sets of glyphs, for + sub-pixel positioning */ + unsigned int version2; /* version stamp double-check */ +} FontInfoRec; + +typedef struct _ExtentInfo { + DrawDirection drawDirection; + int fontAscent; + int fontDescent; + int overallAscent; + int overallDescent; + int overallWidth; + int overallLeft; + int overallRight; +} ExtentInfoRec; + +#endif /* FONTSTRUCT_H */ diff --git a/cde/programs/dtudcfonted/libfal/include/misc.h b/cde/programs/dtudcfonted/libfal/include/misc.h new file mode 100644 index 00000000..d22eded9 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/include/misc.h @@ -0,0 +1,181 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: misc.h /main/7 1996/04/08 15:58:10 cde-fuj $ */ +/*********************************************************** +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, +and the Massachusetts Institute of Technology, Cambridge, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Digital or MIT not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +(c) Copyright 1995 FUJITSU LIMITED +This is source code modified by FUJITSU LIMITED under the Joint +Development Agreement for the CDEnext PST. +This is unpublished proprietary source code of FUJITSU LIMITED + +******************************************************************/ +#ifndef MISC_H +#define MISC_H 1 +/* + * X internal definitions + * + */ + + +extern unsigned long globalSerialNumber; +extern unsigned long serverGeneration; + +#ifndef NULL +#if __STDC__ && !NOSTDHDRS +#include +#else +#define NULL 0 +#endif +#endif + +#define MAXSCREENS 3 +#define MAXCLIENTS 128 +#define MAXFORMATS 8 +#define MAXVISUALS_PER_SCREEN 50 + +typedef unsigned char *pointer; +typedef int Bool; +typedef unsigned long PIXEL; +typedef unsigned long ATOM; + + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif +#include "os.h" /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */ + +#define NullBox ((BoxPtr)0) +#define MILLI_PER_MIN (1000 * 60) +#define MILLI_PER_SECOND (1000) + + /* this next is used with None and ParentRelative to tell + PaintWin() what to use to paint the background. Also used + in the macro IS_VALID_PIXMAP */ + +#define USE_BACKGROUND_PIXEL 3 +#define USE_BORDER_PIXEL 3 + + +/* byte swap a long literal */ +#define lswapl(x) ((((x) & 0xff) << 24) |\ + (((x) & 0xff00) << 8) |\ + (((x) & 0xff0000) >> 8) |\ + (((x) >> 24) & 0xff)) + +/* byte swap a short literal */ +#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)) + +#define min(a, b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) +#ifndef abs +#define abs(a) ((a) > 0 ? (a) : -(a)) +#endif +#ifndef fabs +#define fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */ +#endif +#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) +/* this assumes b > 0 */ +#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b) +/* + * return the least significant bit in x which is set + * + * This works on 1's complement and 2's complement machines. + * If you care about the extra instruction on 2's complement + * machines, change to ((x) & (-(x))) + */ +#define lowbit(x) ((x) & (~(x) + 1)) + +#define MAXSHORT 32767 +#define MINSHORT -MAXSHORT + + +/* some macros to help swap requests, replies, and events */ + +#define LengthRestB(stuff) \ + (((unsigned long)stuff->length << 2) - sizeof(*stuff)) + +#define LengthRestS(stuff) \ + (((unsigned long)stuff->length << 1) - (sizeof(*stuff) >> 1)) + +#define LengthRestL(stuff) \ + ((unsigned long)stuff->length - (sizeof(*stuff) >> 2)) + +#define SwapRestS(stuff) \ + SwapShorts((short *)(stuff + 1), LengthRestS(stuff)) + +#define SwapRestL(stuff) \ + SwapLongs((long *)(stuff + 1), LengthRestL(stuff)) + +/* byte swap a long */ +#define swapl(x, n) n = ((char *) (x))[0];\ + ((char *) (x))[0] = ((char *) (x))[3];\ + ((char *) (x))[3] = n;\ + n = ((char *) (x))[1];\ + ((char *) (x))[1] = ((char *) (x))[2];\ + ((char *) (x))[2] = n; + +/* byte swap a short */ +#define swaps(x, n) n = ((char *) (x))[0];\ + ((char *) (x))[0] = ((char *) (x))[1];\ + ((char *) (x))[1] = n + +/* copy long from src to dst byteswapping on the way */ +#define cpswapl(src, dst) \ + ((char *)&(dst))[0] = ((char *) &(src))[3];\ + ((char *)&(dst))[1] = ((char *) &(src))[2];\ + ((char *)&(dst))[2] = ((char *) &(src))[1];\ + ((char *)&(dst))[3] = ((char *) &(src))[0]; + +/* copy short from src to dst byteswapping on the way */ +#define cpswaps(src, dst)\ + ((char *) &(dst))[0] = ((char *) &(src))[1];\ + ((char *) &(dst))[1] = ((char *) &(src))[0]; + +extern void SwapLongs(); +extern void SwapShorts(); + +typedef struct _DDXPoint *DDXPointPtr; +typedef struct _Box *BoxPtr; + +#endif /* MISC_H */ diff --git a/cde/programs/dtudcfonted/libfal/include/os.h b/cde/programs/dtudcfonted/libfal/include/os.h new file mode 100644 index 00000000..d651f10f --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/include/os.h @@ -0,0 +1,169 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: os.h /main/6 1996/05/28 15:33:04 ageorge $ */ +/*********************************************************** +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, +and the Massachusetts Institute of Technology, Cambridge, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Digital or MIT not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +(c) Copyright 1995 FUJITSU LIMITED +This is source code modified by FUJITSU LIMITED under the Joint +Development Agreement for the CDEnext PST. +This is unpublished proprietary source code of FUJITSU LIMITED + +******************************************************************/ + + +#ifndef OS_H +#define OS_H +#include "misc.h" + +#ifdef INCLUDE_ALLOCA_H +#include +#endif + +#define NullFID ((FID) 0) + +#define SCREEN_SAVER_ON 0 +#define SCREEN_SAVER_OFF 1 +#define SCREEN_SAVER_FORCER 2 + +#if defined(stellar) +#define MAX_REQUEST_SIZE 65535 +#else +#define MAX_REQUEST_SIZE 16384 +#endif + +typedef pointer FID; +typedef struct _FontPathRec *FontPathPtr; +typedef struct _NewClientRec *NewClientPtr; + +#ifndef NO_ALLOCA +/* + * os-dependent definition of local allocation and deallocation + * If you want something other than Xalloc/Xfree for ALLOCATE/DEALLOCATE + * LOCAL then you add that in here. + */ +#if defined(__HIGHC__) + +extern char *alloca(); + +#if HCVERSION < 21003 +#define ALLOCATE_LOCAL(size) alloca((int)(size)) +pragma on(alloca); +#else /* HCVERSION >= 21003 */ +#define ALLOCATE_LOCAL(size) _Alloca((int)(size)) +#endif /* HCVERSION < 21003 */ + +#define DEALLOCATE_LOCAL(ptr) /* as nothing */ + +#endif /* defined(__HIGHC__) */ + + +#if defined(__GNUC__) +#if !defined(__linux__) +#ifdef alloca +#undef alloca +#endif +#define alloca ___builtin_alloca +#endif +#define ALLOCATE_LOCAL(size) alloca((int)(size)) +#define DEALLOCATE_LOCAL(ptr) /* as nothing */ +#else /* ! __GNUC__ */ +/* + * warning: mips alloca is unsuitable in the server, do not use. + */ +#if defined(vax) || defined(sun) || defined(stellar) +/* + * Some System V boxes extract alloca.o from /lib/libPW.a; if you + * decide that you don't want to use alloca, you might want to fix + * ../os/4.2bsd/Imakefile + */ +char *alloca(); +#define ALLOCATE_LOCAL(size) alloca((int)(size)) +#define DEALLOCATE_LOCAL(ptr) /* as nothing */ +#endif /* who does alloca */ +#endif /* __GNUC__ */ + +#endif /* NO_ALLOCA */ + +#ifndef ALLOCATE_LOCAL +#define ALLOCATE_LOCAL(size) Xalloc((unsigned long)(size)) +#define DEALLOCATE_LOCAL(ptr) Xfree((pointer)(ptr)) +#endif /* ALLOCATE_LOCAL */ + + +#define xalloc(size) Xalloc((unsigned long)(size)) +#define xrealloc(ptr, size) Xrealloc((pointer)(ptr), (unsigned long)(size)) +#define xfree(ptr) Xfree((pointer)(ptr)) + +int ReadRequestFromClient(); +#ifndef strcat +char *strcat(); +#endif +#ifndef strncat +char *strncat(); +#endif +#ifndef strcpy +char *strcpy(); +#endif +#ifndef strncpy +char *strncpy(); +#endif +Bool CloseDownConnection(); +FontPathPtr GetFontPath(); +FontPathPtr ExpandFontNamePattern(); +FID FiOpenForRead(); +void CreateWellKnownSockets(); +int SetDefaultFontPath(); +void FreeFontRecord(); +int SetFontPath(); +void ErrorF(); +void Error(); +void FatalError(); +void ProcessCommandLine(); +void Xfree(); +void FlushAllOutput(); +void FlushIfCriticalOutputPending(); +unsigned long *Xalloc(); +unsigned long *Xrealloc(); +long GetTimeInMillis(); + +#endif /* OS_H */ diff --git a/cde/programs/dtudcfonted/libfal/include/pcf.h b/cde/programs/dtudcfonted/libfal/include/pcf.h new file mode 100644 index 00000000..ad36b922 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/include/pcf.h @@ -0,0 +1,107 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: pcf.h /main/2 1996/02/10 16:25:46 cde-fuj $ */ +/* + * + * Copyright 1990 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + (c) Copyright 1995 FUJITSU LIMITED + This is source code modified by FUJITSU LIMITED under the Joint + Development Agreement for the CDEnext PST. + This is unpublished proprietary source code of FUJITSU LIMITED + */ + +#ifndef _PCF_H_ +#define _PCF_H_ + +/* + * Information used to read/write PCF fonts + */ + +typedef struct _PCFTable { + CARD32 type; + CARD32 format; + CARD32 size; + CARD32 offset; +} PCFTableRec, *PCFTablePtr; + +#define PCF_FILE_VERSION (('p'<<24)|('c'<<16)|('f'<<8)|1) +#define PCF_FORMAT_MASK 0xffffff00 + +#define PCF_DEFAULT_FORMAT 0x00000000 +#define PCF_INKBOUNDS 0x00000200 +#define PCF_ACCEL_W_INKBOUNDS 0x00000100 +#define PCF_COMPRESSED_METRICS 0x00000100 + +#define PCF_FORMAT_MATCH(a,b) (((a)&PCF_FORMAT_MASK) == ((b)&PCF_FORMAT_MASK)) + +#define PCF_GLYPH_PAD_MASK (3<<0) +#define PCF_BYTE_MASK (1<<2) +#define PCF_BIT_MASK (1<<3) +#define PCF_SCAN_UNIT_MASK (3<<4) + +#define PCF_BYTE_ORDER(f) (((f) & PCF_BYTE_MASK)?MSBFirst:LSBFirst) +#define PCF_BIT_ORDER(f) (((f) & PCF_BIT_MASK)?MSBFirst:LSBFirst) +#define PCF_GLYPH_PAD_INDEX(f) ((f) & PCF_GLYPH_PAD_MASK) +#define PCF_GLYPH_PAD(f) (1<> 4) +#define PCF_SCAN_UNIT(f) (1< 1, because the padding of the fonts has already + * guarenteed you that your fonts are longword aligned. On the other + * hand, even if you have chosen GLYPHPADBYTES == 1 to save space, you may + * also decide that the computing involved in aligning the pointer is more + * costly than an odd-address access; you choose GETLEFTBITS_ALIGNMENT == 1. + * + * Next, choose the tuning parameters which are appropriate for your + * hardware; these modify the behaviour of the raw frame buffer code + * in ddx/mfb and ddx/cfb. Defining these incorrectly will not cause + * the server to run incorrectly, but defining these correctly will + * cause some noticeable speed improvements: + * + * AVOID_MEMORY_READ - (8-bit cfb only) + * When stippling pixels on the screen (polytext and pushpixels), + * don't read long words from the display and mask in the + * appropriate values. Rather, perform multiple byte/short/long + * writes as appropriate. This option uses many more instructions + * but runs much faster when the destination is much slower than + * the CPU and at least 1 level of write buffer is availible (2 + * is much better). Defined currently for SPARC and MIPS. + * + * FAST_CONSTANT_OFFSET_MODE - (cfb and mfb) + * This define is used on machines which have no auto-increment + * addressing mode, but do have an effectively free constant-offset + * addressing mode. Currently defined for MIPS and SPARC, even though + * I remember the cg6 as performing better without it (cg3 definitely + * performs better with it). + * + * LARGE_INSTRUCTION_CACHE - + * This define increases the number of times some loops are + * unrolled. On 68020 machines (with 256 bytes of i-cache), + * this define will slow execution down as instructions miss + * the cache frequently. On machines with real i-caches, this + * reduces loop overhead, causing a slight performance improvement. + * Currently defined for MIPS and SPARC + * + * FAST_UNALIGNED_READS - + * For machines with more memory bandwidth than CPU, this + * define uses unaligned reads for 8-bit BitBLT instead of doing + * aligned reads and combining the results with shifts and + * logical-ors. Currently defined for 68020 and vax. + * PLENTIFUL_REGISTERS - + * For machines with > 20 registers. Currently used for + * unrolling the text painting code a bit more. Currently + * defined for MIPS. + */ + +#ifdef vax + +#define IMAGE_BYTE_ORDER LSBFirst /* Values for the VAX only */ +#define BITMAP_BIT_ORDER LSBFirst +#define GLYPHPADBYTES 1 +#define GETLEFTBITS_ALIGNMENT 4 +#define FAST_UNALIGNED_READS + +#endif /* vax */ + +#ifdef sun + +#if defined(sun386) || defined(sun5) +# define IMAGE_BYTE_ORDER LSBFirst /* Values for the SUN only */ +# define BITMAP_BIT_ORDER LSBFirst +#else +# define IMAGE_BYTE_ORDER MSBFirst /* Values for the SUN only */ +# define BITMAP_BIT_ORDER MSBFirst +#endif + +#ifdef sparc +# define AVOID_MEMORY_READ +# define LARGE_INSTRUCTION_CACHE +# define FAST_CONSTANT_OFFSET_MODE +#endif + +#ifdef mc68020 +#define FAST_UNALIGNED_READS +#endif + +#define GLYPHPADBYTES 4 +#define GETLEFTBITS_ALIGNMENT 1 + +#endif /* sun */ + +#if defined(ibm032) || defined (ibm) + +#ifdef i386 +# define IMAGE_BYTE_ORDER LSBFirst /* Value for PS/2 only */ +#else +# define IMAGE_BYTE_ORDER MSBFirst /* Values for the RT only*/ +#endif +#define BITMAP_BIT_ORDER MSBFirst +#define GLYPHPADBYTES 1 +#define GETLEFTBITS_ALIGNMENT 4 +/* ibm pcc doesn't understand pragmas. */ + +#endif /* ibm */ + +#ifdef hpux + +#define IMAGE_BYTE_ORDER MSBFirst /* Values for the HP only */ +#define BITMAP_BIT_ORDER MSBFirst +#define GLYPHPADBYTES 2 /* to match product server */ +#define GETLEFTBITS_ALIGNMENT 1 + +#endif /* hpux */ + +#if defined(M4315) || defined(M4317) || defined(M4319) || defined(M4330) + +#define IMAGE_BYTE_ORDER MSBFirst /* Values for Pegasus only */ +#define BITMAP_BIT_ORDER MSBFirst +#define GLYPHPADBYTES 4 +#define GETLEFTBITS_ALIGNMENT 1 + +#define FAST_UNALIGNED_READS + +#endif /* tektronix */ + +#ifdef mips + +#ifdef MIPSEL +# define IMAGE_BYTE_ORDER LSBFirst /* Values for the PMAX only */ +# define BITMAP_BIT_ORDER LSBFirst +# define GLYPHPADBYTES 4 +# define GETLEFTBITS_ALIGNMENT 1 +#else +# define IMAGE_BYTE_ORDER MSBFirst /* Values for the MIPS only */ +# define BITMAP_BIT_ORDER MSBFirst +# define GLYPHPADBYTES 4 +# define GETLEFTBITS_ALIGNMENT 1 +#endif + +#define AVOID_MEMORY_READ +#define FAST_CONSTANT_OFFSET_MODE +#define LARGE_INSTRUCTION_CACHE +#define PLENTIFUL_REGISTERS + +#endif /* mips */ + +#ifdef stellar + +#define IMAGE_BYTE_ORDER MSBFirst /* Values for the stellar only*/ +#define BITMAP_BIT_ORDER MSBFirst +#define GLYPHPADBYTES 4 +#define GETLEFTBITS_ALIGNMENT 4 +/* + * Use SysV random number generator. + */ +#define random rand + +#endif /* stellar */ + +/* size of buffer to use with GetImage, measured in bytes. There's obviously + * a trade-off between the amount of stack (or whatever ALLOCATE_LOCAL gives + * you) used and the number of times the ddx routine has to be called. + * + * for a 1024 x 864 bit monochrome screen with a 32 bit word we get + * 8192/4 words per buffer + * (1024/32) = 32 words per scanline + * 2048 words per buffer / 32 words per scanline = 64 scanlines per buffer + * 864 scanlines / 64 scanlines = 14 buffers to draw a full screen + */ +#if defined(stellar) +#define IMAGE_BUFSIZE (64*1024) +#else +#define IMAGE_BUFSIZE 8192 +#endif + +/* pad scanline to a longword */ +#if defined(ibm) && defined(i386) +#define BITMAP_SCANLINE_UNIT 8 +#else +#define BITMAP_SCANLINE_UNIT 32 +#endif +#define BITMAP_SCANLINE_PAD 32 + +#define LOG2_BITMAP_PAD 5 +#define LOG2_BYTES_PER_SCANLINE_PAD 2 + +/* + * This returns the number of padding units, for depth d and width w. + * For bitmaps this can be calculated with the macros above. + * Other depths require either grovelling over the formats field of the + * screenInfo or hardwired constants. + */ + +typedef struct _PaddingInfo { + int padRoundUp; /* pixels per pad unit - 1 */ + int padPixelsLog2; /* log 2 (pixels per pad unit) */ + int padBytesLog2; /* log 2 (bytes per pad unit) */ +} PaddingInfo; +extern PaddingInfo PixmapWidthPaddingInfo[]; + +#define PixmapWidthInPadUnits(w, d) \ + (((w) + PixmapWidthPaddingInfo[d].padRoundUp) >> \ + PixmapWidthPaddingInfo[d].padPixelsLog2) + +/* + * Return the number of bytes to which a scanline of the given + * depth and width will be padded. + */ +#define PixmapBytePad(w, d) \ + (PixmapWidthInPadUnits(w, d) << PixmapWidthPaddingInfo[d].padBytesLog2) + +#endif /* SERVERMD_H */ diff --git a/cde/programs/dtudcfonted/libfal/readpcf.c b/cde/programs/dtudcfonted/libfal/readpcf.c new file mode 100644 index 00000000..65a8fb49 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/readpcf.c @@ -0,0 +1,903 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: readpcf.c /main/5 1996/06/05 16:42:29 ageorge $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "FaLib.h" +#include "falfont.h" + +#ifndef GLYPHPADOPTIONS +#define GLYPHPADOPTIONS 4 +#endif + +static CARD32 getLSB32(); +static int getINT32(); +static int getINT16(); +static Bool seekToType(); +static void getMetric(); +static Bool getAccel(); +int falInitReadPcf(); +static void ByteSwap(); +static void repadBits(); +int falPcfGlyph(); +void falGetPcfGSize(); +int falInitReadPcfProp() ; +int falInitReadSnfProp() ; +int falReadGpfProp() ; + +extern void BitOrderInvert() ; +extern void set_errfile_str() ; + +static CARD32 +getLSB32( p) +unsigned char *p; +{ + CARD32 c; + + c = *p++; + c |= (CARD32)(*p++) << 8; + c |= (CARD32)(*p++) << 16; + c |= (CARD32)(*p) << 24; + + return c; +} + +static int +getINT32( p, format) +unsigned char *p; +CARD32 format; +{ + CARD32 c; + + if (PCF_BYTE_ORDER(format) == MSBFirst) { + c = (CARD32)(*p++) << 24; + c |= (CARD32)(*p++) << 16; + c |= (CARD32)(*p++) << 8; + c |= (CARD32)(*p); + } else { + c = (CARD32)(*p++); + c |= (CARD32)(*p++) << 8; + c |= (CARD32)(*p++) << 16; + c |= (CARD32)(*p) << 24; + } + + return (int)c; +} + +static int +getINT16( p, format) +unsigned char *p; +CARD32 format; +{ + CARD32 c; + + if (PCF_BYTE_ORDER(format) == MSBFirst) { + c = (CARD32)(*p++) << 8; + c |= (CARD32)(*p); + } else { + c = (CARD32)(*p++); + c |= (CARD32)(*p) << 8; + } + + return (int)c; +} + +static Bool +seekToType( tables, ntables, type, formatp, sizep, offsetp) +PCFTablePtr tables; +int ntables; +CARD32 type; +CARD32 *formatp; +CARD32 *sizep; +CARD32 *offsetp; +{ + int i; + + for ( i = 0; i < ntables; i++) { + if ( getLSB32( (unsigned char *)&tables[i].type ) == type) { + if ( formatp) + *formatp = getLSB32( (unsigned char *)&tables[i].format); + if ( sizep) + *sizep = getLSB32( (unsigned char *)&tables[i].size); + if ( offsetp) + *offsetp = getLSB32( (unsigned char *)&tables[i].offset); + return(TRUE); + } + } + return(FALSE); +} + + + +static void +getMetric( buf, format, metric) +caddr_t buf; +CARD32 format; +xCharInfo *metric; +{ + metric->leftSideBearing = getINT16( (unsigned char *)buf, (CARD32)format); + buf += 2; + metric->rightSideBearing = getINT16( (unsigned char *)buf, (CARD32)format); + buf += 2; + metric->characterWidth = getINT16( (unsigned char *)buf, (CARD32)format); + buf += 2; + metric->ascent = getINT16( (unsigned char *)buf, (CARD32)format); + buf += 2; + metric->descent = getINT16( (unsigned char *)buf, (CARD32)format); + buf += 2; + metric->attributes = getINT16( (unsigned char *)buf, (CARD32)format); + buf += 2; +} + +static Bool +getAccel( pFontInfo, maxink, buf_top, tables, ntables, type) +FontInfoPtr pFontInfo; +xCharInfo *maxink; +caddr_t buf_top; +PCFTablePtr tables; +int ntables; +CARD32 type; +{ + CARD32 format; + CARD32 offset; + caddr_t buffer; + + if ( !seekToType( tables, ntables, (CARD32)type, &format, (CARD32 *)NULL, &offset)) + return FALSE; + + buffer = buf_top + offset; + format = getLSB32( (unsigned char *)buffer ); + buffer += 4; + if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) && + !PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) { + return FALSE; + } + pFontInfo->noOverlap = *buffer++; + pFontInfo->constantMetrics = *buffer++; + pFontInfo->terminalFont = *buffer++; + pFontInfo->constantWidth = *buffer++; + pFontInfo->inkInside = *buffer++; + pFontInfo->inkMetrics = *buffer++; + pFontInfo->drawDirection = *buffer++; + /* pFontInfo->anamorphic = FALSE; */ + /* natural alignment */ buffer++; + pFontInfo->fontAscent = getINT32( (unsigned char *)buffer, (CARD32)format); + buffer += 4; + pFontInfo->fontDescent = getINT32( (unsigned char *)buffer, (CARD32)format); + buffer +=4; + + /* pFontInfo->maxOverlap = getINT32( (unsigned char *)buffer, (CARD32)format); */ buffer += 4; + getMetric(buffer, format, &pFontInfo->minbounds.metrics); + buffer += 12; + getMetric(buffer, format, &pFontInfo->maxbounds.metrics); + buffer += 12; + if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) { + buffer += 12; + getMetric( buffer, format, maxink); + } else { + *maxink = pFontInfo->maxbounds.metrics; + } + return TRUE; +} + +int +falInitReadPcf( pcfinf, buftop) +struct pcf_inf *pcfinf; +caddr_t buftop; +{ + CARD32 format; + CARD32 offset; + CARD32 *bitmapSizes; + xCharInfo maxink; + caddr_t buffp; + + if ( getLSB32( (unsigned char *)buftop ) != PCF_FILE_VERSION) + goto Bail; + + pcfinf->ntables = getLSB32( (unsigned char *)(buftop + 4) ); + + pcfinf->tables = (PCFTablePtr)(buftop + 8); + + if ( !getAccel( &pcfinf->info, &maxink, buftop, pcfinf->tables, pcfinf->ntables, + (CARD32)PCF_BDF_ACCELERATORS)) + if ( !getAccel( &pcfinf->info, &maxink, buftop, pcfinf->tables, pcfinf->ntables, + (CARD32)PCF_ACCELERATORS)) + goto Bail; + + pcfinf->org_bounds = pcfinf->info.maxbounds.metrics; + + if ( !seekToType( pcfinf->tables, pcfinf->ntables, (CARD32)PCF_BITMAPS, + &format, (CARD32 *)NULL, &offset)) + goto Bail; + + buffp = buftop + offset; + + format = getLSB32( (unsigned char *)buffp ); + buffp += 4; + if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) + goto Bail; + + pcfinf->nbitmaps = getINT32( (unsigned char *)buffp, (CARD32)format); + buffp += 4; + pcfinf->offsets = (CARD32 *)buffp; + buffp += sizeof( *pcfinf->offsets) * pcfinf->nbitmaps; + + bitmapSizes = (CARD32 *)buffp; + pcfinf->sizebitmaps = getINT32( (unsigned char *)&bitmapSizes[PCF_GLYPH_PAD_INDEX(format)], (CARD32)format); + pcfinf->bmp_fmt = format; + buffp += sizeof( *bitmapSizes) * GLYPHPADOPTIONS; + pcfinf->bitmaps = buffp; + buffp += pcfinf->sizebitmaps; + + if ( !seekToType( pcfinf->tables, pcfinf->ntables, (CARD32)PCF_BDF_ENCODINGS, + &format, (CARD32 *)NULL, &offset)) + goto Bail; + + buffp = buftop + offset; + format = getLSB32( (unsigned char *)buffp ); + buffp += 4; + if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) + goto Bail; + + pcfinf->info.firstCol = getINT16( (unsigned char *)buffp, (CARD32)format); + buffp += 2; + pcfinf->info.lastCol = getINT16( (unsigned char *)buffp, (CARD32)format); + buffp += 2; + pcfinf->info.firstRow = getINT16( (unsigned char *)buffp, (CARD32)format); + buffp += 2; + pcfinf->info.lastRow = getINT16( (unsigned char *)buffp, (CARD32)format); + buffp += 2; + /* + pcfinf->info.defaultCh = getINT16( (unsigned char *)buffp, (CARD32)format); buffp += 2; + */ + pcfinf->info.chDefault = getINT16( (unsigned char *)buffp, (CARD32)format); + buffp += 2; + + pcfinf->info.allExist = FALSE; + pcfinf->enc_fmt = format; + pcfinf->encodingOffsets = (CARD16 *)buffp; + + return 0; +Bail: + return -1; +} + +static void +ByteSwap( p, scan) +char *p; +int scan; +{ + char w; + + switch( scan) { + case 1: + break; + case 2: + w = *p; + *p = *(p + 1); + *(p + 1) = w; + break; + case 4: + w = *p; + *p = *(p + 3); + *(p + 3) = w; + w = *(p + 1); + *(p + 1) = *(p + 2); + *(p + 2) = w; + break; + } +} +static void +repadBits( src, format, width, height, dest) +char *src; +CARD32 format; +int width, height; +char *dest; +{ + int bit, byte, glyph, scan; + int src_bytewidth, dest_bytewidth; + char work[8]; + int i, j; + + bit = PCF_BIT_ORDER( format); + byte = PCF_BYTE_ORDER( format); + glyph = PCF_GLYPH_PAD( format); + scan = PCF_SCAN_UNIT( format); + + src_bytewidth = (( width + ( 8 * glyph ) - 1)/( 8 * glyph)) * glyph; + dest_bytewidth = ( width + 7) /8; + + for ( i = 0; i < height; i++, src += src_bytewidth, + dest += dest_bytewidth) { + for ( j = 0; j < src_bytewidth; j += scan) { + memcpy( work, src + j, scan); + if ( bit == LSBFirst) + BitOrderInvert( work, scan ); + if ( byte == LSBFirst) + ByteSwap( work, scan); + if (( j + scan) >= dest_bytewidth) { + memcpy( dest + j, work, dest_bytewidth - j); + break; + } + memcpy( dest + j, work, scan); + } + } +} + +int +falPcfGlyph( glyph, finf, code) +char *glyph; +Oak_FontInf *finf; +int code; +{ + int encode; + int inner_code; + char *bitmap; + int encodingOffset; + int codeRow, codeCol; + int bytewidth; + int bmp_adj, ptn_adj; + int adj_hi; + int cpy_height; + int bmp_height; + + if ( !glyph){ + fal_utyerrno = FAL_ERR_PARM ; + return FAL_ERROR ; + } + + inner_code = code; + codeCol = inner_code & 0xff; + codeRow = (inner_code >> 8) & 0xff; + + /* code check */ + if ( + ((code < finf->start) || (code > finf->end))|| + ((codeCol < finf->pFinf->firstCol)||(codeCol > finf->pFinf->lastCol))|| + ((codeRow < finf->pFinf->firstRow)||(codeRow > finf->pFinf->lastRow)) + ) { + fal_utyexists = 1; + return(-1); + } + + encode = (codeRow - finf->pFinf->firstRow) * ( finf->pFinf->lastCol - finf->pFinf->firstCol + 1); + encode += codeCol - finf->pFinf->firstCol; + encodingOffset = getINT16( (unsigned char *)(finf->pcfinf.encodingOffsets + encode), finf->pcfinf.enc_fmt); + + if (encodingOffset == 0xFFFF) { + fal_utyexists = 1; + return(-1); + } + fal_utyexists = 0; + + bitmap = finf->pcfinf.bitmaps + getINT32( (unsigned char *)(finf->pcfinf.offsets + encodingOffset), finf->pcfinf.bmp_fmt); + + bmp_height = finf->pFinf->maxbounds.metrics.ascent + + finf->pFinf->maxbounds.metrics.descent; + if (( adj_hi = finf->pFinf->maxbounds.metrics.ascent + - finf->pcfinf.org_bounds.ascent) > 0) { + bytewidth = 8 * PCF_GLYPH_PAD( finf->pcfinf.bmp_fmt); + bytewidth = (( finf->width + bytewidth - 1)/ bytewidth ) * PCF_GLYPH_PAD( finf->pcfinf.bmp_fmt); + bmp_adj = bytewidth * adj_hi; + ptn_adj = 0; + if (( cpy_height = bmp_height - adj_hi) > finf->height) + cpy_height = finf->height; + } else if ( adj_hi < 0) { + adj_hi *= -1; + bytewidth = ( finf->width + 7) / 8; + bmp_adj = 0; + ptn_adj = bytewidth * adj_hi; + if (( cpy_height = finf->height - adj_hi) > bmp_height) + cpy_height = bmp_height; + } else { + bmp_adj = 0; + ptn_adj = 0; + cpy_height = finf->height; + } + + repadBits( bitmap + bmp_adj , finf->pcfinf.bmp_fmt, finf->width, cpy_height, glyph + ptn_adj); + return(0); +} + +void +falGetPcfGSize( pcfinf, widthp, heightp) +struct pcf_inf *pcfinf; +unsigned int *widthp, *heightp; +{ + unsigned int w, h; + + w = pcfinf->org_bounds.rightSideBearing + - pcfinf->org_bounds.leftSideBearing; + h = pcfinf->org_bounds.ascent + pcfinf->org_bounds.descent; + + *widthp = w; + *heightp = h; +} + + + + +/******************************************************** + * + * functions for collect GPF file properties + * + *******************************************************/ + +#include "fontstruct.h" + +static char *getPcfFontProp(); +static char *getSnfFontProp(); +/* +* read properties and get font style and +* letter size +*/ + +int +falReadFontProp( file, protect_key_data, databuff, islock ) +char *file ; /* name of font file */ +int protect_key_data ; +FalFontData *databuff ; +int islock ; +{ + Oak_FontInf finf; + int fd ; + char *buf; + char *openfontfile; + struct stat st; + int rtn ; + + /* initialezation */ + openfontfile = file ; + + /* read a condition of a fontfile */ + if ( stat( openfontfile, &st ) < 0 ) { + set_errfile_str( fal_err_file, openfontfile ) ; + fal_utyerror = _FAL_STAT_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_STAT ; + return FAL_ERROR; + } + + if ( st.st_size < sizeof( FontInfoRec ) ) { + fal_utyerror = _FAL_FONT_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_FONT ; + return FAL_ERROR; + } + + /* open a fontfile */ + if ( (fd = open( openfontfile, ((islock)? O_RDONLY : O_RDWR) )) < 0 ) { + switch( errno ) { + case EACCES : + return _FAL_TRY_NEXT ; + default : + set_errfile_str( fal_err_file, openfontfile ) ; + fal_utyerror = _FAL_OPEN_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FNT_OPN ; + return FAL_ERROR; + } + } + +#if defined( SVR4 ) + buf = (char *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if ( buf != (char *)-1 ) { + /* if "mmap" is normal end */ + close( fd ); + finf.ismmap = TRUE; + finf.fsize = st.st_size; + } else { + /* if "mmap" is abnormal end , try "read()" */ + finf.ismmap = FALSE; + if ( !(buf = (char *)malloc(st.st_size)) ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + close( fd ); + return FAL_ERROR; + } + if ( read(fd, buf, st.st_size) != st.st_size ) { + set_errfile_str( fal_err_file, openfontfile ) ; + fal_utyerror = _FAL_READ_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FNT_RD ; + free( buf ); + close( fd ); + return FAL_ERROR; + } + } +#else + finf.ismmap = FALSE; + if ( !(buf = (char *)malloc( st.st_size )) ) { + fal_utyerror = _FAL_MALOC_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_MALLOC ; + close( fd ); + return FAL_ERROR; + } + if ( read(fd, buf, st.st_size) != st.st_size ) { + set_errfile_str( fal_err_file, openfontfile ) ; + fal_utyerror = _FAL_READ_ER; + fal_utyderror = errno; + fal_utyerrno = FAL_ERR_FNT_RD ; + free( buf ); + close( fd ); + return FAL_ERROR; + } +#endif + + finf.fname = openfontfile ; + finf.buf = buf ; + + /* + * open GPF font file + */ + rtn = falReadGpfProp( FAL_UPDATE_FONTINFO, &finf, protect_key_data, databuff ) ; +#if defined( SVR4 ) + if ( finf.ismmap == TRUE ) { + munmap( buf, finf.fsize ); + } else { + free(buf); + close(fd); + } +#else + free( buf ); + close( fd ); +#endif + + return( rtn ) ; +} + + +/* +* get properties of GPF format file +*/ +int +falReadGpfProp( updflg, finf, protect_key_data, databuff ) +int updflg ; +Oak_FontInf *finf; +int protect_key_data ; +FalFontData *databuff ; +{ + char *openfontfile; + int rtn ; + + /* initialize */ + openfontfile = finf->fname ; + + if( updflg == FAL_UPDATE_FONTINFO ) { + /* case of a PCF format font */ + if ( strcmp( FILE_SUFFIX( openfontfile ), PCFSUFFIX ) == 0 ) { + + finf->isFef = FALSE; + finf->isPcf = TRUE; + + } + else /* case of a SNF format font */ + { + FAL_READ_SNF_HEADER( finf, protect_key_data, fal_utyerror, fal_utyderror ) ; + } + } /* updflg */ + + /* + * get font properties + */ + if ( finf->isFef ){ + /* read SNF format property */ + if ( rtn = falInitReadSnfProp( finf, (caddr_t)finf->pFinf, databuff ) ) { + if( rtn == _FAL_TRY_NEXT ){ + return( rtn ) ; + } + fal_utyerror = _FAL_FONT_ER; + fal_utyderror = 0; + return FAL_ERROR; + } + } else if ( finf->isPcf ) { + /* read PCF format property */ + if ( rtn = falInitReadPcfProp( updflg, finf, databuff ) ) { + if( rtn == _FAL_TRY_NEXT ){ + return( rtn ) ; + } + fal_utyerror = _FAL_FONT_ER; + fal_utyderror = 0; + return FAL_ERROR; + } + + if( updflg == FAL_UPDATE_FONTINFO ) { + finf->pFinf = &finf->pcfinf.info; + finf->pCinf = NULL; + finf->pGlyphs = NULL; + } + } else { + fal_utyerror = _FAL_FONT_ER; + fal_utyderror = 0; + fal_utyerrno = FAL_ERR_FONT ; + return FAL_ERROR; + } + + return(0); +} + + +/* +* get properties of PCF format file +*/ +int +falInitReadPcfProp( updflg, finf, databuff ) +int updflg ; +Oak_FontInf *finf; +FalFontData *databuff ; +{ + struct pcf_inf *pcfinf; + caddr_t buftop; + xCharInfo maxink; + caddr_t buffp; + int lb, rb, as, ds ; + + + + pcfinf = &finf->pcfinf ; + buftop = finf->buf ; + + if ( getLSB32( (unsigned char *)buftop ) != PCF_FILE_VERSION) + return _FAL_TRY_NEXT ; + + if( updflg == FAL_UPDATE_FONTINFO ) { + pcfinf->ntables = getLSB32( (unsigned char *)(buftop + 4) ); + + pcfinf->tables = (PCFTablePtr)(buftop + 8); + + if ( !getAccel( &pcfinf->info, &maxink, buftop, pcfinf->tables, + pcfinf->ntables, (CARD32)PCF_BDF_ACCELERATORS)) { + if ( !getAccel( &pcfinf->info, &maxink, buftop, pcfinf->tables, + pcfinf->ntables, (CARD32)PCF_ACCELERATORS)) { + fal_utyerrno = FAL_ERR_FONT ; + goto Bail; + } + } + + } + + /* + * read property + */ + + if( updflg == FAL_UPDATE_FONTINFO ) { + pcfinf->org_bounds = pcfinf->info.maxbounds.metrics; + } + + lb = pcfinf->org_bounds.leftSideBearing ; + rb = pcfinf->org_bounds.rightSideBearing ; + as = pcfinf->org_bounds.ascent ; + ds = pcfinf->org_bounds.descent ; + + databuff->size.w = rb - lb ; + databuff->size.h = as + ds ; + + /* + * read property "FONT" + */ + if ( buffp = getPcfFontProp( buftop, pcfinf->tables, + pcfinf->ntables, "FONT" )) { + if( (databuff->xlfdname = (char *)strdup( buffp )) == (char *)NULL ){ + fal_utyerrno = FAL_ERR_MALLOC ; + goto Bail; + } + }else{ + set_errfile_str( fal_err_file, finf->fname ) ; + fal_utyerrno = FAL_ERR_PROP_FONT ; + return( _FAL_TRY_NEXT ) ; + } + + /* + * read property "FAMILY_NAME" + */ + if ( buffp = getPcfFontProp( buftop, pcfinf->tables, + pcfinf->ntables, "FAMILY_NAME")) { + if( (databuff->style.name = (char *)strdup( buffp )) == NULL ){ + fal_utyerrno = FAL_ERR_MALLOC ; + goto Bail ; + } + }else{ + set_errfile_str( fal_err_file, finf->fname ) ; + fal_utyerrno = FAL_ERR_PROP_FNAME ; + return( _FAL_TRY_NEXT ) ; + } + + return 0; +Bail: + return -1; +} + + + +static char * +getPcfFontProp( buftop, tables, ntables, propname) +caddr_t buftop; +PCFTablePtr tables; +int ntables; +char *propname; +{ + caddr_t buffer; + int name_ofs; + int i ; + int nprops; + char *propstr ; + CARD32 format, offset; + + if ( !seekToType( tables, ntables, (CARD32)PCF_PROPERTIES, &format, (CARD32 *)NULL, &offset)) + return NULL; + + buffer = buftop + offset; + format = getLSB32( (unsigned char *)buffer ); + buffer += 4; + if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT)) + return NULL; + + nprops = getINT32( (unsigned char *)buffer, (CARD32)format); + buffer += 4; + propstr = buffer + (4 * ((nprops * 9 + 3) / 4)) + 4; + + for ( i=0; i < nprops ; i++ ) { + name_ofs = getINT32( (unsigned char *)buffer, (CARD32)format ) ; + buffer += 4 ; /* name */ + if ( strcmp( propstr + name_ofs, propname) == 0) { + if ( *buffer) { /* isStringProp */ + return( propstr + getINT32( (unsigned char *)(buffer + 1), (CARD32)format) ); + }else{ + return((char *)(intptr_t)getINT32( (unsigned char *)(buffer + 1), (CARD32)format) ); + } + } + buffer += 5 ; /* isStringProp + value */ + } + + return( NULL); +} + + +/* +* get properties of SNF format file +*/ +int +falInitReadSnfProp( finf, buftop, databuff ) +Oak_FontInf *finf; /* pointer to the infomation structure */ +caddr_t buftop; /* font file */ +FalFontData *databuff ; +{ + caddr_t stprop ; + int lb, rb, as, ds ; + char *propptr ; + char *fnt = NULL, *fam ; + int nprops, bitmapSize, num_chars ; + + + /* initialize pointer */ + nprops = finf->pFinf->nProps ; + num_chars = ( finf->pFinf->lastRow - finf->pFinf->firstRow + 1 ) * + ( finf->pFinf->lastCol - finf->pFinf->firstCol + 1 ) ; + bitmapSize = BYTESOFGLYPHINFO(finf->pFinf) ; + + stprop = buftop ; + stprop += sizeof(FontInfoRec) ; + stprop += num_chars * sizeof(CharInfoRec) ; + stprop += bitmapSize ; + + /* + * read property "FONTBOUNDINGBOX" + */ + lb = finf->pFinf->maxbounds.metrics.leftSideBearing ; + rb = finf->pFinf->maxbounds.metrics.rightSideBearing ; + as = finf->pFinf->maxbounds.metrics.ascent ; + ds = finf->pFinf->maxbounds.metrics.descent ; + + /* + * read property "FONT" + */ + if ( propptr = getSnfFontProp( stprop, nprops, "FONT" )) { + if( (fnt = (char *)strdup( propptr )) == NULL ){ + fal_utyerrno = FAL_ERR_MALLOC ; + goto Bail; + } + }else{ + set_errfile_str( fal_err_file, finf->fname ) ; + fal_utyerrno = FAL_ERR_PROP_FONT ; + return( _FAL_TRY_NEXT ) ; + } + + /* + * read property "FAMILY_NAME" + */ + if ( propptr = getSnfFontProp( stprop, nprops, "FAMILY_NAME")) { + if( (fam = (char *)strdup( propptr )) == NULL ){ + fal_utyerrno = FAL_ERR_MALLOC ; + goto Bail ; + } + }else{ + set_errfile_str( fal_err_file, finf->fname ) ; + fal_utyerrno = FAL_ERR_PROP_FNAME ; + free(fnt); + return( _FAL_TRY_NEXT ) ; + } + + /* + * set data buffer + */ + + databuff->size.w = rb - lb ; + databuff->size.h = as + ds ; + + databuff->xlfdname = fnt ; + databuff->style.name = fam ; + + return 0; +Bail: + free(fnt); + return -1; +} + + + +static char * +getSnfFontProp( buftop, nprops, propname ) +caddr_t buftop; +int nprops ; +char *propname; +{ + caddr_t buffer; + int name_ofs; + int i ; + char *propstr ; + FontPropRec *ProcRec ; + + ProcRec = (FontPropRec *)buftop ; + buffer = (char *)buftop ; + propstr = buffer + nprops * sizeof(FontPropRec) ; + + for ( i=0; i < nprops ; i++, ProcRec++ ) { + name_ofs = ProcRec->name ; + if( strcmp( propstr + name_ofs, propname ) == 0 ){ + if( ProcRec->indirect ){ + return( propstr + ProcRec->value ) ; + }else{ + return( (char *) (intptr_t) ProcRec->value ) ; + } + } + } + + return( NULL); +} + +/***********************< end of readpcf.c >********************/ diff --git a/cde/programs/dtudcfonted/libfal/syncx.c b/cde/programs/dtudcfonted/libfal/syncx.c new file mode 100644 index 00000000..40aa14a1 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/syncx.c @@ -0,0 +1,75 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: syncx.c /main/3 1996/07/04 02:32:52 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ +#include + +/* "fal" -> "X" */ +/* GetFProp.c falGetFontProperty() : Xlib.h */ +/* omDefault.c _falwcDefaultTextPerCharExtents(): omGeneric.c */ +/* IntAtom.c falInternAtom() : Xlib.h */ +/* Font.c falFreeFont() : Xlib.h */ +/* FontInfo.c falFreeFontInfo() : Xlib.h */ +/* TextToStr.c falFreeStringList() : Xlib.h */ +/* FontNames.c falFreeFontNames() : Xlib.h */ + +/* Bool */ falGetFontProperty() { return 0 ; } +/* Status */ _falwcDefaultTextPerCharExtents(){ return 0 ; } +void _falmbDefaultDrawImageString() { return ; } +/* Atom */ falInternAtom() { return 0 ; } +int _falwcGenericDrawString() { return 0 ; } +char **_falParseBaseFontNameList() { return NULL ; } +/* XFontStruct * */ falLoadQueryFont() { return 0 ; } +falFreeFont() { return 0 ; } +falFreeFontInfo() { return 0 ; } +/* char ** */ falListFonts() { return 0 ; } +void _falmbGenericDrawImageString() { return ; } +void _falwcDefaultDrawImageString() { return ; } +int _falmbDefaultDrawString() { return 0 ; } +int _falmbGenericTextEscapement() { return 0 ; } +void falFreeStringList() { return ; } +/* falrmStringToQuark() { return 0 ; } */ +/* falrmPermStringToQuark() { return 0 ; } */ +int _falwcDefaultDrawString() { return 0 ; } +/* char * */ falGetAtomName() { return 0 ; } +int _falwcGenericTextExtents() { return 0 ; } +int _falmbGenericTextExtents() { return 0 ; } +void _falwcGenericDrawImageString() { return ; } +falFreeFontNames() { return 0 ; } +/* falrmQuarkToString() { return 0 ; } */ +int _falwcDefaultTextExtents() { return 0 ; } +/* Status */ _falmbGenericTextPerCharExtents(){ return 0 ; } +int _falmbDefaultTextEscapement() { return 0 ; } +int _falwcGenericTextEscapement() { return 0 ; } +int _falmbDefaultTextExtents() { return 0 ; } +/* char ** */ falListFontsWithInfo() { return 0 ; } +int _falwcDefaultTextEscapement() { return 0 ; } +/* Status */ _falwcGenericTextPerCharExtents(){ return 0 ; } +/* _fallcMapOSLocaleName() { return 0 ; } */ +int _falmbGenericDrawString() { return 0 ; } +/* Status */ _falmbDefaultTextPerCharExtents(){ return 0 ; } diff --git a/cde/programs/dtudcfonted/libfal/syncx.h b/cde/programs/dtudcfonted/libfal/syncx.h new file mode 100644 index 00000000..fde099d5 --- /dev/null +++ b/cde/programs/dtudcfonted/libfal/syncx.h @@ -0,0 +1,77 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: syncx.h /main/2 1996/06/25 20:04:52 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ +#include +#include +#include +#include "_falutil.h" + +extern XrmQuark falrmStringToQuark( +#if NeedFunctionPrototypes + _Xconst char* /* string */ +#endif +); +extern XrmString falrmQuarkToString( +#if NeedFunctionPrototypes + XrmQuark /* quark */ +#endif +); + +extern char *falGetAtomName( +#if NeedFunctionPrototypes + Display* /* display */, + Atom /* atom */ +#endif +); + +extern char **falListFonts( +#if NeedFunctionPrototypes + Display* /* display */, + _Xconst char* /* pattern */, + int /* maxnames */, + int* /* actual_count_return */ +#endif +); + +extern char **falListFontsWithInfo( +#if NeedFunctionPrototypes + Display* /* display */, + _Xconst char* /* pattern */, + int /* maxnames */, + int* /* count_return */, + XFontStruct** /* info_return */ +#endif +); + +extern XFontStruct *falLoadQueryFont( +#if NeedFunctionPrototypes + Display* /* display */, + _Xconst char* /* name */ +#endif +); diff --git a/cde/programs/dtudcfonted/libfuty/Imakefile b/cde/programs/dtudcfonted/libfuty/Imakefile new file mode 100644 index 00000000..a55ac3ac --- /dev/null +++ b/cde/programs/dtudcfonted/libfuty/Imakefile @@ -0,0 +1,32 @@ +XCOMM $XConsortium: Imakefile /main/5 1996/09/09 11:20:01 drk $ +#define DoNormalLib YES +#define DoSharedLib NO +#define DoDebugLib NO +#define DoProfileLib NO +#define LibName oakfuty +#define LibHeaders NO +#define LibInstall NO + + FONTLIST = /config + + OPT1 = -DDEFAULT_CODESET='"'3'"' +#ifdef X11ProjectRoot + OPT2 = -DFONTC='"'$(XPROJECTROOT)/bin/bdftopcf'"' +#else + OPT2 = -DFONTC='"'$(BINDIR)/bdftopcf'"' +#endif + OPT3 = -DSNFFONTC='"'$(SNFFONTC)'"' + OPT4 = -DDTUDCFONTSLISTDIR='"'$(CDE_INSTALLATION_TOP)$(FONTLIST)'"' + OPT5 = -DDEFAULT_TMPPATH='"'/var/tmp/'"' + + DEFINES = $(OPT1) $(OPT2) $(OPT3) $(OPT4) $(OPT5) + + INCLUDES = -I../include -I../libfal/include -I../libfal + + SRCS = oakfuty.c getfname.c lock.c + + OBJS = oakfuty.o getfname.o lock.o + +#include + +DependTarget() diff --git a/cde/programs/dtudcfonted/libfuty/getfname.c b/cde/programs/dtudcfonted/libfuty/getfname.c new file mode 100644 index 00000000..0782b215 --- /dev/null +++ b/cde/programs/dtudcfonted/libfuty/getfname.c @@ -0,0 +1,1163 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: getfname.c /main/9 1996/11/08 02:06:43 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include "FaLib.h" +#include "falfont.h" +#include "udcutil.h" + +#include + +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#endif /* SVR4 */ +#include + +#include "bdfgpf.h" + +static void ErrMsgTable_GetDefaultFile(); +static int falcom_split_data() ; +static void dsp_font_list() ; +static int search_Font_File_Name(); + +extern int searchFontFileName(); +extern int falReadFontProp() ; + +/* + * get "character size" and "letter size" from a character of an interface + * + * return code¡§ + * 1... get "character size" + * 2... get "character size" and "letter size" + * -1... NG + */ + +#define BODY_ONLY 1 +#define BODY_AND_LETTER 2 + +static int +GetSize( size_str, body, letter ) +char *size_str; /* a character of a size */ +int *body; /* set "character size" (output) */ +int *letter; /* set "letter size" (output) */ +{ + char *str_dot; + /* char *str_end; */ + int bdy, ltr; + + str_dot = strchr( size_str, '.'); + /* str_end = strchr( size_str, '\0'); */ + + if ( str_dot == NULL) { + /* change a size of "character size"*/ + if (falcom_atoi( size_str, '\0', &bdy ) ==-1) { + return -1; + } + *body = bdy; + return BODY_ONLY; + } + + /* change a size of "character size"*/ + if (falcom_atoi( size_str, '.', &bdy ) ==-1) { + return -1; + } + + /* change a size of "letter size"*/ + str_dot++; + if (falcom_atoi( str_dot, '\0', <r ) ==-1) { + return -1; + } + *body = bdy; + *letter = ltr; + return BODY_AND_LETTER; +} + + +/* + * + * change numerical character for numarical data + * + */ + +int +#if NeedFunctionPrototypes +falcom_atoi( + char *str, /* numerical character */ + char ed_code,/* an end code in numerical character */ + int *val /* set numarical data */ +) +#else +falcom_atoi(str, ed_code, val) +char *str; /* numerical character */ +char ed_code;/* an end code in numerical character */ +int *val; /* set numarical data */ +#endif +{ + char *ptr; + char *str_end; + int tmp; + + /* get an end index */ + str_end = strchr( str, ed_code ); + + /* change numarical data */ + tmp = (int)strtol(str, &ptr, 10); + + /* error check */ + if ((ptr == str) || (ptr != str_end)) { + return(-1); + } + *val = tmp; + return 0; +} + + +static int +falcom_cr_to_null(buf) +char *buf; +{ + buf = strchr( buf, '\n'); + if (buf != NULL) { + *buf = '\0'; + } + return 0; +} + + + +#define FALCOM_DATA_ELM 3 + +#define FALCOM_ELM_SIZE 0 +#define FALCOM_ELM_STYLE 1 +#define FALCOM_ELM_FNAME 2 + + +int +#if NeedFunctionPrototypes +GetDefaultFile( + int size, + char *style, + char *fname +) +#else +GetDefaultFile( size, style, fname ) +int size; /* character size */ +char *style; /* character style */ +char *fname; /* buffer */ +#endif +{ + FILE *fp; + int ret; + + + char *locale; + char *fal_search_path; + char uflist_d[BUFSIZE]; + char uflist_c[ BUFSIZE ]; + char uflist_l[ BUFSIZE ]; + + GETLISTFILEPATH( locale, fal_search_path, uflist_d, uflist_c, uflist_l, UDFLIST_DEF ) ; + + if ( ( fp = fopen( uflist_l, "r" ) ) == NULL ) { + if ( ( fp = fopen( uflist_c, "r" ) ) == NULL ) { + if ( ( fp = fopen( uflist_d, "r" ) ) == NULL ) { + return FAL_ERROR; + } + } + } + + ret = get_default_file( fp, size, style, fname ); + fclose( fp ); + return ret; +} + + +int +#if NeedFunctionPrototypes +get_default_file( + FILE *fp, + int size, + char *style, + char *fname +) +#else +get_default_file( fp, size, style, fname ) +FILE *fp; +int size; /* character size */ +char *style; /* character style */ +char *fname; /* buffer */ +#endif +{ + char buf[BUFSIZE]; /* buffer */ + int size_tmp; /* size (read file) */ + int ret; + char *elm[FALCOM_DATA_ELM]; + + ret = 0; + + /* read from a file */ + while( fgets(buf, BUFSIZE, fp) != (char *)NULL ) { + + falcom_cr_to_null( buf ); + if ((buf[0] == '#') || (buf[0] == '\0')) { + continue; + } + if (falcom_split_data( buf, FALCOM_DATA_ELM, &elm ) == -1) { + ret = -4; + continue; + } + if (falcom_atoi( elm[FALCOM_ELM_SIZE], '\0', &size_tmp ) == -1) { + ret = -4; + continue; + } + if ( style ) { + if ((size_tmp == size) && !strcmp(elm[FALCOM_ELM_STYLE], style)) { + strcpy( fname, elm[FALCOM_ELM_FNAME] ); + fclose( fp ); + return 0; + } + } + } + if (ret != 0) { + return ret; + } + + if ( feof(fp) != 0 ) { + return -2; + } + return -3; +} + +/**************************************************************/ +/* read from a file and divide a data that read from file */ +/**************************************************************/ + +static int +falcom_split_data( buf, entry_num, elm ) +char *buf; /* read a font information character array from a file */ +int entry_num; +char *elm[]; +{ + int cnt; /* counter */ + int strtop_flg; /* flag of a head of a character array */ + + /* divide a data */ + strtop_flg = 1; + for (cnt=0 ; *buf != '\0' && cnt < entry_num ; buf++){ + /* skip a separate character */ + if ((*buf == '\t') || (*buf == ' ')) { + /* change NULL */ + *buf = '\0'; + /* skip a separate character */ + do { + buf++; + } while((*buf == '\t') || (*buf == ' ')); + strtop_flg = 1; + } + if (strtop_flg) { + elm[cnt] = buf; + cnt++; + strtop_flg = 0; + } + } + /* check a data's number */ + if (cnt != entry_num ) { + return -1; + } + return 0; +} + + +char * +#if NeedFunctionPrototypes +falcom_get_base_name( char *str ) +#else +falcom_get_base_name( str ) +char *str; /* a full path character of a file name */ +#endif +{ + char *str_slash; + + str_slash = strrchr( str, '/'); + if ( str_slash == NULL ) { + return str; + } + return ++str_slash; +} + + +static int +is_letter_size_not_only_one( lst ) +FalFontDataList *lst; /* a font list */ +{ + int i, letter_cmp; + + letter_cmp = lst->list[0].letter.h; + for (i=0 ; i < lst->num ; i++) { + if (lst->list[i].letter.h != letter_cmp){ + return 1; + } + } + return 0; +} + + +/* + * get a real file name from a character of "size" and "style" + * + * return code¡§ + * 0 ... OK + * -1 ... NG + * + */ +int +#if NeedFunctionPrototypes +GetFileName( + char *com, + char *size_str, + char *style, + int codeset, + char *ofile +) +#else +GetFileName(com, size_str, style, codeset, ofile) +char *com; /* a character of a command name(case error) */ +char *size_str; /* a character of "size" */ +char *style; /* a character of "style" */ +int codeset; /* a codeset */ +char *ofile; /* set a target file name (output) */ +#endif +{ + int body, letter; + int size_sw; /* a size flag */ + char buf[BUFSIZE] ; /* an area for a file name */ + char *filename; /* a pointer for a file name */ + char fname[BUFSIZE]; /* a pointer for a file name */ + FalFontDataList *lst; /* a font list */ + FalFontData key; /* search an information of a font */ + unsigned int mask; /* search a mask of a font */ + int i, ret; + struct stat statbuf ; + char *locale; + + char *fal_search_path; + char uflist_d[ BUFSIZE ]; + char uflist_c[ BUFSIZE ]; + char uflist_l[ BUFSIZE ]; + + GETLISTFILEPATH( locale, fal_search_path, uflist_d, uflist_c, uflist_l, UDFLIST_DEF ) ; + + /* change a character of a size */ + if ((size_sw = GetSize(size_str, &body, &letter)) == -1) { + USAGE2("%s : The specification of the character size is improper.\"%s\"\n", + com, size_str); + return -1; + } + + mask = 0; + mask |= FAL_FONT_MASK_UNDEFINED ; + mask |= FAL_FONT_MASK_DEFINED ; + memset( &key, '\0', sizeof(FalFontData) ) ; + /* set information to search fonts */ + + key.cd_set = FALGETFALCODESET( codeset ) ; + mask |= FAL_FONT_MASK_CODE_SET ; + + switch( size_sw ) { + case BODY_AND_LETTER: + key.letter.h = letter; + mask |= FAL_FONT_MASK_LETTER_H; + case BODY_ONLY: + key.size.h = body; + mask |= FAL_FONT_MASK_SIZE_H; + } + + /* aet and check an information of a style */ + COMM_SETSTYLE_TO_FONTDATA( style, key, mask ) ; + + /* get a font information */ + if (FalGetFontList( &key, mask, &lst ) == FAL_ERROR ) { + ErrMsgTable_FalGetFontList( com, fal_utyerror, fal_utyderror ); + return -1; + } + + if ( lst->num == 0 ) { + USAGE3("%s : The user defined character of the specified size and style does not exist.\"%s , %s\"\n", + com, size_str, (style)?style:" "); + FalFreeFontList( lst ); + return -1; + } + + memset( fname, '\0', sizeof(fname) ) ; + switch( size_sw ) { + case BODY_ONLY: + + if ( is_letter_size_not_only_one(lst) ) { + ret = GetDefaultFile( key.size.h, style, buf) ; + if ( ret < 0 ) { + COMM_GET_DEFAULTFILE_ERROR( buf, com, ret, key.size.h, style, uflist_d, uflist_c, uflist_l, statbuf ) ; + } + for ( i = 0 ; i < lst->num; i++ ) { + ret = search_Font_File_Name( lst->list[i], fname ); + if ( ret == FAL_ERROR ) { + FalFreeFontList( lst ); + return -1; + } + filename = falcom_get_base_name( fname ); + if ( (buf[0] != '\0' && fname[0] != '\0') + && !strcmp( buf, filename ) ) { + strcpy( ofile, fname ); + FalFreeFontList( lst ); + return 0; + } + } + COMM_DISPERRORFILE( com, lst, style, i, size_str ) ; + FalFreeFontList( lst ); + return -1; + } + + case BODY_AND_LETTER: + switch( lst->num ) { + case 1: + ret = search_Font_File_Name( lst->list[0], fname ); + if ( ret == FAL_ERROR ) { + FalFreeFontList( lst ); + return -1; + } + strcpy( ofile, fname ); + FalFreeFontList( lst ); + return 0; + default: + ret = GetDefaultFile( key.size.h, style, buf); + if ( ret < 0 ) { + buf[0]='\0'; + } + for( i = 0 ; i < lst->num; i++ ) { + ret = search_Font_File_Name( lst->list[0], fname ); + if ( ret == FAL_ERROR ) { + FalFreeFontList( lst ); + return -1; + } + filename = falcom_get_base_name( fname ); + if ( (buf[0] != '\0' && fname[0] != '\0') + && !strcmp( buf, filename ) ) { + strcpy( ofile, fname ); + FalFreeFontList( lst ); + return 0; + } + } + USAGE1("%s : Two or more corresponding user defined characters exist.\n", com); + for ( i = 0 ; i < lst->num; i++ ) { + ret = search_Font_File_Name( lst->list[i], fname ); + if ( ret == FAL_ERROR ) { + FalFreeFontList( lst ); + return -1; + } + fprintf( stdout, "\t%s\n", fname ); + } + FalFreeFontList( lst ); + return -1; + } /* <--- switch( lst->num ) { */ + } /* <--- switch( size_sw ) { */ + return -1 ; +} + + +/* take out an error message of "FalGetFontList()" */ + +/* + * Error messages(by origin) + */ +char *fal_errmsg_org[0xff] = { +/* 0x00 */ + " ", + "Cannot open the font file.", + "Cannot read the font file.", + "There is no more memory .", + "Fatal error occurred.", + "The specified font file does not exist.", + "This font is not a pcf or snf format.", + "Cannot open fonts.list file.", + "The format of fonts.list file is illegal.", + "The descriptions of the fonts.list file are incorrect.", + "The format of fonts.list file is illegal.", + "Cannot open fonts.dir file.", + "Cannot read fonts.dir file.", + "Cannot read font properties.", + "Cannot get \"FONT\" property.", + "Cannot get \"FAMILY_NAME\" property.", +/* 0x10 */ + "This font file is already opened by other application.", + "Cannot lock font file.", + "Cannot unlock font file.", + "Cannot get lock information from the font file.", + "Cannot find the specified font file.", + "Cannot read NLS database.", + "Cannot get charset names from NLS database.", + "Charset name not defined in NLS database.", + "The specified font has not been opened.", + "Fatal error occurred.", + " "," "," "," "," "," ", +/* 0x20 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x30 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x40 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x50 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x60 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x70 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x80 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0x90 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0xa0 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0xb0 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0xc0 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0xd0 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0xe0 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", +/* 0xf0 */ + " "," "," "," "," "," "," "," "," "," "," "," "," "," "," " +} ; + + +void +#if NeedFunctionPrototypes +ErrMsgTable_FalGetFontList( + char *com, + int utyerr, + int utyderr +) +#else +ErrMsgTable_FalGetFontList( com, utyerr, utyderr ) +char *com; /* command name */ +int utyerr; /* fal_utyerror */ +int utyderr; /* fal_utyderror */ +#endif +{ + char *fontsdir, *locale ; + + if( (locale = (char *)getenv( "LANG" )) == NULL ){ + locale = "C" ; + } + + if( (fontsdir = (char *)getenv( "DTUDCFONTS" )) == NULL ) { + fontsdir = DTUDCFONTSLISTDIR ; + } + switch( utyerr ) { + case 1: + if( fal_utyerrno ) { + USAGE2("%s : %s\n", com, fal_errmsg_org[ fal_utyerrno & 0xff ] ) ; + return ; + } + USAGE4("%s : The font directory information file(%s/%s/%s) cannot be opened.\n", + com, fontsdir, locale, FONTS_LIST_FILE ) ; + break; + case 2: + USAGE4("%s : Information cannot be read from the font directory information file(%s/%s/%s).\n", com, fontsdir, locale, FONTS_LIST_FILE ); + break; + case 3: + USAGE1("%s : The work area cannot be secured.\n", com ); + break; + case 7: + USAGE4("%s : Abnormality is found in the content of the font directory information file((%s/%s/%s).\n", + com , fontsdir, locale, FONTS_LIST_FILE); + break; + case 8: + USAGE4("%s : The font directory information file(%s/%s/%s) cannot be opened.\n", + com , fontsdir, locale, FONTS_LIST_FILE); + break; + case 9: + USAGE4("%s : Information cannot be read from the font directory information file(%s/%s/%s).\n", + com , fontsdir, locale, FONTS_LIST_FILE); + default: + if( fal_utyerrno ) { + USAGE2("%s : %s\n", com, fal_errmsg_org[ fal_utyerrno & 0xff ] ) ; + return ; + } + USAGE1("%s : Terminates abnormally.\n", com ); + } +} + + + +/* take out an error message of "GetDefaultFile()" */ + +static void +ErrMsgTable_GetDefaultFile( com, ret, size, style, fname ) +char *com; /* a command name */ +int ret; /* return code */ +int size; /* a character size */ +char *style; /* a character style */ +char *fname; /* user defined character information file name */ +{ + switch (ret) { + case -1: + USAGE2("%s : The user defined character information file cannot be opened. \"%s \"\n", + com, fname); + break; + case -2: + USAGE4("%s : The representative user defined character of the character size (%d) and style (%s) is not defined.\"%s\"\n", + com, size, (style)?style:" ", fname); + break; + case -3: + USAGE2("%s : Information cannot be read from the user defined character information file.\"%s\"\n", com, fname); + break; + case -4: + USAGE2("%s : The mistake is found in the description of the user defined character information file. \"%s\"\n", com, fname); + break; + } +} + + +/* + * if an end character of a file name is "/",it is cleared + * + * return code¡§none + * none + */ + +void +#if NeedFunctionPrototypes +fal_cut_tailslash( char *name ) +#else +fal_cut_tailslash( name ) +char *name; +#endif +{ + char *p; + + p = strrchr( name, '\0'); + if (p == NULL) { + return; + } + for (p-- ; (p>=name) && (*p == '/') ; p--) { + *p = '\0'; + } +} + + +/* + * get a real file name from a link file name + * + * return code¡§ + * OK¡¡¡¥¡¥a pointer of a file name + * NG¡¡¡¥¡¥NULL + * + */ + +char * +#if NeedFunctionPrototypes +GetRealFileName( char *name ) +#else +GetRealFileName( name ) +char *name; +#endif +{ + static char *ret_name ; + char link_name[BUFSIZE]; + int len; + + struct stat st; + + AllocString( ret_name, name, NULL ) ; + /* strcpy( ret_name, name ) ; */ + fal_cut_tailslash( ret_name ); /* for example /tmp/aa/ --> /tmp/aa */ + + while ( 1 ) { + if ( lstat( ret_name, &st ) == -1) { + FreeString( ret_name ) ; + return NULL; + } + errno = 0; + if ( ( len = readlink( ret_name, link_name, BUFSIZE ) ) == -1 ) { + if ( errno == EINVAL ) { + return( ret_name ) ; + /* return( strdup( ret_name ) ) ; */ + } else { + FreeString( ret_name ) ; + return NULL; + } + } + link_name[len-1] = 0; + if ( link_name[0] == '/' ) { + /* strcpy( ret_name, link_name ) ; */ + FreeString( ret_name ) ; + AllocString( ret_name, link_name, NULL ) ; + } else { + char *slash; + + slash = strrchr( ret_name, '/' ); + if (slash != NULL) { + *slash = '\0'; + fal_cut_tailslash( ret_name ); + ResizeString( ret_name, NULL ); + AddString(ret_name, "/", NULL); + } else { + /* ret_name[0] = '\0' ; */ + FreeString( ret_name ) ; + AllocString(ret_name, "/", NULL); + } + /* strcat( ret_name, "/" ) ; + strcat( ret_name, link_name ) ; */ + AddString( ret_name, link_name, NULL ) ; + } + } +} + + + +/* + * funtctions for search fonts by XLFD and NLS database + */ + +int +#if NeedFunctionPrototypes +IsInRegion( + int code , + int num_gr , + FalGlyphRegion *gr +) +#else +IsInRegion(code, num_gr, gr) +int code ; +int num_gr ; +FalGlyphRegion *gr ; +#endif +{ + int i ; + if( code < MIN_CODE || code > MAX_CODE ) return -1 ; + for( i=0; i MAX_CODE ) continue ; + if( gr[i].start <= code && gr[i].end >= code ) + return 0 ; + } + return -1 ; +} + + + + +static int +search_Font_File_Name( data, fname ) +FalFontData data ; +char *fname ; +{ + FalFontID fid ; + FalFontDataList *flist ; + int mask ; + char *tmp_fname ; + + mask = FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED ; + + if( data.xlfdname ) mask |= FAL_FONT_MASK_XLFDNAME ; + if( data.size.h ) mask |= FAL_FONT_MASK_SIZE_H ; + if( data.size.w >= 0 ) mask |= FAL_FONT_MASK_SIZE_W ; + if( data.style.name ) mask |= FAL_FONT_MASK_STYLE_NAME ; + if( data.cd_set ) mask |= FAL_FONT_MASK_CODE_SET ; + + if( data.letter.w ) mask |= FAL_FONT_MASK_LETTER_W ; + if( data.letter.h ) mask |= FAL_FONT_MASK_LETTER_H ; + if( data.letter.x ) mask |= FAL_FONT_MASK_LETTER_X ; + if( data.letter.y ) mask |= FAL_FONT_MASK_LETTER_Y ; + + if( data.style.def ) mask |= FAL_FONT_MASK_STYLE_DEF ; + if( data.shape.name ) mask |= FAL_FONT_MASK_SHAPE_NAME ; + if( data.shape.def ) mask |= FAL_FONT_MASK_SHAPE_DEF ; + COMM_SBCHR_SETFONTDATA( data, mask ) ; + if( data.prm ) mask |= FAL_FONT_MASK_PERMISSION ; + + fid = FalOpenSysFont( &data, mask, &flist ) ; + if( fid == 0 ) { + memset( fname, '\0', sizeof(fname) ) ; + if( flist ){ + dsp_font_list( flist ) ; + FalFreeFontList( flist ) ; + return(-1); + } else { + switch( fal_utyerror ) { + case _FAL_OPEN_ER : + case _FAL_READ_ER : + case _FAL_STAT_ER : + switch( fal_utyderror ) { + case EACCES : + case ENOENT : + return(0) ; + default : + USAGE3("There is no font file correspond to specified font.\n(%s)\n fal_utyerror = %d fal_utyderror = %d\n", + ((data.xlfdname)?data.xlfdname:"null font name"), fal_utyerror, fal_utyderror ) ; + return(-2) ; + } + case _FAL_MALOC_ER : + USAGE("System call error occurred.\n" ) ; + return(-2) ; + default : + USAGE3("There is no font file correspond to specified font.\n(%s)\n fal_utyerror = %d fal_utyderror = %d\n", + ((data.xlfdname)?data.xlfdname:"null font name"), fal_utyerror, fal_utyderror ) ; + return(-2) ; + } + } + } + if( FalFontIDToFileName( fid, &tmp_fname ) == FAL_ERROR ) { + USAGE3("There is no font file correspond to specified font.\n(%s)\n fal_utyerror = %d fal_utyderror = %d\n", + ((data.xlfdname)?data.xlfdname:"null font name"), fal_utyerror, fal_utyderror ) ; + FalCloseFont( fid ) ; + return(-1) ; + } + strcpy( fname, tmp_fname ) ; + FalFree( tmp_fname ) ; + FalCloseFont( fid ) ; + + return(0) ; +} + + +int +#if NeedFunctionPrototypes +GetUdcFileName( + char *com , + int code_no , + char *xlfdname , + char *fname +) +#else +GetUdcFileName( com, code_no, xlfdname, fname ) +char *com ; +int code_no ; +char *xlfdname ; +char *fname ; +#endif +{ + FalFontData data ; + + if( !xlfdname || !fname ) { + USAGE1("%s: null parameter\n", com ) ; + return(-1) ; + } + memset( &data, '\0', sizeof(FalFontData) ) ; + data.size.w = -1 ; + data.xlfdname = xlfdname ; + data.cd_set = FALGETFALCODESET( code_no ) ; + return( search_Font_File_Name( data, fname ) ) ; +} + + +static void +dsp_font_list( flist ) +FalFontDataList *flist ; +{ + int i ; + + USAGE(" code set / size / style / xlfd\n" ) ; + USAGE("-------------------------------------------------------\n" ) ; + for( i=0; inum; i++ ) { + USAGE4("\t%d\t%d\t%s\t%s\n", + FALCODESETTONUM( flist->list[i].cd_set ), + flist->list[i].size.h, + flist->list[i].style.name, + flist->list[i].xlfdname + ) ; + } +} + + +int +#if NeedFunctionPrototypes +GetUdcRegion( + char *com , + int codeset , + char *gpf_file , + int *num_gr , + FalGlyphRegion **gr +) +#else +GetUdcRegion( com, codeset, gpf_file, num_gr, gr ) +char *com ; +int codeset ; +char *gpf_file ; +int *num_gr ; +FalGlyphRegion **gr ; +#endif +{ + FalFontData fdata ; + char *locale, *char_set, *tmp_gpf ; + + if( (locale = (char *)getenv( "LANG" )) == NULL ){ + locale = "C" ; + } + /* parameter check */ + if( gpf_file == NULL || gr == NULL ) { + USAGE1("%s : null parameters.\n", com); + return( -1 ) ; + } + + /* get font properties */ + tmp_gpf = (char *)GetRealFileName( gpf_file ) ; + if( tmp_gpf == NULL ){ + return -1 ; + } + if( falReadFontProp( tmp_gpf, FAL_FONT_PRM, &fdata, 1 ) ) { + USAGE1("%s : Failed to get font properties.\n", com ) ; + return -1 ; + } + + GETCHARSETSTR( char_set, fdata.xlfdname ) ; + if( FalGetUDCGIArea( locale, FALGETFALCODESET(codeset), char_set, gr, num_gr ) == FAL_ERROR ) + { + USAGE3("%s : Failed to get UDC code region. ( code set %d charset %s )\n", + com, codeset, char_set ) ; + return( -1 ); + } + + if( *num_gr == 0 ) { + USAGE3("%s : Failed to get UDC code region. ( code set %d charset %s )\n", + com, codeset, char_set ) ; + return -1 ; + } + + return(0) ; +} + + + +#define MAX_CODESET 8 + +int +#if NeedFunctionPrototypes +DispUdcCpArea( FILE *fp ) +#else +DispUdcCpArea( fp ) +FILE *fp ; +#endif +{ + int cd_set, j ; + FalFontDataList *fls ; + FalFontData fdata ; + int mask ; + FalCodeRegion *cr ; + int num_cr ; + char *locale ; + + if( (locale = (char *)getenv( "LANG" )) == NULL ){ + locale = "C" ; + } + memset( &fdata, 0, sizeof(FalFontData) ) ; + mask = 0 ; + mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED | + FAL_FONT_MASK_CODE_SET ; + + for( cd_set=0; cd_setnum == 0 ){ + continue ; + } + GETCHARSETSTR( char_set, fls->list[0].xlfdname ) ; + if( FalGetUDCCPArea( locale, + fls->list[0].cd_set, char_set, &cr, &num_cr ) == FAL_ERROR ){ + return -1 ; + } + if( num_cr == 0 ){ + continue ; + } + /* display UDC code region */ + USAGE1(" %d", cd_set ) ; + for( j=0; j +#include +#include +#include +#include +#include "udcutil.h" + +/* + * FileLock( fd ) + * fd: file descripter + * + * lock a file by a writing mode + * + * normal end : 0 + * abnormal end : -1 + * + */ + +int +#if NeedFunctionPrototypes +FileLock( int fd ) +#else +FileLock( fd ) +int fd; /* a file descripter */ +#endif +{ + + struct flock flpar; + + + flpar.l_type = F_RDLCK; + flpar.l_start = 0; + flpar.l_len = 0; + flpar.l_whence = 0; + + if ( fcntl( fd, F_SETLK, &flpar ) == -1 ) { + USAGE("Write lock not success \n" ); + return -1; + } + + return 0; +} + + +/* + * FileUnLock( fd ) + * + * free a file by a writing mode + * + * normal end : 0 + * abnormal end : -1 + */ + +int +#if NeedFunctionPrototypes +FileUnLock( int fd ) +#else +FileUnLock( fd ) +int fd; /* a file descripter */ +#endif +{ + struct flock flpar; + + + flpar.l_type = F_UNLCK; + flpar.l_start = 0; + flpar.l_len = 0; + flpar.l_whence = 0; + + if ( fcntl( fd, F_SETLK, &flpar ) == -1 ){ + USAGE("File unlock not success \n" ); + return -1; + } + return 0; +} + +/* + * isLock( fd ) + * + * search whether file is locked by a writing mode + * + * 1 : file is locked by a writing mode + * 0 : file isn't locked by a writing mode + */ + +int +#if NeedFunctionPrototypes +isLock( int fd ) +#else +isLock( fd ) +int fd; /* file descripter */ +#endif +{ + struct flock flpar; + + + flpar.l_type = F_WRLCK; + flpar.l_start = 0; + flpar.l_len = 0; + flpar.l_whence = 0; + + if ( fcntl( fd, F_GETLK, &flpar ) == -1 ) { + USAGE("Inquiry of file lock not sucess \n" ); + return -1; + } + + if ( flpar.l_type == F_UNLCK ){ + return 0 ; + } else { + return 1 ; + } +} diff --git a/cde/programs/dtudcfonted/libfuty/oakfuty.c b/cde/programs/dtudcfonted/libfuty/oakfuty.c new file mode 100644 index 00000000..04c9d1e0 --- /dev/null +++ b/cde/programs/dtudcfonted/libfuty/oakfuty.c @@ -0,0 +1,1720 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* $XConsortium: oakfuty.c /main/12 1996/11/11 10:55:57 drk $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include +#include +#ifndef SVR4 +#if !defined( SYSV ) +#include +#endif +#include +#else +#include +#include +#endif + +#include +#include +#include +#include + +#include "bdfgpf.h" +#include "udcutil.h" + +static void exline(); + +char *oakgtobdf; +char *bdftosnf = BDFTOSNF; +char *bdftopcf; + +static int put_file_create_err_msg = 0; + +#define DEVICE_FAIL 2 +#define WRITE_FAIL 3 +#define OPEN_FAIL 4 +#define READ_FAIL 5 + +int +#if NeedFunctionPrototypes +ReadBdfHeader( + struct btophead *head, + char *buf +) +#else +ReadBdfHeader( head, buf ) +struct btophead *head; +char *buf; +#endif +{ + char *p; + unsigned int getstat = 0; + + if (NULL == fgets(buf, BUFSIZE, head->input)) { + return(BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p) + + if (strncmp(p, STARTFONT, STARTFONTsz)) { + return(BDF_INVAL); + } + + while( 1 ) { + if (fgets(buf, BUFSIZE, head->input) == NULL) { + return (BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p) + if (!strncmp(p, SIZE, SIZEsz)) { + if ((sscanf(p, "SIZE %f%d", + &(head->bdf_point), &(head->bdf_xdpi))) != 2) { + return(BDF_INVAL); + } + getstat |= 0x01; + } else if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) { + if (sscanf(p, "FONTBOUNDINGBOX %d%d%d%d", + &(head->bdf_width), &(head->bdf_height), + &(head->bdf_x), &(head->bdf_y)) != 4) { + return BDF_INVAL; + } + getstat |= 0x02; + + } else if (!strncmp(p, CHARS, CHARSsz)) { + if ((sscanf(p, "CHARS %d", &(head->num_chars))) != 1) { + return(BDF_INVAL); + } + getstat |= 0x04; + } else if (!strncmp(p, STARTCHAR, STARTCHARsz)) { + break; + } + } + + if (getstat != 0x07) { + return(BDF_INVAL); + } + return 0; +} + + +int +#if NeedFunctionPrototypes +ReadGpfHeader( + struct ptobhead *head, + char *buf +) +#else +ReadGpfHeader(head, buf) +struct ptobhead *head; +char *buf; +#endif +{ + char *p; + unsigned int getstat = 0; + + while(1) { + if (getstat == 0x07) break; + + if (fgets(buf, BUFSIZE, head->input) == NULL) { + return GPF_INVAL; + } + p = buf; + SCAN_TO_NONSP(p) + + if (!strncmp(p, NUMFONTS, NUMFONTSsz)) { + if (sscanf(p, "numfonts:%d", &(head->num_chars)) != 1) { + return(GPF_INVAL); + } + getstat |= 0x01; + } else if (!strncmp(p, WIDTH, WIDTHsz)) { + if (sscanf(p, "width:%d", &(head->p_width)) != 1) { + return(GPF_INVAL); + } + getstat |= 0x02; + } else if (!strncmp(p, HEIGHT, HEIGHTsz)) { + if (sscanf(p, "height:%d", &(head->p_height)) != 1) { + return(GPF_INVAL); + } + getstat |= 0x04; + } + } + return 0; +} + + +int +#if NeedFunctionPrototypes +WriteBdfHeader( struct ptobhead *head ) +#else +WriteBdfHeader(head) +struct ptobhead *head; +#endif +{ + FILE *fp; + int fd[2]; + unsigned int getstat; + char buf[BUFSIZE], *p; + + pid_t chld_pid = 0; +#if defined( SVR4 ) || defined( SYSV ) || defined(CSRG_BASED) || defined(__linux__) + int chld_stat ; +#else + union wait chld_stat ; +#endif + + + if (head->snf_file != NULL) { + if (pipe(fd) != 0) { + return PIPE_ERROR; + } + switch (chld_pid = fork()) { + case 0: + close(1); + if(dup(fd[1]) < 0) { + return(DUP_ERROR); + } + close(fd[0]); + close(fd[1]); + execl( oakgtobdf, oakgtobdf, head->snf_file, 0); + + return EXEC_ERROR; + + case -1: + return(FORK_ERROR); + + default: + break; + } + close(fd[1]); + if((fp = (FILE *)fdopen(fd[0], "r")) == NULL) { + close( fd[0] ); + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + return FDOPEN_ERROR; + } + } else { + if ((fp = fopen(head->bdf_file, "r")) == NULL) { + return(BDF_OPEN_HEAD); + } + } + + getstat = 0; + + while ( 1 ) { + if (fgets(buf, BUFSIZE, fp) == NULL) { + fclose( fp ); + if (head->snf_file != NULL) { + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + return(BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p); + + if (!strncmp(p, CHARS, CHARSsz)) { + fclose( fp ); + if (head->snf_file != NULL) { + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + break; + } + + fprintf(head->output, "%s", buf); + + if (!strncmp(p, SIZE, SIZEsz)) { + if ((sscanf(p, "SIZE %f%d", + &(head->bdf_point), &(head->bdf_xdpi))) != 2) { + fclose(fp); + if (head->snf_file != NULL) { + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + return(BDF_INVAL); + } + getstat |= 0x01; + continue; + } + if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) { + if ( sscanf( p, "FONTBOUNDINGBOX %d%d%d%d", + &(head->bdf_width), + &(head->bdf_height), + &(head->bdf_x), + &(head->bdf_y)) != 4 + ) { + fclose(fp); + if (head->snf_file != NULL) { + kill( chld_pid, SIGKILL ); + WaitID( chld_pid, chld_stat ) ; + } + return BDF_INVAL; + } + getstat |= 0x02; + continue; + } + get_charset_registry(head, p) ; + } + + + if (getstat != 0x03) { + return BDF_INVAL; + } + + return 0; +} + + +void +#if NeedFunctionPrototypes +WriteGpfHeader( struct btophead *head ) +#else +WriteGpfHeader(head) +struct btophead *head; +#endif +{ + fprintf(head->output, "numfonts:%d\n", head->num_chars); + fprintf(head->output, "width:%d\n", head->p_width ); + fprintf(head->output, "height:%d\n", head->p_height ); +} + + + + +int +#if NeedFunctionPrototypes +WritePtnToBdf( struct ptobhead *head ) +#else +WritePtnToBdf(head) +struct ptobhead *head; +#endif +{ + int msize, swidth, rtn, i, nchar; + char *zoomptn; + int bbw, bbh, bbx, bby, dw ; + char glyph_name[BUFSIZE] ; + + nchar = head->num_chars; + put_default_chars(head, nchar, rtn) ; + + if (head->zoomf) { + msize = ((head->bdf_width + 7) / 8) * head->bdf_height; + if ((zoomptn = (char *)malloc(msize)) == NULL) { + return(MALLOC_ERROR); + } + } + + for (i=0; inum_chars; i++) { + sprintf( glyph_name, "%x", head->code[i]); + swidth = (head->bdf_width * 72270)/((int)(head->bdf_point * (float)head->bdf_xdpi)); + dw = head->bdf_width ; + bbw = head->bdf_width ; + bbh = head->bdf_height ; + bbx = head->bdf_x ; + bby = head->bdf_y ; + + fprintf(head->output, "STARTCHAR %s\n", glyph_name ); + fprintf(head->output, "ENCODING %d\n", head->code[i]); + fprintf(head->output, "SWIDTH %d 0\n", swidth ); + fprintf(head->output, "DWIDTH %d 0\n", dw ); + fprintf(head->output, "BBX %d %d %d %d\n", bbw, bbh, bbx, bby ); + fprintf(head->output, "BITMAP\n"); + + if (head->zoomf) { + if ((rtn = PtnZoom(zoomptn, head->ptn[i], head->p_width, + head->p_height, head->bdf_width, head->bdf_height))) { + return(rtn); + } + if( (rtn = PutBdfPtn(zoomptn, head->bdf_width, + head->bdf_height, head->output))) { + return(rtn); + } + } else { + if( (rtn = PutBdfPtn(head->ptn[i], + head->bdf_width, head->bdf_height, head->output))) { + return(rtn); + } + } + fprintf(head->output, "ENDCHAR\n"); + free(head->ptn[i]); + } + fprintf(head->output, "ENDFONT\n"); + return(0); +} + + + + +int +#if NeedFunctionPrototypes +putDefaultChars( struct ptobhead *head ) +#else +putDefaultChars(head ) +struct ptobhead *head; +#endif +{ + int swidth, bytew, i, j; + unsigned int posbit ; + unsigned char *ptnbuf, *ptnbuf2 ; + unsigned char tmp; + + put_default_encode( head ) ; + swidth = (head->bdf_width * 72270)/((int)(head->bdf_point * (float)head->bdf_xdpi)); + fprintf(head->output, "SWIDTH %d 0\n", swidth); + fprintf(head->output, "DWIDTH %d 0\n", head->bdf_width); + fprintf( head->output, "BBX %d %d %d %d\n", head->bdf_width, head->bdf_height, head->bdf_x, head->bdf_y ); + fprintf(head->output, "BITMAP\n"); + + bytew = (head->bdf_width + 7) / 8; + if ((ptnbuf = (unsigned char *)malloc(bytew * 2)) == NULL) { + return(MALLOC_ERROR); + } + put_default_bitmap(head, bytew, posbit, i, j, ptnbuf, ptnbuf2, tmp) ; + + fprintf(head->output, "ENDCHAR\n"); + free(ptnbuf); + return 0; +} + + +int +#if NeedFunctionPrototypes +WritePtnToGpf( struct btophead *head ) +#else +WritePtnToGpf(head) +struct btophead *head; +#endif +{ + int msize, rtn, i; + char *zoomptn; + + + if (head->zoomf) { + msize = ((head->p_width + 7) / 8) * head->p_height; + if ((zoomptn = (char *)malloc(msize)) == NULL) { + return(MALLOC_ERROR); + } + } + + for (i=0; inum_chars; i++) { + + if ( head->code[i] > 0xff ) { + fprintf(head->output, "code:0x%x\n", SHIFT_ON(head->code[i]) ); + } else { + fprintf(head->output, "code:0x%x\n", head->code[i]); + } + if (head->zoomf) { + if ((rtn = PtnZoom(zoomptn, head->ptn[i], head->bdf_width, + head->bdf_height, head->p_width, head->p_height))) { + return(rtn); + } + if ((rtn = PutGpfPtn(zoomptn, head->p_width, + head->p_height, head->output))) { + return(rtn); + } + } else { + if ((rtn = PutGpfPtn(head->ptn[i], + head->bdf_width, head->bdf_height, head->output))) { + return(rtn); + } + } + free(head->ptn[i]); + } + fprintf(head->output, "enddata\n"); + return(0); +} + + +int +#if NeedFunctionPrototypes +ReadBdfToMemory( + struct btophead *head, + char *buf +) +#else +ReadBdfToMemory(head, buf) +struct btophead *head; +char *buf; +#endif +{ + int code, mwidth, num_char, bsize, rtn; + char *ptn; + + num_char = 0; + mwidth = (head->bdf_width + 7) / 8; + bsize = mwidth * head->bdf_height; + while(1) { + if ((rtn = GetBdfCode(head, buf, &code)) < 0) { + return(rtn); /* contain BDF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + + if ( ( code > head->end_code ) + || ( code < head->start_code ) + || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) ) + || COMM_ISDEFAULTCHAR( code ) + ) { + continue; + } + head->code[num_char] = code; + if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) { + return(MALLOC_ERROR); + } + + if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} + + +int +#if NeedFunctionPrototypes +ReadBdfToMemory_with_init( + struct btophead *head, + int init_start, + int init_end, + char *buf +) +#else +ReadBdfToMemory_with_init(head, init_start, init_end, buf) +struct btophead *head; +int init_start; +int init_end; +char *buf; +#endif +{ + int code, mwidth, num_char, bsize, rtn; + char *ptn; + + num_char = 0; + mwidth = (head->bdf_width + 7) / 8; + bsize = mwidth * head->bdf_height; + while(1) { + if ((rtn = GetBdfCode(head, buf, &code)) < 0) { + return(rtn); /* contain BDF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + + if ( ( code > head->end_code ) + || ( code < head->start_code ) + || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) ) + || ( ( code >= init_start ) && ( code <= init_end ) ) + || COMM_ISDEFAULTCHAR( code ) + ) { + continue; + } + + head->code[num_char] = code; + if ((ptn = head->ptn[num_char++] = + (char *)malloc(bsize)) == NULL) { + return(MALLOC_ERROR); + } + + if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} + + +int +#if NeedFunctionPrototypes +GetBdfCode( + struct btophead *head, + char *buf, + int *code +) +#else +GetBdfCode(head, buf, code) +struct btophead *head; +char *buf; +int *code; +#endif +{ + char *p; + + while(1) { + if (fgets(buf, BUFSIZE, head->input) == NULL) { + return (BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p) + if (!strncmp(p, ENDFONT, ENDFONTsz)) { + return(FILE_END); + } + + if (!strncmp(p, ENCODING, ENCODINGsz)) { + if ((sscanf(p, "ENCODING %d", code)) != 1) { + return(BDF_INVAL); + } + break; + } + } + return(0); +} + + +int +#if NeedFunctionPrototypes +GetBdfPtn( + struct btophead *head, + char *buf, + char *ptn, + int mwidth, + int bsize +) +#else +GetBdfPtn(head, buf, ptn, mwidth, bsize) +struct btophead *head; +char *buf; +char *ptn; +int mwidth; +int bsize; +#endif +{ + int skip, i, j; + char *p; + + while(1) { + if (fgets(buf, BUFSIZE, head->input) == NULL) { + return (BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p) + if (!strncmp(p, BITMAP, BITMAPsz)) { + break; + } + } + + ptn[bsize - 1] = 0; + + for (i=0, skip=0; ibdf_height; i++) { + if (skip) { + for(j=0; jinput) == NULL) { + return (BDF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p); + if (!strncmp(p, ENDCHAR, ENDCHARsz)) { + skip = 1; + for(j=0; jbdf_width); + ptn += mwidth; + } + return(0); +} + + +int +#if NeedFunctionPrototypes +ReadGpfToMemory( + struct ptobhead *head, + char *buf +) +#else +ReadGpfToMemory(head, buf) +struct ptobhead *head; +char *buf; +#endif +{ + int code, mwidth, num_char, bsize, rtn; + char *ptn; + + num_char = 0; + mwidth = (head->p_width + 7) / 8; + bsize = mwidth * head->p_height; + while(1) { + if ((rtn = GetGpfCode(head, buf, &code)) < 0) { + return(rtn); /* contain GPF_INVAL */ + } else if (rtn == FILE_END) { + head->num_chars = num_char; + break; + } + if ( ( code > head->end_code ) + || (code < head->start_code ) + || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) ) + || COMM_ISDEFAULTCHAR( code ) + ) { + continue; + } + head->code[num_char] = code; + if ((ptn = head->ptn[num_char++] = + (char *)malloc(bsize)) == NULL) { + return(MALLOC_ERROR); + } + + if ((rtn = GetGpfPtn(head, buf, ptn, mwidth, bsize)) != 0) { + return(rtn); + } + } + return(0); +} + + +int +#if NeedFunctionPrototypes +GetGpfCode( + struct ptobhead *head, + char *buf, + int *code +) +#else +GetGpfCode(head, buf, code) +struct ptobhead *head; +char *buf; +int *code; +#endif +{ + char *p; + + while(1) { + p = buf; + SCAN_TO_NONSP(p) + + if (!strncmp(p, ENDDATA, ENDDATAsz)) { + return(FILE_END); + } + if (!strncmp(p, CODE, CODEsz)) { + *code = (int)strtol(buf+CODEsz, NULL, 0); + CONVGLYPHINDEX( *code ) ; + break; + } + + if (fgets(buf, BUFSIZE, head->input) == NULL) { + return (GPF_INVAL); + } + } + return(0); +} + + +int +#if NeedFunctionPrototypes +GetGpfPtn( + struct ptobhead *head, + char *buf, + char *ptn, + int mwidth, + int bsize +) +#else +GetGpfPtn(head, buf, ptn, mwidth, bsize) +struct ptobhead *head; +char *buf; +char *ptn; +int mwidth; +int bsize; +#endif +{ + int skip, i, j; + char *p; + + for (i=0, skip=0; ip_height; i++) { + if (skip) { + for (j=0; jinput) == NULL) { + return (GPF_INVAL); + } + p = buf; + SCAN_TO_NONSP(p); + if ((!strncmp(p, CODE, CODEsz)) || + (!strncmp(p, ENDDATA, ENDDATAsz))) { + skip = 1; + for (j=0; jp_width); + ptn += mwidth; + } + return(0); +} + + +void +#if NeedFunctionPrototypes +GetBdfLinePtn( + char *mem, + char *buf, + int width +) +#else +GetBdfLinePtn(mem, buf, width) +char *mem; +char *buf; +int width; +#endif +{ + int i, iend, len; + char *p, str[3]; + + str[2] = 0; + + SCAN_TO_NONSP(buf); + + iend = (width + 3) / 4; + + if ((len = strlen(buf)) < iend) { + p = buf+len; + for (i=0; i<(iend-len); i++) { + *p++ = '0'; + } + *p ='\0'; + } + + for (i=0; i> 4; + c = (x>=10)? 'a'-0xa : '0'; + *pbuf++ = c + x; + x = *ptn++ & 0x0f; + c = (x>=10)? 'a'-0xa : '0'; + *pbuf++ = c + x; + } + *pbuf++ = '\n'; + } + *pbuf = '\0'; + fprintf(fp, "%s", buf); + return(0); +} + + + + +int +#if NeedFunctionPrototypes +PutGpfPtn( + char *ptn, + int width, + int height, + FILE *fp +) +#else +PutGpfPtn(ptn, width, height, fp) +char *ptn; +int width; +int height; +FILE *fp; +#endif +{ + int i, j, k, nbyte, tw; + unsigned char p, *pbuf; + static unsigned char *buf=NULL; + + if (buf==NULL) { + buf = (unsigned char *)malloc(((width+1)*height)+1); + if ( buf == NULL) { + return(MALLOC_ERROR); + } + } + + nbyte = (width + 7) / 8; + + pbuf=buf; + for(i=0; i0; k++, tw--) { + if (p & 0x80) { + *pbuf++ = '0'; + } else { + *pbuf++ = '-'; + } + p = p << 1; + } + } + *pbuf++ = '\n'; + } + *pbuf = '\0'; + fprintf(fp, "%s", buf); + return(0); +} + + +int +#if NeedFunctionPrototypes +PtnZoom( + char *dmem, + char *smem, + int sw, + int sh, + int dw, + int dh +) +#else +PtnZoom(dmem, smem, sw, sh, dw, dh) +char *dmem; +char *smem; +int sw; +int sh; +int dw; +int dh; +#endif +{ + int swidth; + int dwidth; + int i, lcnt; + char *dbuf, *sp, *dp; + + swidth = (sw + 7) / 8; + dwidth = (dw + 7) / 8; + + if ((dbuf = (char *)malloc(dwidth)) == NULL) { + return(MALLOC_ERROR); + } + + lcnt = 0; + sp = smem; + dp = dmem; + + for(i=0; i < sh; i++) { + lcnt += dh; + if (lcnt >= sh) { + exline(sp, dbuf, sw, dw); + sp += swidth; + lcnt -= sh; + memcpy(dp, dbuf, dwidth); + dp += dwidth; + for (; lcnt >= sh; lcnt -= sh) { + memcpy(dp, dbuf, dwidth); + dp += dwidth; + } + } else { + sp += swidth; + } + } + free(dbuf); + return(0); +} + + +static void +exline(sp, dbuf, sw, dw) +char *sp; +char *dbuf; +int sw; +int dw; +{ + unsigned int i, bit, sval, dval, dcnt, bcnt; + + bcnt = dval = 0; + dcnt = 8; + + for(i=0; i= sw; bcnt -= sw) { + dval = (dval << 1) | bit; + if (--dcnt == 0) { + *dbuf++ = (char)dval; + dval = 0; + dcnt = 8; + } + } + } + if (dcnt != 8) { + dval <<= dcnt; + *dbuf = (char)dval; + } +} + + +char * +#if NeedFunctionPrototypes +GetTmpPath( char *path ) +#else +GetTmpPath( path ) +char *path; +#endif +{ + char *p=NULL, *sp, *buf ; + int len ; + struct stat statbuf ; + + /* Get directory of temporary file */ + if( !(p = (char *)getenv( "TMPDIR" )) ){ + p = DEFAULT_TMPPATH ; + } + /* Get memory for temporary file name */ + sp = p ; + len = strlen(p) ; + if( *(sp + len -1) == '/' ){ + len += (strlen( TEMPFILEKEY ) + 1) ; + }else{ + len += (strlen( TEMPFILEKEY ) +1 + 1) ; + } + if ((buf = (char *)malloc( len )) == NULL) { + return NULL; + } + /* Get temporary file path */ + strcpy( buf, p ) ; + sp = buf + strlen(buf) -1 ; + if( *sp == '/' ) *sp-- = '\0' ; + sprintf( sp+1, "/%s", TEMPFILEKEY ) ; + /* Get temporary file name */ + return mktemp( buf ) ; +} + + +int +#if NeedFunctionPrototypes +Link_NewFile( char *rd_file, char *wr_file ) +#else +Link_NewFile( rd_file, wr_file ) +char *rd_file ; +char *wr_file ; +#endif +{ + FILE *rfp, *wfp ; + int i, c ; + int rfd, wfd ; + struct stat statbuf ; + unsigned char bufc ; + char *buf ; + int ismmap = 0 ; + + if( stat( wr_file, &statbuf ) == -1 ){ + if( (wfd = open( wr_file, O_CREAT | O_WRONLY, 0644 )) == -1 ){ + return -1 ; + } + }else{ + if( (wfd = open( wr_file, O_WRONLY | O_TRUNC )) == -1 ){ + return -1 ; + } + } + if( stat( rd_file, &statbuf ) == -1 ){ + close(wfd) ; + return -1 ; + } + if( (rfd = open( rd_file, O_RDONLY )) == -1 ){ + close(wfd) ; + return -1 ; + } + +#if defined( SVR4 ) + if( (buf = (char *)mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, rfd, 0)) == (char *)-1 ){ +#endif /* SVR4 */ + if( !(buf = (char *)malloc(statbuf.st_size)) ){ + close(wfd) ; + close(rfd) ; + return -1 ; + } + if( read(rfd, buf, statbuf.st_size) != statbuf.st_size ){ + close(wfd) ; + close(rfd) ; + free(buf) ; + return -1 ; + } +#if defined( SVR4 ) + }else{ + ismmap = 1 ; + } +#endif /* SVR4 */ + + close(rfd) ; + + if( write(wfd, buf, statbuf.st_size) != statbuf.st_size ){ +#if defined( SVR4 ) + if( ismmap ){ + munmap(buf, statbuf.st_size) ; + }else{ +#endif /* SVR4 */ + free(buf) ; +#if defined( SVR4 ) + } +#endif /* SVR4 */ + close(wfd) ; + return (DEVICE_FAIL); + } +#if defined( SVR4 ) + if( ismmap ){ + munmap(buf, statbuf.st_size) ; + }else{ +#endif /* SVR4 */ + free(buf) ; +#if defined( SVR4 ) + } +#endif /* SVR4 */ + close(wfd) ; + + return 0 ; +} + + +int +#if NeedFunctionPrototypes +ChkNumString( char *str ) +#else +ChkNumString( str ) +char *str; +#endif +{ + char *tmp; + int num; + + num = (int)strtol( str, &tmp, 10 ); + if ((num == 0)&&(tmp == str)) { + return(-1); + } + if ((size_t)(tmp - str) != strlen(str)){ + return(-1); + } + return( 0 ); +} + + +void +#if NeedFunctionPrototypes +ErrMsgTable_AndExit( + int er_no, + char *snf_in, + char *snf_out, + char *gpf_in, + char *gpf_out, + char *bdf_in, + char *prog_name +) +#else +ErrMsgTable_AndExit(er_no, snf_in, snf_out, gpf_in, gpf_out, bdf_in, prog_name) +int er_no; +char *snf_in; +char *snf_out; +char *gpf_in; +char *gpf_out; +char *bdf_in; +char *prog_name ; +#endif +{ + int rtn = 0 ; + switch(er_no) { + case 0: + break; + case BDF_OPEN_IN : + USAGE2("%s : The input font file cannot be opened.\"%s\"\A1\A5\n", prog_name, (snf_in != NULL)? snf_in : "\0" ); + rtn = OPEN_FAIL ; + break; + + case BDF_OPEN_OUT : + USAGE2("%s : The output font file cannot be opened.\"%s\"\A1\A5\n", prog_name, (snf_out != NULL)? snf_out : "\0" ); + rtn = OPEN_FAIL ; + break; + + + case BDF_READ : + USAGE2("%s : Information from the font file cannot be extracted.\"%s\"\A1\A5 \n", prog_name, (snf_in != NULL) ? snf_in : "\0" ); + rtn = READ_FAIL ; + break; + + case BDF_WRITE : + USAGE2("%s : It is not possible to write to the font file.\"%s\"\A1\A5\n", prog_name, (snf_out != NULL) ? snf_out : "\0" ); + rtn = DEVICE_FAIL ; + break; + + case BDF_INVAL : + USAGE2("%s : The format of the font file is illegal.\"%s\"\A1\A5 \n", prog_name, (snf_in != NULL) ? snf_in : "\0" ); + rtn = 1 ; + break; + + case BDF_OPEN_HEAD : + USAGE2("%s : The BDF file cannot be opened.\"%s\"\A1\A5\n", prog_name, (bdf_in != NULL)? bdf_in : "\0" ); + rtn = OPEN_FAIL ; + break; + + case BDF_READ_HEAD : + USAGE2("%s : Information of the BDF file cannot be extracted.\"%s\"\A1\A5 \n", prog_name, (bdf_in != NULL) ? bdf_in : "\0" ); + rtn = READ_FAIL ; + break; + + case GPF_OPEN_IN : + USAGE2("%s : The input character pattern file cannot be opened.\"%s\"\A1\A5\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" ); + rtn = OPEN_FAIL ; + break; + + case GPF_OPEN_OUT : + USAGE2("%s : The output character pattern file cannot be opened.\"%s\"\A1\A5\n", prog_name, (gpf_out != NULL) ? gpf_out : "\0" ); + rtn = OPEN_FAIL ; + break; + + case GPF_READ : + USAGE2("%s : The character pattern file cannot be read.\"%s\"\A1\A5\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" ); + rtn = READ_FAIL ; + break; + + case GPF_WRITE : + USAGE2("%s : It is not possible to write to the character pattern file.\"%s\"\A1\A5\n", prog_name, (gpf_out != NULL) ? gpf_out : "\0" ); + rtn = DEVICE_FAIL ; + break; + + case GPF_INVAL : + USAGE2("%s : The format of the character pattern file is illegal.\"%s\"\A1\A5\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" ); + rtn = 1 ; + break; + + default : + fatal_err_msg( er_no, prog_name ); + rtn = 1 ; + break; + } + exit(rtn); +} + + +void +#if NeedFunctionPrototypes +fatal_err_msg( + int er_no, + char *prog_name +) +#else +fatal_err_msg( er_no, prog_name ) +int er_no; +char *prog_name; +#endif +{ + USAGE1("%s : The font file failed to be converted. ", prog_name); + switch( er_no ) { + case MALLOC_ERROR: + USAGE("There is no memory any more.\n"); + break; + case FORK_ERROR: + USAGE("The child process cannot be created.\n" ); + break; + case EXEC_ERROR: + USAGE("Cannot execute dtgpftobdf.\n" ); + break; + case PIPE_ERROR: + USAGE("The pipe buffer cannot be open.\n" ); + break; + case DUP_ERROR: + USAGE("The file descripter cannot be duplicated.\n" ); + break; + case POPEN_ERROR: + USAGE("The X font compiler cannot be executed.\n" ); + break; + case PCLOSE_ERROR: + USAGE("The pipe buffer cannot be close.\n" ); + break; + case FDOPEN_ERROR: + USAGE("The file descripter cannot be got.\n" ); + break; + case STAT_ERROR: + USAGE("The status of font cannot be got.\n" ); + break; + case MKTMP_ERROR: + USAGE("The temporally file cannot be got.\n" ); + break; + case PCFFONTC_ERROR: + USAGE("Cannot execute bdftopcf.\n" ); + break; + case SNFFONTC_ERROR: + USAGE("Cannot execute bdftosnf.\n" ); + break; + default: + USAGE1("Terminates abnormally. ( err_code(%d) )\n", er_no); + break; + } + return; +} + + + +static int sig_flg=0; + +#define GPF_BUCK_UP_FAIL 1 +#define GPF_MODIFY_FAIL 2 +#define RESTORE_FAIL 3 +#define CATCH_SIGNAL 10 + +void +ChatchSig() +{ + sig_flg = 1; +} + +void +#if NeedFunctionPrototypes +Put_File_Create_Err_Msg( + int msg_level, + char *org_name, + char *tmp_name, + char *save_name, + char *com +) +#else +Put_File_Create_Err_Msg( msg_level, org_name, tmp_name, save_name, com ) +int msg_level; +char *org_name; +char *tmp_name; +char *save_name; +char *com; +#endif +{ + switch( msg_level ) { + case GPF_BUCK_UP_FAIL: + USAGE1("%s : Failed to write temporary file. Terminates abnormally.\n", com ); + put_file_create_err_msg = DEVICE_FAIL ; + break; + + case GPF_MODIFY_FAIL: + USAGE1("%s : Failed in the renewal of the font file. Terminates abnormally.\n", com ); + put_file_create_err_msg = WRITE_FAIL ; + break; + + case RESTORE_FAIL: + USAGE3("%s : The file before updating cannot be changed to former file name.\tPlease execute the following command after the inquiry the system manager.\n\t mv %s %s\n", + com, save_name, org_name); + put_file_create_err_msg = WRITE_FAIL ; + break; + + case CATCH_SIGNAL: + USAGE1("%s : The signal was received. Terminates abnormally.\n", com); + put_file_create_err_msg = 1 ; + break; + } +} + +int +#if NeedFunctionPrototypes +Make_NewFefFile( + char *org_name, + char *tmp_name, + mode_t mode, + uid_t owner, + gid_t group, + char *com +) +#else +Make_NewFefFile( org_name, tmp_name, mode, owner, group, com ) +char *org_name; +char *tmp_name; +mode_t mode; +uid_t owner; +gid_t group; +char *com; +#endif +{ + struct stat statbuf; + char *save_name = NULL; + int ret_val; + int msg_level; + int rtn ; + +#ifndef SVR4 + signal( SIGHUP , (void(*)())ChatchSig); + signal( SIGINT , (void(*)())ChatchSig); + signal( SIGQUIT, (void(*)())ChatchSig); + signal( SIGTERM, (void(*)())ChatchSig); +#else + sigset( SIGHUP , (void(*)())ChatchSig); + sigset( SIGINT , (void(*)())ChatchSig); + sigset( SIGQUIT, (void(*)())ChatchSig); + sigset( SIGTERM, (void(*)())ChatchSig); +#endif + + errno = 0; + if (sig_flg || ((save_name = GetTmpPath( org_name )) == NULL)) { + msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_BUCK_UP_FAIL; + Put_File_Create_Err_Msg( msg_level, org_name, tmp_name, + (char *)NULL, com ); + Unlink_Tmpfile ( tmp_name, com ); + return(put_file_create_err_msg); + } + + if (sig_flg || ((rtn=Link_NewFile( org_name, save_name )) != 0)) { + msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_BUCK_UP_FAIL; + Put_File_Create_Err_Msg( msg_level, org_name, tmp_name, + save_name, com ); + Unlink_Tmpfile ( save_name, com ); + Unlink_Tmpfile ( tmp_name, com ); + free(save_name); + return( (put_file_create_err_msg == DEVICE_FAIL)? + put_file_create_err_msg : rtn ); + } + + if (sig_flg || ((rtn=Link_NewFile( tmp_name, org_name )) != 0)) { + msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_MODIFY_FAIL; + Put_File_Create_Err_Msg( msg_level, org_name, tmp_name, + save_name, com ); + if ( (rtn=Link_NewFile( save_name, org_name )) != 0 ) { + Put_File_Create_Err_Msg( RESTORE_FAIL, org_name, + tmp_name, save_name, com ); + Unlink_Tmpfile ( tmp_name, com ); + } else { + Unlink_Tmpfile ( tmp_name, com ); + Unlink_Tmpfile ( save_name, com ); + } + free(save_name); + return( (put_file_create_err_msg == DEVICE_FAIL)? + put_file_create_err_msg : rtn ); + } + + ret_val = 0; + ret_val += Unlink_Tmpfile ( tmp_name, com ); + ret_val += Unlink_Tmpfile ( save_name, com ); + + free(save_name); + return( (ret_val)? 1 : 0 ); +} + + +int +#if NeedFunctionPrototypes +Unlink_Tmpfile( + char *file, + char *com +) +#else +Unlink_Tmpfile( file, com ) +char *file; +char *com; +#endif +{ + errno = 0; + if ( unlink( file ) != 0 ) { + USAGE2("%s : The work file cannot be deleted. Please unlink the following files\tafter the inquiry the system manager.\"%s\" \n", com, file ); + return(1); + } + return(0); +} + + +int +#if NeedFunctionPrototypes +Chmod_File ( + char *fname, + mode_t mode, + char *com +) +#else +Chmod_File ( fname, mode, com ) +char *fname; +mode_t mode; +char *com; +#endif +{ + errno = 0; + if ( mode == 0 ) return( 0 ) ; + if ( chmod (fname, mode) != 0) { + USAGE3("%s : Failed in the mode change of the following files. Please change the mode to %o\tafter the inquiry the system manager.\"%s\" \n", com, (int)mode, fname ); + return( 1 ); + } + return( 0 ); +} + + +int +#if NeedFunctionPrototypes +Chown_File ( + char *fname, + uid_t owner, + gid_t group, + char *com +) +#else +Chown_File ( fname, owner, group, com ) +char *fname; +uid_t owner; +gid_t group; +char *com; +#endif +{ + errno = 0; + if ( chown (fname, owner, group) != 0) { + USAGE2("%s : Failed in setteing of the owner and the group of the following files. \tPlease change to the file of the owner and the group of following ID \tafter the inquiry the system manager.\"%s\"\n", com, fname ); + USAGE1("\t\t Owner ID \A1\A7%d\n", (int)owner); + USAGE1("\t\t Group ID \A1\A7%d\n", (int)group); + return( 1 ); + } + return( 0 ); +} + + + + +int +#if NeedFunctionPrototypes +ChkPcfFontFile( char *filename ) +#else +ChkPcfFontFile( filename ) +char *filename; +#endif +{ + char *suffix; + + if ( !filename ) { + return -1; + } + suffix = ( char * )strrchr( filename, '.' ); + if ( !suffix ) { + return -1; + } + + return strcmp( PCFSUFFIX, suffix ); +} + + +int +#if NeedFunctionPrototypes +ChkSnfFontFile( char *filename ) +#else +ChkSnfFontFile( filename ) +char *filename; +#endif +{ + char *suffix; + + if ( !filename ) { + return -1; + } + suffix = ( char * )strrchr( filename, '.' ); + if ( !suffix ) { + return -1; + } + + return strcmp( SNFSUFFIX, suffix ); +} + + +char * +#if NeedFunctionPrototypes +get_cmd_path( + char *path, + char *cmd +) +#else +get_cmd_path( path, cmd ) +char *path; +char *cmd; +#endif +{ + char *cmd_path = NULL; + struct stat st; + char *end; + char chr_sv; + + if ( !path || !cmd ) { + return NULL; + } + + for ( ; end = ( char * )strchr( path, ':' ); path = end + 1 ) { + chr_sv = *end; + *end = 0; + AllocString( cmd_path, path, NULL ) ; + *end = chr_sv; + + AddString( cmd_path, "/", NULL ) ; + AddString( cmd_path, cmd, NULL ) ; + + if ( stat( cmd_path, &st ) == 0 ) { + if( st.st_mode & S_IFREG ) { + cmd_path = realloc( cmd_path, strlen( cmd_path ) + 1 ); + return cmd_path; + } + } + FreeString( cmd_path ) ; + } + free(cmd_path); + AllocString( cmd_path, path, NULL ) ; + AddString( cmd_path, "/", NULL ) ; + AddString( cmd_path, cmd, NULL ) ; + if ( stat( cmd_path, &st ) == 0 ) { + if( st.st_mode & S_IFREG ) { + cmd_path = realloc( cmd_path, strlen( cmd_path ) + 1 ); + return cmd_path; + } + } + free( cmd_path ); + return NULL; +} + +int +#if NeedFunctionPrototypes +SetCmdPath( + char *com , + char **path , + char *dflt_path , + char *cmd +) +#else +SetCmdPath( com, path, dflt_path, cmd ) +char *com ; +char **path ; +char *dflt_path ; +char *cmd ; +#endif +{ + struct stat statbuf ; + char *pbuf ; + + if( stat( dflt_path, &statbuf ) ){ + if( !( pbuf = (char *)get_cmd_path( getenv( "PATH" ), cmd )) ){ + USAGE2("%s: There is not \"%s\" command in \"PATH\".\n", com, cmd ) ; + return -1 ; + } + if( stat( pbuf, &statbuf ) ){ + USAGE2("%s: There is not \"%s\" command.\n", com, cmd ) ; + free(pbuf); + return STAT_ERROR ; + } + if( !(statbuf.st_mode & S_IXUSR) ){ + USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ; + free(pbuf); + return STAT_ERROR ; + } + }else{ + if( !(statbuf.st_mode & S_IXUSR) ){ + USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ; + return STAT_ERROR ; + } + pbuf = dflt_path ; + } + *path = pbuf ; + return 0 ; +} + +/*****************************< end of oakfuty.c >************************/ diff --git a/cde/programs/dtudcfonted/mtfgui.c b/cde/programs/dtudcfonted/mtfgui.c new file mode 100644 index 00000000..02775f60 --- /dev/null +++ b/cde/programs/dtudcfonted/mtfgui.c @@ -0,0 +1,687 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* mtfgui.c 1.21 - Fujitsu source for CDEnext 96/10/30 13:13:46 */ +/* $XConsortium: mtfgui.c /main/11 1996/11/08 01:55:01 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#include +#include +#include +#include + +#include "xoakufont.h" +#include "util.h" + +void CBeOblB_aEnd(); +void EHeStaT_list(); +void CBeScro(); +void EHeBulB_eMEv(); +void EHeBulB_eExp(); +void EHeBulB_dExp(); +static void EHStaT_disp(); + +extern Resource resource; + +extern int efctPtnNum(); +extern char *char_set(); + +extern char *fullpath; +extern FalFontData fullFontData; + +extern FalCodeRegion CodeArea[16]; + +/******************************************************************** + structure of widgets + ********************************************************************/ +extern Widget toplevel; + Widget editPopW, + wgeScro, + wgeBulB_edit; +static Widget wgeStaT_form[EDLIST_MAX], + wgeStaT_disp[EDLIST_MAX], + wgeStaT_list[EDLIST_MAX], + wgeBulB_disp; + +/********************************************************************** + display windows + **********************************************************************/ + +/* + * contents : displays the "User Defined Charactrer editor" window + */ + +static Widget CreateEditPtn(); +void OpenCB(); +void MngPtnCB(); +void CpyPtnCB(); +void CBeRecB_color(); +void CBeRecB_obj(); +void CBeOblB_aAdd(); +void CBeOblB_rCmd(); +void CBeOblB_rCmdp(); +void CBeOblB_rCan(); + + +/** + ** contents : manage the codes list + ** =================================================================== + **/ + +static void +XlfdCB() +{ + Widget dialog; + Arg args[5]; + char mess[1024]; + int n; + XmString cs, cs1, cs2; + + sprintf(mess, "%s : %s", resource.file_name, fullpath); + cs = XmStringCreateLocalized(mess); + cs1 = XmStringSeparatorCreate(); + cs2 = XmStringConcat(cs, cs1); + XmStringFree(cs); + XmStringFree(cs1); + sprintf(mess, "%s : %s", resource.xlfd_name, fullFontData.xlfdname); + cs1 = XmStringCreateLocalized(mess); + cs = XmStringConcat(cs2, cs1); + XmStringFree(cs1); + XmStringFree(cs2); + n = 0; + XtSetArg (args[n], XmNtitle, resource.l_xlfd_title); n++; + XtSetArg (args[n], XmNmessageString, cs); n++; + XtSetArg (args[n], XmNdialogStyle, XmDIALOG_MODELESS); n++; + dialog = XmCreateInformationDialog (toplevel, "Xlfd_name", args, n); + XtUnmanageChild (XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON)); + XtUnmanageChild (XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON)); + XtManageChild (dialog); + XmStringFree(cs); +} + +static void +CodeAreaCB() +{ + char mess[256]; + char tmp[16]; + Widget dialog; + Arg args[5]; + int n; + XmString cs; + + sprintf(mess, "%s : ", resource.codearea); + switch (fullFontData.cd_set) { + case FAL_FONT_CS0: + strcat(mess, "CS0:"); + break; + case FAL_FONT_CS1: + strcat(mess, "CS1:"); + break; + case FAL_FONT_CS2: + strcat(mess, "CS2:"); + break; + case FAL_FONT_CS3: + strcat(mess, "CS3:"); + break; + } + + for (n=0; CodeArea[n].start != -1; n++) { + sprintf(tmp, " %X - %X ", CodeArea[n].start, CodeArea[n].end); + strcat(mess, tmp); + } + cs = XmStringCreateLocalized(mess); + n = 0; + XtSetArg (args[n], XmNtitle, resource.l_codearea_title); n++; + XtSetArg (args[n], XmNmessageString, cs); n++; + XtSetArg (args[n], XmNdialogStyle, XmDIALOG_MODELESS); n++; + XtSetArg (args[n], XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON); n++; + dialog = XmCreateInformationDialog (toplevel, "UDCarea", args, n); + XtUnmanageChild (XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON)); + XtUnmanageChild (XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON)); + XtManageChild (dialog); + XmStringFree(cs); +} + +void +ListSetLabelStr(i, str) +int i; +String str; +{ + SetLabelString( wgeStaT_list[i], str ); +} + +void +ListSelectItem(i) +int i; +{ + XtVaSetValues( wgeStaT_list[i], + XmNbackground, (XtArgVal) resource.foreground, + XmNforeground, (XtArgVal) resource.background, + NULL); + xl.list_winID = XtWindow( wgeStaT_disp[i] ) ; +} + +void +ListUnselectItem(i) +int i; +{ + XtVaSetValues( wgeStaT_list[i], + XmNbackground, (XtArgVal) resource.background, + XmNforeground, (XtArgVal) resource.foreground, + NULL); + xl.list_winID = 0 ; +} + +void +ListSetGlyphImage( i ) +int i ; +{ + int code ; + + dl_glyph[i].disp_winID = XtWindow(wgeStaT_disp[i]); + code = noToCode(ptnSqToNo(sq_disp[i])); + if (codeCheck(code)) { + XClearWindow(xl.display, dl_glyph[i].disp_winID); + return; + } + if (code == edg.code && xl.dispImage != NULL) { + XPutImage(xl.display, dl_glyph[i].disp_winID, xl.borderGC, + xl.dispImage, 0,0,0,0, edg.width, edg.height ); + } else { + if (dl_glyph[i].dispImage) + XFree((char *)dl_glyph[i].dispImage); + if (ptnGet(code, dl_glyph[i].ptn)) + return ; + dl_glyph[i].dispImage = XCreateImage( xl.display, + DefaultVisual(xl.display, DefaultScreen(xl.display)), 1, + XYBitmap, 0, dl_glyph[i].ptn, edg.width, edg.height, 8, 0); + dl_glyph[i].dispImage->bitmap_bit_order = MSBFirst; + dl_glyph[i].dispImage->byte_order = MSBFirst; + + XPutImage(xl.display, dl_glyph[i].disp_winID, xl.borderGC, + dl_glyph[i].dispImage, 0,0,0,0, edg.width, edg.height); + } +} + +/*ARGSUSED*/ +static void +EHStaT_disp( widget, i ) +Widget widget; +int i; /* widget that have some ivent */ +{ + ListSetGlyphImage( i ); +} + +/** + ** contents : create the icon + ** =================================================================== + **/ + + +/** + ** contents : set callback functions for UDC editor window + ** =================================================================== + **/ + +static void _create_editptn_after(); + +static Widget FooterMessage; +static Widget codeLabel; + +static menuButtonItems menu_btn[] = { + MENUBTNARGS( 'F' ), + MENUBTNARGS( 'E' ), + MENUBTNARGS( 'C' ), + MENUBTNARGS( 'I' ), +}; +static MButton MenuBTN = MBUTTONS( menu_btn ); + +static ButtonItems file_btn[] = { + BTNARGS( OpenCB, NULL, 'O', True, False), + BTNARGS( CBeOblB_aAdd, NULL, 'S', True, False), + BTNARGS( NULL, NULL, NULL, NULL, NULL), + BTNARGS( CBeOblB_aEnd, NULL, 'E', True, False), +}; +static Button FileBTN = BUTTONS( file_btn ); + +static ButtonItems edit_btn[] = { + BTNARGS( CBeOblB_rCmd, PROC_CLS, 'C', True, False), + BTNARGS( CBeOblB_rCmd, PROC_SET, 'S', True, False), + BTNARGS( CBeOblB_rCmd, PROC_REV, 'R', True, False), + BTNARGS( CBeOblB_rCmdp, PROC_CUT, 'U', True, False), + BTNARGS( CBeOblB_rCmdp, PROC_CPY, 'O', True, False), + BTNARGS( CBeOblB_rCmdp, PROC_PASTE,'P', True, False), + BTNARGS( CBeOblB_rCmd, PROC_ROLL, 'A', True, False), + BTNARGS( CBeOblB_rCmd, PROC_SYMV, 'V', True, False), + BTNARGS( CBeOblB_rCmd, PROC_SYMH, 'H', True, False), + BTNARGS( CBeOblB_rCan, NULL, 'N', True, False), +}; +static Button EditBTN = BUTTONS( edit_btn ); + +static ButtonItems char_btn[] = { + BTNARGS( MngPtnCB, NULL, 'A', True, False ), + BTNARGS( CpyPtnCB, NULL, 'C', True, False ), +}; +static Button CharBTN = BUTTONS( char_btn ); + +static ButtonItems info_btn[] = { + BTNARGS( XlfdCB, NULL, 'X', True, False ), + BTNARGS( CodeAreaCB, NULL, 'C', True, False ), +}; +static Button InfoBTN = BUTTONS( info_btn ); + +static ExclusiveItems draw_ex[] = { + EXARGS( PROC_POINT, "pencil", True, CBeRecB_obj, True ), + EXARGS( PROC_LINE, "line", True, CBeRecB_obj, False ), + EXARGS( PROC_RECT, "rectangle", True, CBeRecB_obj, False ), + EXARGS( PROC_CIRCLE, "circle", True, CBeRecB_obj, False ), + EXARGS( PROC_ERASE, "erase", True, CBeRecB_obj, False ), + EXARGS( PROC_SELECT, "select", True, CBeRecB_obj, False ), +}; +static Exclusive DrawEX = EXCLUSIVE( draw_ex ); + +static void +Unset() +{ + XtSetSensitive(EditBTN.w[0], False); + XtSetSensitive(EditBTN.w[1], False); + XtSetSensitive(EditBTN.w[2], False); + XtSetSensitive(EditBTN.w[3], False); + XtSetSensitive(EditBTN.w[4], False); + XtSetSensitive(EditBTN.w[5], False); + XtSetSensitive(EditBTN.w[6], False); + XtSetSensitive(EditBTN.w[7], False); + XtSetSensitive(EditBTN.w[8], False); + XtSetSensitive(EditBTN.w[9], False); +} + +void +SelectSet() +{ + XtSetSensitive(EditBTN.w[0], True); + XtSetSensitive(EditBTN.w[1], True); + XtSetSensitive(EditBTN.w[2], True); + XtSetSensitive(EditBTN.w[3], True); + XtSetSensitive(EditBTN.w[4], True); + XtSetSensitive(EditBTN.w[6], True); + XtSetSensitive(EditBTN.w[7], True); + XtSetSensitive(EditBTN.w[8], True); +} + +void +SelectUnset() +{ + XtSetSensitive(EditBTN.w[0], False); + XtSetSensitive(EditBTN.w[1], False); + XtSetSensitive(EditBTN.w[2], False); + XtSetSensitive(EditBTN.w[3], False); + XtSetSensitive(EditBTN.w[4], False); + XtSetSensitive(EditBTN.w[6], False); + XtSetSensitive(EditBTN.w[7], False); + XtSetSensitive(EditBTN.w[8], False); +} + +void +CopySet() +{ + XtSetSensitive(EditBTN.w[5], True); +} + +void +UndoSet() +{ + XtSetSensitive(EditBTN.w[9], True); +} + +void +UndoUnset() +{ + XtSetSensitive(EditBTN.w[9], False); +} + +/** + ** contents : create the UDC editor window + ** -------------------------------- + **/ + +void +PopupEditPtn(owner) +Widget owner; +{ + if (! editPtnW){ + editPtnW = CreateEditPtn(owner); + _create_editptn_after(); + } + XtPopup(editPtnW, XtGrabNone); +} + +static Widget +CreateEditPtn(owner) +Widget owner; +{ + int slimax; + int i; + Widget baseForm, pop, font_menu, edit_menu, char_menu, info_menu; + Widget listBase, listFrame, rc, editFrame, figure_w; + Widget imageFrame, imageForm, editPane, image; + extern Widget CreateFrame(); + extern Widget CreatePixButton(); + + Arg arg[1]; + + + SetItemLabel(&MenuBTN, 0, resource.l_font); + SetItemLabel(&MenuBTN, 1, resource.l_edit); + SetItemLabel(&MenuBTN, 2, resource.l_manage); + SetItemLabel(&MenuBTN, 3, resource.l_info); + baseForm = (Widget) + CreateMenuBarAndFooterMessageForm( owner, "dtudcfonted", + &MenuBTN, XtNumber(menu_btn), &pop, &FooterMessage ); + + editPopW = pop; + + AddDeleteProc(pop, CBeOblB_aEnd); + + font_menu = GetMenuWidget( &MenuBTN, 0 ); + edit_menu = GetMenuWidget( &MenuBTN, 1 ); + char_menu = GetMenuWidget( &MenuBTN, 2 ); + info_menu = GetMenuWidget( &MenuBTN, 3 ); + + SetItemLabel(&FileBTN, 0, resource.l_open_w); + SetItemLabel(&FileBTN, 1, resource.l_save); + SetItemLabel(&FileBTN, 3, resource.l_exit); + + SetItemLabel(&EditBTN, 0, resource.l_clear); + SetItemLabel(&EditBTN, 1, resource.l_set); + SetItemLabel(&EditBTN, 2, resource.l_reverse); + SetItemLabel(&EditBTN, 3, resource.l_cut); + SetItemLabel(&EditBTN, 4, resource.l_Copy); + SetItemLabel(&EditBTN, 5, resource.l_paste); + SetItemLabel(&EditBTN, 6, resource.l_roll); + SetItemLabel(&EditBTN, 7, resource.l_updown_roll); + SetItemLabel(&EditBTN, 8, resource.l_leftright_roll); + SetItemLabel(&EditBTN, 9, resource.l_undo); + + SetItemLabel(&CharBTN, 0, resource.l_manage_w); + SetItemLabel(&CharBTN, 1, resource.l_copy_w); + + SetItemLabel(&InfoBTN, 0, resource.l_xlfd); + SetItemLabel(&InfoBTN, 1, resource.l_codearea); + + CreateMenuButtons( font_menu, &FileBTN, XtNumber(file_btn)); + CreateMenuButtons( edit_menu, &EditBTN, XtNumber(edit_btn)); + Unset(); + CreateMenuButtons( char_menu, &CharBTN, XtNumber(char_btn)); + CreateMenuButtons( info_menu, &InfoBTN, XtNumber(info_btn)); + + /* create "Character list" */ + + listFrame = + CreateFrame( baseForm, "listFrame", XmSHADOW_IN, 2); + AddTopAttachForm(listFrame, resource.ed_wge_topoff); + AddLeftAttachForm(listFrame, resource.ed_wge_lftoff); + AddBottomAttachForm(listFrame, resource.ed_wge_btmoff); + + listBase = + CreateRowColumn( listFrame, "listFrame", L_VERTICAL, 4, 2, 2); + + for( i=0 ; i < edlist.nlist ; i++ ) { + wgeStaT_form[i] = CreateForm( listBase, "listform" ); + wgeStaT_list[i] = + CreateLabel( wgeStaT_form[i], "label", "0000" ); + wgeStaT_disp[i] = CreateDrawingArea( wgeStaT_form[i], "image", + edg.width, edg.height, EHStaT_disp, i ) ; + AddLeftAttachWidget( wgeStaT_disp[i], wgeStaT_list[i], 0 ) ; + XtAddEventHandler( wgeStaT_list[i], + ButtonPressMask|ButtonReleaseMask, + False, EHeStaT_list, (XtPointer) (intptr_t) i ); + XtAddEventHandler( wgeStaT_disp[i], + ButtonPressMask|ButtonReleaseMask, + False, EHeStaT_list, (XtPointer) (intptr_t) i ); + + if (i==0){ + XtVaGetValues(wgeStaT_disp[i], + XmNheight, &(edlist.elem_h), + XmNwidth, &(edlist.elem_w), NULL); + + edlist.back = resource.pane_background; + edlist.border = resource.pane_foreground; + + dn.elem_h = edlist.elem_h; + dn.elem_w = edlist.elem_w; + + /* + */ + edpane.pix_w = edpane.width / edg.width; + edpane.pix_h = edpane.height / edg.height; + if(edpane.pix_w > edpane.pix_h) + edpane.pix_w = edpane.pix_h; + else + edpane.pix_h = edpane.pix_w; + /* */ + edpane.pix_w = ( edpane.pix_w < 8 ) ? 8 : edpane.pix_w; + edpane.pix_h = ( edpane.pix_h < 8 ) ? 8 : edpane.pix_h; + /* + */ + edpane.width = edpane.pix_w * edg.width - 1; + edpane.height = edpane.pix_h * edg.height - 1; + + edlist.nlist = (edpane.height +2)/(int)(edlist.elem_h +8); + edlist.nlist = + (edlist.nlistbitmap_bit_order = MSBFirst; + xl.dispImage->byte_order = MSBFirst; + + /* + * initialize + */ + edpane.color = ON; + edpane.obj = PROC_POINT; + em.proc = PROC_POINT; + + if(efctPtnNum() > 0){ + slctloc = 0; + SetCodeString(edg.code); + } + else{ + slctloc = -1; + } + chgEdList( 0, slctloc, ON ); + +} + +void +UpdateMessage(str) +String str; +{ + static Boolean nomsg = False; + + if (! str || ! *str){ + if (nomsg){ + return; + } + else{ + nomsg = True; + } + } + else{ + nomsg = False; + } + SetFooterString(FooterMessage, str); +} diff --git a/cde/programs/dtudcfonted/pixmaps/Circle.pm b/cde/programs/dtudcfonted/pixmaps/Circle.pm new file mode 100755 index 00000000..06bc46f7 --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/Circle.pm @@ -0,0 +1,52 @@ +/* XPM */ +/* $XConsortium: Circle.pm /main/4 1996/07/23 11:49:20 drk $ */ +/********************************************************************* +* (c) Copyright 1993, 1994 Hewlett-Packard Company +* (c) Copyright 1993, 1994 International Business Machines Corp. +* (c) Copyright 1993, 1994 Sun Microsystems, Inc. +* (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of +* Novell, Inc. +**********************************************************************/ +static char * Circle [] = { +/* width height ncolors cpp [x_hot y_hot] */ +"36 36 2 1 -1 -1", +/* colors */ +" s background m black c #949494949494", +". s foreground m white c white", +/* pixels */ +" ", +" ", +" ", +" ", +" ", +" ....... ", +" ... ... ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" ... ... ", +" ....... ", +" ", +" ", +" ", +" "}; diff --git a/cde/programs/dtudcfonted/pixmaps/Eraser.pm b/cde/programs/dtudcfonted/pixmaps/Eraser.pm new file mode 100755 index 00000000..253df8fe --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/Eraser.pm @@ -0,0 +1,58 @@ +/* XPM */ +/* $XConsortium: Eraser.pm /main/4 1996/07/23 11:49:43 drk $ */ +/********************************************************************* +* (c) Copyright 1993, 1994 Hewlett-Packard Company +* (c) Copyright 1993, 1994 International Business Machines Corp. +* (c) Copyright 1993, 1994 Sun Microsystems, Inc. +* (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of +* Novell, Inc. +**********************************************************************/ +static char * Eraser [] = { +/* width height ncolors cpp [x_hot y_hot] */ +"36 36 8 1 0 0", +/* colors */ +" s iconColor6 m white c yellow", +". s iconColor2 m white c white", +"X s background m black c #949494949494", +"o s iconGray5 m black c #737373737373", +"O s iconGray1 m white c #dededededede", +"+ s iconGray3 m white c #adadadadadad", +"@ s iconColor3 m black c red", +"# s iconColor1 m black c black", +/* pixels */ +" . . XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"o . . XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +" o . . XXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"o o . . XXXXXXXXXXXXXXXXXXXXXXXXXXXX", +" o o . . XXXXXXXXXXXXXXXXXXXXXXXXXXX", +"o o o . . XXXXXXXXXXXXXXXXXXXXXXXXXX", +"Xo o o . . XXXXXXXXXXXXXXXXXXXXXXXXX", +"XXo o o . . XXXXXXXXXXXXXXXXXXXXXXXX", +"XXXo o o . . XXXXXXXXXXXXXXXXXXXXXXX", +"XXXXo o o . . XXXXXXXXXXXXXXXXXXXXXX", +"XXXXXo o o . . XXXXXXXXXXXXXXXXXXXXX", +"XXXXXXo o o . . XXXXXXXXXXXXXXXXXXXX", +"XXXXXXXo o o . . XXXXXXXXXXXXXXXXXXX", +"XXXXXXXXo o o ...OXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXo o o+...OXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXo oo++...OXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXo+oo++...OXXXXXXXXXXXXXXX", +"XXXXXXXXXXXX++oo++..ooXXXXXXXXXXXXXX", +"XXXXXXXXXXXXX++oo++o@.@XXXXXXXXXXXXX", +"XXXXXXXXXXXXXX++ooo@.@O@XXXXXXXXXXXX", +"XXXXXXXXXXXXXXX+oo@+@O@O@XXXXXXXXXXX", +"XXXXXXXXXXXXXXXXo@o@o@O@O@XXXXXXXXXX", +"XXXXXXXXXXXXXXXXXo@o@o@O@O@#########", +"XXXXXXXXXXXXXXXXXXo@o@o@O@##########", +"XXXXXXXXXXXXXXXXXXXo@o@o@###########", +"XXXXXXXXXXXXXXXXXXXXo@o@############", +"XXXXXXXXXXXXXXXXXXXXXo@#############", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}; diff --git a/cde/programs/dtudcfonted/pixmaps/Line.pm b/cde/programs/dtudcfonted/pixmaps/Line.pm new file mode 100755 index 00000000..aa8ae113 --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/Line.pm @@ -0,0 +1,52 @@ +/* XPM */ +/* $XConsortium: Line.pm /main/4 1996/07/23 11:50:13 drk $ */ +/********************************************************************* +* (c) Copyright 1993, 1994 Hewlett-Packard Company +* (c) Copyright 1993, 1994 International Business Machines Corp. +* (c) Copyright 1993, 1994 Sun Microsystems, Inc. +* (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of +* Novell, Inc. +**********************************************************************/ +static char * Line [] = { +/* width height ncolors cpp [x_hot y_hot] */ +"36 36 2 1 -1 -1", +/* colors */ +" s background m black c #949494949494", +". s foreground m white c white", +/* pixels */ +" ", +" ", +" ", +" ", +" ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" . ", +" ", +" ", +" ", +" ", +" "}; diff --git a/cde/programs/dtudcfonted/pixmaps/Pencil.pm b/cde/programs/dtudcfonted/pixmaps/Pencil.pm new file mode 100644 index 00000000..8a1c1c4d --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/Pencil.pm @@ -0,0 +1,58 @@ +/* XPM */ +/* $XConsortium: Pencil.pm /main/4 1996/07/23 11:50:33 drk $ */ +/********************************************************************* +* (c) Copyright 1993, 1994 Hewlett-Packard Company +* (c) Copyright 1993, 1994 International Business Machines Corp. +* (c) Copyright 1993, 1994 Sun Microsystems, Inc. +* (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of +* Novell, Inc. +**********************************************************************/ +static char * Pencil [] = { +/* width height ncolors cpp [x_hot y_hot] */ +"36 36 8 1 0 0", +/* colors */ +" s background m black c #949494949494", +". s iconColor6 m white c yellow", +"X s iconColor2 m white c white", +"o s iconGray5 m black c #737373737373", +"O s foreground m white c white", +"+ s iconGray3 m white c #adadadadadad", +"@ s iconGray1 m white c #dededededede", +"# s iconGray7 m black c #424242424242", +/* pixels */ +" ", +" ", +" .", +" .X", +" .X.", +" .X.X", +" .X.X.", +" .X.X.o", +" .X.X.o.", +" .X.X.o.o", +" OOOOO .X.X.o.o.", +" OOO .X.X.o.o.o", +" O .X.X.o.o.o ", +" O .X.X.o.o.o ", +" O .X.X.o.o.o ", +" O .X.X.o.o.o ", +" O .X.X.o.o.o ", +" O +@XX.o.o.o ", +" O +XX@o.o.o ", +" OO +XX@ooo.o ", +" OOO +X@ooo.o ", +" O +X@ooooo ", +" O +@ooooo ", +" O +#ooooo ", +" O ###oo ", +" O ##o ", +" OO ## ", +" O## ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/cde/programs/dtudcfonted/pixmaps/Rectangle.pm b/cde/programs/dtudcfonted/pixmaps/Rectangle.pm new file mode 100755 index 00000000..7d7df140 --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/Rectangle.pm @@ -0,0 +1,52 @@ +/* XPM */ +/* $XConsortium: Rectangle.pm /main/4 1996/07/23 11:50:54 drk $ */ +/********************************************************************* +* (c) Copyright 1993, 1994 Hewlett-Packard Company +* (c) Copyright 1993, 1994 International Business Machines Corp. +* (c) Copyright 1993, 1994 Sun Microsystems, Inc. +* (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of +* Novell, Inc. +**********************************************************************/ +static char * Rectangle [] = { +/* width height ncolors cpp [x_hot y_hot] */ +"36 36 2 1 -1 -1", +/* colors */ +" s background m black c #949494949494", +". s foreground m white c white", +/* pixels */ +" ", +" ", +" ", +" ", +" ", +" ", +" .............................. ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" . . ", +" .............................. ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/cde/programs/dtudcfonted/pixmaps/SelectArea.pm b/cde/programs/dtudcfonted/pixmaps/SelectArea.pm new file mode 100755 index 00000000..01e9a623 --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/SelectArea.pm @@ -0,0 +1,53 @@ +/* XPM */ +/* $XConsortium: SelectArea.pm /main/4 1996/07/23 11:51:18 drk $ */ +/********************************************************************* +* (c) Copyright 1993, 1994 Hewlett-Packard Company +* (c) Copyright 1993, 1994 International Business Machines Corp. +* (c) Copyright 1993, 1994 Sun Microsystems, Inc. +* (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of +* Novell, Inc. +**********************************************************************/ +static char * SelectArea [] = { +/* width height ncolors cpp [x_hot y_hot] */ +"36 36 3 1 -1 -1", +/* colors */ +" s background m black c #949494949494", +". s iconColor1 m black c black", +"X s iconColor2 m white c white", +/* pixels */ +" ", +" ", +" ", +" ", +" ", +" ", +" .... .. .. .. .. .... ", +" .... .. .. .. .. .... ", +" ..XXX XX XX XX XX X..X ", +" ..XXXX XX XX XX XX ..XX ", +" XX XX ", +" X X ", +" .. .. ", +" ..X ..X ", +" XX XX ", +" X X ", +" .. .. ", +" ..X ..X ", +" XX XX ", +" X X ", +" .. .. ", +" ..X ..X ", +" XX XX ", +" X X ", +" .. .. ", +" ..X ..X ", +" .... .. .. .. .. ....XX ", +" .... .. .. .. .. ....XX ", +" XXXX XX XX XX XX XXXXX ", +" XXXX XX XX XX XX XXXX ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/cde/programs/dtudcfonted/pixmaps/arrow.pm b/cde/programs/dtudcfonted/pixmaps/arrow.pm new file mode 100755 index 00000000..40f81d20 --- /dev/null +++ b/cde/programs/dtudcfonted/pixmaps/arrow.pm @@ -0,0 +1,21 @@ +/* XPM */ +/* $XConsortium: arrow.pm /main/4 1996/07/23 11:51:52 drk $ */ +static char * arrow_pm[] = { +"14 14 3 1", +" c #C2C2C2C2C2C2", +". c #727272727272", +"X c #E8E8E8E8E8E8", +" . ", +" .. ", +" ... ", +"......... . ", +"......... . ", +".. . ", +".. X", +".. X", +".. XX", +".XXXXXXX XX ", +" X XX ", +" X XX ", +" XXX ", +" XX "}; diff --git a/cde/programs/dtudcfonted/resource/Dtudcfonted b/cde/programs/dtudcfonted/resource/Dtudcfonted new file mode 100644 index 00000000..233e94c3 --- /dev/null +++ b/cde/programs/dtudcfonted/resource/Dtudcfonted @@ -0,0 +1,10 @@ +! (c) Copyright 1995 FUJITSU LIMITED +! This is source code modified by FUJITSU LIMITED under the Joint +! Development Agreement for the CDEnext PST. +! This is unpublished proprietary source code of FUJITSU LIMITED + +*Lptog: /usr/dt/lib/dtudcfonted/dtaddcpf +*LptogCmd: dtaddcpf + +*PaneForeground : black +*PaneBackground : white diff --git a/cde/programs/dtudcfonted/selectx.c b/cde/programs/dtudcfonted/selectx.c new file mode 100644 index 00000000..85906430 --- /dev/null +++ b/cde/programs/dtudcfonted/selectx.c @@ -0,0 +1,828 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* selectx.c 1.23 - Fujitsu source for CDEnext 96/10/30 13:13:45 */ +/* $XConsortium: selectx.c /main/7 1996/11/08 01:54:18 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * There is no public header file for this function (only an + * internal header XmStringI.h). + */ +extern XtPointer _XmStringUngenerate (XmString string, + XmStringTag tag, + XmTextType tag_type, + XmTextType output_type); + + +#include "xoakufont.h" +#include "selectxlfd.h" + +extern Resource resource ; + +/* + * parameters + */ + +FalFontData fullFontData; + +void PopupSelectXLFD() ; +static Widget CreateSelectXLFD() ; + +extern void xlfdPopupDialog() ; +extern int GetListsOfItems() ; + +extern void ReadCB(); + + +Widget xlfdDialog; +static Widget xlfdWform; + +#define CS0 "Codeset 0" +#define CS1 "Codeset 1" +#define CS2 "Codeset 2" +#define CS3 "Codeset 3" + +#define FAL_ERROR_STR resource.falerrmsg[((fal_utyerrno & 0xff) > 25) ? 0 : (fal_utyerrno & 0xff)] + +static Widget pull1, pull2, pull3, pull4, scrolllist; +static int xlf_count = 0; +static XmString *xlf=NULL; +static int udc_count = 0; +static Boolean udc_flag = False; +static int *udc=NULL; +static int udc_val; +static int sty_count = 0; +static Boolean sty_flag = False; +static char **sty=NULL; +static char *sty_val=NULL; +static int wls_count = 0; +static Boolean wls_flag = False; +static int *wls=NULL; +static int wls_val; +static int hls_count = 0; +static Boolean hls_flag = False; +static int *hls=NULL; +static int hls_val; +static Widget *button1=NULL; +static Widget *button2=NULL; +static Widget *button3=NULL; +static Widget *button4=NULL; + +/**************************************************************** + * callbacks * + ***************************************************************/ + +static char * +spc(str, ch, count) +char * str; +char ch; +int count; +{ + char *p; + p = str + strlen(str); + for(;count && (str < p);p--) { + if (*p == ch) + count --; + } + if (! count) + return(p+1); + else + return(NULL); +} + +static void OpenWindowCB() +{ + char *str, *p; + XmStringTable st; + + XtVaGetValues(scrolllist, XmNselectedItems, &st, NULL); + if( st == NULL ){ + fullFontData.xlfdname = NULL; + return ; + } + str = (char *) _XmStringUngenerate(st[0], NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + + p = spc(str, '-', 4); + p++; + + if (*p == 'p' || *p == 'P') { + fullFontData.xlfdname = (char *)-1; + return ; + } + + fullFontData.xlfdname = str; + if(udc_flag == True) + fullFontData.cd_set = udc_val; + else + fullFontData.cd_set = -1; +} + +/** + ** contents : "Cancel" button callback + ** ------------------------ + ** + ** + **/ + +/*ARGSUSED*/ +static void +OpenCancelCB( widget, clientData, callData ) +Widget widget; +caddr_t clientData; +caddr_t callData; +{ + extern void ForcePopdownDialog(); + if ( !editPtnW ){ + exit( 0 ); + } + ForcePopdownDialog(xlfdDialog); +} + + +/* +* create selection window view +*/ +void +PopupSelectXLFD( top ) +Widget top ; +{ + + if( xlfdDialog == NULL ){ + if( (xlfdDialog = CreateSelectXLFD( top )) == NULL ){ + exit( -1 ) ; + } + } + /* pop up select window */ + xlfdPopupDialog( xlfdDialog ); +} + + +static void +create_xlfd() +{ + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + int i; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + xlf_count = 0; + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + return; + } + if(fontlist->num == 0) { + FalFreeFontList(fontlist); + return; + } + if (xlf) { + for (i=0; i < xlf_count; i++) { + XmStringFree(xlf[i]); + } + XtFree((char *)xlf); + } + xlf = (XmString *)XtMalloc(sizeof(XmString) * fontlist->num); + for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) { + xlf[xlf_count++] = XmStringCreateLocalized(f->xlfdname); + } + FalFreeFontList(fontlist); +} + +static void +udc_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + udc_flag = False; + } else if(strcmp(moji, CS0) == 0) { + udc_val = FAL_FONT_CS0; + udc_flag = True; + } else if(strcmp(moji, CS1) == 0) { + udc_val = FAL_FONT_CS1; + udc_flag = True; + } else if(strcmp(moji, CS2) == 0) { + udc_val = FAL_FONT_CS2; + udc_flag = True; + } else if(strcmp(moji, CS3) == 0) { + udc_val = FAL_FONT_CS3; + udc_flag = True; + } else { + udc_flag = False; + } + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +sty_call(w) +Widget w; +{ + XmString label; + char *moji; + if (sty_val) { + XtFree(sty_val); + sty_val = NULL; + } + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + sty_flag = False; + } + else { + sty_val = XtMalloc(sizeof(char) * (strlen(moji) + 1)); + strcpy(sty_val, moji); + sty_flag = True; + } + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +wls_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + wls_flag = False; + } + else { + wls_val = atoi(moji); + wls_flag = True; + } + XmStringFree(label); + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +hls_call(w) +Widget w; +{ + XmString label; + char *moji; + XtVaGetValues(w, XmNlabelString, &label, NULL); + moji = (char *) _XmStringUngenerate(label, NULL, XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT); + if(strncmp(moji, "*", 1) == 0) { + hls_flag = False; + } + else { + hls_val = atoi(moji); + hls_flag = True; + } + XmStringFree(label); + XtFree(moji); + create_xlfd(); + XtVaSetValues(scrolllist, XmNitems, xlf, XmNitemCount, xlf_count, NULL); +} + +static void +button_set1() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(udc[j] == f->cd_set) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button1[j], False); + else + XtSetSensitive(button1[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set2() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(strcmp(sty[j], f->style.name) == 0) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button2[j], False); + else + XtSetSensitive(button2[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set3() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (hls_flag == True) { + key.size.h = hls_val; + mask |= FAL_FONT_MASK_SIZE_H; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(wls[j] == f->size.w) { + found = True; + break; + } + } + if(found == False) + XtSetSensitive(button3[j], False); + else + XtSetSensitive(button3[j], True); + } + FalFreeFontList(fontlist); +} + +static void +button_set4() +{ + int i, j; + int mask = FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UNDEFINED; + FalFontData key; + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + + if (udc_flag == True) { + key.cd_set = udc_val; + mask |= FAL_FONT_MASK_CODE_SET; + } + if (sty_flag == True) { + key.style.name = sty_val; + mask |= FAL_FONT_MASK_STYLE_NAME; + } + if (wls_flag == True) { + key.size.w = wls_val; + mask |= FAL_FONT_MASK_SIZE_W; + } + if (FalGetFontList(&key, mask, &fontlist) == FAL_ERROR) { + for (j=0; jnum == 0) { + for (j=0; jlist, found=False; i < fontlist->num; i++, f++) { + if(hls[j] == f->size.h) { + found = True; + break; + } + } + if (found == False) + XtSetSensitive(button4[j], False); + else + XtSetSensitive(button4[j], True); + } + FalFreeFontList(fontlist); +} + +void +data_sort(data, count) +int *data; +int count; +{ + int *p1, *p2, tmp, i; + + for (; count; count--) { + for (i=1, p1=data, p2=data+1; i < count; i++, p1++, p2++) { + if( *p1 > *p2) { + tmp = *p2; + *p2 = *p1; + *p1 = tmp; + } + } + } +} + + +static void +font_init() +{ + FalFontDataList *fontlist; + FalFontData *f; + Boolean found; + int i, j; + char tmp[16]; + char err[128]; + Widget button; + extern void Error_message(); + + xlf_count = udc_count = sty_count = wls_count = hls_count = 0; + if (FalGetFontList(NULL, FAL_FONT_MASK_DEFINED | + FAL_FONT_MASK_UNDEFINED, &fontlist) == FAL_ERROR) { + strcpy(err, FAL_ERROR_STR); + Error_message((Widget)NULL, err); + return; + } + if(fontlist->num == 0) { + FalFreeFontList(fontlist); + strcpy(err, resource.mn_no_font); + Error_message((Widget)NULL, err); + return; + } + udc = (int *)XtMalloc(sizeof(int) * fontlist->num); + sty = (char **)XtMalloc(sizeof(char *) * fontlist->num); + wls = (int *)XtMalloc(sizeof(int) * fontlist->num); + hls = (int *)XtMalloc(sizeof(int) * fontlist->num); + for (i=0, f=fontlist->list; i < fontlist->num; i++, f++) { + for (j=0,found=False; jcd_set) { + found=True; + break; + } + } + if (found == False) { + udc[udc_count++] = f->cd_set; + } + for (j=0,found=False; jstyle.name) == 0) { + found=True; + break; + } + } + if (found == False) { + sty[sty_count] = XtMalloc(sizeof(char) * (strlen(f->style.name) + 1)); + strcpy(sty[sty_count++], f->style.name); + } + if (f->size.w != -1) { + for (j=0,found=False; jsize.w) { + found=True; + break; + } + } + if (found == False) { + wls[wls_count++] = f->size.w; + } + } + for (j=0,found=False; jsize.h) { + found=True; + break; + } + } + if (found == False) { + hls[hls_count++] = f->size.h; + } + } + FalFreeFontList(fontlist); + + data_sort(udc, udc_count); + data_sort(wls, wls_count); + data_sort(hls, hls_count); + + button1 = (Widget *) XtMalloc(sizeof(Widget) * udc_count); + button2 = (Widget *) XtMalloc(sizeof(Widget) * sty_count); + button3 = (Widget *) XtMalloc(sizeof(Widget) * wls_count); + button4 = (Widget *) XtMalloc(sizeof(Widget) * hls_count); + + button = XmCreatePushButton(pull1, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)udc_call, NULL); + for (i=0; i < udc_count; i++) { + if(udc[i] == FAL_FONT_CS0) + sprintf(tmp, CS0); + else if(udc[i] == FAL_FONT_CS1) + sprintf(tmp, CS1); + else if(udc[i] == FAL_FONT_CS2) + sprintf(tmp, CS2); + else if(udc[i] == FAL_FONT_CS3) + sprintf(tmp, CS3); + else + sprintf(tmp, "Codeset %x?", udc[i]); + button1[i] = XmCreatePushButton(pull1, tmp, NULL, 0); + XtManageChild(button1[i]); + XtAddCallback(button1[i], XmNactivateCallback, + (XtCallbackProc)udc_call, NULL); + } + + button = XmCreatePushButton(pull2, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)sty_call, NULL); + for (i=0; i < sty_count; i++) { + button2[i] = XmCreatePushButton(pull2, sty[i], NULL, 0); + XtManageChild(button2[i]); + XtAddCallback(button2[i], XmNactivateCallback, + (XtCallbackProc)sty_call, NULL); + } + + button = XmCreatePushButton(pull3, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)wls_call, NULL); + for (i=0; i < wls_count; i++) { + sprintf(tmp, "%d", wls[i]); + button3[i] = XmCreatePushButton(pull3, tmp, NULL, 0); + XtManageChild(button3[i]); + XtAddCallback(button3[i], XmNactivateCallback, + (XtCallbackProc)wls_call, NULL); + } + + button = XmCreatePushButton(pull4, "*", NULL, 0); + XtManageChild(button); + XtAddCallback(button, XmNactivateCallback, + (XtCallbackProc)hls_call, NULL); + for (i=0; i < hls_count; i++) { + sprintf(tmp, "%d", hls[i]); + button4[i] = XmCreatePushButton(pull4, tmp, NULL, 0); + XtManageChild(button4[i]); + XtAddCallback(button4[i], XmNactivateCallback, + (XtCallbackProc)hls_call, NULL); + } +} + + +static Widget +CreateSelectXLFD( top ) +Widget top ; +{ + + int n; + Arg args[16]; + XmString xms, xms1 ; + Widget editW ; + Widget frame, row1, label1, row2, cas1, cas2, cas3, cas4; + XmString str; + udc_flag = sty_flag = wls_flag = hls_flag = False; + + /* + * create base window + */ + n = 0 ; + XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ; + XtSetArg( args[n], XmNnoResize, True ) ; n++ ; + XtSetArg( args[n], XmNminimizeButtons, True ) ; n++ ; + xms = XmStringCreateLocalized( resource.exec_label ) ; + XtSetArg( args[n], XmNokLabelString, xms ) ; n++ ; + xms1 = XmStringCreateLocalized( resource.quit_label) ; + XtSetArg( args[n], XmNhelpLabelString, xms1 ) ; n++ ; + XtSetArg( args[n], XmNtitle, resource.l_open_title ) ; n++ ; + editW = XmCreateTemplateDialog( top, "open_dialog", args, n ); + + XmStringFree( xms ) ; + XmStringFree( xms1 ) ; + + n = 0; + pull1 = XmCreatePulldownMenu(toplevel, "pull", args, n); + pull2 = XmCreatePulldownMenu(toplevel, "pull", args, n); + pull3 = XmCreatePulldownMenu(toplevel, "pull", args, n); + pull4 = XmCreatePulldownMenu(toplevel, "pull", args, n); + + n = 0 ; + xlfdWform = XmCreateRowColumn( editW, "BaseForm", args, n ); + XtManageChild( xlfdWform ); + + n = 0; + frame = XmCreateFrame( xlfdWform, "frame", args, n); + XtManageChild( frame ); + + n = 0 ; + row1 = XmCreateRowColumn( frame, "row", args, n ); + XtManageChild( row1 ); + + n = 0; + str = XmStringCreateLocalized(resource.l_selectitem) ; + XtSetArg(args[n], XmNlabelString, str); n++; + label1 = XmCreateLabel( row1, "SelectItems", args, n); + XtManageChild( label1 ); + XmStringFree(str); + + n = 0 ; + row2 = XmCreateRowColumn( row1, "row", args, n ); + XtManageChild( row2 ); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_codeset) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull1); n++; + cas1 = XmCreateOptionMenu( row2, "CodeSet", args, n ); + XtManageChild( cas1 ); + XtAddCallback(XmOptionButtonGadget(cas1), XmNcascadingCallback, + (XtCallbackProc)button_set1, NULL); + XmStringFree(str); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_style) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull2); n++; + cas2 = XmCreateOptionMenu( row2, "Style", args, n ); + XtAddCallback(XmOptionButtonGadget(cas2), XmNcascadingCallback, + (XtCallbackProc)button_set2, NULL); + XtManageChild( cas2 ); + XmStringFree(str); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_width) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull3); n++; + cas3 = XmCreateOptionMenu( row2, "Width", args, n ); + XtManageChild( cas3 ); + XtAddCallback(XmOptionButtonGadget(cas3), XmNcascadingCallback, + (XtCallbackProc)button_set3, NULL); + XmStringFree(str); + + n = 0 ; + str = XmStringCreateLocalized(resource.l_height) ; + XtSetArg(args[n], XmNlabelString, str); n++; + XtSetArg(args[n], XmNsubMenuId, pull4); n++; + cas4 = XmCreateOptionMenu( row2, "Height", args, n ); + XtManageChild( cas4 ); + XtAddCallback(XmOptionButtonGadget(cas4), XmNcascadingCallback, + (XtCallbackProc)button_set4, NULL); + XmStringFree(str); + + font_init(); + create_xlfd(); + + n = 0; + XtSetArg(args[n], XmNvisibleItemCount, 10) ; n++ ; + XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT) ; n++ ; + XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC) ; n++ ; + XtSetArg(args[n], XmNselectionPolicy, XmSINGLE_SELECT) ; n++ ; + XtSetArg(args[n], XmNitems, xlf) ; n++ ; + XtSetArg(args[n], XmNitemCount, xlf_count) ; n++ ; + scrolllist = XmCreateScrolledList(xlfdWform, "scrolllist", args, n); + XtManageChild(scrolllist); + + /* + * Error_Messege + */ + + XtAddCallback(editW, XmNokCallback, (XtCallbackProc)OpenWindowCB, NULL); + XtAddCallback(editW, XmNokCallback, (XtCallbackProc)ReadCB, NULL); + XtAddCallback(editW, XmNhelpCallback, + (XtCallbackProc)OpenCancelCB, NULL); + + return( editW ) ; +} diff --git a/cde/programs/dtudcfonted/selectxlfd.h b/cde/programs/dtudcfonted/selectxlfd.h new file mode 100644 index 00000000..585599f7 --- /dev/null +++ b/cde/programs/dtudcfonted/selectxlfd.h @@ -0,0 +1,64 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* selectxlfd.h 1.1 - Fujitsu source for CDEnext 96/01/06 16:57:23 */ +/* $XConsortium: selectxlfd.h /main/3 1996/04/08 16:02:27 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#define BUTTONITEMS 4 +#define PUSHBUTTONS 2 +#define COPYLABELS 2 + +#define CX 12 +#define CY -4 + +#define XLFD_COLUMNS 38 +#define KEY_COLUMNS 15 + +#define PIXELSIZE 7 + +/* + * put data from resource database + */ +typedef struct _Rsrc { + char * xlfd_label ; + char * copy_xlfd_label ; + char * code_label ; + char * style_label ; + char * size_label ; + char * exec_label ; + char * quit_label ; + char * ok_label ; + char * cancel_label ; + char * copy_orgin ; + char * copy_target ; + char * copy_label ; + char * overlay_label ; +} Rsrc ; +/***************< end of selectxlfd.h >***************/ diff --git a/cde/programs/dtudcfonted/ufont.c b/cde/programs/dtudcfonted/ufont.c new file mode 100644 index 00000000..62be2192 --- /dev/null +++ b/cde/programs/dtudcfonted/ufont.c @@ -0,0 +1,2635 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* ufont.c 1.45 - Fujitsu source for CDEnext 96/12/03 18:34:11 */ +/* $XConsortium: ufont.c /main/14 1996/12/17 19:30:16 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#define substance_source + +#include +#include + +#include + +#include "xoakufont.h" +#include "util.h" + +#ifndef NO_MESSAGE_CAT +#ifdef __ultrix +#define _CLIENT_CAT_NAME "dtudcfonted.cat" +#else /* __ultrix */ +#define _CLIENT_CAT_NAME "dtudcfonted" +#endif /* __ultrix */ +#ifdef _NO_PROTO +extern char *_DtGetMessage(); +#else /* _NO_PROTO */ +extern char *_DtGetMessage( + char *filename, + int set, + int n, + char *s ); +#endif /* _NO_PROTO */ +#define GETMESSAGE(set, number, string) GetMessage(set, number, string) +static char * +GetMessage(set, number, string) +int set, number; +char *string; +{ + char *tmp, *ret; + tmp = _DtGetMessage(_CLIENT_CAT_NAME, set, number, string); + ret = malloc(strlen(tmp) + 1); + strcpy(ret, tmp); + return (ret); +} +#else /* NO_MESSAGE_CAT */ +#define GETMESSAGE(set, number, string)\ + string +#endif /* NO_MESSAGE_CAT */ + +/**************************************************************** + * Widgets * + ***************************************************************/ +/* Widget toplevel; */ +static Widget dnPopW; +Widget wgeScro, editPopW; + +static int select_x, select_y, select_w, select_h; +static int r1_x, r1_y, r2_x, r2_y, cut_w, cut_h; + +extern Widget xlfdDialog, cpyDialog ; + +extern FalFontID font_id; + +Pixmap arrow_pix=0; + +/* + * + */ +static XtAppContext app; /* application context */ +static int edpane_size=0; +void CB_set_wait_msg(); +void set_wait_msg(); + +static void OtherFontSelect(); +void drawDelCode(); +void drawDelPtn(); +static void xeg_init(); + + +static void dstrypaneEditPtn(); +void chgEdCode(); +void chgEdList(); +static void chgEdPtn(); +static void DrawRectEdPn(); +static void DrawBorderEdPn(); +static void DrawPointEdPn(); +static void DrawDpPn(); +static void DrawPointDpPn(); +static void musPoint(); +static void musLine(); +static void musCircle(); +static void musRect(); +static void musRegionProc(); +static void musPasteProc(); +static void rubLine(); +static void rubBand(); +static void rubCircle(); +static void resetEditMode(); +static void copyPatterns(); +extern String MngCodeTfValue(); +extern String CpySrcCodeTfValue(); +extern String CpyDestCodeTfValue(); +char *get_cmd_path() ; +extern FalFontData fullFontData; +extern FalFontData copyFontData; + +extern void PopupSelectXLFD(); +extern void UpdateMessage(); +extern void DispMngErrorMessage(); +extern void DispCpyErrorMessage(); +static int setRealDelArea(); + +/**************************************************************** + * parameters * + ***************************************************************/ +static Arg arg[30]; +static int n; + +Resource resource; + +/**************************************************************** + * callback routines * + ***************************************************************/ + +static void CancelCB(); + +static void +ExitCB() +{ + exit(0); +} + +int +efctPtnNum() +{ + int no; + int sq; + int cnt; + + for ( cnt = 0, sq = edlist.sqstart; + sq < (edlist.sqstart + edlist.nptn); sq++) { + no = ptnSqToNo(sq); + if (( no >= 0) && (codeCheck( noToCode( no)) == 0)) + cnt++; + } + return( cnt); +} + +void +Error_message(widget, message) +Widget widget; +char *message; +{ + static NoticeButton is_lock[] = { + NBTNARGS( ExitCB, NULL, 'E', True, False ), + NBTNARGS( CancelCB, NULL, 'C', True, True ) + }; + static NButton LockBTN = NBUTTONS( is_lock ); + + SetItemLabel(&LockBTN, 0, resource.l_exit); + SetItemLabel(&LockBTN, 1, resource.l_cancel); + PopupNotice( (widget), message, + D_ERROR, + &LockBTN, + True, + resource.l_question_title); +} + +void +Error_message2(widget, message) +Widget widget; +char *message; +{ + static NoticeButton is_lock[] = { + NBTNARGS( CancelCB, NULL, 'C', True, True ) + }; + static NButton LockBTN = NBUTTONS( is_lock ); + + if (widget == NULL) + widget = toplevel; + + SetItemLabel(&LockBTN, 0, resource.l_ok); + PopupNotice( (widget), message, + D_ERROR, + &LockBTN, + True, + resource.l_question_title); +} + +/* + * contents : read a character pattern from SNF file + */ +/*ARGSUSED*/ +static void +CBmOblB_edit( widget, clientData, callData ) +Widget widget; +caddr_t clientData; +caddr_t callData; +{ + int ptn_n; + int ptn_w; + int ptn_h; + int code; + int i; + int ret; + char err[128]; + extern int begin_code; + + extern int ptnGetInfo(); + extern void PopupEditPtn(); + + /* open font file and get informations of character to be edited */ + + ret = readSNF( &(edg.fdata), &(edg.width), &(edg.height), err); + + if( ret == -1 ) { + Error_message(widget, err); + return; + } + dn.ptn_w = (Dimension) edg.width; + dn.ptn_h = (Dimension) edg.height; + + + if( xlfdDialog != NULL ) + PopdownDialog(xlfdDialog); + + /* */ + ptnGetInfo( &ptn_n, &ptn_w, &ptn_h ); + for( i=0 ; i code){ + edlist.sqstart = i+1; + } else { + edlist.nptn++; + } + } + if( efctPtnNum() > 0) { + for ( i=edlist.sqstart; i<(edlist.sqstart+edlist.nptn); i++){ + if ( codeCheck( noToCode( ptnSqToNo(i))) == 0) + break; + } + edg.ncode = ptnSqToNo( i ); + edg.code = noToCode( edg.ncode ); + ptnGet( edg.code, edg.ptn ); + } + PopupEditPtn(toplevel); +} + + + +void CBeOblB_aAdd(); + +static Boolean do_read = False; +static Boolean do_end = False; + +static void CancelCB() { } + +static void ContReadCB(w) +Widget w; +{ + FalCloseFont(font_id); + editPtnW = NULL; + OtherFontSelect(); + PopupSelectXLFD(toplevel); +} + +static void SaveReadCB() +{ + CBeOblB_aAdd(); + do_read = True; + PopupSelectXLFD(toplevel); +} + + +static void ContEndCB() +{ + FalCloseFont(font_id); + exit(0); +} + +static void SaveEndCB() +{ + CBeOblB_aAdd(); + do_end = True; +} + + +/* + * contents : quit editting + */ + + +/*ARGSUSED*/ +static int +QuitEditPtn( widget, clientData, callData ) +Widget widget; +caddr_t clientData; +caddr_t callData; +{ + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + + if( edg.code != 0 ){ + ptnAdd( edg.code, edg.ptn ); + } + if( edg.flag == ON ){ + return(0); + } + return(1); +} + + + +void +OpenCB(w, client_data, call_data) +Widget w; +XtPointer client_data; +XtPointer call_data; +{ + static NoticeButton is_save_read_btn1[] = { + NBTNARGS( SaveReadCB, NULL, 'S', True, False ), + NBTNARGS( ContReadCB, NULL, 'O', True, False ), + NBTNARGS( CancelCB, NULL, 'C', True, True ), + }; + static NoticeButton is_save_read_btn2[] = { + NBTNARGS( ContReadCB, NULL, 'O', True, False ), + NBTNARGS( CancelCB, NULL, 'C', True, True ), + }; + static NButton SaveReadBTN1 = NBUTTONS( is_save_read_btn1 ); + static NButton SaveReadBTN2 = NBUTTONS( is_save_read_btn2 ); + + if (QuitEditPtn((Widget)NULL, (caddr_t)NULL, (caddr_t)NULL)){ + FalCloseFont(font_id); + editPtnW = NULL; + OtherFontSelect(); + PopupSelectXLFD(toplevel); + } + else{ + if (! fullFontData.prm) { + SetItemLabel(&SaveReadBTN1, 0, resource.l_do_save_exit); + SetItemLabel(&SaveReadBTN1, 1, resource.l_dont_save_exit); + SetItemLabel(&SaveReadBTN1, 2, resource.l_cancel); + PopupNotice( (w), resource.mn_saved_open , + D_QUESTION, + &SaveReadBTN1, + True, + resource.l_question_title); + } else { + SetItemLabel(&SaveReadBTN2, 0, resource.l_dont_save_exit); + SetItemLabel(&SaveReadBTN2, 1, resource.l_cancel); + PopupNotice( (w), resource.mn_saved_open , + D_QUESTION, + &SaveReadBTN2, + True, + resource.l_question_title); + } + } +} + + +void +ReadCB(w, client_data, call_data) +Widget w; +XtPointer client_data; +XtPointer call_data; +{ + if (fullFontData.xlfdname == NULL) { + return; + } + if (fullFontData.xlfdname == (char *) -1) { + Error_message(w, resource.mn_prop_font); + return; + } + CBmOblB_edit( w, client_data, call_data ); +} + +/**************************************************************** + * callback routines and event handler * + ***************************************************************/ + +/* + * contents : write character patterns to SNF file +*/ + +static Boolean +WPwriteSNF( restart ) +int restart; +{ + int rc, err; + char str[MG_MAXSIZE]; + + switch( rc = writeSNF( restart, &err ) ) { + case -1: + if (dnPopW) + XtSetSensitive( dnPopW, TRUE ); + switch( err ) { + case 001: + sprintf(str, "%s(permission denied)", resource.me_write_snf); + break; + case 002: + sprintf(str, "%s(disk full)", resource.me_write_snf); + break; + case 101: + sprintf(str, "%s(pipe error)", resource.me_write_snf); + break; + case 102: + sprintf(str, "%s(fork error)", resource.me_write_snf); + break; + case 103: + sprintf(str, "%s(execv error)", resource.me_write_snf); + break; + case 104: + sprintf(str, "%s(data error)", resource.me_write_snf); + break; + default: + sprintf(str, "%s", resource.me_write_snf); + } + SetString( wgeStaT, str ); + return( TRUE ); + case 0: + edg.flag = 0; + UpdateMessage( resource.mg_register ); + sleep(1); + UpdateMessage(""); + + if (do_read){ + do_read = False; + ContReadCB((Widget)NULL); + } + if (do_end){ + do_read = False; + ContEndCB(); + } + return(TRUE); + default: + if( rc == 1101 ) + sprintf( str, "%s", resource.me_wait ); + else + sprintf( str, "%s(%3d%%)", resource.mg_write_snf , rc-1000 ); + + SetString( wgeStaT, str ); + XtAppAddWorkProc( app, (XtWorkProc)WPwriteSNF, (XtPointer)ON ); + if( rc == 1101 ){ + XSync( xl.display,0 ); + } + return( TRUE ); + } +} + + + +/* + * contents : write character patterns to SNF file + */ + +void +CBeOblB_aAdd() +{ + char str[MG_MAXSIZE]; + + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + SetString( wgeStaT, resource.mg_write_snf ); + + if( edg.code != 0 ) + ptnAdd( edg.code, edg.ptn ); + + if( edg.flag == ON ) { + sprintf( str, "%s", resource.mg_write_snf ); + if (dnPopW) + XtSetSensitive( dnPopW, FALSE ); + + XtAppAddWorkProc( app, (XtWorkProc)WPwriteSNF, (XtPointer)OFF ); + return; + } + else{ + SetString( wgeStaT, "" ); + } +} + + + +/* + * contents : destroy the editor window + */ + +static void +OtherFontSelect() +{ + dstrypaneEditPtn(); + xeg_init(); +} + + + +/* + * contents : close dtudcfonted + */ + +/*ARGSUSED*/ +void +CBeOblB_aEnd( widget, clientData, callData ) +Widget widget; +caddr_t clientData; +caddr_t callData; +{ + static NoticeButton is_save_exit_btn[] = { + NBTNARGS( SaveEndCB, NULL, 'S', True, False ), + NBTNARGS( ContEndCB, NULL, 'E', True, False ), + NBTNARGS( CancelCB, NULL, 'C', True, True ), + }; + static NButton SaveEndBTN = NBUTTONS( is_save_exit_btn ); + + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + + if( edg.code != 0 ) + ptnAdd( edg.code, edg.ptn ); + if( edg.flag == ON ) { + + SetItemLabel(&SaveEndBTN, 0, resource.l_do_save); + SetItemLabel(&SaveEndBTN, 1, resource.l_dont_save); + SetItemLabel(&SaveEndBTN, 2, resource.l_cancel); + PopupNotice( widget, resource.mn_saved_exit, D_QUESTION, + &SaveEndBTN, True, resource.l_question_title); + return; + } else { + FalCloseFont(font_id); + } + + exit(0); +} + + + +/*ARGSUSED*/ +void +CBeOblB_rCmd( widget, proc, callData ) +Widget widget; +int proc; +caddr_t callData; +{ + extern void SelectUnset(); + extern void UndoSet(); + if (!select_x && !select_y && !select_w && !select_h) + return; + em.rsv_f = ON; + bitPtnCopy( em.rsv_ptn, edg.ptn ); + rubBand( r1_x, r1_y, r2_x, r2_y ); + switch( proc ) { + case PROC_CLS: + bitDrawCls (edg.ptn, select_x, select_y, select_w, select_h ); + break; + case PROC_SET: + bitDrawSet (edg.ptn, select_x, select_y, select_w, select_h ); + break; + case PROC_REV: + bitDrawRev (edg.ptn, select_x, select_y, select_w, select_h ); + break; + case PROC_ROLL: + bitDrawRoll(edg.ptn, select_x, select_y, select_w, select_h); + break; + case PROC_SYMV: + bitDrawSymV(edg.ptn, select_x, select_y, select_w, select_h ); + break; + case PROC_SYMH: + bitDrawSymH(edg.ptn, select_x, select_y, select_w, select_h ); + break; + } + edg.flag = ON; + DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 ); + DrawDpPn(); + select_x = select_y = select_w = select_h = 0; + SelectUnset(); + UndoSet(); +} + +/*ARGSUSED*/ +void +CBeOblB_rCmdp( widget, proc, callData ) +Widget widget; +int proc; +caddr_t callData; +{ + extern Widget wgeBulB_edit; + extern void CopySet(); + extern void UndoSet(); + extern void SelectUnset(); + + switch( proc ) { + case PROC_CPY: + if (!select_x && !select_y && !select_w && !select_h) + return; + rubBand( r1_x, r1_y, r2_x, r2_y ); + bitDrawCpy(edg.ptn, select_x, select_y, select_w, select_h, False); + cut_w = select_w; + cut_h = select_h; + select_x = select_y = select_w = select_h = 0; + CopySet(); + SelectUnset(); + break; + case PROC_CUT: + if (!select_x && !select_y && !select_w && !select_h) + return; + em.rsv_f = ON; + rubBand( r1_x, r1_y, r2_x, r2_y ); + bitPtnCopy( em.rsv_ptn, edg.ptn ); + bitDrawCpy(edg.ptn, select_x, select_y, select_w, select_h, True); + cut_w = select_w; + cut_h = select_h; + edg.flag = ON; + DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 ); + DrawDpPn(); + select_x = select_y = select_w = select_h = 0; + CopySet(); + UndoSet(); + SelectUnset(); + break; + case PROC_PASTE: + XtAddEventHandler(wgeBulB_edit, + ButtonReleaseMask|PointerMotionMask, + False, musPasteProc, NULL ); + } +} + + + + +/* + * contents : cancel all editting + */ + +/*ARGSUSED*/ +void +CBeOblB_rCan( widget, clientData, callData ) +Widget widget; +caddr_t clientData; +caddr_t callData; +{ + extern void UndoUnset(); + + resetEditMode( RES_MSG | RES_PROC | RES_SLCT ); + + if( em.rsv_f == ON ) { + bitPtnCopy( edg.ptn, em.rsv_ptn ); + em.rsv_f = OFF; + + DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 ); + DrawDpPn(); + UndoUnset(); + } +} + + + + +/* + * + * contents : get a sequential number of the editor + */ +int +RelToAbsSq( from, cnt) +int from; +int cnt; +{ + int i; + int no; + + if ( cnt >= 0) { + for ( i = -1; from < (edlist.sqstart + edlist.nptn) ; from++) { + no = ptnSqToNo(from); + if (( no >= 0) && ( noToCode( no) >= 0) ) { + i++; + if ( i >= cnt) + return( from); + } + } + } else { + cnt *= -1; + for ( i = -1; from >= edlist.sqstart; from--) { + no = ptnSqToNo(from); + if (( no >= 0) && ( noToCode( no) >= 0) ) { + i++; + if ( i >= cnt) + return(from); + } + } + } + return( -1); +} + +/* + * contents : get a relative number of the system area + */ +int +AbsSqToRel( from, to) +int from; +int to; +{ + int sq; + int cnt; + int sign = 1; + int no; + + if ( from > to) { + sq = from; + from = to; + to = sq; + sign = -1; + } + + for ( cnt = -1, sq = from; sq <= to; sq++) { + no = ptnSqToNo(sq); + if (( no >= 0) && (codeCheck( noToCode( no)) == 0)) + cnt++; + } + + if ( cnt < 0) + cnt = 0; + + cnt *= sign; + return( cnt); +} + + + + +/* + * contents : be the character list selected + */ + +/*ARGSUSED*/ +void +EHeStaT_list( widget, select, e ) +Widget widget; +int select; +XEvent *e; /* X Event */ +{ + int sq, no; + int code; + + resetEditMode( RES_MSG|RES_PROC|RES_SLCT|RES_RSV ); + + if( (e->xbutton.button != 1) || (e->type != ButtonRelease) || + (e->xbutton.x < 0) || ((int)edlist.elem_w < e->xbutton.x) || + (e->xbutton.y < 0) || ((int)edlist.elem_h < e->xbutton.y) + ) + return; + + if( edlist.slctloc == select ) + return; + + /* */ + sq = RelToAbsSq( edlist.sqstart + edlist.statloc, select); + + if( (no = ptnSqToNo(sq)) == -1 ) + return; + + code = noToCode( no ); + if( codeCheck( code ) == -1 ) + return; + + if( ptnSense( code) == 0 ) + return ; + + chgEdList( edlist.statloc, select, OFF ); + if( ptnSense(edg.code) == 1 ) + ptnAdd(edg.code, edg.ptn ); + chgEdPtn( code ); +} + + + + +/* + * contents : update the character list + */ + +/*ARGSUSED*/ +void +CBeScro( widget, clientData, callData ) +Widget widget; +caddr_t clientData; +caddr_t callData; +{ + int newl; + int new_statloc; + int new_slct; + + n = 0; + XtSetArg( arg[n], XmNvalue, (XtArgVal)&newl ); n++; + XtGetValues( wgeScro , arg, n ); + + if (( new_statloc = RelToAbsSq( edlist.sqstart, newl)) < 0) { + new_statloc = 0; + } else { + new_statloc -= edlist.sqstart; + } + /* + */ + new_slct = edlist.slctloc + - AbsSqToRel( edlist.sqstart + edlist.statloc, + edlist.sqstart + new_statloc); + chgEdList( new_statloc, new_slct, OFF); +} + + + + +/* + * contents : select the edit items by mouse + */ + +/*ARGSUSED*/ +void +EHeBulB_eMEv( widget, clientData, e ) +Widget widget; +caddr_t clientData; +XEvent *e; /* X Event */ +{ + int px, py; + int downbutton; + + if (edpane.pix_w * edpane.pix_h == 0 ) { + return; + } + + if( e->type == ButtonPress ){ + em.drag_f = ON; + } + if( (edg.code == 0) || (em.drag_f == OFF) ) + return; + if( e->type == ButtonRelease ){ + em.drag_f = OFF; + } + + px = e->xbutton.x / edpane.pix_w; + py = e->xbutton.y / edpane.pix_h; + + if (( e->type == ButtonPress) || (e->type == ButtonRelease)){ + downbutton = e->xbutton.button; + }else if ( e->type == MotionNotify ){ + if ( e->xmotion.state & Button1Mask ){ + downbutton = 1; /* select button */ + }else if ( e->xmotion.state & Button2Mask ){ + downbutton = 2; /* adjust button */ + } else { + downbutton = 0; + } + } + + switch( downbutton ) { + case 1: + switch( em.proc ) { + case PROC_POINT: + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + musPoint( e->type, px, py ); + break; + case PROC_LINE: + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + musLine( e->type, px, py ); + break; + case PROC_CIRCLE: + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + musCircle( e->type, px, py ); + break; + case PROC_RECT: + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + musRect( em.proc, e->type, px, py ); + break; + case PROC_ERASE: + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + musPoint( e->type, px, py ); + break; + case PROC_SELECT: + musRegionProc( em.proc, e->type, px, py ); + break; + default: + break; + } + break; + + case 2: + if( (0 <= px) && (px < edg.width) && (0 <= py) && (py < edg.height) ) { + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + + switch( e->type ) { + case MotionNotify: + if( (em.adj_px == px) && (em.adj_py == py) ) + return; + break; + case ButtonPress: + em.adj_px = px; + em.adj_py = py; + if( bitRead(edg.ptn, px, py) == 0 ) { + bitSet( edg.ptn, px, py ); + DrawPointEdPn( px,py, 1 ); + DrawPointDpPn( px,py, 1 ); + } + else { + bitReset( edg.ptn, px, py ); + DrawPointEdPn( px,py, 0 ); + DrawPointDpPn( px,py, 0 ); + } + edg.flag = ON; + break; + default: + return; + } + } + default: + break; + } +} + + + + +/* + * contents : restore the editting pane + */ + +/*ARGSUSED*/ +void +EHeBulB_eExp( widget, clientData, e ) +Widget widget; +caddr_t clientData; +XEvent *e; /* X Event */ +{ + int x1, y1; + int x2, y2; + + if (edpane.pix_w * edpane.pix_h == 0 ) { + return; + } + + x1 = e->xexpose.x / edpane.pix_w; + y1 = e->xexpose.y / edpane.pix_h; + x2 = (e->xexpose.x + e->xexpose.width - 1) / edpane.pix_w; + y2 = (e->xexpose.y + e->xexpose.height - 1) / edpane.pix_h; + + DrawRectEdPn( x1, y1, x2, y2 ); + DrawBorderEdPn( x1, y1, x2, y2 ); +} + + + + +/* + * contents : specifies the drawing operation (Pont/Line/Rectangle/Circle) + */ + +/*ARGSUSED*/ +void +CBeRecB_obj( widget, obj, call) +Widget widget; +int obj; +XmToggleButtonCallbackStruct *call; +{ + extern void SelectUnset(); + + if (call->set == False) + return; + + resetEditMode( RES_MSG | RES_RSV | RES_SLCT ); + + if (obj == PROC_ERASE) + edpane.color = OFF; + else + edpane.color = ON; + edpane.obj = obj; + em.proc = obj; + if (obj != PROC_SELECT) { + if (select_x || select_y || select_w || select_h) { + rubBand( r1_x, r1_y, r2_x, r2_y ); + select_x = select_y = select_w = select_h = 0; + SelectUnset(); + } + } +} + + + + +/* + * contents : restore the displaying pane + */ + +/*ARGSUSED*/ +void +EHeBulB_dExp( widget, clientData ) +Widget widget; +caddr_t clientData; +{ + if (xl.display == NULL ){ + return; + } + + DrawDpPn(); +} + +/* + * contents : set the range to be add or deleted + */ + +static int +codeAreaSet(s_code,e_code) +int *s_code; +int *e_code; +{ + char *str; + char delm; + + str = MngCodeTfValue(); + delm = '\0'; + *s_code = 0; + *e_code = 0; + if (!str || !*str){ + return(-1); + } + sscanf( str, "%x %c %x", s_code, &delm, e_code ); + if (str) free( str ); + switch( delm ) { + case '\0': + *e_code = *s_code; + break; + case '-': + break; + default: + return(-1); + } + if( codeCheck(*s_code) || codeCheck(*e_code) || + (*s_code > *e_code) ) { + return(-1); + } + return(0); +} + + +/**************************************************************** + * callback routines (character management window) * + ***************************************************************/ + +Boolean +BeforeMngCheck(s_code, e_code) +int *s_code; +int *e_code; +{ + if(codeAreaSet(s_code, e_code) == -1) { + DispMngErrorMessage( resource.me_illegal_code ); + return(False); + } + return(True); +} + +void +DoAddProc(s_code, e_code) +int s_code; +int e_code; +{ + int code; + + int s_ncode; + int e_ncode; + char ptn[MAXPTNBYTE]; + char mode; + int i; + + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + + /* */ + s_ncode = codeToNo( s_code ); + e_ncode = codeToNo( e_code ); + mode = OFF; + bitPtnClear( ptn ); + for( i=s_ncode ; i <= e_ncode ; i++ ) { + code = noToCode(i); + if ( codeCheck( code)) + continue; + if (ptnSense(code) == 0) { + if(ptnAdd(code, ptn) != 1) { + SetString( wgeStaT, resource.me_non_memory ); + return; + } + edg.flag = ON; + mode = ON; + edlist.nptn++; + } + } + + /* */ + if( ptnSense( edg.code ) == 1 ) { + ptnAdd( edg.code, edg.ptn ); + } + /* */ + if(mode == ON) { + chgEdCode( s_code, mode ); + } + + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); +} + + + +void PopupDelNotice(); +Widget CreateDelNotice(); + + +void +DoDelProc( s_code, e_code ) +int s_code; +int e_code; +{ + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + + if( ptnSense( edg.code) == 1 ) + ptnAdd( edg.code, edg.ptn ); + + dn.s_ncode = codeToNo( s_code ); + dn.e_ncode = codeToNo( e_code ); + + if (setRealDelArea(&dn.s_ncode, &dn.e_ncode, &dn.sq_start, &dn.sq_end) == -1) { + DispMngErrorMessage( resource.me_nodelete_code ); + return; + } + dn.sq_top = dn.sq_start; + dn.disp_num = AbsSqToRel( dn.sq_start, dn.sq_end) + 1; + dn.disp_num = (dn.disp_num <= D_MAX) ? dn.disp_num : D_MAX; + + PopupDelNotice( mngPtnW ); + +} + + + + +/* + * contents : get the real range to be add or delete + */ + + +static int +setRealDelArea(s_ncode, e_ncode, sq_start, sq_end ) +int *s_ncode, *e_ncode; +int *sq_start, *sq_end; +{ + int ncode; + int flg; + int sq; + int i; + + /* first code */ + flg = 0; + ncode = *e_ncode; + for( i=*s_ncode ; i <= ncode ; i++ ) { + if (((sq = ptnNoToSq(i)) != -1) && (codeCheck( noToCode(i)) == 0)) { + flg = 1; + break; + } + } + if (flg == 1) { + *s_ncode = ptnSqToNo( sq ); + *sq_start = sq; + } else { + return(-1); + } + + /* last code */ + flg = 0; + ncode = *s_ncode; + for( i=*e_ncode ; i >= ncode ; i-- ) { + if ((( sq = ptnNoToSq(i)) != -1) && (codeCheck( noToCode(i) ) == 0)) { + flg = 1; + break; + } + } + *e_ncode = ptnSqToNo( sq ); + *sq_end = sq; + return(0); +} + + + + + + +/**************************************************************** + * callback routines (Copy) * + ****************************************************************/ + +static int +CpySrcCodeCheck() +{ + char *str; + char delm; + + str = CpySrcCodeTfValue(); + if (!str) + return(-1); + if (!*str) { + free(str); + return(-1); + } + delm = '\0'; + cpm.s1_code = 0; + cpm.s2_code = 0; + sscanf( str, "%x %c %x", &cpm.s1_code,&delm, &cpm.s2_code ); + free( str ); + switch( delm ) { + case '\0': + cpm.s2_code = cpm.s1_code; + break; + case '-': + break; + default: + return(-1); + } + if (cpm.s1_code > cpm.s2_code) + return(-1); + return(0); +} + +static int +CpyDestCodeCheck() +{ + char *str; + + str = CpyDestCodeTfValue(); + if (!str) + return(-1); + if (!*str){ + free(str); + return(-1); + } + cpm.d1_code = 0; + sscanf( str, "%x", &cpm.d1_code ); + free( str ); + + if( codeCheck(cpm.d1_code) ) { + return(-1); + } + return(0); +} + +Boolean +BeforeCpyCheck( proc ) +int proc; +{ + int s_ncode, e_ncode; + int r1_code, r2_code; + int no; + int i; + char rstr[30]; + extern void PopupCpyNotice(); + + if (copyFontData.xlfdname == NULL) { + DispCpyErrorMessage(resource.me_non_srcfile); + return(False); + } + + if (CpySrcCodeCheck() == -1){ + DispCpyErrorMessage( resource.me_illegal_srccode ); + return(False); + } + + if (CpyDestCodeCheck() == -1){ + DispCpyErrorMessage( resource.me_illegal_destcode ); + return(False); + } + + s_ncode = codeToNo( cpm.d1_code ); + e_ncode = codeToNo( cpm.d1_code + cpm.s2_code - cpm.s1_code); + r1_code = r2_code = 0; + for( i=s_ncode ; i <= e_ncode ; i++ ) { + no = ptnSqToNo(i); + if (( no >= 0) && (codeCheck( noToCode( no)) == 0)) { + if(r1_code == 0) + r1_code = noToCode(i); + r2_code = noToCode(i); + } + } + + cpm.proc = proc; + + if( r1_code != 0 ) { + if( r1_code == r2_code ) { + sprintf( rstr, "%s %x¡¡", resource.l_code, r1_code ); + } else if ( codeCheck(r1_code) && codeCheck(r2_code)){ + sprintf( rstr, " %x - %x", r1_code, r2_code ); + } else { + sprintf( rstr, "%s %x - %x ", resource.l_code_range, r1_code, r2_code ); + } + PopupCpyNotice(rstr); + + return(False); + } + return(True); +} + +void +DoCpyProc() +{ + extern void PopdownCpyPtn(); + + PopdownCpyPtn(); + + resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV ); + + copyPatterns( cpm.fdata, cpm.s1_code, cpm.s2_code, cpm.d1_code, cpm.proc ); +} + +/**************************************************************** + * main routine * + ****************************************************************/ +#define R(name, class, member,def) { \ + name, \ + class, \ + XtRString, \ + sizeof(char *), \ + XtOffsetOf(Resource, member), \ + XtRString, \ + (XtPointer)def } + +#define RBoolean(name, class, member,def) \ + { name, class, XtRBoolean, sizeof(XtRBoolean), \ + XtOffsetOf(Resource, member), XtRString, (XtPointer)def } + +#define RDimension(name, class, member,def) \ + { name, class, XtRDimension, sizeof(XtRDimension), \ + XtOffsetOf(Resource, member), XtRString, (XtPointer)def } + +#define Rint(name, class, member,def) \ + { name, class, XtRInt, sizeof(XtRInt), \ + XtOffsetOf(Resource, member), XtRString, (XtPointer)def } + +#define RPixel(name, class, member,def) \ + { name, class, XtRPixel, sizeof(XtRPixel), \ + XtOffsetOf(Resource, member), XtRString, (XtPointer)def } + +static XtResource app_resources[] = { +RBoolean("Codepoint", "codepoint", codepoint, "False"), + +R( "lptog", "Lptog", l_ptog, DFLTPATH ), +R( "lptogCmd", "LptogCmd", l_ptog_cmd, DFLTCMD ), + +/* CreateCaptionFrame() */ +RBoolean( "captResize", "CaptResize", capt_resize, "True" ) , +Rint( "captLftoff", "CaptLftoff", capt_lftoff, "2" ) , +Rint( "captTopoff", "CaptTopoff", capt_topoff, "2" ) , +Rint( "captRghoff", "CaptRghoff", capt_rghoff, "2" ) , + +RPixel( "paneBackground", "paneBackground", pane_background, "white" ), +RPixel( "paneForeground", "PaneForeground", pane_foreground, "black" ), +RPixel( "background", "Background", background, "white" ), +RPixel( "foreground", "Foreground", foreground, "black" ), + +/* CreateMenuButtons() */ +RDimension( "menuMargin", "MenuMargin", menu_margin, "0" ) , + +/* CreateDialogAndButtons() */ +RBoolean( "diaTmAutomng", "DiaTmAutomng", dia_tm_automng, "False" ) , +RDimension( "diaTmWidth", "DiaTmWidth", dia_tm_width, "4" ) , +RDimension( "diaTmHeight", "DiaTmHeight", dia_tm_height, "4" ) , +RBoolean( "diaTmResize", "DiaTmResize", dia_tm_resize, "True" ) , +RBoolean( "diaTmMinimize", "DiaTmMinimize", dia_tm_minimize, "True" ) , + +RDimension( "diaRwWidth", "DiaRwWidth", dia_rw_width, "6" ) , +RDimension( "diaRwHeight", "DiaRwHeight", dia_rw_height, "6" ) , +RDimension( "diaRwSpacing", "DiaRwSpacing", dia_rw_spacing, "4" ) , + +/* CreateDrawingArea() */ +RDimension( "drawBorder", "DrawBorder", draw_border, "1" ) , +Rint( "drawTopoff", "DrawTopoff", draw_topoff, "2" ) , +Rint( "drawLftoff", "DrawLftoff", draw_lftoff, "2" ) , + +/* PopupNotice() */ +RBoolean( "popResize", "PopResize", pop_resize , "True" ) , +RBoolean( "popMinimize", "PopMinimize", pop_minimize , "True" ) , + +/* CreateTemplateDialog() */ +RBoolean( "tempResize", "TempResize", temp_resize, "True" ) , +RBoolean( "tempMinimize", "TempMinimize", temp_minimize, "True" ) , + +RDimension( "tempWidth", "TempWidth", temp_width, "1" ) , +RDimension( "tempHeight", "TempHeight", temp_height, "1" ) , + +/* CreateMenuBarAndFooterMessageForm() */ +Rint( "edBarTopoff", "EdBarTopoff", ed_bar_topoff, "1" ) , +Rint( "edBarLftoff", "EdBarLftoff", ed_bar_lftoff, "1" ) , +Rint( "edBarRghoff", "EdBarRghoff", ed_bar_rghoff, "1" ) , + +Rint( "edFrmBtmoff", "EdFrmBtmoff", ed_frm_btmoff, "3" ) , +Rint( "edFrmLftoff", "EdFrmLftoff", ed_frm_lftoff, "3" ) , +Rint( "edFrmRghoff", "EdFrmRghoff", ed_frm_rghoff, "3" ) , + +RDimension( "edMsgMargintop", "EdMsgMargintop", ed_msg_margintop, "3" ) , +RDimension( "edMsgMarginbtm", "EdMsgMarginbtm", ed_msg_marginbtm, "3" ) , + +RDimension( "edMesgMargintop", "EdMesgMargintop", ed_mesg_margintop, "3" ) , +RDimension( "edMesgMarginbtm", "EdMesgMarginbtm", ed_mesg_marginbtm, "3" ) , + +Rint( "edSepBtmoff", "EdSepBtmoff", ed_sep_btmoff, "3" ) , +Rint( "edSepLftoff", "EdSepLftoff", ed_sep_lftoff, "0" ) , +Rint( "edSepRghoff", "EdSepRghoff", ed_sep_rghoff, "0" ) , +RDimension( "edSepMargin", "EdSepMargin", ed_sep_margin, "0" ) , + +Rint( "edWgeTopoff", "EdWgeTopoff", ed_wge_topoff, "10" ) , +Rint( "edWgeLftoff", "EdWgeLftoff", ed_wge_lftoff, "10" ) , +Rint( "edWgeRghoff", "EdWgeRghoff", ed_wge_rghoff, "10" ) , +Rint( "edWgeBtmoff", "EdWgeBtmoff", ed_wge_btmoff, "10" ) , + +/* CreateFrame() */ +RBoolean( "frameResize", "FrameResize", frame_resize, "False" ) , + +/* CreateScrollBase() */ +RDimension( "scllFrWidth", "ScllFrWidth", scll_fr_width, "500" ) , + +RDimension( "scllFrThick", "ScllFrThick", scll_fr_thick, "2" ) , + +Rint( "scllBarLftoff", "ScllBarLftoff", scll_bar_lftoff, "4" ) , +}; +#undef R +#undef RBoolean +#undef RDimension +#undef Rint +#undef RPixel + +int CodePoint = False; + +/*ARGSUSED*/ +static void +xerror(d, ev) +Display *d; +register XErrorEvent *ev; +{ + fprintf (stderr, "dtudcfonted: warning, error event receieved.\n"); + exit(-1); +} + +int +main(argc, argv) +int argc; +char *argv[]; +{ + static char class_name[] = "Dtudcfonted"; + int i; + + /* initialize GUI */ + toplevel = (Widget)GuiInitialize(&app, class_name, &argc, argv); + + /* get application's resources */ + XtGetApplicationResources( toplevel, &resource, + app_resources, XtNumber(app_resources), NULL, 0); + + if (resource.codepoint) + CodePoint = True; + /* initialize the code range */ + for( i=1 ; i < argc ; i++ ) { + if( !strcmp(argv[i],"-pane_size") ) { + i++; + edpane_size = atoi( argv[i] ); + } else if( !strcmp(argv[i],"-codepoint") ) { + CodePoint = True; + } + } + + resource.mg_write_snf = GETMESSAGE(2, 2, "Registration processing inside."); + resource.me_write_snf = GETMESSAGE(2, 4, "Failed in the registration of the character."); + resource.me_illegal_code = GETMESSAGE(2, 6, "Illegal code."); + resource.me_non_memory = GETMESSAGE(2, 8, "Because the memory allocation cannot be done, it is not possible to add."); + resource.mg_non_code = GETMESSAGE(2, 10, "There is no character of the specified code."); + resource.me_illegal_srccode = GETMESSAGE(2, 12, "The mistake is found in the specified copy origin code."); + resource.me_illegal_destcode = GETMESSAGE(2, 14, "The mistake is found in the specified copy target code."); + resource.me_nodelete_code = GETMESSAGE(2, 16, "There is no character in the specified area."); + resource.me_wait = GETMESSAGE(2, 18, "Please wait for a while."); + resource.me_non_srcfile = GETMESSAGE(2, 20, "No copy origin code file is specified."); + resource.mn_no_font = GETMESSAGE(2, 22, "Informations of user defined character cannot collect.\nThere is no font specified."); + resource.mn_plural_font = GETMESSAGE(2, 24, "Informations of user defined character cannot collect.\nThere are plural fonts specified."); + resource.mn_not_udc = GETMESSAGE(2, 26, "The specified font do not have any UDCs areas."); + resource.mn_no_mem = GETMESSAGE(2, 28, "There are no memories any more."); + resource.mn_illegal_area = GETMESSAGE(2, 30, "The information of UDCs area is illegal."); + resource.mn_no_read = GETMESSAGE(2, 32, "The font file cannot read.\nPattern area was broken."); + resource.mn_prop_font = GETMESSAGE(2, 34, "Dtudcfonted cannot edit proportional character font."); + resource.mn_saved_open = GETMESSAGE(2, 36, "There are unsaved edits.\nDo you want to save them before opening?"); + resource.mn_saved_exit = GETMESSAGE(2, 38, "There are unsaved edits.\nDo you want to save them before exiting?"); + resource.mn_cpy_lost = GETMESSAGE(2, 40, "When the copy processing is done, the glyph\nimage within the following ranges is changed.\nDo you want to do the copy processing?\n\n"); + resource.mn_no_perm = GETMESSAGE(2, 42, "No write permission for this font. You should change the file access mode before saving.\n"); + + resource.l_selectitem = GETMESSAGE(2, 100, "Select Items"); /* font open */ + resource.l_codeset = GETMESSAGE(2, 102, " CodeSet:"); + resource.l_style = GETMESSAGE(2, 104, " Style:"); + resource.l_width = GETMESSAGE(2, 106, " Width:"); + resource.l_height = GETMESSAGE(2, 108, " Height:"); + resource.exec_label = GETMESSAGE(2, 110, "Open"); + resource.quit_label = GETMESSAGE(2, 112, "Quit"); + + resource.l_font = GETMESSAGE(2, 114, "Font"); /* menu bar */ + resource.l_edit = GETMESSAGE(2, 116, "Edit"); + resource.l_manage = GETMESSAGE(2, 118, "Character"); + resource.l_info = GETMESSAGE(2, 120, "Information"); + + resource.l_open_w = GETMESSAGE(2, 122, "Open"); /* font menu */ + resource.l_save = GETMESSAGE(2, 124, "Save"); + resource.l_exit = GETMESSAGE(2, 126, "Exit"); + + resource.l_clear = GETMESSAGE(2, 128, "Clear"); /* edit menu */ + resource.l_set = GETMESSAGE(2, 130, "Set"); + resource.l_reverse = GETMESSAGE(2, 132, "Reverse"); + resource.l_cut = GETMESSAGE(2, 134, "Cut"); + resource.l_Copy = GETMESSAGE(2, 135, "Copy"); + resource.l_paste = GETMESSAGE(2, 136, "Paste"); + resource.l_roll = GETMESSAGE(2, 138, "Rotate"); + resource.l_updown_roll = GETMESSAGE(2, 140, "Vertical Roll"); + resource.l_leftright_roll = GETMESSAGE(2, 142, "Horizontal Roll"); + resource.l_undo = GETMESSAGE(2, 144, "Undo"); + + resource.l_manage_w = GETMESSAGE(2, 146, "Add/Delete..."); /* character menu */ + resource.l_copy_w = GETMESSAGE(2, 148, "Copy..."); + + resource.l_xlfd = GETMESSAGE(2, 150, "XLFD name..."); /* information menu */ + resource.l_codearea = GETMESSAGE(2, 152, "Code Area..."); + + resource.l_add = GETMESSAGE(2, 154, "Add"); /* add/delete dialog */ + resource.l_delete = GETMESSAGE(2, 156, "Delete"); + resource.l_cancel = GETMESSAGE(2, 158, "Cancel"); + + resource.l_manage_code = GETMESSAGE(2, 160, "Code(hex):"); /* copy dialog */ + resource.l_copy_src_code = GETMESSAGE(2, 162, " Copy origin code(hex):"); + resource.l_copy_dest_code = GETMESSAGE(2, 164, "Copy target code(hex):"); + resource.l_copy = GETMESSAGE(2, 166, "Copy"); + resource.l_overlay = GETMESSAGE(2, 168, "Overlay"); + resource.l_ok = GETMESSAGE(2, 170, "OK"); + + resource.l_do_save = GETMESSAGE(2, 172, "Save"); /* unsaved edits */ + resource.l_dont_save = GETMESSAGE(2, 174, "Do not Save"); + resource.l_do_save_exit = GETMESSAGE(2, 176, "Save and Exit"); + resource.l_dont_save_exit = GETMESSAGE(2, 178, "Do not Save and Exit"); + + resource.mg_start_del_s = GETMESSAGE(2, 180, "The following character will be deleted."); /* delete notice dialog */ + resource.mg_start_del_cs = GETMESSAGE(2, 182, "character"); + resource.mg_start_del_m = GETMESSAGE(2, 184, "The following characters will be deleted."); + resource.mg_start_del_cm = GETMESSAGE(2, 186, "characters"); + resource.mg_register = GETMESSAGE(2, 188, "Register completed"); + resource.l_code = GETMESSAGE(2, 190, " Code : "); + resource.l_code_range = GETMESSAGE(2, 192, " Code range : "); + + resource.message = GETMESSAGE(2, 194, "Message : "); + + resource.code = GETMESSAGE(2, 196, "code..."); /* code dialog */ + resource.previous = GETMESSAGE(2, 198, "Page up"); + resource.next = GETMESSAGE(2, 200, "Page down"); + resource.apply = GETMESSAGE(2, 202, "Apply"); + + resource.l_question_title = GETMESSAGE(2, 204, "dtudcfonted - Question"); + resource.l_warning_title = GETMESSAGE(2, 206, "dtudcfonted - Warning"); + resource.l_error_title = GETMESSAGE(2, 208, "dtudcfonted - Error"); + resource.l_copy_title = GETMESSAGE(2, 210, "dtudcfonted - Copy"); + resource.l_open_title = GETMESSAGE(2, 212, "dtudcfonted - Open"); + resource.l_add_title = GETMESSAGE(2, 214, "dtudcfonted - Add/Delete"); + resource.l_xlfd_title = GETMESSAGE(2, 216, "dtudcfonted - XLFD"); + resource.l_codearea_title = GETMESSAGE(2, 218, "dtudcfonted - CodeArea"); + + resource.file_name = GETMESSAGE(2, 230, "File name"); + resource.xlfd_name = GETMESSAGE(2, 232, "XLFD name"); + resource.codearea = GETMESSAGE(2, 234, "Code area"); + + resource.falerrmsg[0] = GETMESSAGE(2, 300, "Fatal error occurred."); + resource.falerrmsg[1] = GETMESSAGE(2, 301, "Cannot open the font file."); + resource.falerrmsg[2] = GETMESSAGE(2, 302, "Cannot read the font file."); + resource.falerrmsg[3] = GETMESSAGE(2, 303, "There is no more memory."); + resource.falerrmsg[4] = GETMESSAGE(2, 304, "Fatal error occurred."); + resource.falerrmsg[5] = GETMESSAGE(2, 305, "The specified font file does not exist."); + resource.falerrmsg[6] = GETMESSAGE(2, 306, "This font is not a pcf or snf font."); + resource.falerrmsg[7] = GETMESSAGE(2, 307, "Cannot open fonts.list file."); + resource.falerrmsg[8] = GETMESSAGE(2, 308, "The format of fonts.list file is illegal."); + resource.falerrmsg[9] = GETMESSAGE(2, 309, "The descriptions of the fonts.list file are incorrect."); + resource.falerrmsg[10] = GETMESSAGE(2, 310, "The format of fonts.list file is illegal."); + resource.falerrmsg[11] = GETMESSAGE(2, 311, "Cannot open fonts.dir file."); + resource.falerrmsg[12] = GETMESSAGE(2, 312, "Cannot read fonts.dir file."); + resource.falerrmsg[13] = GETMESSAGE(2, 313, "Cannot read font properties."); + resource.falerrmsg[14] = GETMESSAGE(2, 314, "Cannot get FONT property."); + resource.falerrmsg[15] = GETMESSAGE(2, 315, "Cannot get FAMILY_NAME property."); + resource.falerrmsg[16] = GETMESSAGE(2, 316, "This font file is already opened by other application."); + resource.falerrmsg[17] = GETMESSAGE(2, 317, "Cannot lock font file."); + resource.falerrmsg[18] = GETMESSAGE(2, 318, "Cannot unlock font file."); + resource.falerrmsg[19] = GETMESSAGE(2, 319, "Cannot get lock information from the font file."); + resource.falerrmsg[20] = GETMESSAGE(2, 320, "Cannot find the specified font file."); + resource.falerrmsg[21] = GETMESSAGE(2, 321, "Cannot read NLS database."); + resource.falerrmsg[22] = GETMESSAGE(2, 322, "Cannot get charset names from NLS database."); + resource.falerrmsg[23] = GETMESSAGE(2, 323, "Charset name not defined in NLS database."); + resource.falerrmsg[24] = GETMESSAGE(2, 324, "The specified font has not been opened."); + resource.falerrmsg[25] = GETMESSAGE(2, 325, "Fatal error occurred."); + + xlfdDialog = NULL ; + cpyDialog = NULL ; + + /* initialize the global values and allocate the memories */ + xeg_init(); + + + /* displays the selection window */ + PopupSelectXLFD(toplevel); + + XSetErrorHandler((XErrorHandler)xerror); + XSetIOErrorHandler((XIOErrorHandler)xerror); + + /* main loop */ + XtAppMainLoop(app); + + return(-1); +} + + +/* + * contents : initialize the global values + */ + +static void +xeg_init() +{ + int i; + + edg.code = edg.ncode = 0; + bitPtnClear( edg.ptn ); + edg.flag = (char)0; + + edlist.nlist = EDLIST_MAX; + edlist.statloc = edlist.slctloc = 0; + edlist.nptn = 0; + edlist.sqstart = 0; + edlist.list_h = edlist.elem_w = edlist.elem_h = (Dimension)0; + edlist.back = resource.pane_background; + edlist.border = resource.pane_foreground; + + if ( edpane_size ){ + edpane.width = edpane_size; + edpane.height = edpane_size; + } else { + edpane.width = EDPANE_SIZE; + edpane.height = EDPANE_SIZE; + } + edpane.pix_w = edpane.pix_h = 0; + edpane.color = 0; + edpane.obj = 0; + edpane.back = resource.pane_background; + edpane.border = resource.pane_foreground; + + xl.display = NULL; + xl.root_winID = xl.edit_winID = xl.disp_winID = xl.list_winID = + (Window)NULL; + xl.borderGC = xl.backGC = xl.rubGC = xl.dashGC = (GC)NULL; + xl.dispImage = NULL; + + dn.elem_w = dn.elem_h = (Dimension)0; + dn.ptn_w = dn.ptn_h = (Dimension)0; + dn.list_h = (Dimension)0; + dn.s_ncode = dn.e_ncode = 0; + dn.sq_top = dn.sq_start = dn.sq_end = 0; + dn.disp_num = 0; + + for ( i=0 ; i= edlist.statloc) + && (esq <= (RelToAbsSq( edlist.sqstart + edlist.statloc, + edlist.nlist - 1) - edlist.sqstart))){ + statloc = edlist.statloc; + slctloc = AbsSqToRel(edlist.sqstart+statloc, + edlist.sqstart + esq); + } else { + statloc = esq; + slctloc = 0; + } + while( RelToAbsSq(edlist.sqstart+statloc, edlist.nlist - 1) < 0) + statloc = RelToAbsSq( edlist.sqstart + statloc, -1) + - edlist.sqstart; + slctloc = AbsSqToRel( edlist.sqstart + statloc, edlist.sqstart + esq); + } + + n = 0; + if (( slimax = efctPtnNum()) < edlist.nlist) + slimax = edlist.nlist; + XtSetArg( arg[n], XmNmaximum, (XtArgVal)slimax ); n++; + XtSetArg( arg[n], XmNvalue, (XtArgVal)AbsSqToRel( edlist.sqstart, edlist.sqstart + statloc) ); n++; + XtSetValues( wgeScro , arg, n ); + + chgEdList( statloc, slctloc, mode ); + chgEdPtn( code ); +} + + +/* + * contents : rewrite the character list + */ + +void +chgEdList( statloc, slctloc, mode ) +int statloc; +int slctloc; +char mode; +{ + int sq; + int i; + char str[6]; + int no; + int code; + extern void ListSetLabelStr(); + extern void ListSetGlyphImage(); + extern void ListUnselectItem(); + extern void ListSelectItem(); + + if((mode == ON) || (edlist.statloc != statloc)){ + for (i=0, sq=edlist.sqstart+statloc; i < edlist.nlist; sq++){ + no = ptnSqToNo(sq); + sq_disp[i] = sq ; + + if ((no >= 0) && (code = noToCode(no)) >= 0 ){ + sprintf(str, "%4x", code); + ListSetLabelStr(i, str); + ListSetGlyphImage(i) ; + if (i == 0) + edlist.statloc = sq - edlist.sqstart; + i++; + } else if (sq > ( edlist.sqstart + edlist.nptn - 1)){ + strcpy(str, " "); + ListSetLabelStr(i, str); + ListSetGlyphImage(i) ; + i++; + } + } + } + + if( (mode == ON) || (edlist.slctloc != slctloc) ) { + if((0 <= edlist.slctloc) && (edlist.slctloc < edlist.nlist)){ + ListUnselectItem(edlist.slctloc); + } + if((0 <= slctloc) && (slctloc < edlist.nlist)){ + ListSelectItem(slctloc); + } + edlist.slctloc = slctloc; + } +} + + +/* + * contents : rewrite the editting pane + */ + +static void +chgEdPtn( code ) +int code; +{ + extern void SetCodeString(); + + if (xl.display == NULL ){ + return; + } + + if( code == 0 ) { + XClearWindow( xl.display, xl.edit_winID ); + DrawBorderEdPn( 0, 0, edg.width - 1, edg.height - 1 ); + XClearWindow( xl.display, xl.disp_winID ); + XClearWindow( xl.display, xl.list_winID ); + bitPtnClear( edg.ptn ); + edg.code = 0; + edg.ncode = 0; + SetCodeString(0); + } + + if( ptnGet( code, edg.ptn) == 0 ) { + edg.code = code; + edg.ncode = codeToNo( code ); + DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 ); + + SetCodeString(code); + DrawDpPn(); + } +} + + + + + +/**************************************************************** + * draw patterns to the editting pane * + ***************************************************************/ + +/* + * contents : draw a rectangle + * + */ + +static void +DrawRectEdPn( x1, y1, x2, y2 ) +int x1; +int y1; +int x2; +int y2; +{ + int i, j, wk; + short cx1, cy1, cx2, cy2; + XRectangle recOn[MAXPTNSIZE*MAXPTNSIZE]; + XRectangle recOff[MAXPTNSIZE*MAXPTNSIZE]; + int nron, nroff; + + if (xl.display == NULL ){ + return; + } + + if( x2 < x1 ) { + wk = x2; + x2 = x1; + x1 = wk; + } + if( y2 < y1 ) { + wk = y2; + y2 = y1; + y1 = wk; + } + + nron = nroff = 0; + for( j=y1 ; j <= y2 ; j++ ) { + for( i=x1 ; i <= x2 ; i++ ) { + cx1 = (short)(edpane.pix_w * i); + cy1 = (short)(edpane.pix_h * j); + cx2 = (short)(cx1 + edpane.pix_w - 1); + cy2 = (short)(cy1 + edpane.pix_h - 1); + + if( bitRead( edg.ptn, i, j ) != 0 ) { + recOn[nron].x = cx1; + recOn[nron].y = cy1; + recOn[nron].width = (USHORT)(cx2 - cx1); + recOn[nron].height = (USHORT)(cy2 - cy1); + nron++; + } + else { + recOff[nroff].x = cx1; + recOff[nroff].y = cy1; + recOff[nroff].width = (USHORT)(cx2 - cx1); + recOff[nroff].height = (USHORT)(cy2 - cy1); + nroff++; + } + } + } + if( nron ) + XFillRectangles( xl.display, xl.edit_winID, xl.borderGC, recOn, nron ); + if( nroff ) + XFillRectangles( xl.display, xl.edit_winID, xl.backGC, recOff, nroff ); +} + + +/* + * contents : draw a lattice inside of the editting pane + */ + +static void +DrawBorderEdPn( x1, y1, x2, y2 ) +int x1; +int y1; +int x2; +int y2; +{ + short cx1, cy1; + short cx2, cy2; + int ndseg; + int wk, i; + XSegment dseg[MAXPTNSIZE*2]; + + if (xl.display == NULL ){ + return; + } + + if( x2 < x1 ) { + wk = x2; + x2 = x1; + x1 = wk; + } + if( y2 < y1 ) { + wk = y2; + y2 = y1; + y1 = wk; + } + + ndseg = 0; + + cx1 = (short)(edpane.pix_w * x1); + cx2 = (short)(edpane.pix_w * x2 + edpane.pix_w - 1); + for( i=y1 ; i <= y2 ; i++ ) { + cy1 = (short)(edpane.pix_h * i + edpane.pix_h - 1); + dseg[ndseg].x1 = cx1; + dseg[ndseg].y1 = cy1; + dseg[ndseg].x2 = cx2; + dseg[ndseg].y2 = cy1; + ndseg++; + } + cy1 = (short)(edpane.pix_h * y1); + cy2 = (short)(edpane.pix_h * y2 + edpane.pix_h - 1); + for( i=x1 ; i <= x2 ; i++ ) { + cx1 = (short)(edpane.pix_w * i + edpane.pix_w - 1); + dseg[ndseg].x1 = cx1; + dseg[ndseg].y1 = cy1; + dseg[ndseg].x2 = cx1; + dseg[ndseg].y2 = cy2; + ndseg++; + } + + if( ndseg ) { + XDrawSegments( xl.display, xl.edit_winID, xl.dashGC, dseg, ndseg); + } +} + + +/* + * contents : draw a dot + */ + +static void +DrawPointEdPn( x, y, mode ) +int x; +int y; +int mode; +{ + int x1, y1; + int x2, y2; + + if (xl.display == NULL ){ + return; + } + + x1 = edpane.pix_w * x; + y1 = edpane.pix_h * y; + x2 = x1 + edpane.pix_w - 1; + y2 = y1 + edpane.pix_h - 1; + + if( mode != 0 ) { + XFillRectangle( xl.display, xl.edit_winID, xl.borderGC, + x1, y1, x2-x1, y2-y1 ); + } else { + XFillRectangle( xl.display, xl.edit_winID, xl.backGC, + x1, y1, x2-x1, y2-y1 ); + } +} + + + +/* + * contents : draw a current character pattern to the display pane + */ + +static void +DrawDpPn() +{ + if (xl.display == NULL ){ + return; + } + + XPutImage( xl.display, xl.disp_winID, xl.borderGC, xl.dispImage, + 0, 0, 0, 0, edg.width, edg.height ); + if( xl.list_winID ) { + XPutImage( xl.display, xl.list_winID, xl.borderGC, + xl.dispImage, 0, 0, 0, 0, edg.width, edg.height ); + } +} + + + +/* + * contents : draw a dot + */ + +static void +DrawPointDpPn( x, y, mode ) +int x; +int y; +int mode; +{ + + if (xl.display == NULL ){ + return; + } + if( mode != 0 ){ + XDrawPoint( xl.display, xl.disp_winID, xl.borderGC, x, y ); + if (xl.list_winID) + XDrawPoint( xl.display, xl.list_winID, xl.borderGC, x, y ); + } else { + XDrawPoint( xl.display, xl.disp_winID, xl.backGC, x, y ); + if (xl.list_winID) + XDrawPoint( xl.display, xl.list_winID, xl.backGC, x, y ); + } +} + + + +/**************************************************************** + * draw patterns by mouse * + ****************************************************************/ + + +/* + * contents : draw a dot + */ + +static void +musPoint( evtype, px, py ) +int evtype; +int px; +int py; +{ + switch( evtype ) { + case MotionNotify: + if( (em.src1_px == px) && (em.src1_py == py) ) + return; + break; + case ButtonPress: + em.src1_px = px; + em.src1_py = py; + break; + default: + return; + } + + if( edpane.color == ON ) + bitSet( edg.ptn, px, py ); + else + bitReset( edg.ptn, px, py ); + edg.flag = ON; + DrawPointEdPn( px, py, edpane.color ); + DrawPointDpPn( px, py, edpane.color ); +} + + +/* + * contents : draw a line + */ + +static void +musLine( evtype, px, py ) +int evtype; +int px; +int py; +{ + int r1_x, r1_y; + int r2_x, r2_y; + int rx, ry; + int harf_pix_w; + int harf_pix_h; + + harf_pix_w = edpane.pix_w / 2; + harf_pix_h = edpane.pix_h / 2; + r1_x = em.src1_px * edpane.pix_w + harf_pix_w; + r1_y = em.src1_py * edpane.pix_h + harf_pix_h; + r2_x = em.src2_px * edpane.pix_w + harf_pix_w; + r2_y = em.src2_py * edpane.pix_h + harf_pix_h; + rx = px * edpane.pix_w + harf_pix_w; + ry = py * edpane.pix_h + harf_pix_h; + + switch( evtype ) { + case MotionNotify: + if( (em.src2_px == px) && (em.src2_py == py) ) + return; + rubLine( r1_x, r1_y, r2_x, r2_y ); + rubLine( r1_x, r1_y, rx, ry ); + em.src2_px = px; + em.src2_py = py; + return; + case ButtonPress: + em.src1_px = em.src2_px = px; + em.src1_py = em.src2_py = py; + return; + default: + if( (r1_x == r2_x) && (r1_y == r2_y) ) + return; + rubLine( r1_x, r1_y, r2_x, r2_y ); + + if ((em.src2_px < 0) || (em.src2_py < 0) || + (edg.width <= em.src2_px) || (edg.height <= em.src2_py)) + return; + + bitDrawLine( edg.ptn, em.src1_px, em.src1_py, + em.src2_px, em.src2_py, edpane.color ); + edg.flag = ON; + DrawRectEdPn( em.src1_px, em.src1_py, em.src2_px, em.src2_py ); + DrawDpPn(); + } +} + + + +/* + * contents : draw a circle + */ + +static void +musCircle( evtype, px, py ) +int evtype; +int px; +int py; +{ + int r1_x, r1_y; + int r2_x, r2_y; + int rx, ry; + int harf_pix_w; + int harf_pix_h; + extern int bitDrawCircle(); + + harf_pix_w = edpane.pix_w / 2; + harf_pix_h = edpane.pix_h / 2; + + r1_x = em.src1_px * edpane.pix_w + harf_pix_w; + r1_y = em.src1_py * edpane.pix_h + harf_pix_h; + r2_x = em.src2_px * edpane.pix_w + harf_pix_w; + r2_y = em.src2_py * edpane.pix_h + harf_pix_h; + rx = px * edpane.pix_w + harf_pix_w; + ry = py * edpane.pix_h + harf_pix_h; + + switch( evtype ) { + case MotionNotify: + if( (em.src2_px == px) && (em.src2_py == py) ) { + return; + } + rubCircle( r1_x, r1_y, r2_x, r2_y ); + rubCircle( r1_x, r1_y, rx, ry ); + em.src2_px = px; + em.src2_py = py; + return; + case ButtonPress: + em.src1_px = em.src2_px = px; + em.src1_py = em.src2_py = py; + return; + default: + if( (em.src1_px == px) && (em.src1_py == py) ) { + return; + } + rubCircle( r1_x, r1_y, r2_x, r2_y ); + + if( (px < 0) || (py < 0) || (edg.width <= px) || (edg.height <= py) ) { + return; + } + bitDrawCircle( edg.ptn, em.src1_px, em.src1_py, px, py, edpane.color); + + edg.flag = ON; + DrawRectEdPn( 0, 0, edg.width -1, edg.height -1 ); + DrawDpPn(); + } +} + + +/* + * contents : draw a rectangle + */ + +static void +musRect( proc, evtype, px, py ) +int proc; +int evtype; +int px; +int py; +{ + int r1_x, r1_y; + int r2_x, r2_y; + int rx, ry; + int lux, luy; + int width, height; + int dpx, dpy, dp; + + if( (proc == PROC_ROLL) && (evtype != ButtonPress) ) { + dpx = px - em.src1_px; + dpy = py - em.src1_py; + dp = (abs(dpx) > abs(dpy) ) ? abs(dpx) : abs(dpy); + + if( dpx != 0 ) + px = em.src1_px + dpx/abs(dpx) * dp; + if( dpy != 0 ) + py = em.src1_py + dpy/abs(dpy) * dp; + } + + r1_x = em.src1_px * edpane.pix_w + edpane.pix_w / 2; + r1_y = em.src1_py * edpane.pix_h + edpane.pix_h / 2; + r2_x = em.src2_px * edpane.pix_w + edpane.pix_w / 2; + r2_y = em.src2_py * edpane.pix_h + edpane.pix_h / 2; + rx = px * edpane.pix_w + edpane.pix_w / 2; + ry = py * edpane.pix_h + edpane.pix_h / 2; + + switch( evtype ) { + case MotionNotify: + if( (em.src2_px == px) && (em.src2_py == py) ) + return; + rubBand( r1_x, r1_y, r2_x, r2_y ); + rubBand( r1_x, r1_y, rx, ry ); + em.src2_px = px; + em.src2_py = py; + return; + case ButtonPress: + resetEditMode( RES_SLCT ); + em.src1_px = em.src2_px = px; + em.src1_py = em.src2_py = py; + return; + default: + resetEditMode( RES_MSG | RES_PROC ); + rubBand( r1_x, r1_y, r2_x, r2_y ); + if( (r1_x == r2_x) || (r1_y == r2_y) ) + return; + if( (em.src2_px < 0) || (em.src2_py < 0) || + (edg.width <= em.src2_px) || (edg.height <= em.src2_py) ) + return; + + lux = (em.src1_px < em.src2_px ) ? em.src1_px : em.src2_px; + luy = (em.src1_py < em.src2_py ) ? em.src1_py : em.src2_py; + width = abs( em.src1_px - em.src2_px ) + 1; + height = abs( em.src1_py - em.src2_py ) + 1; + + bitDrawRect(edg.ptn, lux, luy, width, height, edpane.color); + + edg.flag = ON; + DrawRectEdPn( em.src1_px, em.src1_py, px, py ); + DrawDpPn(); + } +} + + +/* + * contents : edit inside of the specified area (clear, reverse, rotate,etc.) + */ + +static void +musRegionProc( proc, evtype, px, py ) +int proc; +int evtype; +int px; +int py; +{ + int rx, ry; + int dpx, dpy, dp; + extern void SelectSet(); + + if( (proc == PROC_ROLL) && (evtype != ButtonPress) ) { + dpx = px - em.src1_px; + dpy = py - em.src1_py; + dp = (abs(dpx) > abs(dpy) ) ? abs(dpx) : abs(dpy); + + if( dpx != 0 ) + px = em.src1_px + dpx/abs(dpx) * dp; + if( dpy != 0 ) + py = em.src1_py + dpy/abs(dpy) * dp; + } + + r1_x = em.src1_px * edpane.pix_w + edpane.pix_w / 2; + r1_y = em.src1_py * edpane.pix_h + edpane.pix_h / 2; + r2_x = em.src2_px * edpane.pix_w + edpane.pix_w / 2; + r2_y = em.src2_py * edpane.pix_h + edpane.pix_h / 2; + rx = px * edpane.pix_w + edpane.pix_w / 2; + ry = py * edpane.pix_h + edpane.pix_h / 2; + + switch( evtype ) { + case MotionNotify: + if( (em.src2_px == px) && (em.src2_py == py) ) + return; + rubBand( r1_x, r1_y, r2_x, r2_y ); + rubBand( r1_x, r1_y, rx, ry ); + em.src2_px = px; + em.src2_py = py; + return; + case ButtonPress: + if (select_x || select_y || select_w || select_h) { + rubBand( r1_x, r1_y, r2_x, r2_y ); + } + resetEditMode( RES_SLCT ); + em.src1_px = em.src2_px = px; + em.src1_py = em.src2_py = py; + return; + default: + resetEditMode( RES_MSG | RES_PROC ); + select_x = select_y = select_w = select_h = 0; + if( (r1_x == r2_x) || (r1_y == r2_y) ) { + rubBand( r1_x, r1_y, r2_x, r2_y ); + return; + } + if( (em.src2_px < 0) || (em.src2_py < 0) || + (edg.width <= em.src2_px) || (edg.height <= em.src2_py) ) { + rubBand( r1_x, r1_y, r2_x, r2_y ); + return; + } + + select_x = (em.src1_px < em.src2_px ) ? em.src1_px : em.src2_px; + select_y = (em.src1_py < em.src2_py ) ? em.src1_py : em.src2_py; + select_w = abs( em.src1_px - em.src2_px ) + 1; + select_h = abs( em.src1_py - em.src2_py ) + 1; + SelectSet(); + } +} + + +/*ARGSUSED*/ +static void +musPasteProc(w, client_data, event) +Widget w; +XtPointer client_data; +XEvent *event; +{ + static int ox=0, oy=0; + int rc, tx, ty; + extern void UndoSet(); + extern Widget wgeBulB_edit; + extern int bitDrawPaste(); + + switch(event->type) { + case MotionNotify: + tx = (event->xmotion.x / edpane.pix_w) * edpane.pix_w + edpane.pix_w / 2; + ty = (event->xmotion.y / edpane.pix_h) * edpane.pix_h + edpane.pix_h / 2; + if (tx == ox && ty == oy) + return; + if(ox) { + rubBand(ox, oy, ox + cut_w * edpane.pix_w, oy + cut_h * edpane.pix_h); + } + ox = tx; + oy = ty; + rubBand(ox, oy, ox + cut_w * edpane.pix_w, oy + cut_h * edpane.pix_h); + break; + case ButtonRelease: + XtRemoveEventHandler(wgeBulB_edit, + ButtonReleaseMask|PointerMotionMask, + False, (XtEventHandler)musPasteProc, NULL ); + rubBand(ox, oy, ox + cut_w * edpane.pix_w, oy + cut_h * edpane.pix_h); + ox = 0; + oy = 0; + bitPtnCopy( em.rsv_ptn, edg.ptn ); + + tx = event->xbutton.x / edpane.pix_w; + ty = event->xbutton.y / edpane.pix_h; + rc = bitDrawPaste(edg.ptn, tx, ty); + if( rc == -1 ) + return; + edg.flag = ON; + em.rsv_f = ON; + DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 ); + DrawDpPn(); + UndoSet(); + break; + defaults: + break; + } +} + + + +static void +rubLine( x1, y1, x2, y2 ) +int x1; +int y1; +int x2; +int y2; +{ + if( x1==x2 && y1==y2 ) return; + + XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1,y1, x2,y2 ); +} + + + +static void +rubBand( x1, y1, x2, y2 ) +int x1; +int y1; +int x2; +int y2; +{ + if( x1==x2 && y1==y2 ) + return; + + XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1, y1, x2, y1 ); + XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1, y1, x1, y2 ); + XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x2, y1, x2, y2 ); + XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1, y2, x2, y2 ); +} + + + +static void +rubCircle( ox, oy, rx, ry ) +int ox; +int oy; +int rx; +int ry; +{ + unsigned int r; + int x, y; + + if( ox==rx && oy==ry ) return; + + x = rx - ox; + y = ry - oy; + r = (unsigned int)sqrt( (double)(x*x + y*y) ); + if ( r == 0 ) return; + + x = ox - (int)r; + y = oy - (int)r; + XDrawArc( xl.display, xl.edit_winID, xl.rubGC, + x, y, 2*r-1, 2*r-1, + 0, 360*64 + ); +} + + + +static void +resetEditMode( flag ) +UINT flag; +{ + int r1_x, r1_y; + int r2_x, r2_y; + + if( flag & RES_MSG ) + SetString( wgeStaT, "" ); + + if( flag & RES_PROC ) + em.proc = edpane.obj; + + if( (flag & RES_SLCT) && (em.slct_f) ) { + r1_x = em.src1_px * edpane.pix_w + edpane.pix_w / 2; + r1_y = em.src1_py * edpane.pix_h + edpane.pix_h / 2; + r2_x = em.src2_px * edpane.pix_w + edpane.pix_w / 2; + r2_y = em.src2_py * edpane.pix_h + edpane.pix_h / 2; + rubBand( r1_x, r1_y, r2_x, r2_y ); + em.slct_f = OFF; + } + + if( flag & RES_RSV ) + em.rsv_f = OFF; +} + + +/**************************************************************** + * copy character pattern * + ***************************************************************/ + +/* + * contents : copy or overlay the new character pattern to the current pattern + */ + +/*ARGSUSED*/ +static void +copyPatterns( fdata, s1_code, s2_code, d1_code, proc ) +FalFontData *fdata; +int s1_code; +int s2_code; +int d1_code; +int proc; +{ + int ret; + int d1_ncode, d2_ncode; + int code_d; + int code_disp; + char err[128]; + int i_s, i_d; + int i; + char grc_d; + char **ptn; + char ptn2[MAXPTNBYTE]; + int num; + extern int last_code; + + ret = copySNF(s1_code, s2_code, &ptn, &num, err); + if( ret == -1 ) { + Error_message2((Widget)NULL, err); + return; + } + + if (last_code < (d1_code + num)) + last_code = d1_code + num; + + if( ptnSense(edg.code) == 1 ) + ptnAdd( edg.code, edg.ptn ); + + d1_ncode = codeToNo( d1_code ); + + for (i_d=d1_ncode, i_s=0; i_s < num; i_d++) { + if ( codeCheck( noToCode( i_d))) + continue; + bitPtnClear( ptn2 ); + code_d = noToCode( i_d ); + grc_d = ptnGet( code_d, ptn2 ); + + if (grc_d == 0) { + if( proc == CPY_OVERLAY ) { + for( i=0 ; i < edg.height*((edg.width+7)/8) ; i++ ) { + ptn[i_s][i] |= ptn2[i]; + } + } + ptnAdd( code_d, ptn[i_s] ); + edg.flag = ON; + } else { + if( ptnAdd( code_d, ptn[i_s] ) != 1 ) { + SetString( wgeStaT, resource.me_non_memory ); + break; + } + edlist.nptn++; + edg.flag = ON; + } + i_s ++; + } + d2_ncode = i_d - 1; + + code_disp = 0; + for( i=d1_ncode ; i <= d2_ncode; i++ ) { + if ( codeCheck( noToCode(i) ) ) + continue; + if( ptnSense( noToCode( i ) ) == 1 ) { + code_disp = noToCode( i ); + break; + } + } + freeSNF(ptn, num); + + if( (code_disp == 0) && (efctPtnNum() > 0)) + code_disp = noToCode( ptnSqToNo(edlist.sqstart) ); + + chgEdCode( code_disp, ON ); + + resetEditMode( (UINT) (RES_MSG | RES_PROC | RES_SLCT | RES_RSV) ); +} diff --git a/cde/programs/dtudcfonted/ufontrsrc.h b/cde/programs/dtudcfonted/ufontrsrc.h new file mode 100644 index 00000000..cd9b5633 --- /dev/null +++ b/cde/programs/dtudcfonted/ufontrsrc.h @@ -0,0 +1,223 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* ufontrsrc.h 1.18 - Fujitsu source for CDEnext 96/10/30 13:13:44 */ +/* $XConsortium: ufontrsrc.h /main/9 1996/11/08 01:52:14 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +typedef struct _Resource { + char *mg_write_snf; + char *me_write_snf; + char *me_illegal_code; + char *me_non_memory; + char *mg_non_code; + char *me_illegal_srccode; + char *me_illegal_destcode; + char *me_nodelete_code; + char *me_wait; + char *me_non_srcfile; + + char *mn_no_font; + char *mn_plural_font; + char *mn_not_udc; + char *mn_no_mem; + char *mn_illegal_area; + char *mn_no_read; + char *mn_prop_font; + char *mn_saved_open; + char *mn_saved_exit; + char *mn_cpy_lost; + char *mn_no_perm; + + Boolean codepoint; + + char *l_font; + char *l_edit; + char *l_manage; + char *l_info; + char *l_open; + char *l_selectitem; + char *l_codeset; + char *l_style; + char *l_width; + char *l_height; + char *l_cancel; + char *l_copy; + char *l_overlay; + char *l_add; + char *l_delete; + char *l_open_w; + char *l_save; + char *l_exit; + char *l_manage_w; + char *l_xlfd; + char *l_codearea; + char *l_copy_w; + char *l_clear; + char *l_set; + char *l_reverse; + char *l_cut; + char *l_Copy; + char *l_paste; + char *l_roll; + char *l_updown_roll; + char *l_leftright_roll; + char *l_undo; + + char *l_manage_code; + char *l_copy_src_code; + char *l_copy_dest_code; + + char *l_ok; + + char *l_question_title; + char *l_warning_title; + char *l_error_title; + char *l_copy_title; + char *l_open_title; + char *l_add_title; + char *l_xlfd_title; + char *l_codearea_title; + + char *file_name; + char *xlfd_name; + char *codearea; + + char *l_do_save; + char *l_dont_save; + char *l_do_save_exit; + char *l_dont_save_exit; + + char *l_ptog; + char *l_ptog_cmd; + + char *mg_start_del_s; + char *mg_start_del_cs; + char *mg_start_del_m; + char *mg_start_del_cm; + + char *mg_register; + + char *l_code; + char *l_code_range; + + +/* CreateCaptionFrame() */ + Boolean capt_resize ; /* resizable: */ + int capt_lftoff ; /* leftOffset: */ + int capt_topoff ; /* topOffset: */ + int capt_rghoff ; /* RightOffset: */ + + Pixel pane_background; + Pixel pane_foreground; + Pixel background; + Pixel foreground; + +/* CreateMenuButtons() */ + Dimension menu_margin ; /* margin: */ + +/* CreateDialogAndButtons() */ + Boolean dia_tm_automng ; /* autoUnmanage: */ + Dimension dia_tm_width ; /* marginWidth: */ + Dimension dia_tm_height ; /* marginHeight: */ + Boolean dia_tm_resize ; /* noResize: */ + Boolean dia_tm_minimize ; /* minimizeButtons: */ + + Dimension dia_rw_width ; /* marginWidth: */ + Dimension dia_rw_height ; /* marginHeight: */ + Dimension dia_rw_spacing ; /* spacing: */ + +/* CreateDrawingArea() */ + Dimension draw_border ; /* borderWidth: */ + int draw_topoff ; /* topOffset: */ + int draw_lftoff ; /* leftOffset: */ + +/* PopupNotice() */ + Boolean pop_resize ; /* noResize: */ + Boolean pop_minimize ; /* minimizeButtons: */ + +/* CreateTemplateDialog() */ + Boolean temp_resize ; /* noResize: */ + Boolean temp_minimize ; /* minimizeButtons: */ + + Dimension temp_width ; /* width: */ + Dimension temp_height ; /* height: */ + +/* CreateMenuBarAndFooterMessageForm() */ + + int ed_bar_topoff ; /* topOffset: */ + int ed_bar_lftoff ; /* leftOffset: */ + int ed_bar_rghoff ; /* rightOffset: */ + + int ed_frm_btmoff ; /* bottomOffset: */ + int ed_frm_lftoff ; /* leftOffset: */ + int ed_frm_rghoff ; /* rightOffset: */ + + Dimension ed_msg_margintop ; /* marginTop: */ + Dimension ed_msg_marginbtm ; /* marginBottom: */ + + Dimension ed_mesg_margintop ; /* marginTop: */ + Dimension ed_mesg_marginbtm ; /* marginBottom: */ + + int ed_sep_btmoff ; /* bottomOffset: */ + int ed_sep_lftoff ; /* leftOffset: */ + int ed_sep_rghoff ; /* rightOffset: */ + Dimension ed_sep_margin ; /* margin: */ + + int ed_wge_topoff ; /* topOffset: */ + int ed_wge_lftoff ; /* leftOffset: */ + int ed_wge_rghoff ; /* rightOffset: */ + int ed_wge_btmoff ; /* bottomOffset: */ + +/* CreateFrame() */ + Boolean frame_resize ; /* resizable: */ + +/* CreateScrollBase() */ + Dimension scll_fr_width ; /* width: */ + + Dimension scll_fr_thick ; /* shadowThickness: */ + + int scll_bar_lftoff ; /* leftOffset: */ + + /* put data from resource database */ + char * exec_label ; + char * quit_label ; + + char * message ; + + char * code ; + char * previous ; + char * next ; + char * apply ; + + char * falerrmsg[26]; +} Resource; + + +/**********/ diff --git a/cde/programs/dtudcfonted/util.c b/cde/programs/dtudcfonted/util.c new file mode 100644 index 00000000..3447ec52 --- /dev/null +++ b/cde/programs/dtudcfonted/util.c @@ -0,0 +1,1179 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* util.c 1.22 - Fujitsu source for CDEnext 96/10/30 13:31:41 */ +/* $XConsortium: util.c /main/13 1996/11/08 01:56:34 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + + +#include +#include +#include +#include +#include + +#include "util.h" +#include "ufontrsrc.h" +#include "FaLib.h" + +extern Widget toplevel; +static void _destroy(); +void _unmap(); + +extern Resource resource ; + +#include "xpm.h" +#include "pixmaps/Pencil.pm" +#include "pixmaps/Line.pm" +#include "pixmaps/Rectangle.pm" +#include "pixmaps/Circle.pm" +#include "pixmaps/Eraser.pm" +#include "pixmaps/SelectArea.pm" + +#ifdef XPM +#define ReadXpm XpmCreatePixmapFromData +#else +#define ReadXpm _DtXpmCreatePixmapFromData +#endif +#define NUMPIX 6 + +#include "pixmaps/arrow.pm" + +/*ARGSUSED*/ +Widget +CreateCaptionFrame(owner, name, labelstr, type, thickness) +Widget owner; +String name; +String labelstr; +int type; +int thickness; +{ + Widget top, label, frame; + Arg args[20]; + int n; + XmString xmstr; + + n = 0; + top = XmCreateForm(owner, "form", args, n); + if (labelstr && *labelstr){ + xmstr = XmStringCreateLocalized(labelstr); + n = 0; + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNlabelString, xmstr); n++; + label = XmCreateLabelGadget(top, "label", args, n); + XtManageChild(label); + XmStringFree(xmstr); + + n = 0; + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; + XtSetArg(args[n], XmNtopWidget, label); n++; + } + else{ + n = 0; + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; + } + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNresizable, resource.capt_resize ); n++; + XtSetArg(args[n], XmNshadowType, type); n++; + XtSetArg(args[n], XmNshadowThickness , thickness); n++; + XtSetArg(args[n], XmNleftOffset, resource.capt_lftoff ); n++; + XtSetArg(args[n], XmNtopOffset, resource.capt_topoff ); n++; + XtSetArg(args[n], XmNrightOffset, resource.capt_rghoff ); n++; + frame = XmCreateFrame(top, "frame", args, n); + XtManageChild(frame); + XtManageChild(top); + return(frame); +} + +/* + * + * create pix button + * + */ + +Widget +CreatePixButton(owner, name, data) +Widget owner; +String name; +RadioButt *data; +{ + Arg args[20]; + int i, n; + Pixmap mask; + XpmAttributes attr; + Pixmap pix[NUMPIX]; + Widget top; + Display *disp; + Window root; + + disp = XtDisplay(owner); + root = DefaultRootWindow(disp); + + n = 0; + XtSetArg(args[n], XmNborderWidth, 1); n++; + XtSetArg(args[n], XmNradioAlwaysOne, TRUE); n++; + XtSetArg(args[n], XmNradioBehavior, TRUE); n++; + top = XmCreateRowColumn(owner, name, args, n); + + attr.valuemask = 0; + + ReadXpm(disp, root, Pencil, &pix[0], &mask, &attr); + ReadXpm(disp, root, Line, &pix[1], &mask, &attr); + ReadXpm(disp, root, Rectangle, &pix[2], &mask, &attr); + ReadXpm(disp, root, Circle, &pix[3], &mask, &attr); + ReadXpm(disp, root, Eraser, &pix[4], &mask, &attr); + ReadXpm(disp, root, SelectArea, &pix[5], &mask, &attr); + + for (i=0; i < NUMPIX; i++) { + n = 0; + XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++; + XtSetArg(args[n], XmNlabelPixmap, pix[i]); n++; + XtSetArg(args[n], XmNindicatorOn, False); n++; + XtSetArg(args[n], XmNshadowThickness, 2); n++; + XtSetArg(args[n], XmNfillOnSelect, False); n++; + XtSetArg(args[n], XmNset, data->items[i].set); n++; + XtSetArg(args[n], XmNwidth, 36); n++; + XtSetArg(args[n], XmNheight, 36); n++; + data->items[i].w = XmCreateToggleButton(top, data->items[i].name, args, n); + XtManageChild(data->items[i].w); + XtAddCallback(data->items[i].w, XmNvalueChangedCallback, + data->items[i].cb, data->items[i].clientdata); + } + XtManageChild(top); + return(top); +} + + +/* + * + * returns the value what the text field has + * + */ + +#ifdef _HPUX_SOURCE +String +#else +XtPointer +#endif +GetTextFieldValue(textf) +TextField *textf; +{ + char *s1, *s2, *s3; + if (textf->w2 == NULL) { + XtVaGetValues(textf->w1, XmNvalue, &s1, NULL); + return(s1); + } else { + if (XtIsSensitive(textf->w2)) { + XtVaGetValues(textf->w1, XmNvalue, &s1, NULL); + XtVaGetValues(textf->w2, XmNvalue, &s2, NULL); + s3 = (char *) XtMalloc(strlen(s1) + strlen(s2) + 2); + strcpy(s3, s1); + strcat(s3, "-"); + strcat(s3, s2); + XtFree(s1); + XtFree(s2); + return(s3); + } else { + XtVaGetValues(textf->w1, XmNvalue, &s1, NULL); + return(s1); + } + } +} + +/*ARGSUSED*/ +static void +arrow_change(w, data) +TextField *data; +{ + if (XtIsSensitive(data->w2)) { + XtSetSensitive(data->w2, False); + } else { + XtSetSensitive(data->w2, True); + } +} + +static Widget focus_widget=NULL; +extern char AreaStr[160]; +extern FalFontData fullFontData; + +static void +focus(w) +Widget w; +{ + focus_widget = w; +} + +static void +code_input() +{ + extern void CodeWindow(); + CodeWindow(focus_widget, fullFontData.xlfdname, False); +} + +/*ARGSUSED*/ +void +CreateTextField(owner, name, labelstr, data, maxlength) +Widget owner; +String name; +String labelstr; +TextField *data; +int maxlength; +{ + Widget row, label, arrow, textfield, code; + Arg args[20]; + register int n; + Display *disp; + Window root; + Pixmap mask; + XpmAttributes attr; + XmString xms; + extern Pixmap arrow_pix; + + n = 0; + XtSetArg(args[n], XmNorientation, (XtArgVal)XmHORIZONTAL); n++; + row = XmCreateRowColumn(owner, "row", args, n); + XtManageChild(row); + + n = 0; + xms = XmStringCreateLocalized(labelstr); + XtSetArg(args[n], XmNlabelString, xms); n++; + label = XmCreateLabelGadget(row, "label", args, n); + XtManageChild(label); + XmStringFree(xms); + + n = 0; + XtSetArg(args[n], XmNcolumns, maxlength); n++; + XtSetArg(args[n], XmNmaxLength, maxlength); n++; + data->w1 = focus_widget = textfield = + XmCreateText(row, "textField", args, n); + XtManageChild(textfield); + XtAddCallback(textfield, XmNfocusCallback, (XtCallbackProc)focus, NULL); + + if (! arrow_pix) { + disp = XtDisplay(row); + root = DefaultRootWindow(disp); + attr.valuemask = 0; + ReadXpm(disp, root, arrow_pm, &arrow_pix, &mask, &attr); + } + + n = 0; + XtSetArg(args[n], XmNlabelPixmap, arrow_pix); n++; + XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++; + XtSetArg(args[n], XmNindicatorOn, False); n++; + XtSetArg(args[n], XmNshadowThickness, 2); n++; + XtSetArg(args[n], XmNfillOnSelect, False); n++; + XtSetArg(args[n], XmNhighlightThickness, 0); n++; + arrow = XmCreateToggleButton(row, "arrow", args, n); + XtManageChild(arrow); + XtAddCallback(arrow, XmNvalueChangedCallback, + (XtCallbackProc)arrow_change, (XtPointer)data); + + n = 0; + XtSetArg(args[n], XmNcolumns, maxlength ); n++; + XtSetArg(args[n], XmNmaxLength, maxlength); n++; + data->w2 = textfield = XmCreateText(row, "textField", args, n); + XtManageChild(textfield); + XtSetSensitive(textfield, False); + XtAddCallback(textfield, XmNfocusCallback, (XtCallbackProc)focus, NULL); + + n = 0; + xms = XmStringCreateLocalized(resource.code) ; + XtSetArg(args[n], XmNlabelString, xms); n++; + XtSetArg(args[n], XmNhighlightThickness, 0); n++; + code = XmCreatePushButton(row, "Code", args, n); + XtManageChild(code); + XmStringFree(xms); + + XtAddCallback(code, XmNactivateCallback, + (XtCallbackProc)code_input, (XtPointer)textfield); +} + + +void +#if __STDC__ +CreateMenuButtons( Widget owner, Button *buttons, int buttons_cnt ) +#else +CreateMenuButtons( owner, buttons, buttons_cnt ) +Widget owner; +Button *buttons; +int buttons_cnt; +#endif +{ + Arg args[4]; + char buf[64]; + XmString xms; + int i, n; + +#define LABEL(x) (buttons->items[(x)].label) +#define NMNIC(x) (buttons->items[(x)].mnemonic) +#define SENS(x) (buttons->items[(x)].sensitive) + + buttons->w = (Widget *) malloc(sizeof(Widget)*buttons_cnt); + + if (buttons->w) { + for (i=0; iw[i] = + XmCreatePushButtonGadget(owner, "button", args, n); + if (buttons->items[i].cb){ + XtAddCallback(buttons->w[i], XmNactivateCallback, + buttons->items[i].cb, buttons->items[i].clientdata); + } + XmStringFree(xms); + } else{ + n = 0; + XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++; + XtSetArg(args[n], XmNmargin, resource.menu_margin ); n++; + buttons->w[i] = XmCreateSeparatorGadget(owner, + "separater", args, n); + } + XtManageChild(buttons->w[i]); + } + } +#undef LABEL +#undef NMNIC +#undef SENS +} + +static Atom +DeleteWindowAtom() +{ + static Atom delatom = 0; + if (! delatom){ + delatom = XInternAtom(XtDisplayOfObject(toplevel), + "WM_DELETE_WINDOW", False); + } + return(delatom); +} + +/*ARGSUSED*/ +Widget +#if __STDC__ +CreateDialogAndButtons( Widget owner, String name, + void (*delcb)(), Button *btns, int btns_cnt, Widget *pop ) +#else +CreateDialogAndButtons( owner, name, delcb, btns, btns_cnt, pop ) +Widget owner; +String name; +void (*delcb)(); +Button *btns; +int btns_cnt; +Widget *pop; +#endif +{ + int n; + Arg args[32]; + Arg arg[8]; + Widget rowcol; + XmString cs1, cs2, cs3; + + n = 0; + XtSetArg( args[n], XmNautoUnmanage, resource. dia_tm_automng ); n++; + XtSetArg( args[n], XmNmarginWidth, resource.dia_tm_width ); n++; + XtSetArg( args[n], XmNmarginHeight, resource.dia_tm_height ); n++; + if (btns->itemcnt > 0){ + cs1 = XmStringCreateLocalized(btns->items[0].label); + XtSetArg(args[n], XmNokLabelString, cs1); n++; + } + if (btns->itemcnt > 1){ + cs2 = XmStringCreateLocalized(btns->items[1].label); + XtSetArg(args[n], XmNcancelLabelString, cs2); n++; + } + if (btns->itemcnt > 2){ + cs3 = XmStringCreateLocalized(btns->items[2].label); + XtSetArg(args[n], XmNhelpLabelString, cs3); n++; + } + XtSetArg(args[n], XmNnoResize, resource.dia_tm_resize ); n++; + XtSetArg(args[n], XmNminimizeButtons, resource.dia_tm_minimize ); n++; + XtSetArg(args[n], XmNtitle, name ); n++; + *pop = XmCreateTemplateDialog(toplevel, "dialog", args, n); + if (delcb) + XmAddWMProtocolCallback(XtParent(*pop), + DeleteWindowAtom(), delcb, 0); + n = 0; + XtSetArg( arg[n], XmNmarginWidth, resource.dia_rw_width ); n++; + XtSetArg( arg[n], XmNmarginHeight, resource.dia_rw_height ); n++; + XtSetArg( arg[n], XmNspacing, resource.dia_rw_spacing ); n++; + XtSetArg( arg[n], XmNorientation, XmVERTICAL); n++; + rowcol = XmCreateRowColumn( *pop, "RowCol", arg, n); + XtManageChild(rowcol); + if (btns->itemcnt > 0){ + if (! btns->items[0].cb) + XtAddCallback(*pop, XmNokCallback, _unmap, 0); + XtAddCallback(*pop, XmNokCallback, btns->items[0].cb, + (btns->items[0].clientdata != NULL) ? btns->items[0].clientdata : 0); + } + if (btns->itemcnt > 1){ + if (! btns->items[1].cb) + XtAddCallback(*pop, XmNcancelCallback, _unmap, 0); + XtAddCallback(*pop, XmNcancelCallback, btns->items[1].cb, + (btns->items[1].clientdata != NULL) ? btns->items[1].clientdata : 0); + } + if (btns->itemcnt > 2){ + if (! btns->items[2].cb) + XtAddCallback(*pop, XmNhelpCallback, _unmap, 0); + XtAddCallback(*pop, XmNhelpCallback, btns->items[2].cb, + (btns->items[2].clientdata != NULL) ? btns->items[2].clientdata : 0); + } + n = 0; + XtSetValues(*pop, args, n); + if (btns->itemcnt == 1){ + XmStringFree(cs1); + } + else if (btns->itemcnt == 2){ + XmStringFree(cs1); + XmStringFree(cs2); + } + else if (btns->itemcnt == 3){ + XmStringFree(cs1); + XmStringFree(cs2); + XmStringFree(cs3); + } + return(rowcol); +} + + +/* Initialize GUI */ + +Widget +GuiInitialize(app, class_name, ac, av) +XtAppContext *app; +String class_name; +int *ac; +String av[]; +{ + Widget top; + + XtSetLanguageProc(NULL, NULL, NULL); + _DtEnvControl(0); + + top = XtAppInitialize(app, class_name, NULL,0, ac,av, NULL,NULL,0); + + return(top); +} + +Widget +CreateDrawingArea( owner, name, width, height, proc, val ) +Widget owner; +String name; +int width; +int height; +void (*proc)(); +int val; +{ + int n; + Arg arg[16]; + Widget drawarea; + + n = 0; + XtSetArg(arg[n], XmNwidth, width); n++; + XtSetArg(arg[n], XmNheight, height); n++; + XtSetArg(arg[n], XmNresizePolicy, XmRESIZE_NONE); n++; + XtSetArg(arg[n], XmNborderWidth, resource.draw_border); n++; + XtSetArg(arg[n], XmNbackground, resource.pane_background); n++; + XtSetArg(arg[n], XmNtopAttachment, (XtArgVal)XmATTACH_FORM); n++; + XtSetArg(arg[n], XmNleftAttachment, (XtArgVal)XmATTACH_FORM); n++; + XtSetArg(arg[n], XmNtopOffset, (XtArgVal)resource.draw_topoff); n++; + XtSetArg(arg[n], XmNleftOffset, (XtArgVal)resource.draw_lftoff); n++; + drawarea = XmCreateDrawingArea(owner, name, arg, n); + XtManageChild( drawarea ); + XtAddEventHandler(drawarea, ExposureMask, FALSE, proc, (XtPointer) (intptr_t) val); + return(drawarea); +} + + +#ifndef USE_MACRO + +void +AddLeftAttachWidget( w, ref, offset ) +Widget w; +Widget ref; +int offset; +{ + XtVaSetValues( w, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, ref, + XmNleftOffset, offset, + NULL); +} + +void +AddLeftAttachForm( w, offset ) +Widget w; +int offset; +{ + XtVaSetValues( w, + XmNleftAttachment, XmATTACH_FORM, + XmNleftOffset, offset, + NULL); +} + +void +AddTopAttachWidget( w, ref, offset ) +Widget w; +Widget ref; +int offset; +{ + XtVaSetValues( w, + XmNtopAttachment, XmATTACH_WIDGET, + XmNtopWidget, ref, + XmNtopOffset, offset, + NULL); +} + +void +AddTopAttachForm( w, offset ) +Widget w; +int offset; +{ + XtVaSetValues( w, + XmNtopAttachment, XmATTACH_FORM, + XmNtopOffset, offset, + NULL); +} + +void +AddRightAttachWidget( w, ref, offset ) +Widget w; +Widget ref; +int offset; +{ + XtVaSetValues( w, + XmNrightAttachment, XmATTACH_WIDGET, + XmNrightWidget, ref, + XmNrightOffset, offset, + NULL); +} + +void +AddRightAttachForm( w, offset ) +Widget w; +int offset; +{ + XtVaSetValues( w, + XmNrightAttachment, XmATTACH_FORM, + XmNrightOffset, offset, + NULL); +} + +void +AddBottomAttachForm( w, offset ) +Widget w; +int offset; +{ + XtVaSetValues( w, + XmNbottomAttachment, XmATTACH_FORM, + XmNbottomOffset, offset, + NULL); +} +#endif /* not USE_MACRO */ + +void +PopupDialog(w) +Widget w; +{ + if (! XtIsManaged(w)) + XtManageChild(w); + else + XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w))); +} + +void +PopdownDialog(w) +Widget w; +{ + if (XtIsManaged(w)){ + XtUnmanageChild(w); + } +} + +void +ForcePopdownDialog(w) +Widget w; +{ + if (XtIsManaged(w)){ + XtUnmanageChild(w); + } +} + +void +SetLabelString(w, str) +Widget w; +String str; +{ + XmString cs; + cs = XmStringCreateLocalized(str); + XtVaSetValues( w, XmNlabelString, cs, NULL); + XmStringFree( cs ); +} + +void +SetFooterString(w, str) +Widget w; +String str; +{ + XmString cs; + cs = XmStringCreateLocalized(str); + XtVaSetValues( w, XmNlabelString, cs, NULL); + XmStringFree( cs ); + XmUpdateDisplay(w); +} + + +/*********************************************************************** + create and pop up the confirmaiton window + **********************************************************************/ + +static Widget notice=NULL; + +static void +format_str(st, charcnt , str) +Widget st; +int charcnt ; +char *str; +{ + int i ; + char *s, *p; + static char buf[512]; + int lw; + int len ; + wchar_t wc ; + XmString cs; + + if (! str || ! *str) return; + + for( p=str, s=buf, lw=0; *p != 0; ){ + + if ( (*p == '\n') || (charcnt <= lw) ){ + *s = '\n'; /* new line */ + lw = 0; + s++; + } + if( (len = mbtowc( &wc, p, MB_CUR_MAX )) <= 0 ) break; + for( i=0; iitemcnt > 0){ + cs1 = XmStringCreateLocalized(button->items[0].label); + XtSetArg(args[n], XmNokLabelString, cs1); n++; + if (button->items[0].cb) + XtAddCallback(notice, XmNokCallback, button->items[0].cb, NULL); + cancel = XmMessageBoxGetChild(notice, XmDIALOG_CANCEL_BUTTON); + help = XmMessageBoxGetChild(notice, XmDIALOG_HELP_BUTTON); + } + if (button->itemcnt > 1){ + cs2 = XmStringCreateLocalized(button->items[1].label); + XtSetArg(args[n], XmNcancelLabelString, cs2); n++; + if (button->items[1].cb) + XtAddCallback(notice, XmNcancelCallback, button->items[1].cb, NULL); + } + if (button->itemcnt > 2){ + cs3 = XmStringCreateLocalized(button->items[2].label); + XtSetArg(args[n], XmNhelpLabelString, cs3); n++; + if (button->items[2].cb) + XtAddCallback(notice, XmNhelpCallback, button->items[2].cb, NULL); + XtAddCallback(help, XmNactivateCallback, (XtCallbackProc)_unmap, NULL); + } + XtSetValues(notice, args, n); + XtAddCallback(notice, XmNunmapCallback, (XtCallbackProc)_destroy, NULL); + if (button->itemcnt == 1){ + XmStringFree(cs1); + XtUnmanageChild(cancel); + XtUnmanageChild(help); + } + else if (button->itemcnt == 2){ + XmStringFree(cs1); + XmStringFree(cs2); + XtUnmanageChild(help); + } + else if (button->itemcnt == 3){ + XmStringFree(cs1); + XmStringFree(cs2); + XmStringFree(cs3); + } + + label = XmMessageBoxGetChild(notice, XmDIALOG_MESSAGE_LABEL); + + if (do_format) + format_str(label, 52, message); + else{ + cs1 = XmStringCreateLocalized(message); + XtVaSetValues(notice, + XmNmessageString, (XtArgVal) cs1, (String) 0); + XtVaSetValues(notice, + XmNmessageAlignment, XmALIGNMENT_CENTER, (String) 0); + XmStringFree(cs1); + } + XtManageChild(notice); + XBell(XtDisplayOfObject( toplevel ), 0); +} + + +/*ARGSUSED*/ +static void +_layout_centerEH(w, clientdata) +Widget w; +XtPointer clientdata; +{ + Widget *child; + int num; + Dimension bbw, mw, sw, cw; + + + XtVaGetValues(w, XmNchildren, &child, XmNnumChildren, &num, NULL); + XtVaGetValues(XtParent(w), + XmNwidth, &bbw, + XmNmarginWidth, &mw, + XmNshadowThickness, &sw, + NULL); + XtVaGetValues(child[0], XmNwidth, &cw, NULL); + XtVaSetValues(w, XmNwidth, ((int)bbw-2*((int)mw+(int)sw)), NULL); + XtVaSetValues(child[0], XmNx, + ((((int)bbw-2*((int)mw+(int)sw))-(int)cw)/2), NULL); +} + +/*ARGSUSED*/ +Widget +CreateTemplateDialog( w, message, type, button, title, pop ) +Widget w; +char *message; +unsigned char type; +NButton *button; +String title; +Widget *pop; +{ + int n; + Arg args[32]; + XmString cs, cs1=NULL, cs2=NULL, cs3=NULL; + Widget brtnb; + + n = 0; + cs = XmStringCreateLocalized(message); + XtSetArg(args[n], XmNnoResize, resource.temp_resize ); n++; + XtSetArg(args[n], XmNminimizeButtons, resource.temp_minimize ); n++; + XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++; + XtSetArg(args[n], XmNmessageString, cs); n++; + XtSetArg(args[n], XmNmessageAlignment, XmALIGNMENT_CENTER); n++; + XtSetArg(args[n], XmNtitle, title ); n++; + + if (button->itemcnt > 0){ + cs1 = XmStringCreateLocalized(button->items[0].label); + XtSetArg(args[n], XmNokLabelString, cs1); n++; + } + if (button->itemcnt > 1){ + cs2 = XmStringCreateLocalized(button->items[1].label); + XtSetArg(args[n], XmNcancelLabelString, cs2); n++; + } + if (button->itemcnt > 2){ + cs3 = XmStringCreateLocalized(button->items[2].label); + XtSetArg(args[n], XmNhelpLabelString, cs3); n++; + } + *pop = XmCreateTemplateDialog(w, "TemplateDialog", args, n); + if (button->itemcnt > 0 && button->items[0].cb) + XtAddCallback(*pop, XmNokCallback, button->items[0].cb, NULL); + if (button->itemcnt > 1 && button->items[1].cb) + XtAddCallback(*pop, XmNcancelCallback, button->items[1].cb, NULL); + if (button->itemcnt > 2 && button->items[2].cb) + XtAddCallback(*pop, XmNhelpCallback, button->items[2].cb, NULL); + + XmStringFree(cs); + if (cs1) XmStringFree(cs1); + if (cs2) XmStringFree(cs2); + if (cs3) XmStringFree(cs3); + + XtAddCallback(*pop, XmNunmapCallback, (XtCallbackProc)_destroy, NULL); + n = 0; + XtSetArg(args[n], XmNwidth, resource.temp_width ); n++; + XtSetArg(args[n], XmNheight, resource.temp_height ); n++; + brtnb = XmCreateBulletinBoard(*pop, "BulletinBo", args, n); + XtManageChild(brtnb); + XtAddEventHandler(brtnb, + StructureNotifyMask, True, (XtEventHandler)_layout_centerEH, NULL); + return(brtnb); +} + + + + +void +AddDeleteProc(w, delcb) +Widget w; +void (*delcb)(); +{ + Atom del = DeleteWindowAtom(); + XmAddWMProtocols( w, &del, 1); + XmAddWMProtocolCallback( w, del, delcb, NULL ); +} + +void +AddPopupProc(w, popupcb) +Widget w; +void (*popupcb)(); +{ + XtAddCallback(XtParent(w), XmNpopupCallback, popupcb, 0); +} + +void +AddDestroyProc(w, destroycb) +Widget w; +void (*destroycb)(); +{ + XtAddCallback(XtParent(w), XmNdestroyCallback, destroycb, 0); +} + +Widget +CreateMenuBarAndFooterMessageForm(owner, name, buttons, bcnt, pop, footer) +Widget owner; +String name; +MButton *buttons; +int bcnt; +Widget *pop; +Widget *footer; +{ + Widget menuBar, form; + Widget footerFrame, footerForm, footerLabel, sep, casBtn, baseForm; + XmString cs; + char buf[64]; + Arg arg[20]; + int n, i; + + n = 0; + XtSetArg( arg[n], XmNiconName, name ); n++; + XtSetArg( arg[n], XmNdeleteResponse, XmUNMAP ); n++; + XtSetArg( arg[n], XmNmwmFunctions, + (MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_CLOSE)); n++; + *pop = XtCreatePopupShell(name, applicationShellWidgetClass, owner, arg, n); + + n = 0; + XtSetArg( arg[n], XmNshowSeparator, True ); n++; + form = XmCreateMainWindow( *pop, "MainW", arg, n); + XtManageChild(form); + + n = 0; + menuBar = XmCreateMenuBar( form, "menuBar", arg, n); + XtManageChild(menuBar); + + n = 0; + baseForm = XmCreateForm( form, "wgeForm", arg, n); + XtManageChild(baseForm); + + for (i=0; iitems[i].menu = + XmCreatePulldownMenu(menuBar, "menu", arg, n); + n = 0; + if (strchr(buttons->items[i].label, buttons->items[i].mnemonic)){ + sprintf(buf, "%s", buttons->items[i].label); + }else{ + snprintf(buf, sizeof(buf), "%s(%s)", buttons->items[i].label, &(buttons->items[i].mnemonic)); + } + cs = XmStringCreateLocalized(buf); + XtSetArg(arg[n],XmNmnemonic, buttons->items[i].mnemonic ); n++; + XtSetArg(arg[n],XmNlabelString, cs ); n++; + XtSetArg(arg[n],XmNsubMenuId, buttons->items[i].menu ); n++; + casBtn = XmCreateCascadeButton( menuBar, "casBtnA", arg, n); + XtManageChild(casBtn); + XmStringFree(cs); + } + + n = 0; + XtSetArg( arg[n], XmNshadowType, XmSHADOW_IN ); n++; + footerFrame = XmCreateFrame( form, "footerFrame", arg, n); + XtManageChild(footerFrame); + XtVaSetValues(form, XmNmessageWindow, footerFrame, NULL); + + n = 0; + XtSetArg( arg[n], XmNtopAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNleftAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNrightAttachment, XmATTACH_FORM); n++; + footerForm = XmCreateForm( footerFrame, "footerForm", arg, n); + XtManageChild(footerForm); + + n = 0; + cs = XmStringCreateLocalized(resource.message); + XtSetArg( arg[n], XmNlabelString, cs); n++; + XtSetArg( arg[n], XmNtopAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNleftAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNmarginTop, resource.ed_msg_margintop ); n++; + XtSetArg( arg[n], XmNmarginBottom, resource.ed_msg_marginbtm ); n++; + footerLabel = XmCreateLabel(footerForm, "Message", arg,n); + XtManageChild(footerLabel); + XmStringFree(cs); + + n = 0; + cs = XmStringCreateLocalized(""); + XtSetArg( arg[n], XmNtopAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNrightAttachment, XmATTACH_FORM); n++; + XtSetArg( arg[n], XmNleftAttachment, XmATTACH_WIDGET); n++; + XtSetArg( arg[n], XmNleftWidget, footerLabel); n++; + XtSetArg( arg[n], XmNalignment, XmALIGNMENT_BEGINNING); n++; + XtSetArg( arg[n], XmNmarginTop, resource.ed_mesg_margintop ); n++; + XtSetArg( arg[n], XmNmarginBottom, resource.ed_mesg_marginbtm ); n++; + XtSetArg( arg[n], XmNlabelString, cs); n++; + *footer = XmCreateLabelGadget(footerForm, "MessageG", arg, n); + XtManageChild(*footer); + XmStringFree(cs); + + return(baseForm); +} + +Widget +GetMenuWidget( buttons, buttons_num ) +MButton *buttons; +int buttons_num; +{ + return(buttons->items[buttons_num].menu); +} + +Widget +CreateForm( owner, name ) +Widget owner; +String name; +{ + Widget form; + int n; + Arg arg[8]; + + n=0; + form = XmCreateForm( owner, name, arg, n ); + XtManageChild(form); + return(form); +} + +/*ARGSUSED*/ +Widget +CreateLabel( owner, name, str ) +Widget owner; +String name; +String str; +{ + Widget label; + Arg arg[2]; + int n=0; + XmString cs = XmStringCreateLocalized(str); + XtSetArg( arg[n], XmNlabelString, cs); n++; + label = XmCreateLabel( owner, "label", arg, n); + XtManageChild(label); + return(label); +} + + +/*ARGSUSED*/ +Widget +CreateFrame(owner, name, type, thickness) +Widget owner; +String name; +XtPointer type; +XtPointer thickness; +{ + Widget frame; + Arg args[20]; + int n; + + n = 0; + XtSetArg(args[n], XmNresizable, resource.frame_resize ); n++; + XtSetArg(args[n], XmNshadowType, type); n++; + XtSetArg(args[n], XmNshadowThickness , thickness); n++; + frame = XmCreateFrame(owner, "frame", args, n); + XtManageChild(frame); + return(frame); +} + +/*ARGSUSED*/ +Widget +CreateRowColumn(owner, name, layout, space, marginw, marginh) +Widget owner; +String name; +int layout; +int space; +int marginw; +int marginh; +{ + Widget rc; + Arg args[20]; + int n; + + n = 0; + XtSetArg(args[n], XmNorientation, layout); n++; + XtSetArg(args[n], XmNspacing, space); n++; + XtSetArg(args[n], XmNmarginWidth, marginw); n++; + XtSetArg(args[n], XmNmarginHeight, marginh); n++; + rc = XmCreateRowColumn(owner, "rowColumn", args, n); + XtManageChild(rc); + return(rc); +} + +/*ARGSUSED*/ +Widget +CreateScrollBar( owner, name, height, val, min, max, proc ) +Widget owner; +String name; +int height; +int val; +int min; +int max; +void (*proc)(); +{ + Widget sc; + int n; + Arg arg[16]; + + n = 0; + XtSetArg( arg[n], XmNsliderSize, (XtArgVal)val ); n++; + XtSetArg( arg[n], XmNpageIncrement, (XtArgVal)val ); n++; + XtSetArg( arg[n], XmNmaximum, (XtArgVal)max ); n++; + + sc = XmCreateScrollBar(owner, "wgeScro", arg, n); + XtManageChild( sc ); + XtAddCallback( sc, XmNvalueChangedCallback, proc, NULL ); + return(sc); +} + + +/*ARGSUSED*/ +static void +_scbase_cb( w, proc, calldata ) +Widget w; +void (*proc)(); +XmScrollBarCallbackStruct *calldata; +{ + (*proc)(calldata->value); +} + +Widget +CreateScrollBase( owner, name, min, max, val, vcnt, sbproc ) +Widget owner; +String name; +int min; +int max; +int val; +int vcnt; +void (*sbproc)(); +{ + int n; + Arg arg[16]; + Widget base, frame, rwclm, sc; + + n=0; + XtSetArg( arg[n], XmNwidth, resource.scll_fr_width ); n++; + base = XmCreateForm( owner, name, arg, n ); + XtManageChild( base ); + n=0; + XtSetArg( arg[n], XmNshadowType, XmSHADOW_IN ); n++; + XtSetArg( arg[n], XmNshadowThickness, resource.scll_fr_thick ); n++; + XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM ); n++; + frame = XmCreateFrame( base, name, arg, n ); + XtManageChild( frame ); + n=0; + rwclm = XmCreateRowColumn( frame, name, arg, n ); + XtManageChild( rwclm ); + if (vcnt < (max-min)){ + n=0; + XtSetArg( arg[n], XmNsliderSize, vcnt ); n++; + XtSetArg( arg[n], XmNminimum, min ); n++; + XtSetArg( arg[n], XmNmaximum, max ); n++; + XtSetArg( arg[n], XmNvalue, val ); n++; + XtSetArg( arg[n], XmNleftAttachment, XmATTACH_WIDGET ); n++; + XtSetArg( arg[n], XmNleftWidget, rwclm ); n++; + XtSetArg( arg[n], XmNleftOffset, resource.scll_bar_lftoff ); n++; + XtSetArg( arg[n], XmNtopAttachment, XmATTACH_FORM ); n++; + XtSetArg( arg[n], XmNbottomAttachment, XmATTACH_FORM ); n++; + sc = XmCreateScrollBar( base, name, arg, n ); + XtManageChild( sc ); + XtAddCallback( sc, XmNvalueChangedCallback, + (XtCallbackProc)_scbase_cb, (XtPointer)sbproc); + } + return( rwclm ); +} diff --git a/cde/programs/dtudcfonted/util.h b/cde/programs/dtudcfonted/util.h new file mode 100644 index 00000000..d81f4545 --- /dev/null +++ b/cde/programs/dtudcfonted/util.h @@ -0,0 +1,267 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* util.h 1.5 - Fujitsu source for CDEnext 96/09/18 13:59:22 */ +/* $XConsortium: util.h /main/5 1996/09/19 19:42:11 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +extern Widget GetMenuWidget(); +extern Widget CreateFrame(); +extern Widget CreateControlArea(); +extern Widget CreateScrollBar(); +extern Widget CreateDrawingArea(); +extern Widget CreateExclusive(); +extern Widget CreateLabel(); +extern Widget CreateDialogAndButtons(); +extern +#ifdef _HPUX_SOURCE +String +#else +XtPointer +#endif +GetTextFieldValue(); +extern Widget CreateTemplateDialog(); +extern Widget CreateScrollBase(); +extern Widget CreateForm(); + +#include +#include + +Widget CreateCaptionFrame(); +#ifdef _HPUX_SOURCE +String +#else +XtPointer +#endif +GetTextFieldValue(); +void CreateTextField(); +void CreateButtons(); +void CreateMenuButtons(); +void LayoutButtonsEH(); +Widget CreateLayoutButtons(); +Widget CreateDialogAndButtons(); +Widget GuiInitialize(); +Widget CreateDrawingArea(); +void AddTopWidget(); +void AddLeftAttachWidget(); +void AddLeftAttachForm(); +void AddTopAttachWidget(); +void AddTopAttachForm(); +void AddRightAttachWidget(); +void AddRightAttachForm(); +void AddBottomAttachForm(); +void PopupDialog(); +void PopdownDialog(); +void ForcePopdownDialog(); +void SetLabelString(); +void SetFooterString(); +void PopupNotice(); +void AddDeleteProc(); +Widget CreateMenuBarAndFooterMessageForm(); +Widget GetMenuWidget(); +Widget CreateForm(); +Widget CreateLabel(); +Widget CreateFrame(); +Widget CreateRowColumn(); +Widget CreateScrollBar(); + + +#define MarginWidth 4 +#define RowMarginWidth 11 +#define MarginHeight 11 +#define HeightSpace 4 +#define MinimumSpace 4 + +/***** Exclusive Set *****/ + +typedef struct _ToggleButt { + Widget w; + char * label; + XtPointer clientdata; + String name; + XtArgVal sensitive; + XtCallbackProc cb; + XtArgVal set; +} ToggleButt; + +#define EXARGS( clientdata, name, sensitive, cb, set ){ \ + NULL, \ + (char *) "", \ + (XtPointer) clientdata, \ + name, \ + (XtArgVal) sensitive, \ + (XtCallbackProc) cb, \ + (XtArgVal) set \ +} + +typedef struct _RadioButt { + String label; + ToggleButt *items; + int items_cnt; + String name; + Widget w; + XtPointer udata; +} RadioButt; + + +#define EXCLUSIVE(a) { 0, a, XtNumber(a), 0, 0, 0 } + +#define ExclusiveItems ToggleButt +#define Exclusive RadioButt + +#define SetItemLabel(b,n,l) (b)->items[(n)].label = (l) + +/***** PushButton Set *****/ + +typedef struct _ButtonItems { + char * label; + XtCallbackProc cb; + XtPointer clientdata; + XtArgVal mnemonic; + XtArgVal sensitive; + XtArgVal deflt; +} ButtonItems; + +#define BTNARGS( cb, clientdata, mnumonic, sensitive, deflt ) { \ + (char *) "", \ + (XtCallbackProc) cb, \ + (XtPointer) clientdata, \ + (XtArgVal) mnumonic, \ + (XtArgVal) sensitive, \ + (XtArgVal) deflt \ +} + +typedef struct _Button { + Widget *w; + ButtonItems *items; + int itemcnt; +} Button; + +#define BUTTONS( items ) { 0, items, XtNumber(items) } + +/***** MenuButton Set *****/ + +typedef struct _menuButtonItems { + char *label; + char mnemonic; + Widget menu; +} menuButtonItems; + +#define MENUBTNARGS( mnumonic ) { \ + "", \ + mnumonic, \ + NULL, \ +} + +typedef struct _MButton { + menuButtonItems *items; + int itemcnt; +} MButton; + +#define MBUTTONS(items) {items,XtNumber((items))} + + +/***** NoticeButton Set *****/ + +typedef struct _NoticeButton { + char *label; + void (*cb)(); +} NoticeButton; + +#define NBTNARGS( cb, clientdata, mnumonic, sensitive, deflt) { \ + "", \ + cb, \ +} + +typedef struct _NButton { + NoticeButton *items; + int itemcnt; +} NButton; + +#define NBUTTONS(items) {items,XtNumber((items))} + + +/***** TextField Set *****/ + +typedef struct _TextField { + Widget w1; + Widget w2; + String label; +} TextField; + + +/***** Function Type *****/ + +#define D_WARNING XmDIALOG_WARNING +#define D_QUESTION XmDIALOG_QUESTION +#define D_ERROR XmDIALOG_ERROR +#define D_TEMPLATE XmDIALOG_TEMPLATE +#define L_VERTICAL XmVERTICAL +#define L_HORIZONTAL XmHORIZONTAL + + +#ifdef USE_MACRO +#define AddLeftAttachWidget( w, ref, offset ) XtVaSetValues( w, \ + XmNleftAttachment, XmATTACH_WIDGET, \ + XmNleftWidget, ref, \ + XmNleftOffset, offset, \ + 0) + +#define AddLeftAttachForm( w, offset ) XtVaSetValues( w, \ + XmNleftAttachment, XmATTACH_FORM, \ + XmNleftOffset, offset, \ + 0) + +#define AddTopAttachWidget( w, ref, offset ) XtVaSetValues( w, \ + XmNtopAttachment, XmATTACH_WIDGET, \ + XmNtopWidget, ref, \ + XmNtopOffset, offset, \ + 0) + +#define AddTopAttachForm( w, offset ) XtVaSetValues( w, \ + XmNtopAttachment, XmATTACH_FORM, \ + XmNtopOffset, offset, \ + 0) + +#define AddRightAttachWidget( w, ref, offset ) XtVaSetValues( w, \ + XmNrightAttachment, XmATTACH_WIDGET, \ + XmNrightWidget, ref, \ + XmNrightOffset, offset, \ + 0) + +#define AddRightAttachForm( w, offset ) XtVaSetValues( w, \ + XmNrightAttachment, XmATTACH_FORM, \ + XmNrightOffset, offset, \ + 0) + +#define AddBottomAttachForm( w, offset ) XtVaSetValues( w, \ + XmNbottomAttachment, XmATTACH_FORM, \ + XmNbottomOffset, offset, \ + 0) +#endif /* USE_MACRO */ diff --git a/cde/programs/dtudcfonted/xoakufont.h b/cde/programs/dtudcfonted/xoakufont.h new file mode 100644 index 00000000..8ff359d3 --- /dev/null +++ b/cde/programs/dtudcfonted/xoakufont.h @@ -0,0 +1,404 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* xoakufont.h 1.4 - Fujitsu source for CDEnext 96/05/30 11:20:56 */ +/* $XConsortium: xoakufont.h /main/4 1996/06/25 20:17:03 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#include "fssxeg.h" + +extern Widget CreateOblB(); +extern Widget CreateOblBG(); +extern Widget CreateToglBG(); +extern Widget CreateToglB(); +extern Widget CreateRecBG(); +extern Widget CreateRecB(); +extern Widget CreateCapt(); +extern Widget CreateCaptG(); +extern Widget CreateLabelG(); +extern Widget CreateLabel(); +extern void SetString(); + +extern int readSNF(); +extern int writeSNF(); +extern int ptnClose(); +extern int ptnAdd(); +extern int ptnGet(); +extern int ptnSense(); +extern int ptnDel(); +extern int GetInfo(); +extern int ptnSqToNo(); +extern int ptnNoToSq(); +extern int noToCode(); +extern int noToCode2(); +extern int codeToNo(); +extern int codeToNo2(); +extern int codeCheck(); +extern int codeCheck2(); +extern void bitSetInfo(); +extern void bitSet(); +extern void bitReset(); +extern int bitRead(); +extern void bitPtnClear(); +extern void bitPtnCopy(); +extern int bitDrawLine(); +extern int bitDrawRect(); +extern int bitDrawCls(); +extern int bitDrawSet(); +extern int bitDrawRev(); +extern int bitDrawCpy(); +extern int bitDrawMov(); +extern int bitDrawRoll(); +extern int bitDrawSymV(); +extern int bitDrawSymH(); + +#define D_MAX 10 + +#define SetString(w,s) UpdateMessage((s)) + +#define PROC_POINT 0 +#define PROC_LINE 1 +#define PROC_RECT 2 +#define PROC_CLS 3 +#define PROC_SET 4 +#define PROC_REV 5 +#define PROC_CUT 6 +#define PROC_CPY 7 +#define PROC_PASTE 8 +#define PROC_ROLL 9 +#define PROC_SYMV 10 +#define PROC_SYMH 11 +#define PROC_CIRCLE 12 +#define PROC_ERASE 13 +#define PROC_SELECT 14 + +#define RES_MSG (1L<<0) +#define RES_PROC (1L<<1) +#define RES_SLCT (1L<<2) +#define RES_RSV (1L<<3) + + +#define CPY_COPY 0 +#define CPY_OVERLAY 1 + + +#define CODE_ADD 0 +#define CODE_DEL 1 + +#define SET_CDSET1 0 +#define SET_CDSET3 1 + + +#define SET_NORMAL_U90_G1 0 +#define SET_NORMAL_G1 1 +#define SET_SYSTEM_G1 2 +#define SET_NORMAL 3 +#define SET_JEF 4 +#define SET_SYSTEM 5 + + + +#define MG_MAXSIZE 100 + + + +#ifdef DEBUG +#define Dprintf2 printf +#define Dprintf printf +#else +#define Dprintf2 +#define Dprintf +#endif + + +/********************************************************************** + structure + **********************************************************************/ + +/* editting character */ +typedef struct _EditChar { + FalFontData *fdata; + int width; + int height; + int code; + int ncode; + char ptn[MAXPTNBYTE]; + char flag; + +} EditChar; + +/* character list */ +typedef struct _EditList { + int nlist; + int statloc; + int slctloc; + int nptn; + int sqstart; + Dimension list_h; + Dimension elem_w; + Dimension elem_h; + Pixel back; + Pixel border; +} EditList; + +/* editting pane */ +typedef struct _EditPane { + int width; + int height; + int pix_w; + int pix_h; + int color; + int obj; + Pixel back; + Pixel border; +} EditPane; + +/* X library */ +typedef struct _XlibInf { + Display *display; + Window root_winID; + Window edit_winID; + Window disp_winID; + Window list_winID; /* 1995.10.02 */ + GC borderGC; + GC backGC; + GC rubGC; + GC dashGC; + XImage *dispImage; +} XlibInf; + + +typedef struct _DelInf { + Dimension elem_w; + Dimension elem_h; + Dimension ptn_w; + Dimension ptn_h; + Dimension list_h; + int s_ncode; + int e_ncode; + int sq_top; + int sq_start; + int sq_end; + int disp_num; +} DelInf; + +/* X library */ +typedef struct _DelPtnInf { + Window disp_winID; + XImage *dispImage; + char ptn[MAXPTNBYTE]; +} DelPtnInf; + +/* editting pattern */ +typedef struct _EditPtnInf { + char drag_f; + int adj_px; + int adj_py; + int proc; + char slct_f; + int src1_px; + int src1_py; + int src2_px; + int src2_py; + int dest_px; + int dest_py; + char rsv_f; + char rsv_ptn[MAXPTNBYTE]; +} EditPtnInf; + +/* copy patterns */ +typedef struct _CopyPtnInf { +/* int size;*/ + FalFontData *fdata; + int s1_code; + int s2_code; + int d1_code; + int proc; +} CopyPtnInf; + +/* fonts */ +typedef struct _FontInf { + int num; + FalFontDataList *lp; + Widget *RecB; +} FontInf; + +/********************************************************************** + + + **********************************************************************/ + +#ifdef substance_source +#define ex +#define I(x) =(x) +#else +#define ex extern +#define I(x) +#endif /* substance_source */ + +ex Widget toplevel I(NULL); + +ex Widget editPtnW I(NULL); +ex Widget cpyPtnW I(NULL); +ex Widget mngPtnW I(NULL); + +ex EditChar edg +#ifdef substance_source +={ 0,0,0,0,0,0,0, OFF } +#endif /* substance_source */ +; +ex EditList edlist +#ifdef substance_source + ={ EDLIST_MAX, 0,0,0,0,0,0,0,0,0 } +#endif /* substance_source */ +; +EditPane edpane +#ifdef substance_source + ={ EDPANE_SIZE, EDPANE_SIZE, 0,0,0,0,0,0 } +#endif /* substance_source */ +; +ex XlibInf xl; +ex DelInf dn +#ifdef substance_source + ={ 0,0,0,0,0,0,0,0,0,0,0 } +#endif /* substance_source */ +; +ex DelPtnInf dl[D_MAX] ; +ex DelPtnInf dl_glyph[EDLIST_MAX] ; /* add dl_disp 1995.09.20 */ +ex int sq_disp[EDLIST_MAX] ; /* add sq_disp 1995.09.20 */ + +ex EditPtnInf em +#ifdef substance_source + ={ OFF,0,0,0,0,0,0,0,0,0,0,0,0,0 } +#endif /* substance_source */ +; +ex CopyPtnInf cpm +#ifdef substance_source + ={ 0,0,0,0,0 } +#endif /* substance_source */ +; + +#undef ex +#undef I + + +/* + * resources for font editor + */ + +#include"ufontrsrc.h" /* 1995.06.28 H.Chiba */ + + +/*Resource resource; del 1995.05.30 H.Chiba BSC */ + + +#ifdef substance_source /* add 1995.06.29 H.Chiba -> */ + + +/* CreateCaptionFrame() */ +Boolean capt_resize = True ; /* resizable: */ +int capt_lftoff = 2 ; /* leftOffset: */ +int capt_topoff = 2 ; /* topOffset: */ +int capt_rghoff = 2 ; /* rightOffset: */ + +Pixel pane_background; +Pixel pane_foreground; + +/* CreateMenuButtons() */ +Dimension menu_margin = 0 ; /* margin: */ + +/* CreateDialogAndButtons() */ +Boolean dia_tm_automng = False ; /* autoUnmanage: */ +Dimension dia_tm_width = 4 ; /* marginWidth: */ +Dimension dia_tm_height = 4 ; /* marginHeight: */ +Boolean dia_tm_resize = True ; /* noResize: */ +Boolean dia_tm_minimize = True ; /* minimizeButtons: */ + +Dimension dia_rw_width = 6 ; /* marginWidth: */ +Dimension dia_rw_height = 6 ; /* marginHeight: */ +Dimension dia_rw_spacing = 4 ; /* spacing: */ + +/* CreateDrawingArea() */ +Dimension draw_border = 1 ; /* borderWidth: */ +int draw_topoff = 2 ; /* topOffset: */ +int draw_lftoff = 2 ; /* leftOffset: */ + +/* PopupNotice() */ +Boolean pop_resize = True ; /* noResize: */ +Boolean pop_minimize = True ; /* minimizeButtons: */ + +/* CreateTemplateDialog() */ +Boolean temp_resize = True ; /* noResize: */ +Boolean temp_minimize = True ; /* minimizeButtons: */ + +Dimension temp_width = 1 ; /* width: */ +Dimension temp_height = 1 ; /* height: */ + +/* CreateMenuBarAndFooterMessageForm() */ +#if 0 +ed_functions = ( MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | MWM_FUNC_CLOSE ) ;/* mwmFunctions: */ +#endif + +int ed_bar_topoff = 1 ; /* topOffset: */ +int ed_bar_lftoff = 1 ; /* leftOffset: */ +int ed_bar_rghoff = 1 ; /* rightOffset: */ + +int ed_frm_btmoff = 3 ; /* bottomOffset: */ +int ed_frm_lftoff = 3 ; /* leftOffset: */ +int ed_frm_rghoff = 3 ; /* rightOffset: */ + +Dimension ed_msg_margintop = 3 ; /* marginTop: */ +Dimension ed_msg_marginbtm = 3 ; /* marginBottom: */ + +Dimension ed_mesg_margintop = 3 ; /* marginTop: */ +Dimension ed_mesg_marginbtm = 3 ; /* marginBottom: */ + +int ed_sep_btmoff = 3 ; /* bottomOffset: */ +int ed_sep_lftoff = 0 ; /* leftOffset: */ +int ed_sep_rghoff = 0 ; /* rightOffset: */ +Dimension ed_sep_margin = 0 ; /* margin: */ + +int ed_wge_topoff = 10 ; /* topOffset: */ +int ed_wge_lftoff = 10 ; /* leftOffset: */ +int ed_wge_rghoff = 10 ; /* rightOffset: */ +int ed_wge_btmoff = 10 ; /* bottomOffset: */ + +/* CreateFrame() */ +Boolean frame_resize = False ; /* resizable: */ + +/* CreateScrollBase() */ +Dimension scll_fr_width = 500 ; /* width: */ + +Dimension scll_fr_thick = 2 ; /* shadowThickness: */ + +int scll_bar_lftoff = 4 ; /* leftOffset: */ + +#endif /* substance_source */ /* -> add 1995.06.29 H.Chiba */ + +/**********/ diff --git a/cde/programs/dtudcfonted/xutil.c b/cde/programs/dtudcfonted/xutil.c new file mode 100644 index 00000000..d6646846 --- /dev/null +++ b/cde/programs/dtudcfonted/xutil.c @@ -0,0 +1,83 @@ +/* + * CDE - Common Desktop Environment + * + * Copyright (c) 1993-2012, The Open Group. All rights reserved. + * + * These libraries and programs are free software; you can + * redistribute them and/or modify them under the terms of the GNU + * Lesser General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * These libraries and programs are distributed in the hope that + * they will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with these libraries and programs; if not, write + * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301 USA + */ +/* xutil.c 1.2 - Fujitsu source for CDEnext 96/02/29 17:30:54 */ +/* $XConsortium: xutil.c /main/2 1996/04/08 16:03:37 cde-fuj $ */ +/* + * (c) Copyright 1995 FUJITSU LIMITED + * This is source code modified by FUJITSU LIMITED under the Joint + * Development Agreement for the CDEnext PST. + * This is unpublished proprietary source code of FUJITSU LIMITED + */ + + + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "selectxlfd.h" +#include "xoakufont.h" + +/* + * parameters + */ +void xlfdPopupDialog() ; + +extern int getmask ; + +extern Widget toplevel ; +extern Widget slctBLabel[BUTTONITEMS], + slctBText[BUTTONITEMS], slctButton[BUTTONITEMS], + listPop[BUTTONITEMS], listW[BUTTONITEMS], errorMD, msgBox ; + +/**************************************************************** + * common functions +****************************************************************/ + + +/* + * pop up and down dialog box + */ + +void +xlfdPopupDialog(w) +Widget w; +{ + if (! XtIsManaged(w)) + XtManageChild(w); + else + XRaiseWindow(XtDisplayOfObject(w), XtWindow(XtParent(w))); +} diff --git a/cde/programs/localized/templates/app-defaults.tmpl b/cde/programs/localized/templates/app-defaults.tmpl index 57e46d58..6b03d380 100644 --- a/cde/programs/localized/templates/app-defaults.tmpl +++ b/cde/programs/localized/templates/app-defaults.tmpl @@ -28,6 +28,7 @@ OBJS = \ Dtmail \ Dtbuilder \ Dtinfo \ + Dtudcfonted \ Dt all:: $(OBJS) @@ -50,6 +51,7 @@ LinkFile(Dtterm.nls,$(CDESRC)/dtterm/Dtterm.ad) LinkFile(Dtmail.nls,$(CDESRC)/dtmail/dtmail/Dtmail) LinkFile(Dtbuilder.nls,$(CDESRC)/dtappbuilder/src/ab/Dtbuilder.ad) LinkFile(Dtinfo.nls,$(CDESRC)/dtinfo/dtinfo/src/Dtinfo) +LinkFile(Dtudcfonted.nls,$(CDESRC)/dtudcfonted/resource/Dtudcfonted) LinkFile(Dt.nls,$(DTSVCSRC)/DtUtil2/Dt.ad) DtstyleDescRule(Dthelpview,Dthelpview) @@ -70,6 +72,7 @@ DtstyleDescRule(Dtterm,Dtterm) DtstyleDescRule(Dtmail,Dtmail) DtstyleDescRule(Dtbuilder,Dtbuilder) DtstyleDescRule(Dtinfo,Dtinfo) +DtstyleDescRule(Dtudcfonted,Dtudcfonted) DtstyleDescRule(Dt,Dt) depend:: diff --git a/cde/programs/localized/templates/msg.C.tmpl b/cde/programs/localized/templates/msg.C.tmpl index 1eda3809..453cf195 100644 --- a/cde/programs/localized/templates/msg.C.tmpl +++ b/cde/programs/localized/templates/msg.C.tmpl @@ -52,6 +52,8 @@ OBJS= \ dtterm.cat \ dttypes.cat \ dtwm.cat \ + dtudcexch.cat \ + dtudcfonted.cat \ libdtcm.cat \ libDtMail.cat @@ -103,6 +105,8 @@ LinkFile(dtstyle.msg,$(CDESRC)/dtstyle/dtstyle.msg) LinkFile(dtterm.msg,$(CDESRC)/dtterm/dtterm.msg) LinkFile(dttypes.msg,$(CDESRC)/util/dttypes/dttypes.msg) LinkFile(dtwm.msg,$(CDESRC)/dtwm/dtwm.msg) +LinkFile(dtudcexch.msg,$(CDESRC)/dtudcexch/dtudcexch.msg) +LinkFile(dtudcfonted.msg,$(CDESRC)/dtudcfonted/dtudcfonted.msg) LinkFile(libABil.msg,$(CDESRC)/dtappbuilder/src/libABil/libABil.msg) LinkFile(libABobjXm.msg,$(CDESRC)/dtappbuilder/src/libABobjXm/libABobjXm.msg) LinkFile(libAButil.msg,$(CDESRC)/dtappbuilder/src/libAButil/libAButil.msg) diff --git a/cde/programs/localized/templates/msg.el_GR.UTF-8.tmpl b/cde/programs/localized/templates/msg.el_GR.UTF-8.tmpl index 42260bce..72c3700c 100644 --- a/cde/programs/localized/templates/msg.el_GR.UTF-8.tmpl +++ b/cde/programs/localized/templates/msg.el_GR.UTF-8.tmpl @@ -58,6 +58,8 @@ OBJS= \ dtterm.cat \ dttypes.cat \ dtwm.cat \ + dtudcexch.cat \ + dtudcfonted.cat \ libdtcm.cat \ libDtMail.cat @@ -112,6 +114,8 @@ LinkFile(dtstyle.msg,$(CDESRC)/dtstyle/dtstyle.msg) LinkFile(dtterm.msg,$(CDESRC)/dtterm/dtterm.msg) LinkFile(dttypes.msg,$(CDESRC)/util/dttypes/dttypes.msg) LinkFile(dtwm.msg,$(CDESRC)/dtwm/dtwm.msg) +LinkFile(dtudcexch.msg,$(CDESRC)/dtudcexch/dtudcexch.msg) +LinkFile(dtudcfonted.msg,$(CDESRC)/dtudcfonted/dtudcfonted.msg) LinkFile(libABil.msg,$(CDESRC)/dtappbuilder/src/libABil/libABil.msg) LinkFile(libABobjXm.msg,$(CDESRC)/dtappbuilder/src/libABobjXm/libABobjXm.msg) LinkFile(libAButil.msg,$(CDESRC)/dtappbuilder/src/libAButil/libAButil.msg)