SDDSlib
Loading...
Searching...
No Matches
bomb.c File Reference

Provides functions to report errors and abort the program. More...

#include "mdb.h"

Go to the source code of this file.

Functions

void bomb (char *error, char *usage)
 Reports error messages to the terminal and aborts the program.
 
long bombre (char *error, char *usage, long return_value)
 Reports error messages to the terminal and returns a specified value.
 
void bombVA (char *template,...)
 Reports error messages using a printf-style template and aborts the program.
 

Detailed Description

Provides functions to report errors and abort the program.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file bomb.c.

Function Documentation

◆ bomb()

void bomb ( char * error,
char * usage )

Reports error messages to the terminal and aborts the program.

This function prints the provided error and usage messages to the standard error stream and then terminates the program.

Parameters
errorA string describing the error.
usageA string describing the correct usage.

Definition at line 26 of file bomb.c.

26 {
27 if (error)
28 fprintf(stderr, "error: %s\n", error);
29 if (usage)
30 fprintf(stderr, "usage: %s\n", usage);
31 exit(1);
32}

◆ bombre()

long bombre ( char * error,
char * usage,
long return_value )

Reports error messages to the terminal and returns a specified value.

This function prints the provided error and usage messages to the standard error stream and returns the given return value.

Parameters
errorA string describing the error.
usageA string describing the correct usage.
return_valueThe value to return after reporting the messages.
Returns
The specified return value.

Definition at line 44 of file bomb.c.

44 {
45 if (error)
46 fprintf(stderr, "error: %s\n", error);
47 if (usage)
48 fprintf(stderr, "usage: %s\n", usage);
49 return return_value;
50}

◆ bombVA()

void bombVA ( char * template,
... )

Reports error messages using a printf-style template and aborts the program.

This function accepts a format string and a variable number of arguments, formats the message accordingly, prints it to the standard output, and then terminates the program.

Parameters
templateA printf-style format string.
...Variable arguments corresponding to the format string.

Definition at line 60 of file bomb.c.

60 {
61 char *p;
62 char c, *s;
63 int i;
64 long j;
65 va_list argp;
66 double d;
67
68 va_start(argp, template);
69 p = template;
70 while (*p) {
71 if (*p == '%') {
72 switch (*++p) {
73 case 'l':
74 switch (*++p) {
75 case 'd':
76 j = va_arg(argp, long int);
77 printf("%ld", j);
78 break;
79 case 'e':
80 d = va_arg(argp, double);
81 printf("%21.15le", d);
82 break;
83 case 'f':
84 d = va_arg(argp, double);
85 printf("%lf", d);
86 break;
87 case 'g':
88 d = va_arg(argp, double);
89 printf("%21.15lg", d);
90 break;
91 default:
92 printf("%%l%c", *p);
93 break;
94 }
95 break;
96 case 'c':
97 c = va_arg(argp, int);
98 putchar(c);
99 break;
100 case 'd':
101 i = va_arg(argp, int);
102 printf("%d", i);
103 break;
104 case 's':
105 s = va_arg(argp, char *);
106 fputs(s, stdout);
107 break;
108 case 'e':
109 d = va_arg(argp, double);
110 printf("%21.15e", d);
111 break;
112 case 'f':
113 d = va_arg(argp, double);
114 printf("%f", d);
115 break;
116 case 'g':
117 d = va_arg(argp, double);
118 printf("%21.15g", d);
119 break;
120 default:
121 printf("%%%c", *p);
122 break;
123 }
124 } else {
125 putchar(*p);
126 }
127 p++;
128 }
129 va_end(argp);
130 exit(1);
131}