FrontISTR 5.2.0
Large-scale structural analysis program with finit element method
Loading...
Searching...
No Matches
hecmw_msg.c
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (c) 2019 FrontISTR Commons
3 * This software is released under the MIT License, see LICENSE.txt
4 *****************************************************************************/
5
6#include <stdio.h>
7#include <string.h>
8#include "hecmw_config.h"
9#include "hecmw_msg.h"
10#include "hecmw_util.h"
11
12static struct hecmw_msgent msg_unknown = {-1, "HEC-MW-UNKNOWN",
13 "Unkown message No"};
14
15static struct hecmw_msgent msg_err = {-1, "HEC-MW-SYSERR", NULL};
16
17static char msg_buf[HECMW_MSG_LEN + 1];
18
19static struct hecmw_msgent *get_msgent(int msgno) {
20 int i;
21 struct hecmw_msgent *p;
22
23 i = 0;
24 for (p = &hecmw_msg_table[i]; p->msgno != -1; p = &hecmw_msg_table[i++]) {
25 if (msgno == p->msgno) return p;
26 }
27
28 return NULL; /* not found */
29}
30
31char *HECMW_strmsg(int msgno) {
32 struct hecmw_msgent *p;
33
34 p = NULL;
35 if (msgno < HECMW_MSGNO_BASE) {
36 /* system error */
37 p = &msg_err;
38 p->msg = strerror(msgno);
39 }
40 if (p == NULL) p = get_msgent(msgno);
41 if (p == NULL) p = &msg_unknown;
42 sprintf(msg_buf, "%s: %s(%d)", p->msgno_str, p->msg, msgno);
43 return msg_buf;
44}
45
47
48void hecmw_strmsg_if(int *msgno, char *dst, int dstlen) {
49 const char *p;
50
51 if (dst == NULL) return;
52 if (dstlen < 0) return;
53
54 p = HECMW_strmsg(*msgno);
55 HECMW_strcpy_c2f(p, dst, dstlen);
56}
57
58void hecmw_strmsg_if_(int *msgno, char *dst, int dstlen) {
59 hecmw_strmsg_if(msgno, dst, dstlen);
60}
61
62void hecmw_strmsg_if__(int *msgno, char *dst, int dstlen) {
63 hecmw_strmsg_if(msgno, dst, dstlen);
64}
65
66void HECMW_STRMSG_IF(int *msgno, char *dst, int dstlen) {
67 hecmw_strmsg_if(msgno, dst, dstlen);
68}
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74
#define NULL
int HECMW_strcpy_c2f(const char *cstr, char *fstr, int flen)
Definition: hecmw_lib_fc.c:72
void hecmw_strmsg_if__(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:62
int HECMW_is_syserr(int msgno)
Definition: hecmw_msg.c:46
void HECMW_STRMSG_IF(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:66
void hecmw_strmsg_if(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:48
char * HECMW_strmsg(int msgno)
Definition: hecmw_msg.c:31
void hecmw_strmsg_if_(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:58
struct hecmw_msgent hecmw_msg_table[]
#define HECMW_MSGNO_BASE
Definition: hecmw_msgno.h:9
char * msg
Definition: hecmw_msg.h:14
char * msgno_str
Definition: hecmw_msg.h:13