(MOD) Modified several places to adapt the extraction of Report.

This commit is contained in:
2024-06-26 11:19:11 +08:00
parent 8696b89c2e
commit d19256621b
5 changed files with 120 additions and 116 deletions

View File

@@ -113,7 +113,6 @@ typedef struct _Status {
Status Location_Literalise(Location *inst, char *buff); Status Location_Literalise(Location *inst, char *buff);
bool Location_Equals(Location lc1, Location lc2); bool Location_Equals(Location lc1, Location lc2);
Status Status_Literalise(Status *inst, char *buff); Status Status_Literalise(Status *inst, char *buff);
Status Status_LiteraliseForReport(Status *inst, char *buff);
bool Status_Equal(Status *stat1, Status *stat2); 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); void StatusUtils_Dump(Status *inst, Status *store);

View File

@@ -79,21 +79,6 @@ Status Status_Literalise(Status *inst, char *buff)
}); });
} }
Status Status_LiteraliseForReport(Status *inst, char *buff)
{
/* Skip unavailable instance and invalid parameter. */
nonull(inst, apply(UnavailableInstance));
nonull(buff, apply(UnavailableBuffer));
where(
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM, REPORT_LITERALISE_FORMAT_DETAIL,
strnil(inst->identity), strnil(inst->prev->identity),
inst->value, inst->characteristic, inst->loc.file, inst->loc.line,
inst->loc.func), {
return apply(value(TraditionalFunctionReturn, _));
});
}
bool StatusUtils_HasPrev(Status stat) bool StatusUtils_HasPrev(Status stat)
{ {
return (stat.prev != NULL); return (stat.prev != NULL);
@@ -174,65 +159,3 @@ int StatusUtils_Depth(Status *stat)
// return (inst1->argue_start == inst2->argue_start) // return (inst1->argue_start == inst2->argue_start)
// || (inst1->external_param == inst2->external_param); // || (inst1->external_param == inst2->external_param);
// } // }
ReportTaskID THROW(Report report, Location loc)
{
// // /* Create new a instance of ReportSender. */
// // ReportSender sender;
// // ReportSender_Create(&sender, stderr);
// // /* Send message. */
// // /* Initialise sender's thread. */
// // thrd_t sending;
// // /* Skip on failing on creating thread. */
// // if (!thrd_create(&sending, starter, NULL)) {
// // /* Conclude the session of sender. */
// // report.status = REPORT_SENDING_TASK_STATUS_FINISHED,
// // report.result = (ARGUE_RESULT_FINALISED | ARGUE_RESULT_NEGATIVE);
// // sender.result = REPORT_SENDER_RESULT_FINISHED;
// // sender.successful = false;
// // return -1;
// // }
// // /* Perform sending. */
// // ReportSender_Send(&sender, NULL);
// /* Initialise sender. */
// ReportSender sender;
// /* Return with -1 when initialisation failed. */
// state(!(StatusUtils_IsOkay(ReportSender_Create(&sender, &report))), -1);
// /* Inject location information. Could be more elegant, though. */
// sender.report->status.loc = loc;
// /* Send. */ /* Return -1 when failed on sending. */
// state(!StatusUtils_IsOkay(ReportSender_Send(&sender, HANDLER)), -1);
return 0;
}
int HANDLER(void *report)
{
// /* Throw UnableToThrowError when param is unavailable. */
// if (report == NULL) {
// /* Create report on this. */
// Report e;
// Report_Create(
// &e,
// &error(UnableToThrowError, "Cannot perform throwing. Aborted."),
// stderr, nameof(DEFAULT_ARGUE_STARTER),
// REPORT_SENDING_PRIORITY_FATAL);
// /* Perform throwing. */
// (void)throw(e); // Throw the report alone.
// return 1;
// }
// (void)throw(*(Report *)report); // Lonely throw, no catch will company.
// return 0;
return 0;
}

View File

@@ -209,4 +209,8 @@ typedef bool _Bit;
# define __ATTRIBUTABLE__ # define __ATTRIBUTABLE__
# define attr(a) # define attr(a)
/* Useless in C, only for human to see.
Probably rewrite this in Classify. */
# define throws(e)
#endif /* COMPOUND_COMMON_H */ #endif /* COMPOUND_COMMON_H */

150
report.c
View File

@@ -51,6 +51,17 @@ void Report_Delete(Report *inst)
inst = NULL; inst = NULL;
} }
/* /*
Status status; Status status;
char *initiator; char *initiator;
@@ -61,47 +72,56 @@ void Report_Delete(Report *inst)
*/ */
Status Report_Literalise(Report *inst, char *buff) Status Report_Literalise(Report *inst, char *buff)
{ {
nonull(inst, apply(UnavailableInstance)); // nonull(inst, apply(UnavailableInstance));
nonull(buff, apply(UnavailableBuffer)); // nonull(buff, apply(UnavailableBuffer));
/* Report literalisation. */ // /* Report literalisation. */
char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY; // char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
/** Status literalisation. **/ // /** Status literalisation. **/
char status_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY; // char status_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
/* Fault detection on status literalisation. */ // /* Fault detection on status literalisation. */
// settle(Status_LiteraliseForReport(&inst->status, status_literalising), // // settle(Status_LiteraliseForReport(&inst->status, status_literalising),
// _.characteristic == STATUS_UNKNOWN, { // // _.characteristic == STATUS_UNKNOWN, {
// nest(_, __, { // // nest(_, __, {
// /* Skip when ZERO byte were written. (failed to write) */ // // /* Skip when ZERO byte were written. (failed to write) */
// state(!__.value, apply( // // state(!__.value, apply(
// error(value(TraditionalFunctionReturn, __.value), // // error(value(TraditionalFunctionReturn, __.value),
// "ZERO byte were written.") // // "ZERO byte were written.")
// )); // // ));
// }) // // })
// }); // // });
/* Traditional function returning handling. */ // /* Traditional function returning handling. */
settle(Status_LiteraliseForReport(&inst->content, status_literalising), // // settle(Status_LiteraliseForReport(&inst->content, status_literalising),
!_.value, { // // !_.value, {
return apply(annot(RuntimeError, "Failed to literalise status for report.")); // // return apply(annot(RuntimeError, "Failed to literalise status for report."));
}); // // });
/* Write result to buffer. */ // where(
/* Write the report "header". */ // snprintf(buff, LITERALISATION_LENGTH_MAXIMUM, REPORT_LITERALISE_FORMAT_DETAIL,
/* Literalise current time and date. */ // strnil(inst->content.identity), strnil(inst->content.prev->identity),
char datetime[LITERALISATION_LENGTH_MAXIMUM]; // inst->content.value, inst->content.characteristic,
// settle(strftime(datetime, 64, "%c", localtime(&inst->time)), ) // inst->content.loc.file, inst->content.loc.line,
// inst->content.loc.func), {
// return apply(value(TraditionalFunctionReturn, _));
// });
// /* Write result to buffer. */
// /* Write the report "header". */
// /* Literalise current time and date. */
// char datetime[LITERALISATION_LENGTH_MAXIMUM];
// // settle(strftime(datetime, 64, "%c", localtime(&inst->time)), )
// DATETIME [LEVEL] STATUS.IDENTITY (INITIATOR): STATUS.DESCRIPTION // // DATETIME [LEVEL] STATUS.IDENTITY (INITIATOR): STATUS.DESCRIPTION
state(!snprintf(report_literalising, LITERALISATION_LENGTH_MAXIMUM, // state(!snprintf(report_literalising, LITERALISATION_LENGTH_MAXIMUM,
REPORT_LITERALISE_FORMAT_HEADER, datetime, inst->level, // REPORT_LITERALISE_FORMAT_HEADER, datetime, inst->level,
inst->content.identity, inst->initiator, inst->content.description), // inst->content.identity, inst->initiator, inst->content.description),
apply(annot(NoBytesWereWritten, "Failed to literalise date and time.")) // apply(annot(NoBytesWereWritten, "Failed to literalise date and time."))
); // );
/* Write the report "detail". */ // /* Write the report "detail". */
return apply(NormalStatus); return apply(NormalStatus);
} }
@@ -149,3 +169,65 @@ Status ReportSender_Send(ReportSender *inst, ReportTask task)
// /* Sent successfully! Mark down properties. */ // /* Sent successfully! Mark down properties. */
return apply(NormalStatus); return apply(NormalStatus);
} }
ReportTaskID THROW(Report report, Location loc)
{
// // /* Create new a instance of ReportSender. */
// // ReportSender sender;
// // ReportSender_Create(&sender, stderr);
// // /* Send message. */
// // /* Initialise sender's thread. */
// // thrd_t sending;
// // /* Skip on failing on creating thread. */
// // if (!thrd_create(&sending, starter, NULL)) {
// // /* Conclude the session of sender. */
// // report.status = REPORT_SENDING_TASK_STATUS_FINISHED,
// // report.result = (ARGUE_RESULT_FINALISED | ARGUE_RESULT_NEGATIVE);
// // sender.result = REPORT_SENDER_RESULT_FINISHED;
// // sender.successful = false;
// // return -1;
// // }
// // /* Perform sending. */
// // ReportSender_Send(&sender, NULL);
// /* Initialise sender. */
// ReportSender sender;
// /* Return with -1 when initialisation failed. */
// state(!(StatusUtils_IsOkay(ReportSender_Create(&sender, &report))), -1);
// /* Inject location information. Could be more elegant, though. */
// sender.report->status.loc = loc;
// /* Send. */ /* Return -1 when failed on sending. */
// state(!StatusUtils_IsOkay(ReportSender_Send(&sender, HANDLER)), -1);
return 0;
}
int HANDLER(void *report)
{
// /* Throw UnableToThrowError when param is unavailable. */
// if (report == NULL) {
// /* Create report on this. */
// Report e;
// Report_Create(
// &e,
// &error(UnableToThrowError, "Cannot perform throwing. Aborted."),
// stderr, nameof(DEFAULT_ARGUE_STARTER),
// REPORT_SENDING_PRIORITY_FATAL);
// /* Perform throwing. */
// (void)throw(e); // Throw the report alone.
// return 1;
// }
// (void)throw(*(Report *)report); // Lonely throw, no catch will company.
// return 0;
return 0;
}

View File

@@ -93,10 +93,6 @@ Status ReportSender_Send(ReportSender *inst, ReportTask task);
* 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.
Probably rewrite this in Classify. */
# define throws(e)
// ReportTaskID THROW(Report report, Location loc); // ReportTaskID THROW(Report report, Location loc);
// Report CATCH(ReportTaskID taskid, Status (*handler)()); // Report CATCH(ReportTaskID taskid, Status (*handler)());
int HANDLER(void *report); int HANDLER(void *report);