Commenting + man generation

This commit is contained in:
Yann Weber 2023-03-29 18:11:59 +02:00
commit 43935cf566
5 changed files with 72 additions and 4 deletions

30
asmsh.h Normal file
View file

@ -0,0 +1,30 @@
/**@page asmsh
@brief A shell that runs assembly
@section SYNOPSIS
asmsh [OPTIONS]...
@section DESCRIPTION
A shell designed to run assembly.
A simple programm is spawned by the shell, and each instructions are runned in the
subprocess environment.
@section AUTHOR
Written by Yann Weber <yann.weber@members.fsf.org>
@section COPYRIGHT
Copyright © 2023 Weber Yann License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
*/
/**@mainpage
* @brief Asmsh a shell that runs assembly
*
* @section Description
*
* A simple programm is spawned by the shell, and each instructions are runned in the
* subprocess environment.
*/

View file

@ -117,6 +117,12 @@ void asmsh_asmc_ctx_free(asmsh_asmc_ctx_t *ctx);
*/
int asmsh_asmc_compile(asmsh_asmc_ctx_t *ctx, const char *instr, asmsh_bytecode_t *res);
/** Compile an instruction
* @param asmsh_asmc_ctx_t* The context
* @param const char* The instruction to compile
* @param asmsh_bytecode_t* Pointer on the result struct
* @return 0 if ok else -1 on failure with errno set
*/
int asmsh_asmc_compile_unsafe(asmsh_asmc_ctx_t *ctx, const char *_instr, asmsh_bytecode_t *res);
/** Spawn an assembler process child process

View file

@ -219,6 +219,17 @@ int asmsh_log(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[],
}
/*
int asmsh_dlog(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[],
const char *msg, ...)
{
if(lvl < logger->min_level) { return 0; }
}
*/
const char * asmsh_loglevel_name(asmsh_loglevel_t lvl)
{
switch(lvl)

View file

@ -19,6 +19,12 @@
/** A logger suitable for a shell
*
* Collect messages and deliver them when needed
*
* @warning This module is totally overkill. Most of the features (log collection
* etc.) seems to be useless ! Apparently, in a shell, we just want errors to be printed
* on stderr ?
*
* TODO continue to simplify the module & implement direct logging features
*/
#include <errno.h>
@ -49,10 +55,14 @@
typedef struct asmsh_logger_s asmsh_logger_t;
typedef struct asmsh_log_msg_s asmsh_log_msg_t;
typedef enum asmsh_loglevel_e asmsh_loglevel_t;
/**@param asmsh_log_msg_t* the log message to format
* @param char* the result buffer
* @param int the buffer size
* @return The needed size for the message in buffer (@see snprintf)
* if no error, else -1
*/
typedef int (asmsh_log_fmt_f)(asmsh_log_msg_t*, char*, int);
extern asmsh_logger_t *_default_logger;
enum asmsh_loglevel_e
{
@ -64,6 +74,8 @@ enum asmsh_loglevel_e
ASMSH_FATAL = 50
};
extern asmsh_logger_t *_default_logger;
struct asmsh_log_msg_s
{
@ -78,6 +90,8 @@ struct asmsh_log_msg_s
struct asmsh_logger_s
{
asmsh_loglevel_t min_level;
/** Direct log fd */
//int dlog_fd; // TODO should be multiple FDs !?
/** Buffered messages
*
* A single buffer is used to store asmsh_log_msg_t and the
@ -93,6 +107,8 @@ struct asmsh_logger_s
size_t msgs_alloc;
/** Default formatter */
asmsh_log_fmt_f *fmt;
/** Default direct log formatter */
asmsh_log_fmt_f *dfmt;
};
@ -112,8 +128,13 @@ static inline int asmsh_logger_empty(asmsh_logger_t *logger) {
*/
int asmsh_logger_setup(asmsh_logger_t *logger);
/** Returns a pointer on a newly allocated logger
* @param asmsh_log_level_t The minimum level for a message must have to be printed
* @returns A newly allocated logger that must be freed after use by @ref asmsh_logger_ferr()
*/
asmsh_logger_t* asmsh_logger_new(asmsh_loglevel_t min_level);
/** Free a logger */
void asmsh_logger_free(asmsh_logger_t* logger);
int asmsh_logger_dprint_fmt(int fd, asmsh_logger_t *logger, asmsh_log_fmt_f *custom_fmt);
@ -128,10 +149,11 @@ static inline int asmsh_logger_stderr(asmsh_logger_t *logger) {
return asmsh_logger_dprint(2, logger);
}
/** Log a message( see macros ) */
int asmsh_log(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[], const char *msg, ...);
/** Return a pointer on a static string representing a loglevel name */
const char * asmsh_loglevel_name(asmsh_loglevel_t lvl);
/** Default formatter with UTC datetime, lvl, caller and message */

View file

@ -153,7 +153,6 @@ static int _compile_step(asmsh_t *sh, const char *cmd)
}
else if(ret > 0)
{
asmsh_log_fatal("Child exited with non-zero status");
return 1+WEXITSTATUS(status);
}
return 0;