- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
131
help.c
131
help.c
@ -18,133 +18,142 @@ extern char *stptok(const char *s, char *tok, size_t toklen, char *brk);
|
||||
#define PATHSEP ":"
|
||||
#define DIRSEP "/"
|
||||
static char *helpDirs = NULL;
|
||||
static char *defaultFile="master.txt";
|
||||
static char *defaultFile = "master.txt";
|
||||
/*----------------------------------------------------------------------*/
|
||||
void KillHelp(void *pData){
|
||||
void KillHelp(void *pData)
|
||||
{
|
||||
KillDummy(pData);
|
||||
if(helpDirs != NULL){
|
||||
if (helpDirs != NULL) {
|
||||
free(helpDirs);
|
||||
helpDirs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static FILE *findHelpFile(char *name){
|
||||
static FILE *findHelpFile(char *name)
|
||||
{
|
||||
FILE *fd = NULL;
|
||||
char pBueffel[256];
|
||||
char dir[132];
|
||||
char *pPtr;
|
||||
|
||||
if(helpDirs == NULL){
|
||||
if (helpDirs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pPtr = helpDirs;
|
||||
while( (pPtr = stptok(pPtr,dir,131,PATHSEP)) != NULL){
|
||||
strcpy(pBueffel,dir);
|
||||
strcat(pBueffel,DIRSEP);
|
||||
strncat(pBueffel,name,(254-strlen(pBueffel)));
|
||||
fd = fopen(pBueffel,"r");
|
||||
if(fd != NULL){
|
||||
while ((pPtr = stptok(pPtr, dir, 131, PATHSEP)) != NULL) {
|
||||
strcpy(pBueffel, dir);
|
||||
strcat(pBueffel, DIRSEP);
|
||||
strncat(pBueffel, name, (254 - strlen(pBueffel)));
|
||||
fd = fopen(pBueffel, "r");
|
||||
if (fd != NULL) {
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
this means: not found!
|
||||
*/
|
||||
this means: not found!
|
||||
*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void printHelpFile(SConnection *pCon, FILE *fd){
|
||||
static void printHelpFile(SConnection * pCon, FILE * fd)
|
||||
{
|
||||
char line[132];
|
||||
|
||||
while(fgets(line,131,fd) != NULL){
|
||||
SCWrite(pCon,line,eValue);
|
||||
while (fgets(line, 131, fd) != NULL) {
|
||||
SCWrite(pCon, line, eValue);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void configureHelp(SConnection *pCon,
|
||||
char *option, char *parameter){
|
||||
static void configureHelp(SConnection * pCon,
|
||||
char *option, char *parameter)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int length;
|
||||
|
||||
strtolower(option);
|
||||
if(strcmp(option,"adddir") == 0){
|
||||
if(parameter == NULL){
|
||||
SCWrite(pCon,helpDirs,eValue);
|
||||
if (strcmp(option, "adddir") == 0) {
|
||||
if (parameter == NULL) {
|
||||
SCWrite(pCon, helpDirs, eValue);
|
||||
return;
|
||||
} else {
|
||||
pPtr = helpDirs;
|
||||
if(pPtr != NULL){
|
||||
length = strlen(pPtr) + strlen(PATHSEP) + strlen(parameter) + 2;
|
||||
helpDirs = (char *)malloc(length*sizeof(char));
|
||||
memset(helpDirs,0,length*sizeof(char));
|
||||
strcpy(helpDirs,pPtr);
|
||||
strcat(helpDirs,PATHSEP);
|
||||
strcat(helpDirs,parameter);
|
||||
free(pPtr);
|
||||
if (pPtr != NULL) {
|
||||
length = strlen(pPtr) + strlen(PATHSEP) + strlen(parameter) + 2;
|
||||
helpDirs = (char *) malloc(length * sizeof(char));
|
||||
memset(helpDirs, 0, length * sizeof(char));
|
||||
strcpy(helpDirs, pPtr);
|
||||
strcat(helpDirs, PATHSEP);
|
||||
strcat(helpDirs, parameter);
|
||||
free(pPtr);
|
||||
} else {
|
||||
helpDirs=strdup(parameter);
|
||||
helpDirs = strdup(parameter);
|
||||
}
|
||||
}
|
||||
} else if(strcmp(option,"defaultfile") == 0){
|
||||
if(parameter == NULL){
|
||||
SCWrite(pCon,defaultFile,eValue);
|
||||
} else if (strcmp(option, "defaultfile") == 0) {
|
||||
if (parameter == NULL) {
|
||||
SCWrite(pCon, defaultFile, eValue);
|
||||
return;
|
||||
} else {
|
||||
if(defaultFile != NULL){
|
||||
free(defaultFile);
|
||||
if (defaultFile != NULL) {
|
||||
free(defaultFile);
|
||||
}
|
||||
defaultFile = strdup(parameter);
|
||||
}
|
||||
} else {
|
||||
SCWrite(pCon,"Unknown option to configure",eWarning);
|
||||
SCWrite(pCon,"Known options: defaultfile, adddir",eWarning);
|
||||
SCWrite(pCon, "Unknown option to configure", eWarning);
|
||||
SCWrite(pCon, "Known options: defaultfile, adddir", eWarning);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int SicsHelp(SConnection *pCon,SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
int SicsHelp(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char helpFile[256];
|
||||
FILE *fd = NULL;
|
||||
|
||||
strncpy(helpFile,defaultFile,255);
|
||||
strncpy(helpFile, defaultFile, 255);
|
||||
|
||||
if(argc > 1){
|
||||
if (argc > 1) {
|
||||
strtolower(argv[1]);
|
||||
/*
|
||||
check for configure
|
||||
*/
|
||||
if(strcmp(argv[1],"configure") == 0){
|
||||
if(argc < 3){
|
||||
SCWrite(pCon,"ERROR: need an option to configure",eError);
|
||||
return 0;
|
||||
check for configure
|
||||
*/
|
||||
if (strcmp(argv[1], "configure") == 0) {
|
||||
if (argc < 3) {
|
||||
SCWrite(pCon, "ERROR: need an option to configure", eError);
|
||||
return 0;
|
||||
}
|
||||
if(argc > 3){
|
||||
configureHelp(pCon,argv[2],argv[3]);
|
||||
if (argc > 3) {
|
||||
configureHelp(pCon, argv[2], argv[3]);
|
||||
} else {
|
||||
configureHelp(pCon,argv[2],NULL);
|
||||
configureHelp(pCon, argv[2], NULL);
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
the parameter is a help file name
|
||||
*/
|
||||
strncpy(helpFile,argv[1],255);
|
||||
strncat(helpFile,".txt",255);
|
||||
the parameter is a help file name
|
||||
*/
|
||||
strncpy(helpFile, argv[1], 255);
|
||||
strncat(helpFile, ".txt", 255);
|
||||
}
|
||||
|
||||
/*
|
||||
print the helpFile
|
||||
*/
|
||||
print the helpFile
|
||||
*/
|
||||
fd = findHelpFile(helpFile);
|
||||
if(fd == NULL){
|
||||
SCWrite(pCon,"ERROR: failed to locate helpFile:",eError);
|
||||
SCWrite(pCon,helpFile,eError);
|
||||
if (fd == NULL) {
|
||||
SCWrite(pCon, "ERROR: failed to locate helpFile:", eError);
|
||||
SCWrite(pCon, helpFile, eError);
|
||||
return 0;
|
||||
}
|
||||
printHelpFile(pCon,fd);
|
||||
printHelpFile(pCon, fd);
|
||||
fclose(fd);
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user