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

[tyndur-devel] [PATCH] kedit: NULL-Pointer abgefangen



* kedit: kedit_tui.pas: Wenn keine zu highlightende Datei geladen wird,
	 wird der entstehende NULL-Pointer abgefangen
* kedit: kedit_main.pas: Tabs zu Leerzeichen (ja kwolf, mecker ruhig *g*)

Signed-off-by: Alexander Hartmut Kluth <hartmut@xxxxxxxxxx>
---
 src/modules/pas/kedit/kedit_main.pas |   29 +++++++++++++++++++++++++----
 src/modules/pas/kedit/kedit_tui.pas  |   21 ++++++++++++++++++---
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas
index 18dbef7..0195ca3 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,10 +152,6 @@ begin
         Textbackground(0);
     end;
 
-    if loadname = '' then begin
-        exit;
-    end;
-
     if not FileExists(loadname) then begin
         if create then begin
             state^.filename := loadname;
@@ -167,6 +166,28 @@ 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;
+
+        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..f9bd5b7 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;
@@ -276,7 +278,7 @@ begin
     GotoXY(1,2);
     firstVisible := 1 + state^.scrolly;
     lastVisible := TextLines + state^.scrolly;
-    if not highlight then begin
+    if (not highlight) or (highlighter = nil) then begin
         for i := firstVisible to lastVisible do begin
             s := Copy(state^.text^[i], 1 + state^.scrollx, 80);
             Write(Utf8Encode(s));
@@ -357,6 +359,19 @@ 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;
+end;
+
+begin
+    highlighter := nil;
 end.
-- 
1.6.0.4