batchlib

Samstag, 29. März 2008

BATCHLIB_ Batchlib package v1.0

Download
Batchlib package v1.0 (5 KB zip file)

What is it?
Inspired by my library idea, I created a package containing several libraries with subroutines that I need more or less often.

What Libraries are contained?
Currently, the following libraries are contained in the package:
How to use the libraries?
Place the libraries in a subdirectory named "lib" of your batch script(s). To call the subroutine :TRIM of the string.cmd library, use the following code:
SET MY_STRING=    A string with spaces around the text   
CALL %~dps0lib\string.cmd :TRIM "%MY_STRING%"
ECHO Trimmed string is '%RESULT%'.

License
This work is licensed under the Creative Commons Attribution-Noncommercial 2.0 Germany (Namensnennung-Keine kommerzielle Nutzung 2.0 Deutschland).

History
  • v1.0 2008-03-29 First release

BATCHLIB_ Batchlib library string.cmd

The batchlib library string.cmd is part of the batchlib package. It provides the following subroutines:

:STRLEN: Returns the string length.
:SUBSTR: Extracts a substring. Works exactly the same the string substitution function %VAR:~x,y% does.
:TRIM: Trims whitespace at beginning and end of a string.
:GET_ASCII_CHARS: Returns a string containing all ASCII characters at their given offset.
:ASC2HEX: Converts the ASCII string to a space separated list of hex numbers.
:ASC2DEC: Converts an ASCII string to a space separated list of decimal numbers.
:HEX2ASC: Converts a list of hexadecimal numbers to an ASCII string.
:DEC2ASC: Converts a list of decimal numbers to an ASCII string.
:ASCII: Returns the numeric (decimal) ASCII code of the character.
:CHAR: Returns the ASCII character denoted by the decimal number.



Integer :STRLEN String
Returns the string length.
Parameters:
  1. string
Returns:
string length
Since: 1.0



String :SUBSTR String Integer Integer?
Extracts a substring. Works exactly the same the string substitution function %VAR:~x,y% does. Provides a way for dynamically extracting substrings.
Parameters:
  1. string to extract substring of
  2. x; 0 or greater: string offset, negative number: string offset from end
  3. (default -0) y; 0 or greater: number of characters to extract, negative number: string offset from end where to stop substring extraction
Returns:
substring
Since: 1.0



String :TRIM String
Trims whitespace at beginning and end of a string.
Parameters:
  1. string to trim
Returns:
trimmed string
Since: 1.0



String :GET_ASCII_CHARS
Returns a string containing all ASCII characters at their given offset. All (in batch) non-printable characters will be replaced by a space.
Returns:
all ASCII characters
Since: 1.0



String[] :ASC2HEX String Boolean? String?
Converts the ASCII string to a space separated list of hex numbers. For example "ABC" will be converted to "41 42 43".
Parameters:
  1. ASCII string
  2. (default false) use 0x prefix
  3. (default " ") separator string
Returns:
list of hex numbers
Since: 1.0



Integer[] :ASC2DEC String String?
Converts an ASCII string to a space separated list of decimal numbers. For each character in the the string it's decimal ASCII index will be used. For example the string "ABC" will be converted to "65 66 67".
Parameters:
  1. ASCII string
  2. (default " ") list item separator string
Returns:
list of decimals
Since: 1.0



String :HEX2ASC String[] String?
Converts a list of hexadecimal numbers to an ASCII string. Automatically detects if numbers are prefixed with "0x".
Parameters:
  1. hexadecimal list
  2. (default " ") list item separator
Returns:
ASCII string
Since: 1.0



String :DEC2ASC Integer[] String?
Converts a list of decimal numbers to an ASCII string.
Parameters:
  1. decimal list
  2. (default " ") list item separator string
Returns:
ASCII string
Since: 1.0



Integer :ASCII String
Returns the numeric (decimal) ASCII code of the character.
Parameters:
  1. single character
Returns:
ASCII code
Since: 1.0



String :CHAR Integer
Returns the ASCII character denoted by the decimal number. Non-printable characters will be returned as space.
Parameters:
  1. ASCII offset number of character
