Noble Ape
The Central Directories of the Noble Ape Simulation.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
io.c File Reference

Covers the low level input and output relating to memory and files. In addition to memory and file handling, io has typically been a place holder for new functionality. More...

#include "noble.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Include dependency graph for io.c:

Go to the source code of this file.

Macros

#define CHAR_TAB   (9)
#define CHAR_SPACE   (32)
#define CHAR_EOF   0
#define IS_RETURN(val)   (((val) == 10) || ((val) == 13))
#define IS_TAB(val)   ((val) == CHAR_TAB)
#define IS_SPACE(val)   ((val) == CHAR_SPACE)
#define IS_WHITE_HORIZON(val)   (IS_TAB(val) || IS_SPACE(val))
#define IS_WHITE_SPACE(val)   (IS_WHITE_HORIZON((val))||IS_RETURN((val)))
#define FILE_END_INCLUSION   0x0101
#define FILE_TYPE(num)   ((num)&0x07)
#define FILE_CONTINUATION   0x80
#define ASCII_WHITESPACE(num)   ((((num)>8)&&((num)<14))||((num)==32))
#define FILE_MACRO_WRITE(ch)   if(io_file_write(fil,(ch)) == -1) return -1
#define FILE_MACRO_CONCLUSION(ch)
#define IO_CHECK_ERROR(cnd)

Functions

void io_command_line_execution_set (void)
n_int io_command_line_execution (void)
void io_entry_execution (n_int argc, n_string *argv)
void io_copy (n_byte *from, n_byte *to, n_uint number)
void * io_new (n_uint bytes)
void io_free (void **ptr)
void * io_new_range (n_uint memory_min, n_uint *memory_allocated)
void io_lower (n_string value, n_int length)
n_fileio_file_new (void)
void io_file_free (n_file **file)
void io_int_to_bytes (n_int value, n_byte *bytes)
n_int io_bytes_to_int (n_byte *bytes)
n_int io_disk_read (n_file *local_file, n_string file_name)
n_int io_disk_write (n_file *local_file, n_string file_name)
n_int io_disk_check (n_constant_string file_name)
n_int io_read_bin (n_file *fil, n_byte *local_byte)
n_stringio_tab_delimit_to_n_string_ptr (n_file *tab_file, n_int *size_value, n_int *row_value)
n_int io_read_byte4 (n_file *fil, n_uint *actual_value, n_byte *final_char)
n_int io_number (n_string number_string, n_int *actual_value, n_int *decimal_divisor)
void io_whitespace (n_file *input)
n_int io_file_write (n_file *fil, n_byte byte)
void io_file_reused (n_file *fil)
n_int io_length (n_string value, n_int max)
n_int io_find (n_string check, n_int from, n_int max, n_string value_find, n_int value_find_length)
n_int io_write (n_file *fil, n_constant_string ch, n_byte new_line)
n_int io_writenumber (n_file *fil, n_int loc_val, n_uint numer, n_uint denom)
n_int io_writenum (n_file *fil, n_int loc_val, n_byte ekind, n_byte new_line)
n_int io_command (n_file *fil, const noble_file_entry *commands)
n_int io_find_size_data (noble_file_entry *commands)
n_int io_read_data (n_file *fil, n_byte2 command, n_byte *data_read)
void io_output_contents (n_file *file)
n_int io_read_buff (n_file *fil, n_byte *data, const noble_file_entry *commands)
n_int io_write_buff (n_file *fil, void *data, const noble_file_entry *commands, n_byte command_num, n_file_specific *func)
n_int io_write_csv (n_file *fil, n_byte *data, const noble_file_entry *commands, n_byte command_num, n_byte initial)
void io_erase (n_byte *buf_offscr, n_uint nestop)
void io_search_file_format (const noble_file_entry *format, n_string compare)
void io_audit_file (const noble_file_entry *format, n_byte section_to_audit)
void io_three_string_combination (n_string output, n_string first, n_string second, n_string third, n_int count)
void io_time_to_string (n_string value, n_int minutes, n_int days)
void io_offset (n_byte *start, n_byte *point, n_string text)
void io_help_line (noble_console_command *specific, n_console_output output_function)
n_int io_help (void *ptr, n_string response, n_console_output output_function)
n_int io_quit (void *ptr, n_string response, n_console_output output_function)
n_string io_console_entry_clean (n_string string, n_int length)
n_string io_console_entry (n_string string, n_int length)
void io_console_out (n_constant_string value)
void io_console_quit (void)
n_int io_console (void *ptr, noble_console_command *commands, n_console_input input_function, n_console_output output_function)
void io_string_write (n_string dest, n_string insert, n_int *pos)
n_int io_apescript_error (void *ptr, AE_ENUM value)
n_fileio_file_ready (n_int entry, n_file *file)
void io_file_cleanup (n_int *entry, n_file **file)
void io_file_writeon (n_int *entry, n_file **file, n_byte blocked_write)
void io_file_writeoff (n_int *entry, n_file *file)
void io_file_string (n_int entry, n_file *file, n_constant_string string)

