Macros | Typedefs | Functions
fileioc.h File Reference

Implements variable reading and writing routines. More...

#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <tice.h>

Go to the source code of this file.

Macros

#define ti_MallocReal()
 
#define ti_MallocCplx()
 
#define ti_MallocString(len)
 
#define ti_MallocList(dim)
 
#define ti_MallocMatrix(rows, cols)
 
#define ti_MallocCplxList(dim)
 
#define ti_MallocEqu(len)
 

Typedefs

typedef uint8_t ti_var_t
 Variable slot type.
 

Functions

void ti_CloseAll (void)
 
ti_var_t ti_Open (const char *name, const char *mode)
 
ti_var_t ti_OpenVar (const char *varname, const char *mode, uint8_t type)
 
int ti_Close (const ti_var_t slot)
 
char * ti_Detect (void **curr_search_posistion, const char *detection_string)
 
char * ti_DetectVar (void **curr_search_posistion, const char *detection_string, uint8_t var_type)
 
char * ti_DetectAny (void **curr_search_posistion, const char *detection_string, uint8_t *var_type)
 
size_t ti_Write (const void *data, size_t size, size_t count, const ti_var_t slot)
 
size_t ti_Read (const void *data, size_t size, size_t count, const ti_var_t slot)
 
int ti_PutC (const char c, const ti_var_t slot)
 
int ti_GetC (const ti_var_t slot)
 
int ti_Seek (int offset, unsigned int origin, const ti_var_t slot)
 
int ti_Rewind (const ti_var_t slot)
 
uint16_t ti_Tell (const ti_var_t slot)
 
uint16_t ti_GetSize (const ti_var_t slot)
 
int ti_Resize (size_t new_size, const ti_var_t slot)
 
int ti_IsArchived (const ti_var_t slot)
 
int ti_SetArchiveStatus (bool archived, const ti_var_t slot)
 
int ti_Delete (const char *name)
 
int ti_DeleteVar (const char *varname, const uint8_t type)
 
char * ti_GetTokenString (void **read_pointer, uint8_t *length_of_token, unsigned int *length_of_string)
 
void * ti_GetDataPtr (const ti_var_t slot)
 
void * ti_GetVATPtr (const ti_var_t slot)
 
void ti_GetName (char *name, const ti_var_t slot)
 
uint8_t ti_Rename (const char *old, const char *new)
 
uint8_t ti_RenameVar (const char *old, const char *new, const uint8_t type)
 
uint8_t ti_SetVar (const ti_var_t var_type, const char *name, void *data)
 
uint8_t ti_StoVar (const ti_var_t var_type_to, void *to, const ti_var_t var_type_from, void *from)
 
uint8_t ti_RclVar (const uint8_t var_type, const char *var_name, void **data_struct)
 

Detailed Description

Implements variable reading and writing routines.

Author
Matt "MateoConLechuga" Waltz

Macro Definition Documentation

◆ ti_MallocCplx

#define ti_MallocCplx ( )

Allocates space for a complex variable

Returns
Pointer to variable

◆ ti_MallocCplxList

#define ti_MallocCplxList (   dim)

Allocates space for a complex list variable

Parameters
dimDimension of complex list
Returns
Pointer to variable

◆ ti_MallocEqu

#define ti_MallocEqu (   len)

Allocates space for an equation variable

Parameters
lenLength of equation variable
Returns
Pointer to variable

◆ ti_MallocList

#define ti_MallocList (   dim)

Allocates space for a list variable

Parameters
dimDimension of list
Returns
Pointer to variable

◆ ti_MallocMatrix

#define ti_MallocMatrix (   rows,
  cols 
)

Allocates space for a matrix variable

Parameters
rowsRows in matrix
colsColumns in matrix
Returns
Pointer to variable

◆ ti_MallocReal

#define ti_MallocReal ( )

Allocates space for a real variable

Returns
Pointer to variable

◆ ti_MallocString

#define ti_MallocString (   len)

Allocates space for a string variable

Parameters
lenLength of string
Returns
Pointer to variable

Function Documentation

◆ ti_Close()

int ti_Close ( const ti_var_t  slot)

Frees an open variable slot

Returns
Zero if closing failed

◆ ti_CloseAll()

void ti_CloseAll ( void  )

Closes all open slots

Warning
Call before you use any variable functions

◆ ti_Delete()

int ti_Delete ( const char *  name)

Deletes an AppVar

Parameters
nameName of AppVar to delete
Returns
0 if failed

◆ ti_DeleteVar()

int ti_DeleteVar ( const char *  varname,
const uint8_t  type 
)

Deletes a variable given the name and type

Parameters
varnameName of variable to delete
typeType of variable to delete
Returns
0 if failed

◆ ti_Detect()

char* ti_Detect ( void **  curr_search_posistion,
const char *  detection_string 
)

Returns the name of the file(s) that contains the string as the first part of the variable; which can then be used with ti_Open and other functions

