Commit 2e4c846c authored by Christoffer Ackelman's avatar Christoffer Ackelman

Refactored pwr_lst to remove redundant pointer to data,

the data struct already contain the linked list,
so the linked list do not need pointers to the data.
parent a557a8ee
......@@ -59,27 +59,24 @@ typedef struct sAttribute sAttribute;
typedef struct sObject sObject;
typedef struct sSupObject sSupObject;
LstType(sAttribute);
LstType(sSupObject);
struct sObject {
tree_sNode tn;
pwr_tObjid oid;
int sup_c;
int attr_c;
LstHead(sAttribute) attr_l;
struct LstHead attr_l;
};
struct sAttribute {
LstLink(sAttribute) attr_l;
struct LstHead attr_l;
pwr_sAttrRef aref;
pwr_tClassId cid;
int sup_c;
LstHead(sSupObject) sup_l;
struct LstHead sup_l;
};
struct sSupObject {
LstLink(sSupObject) sup_l;
struct LstHead sup_l;
pwr_tObjid oid;
void* p;
};
......@@ -100,8 +97,8 @@ static alimsrv_sSupDataBuf* buildBuffer(
sObject* op;
sAttribute* ap;
sSupObject* sp;
LstLink(sAttribute) * al;
LstLink(sSupObject) * sl;
struct LstHead * al;
struct LstHead * sl;
pwr_tStatus sts;
*size = 0;
......@@ -123,15 +120,15 @@ static alimsrv_sSupDataBuf* buildBuffer(
bp->NoOfSupAttr = op->attr_c;
bap = bp->AttrSupList;
for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) {
ap = LstObj(al);
LstForEach(al, &op->attr_l) {
ap = LstEntry(al, sAttribute, attr_l);
bap->SupAttr = ap->aref;
bap->NoOfSupObjs = ap->sup_c;
bap->SupClass = ap->cid;
bsp = bap->SupList;
for (sl = LstFir(&ap->sup_l); sl != LstEnd(&ap->sup_l); sl = LstNex(sl)) {
sp = LstObj(sl);
LstForEach(sl, &ap->sup_l) {
sp = LstEntry(sl, sSupObject, sup_l);
bsp->SupObjid = sp->oid;
if (ap->cid == pwr_cClass_ASup) {
pwr_sClass_ASup* asup = (pwr_sClass_ASup*)sp->p;
......@@ -160,12 +157,12 @@ static alimsrv_sSupDataBuf* buildBuffer(
static sAttribute* findAttribute(
sObject* op, pwr_sAttrRef* aref, pwr_tClassId cid)
{
LstLink(sAttribute) * al;
struct LstHead * al;
sAttribute* ap = NULL;
for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) {
if (aref->Offset == LstObj(al)->aref.Offset) {
ap = LstObj(al);
LstForEach(al, &op->attr_l) {
if (aref->Offset == LstEntry(al, sAttribute, attr_l)->aref.Offset) {
ap = LstEntry(al, sAttribute, attr_l);
break;
}
}
......@@ -175,9 +172,9 @@ static sAttribute* findAttribute(
if (ap == NULL)
exit(2);
LstIni(&ap->attr_l);
LstIni(&ap->sup_l);
(void)LstIns(&op->attr_l, ap, attr_l);
LstInit(&ap->attr_l);
LstInit(&ap->sup_l);
LstInsert(&op->attr_l, &ap->attr_l);
op->attr_c++;
ap->cid = cid;
ap->aref = *aref;
......@@ -204,13 +201,13 @@ static void init()
op = tree_Find(&sts, ltp, &asp->Attribute.Objid);
if (op == NULL) {
op = tree_Insert(&sts, ltp, &asp->Attribute.Objid);
LstIni(&op->attr_l);
LstInit(&op->attr_l);
}
ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup);
sp = calloc(1, sizeof(*sp));
(void)LstIns(LstEnd(&ap->sup_l), sp, sup_l);
LstInsert(&ap->sup_l, &sp->sup_l);
sp->oid = oid;
sp->p = asp;
op->sup_c++;
......@@ -225,13 +222,13 @@ static void init()
op = tree_Find(&sts, ltp, &dsp->Attribute.Objid);
if (op == NULL) {
op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid);
LstIni(&op->attr_l);
LstInit(&op->attr_l);
}
ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup);
sp = calloc(1, sizeof(*sp));
(void)LstIns(LstEnd(&ap->sup_l), sp, sup_l);
LstInsert(&ap->sup_l, &sp->sup_l);
sp->oid = oid;
sp->p = dsp;
op->sup_c++;
......
This diff is collapsed.
......@@ -69,11 +69,9 @@ typedef enum { eTimer_ScanMessage = 1 } eTimer;
typedef struct s_Node sNode;
LstType(sNode);
struct s_Node {
LstLink(sNode) node_l;
LstLink(sNode) timer_l;
struct LstHead node_l;
struct LstHead timer_l;
pwr_tObjid oid;
pwr_sClass_NodeLinkSup node;
pwr_sClass_NodeLinkSup* o;
......@@ -84,8 +82,8 @@ struct s_Node {
};
static eListState list_state = eListState_Init;
static LstHead(sNode) node_l;
static LstHead(sNode) timer_l;
static struct LstHead node_l;
static struct LstHead timer_l;
static void detect(pwr_sClass_NodeLinkSup*, pwr_tBoolean, sNode*);
static void event(qcom_sGet*);
......@@ -137,11 +135,11 @@ int main(int argc, char** argv)
plc_UtlWaitForPlc();
LstIni(&node_l);
LstIni(&timer_l);
LstInit(&node_l);
LstInit(&timer_l);
init_nodes();
if (!LstEmp(&node_l)) {
if (!LstEmpty(&node_l)) {
list_state = eListState_Scan;
} else {
errh_Info("No nodes to supervise, exiting");
......@@ -195,8 +193,8 @@ static void detect(pwr_sClass_NodeLinkSup* o, pwr_tBoolean con, sNode* np)
if (o->DetectCheck) {
o->TimerCount = (o->TimerTime * 1000) / cTimerTimeDetect;
if (!o->TimerFlag && o->TimerCount > 0) {
if (!LstInl(&np->timer_l)) {
LstIns(&timer_l, np, timer_l);
if (LstIsNull(&np->timer_l)) {
LstInsert(&timer_l, &np->timer_l);
}
o->TimerFlag = TRUE;
}
......@@ -229,7 +227,7 @@ static void event(qcom_sGet* get)
if (new_event.b.swapDone & !cur_event.b.swapDone) {
errh_Info("Warm restart completed.");
reinit_nodes();
if (!LstEmp(&node_l)) {
if (!LstEmpty(&node_l)) {
list_state = eListState_Scan;
scan_timers();
scan_nodes();
......@@ -322,21 +320,22 @@ static sNode* init_node(pwr_tObjid oid, sNode* np, pwr_tBoolean new_sub)
static pwr_tStatus init_nodes()
{
pwr_tStatus sts;
LstLink(sNode) * nl;
struct LstHead * nl;
sNode* np;
pwr_tObjid oid;
nl = LstEnd(&node_l);
nl = &node_l;
for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) {
np = init_node(oid, NULL, 1);
if (np != NULL) {
nl = LstIns(nl, np, node_l);
LstInsert(nl, &np->node_l);
nl = &np->node_l;
}
}
if (LstEmp(&node_l))
if (LstEmpty(&node_l))
errh_Info("No NodeLink objects");
return (sts);
......@@ -346,11 +345,11 @@ static pwr_tStatus init_nodes()
static sNode* get_nodes(pwr_tObjid oid)
{
LstLink(sNode) * nl;
struct LstHead * nl;
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) {
if (cdh_ObjidIsEqual(LstObj(nl)->oid, oid))
return LstObj(nl);
LstForEach(nl, &node_l) {
if (cdh_ObjidIsEqual(LstEntry(nl, sNode, node_l)->oid, oid))
return LstEntry(nl, sNode, node_l);
}
return NULL;
......@@ -359,20 +358,21 @@ static sNode* get_nodes(pwr_tObjid oid)
static void reinit_nodes()
{
pwr_tStatus sts;
LstLink(sNode) * nl;
struct LstHead * nl;
sNode* np;
pwr_tObjid oid;
/* Mark all links in the NodeLink list */
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl))
LstObj(nl)->found = FALSE;
LstForEach(nl, &node_l)
LstEntry(nl, sNode, node_l)->found = FALSE;
for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) {
if ((np = get_nodes(oid)) == NULL) {
np = init_node(oid, NULL, 1);
if (np != NULL) {
nl = LstIns(nl, np, node_l);
LstInsert(nl, &np->node_l);
nl = &np->node_l;
np->found = TRUE;
}
} else {
......@@ -380,12 +380,12 @@ static void reinit_nodes()
}
}
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) {
np = LstObj(nl);
LstForEach(nl, &node_l) {
np = LstEntry(nl, sNode, node_l);
if (!np->found) {
nl = LstPre(&np->node_l);
LstRem(&np->node_l);
LstNul(&np->node_l);
nl = np->node_l.prev;
LstRemove(&np->node_l);
LstNull(&np->node_l);
gdh_SubUnrefObjectInfo(np->o->SubId);
gdh_DLUnrefObjectInfo(np->dlid);
free(np);
......@@ -395,7 +395,7 @@ static void reinit_nodes()
static void scan_nodes()
{
LstLink(sNode) * nl;
struct LstHead * nl;
pwr_tStatus sts;
pwr_tBoolean Old;
pwr_tTime LastUpdate, Timeout, CurrentTime;
......@@ -404,8 +404,8 @@ static void scan_nodes()
time_GetTime(&CurrentTime);
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) {
sNode* np = LstObj(nl);
LstForEach(nl, &node_l) {
sNode* np = LstEntry(nl, sNode, node_l);
pwr_sClass_NodeLinkSup* o = np->o;
LinkUp = 0;
sts = gdh_GetSubscriptionOldness(o->SubId, &Old, &LastUpdate, NULL);
......@@ -435,17 +435,17 @@ static void scan_nodes()
static void scan_timers()
{
LstLink(sNode) * nl, *nxtnl;
struct LstHead * nl, *nxtnl;
plc_sTimer* tp;
for (nl = LstFir(&timer_l); nl != LstEnd(&timer_l); nl = nxtnl) {
tp = LstObj(nl)->timer;
nxtnl = LstNex(nl);
for (nl = timer_l.next; nl != &timer_l; nl = nxtnl) {
tp = LstEntry(nl, sNode, timer_l)->timer;
nxtnl = nl->next;
if (tp->TimerCount <= 1 || !tp->TimerFlag) {
tp->TimerCount = 0;
tp->TimerFlag = FALSE;
LstRem(nl);
LstNul(nl);
LstRemove(nl);
LstNull(nl);
} else {
tp->TimerCount--;
}
......
......@@ -57,19 +57,17 @@
typedef struct s_Timer sTimer;
LstType(sTimer);
struct s_Timer {
LstLink(sTimer) ll;
struct LstHead ll;
time_tClock clock;
pwr_tBoolean wrapped;
void* data;
void (*exec)();
};
static LstHead(sTimer) timer_lh;
static LstHead(sTimer) wrap_lh;
static LstHead(sTimer) free_lh;
static struct LstHead timer_lh;
static struct LstHead wrap_lh;
static struct LstHead free_lh;
static time_tClock now_clock;
static time_tClock last_clock;
......@@ -104,7 +102,7 @@ static void waitClock(time_tClock c, int* tmo_ms);
static void setInterval(time_tClock* c, pwr_tUInt32 i);
static void executeExpired(LstHead(sTimer) * lh, pwr_tBoolean force);
static void executeExpired(struct LstHead * lh, pwr_tBoolean force);
static void getNewTimers();
......@@ -370,16 +368,16 @@ static void cacheTrim(sTimer* tp)
static void insertTimer(sTimer* tp)
{
LstLink(sTimer) * tl;
struct LstHead * tl;
sTimer* tip;
if (LstEmp(&timer_lh)) {
(void)LstIns(LstEnd(&timer_lh), tp, ll);
if (LstEmpty(&timer_lh)) {
LstInsert(&timer_lh, &tp->ll);
return;
}
for (tl = LstLas(&timer_lh); tl != LstEnd(&timer_lh); tl = LstPre(tl)) {
tip = LstObj(tl);
for (tl = timer_lh.prev; tl != &timer_lh; tl = tl->prev) {
tip = LstEntry(tl, sTimer, ll);
if (tp->wrapped) {
if (!tip->wrapped || tip->clock < tp->clock)
......@@ -388,8 +386,8 @@ static void insertTimer(sTimer* tp)
break;
}
tl = LstNex(tl);
(void)LstIns(tl, tp, ll);
tl = tl->next;
LstInsert(tl, &tp->ll);
}
/* . */
......@@ -416,7 +414,7 @@ static sTimer* newTimer(time_tClock* clock, void* data, void (*exec)())
static void freeTimer(sTimer* tp)
{
memset(tp, 0, sizeof(*tp));
LstIns(&LstEnd(free_lh), tp, ll);
LstInsert(&free_lh, &tp->ll);
}
/* . */
......@@ -425,19 +423,19 @@ static sTimer* allocTimer()
{
const int cAllocCount = 100;
sTimer* ftp;
LstLink(sTimer) * ftl;
struct LstHead * ftl;
int i;
if (LstEmp(&free_lh)) {
if (LstEmpty(&free_lh)) {
ftp = (sTimer*)calloc(cAllocCount, sizeof(sTimer));
for (i = 0; i < cAllocCount; i++, ftp++) {
LstIns(&LstEnd(free_lh), ftp, ll);
LstInsert(&free_lh, &ftp->ll);
}
}
ftl = LstFir(&free_lh);
LstRem(ftl);
return LstObj(ftl);
ftl = free_lh.next;
LstRemove(ftl);
return LstEntry(ftl, sTimer, ll);
}
static void setTimer(sTimer* tp, time_tClock offs)
......@@ -498,21 +496,21 @@ static void setInterval(time_tClock* c,
#endif
}
static void executeExpired(LstHead(sTimer) * lh, pwr_tBoolean force)
static void executeExpired(struct LstHead * lh, pwr_tBoolean force)
{
LstLink(sTimer) * tl;
struct LstHead * tl;
sTimer* tp;
gdb_AssumeUnlocked;
gdb_ScopeLock
{
for (tl = LstFir(lh); tl != LstEnd(lh); tl = LstFir(lh)) {
tp = LstObj(tl);
LstForEach(tl, lh) {
tp = LstEntry(tl, sTimer, ll);
if (force || (!tp->wrapped && tp->clock <= now_clock)) {
LstRem(tl);
LstNul(tl);
LstRemove(tl);
LstNull(tl);
tp->exec(tp);
} else
break;
......@@ -560,11 +558,11 @@ static void getNewTimers()
static void getWaitClock(time_tClock* wait_clock, time_tClock last_clock)
{
int diff;
LstLink(sTimer) * tl;
struct LstHead * tl;
sTimer* tp;
tl = LstFir(&timer_lh);
tp = LstObj(tl);
tl = timer_lh.next;
tp = LstEntry(tl, sTimer, ll);
if (now_clock < last_clock) {
if (tp->wrapped) {
......@@ -610,9 +608,9 @@ static void init()
gdbroot->db->tmon = gdbroot->my_qid;
gdbroot->is_tmon = 1;
LstIni(&timer_lh);
LstIni(&wrap_lh);
LstIni(&free_lh);
LstInit(&timer_lh);
LstInit(&wrap_lh);
LstInit(&free_lh);
last_clock = now_clock = time_Clock(NULL, NULL);
......@@ -631,18 +629,18 @@ static void init()
static void toggleWrapped()
{
LstLink(sTimer) * tl;
LstLink(sTimer) * ntl;
struct LstHead * tl;
struct LstHead * ntl;
sTimer* tp;
LstHead(sTimer)* tlh = &timer_lh;
struct LstHead* tlh = &timer_lh;
for (tl = LstFir(tlh); tl != LstEnd(tlh); tl = ntl) {
tp = LstObj(tl);
ntl = LstNex(tl);
for (tl = tlh->next; tl != tlh; tl = ntl) {
tp = LstEntry(tl, sTimer, ll);
ntl = tl->next;
if (!tp->wrapped) {
LstRem(tl);
(void)LstIns(LstEnd(&wrap_lh), tp, ll);
LstRemove(tl);
LstInsert(&wrap_lh, &tp->ll);
} else
tp->wrapped = 0;
}
......
......@@ -40,33 +40,96 @@
/* pwr_lst.h -- list macros
*/
#define LstType(a) \
typedef struct s_LstLink_##a sLstLink_##a; \
struct s_LstLink_##a { \
sLstLink_##a* nex; \
sLstLink_##a* pre; \
a* obj; \
}
struct LstHead {
struct LstHead *next, *prev;
};
#define LstLink(a) sLstLink_##a
/*
* LstInsert(s_LstLink_T* next, s_LstLink_T elem) inserts the element \a into
* the linked list before the element \a next.
*
* Before:
* a <-> c
*
* Calling LstInsert(c, b)
* a <- b (a <- b)
* b -> c (a <- b -> c)
* a -> b (a <-> b -> c)
* b <- c (a <-> b <-> c)
*/
static inline void LstInsert(struct LstHead *p, struct LstHead *e)
{
e->prev = p->prev;
e->next = p;
p->prev->next = e;
p->prev = e;
}
/*
* LstRemove(s_LstLink_T) removes the element from the linked list, which is
* done by modifying the next element to point at the previous and vice versa.
*/
static inline void LstRemove(struct LstHead *p)
{
p->next->prev = p->prev;
p->prev->next = p->next;
}
#define LstHead(a) sLstLink_##a
/*
* LstNull(s_LstLink_T) sets the linked list to NULL.
*/
static inline void LstNull(struct LstHead *p)
{
p->next = p->prev = NULL;
}
#define LstNex(p) ((p)->nex)
#define LstPre(p) ((p)->pre)
#define LstLas(h) ((h)->pre)
#define LstFir(h) ((h)->nex)
#define LstEnd(h) (h)
#define LstIns(p, o, e) \
((o)->e.obj = (void*)o, (o)->e.pre = (void*)((p)->pre), \
(o)->e.nex = (void*)(p), (p)->pre->nex = (void*)(&(o)->e), \
(p)->pre = (void*)(&(o)->e))
#define LstRem(p) ((p)->nex->pre = (p)->pre, (p)->pre->nex = (p)->nex)
#define LstNul(p) ((p)->nex = (p)->pre = NULL)
#define LstIsNul(p) ((p)->nex == NULL && (p)->pre == NULL)
#define LstInl(p) ((p)->nex != NULL && (p)->pre != NULL)
#define LstIni(h) ((h)->nex = (h)->pre = (h))
#define LstObj(p) ((p)->obj)
#define LstEmp(h) ((h) == (h)->nex)
/*
* LstIsNull(s_LstLink_T) checks if the linked list is NULL.
*/
static inline int LstIsNull(struct LstHead *p)
{
return (p->next == NULL && p->prev == NULL);
}
/*
* LstInit(s_LstLink_T) initializes the linked list.
*/
static inline void LstInit(struct LstHead *h)
{
h->next = h->prev = h;
}
/*
* LstEntry(s_LstLink_T*, sTimer, ll) fetches the struct sTimer corresponding to
* the list pointer \a ptr.
* It does this by calculating the offset of a list pointers \a ll within the
* struct sTimer, and then subtracts that from the list pointer \a ptr.
*/
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#define LstEntry(ptr, type, member) container_of(ptr, type, member)
/*
* LstEmpty(s_LstLink_T) checks if the linked list is empty.
*/
static inline int LstEmpty(struct LstHead *h)
{
return h->next == h;
}
/*
* LstForEach(i, listHead) is a convenience macro for:
* for (i = listHead->next; i != listHead, i = i->next)
*/
#define LstForEach(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#endif
This diff is collapsed.
......@@ -64,10 +64,8 @@
typedef struct s_FacilityCB sFacilityCB;
LstType(sFacilityCB);
struct s_FacilityCB {
LstLink(sFacilityCB) FacL;
struct LstHead FacL;
char* facnam;
int facnum;
};
......@@ -76,7 +74,7 @@ extern int lineno;
static int SyntaxError;
static LstHead(sFacilityCB) lFacH;
static struct LstHead lFacH;
static sFacilityCB* CurrFac = NULL;
static void CopyFile(FILE* ifp, FILE* ofp);
......@@ -122,7 +120,7 @@ int main(int argc, char** argv)
exit(1);
}
LstIni(&lFacH);
LstInit(&lFacH);
SyntaxError = 0;
lineno = 1;
......@@ -159,7 +157,7 @@ void lex_FacName(char* facnam)
void lex_FacNum(int facnum)
{
LstLink(sFacilityCB) * fl;
struct LstHead * fl;
/*
* To do: Check that the facility number is within the valid range
......@@ -167,14 +165,14 @@ void lex_FacNum(int facnum)
*/
/* Insert in ascending order */
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) {
if (LstObj(fl)->facnum > facnum) {
LstForEach(fl, &lFacH) {
if (LstEntry(fl, sFacilityCB, FacL)->facnum > facnum) {
break;
}
}
CurrFac->facnum = facnum;
LstIns(fl, CurrFac, FacL);
LstInsert(fl, &CurrFac->FacL);
CurrFac = NULL;
}
......@@ -192,20 +190,20 @@ static void CopyFile(FILE* ifp, FILE* ofp)
static void WriteFacility(FILE* cfp, char* branch)
{
LstLink(sFacilityCB) * fl;
struct LstHead * fl;
int i = 0;
fprintf(cfp, "static msg_sFacility *Facilities[] = {\n");
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) {
LstForEach(fl, &lFacH) {
if (i++)
fprintf(cfp, ",\n");
fprintf(cfp, "\t%-20s /* %4d */", LstObj(fl)->facnam, LstObj(fl)->facnum);
fprintf(cfp, "\t%-20s /* %4d */", LstEntry(fl, sFacilityCB, FacL)->facnam, LstEntry(fl, sFacilityCB, FacL)->facnum);
}
fprintf(cfp, "};\n\n");
if (LstFir(&lFacH) == LstEnd(&lFacH))
if (LstEmpty(&lFacH))
fprintf(cfp, "msg_sHead %sMsgHead = {0, 0};\n", branch ? branch : "pwrp");
else
fprintf(cfp, "msg_sHead %sMsgHead = {MSG_NOF(Facilities), Facilities};\n",
......
......@@ -61,18 +61,15 @@
typedef struct s_FacilityCB sFacilityCB;
typedef struct s_MsgCB sMsgCB;
LstType(sFacilityCB);
LstType(sMsgCB);
struct s_MsgCB {
LstLink(sMsgCB) MsgL;
struct LstHead MsgL;
msg_sMsg m;
msg_eSeverity Severity;
};
struct s_FacilityCB {
LstLink(sFacilityCB) FacL;
LstHead(sMsgCB) MsgH;
struct LstHead FacL;
struct LstHead MsgH;
msg_sFacility f;
};
......@@ -81,7 +78,7 @@ extern int lineno;
static int SyntaxError;
static LstHead(sFacilityCB) lFacH;
static struct LstHead lFacH;
/*
* Local functions
......@@ -125,7 +122,7 @@ int main(int argc, char** argv)
exit(2);
}
LstIni(&lFacH);
LstInit(&lFacH);
SyntaxError = 0;
lineno = 1;
yylex();
......@@ -160,20 +157,20 @@ void lex_FacName(const char* FacName)
{
sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB));
LstIni(&facp->MsgH);
LstInit(&facp->MsgH);
facp->f.FacName = MSG_NEW_STRING(FacName);
LstIns(&lFacH, facp, FacL);
LstInsert(&lFacH, &facp->FacL);
}
void lex_FacNum(int FacNum)
{
LstObj(LstLas(&lFacH))->f.FacNum = FacNum;
LstEntry(lFacH.prev, sFacilityCB, FacL)->f.FacNum = FacNum;
}
void lex_FacPrefix(const char* Prefix)
{
LstObj(LstLas(&lFacH))->f.Prefix = MSG_NEW_STRING(Prefix);
LstEntry(lFacH.prev, sFacilityCB, FacL)->f.Prefix = MSG_NEW_STRING(Prefix);
}
void lex_MsgName(const char* MsgName)
......@@ -187,21 +184,21 @@ void lex_MsgName(const char* MsgName)
msgp->m.MsgName[i] = toupper(MsgName[i]);
msgp->m.MsgName[i] = '\0';
(void)LstIns(&LstObj(LstLas(&lFacH))->MsgH, msgp, MsgL);
LstInsert(&LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH, &msgp->MsgL);
}
void lex_MsgText(const char* Text)
{
LstLink(sMsgCB)* ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH);
struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
TranslateFormatSpec(
Text, &LstObj(ml)->m.MsgTxt); /* convert any VMS-style form spec */
Text, &LstEntry(ml, sMsgCB, MsgL)->m.MsgTxt); /* convert any VMS-style form spec */
}
void lex_MsgSeverity(msg_eSeverity Severity)
{
LstLink(sMsgCB)* ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH);
LstObj(ml)->Severity = Severity;
struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
LstEntry(ml, sMsgCB, MsgL)->Severity = Severity;
}
void lex_LexError(int Lineno, char* Str)
......@@ -215,8 +212,8 @@ void lex_LexError(int Lineno, char* Str)
*/
static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
{
LstLink(sFacilityCB) * fl;
LstLink(sMsgCB) * ml;
struct LstHead * fl;
struct LstHead * ml;
int idx;
int facid;
char prefix[32];
......@@ -227,37 +224,38 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
fprintf(hfp, "#ifndef %s_h\n", fname);
fprintf(hfp, "#define %s_h\n\n", fname);
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) {
facid = 0x800 + LstObj(fl)->f.FacNum;
snprintf(name, sizeof(name), "%s_FACILITY", LstObj(fl)->f.FacName);
LstForEach(fl, &lFacH) {
facid = 0x800 + LstEntry(fl, sFacilityCB, FacL)->f.FacNum;
snprintf(name, sizeof(name), "%s_FACILITY", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(hfp, "#define %-29s %9d /* x%08x */\n", name, facid, facid);
facid = facid << 16;
if (LstObj(fl)->f.Prefix)
strncpy(prefix, LstObj(fl)->f.Prefix, sizeof(prefix));
if (LstEntry(fl, sFacilityCB, FacL)->f.Prefix)
strncpy(prefix, LstEntry(fl, sFacilityCB, FacL)->f.Prefix, sizeof(prefix));
else
snprintf(prefix, sizeof(prefix), "%s_", LstObj(fl)->f.FacName);
snprintf(prefix, sizeof(prefix), "%s_", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
snprintf(msgName, sizeof(msgName), "%smsg", LstObj(fl)->f.FacName);
snprintf(msgName, sizeof(msgName), "%smsg", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(cfp, "static msg_sMsg %s[] = {\n", msgName);
for (idx = 1, ml = LstFir(&LstObj(fl)->MsgH);
ml != LstEnd(&LstObj(fl)->MsgH); ml = LstNex(ml), idx++) {
idx = 1;
LstForEach(ml, &LstEntry(fl, sFacilityCB, FacL)->MsgH) {
if (idx != 1)
fprintf(cfp, ",\n");
msg = facid + 0x8000 + (idx << 3) + LstObj(ml)->Severity;
snprintf(name, sizeof(name), "%s%s", prefix, LstObj(ml)->m.MsgName);
msg = facid + 0x8000 + (idx << 3) + LstEntry(ml, sMsgCB, MsgL)->Severity;
snprintf(name, sizeof(name), "%s%s", prefix, LstEntry(ml, sMsgCB, MsgL)->m.MsgName);
fprintf(hfp, "#define %-29s %9.9d /* x%08x */\n", name, msg, msg);
fprintf(cfp, "\t{\"%s\", \"%s\"}", LstObj(ml)->m.MsgName,
LstObj(ml)->m.MsgTxt);
fprintf(cfp, "\t{\"%s\", \"%s\"}", LstEntry(ml, sMsgCB, MsgL)->m.MsgName,
LstEntry(ml, sMsgCB, MsgL)->m.MsgTxt);
idx++;
}
fprintf(cfp, "\n};\n\n");
fprintf(cfp, "static msg_sFacility %sfacility[] = {\n\t",
LstObj(fl)->f.FacName);
LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(cfp, "{%d, \"%s\", \"%s\", MSG_NOF(%s), %s}\n",
LstObj(fl)->f.FacNum, LstObj(fl)->f.FacName, prefix, msgName, msgName);
LstEntry(fl, sFacilityCB, FacL)->f.FacNum, LstEntry(fl, sFacilityCB, FacL)->f.FacName, prefix, msgName, msgName);
fprintf(cfp, "};\n\n");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment