source: Main/trunk/Server/config.c@ 4

Last change on this file since 4 was 4, checked in by Nishi, on Sep 13, 2024 at 6:39:33 PM

can trim line

  • Property svn:keywords set to Id
File size: 773 bytes
Line 
1/* $Id: config.c 4 2024-09-13 09:39:33Z nishi $ */
2
3#include "tw_config.h"
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8
9#include <cm_string.h>
10#include <cm_log.h>
11
12int tw_config_read(const char* path){
13 cm_log("Config", "Reading %s", path);
14 char cbuf[2];
15 cbuf[1] = 0;
16 FILE* f = fopen(path, "r");
17 if(f != NULL){
18 char* line = malloc(1);
19 line[0] = 0;
20 while(1){
21 int c = fread(cbuf, 1, 1, f);
22 if(cbuf[0] == '\n' || c <= 0){
23 char* l = cm_trim(line);
24 if(strlen(l) > 0 && l[0] != '#'){
25 printf("[%s]\n", l);
26 }
27 free(l);
28 free(line);
29 line = malloc(1);
30 line[0] = 0;
31 if(c <= 0) break;
32 }else if(cbuf[0] != '\r'){
33 char* tmp = line;
34 line = cm_strcat(tmp, cbuf);
35 free(tmp);
36 }
37 }
38 free(line);
39 fclose(f);
40 return 0;
41 }else{
42 return 1;
43 }
44}
Note: See TracBrowser for help on using the repository browser.