/***************************************************************************
* exe_builtin_mod.c - description
* -------------------
* begin : Mon 19 Dec 2005 04:20:14 PM EST
* copyright : (C) 2005 by Terry D. Boldt
* email : fastsnip-wm1@yahoo.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/*
*
* QTAwk plugin function to demonstrate executing QTAwk builtin functions
*/

#include "QTAwk_plugins.h"
#include <string.h> #include <stdlib.h> #include <stdio.h> /* define some useful constants */ #define TRUE 1 #define FALSE 0 /* define End Of String marker */ #define EOS '\x000' /* define initialization function */ unsigned init_exebuiltin( void) { /* array of pointers to string with argument names for loaded functions * Here both functions take a single string function */ unsigned char *arguments[] = { "lcl_time", NULL }; /* declare error return variable */ unsigned char *reg_err; /* call function to initialize for installing dynamic function(s) */ QTAwk_register_function_count(3); /* now call function to register each dynamic function to load * * Note that 'QTAwk_register_function' returns a pointer to a string or NULL * if no error in registering function. Here we are ignoring the return value * until returning from the call. * We "should" examine the return value for every call to 'QTAwk_register_function' * and report any errors. */ reg_err = QTAwk_register_function("exe_builtin_mod_version",NULL,FALSE); reg_err = QTAwk_register_function("exe_builtin",NULL,FALSE); reg_err = QTAwk_register_function("get_dup",NULL,FALSE); return reg_err ? -1 : 0; } /* init_exebuiltin */ /* function registered to accomplish actual work. * * All dynamically loaded functions have the following prototype form: * * Variable_ptr loaded_function(unsigned argument_count); * * Where 'Variable_ptr' is a QTAwk variable defined in the QTAwk plugin * header file "QTAwk_plugins.h" * Do NOT manipulate the fields in the structure directly. Use the function * calls defined in "QTAwk_plugins.h" for that purpose. * * * */ /* version string */ static unsigned char version_string[] = "Execute Builtin Function Module, Version 1.00"; /* function to return module version string */ Variable_ptr exe_builtin_mod_version( void) { Variable_ptr retval; retval = QTAwk_get_variable_set((void *)version_string,STRING_VAL); return retval; } /* exe_builtin_mod_version */ /* * Execute builtin function srange * */ Variable_ptr exe_builtin( unsigned arg_cnt) { Variable_ptr retval; Variable_ptr chr1, chr2; qta_long elem_value; unsigned char chr; /* get first character in range */ chr = 'A'; chr1 = QTAwk_get_variable_set((void *)&chr,CHAR_VAL); /* get second character in range */ chr = 'z'; chr2 = QTAwk_get_variable_set((void *)&chr,CHAR_VAL); /* the following call illustrates an incorrect argument list. There is one * argument for the builtin function, but 2 specified (the correct number for the * builtin function is 2). Uncommenting the following line, compiling and * executing will result in a run-time error from QTAwk. */ /* retval = QTAwk_execute_builtin_function(QTAWK_SRANGE,2,chr1,NULL); */ /* the following call illustrates an incorrect argument list. There is one * argument for the builtin function, but 2 specified (the correct number for the * builtin function is 2). Uncommenting the following line, compiling and * executing will result in a run-time error from QTAwk. */ /* retval = QTAwk_execute_builtin_function(QTAWK_SRANGE,2,chr1,chr2); */ /* the following is the correct argument list for the call. It has the correct number of * arguments for the builtin function, the correct number specified, and the terminating * NULL pointer - which is NOT included in the argument count specified. */ retval = QTAwk_execute_builtin_function(QTAWK_SRANGE,2,chr1,chr2,NULL); return retval; } /* exe_builtin */ /* Get alpha characters from POSIX array and duplicate */ Variable_ptr get_dup( unsigned arg_cnt) { Variable_ptr retval; Variable_ptr alpha; alpha = QTAwk_get_named_variable("POSIX"); alpha = QTAwk_get_array_element(alpha,"s","alpha"); retval = QTAwk_dup(alpha); return retval; } /* get_dup */ /* exit function - executed before unloading module * Using default function name here. */ unsigned QTAwk_exit_load_module( void) { printf("Unloading Execute built function Demo module.\n"); } /* QTAwk_exit_load_module */