Newer
Older
ubixos / src / tools / make_kernel_string_pool.h
/*
   "make_kernel_string_pool.h"

   created by: grayspace aka J. Leveille
   for: UbixOS Project
   date: July 3, 2002

   purpose: - tool to create string pools for in kernel use
            - will generate the source for including a global
            set of ASCII (for now) strings into the kernel
            to avoid memory wastage for kernel output strings
            for long lists of things such as device descriptions

   NOTEs:
      - for now only ASCII is supported

   TODO:
      - expand to support unicode
      - use huffman encoding instead

   $Id$
*/


#ifndef _MAKE_KERNEL_STRING_POOL_H
#define _MAKE_KERNEL_STRING_POOL_H


// Resets *everything*, frees all memory in use, closes all open files
void MakeKSP_ResetAll();

// given a path, opens an existing string file
// (a simple line by line list of strings)
// reads in the contents and appends them to the
// current string list and the current string file
//
// returns 1 on success, 0 on failure
// p_startidx_o <- beginning index of strings within the pool
// p_size_o <- number of strings appended
int AppendStringsFromFile( int * p_startidx_o,
                           int * p_size_o,
                           const char * p_path );

// given a path, opens an existing string file
// (a simple line by line list of strings)
// reads in the contents as the string list and sets
// the file as the current open string file
//
// returns 1 on success, 0 on failure
int Open_StringFile( const char * p_path );

// closes the current open string file and frees
// the current string list
// returns 1 on success, 0 on failure
int Close_StringFile();

// given a path, creates a string file for writing to
// as the current open string file
//
// returns 1 on success, 0 on failure
int Create_StringFile( const char * p_path );

// writes out and closes the current string file if possible
// and frees the current string list
// returns 1 on success, 0 on failure
int WriteAndClose_StringFile();


// given a path, creates a sub string file for writing to
// as the current open sub string file
//
// returns 1 on success, 0 on failure
int Create_SubStringFile( const char * p_path );

// writes out and closes the current sub string file if possible
// and frees the current sub string list
// returns 1 on success, 0 on failure
int WriteAndClose_SubStringFile();

// closes the current open sub string file and frees
// the current sub string list
// returns 1 on success, 0 on failure
int Close_SubStringFile();

// given a path, opens an existing sub string file
// (shoudl conatin an alphabetically sorted list of unique substrings)
// reads in the contents as the current sub string list and sets
// the file as the current open sub string file
//
// returns 1 on success, 0 on failure
int Open_SubStringFile( const char * p_path );

// given a plain text files, extracts any unique sub strings
// and adds them into the current sub string list
//
// returns 1 on success, 0 on failure
int Add_SubStringsFromFile( const char * p_path );

/*
   Input:
      - p_hdr_path <-   full path to header file to write
                        relative to current working directory
      - p_hdr_name <- name of header file
      - p_src_path <-   full path to source file to write
                        relativeto current working directory
      - p_src_name <- name of source file
      - pp_includes <- list of files to include eg. <h1.h>, "h4.h", ...
      - numincludes <- number of files in include list
      - p_pool_name <-  name of identifier to use for string pool
                        generated ( NOTE: sub-arrays of string pool
                                    will use this name to base their names )
   Output:
      - generates both a header file and a source code file which
      can be used to embed compressed strings into an object module
      based on the currently open string list and sub string list
      - returns 1 on success, 0 on failure

   Assumptions:
      - a string list is current open <see: 'Open_StringFile', etc.>
      - a sub string list is current open <see: 'Open_SubStringFile', etc.>
      - the strings in the open string file are a superset of the sub strings
      in the open string file
*/
int Create_KStringSourceCode( const char * p_hdr_path,
                              const char * p_hdr_name,
                              const char * p_src_path,
                              const char * p_src_name,
                              const char ** pp_includes,
                              int numincludes,
                              const char * p_pool_name   );

#endif // _MAKE_KERNEL_STRING_POOL_H