static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: Tp2p7b input.tap output.tap"); return; } using (TapeReader r = new TapeReader(args[0], false)) using (TapeWriter w = new TapeWriter(args[1], true)) { int ret; while ((ret = r.ReadRecord(out bool binary, out byte[] mrecord)) >= 0) { if (ret == 0) { Console.WriteLine("Eof"); } else { Console.WriteLine("{0} record, length {1}", binary ? "binary" : "BCD", mrecord.Length); } if (ret == 0) { w.WriteEOF(); } else { w.WriteRecord(binary, mrecord); } } } return; }
static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage CleanDeck n.cbn out.cbn"); return; } using (TapeReader r = new TapeReader(args[0], true)) using (TapeWriter w = new TapeWriter(args[1], true)) { int retval; int cnt = 0; while ((retval = r.ReadRecord(out bool binary, out byte[] rrecord)) >= 0) { cnt++; if (retval == 0) { Console.Error.WriteLine("invalid EOF"); return; } if (!binary) { Console.Error.WriteLine("not binary"); return; } if (rrecord.Length != 160) { Console.Error.WriteLine("Wrong record length"); return; } CBNConverter.FromCBN(rrecord, out Card crd); int i; for (i = 0; i < 24; i++) { if (crd.C[i].LW != 0) { break; } } if (i == 24) { continue; /* blank card */ } if (crd.W9L.LW == 0xFFFFFFFFFL) { continue; /* 9L has all ones */ } w.WriteRecord(true, rrecord); } } }
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(); } }
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) { if (args.Length != 2) { Console.Error.WriteLine("Usage: CopyCards in.cbn[+in2.cbn ...] out.cbn"); return; } int retval = 0; string[] split = args[0].Split(new char[] { '+' }); using (TapeWriter w = new TapeWriter(args[1], true)) foreach (string rfile in split) { Console.WriteLine(rfile); using (TapeReader r = new TapeReader(rfile, true)) while ((retval = r.ReadRecord(out bool binary, out byte[] rrecord)) >= 0) { if (retval == 0) { Console.Error.WriteLine("invalid EOF"); return; } if (!binary) { Console.Error.WriteLine("not binary record"); return; } if (rrecord.Length != 160) { Console.Error.WriteLine("wrong record length"); return; } w.WriteRecord(binary, rrecord); } } Console.WriteLine(" {0} written", args[1]); }
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 != 2) { Console.Error.WriteLine("Usage RemoveTransfercard in.cbn[+in2.cbn ...] out.cbn"); return; } bool cardtypeset = false; bool tfound = false; int retval = 0; BinaryCardConverter.CardType t0 = BinaryCardConverter.CardType.Full; string[] split = args[0].Split(new char[] { '+' }); using (TapeWriter w = new TapeWriter(args[1], true)) foreach (string rfile in split) { using (TapeReader r = new TapeReader(rfile, true)) while ((retval = r.ReadRecord(out bool binary, out byte[] rrecord)) >= 0) { if (retval == 0) { Console.Error.WriteLine("invalid EOF"); return; } if (!binary) { Console.Error.WriteLine("not binary"); return; } if (rrecord.Length != 160) { Console.Error.WriteLine("Wrong record length"); return; } CBNConverter.FromCBN(rrecord, out Card crd); BinaryCardConverter.CardType t = BinaryCardConverter.GetCardType(crd); if (tfound) { Console.Error.WriteLine("Transfercard not at end"); return; } switch (t) { case BinaryCardConverter.CardType.Full: case BinaryCardConverter.CardType.Abs: case BinaryCardConverter.CardType.Rel: if (cardtypeset && t0 != t) { Console.Error.WriteLine("Card type change"); return; } w.WriteRecord(binary, rrecord); break; case BinaryCardConverter.CardType.Transfer: if (cardtypeset && t0 != BinaryCardConverter.CardType.Abs) { Console.Error.WriteLine("Card type change"); return; } Console.WriteLine("transfercard removed"); tfound = true; break; case BinaryCardConverter.CardType.RelTransfer: if (cardtypeset && t0 != BinaryCardConverter.CardType.Rel) { Console.Error.WriteLine("Card type change"); return; } Console.WriteLine("Rel transfercard removed"); tfound = true; break; default: Console.Error.WriteLine("wrong Card type"); return; } if (!cardtypeset) { t0 = t; cardtypeset = true; } } } }
static void Main(string[] args) { string[] loc1 = new string[] { "9L", "9R", "8L", "8R", "7L", "7R", "6L", "6R", "5L", "5R", "4L", "4R", "3L", "3R", "2L", "2R", "1L", "1R", "0L", "0R", "11L", "11R", "12L", "12R" }; string[] loc2 = new string[] { "", "A", "T", "D", "P", "M", "S" }; int[] startbit = new int[] { 0, 0, 15, 18, 33, 0, 35 }; int[] bitlen = new[] { 36, 15, 3, 15, 3, 35, 1 }; if (args.Length != 3 && args.Length != 2) { Console.Error.WriteLine("Usage PatchCard location=value,... in.cbn [out.cbn]"); Console.Error.Write("location is x or xy, where x=9L,9R ... 0L,0R, ... 12L,12R"); Console.Error.WriteLine(" and y=A,T,D,P,M,S,1,2,...,36"); Console.Error.WriteLine("value is octal number"); return; } byte[] wrecord; using (TapeReader r = new TapeReader(args[1], true)) { if (r.ReadRecord(out bool binary, out byte[] rrecord) != 1 || !binary) { Console.Error.WriteLine("invalid input file"); return; } if (r.ReadRecord(out bool b2, out byte[] m2) != -1) { Console.Error.WriteLine("not a single card file"); return; } CBNConverter.FromCBN(rrecord, out Card C); bool cs = BinaryCardConverter.VerifyChecksum(C); string[] lis1 = args[0].Split(new char[] { ',' }); foreach (string a0 in lis1) { string[] lis = a0.Split(new char[] { '=' }); if (lis.Length != 2) { Console.Error.WriteLine("= missing"); return; } string loc = lis[0].ToUpper(); int pos = -1; for (int i = 0; i < loc1.Length; i++) { if (loc.Length >= loc1[i].Length && loc.StartsWith(loc1[i])) { pos = i; break; } } if (pos == -1) { Console.Error.WriteLine("wrong location"); return; } loc = loc.Substring(loc1[pos].Length); int type = -1; int bpos = 0; int blen = 0; if (loc.Length > 0) { for (int i = 0; i < loc2.Length; i++) { if (loc == loc2[i]) { type = i; bpos = startbit[i]; blen = bitlen[i]; break; } } if (type == -1) { if (!int.TryParse(loc, out int result) || result < 1 || result > 36) { Console.Error.WriteLine("wrong location"); return; } bpos = 36 - result; blen = 1; } } long value = Convert.ToInt64(lis[1], 8); ulong imask = ((1ul << 36) - 1ul) - (((1ul << blen) - 1ul) << bpos); if (value < 0 || value >= (1 << blen)) { Console.Error.WriteLine("wrong value"); return; } ulong uvalue = (ulong)value << bpos; ulong oldvalue = C.C[pos].LW; C.C[pos].LW = ((C.C[pos].LW & imask) | uvalue); ulong newvalue = C.C[pos].LW; Console.WriteLine("{0} updated from {1} to {2}", loc1[pos], Convert.ToString((long)oldvalue, 8).PadLeft(12, '0'), Convert.ToString((long)newvalue, 8).PadLeft(12, '0')); } if (cs) { BinaryCardConverter.UpdateChecksum(C); Console.WriteLine("Checksum updated"); } wrecord = CBNConverter.ToCBN(C); Array.Copy(rrecord, 72 * 2, wrecord, 72 * 2, 8 * 2); } using (TapeWriter w = new TapeWriter(args[args.Length - 1], true)) w.WriteRecord(true, wrecord); }
public void END(int?TransferAdr) { char tch = ' '; if (TransferAdr != null && dr == null) { deck = new List <Card>(); dr = new DeckReader(tr, deck); if (hadnoorg) { startline = thisline; startpage = thispage; } } if (dr != null) { if (dr.Cardtype() == 'R') { TransferAdr = 0; } if ((TransferAdr != null && (!hadnoorg || TransferAdr != 0))) { if (dr.Read(out int adr, out long value)) { Console.WriteLine("Difference {0} {1}", thispage, thisline); Console.WriteLine("Card {0} {1}", Convert.ToString(adr, 8).PadLeft(5, '0'), Convert.ToString(value, 8).PadLeft(12, '0')); Console.WriteLine("List Transfer {0}", Convert.ToString((int)TransferAdr, 8).PadLeft(5, '0')); Environment.Exit(-1); } else if (adr != TransferAdr) { Console.WriteLine("Difference {0} {1}", thispage, thisline); Console.WriteLine("Card Transfer {0}", Convert.ToString(adr, 8).PadLeft(5, '0')); Console.WriteLine("List Transfer {0}", Convert.ToString((int)TransferAdr, 8).PadLeft(5, '0')); Environment.Exit(-1); } if (dr.Cardtype() != 'T') { tch = 'T'; } } if (!dr.CardEmpty()) { Console.WriteLine("Difference {0} {1}", thispage, thisline); Console.WriteLine("more data on card"); Environment.Exit(-1); } string x = ""; if (startpage != 0) { x += string.Format("Page{0}", startpage); } x += string.Format("Line{0}", startline); x += "_"; x += dr.Cardtype(); if (tch != ' ') { x += tch; } Console.Write("{0}:{1} {2} {3} {4}\n", x, deck.Count, Convert.ToString(FirstAdr, 8).PadLeft(5, '0'), Convert.ToString(LastAdr, 8).PadLeft(5, '0'), TransferAdr != null ? Convert.ToString((int)TransferAdr, 8).PadLeft(5, '0') : ""); using (TapeWriter tw = new TapeWriter(out_p + x + ".cbn", true)) foreach (Card crd in deck) { tw.WriteRecord(true, CBNConverter.ToCBN(crd)); } deck.Clear(); dr = null; } curadr = 0; bssflag = false; hadnoorg = true; FirstAdr = 1000000; LastAdr = -1000000; }