~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to xless/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xless - X Window System file browser.
 
3
 *
 
4
 * Copyright 1989 Massachusetts Institute of Technology
 
5
 *
 
6
 * Permission to use, copy, modify, and distribute this software and its
 
7
 * documentation for any purpose and without fee is hereby granted, provided
 
8
 * that the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of M.I.T. not be used in advertising
 
11
 * or publicity pertaining to distribution of the software without specific,
 
12
 * written prior permission.  M.I.T. makes no representations about the
 
13
 * suitability of this software for any purpose.  It is provided "as is"
 
14
 * without express or implied warranty.
 
15
 *
 
16
 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
 
18
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
19
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
21
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author: Carlo Lisa
 
24
 *         MIT Project Athena
 
25
 *         carlo@athena.mit.edu
 
26
 *
 
27
 * Date: October 11, 1989
 
28
 *
 
29
 * $Header: /usr/sww/share/src/X11R5/local/clients/xless-1.4/RCS/main.c,v 1.23 1993/04/30 21:40:35 dglo Exp dglo $
 
30
 */
 
31
 
 
32
#include "xless.h"
 
33
#include "XLessTop.icon"
 
34
 
 
35
XtAppContext context;
 
36
Widget toplevel;
 
37
Display *disp;
 
38
 
 
39
XLessResources resources;
 
40
 
 
41
#define Offset(field) (XtOffset(XLessResources *, field))
 
42
 
 
43
static XtResource priv_resources[] = {
 
44
  {"helpFile", XtCFile, XtRString, sizeof(char *),
 
45
     Offset(help_file), XtRString, "xless.help"},
 
46
  {"standardCur", XtCCursor, XtRCursor, sizeof(Cursor),
 
47
     Offset(cursors.top), XtRString, STANDARDCUR},
 
48
  {"dialogCur", XtCCursor, XtRCursor, sizeof(Cursor),
 
49
     Offset(cursors.dialog), XtRString, STANDARDCUR},
 
50
  {"standardFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
 
51
     Offset(fonts.standard), XtRString, STANDARDFONT},
 
52
  {"textFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
 
53
     Offset(fonts.text), XtRString, TEXTFONT},
 
54
  {"labelFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
 
55
     Offset(fonts.label), XtRString, LABELFONT},
 
56
  {"buttonFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
 
57
     Offset(fonts.button), XtRString, BUTTONFONT},
 
58
  {"editorDoesWindows", "EditorDoesWindows", XtRBoolean, sizeof(Boolean),
 
59
     Offset(editorDoesWindows), XtRString, "False"},
 
60
  {"printCommand", "PrintCommand", XtRString, sizeof(char *),
 
61
     Offset(printCmd), XtRString, PRINTCMD},
 
62
  {"printCmd", "PrintCommand", XtRString, sizeof(char *),
 
63
     Offset(printCmd), XtRString, PRINTCMD},
 
64
  {"maxWindows", "MaxWindows", XtRInt, sizeof(int),
 
65
     Offset(maxWindows), XtRString, "0"},
 
66
  {"quitButton", "QuitButton", XtRBoolean, sizeof(Boolean),
 
67
     Offset(quitButton), XtRString, "False"},
 
68
  {"textGeometry", "Geometry", XtRString, sizeof(char *),
 
69
     Offset(textGeometry), XtRString, "150x25"},
 
70
  {"sizeToFit", "SizeToFit", XtRBoolean, sizeof(Boolean),
 
71
     Offset(sizeToFit), XtRString, "True"},
 
72
  {"namePrefix", "NamePrefix", XtRString, sizeof(char *),
 
73
     Offset(namePrefix), XtRString, "xless:"},
 
74
  {"removePath", "RemovePath", XtRBoolean, sizeof(Boolean),
 
75
     Offset(removePath), XtRString, "True"},
 
76
  {"helpMessage", "HelpMessage", XtRBoolean, sizeof(Boolean),
 
77
     Offset(helpMessage), XtRString, "False"},
 
78
};
 
79
 
 
80
static XrmOptionDescRec options[] = {
 
81
  {"-help",     "*helpMessage", XrmoptionNoArg, "True"},
 
82
};
 
83
 
 
84
void
 
85
cleanup()
 
86
{
 
87
  XtDestroyWidget(toplevel);
 
88
  XtDestroyApplicationContext(context);
 
89
}
 
90
 
 
91
void
 
92
main(argc, argv)
 
93
int argc;
 
94
char *argv[];
 
95
{
 
96
  Arg   arg[10];
 
97
  Cardinal n;
 
98
  int i;
 
99
#ifdef _DEBUG_MALLOC_INC
 
100
  {
 
101
    union dbmalloptarg  moa;
 
102
 
 
103
    moa.i = 0;
 
104
    dbmallopt(MALLOC_CKCHAIN, &moa);
 
105
  }
 
106
#endif
 
107
  toplevel = XtAppInitialize(&context, XLESS_CLASS, NULL, (Cardinal )0,
 
108
                             &argc, argv, NULL, NULL, 0);
 
109
 
 
110
  XtGetApplicationResources(toplevel, (XtPointer )&resources, priv_resources,
 
111
                            XtNumber(priv_resources), NULL, (Cardinal) 0);
 
112
 
 
113
  XtAppAddActions(context, actions, numactions);
 
114
 
 
115
  disp = XtDisplay(toplevel);
 
116
 
 
117
  n = 0;
 
118
  XtSetArg(arg[n], XtNiconPixmap,
 
119
           XCreateBitmapFromData(disp, XRootWindow(disp, 0),
 
120
                                 XLessTop_bits, XLessTop_width,
 
121
                                 XLessTop_height)); n++;
 
122
  XtSetValues(toplevel, arg, n);
 
123
 
 
124
  CheckFonts();
 
125
 
 
126
  for (i = 1; resources.helpMessage || i < argc; i++) {
 
127
 
 
128
    /* whine if there's still an argument */
 
129
    if (resources.helpMessage || *argv[i] == '-') {
 
130
      fprintf(stdout, "usage:\txless filename\n");
 
131
      fprintf(stdout, "\t(xless also takes input from stdin)\n");
 
132
      cleanup();
 
133
      exit(0);
 
134
    }
 
135
 
 
136
    CreateWindow(toplevel, argv[i]);
 
137
  }
 
138
 
 
139
  /* if we haven't opened a window yet... */
 
140
  if (windowcount == 0) {
 
141
    /*
 
142
     * Not really necessary to call this an error,
 
143
     * but if the control terminal (for commands)
 
144
     * and the input file (for data) are the same,
 
145
     * we get weird results at best.
 
146
     */
 
147
    if (isatty(fileno(stdin))) {
 
148
      fprintf(stderr, "xless: can't take input from terminal\n");
 
149
      cleanup();
 
150
      exit(1);
 
151
    }
 
152
 
 
153
    /* bring up controlling window using stdin as input */
 
154
    CreateWindow(toplevel, NULL);
 
155
  }
 
156
 
 
157
  XtAppMainLoop(context);
 
158
}