aboutsummaryrefslogtreecommitdiff
path: root/noao/rv/rverrmsg.x
blob: 69cbbc736e98bc3549b373eadb37603423469992 (plain) (blame)
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
include "rvpackage.h"
include "rvflags.h"

# RV_ERRMSG - Print an error message to STDERR and flush the buffer

procedure rv_errmsg (errstr)

char	errstr[SZ_LINE]				#I Error message to be printed

int	ip, stridxs()

begin
	if (stridxs("%", errstr) > 0) {
	    # The errstr contains a format specifier and an argument is
	    # expected in a 'parg' call following return.  The caller will
	    # handle the stream flush.
	    call eprintf (errstr)

	} else {
	    # At this point the error message is simply a text string we want
	    # to output.  No format has been detected and no arguments are
	    # expected.

	    ip = stridxs("\n", errstr) 		# replace any misc. newlines
	    if (ip > 0) 
	        errstr[ip] = EOS

	    call eprintf ("%s\n")
	        call pargstr (errstr)
	    call flush (STDERR)
	    call tsleep (1)			# delay so it can be read
	}
end


# RV_ERR_COMMENT - Record a message for the comment section of the logs

procedure rv_err_comment (rv, errstr, arg)

pointer	rv					#I RV struct pointer
char	errstr[SZ_LINE]				#I Error message to be printed
char	arg[SZ_LINE]				#I Error argument to be printed

pointer	sp, tmp
int	ip, newlen
int	stridxs(), strlen()
errchk	realloc

define	MAX_ERRBUF	4192

begin
	if (RV_VERBOSE(rv) == OF_SHORT || RV_VERBOSE(rv) == OF_NOLOG ||
	    RV_VERBOSE(rv) == OF_TXTONLY || RV_VERBOSE(rv) == OF_STXTONLY)
	        return

	call smark (sp)
	call salloc (tmp, SZ_LINE, TY_CHAR)

	# Re-allocate the error string.
	if (RV_ERRCOMMENTS(rv) == NULL) {
	    newlen = strlen (errstr) + 6 + SZ_FNAME
	    call realloc (RV_ERRCOMMENTS(rv), newlen, TY_CHAR)
	    call strcpy ("\t\0", ERRCOMMENTS(rv), 4)
	} else {
	    newlen = strlen (ERRCOMMENTS(rv)) +  strlen (errstr) + 6 + SZ_FNAME
	    call realloc (RV_ERRCOMMENTS(rv), newlen, TY_CHAR)
	}

	if (stridxs("%", errstr) > 0) {
	    # The errstr contains a format specifier and an argument is
	    # expected in a 'parg' call.

	    call sprintf (Memc[tmp], SZ_LINE, errstr)
	        call pargstr (arg)
	    call strcat (Memc[tmp], ERRCOMMENTS(rv), MAX_ERRBUF)
	    call strcat ("\n\t", ERRCOMMENTS(rv), MAX_ERRBUF)

	} else {
	    # At this point the error message is simply a text string we want
	    # to output.  No format has been detected and no arguments are
	    # expected.

	    ip = stridxs("\n", errstr) 		# replace any misc. newlines
	    if (ip > 0) 
	        errstr[ip] = EOS

	    call sprintf (Memc[tmp], SZ_LINE, "%s\n\t")
	        call pargstr (errstr)
	    call strcat (Memc[tmp], ERRCOMMENTS(rv), MAX_ERRBUF)
	}

	call sfree (sp)
end


# RESET_ERRCOM --  Clear the error comments structure.

procedure reset_errcom (rv)

pointer	rv						#I RV struct pointer

begin
	call mfree (RV_ERRCOMMENTS(rv), TY_CHAR)
	RV_ERRCOMMENTS(rv) = NULL
end