cctools
text_array.h File Reference

Go to the source code of this file.

Functions

struct text_array * text_array_create (int w, int h)
 Create a new text array. More...
 
void text_array_delete (struct text_array *t)
 Delete a text array and all of its contents. More...
 
int text_array_width (struct text_array *t)
 Get the width of the array. More...
 
int text_array_height (struct text_array *t)
 Get the height of the array. More...
 
const char * text_array_get (struct text_array *t, int x, int y)
 Look up one cell in the array. More...
 
int text_array_set (struct text_array *t, int x, int y, const char *c)
 Set one cell in the array. More...
 
int text_array_load (struct text_array *t, const char *filename)
 Load an array from a file. More...
 
int text_array_save (struct text_array *t, const char *filename)
 Save an array to a file. More...
 
int text_array_save_range (struct text_array *t, const char *filename, int x, int y, int w, int h)
 Save a portion of an array to a file. More...
 

Detailed Description

A two dimensional array of strings. Each cell may contain either a null pointer or a pointer to an ordinary string. A simple external representation is used to load, store, and subset arrays between processes.

Function Documentation

◆ text_array_create()

struct text_array* text_array_create ( int  w,
int  h 
)

Create a new text array.

Parameters
wWidth of the array.
hHeight of the array.
Returns
A new text array on success, or null on failure.

◆ text_array_delete()

void text_array_delete ( struct text_array *  t)

Delete a text array and all of its contents.

Parameters
tThe text array to deleted.

◆ text_array_width()

int text_array_width ( struct text_array *  t)

Get the width of the array.

Parameters
tA text array.
Returns
The width of the array.

◆ text_array_height()

int text_array_height ( struct text_array *  t)

Get the height of the array.

Parameters
tA text array.
Returns
The height of the array.

◆ text_array_get()

const char* text_array_get ( struct text_array *  t,
int  x,
int  y 
)

Look up one cell in the array.

Parameters
tA text array.
xThe x position of the cell.
yThe y position of the cell.
Returns
The value of the cell, which might be null.

◆ text_array_set()

int text_array_set ( struct text_array *  t,
int  x,
int  y,
const char *  c 
)

Set one cell in the array.

Parameters
tA text array.
xThe x position of the cell.
yThe y position of the cell.
cA string to place in the cell. If not null, c will be copied with strdup and placed in the data structure. Regardless, the current occupant of the cell will be freed.

◆ text_array_load()

int text_array_load ( struct text_array *  t,
const char *  filename 
)

Load an array from a file.

Parameters
tAn array created by text_array_create.
filenameThe filename to load from.

◆ text_array_save()

int text_array_save ( struct text_array *  t,
const char *  filename 
)

Save an array to a file.

Parameters
tAn array created by text_array_create.
filenameThe filename to write to.

◆ text_array_save_range()

int text_array_save_range ( struct text_array *  t,
const char *  filename,
int  x,
int  y,
int  w,
int  h 
)

Save a portion of an array to a file.

Parameters
tAn array created by text_array_create.
filenameThe filename to write to.
xThe starting x position of the range to save.
yThe starting y position of the range to save.
wThe width of the range to save.
hThe height of the range to save.