Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / examples / dtdts / datatyping.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: datatyping.c /main/3 1995/10/27 10:39:52 rswiston $ */
24 /*
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company
26  * (c) Copyright 1993, 1994 International Business Machines Corp.
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
28  * (c) Copyright 1993, 1994 Novell, Inc.
29  */
30
31 #include <Xm/Form.h>
32 #include <Xm/Text.h>
33 #include <Dt/Dts.h>
34
35 #define ApplicationClass "DtDatatyping"
36
37 static Widget text;
38
39 static void DisplayTypeInfo(int, char**);
40
41 int main(int argc, char **argv)
42 {
43     XtAppContext appContext;
44     Widget toplevel, form;
45     Arg args[20];
46     int n;
47
48     toplevel = XtAppInitialize(&appContext, ApplicationClass, NULL, 0,
49                                                 &argc, argv, NULL, NULL, 0);
50
51     if (argc == 1) {
52         printf("%s: No files specified.\n", argv[0]);
53         exit(1);
54     }
55
56     form = XmCreateForm(toplevel, "form", NULL, 0);
57     XtManageChild(form);
58     n = 0;
59     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
60     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
61     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
62     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
63     XtSetArg(args[n], XmNeditable, False); n++;
64     XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
65     XtSetArg(args[n], XmNrows, 25); n++;
66     XtSetArg(args[n], XmNcolumns, 90); n++;
67     text = XmCreateScrolledText(form, "text", args, n);
68     XtManageChild(text);
69
70     XtRealizeWidget(toplevel);
71
72     if (DtAppInitialize(appContext, XtDisplay(toplevel), toplevel, argv[0],
73                                                 ApplicationClass) == False) {
74         printf("%s: Couldn't initialize Dt\n", argv[0]);
75         exit(1);
76     }
77
78     DtDbLoad();
79
80     DisplayTypeInfo(argc, argv);
81
82     XtAppMainLoop(appContext);
83 }
84
85 static void DisplayTypeInfo(int argc, char **argv)
86 {
87     char *file;
88     char *datatype;
89     char *icon;
90     char *actions;
91     char str[100];
92     int i;
93
94     sprintf(str, "%-30s\t%-10s\t%-8s\t%-20s\n",
95                 "File",
96                 "DataType",
97                 "Icon",
98                 "Actions");
99     XmTextInsert(text, XmTextGetLastPosition(text), str);
100
101     sprintf(str, "%-30s\t%-10s\t%-8s\t%-20s\n",
102                 "-------------------",
103                 "--------",
104                 "----",
105                 "-------");
106     XmTextInsert(text, XmTextGetLastPosition(text), str);
107
108     for(i=1; i < argc; i++) {
109         char *file = argv[i];
110
111         /* find out the Dts data type */
112         datatype = DtDtsFileToDataType(file);
113
114         if(datatype) {
115             /* find the icon attribute for the data type */
116             icon = DtDtsDataTypeToAttributeValue(datatype, DtDTS_DA_ICON, file);
117         }
118
119         /*  Directly find the action attribute for a file */
120
121         actions = DtDtsFileToAttributeValue(file, DtDTS_DA_ACTION_LIST);
122         
123         sprintf(str, "%-30s\t%-10s\t%-8s\t%s\n",
124                         file,
125                         datatype?datatype:"unknown",
126                         icon?icon:"unknown",
127                         actions?actions:"unknown");
128         XmTextInsert(text, XmTextGetLastPosition(text), str);
129
130         /* Free the space allocated by Dts */
131
132         DtDtsFreeAttributeValue(icon);
133         DtDtsFreeAttributeValue(actions);
134         DtDtsFreeDataType(datatype);
135     }
136 }
137