#! /usr/local/bin/apl --script ⍝ ******************************************************************** ⍝ utf8 workspace to read and write utf8 files ⍝ Copyright (C) 2019 Bill Daly ⍝ 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 3 of the License, or ⍝ (at your option) any later version. ⍝ This program is distributed in the hope that it will be useful, ⍝ but WITHOUT ANY WARRANTY; without even the implied warranty of ⍝ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ⍝ GNU General Public License for more details. ⍝ You should have received a copy of the GNU General Public License ⍝ along with this program. If not, see . ⍝ ******************************************************************** )copy 1 utl utl∆es ∇err←txt utf8∆write fname;fh;size ⍝ Function to write utf8 files utl∆es (0>fh ←'w' ⎕FIO[3] fname)/fname,' NOT FOUND.' size←txt ⎕FIO[23] fh err←⎕FIO[4] fh ∇ ∇txt← utf8∆read fname;fh;size;stat;sink ⍝ Function to read utf8 files utl∆es (0>fh←'r' ⎕FIO[3] fname)/fname,' NOT FOUND.' stat←⎕FIO[18] fh txt←⎕ucs stat[8] ⎕FIO[6] fh sink←⎕FIO[4] fh ⎕es (0≠sink)/'Error closing ',fname ∇ ∇flist←utf8∆dir path ⍝ Function lists files in path (but not . or ..). flist ← ⎕FIO[29] path ∇ ∇txt utf8∆pipe cmd;ph;sink ⍝ Function to pipe text to an operating system command. ph←'w' ⎕FIO[24] cmd sink←{⍵ ⎕FIO[43] ph}¨txt sink←⎕FIO[25] ph ⎕es (0≠sink)/'Error ',(⍕sink),' while closing pipe to ',cmd ∇ ∇txt←utf8∆sh cmd;ph;sink ⍝ Function to pipe text from a shell command. ph←'r' ⎕FIO[24] cmd txt←⍬ st: →(0=⍴sink←5000 ⎕FIO[41] ph)/end txt←txt,sink →st end: txt←⎕ucs txt sink←⎕fio[25] ph ∇ ∇b←dir utf8∆file_exists fname;count ⍝ Function tests for the existance of a file. count←''⍴⍴dir←utf8∆dir dir b←count ≥ dir utl∆listSearch fname ∇ ∇ z←utf8∆rm fname;handle ⍝ Function to remove a file. z←⎕fio[19] fname ∇ ∇Z←utf8⍙metadata Z←0 2⍴⍬ Z←Z⍪'Author' 'Bill Daly' Z←Z⍪'BugEmail' 'address@hidden' Z←Z⍪'Documentation' 'commments in file.' Z←Z⍪'Download' 'https://sourceforge.net/projects/apl-library' Z←Z⍪'License' 'GPL v3.0' Z←Z⍪'Portability' 'L3' Z←Z⍪'Provides' 'Functions to read and write utf8 files.' Z←Z⍪'Requires' '' Z←Z⍪'Version' '0 1 2' Z←Z⍪'Last update' '2019-02-11' ∇