Пример #1
0
        static void Main(string[] args)
        {
            if (args.Length > 2 || args.Length == 0)
            {
                Console.Error.WriteLine("Usage: ShowTape Tape.tap  [linelength]");
                return;
            }
            int lenght = -1;

            if (args.Length == 2)
            {
                if (!int.TryParse(args[1], out lenght))
                {
                    Console.Error.WriteLine("wrong linelength");
                    return;
                }
            }
            using (TapeReader r = new TapeReader(args[0], true))
            {
                int rtype;
                while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0)
                {
                    if (rtype == 0)
                    {
                        Printskipped();
                        Console.WriteLine("\\Eof\\");
                    }
                    else if (binary)
                    {
                        numbin++;
                    }
                    else
                    {
                        Printskipped();
                        string line = BcdConverter.BcdToString(mrecord);
                        if (lenght <= 0)
                        {
                            Console.WriteLine(line.TrimEnd());
                        }
                        else
                        {
                            for (int i = 0; i < line.Length; i += lenght)
                            {
                                if (i + lenght < line.Length)
                                {
                                    Console.WriteLine(line.Substring(i, lenght).TrimEnd());
                                }
                                else
                                {
                                    Console.WriteLine(line.Substring(i).TrimEnd());
                                }
                            }
                        }
                    }
                }
                Printskipped();
            }
        }
Пример #2
0
 static void Main(string[] args)
 {
     if (args.Length != 2)
     {
         Console.Error.WriteLine("Usage: WriteTape input.txt output.tap");
         return;
     }
     using (StreamReader r = new StreamReader(args[0]))
         using (TapeWriter w = new TapeWriter(args[1], true))
         {
             while (!r.EndOfStream)
             {
                 string line = ExpandTabs(r.ReadLine().ToUpper(), 8).PadRight(80).Substring(0, 80).PadRight(84);
                 w.WriteRecord(false, BcdConverter.StringToBcd(line));
             }
             w.WriteEOF();
         }
 }
Пример #3
0
        static void Main(string[] args)
        {
            byte[] trecord = new byte[160];
            if (args.Length != 2)
            {
                Console.Error.WriteLine("Usage: TapeExtract tapefile dir");
            }
            string tape  = args[0];
            string dir   = args[1] + "\\";
            int    count = 0;
            bool   eof   = false;

            using (StreamWriter tx = new StreamWriter(dir + "index.txt"))
                using (TapeReader r = new TapeReader(tape, true))
                {
                    rd = r;
                    while (!eof && GetRecord(out bool binary, out byte[] mrecord) == 1)
                    {
                        if (binary || (mrecord.Length != 80 && mrecord.Length != 84))
                        {
                            throw new Exception("wrong Control card");
                        }
                        string descr = BcdConverter.BcdToString(mrecord).Substring(0, 80);
                        tx.WriteLine(descr.TrimEnd());
                        descr = descr.Replace('/', '_');
                        descr = descr.Replace('.', '_');
                        descr = descr.Replace('+', '_');
                        string filename;
                        if (descr[5] == ' ')
                        {
                            filename = dir + descr.Substring(3, 2).Trim() + "_" + descr.Substring(6, 5).Trim();
                        }
                        else
                        {
                            filename = dir + descr.Substring(3, 8).Trim();
                        }
                        filename += "_" + descr.Substring(20, 4).Trim() + "." + descr.Substring(33, 2).Trim();

                        using (TapeWriter wr = new TapeWriter(filename, true))
                        {
                            bool lastrecord = false;
                            do
                            {
                                int ret = GetRecord(out binary, out mrecord);
                                if (ret != 1)
                                {
                                    eof        = true;
                                    lastrecord = true;
                                }
                                else
                                {
                                    if (binary)
                                    {
                                        Deblock(mrecord, 160, out byte[][] orecord);
                                        if (orecord != null)
                                        {
                                            for (int i = 0; i < orecord.Length; i++)
                                            {
                                                wr.WriteRecord(true, orecord[i]);
                                                count++;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (mrecord.Length == 80 || mrecord.Length == 84)
                                        {
                                            UngetRecord(binary, mrecord);
                                            lastrecord = true;
                                        }
                                        else
                                        {
                                            Deblock(mrecord, 80, out byte[][] orecord);
                                            if (orecord != null)
                                            {
                                                for (int i = 0; i < orecord.Length; i++)
                                                {
                                                    HollerithConverter.BCDToCBN(orecord[i], 0, trecord);
                                                    wr.WriteRecord(true, trecord);
                                                    count++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }while (!lastrecord);
                        }
                    }
                    rd = null;
                }
            Console.WriteLine("{0} cards written", count);
        }