Browse Source

Commenting + man generation

Yann Weber 1 year ago
parent
commit
43935cf566
5 changed files with 72 additions and 4 deletions
  1. 30
    0
      asmsh.h
  2. 6
    0
      compile.h
  3. 11
    0
      logger.c
  4. 25
    3
      logger.h
  5. 0
    1
      shell.c

+ 30
- 0
asmsh.h View File

@@ -0,0 +1,30 @@
1
+/**@page asmsh
2
+@brief A shell that runs assembly
3
+@section SYNOPSIS
4
+asmsh [OPTIONS]...
5
+@section DESCRIPTION
6
+A shell designed to run assembly.
7
+
8
+A simple programm is spawned by the shell, and each instructions are runned in the
9
+subprocess environment.
10
+
11
+@section AUTHOR
12
+Written by Yann Weber <yann.weber@members.fsf.org>
13
+
14
+@section COPYRIGHT
15
+Copyright  ©  2023  Weber Yann  License GPLv3+: GNU GPL version 3 or later 
16
+<http://gnu.org/licenses/gpl.html>.
17
+
18
+This is free software: you are free  to  change  and  redistribute  it.
19
+There is NO WARRANTY, to the extent permitted by law.
20
+
21
+*/
22
+
23
+/**@mainpage
24
+ * @brief Asmsh a shell that runs assembly
25
+ *
26
+ * @section Description
27
+ *
28
+ * A simple programm is spawned by the shell, and each instructions are runned in the
29
+ * subprocess environment.
30
+ */

+ 6
- 0
compile.h View File

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

+ 11
- 0
logger.c View File

@@ -219,6 +219,17 @@ int asmsh_log(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[],
219 219
 
220 220
 }
221 221
 
222
+/*
223
+int asmsh_dlog(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[],
224
+		const char *msg, ...)
225
+{
226
+	if(lvl < logger->min_level) { return 0; }
227
+
228
+
229
+}
230
+*/
231
+
232
+
222 233
 const char * asmsh_loglevel_name(asmsh_loglevel_t lvl)
223 234
 {
224 235
 	switch(lvl)

+ 25
- 3
logger.h View File

@@ -19,6 +19,12 @@
19 19
 /** A logger suitable for a shell
20 20
  *
21 21
  * Collect messages and deliver them when needed
22
+ *
23
+ * @warning This module is totally overkill. Most of the features (log collection
24
+ * etc.) seems to be useless ! Apparently, in a shell, we just want errors to be printed
25
+ * on stderr ?
26
+ *
27
+ * TODO continue to simplify the module & implement direct logging features
22 28
  */
23 29
 
24 30
 #include <errno.h>
@@ -49,10 +55,14 @@
49 55
 typedef struct asmsh_logger_s asmsh_logger_t;
50 56
 typedef struct asmsh_log_msg_s asmsh_log_msg_t;
51 57
 typedef enum asmsh_loglevel_e asmsh_loglevel_t;
58
+/**@param asmsh_log_msg_t* the log message to format
59
+ * @param char* the result buffer
60
+ * @param int the buffer size
61
+ * @return The needed size for the message in buffer (@see snprintf)
62
+ * 	if no error, else -1
63
+ */
52 64
 typedef int (asmsh_log_fmt_f)(asmsh_log_msg_t*, char*, int);
53 65
 
54
-extern asmsh_logger_t *_default_logger;
55
-
56 66
 
57 67
 enum asmsh_loglevel_e
58 68
 {
@@ -64,6 +74,8 @@ enum asmsh_loglevel_e
64 74
 	ASMSH_FATAL = 50
65 75
 };
66 76
 
77
+extern asmsh_logger_t *_default_logger;
78
+
67 79
 
68 80
 struct asmsh_log_msg_s
69 81
 {
@@ -78,6 +90,8 @@ struct asmsh_log_msg_s
78 90
 struct asmsh_logger_s
79 91
 {
80 92
 	asmsh_loglevel_t min_level;
93
+	/** Direct log fd */
94
+	//int dlog_fd;  // TODO should be multiple FDs !?
81 95
 	/** Buffered messages
82 96
 	 * 
83 97
 	 * A single buffer is used to store asmsh_log_msg_t and the
@@ -93,6 +107,8 @@ struct asmsh_logger_s
93 107
 	size_t msgs_alloc;
94 108
 	/** Default formatter */
95 109
 	asmsh_log_fmt_f *fmt;
110
+	/** Default direct log formatter */
111
+	asmsh_log_fmt_f *dfmt;
96 112
 };
97 113
 
98 114
 
@@ -112,8 +128,13 @@ static inline int asmsh_logger_empty(asmsh_logger_t *logger) {
112 128
  */
113 129
 int asmsh_logger_setup(asmsh_logger_t *logger);
114 130
 
131
+/** Returns a pointer on a newly allocated logger
132
+ * @param asmsh_log_level_t The minimum level for a message must have to be printed
133
+ * @returns A newly allocated logger that must be freed after use by @ref asmsh_logger_ferr()
134
+ */
115 135
 asmsh_logger_t* asmsh_logger_new(asmsh_loglevel_t min_level);
116 136
 
137
+/** Free a logger */
117 138
 void asmsh_logger_free(asmsh_logger_t* logger);
118 139
 
119 140
 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) {
128 149
 	return asmsh_logger_dprint(2, logger);
129 150
 }
130 151
 
131
-
152
+/** Log a message( see macros ) */
132 153
 int asmsh_log(asmsh_logger_t *logger, asmsh_loglevel_t lvl, const char caller[], const char *msg, ...);
133 154
 
134 155
 
156
+/** Return a pointer on a static string representing a loglevel name */
135 157
 const char * asmsh_loglevel_name(asmsh_loglevel_t lvl);
136 158
 
137 159
 /** Default formatter with UTC datetime, lvl, caller and message */

+ 0
- 1
shell.c View File

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

Loading…
Cancel
Save