TeX in C
Explore TeX with modern c compiler.
str.h
浏览该文件的文档.
1 #pragma once
2 #ifndef STR_H
3 // 字符串相关操作
4 #define STR_H
5 // Need:
6 // [type] Boolean@tex_types
7 #include <stdio.h> // FILE
8 #include <stdint.h> // int_fast32_t
9 #include "global.h" // [const] UMAXOF, static_assert
10 #include "charset.h" // [type] ASCIICode
11 
12 
23 #define MAX_STRINGS 300000
30 #define STRING_VACANCIES 8000
41 #define POOL_SIZE (1024 * 1024 * 4 - 1) // end group S1x16_P3x9
43 
44 
49 #define POOLPOINTER_IS_POINTER 1
50 #if POOLPOINTER_IS_POINTER
54 typedef ASCIICode* PoolPtr;
55 #define POOL_TOP (str_pool + POOL_SIZE)
56 #define POOL_ELEM(x, y) ((x)[(y)])
57 #else
58 typedef Pointer PoolPtr; // PoolPtr = [0, POOL_SIZE=3200000]
59 static_assert(UMAXOF(PoolPtr) >= POOL_SIZE,
60  "PoolPtr = [0, POOL_SIZE=3200000]");
61 #define POOL_TOP POOL_SIZE
62 #define POOL_ELEM(x, y) (str_pool[(x) + (y)])
63 #endif
64 
65 // [str], tex
66 typedef struct {
67  PoolPtr val; // 暂存 pool_ptr::PoolPtr
68 } StrPoolPtr;
69 // dviout, fonts, global.h, str, tex
70 
72 #define S(x) (x)
73 typedef uint_fast32_t StrNumber; // [0, MAX_STRINGS=300000]
74 static_assert(UMAXOF(StrNumber) >= MAX_STRINGS,
75  "StrNumber = [0, MAX_STRINGS=300000]");
77 typedef char* Str; // end group S38x53_P19x23
79 
80 
81 #ifdef tt_INIT
82 // [str], tex
83 extern Boolean get_strings_started(void); // #47
84 #endif // tt_INIT
85 
86 // [str], dviout, tex
87 extern void str_map(StrNumber k, void (*f)(ASCIICode));
88 extern int str_length(StrNumber s);
89 
90 // [str][0] only
91 // NOTE: _not_use_
92 // extern void f_pool(StrNumber s);
93 
94 // [str][0], printout[1], tex[16]
95 extern void slow_print(StrNumber s);
96 
97 // [str], inipool, tex
99 extern StrNumber makestring(void);
100 
101 // [str], tex
102 extern StrPoolPtr str_mark(void); // [str][0], tex[2]
103 extern int str_cmp(StrNumber s, StrNumber t);
104 extern int str_getc(StrNumber s, int k);
105 extern void str_map_from_mark(StrPoolPtr b, void (*f)(ASCIICode));
106 extern void str_room(StrNumber l);
107 extern void str_set_init_ptrs(void);
108 extern void str_print_stats(FILE* f_log_file);
109 extern void str_dump(FILE* fmt_file);
110 extern int str_undump(FILE* fmt_file, FILE* _not_use_);
111 extern void str_cur_map(void (*f)(ASCIICode));
112 extern int cur_length(void);
113 extern void flush_string(void);
114 extern void flush_char(void); // texmax.h
115 extern StrNumber idlookup_s(StrNumber s, Boolean no_new_cs);
116 extern void printcurrentstring(void);
118 extern void append_char(ASCIICode s);
119 extern void str_print(StrNumber s);
120 extern int str_valid(StrNumber s);
121 extern Boolean str_bcmp(ASCIICode buffp[], long l, StrNumber s);
122 extern int str_scmp(StrNumber s, short* buffp);
123 extern StrNumber str_insert(ASCIICode buffp[], Integer l);
124 extern StrNumber str_ins(short* buffp, long l);
125 
126 // [inipool], str
127 extern Boolean str_pool_init(void); // inipool.c
128 
129 #endif // #ifndef STR_H
#define UMAXOF(t)
取无符号类型的最大值
Definition: global_macros.h:9
FILE * fmt_file
[#1305] [G_var] for input or output of format information.
Definition: dump.c:23
UChar ASCIICode
[#18]: ASCIICode::UChar(8) = [0, 255]
Definition: charset.h:11
#define MAX_STRINGS
[#11] maximum number of strings; must not exceed MAX_HALF_WORD.
Definition: str.h:23
#define POOL_SIZE
[#11] maximum number of characters in strings.
Definition: str.h:41
uint_fast32_t StrNumber
Definition: str.h:73
void flush_string(void)
[#44]: destroy the most recently made string.
Definition: str.c:69
int str_length(StrNumber s)
[#40]: the number of characters in string number x.
Definition: str.c:32
Boolean get_strings_started(void)
[#47]: initializes the string pool, but returns false if something goes wrong.
Definition: str.c:102
void str_room(StrNumber l)
[#42]: make sure that the pool hasn’t overflowed.
Definition: str.c:48
ASCIICode * PoolPtr
[#38] for variables that point into str_pool.
Definition: str.h:54
void flush_char(void)
[#42]: forget the last character in the pool.
Definition: str.c:45
StrNumber makestring(void)
[#43]: current string enters the pool.
Definition: str.c:60
int str_cmp(StrNumber s, StrNumber t)
比较两个 str 的差别。返回 0 为相同,非 0 为有差异。
Definition: str.c:75
char * Str
real string.
Definition: str.h:75
Boolean str_pool_init(void)
[p21#47] Make the first 256 strings, and copy all string in pool_strs[] to string pool.
Definition: str.c:128
int cur_length(void)
[#41]: The length of the current string.
Definition: str.c:35
Boolean str_eq_str(StrNumber s, StrNumber t)
[p21#46]: test equality of strings。
Definition: str.c:91
void append_char(ASCIICode s)
[#42]: put ASCII code s at the end of str_pool.
Definition: str.c:38
int str_valid(StrNumber s)
Definition: str.c:370
int str_undump(FILE *fmt_file, FILE *_not_use_)
Definition: str.c:254
void str_set_init_ptrs(void)
Definition: str.c:222
Boolean str_bcmp(ASCIICode buffp[], long l, StrNumber s)
Definition: str.c:386
void str_map(StrNumber k, void(*f)(ASCIICode))
Definition: str.c:337
StrPoolPtr str_mark(void)
Definition: str.c:227
void str_print_stats(FILE *f_log_file)
Definition: str.c:242
void slow_print(StrNumber s)
#60: prints string s
Definition: str.c:197
void printcurrentstring(void)
[#70] prints a yet-unmade string.
Definition: str.c:209
void str_print(StrNumber s)
Definition: str.c:347
void str_cur_map(void(*f)(ASCIICode))
Definition: str.c:329
int str_getc(StrNumber s, int k)
Definition: str.c:220
void str_map_from_mark(StrPoolPtr b, void(*f)(ASCIICode))
Definition: str.c:233
Integer str_adjust_to_room(Integer len)
Definition: str.c:321
StrNumber idlookup_s(StrNumber s, Boolean no_new_cs)
Definition: str.c:361
void str_dump(FILE *fmt_file)
Definition: str.c:290
StrNumber str_insert(ASCIICode buffp[], Integer l)
Definition: str.c:400
int str_scmp(StrNumber s, short *buffp)
Definition: str.c:374
StrNumber str_ins(short *buffp, long l)
Definition: str.c:391
Definition: str.h:66
PoolPtr val
Definition: str.h:67
int64_t Integer
Integer(64) =
Definition: tex_types.h:42
size_t Pointer
Pointer::size_t(64), a flag or a location in mem or eqtb.
Definition: tex_types.h:45
bool Boolean
布尔类型定义
Definition: tex_types.h:11