001package Torello.Java;
002
003import java.io.*;
004import java.util.*;
005import java.util.regex.*;
006
007import java.util.concurrent.CompletionException;
008import java.util.function.Consumer;
009
010import Torello.Java.*;
011import Torello.HTML.*;
012import Torello.HTML.NodeSearch.*;
013import Torello.Java.Additional.*;
014
015/**
016 * A great tool for invoking commands to an MS-DOS operating-system.
017 * 
018 * <EMBED ClASS='external-html' DATA-FILE-ID=MSDOS>
019 * <EMBED ClASS='external-html' DATA-FILE-ID=OSC_WORA>
020 * <EMBED CLASS='external-html' DATA-FILE-ID=OSC_WILD_CARD_02>
021 * <EMBED CLASS='external-html' DATA-CLASS=MSDOS DATA-VAR=dos DATA-FILE-ID=OSC_ALL_FIELDS>
022 * <EMBED CLASS='external-html' DATA-FILE-ID=APPENDABLE>
023 * 
024 * @see OSCommands
025 * @see OSResponse
026 */
027@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="OSC_INHERITORS")
028public class MSDOS extends OSCommands implements Cloneable
029{
030    // ********************************************************************************************
031    // ********************************************************************************************
032    // Constructors
033    // ********************************************************************************************
034    // ********************************************************************************************
035
036
037    /** <EMBED CLASS='external-html' DATA-FILE-ID=OSC_CTOR_1> */
038    public MSDOS() { super(); }
039
040    /**
041     * <EMBED CLASS='external-html' DATA-FILE-ID=OSC_CTOR_2>
042     * @param outputAppendable <EMBED CLASS='external-html' DATA-FILE-ID=OSC_APPENDABLE_PARAM>
043     * @see OSCommands#outputAppendable
044     */
045    public MSDOS(Appendable outputAppendable)
046    { super(outputAppendable); }
047
048    /**
049     * <EMBED CLASS='external-html' DATA-FILE-ID=OSC_CTOR_3>
050     * 
051     * @param outputAppendable      <EMBED CLASS='external-html' DATA-FILE-ID=OSC_APPENDABLE_PARAM>
052     * @param commandStrAppendable  <EMBED CLASS='external-html' DATA-FILE-ID=OSC_CSA_PARAM>
053     * @param standardOutput        <EMBED CLASS='external-html' DATA-FILE-ID=OSC_STND_OUT_PARAM>
054     * @param errorOutput           <EMBED CLASS='external-html' DATA-FILE-ID=OSC_ERROR_OUT_PARAM>
055     * @see OSCommands#outputAppendable
056     * @see OSCommands#commandStrAppendable
057     * @see OSCommands#standardOutput 
058     * @see OSCommands#errorOutput 
059     */
060    public MSDOS(
061            Appendable outputAppendable,
062            Appendable commandStrAppendable,
063            Appendable standardOutput,
064            Appendable errorOutput
065        )
066    { super(outputAppendable, commandStrAppendable, standardOutput, errorOutput); }
067
068    /**
069     * <EMBED CLASS='external-html' DATA-FILE-ID=OSC_CTOR_4>
070     * 
071     * @param standardOutput    <EMBED CLASS='external-html' DATA-FILE-ID=OSC_STND_OUT_PARAM>
072     * @param errorOutput       <EMBED CLASS='external-html' DATA-FILE-ID=OSC_ERROR_OUT_PARAM>
073     * @see OSCommands#standardOutput 
074     * @see OSCommands#errorOutput 
075     */
076    public MSDOS(Appendable standardOutput, Appendable errorOutput)
077    { super(standardOutput, errorOutput); }
078
079    /**
080     * Used by the method {@code clone()}.
081     * @param other Another instance of this class.
082     */
083    protected MSDOS(MSDOS other) { super(other); }
084
085    /** {@inheritDoc} */
086    public MSDOS clone() { return new MSDOS(this); }
087
088
089    // ********************************************************************************************
090    // ********************************************************************************************
091    // Commands
092    // ********************************************************************************************
093    // ********************************************************************************************
094
095
096    /**
097     * MS-DOS Command: {@code COPY}
098     * 
099     * <DIV CLASS="SHELL">{@code
100     * C:\>COPY <src> <target>
101     * }</DIV>
102     * 
103     * @param src MS-DOS {@code 'COPY'} command's "source" argument
104     * @param target The {@code 'COPY'} command's "target" argument
105     * @return <EMBED CLASS='external-html' DATA-FILE-ID=OSRET>
106     * @see OSCommands#printAndRun(String[])
107     * @throws IOException If there are problems while invoking the operating-system command
108     */
109    public OSResponse COPY(String src, String target) throws IOException
110    { 
111        String[] command = { "COPY", src, target };
112
113        return printAndRun(command);
114    }
115
116    /**
117     * MS-DOS Command: {@code COPY}
118     * 
119     * <DIV CLASS="SHELL">{@code
120     * C:\>COPY <src.elementAt(0)> <src.elementAt(1)> ... <src.elementAt(src.size()-1)> <target>
121     * }</DIV>
122     * 
123     * @param src This may be a list of files to be copied to a target directory
124     * @param target This is the target directory for the files listed.
125     * @return <EMBED CLASS='external-html' DATA-FILE-ID=OSRET>
126     * @see OSCommands#printAndRun(String[])
127     * @throws IOException If there are problems while invoking the operating-system command
128     */
129    public OSResponse COPY(Vector<String> src, String target) throws IOException
130    {
131        String[] command = new String[src.size() + 2];
132        command[0] = "COPY";
133        command[src.size() + 1] = target;
134
135        for (int i=0; i < src.size(); i++) command[1 + i] = src.elementAt(i);
136
137        return printAndRun(command);
138    }
139
140    /**
141     * MS-DOS Command: {@code COPY}
142     * 
143     * <DIV CLASS="SHELL">{@code
144     * C:\>COPY <src[0]> <src[1]> ... <src[src.length-1]> <target>
145     * }</DIV>
146     * 
147     * @param src This may be a list of files to be copied to a target directory
148     * @param target This is the target directory for the files listed.
149     * @return <EMBED CLASS='external-html' DATA-FILE-ID=OSRET>
150     * @see OSCommands#printAndRun(String[])
151     * @throws IOException If there are problems while invoking the operating-system command
152     */
153    public OSResponse COPY(String[] src, String target) throws IOException
154    {
155        String[] command = new String[src.length + 2];
156        command[0] = "COPY";
157        command[src.length + 1] = target;
158
159        for (int i=0; i < src.length; i++) command[1 + i] = src[i];
160
161        return printAndRun(command);
162    }   
163
164    /**
165     * MS-DOS Command: {@code DEL}
166     * 
167     * <DIV CLASS="SHELL">{@code
168     * C:\>DEL <s1>
169     * }</DIV>
170     * 
171     * @param s1 The item to be removed, using an MS-DOS command.
172     * @return <EMBED CLASS='external-html' DATA-FILE-ID=OSRET>
173     * @see OSCommands#printAndRun(String[])
174     * @throws IOException If there are problems while invoking the operating-system command
175     */
176    public OSResponse DEL(String s1) throws IOException
177    { 
178        String[] command = { "DEL", s1 };
179
180        return printAndRun(command);
181    }
182
183    /**
184     * MS-DOS Command: {@code DEL}
185     * 
186     * <DIV CLASS="SHELL">{@code
187     * C:\>DEL <sArr[0]> <sArr[1]> ... <sArr[sArr.length-1]>
188     * }</DIV>
189     * 
190     * @param sArr An {@code String[] array} which is added to the end of this MS-DOS command.
191     * These will be the item(s) removed by the {@code 'DEL'} command.
192     * 
193     * @return <EMBED CLASS='external-html' DATA-FILE-ID=OSRET>
194     * @see OSCommands#printAndRun(String[])
195     * @throws IOException If there are problems while invoking the operating-system command
196     */
197    public OSResponse DEL(String[] sArr) throws IOException
198    {
199        String[] command = new String[sArr.length + 1];
200        command[0] = "DEL";
201
202        for (int i=0; i < sArr.length; i++) command[i + 1] = sArr[i];
203
204        return printAndRun(command);
205    }
206}