summaryrefslogtreecommitdiff
path: root/dviware/umddvi/previewers/texx2/texx2-error.c
blob: fdb0854ce514a5b45e961d5af41a86123f2d90ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 *	This program is Copyright (C) 1987 by the Board of Trustees of the
 *	University of Illinois, and by the author Dirk Grunwald.
 */

/*
 * Print an error message with an optional system error number, and
 * optionally quit.
 *
 */

#include <stdio.h>
#include <varargs.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/ShellP.h>
#include <X11/AsciiText.h>
#include "texx2.h"
#include "texx2-widgets.h"

#ifdef _STDC_
  extern char* malloc(int);
  extern char* realloc(char *, int);
#else
  extern char* malloc();
  extern char* realloc();
#endif

#define ERROR_BUFFER_SIZE 2048
static char errorMessageBuffer[ ERROR_BUFFER_SIZE ]
  = {"Welcome to TeXx-2.8.5\nThis is the dialog box\n"};
static int errorMessageBufferLength=0;

static message(str,quit)
     char *str;
     int quit;
{
  
  if ( errorText ) {
    int len = strlen(str);
    char *p;
    XtTextPosition start;
    XtTextPosition end;
    XtTextBlock tblk;

    tblk.firstPos = 0;
    tblk.length = len;
    tblk.ptr = str;
    tblk.format = FMT8BIT;

    if ( len > 0 && str[len-1] != '\n' ) {
      str[len] = '\n';
      str[len+1] = 0;
      tblk.length = len+1;
    }
    
    start = strlen( errorMessageBuffer );

    if ( start + len > ERROR_BUFFER_SIZE ) {
      start = 0;
      bzero( errorMessageBuffer, ERROR_BUFFER_SIZE );
    }

    end = start;

    XtTextDisableRedisplay(errorText);

    XtTextSetInsertionPoint(errorText, start);
    XtTextSetLastPos( errorText, start );
    
    XtTextReplace( errorText, start, end, &tblk );

    XtTextEnableRedisplay(errorText);

  }
}

static void
pushClearButton(w, clientData,  callData)
Widget w;
caddr_t clientData;	/* unused */
caddr_t callData; /* unused */
{
  bzero( errorMessageBuffer , ERROR_BUFFER_SIZE );

  XtTextDisableRedisplay(errorText);
  XtTextSetInsertionPoint(errorText, 0);
  XtTextSetLastPos( errorText, 0 );
  XtTextEnableRedisplay(errorText);
} 

/*
 *	If you had a real compiler, these would all be 
 *	local the next function
 */

static XtCallbackRec clearButtonCallBacks [] = {
  {pushClearButton,NULL},
  {NULL, NULL}
};

static Arg clearButtonArgs[] = {
  {XtNcallback, (XtArgVal) clearButtonCallBacks}
};

static Arg textArgs[] = {
  {XtNeditType, (XtArgVal) XttextEdit},
  {XtNstring, (XtArgVal) errorMessageBuffer},
  {XtNlength, (XtArgVal) ERROR_BUFFER_SIZE},
  {XtNtextOptions, (XtArgVal) (scrollVertical | scrollOnOverflow | wordBreak )}
};

void
BuildErrorBox()
{

  clearButton =
    XtCreateManagedWidget("Clear Dialog Box",
			  commandWidgetClass, topPane,
			  clearButtonArgs, XtNumber(clearButtonArgs));
  errorText = 
    XtCreateManagedWidget("Error-Text",
			  asciiStringWidgetClass, topPane,
			  textArgs, XtNumber(textArgs));
}


#ifdef lint

/* VARARGS3 ARGSUSED */
error(quit, e, fmt) int quit, e; char *fmt; {;}

/* VARARGS1 ARGSUSED */
panic(fmt) char *fmt; { exit(1); /* NOTREACHED */ }

#else lint

extern char *ProgName;
extern int errno;
extern char *sys_errlist[];
extern int sys_nerr;

#define ERROR_MSG_LEN 1024
static char ErrorMsgBuffer[ ERROR_MSG_LEN ];

error(va_alist)
     va_dcl
{
  va_list l;
  int quit, e;
  char *fmt;
  char *p;

  p = ErrorMsgBuffer;

  va_start(l);
  /* pick up the constant arguments: quit, errno, printf format */
  quit = va_arg(l, int);
  e = va_arg(l, int);
  if (e < 0)
    e = errno;

  fmt = va_arg(l, char *);

#if defined(sun)
  (void) vsprintf(p, fmt, l);
#else
  /*	Does someone know how to do this properly? */

  {
    struct _iobuf ungodlyhack;
    ungodlyhack._cnt = ERROR_MSG_LEN;
    ungodlyhack._ptr = p;
    ungodlyhack._base = p;
    ungodlyhack._bufsiz = ERROR_MSG_LEN;
    ungodlyhack._flag = _IOSTRG;
    ungodlyhack._file = 255;
    _doprnt(fmt, l, &ungodlyhack);
  }
#endif

  va_end(l);

  message( ErrorMsgBuffer, quit);
}

panic(va_alist)
     va_dcl
{
  va_list l;
  char *fmt;
  char *p;

  p = ErrorMsgBuffer;
  sprintf(p, "panic: ");
  p += strlen(p);

  va_start(l);
  /* pick up the constant arguments: quit, errno, printf format */
  fmt = va_arg(l, char *);

#if defined(sun)
  (void) vsprintf(p, fmt, l);
#else
  /*	Does someone know how to do this properly? */

  {
    struct _iobuf ungodlyhack;
    ungodlyhack._cnt = ERROR_MSG_LEN;
    ungodlyhack._ptr = p;
    ungodlyhack._base = p;
    ungodlyhack._bufsiz = ERROR_MSG_LEN;
    ungodlyhack._flag = _IOSTRG;
    ungodlyhack._file = 255;
    _doprnt(fmt, l, &ungodlyhack);
  }
#endif

  va_end(l);

  message(ErrorMsgBuffer, 1);
}

#endif /* lint */