46 lines
1004 B
C
46 lines
1004 B
C
#ifndef COMMANDER_H
|
|
#define COMMANDER_H
|
|
|
|
#include "aliases.h"
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // __cplusplus
|
|
|
|
#define CMD_NO_EXIT(ERR) \
|
|
((CMDResult){.exited = false, .exit_code = EXIT_FAILURE})
|
|
#define wapp_shell_commander_execute(HANDLE_OUTPUT, OUT_BUF, BUF_SIZE, ...) \
|
|
run_command(HANDLE_OUTPUT, OUT_BUF, BUF_SIZE, __VA_ARGS__, NULL)
|
|
|
|
typedef enum {
|
|
SHELL_OUTPUT_PRINT,
|
|
SHELL_OUTPUT_CAPTURE,
|
|
} CMDOutHandling;
|
|
|
|
typedef enum {
|
|
SHELL_ERR_NO_ERROR,
|
|
SHELL_ERR_CMD_BUF_FULL,
|
|
SHELL_ERR_PROC_START_FAIL,
|
|
SHELL_ERR_OUT_BUF_FULL,
|
|
SHELL_ERR_PROC_EXIT_FAIL,
|
|
} CMDError;
|
|
|
|
typedef struct commander_result CMDResult;
|
|
struct commander_result {
|
|
bool exited;
|
|
int exit_code;
|
|
CMDError error;
|
|
};
|
|
|
|
// clang-format off
|
|
CMDResult run_command(CMDOutHandling out_handling, char *out_buf, u64 buf_size, ...);
|
|
// clang-format on
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif // __cplusplus
|
|
|
|
#endif // !COMMANDER_H
|