OSDN Git Service

Script to convert the character string declarations to the more common form.
authorJoel Matthew Rees <joel.rees@gmail.com>
Tue, 22 Jan 2019 07:28:12 +0000 (16:28 +0900)
committerJoel Matthew Rees <joel.rees@gmail.com>
Tue, 22 Jan 2019 07:28:12 +0000 (16:28 +0900)
socialize6809.pl [new file with mode: 0755]

diff --git a/socialize6809.pl b/socialize6809.pl
new file mode 100755 (executable)
index 0000000..f067e93
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+  use v5.010.000;
+  use warnings;
+  use strict;
+
+#  say "Hello World!";
+
+#  print $ARGV[ 1 ];
+
+
+while ( my $line = <> )
+{
+  if ( $line =~ m/^(\w*)\s+FCC\s+(\d+),(\S+)(.*)$/ )
+  {
+    my $label = $1;
+    my $symlength = $2;
+    my $strfield = $3;
+    my $leftovers = $4;
+    my $symbol = substr( $strfield, 0, $symlength );
+    my $strlength = length( $symbol );
+    if ( $strlength < $symlength )
+    {
+      my $difference = $symlength - $strlength;
+      $symbol .= substr( $leftovers, 0, $difference );
+      $leftovers = substr( $leftovers, $difference );
+    }
+    print "$label\tFCC\t'$symbol'\t; '$strfield'";
+    if ( $leftovers ne "" )
+    {
+      print " : $leftovers";
+    }
+    print "\n";
+  }
+  else
+  {
+    print $line;
+  }
+}
+