2 * Copyright (C) Angus J. C. Duggan 1991-1995
3 * See file LICENSE for details.
5 * Warnings and errors for PS programs
8 extern char *program
; /* Defined by main program, giving program name */
16 /* Message functions; there is a single are varargs functions for messages,
17 warnings, and errors sent to stderr. If called with the flags MESSAGE_EXIT
18 set, the routine does not return */
20 #define MAX_MESSAGE 256 /* maximum formatted message length */
21 #define MAX_FORMAT 16 /* maximum format length */
22 #define MAX_COLUMN 78 /* maximum column to print upto */
24 void message(int flags
, char *format
, ...)
27 static column
= 0 ; /* current screen column for message wrap */
28 char msgbuf
[MAX_MESSAGE
] ; /* buffer in which to put the message */
29 char *bufptr
= msgbuf
; /* message buffer pointer */
31 if ( (flags
& MESSAGE_NL
) && column
!= 0 ) { /* new line if not already */
36 if ( flags
& MESSAGE_PROGRAM
) {
37 strcpy(bufptr
, program
) ;
38 bufptr
+= strlen(program
) ;
43 va_start(args
, format
) ;
44 if ( format
!= NULL
) {
46 while ( (c
= *format
++) != '\0' ) {
48 int done
, longform
, index
;
49 char fmtbuf
[MAX_FORMAT
] ;
50 longform
= index
= 0 ;
54 fmtbuf
[index
++] = c
= *format
++ ;
55 fmtbuf
[index
] = '\0' ;
61 case 'e': case 'E': case 'f': case 'g': case 'G':
63 double d
= va_arg(args
, double) ;
64 sprintf(bufptr
, fmtbuf
, d
) ;
65 bufptr
+= strlen(bufptr
) ;
68 case 'c': case 'd': case 'i': case 'o':
69 case 'p': case 'u': case 'x': case 'X':
71 long l
= va_arg(args
, long) ;
72 sprintf(bufptr
, fmtbuf
, l
) ;
74 int i
= va_arg(args
, int) ;
75 sprintf(bufptr
, fmtbuf
, i
) ;
77 bufptr
+= strlen(bufptr
) ;
81 char *s
= va_arg(args
, char *) ;
82 sprintf(bufptr
, fmtbuf
, s
) ;
83 bufptr
+= strlen(bufptr
) ;
93 } else if ( c
== '\n' ) { /* write out message so far and reset column */
94 int len
= bufptr
- msgbuf
; /* length of current message */
97 if ( column
+ len
> MAX_COLUMN
&& column
> 0 ) {
101 fputs(bufptr
= msgbuf
, stderr
) ;
108 int len
= bufptr
- msgbuf
; /* length of current message */
109 if ( column
+ len
> MAX_COLUMN
&& column
> 0 ) {
113 fputs(msgbuf
, stderr
) ;
120 if ( flags
& MESSAGE_EXIT
) /* don't return to program */