seach_pos should be set to NULL to begin a search, and is updated with each call

char *var_name;
uint8_t *search_pos = NULL;
while((var_name = ti_Detect(&search_pos, "my_data")) != NULL) {
...do something with the name or search_pos...
}
Parameters
curr_search_posistionCurrent offset in the VAT
detection_stringString to search for (NULL to search for all)
Note
If the return value is NULL, there are no more variables to find

◆ ti_DetectAny()

char* ti_DetectAny ( void **  curr_search_posistion,
const char *  detection_string,
uint8_t *  var_type 
)

Returns the name of the file(s) that contains the string as the first part of the variable; which can then be used with ti_OpenVar and other functions

seach_pos should be set to NULL to begin a search, and is updated with each call

char *var_name;
uint8_t *search_pos = NULL;
uint8_t type;
while((var_name = ti_DetectVar(&search_pos, "my_data", &type)) != NULL) {
if (type == TI_PRGM_TYPE || type == TI_PPRGM_TYPE) {
...do something with the name or search_pos...
}
}
Parameters
curr_search_posistionCurrent offset in the VAT
detection_stringString to search for (NULL to search for all)
var_typeType of variable found
Note
If the return value is NULL, there are no more variables to find

◆ ti_DetectVar()

char* ti_DetectVar ( void **  curr_search_posistion,
const char *  detection_string,
uint8_t  var_type 
)

Returns the name of the file(s) that contains the string as the first part of the variable; which can then be used with ti_OpenVar and other functions

seach_pos should be set to NULL to begin a search, and is updated with each call

char *var_name;
uint8_t *search_pos = NULL;
while((var_name = ti_DetectVar(&search_pos, "my_data", TI_PRGM_TYPE)) != NULL) {
...do something with the name or search_pos...
}
Parameters
curr_search_posistionCurrent offset in the VAT
detection_stringString to search for (NULL to search for all)
var_typeType of variable to detect
Note
If the return value is NULL, there are no more variables to find

◆ ti_GetC()

int ti_GetC ( const ti_var_t  slot)

Pulls a character directly from the slot data pointer, and increments the offset

Parameters
slotVariable slot to get the character from
Returns
1 byte character at the current variable offset
'EOF' if current offset is larger than file size

◆ ti_GetDataPtr()

void* ti_GetDataPtr ( const ti_var_t  slot)

Gets a pointer to the data located at the current posistion in the slot; Good way for fast reading of data

Parameters
slotVariable slot to get pointer of
Returns
Pointer to variable data

◆ ti_GetName()

void ti_GetName ( char *  name,
const ti_var_t  slot 
)

Gets the variable name of an already opened slot

Parameters
slotVariable slot to get name of
nameBuffer to store name in, generally at least 10 bytes including null terminator.
Returns
None

◆ ti_GetSize()

uint16_t ti_GetSize ( const ti_var_t  slot)

Gets the size of a slot

Parameters
slotSlot to test
Returns
The size of the slot variable

◆ ti_GetTokenString()

char* ti_GetTokenString ( void **  read_pointer,
uint8_t *  length_of_token,
unsigned int *  length_of_string 
)

Gets the string used for displaying a TI token