Variables

noble_console_commandlocal_commands = 0L

Detailed Description

Covers the low level input and output relating to memory and files. In addition to memory and file handling, io has typically been a place holder for new functionality.

Definition in file io.c.


Macro Definition Documentation

#define ASCII_WHITESPACE (   num)    ((((num)>8)&&((num)<14))||((num)==32))

Definition at line 564 of file io.c.

#define CHAR_EOF   0

Definition at line 54 of file io.c.

#define CHAR_SPACE   (32)

Definition at line 51 of file io.c.

#define CHAR_TAB   (9)

Definition at line 50 of file io.c.

#define FILE_CONTINUATION   0x80

Definition at line 62 of file io.c.

#define FILE_END_INCLUSION   0x0101

Definition at line 60 of file io.c.

#define FILE_MACRO_CONCLUSION (   ch)
Value:
(((comman_req==1) && (ch) == ',') || \
((comman_req==0) && (ch) == ';'))

Definition at line 911 of file io.c.

#define FILE_MACRO_WRITE (   ch)    if(io_file_write(fil,(ch)) == -1) return -1

Definition at line 738 of file io.c.

#define FILE_TYPE (   num)    ((num)&0x07)

Definition at line 61 of file io.c.

#define IO_CHECK_ERROR (   cnd)
Value:
{ \
n_int out_cnd = cnd; \
if ( (out_cnd) != FILE_OKAY) \
return out_cnd; \
}

Definition at line 1095 of file io.c.

#define IS_RETURN (   val)    (((val) == 10) || ((val) == 13))

Definition at line 55 of file io.c.

#define IS_SPACE (   val)    ((val) == CHAR_SPACE)

Definition at line 57 of file io.c.

#define IS_TAB (   val)    ((val) == CHAR_TAB)

Definition at line 56 of file io.c.

#define IS_WHITE_HORIZON (   val)    (IS_TAB(val) || IS_SPACE(val))

Definition at line 58 of file io.c.

#define IS_WHITE_SPACE (   val)    (IS_WHITE_HORIZON((val))||IS_RETURN((val)))

Definition at line 59 of file io.c.


Function Documentation

n_int io_apescript_error ( void *  ptr,
AE_ENUM  value 
)

Definition at line 1748 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void io_audit_file ( const noble_file_entry format,
n_byte  section_to_audit 
)

Definition at line 1499 of file io.c.

n_int io_bytes_to_int ( n_byte bytes)

Definition at line 202 of file io.c.

Here is the call graph for this function:

n_int io_command ( n_file fil,
const noble_file_entry commands 
)

Definition at line 830 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_command_line_execution ( void  )

Definition at line 69 of file io.c.

Here is the caller graph for this function:

void io_command_line_execution_set ( void  )

Definition at line 64 of file io.c.

Here is the caller graph for this function:

n_int io_console ( void *  ptr,
noble_console_command commands,
n_console_input  input_function,
n_console_output  output_function 
)

Definition at line 1660 of file io.c.

Here is the call graph for this function:

n_string io_console_entry ( n_string  string,
n_int  length 
)

Definition at line 1643 of file io.c.

Here is the call graph for this function:

n_string io_console_entry_clean ( n_string  string,
n_int  length 
)

Definition at line 1638 of file io.c.

Here is the caller graph for this function:

void io_console_out ( n_constant_string  value)

Definition at line 1649 of file io.c.

Here is the caller graph for this function:

void io_console_quit ( void  )

Definition at line 1655 of file io.c.

Here is the caller graph for this function:

void io_copy ( n_byte from,
n_byte to,
n_uint  number 
)

This is a historical legacy function as all platforms now use memcpy. Although in the future this may change.

Parameters:
frompointer to copy from.
topointer to copy to.
numberthe number of bytes to copy.

Definition at line 91 of file io.c.

Here is the caller graph for this function:

n_int io_disk_check ( n_constant_string  file_name)

Appends a file to disk.

Parameters:
local_filethe pointer to the n_file data that is written to disk.
file_namethe name of the file to be appended.
Returns:
FILE_ERROR if there is a problem and FILE_OKAY if it is successful.

