After some time I finally had the time to clean up my code and to publish some of my libraries, the following are a group of essential libraries available for free, but if someone would like to say thanks with a small donation I'd be very happy, even a cup of coffee is appreciated
SOME NOTES ABOUT THE DISTRIBUTION
I've found an easy way to manage library dependancies and allow users to include them with a single change.
Along with the libraries there is a master include called +Includes.hws, this file defines some constants that you will use to include all the other needed libraries, changing the line 6 of the +Includes.hws file will let you set the position of your libraries folder and allow you to include libraries using the defined constants, here is an example.
Suppose your library folder is here : C:/development/libraries/
You have to place all your libraries inside this folder, including +Includes.hws
Now you have to edit +Includes.hws and change the line 6 with the location where you libraries are stored:
Code: Select all
Const #INC_PATH = "C:/development/libraries/"Now, when you need to include libraries you have to include the master include file and all stuff you need as follow:
Code: Select all
@INCLUDE "C:/development/libraries/+Includes.hws"
@INCLUDE #INC_DEBUG
@INCLUDE #INC_HELPERS
...
THE PACKAGE
The package is available as a zip file HERE
LIBRARIES INCLUDED IN THE PACKAGE
- Helpers
- Debug
- Tables
- FileSystem
- Easing
- EXAMPLES [list]
- Debug library : 2 examples
- Easing library : 1 example
- Helpers library : 9 examples
- Tables library : 18 examples
HELPERS Library
Code: Select all
LIBRARY NAME : HELPERS
SOURCE FILE : Helpers.hws
AUTHOR : Fabio Falcucci
LICENSE : FREEWARE
RELEASE : 26/11/2014
VERSION : 1.3
DOCUMENTATION: Embedded in the source code
ROOT TABLE : HL
DEPENDANCIES : -
DESCRIPTION
The helpers library is a collection of function to speed up common tasks.
CONTENTS
GENERIC FUNCTIONS
HL.CutStringLeft(text, maxLen)
| Cut the given string to the left if the string length is greater the
| <maxLen> and prefix the string with the triple point (...) to
| indicate that the string has been shortened.
HL.CutStringRight(text, maxLen)
| Cut the given string to the right if the string length is greater the
| <maxLen> and add the triple point (...) suffix to indicate that the
| string has been shortened.
HL.GetRndName()
| Use this function to obtain a unique random name anytime you need it
HL.IsNil(<value>)
| Check <value> and returns TRUE if it is NIL, otherwise returns FALSE
HL.IsNotNil(<value>)
| Check <value> and returns FALSE if it is NIL, otherwise returns TRUE
HL.ParseArgs(<caseSensitive>)
| Parse command line arguments and return a table indexed with the
| argument token and with the value sets with the argument's parameter.
| The switch <caseSensitive> defaults to TRUE, set it to FALSE to parse
| arguments and parameters without case distinctions.
HL.Safe(<value>)
| Returns the string 'NIL' if <value> is NIL, otherwise returns <value>
| without any changes.
| This function is usefull to concatenate strings without worring about
| errors caused by concatenating uninitialized variables.
HL.SizeString(txt, size)
| This function is usefull to process strings and to produce easily
| aligned text columns, the string <txt> will be processed and adapted
| to <size> length by adding spaces or by removing exceeding characters
| and adding '...' to the end to indicate that the string is not
| finished.
HL.Value2Perc(range, value)
| Convert the given <value> to a percentual value, the percentual will
| be calculated using the table <range> that must have the following
| fields:
| [0] Minimum value in the range
| [1] Maximum value in the range
| If <value> is out of the range it will get Minimum or Maximum
| depending on the boundary it exceeds.
HL.WaitForAction(key, delay, callback, timeout, to_callback, userData)
| This function is used to wait for an user action, the action can be a
| key press defined by <key> or for the left mouse button press. It's
| possible to define a timeout to let the program continue without user
| action. This routine provides callback functions to run an animation
| during the wait or to call a specific function if the timeout occurs.
CONVERSION FUNCTIONS
HL.Convert.BytesTo(<bytes>, <target>, <decimals>)
| Convertes the bytes specified in <bytes> into the <target> unit, the
| result will have <decimals> decimal positions.
HL.Convert.HTML2Hollywood(text)
| Convert the given HTML <text> into a text formatted with Hollywood
| tags.
HL.Convert.HTMLAmper2UTF8(html_amper)
| Convert the given <html_amper> into an UTF8 encoded string
HL.Convert.HTMLTag2HollywoodTag(html_tag)
| Convert the given <html_tag> into stardard text Hollywood's tags
HL.Convert.Unicode2UTF8(value)
| Encode <value>, an hexadecimal string without any prefixes ($, 0x),
| to the corresponding UTF8 string.
BUFFERED STRINGS CLASS
String concatenation in Hollywood is somewhat slow so I've implemented
this class for speed up concatenation where there is the need to
concatenate character by character, for example while decoding or encoding
data.
This trick speed up a lot this operation, in my tests I was able to process
strings with single character concatenation at around 18 Kb/s, using this
system I was able to reach 680 Kb/s.
----------------------------------------------------------------------------
BSObject = HL.BufferedString:New()
| Create a new buffered string object.
BSObject:AddChar(<char>)
| Add the character <char> to the buffered string object.
BSObject:Get()
| Returns the current contents of the buffered string object.
Code: Select all
LIBRARY NAME : EASING
SOURCE FILE : Easing.hws
AUTHOR : Fabio Falcucci
LICENSE : FREEWARE
RELEASE : 26/03/2014
VERSION : 1.0
DOCUMENTATION: Embedded in the source code
ROOT TABLE : tween
DEPENDANCIES : -
DESCRIPTION
The easing library can be used to achieve smooth transitions between values,
with it you can animate objects, fade colors and change values smoothly using
one of the provided 41 transition functions.
CONTENTS
TWEEN FUNCTIONS
tween.start(time, subject, target, easing, callback, ...)
| Start a new tween and returns its id.
tween.reset(tweenId)
| Reset, and stop, the given tween.
tween.resetAll()
| Reset, and stop, all tweens.
tween.update(dt)
| Update all running tweens evaluating the given <dt> delta time.
tween.stop(id)
| Stops the given tween.
tween.stopAll()
| Stops all running tweens
Code: Select all
LIBRARY NAME : TABLES
SOURCE FILE : Tables.hws
AUTHOR : Fabio Falcucci
LICENSE : FREEWARE
RELEASE : 27/03/2014
VERSION : 1.1
DOCUMENTATION: Embedded in the source code
ROOT TABLE : TB
DEPENDANCIES : TABLES, EASING
DESCRIPTION
This library exposes common functions to manipulate and convert tables.
CONTENTS
GENERIC FUNCTIONS
TB.Compare(table1, table2, compare_funcs)
| Compare <table1> and <table2> and returns TRUE if they are equal.
| Set <compare_funcs> to TRUE if you want to compare function entries too.
| The comparisons are fully recursive.
TB.CompareScore(table1, table2, compare_funcs, count, equals)
| Compare <table1> and <table2> and returns a score. Set <compare_funcs>
| to TRUE if you want to compare function entries too. The comparisons are
| recursive.
TB.Copy(source, skipFunc)
| Use this function to copy tables recursively, you can skip functions
| setting <skipFunc> to TRUE.
TB.Count(table)
| Return how many entries are stored in 'table'. This function is able
| to count any type of table with any type of index.
TB.Fill(Source, StartIndex, EndIndex, Value)
| Simple function to fill/initialize a table range with a value.
TB.Interpolate(Source, StartIndex, EndIndex, StartValue, EndValue, mode)
| This function is used to fill the table <source> with values. The index
| range is delimited by <startIndex> and <endIndex>, the values range is
| delimited by <startValue> and <endValue>. <mode> defines the
| interpolation mode, for all supported modes have a look at the Easing
| library.
TB.Merge(table1, table2, overwrite)
| Adds all <table2> items to <table1>, note that <table1> will be directly
| modified. <overwrite> is used to specify if any existing <table1> items
| should be overwritten by <table2> items.
TB.PushUp(table, pos)
| Move the item at position <pos> from its current position to position
| 0 (to the top) and move all the rest down by one position.
TB.ReplaceChars(table, chars, replacer, recursive)
| Scans <table> for each string entry and replaces any occurrencies of
| <chars> with the string <replacer>. Set <recursive> to TRUE if you want
| to scan <table> recusively.
TB.Set(Source, Changes, ReturnsNew)
| Sets all fields found in the table <source> with the corrisponding
| fields in the table <changes>, returns a new modified table if
| <ReturnsNew> has been set to TRUE otherwise modify <source> directly.
| The process is recursive.
TB.ShiftDown(table)
| Shifts all 'table' items down by one position, the last item will be
| placed at the first position.
TB.ShiftUp(table)
| Shifts all <table> items up by one position, the first item will be
| placed at the last position.
TB.Sort(table, descending, column, associated)
| Sort the given <table> basing the sorting on <column>. <table> must be
| composed by subtables, like records, and indexed with numeric values.
| <table> will be directly modified.
| You can set sorting order setting <descending> to TRUE or FALSE, <column>
| can be a field name or a table width field names we want to use to sort
| <table>.
TB.TrimSpaces(table, recursive)
| Remove from any string entries in the given <table> any trailing or
| leading spaces. The source <table> will be directly modified.
TABLE INSPECTION FUNCTIONS
TB.Item.Compare(record1, record2, greater, columns)
| This routine is used to compare two records (tables). The comparison is
| based on one or more fields (indexes), this fields must be specified in
| the <columns> table. <greater> is a table with booleans and specify what
| kind of comparison must be performed: if TRUE means that the following
| check will be made:
| record1.field is greater then record2.field ?
| This routine supports multilevel comparisons, just supply the field names
| in the <columns> table and in the right order.
TB.Item.Exists(table, index)
| Returns TRUE if <index> is not NIL within <table> otherwise returns
| FALSE.
| This function is usefull to test if there are defined items within
| tables.
TB.Item.IsNil(table, index)
| Returns TRUE if <index> doesn't exists in <table> otherwise returns
| FALSE.
| This function is usefull to test if there are undefined items within
| tables.
TB.Item.Find(table, value, caseSensitive)
| Search in <table> an item with the value equal to <value>. The search
| will be performed only in the first table level (subtables will not be
| scanned). <value> can be of any type.
TABLE CONVERTION FUNCTIONS
TB.Convert.String2Table(string, separator)
| Converts the given <string> into a table splitting its items using the
| provided <separator> as delimiter between each item. Returns the
| resulting table.
| Leading spaces will be trimmed out from the resulting items.
TB.Convert.Table2String(table, separator)
| Converts all <table> items into a string using <separator> as delimiter
| between each item. Returns the resulting string.
Code: Select all
LIBRARY NAME : DEBUG
SOURCE FILE : Debug.hws
AUTHOR : Fabio Falcucci
LICENSE : FREEWARE
RELEASE : 23/11/2014
VERSION : 1.1
DOCUMENTATION: Embedded in the source code
ROOT TABLE : DBG
DEPENDANCIES : TABLES, HELPERS
DESCRIPTION
With this library you can easily manage debug output to the console or to a
log file. The console log system allow you to define channels and message
types you can easily filter during the debug of your programs.
CONTENTS
GENERIC FUNCTIONS
DBG.DumpTable(table, mode, sorted, ident, check, rec_count, channel, ccheck)
| Dump the <table> contents according to the <mode> specified, <ident> is
| a private variable used in recursive dumping and should not be used
| directly.
CONSOLE LOGS
DBG.Console.AddChannel(ChannelName)
| Defines a new console debug channel named <ChannelName>.
DBG.Console.Disable()
| Disable the debug output to the console.
DBG.Console.Enable(timing)
| Enable the debug output to the console. If <timing> is set to TRUE a
| timestamp will be added to the beggining of the data we are logging,
| defaults to FALSE.
DBG.Console.Out(Message, Mode, Channel)
| If the console debug has been activated with <DBG.Console.Enable> the
| <message> will be printed to the console. <message> can be of any type
| also tables are supported.
DBG.Console.SkipNormalLevel(value)
| Switch the normal-level-messages logging. Set <value> to TRUE to skip
| skip normal-level-messages, otherwise set it to FALSE (default).
DBG.Console.RemoveChannel(ChannelName)
| Remove an existing console debug channel named <ChannelName>.
FILE LOGS
DBG.Log.Enable(LogFile, Preserve, Timings)
| Enable the debug output messages to a log file named <LogFile>.
DBG.Log.Disable()
| Disable the debug output to the file.
DBG.Log.Out(Message, Mode)
| If the debug output has been activated with <DBG.Log.Enable> then the
| <message> will be written to the log file.
PRIVATE FUNCTIONS
DBG.DTS(tbl, outfunc)
| Support function used by DBG.DumpTable() to print sorted tables.
FILESYSTEM Library
Code: Select all
LIBRARY NAME : FILESYSTEM
SOURCE FILE : FileSystem.hws
AUTHOR : Fabio Falcucci
LICENSE : FREEWARE
RELEASE : 27/03/2014
VERSION : 1.2
DOCUMENTATION: Embedded in the source code
ROOT TABLE : FS
DEPENDANCIES : TABLES, HELPERS, DEBUG
DESCRIPTION
This library exposes common functions to manipulate file and check the file
system.
CONTENTS
GENERIC FUNCTIONS
FS.Config.Load(<filename>, <header>, <updFunc>, <fileID>, <recursive>)
| Read a configuration file and return its contents into a table or
| returns NIL if an error has been encontered.
| This is an handy and structured way to store configuration files or any
| type of data you wish to save, this data will be loaded back and
| returned into a single table.
FS.CutLastFolder(<folder>)
| Divide the given <folder> and returns two strings, the second one is the
| last folder in the path, the first one is all the rest.
| The 'cut' is sensible to the "/", "\" and ":" path dividers. This
| function is usefull to process paths and, for example, to retrieve the
| upper level of a given <folder>.
FS.Execute_Script(<scriptFile>)
| Silently execute the given <scriptFile>.
| ONLY FOR AROS and AMIGAOS4
FS.Execute_Script(<scriptFile>)
| Silently execute asynchronously the given <scriptFile>.
FS.Volumes.IsAvailable(<volumeName>)
| Returns TRUE if <volumeName> is available in the current system.
| ONLY FOR AMIGA-Like Systems
FS.Volumes.Monitor_Start(<callback>, <scandelayms>)
| Initialize a volume monitor that will execute the <callback> function
| everytime the volume list changes. The volume check will be executed
| every <scanDelayMS> milliseconds.
| ONLY FOR AMIGA-Like Systems
FS.Volumes.Monitor_Check()
| Interval routine called every time the volume list must be checked. If
| the volume list is changed the function (stored in
| FS.Volumes.Monitor_Callback) will be called with the updated device
| list.
| ONLY FOR AMIGA-Like Systems
FS.Volumes.Monitor_Stop()
| Stops the volume detection system.
| ONLY FOR AMIGA-Like Systems
FS.Volumes.GetPart(<fullpath>)
| Returns the volume part of the <fullpath> file.
FILE RELATED FUNCTIONS
FS.Files.ChangeExistingName(<filename>, <filePath>)
| This routine is usefull to retrieve alternative filenames to do not
| overwrite existing ones. This is particularly handy when you have to
| write several version of the same file using only one filename in your
| main code. This routine will find for you alternative names adding to
| the file name a number enclosed by round brackets.
FS.Files.CheckLastChar(<filename>, <ascvalue>)
| Read the last character of <filename> and returns TRUE if it's equal to
| the <ascvalue> specified.
FS.Files.GetLastLine(<filename>)
| Read the last line of <filename> and returns it as result.
FS.Files.Find(<startingDir>, <pattern>, <recursive>, <dirProgressFunc>,
| <fileProgressFunc>, <foundProgressFunc>, <breakKey>,
| <userData>, <results>)
| Search and returns any file that matches the specified <pattern>.
FS.Files.FindByCRC32(<startingDir>, <crc>, <recursive>, <dirProgressFunc>,
| <fileProgressFunc>, <foundProgressFunc>, <breakKey>,
| <userData>, <results>)
| Search and returns any file that matches the specified <crc>.
FS.Files.GetExtention(Filename)
| Returns the <filename> extention or NIL if extention is not available.
FS.Files.IsAvailable(<fileName>, <useCache>)
| Returns TRUE if the <fileName> specified exists in the current system.
| If <fileName> was not found in the cache then it will be searched in
| the file system.
| Setting <useCache> to TRUE will force the file search on the cache
| system toimprove response speed.
| ONLY FOR AMIGA-Like Systems
FS.Files.Open
| Safely opens file function without the risk to break the code. If there
| is a file error during the opening, instead of crashing the program with
| this functions you will get a result with error informations.
FS.Files.ReadTable(handler)
| You can use this function to safely read a table from an opened file.
| If there is an error while reading the table the program will not crash,
| instead you will get informations about the error.
FS.Files.WriteTable(handler, tbl)
| You can use this function to safely write a table from an opened file.
| If there is an error while reading the table the program will not crash,
| instead you will get informations about the error.
FS.Files.RemoveExtention(<filename>)
| Returns the given <filename> without its file-extension, if any,
| additionally returns the removed extention.
FS.Files.Validate(<prefix>, <filename>, <searchPaths>)
| Validate the string <filename> checking if the filename exists or not.
| <Prefix> can be a token that prefixes the filename, for example, suppose
| you have a field that can be a string or a filename, in the last case
| the string could be prefixed by 'file::' the remaining part is the
| filename.
| <SearchPaths> is a table of strings with valid paths where the filename
| will be searched.
| If at least one entry is found the function returns TRUE.
| If <SearchPaths> is Nil or empty the search will be performed in the
| current directory.
FS.ParseFilename(<filename>)
| This function parses the given <filename> and replaces special
| placeholder with the corresponding values.
| Actually the supported placeholders are:
| $APPPATH Running executable's path
| $CURRPATH Working executable's path
FS.TxtFile.InsertBefore(<filename>, <marker>, <newline>, <allowMultiple>,
| <caseSensitive>, <makeBackup>)
| Read the text file <filename> and look for a row equal to <marker>, then
| the routine will insert, just before the detected row, the <newLine> row
| or rows if <newLine> is a table.
| <allowMultiple> specify if <newLine> can be inserted only in the first
| occurance or on all occurrencies of <marker>.
| <makeBackup> specify in <filename> we are going to modify must be backed
| up or not.
CACHE SYSTEM
FS.Files.ClearCache()
| Clear all cached files.
| ONLY FOR AMIGA-Like Systems
FS.Volumes.ClearCache()
| Clears the cached volumes.
| ONLY FOR AMIGA-Like Systems
FS.Volumes.Get(<useCache>)
| Returns the available volumes list detected in the current system.
| Setting <useCache> to TRUE means that the volume list will be taken
| from the cache otherwise the system will be scanned for available
| devices, updating the cache if needed.
| ONLY FOR AMIGA-Like Systems
PRIVATE FUNCTIONS
FS.Private.ParseSpecial(<dataPair>)
| Private routine used to parse special tags of FS.Config.Load()
I will try to keep updated this thread with future updates, have fun!