next up previous contents index
Next: Running modules Up: Modules Previous: Setting module attributes   Contents   Index


Loading module functions

Since a shared object file may have several different module functions, and you may be interested only in one of them, GOCR enables you to decide exactly which module function should be run, and the order they do that. The functions that load module functions are:

int gocr_functionAppend ( gocr_moduleType t, 
char *functionname, void *data ); 
int gocr_functionInsertBefore ( gocr_moduleType t, 
char *functionname, void *data, int id ); 
int gocr_functionDeleteById ( int id );
Module functions are internally saved in a linked list, but you don't have to know that (so, I shouldn't haven written... well, knowledge is never too much). Let's first see gocr_functionAppend. The arguments are:

t
the module type, as in the first column of the table above.
functionname
this is the name of the module function you want to load. Refer to the documentation that should come with the shared file object.
data
this is a parameter that will be passed to the function when it's called. It's a pointer, that you are responsible for allocation. Do not free it until you call gocr_functionDelete or gocr_finalize. Being a void pointer, you can pass anything to it. If you need more than one argument, use a structure. Read the module function docs to know what you can do with this.
gocr_functionAppend returns -1 in case of error, or a non-negative number if successful. This number is the function's ID. It can be used if you want to do access this function.

gocr_functionDeleteById is straight forward. Its sole argument is the id of the module function you want to delete. As usual, returns -1 if error, 0 on success.

Last, but not least, there's gocr_functionInsertBefore. It works like its counterpart gocr_functionAppend, but there's a difference: it allows you to insert a function in the middle of the list. Good for the absent minded ones. The first three arguments are the same of gocr_functionAppend, and the fourth argument is the id of the function that is be just after the position you want to insert the new function. So, if you want to insert a function in the first position, you should pass the id of the current first position function. Hm. Read it again, and it should become clearer. ;-)

The order of the inclusion is very important, since it will determine the order of running. So, if you add a module function to recognize cyrilic text before latin text and try to decode a latin text, it'll be much slower than if you did vice-versa. Always sort the functions by the probability of their usefullness.

Note that you don't need to specify in which shared object file the function is; GOCR does it automatically for you.


next up previous contents index
Next: Running modules Up: Modules Previous: Setting module attributes   Contents   Index
root 2002-02-17