+/* The get_next_token() code reads characters into the current lextext,
+ which is lextexts[lex_index]. It uses these routines to add and remove
+ characters, reallocing when necessary.
+
+ lex_pos is the current number of characters in the lextext. It is
+ not necessarily null-terminated until get_next_token() completes.
+ */
+
+/* Add one character */
+static void lexaddc(char ch)
+{
+ if ((size_t)lex_pos >= lextexts[lex_index].size) {
+ size_t newsize = lextexts[lex_index].size * 2;
+ my_realloc(&lextexts[lex_index].text, lextexts[lex_index].size, newsize, "one lexeme text");
+ lextexts[lex_index].size = newsize;
+ }
+ lextexts[lex_index].text[lex_pos++] = ch;
+}
+
+/* Remove the last character and ensure it's null-terminated */
+static void lexdelc(void)
+{
+ if (lex_pos > 0) {
+ lex_pos--;
+ }
+ lextexts[lex_index].text[lex_pos] = 0;
+}
+
+/* Return the last character */
+static char lexlastc(void)
+{
+ if (lex_pos == 0) {
+ return 0;
+ }
+ return lextexts[lex_index].text[lex_pos-1];
+}
+
+/* Add a string of characters (including the null) */
+static void lexadds(char *str)
+{
+ while (*str) {
+ lexaddc(*str);
+ str++;
+ }
+ lexaddc(0);
+}
+