Parameters
length_of_stringPointer to variable to hold length of resulting string (Can be NULL if you don't care)
length_of_tokenPointer to variable to hold length of the token, used for determining the next read location (Can be NULL if you don't care)
read_pointerAddress of pointer to data to read
Note
read_pointer is updated to the next token, depending on if it is 1 or 2 bytes in length

◆ ti_GetVATPtr()

void* ti_GetVATPtr ( const ti_var_t  slot)

Gets the VAT location of the slot

Parameters
slotVariable slot to get VAT location of
Returns
VAT location of variable

◆ ti_IsArchived()

int ti_IsArchived ( const ti_var_t  slot)

Tests if a slot is in the archive

Parameters
slotSlot to test
Returns
Zero (0) if the slot is not in the archive

◆ ti_Open()

ti_var_t ti_Open ( const char *  name,
const char *  mode 
)

Opens a file

An AppVar is used as default file storage

Parameters
nameName of file to open
mode"r" - Opens a file for reading. The file must exist. Keeps file in archive if in archive.
"w" - Creates an empty file for writing. Overwrites file if already exists.
"a" - Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist.
"r+" - Opens a file to update both reading and writing. The file must exist. Moves file from archive to RAM if in archive.
"w+" - Creates an empty file for both reading and writing. Overwrites file if already exists.
"a+" - Opens a file for reading and appending. Moves file from archive to RAM if in archive. Created if it does not exist.
Returns
Slot variable
Note
If there isn't enough memory to create the variable, or a slot isn't open, zero (0) is returned

◆ ti_OpenVar()

ti_var_t ti_OpenVar ( const char *  varname,
const char *  mode,
uint8_t  type 
)

Opens a variable

Can open any type of program or appvar variable

Parameters
varnameName of variable to open
mode"r" - Opens a file for reading. The file must exist. Keeps file in archive if in archive.
"w" - Creates an empty file for writing. Overwrites file if already exists.
"a" - Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist.
"r+" - Opens a file to update both reading and writing. The file must exist. Moves file from archive to RAM if in archive.
"w+" - Creates an empty file for both reading and writing. Overwrites file if already exists.
"a+" - Opens a file for reading and appending. Moves file from archive to RAM if in archive. Created if it does not exist.
typeSpecifies the type of variable to open
Returns
Slot variable
Note
If there isn't enough memory to create the variable, or a slot isn't open, zero (0) is returned

◆ ti_PutC()

int ti_PutC ( const char  c,
const ti_var_t  slot 
)

Writes a character directly into the slot data pointer, and increments the offset

Parameters
cCharacter to write
slotVariable slot to put the character to
Returns
The input c is returned if no error
'EOF' if current offset is larger than file size, or memory isn't large enough

◆ ti_RclVar()

uint8_t ti_RclVar ( const uint8_t  var_type,
const char *  var_name,
void **  data_struct 
)

Recalls a variable

Parameters
var_typeType of variable to recall
var_namePointer to name of variable to recall
data_structAddress of pointer to variable structure
Returns
0 if success
Note
data_struct is set to the variable's data

◆ ti_Read()

size_t ti_Read ( const void *  data,
size_t  size,
size_t  count,
const ti_var_t  slot 
)

Reads from the current variable pointer

Parameters
dataPointer to data to read into
sizeSize (in bytes) of a single data chunk
countNumber of data chunks to read from the variable slot
slotVariable slot to read the data from
Returns
The number of chunks read (should be equal to count)

◆ ti_Rename()

uint8_t ti_Rename ( const char *  old,
const char *  new 
)

Renames a file

Parameters
oldOld name of file
newNew name of file
Returns
0 if success, 1 if file already exists, 2 any other error occurs.
Warning
It is potentially hazardous to rename an open file. Be sure to close the open file before renaming,

◆ ti_RenameVar()

uint8_t ti_RenameVar ( const char *  old,
const char *  new,
const uint8_t  type 
)

Renames a variable

Parameters
oldOld name of variable
newNew name of variable
typeType of variable to rename
Returns
0 if success, 1 if variable already exists, 2 any other error occurs.
Warning
It is potentially hazardous to rename an open variable. Be sure to close the open variable before renaming,

◆ ti_Resize()

int ti_Resize ( size_t  new_size,
const ti_var_t  slot 
)

Resizes the slot variable

Parameters
slotSlot to resize
new_sizeNew size of slot
Returns
Resized size on success, 0 on failure, or -1 if the slot cannot be opened
Note
The variable offset is set to the beginning of the file

◆ ti_Rewind()

int ti_Rewind ( const ti_var_t  slot)

Seeks to the start of the given variable

Basically an ti_Seek(0, SEEK_SET, slot);

Parameters
slotVariable slot to rewind
Returns
'EOF' on rewind failure

◆ ti_Seek()

int ti_Seek ( int  offset,
unsigned int  origin,
const ti_var_t  slot 
)

Seeks to an offset

Parameters
offsetNumber of bytes to offest from (can be negative)
originSEEK_SET (0) - Seek from beginning of file
SEEK_CUR (1) - Seek from current offset in file
SEEK_END (2) - Seek from end of file
slotVariable slot seeking in
Returns
'EOF' on seek failure

◆ ti_SetArchiveStatus()

int ti_SetArchiveStatus ( bool  archived,
const ti_var_t  slot 
)

Sends the variable into either the archive or RAM if needed

Parameters
archivedTrue - Send to Archive
False - Send to RAM
slotSlot to send
Returns
Zero if the operation fails from not enough memory or another error

◆ ti_SetVar()

uint8_t ti_SetVar ( const ti_var_t  var_type,
const char *  name,
void *  data 
)

Sets a variable

Parameters
var_typeType of variable to set
namePointer to name of variable
dataPointer to data to set
Returns
0 if success

◆ ti_StoVar()

uint8_t ti_StoVar ( const ti_var_t  var_type_to,
void *  to,
const ti_var_t  var_type_from,
void *  from 
)

Stores a variable to another variable

Parameters
var_type_toType of variable to store to
toPointer to data to store to
var_type_fromType of variable to get from
fromPointer to data to get from
Returns
0 if success

◆ ti_Tell()

uint16_t ti_Tell ( const ti_var_t  slot)

Gets the offset in a slot

Parameters
slotSlot to test
Returns
The value of the current slot offset

◆ ti_Write()

size_t ti_Write ( const void *  data,
size_t  size,
size_t  count,
const ti_var_t  slot 
)

Writes to the current variable slot

Parameters
dataPointer to data to write
sizeSize (in bytes) of a single data chunk
countNumber of data chunks to write to the variable slot
slotVariable slot to write the data to
Returns
The number of chunks written (should be equal to count)