Print Big Characters using Windows Batch Programming


Windows Batch Programming has been in existent for decades, ever since the first MS-DOS. The file extension that ends with *.bat will be interpreted by the DOS line by line. Inbuilt statements such as echo, for, if together with external utilites such as grep, find have made the batch programming powerful and enjoyable. From Windows XP and after, the *.cmd file extension is also used to indicate that it is a batch script, which is to be executed by the command shell.

The following will show a fun utility that is written in batch script, and this script can print large letters. The usage is pretty simple from the command line, which takes parameters as the given input text.

batprint Print Big Characters using Windows Batch Programming algorithms batch script beginner games images drawing profiler software design string technical tools / utilities windows command shell

The following are the essentials for this utility.

First of all, you have to define the ‘graphic representations’ for each alphabetic letters and digits, to make it simple, only upper case letters and digits from 0 to 9 are considered. Also, some commonly-used symbols such as periods, semi-colons are supported. It is an disadvantage that the print function in batch script i.e. echo statement, only prints seqential characters. Therefore, it is not possible to print each large letter one by one (i.e. vertically). However, this can be solved by storing lines by lines of black-square representation of the current single line of the big letters. After the end of line is reached (maximum 8 letters for example), the line of big letters are output line by line using black squares (ASCII 219).

print Print Big Characters using Windows Batch Programming algorithms batch script beginner games images drawing profiler software design string technical tools / utilities windows command shell

The above image shows the definitions for letters ‘F’ and ‘G’. Each character is defined as 7 separate lines and 6 columns (two-dimensional array). The rest is simple: parsing the given text character by character and concat these 7 line variables. Output these 7 variables (as a single line of big text) at the end of each line. The source code of this batch file can be found at [github] and the main processing code excluding the character definitions using black squares can be found below.

@echo off
:: https://helloacm.com
:: 12-Sept-2012

setlocal enableextensions enabledelayedexpansion 

if [%1] neq [] goto start
echo %0 text

goto :eof

	:start
		set _len=0
		set _str=%*

		:: Get the length of the sentence
		set _subs=%_str%

	:loop
		if not defined _subs goto :result

		::remove the first char
		set _subs=%_subs:~1%
		set /a _len+=1
		goto loop	
      
	:result
		set /a _len-=1

		::for /f "tokens=2" %%g in ('mode ^|find "Columns"') do set/a _window=%%g/6
		set _window=8

		:: clear
		(set _1=)
		(set _2=)
		(set _3=)
		(set _4=)
		(set _5=)
		(set _6=)
		(set _7=)

		:: digit by digit
		for /l %%g in (0,1,%_len%) do (
			set /a i=%%g%%%_window%
			if !i! equ 0 (
				:: new line
				if "!_1!" neq "" (
					echo !_1!
					echo !_2!
					echo !_3!
					echo !_4!
					echo !_5!
					echo !_6!
					echo !_7!
					(echo.)
				)
				(set _1=)
				(set _2=)
				(set _3=)
				(set _4=)
				(set _5=)
				(set _6=)
				(set _7=)
			) 
			call :build %%g
		)

		if "!_1!" neq "" (
			echo !_1!
			echo !_2!
			echo !_3!
			echo !_4!
			echo !_5!
			echo !_6!
			echo !_7!
		)
		goto :eof

	
	:build
		:: get the next character
		call set _digit=%%_str:~%1,1%%%
		
		:: Add the graphics
		if "!_digit!"==" " (
			call :s_space
		) else (
			if "!_digit!"=="," (
				call :s_c1
			) else (
				if "!_digit!"==":" (
					call :s_c2
				) else (
					if "!_digit!"=="+" (
						call :s_c3
					) else (
						if "!_digit!"=="#" (
							call :s_c4
						) else (
							call :s_!_digit!
						)
					)
				)
			)
		)

		goto :eof

:: Graphics
:: omitted due to the length, please download the rest at
:: https://github.com/DoctorLai/BatchUtils/blob/master/print.bat

At the beginning, the length of the given text is determined [see here]. The window variable _window is computed using the following.

for /f "tokens=2" %%g in ('mode ^|find "Columns"') do set/a _window=%%g/6

This is the maximum number of big letters to print for each line. mode | find “Columns” will return the number of columns (using pipe to filter the corresponding value). The width of each letter is 6 in this case, therefore the window size can be obtained by column/6.

For each character, the sub-routine build is called, in order to build the string output. At the end of each line, the buffer is flushed and a new line starts again until all characters are processed.

The improvement with the support of using pipeline is detailed in this post.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
801 words
Last Post: Get String Length using Windows Batch
Next Post: Set the Color for Console using Windows Batch

The Permanent URL is: Print Big Characters using Windows Batch Programming

Leave a Reply