diff --git a/.gitignore b/.gitignore index 39497a3..7dd746d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -# Put ignorables here \ No newline at end of file +# Put ignorables here +sandbox/ \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index a9cd094..37f2a32 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,7 +4,9 @@ This is an attempt of *OOP* using `.bat` and `.ini` files. ## Functionality -None. +`.ini` file reading (`src\iniread.bat [file name] [key name] [output value]`) + +See `src\test.bat` for new functionality. ## Notes diff --git a/demo/HelloWorld/todo.md b/demo/HelloWorld/todo.md new file mode 100644 index 0000000..9169de8 --- /dev/null +++ b/demo/HelloWorld/todo.md @@ -0,0 +1 @@ +this is a placeholder for a hello world project using this framework \ No newline at end of file diff --git a/doc/files.md b/doc/files.md new file mode 100644 index 0000000..ed7f47f --- /dev/null +++ b/doc/files.md @@ -0,0 +1,29 @@ +# File type info + +Proposed file types (ideas): +* General: + * `.list` - a list of strings + * a list of strings placed in separate lines + * doesn't count empty lines + * gotta think about comments within + * maybe the standard `//`? + * maybe `;`, etc at the beginning of line? + * `.map` - a map of key-value pairs + * primarily for saving values of actual objects' parameters + * can be used for other purposes as well + * `.class` - a class file + * parent object reference + * references to `.list` + * primitive variables list + * object reference list + * references to maps (see below) + * for constants + * for static variables + * for methods +* For handling objects: + * a folder for keeping static class definitions + * a folder for keeping object instances + * a ledger for keeping track of object instances + * and maybe relations? +* For future reference: + * `.vob` - visual object-batch \ No newline at end of file diff --git a/src/placeholder b/src/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/test/iniReadWriteTest/.gitignore b/test/iniReadWriteTest/.gitignore new file mode 100644 index 0000000..d1cf45c --- /dev/null +++ b/test/iniReadWriteTest/.gitignore @@ -0,0 +1 @@ +test.ini \ No newline at end of file diff --git a/test/iniReadWriteTest/ReadMe.md b/test/iniReadWriteTest/ReadMe.md new file mode 100644 index 0000000..1a4ebd6 --- /dev/null +++ b/test/iniReadWriteTest/ReadMe.md @@ -0,0 +1 @@ +Run `test.bat` by double-clicking on it and follow instructions. \ No newline at end of file diff --git a/test/iniReadWriteTest/footer.bat b/test/iniReadWriteTest/footer.bat new file mode 100644 index 0000000..f3d76bf --- /dev/null +++ b/test/iniReadWriteTest/footer.bat @@ -0,0 +1,5 @@ +echo. +echo Done. +echo. +pause +goto :eof \ No newline at end of file diff --git a/test/iniReadWriteTest/test.bat b/test/iniReadWriteTest/test.bat new file mode 100644 index 0000000..71d6eaa --- /dev/null +++ b/test/iniReadWriteTest/test.bat @@ -0,0 +1,135 @@ +REM Order of this test: +REM 1. Initialize. +REM 2. Write to .ini. +REM 3. Read from .ini. +REM 4. Compare written and read values. + +REM Initialize variables. +:initialize +@echo off +call :set_dirs +call :set_fileNames +call :set_vars +goto start + + +REM Sets paths for the directories used. +REM call :set_dirs +:set_dirs +set rootDir=..\.. +set toolsDir=tools +goto :eof + + +REM Sets names for the files used. +REM call :set_fileNames +:set_fileNames +set iniName=test.ini +goto :eof + + +REM Sets variables for reading and writing. +REM call :set_vars +:set_vars +set key1=myKey1 +set key2=myKey2 +set writeValue1=myValue1 +set writeValue2=myValue2 +set readValue1= +set readValue2= +goto :eof + + +REM Script is supposed to start here. +REM Go here when initialization has completed. +:start +cls +echo Testing reading and writing of .ini files. +echo Are you ready? +echo. +pause +call :write +call :read +call :compare +goto end + + +REM Write to .ini. +REM call :write +:write +cls +echo Writing to ini. +echo. +call %rootDir%\%toolsDir%\iniNew.bat %iniName% +call :write_single %key1% %writeValue1% +call :write_single %key2% %writeValue2% +call footer.bat +goto :eof + + +REM Writes a single key-value pair to .ini. +REM call :write_single [key] [value] +:write_single +set key=%~1 +set value=%~2 +echo Writing "%key%=%value%" to %iniName% +call %rootDir%\%toolsDir%\iniAdd.bat %iniName% %key% %value% +goto :eof + + +REM Read from .ini. +REM call :read +:read +cls +echo Reading from %iniName% +echo. +call :read_single %key1% readValue1 +call :read_single %key2% readValue2 +call footer.bat +goto :eof + + +REM Reads a single line from .ini. +REM call :read_single [key] [read value output] +:read_single +set keyName=%~1 +echo Looking for %keyName% +call %rootDir%\%toolsDir%\iniRead.bat %iniName% %keyName% readValue +echo Read value: %readValue% +set %~2=%readValue% +goto :eof + + +REM Compare written and read values. +REM call :compare +:compare +cls +echo Comparing values. +echo. +call :compare_single %writeValue1% %readValue1% +call :compare_single %writeValue2% %readValue2% +call footer.bat +goto :eof + + +REM Compare a single pair of written-read values. +REM call :compare_single [written value] [read value] +:compare_single +set writeValue=%~1 +set readValue=%~2 +echo Written: %writeValue%, read: %readValue% +if %readValue%==%writeValue% (echo OK) else (echo Values are not equal!) +goto :eof + + +REM Exits program. +:end +call :cleanup +exit + + +REM Remove temporary files. +REM call :cleanup +:cleanup +if exist %iniName% del %iniName% +goto :eof \ No newline at end of file diff --git a/tools/iniAdd.bat b/tools/iniAdd.bat new file mode 100644 index 0000000..b077249 --- /dev/null +++ b/tools/iniAdd.bat @@ -0,0 +1,6 @@ +REM Sets key-value pair +REM call addPair [file name] [key] [value] +set delim== +set line=%~2%delim%%~3 +echo %line%>> %~1 +goto :eof \ No newline at end of file diff --git a/tools/iniNew.bat b/tools/iniNew.bat new file mode 100644 index 0000000..97eb24f --- /dev/null +++ b/tools/iniNew.bat @@ -0,0 +1,6 @@ +REM Creates a new blank file with the specified name +REM call iniNew.bat [file name] +set fileName=%~1 +if exist %fileName% del %fileName% +echo.> %fileName% +goto :eof \ No newline at end of file diff --git a/tools/iniRead.bat b/tools/iniRead.bat new file mode 100644 index 0000000..72d34aa --- /dev/null +++ b/tools/iniRead.bat @@ -0,0 +1,12 @@ +REM call iniread.bat [file name] [key name] [output value] + +set fileName=%~1 +set keyName=%~2 + +REM delimiter +set delim== + +REM Returns 2nd token separated by delim as 2nd parameter. +for /f "tokens=2 delims=%delim%" %%a in ('find "%keyName%%delim%" %fileName%') do set %~3=%%a + +goto :eof \ No newline at end of file