EDI in linux (everone PLEASE read)

Douglas J Hunley doug
Mon May 17 11:37:47 PDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ben Duncan spewed electrons into the ether that resembled:
> Yeah, it might pay to have multiple pieces. However, here is a link I
> think
> everyone might find interesting on the COBOL aspect.
>
> http://www.linuxmax.net/news/00840.html

interesting. I don't think you're going to like the performance 
characteristics of COBOL in any shape though. I definately think Perl for 
most of the data managers, C for the translator, mysql for the backend, 
perhaps rebol (www.rebol.org) for the messaging (partner to partner, perhaps 
VAN). XML datafiles is a no-brainer, IMHO. you should probably start w/ ANSI, 
implement a fairly recent Y2K compliant standard (but not too recent. maybe 
3051?) doing the most "heavily used" (read most interested in by 
developer/user community) of the transaction sets, then move to EDIFACT and 
do the same. then fill in the missing transaction sets later.
of course, you need a mapper to be built along side this. a really good XML 
and XSLT should get most of the way there.

Here's a quick example of REBOL code. this would be a decent start for sending 
transactions to a van I think. Not that I'm pushing REBOL, I personally don't 
use it. I just think it's well suited to the task here. along with perl and c 
for the other bits.

example rebol:
 
REBOL [
    Title:  "Selective File Tree Upload"
    File:   %curdirtreeupload.r
    Email:  timewarp at sirius.com
    Author: "Erin A Thomas"
    Date:   18-Aug-1999
    Purpose:    { Find new and recently modified files and upload them to
                  a source directory on a specified ftp site }
    Category:   'ftp
]

;;; Edit site with the user name, password, and site name of your ftp site 
site:       ftp://username:password@www.yourhost.com/

;;; Edit ftp-root to contain the directory path you want to upload the current
;;; directory tree to
ftp-root:   to-file "path-on-ftp-site/"

;;; Edit extentions to contain the extentions of all the files in the current
;;; tree you want to upload
extentions: [".htm" ".txt" ".jpg" ".gif"]


;;============================================================================
;;  Function Name:  get-dirtree (recursive)
;;
;;  Purpose:        Cycle through a directory tree asigning all found 
;;          files to filenames: and directories to directories:
;;
;;  Parameters:     path, exts
;;    path      - initial directory path of file datatype
;;    exts      - file extentions to upload
;;
;;  Global Vars:    filenames, directories
;;    filenames     - series of all found files put together with append
;;    directories   - series of all found directories put together with 
;;            append
;;
;;  Local Vars:     curdir, file, fpath
;;    curdir        - content listing in file datatype of path
;;    file      - temp variable in foreach loop containing individual
;;            file names
;;    fpath     - "full path", inside foreach loop, the result of 
;;            path and file join'ed
;;============================================================================
get-dirtree: function [path [file!] exts [block!]] 
              [curdir file fpath files dirs] [
    curdir:     load path

    foreach file curdir [ 
        fpath: join path file

        either dir? fpath [
            append directories fpath
            get-dirtree fpath exts
        ] [
            foreach ext exts [
                if find file ext [append filenames fpath]
            ]
        ]
    ]
]


;;============================================================================
;;  Function Name:  loadmap
;;
;;  Purpose:        Parse "file date" map in 'map and return the parsed
;;          file map as 'pmap
;;
;;  Returned:       pmap
;;
;;  Parameters:     map
;;    map       - the name of the file containing file names and their
;;            stored modification dates.  The file's table should
;;            be in "key value" pair with the key as %file, and 
;;            value as a valid date readable by rebol
;;
;;  Local Vars:     pmap, filedates-map, file, date
;;    pmap      - the contents of the map file parsed in linear 
;;            format, i.e: [file date file date file date]
;;    filedates-map - contains the contents of the map file once it's 
;;            been loaded as: [[file date] [file date] [...]]
;;    file      - temp variable in foreach loop containing the 
;;            file from the key in 'filedates-map key value pairs
;;    date      - temp variable in foreach loop containing the
;;            date from the value in 'filedates-map key value 
;;          - pairs
;;
;;============================================================================
loadmap: function [map [file!]] [filedates-map file date pmap] [
    pmap: make block! 1
    filedates-map: load map
    foreach [file date] filedates-map [
        append pmap file
        append pmap date
    ]
    while [find pmap none] [
        remove find pmap none pmap
    ]
    return pmap
]


