]>
Commit | Line | Data |
---|---|---|
d5a7ea17 | 1 | /* $Id$ |
2 | * | |
3 | * mrcl error interface | |
4 | * | |
5 | * Copyright (C) 1999 by the Massachusetts Institute of Technology | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
10 | #include <mit-copyright.h> | |
11 | #include <moira.h> | |
12 | #include <mrclient.h> | |
13 | #include "mrclient-internal.h" | |
14 | ||
15 | #include <stdarg.h> | |
16 | #include <stdlib.h> | |
17 | #include <stdio.h> | |
ec0cf898 | 18 | #include <string.h> |
d5a7ea17 | 19 | |
20 | #include <com_err.h> | |
21 | ||
22 | RCSID("$Header$"); | |
23 | ||
24 | static char *mrcl_message = NULL; | |
25 | ||
26 | void mrcl_set_message(char *fmt, ...) | |
27 | { | |
28 | int args, len; | |
29 | char *p; | |
30 | va_list ap; | |
31 | ||
32 | free(mrcl_message); | |
33 | ||
34 | /* Count "%s"s */ | |
35 | for (args = 0, p = strstr(fmt, "%s"); p; p = strstr(p + 2, "%s")) | |
36 | args++; | |
37 | ||
38 | /* Measure the output string. */ | |
39 | len = strlen(fmt) + 1; | |
40 | va_start(ap, fmt); | |
41 | while (args--) | |
42 | { | |
43 | p = va_arg(ap, char *); | |
44 | len += strlen(p); | |
45 | } | |
46 | va_end(ap); | |
47 | ||
48 | /* Malloc and print */ | |
49 | mrcl_message = malloc(len); | |
50 | if (mrcl_message) | |
51 | { | |
52 | va_start(ap, fmt); | |
53 | vsprintf(mrcl_message, fmt, ap); | |
54 | va_end(ap); | |
55 | } | |
56 | } | |
57 | ||
58 | char *mrcl_get_message(void) | |
59 | { | |
60 | return mrcl_message; | |
61 | } | |
62 | ||
63 | void mrcl_clear_message(void) | |
64 | { | |
65 | free(mrcl_message); | |
66 | mrcl_message = NULL; | |
67 | } | |
68 | ||
69 | void mrcl_com_err(char *whoami) | |
70 | { | |
71 | if (mrcl_message) | |
72 | com_err(whoami, 0, "%s", mrcl_message); | |
73 | } |