VerticalMirroring, HorizontalMirroring

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 630
Joined: 28 Jun 2010 03:46

VerticalMirroring, HorizontalMirroring

#1 Post by miskox » 13 Jan 2016 13:01

I have a .txt file with this ASCII graphics:

Code: Select all

+----+-----+--+---+
|    |     |==|   |
|    |   22|==|   |
|  +-+--- -+==|   |
|23  |||       21 |
+--+          |   |
|24           |   |
|  +-+--- -+==|   |
|    |   25|==|   |
|    |     |==|   |
+----+-----+--+---+


And I have this program VMirroring.cmd (V stands for Vertical):

Code: Select all

@echo off
if "%1"=="" echo %0 input_file output_file&goto :EOF

set outfil=%2
if not exist %1 echo Input file does not exist.&goto :EOF
break>%outfil%

for /f "tokens=1 delims=" %%f in (%1) do call :DOSOMEWORK "%%f"
goto :EOF

:DOSOMEWORK
set par1=%~1

set strng=&rem
set /a cnt=0

:LOOP
call set strngtmp=%%par1:~%cnt%,1%%

if "%strngtmp%"=="" echo %strng% >>%outfil%&goto :EOF
set strng=%strngtmp%%strng%

set /a cnt+=1
goto :LOOP


Output file should be mirrored:

Code: Select all

+---+--+-----+----+ 
|   |==|     |    |
|   |==|22   |    |
|   |==+- ---+-+  |
| 12       |||  32|
|   |          +--+
|   |           42|
|   |==+- ---+-+  |
|   |==|52   |    |
|   |==|     |    |
+---+--+-----+----+


I receive this error:

Code: Select all

| was unexpected at this time.


Currently I replace '|' with 'x' and then execute the .cmd.

Help!

Next program will be HMirroring.cmd.

Thanks.
Saso

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: VerticalMirroring, HorizontalMirroring

#2 Post by Aacini » 13 Jan 2016 14:51

Code: Select all

@echo off
setlocal EnableDelayedExpansion

if "%~2" equ "" echo %0 input_file output_file [/V]& goto :EOF

if not exist %1 echo Input file does not exist.& goto :EOF

(
   if /I "%3" neq "/V" (

      rem Horizontal mirroring
      for /F "delims=" %%a in (%1) do (
         set "output="
         for /F "delims=" %%b in ('cmd /U /C echo "%%a"^| find /V ""') do (
            set "output=%%b!output!"
         )
         echo !output:~1,-1!
      )

   ) else (

      rem Vertical mirroring
      set "i=100000000"
      for /F "delims=" %%a in (%1) do (
         set /A i-=1
         set "line[!i!]=%%a"
      )
      for /F "tokens=1* delims==" %%a in ('set line[') do (
         set "output=%%b"
         echo !output!
      )

   )

) > %2


Antonio

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: VerticalMirroring, HorizontalMirroring

#3 Post by Squashman » 13 Jan 2016 14:55

I want to see it vertically flipped with the numbers upside down. :twisted:

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: VerticalMirroring, HorizontalMirroring

#4 Post by Aacini » 13 Jan 2016 19:16

Squashman wrote:I want to see it vertically flipped with the numbers upside down. :twisted:

Unfortunately, that is not possible with digits, but just with letters:

Code: Select all

@if (@CodeSection == @Batch) @then

@echo off

rem This program requires Consolas font in order to properly show the output
rem Reference: http://www.dostips.com/forum/viewtopic.php?f=3&t=6776&p=43943#p43943

CScript //nologo //E:JScript "%~F0" < input.txt
goto :EOF


@end


// JScript section

// Define the map from normal characters to upside-down ones **IN "Consolas" FONT!**

var upside = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.!?",
    down   = "\u0244\u0071\u0186\u0070\u018e\u2132\u0494\u0048\u0049\u017f\u029e\u02e5\u0057" +  // "ABCDEFGHIJKLM"
             "\u004e\u004f\u0500\u00d2\u1d1a\u0053\u2534\u041f\u039b\u004d\u0058\u019b\u005a" +  // "NOPQRSTUVWXYZ"
             "\u0250\u0071\u0254\u0070\u01dd\u025f\u1d77\u0265\u1d09\u027e\u029e\u01ae\u026f" +  // "abcdefghijklm"
             "\u0075\u006f\u0064\u0062\u0279\u0073\u0287\u006e\u028c\u028d\u0078\u028e\u007a" +  // "nopqrstuvwxyz"
             "\u2018\u0387\u00a1\u00bf";                                                         // ",.!?"

var n = 0, line = new Array();
while ( ! WScript.Stdin.AtEndOfStream ) {
   line[++n] = WScript.Stdin.ReadLine();
}
while ( n ) {
   var input = line[n--], output = "";
   for ( var i = 0; i < input.length; i++ ) {
      var pos = upside.indexOf(input.charAt(i));
      output += (pos >= 0) ? down.charAt(pos) : input.charAt(i) ;
   }
   WScript.Stdout.WriteLine(output);
}

input.txt:

Code: Select all

+----+-----+--+---+
|    |     |==|   |
|    |  One|==|   |
|  +-+--- -+==|   |
|Two |||    Three |
+--+          |   |
|Four         |   |
|  +-+--- -+==|   |
|    | Five|==|   |
|    |     |==|   |
+----+-----+--+---+

output:

Code: Select all

+----+-----+--+---+
|    |     |==|   |
|    | Ⅎᴉʌǝ|==|   |
|  +-+--- -+==|   |
|Ⅎonɹ         |   |
+--+          |   |
|┴ʍo |||    ┴ɥɹǝǝ |
|  +-+--- -+==|   |
|    |  Ouǝ|==|   |
|    |     |==|   |
+----+-----+--+---+

If we change the processing of the line to reversed order:

Code: Select all

   for ( var i = input.length-1; i >= 0; i-- ) {

... we get the output flipped both vertically and horizontally:

Code: Select all

+---+--+-----+----+
|   |==|     |    |
|   |==|ǝʌᴉℲ |    |
|   |==+- ---+-+  |
|   |         ɹnoℲ|
|   |          +--+
| ǝǝɹɥ┴    ||| oʍ┴|
|   |==+- ---+-+  |
|   |==|ǝuO  |    |
|   |==|     |    |
+---+--+-----+----+

Antonio

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: VerticalMirroring, HorizontalMirroring

#5 Post by miskox » 15 Jan 2016 14:45

Aacini thanks alot. Completely different approach. Works great!

Thanks again.
Saso

Post Reply