Re: blob in embedded c code

Mike Aubury <[email protected]>
Newsgroups gmane.comp.lang.4gl.aubit.general
Message-ID <CAGAq4WGsdXjJrfKprc49=SjkZGtb6-4AMG1nt0ET_vz3cB__Mg@mail.gmail.com>
There are "A4GL_file" and "channel" libraries you can use.

Using the "A4GL_file" library is just a wrapper around fopen & friends - so
might be more familiar if you know 'C' - eg :


{
This is example for new SHARED handling of libraries - old method was
removed
(which looked bad) and introduced the "::" syntax as per perl

This code uses library from lib/extra_libs/file for file handling as an
example.
}

main
define afile integer
define fsize integer
define buff CHAR(80)

WHENEVER SQLERROR CONTINUE
WHENEVER ERROR CONTINUE
WHENEVER ANY ERROR CONTINUE

        CALL A4GL_file::fopen("file.4gl","r") returning afile

        IF afile=0 THEN
                ERROR "Unable to open a file called 'file.4gl'"
                        WAIT FOR KEY
                EXIT PROGRAM
        END IF

        DISPLAY "afile=",afile

        LET status=0
        CALL A4GL_file::fsize(afile) returning fsize

        IF status!=0 THEN
                DISPLAY "ERROR : ",A4GL_file::ferror(afile);
        END IF

        DISPLAY "Size=",fsize
        WHILE TRUE
                CALL A4GL_file::fgets(afile) returning buff
                IF A4GL_file::feof(afile) THEN
                        EXIT WHILE
                END IF
                DISPLAY "Read '",buff clipped,"' from file"
        END WHILE

end main


[ You can see the sourcecode in lib/extra_libs/file ]



Its also very easy for you to write your own extension libraries that use
the "::" format - just compile your normal 4gls with :
(Assuming a unix platform) :

   4glpc --as-dll -o somelib.so somelib.4gl

You can then reference any 4gl function in this "somelib" directly in code
(so long as its on the LD_LIBRARY_PATH)
  CALL somelib::somefunc(1,2)


Nice thing about this is that there's no direct link between somelib and
the the usage in your 4gl - so you can embed code in there that will change
often - and you wont need to recompile your .4ae/.4ge's :)

In fact - "somelib.so" doesn't even need to exist when you compile your 4gl
that uses it !






On 10 January 2012 18:46, Michal Hajek <[email protected]> wrote:

> Thanks for your comment .-)
>
> Is there any way how to write/append to files without C code and not
> using reports? Such Aubit native 4gl functions would be handy. I drop
> into C just for the files operations.
>
> Michal
>
> On Tue, Jan 10, 2012 at 4:53 PM, Mike Aubury <[email protected]>
> wrote:
> > Excellent :)
> > Yes - it downshifts all the variable names used in 4gl (which is case
> > insensitive) - but always leaves everything in the code..endcode
> completely
> > unchanged..
> >
> >
> > (The other potential "gotcha" when dropping into c is the prefix
> (aclfgl_)
> > we apply to function names to stop them clashing with the builtin C
> > functions..)
> >
> >
> >
> > On 10 January 2012 15:14, Michal Hajek <[email protected]> wrote:
> >>
> >> Eh, solved.
> >>
> >> Compiler downshifts the varnames - but not insinde code section and the
> >> address of the text is xxx.ptr (name "ptr" found in headers in incl
> >> directory).
> >>
> >> ok=printf("%s\n",xxx.ptr);
> >>
> >> seems to be ok.
> >>
> >> Michal
> >>
> >>
> >>
> >>
> >>
> ------------------------------------------------------------------------------
> >> Write once. Port to many.
> >> Get the SDK and tools to simplify cross-platform app development. Create
> >> new or port existing apps to sell to consumers worldwide. Explore the
> >> Intel AppUpSM program developer opportunity.
> appdeveloper.intel.com/join
> >> http://p.sf.net/sfu/intel-appdev
> >> _______________________________________________
> >> Aubit4gl-discuss mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss
> >
> >
>
>
> ------------------------------------------------------------------------------
> Write once. Port to many.
> Get the SDK and tools to simplify cross-platform app development. Create
> new or port existing apps to sell to consumers worldwide. Explore the
> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
> http://p.sf.net/sfu/intel-appdev
> _______________________________________________
> Aubit4gl-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss
>

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox

_______________________________________________
Aubit4gl-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.