主程序
在本例中,程序名是 textpr。
主程序确定了要装入的模块,并调用该模块。 请注意 textpr.h 包含文件是用来指定装入对象的路径名。 这样,就可以很容易地更改这一特定于系统的路径名。
#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)();
}