[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 1/3] kedit: Syntax-Highlighting [1]



Bitte den davorgehenden Patch ignorieren, da war was mit meinen Branches
nicht in Ordnung!

* kedit: Eine elegante Lösung für das Herausfinden der Dateiendung gefunden

Signed-off-by: Alexander Hartmut Kluth <hartmut@xxxxxxxxxx>
---
 src/modules/pas/kedit/kedit.pas      |    3 ++-
 src/modules/pas/kedit/kedit_main.pas |   30 +++++++++++++++++++++++++++++-
 src/modules/pas/kedit/kedit_tui.pas  |   20 ++++++++++++++++++--
 3 files changed, 49 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..54da53e 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,29 @@ 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 RightStr(loadname, 4) = '.asm' then begin
+			extension := 'asm';
+		end else if RightStr(loadname, 2) = '.c' then begin
+			extension := 'c';
+		end else if RightStr(loadname, 2) = '.S' then begin 
+			extension := 's';
+		end else if RightStr(loadname, 2) = '.s' 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..976ba69 100644
--- a/src/modules/pas/kedit/kedit_tui.pas
+++ b/src/modules/pas/kedit/kedit_tui.pas
@@ -61,10 +61,12 @@ 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_intel,
+syntax_atandt;
 
 var
     highlighter: TSyntax;
@@ -357,6 +359,20 @@ begin
     flush(output);
 end;
 
+procedure SetSyntaxHighlighting(state: pkedit_state);
 begin
-    highlighter := TSyntax_C.create;
+    if state^.extension = 'c' then begin
+        highlighter := TSyntax_C.create;
+    end else if state^.extension = 'pas' then begin
+        highlighter := TSyntax_Pas.create;
+    end else if state^.extension = 'asm' then begin
+		highlighter := TSyntax_INTEL.create;
+    end else if state^.extension = 's' then begin
+        highlighter := TSyntax_ATANDT.create;
+    end else begin
+    end;
+end;
+
+begin
+    highlighter := nil;
 end.
-- 
1.6.0.4