Shlib
Shlib
While this may be customary for sample code it is very dangerous when working with real C code. You have been warned.
Problem: No OS-PUTENV()
NAME putenv - change or add an environment variable SYNOPSIS #include <stdlib.h> int putenv(char *string); DESCRIPTION The putenv() function adds or changes the value of environment variables. The argument string is of the form name=value. If name does not already exist in the environment, then string is added to the environment. If name does exist, then the value of name in the environment is changed to value. The string pointed to by string becomes part of the environment, so altering the string changes the environment. RETURN VALUE The putenv() function returns zero on success, or non-zero if an error occurs.
Calling putenv()
define variable x as integer no-undo. procedure putenv external "/lib64/libc.so.6": define input parameter env as character. define return parameter x as long. end. display os-getenv( "XYZZY" ). pause. run putenv( "XYZZY=pflugh", output x ). display os-getenv( "XYZZY" ). os-command value( 'echo "$XYZZY"' ). return.
Calling putenv()
? Press space bar to continue.
? pflugh
Press space bar to continue. pflugh
Calling sprintf()
define variable x as integer no-undo. define variable c as memptr no-undo. define variable m as memptr no-undo. procedure sprintf external "/lib64/libc.so.6": define input-output parameter fStr as memptr. define input parameter mask as memptr. define input parameter arg as double. define return parameter x as long. end. set-size( c ) = 1024. set-size( m ) = 1024. put-string( m, 1 ) = "%1.4e". run sprintf( input-output c, m, 0.0123, output x ). display get-string( c, 1 ) format x(20). return.
Calling sprintf()
1.2300e-02
float
double char* (read-only) char* (writeable) pointer to
FLOAT
DOUBLE CHARACTER or MEMPTR MEMPTR HANDLE TO
Overview
Youll need some C source code. Compile to object code. Run the Linker and create a Shared Library. Test with Progress.
Source Code
#include <time.h>
$ ls shortsleep.c
shortleep.o
$ file shortleep.o ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not stripped
shortsleep.so
$ file shortsleep.so shortsleep.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped $ nm -DC shortsleep.so shortsleep.so:0000000000100460 shortsleep.so:0000000000100460 shortsleep.so:0000000000100460 shortsleep.so: shortsleep.so:0000000000000280
A A A U T
Test Again!
$ ps -ef | grep [_]progres tom 21243 27534 1 17:16 pts/0 00:10:50 /usr/pro102a/bin/_progres -1 $ pro p shortsleep.p i 1,000 08:20 $ ps -ef | grep [_]progres tom 21243 27534 8 17:16 pts/0 00:10:50 /usr/pro102a/bin/_progres -1
Source Code
#include <regex.h>
if ( regcomp(&xpattern, pattern, REG_EXTENDED|REG_ICASE ) != 0 ) { offset = -2; } else { if ( regexec(&xpattern, string, matchDepth, pmatch, 0 ) != 0 ) { offset = -1; } else { offset = pmatch[1].rm_so; } } regfree( &xpattern ); return offset; }
Test!
$ pro p rx.p pattern: .*(Fox).* string: The quick brown fox jumped over the lazy dog! x: 16
Use a variable? NOT! Use a pre-processor. Use symbolic links. Wait for 10.2B.
Isolate different cases in multiple .p files. Use wrapper libraries. Wait for 10.2B.
Call-Backs?
void qsort( void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *) );
Not supported .
Persistence
procedure putenv external "/lib64/libc.so.6" PERSISTENT: define input parameter env as character. define return parameter x as long. end.
MEMPTRs
define variable x as integer no-undo. define variable c as memptr no-undo. define variable m as memptr no-undo. procedure sprintf external "/lib64/libc.so.6": define input-output parameter fStr as memptr. define input parameter mask as memptr. define input parameter arg as double. define return parameter x as long. end. set-size( c ) = 1024. set-size( m ) = 1024. put-string( m, 1 ) = "%1.4e". run sprintf( input-output c, m, 0.0123, output x ). display get-string( c, 1 ) format x(20). set-size( c ) = 0. set-size( m ) = 0. return.
Conclusion
Share code from 3rd party, non-Progress, sources. Gain performance improvements from routines written in faster languages. Access low-level OS features that are not otherwise available. It beats the heck out of using PROBUILD.
Questions?
Thank-you!
void *dlopen( const char *filename, int flag ); char *dlerror( void ); void *dlsym( void *handle, const char *symbol ); int dlclose( void *handle ); DESCRIPTION The four functions dlopen(), dlsym(), dlclose(), dlerror() implement the interface to the dynamic linking loader.