| 145 | #define TAB_SIZE 4 |
| 146 | |
| 147 | static int textReadLine(char *buffer, int offset, int size, char *line) { |
| 148 | // Get line |
| 149 | int line_width = 0; |
| 150 | int count = 0; |
| 151 | |
| 152 | int i; |
| 153 | for (i = 0; i < MIN(size, MIN(size - offset, MAX_LINE_CHARACTERS - 1)); i++) { |
| 154 | char ch = buffer[offset + i]; |
| 155 | char ch_width = 0; |
| 156 | |
| 157 | // Line break |
| 158 | if (ch == '\n') { |
| 159 | i++; // Skip it |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | // Tab |
| 164 | if (ch == '\t') { |
| 165 | ch_width = TAB_SIZE * font_size_cache[' ']; |
| 166 | } else { |
| 167 | ch_width = font_size_cache[(int)ch]; |
| 168 | if (ch_width == 0) { |
| 169 | ch = ' '; // Change invalid characters to space |
| 170 | ch_width = font_size_cache[(int)ch]; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Too long |
| 175 | if ((line_width + ch_width) >= (MAX_WIDTH - TEXT_START_X + SHELL_MARGIN_X)) |
| 176 | break; |
| 177 | |
| 178 | // Increase line width |
| 179 | line_width += ch_width; |
| 180 | |
| 181 | // Add to line string |
| 182 | if (line) |
| 183 | line[count++] = ch; |
| 184 | } |
| 185 | |
| 186 | // End of line |
| 187 | if (line) |
| 188 | line[count] = '\0'; |
| 189 | |
| 190 | return i; |
| 191 | } |
| 192 | |
| 193 | static void updateTextEntry(TextEditorState *state, TextListEntry* entry, int rel_pos) { |
| 194 | entry->line_number = state->base_pos + rel_pos; |
no outgoing calls
no test coverage detected