Don't use fstat for readable pipe chars in dtexec.
[oweals/cde.git] / cde / programs / dtudcexch / udcimp.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: udcimp.c /main/4 1996/09/02 18:51:02 cde-fuj $ */
24 /*
25  *  (c) Copyright 1995 FUJITSU LIMITED
26  *  This is source code modified by FUJITSU LIMITED under the Joint
27  *  Development Agreement for the CDEnext PST.
28  *  This is unpublished proprietary source code of FUJITSU LIMITED
29  */
30
31 #include "excutil.h"
32 #include "FaLib.h"
33 void addcharptn();
34 void setcodelists();
35
36 extern ListData *ld;
37 extern int num_gr;
38 extern FalGlyphRegion  *gr;
39 extern FalFontData fullFontData;
40
41 void udcimp(Exc_data * ed)
42 {
43     ed->function = IMPORT;
44     strcpy(ed->bdfmode,"r");
45     getbdffn(ed);
46 }
47
48 int checkcode(int code)
49 {
50     int i, j;
51     int code1, code2;
52
53     for (i = 0; i < num_gr; i++) {
54         code1 = smaller(gr[i].start, gr[i].end);
55         code2 = bigger(gr[i].start, gr[i].end);
56         if ((code >= code1) && (code <= code2)) { /*in udc area */
57             for (j = 0; j < ld->existcode_num; j++) {
58                 if (code == ld->existcode[j])
59                     return (1); /* the font has same glyph index */
60             }
61             return (0);
62         }
63     }
64     return (-1); /* out of udc area */
65 }
66         
67
68 int checkcodes(int code_num, int * code_list)
69 {
70     int *codep;
71     int i, ans;
72     int exist = 0;
73
74     codep = code_list;
75     for (i = 0; i < code_num; i++) {
76         ans = checkcode(*codep);
77         if (ans == -1) {
78             return (-1);
79         } else if (ans == 1) {
80             exist = 1;
81         }
82         codep++;
83     }
84     return (exist);
85 }
86
87 void getcharcd(Exc_data * ed)
88 {
89     int code_num;
90     int *code_list;
91     int i;
92     char *msg;
93     char *msg2;
94     char *msg3;
95     int ans, ans2;
96
97     msg = GETMESSAGE(12, 2, "Glyph images in this BDF file can't be added to the font.");
98     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.");
99     msg3 = GETMESSAGE(12, 6, "There are one or more glyph images being overwritten. Overwrite?");
100
101     i = ImpBDFCodeList(ed->bdffile, &code_num, &code_list);
102
103     if (i != 0) { /* bad BDF format */
104         AskUser(ed->toplevel, ed, msg2, &ans, "error");
105         freeld(ld);
106         excterminate(ed);
107     }
108
109     ans2 = checkcodes(code_num, code_list);
110     if (ans2 == -1) { /* out of UDC code exists */
111         AskUser(ed->toplevel, ed, msg, &ans, "error");
112         freeld(ld);
113         excterminate(ed);
114     } else if (ans2 == 1) { /* font file has same glyph index */
115         AskUser(ed->toplevel, ed, msg3, &ans, "warning");
116         if (ans != 1) {
117             freeld(ld);
118             excterminate(ed);
119         }
120     }    
121
122 /* set twe codelists */
123     setcodelists(ld, code_num, code_list);
124
125     if (ImpBDFCodeListFree(&code_list) != 0) {
126         fprintf(stderr,"error in ImpBDFCodeListFree\n");
127     }
128
129 /* add gryph images to font */
130     addcharptn(ed);
131 }
132
133 void addcharptn(Exc_data * ed)
134 {
135     int i;
136     int ans;
137     char *msg;
138     char *msg2;
139     char *msg3;
140
141     int mask;
142     FalFontDataList     *fulllist = NULL;
143     FalFontID           fontid;
144
145     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.");
146     msg2 = GETMESSAGE(12, 10, "Glyph images in this BDF file can't be added to the font.");
147     msg3 = GETMESSAGE(12, 12, "Failed in the registration of the font file.");
148
149     mask =  FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_GLYPH_INDEX |
150             FAL_FONT_MASK_DEFINED | FAL_FONT_MASK_UPDATE |
151             FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_CODE_SET;
152
153     i = ImpBDFCheck(ed->bdffile, ed->fontfile);
154     if (i != 0) {
155         AskUser(ed->toplevel, ed, msg2, &ans, "error");
156         excterminate(ed);
157     }
158     
159     fontid = FalOpenSysFont(&fullFontData, mask, &fulllist);
160     if (fontid == 0) {
161         AskUser(ld->ed->toplevel, ld->ed, msg, &ans, "error");
162         excterminate(ed);
163     }
164     i = 0;
165     i = ImpBDFtoGpf(ed->bdffile, ed->fontfile,
166                     ed->code_num, ed->bdf_code_list);
167     FalCloseFont( fontid );
168     if (i != 0) {
169         AskUser(ed->toplevel, ed, msg3, &ans, "error");
170     }
171
172     excterminate(ed);
173 }
174
175 void setcodelists(ListData *ld, int code_num, int *code_list)
176 {
177     int         *c1, *c2;
178     int         i;
179     Exc_data    *ed;
180
181     ld->ed->code_num = code_num;
182
183     if ((c1 = (int *) calloc(code_num, sizeof(int))) == NULL) {
184         ed = ld->ed;
185         freeld(ld);
186         excerror(ed, EXCERRMALLOC, "setcodelists", "exit");
187     }
188     ld->ed->bdf_code_list = c1;
189     c2 = code_list;
190     for (i = 0; i < code_num; i++)
191     {
192         *c1 = *c2;
193         c1++;
194         c2++;
195     }
196     
197     if ((c1 = (int *) calloc(code_num, sizeof(int))) == NULL) {
198         ed = ld->ed;
199         freeld(ld);
200         excerror(ed, EXCERRMALLOC, "setcodelists", "exit");
201     }
202     ld->ed->gpf_code_list = c1;
203     c2 = code_list;
204     for (i = 0; i < code_num; i++)
205     {
206         *c1 = *c2;
207         c1++;
208         c2++;
209     }
210 }