static void Main(string[] args) { if (args.Length != 1) { Console.Error.WriteLine("Usage: ShowHCards input.cbn"); return; } using (TapeReader r = new TapeReader(args[0], true)) { int ret; while ((ret = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { if (ret == 0) { Console.WriteLine("\\Eof\\"); } else { if (mrecord.Length != 160 || !binary) { Console.Error.WriteLine("\\invalid {0} record with length={1}\\", binary?"binary":"BCD", mrecord.Length); } else { HollerithConverter.CBNToString(mrecord, 0, 80, out string s); Console.WriteLine(s.TrimEnd()); } } } } }
static void Main(string[] args) { if (args.Length != 1) { Console.Error.WriteLine("Usage: ShowCards deck.cbn"); return; } int cardno = 0; using (TapeReader r = new TapeReader(args[0], true)) { int rtype; string label; while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { cardno++; if (rtype == 0) { Console.WriteLine("EOF"); } else { if (!binary) { Console.Error.WriteLine("not binary record"); return; } if (HollerithConverter.CBNToString(mrecord, 72, 8, out label) > 0) { label = ""; } CBNConverter.FromCBN(mrecord, out Card crd); for (int i = 0; i < 24; i++) { Console.Write(" {0}", crd.C[i].ToString()); if (i == 0) { Console.WriteLine(" Card {0} FUL {1}", cardno, label); } else { Console.WriteLine(); } } } } } }
static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: Punch input.txt output.cbn"); 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); byte[] trecord = new byte[160]; HollerithConverter.StringToCBN(line, 0, trecord); w.WriteRecord(true, trecord); } } }
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); }
static void Main(string[] args) { if (args.Length != 1) { Console.Error.WriteLine("Usage: ShowCards deck.cbn"); return; } int cardno = 0; using (TapeReader r = new TapeReader(args[0], true)) { int rtype; string label; while ((rtype = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { cardno++; if (rtype == 0) { Console.WriteLine("EOF"); } else { if (!binary) { Console.Error.WriteLine("not binary record"); return; } if (HollerithConverter.CBNToString(mrecord, 72, 8, out label) > 0) { label = ""; } CBNConverter.FromCBN(mrecord, out Card crd); BinaryCardConverter.CardType t = BinaryCardConverter.GetCardType(crd); switch (t) { case BinaryCardConverter.CardType.Full: for (int i = 0; i < 24; i++) { Console.Write(" {0}", crd.C[i].ToString()); if (i == 0) { Console.WriteLine(" Card {0} FUL {1}", cardno, label); } else { Console.WriteLine(); } } break; case BinaryCardConverter.CardType.Abs: for (int i = 0; i < crd.W9L.D; i++) { Console.Write(" {0} {1}", Convert.ToString(crd.W9L.A + i, 8).PadLeft(5, '0'), crd.C[i + 2].ToString()); if (i == 0) { Console.WriteLine(" Card {0} ABS {1}", cardno, label); } else { Console.WriteLine(); } } break; case BinaryCardConverter.CardType.Rel: BinaryCardConverter.RelType[] rel = BinaryCardConverter.GetRelData(crd); for (int i = 0; i < crd.W9L.D; i++) { char rd = ' ', ra = ' '; switch (rel[i * 2]) { case BinaryCardConverter.RelType.absolute: rd = ' '; break; case BinaryCardConverter.RelType.relocatable_direct: rd = 'R'; break; case BinaryCardConverter.RelType.relocatable_complemented: rd = 'C'; break; } switch (rel[i * 2 + 1]) { case BinaryCardConverter.RelType.absolute: ra = ' '; break; case BinaryCardConverter.RelType.relocatable_direct: ra = 'R'; break; case BinaryCardConverter.RelType.relocatable_complemented: ra = 'C'; break; } Console.Write(" {0} {1} {2} {3}", rd, ra, Convert.ToString(crd.W9L.A + i, 8).PadLeft(5, '0'), crd.C[i + 4].ToString()); if (i == 0) { Console.WriteLine(" Card {0} REL {1}", cardno, label); } else { Console.WriteLine(); } } break; case BinaryCardConverter.CardType.Transfer: Console.WriteLine(" TRANSFER {0} Card {1} ABS {2}", Convert.ToString(crd.W9L.A, 8).PadLeft(5, '0'), cardno, label); break; case BinaryCardConverter.CardType.RelTransfer: Console.WriteLine(" TRANSFER {0} Card {1} REL {2}", Convert.ToString(crd.W9L.A, 8).PadLeft(5, '0'), cardno, label); break; default: Console.Error.WriteLine("Invalid Card Type"); return; } } } } }