2023-11-13 21:03:29 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
|
|
|
|
|
|
|
|
Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
|
|
|
|
And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
|
|
|
|
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CHAPTER_4_SOURCE
|
|
|
|
#define CHAPTER_4_SOURCE
|
|
|
|
|
|
|
|
#include "chapter_4.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2023-11-15 16:10:08 -05:00
|
|
|
void program_view_c_file (char * text_file, int width, int height, int x, int y) {
|
|
|
|
char * text_data;
|
|
|
|
|
|
|
|
curses_active = 1;
|
|
|
|
|
|
|
|
text_data = file_record (text_file);
|
|
|
|
|
|
|
|
while (curses_active != 0) {
|
|
|
|
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
|
|
|
|
curses_render_string (text_data, COLOUR_WHITE, EFFECT_NORMAL, x, x);
|
|
|
|
|
|
|
|
curses_synchronize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
text_data = deallocate (text_data);
|
|
|
|
}
|
|
|
|
|
2023-11-13 21:03:29 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
void program_view_c_file (char * text_file, int width, int height, int x, int y) {
|
|
|
|
char * text_data;
|
|
|
|
|
2023-11-15 16:10:08 -05:00
|
|
|
int reset_x = x;
|
|
|
|
int reset_y = y;
|
|
|
|
|
2023-11-13 21:03:29 -05:00
|
|
|
curses_active = 1;
|
|
|
|
|
|
|
|
text_data = file_record (text_file);
|
|
|
|
|
|
|
|
while (curses_active != 0) {
|
2023-11-15 16:10:08 -05:00
|
|
|
int offset, colour, effect, string;
|
|
|
|
|
2023-11-13 21:03:29 -05:00
|
|
|
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
|
2023-11-15 16:10:08 -05:00
|
|
|
|
|
|
|
x = reset_x;
|
|
|
|
y = reset_y;
|
|
|
|
|
|
|
|
string = 0;
|
|
|
|
colour = COLOUR_WHITE;
|
|
|
|
effect = EFFECT_NORMAL;
|
|
|
|
|
|
|
|
for (offset = 0; offset != string_length (text_data); ++offset) {
|
|
|
|
switch (text_data [offset]) {
|
|
|
|
case '"':
|
|
|
|
string = ! string;
|
|
|
|
colour = (string != 0) ? COLOUR_RED : COLOUR_WHITE;
|
|
|
|
effect = (string != 0) ? EFFECT_BOLD : EFFECT_NORMAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
curses_render_character (text_data [offset], colour, effect, x, y);
|
|
|
|
|
|
|
|
switch (text_data [offset]) {
|
|
|
|
case '\t': x += 8; break;
|
|
|
|
case '\n': y += 1; x = reset_x; break;
|
|
|
|
default: x += 1; break;
|
|
|
|
}
|
|
|
|
}
|
2023-11-13 21:03:29 -05:00
|
|
|
|
|
|
|
curses_synchronize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
text_data = deallocate (text_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|