first commit
This commit is contained in:
3
CS4210/Project 3/common/config_parser/CVS/Entries
Normal file
3
CS4210/Project 3/common/config_parser/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/parser.c/1.3/Sun Apr 2 10:06:57 2006//
|
||||
/parser.h/1.3/Sun Apr 2 10:06:57 2006//
|
||||
D
|
||||
2
CS4210/Project 3/common/config_parser/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/common/config_parser/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/parser.c////*///
|
||||
/parser.h////*///
|
||||
@@ -0,0 +1,2 @@
|
||||
/parser.c////*///
|
||||
/parser.h////*///
|
||||
3
CS4210/Project 3/common/config_parser/CVS/Entries.Old
Normal file
3
CS4210/Project 3/common/config_parser/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/parser.c/0/dummy timestamp//
|
||||
/parser.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/common/config_parser/CVS/Repository
Normal file
1
CS4210/Project 3/common/config_parser/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/common/config_parser
|
||||
1
CS4210/Project 3/common/config_parser/CVS/Root
Normal file
1
CS4210/Project 3/common/config_parser/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
85
CS4210/Project 3/common/config_parser/parser.c
Normal file
85
CS4210/Project 3/common/config_parser/parser.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static char* getNextLine(char arr[160], FILE* stream) {
|
||||
while (fgets(arr, 160, stream)) {
|
||||
if (arr[0] == '#' || !isalnum(arr[0])) {
|
||||
continue;
|
||||
} else {
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load fileName and return a FILE*
|
||||
*/
|
||||
ConfigFile* loadFile(char* fileName) {
|
||||
ConfigFile* newConfig = NULL;
|
||||
|
||||
newConfig = malloc(sizeof(ConfigFile));
|
||||
if (!newConfig) {
|
||||
printf("Memory Allocation Failed in _FILE_ line: _LINE_\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newConfig->file = fopen(fileName, "r");
|
||||
|
||||
if (!newConfig->file) {
|
||||
free(newConfig);
|
||||
printf("Failed to Open File in _FILE_: _LINE_\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void releaseConfig(ConfigFile** configFile) {
|
||||
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
if ((*configFile)->file) {
|
||||
fclose((*configFile)->file);
|
||||
}
|
||||
free(*configFile);
|
||||
*configFile = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int nextSet(ConfigFile* config) {
|
||||
char temp[160];
|
||||
char* pc;
|
||||
int i;
|
||||
|
||||
if (!getNextLine(temp, config->file)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pc = strtok(temp,":");
|
||||
|
||||
strncpy(config->currentParamter, pc, 80);
|
||||
|
||||
pc = strtok(NULL,":");
|
||||
|
||||
for (i=0; pc[i] != '\0'; i++) {
|
||||
if (isspace(pc[i])) {
|
||||
pc[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(config->currentValue, pc, 80);
|
||||
|
||||
return 1;
|
||||
}
|
||||
22
CS4210/Project 3/common/config_parser/parser.h
Normal file
22
CS4210/Project 3/common/config_parser/parser.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef _PARSER_H_
|
||||
#define _PARSER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct SCONFIGFILE {
|
||||
char currentParamter[80];
|
||||
char currentValue[80];
|
||||
FILE* file;
|
||||
} ConfigFile;
|
||||
|
||||
/*
|
||||
* Load a file
|
||||
*/
|
||||
ConfigFile* loadFile(char* fileName);
|
||||
void releaseConfig(ConfigFile**);
|
||||
|
||||
int nextSet(ConfigFile*);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user