FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
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 
12 static struct hecmw_msgent msg_unknown = {-1, "HEC-MW-UNKNOWN",
13  "Unknown message No"};
14 
15 static struct hecmw_msgent msg_err = {-1, "HEC-MW-SYSERR", NULL};
16 
17 static char msg_buf[HECMW_MSG_LEN + 1];
18 
19 static 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 
31 char *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 
48 void 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 
58 void hecmw_strmsg_if_(int *msgno, char *dst, int dstlen) {
59  hecmw_strmsg_if(msgno, dst, dstlen);
60 }
61 
62 void hecmw_strmsg_if__(int *msgno, char *dst, int dstlen) {
63  hecmw_strmsg_if(msgno, dst, dstlen);
64 }
65 
66 void HECMW_STRMSG_IF(int *msgno, char *dst, int dstlen) {
67  hecmw_strmsg_if(msgno, dst, dstlen);
68 }
HECMW_is_syserr
int HECMW_is_syserr(int msgno)
Definition: hecmw_msg.c:46
HECMW_MSGNO_BASE
#define HECMW_MSGNO_BASE
Definition: hecmw_msgno.h:5
hecmw_msgent
Definition: hecmw_msg.h:11
HECMW_STRMSG_IF
void HECMW_STRMSG_IF(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:66
hecmw_msgent::msgno
int msgno
Definition: hecmw_msg.h:15
hecmw_strmsg_if__
void hecmw_strmsg_if__(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:62
HECMW_strcpy_c2f
int HECMW_strcpy_c2f(const char *cstr, char *fstr, int flen)
Definition: hecmw_lib_fc.c:72
hecmw_config.h
hecmw_strmsg_if
void hecmw_strmsg_if(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:48
hecmw_msg.h
HECMW_strmsg
char * HECMW_strmsg(int msgno)
Definition: hecmw_msg.c:31
hecmw_msgent::msgno_str
char * msgno_str
Definition: hecmw_msg.h:16
hecmw_msgent::msg
char * msg
Definition: hecmw_msg.h:17
hecmw_strmsg_if_
void hecmw_strmsg_if_(int *msgno, char *dst, int dstlen)
Definition: hecmw_msg.c:58
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
hecmw_util.h
HECMW_MSG_LEN
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74
hecmw_msg_table
struct hecmw_msgent hecmw_msg_table[]
Definition: hecmw_msg_table.c:5