Re: [BLACKBOX] Merge ASCII text files

From: [at]} <Carl>
Date: Thu, 26 Jul 2012 19:07:59 -0700

----boundary-LibPST-iamunique-893065161_-_-
Content-type: text/plain

Hello Rainer:

A possible simple approach might be to see if you can adapt the following single file "copy" example, which requires you to use Douglas Danforth's amazing and excellent subsystem ["My"] available from Howard Zinn's website CPC at <http://www.zinnamturm.eu/>

I hope Douglas Danforth doesn't object, but I adapted his "My.Files" examples of separate read and write and created a single combination example for copying a single file.

You will need to adapt the following so each file to be merged is copied to a singe output file in the order you wish the concatenation to occur.

Danforth has "Open" commands provided for both input and output in his Files library so you should have more flexibility in the filenames then this example. You should be able to avoid the interactive file prompting of the example if you already know the input and output filenames.

There will be 1 output file which remains open until the input files have been copied. Presumably after each input file is copied, it is closed, so only 1 input need be open at a time.

These are the details you would work out for yourself when you modify the example.

I have to give credit though to Professor K.N. King because there is an example of concatenating input files in his book "Modula-2: A Complete Guide", available from Amazon.

I claim no credit for merging Danforth's read/write examoles and hope he doesn't mind.

Sincerely
Carl Glassberg

Std encoder/decoder appears not to be working on my system, some problem with extra end-of-lines, so here is the program text:

Copyright © 2012,
by Douglas G. Danforth

Version 20-Jan-2012

This program is free software; you can redistribute it and/or modify it under the terms of the "BlackBox Component Builder Open Source License".

MODULE MyTest;
(* modified from Douglas Danforth's separate read/write examples by Carl Glassberg *)

    IMPORT MyFiles, Stores;

    PROCEDURE Copy *;
        VAR rc: MyFiles.ReadController; rd: Stores.Reader;
            wc: MyFiles.WriteController; wr: Stores.Writer;
            ch: CHAR;

    BEGIN
        rc.SetExtension("txt");
        IF rc.OpenDialog(rd) THEN
            wc.SetExtension("txt");
            IF wc.OpenDialog(wr) THEN
                rd.ReadChar(ch);
                WHILE ~rd.rider.eof DO
                    wr.WriteChar(ch);
                    rd.ReadChar(ch)
                END (* while *);
                wc.Close
            END (* if *);
            rc.Close
        END (* if *)
    END Copy;

END MyTest .
---------------------


>Hi all,
>in the near future I will have to programatically merge two or three >ASCII files into one new file.
   
>Does anybody have a hint how to do this in a simple manner ?
   
>I had a look at the interface of module WinApi but could not find a >procedure for this task.

>Reading the files line by line into a buffer and writing the contents to >a new file seems to be a bit nasty.

>    Best regards,
>    Rainer

>    ----


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-893065161_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGZiaWRpcyBcZGVmZjB7XGZvbnR0YmwN
CntcZjBcZnN3aXNzXGZjaGFyc2V0MCBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7
fQ0Ke1xmMlxmbmlsXGZjaGFyc2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBD
b3VyaWVyIE5ldzt9fQ0Ke1xjb2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBc
Ymx1ZTI1NTt9DQpcdWMxXHBhcmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEhlbGxvIFJhaW5l
cjpccGFyDQpccGFyDQpBIHBvc3NpYmxlIHNpbXBsZSBhcHByb2FjaCBtaWdodCBiZSB0byBzZWUg
aWYgeW91IGNhbiBhZGFwdCB0aGUgZm9sbG93aW5nIHNpbmdsZSBmaWxlICJjb3B5IiBleGFtcGxl
LCB3aGljaCByZXF1aXJlcyB5b3UgdG8gdXNlIERvdWdsYXMgRGFuZm9ydGgncyBhbWF6aW5nIGFu
ZCBleGNlbGxlbnQgc3Vic3lzdGVtIFsiTXkiXSBhdmFpbGFibGUgZnJvbSBIb3dhcmQgWmlubidz
IHdlYnNpdGUgQ1BDIGF0IDxodHRwOi8vd3d3Lnppbm5hbXR1cm0uZXUvPlxwYXINClxwYXINCkkg
aG9wZSBEb3VnbGFzIERhbmZvcnRoIGRvZXNuJ3Qgb2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lIHRvIHByb2dyYW1hdGljYWxseSBtZXJnZSB0
d28gb3IgdGhyZWUgPkFTQ0lJIGZpbGVzIGludG8gb25lIG5ldyBmaWxlLlxwYXINClwnYTAgXCdh
MCBccGFyDQo+RG9lcyBhbnlib2R5IGhhdmUgYSBoaW50IGhvdyB0byBkbyB0aGlzIGluIGEgc2lt
cGxlIG1hbm5lciA/XHBhcg0KXCdhMCBcJ2EwIFxwYXINCj5JIGhhZCBhIGxvb2sgYXQgdGhlIGlu
dGVyZmFjZSBvZiBtb2R1bGUgV2luQXBpIGJ1dCBjb3VsZCBub3QgZmluZCBhID5wcm9jZWR1cmUg
Zm9yIHRoaXMgdGFzay5ccGFyDQpccGFyDQo+UmVhZGluZyB0aGUgZmlsZXMgbGluZSBieSBsaW5l
IGludG8gYSBidWZmZXIgYW5kIHdyaXRpbmcgdGhlIGNvbnRlbnRzIHRvID5hIG5ldyBmaWxlIHNl
ZW1zIHRvIGJlIGEgYml0IG5hc3R5LlxwYXINClxwYXINCj5cJ2EwIFwnYTAgQmVzdCByZWdhcmRz
LFxwYXINCj5cJ2EwIFwnYTAgUmFpbmVyXHBhcg0KXHBhcg0KPlwnYTAgXCdhMCAtLS0tXHBhcg0K
XHBhcg0KXHBhcg0KLS0tLVxwYXINClRvIHVuc3Vic2NyaWJlLCBzZW5kIGEgbWVzc2FnZSB3aXRo
IGJvZHkgIlNJR05PRkYgQkxBQ0tCT1giIHRvIExJU1RTRVJWQExJU1RTLk9CRVJPTi5DSH19APZx
iOE
----boundary-LibPST-iamunique-893065161_-_---
Received on Fri Jul 27 2012 - 04:07:59 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:00 UTC