[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
helplib.c
The helplib.c program is compiled into a .so library file
which is used for direct communication with the help
daemon. The library ensures that only one help daemon
is ever operating at one time, and manages the user end
of the communication pipe. If the method of communication
with the help daemon changes, the library file is the only
file which needs to change on the users side.
This program should pass along at least three messages to
the help daemon.
1. Open a main help page as default
2. Open a specific file
3. Open a topic.
The current implementation only accomplishes the second task,
though the first is fairly simple and should be easily
completed.
The code is attached.
Ken Duck
twoducks@globalserve.net
/*
* helplib.c
*
* This library provides the API to the help daemon.
* The following functions are provided:
*
* loadFile(char *filename) opens a specific help file.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
__BEGIN_DECLS
extern void loadFile __P((char *filename));
__END_DECLS
void loadFile(char *filename)
{
FILE *fptr;
int fd;
char buf[100];
struct stat statBuf;
printf("Here is my file %s\n", filename);
/* Find out if the help daemon exists. If it does not, start it. */
/* To find out if it exists, see if the pipe exists */
if(stat("help.fifo", &statBuf) == -1)
{
sprintf(buf, "helpd open %s&", filename);
system(buf);
}
else
{
fptr = fopen("help.fifo", "w");
fprintf(fptr, "open %s", filename);
fclose(fptr);
}
}