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

[tyndur-devel] [PATCH] kedit: Syntax-Highlighting für Pascal



Highlighting anhand der Dateiendung erkennen

* kedit: Ausinanderfrickeln der Dateiendung
* kedit: Ein Feld für die DateienEin Feld für die Dateiendung hinzugefügtt

Signed-off-by: Alexander Hartmut Kluth <hartmut@xxxxxxxxxx>
---
 src/modules/pas/kedit/kedit.pas      |    1 +
 src/modules/pas/kedit/kedit_main.pas |   20 ++++++++++++++++++++
 src/modules/pas/kedit/kedit_tui.pas  |   14 ++++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas
index 3542b07..bfca877 100644
--- a/src/modules/pas/kedit/kedit.pas
+++ b/src/modules/pas/kedit/kedit.pas
@@ -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..ab1412d 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);
@@ -167,6 +170,23 @@ begin
     end;
 
     with state^ do begin
+        loadname := Trim(loadname);
+
+        // Dateiendung herausbekommen
+        ext := RightStr(loadname, 4);
+
+        if CompareStr(ext, '.pas') <> 0 then begin
+            ext := RightStr(loadname, 2);
+
+            if CompareStr(ext, '.c') = 0 then begin
+                extension := 'c';
+            end;
+        end else begin
+            extension := 'pas';
+        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..c85cb97 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;
 
 var
     highlighter: TSyntax;
@@ -357,6 +358,15 @@ 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 begin
+        highlighter := TSyntax_Pas.create;
+    end;
+end;
+
+begin
+    highlighter := NIL;
 end.
-- 
1.6.0.4