Main program
In this example, the program name is textpr.
The main program determines the module to load and invokes it. Note that the textpr.h include file is used to specify the path name of the load object. This way, the path name, which is system-specific, can be changed easily.
#include <stdio.h>
#include <errno.h>
#include "methods.h"
#include "textpr.h" /* contains the pathname where
the load object can be found */
extern int errno;
main()
{
char libpath[PATH_MAX];&rbl;&rbl;&rbl;/* stores the full pathname of the
load object */
char *prefix_path=PREFIX_PATH; /* from textpr.h */
char *method=METHOD; /* from textpr.h */
int (*func)();
char *path;
/* Methods */
int ver;
char *p;
struct Methods *md;
setlocale(LC_ALL, "");
path = setlocale(LC_CTYPE, 0); /* obtain the locale
for LC_CTYPE category */
/* Construct the full pathname for the */
/* object to be loaded */
strcpy(libpath, prefix_path);
strcat(libpath, path);
strcat(libpath, "/");
strcat(libpath, method);
func = load(conv, 1, libpath); /* load the object */
if(func==NULL){
strerror(errno);
exit(1);
}
/* invoke the loaded module ");
md =(struct Methods *) func(); /* Obtain the methods
structure */
ver = md->version;
/* Invoke the methods as needed */
p = (md->hyphen)();
p = (md->wordbegin)();
p = (md->wordend)();
}