(FEA) Compound is now fully featured with literalisation of Status along with its printting!
This commit is contained in:
@@ -187,7 +187,8 @@ bool Location_Equals(Location lc1, Location lc2);
|
||||
Status Status_Literalise(Status *inst, char *buff);
|
||||
Status Status_LiteraliseForReport(Status *inst, char *buff);
|
||||
bool Status_Equal(Status *stat1, Status *stat2);
|
||||
void StatusUtils_Dump(Status *inst, Status *store, int idx);
|
||||
// void StatusUtils_Dump(Status *inst, Status **store, int idx);
|
||||
void StatusUtils_Dump(Status *inst, Status *store);
|
||||
bool StatusUtils_HasPrev(Status inst);
|
||||
bool StatusUtils_IsOkay(Status inst);
|
||||
bool StatusUtils_IsRecursive(Status inst);
|
||||
@@ -406,28 +407,39 @@ static inline Status PrintStatus(Status s)
|
||||
static inline void PrintStatusDump(Status s)
|
||||
{
|
||||
/* Create dump. */
|
||||
Status store = s;
|
||||
const int dump_len = StatusUtils_Depth(&store);
|
||||
const int dump_len = StatusUtils_Depth(&s);
|
||||
Status dump[dump_len];
|
||||
StatusUtils_Dump(&store, dump, dump_len);
|
||||
Status current = s;
|
||||
dump[0] = current; // Put self at leading.
|
||||
for (register int i = 1; i < dump_len; i++) {
|
||||
// StatusUtils_Dump will only access (storage) the prev.
|
||||
// It does not include this status itself.
|
||||
StatusUtils_Dump(¤t, &dump[i]);
|
||||
current = *current.prev;
|
||||
}
|
||||
|
||||
/* Output by iterating. */
|
||||
for (register int i = 0; i < dump_len; i++) {
|
||||
seek(PrintStatus(dump[i]), { // Get returning status.
|
||||
|
||||
unsure(PrintStatus(dump[i]), !_.value, {
|
||||
(void)fprintf(stderr, "Unable to literalise.\n");
|
||||
})
|
||||
|
||||
// seek(PrintStatus(dump[i]), { // Get returning status.
|
||||
|
||||
/* Handle TraditionalFunctionReturn. */
|
||||
nest(_, __, unsure(__, !__.value, { // No bytes were written to buffer.
|
||||
(void)fprintf(stderr, "Unable to literalise.\n");
|
||||
return;
|
||||
}));
|
||||
// /* Handle TraditionalFunctionReturn. */
|
||||
// nest(_, __, unsure(__, !__.value, { // No bytes were written to buffer.
|
||||
// (void)fprintf(stderr, "Unable to literalise.\n");
|
||||
// return;
|
||||
// }));
|
||||
|
||||
// Handle abnormal status.
|
||||
nest(_, __, notok(__, {
|
||||
/* Output the description as explanation. */
|
||||
(void)fprintf(stderr, "%s\n", __.description);
|
||||
return;
|
||||
}));
|
||||
});
|
||||
// // Handle abnormal status.
|
||||
// nest(_, __, notok(__, {
|
||||
// /* Output the description as explanation. */
|
||||
// (void)fprintf(stderr, "%s\n", __.description);
|
||||
// return;
|
||||
// }));
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,11 +6,11 @@ Status Location_Literalise(Location *inst, char *buff)
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
/* Literalise line. */
|
||||
char line_buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||
char line_buff[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||
Utils_LiteraliseInteger(inst->line, line_buff);
|
||||
|
||||
where(
|
||||
!snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
||||
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
||||
LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func),
|
||||
return apply(value(TraditionalFunctionReturn, _));
|
||||
);
|
||||
@@ -48,8 +48,10 @@ Status Status_Literalise(Status *inst, char *buff)
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
/* Literalise loc. */
|
||||
char loc_buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||
notok(Location_Literalise(&inst->loc, loc_buff), {
|
||||
char loc_buff[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||
(void)printf("%s\n", loc_buff);
|
||||
unsure(Location_Literalise(&inst->loc, loc_buff), !_.value, {
|
||||
(void)printf("failed on loc liter.\n");
|
||||
return apply(_);
|
||||
});
|
||||
|
||||
@@ -107,31 +109,61 @@ bool StatusUtils_IsRecursive(Status stat)
|
||||
return (stat.prev && stat.prev == &stat);
|
||||
}
|
||||
|
||||
void StatusUtils_Dump(Status *inst, Status *store, int idx)
|
||||
void StatusUtils_Dump(Status *inst, Status *store)
|
||||
{
|
||||
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
||||
svoid((!inst || !store || idx < 0));
|
||||
|
||||
store[idx] = *inst;
|
||||
/* Skip when store is unavailable, or, inst is unavailable,
|
||||
recursive or does not have any predecessor. */
|
||||
svoid(!inst || !store
|
||||
|| StatusUtils_IsRecursive(*inst) || !StatusUtils_HasPrev(*inst));
|
||||
|
||||
StatusUtils_Dump(inst->prev, store, --idx);
|
||||
*store = *inst->prev;
|
||||
}
|
||||
|
||||
// void StatusUtils_Dump(Status *inst, Status **store, int idx)
|
||||
// {
|
||||
// /* Skip when having invalid inst, store or idx. */
|
||||
// svoid(!inst || !store || idx < 0 || StatusUtils_IsRecursive(*inst));
|
||||
|
||||
// // store[idx] = *inst;
|
||||
// *store[idx] = (Status){
|
||||
// .identity = inst->identity,
|
||||
// .value = inst->value,
|
||||
// .description = inst->description,
|
||||
// .characteristic = inst->characteristic,
|
||||
// .loc = inst->loc,
|
||||
// .prev = inst->prev
|
||||
// };
|
||||
|
||||
// (void)printf("idx: %d\n", idx);
|
||||
|
||||
// StatusUtils_Dump(inst->prev, store, (idx - 1));
|
||||
// }
|
||||
|
||||
int StatusUtils_Depth(Status *stat)
|
||||
{
|
||||
/* Skip unavailable stat. */
|
||||
state((!stat || !stat->prev), -1);
|
||||
|
||||
Status *p = stat; // Include this layer of Status.
|
||||
register int cnt;
|
||||
for (cnt = 0; (!StatusUtils_IsRecursive(*p)
|
||||
&& StatusUtils_HasPrev(*p)); cnt++) {
|
||||
(void)printf("Depth: %d\n", cnt);
|
||||
p = p->prev;
|
||||
|
||||
/* Set up counter. */
|
||||
int cnt = 1;
|
||||
/* Set up current status indication representor. */
|
||||
Status current = *stat;
|
||||
/* Iterate to accumulate. */
|
||||
while (current.prev) {
|
||||
current = *current.prev;
|
||||
cnt += 1;
|
||||
}
|
||||
|
||||
(void)printf("Depth returns: %d\n", cnt);
|
||||
return cnt;
|
||||
|
||||
// Status *current = stat; // Include this layer of Status.
|
||||
// register int cnt;
|
||||
// for (cnt = 0; (!StatusUtils_IsRecursive(*current)
|
||||
// && StatusUtils_HasPrev(*current)); cnt++) {
|
||||
// current = current->prev;
|
||||
// }
|
||||
|
||||
// return cnt;
|
||||
}
|
||||
|
||||
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||
@@ -199,10 +231,10 @@ Status Report_Literalise(Report *inst, char *buff)
|
||||
nonull(buff, apply(UnavailableBuffer));
|
||||
|
||||
/* Report literalisation. */
|
||||
char report_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||
|
||||
/** Status literalisation. **/
|
||||
char status_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
||||
char status_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||
|
||||
/* Fault detection on status literalisation. */
|
||||
// settle(Status_LiteraliseForReport(&inst->status, status_literalising),
|
||||
|
Reference in New Issue
Block a user