(SOC - Test) Storage Only Commit
This commit is contained in:
@@ -118,8 +118,8 @@ TIME [PRIORITY] STATUSNAME (ORIGINATOR): STATUS.DESCRIPTION
|
||||
|
||||
|
||||
Fri 10 May 03:02:37 CST 2024 [EXCEPTIONAL] InvalidParameter (Nullity): Given buffer was unavailable.
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:104, report_literalise
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:114, reportsender_send
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:104, Report_Literalise
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:114, ReportSender_Send
|
||||
at /external/Documents/Projects/Compound/Status/src/status.c:69, _throw
|
||||
!!!!at /external/Documents/Projects/Compound/Array/src/array.c:16, array_create
|
||||
at /external/Documents/Projects/Compound/test.c:24, main
|
||||
@@ -130,10 +130,14 @@ Fri 10 May 03:02:37 CST 2024 [EXCEPTIONAL] InvalidParameter (Nullity): Given buf
|
||||
# define REPORT_LITERALISE_CHAINS_FORMAT " at %s:%d, %s"
|
||||
# define REPORT_LITERALISE_CHAINS_EXCLAIM_FORMAT "!!!!at %s:%d, %s"
|
||||
|
||||
# define REPORT_LITERALISE_HEADER_FORMAT_LENGTH(PRIORITY, STATUSNAME, \
|
||||
# define REPORT_LITERALISE_HEADER_FORMAT_LENGTH(buff, PRIORITY, STATUSNAME, \
|
||||
ORIGINATOR, DESCRIPTION) \
|
||||
(INT64_DIGITS_DEC + strlen(PRIORITY) + strlen(STATUSNAME) + \
|
||||
strlen(ORIGINATOR) + strlen(DESCRIPTION) + 9) // Does not count '\0'
|
||||
{ \
|
||||
const time_t now = time(NULL); \
|
||||
(void)strflen(buff, 28, DATETIME_FORMAT, localtime(&now)); \
|
||||
*length = strlen(buff); \
|
||||
}
|
||||
|
||||
# define REPORT_LITERALISE_CHAINS_FORMAT_LENGTH(FILEPATH, LINE, FUNCNAME) \
|
||||
(strlen(FILEPATH) + utils_calc_digits(LINE) + \
|
||||
strlen(FUNCNAME) + 10) // Does not count '\0'
|
||||
@@ -197,9 +201,10 @@ typedef struct {
|
||||
# define STATUS_BUFFER_MAXIMUM_LENGTH UINT32_MAX
|
||||
|
||||
bool Location_Equal(Location lc1, Location lc2);
|
||||
void Status_Dump(Status stat, Status *statbuff, int idx);
|
||||
bool Status_Equal(Status stat1, Status stat2);
|
||||
bool StatusUtils_HasPrev(Status stat);
|
||||
Status Status_Literalise(Status *inst, char *buff);
|
||||
void StatusUtils_Dump(Status *stat, Status *statbuff, int idx);
|
||||
bool StatusUtils_HasPrev(Status *stat);
|
||||
bool StatusUtils_IsOkay(Status stat);
|
||||
bool StatusUtils_IsValid(Status stat);
|
||||
bool StatusUtils_IsRecursive(Status stat);
|
||||
@@ -382,6 +387,7 @@ static Status ReportMessageLengthTooLong = {
|
||||
|
||||
// ========================================================
|
||||
|
||||
/* Throw the report created with $e if $e is abnormal, commented with $c. */
|
||||
# define ensure(e, c) { \
|
||||
Status stat = e; \
|
||||
solve(!(StatusUtils_IsOkay(stat)), { \
|
||||
@@ -391,6 +397,16 @@ static Status ReportMessageLengthTooLong = {
|
||||
}) \
|
||||
}
|
||||
|
||||
/* Throw the report created with $s if $e is abnormal, commented with $c. */
|
||||
# define match(s, e, c) { \
|
||||
Status stat = s; \
|
||||
solve(!(StatusUtils_IsOkay(e)), { \
|
||||
Report rep = stamp(error(stat, c), (char *)__func__); \
|
||||
(void)throw(rep); \
|
||||
return ReportThrown; \
|
||||
}) \
|
||||
}
|
||||
|
||||
/* Add location parameter requirement in order to give proper information
|
||||
* before throwing the report out. */
|
||||
# define throw(report) __throw(report, __HERE__)
|
||||
@@ -414,11 +430,11 @@ static int HANDLER(void *report)
|
||||
REPORT_SENDING_PRIORITY_FATAL);
|
||||
|
||||
/* Perform throwing. */
|
||||
(void)_throw(e); // Throw the report alone.
|
||||
(void)throw(e); // Throw the report alone.
|
||||
return 1;
|
||||
}
|
||||
|
||||
(void)_throw(*(Report *)report); // Lonely _throw, no catch will company.
|
||||
(void)throw(*(Report *)report); // Lonely _throw, no catch will company.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <Compound/common.h>
|
||||
#include <Compound/status.h>
|
||||
#include <Compound/var.h>
|
||||
|
||||
bool status_issuelocation_equal(Location lc1, Location lc2) {
|
||||
return ((!strcmp(lc1.file, lc2.file)) && (lc1.line == lc2.line) &&
|
||||
@@ -8,7 +9,7 @@ bool status_issuelocation_equal(Location lc1, Location lc2) {
|
||||
|
||||
bool status_hasprev(Status stat) {
|
||||
/* Skip when stat is unavailable for accessing. */
|
||||
state(status_equal(stat, (Status){}), false);
|
||||
state(Status_Equal(stat, (Status){}), false);
|
||||
|
||||
return (stat.prev != NULL);
|
||||
}
|
||||
@@ -24,18 +25,18 @@ bool status_recursive(Status stat) {
|
||||
return (stat.prev != NULL && stat.prev == &stat);
|
||||
}
|
||||
|
||||
void status_dump(Status inst, Status *statbuff, int idx) {
|
||||
void status_dump(Status *inst, Status *statbuff, int idx) {
|
||||
|
||||
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
||||
solve((statbuff == NULL || !status_hasprev(inst) || idx < 0), return;);
|
||||
solve((statbuff == NULL || !status_hasprev(*inst) || idx < 0), return;);
|
||||
|
||||
statbuff[idx] = inst;
|
||||
statbuff[idx] = *inst;
|
||||
(void)printf("status_dump: Index %d has assigned with %p\n", idx, &inst);
|
||||
|
||||
status_dump(*inst.prev, statbuff, ++idx);
|
||||
status_dump(inst->prev, statbuff, ++idx);
|
||||
}
|
||||
|
||||
bool status_equal(Status stat1, Status stat2) {
|
||||
bool Status_Equal(Status stat1, Status stat2) {
|
||||
|
||||
/* Skip when both stat1 and stat2 are empty. */
|
||||
state((stat1.value == 0 && stat2.value == 0 && stat1.description == 0x0 &&
|
||||
@@ -47,10 +48,15 @@ bool status_equal(Status stat1, Status stat2) {
|
||||
return ((stat1.value == stat2.value) &&
|
||||
(!strcmp(stat1.description, stat2.description)) &&
|
||||
(stat1.characteristic == stat2.characteristic) &&
|
||||
(status_equal(*stat1.prev, *stat2.prev)));
|
||||
(Status_Equal(*stat1.prev, *stat2.prev)));
|
||||
}
|
||||
|
||||
int status_depth(Status *stat) {
|
||||
Status Status_Literalise(Status *inst, char *buff)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int StatusUtils_Depth(Status *stat) {
|
||||
/* Skip unavailable stat. */
|
||||
state((stat == NULL), -1);
|
||||
|
||||
@@ -85,16 +91,41 @@ Status report_create(Report *inst, Status *stat, FILE *dest, char *originator,
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status report_literalise(Report *inst, char *buff) {
|
||||
Status Report_Literalise(Report *inst, char *buff)
|
||||
{
|
||||
/* Skip when inst or buff is unavailable. */
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(buff, error(InvalidParameter, "Given buffer was unavailable."));
|
||||
|
||||
const int depth = status_depth(&inst->stat);
|
||||
char buff // TODO(william): HERE
|
||||
/* By calculating the depth of status, we can calculate the exact length of
|
||||
literalisation of report. */
|
||||
const int depth = StatusUtils_Depth(&inst->stat);
|
||||
|
||||
/* Dump all the status. */
|
||||
Status stats[depth];
|
||||
StatusUtils_Dump(&inst->stat, stats, 0);
|
||||
|
||||
/* Literalise by iterating. */
|
||||
int report_literalised_length = 0;
|
||||
for (register int i = 0; i < depth; i++) {
|
||||
/* Literalise individual status. */
|
||||
char buff[strlen(stats[i].description) + 1 + ];
|
||||
(void)Status_Literalise(&stats[i], buff); // Ignore the returning.
|
||||
// Otherwise, if we throw the report once the returning status is abnormal,
|
||||
// this function would be called again by the throw function.
|
||||
|
||||
/* Accumulate length of report literalisation. */
|
||||
report_literalised_length += strlen(buff);
|
||||
}
|
||||
|
||||
/* Create report literalisation buffer according to
|
||||
report_literalised_length. */
|
||||
char report_literalised_buffer[report_literalised_length];
|
||||
|
||||
/* */
|
||||
}
|
||||
|
||||
Status reportsender_create(ReportSender *inst, Report *report) {
|
||||
Status ReportSender_Create(ReportSender *inst, Report *report) {
|
||||
fails(inst, UnavailableInstance);
|
||||
fails(report, error(UnavailableParameter, "Given report was unavailable."));
|
||||
|
||||
@@ -107,7 +138,7 @@ Status reportsender_create(ReportSender *inst, Report *report) {
|
||||
return NormalStatus;
|
||||
}
|
||||
|
||||
Status reportsender_send(ReportSender *inst, ReportSendingTask task) {
|
||||
Status ReportSender_Send(ReportSender *inst, ReportSendingTask task) {
|
||||
/* Skip when inst or task is unavailable. */
|
||||
fails(inst,
|
||||
error(UnavailableInstance, "Report sender was given unavailable."));
|
||||
@@ -116,7 +147,7 @@ Status reportsender_send(ReportSender *inst, ReportSendingTask task) {
|
||||
/* Assign for dest. */
|
||||
const FILE *dest = (inst->report->dest == NULL ? stdout : inst->report->dest);
|
||||
// char buff[];
|
||||
// TODO(william): HERE, report_literalise
|
||||
// TODO(william): HERE, Report_Literalise
|
||||
|
||||
/* Write/Send data. */
|
||||
inst->report->status = REPORT_SENDING_TASK_STATUS_PROCEEDING;
|
||||
@@ -138,7 +169,7 @@ Status reportsender_send(ReportSender *inst, ReportSendingTask task) {
|
||||
ReportSendingTaskID _throw(Report report, Location loc) {
|
||||
// /* Create new a instance of ReportSender. */
|
||||
// ReportSender sender;
|
||||
// reportsender_create(&sender, stderr);
|
||||
// ReportSender_Create(&sender, stderr);
|
||||
|
||||
// /* Send message. */
|
||||
// /* Initialise sender's thread. */
|
||||
@@ -157,18 +188,18 @@ ReportSendingTaskID _throw(Report report, Location loc) {
|
||||
// }
|
||||
|
||||
// /* Perform sending. */
|
||||
// reportsender_send(&sender, NULL);
|
||||
// ReportSender_Send(&sender, NULL);
|
||||
|
||||
/* Initialise sender. */
|
||||
ReportSender sender;
|
||||
/* Return with -1 when initialisation failed. */
|
||||
state(!(status_isokay(reportsender_create(&sender, &report))), -1);
|
||||
state(!(status_isokay(ReportSender_Create(&sender, &report))), -1);
|
||||
|
||||
/* Inject location information. Could be more elegant, though. */
|
||||
sender.report->stat.loc = loc;
|
||||
|
||||
/* Send. */ /* Return -1 when failed on sending. */
|
||||
state(!status_isokay(reportsender_send(&sender, HANDLER)), -1);
|
||||
state(!status_isokay(ReportSender_Send(&sender, HANDLER)), -1);
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user