TeX in C
Explore TeX with modern c compiler.
PART 4: String handling

结构体

struct  StrPoolPtr
 

宏定义

#define POOLPOINTER_IS_POINTER   1
 
#define POOL_TOP   (str_pool + POOL_SIZE)
 
#define POOL_ELEM(x, y)   ((x)[(y)])
 
#define S(x)   (x)
 标记字符串序号 更多...
 

类型定义

typedef ASCIICodePoolPtr
 [#38] for variables that point into str_pool. 更多...
 
typedef uint_fast32_t StrNumber
 
typedef char * Str
 real string. 更多...
 

函数

int str_length (StrNumber x)
 [#40]: the number of characters in string number x. 更多...
 
int cur_length ()
 [#41]: The length of the current string. 更多...
 
void append_char (ASCIICode s)
 [#42]: put ASCII code s at the end of str_pool. 更多...
 
void flush_char (void)
 [#42]: forget the last character in the pool. 更多...
 
void str_room (StrNumber l)
 [#42]: make sure that the pool hasn’t overflowed. 更多...
 
StrNumber makestring (void)
 [#43]: current string enters the pool. 更多...
 
void flush_string (void)
 [#44]: destroy the most recently made string. 更多...
 
int str_cmp (StrNumber s, StrNumber t)
 比较两个 str 的差别。返回 0 为相同,非 0 为有差异。 更多...
 
Boolean str_eq_str (StrNumber s, StrNumber t)
 [p21#46]: test equality of strings。 更多...
 
Boolean get_strings_started (void)
 [#47]: initializes the string pool, but returns false if something goes wrong. 更多...
 
static void app_lc_hex (UChar l)
 [#48] int to hex 更多...
 
Boolean str_pool_init (void)
 [p21#47] Make the first 256 strings, and copy all string in pool_strs[] to string pool. 更多...
 

变量

static ASCIICode str_pool [POOL_SIZE+1]
 [#39] the characters. 更多...
 
static PoolPtr str_start [MAX_STRINGS+1]
 [#39] the starting pointers. 更多...
 
static PoolPtr pool_ptr
 [#39] first unused position in str_pool. 更多...
 
static StrNumber str_ptr
 [#39] number of the current string being created. 更多...
 
static PoolPtr init_pool_ptr
 [#39] the starting value of pool_ptr. 更多...
 
static StrNumber init_str_ptr
 [#39] the starting value of str_ptr. 更多...
 

详细描述

宏定义说明

◆ POOL_ELEM

#define POOL_ELEM (   x,
 
)    ((x)[(y)])

◆ POOL_TOP

#define POOL_TOP   (str_pool + POOL_SIZE)

◆ POOLPOINTER_IS_POINTER

#define POOLPOINTER_IS_POINTER   1

◆ S

#define S (   x)    (x)

标记字符串序号

类型定义说明

◆ PoolPtr

typedef ASCIICode* PoolPtr

[#38] for variables that point into str_pool.

[PoolPointer => PoolPtr], [0, POOL_SIZE=4MB-1B]

◆ Str

typedef char* Str

real string.

◆ StrNumber

typedef uint_fast32_t StrNumber

函数说明

◆ app_lc_hex()

static void app_lc_hex ( UChar  l)
static

[#48] int to hex

◆ append_char()

void append_char ( ASCIICode  s)

[#42]: put ASCII code s at the end of str_pool.

◆ cur_length()

int cur_length ( void  )

[#41]: The length of the current string.

◆ flush_char()

void flush_char ( void  )

[#42]: forget the last character in the pool.

◆ flush_string()

void flush_string ( void  )

[#44]: destroy the most recently made string.

◆ get_strings_started()

Boolean get_strings_started ( void  )

[#47]: initializes the string pool, but returns false if something goes wrong.

called by: main()

◆ makestring()

StrNumber makestring ( void  )

[#43]: current string enters the pool.

Once a sequence of characters has been appended to str pool, it officially becomes a string when the function make string is called.

This function returns the identification number of the new string as its value.

◆ str_cmp()

int str_cmp ( StrNumber  s,
StrNumber  t 
)

比较两个 str 的差别。返回 0 为相同,非 0 为有差异。

◆ str_eq_str()

Boolean str_eq_str ( StrNumber  s,
StrNumber  t 
)

[p21#46]: test equality of strings。

◆ str_length()

int str_length ( StrNumber  x)

[#40]: the number of characters in string number x.

◆ str_pool_init()

Boolean str_pool_init ( void  )

[p21#47] Make the first 256 strings, and copy all string in pool_strs[] to string pool.

length of pool_strs[].

[#48] Make the first 256 strings. ASCII 输入表见 TeXBook: Appendix C: Character Codes.

[#52] Copy strings from 'pool_strs[]' to the pool

◆ str_room()

void str_room ( StrNumber  l)

[#42]: make sure that the pool hasn’t overflowed.

变量说明

◆ init_pool_ptr

PoolPtr init_pool_ptr
static

[#39] the starting value of pool_ptr.

◆ init_str_ptr

StrNumber init_str_ptr
static

[#39] the starting value of str_ptr.

◆ pool_ptr

PoolPtr pool_ptr
static

[#39] first unused position in str_pool.

◆ str_pool

ASCIICode str_pool[POOL_SIZE+1]
static

[#39] the characters.

◆ str_ptr

StrNumber str_ptr
static

[#39] number of the current string being created.

◆ str_start

PoolPtr str_start[MAX_STRINGS+1]
static

[#39] the starting pointers.