[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 8.14.3 Overcome some differences between Dos and Unix

The following listing contains the interface of the DosUnix unit.

This unit is there to overcome some of those differences between Dos and Unix systems that are not automatically hidden by GPC and the Run Time System. Currently features translation of bash style input/output redirections (``foo 2>&1'`) into ``redir'` calls for DJGPP (``redir -eo foo'`) and a way to read files with Dos CR/LF pairs on any system.

When necessary, new features will be added to the unit in future releases.

    { Some routines to support writing programs portable between Dos and
      Unix. Perhaps it would be a good idea not to put features to make
      Dos programs Unix-compatible (shell redirections) and vice versa
      (reading Dos files from Unix) together into one unit, but rather
      into two units, DosCompat and UnixCompat or so -- let's wait and
      see, perhaps when more routines suited for this/these unit(s) will
      be found, the design will become clearer ...

      Copyright (C) 1998-2002 Free Software Foundation, Inc.

      Author: Frank Heckenbach <frank@pascal.gnu.de>

      This file is part of GNU Pascal.

      GNU Pascal 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 2, or (at your
      option) any later version.

      GNU Pascal 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 GNU Pascal; see the file COPYING. If not, write to the
      Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
      02111-1307, USA.

      As a special exception, if you link this file with files compiled
      with a GNU compiler to produce an executable, this does not cause
      the resulting executable to be covered by the GNU General Public
      License. This exception does not however invalidate any other
      reasons why the executable file might be covered by the GNU
      General Public License. }

    {$gnu-pascal,I-}
    {$if __GPC_RELEASE__ < 20001023}
    {$error This unit requires GPC release 20001023 or newer.}
    {$endif}

    unit DosUnix;

    interface

    uses GPC;

    { This function is meant to be used when you want to invoke a system
      shell command (e.g. via Execute or Exec from the Dos unit) and
      want to specify input/output redirections for the command invoked.
      It caters for the different syntax between DJGPP (with the `redir'
      utility) and other systems.

      To use it, code your redirections in bash style (see the table
      below) in your command line string, pass this string to this
      function, and the function's result to Execute or the other
      routines.

      The function translates the following bash style redirections
      (characters in brackets are optional) into a redir call under Dos
      systems except EMX, and leave them unchanged under other systems.
      Note: `redir' comes with DJGPP, but it should be possible to
      install it on other Dos systems as well. OS/2's shell, however,
      supports bash style redirections, I was told, so we don't
      translate on EMX.

      [0]<     file      redirect standard input from file
      [1]>[|]  file      redirect standard output to file
      [1]>>    file      append standard output to file
      [1]>&2             redirect standard output to standard error
      2>[|]    file      redirect standard error to file
      2>>      file      append standard error to file
      2>&1               redirect standard error to standard output
      &> file            redirect both standard output and standard
                         error to file }
    function  TranslateRedirections (const Command: String): TString;
      asmname '_p_TranslateRedirections';

    { Under Unix, translates CR/LF pairs to single LF characters when
      reading from f, and back when writing to f. Under Dos, does
      nothing because the run time system alrady does this job. In the
      result, you can read both Dos and Unix files, and files written
      will be Dos. }
    procedure AssignDos (var f: AnyFile; const Name: String);
      asmname '_p_AssignDos';

    { Translates a character from the "OEM" charset used under Dos to
      the ISO-8859-1 (AKA Latin1) character set. }
    function  OEM2Latin1 (ch: Char): Char; asmname '_p_OEM2Latin1';

    { Translates a character from the ISO-8859-1 (AKA Latin1) character
      set to the "OEM" charset used under Dos. }
    function  Latin12OEM (ch: Char): Char; asmname '_p_Latin12OEM';

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html