2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: getbdffn.c /main/5 1996/10/14 14:44:32 barstow $ */
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
32 #include <Xm/FileSB.h>
33 #include <sys/types.h>
38 * There is no public header file for this function (only an
39 * internal header XmStringI.h).
41 extern XtPointer _XmStringUngenerate (XmString string,
44 XmTextType output_type);
47 void filesbcancelCB();
49 extern char *maintitle;
51 void getbdffn(Exc_data * ed)
59 selectlabel = GETMESSAGE(2, 2, "BDF file selection");
61 XtSetArg(args[n], XmNtitle, maintitle); n++;
62 xms = XmStringCreateLocalized(selectlabel);
63 XtSetArg(args[n], XmNselectionLabelString, xms); n++;
64 filesb = XmCreateFileSelectionDialog(ed->toplevel, "filesb", args, n);
65 XtAddCallback(filesb, XmNokCallback,
66 (XtCallbackProc) filesbokCB,
68 XtAddCallback(filesb, XmNcancelCallback,
69 (XtCallbackProc) filesbcancelCB,
71 XtUnmanageChild(XmFileSelectionBoxGetChild(filesb, XmDIALOG_HELP_BUTTON));
72 XtManageChild(filesb);
75 int fopencheck(char *file, char *dir, char *mode)
77 * when mode = "r", if fopen can open the file with read only mode, return 0
78 * when mode = "w", if fopen can open the file with write mode, return 0
79 * but if the file exists, return 1
85 if (strcmp(mode, "r") == 0) {
86 if (stat(file, &buf) == 0)
87 if ((buf.st_mode & S_IFMT) == S_IFREG)
88 return 0; /* readable regular file */
89 } else if (strcmp(mode, "w") == 0) {
90 if (stat(file, &buf) == 0) {
91 if (((buf.st_mode & S_IFMT) == S_IFREG) &&
92 (access(file, W_OK) == 0))
93 return 1; /* writable existing file */
95 if (stat(dir, &buf) == 0) {
96 if (((buf.st_mode & S_IFMT) == S_IFDIR) &&
97 (access(dir, W_OK) == 0)) {
98 return 0; /* writable new file */
103 fprintf(stderr, "Unanticipatable error occured in fopencheck.\n");
107 void filesbcancelCB(Widget widget, Exc_data * ed, XtPointer call_data)
112 void freeStrings(char * dir, char * file)
120 void filesbokCB(Widget widget, Exc_data * ed, XtPointer call_data)
122 XmFileSelectionBoxCallbackStruct *ptr;
123 char *file = NULL, *dir = NULL, *tmpfile;
128 msg1 = GETMESSAGE(2, 4, "The selected file exists. Overwrite?");
129 msg2 = GETMESSAGE(2, 6, "Failed to open the selected file.");
131 ptr = (XmFileSelectionBoxCallbackStruct *) call_data;
133 file = (char *) _XmStringUngenerate((XmString) ptr->value, NULL,
134 XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
139 dir = (char *) _XmStringUngenerate((XmString) ptr->dir, NULL,
140 XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
145 if ((tmpfile = XtMalloc(strlen(dir) + 1 + strlen(file) + 1))
147 excerror(ed, EXCERRMALLOC, "filesbokCB", "exit");
149 sprintf(tmpfile, "%s/%s", dir, file);
155 r = fopencheck(file, dir, ed->bdfmode);
156 if (r == 0) {/* no problem */
157 /*fprintf(stderr, "%s will be opened\n", file);*/
158 } else if (r == 1) { /* file exist at export function */
159 AskUser(widget, ed, msg1, &ans, "warning");
160 if (ans != 1) { /* overwrite cancel */
161 freeStrings(dir, file);
164 } else { /* file will not be opened */
165 AskUser(widget, ed, msg2, &ans, "error");
166 freeStrings(dir, file);
169 ed->bdffile = (char *) malloc(strlen(file) + 1);
170 strcpy(ed->bdffile, file);
171 freeStrings(dir, file);
172 XtUnmanageChild(widget);
173 if (ed->function == EXPORT)
176 } else if (ed->function == IMPORT)
178 PopupSelectXLFD(ed->toplevel);