Definition at line 292 of file io.c.

n_int io_disk_read ( n_file local_file,
n_string  file_name 
)

Reads a file from disk.

Parameters:
local_filethe pointer to the n_file data that will have the file stored in it.
file_namethe name of the file to be read.
Returns:
FILE_ERROR if there is a problem and FILE_OKAY if it is successful.

Definition at line 217 of file io.c.

Here is the call graph for this function:

n_int io_disk_write ( n_file local_file,
n_string  file_name 
)

Writes a file to disk.

Parameters:
local_filethe pointer to the n_file data that is written to disk.
file_namethe name of the file to be written.
Returns:
FILE_ERROR if there is a problem and FILE_OKAY if it is successful.

Definition at line 254 of file io.c.

Here is the caller graph for this function:

void io_entry_execution ( n_int  argc,
n_string argv 
)

Definition at line 74 of file io.c.

Here is the call graph for this function:

void io_erase ( n_byte buf_offscr,
n_uint  nestop 
)

Definition at line 1413 of file io.c.

Here is the caller graph for this function:

void io_file_cleanup ( n_int entry,
n_file **  file 
)

Definition at line 1794 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void io_file_free ( n_file **  file)

Frees the file pointer

Parameters:
filethe pointer to be freed.

Definition at line 188 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_file* io_file_new ( void  )

Allocates a new file.

Returns:
a 4k worth of data file pointer.

Definition at line 165 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_file* io_file_ready ( n_int  entry,
n_file file 
)

Definition at line 1785 of file io.c.

Here is the caller graph for this function:

void io_file_reused ( n_file fil)

Definition at line 663 of file io.c.

Here is the call graph for this function:

void io_file_string ( n_int  entry,
n_file file,
n_constant_string  string 
)

Definition at line 1843 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_file_write ( n_file fil,
n_byte  byte 
)

This is a dynamic write to file function which will increase the file size and allocated a larger data buffer if the original end of the file is reached. It is very useful for a number of dynamic file applications through the simulation.

Parameters:
filThe file data to be written to.
byteThe byte/character to be written.
Returns:
Whether the parsing was successful or -1 on failure.

Definition at line 625 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void io_file_writeoff ( n_int entry,
n_file file 
)

Definition at line 1832 of file io.c.

Here is the caller graph for this function:

void io_file_writeon ( n_int entry,
n_file **  file,
n_byte  blocked_write 
)

Definition at line 1808 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_find ( n_string  check,
n_int  from,
n_int  max,
n_string  value_find,
n_int  value_find_length 
)

Definition at line 714 of file io.c.

Here is the caller graph for this function:

n_int io_find_size_data ( noble_file_entry commands)

Definition at line 870 of file io.c.

Here is the caller graph for this function:

void io_free ( void **  ptr)

This is a historical legacy function as all platforms now use free. Although in the future this may change.

Parameters:
ptrthe void * pointer to be freed. Should really be a void ** to catch the 0L-ing.

Definition at line 115 of file io.c.

Here is the caller graph for this function:

n_int io_help ( void *  ptr,
n_string  response,
n_console_output  output_function 
)

Definition at line 1585 of file io.c.

Here is the call graph for this function:

void io_help_line ( noble_console_command specific,
n_console_output  output_function 
)

Definition at line 1578 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void io_int_to_bytes ( n_int  value,
n_byte bytes 
)

Definition at line 197 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_length ( n_string  value,
n_int  max 
)

Definition at line 680 of file io.c.

Here is the caller graph for this function:

void io_lower ( n_string  value,
n_int  length 
)

Moves the string to lower case for the length shown.

Parameters:
valuethe string with the case to be lowered.
lengththe number of bytes to be lowered.
Returns:
a void* pointer of the allocated bytes.

Definition at line 151 of file io.c.

Here is the caller graph for this function:

void* io_new ( n_uint  bytes)

This is a historical legacy function as all platforms now use malloc. Although in the future this may change.

Parameters:
bytesnumber of bytes to allocate.
Returns:
a void* pointer of the allocated bytes.

Definition at line 101 of file io.c.

Here is the caller graph for this function:

void* io_new_range ( n_uint  memory_min,
n_uint memory_allocated 
)

This is allocates a range of memory depending on availability.

Parameters:
memory_minthe minimum possible allocated memory before returning 0L.
memory_allocatedthe starting value for memory size and returning the actual size.
Returns:
a void* pointer of the allocated bytes.

Definition at line 130 of file io.c.

n_int io_number ( n_string  number_string,
n_int actual_value,
n_int decimal_divisor 
)