Returns:
ASCII character
Since: 1.0

Freitag, 28. März 2008

BATCHLIB_ Batchlib library io.cmd

The batchlib library io.cmd is part of the batchlib package. It provides the following subroutines:

:PRINT: Prints all arguments into one line without new line.
:PRINTLN: Prints all arguments into one line with delimiting new line.
:ISDIR: Tests for exisiting directory.
:CREATE_TEMPFILE: Creates an empty temporary file within the user's temp directory.


void :PRINT varargs
Prints all arguments into one line without new line.
Parameters:
  1. variable number of arguments
Since: 1.0


void :PRINTLN varargs
Prints all arguments into one line with delimiting new line.
Parameters:
  1. variable number of arguments
Since: 1.0


Boolean :ISDIR String
Tests for exisiting directory.
Parameters:
  1. path to directory or file
Returns:
"true" if input is an existing directory, otherwise "false"
Since: 1.0


String :CREATE_TEMPFILE
Creates an empty temporary file within the user's temp directory.
Returns:
full path to temp file
Since: 1.0

BATCHLIB_ Batchlib library number.cmd

The batchlib library number.cmd is part of the batchlib package. It provides the following subroutines:

:IS_NUMBER: Checks if the first parameter is a number.
:NEAREST: Returns the nearest matching number from a sorted list of numbers.
:NEAREST_LESS: Returns the nearest matching number from a sorted list of numbers that is equal or less.
:NEAREST_GREATER: Returns the nearest matching number from a sorted list of numbers that is equal or greater.
:DEC2HEX: Converts a decimal number to hex.


Boolean :IS_NUMBER String
Checks if the first parameter is a number. That is it only contains the characters 0 to 9 and additionally the minus as the first character.
Parameters:
  1. string to test for number
Returns:
"true" if string is a valid number, "false" otherwise
Since: 1.0


Integer :NEAREST Integer[] Integer
Returns the nearest matching number from a sorted list of numbers.
Parameters:
  1. list of integers sorted ascending
  2. number to match
Returns:
nearest matching number of list
Since: 1.0


Integer :NEAREST_LESS Integer[] Integer
Returns the nearest matching number from a sorted list of numbers that is equal or less. If no such number can be found, the smallest from the list will be returned.
Parameters:
  1. list of integers sorted ascending
  2. number to match
Returns:
nearest matching number of list
Since: 1.0


Integer :NEAREST_GREATER Integer[] Integer
Returns the nearest matching number from a sorted list of numbers that is equal or greater. If no such number can be found, the greatest from the list will be returned.
Parameters:
  1. list of integers sorted ascending
  2. number to match
Returns:
nearest matching number of list
Since: 1.0


String :DEC2HEX Integer
Converts a decimal number to hex. Currently only numbers 0 <= x <= 255 are supported (0x00 <= x <= 0xFF). The result will NOT be prefixed with 0x!
Parameters:
  1. decimal number 0 <= x <= 255
Returns:
hex representation of number
Since: 1.0

Reflog

Informationstechnische Howtos, Hinweise und Merkwürdiges

Batchlib v1.0 2008-03-29

Aktuelle Beiträge

HOWTO_ O2 DSL Surf &...
Der O2 DSL Surf & Phone-Router ist für die alleinige...
cypressor - 12. Feb, 19:57
Uptweak Windows XP Home...
There are a lot of annoying limitations in Windows...
cypressor - 9. Okt, 19:30
BATCHLIB_ Batchlib package...
Download Batchlib package v1.0 (5 KB zip file) What...
cypressor - 29. Mär, 19:10
BATCHLIB_ Batchlib library...
The batchlib library string.cmd is part of the batchlib...
cypressor - 29. Mär, 18:10

Homepage Ticker

Links

Status

Online seit 6784 Tagen
Zuletzt aktualisiert: 28. Jun, 11:32
RSS XML 1.0 Button-Get-Firefox

batch
batchlib
howto
tech
video
Profil
Abmelden
Weblog abonnieren