Other versions with updates and for another platforms will be available later. If your prefered platform is not available, please contact us on iklaxmedia.com.
See the kio.h file reference.
See the ktool.h file reference.
See the KIntList.h file reference.
#include <KToolLib.h> static KCString m_sLicenceFileName = "LICENCE.TXT"; static KString k_getTextFromFile (KCString sFilePath); static KString k_searchFile (KCString sFileName);
// Searchs a file in parent directories KString k_searchFile (KCString sFileName) { static const KUInt8 iIterMax = 10; KUInt8 i = 0; KFILE* pFile = knull; KString sPath = knull; KString sTmpPath = knull; KBool bRet = kfalse; // Check paramter bRet = knull != sFileName; // Copy the file name - This function copy all the string until // and with the character '\0'. bRet = bRet && knull != (sPath = k_strcpy (sFileName)); for (i=0; bRet && i<iIterMax; i++) { // Try to open the file pFile = k_fmopen (sPath, K_OPEN_READ); if (knull != pFile) { // The file exists k_fclose (pFile); return sPath; } // Create a new file path sTmpPath = sPath; bRet = bRet && knull != (sPath = KString_new (k_strlen (sTmpPath) + 3)); bRet = bRet && knull != k_memcpy (sPath, "../", 3); bRet = bRet && knull != k_memcpy ( sPath + 3, sTmpPath, k_strlen (sTmpPath)); k_free (sTmpPath); } k_free (sPath); return knull; }
// Reads a file and returns its contents in a string KString k_getTextFromFile (KCString sFilePath) { KFILE* pFile = knull; KBool bRet = kfalse; KString sText = knull; KInt32 iBytes = 0; // Check paramter bRet = knull != sFilePath; // Open the file bRet = bRet && knull != (pFile = k_fmopen (sFilePath, K_OPEN_READ)); // Go to the end of the file bRet = bRet && 0 == k_fseek (pFile, 0, K_SEEK_END); // iBytes = size of file bRet = bRet && 0 < (iBytes = k_ftell (pFile)); // Go to the begin of the file bRet = bRet && 0 == k_fseek (pFile, 0, K_SEEK_SET); // Initialize the string bRet = bRet && knull != (sText = KString_new (iBytes)); // Read in the file bRet = bRet && 1 == k_fread (sText, iBytes, 1, pFile); // Close the file. It's not necessary to check the pointer // before this call: this function do it, and resets the // pointer to knull. k_fclose (pFile); // Error & return if (!bRet) { // It's not necessary to check the pointer before this call: // this function do it, and resets the pointer to knull. k_free (sText); return knull; } return sText; }
KBool ktest_ktoollib () { KString sFilePath = knull; KString sText = knull; // Search the licence file sFilePath = k_searchFile (m_sLicenceFileName); if (knull == sFilePath) { k_print_std ( "Cannot find the licence file (%s)!\n", m_sLicenceFileName); return kfalse; } // Read the file sText = k_getTextFromFile (sFilePath); if (knull == sText) { k_free (sFilePath); k_print_std ("Cannot read the licence file (%s)!\n", sFilePath); return kfalse; } // Write on standard output the licence file k_print_std ("This is the licence of iKlax Librairies:\n%s\n", sText); k_free (sText); k_free (sFilePath); return ktrue; }
iKlax Media SAS hereby grant permission to use, copy and distribute this software and its documentation for any non-commercial purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in non-commercial distributions. No written agreement, license, or royalty fee is required for non-commercial uses. For commercial uses, distribution of this software or for modification on this this software, please contact iKlax Media SAS. (http://www.iklaxmedia.com)
IN NO EVENT SHALL IKLAX MEDIA SAS, THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IKLAX MEDIA SAS, THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED ON AN "AS IS" BASIS, AND IKLAX MEDIA SAS, THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1.3.8