;;============================================================================
;;  Function Name:  compare-map
;;
;;  Purpose:        Check files in fmap (existing files in filetree)
;;          against files in pmap (map of file names with last
;;          modification date in linear format), return pmap
;;          with updated modification dates for recently modified
;;          files and added files and dates for new files found
;;          in the filetree.
;;
;;  Returned:       pmap [block], cmap [block], fileschanged [string]
;; 
;;  Parameters:     fmap, pmap, exts
;;    fmap      - [block!] all files in file tree to be checked
;;    pmap      - [block!] file map with dates fmap will be checked
;;            against
;; 
;;  Local Vars:     cmap, file, cur-file-date, svd-file-date, cur-index
;;          new-index, fileschanged, exts
;;    cmap      - block of files which have been determined to be 
;;            new, or modified
;;    file      - temp variable in foreach loop for 'fmap
;;    cur-file-date - for 'fmap files found in 'pmap, the current date of
;;            the file
;;    svd-file-date - for 'fmap files found in 'pmap, the date indicated 
;;            in 'pmap
;;    cur-index     - the current index of files found in 'pmap
;;    new-index     - cur-index plus 1, the index of the saved 
;;            modification date of files found in 'pmap
;;    fileschanged  - a flag "yes", or "no" indicating if modified, or new
;;            files were found
;;============================================================================
compare-map: function [fmap [block!] pmap [block!]] 
                      [file cur-file-date svd-file-date cur-index new-index
                       cmap fileschanged] [
    cmap: make block! 1
    fileschanged: "no"
    foreach file fmap [
        either find pmap file [ 
            cur-file-date: modified? file
            svd-file-date: select pmap file
            if cur-file-date > svd-file-date [ 
                cur-index: index? find pmap file
                new-index: cur-index + 1
                poke pmap new-index cur-file-date
                print ["Modified file:  " file]
                append cmap file
                fileschanged: "yes"
            ]
        ][
            append pmap file
            append pmap modified? file
            print ["new file:   " file]
            append cmap file
            fileschanged: "yes"
        ]
    ]
    return [pmap cmap fileschanged]
]


fullsite:   join site ftp-root
path:       to-file "./"
uploadmap:  to-file "upload_map.map"
directories:    make block! 1
filedates:  make block! 1
fds-map-parsed: make block! 1
filenames:  make block! 1
uploadfiles:    make block! 1
changed:    "no"
upload:     "no"

get-dirtree path extentions

either exists? uploadmap [
    fds-map-parsed:     loadmap uploadmap
    filemaps:       compare-map filenames fds-map-parsed
    fds-map-parsed:     get filemaps/1
    uploadfiles:        get filemaps/2
    changed:        get filemaps/3
    upload:         get filemaps/3
][
    foreach file filenames [
        append filedates remold [ file modified? file ]
        append uploadfiles file
    ]
    write/lines uploadmap filedates
    upload: "yes"
]

if upload == "yes" [
    if error? try [ dir? fullsite ] [ make-dir fullsite ]
    foreach dir directories [
        fullsite-path: join fullsite dir
        either error? try [ dir? fullsite-path ] [ 
            print ["creating:   " dir ]
            make-dir fullsite-path
        ][
            print ["exists! " dir]
        ]
    ]

    foreach file uploadfiles [
        fullsite-path: join fullsite file
        print ["uploading:  " file]
        write/binary fullsite-path read/binary file
        print ["upload finished"]
    ]
]

either changed == "yes" [
    filedates: []
    foreach [file date] fds-map-parsed [
        if file? file [ if date? date [
            append filedates remold [file date]
        ]]
    ]
    write/lines uploadmap filedates
][
    print "no files have changed!"
]

- -- 
Douglas J Hunley (doug at hunley.homeip.net) - Linux User #174778
Admin: Linux StepByStep - http://www.linux-sxs.org
	and http://jobs.linux-sxs.org

Every nonzero finite dimensional inner product space has an orthonormal basis.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9hpgcSrrWWknCnMIRArGHAJ9TodorfuyYmj6Ru7HSzXYYbVtUugCfbSuT
qCcToeWarkmwqXtA2K7xk+I=
=So9/
-----END PGP SIGNATURE-----




More information about the Linux-users mailing list