(FIX) Fixed problem of multiple same output for one Status from PrintStatus.
This commit is contained in:
@@ -222,7 +222,6 @@ 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);
|
||||||
bool StatusUtils_HasPrev(Status inst);
|
bool StatusUtils_HasPrev(Status inst);
|
||||||
bool StatusUtils_IsOkay(Status inst);
|
bool StatusUtils_IsOkay(Status inst);
|
||||||
bool StatusUtils_IsValid(Status inst);
|
|
||||||
bool StatusUtils_IsRecursive(Status inst);
|
bool StatusUtils_IsRecursive(Status inst);
|
||||||
int StatusUtils_Depth(Status *inst);
|
int StatusUtils_Depth(Status *inst);
|
||||||
|
|
||||||
@@ -331,6 +330,11 @@ DEFSTATUS(ImprecisionError, 1,
|
|||||||
|
|
||||||
// ---------------------USER DEFINED-----------------------
|
// ---------------------USER DEFINED-----------------------
|
||||||
|
|
||||||
|
// The meaning of value is defined by the function itself.
|
||||||
|
DEFSTATUS(TraditionalFunctionReturn, 0,
|
||||||
|
"Function has returned an integer.",
|
||||||
|
STATUS_UNKNOWN, &UnknownStatus);
|
||||||
|
|
||||||
DEFSTATUS(UnavailableInstance, 1,
|
DEFSTATUS(UnavailableInstance, 1,
|
||||||
"An unavailable instance was given for initialisation.",
|
"An unavailable instance was given for initialisation.",
|
||||||
STATUS_ERROR, &NullPointerAccounted);
|
STATUS_ERROR, &NullPointerAccounted);
|
||||||
@@ -399,6 +403,39 @@ DEFSTATUS(InvalidLiteralisingBuffer, 1,
|
|||||||
"Given buffer does not have a good integrity on its length.",
|
"Given buffer does not have a good integrity on its length.",
|
||||||
STATUS_ERROR, &InvalidObject);
|
STATUS_ERROR, &InvalidObject);
|
||||||
|
|
||||||
|
// ========================================================
|
||||||
|
|
||||||
|
static inline Status PrintStatus(Status s)
|
||||||
|
{
|
||||||
|
char buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||||
|
(void)Status_Literalise(&s, buff);
|
||||||
|
|
||||||
|
where(fprintf(stderr, "%s\n", buff), {
|
||||||
|
return apply(value(TraditionalFunctionReturn, _));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void PrintStatusDump(Status s)
|
||||||
|
{
|
||||||
|
Status stat = s;
|
||||||
|
const int dump_len = StatusUtils_Depth(&stat);
|
||||||
|
Status dump[dump_len];
|
||||||
|
StatusUtils_Dump(&stat, dump, 0);
|
||||||
|
/* TODO(william): Replace following line with coloured-term-output function. */
|
||||||
|
(void)printf("\e[1m======== STATUS STACK DUMP: %s ========\e[0m\n",
|
||||||
|
stat.identity);
|
||||||
|
for (register int i = 0; i < dump_len; i++) {
|
||||||
|
/* TODO(william): Replace following line with coloured-term-output function. */
|
||||||
|
(void)printf("\e[1m[%d/%d]\e[0m\n", (dump_len - i), dump_len);
|
||||||
|
seek(PrintStatus(dump[i]), {
|
||||||
|
solve(!_.value, {
|
||||||
|
(void)fprintf(stderr, "\e[38;5;9m!!!!!!!! PRINT DUMP FAILED !!!!!!!!"
|
||||||
|
"\e[0m\n");
|
||||||
|
(void)PrintStatus(_);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ========================================================
|
// ========================================================
|
||||||
|
|
||||||
@@ -424,14 +461,14 @@ DEFSTATUS(InvalidLiteralisingBuffer, 1,
|
|||||||
|
|
||||||
/* Add location parameter requirement in order to give proper information
|
/* Add location parameter requirement in order to give proper information
|
||||||
* before throwing the report out. */
|
* before throwing the report out. */
|
||||||
# define throw(report) __throw(report, __HERE__)
|
# define throw(report) THROW(report, __HERE__)
|
||||||
|
|
||||||
/* Useless in C, only for human to see.
|
/* Useless in C, only for human to see.
|
||||||
Probably rewrite this in Classify. */
|
Probably rewrite this in Classify. */
|
||||||
# define throws(e)
|
# define throws(e)
|
||||||
|
|
||||||
ReportSendingTaskID __throw(Report report, Location loc);
|
ReportSendingTaskID THROW(Report report, Location loc);
|
||||||
Report catch(ReportSendingTaskID taskid);
|
Report CATCH(ReportSendingTaskID taskid);
|
||||||
int HANDLER(void *report);
|
int HANDLER(void *report);
|
||||||
|
|
||||||
#endif /* COMPOUND_STATUS_H */
|
#endif /* COMPOUND_STATUS_H */
|
||||||
|
@@ -62,30 +62,31 @@ Status Status_Literalise(Status *inst, char *buff)
|
|||||||
/* Literalise loc. */
|
/* Literalise loc. */
|
||||||
char loc_buff[LITERALISATION_LENGTH_MAXIMUM];
|
char loc_buff[LITERALISATION_LENGTH_MAXIMUM];
|
||||||
notok(Location_Literalise(&inst->loc, loc_buff), {
|
notok(Location_Literalise(&inst->loc, loc_buff), {
|
||||||
return _;
|
return apply(_);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Styling output. */
|
/* Styling output. */
|
||||||
|
// TODO(william): Replace following lines with
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
if (inst->characteristic == STATUS_ERROR) {
|
if (inst->characteristic == STATUS_ERROR) {
|
||||||
// TODO(william): Replace following line with coloured-term-output function.
|
// TODO(william): Replace following line with coloured-term-output function.
|
||||||
fmt = "\e[38;5;9m\e[4m\e[1m"STATUS_LITERALISE_FORMAT"\e[0m";
|
fmt = "\e[38;5;9m\e[1m"STATUS_LITERALISE_FORMAT"\e[0m";
|
||||||
} else if (inst->characteristic == STATUS_UNKNOWN) {
|
} else if (inst->characteristic == STATUS_UNKNOWN) {
|
||||||
// TODO(william): Replace following line with coloured-term-output function.
|
// TODO(william): Replace following line with coloured-term-output function.
|
||||||
fmt = "\e[38;5;11m\e[4m"STATUS_LITERALISE_FORMAT"\e[0m";
|
fmt = "\e[38;5;11m"STATUS_LITERALISE_FORMAT"\e[0m";
|
||||||
} else {
|
} else {
|
||||||
// TODO(william): Replace following line with coloured-term-output function.
|
// TODO(william): Replace following line with coloured-term-output function.
|
||||||
fmt = "\e[38;5;10m\e[2m"STATUS_LITERALISE_FORMAT"\e[0m";
|
fmt = "\e[38;5;10m"STATUS_LITERALISE_FORMAT"\e[0m";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Concatenate every buffer. */
|
/* Concatenate every buffer. */
|
||||||
state(!sprintf(buff, fmt,
|
where(sprintf(buff, fmt, inst->identity, inst->description,
|
||||||
inst->identity, inst->description,
|
(!inst->prev
|
||||||
(!inst->prev ? "(null)" : (inst->prev->identity)),
|
? "(null)"
|
||||||
inst->value, inst->characteristic, loc_buff),
|
: (inst->prev->identity)),
|
||||||
apply(error(ReadWriteError, "No bytes were written into buffer.")));
|
inst->value, inst->characteristic, loc_buff), {
|
||||||
|
return apply(value(TraditionalFunctionReturn, _));
|
||||||
return apply(NormalStatus);
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StatusUtils_HasPrev(Status stat)
|
bool StatusUtils_HasPrev(Status stat)
|
||||||
@@ -98,12 +99,6 @@ bool StatusUtils_IsOkay(Status stat)
|
|||||||
return (!stat.characteristic);
|
return (!stat.characteristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StatusUtils_IsValid(Status stat)
|
|
||||||
{
|
|
||||||
return (!strcmp(stat.description, "") && stat.characteristic >= 0
|
|
||||||
&& !stat.prev);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StatusUtils_IsRecursive(Status stat)
|
bool StatusUtils_IsRecursive(Status stat)
|
||||||
{
|
{
|
||||||
return (stat.prev && stat.prev == &stat);
|
return (stat.prev && stat.prev == &stat);
|
||||||
@@ -111,9 +106,8 @@ bool StatusUtils_IsRecursive(Status stat)
|
|||||||
|
|
||||||
void StatusUtils_Dump(Status *inst, Status *store, int idx)
|
void StatusUtils_Dump(Status *inst, Status *store, int idx)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
||||||
svoid((!store || !StatusUtils_HasPrev(*inst) || idx < 0));
|
svoid((!inst || !store || idx < 0));
|
||||||
|
|
||||||
store[idx] = *inst;
|
store[idx] = *inst;
|
||||||
|
|
||||||
@@ -128,7 +122,9 @@ int StatusUtils_Depth(Status *stat)
|
|||||||
Status *p = stat; // Include this layer of Status.
|
Status *p = stat; // Include this layer of Status.
|
||||||
register int cnt;
|
register int cnt;
|
||||||
for (cnt = 0; (!StatusUtils_IsRecursive(*p)
|
for (cnt = 0; (!StatusUtils_IsRecursive(*p)
|
||||||
&& StatusUtils_HasPrev(*p)); cnt++) p = p->prev;
|
&& StatusUtils_HasPrev(*p)); cnt++) {
|
||||||
|
p = p->prev;
|
||||||
|
}
|
||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
@@ -288,7 +284,7 @@ Status ReportSender_Send(ReportSender *inst, ReportSendingTask task)
|
|||||||
// || (inst1->external_param == inst2->external_param);
|
// || (inst1->external_param == inst2->external_param);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
ReportSendingTaskID _throw(Report report, Location loc)
|
ReportSendingTaskID THROW(Report report, Location loc)
|
||||||
{
|
{
|
||||||
// // /* Create new a instance of ReportSender. */
|
// // /* Create new a instance of ReportSender. */
|
||||||
// // ReportSender sender;
|
// // ReportSender sender;
|
||||||
|
2
catlog.c
2
catlog.c
@@ -91,7 +91,7 @@ Status CatlogSender_Send(CatlogSender *inst)
|
|||||||
/* Skip unavailable instances and parameters. */
|
/* Skip unavailable instances and parameters. */
|
||||||
fails(inst, apply(UnavailableInstance));
|
fails(inst, apply(UnavailableInstance));
|
||||||
|
|
||||||
const int written = fprintf(inst->dst, "%s", inst->msg.content);
|
const int written = fprintf(inst->dst, "%s\n", inst->msg.content);
|
||||||
|
|
||||||
/* Write msg. */
|
/* Write msg. */
|
||||||
state(!written, error(ReadWriteError, "No bytes were written into buffer."));
|
state(!written, error(ReadWriteError, "No bytes were written into buffer."));
|
||||||
|
51
common.h
51
common.h
@@ -23,6 +23,18 @@
|
|||||||
/* Another way to handle if statements more cleanly. */
|
/* Another way to handle if statements more cleanly. */
|
||||||
# define solve(s, b) { if (s) b }
|
# define solve(s, b) { if (s) b }
|
||||||
|
|
||||||
|
/* Handling expression with its result. */
|
||||||
|
# define when(expr, b) { int _ = expr; if (expr) b }
|
||||||
|
|
||||||
|
/* Handling expression with its calculated result. */
|
||||||
|
# define where(expr, b) { int _ = expr; b }
|
||||||
|
|
||||||
|
# define ok(s, b) { Status _ = s; if (StatusUtils_IsOkay(_)) b }
|
||||||
|
|
||||||
|
# define notok(s, b) { Status _ = s; if (!StatusUtils_IsOkay(_)) b }
|
||||||
|
|
||||||
|
# define seek(s, b) { Status _ = s; b }
|
||||||
|
|
||||||
/* Create a new UnknownStatus on the fly. */
|
/* Create a new UnknownStatus on the fly. */
|
||||||
# define unknown(e, c, v) ((Status) {\
|
# define unknown(e, c, v) ((Status) {\
|
||||||
.identity = e.identity,\
|
.identity = e.identity,\
|
||||||
@@ -60,7 +72,7 @@
|
|||||||
.description = e.description,\
|
.description = e.description,\
|
||||||
.characteristic = p.characteristic,\
|
.characteristic = p.characteristic,\
|
||||||
.loc = __HERE__,\
|
.loc = __HERE__,\
|
||||||
.prev = &p\
|
.prev = (Status *)&p\
|
||||||
})
|
})
|
||||||
|
|
||||||
# define value(e, v) ((Status) {\
|
# define value(e, v) ((Status) {\
|
||||||
@@ -98,12 +110,6 @@
|
|||||||
CatlogSender_Send(&sender);\
|
CatlogSender_Send(&sender);\
|
||||||
}
|
}
|
||||||
|
|
||||||
# define ok(s, b) { Status _ = s; if (StatusUtils_IsOkay(_)) b }
|
|
||||||
|
|
||||||
# define notok(s, b) { Status _ = s; if (!StatusUtils_IsOkay(_)) b }
|
|
||||||
|
|
||||||
# define seek(s, b) { Status _ = s; b }
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @brief Forcibly return desired value $v once $s is not $k.
|
// * @brief Forcibly return desired value $v once $s is not $k.
|
||||||
// * @return $v once state for $s is false.
|
// * @return $v once state for $s is false.
|
||||||
@@ -125,22 +131,23 @@
|
|||||||
// (void)printf("%s\n", buff);\
|
// (void)printf("%s\n", buff);\
|
||||||
// }
|
// }
|
||||||
|
|
||||||
# define print_status(s) {\
|
// # define print_status(s) {\
|
||||||
char buff[LITERALISATION_LENGTH_MAXIMUM];\
|
// char buff[LITERALISATION_LENGTH_MAXIMUM];\
|
||||||
(void)Status_Literalise(&s, buff);\
|
// (void)Status_Literalise(&s, buff);\
|
||||||
(void)fprintf(stderr, "%s\n", buff);\
|
// (void)fprintf(stderr, "%s\n", buff);\
|
||||||
}
|
// }
|
||||||
|
|
||||||
# define print_statusdump(s) {\
|
// # define print_statusdump(s) {\
|
||||||
Status _ = s;\
|
// Status _ = s;\
|
||||||
const int dump_len = StatusUtils_Depth(&_);\
|
// const int dump_len = StatusUtils_Depth(&_);\
|
||||||
Status dump[dump_len];\
|
// Status dump[dump_len];\
|
||||||
StatusUtils_Dump(&_, dump, 0);\
|
// StatusUtils_Dump(&_, dump, 0);\
|
||||||
for (register int i = 0; i < dump_len; i++) {\
|
// for (register int i = 0; i < dump_len; i++) {\
|
||||||
(void)printf("%d/%d\n", i, dump_len - 1);\
|
// /* TODO(william): Replace following line with coloured-term-output function. */\
|
||||||
print_status(dump[i]);\
|
// (void)printf("\e[1m[%d/%d]\e[0m\n", i, dump_len - 1);\
|
||||||
}\
|
// print_status(dump[i]);\
|
||||||
}
|
// }\
|
||||||
|
// }
|
||||||
|
|
||||||
# define strnil(s) (!s ? ("(null)") : s)
|
# define strnil(s) (!s ? ("(null)") : s)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user