Read a number from a string.

Parameters:
number_stringthe string to be read from.
actual_valuethe actual value read.
decimal_divisorthe value required to provide a decimal version.
Returns:
number of characters read in condition of success and -1 in condition of failure.

Definition at line 473 of file io.c.

Here is the caller graph for this function:

void io_offset ( n_byte start,
n_byte point,
n_string  text 
)

Definition at line 1573 of file io.c.

void io_output_contents ( n_file file)

Definition at line 999 of file io.c.

Here is the caller graph for this function:

n_int io_quit ( void *  ptr,
n_string  response,
n_console_output  output_function 
)

Definition at line 1633 of file io.c.

Here is the caller graph for this function:

n_int io_read_bin ( n_file fil,
n_byte local_byte 
)

Reads binary data from the file pointer.

Parameters:
filthe pointer to the n_file data that is read from.
local_bytethe single byte.
Returns:
FILE_ERROR if there is a problem and FILE_OKAY if it is successful.

Definition at line 318 of file io.c.

Here is the caller graph for this function:

n_int io_read_buff ( n_file fil,
n_byte data,
const noble_file_entry commands 
)

This function takes a file and parses the file date with the commands shown into the output data. This function is extremely powerful because it allows all different kinds of format-rich text data to be converted into binary information based on the command information passed in to this function too.

Parameters:
filThe file data to be parsed.
dataThe resultant output data.
commandsThe commands used to parse the output data.
Returns:
Whether the parsing was successful or -1 on failure.

Definition at line 1025 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_read_byte4 ( n_file fil,
n_uint actual_value,
n_byte final_char 
)

Read a four byte value from n_file

Parameters:
filthe pointer to the n_file data that is read from.
actual_valuethe actual value read.
final_charthe final character (after the last number).
Returns:
number of characters read in condition of success and -1 in condition of failure.

Definition at line 438 of file io.c.

Here is the caller graph for this function:

n_int io_read_data ( n_file fil,
n_byte2  command,
n_byte data_read 
)

Definition at line 916 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void io_search_file_format ( const noble_file_entry format,
n_string  compare 
)

Definition at line 1418 of file io.c.

Here is the caller graph for this function:

void io_string_write ( n_string  dest,
n_string  insert,
n_int pos 
)

Definition at line 1733 of file io.c.

Here is the caller graph for this function:

n_string* io_tab_delimit_to_n_string_ptr ( n_file tab_file,
n_int size_value,
n_int row_value 
)

Converts a tab delimited file to a series of string pointers

Parameters:
tab_filethe pointer to the n_file data that is read from.
size_valuethe pointer to the total number.
row_valuethe pointer to the number of columns per row.
Returns:
string pointers.

Definition at line 353 of file io.c.

Here is the call graph for this function:

void io_three_string_combination ( n_string  output,
n_string  first,
n_string  second,
n_string  third,
n_int  count 
)

Definition at line 1544 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void io_time_to_string ( n_string  value,
n_int  minutes,
n_int  days 
)

Definition at line 1565 of file io.c.

Here is the caller graph for this function:

void io_whitespace ( n_file input)

Removes the whitespace from the initial file - CRs, LFs, tabs and spaces.

Parameters:
inputthe file pointer that will have the white space removed.

Definition at line 570 of file io.c.

Here is the caller graph for this function:

n_int io_write ( n_file fil,
n_constant_string  ch,
n_byte  new_line 
)

Definition at line 740 of file io.c.

Here is the caller graph for this function:

n_int io_write_buff ( n_file fil,
void *  data,
const noble_file_entry commands,
n_byte  command_num,
n_file_specific func 
)

This function takes a block of data and various format-rules (through the commands) and applies these rules to produce an output datafile. In many regards this can be thought of as the inverse of io_read_buff.

Parameters:
filThe file data that is produced.
dataThe resultant output data.
commandsThe commands used to parse data to the output file.
command_numOutput the command number block of commands.
funcAllows a file specific function to be injected to add additional format requirments.
Returns:
Whether the parsing was successful.

Definition at line 1112 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_write_csv ( n_file fil,
n_byte data,
const noble_file_entry commands,
n_byte  command_num,
n_byte  initial 
)

Definition at line 1316 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_writenum ( n_file fil,
n_int  loc_val,
n_byte  ekind,
n_byte  new_line 
)

Definition at line 818 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int io_writenumber ( n_file fil,
n_int  loc_val,
n_uint  numer,
n_uint  denom 
)

Definition at line 768 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

noble_console_command* local_commands = 0L

Definition at line 1541 of file io.c.