(SOC - Test) Storage Only Commit

This commit is contained in:
William
2024-05-16 06:53:55 +08:00
parent ce09981e05
commit e73f3af436
12 changed files with 189 additions and 86 deletions

View File

@@ -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);
}