mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-11-27 03:09:59 +03:00
add CodeView to ISO
git-svn-id: svn://kolibrios.org@7592 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
36f4758c4b
commit
bf033b8aaa
@ -604,8 +604,9 @@ tup.append_table(extra_files, {
|
||||
{"kolibrios/drivers/drvinst.kex", PROGS .. "/cmm/drvinst/drvinst.com"},
|
||||
{"kolibrios/games/pig/pigex", PROGS .. "/cmm/examples/pigex.com"},
|
||||
{"kolibrios/games/the_bus/the_bus", PROGS .. "/cmm/the_bus/the_bus.com"},
|
||||
{"kolibrios/utils/dicty.kex", PROGS .. "/cmm/dicty/dicty.com"},
|
||||
{"kolibrios/utils/appearance", PROGS .. "/cmm/appearance/appearance.com"},
|
||||
{"kolibrios/utils/codeview", PROGS .. "/cmm/codeview/codeview.com"},
|
||||
{"kolibrios/utils/dicty.kex", PROGS .. "/cmm/dicty/dicty.com"},
|
||||
{"kolibrios/utils/netcheck", PROGS .. "/cmm/examples/netcheck.com"},
|
||||
})
|
||||
end -- tup.getconfig('NO_CMM') ~= 'full'
|
||||
|
6
programs/cmm/codeview/Tupfile.lua
Normal file
6
programs/cmm/codeview/Tupfile.lua
Normal file
@ -0,0 +1,6 @@
|
||||
if tup.getconfig("NO_CMM") ~= "" then return end
|
||||
if tup.getconfig("LANG") == "ru"
|
||||
then C_LANG = "LANG_RUS"
|
||||
else C_LANG = "LANG_ENG" -- this includes default case without config
|
||||
end
|
||||
tup.rule("codeview.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "codeview.com")
|
250
programs/cmm/codeview/codeview.c
Normal file
250
programs/cmm/codeview/codeview.c
Normal file
@ -0,0 +1,250 @@
|
||||
|
||||
#define MEMSIZE 4096 * 200
|
||||
|
||||
//libraries
|
||||
#include "..\lib\gui.h"
|
||||
#include "..\lib\draw_buf.h"
|
||||
#include "..\lib\list_box.h"
|
||||
#include "..\lib\cursor.h"
|
||||
#include "..\lib\collection.h"
|
||||
#include "..\lib\random.h"
|
||||
#include "..\lib\clipboard.h"
|
||||
|
||||
// *.obj libraries
|
||||
#include "..\lib\obj\box_lib.h"
|
||||
#include "..\lib\obj\libio.h"
|
||||
#include "..\lib\obj\libimg.h"
|
||||
#include "..\lib\obj\http.h"
|
||||
#include "..\lib\obj\iconv.h"
|
||||
|
||||
#include "..\lib\patterns\history.h"
|
||||
#include "..\lib\patterns\http_downloader.h"
|
||||
|
||||
_http http = {0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
char homepage[] = FROM "html\\homepage.htm""\0";
|
||||
char page_not_found[] = FROM "html\\page_not_found_en.htm""\0";
|
||||
|
||||
char version[]="C-- Code View";
|
||||
char accept_language[]= "Accept-Language: en\n";
|
||||
|
||||
#define URL_SERVICE_HOME "CodeView://home"
|
||||
|
||||
proc_info Form;
|
||||
|
||||
|
||||
dword TOOLBAR_H = 40;
|
||||
dword STATUSBAR_H = 0;
|
||||
|
||||
dword col_bg = 0xE3E2E2;
|
||||
dword panel_color = 0xE3E2E2;
|
||||
dword border_color = 0x8C8C8C;
|
||||
|
||||
bool debug_mode = false;
|
||||
bool old_tag_parser_mode = false;
|
||||
|
||||
bool open_in_a_new_window = false;
|
||||
|
||||
enum {
|
||||
REFRESH_BUTTON,
|
||||
EDIT_SOURCE,
|
||||
};
|
||||
|
||||
#include "..\TWB\TWB.c"
|
||||
#include "show_src.h"
|
||||
|
||||
char editURL[sizeof(URL)];
|
||||
int mouse_twb;
|
||||
edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19};
|
||||
|
||||
#define SKIN_Y 24
|
||||
|
||||
void main()
|
||||
{
|
||||
int i;
|
||||
int id;
|
||||
load_dll(boxlib, #box_lib_init,0);
|
||||
load_dll(libio, #libio_init,1);
|
||||
load_dll(libimg, #libimg_init,1);
|
||||
load_dll(iconv_lib, #iconv_open,0);
|
||||
if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
|
||||
WB1.list.SetFont(8, 14, 10011000b);
|
||||
WB1.list.no_selection = true;
|
||||
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
|
||||
loop() switch(WaitEvent())
|
||||
{
|
||||
case evMouse:
|
||||
edit_box_mouse stdcall (#address_box);
|
||||
mouse.get();
|
||||
if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
|
||||
scrollbar_v_mouse (#scroll_wv);
|
||||
if (WB1.list.first != scroll_wv.position)
|
||||
{
|
||||
WB1.list.first = scroll_wv.position;
|
||||
WB1.DrawPage();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case evButton:
|
||||
id=GetButtonID();
|
||||
if (1==id) ExitProcess();
|
||||
break;
|
||||
|
||||
case evKey:
|
||||
GetKeys();
|
||||
|
||||
if (SCAN_CODE_F5 == key_scancode) {
|
||||
OpenPage();
|
||||
}
|
||||
if (SCAN_CODE_F3 == key_scancode) {
|
||||
RunProgram("/rd/1/tinypad", #URL);
|
||||
}
|
||||
|
||||
if (address_box.flags & 0b10)
|
||||
{
|
||||
if (key_ascii == ASCII_KEY_ENTER) EventGoToPage();
|
||||
else {
|
||||
EAX = key_editbox;
|
||||
edit_box_key stdcall(#address_box);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#define KEY_SCROLL_N 11
|
||||
if (SCAN_CODE_UP == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyUp();
|
||||
if (SCAN_CODE_DOWN == key_scancode) for (i=0;i<KEY_SCROLL_N;i++) WB1.list.KeyDown();
|
||||
if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
|
||||
}
|
||||
break;
|
||||
|
||||
case evReDraw:
|
||||
DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0);
|
||||
GetProcessInfo(#Form, SelfInfo);
|
||||
if (Form.status_window>2) { DrawTitle(#header); break; }
|
||||
if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; }
|
||||
if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; }
|
||||
Draw_Window();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetElementSizes()
|
||||
{
|
||||
address_box.top = TOOLBAR_H/2-10;
|
||||
basic_line_h = calc(WB1.list.font_h * 130) / 100;
|
||||
address_box.left = address_box.top;
|
||||
address_box.width = Form.cwidth - address_box.left - address_box.left -14;
|
||||
WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
|
||||
Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
|
||||
WB1.list.wheel_size = 7 * basic_line_h;
|
||||
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
|
||||
WB1.list.visible = WB1.list.h;
|
||||
if (WB1.list.w!=WB1.DrawBuf.bufw) {
|
||||
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
|
||||
OpenPage();
|
||||
}
|
||||
}
|
||||
|
||||
void Draw_Window()
|
||||
{
|
||||
DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color);
|
||||
DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3);
|
||||
DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color);
|
||||
SetElementSizes();
|
||||
DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+4, 25,border_color);
|
||||
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg);
|
||||
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color);
|
||||
DrawEditBoxWebView();
|
||||
if (!header)
|
||||
OpenPage();
|
||||
else {
|
||||
WB1.DrawPage();
|
||||
DrawEditBoxWebView();
|
||||
}
|
||||
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col);
|
||||
}
|
||||
|
||||
void EventGoToPage()
|
||||
{
|
||||
if (!editURL[0]) {
|
||||
strcpy(#URL, URL_SERVICE_HOME);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(#URL, #editURL);
|
||||
}
|
||||
OpenPage();
|
||||
}
|
||||
|
||||
|
||||
void SetPageDefaults()
|
||||
{
|
||||
strcpy(#header, #version);
|
||||
WB1.list.count = WB1.list.first = 0;
|
||||
cur_encoding = CH_NULL;
|
||||
if (o_bufpointer) o_bufpointer = free(o_bufpointer);
|
||||
}
|
||||
|
||||
void OpenPage()
|
||||
{
|
||||
char getUrl[sizeof(URL)];
|
||||
strcpy(#editURL, #URL);
|
||||
history.add(#URL);
|
||||
if (!strncmp(#URL,"CodeView:",8))
|
||||
{
|
||||
SetPageDefaults();
|
||||
if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage));
|
||||
DrawEditBoxWebView();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_size stdcall (#URL);
|
||||
bufsize = EBX;
|
||||
if (bufsize)
|
||||
{
|
||||
free(bufpointer);
|
||||
bufpointer = malloc(bufsize);
|
||||
SetPageDefaults();
|
||||
ReadFile(0, bufsize, bufpointer, #URL);
|
||||
ShowCodeSource();
|
||||
WB1.LoadInternalPage(bufpointer, bufsize);
|
||||
}
|
||||
ShowPage();
|
||||
}
|
||||
}
|
||||
|
||||
DrawEditBoxWebView()
|
||||
{
|
||||
int skin_x_offset;
|
||||
DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color);
|
||||
DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color);
|
||||
address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
|
||||
address_box.offset = 0;
|
||||
edit_box_draw stdcall(#address_box);
|
||||
skin_x_offset = 51;
|
||||
img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, skin_x_offset, SKIN_Y);
|
||||
}
|
||||
|
||||
|
||||
void ShowPage()
|
||||
{
|
||||
DrawEditBoxWebView();
|
||||
if (!bufsize)
|
||||
{
|
||||
WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
|
||||
}
|
||||
else
|
||||
{
|
||||
WB1.Prepare();
|
||||
}
|
||||
}
|
||||
|
||||
void DrawStatusBar() {return;};
|
||||
void ClickLink() {return;};
|
||||
void EventShowLinkMenu() {return;};
|
||||
|
||||
char anchor[256];
|
||||
|
||||
stop:
|
5
programs/cmm/codeview/compile_en.bat
Normal file
5
programs/cmm/codeview/compile_en.bat
Normal file
@ -0,0 +1,5 @@
|
||||
@c-- CodeView.c
|
||||
@del CodeView
|
||||
@rename CodeView.com CodeView
|
||||
@del warning.txt
|
||||
@pause
|
12
programs/cmm/codeview/html/homepage.htm
Normal file
12
programs/cmm/codeview/html/homepage.htm
Normal file
@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Homepage</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<br>
|
||||
CodeView is a sipmle C--/C/C++ code viewer based on TWB component.
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
14
programs/cmm/codeview/html/page_not_found_en.htm
Normal file
14
programs/cmm/codeview/html/page_not_found_en.htm
Normal file
@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=cp-866" />
|
||||
<title>File not found</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1> File not found</h1>
|
||||
<ul>
|
||||
<li>
|
||||
Check page address, there may have been made a typo.<br>
|
||||
</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
122
programs/cmm/codeview/show_src.h
Normal file
122
programs/cmm/codeview/show_src.h
Normal file
@ -0,0 +1,122 @@
|
||||
enum { TAG, OPTION_VALUE, TEXT, COMMENT, INLINE_COMMENT, CODE };
|
||||
|
||||
|
||||
|
||||
char* C_HL_keywords[] = {
|
||||
"switch", "if", "while", "for", "break", "continue", "return", "else",
|
||||
"union", "typedef", "static", "class", "case", "#include",
|
||||
"volatile", "register", "sizeof", "typedef", "union", "goto", "const", "auto",
|
||||
"#define", "#endif", "#error", "#ifdef", "#ifndef", "#undef", "#if", "#else",
|
||||
"inline",
|
||||
|
||||
"int ", "dword ", "long ", "double ", "float ", "char ", "unsigned ", "signed ",
|
||||
"void ", "bool ", "enum ", "byte ", "word ", "struct ", "NULL", "loop", "stdcall ",
|
||||
":void ", ":int ", ":bool ", ":dword ", NULL
|
||||
};
|
||||
|
||||
dword ShowCodeSource()
|
||||
{
|
||||
dword new_buf, new_buf_start, i;
|
||||
int mode = CODE;
|
||||
|
||||
char spstr[64];
|
||||
dword keylen;
|
||||
dword keyn;
|
||||
dword keycolor;
|
||||
|
||||
new_buf = malloc(bufsize*10);
|
||||
new_buf_start = new_buf;
|
||||
sprintf(new_buf,"<html><head><body><pre>",#URL);
|
||||
new_buf += strlen(new_buf);
|
||||
for (i=bufpointer; i<bufpointer+bufsize; i++)
|
||||
{
|
||||
if ('<' == ESBYTE[i]) {
|
||||
strcpy(new_buf, "<");
|
||||
new_buf+=4;
|
||||
continue;
|
||||
}
|
||||
if ('>' == ESBYTE[i]) {
|
||||
strcpy(new_buf, ">");
|
||||
new_buf+=4;
|
||||
continue;
|
||||
}
|
||||
if (ESBYTE[i] >= '0') && (ESBYTE[i] <= '9') && (CODE == mode) {
|
||||
strcpy(new_buf, "<font color=#CF00FF>?</font>");
|
||||
ESBYTE[new_buf+20] = ESBYTE[i];
|
||||
new_buf+=28;
|
||||
if (ESBYTE[i+1] == 'x') {
|
||||
strcpy(new_buf, "<font color=#CF00FF>x</font>");
|
||||
new_buf+=28;
|
||||
i++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CODE == mode) && ('\"' == ESBYTE[i]) {
|
||||
mode = TEXT;
|
||||
strcpy(new_buf, "<font color=#080>\"");
|
||||
new_buf+=18;
|
||||
continue;
|
||||
}
|
||||
if (TEXT == mode) && ('\"' == ESBYTE[i]) {
|
||||
mode = CODE;
|
||||
strcpy(new_buf, "\"</font>");
|
||||
new_buf+=8;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! strncmp(i, "//", 2) ) && (mode == CODE) {
|
||||
mode = INLINE_COMMENT;
|
||||
strcpy(new_buf, "<font color=#999>//");
|
||||
new_buf+=19;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (INLINE_COMMENT == mode) {
|
||||
if (13 == ESBYTE[i]) {
|
||||
mode = CODE;
|
||||
strcpy(new_buf, "\13</font>");
|
||||
new_buf+=8;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (! strncmp(i, "/*", 2) ) {
|
||||
mode = COMMENT;
|
||||
strcpy(new_buf, "<font color=#999>/*");
|
||||
new_buf+=19;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (! strncmp(i, "*/", 2) ) {
|
||||
mode = CODE;
|
||||
strcpy(new_buf, "*/</font>");
|
||||
new_buf+=9;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CODE == mode) for (keyn=0; C_HL_keywords[keyn]!=NULL; keyn++)
|
||||
{
|
||||
keylen = strlen(C_HL_keywords[keyn]);
|
||||
if (! strncmp(i, C_HL_keywords[keyn], keylen) ) {
|
||||
|
||||
if (keyn<31) keycolor="#f00"; else keycolor="#00f";
|
||||
sprintf(#spstr, "<font color=%s>%s</font>", keycolor, C_HL_keywords[keyn]);
|
||||
strcpy(new_buf, #spstr);
|
||||
|
||||
new_buf += keylen + 24;
|
||||
i += keylen-1;
|
||||
goto _CONTINUE;
|
||||
}
|
||||
}
|
||||
ESBYTE[new_buf] = ESBYTE[i];
|
||||
new_buf++;
|
||||
_CONTINUE:
|
||||
}
|
||||
ESBYTE[new_buf] = 0;
|
||||
bufsize = new_buf - new_buf_start;
|
||||
free(bufpointer);
|
||||
bufpointer = new_buf_start;
|
||||
}
|
Loading…
Reference in New Issue
Block a user