.PHONY: all clean
.SUFFIXES: .c .o
-OBJS = string.o
+OBJS = string.o log.o
all: common.a
--- /dev/null
+/* $Id$ */
+
+#ifndef __CM_LOG_H__
+#define __CM_LOG_H__
+
+void cm_log(const char* name, const char* log, ...);
+
+#endif
--- /dev/null
+/* $Id$ */
+
+#ifndef __CM_STRING_H__
+#define __CM_STRING_H__
+
+char* cm_strcat(const char* a, const char* b);
+char* cm_strdup(const char* str);
+
+#endif
--- /dev/null
+/* $Id$ */
+
+#include "cm_log.h"
+
+#include "cm_string.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+bool cm_do_log = false;
+
+#define LOGNAME_LENGTH 12
+
+void cm_log(const char* name, const char* log, ...) {
+ if(!cm_do_log) return;
+ va_list args;
+ va_start(args, log);
+ char namebuf[LOGNAME_LENGTH + 1];
+ memset(namebuf, '.', LOGNAME_LENGTH);
+ namebuf[LOGNAME_LENGTH] = 0;
+ int i;
+ for(i = 0; name[i] != 0 && i < LOGNAME_LENGTH; i++) {
+ namebuf[i] = name[i];
+ }
+
+ char* result = malloc(1);
+ result[0] = 0;
+
+ char cbuf[2];
+ cbuf[1] = 0;
+
+ for(i = 0; log[i] != 0; i++) {
+ if(log[i] == '%') {
+ i++;
+ if(log[i] == 's') {
+ char* tmp = result;
+ result = cm_strcat(tmp, va_arg(args, char*));
+ free(tmp);
+ }
+ } else {
+ cbuf[0] = log[i];
+ char* tmp = result;
+ result = cm_strcat(tmp, cbuf);
+ free(tmp);
+ }
+ }
+
+ fprintf(stderr, "%s %s\n", namebuf, result);
+ va_end(args);
+
+ free(result);
+}
/* $Id$ */
+
+#include <string.h>
+#include <stdlib.h>
+
+char* cm_strcat(const char* a, const char* b) {
+ char* str = malloc(strlen(a) + strlen(b) + 1);
+ memcpy(str, a, strlen(a));
+ memcpy(str + strlen(a), b, strlen(b));
+ str[strlen(a) + strlen(b)] = 0;
+ return str;
+}
+
+char* cm_strdup(const char* str) { return cm_strcat(str, ""); }
CC = cc
AR = ar
-CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\"
+CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common
LDFLAGS =
LIBS =
.PHONY: all clean
.SUFFIXES: .c .o
-OBJS = ../Common/common.a main.o
+OBJS = version.o main.o
all: tewi$(EXEC)
-tewi$(EXEC): $(OBJS)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+tewi$(EXEC): $(OBJS) ../Common/common.a
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) ../Common/common.a
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
/* $Id$ */
-int main() {}
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <cm_log.h>
+
+#include "tw_version.h"
+
+extern bool cm_do_log;
+
+int main(int argc, char** argv) {
+ int i;
+ for(i = 1; i < argc; i++) {
+ if(argv[i][0] == '-') {
+ if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
+ if(!cm_do_log) {
+ cm_do_log = true;
+ cm_log("", "This is Tewi HTTPd, version %s", tw_get_version());
+ } else {
+ cm_do_log = true;
+ }
+ } else {
+ fprintf(stderr, "Unknown option: %s\n", argv[i]);
+ return 1;
+ }
+ }
+ }
+ cm_log("Daemon", "Ready");
+}
--- /dev/null
+/* $Id$ */
+
+#ifndef __TW_VERSION_H__
+#define __TW_VERSION_H__
+
+const char* tw_get_version(void);
+
+#endif
--- /dev/null
+/* $Id$ */
+
+#include "tw_version.h"
+
+const char* tw_version = "0.00";
+
+const char* tw_get_version(void) { return tw_version; }