Subversion Repositories IRC-Archiver

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 nishi 1
/* $Id: main.c 2 2024-08-29 17:56:13Z nishi $ */
2
 
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
#include <sys/stat.h>
7
 
8
int main(int argc, char** argv){
9
	const char* fn = argv[1] == NULL ? "archiver.ini" : argv[1];
10
	FILE* f = fopen(fn, "r");
11
	if(f == NULL){
12
		fprintf(stderr, "Could not open the config: %s\n", fn);
13
		return 1;
14
	}
15
 
16
	struct stat s;
17
	stat(fn, &s);
18
 
19
	char* buf = malloc(s.st_size + 1);
20
	fread(buf, s.st_size, 1, f);
21
	buf[s.st_size] = 0;
22
 
23
	int i;
24
	int incr = 0;
25
 
26
	for(i = 0;; i++){
27
		if(buf[i] == 0 || buf[i] == '\n'){
28
			char oldc = buf[i];
29
			buf[i] = 0;
30
			char* line = buf + incr;
31
			if(strlen(line) > 0){
32
				int j;
33
				for(j = 0; line[j] != 0; j++){
34
					if(line[j] == '='){
35
						line[j] = 0;
36
						char* key = line;
37
						char* value = line + j + 1;
38
 
39
 
40
 
41
						break;
42
					}
43
				}
44
			}
45
			incr = i + 1;
46
			if(oldc == 0) break;
47
		}else{
48
		}
49
	}
50
 
51
	free(buf);
52
	fclose(f);
53
}