git-svn-id: file:///raid/svn-personal/irc-archiver/trunk@3 f310dea9-ad02-7e44-859a-30a050007fc7
This commit is contained in:
Nishi 2024-08-29 18:49:46 +00:00
parent e160c99048
commit 396c57bb68
6 changed files with 110 additions and 11 deletions

15
.clang-format Normal file
View File

@ -0,0 +1,15 @@
---
# $Id$
Language: Cpp
UseTab: Always
TabWidth: 8
IndentWidth: 8
PointerAlignment: Left
ColumnLimit: 1024
AllowShortIfStatementsOnASingleLine: Always
AllowShortBlocksOnASingleLine: Never
AllowShortLoopsOnASingleLine: true
SpaceBeforeParens: Never
AlignEscapedNewlines: DontAlign
SortIncludes: false
AllowShortEnumsOnASingleLine: false

19
Bot/Makefile Normal file
View File

@ -0,0 +1,19 @@
# $Id$
include $(PWD)/Platform/$(PLATFORM).mk
.PHONY: all clean
.SUFFIXES: .c .o
OBJS = main.o util.o
all: ircarc$(EXEC)
ircarc$(EXEC): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f *.o *.exe ircarc

9
Bot/ia_util.h Normal file
View File

@ -0,0 +1,9 @@
/* $Id$ */
#ifndef __IA_UTIL_H__
#define __IA_UTIL_H__
char* ia_strcat(const char* a, const char* b);
char* ia_strdup(const char* str);
#endif

View File

@ -5,10 +5,13 @@
#include <string.h>
#include <sys/stat.h>
int main(int argc, char** argv){
#include "ia_util.h"
#include "ia_util.h"
int main(int argc, char** argv) {
const char* fn = argv[1] == NULL ? "archiver.ini" : argv[1];
FILE* f = fopen(fn, "r");
if(f == NULL){
if(f == NULL) {
fprintf(stderr, "Could not open the config: %s\n", fn);
return 1;
}
@ -23,20 +26,36 @@ int main(int argc, char** argv){
int i;
int incr = 0;
for(i = 0;; i++){
if(buf[i] == 0 || buf[i] == '\n'){
char* host = NULL;
int port = 0;
char* username = NULL;
char* password = NULL;
for(i = 0;; i++) {
if(buf[i] == 0 || buf[i] == '\n') {
char oldc = buf[i];
buf[i] = 0;
char* line = buf + incr;
if(strlen(line) > 0){
if(strlen(line) > 0 && line[0] != '#') {
int j;
for(j = 0; line[j] != 0; j++){
if(line[j] == '='){
for(j = 0; line[j] != 0; j++) {
if(line[j] == '=') {
line[j] = 0;
char* key = line;
char* value = line + j + 1;
if(strcmp(key, "host") == 0) {
if(host != NULL) free(host);
host = ia_strdup(value);
} else if(strcmp(key, "port") == 0) {
port = atoi(value);
} else if(strcmp(key, "username") == 0) {
if(username != NULL) free(username);
username = ia_strdup(value);
} else if(strcmp(key, "password") == 0) {
if(password != NULL) free(password);
password = ia_strdup(value);
}
break;
}
@ -44,10 +63,28 @@ int main(int argc, char** argv){
}
incr = i + 1;
if(oldc == 0) break;
}else{
}
}
free(buf);
fclose(f);
int st = 0;
if(host == NULL) {
fprintf(stderr, "Specify host\n");
st = 1;
}
if(username == NULL) {
fprintf(stderr, "Specify username\n");
st = 1;
}
if(password == NULL) {
fprintf(stderr, "Specify password\n");
st = 1;
}
if(st == 1) return st;
if(host != NULL) free(host);
if(username != NULL) free(username);
if(password != NULL) free(password);
}

16
Bot/util.c Normal file
View File

@ -0,0 +1,16 @@
/* $Id$ */
#include "ia_util.h"
#include <stdlib.h>
#include <string.h>
char* ia_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* ia_strdup(const char* str) { return ia_strcat(str, ""); }

View File

@ -3,14 +3,17 @@
PWD = `pwd`
PLATFORM = generic
FLAG = PWD=$(PWD) PLATFORM=$(PLATFORM)
FLAGS = PWD=$(PWD) PLATFORM=$(PLATFORM)
.PHONY: all clean ./Bot
.PHONY: all format clean ./Bot
all: ./Bot
./Bot::
$(MAKE) -C $@ $(FLAGS)
format:
clang-format --verbose -i `find . -name "*.c" -or -name "*.h"`
clean:
$(MAKE) -C $@ $(FLAGS) clean