[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH] kedit: Syntax-Highlighting
* kedit: Eine elegante Lösung für das Herausfinden der Dateiendung gefunden
Ersetzt den 2. Patch in der 3er-Patchfolge
Signed-off-by: Alexander Hartmut Kluth <hartmut@xxxxxxxxxx>
---
src/modules/pas/kedit/kedit.pas | 3 ++-
src/modules/pas/kedit/kedit_main.pas | 28 +++++++++++++++++++++++++++-
src/modules/pas/kedit/kedit_tui.pas | 17 +++++++++++++++--
3 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas
index 3542b07..5741842 100644
--- a/src/modules/pas/kedit/kedit.pas
+++ b/src/modules/pas/kedit/kedit.pas
@@ -12,7 +12,7 @@ var
state: kedit_state;
(***********************************************
- * Dummyfunktionen für LOST *
+ * Dummyfunktionen für tyndur *
***********************************************)
procedure DisableFlushing(var f: Textfile); external name 'disable_flushing';
@@ -61,6 +61,7 @@ var
begin
with state do begin
filename := '(unbenannt)';
+ extension := '';
highlight := false;
readonly := false;
diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas
index 18dbef7..17a393e 100644
--- a/src/modules/pas/kedit/kedit_main.pas
+++ b/src/modules/pas/kedit/kedit_main.pas
@@ -12,6 +12,7 @@ type
// Beschreibt einen offenen Puffer
kedit_state = record
filename: String;
+ extension: String;
cursX: longint;
cursY: longint;
@@ -141,6 +142,8 @@ var lfile: textfile;
i: integer;
attr: word;
s: String;
+ ext: String;
+ reversed: String;
begin
if loadname = '' then begin
Textbackground(1);
@@ -149,11 +152,13 @@ begin
Textbackground(0);
end;
+ Write(loadname);
+
if loadname = '' then begin
exit;
end;
- if not FileExists(loadname) then begin
+ if not FileExists(loadname) then begin
if create then begin
state^.filename := loadname;
exit;
@@ -167,6 +172,27 @@ begin
end;
with state^ do begin
+ loadname := Trim(loadname);
+
+ {
+ Dieses wundervolle Code-Konstrukt ist das Ergebnis
+ stundenlanger Codearbeit von Patrick Pokatilo a.k.a
+ the incredible SHyx0rmz und von Alexander H. Kluth a.k.a.
+ 'Pagefault-it!'-DerHartmut.
+ }
+ if RightStr(loadname, 4) = '.pas' then begin
+ extension := 'pas';
+ end else if CompareStr(RightStr(loadname, 4), '.asm') = 0 then begin
+ extension := 'asm';
+ end else if CompareStr(RightStr(loadname, 2), '.c') = 0 then begin
+ extension := 'c';
+ end else if CompareStr(RightStr(loadname, 2), '.S') = 0 then begin
+ extension := 's';
+ end else begin
+ end;
+
+ SetSyntaxHighlighting(state);
+
Assign(lfile,loadname);
GetFAttr(lfile, attr);
if attr and dos.ReadOnly = dos.ReadOnly then readonly := true;
diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas
index 13c7781..5e27981 100644
--- a/src/modules/pas/kedit/kedit_tui.pas
+++ b/src/modules/pas/kedit/kedit_tui.pas
@@ -61,10 +61,11 @@ function YesNoCancel(question: string; cancel: boolean): integer;
procedure RedrawLine(state: pkedit_state; y: longint);
procedure DrawTitleBar(state: pkedit_state);
procedure DrawEditor(state: pkedit_state);
+procedure SetSyntaxHighlighting(state: pkedit_state);
implementation
-uses crt, syntax;
+uses crt, strutils, sysutils, syntax, syntax_c, syntax_pas, syntax_nasm;
var
highlighter: TSyntax;
@@ -357,6 +358,18 @@ begin
flush(output);
end;
+procedure SetSyntaxHighlighting(state: pkedit_state);
begin
- highlighter := TSyntax_C.create;
+ if CompareStr(state^.extension, 'c') = 0 then begin
+ highlighter := TSyntax_C.create;
+ end else if CompareStr(state^.extension, 'pas') = 0 then begin
+ highlighter := TSyntax_Pas.create;
+ end else if CompareStr(state^.extension, 'asm') = 0 then begin
+ highlighter := TSyntax_NASM.create;
+ end else begin
+ end;
+end;
+
+begin
+ highlighter := nil;
end.
--
1.6.0.4