musrfit 1.10.0
mud_new.c
Go to the documentation of this file.
1/*
2 * mud_new.c -- Procedure for mallocing and initializing a new MUD section.
3 * This routine is used for _all_ section types, and so a
4 * CASE entry must be added for each unique type.
5 *
6 * Copyright (C) 1994-2010 TRIUMF (Vancouver, Canada)
7 *
8 * Authors: T. Whidden, D. Arseneau
9 *
10 * Released under the GNU LGPL - see http://www.gnu.org/licenses
11 *
12 * This program is free software; you can distribute it and/or modify it under
13 * the terms of the Lesser GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or any later version.
15 * Accordingly, this program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License
18 * for more details.
19 *
20 * Revision history:
21 * v1.0 26-Jan-1994 [TW] Initial version
22 * v1.0a 08-Feb-1994 [TW] Added sizeOf to core
23 * v1.0b 15-Feb-1994 [TW] Split ...GEN_HIST to ...GEN_HIST_HDR
24 * and ...GEN_HIST_DAT
25 * v1.0c 25-Apr-1994 [TW] Added CAMP sections
26 * v1.1 21-Feb-1996 TW Remove CAMP sections, add GEN_ARRAY
27 * v1.2a 01-Mar-2000 DA Add handling of unidentified sections (don't quit)
28 */
29
30
31#include "mud.h"
32
34MUD_new( UINT32 secID, UINT32 instanceID )
35{
36 MUD_SEC* pMUD_new;
37 MUD_PROC proc;
38 int sizeOf;
39
40 switch( secID )
41 {
42 case MUD_SEC_ID:
43 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC ) );
44 proc = (MUD_PROC)MUD_SEC_proc;
45 sizeOf = sizeof( MUD_SEC );
46 break;
48 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_FIXED ) );
50 sizeOf = sizeof( MUD_SEC_FIXED );
51 break;
52 case MUD_SEC_GRP_ID:
53 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GRP ) );
55 sizeOf = sizeof( MUD_SEC_GRP );
56 break;
57 case MUD_SEC_EOF_ID:
58 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_EOF ) );
60 sizeOf = sizeof( MUD_SEC_EOF );
61 break;
62 case MUD_SEC_CMT_ID:
63 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_CMT ) );
65 sizeOf = sizeof( MUD_SEC_CMT );
66 break;
68 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GEN_RUN_DESC ) );
70 sizeOf = sizeof( MUD_SEC_GEN_RUN_DESC );
71 break;
73 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GEN_HIST_HDR ) );
75 sizeOf = sizeof( MUD_SEC_GEN_HIST_HDR );
76 break;
78 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GEN_HIST_DAT ) );
80 sizeOf = sizeof( MUD_SEC_GEN_HIST_DAT );
81 break;
83 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GEN_SCALER ) );
85 sizeOf = sizeof( MUD_SEC_GEN_SCALER );
86 break;
88 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GEN_IND_VAR ) );
90 sizeOf = sizeof( MUD_SEC_GEN_IND_VAR );
91 break;
93 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_GEN_ARRAY ) );
95 sizeOf = sizeof( MUD_SEC_GEN_ARRAY );
96 break;
98 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_TRI_TI_RUN_DESC ) );
100 sizeOf = sizeof( MUD_SEC_TRI_TI_RUN_DESC );
101 break;
102/*
103 case MUD_SEC_CAMP_NUM_ID:
104 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_CAMP_NUM ) );
105 proc = (MUD_PROC)MUD_SEC_CAMP_NUM_proc;
106 sizeOf = sizeof( MUD_SEC_CAMP_NUM );
107 break;
108 case MUD_SEC_CAMP_STR_ID:
109 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_CAMP_STR ) );
110 proc = (MUD_PROC)MUD_SEC_CAMP_STR_proc;
111 sizeOf = sizeof( MUD_SEC_CAMP_STR );
112 break;
113 case MUD_SEC_CAMP_SEL_ID:
114 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_CAMP_SEL ) );
115 proc = (MUD_PROC)MUD_SEC_CAMP_SEL_proc;
116 sizeOf = sizeof( MUD_SEC_CAMP_SEL );
117 break;
118*/
119
120/* add action for unknown */
121 default:
122 pMUD_new = (MUD_SEC*)zalloc( sizeof( MUD_SEC_UNKNOWN ) );
124 sizeOf = sizeof( MUD_SEC_UNKNOWN );
125 break;
126
127 }
128
129 if( pMUD_new == NULL ) return( NULL );
130
131 pMUD_new->core.sizeOf = sizeOf;
132 pMUD_new->core.secID = secID;
133 pMUD_new->core.instanceID = instanceID;
134 pMUD_new->core.proc = proc;
135
136 return( pMUD_new );
137}
138
#define NULL
Definition mud.h:167
unsigned long UINT32
Definition mud.h:146
#define MUD_SEC_CMT_ID
Definition mud.h:67
#define zalloc(n)
Definition mud.h:201
#define MUD_SEC_GEN_HIST_HDR_ID
Definition mud.h:74
struct _MUD_SEC_GRP MUD_SEC_GRP
#define MUD_SEC_GEN_ARRAY_ID
Definition mud.h:78
int(* MUD_PROC)(MUD_OPT, void *p1, void *p2)
Definition mud.h:216
struct _MUD_SEC MUD_SEC
#define MUD_SEC_GEN_RUN_DESC_ID
Definition mud.h:73
#define MUD_SEC_GRP_ID
Definition mud.h:65
#define MUD_SEC_EOF_ID
Definition mud.h:66
struct _MUD_SEC_UNKNOWN MUD_SEC_UNKNOWN
#define MUD_SEC_GEN_HIST_DAT_ID
Definition mud.h:75
#define MUD_SEC_FIXED_ID
Definition mud.h:64
#define MUD_SEC_GEN_SCALER_ID
Definition mud.h:76
#define MUD_SEC_TRI_TI_RUN_DESC_ID
Definition mud.h:95
#define MUD_SEC_ID
Definition mud.h:63
#define MUD_SEC_GEN_IND_VAR_ID
Definition mud.h:77
int MUD_SEC_FIXED_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_FIXED *pMUD)
Definition mud_all.c:76
int MUD_SEC_UNKNOWN_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_UNKNOWN *pMUD)
Definition mud_all.c:236
int MUD_SEC_CMT_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_CMT *pMUD)
Definition mud_all.c:165
int MUD_SEC_GRP_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GRP *pMUD)
Definition mud_all.c:107
int MUD_SEC_proc(MUD_OPT op, BUF *pBuf, MUD_SEC *pMUD)
Definition mud_all.c:30
int MUD_SEC_EOF_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_EOF *pMUD)
Definition mud_all.c:53
int MUD_SEC_GEN_ARRAY_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GEN_ARRAY *pMUD)
Definition mud_gen.c:419
int MUD_SEC_GEN_HIST_HDR_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GEN_HIST_HDR *pMUD)
Definition mud_gen.c:196
int MUD_SEC_GEN_SCALER_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GEN_SCALER *pMUD)
Definition mud_gen.c:316
int MUD_SEC_GEN_IND_VAR_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GEN_IND_VAR *pMUD)
Definition mud_gen.c:357
int MUD_SEC_GEN_HIST_DAT_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GEN_HIST_DAT *pMUD)
Definition mud_gen.c:283
int MUD_SEC_GEN_RUN_DESC_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_GEN_RUN_DESC *pMUD)
Definition mud_gen.c:45
MUD_SEC * MUD_new(UINT32 secID, UINT32 instanceID)
Definition mud_new.c:34
int MUD_SEC_TRI_TI_RUN_DESC_proc(MUD_OPT op, BUF *pBuf, MUD_SEC_TRI_TI_RUN_DESC *pMUD)
Definition mud_tri_ti.c:30
UINT32 secID
Definition mud.h:228
UINT32 instanceID
Definition mud.h:229
UINT32 sizeOf
Definition mud.h:230
MUD_PROC proc
Definition mud.h:231
MUD_CORE core
Definition mud.h:261