forked from lda/telodendria
Telodendria and all tools now use the Cytoplasm runtime stub.
This reduces the amount of manual work programs have to do, and gives us some free features, like automatic leak reports in all tools.
This commit is contained in:
parent
8021cff122
commit
4043285413
5 changed files with 35 additions and 49 deletions
26
src/Main.c
26
src/Main.c
|
@ -33,7 +33,7 @@
|
|||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include <Telodendria.h>
|
||||
#include <Args.h>
|
||||
#include <Memory.h>
|
||||
#include <Config.h>
|
||||
#include <Log.h>
|
||||
|
@ -46,6 +46,7 @@
|
|||
#include <Util.h>
|
||||
#include <Str.h>
|
||||
|
||||
#include <Telodendria.h>
|
||||
#include <Matrix.h>
|
||||
#include <User.h>
|
||||
#include <RegToken.h>
|
||||
|
@ -90,11 +91,12 @@ typedef enum ArgFlag
|
|||
} ArgFlag;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
Main(Array *args)
|
||||
{
|
||||
int exit;
|
||||
|
||||
/* Arg parsing */
|
||||
ArgParseState arg;
|
||||
int opt;
|
||||
int flags;
|
||||
char *dbPath;
|
||||
|
@ -148,12 +150,13 @@ start:
|
|||
|
||||
TelodendriaPrintHeader();
|
||||
|
||||
while ((opt = getopt(argc, argv, "d:Vv")) != -1)
|
||||
ArgParseStateInit(&arg);
|
||||
while ((opt = ArgParse(&arg, args, "d:Vv")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'd':
|
||||
dbPath = optarg;
|
||||
dbPath = arg.optArg;
|
||||
break;
|
||||
case 'V':
|
||||
flags |= ARG_VERSION;
|
||||
|
@ -591,7 +594,6 @@ finish:
|
|||
*/
|
||||
MemoryHook(NULL, NULL);
|
||||
|
||||
LogConfigFree(LogConfigGlobal());
|
||||
StreamClose(logFile);
|
||||
|
||||
if (restart)
|
||||
|
@ -607,19 +609,5 @@ finish:
|
|||
goto start;
|
||||
}
|
||||
|
||||
StreamClose(StreamStdout());
|
||||
|
||||
/* Standard error should never have been opened, but just in case
|
||||
* it was, this doesn't hurt anything. */
|
||||
StreamClose(StreamStderr());
|
||||
|
||||
/* Generate a memory report if any leaks occurred. At this point no
|
||||
* memory should be allocated. */
|
||||
TelodendriaGenerateMemReport();
|
||||
|
||||
/* Free any leaked memory now, just in case the operating system
|
||||
* we're running on won't do it for us. */
|
||||
MemoryFreeAll();
|
||||
|
||||
return exit;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ recipe_cytoplasm() {
|
|||
cd Cytoplasm
|
||||
export TLS_IMPL
|
||||
sh make.sh
|
||||
CYTOPLASM_FLAGS="-LCytoplasm/out/lib -lcytoplasm $(sh make.sh libs)"
|
||||
CYTOPLASM_FLAGS="Cytoplasm/out/lib/cytoplasm.o -LCytoplasm/out/lib -lcytoplasm $(sh make.sh libs)"
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
|
@ -193,9 +193,9 @@ recipe_run() {
|
|||
if [ -f "build/$PROG" ]; then
|
||||
"build/$PROG" -d data
|
||||
|
||||
if [ -f "data/Memory.txt" ]; then
|
||||
echo "WARNING: Memory.txt exists in the data directory; this means"
|
||||
echo "Telodendria is leaking memory. Please fix memory leaks."
|
||||
if [ -f "data/telodendria-leaked.txt" ]; then
|
||||
echo "WARNING: Telodendria is leaking memory."
|
||||
echo "Please fix memory leaks."
|
||||
fi
|
||||
else
|
||||
echo "build/$PROG does not exist; build it first."
|
||||
|
|
|
@ -70,7 +70,7 @@ HttpHandle(HttpServerContext * cx, void *args)
|
|||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
Main(void)
|
||||
{
|
||||
struct sigaction sa;
|
||||
HttpServerConfig cfg;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <Args.h>
|
||||
#include <Memory.h>
|
||||
#include <Str.h>
|
||||
#include <HashMap.h>
|
||||
|
@ -43,7 +44,7 @@ usage(char *prog)
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
Main(Array *args)
|
||||
{
|
||||
HttpClientContext *cx;
|
||||
HttpStatus res;
|
||||
|
@ -55,12 +56,14 @@ main(int argc, char **argv)
|
|||
char *key;
|
||||
char *val;
|
||||
|
||||
ArgParseState arg;
|
||||
int flags = 0;
|
||||
int requestFlags = HTTP_FLAG_NONE;
|
||||
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "iH:X:d:")) != -1)
|
||||
ArgParseStateInit(&arg);
|
||||
while ((ch = ArgParse(&arg, args, "iH:X:d:")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
|
@ -68,16 +71,16 @@ main(int argc, char **argv)
|
|||
flags |= FLAG_HEADERS;
|
||||
break;
|
||||
case 'X':
|
||||
method = HttpRequestMethodFromString(optarg);
|
||||
method = HttpRequestMethodFromString(arg.optArg);
|
||||
if (!method)
|
||||
{
|
||||
StreamPrintf(StreamStderr(), "Unknown request method: %s\n", optarg);
|
||||
StreamPrintf(StreamStderr(), "Unknown request method: %s\n", arg.optArg);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
key = optarg;
|
||||
val = optarg;
|
||||
key = arg.optArg;
|
||||
val = arg.optArg;
|
||||
|
||||
while (*val && *val != ':')
|
||||
{
|
||||
|
@ -95,24 +98,24 @@ main(int argc, char **argv)
|
|||
HashMapSet(requestHeaders, key, StrDuplicate(val));
|
||||
break;
|
||||
case 'd':
|
||||
data = optarg;
|
||||
data = arg.optArg;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
usage(ArrayGet(args, 0));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc - optind < 1)
|
||||
if (ArraySize(args) - arg.optInd < 1)
|
||||
{
|
||||
usage(argv[0]);
|
||||
usage(ArrayGet(args, 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
uri = UriParse(argv[optind]);
|
||||
uri = UriParse(ArrayGet(args, arg.optInd));
|
||||
if (!uri)
|
||||
{
|
||||
StreamPrintf(StreamStderr(), "Failed to parse URI: %s\n", argv[optind]);
|
||||
StreamPrintf(StreamStderr(), "Failed to parse URI: %s\n", ArrayGet(args, arg.optInd));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -250,8 +253,5 @@ main(int argc, char **argv)
|
|||
HttpClientContextFree(cx);
|
||||
UriFree(uri);
|
||||
|
||||
StreamClose(StreamStdout());
|
||||
StreamClose(StreamStderr());
|
||||
|
||||
return !(res == HTTP_OK);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include <Args.h>
|
||||
#include <Array.h>
|
||||
#include <HashMap.h>
|
||||
#include <Str.h>
|
||||
|
@ -177,27 +178,29 @@ encode(char *str)
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
Main(Array *args)
|
||||
{
|
||||
HashMap *json;
|
||||
int flag = 0;
|
||||
int ch;
|
||||
char *input = NULL;
|
||||
ArgParseState arg;
|
||||
|
||||
while ((ch = getopt(argc, argv, "s:e:")) != -1)
|
||||
ArgParseStateInit(&arg);
|
||||
while ((ch = ArgParse(&arg, args, "s:e:")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 's':
|
||||
flag = FLAG_SELECT;
|
||||
input = optarg;
|
||||
input = arg.optArg;
|
||||
break;
|
||||
case 'e':
|
||||
flag = FLAG_ENCODE;
|
||||
input = optarg;
|
||||
input = arg.optArg;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
usage(ArrayGet(args, 0));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -227,10 +230,5 @@ main(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
|
||||
StreamClose(StreamStdout());
|
||||
StreamClose(StreamStderr());
|
||||
StreamClose(StreamStdin());
|
||||
|
||||
MemoryFreeAll();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue