From hartmut at tyndur.org Thu Sep 3 20:20:29 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Thu, 3 Sep 2009 20:20:29 +0200 Subject: [tyndur-devel] [PATCH] tyndur-fpc: Patch gepatcht Message-ID: <1252002029-21994-1-git-send-email-hartmut@tyndur.org> From: Alexander Hartmut Kluth * lbuilds: den fpc-Patch in 2.3.x gepatcht, funktioniert nun Signed-off-by: Alexander Hartmut Kluth --- patches/fpc/2.3.x/fpc-2.3.x.patch | 63 ++++++++++++++++++++----------------- 1 files changed, 34 insertions(+), 29 deletions(-) diff --git a/patches/fpc/2.3.x/fpc-2.3.x.patch b/patches/fpc/2.3.x/fpc-2.3.x.patch index 26eff56..3246fe4 100644 --- a/patches/fpc/2.3.x/fpc-2.3.x.patch +++ b/patches/fpc/2.3.x/fpc-2.3.x.patch @@ -1,15 +1,15 @@ Index: fpc/compiler/fpc =================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ fpc/compiler/fpc 2009-08-06 16:03:08.726695360 +0200 +--- /dev/null ++++ fpc/compiler/fpc @@ -0,0 +1,2 @@ +#!/bin/bash +echo /home/kevin/tyndur-fp-system/fpcbuild_2.0.4_exp/fpcsrc/compiler/ppc386 Index: fpc/compiler/i386/cputarg.pas =================================================================== ---- fpc.orig/compiler/i386/cputarg.pas 2008-05-20 01:00:27.000000000 +0200 -+++ fpc/compiler/i386/cputarg.pas 2009-08-06 16:03:08.730694280 +0200 -@@ -41,6 +41,9 @@ +--- fpc/compiler/i386/cputarg.pas.orig ++++ fpc/compiler/i386/cputarg.pas +@@ -41,6 +41,9 @@ implementation {$ifndef NOTARGETBSD} ,t_bsd {$endif} @@ -21,8 +21,8 @@ Index: fpc/compiler/i386/cputarg.pas {$endif} Index: fpc/compiler/systems/i_tyndur.pas =================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ fpc/compiler/systems/i_tyndur.pas 2009-08-06 16:14:32.434692840 +0200 +--- /dev/null ++++ fpc/compiler/systems/i_tyndur.pas @@ -0,0 +1,102 @@ +{ + Copyright (c) 1998-2002 by Peter Vreman @@ -83,8 +83,8 @@ Index: fpc/compiler/systems/i_tyndur.pas + staticClibext : '.a'; + staticClibprefix : 'lib'; + sharedClibprefix : 'lib'; -+ importlibprefix : 'libimp'; -+ importlibext : '.a'; ++ importlibprefix : ''; ++ importlibext : ''; + Cprefix : ''; + newline : #10; + dirsep : '/'; @@ -128,8 +128,8 @@ Index: fpc/compiler/systems/i_tyndur.pas +end. Index: fpc/compiler/systems/t_tyndur.pas =================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ fpc/compiler/systems/t_tyndur.pas 2009-08-06 16:03:08.734695720 +0200 +--- /dev/null ++++ fpc/compiler/systems/t_tyndur.pas @@ -0,0 +1,868 @@ +{ + Copyright (c) 1998-2008 by Peter Vreman @@ -1001,9 +1001,9 @@ Index: fpc/compiler/systems/t_tyndur.pas +end. Index: fpc/compiler/systems.pas =================================================================== ---- fpc.orig/compiler/systems.pas 2009-06-28 01:00:28.000000000 +0200 -+++ fpc/compiler/systems.pas 2009-08-06 16:03:08.738692440 +0200 -@@ -145,7 +145,8 @@ +--- fpc/compiler/systems.pas.orig ++++ fpc/compiler/systems.pas +@@ -145,7 +145,8 @@ interface system_x86_64_darwin, { 61 } system_avr_embedded, { 62 } system_i386_haiku, { 63 } @@ -1013,7 +1013,7 @@ Index: fpc/compiler/systems.pas ); type -@@ -831,6 +832,9 @@ +@@ -819,6 +820,9 @@ begin default_target(system_i386_linux); {$define default_target_set} {$endif} @@ -1025,9 +1025,9 @@ Index: fpc/compiler/systems.pas {$define default_target_set} Index: fpc/utils/fpcm/fpcmmain.pp =================================================================== ---- fpc.orig/utils/fpcm/fpcmmain.pp 2008-05-20 01:00:23.000000000 +0200 -+++ fpc/utils/fpcm/fpcmmain.pp 2009-08-06 16:03:08.742692280 +0200 -@@ -70,7 +70,7 @@ +--- fpc/utils/fpcm/fpcmmain.pp.orig ++++ fpc/utils/fpcm/fpcmmain.pp +@@ -70,7 +70,7 @@ interface o_linux,o_go32v2,o_win32,o_os2,o_freebsd,o_beos,o_haiku,o_netbsd, o_amiga,o_atari, o_solaris, o_qnx, o_netware, o_openbsd,o_wdosx, o_palmos,o_macos,o_darwin,o_emx,o_watcom,o_morphos,o_netwlibc, @@ -1036,7 +1036,7 @@ Index: fpc/utils/fpcm/fpcmmain.pp ); TTargetSet=array[tcpu,tos] of boolean; -@@ -92,14 +92,14 @@ +@@ -92,14 +92,14 @@ interface 'linux','go32v2','win32','os2','freebsd','beos','haiku','netbsd', 'amiga','atari','solaris', 'qnx', 'netware','openbsd','wdosx', 'palmos','macos','darwin','emx','watcom','morphos','netwlibc', @@ -1053,7 +1053,7 @@ Index: fpc/utils/fpcm/fpcmmain.pp ); { This table is kept OS,Cpu because it is easier to maintain (PFV) } -@@ -132,7 +132,8 @@ +@@ -132,7 +132,8 @@ interface { gba } ( false, false, false, false, false, true, false, false, false), { nds } ( false, false, false, false, false, true, false, false, false), { embedded }( true, true, true, true, true, true, true, true, true ), @@ -1065,30 +1065,35 @@ Index: fpc/utils/fpcm/fpcmmain.pp type Index: fpc/utils/fpcm/fpcmake.inc =================================================================== ---- fpc.orig/utils/fpcm/fpcmake.inc 2009-07-31 01:00:26.000000000 +0200 -+++ fpc/utils/fpcm/fpcmake.inc 2009-08-06 16:03:08.750693000 +0200 +--- fpc/utils/fpcm/fpcmake.inc.orig ++++ fpc/utils/fpcm/fpcmake.inc @@ -1,7 +1,7 @@ {$ifdef Delphi} -const fpcmakeini : array[0..218] of string[240]=( -+const fpcmakeini : array[0..219] of string[240]=( ++const fpcmakeini : array[0..220] of string[240]=( {$else Delphi} -const fpcmakeini : array[0..218,1..240] of char=( -+const fpcmakeini : array[0..219,1..240] of char=( ++const fpcmakeini : array[0..220,1..240] of char=( {$endif Delphi} ';'#010+ '; Templates used by fpcmake to create a Makefile from Makefile.fpc'#010+ -@@ -858,6 +858,14 @@ - 'SHO','RTSUFFIX=lnx'#010+ +@@ -877,6 +877,14 @@ const fpcmakeini : array[0..218,1..240] + 'SHORTSUFFIX=lnx'#010+ 'endif'#010+ #010+ + '# tyndur'#010+ -+ 'ifeq ($(OS_TARGET),tyndur)'#010+ ++ 'ifeq',' ($(OS_TARGET),tyndur)'#010+ + 'BATCHEXT=.lsh'#010+ + 'EXEEXT='#010+ -+ 'HASSHAREDLIB=1'#010+ ++ 'HASS','HAREDLIB=1'#010+ + 'SHORTSUFFIX=tyn'#010+ -+ 'endif'#010, ++ 'endif'#010+ + #010+ '# FreeBSD'#010+ 'ifeq ($(OS_TARGET),freebsd)'#010+ 'BATCHEXT=.sh'#010+ +@@ -2383,4 +2383,4 @@ + ' @$(ECHO) LCLDIR............... $(LCLDIR)'#010+ +- ' @$(ECHO) LCL Unit dir......... $(LC','LUNITDIR)'#010+ ++ ' @$(ECHO) LCL Unit dir.....','.... $(LCLUNITDIR)'#010+ + ' @$(ECHO) LCL Component dir.... $(LCLCOMPONENTDIR)'#010+ -- 1.6.0.4 From hartmut at tyndur.org Fri Sep 4 02:21:20 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 4 Sep 2009 02:21:20 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_kedit=3A_Syntax-Highlighting?= =?utf-8?q?_f=C3=BCr_Pascal?= Message-ID: <1252023680-12501-1-git-send-email-hartmut@tyndur.org> Syntax-Highlighting für Pascal hinzugefügt, weitere folgen (falls das hier so richtig ist) + kedit: Aufteilung in syntax.pas, syntax_*.pas für verschiedene Syntaxdateien * kedit: syntax.pas, Klasse TSyntax + kedit: syntax_c.pas, C-Syntax-Highlighting + kedit: syntax_pas.pas, Pascal-Syntax-Highlighting * kedit: kedit_main.pas, Dateiendungsprüfung, setzen des Highlightings * kedit: kedit_tui.pas, Prozedur zum Setzen des Highlightings Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/kedit_main.pas | 20 +++ src/modules/pas/kedit/kedit_tui.pas | 14 ++- src/modules/pas/kedit/syntax.pas | 195 ++---------------------------- src/modules/pas/kedit/syntax_c.pas | 197 ++++++++++++++++++++++++++++++ src/modules/pas/kedit/syntax_pas.pas | 222 ++++++++++++++++++++++++++++++++++ 5 files changed, 460 insertions(+), 188 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_c.pas create mode 100644 src/modules/pas/kedit/syntax_pas.pas 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. diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas index b382265..0f9950e 100644 --- a/src/modules/pas/kedit/syntax.pas +++ b/src/modules/pas/kedit/syntax.pas @@ -29,30 +29,18 @@ type property GetState: integer read f_state; end; - TSyntax_C = class(TSyntax) - public - procedure StartLine(s: String; state: integer); override; - function Next: TSyntaxChange; override; - end; - function SyntaxColor(c: TSyntaxColor): byte; function SyntaxBgColor(c: TSyntaxColor): byte; +function Matches(s: String; pos: integer; pattern: String): boolean; +function MatchesNumber(s: string; pos: integer): integer; +function MatchesKeyword(s: string; pos: integer; p: Array of String): integer; +function MatchesLabel(s: string; pos: integer): integer; +function MatchesType(s: string; pos: integer): integer; +function MatchesTrailingSpace(s: string; pos: integer): boolean; implementation - -const - Keywords_C: Array [1..15] of String = ( - 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', - 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' - ); - Types_C: Array [1..17] of String = ( - 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', - 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' - ); - - function SyntaxColor(c: TSyntaxColor): byte; begin case c of @@ -70,6 +58,7 @@ begin exit(8); end; + function SyntaxBgColor(c: TSyntaxColor): byte; begin case c of @@ -79,11 +68,13 @@ begin exit(0); end; + function Matches(s: String; pos: integer; pattern: String): boolean; begin Matches := (Copy(s, pos, length(pattern)) = pattern); end; + function MatchesNumber(s: String; pos: integer): integer; var i: integer; @@ -261,172 +252,4 @@ begin color := c; end; -procedure TSyntax_C.StartLine(s: String; state: integer); -begin - line := s; - f_state := state; - pos := 1; - - case f_state of - 1: color := syn_comment; - 2: color := syn_comment; - 3: color := syn_number; - 4: color := syn_string; - 5: color := syn_string_special; - 6: color := syn_keyword; - 7: color := syn_type; - 8: color := syn_label; - else color := syn_other; - end; -end; - -function TSyntax_C.Next: TSyntaxChange; -var - c: char; - tmp: integer; -begin - Next.posY := 0; - Next.color := color; - - while pos <= length(line) do begin - c := line[pos]; - - case f_state of - - 0: { Normaler Text } - case c of - '/': - if Matches(line, pos, '//') then begin - f_state := 1; - exit(Highlight(syn_comment)); - end else if Matches(line, pos, '/*') then begin - f_state := 2; - exit(Highlight(syn_comment)); - end; - - '0' .. '9', '-', '+': - begin - tmp := MatchesNumber(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_number); - Inc(pos, tmp); - f_state := 3; - exit; - end; - end; - - '#': - begin - if Copy(line, 1, pos - 1) = Space(pos - 1) then begin - f_state := 1; - exit(Highlight(syn_compiler)); - end; - end; - - '"': - begin - Next := Highlight(syn_string); - Inc(pos); - f_state := 4; - exit; - end; - ' ': - begin - if MatchesTrailingSpace(line, pos) then begin - Next := Highlight(syn_trailing_space); - pos := length(line) + 1; - exit; - end; - end; - - else - begin - tmp := MatchesKeyword(line, pos, Keywords_C); - if tmp <> 0 then begin - Next := Highlight(syn_keyword); - Inc(pos, tmp); - f_state := 6; - exit; - end; - - tmp := MatchesKeyword(line, pos, Types_C); - if tmp <> 0 then begin - Next := Highlight(syn_type); - Inc(pos, tmp); - f_state := 7; - exit; - end; - - tmp := MatchesType(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_type); - Inc(pos, tmp); - f_state := 7; - exit; - end; - - tmp := MatchesLabel(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_label); - Inc(pos, tmp); - f_state := 8; - exit; - end; - end; - end; - - 1: { Kommentar bis Zeilenende } - begin - pos := length(line); - break; - end; - - 2: { C-Kommentar } - if Matches(line, pos, '*/') then begin - f_state := 0; - Inc(pos, 2); - exit(Highlight(syn_other)); - end; - - 3, 6, 7, 8: { Ende eines gefaerbten Worts } - begin - f_state := 0; - exit(Highlight(syn_other)); - end; - - 4: { String } - case c of - '\': - begin - f_state := 5; - Next := Highlight(syn_string_special); - Inc(pos); - exit; - end; - - '"': - begin - f_state := 0; - Inc(pos); - exit(Highlight(syn_other)); - end; - end; - - 5: { Escaptes Zeichen in einem String } - begin - f_state := 4; - Inc(pos); - exit(Highlight(syn_string)); - end; - - end; - - Inc(pos); - end; - - if f_state in [1, 3, 4, 5] then begin - f_state := 0; - end; -end; - end. diff --git a/src/modules/pas/kedit/syntax_c.pas b/src/modules/pas/kedit/syntax_c.pas new file mode 100644 index 0000000..f7662cc --- /dev/null +++ b/src/modules/pas/kedit/syntax_c.pas @@ -0,0 +1,197 @@ +unit syntax_c; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_C = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_C: Array [1..15] of String = ( + 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', + 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' + ); + + Types_C: Array [1..17] of String = ( + 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', + 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' + ); + +procedure TSyntax_C.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_C.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + + 0: { Normaler Text } + case c of + '/': + if Matches(line, pos, '//') then begin + f_state := 1; + exit(Highlight(syn_comment)); + end else if Matches(line, pos, '/*') then begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '#': + begin + if Copy(line, 1, pos - 1) = Space(pos - 1) then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end; + end; + + '"': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_C); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Types_C); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { C-Kommentar } + if Matches(line, pos, '*/') then begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + '\': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end; + + '"': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. diff --git a/src/modules/pas/kedit/syntax_pas.pas b/src/modules/pas/kedit/syntax_pas.pas new file mode 100644 index 0000000..314f9f5 --- /dev/null +++ b/src/modules/pas/kedit/syntax_pas.pas @@ -0,0 +1,222 @@ +unit syntax_pas; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_Pas = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_Pas: Array [1..81] of String = ( + 'absolute', 'abstract', 'and', 'array', 'assembler', 'asm', + 'automated', 'begin', 'case', 'cdecl', + 'class', 'compilerprog', 'const', 'constructor', + 'deconstructor', 'default', 'deprecated', 'div', 'do', 'downto', + 'dynamic', 'else', 'end', 'export', 'external', 'far', + 'forward', 'finalization', 'for', + 'function', 'generic', 'goto', 'inline', 'if', 'implementation', 'in', + 'interface', 'label', 'message', 'mod', 'near', 'nil', 'not', + 'object', 'overlay', 'overload', 'override', 'of', 'or', 'packed', + 'platform', 'private', 'procedure', + 'program', 'property', 'protected', 'public', 'published', 'raise', + 'record', 'reintroduce', 'resourcestring', + 'repeat', 'sealed', 'set', 'shl', 'shr', 'specialize', 'stdcall', + 'then', 'threadvar', 'to', + 'type', 'unit', 'until', 'uses', 'var', 'virtual', 'while', 'with', + 'xor' + ); + + Types_Pas: Array [1..8] of String = ( + 'integer', 'byte', 'real', 'char', 'string', 'boolean', 'string', + 'file' + ); + + +procedure TSyntax_Pas.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_Pas.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + 0: + case c of + '{': + if Matches(line, pos, '{$') then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end else begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '(': + if Matches(line, pos, '(*') then begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '/': + if (Matches(line, pos, '//')) then begin + f_state := 1; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '''': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_Pas); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Types_Pas); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { Pascal-Kommentar } + if Matches(line, pos, '}') then begin + f_state := 0; + Inc(pos, 1); + exit(Highlight(syn_other)); + end else if Matches(line, pos, '*)') then begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + {'''''': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end;} + + '''': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. + -- 1.6.0.4 From kevin at tyndur.org Fri Sep 4 20:49:10 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 4 Sep 2009 20:49:10 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_kedit=3A_Syntax-Highlig?= =?iso-8859-1?q?hting_f=FCr_Pascal?= In-Reply-To: <1252023680-12501-1-git-send-email-hartmut@tyndur.org> References: <1252023680-12501-1-git-send-email-hartmut@tyndur.org> Message-ID: <20090904184907.GA4688@silvanus> On Fri, Sep 04, 2009 at 02:21:20AM +0200, Alexander Hartmut Kluth wrote: > Syntax-Highlighting für Pascal hinzugefügt, weitere folgen (falls das hier so > richtig ist) > > + kedit: Aufteilung in syntax.pas, syntax_*.pas für verschiedene Syntaxdateien > * kedit: syntax.pas, Klasse TSyntax > + kedit: syntax_c.pas, C-Syntax-Highlighting > + kedit: syntax_pas.pas, Pascal-Syntax-Highlighting > * kedit: kedit_main.pas, Dateiendungsprüfung, setzen des Highlightings > * kedit: kedit_tui.pas, Prozedur zum Setzen des Highlightings > > Signed-off-by: Alexander Hartmut Kluth Wie schon gesagt, das ist zu viel Zeug in einem Patch. Hier nochmal die Teilstücke, in die er unterteilt werden sollte: 1. Splitten der syntax.pas 2. Abhängig von der Endung aussuchen, wie gehighlightet wird 3. Pascal-Highlighting hinzufügen > --- > src/modules/pas/kedit/kedit_main.pas | 20 +++ > src/modules/pas/kedit/kedit_tui.pas | 14 ++- > src/modules/pas/kedit/syntax.pas | 195 ++---------------------------- > src/modules/pas/kedit/syntax_c.pas | 197 ++++++++++++++++++++++++++++++ > src/modules/pas/kedit/syntax_pas.pas | 222 ++++++++++++++++++++++++++++++++++ > 5 files changed, 460 insertions(+), 188 deletions(-) > create mode 100644 src/modules/pas/kedit/syntax_c.pas > create mode 100644 src/modules/pas/kedit/syntax_pas.pas > > 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 Hm, das sieht irgendwie sehr C-ig aus... In Pascal darf man ganz normal vergleichen: if ext <> '.pas' then ... Das zieht sich durch den ganzen Patch, da gibt es also ein paar Stellen zu ändern. Aber an dieser Stelle ist auch das nicht, was du willst, sondern eher if AnsiEndsStr('.pas', loadname) then ... Wenn nicht sogar eine allgemeingültige Implementierung, also den letzten Punkt suchen und einfach den ganzen Rest nehmen. > + 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; nil wird normal kleingeschrieben > end. > diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas > index b382265..0f9950e 100644 > --- a/src/modules/pas/kedit/syntax.pas > +++ b/src/modules/pas/kedit/syntax.pas > @@ -29,30 +29,18 @@ type > property GetState: integer read f_state; > end; > > - TSyntax_C = class(TSyntax) > - public > - procedure StartLine(s: String; state: integer); override; > - function Next: TSyntaxChange; override; > - end; > - > > function SyntaxColor(c: TSyntaxColor): byte; > function SyntaxBgColor(c: TSyntaxColor): byte; > +function Matches(s: String; pos: integer; pattern: String): boolean; > +function MatchesNumber(s: string; pos: integer): integer; > +function MatchesKeyword(s: string; pos: integer; p: Array of String): integer; > +function MatchesLabel(s: string; pos: integer): integer; > +function MatchesType(s: string; pos: integer): integer; > +function MatchesTrailingSpace(s: string; pos: integer): boolean; > > > implementation > - > -const > - Keywords_C: Array [1..15] of String = ( > - 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', > - 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' > - ); > - Types_C: Array [1..17] of String = ( > - 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', > - 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' > - ); > - > - > function SyntaxColor(c: TSyntaxColor): byte; > begin > case c of > @@ -70,6 +58,7 @@ begin > exit(8); > end; > > + > function SyntaxBgColor(c: TSyntaxColor): byte; > begin > case c of > @@ -79,11 +68,13 @@ begin > exit(0); > end; > > + > function Matches(s: String; pos: integer; pattern: String): boolean; > begin > Matches := (Copy(s, pos, length(pattern)) = pattern); > end; > > + > function MatchesNumber(s: String; pos: integer): integer; > var > i: integer; > @@ -261,172 +252,4 @@ begin > color := c; > end; > > -procedure TSyntax_C.StartLine(s: String; state: integer); > -begin > - line := s; > - f_state := state; > - pos := 1; > - > - case f_state of > - 1: color := syn_comment; > - 2: color := syn_comment; > - 3: color := syn_number; > - 4: color := syn_string; > - 5: color := syn_string_special; > - 6: color := syn_keyword; > - 7: color := syn_type; > - 8: color := syn_label; > - else color := syn_other; > - end; > -end; > - > -function TSyntax_C.Next: TSyntaxChange; > -var > - c: char; > - tmp: integer; > -begin > - Next.posY := 0; > - Next.color := color; > - > - while pos <= length(line) do begin > - c := line[pos]; > - > - case f_state of > - > - 0: { Normaler Text } > - case c of > - '/': > - if Matches(line, pos, '//') then begin > - f_state := 1; > - exit(Highlight(syn_comment)); > - end else if Matches(line, pos, '/*') then begin > - f_state := 2; > - exit(Highlight(syn_comment)); > - end; > - > - '0' .. '9', '-', '+': > - begin > - tmp := MatchesNumber(line, pos); > - if tmp <> 0 then begin > - Next := Highlight(syn_number); > - Inc(pos, tmp); > - f_state := 3; > - exit; > - end; > - end; > - > - '#': > - begin > - if Copy(line, 1, pos - 1) = Space(pos - 1) then begin > - f_state := 1; > - exit(Highlight(syn_compiler)); > - end; > - end; > - > - '"': > - begin > - Next := Highlight(syn_string); > - Inc(pos); > - f_state := 4; > - exit; > - end; > - ' ': > - begin > - if MatchesTrailingSpace(line, pos) then begin > - Next := Highlight(syn_trailing_space); > - pos := length(line) + 1; > - exit; > - end; > - end; > - > - else > - begin > - tmp := MatchesKeyword(line, pos, Keywords_C); > - if tmp <> 0 then begin > - Next := Highlight(syn_keyword); > - Inc(pos, tmp); > - f_state := 6; > - exit; > - end; > - > - tmp := MatchesKeyword(line, pos, Types_C); > - if tmp <> 0 then begin > - Next := Highlight(syn_type); > - Inc(pos, tmp); > - f_state := 7; > - exit; > - end; > - > - tmp := MatchesType(line, pos); > - if tmp <> 0 then begin > - Next := Highlight(syn_type); > - Inc(pos, tmp); > - f_state := 7; > - exit; > - end; > - > - tmp := MatchesLabel(line, pos); > - if tmp <> 0 then begin > - Next := Highlight(syn_label); > - Inc(pos, tmp); > - f_state := 8; > - exit; > - end; > - end; > - end; > - > - 1: { Kommentar bis Zeilenende } > - begin > - pos := length(line); > - break; > - end; > - > - 2: { C-Kommentar } > - if Matches(line, pos, '*/') then begin > - f_state := 0; > - Inc(pos, 2); > - exit(Highlight(syn_other)); > - end; > - > - 3, 6, 7, 8: { Ende eines gefaerbten Worts } > - begin > - f_state := 0; > - exit(Highlight(syn_other)); > - end; > - > - 4: { String } > - case c of > - '\': > - begin > - f_state := 5; > - Next := Highlight(syn_string_special); > - Inc(pos); > - exit; > - end; > - > - '"': > - begin > - f_state := 0; > - Inc(pos); > - exit(Highlight(syn_other)); > - end; > - end; > - > - 5: { Escaptes Zeichen in einem String } > - begin > - f_state := 4; > - Inc(pos); > - exit(Highlight(syn_string)); > - end; > - > - end; > - > - Inc(pos); > - end; > - > - if f_state in [1, 3, 4, 5] then begin > - f_state := 0; > - end; > -end; > - > end. > diff --git a/src/modules/pas/kedit/syntax_c.pas b/src/modules/pas/kedit/syntax_c.pas > new file mode 100644 > index 0000000..f7662cc > --- /dev/null > +++ b/src/modules/pas/kedit/syntax_c.pas > @@ -0,0 +1,197 @@ > +unit syntax_c; > +{$mode ObjFPC} > + > +interface > + > +uses syntax; > + > +type > + TSyntax_C = class(TSyntax) > + public > + procedure StartLine(s: String; state: integer); override; > + function Next: TSyntaxChange; override; > + end; > + > + > +implementation > +const > + Keywords_C: Array [1..15] of String = ( > + 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', > + 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' > + ); > + > + Types_C: Array [1..17] of String = ( > + 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', > + 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' > + ); > + > +procedure TSyntax_C.StartLine(s: String; state: integer); > +begin > + line := s; > + f_state := state; > + pos := 1; > + > + case f_state of > + 1: color := syn_comment; > + 2: color := syn_comment; > + 3: color := syn_number; > + 4: color := syn_string; > + 5: color := syn_string_special; > + 6: color := syn_keyword; > + 7: color := syn_type; > + 8: color := syn_label; > + else color := syn_other; > + end; > +end; > + > + > +function TSyntax_C.Next: TSyntaxChange; > +var > + c: char; > + tmp: integer; > +begin > + Next.posY := 0; > + Next.color := color; > + > + while pos <= length(line) do begin > + c := line[pos]; > + > + case f_state of > + > + 0: { Normaler Text } > + case c of > + '/': > + if Matches(line, pos, '//') then begin > + f_state := 1; > + exit(Highlight(syn_comment)); > + end else if Matches(line, pos, '/*') then begin > + f_state := 2; > + exit(Highlight(syn_comment)); > + end; > + > + '0' .. '9', '-', '+': > + begin > + tmp := MatchesNumber(line, pos); > + if tmp <> 0 then begin > + Next := Highlight(syn_number); > + Inc(pos, tmp); > + f_state := 3; > + exit; > + end; > + end; > + > + '#': > + begin > + if Copy(line, 1, pos - 1) = Space(pos - 1) then begin > + f_state := 1; > + exit(Highlight(syn_compiler)); > + end; > + end; > + > + '"': > + begin > + Next := Highlight(syn_string); > + Inc(pos); > + f_state := 4; > + exit; > + end; > + ' ': > + begin > + if MatchesTrailingSpace(line, pos) then begin > + Next := Highlight(syn_trailing_space); > + pos := length(line) + 1; > + exit; > + end; > + end; > + > + else > + begin > + tmp := MatchesKeyword(line, pos, Keywords_C); > + if tmp <> 0 then begin > + Next := Highlight(syn_keyword); > + Inc(pos, tmp); > + f_state := 6; > + exit; > + end; > + > + tmp := MatchesKeyword(line, pos, Types_C); > + if tmp <> 0 then begin > + Next := Highlight(syn_type); > + Inc(pos, tmp); > + f_state := 7; > + exit; > + end; > + > + tmp := MatchesType(line, pos); > + if tmp <> 0 then begin > + Next := Highlight(syn_type); > + Inc(pos, tmp); > + f_state := 7; > + exit; > + end; > + > + tmp := MatchesLabel(line, pos); > + if tmp <> 0 then begin > + Next := Highlight(syn_label); > + Inc(pos, tmp); > + f_state := 8; > + exit; > + end; > + end; > + end; > + > + 1: { Kommentar bis Zeilenende } > + begin > + pos := length(line); > + break; > + end; > + > + 2: { C-Kommentar } > + if Matches(line, pos, '*/') then begin > + f_state := 0; > + Inc(pos, 2); > + exit(Highlight(syn_other)); > + end; > + > + 3, 6, 7, 8: { Ende eines gefaerbten Worts } > + begin > + f_state := 0; > + exit(Highlight(syn_other)); > + end; > + > + 4: { String } > + case c of > + '\': > + begin > + f_state := 5; > + Next := Highlight(syn_string_special); > + Inc(pos); > + exit; > + end; > + > + '"': > + begin > + f_state := 0; > + Inc(pos); > + exit(Highlight(syn_other)); > + end; > + end; > + > + 5: { Escaptes Zeichen in einem String } > + begin > + f_state := 4; > + Inc(pos); > + exit(Highlight(syn_string)); > + end; > + > + end; > + > + Inc(pos); > + end; > + > + if f_state in [1, 3, 4, 5] then begin > + f_state := 0; > + end; > +end; > + > +end. > diff --git a/src/modules/pas/kedit/syntax_pas.pas b/src/modules/pas/kedit/syntax_pas.pas > new file mode 100644 > index 0000000..314f9f5 > --- /dev/null > +++ b/src/modules/pas/kedit/syntax_pas.pas > @@ -0,0 +1,222 @@ > +unit syntax_pas; > +{$mode ObjFPC} > + > +interface > + > +uses syntax; > + > +type > + TSyntax_Pas = class(TSyntax) > + public > + procedure StartLine(s: String; state: integer); override; > + function Next: TSyntaxChange; override; > + end; > + > + > +implementation > +const > + Keywords_Pas: Array [1..81] of String = ( > + 'absolute', 'abstract', 'and', 'array', 'assembler', 'asm', > + 'automated', 'begin', 'case', 'cdecl', > + 'class', 'compilerprog', 'const', 'constructor', > + 'deconstructor', 'default', 'deprecated', 'div', 'do', 'downto', > + 'dynamic', 'else', 'end', 'export', 'external', 'far', > + 'forward', 'finalization', 'for', > + 'function', 'generic', 'goto', 'inline', 'if', 'implementation', 'in', > + 'interface', 'label', 'message', 'mod', 'near', 'nil', 'not', > + 'object', 'overlay', 'overload', 'override', 'of', 'or', 'packed', > + 'platform', 'private', 'procedure', > + 'program', 'property', 'protected', 'public', 'published', 'raise', > + 'record', 'reintroduce', 'resourcestring', > + 'repeat', 'sealed', 'set', 'shl', 'shr', 'specialize', 'stdcall', > + 'then', 'threadvar', 'to', > + 'type', 'unit', 'until', 'uses', 'var', 'virtual', 'while', 'with', > + 'xor' > + ); > + > + Types_Pas: Array [1..8] of String = ( > + 'integer', 'byte', 'real', 'char', 'string', 'boolean', 'string', > + 'file' > + ); > + > + > +procedure TSyntax_Pas.StartLine(s: String; state: integer); > +begin > + line := s; > + f_state := state; > + pos := 1; > + > + case f_state of > + 1: color := syn_comment; > + 2: color := syn_comment; > + 3: color := syn_number; > + 4: color := syn_string; > + 5: color := syn_string_special; > + 6: color := syn_keyword; > + 7: color := syn_type; > + 8: color := syn_label; > + else color := syn_other; > + end; > +end; > + > + > +function TSyntax_Pas.Next: TSyntaxChange; > +var > + c: char; > + tmp: integer; > +begin > + Next.posY := 0; > + Next.color := color; > + > + while pos <= length(line) do begin > + c := line[pos]; > + > + case f_state of > + 0: > + case c of > + '{': > + if Matches(line, pos, '{$') then begin > + f_state := 1; Zustand 1 sieht nicht richtig aus, das ist Kommentar bis zum Zeilenende. In C funktioniert das, weil da eine Compileranweisung immer eine ganze Zeile lang ist. In Pascal kann das aber auch einfach mitten in der Zeile stehen: foo := {$IFDEF SIGNIFANT} bar {$ELSE} baz {$ENDIF}; > + exit(Highlight(syn_compiler)); > + end else begin > + f_state := 2; > + exit(Highlight(syn_comment)); > + end; > + > + '(': > + if Matches(line, pos, '(*') then begin > + f_state := 2; Für (* und { kannst du nicht denselben Zustand nehmen. Der Kommentar kann nur durch das passende Token wieder beendet werden: (* } Das hier ist immer noch Kommentar *) Richtig spaßig wird es, wenn wir FPC-kompatibel sein wollen, der kann nämlich verschachtelte Kommentare. Da müsste man noch irgendwo einen Zähler benutzen, in welcher Ebene wir momentan sind. > + exit(Highlight(syn_comment)); > + end; > + > + '/': > + if (Matches(line, pos, '//')) then begin > + f_state := 1; > + exit(Highlight(syn_comment)); > + end; > + > + '0' .. '9', '-', '+': > + begin > + tmp := MatchesNumber(line, pos); > + > + if tmp <> 0 then begin > + Next := Highlight(syn_number); > + Inc(pos, tmp); > + f_state := 3; > + exit; > + end; > + end; > + > + '''': > + begin > + Next := Highlight(syn_string); > + Inc(pos); > + f_state := 4; > + exit; > + end; > + > + ' ': > + begin > + if MatchesTrailingSpace(line, pos) then begin > + Next := Highlight(syn_trailing_space); > + pos := length(line) + 1; > + exit; > + end; > + end; > + > + else > + begin > + tmp := MatchesKeyword(line, pos, Keywords_Pas); Wir brauchen noch eine andere Funktion, die sowas wie MatchesKeyword macht, aber nicht Groß- und Kleinschreibung unterscheidet. FunCTiOn ist ein perfekt gültiges Pascal-Schlüsselwort. > + if tmp <> 0 then begin > + Next := Highlight(syn_keyword); > + Inc(pos, tmp); > + f_state := 6; > + exit; > + end; > + > + tmp := MatchesKeyword(line, pos, Types_Pas); > + if tmp <> 0 then begin > + Next := Highlight(syn_type); > + Inc(pos, tmp); > + f_state := 7; > + exit; > + end; > + > + tmp := MatchesType(line, pos); > + if tmp <> 0 then begin > + Next := Highlight(syn_type); > + Inc(pos, tmp); > + f_state := 7; > + exit; > + end; > + > + tmp := MatchesLabel(line, pos); > + if tmp <> 0 then begin > + Next := Highlight(syn_label); > + Inc(pos, tmp); > + f_state := 8; > + exit; > + end; > + end; > + end; > + > + 1: { Kommentar bis Zeilenende } > + begin > + pos := length(line); > + break; > + end; > + > + 2: { Pascal-Kommentar } > + if Matches(line, pos, '}') then begin > + f_state := 0; > + Inc(pos, 1); > + exit(Highlight(syn_other)); > + end else if Matches(line, pos, '*)') then begin > + f_state := 0; > + Inc(pos, 2); > + exit(Highlight(syn_other)); > + end; > + > + 3, 6, 7, 8: { Ende eines gefaerbten Worts } > + begin > + f_state := 0; > + exit(Highlight(syn_other)); > + end; > + > + 4: { String } > + case c of > + {'''''': > + begin > + f_state := 5; > + Next := Highlight(syn_string_special); > + Inc(pos); > + exit; > + end;} Auskommentierten Code vergessen? Aber die Idee ist schon richtig, auf doppeltes Anführungszeichen sollte man prüfen. Scheinst du unten nicht zu machen. > + > + '''': > + begin > + f_state := 0; > + Inc(pos); > + exit(Highlight(syn_other)); > + end; > + end; > + > + 5: { Escaptes Zeichen in einem String } > + begin > + f_state := 4; > + Inc(pos); > + exit(Highlight(syn_string)); > + end; > + > + end; > + > + Inc(pos); > + end; > + > + if f_state in [1, 3, 4, 5] then begin > + f_state := 0; > + end; > +end; > + > +end. > + > -- > 1.6.0.4 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From kevin at tyndur.org Fri Sep 4 23:59:29 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 4 Sep 2009 23:59:29 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Verbindung schliessen beim close() Message-ID: <1252101569-15423-1-git-send-email-kevin@tyndur.org> + tcpip: Wenn der Benutzer die Datei zumacht, sollten wir auch die TCP-Verbindung schliessen. Signed-off-by: Kevin Wolf --- src/modules/tcpip/include/tcp.h | 2 ++ src/modules/tcpip/lostio_if.c | 4 ++-- src/modules/tcpip/tcp.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/modules/tcpip/include/tcp.h b/src/modules/tcpip/include/tcp.h index b0b5917..c741ea8 100644 --- a/src/modules/tcpip/include/tcp.h +++ b/src/modules/tcpip/include/tcp.h @@ -44,6 +44,7 @@ #define TCPS_CONNECTED_FIN 4 #define TCPS_CLOSED 5 #define TCPS_WAIT_FOR_ACCEPT 6 +#define TCPS_WAIT_FOR_FIN_ACK 7 #define TCPF_FIN (1 << 0) #define TCPF_SYN (1 << 1) @@ -116,6 +117,7 @@ struct tcp_server { void init_tcp(void); struct tcp_connection* tcp_open_connection(dword ip, word port); +void tcp_close_connection(struct tcp_connection* conn); void tcp_free_connection(struct tcp_connection* conn); void tcp_accept_connection(struct tcp_connection* conn); diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c index b79ebf8..1f3b428 100644 --- a/src/modules/tcpip/lostio_if.c +++ b/src/modules/tcpip/lostio_if.c @@ -337,15 +337,15 @@ int lostio_tcp_close(lostio_filehandle_t* filehandle) free(buffer->data); free(buffer); } + v(); - // TODO tcp_connection_close + tcp_close_connection(conn); /* * TODO Reaktivieren, sobald die Verbindungen nicht mehr hartkodiert sind if (--(filehandle->node->size) == 0) { vfstree_delete_node(filehandle->node->name); } */ - v(); return 0; } diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index b8a7f0f..60fb896 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -179,6 +179,7 @@ static void tcp_send_reset(struct tcp_connection* conn) static void tcp_send_fin(struct tcp_connection* conn, bool ack) { tcp_send_packet(conn, NULL, 0, TCPF_FIN | (ack ? TCPF_ACK : 0)); + conn->seq++; } static void do_nothing(void) {} @@ -265,6 +266,30 @@ void tcp_free_connection(struct tcp_connection* conn) free(conn); } +void tcp_close_connection(struct tcp_connection* conn) +{ + uint64_t timeout; + + DEBUG_MSG("tcp_send_fin_ack"); + conn->status = TCPS_WAIT_FOR_FIN_ACK; + tcp_send_fin(conn, FALSE); + + timeout = get_tick_count() + 9 * 1000000; + timer_register(do_nothing, 10 * 1000000); + while ((conn->status == TCPS_WAIT_FOR_FIN_ACK) + && (get_tick_count() < timeout)) + { + wait_for_rpc(); + } + + if (conn->status == TCPS_WAIT_FOR_FIN_ACK) { + tcp_send_reset(conn); + DEBUG_MSG("Timeout beim Schliessen der Verbindung"); + } + + tcp_free_connection(conn); +} + void tcp_accept_connection(struct tcp_connection* conn) { DEBUG_MSG("tcp_send_syn_ack"); @@ -512,6 +537,15 @@ void tcp_receive(dword source_ip, void* data, dword data_size) }*/ break; + case TCPS_WAIT_FOR_FIN_ACK: + if ((header->flags & TCPF_FIN) && (header->flags & TCPF_ACK)) { + DEBUG_MSG("FIN ACK erhalten"); + conn->ack = big_endian_dword(header->seq) + 1; + tcp_send_ack(conn); + conn->status = TCPS_CLOSED; + } + break; + case TCPS_WAIT_FOR_LAST_ACK: // TODO: Pr�fen, ob f�r das richtige Segment DEBUG_MSG("ACK"); -- 1.6.0.2 From toni at tyndur.org Sat Sep 5 00:14:05 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 5 Sep 2009 00:14:05 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Verbindung schliessen beim close() In-Reply-To: <1252101569-15423-1-git-send-email-kevin@tyndur.org> References: <1252101569-15423-1-git-send-email-kevin@tyndur.org> Message-ID: <20090904221405.GA18167@neo.geekcave.lan> On Fri, Sep 04 23:59, Kevin Wolf wrote: > + tcpip: Wenn der Benutzer die Datei zumacht, sollten wir auch die > TCP-Verbindung schliessen. > > Signed-off-by: Kevin Wolf Sieht vernünftig aus. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Sep 5 10:37:04 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 5 Sep 2009 10:37:04 +0200 Subject: [tyndur-devel] [PATCH] Mehrere ISRs pro IRQ In-Reply-To: <1251633202-21166-1-git-send-email-max@tyndur.org> References: <1251633202-21166-1-git-send-email-max@tyndur.org> Message-ID: <20090905083703.GA8175@silvanus> On Sun, Aug 30, 2009 at 01:53:22PM +0200, max at tyndur.org wrote: > From: Max Reitz > > Signed-off-by: Max Reitz > --- > src/kernel/src/intr.c | 76 +++++++++++++++++++++++++++++++------------------ > 1 files changed, 48 insertions(+), 28 deletions(-) Der Patch macht übrigens irgendwas kaputt. Ich hatte ihn gestern versehentlich eincheckt, muss ihn jetzt reverten... From kevin at tyndur.org Sat Sep 5 11:04:17 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 5 Sep 2009 11:04:17 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Konfigurationsdateien haben ein Nullbyte zuviel Message-ID: <1252141457-22050-1-git-send-email-kevin@tyndur.org> ! tcpip: An Ende von IP und MAC gehoert kein Nullbyte. kedit zeigt das naemlich sogar an. Signed-off-by: Kevin Wolf --- src/modules/tcpip/lostio_if.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c index 1f3b428..a849f18 100644 --- a/src/modules/tcpip/lostio_if.c +++ b/src/modules/tcpip/lostio_if.c @@ -361,7 +361,7 @@ size_t lostio_netconfig_read(lostio_filehandle_t *handle, void *buf, size_t bloc // //mac else if (handle->node->size == 2) data = mac_to_string(device->dev.mac); - size_t size = strlen(data) + 1; + size_t size = strlen(data); if (handle->pos >= size) { handle->flags |= LOSTIO_FLAG_EOF; -- 1.6.0.2 From toni at tyndur.org Sat Sep 5 11:40:58 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 5 Sep 2009 11:40:58 +0200 Subject: [tyndur-devel] [PATCH 4/6] libc: POSIX: fcntl In-Reply-To: <1250454132-11413-5-git-send-email-kevin@tyndur.org> References: <1250454132-11413-1-git-send-email-kevin@tyndur.org> <1250454132-11413-5-git-send-email-kevin@tyndur.org> Message-ID: <20090905094057.GA20179@neo.geekcave.lan> On Sun, Aug 16 22:22, Kevin Wolf wrote: > + libc: POSIX: Ungefaehr ganz genau jedes Programm braucht diese > Funktion, implementieren wir halt mal irgendwas, was so aehnlich > aussieht. Flags, die gesetzt werden, koennen wieder abgeholt werden, > aber haben ansonsten keine Auswirkungen. > - libc: O_BINARY ist kein POSIX, wir unterscheiden nicht zwischen Text- > und Binaerdateien und das Gegenstueck O_TEXT fehlt auch. > > Signed-off-by: Kevin Wolf > --- > src/modules/include/fcntl.h | 20 ++++++++- > src/modules/lib/posix/posix_files.c | 83 ++++++++++++++++++++++++++++++++++- > 2 files changed, 101 insertions(+), 2 deletions(-) > > diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c > index d8c17e6..4c1cf90 100644 > --- a/src/modules/lib/posix/posix_files.c > +++ b/src/modules/lib/posix/posix_files.c Hm irgendwie fehlt mir da noch eine stdarg.h, oder übersehe ich da was? > @@ -38,6 +38,9 @@ > struct fd_list_element { > FILE* io_res; > int fd; > + > + int fd_flags; > + int file_flags; > }; > > /// Liste mit den Dateideskriptoren > @@ -104,6 +107,8 @@ int fileno(FILE* io_res) > > fdl_element->io_res = io_res; > fdl_element->fd = next_fd++; > + fdl_element->fd_flags = 0; > + fdl_element->file_flags = 0; > } > > return fdl_element->fd; > @@ -149,6 +154,77 @@ FILE* fdopen(int fd, const char* mode) > } > > /** > + * Fuehrt unterschiedliche Aktionen (F_*) auf Dateien aus > + */ > +int fcntl(int fd, int cmd, ...) > +{ > + // Liste mit den Dateideskriptoren durchsuchen > + struct fd_list_element* fdl_element = NULL; > + int i = 0; > + while ((fdl_element = list_get_element_at(fd_list, i))) { > + if (fdl_element->fd == fd) { > + break; > + } > + i++; > + } > + > + if (fdl_element == NULL) { > + errno = EBADF; > + return -1; > + } > + > + // Aktion durchfuehren > + switch (cmd) { > + case F_GETFD: > + return fdl_element->fd_flags; > + > + case F_GETFL: > + return fdl_element->file_flags; > + > + case F_SETFD: > + { > + va_list ap; > + int arg; > + > + va_start(ap, cmd); > + arg = va_arg(ap, int); > + va_end(ap); > + > + if (arg != fdl_element->fd_flags) { > + fprintf(stderr, "Warnung: S_SETFD ??ndert Flags (%#x => %#x) " > + "ohne Effekt\n", fdl_element->fd_flags, arg); > + } > + > + fdl_element->fd_flags = arg; > + return 0; > + } > + > + case F_SETFL: > + { > + va_list ap; > + int arg; > + > + va_start(ap, cmd); > + arg = va_arg(ap, int); > + va_end(ap); > + > + // Wenn die Flags bisher 0 sind, ist es open, das aendert. In > + // diesem Fall wollen wir keine Warnung. > + if ((arg != fdl_element->file_flags) && fdl_element->file_flags) { > + fprintf(stderr, "Warnung: S_SETFL ??ndert Flags (%#x => %#x) " > + "ohne Effekt\n", fdl_element->file_flags, arg); > + } > + > + fdl_element->file_flags = arg; > + return 0; > + } > + } > + > + errno = EINVAL; > + return -1; > +} > + > +/** > * Eine Datei als Unix-Dateideskriptor oeffnen > * > * @param filename Dateiname > @@ -161,6 +237,7 @@ int open(const char* filename, int flags, ...) > { > char fopen_flags[4]; > size_t flags_size = 0; > + int fd; > > // Wenn O_CREAT und O_EXCL gleichzeitig gesetzt ist, muessen wir abbrechen > // wenn die Datei existiert. > @@ -217,7 +294,11 @@ int open(const char* filename, int flags, ...) > errno = ENOENT; > return -1; > } > - return fileno(file); > + > + fd = fileno(file); > + fcntl(fd, F_SETFL, flags); > + > + return fd; > } > > /** Sonst sieht das vernünftig aus, glaube ich. ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Sep 5 13:21:15 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 5 Sep 2009 13:21:15 +0200 Subject: [tyndur-devel] [PATCH 0/3] Veraenderbare Tastaturbelegung Message-ID: <1252149678-24099-1-git-send-email-kevin@tyndur.org> Diese Patchserie bastelt ein LIO-Interface fuer die Tastaturbelegung in vterm. Tastaturbelegung wechseln geht damit so: file:/# cp system/keymaps/us.kdb vterm:/keymap Kevin Wolf (3): vterm: include-Verzeichnis anlegen vterm: Tastaturbelegung aenderbar machen vterm: Tastaturbelegungen de und us src/modules/vterm/Makefile.all | 2 +- src/modules/vterm/include/keymap.h | 79 ++++++++++++++ src/modules/vterm/keymap.c | 181 +++++++++----------------------- src/modules/vterm/keymap.h | 59 ---------- src/modules/vterm/keymaps/Makefile.all | 10 ++ src/modules/vterm/keymaps/de.c | 167 +++++++++++++++++++++++++++++ src/modules/vterm/keymaps/us.c | 167 +++++++++++++++++++++++++++++ src/modules/vterm/lostio.c | 10 ++ src/modules/vterm/vterm.c | 4 + src/modules/vterm/vterm.h | 1 + 10 files changed, 489 insertions(+), 191 deletions(-) create mode 100644 src/modules/vterm/include/keymap.h delete mode 100644 src/modules/vterm/keymap.h create mode 100644 src/modules/vterm/keymaps/Makefile.all create mode 100644 src/modules/vterm/keymaps/de.c create mode 100644 src/modules/vterm/keymaps/us.c From kevin at tyndur.org Sat Sep 5 13:21:16 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 5 Sep 2009 13:21:16 +0200 Subject: [tyndur-devel] [PATCH 1/3] vterm: include-Verzeichnis anlegen In-Reply-To: <1252149678-24099-1-git-send-email-kevin@tyndur.org> References: <1252149678-24099-1-git-send-email-kevin@tyndur.org> Message-ID: <1252149678-24099-2-git-send-email-kevin@tyndur.org> * vterm: Header in einem include-Verzeichnis koennen auch von Unterverzeichnissen benutzt werden; solche im Hauptverzeichnis nicht. Signed-off-by: Kevin Wolf --- src/modules/vterm/include/keymap.h | 59 ++++++++++++++++++++++++++++++++++++ src/modules/vterm/keymap.h | 59 ------------------------------------ 2 files changed, 59 insertions(+), 59 deletions(-) create mode 100644 src/modules/vterm/include/keymap.h delete mode 100644 src/modules/vterm/keymap.h diff --git a/src/modules/vterm/include/keymap.h b/src/modules/vterm/include/keymap.h new file mode 100644 index 0000000..668067e --- /dev/null +++ b/src/modules/vterm/include/keymap.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _KEYMAP_H_ +#define _KEYMAP_H_ +#include +#include + +/** + * Eintrag in der Keymap + */ +typedef struct keymap_entry { + wchar_t normal; + wchar_t shift; + wchar_t altgr; + wchar_t ctrl; +} keymap_entry_t; + +/** + * Eintrag aus der Keymap auslesen + * + * @return Pointer auf den Eintrag oder NULL wenn keiner existiert + */ +keymap_entry_t* keymap_get(uint8_t keycode); + +#endif // ifndef _KEYMAP_H_ + diff --git a/src/modules/vterm/keymap.h b/src/modules/vterm/keymap.h deleted file mode 100644 index 668067e..0000000 --- a/src/modules/vterm/keymap.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2008 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the tyndur Project - * and its contributors. - * 4. Neither the name of the tyndur Project nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _KEYMAP_H_ -#define _KEYMAP_H_ -#include -#include - -/** - * Eintrag in der Keymap - */ -typedef struct keymap_entry { - wchar_t normal; - wchar_t shift; - wchar_t altgr; - wchar_t ctrl; -} keymap_entry_t; - -/** - * Eintrag aus der Keymap auslesen - * - * @return Pointer auf den Eintrag oder NULL wenn keiner existiert - */ -keymap_entry_t* keymap_get(uint8_t keycode); - -#endif // ifndef _KEYMAP_H_ - -- 1.6.0.2 From kevin at tyndur.org Sat Sep 5 13:21:17 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 5 Sep 2009 13:21:17 +0200 Subject: [tyndur-devel] [PATCH 2/3] vterm: Tastaturbelegung aenderbar machen In-Reply-To: <1252149678-24099-1-git-send-email-kevin@tyndur.org> References: <1252149678-24099-1-git-send-email-kevin@tyndur.org> Message-ID: <1252149678-24099-3-git-send-email-kevin@tyndur.org> + vterm: Ueber die Datei vterm:/keymap kann die Tastaturbelegung veraendert werden Signed-off-by: Kevin Wolf --- src/modules/vterm/include/keymap.h | 18 +++++++++++++ src/modules/vterm/keymap.c | 50 ++++++++++++++++++++++++++++++++++++ src/modules/vterm/lostio.c | 10 +++++++ src/modules/vterm/vterm.c | 4 +++ src/modules/vterm/vterm.h | 1 + 5 files changed, 83 insertions(+), 0 deletions(-) diff --git a/src/modules/vterm/include/keymap.h b/src/modules/vterm/include/keymap.h index 668067e..dcbc0ba 100644 --- a/src/modules/vterm/include/keymap.h +++ b/src/modules/vterm/include/keymap.h @@ -37,6 +37,7 @@ #define _KEYMAP_H_ #include #include +#include /** * Eintrag in der Keymap @@ -55,5 +56,22 @@ typedef struct keymap_entry { */ keymap_entry_t* keymap_get(uint8_t keycode); +/** + * Legt die vterm:/keymap im Verzeichnisbaum an + */ +void keymap_init(void); + +/** + * LostIO-Handller um die Tastaturbelegung zu lesen + */ +size_t keymap_read(lostio_filehandle_t* file, void* buf, + size_t blocksize, size_t blockcount); + +/** + * LostIO-Handler um die Tastaturbelegung zu aendern + */ +size_t keymap_write(lostio_filehandle_t* file, size_t blocksize, + size_t blockcount, void* data); + #endif // ifndef _KEYMAP_H_ diff --git a/src/modules/vterm/keymap.c b/src/modules/vterm/keymap.c index 4b5846f..c1881bd 100644 --- a/src/modules/vterm/keymap.c +++ b/src/modules/vterm/keymap.c @@ -33,6 +33,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + +#include "vterm.h" #include "keymap.h" keymap_entry_t keymap[] = { @@ -176,3 +180,49 @@ keymap_entry_t* keymap_get(uint8_t keycode) return &keymap[keycode]; } +/** + * Legt die vterm:/keymap im Verzeichnisbaum an + */ +void keymap_init(void) +{ + stdout = NULL; + vfstree_create_node("/keymap", LOSTIO_TYPES_KEYMAP, 0, NULL, 0); +} + +/** + * LostIO-Handller um die Tastaturbelegung zu lesen + */ +size_t keymap_read(lostio_filehandle_t* file, void* buf, + size_t blocksize, size_t blockcount) +{ + size_t size = blocksize * blockcount; + + if (file->pos + size >= sizeof(keymap)) { + size = sizeof(keymap) - file->pos; + file->flags |= LOSTIO_FLAG_EOF; + } + + memcpy(buf, ((uint8_t*) keymap) + file->pos, size); + file->pos += size; + + return size; +} + +/** + * LostIO-Handler um die Tastaturbelegung zu aendern + */ +size_t keymap_write(lostio_filehandle_t* file, size_t blocksize, + size_t blockcount, void* buf) +{ + size_t size = blocksize * blockcount; + + if (file->pos + size >= sizeof(keymap)) { + size = sizeof(keymap) - file->pos; + file->flags |= LOSTIO_FLAG_EOF; + } + + memcpy(((uint8_t*) keymap) + file->pos, buf, size); + file->pos += size; + + return size; +} diff --git a/src/modules/vterm/lostio.c b/src/modules/vterm/lostio.c index a835d6a..1470fa7 100644 --- a/src/modules/vterm/lostio.c +++ b/src/modules/vterm/lostio.c @@ -35,8 +35,11 @@ #include #include #include + #include "vterm.h" #include "lostio.h" +#include "keymap.h" + /// Handler fuer Lesen aus in size_t terminal_read(lostio_filehandle_t* handle, void* buf, size_t blocksize, size_t blockcount); @@ -83,6 +86,13 @@ void init_lostio_interface() typehandle->link = NULL; typehandle->unlink = NULL; lostio_register_typehandle(typehandle); + + // Typehandle fuer Keymaps + typehandle = calloc(1, sizeof(typehandle_t)); + typehandle->id = LOSTIO_TYPES_KEYMAP; + typehandle->read = &keymap_read; + typehandle->write = &keymap_write; + lostio_register_typehandle(typehandle); } /** diff --git a/src/modules/vterm/vterm.c b/src/modules/vterm/vterm.c index d3fcd7f..d27fbc6 100644 --- a/src/modules/vterm/vterm.c +++ b/src/modules/vterm/vterm.c @@ -41,6 +41,7 @@ #include "vterm.h" #include "sleep.h" #include "init.h" +#include "keymap.h" /// Hier kommen die Eingaben fuer all die virtuellen Terminals her @@ -67,6 +68,9 @@ int main(int argc, char* argv[]) return -1; } + // Tastaturbelegung konfigurierbar machen + keymap_init(); + // Auf Anfragen warten while(TRUE) { wait_for_rpc(); diff --git a/src/modules/vterm/vterm.h b/src/modules/vterm/vterm.h index d5149da..0871db9 100644 --- a/src/modules/vterm/vterm.h +++ b/src/modules/vterm/vterm.h @@ -39,6 +39,7 @@ #define LOSTIO_TYPES_OUT 255 #define LOSTIO_TYPES_IN 254 +#define LOSTIO_TYPES_KEYMAP 253 #define SCREEN_WIDTH_MAX 80 #define SCREEN_HEIGHT_MAX 25 -- 1.6.0.2 From kevin at tyndur.org Sat Sep 5 13:21:18 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 5 Sep 2009 13:21:18 +0200 Subject: [tyndur-devel] [PATCH 3/3] vterm: Tastaturbelegungen de und us In-Reply-To: <1252149678-24099-1-git-send-email-kevin@tyndur.org> References: <1252149678-24099-1-git-send-email-kevin@tyndur.org> Message-ID: <1252149678-24099-4-git-send-email-kevin@tyndur.org> * vterm: Deutsche Tastaturbelegung auslagern und in system/keymaps verfuegbar machen, aber weiterhin als Default dazulinken. + vterm: Amerikanische Tastaturbelegung. Nur kompilieren und nach system/keymaps kopieren. Signed-off-by: Kevin Wolf --- src/modules/vterm/Makefile.all | 2 +- src/modules/vterm/include/keymap.h | 2 + src/modules/vterm/keymap.c | 131 ------------------------- src/modules/vterm/keymaps/Makefile.all | 10 ++ src/modules/vterm/keymaps/de.c | 167 ++++++++++++++++++++++++++++++++ src/modules/vterm/keymaps/us.c | 167 ++++++++++++++++++++++++++++++++ 6 files changed, 347 insertions(+), 132 deletions(-) create mode 100644 src/modules/vterm/keymaps/Makefile.all create mode 100644 src/modules/vterm/keymaps/de.c create mode 100644 src/modules/vterm/keymaps/us.c diff --git a/src/modules/vterm/Makefile.all b/src/modules/vterm/Makefile.all index 7b9fe63..a987d5c 100644 --- a/src/modules/vterm/Makefile.all +++ b/src/modules/vterm/Makefile.all @@ -2,5 +2,5 @@ shopt -s extglob source $LOST_BUILDMK_ROOT/config.sh echo "LD $1/modules/vterm" -$LOST_TOOLS_LD -Ttext=0x40000000 -ovterm.mod *.o --start-group $2 --end-group +$LOST_TOOLS_LD -Ttext=0x40000000 -ovterm.mod *.o keymaps/de.o --start-group $2 --end-group $LOST_TOOLS_STRIP -s vterm.mod -o $1/modules/vterm diff --git a/src/modules/vterm/include/keymap.h b/src/modules/vterm/include/keymap.h index dcbc0ba..4a8a733 100644 --- a/src/modules/vterm/include/keymap.h +++ b/src/modules/vterm/include/keymap.h @@ -49,6 +49,8 @@ typedef struct keymap_entry { wchar_t ctrl; } keymap_entry_t; +extern keymap_entry_t keymap[128]; + /** * Eintrag aus der Keymap auslesen * diff --git a/src/modules/vterm/keymap.c b/src/modules/vterm/keymap.c index c1881bd..48cd340 100644 --- a/src/modules/vterm/keymap.c +++ b/src/modules/vterm/keymap.c @@ -39,137 +39,6 @@ #include "vterm.h" #include "keymap.h" -keymap_entry_t keymap[] = { - { 0, 0, 0, 0 }, // 0 - { '\033', '\033', '\033', '\033' }, - { '1', '!', '|', 0 }, - { '2', '"', 0, 0 }, - { '3', '#', 0, 0 }, - { '4', '$', 0, 0 }, - { '5', '%', 0, 0 }, - { '6', '&', 0, 0 }, - { '7', '/', '{', 0 }, - { '8', '(', '[', 0 }, - { '9', ')', ']', 0 }, // 10 - { '0', '=', '}', 0 }, - {L'ß', '?', '\\', 0 }, - { 0, '`', 0, 0 }, - { '\b', 0, 0, 0 }, - { '\t', 0, 0, 0 }, - { 'q', 'Q', '@', 17 }, - { 'w', 'W', 0, 23 }, - { 'e', 'E', 0, 5 }, - { 'r', 'R', 0, 18 }, - { 't', 'T', 0, 20 }, // 20 - { 'z', 'Z', 0, 26 }, - { 'u', 'U', 0, 21 }, - { 'i', 'I', 0, 9 }, - { 'o', 'O', 0, 15 }, - { 'p', 'P', 0, 16 }, - {L'ü', L'Ü', 0, 0 }, - { '+', '*', '~', 0 }, - { '\n', 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 'a', 'A', 0, 1 }, // 30 - { 's', 'S', 0, 19 }, - { 'd', 'D', 0, 4 }, - { 'f', 'F', 0, 6 }, - { 'g', 'G', 0, 7 }, - { 'h', 'H', 0, 8 }, - { 'j', 'J', 0, 10 }, - { 'k', 'K', 0, 11 }, - { 'l', 'L', 0, 12 }, - {L'ö', L'Ö', 0, 0 }, - {L'ä', L'Ä', 0, 0 }, // 40 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { '#', '\'', 0, 0 }, - { 'y', 'Y', 0, 25 }, - { 'x', 'X', 0, 24 }, - { 'c', 'C', 0, 3 }, - { 'v', 'V', 0, 22 }, - { 'b', 'B', 0, 2 }, - { 'n', 'N', 0, 14 }, - { 'm', 'M', 0, 13 }, // 50 - { ',', ';', 0, 0 }, - { '.', ':', 0, 0 }, - { '-', '_', 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { ' ', ' ', ' ', 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 60 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 70 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 80 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { '<', '>', '|', 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 90 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 100 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 110 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, // 120 - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 0 }, -}; - /** * Eintrag aus der Keymap auslesen * diff --git a/src/modules/vterm/keymaps/Makefile.all b/src/modules/vterm/keymaps/Makefile.all new file mode 100644 index 0000000..b0efe9a --- /dev/null +++ b/src/modules/vterm/keymaps/Makefile.all @@ -0,0 +1,10 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +mkdir -p $1/system/keymaps + +for lang in de us; do + echo "KMAP $lang" + $LOST_TOOLS_LD --oformat binary $lang.o -e 0 -o $1/system/keymaps/$lang.kbd + chmod a-x $1/system/keymaps/$lang.kbd +done diff --git a/src/modules/vterm/keymaps/de.c b/src/modules/vterm/keymaps/de.c new file mode 100644 index 0000000..df400bd --- /dev/null +++ b/src/modules/vterm/keymaps/de.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "keymap.h" + +keymap_entry_t keymap[128] = { + { 0, 0, 0, 0 }, // 0 + { '\033', '\033', '\033', '\033' }, + { '1', '!', '|', 0 }, + { '2', '"', 0, 0 }, + { '3', '#', 0, 0 }, + { '4', '$', 0, 0 }, + { '5', '%', 0, 0 }, + { '6', '&', 0, 0 }, + { '7', '/', '{', 0 }, + { '8', '(', '[', 0 }, + { '9', ')', ']', 0 }, // 10 + { '0', '=', '}', 0 }, + {L'ß', '?', '\\', 0 }, + { 0, '`', 0, 0 }, + { '\b', 0, 0, 0 }, + { '\t', 0, 0, 0 }, + { 'q', 'Q', '@', 17 }, + { 'w', 'W', 0, 23 }, + { 'e', 'E', 0, 5 }, + { 'r', 'R', 0, 18 }, + { 't', 'T', 0, 20 }, // 20 + { 'z', 'Z', 0, 26 }, + { 'u', 'U', 0, 21 }, + { 'i', 'I', 0, 9 }, + { 'o', 'O', 0, 15 }, + { 'p', 'P', 0, 16 }, + {L'ü', L'Ü', 0, 0 }, + { '+', '*', '~', 0 }, + { '\n', 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 'a', 'A', 0, 1 }, // 30 + { 's', 'S', 0, 19 }, + { 'd', 'D', 0, 4 }, + { 'f', 'F', 0, 6 }, + { 'g', 'G', 0, 7 }, + { 'h', 'H', 0, 8 }, + { 'j', 'J', 0, 10 }, + { 'k', 'K', 0, 11 }, + { 'l', 'L', 0, 12 }, + {L'ö', L'Ö', 0, 0 }, + {L'ä', L'Ä', 0, 0 }, // 40 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { '#', '\'', 0, 0 }, + { 'y', 'Y', 0, 25 }, + { 'x', 'X', 0, 24 }, + { 'c', 'C', 0, 3 }, + { 'v', 'V', 0, 22 }, + { 'b', 'B', 0, 2 }, + { 'n', 'N', 0, 14 }, + { 'm', 'M', 0, 13 }, // 50 + { ',', ';', 0, 0 }, + { '.', ':', 0, 0 }, + { '-', '_', 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { ' ', ' ', ' ', 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 60 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 70 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 80 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { '<', '>', '|', 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 90 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 100 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 110 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 120 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, +}; diff --git a/src/modules/vterm/keymaps/us.c b/src/modules/vterm/keymaps/us.c new file mode 100644 index 0000000..783268e --- /dev/null +++ b/src/modules/vterm/keymaps/us.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "keymap.h" + +keymap_entry_t keymap[128] = { + { 0, 0, 0, 0 }, // 0 + { '\033', '\033', '\033', '\033' }, + { '1', '!', '|', 0 }, + { '2', '@', 0, 0 }, + { '3', '#', 0, 0 }, + { '4', '$', 0, 0 }, + { '5', '%', 0, 0 }, + { '6', '^', 0, 0 }, + { '7', '&', 0, 0 }, + { '8', '*', 0, 0 }, + { '9', '(', 0, 0 }, // 10 + { '0', ')', 0, 0 }, + { '-', '_', 0, 0 }, + { '=', '+', 0, 0 }, + { '\b', 0, 0, 0 }, + { '\t', 0, 0, 0 }, + { 'q', 'Q', '@', 17 }, + { 'w', 'W', 0, 23 }, + { 'e', 'E', 0, 5 }, + { 'r', 'R', 0, 18 }, + { 't', 'T', 0, 20 }, // 20 + { 'y', 'Y', 0, 26 }, + { 'u', 'U', L'ü', 21 }, + { 'i', 'I', 0, 9 }, + { 'o', 'O', L'ö', 15 }, + { 'p', 'P', 0, 16 }, + { '[', '{', 0, 0 }, + { ']', '}', 0, 0 }, + { '\n', 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 'a', 'A', L'ä', 1 }, // 30 + { 's', 'S', L'ß', 19 }, + { 'd', 'D', 0, 4 }, + { 'f', 'F', 0, 6 }, + { 'g', 'G', 0, 7 }, + { 'h', 'H', 0, 8 }, + { 'j', 'J', 0, 10 }, + { 'k', 'K', 0, 11 }, + { 'l', 'L', 0, 12 }, + { ';', ':', 0, 0 }, + { '\'', '"', 0, 0 }, // 40 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { '\\', '|', 0, 0 }, + { 'z', 'Z', 0, 25 }, + { 'x', 'X', 0, 24 }, + { 'c', 'C', 0, 3 }, + { 'v', 'V', 0, 22 }, + { 'b', 'B', 0, 2 }, + { 'n', 'N', 0, 14 }, + { 'm', 'M', 0, 13 }, // 50 + { ',', '<', 0, 0 }, + { '.', '>', 0, 0 }, + { '/', '?', 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { ' ', ' ', ' ', 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 60 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 70 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 80 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { '<', '>', '|', 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 90 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 100 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 110 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, // 120 + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, +}; -- 1.6.0.2 From kevin at tyndur.org Sun Sep 6 10:21:10 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 6 Sep 2009 10:21:10 +0200 Subject: [tyndur-devel] [RFC][PATCH] Pascal-RTL: Units zum Pinseln von TUIs Message-ID: <1252225270-5674-1-git-send-email-kevin@tyndur.org> + Pascal-RTL: Unit tui Signed-off-by: Kevin Wolf --- src/modules/pas/lib/tui/tui.pas | 526 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 526 insertions(+), 0 deletions(-) create mode 100644 src/modules/pas/lib/tui/tui.pas diff --git a/src/modules/pas/lib/tui/tui.pas b/src/modules/pas/lib/tui/tui.pas new file mode 100644 index 0000000..12c4017 --- /dev/null +++ b/src/modules/pas/lib/tui/tui.pas @@ -0,0 +1,526 @@ +unit tui; +{$MODE ObjFPC} +{$H+} + +interface + +// TODO UTF-8-Unterstuetzung + +type + TUIObject = class + public + color: byte; + bgcolor: byte; + + protected + f_w, f_h: integer; + + public + constructor create; + procedure align(w, h: integer); virtual; + procedure draw(x, y: integer); virtual; + + property width: integer read f_w write f_w; + property height: integer read f_h write f_h; + end; + PTUIObject = ^TUIObject; + + TUIRowColContainer = class(TUIObject) + public + constructor create(num: integer); + destructor free; + + protected + cols: integer; + children: PTUIObject; + + f_fixed: PInteger; + f_prop: PInteger; + + public + spacer: boolean; + + protected + procedure SetChild(i: integer; obj: TUIObject); + procedure SetFixedWidth(i: integer; w: integer); + procedure SetPropWidth(i: integer; w: integer); + + public + property _children[i: integer]: TUIObject write SetChild; default; + property fixed[i: integer]: integer write SetFixedWidth; + property prop[i: integer]: integer write SetPropWidth; + end; + + TUIColContainer = class(TUIRowColContainer) + public + procedure align(w, h: integer); override; + procedure draw(x, y: integer); override; + end; + + TUIRowContainer = class(TUIRowColContainer) + public + procedure align(w, h: integer); override; + procedure draw(x, y: integer); override; + end; + + TUIFrame = class(TUIObject) + protected + f_obj: TUIObject; + f_obj_w: integer; + f_obj_h: integer; + + public + constructor create(obj: TUIObject; w, h: integer); + procedure align(w, h: integer); override; + procedure draw(x, y: integer); override; + end; + + TUILabel = class(TUIObject) + protected + f_content: String; + + public + procedure draw(x, y: integer); override; + property content: String read f_content write f_content; + end; + + TUIButton = class(TUILabel) + public + procedure draw(x, y: integer); override; + end; + + TMenuItem = record + s: String; + opaque: Pointer; + end; + PMenuItem = ^TMenuItem; + + TUIMenu = class(TUIObject) + protected + f_num: integer; + f_cur: integer; + f_selected: integer; + f_items: PMenuItem; + + public + sel_color: byte; + sel_bgcolor: byte; + + public + constructor create(num: integer); + destructor free; + + procedure draw(x, y: integer); override; + procedure AddItem(s: String; opaque: Pointer); + end; + +implementation + +uses crt, sysutils, strutils; + +procedure FillRect(x, y, w, h: integer); +var + i: integer; +begin + for i := y to y + h - 1 do begin + GotoXY(x, i); + Write(StringOfChar(' ', w)); + end; +end; + +procedure WritePadded(s: String; w: integer); +begin + if Length(s) >= w then begin + Write(Copy(s, 1, w)); + end else begin + Write(s); + Write(StringOfChar(' ', w - Length(s))); + end; +end; + + +constructor TUIObject.create; +begin + color := 7; + bgcolor := 0; +end; + +procedure TUIObject.align(w, h: integer); +begin + f_w := w; + f_h := h; +end; + +procedure TUIObject.draw(x, y: integer); +begin + TextColor(color); + TextBackground(bgcolor); + FillRect(x, y, f_w, f_h); +end; + +constructor TUIRowColContainer.create(num: integer); +var + i: integer; +begin + if num < 1 then begin + raise Exception.create('TUIColContainer: num < 1'); + end; + + spacer := false; + + cols := num; + children := GetMem(sizeof(PTUIObject) * num); + f_fixed := GetMem(sizeof(integer) * num); + f_prop := GetMem(sizeof(integer) * num); + + for i := 0 to cols - 1 do begin + children[i] := nil; + f_fixed[i] := 0; + f_prop[i] := 0; + end; +end; + +destructor TUIRowColContainer.free; +var + i: integer; +begin + for i := 0 to cols - 1 do begin + if children[i] <> nil then begin + children[i].free; + end; + end; + + FreeMem(children); + FreeMem(f_fixed); + FreeMem(f_prop); +end; + +procedure TUIRowColContainer.SetChild(i: integer; obj: TUIObject); +begin + children[i] := obj; +end; + +procedure TUIRowColContainer.SetFixedWidth(i: integer; w: integer); +begin + f_fixed[i] := w; +end; + +procedure TUIRowColContainer.SetPropWidth(i: integer; w: integer); +begin + f_prop[i] := w; +end; + +procedure TUIColContainer.align(w, h: integer); +var + i: integer; + prop_space: integer; + cur_w: integer; +begin + f_w := w; + f_h := h; + + prop_space := 0; + for i := 0 to cols - 1 do begin + if f_fixed[i] > 0 then begin + if w >= f_fixed[i] then begin + w -= f_fixed[i]; + end else begin + f_fixed[i] := w; + w := 0; + end; + + children[i].align(f_fixed[i], h); + end else begin + prop_space += f_prop[i]; + end; + + if spacer and (w > 0) and (i < cols - 1) then begin + Dec(w); + end; + end; + + for i := 0 to cols - 1 do begin + if f_fixed[i] = 0 then begin + if prop_space = 0 then begin + children[i].align(0, h); + end else begin + cur_w := (w * f_prop[i]) div prop_space; + children[i].align(cur_w, h); + prop_space -= f_prop[i]; + w -= cur_w; + end; + end; + end; +end; + +procedure TUIColContainer.draw(x, y: integer); +var + i: integer; + w: integer; +begin + w := 0; + for i := 0 to cols - 1 do begin + children[i].draw(x + w, y); + w += children[i].width; + + if spacer then begin + Inc(w); + end; + end; + + if w < f_w then begin + TextColor(color); + TextBackground(bgcolor); + FillRect(x + w, y, f_w - w, f_h); + end; +end; + +procedure TUIRowContainer.align(w, h: integer); +var + i: integer; + prop_space: integer; + cur_h: integer; +begin + f_w := w; + f_h := h; + + prop_space := 0; + for i := 0 to cols - 1 do begin + if f_fixed[i] > 0 then begin + if w >= f_fixed[i] then begin + h -= f_fixed[i]; + end else begin + f_fixed[i] := h; + h := 0; + end; + + children[i].align(w, f_fixed[i]); + end else begin + prop_space += f_prop[i]; + end; + + if spacer and (h > 0) and (i <> cols - 1) then begin + Dec(h); + end; + end; + + for i := 0 to cols - 1 do begin + if f_fixed[i] = 0 then begin + if prop_space = 0 then begin + children[i].align(w, 0); + end else begin + cur_h := (h * f_prop[i]) div prop_space; + children[i].align(w, cur_h); + prop_space -= f_prop[i]; + h -= cur_h; + end; + end; + end; +end; + +procedure TUIRowContainer.draw(x, y: integer); +var + i: integer; + h: integer; +begin + h := 0; + for i := 0 to cols - 1 do begin + children[i].draw(x, y + h); + h += children[i].height; + + if spacer then begin + Inc(h); + end; + end; + + if h < f_h then begin + TextColor(color); + TextBackground(bgcolor); + FillRect(x, y + h, f_w, f_h - h); + end; +end; + +constructor TUIFrame.create(obj: TUIObject; w, h: integer); +begin + f_obj := obj; + f_obj_w := w; + f_obj_h := h; +end; + +procedure TUIFrame.align(w, h: integer); +begin + f_w := w; + f_h := h; + + if f_obj_w < w then begin + w := f_obj_w; + end; + + if f_obj_h < h then begin + h := f_obj_h; + end; + + f_obj.align(w, h); +end; + +procedure TUIFrame.draw(x, y: integer); +var + w, h: integer; +begin + w := f_w; + h := f_h; + + TextColor(color); + TextBackground(bgcolor); + FillRect(x, y, w, h); + + if f_obj_w < w then begin + w := f_obj_w; + end; + + if f_obj_h < h then begin + h := f_obj_h; + end; + + f_obj.draw(x + ((f_w - w) div 2), y + ((f_h - h) div 2)); +end; + +procedure TUILabel.draw(x, y: integer); +var + s: String; + pos: integer; + cnt: integer; + row: integer; + line_start_pos: integer; +begin + if f_h > 0 then begin + TextColor(color); + TextBackground(bgcolor); + FillRect(x, y, f_w, f_h); + + pos := 0; + row := 0; + cnt := 1; + line_start_pos := 1; + + while (pos < Length(f_content)) and (row < f_h) do begin + + s := ExtractWordPos(cnt, f_content, [' '], pos); + Inc(cnt); + if s = '' then begin + break; + end; + + if pos - line_start_pos + Length(s) > f_w then begin + Inc(row); + line_start_pos := pos; + if row >= f_h then begin + break; + end; + end; + + GotoXY(x + pos - line_start_pos, y + row); + Write(s); + end; + end; +end; + +procedure TUIButton.draw(x, y: integer); +var + s: String; + diff: integer; +begin + if f_w > 2 then begin + TextColor(color); + TextBackground(bgcolor); + FillRect(x, y, f_w, f_h); + + if Length(content) > f_w - 2 then begin + s := '<' + Copy(content, 1, f_w - 2) + '>'; + end else begin + diff := f_w - 2 - Length(content); + s := '<' + StringOfChar(' ', diff div 2) + content + + StringOfChar(' ', diff - (diff div 2)) + '>'; + end; + + GotoXY(x, y); + Write(s); + end; +end; + +constructor TUIMenu.create(num: integer); +var + i: integer; +begin + if num < 1 then begin + raise Exception.create('TUIColContainer: num < 1'); + end; + + sel_color := 14; + sel_bgcolor := 1; + + f_cur := 0; + f_selected := 0; + f_num := num; + f_items := GetMem(sizeof(TMenuItem) * num); + + for i := 0 to f_num - 1 do begin + f_items[i].s := ''; + f_items[i].opaque := nil; + end; +end; + +destructor TUIMenu.free; +begin + FreeMem(f_items); +end; + +procedure TUIMenu.draw(x, y: integer); +var + i: integer; + last: integer; +begin + TextColor(color); + TextBackground(bgcolor); + FillRect(x, y, f_w, f_h); + + last := f_cur - 1; + if last >= f_h then begin + last := f_h - 1; + end; + + for i := 0 to last do begin + GotoXY(x, y + i); + if f_selected = i then begin + TextColor(sel_color); + TextBackground(sel_bgcolor); + end; + WritePadded(f_items[i].s, f_w); + if f_selected = i then begin + TextColor(color); + TextBackground(bgcolor); + end; + end; +end; + +procedure TUIMenu.AddItem(s: String; opaque: Pointer); +begin + if f_cur < f_num then begin + f_items[f_cur].s := s; + f_items[f_cur].opaque := opaque; + Inc(f_cur); + end; +end; + + +initialization + + ClrScr; + +finalization + + TextBackground(0); + TextColor(7); + WriteLn; + +end. -- 1.6.0.2 From kevin at tyndur.org Sun Sep 6 20:02:20 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 6 Sep 2009 20:02:20 +0200 Subject: [tyndur-devel] [PATCH] Pascal-RTL: ReadEscapeSequence Message-ID: <1252260140-29629-1-git-send-email-kevin@tyndur.org> * Pascal-RTL: kedit hat so eine schoene Funktion, um den vt100-Kram einzulesen und in was vernuenftiges umzuwanden. Das kann so ziemlich jedes interaktiven Programm brauchen, also ab in die RTL damit. Signed-off-by: Kevin Wolf --- src/modules/pas/kedit/kedit.pas | 2 +- src/modules/pas/kedit/kedit_input.pas | 2 +- src/modules/pas/kedit/kedit_tui.pas | 82 --------------------------------- src/modules/pas/lib/tyndur/tyndur.pas | 81 ++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 84 deletions(-) diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas index 3542b07..dc956d5 100644 --- a/src/modules/pas/kedit/kedit.pas +++ b/src/modules/pas/kedit/kedit.pas @@ -103,7 +103,7 @@ procedure Edit; case key of #27: { VT100-Escapesequenz } begin - key := HandleEscapeSequence(); + key := ReadEscapeSequence(); if (key >= SK_MIN) and (key <= SK_MAX) and (special_key_handler[key] <> nil) then begin special_key_handler[key](@state); end else begin diff --git a/src/modules/pas/kedit/kedit_input.pas b/src/modules/pas/kedit/kedit_input.pas index 0b2e298..493d6b8 100644 --- a/src/modules/pas/kedit/kedit_input.pas +++ b/src/modules/pas/kedit/kedit_input.pas @@ -2,7 +2,7 @@ unit kedit_input; interface -uses kedit_main, kedit_tui; +uses tyndur, kedit_main, kedit_tui; type diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas index 13c7781..028d9b6 100644 --- a/src/modules/pas/kedit/kedit_tui.pas +++ b/src/modules/pas/kedit/kedit_tui.pas @@ -16,40 +16,6 @@ const OPT_NO = 2; OPT_CANCEL = 3; - - SK_F1 = #59; - SK_F2 = #60; - SK_F3 = #61; - SK_F4 = #62; - SK_F5 = #63; - SK_F6 = #64; - SK_F7 = #65; - SK_F8 = #66; - SK_F9 = #67; - SK_F10 = #68; - SK_F11 = #133; - SK_F12 = #134; - - SK_INS = #82; - SK_DEL = #83; - SK_HOME = #71; - SK_END = #79; - SK_PGUP = #73; - SK_PGDN = #81; - - SK_UP = #72; - SK_DOWN = #80; - SK_LEFT = #75; - SK_RIGHT = #77; - - SK_CTRL_PGUP = #132; - SK_CTRL_PGDN = #118; - - SK_MIN = #59; - SK_MAX = #134; - -function HandleEscapeSequence: char; - procedure ShowCursor(visible: boolean); procedure FillRectangle(x1, y1, x2, y2: integer); function Space(n: integer): string; @@ -74,54 +40,6 @@ begin if visible then CursorOn else CursorOff; end; -(* Eingabeverarbeitung ************************************************) - -function HandleEscapeSequence: char; -begin - HandleEscapeSequence := #0; - - case readkey of - 'O': - case readkey of - 'P': exit(SK_F1); - 'Q': exit(SK_F2); - 'R': exit(SK_F3); - 'S': exit(SK_F4); - end; - - '[': - case readkey of - 'A': exit(SK_UP); - 'B': exit(SK_DOWN); - 'C': exit(SK_RIGHT); - 'D': exit(SK_LEFT); - 'F': exit(SK_END); - 'H': exit(SK_HOME); - - '3': if readkey = '~' then exit(SK_DEL); - '5': if readkey = '~' then exit(SK_PGUP); - '6': if readkey = '~' then exit(SK_PGDN); - - '1': - case readkey of - '5': if readkey = '~' then exit(SK_F5); - '7': if readkey = '~' then exit(SK_F6); - '8': if readkey = '~' then exit(SK_F7); - '9': if readkey = '~' then exit(SK_F8); - end; - - '2': - case readkey of - '0': if readkey = '~' then exit(SK_F9); - '1': if readkey = '~' then exit(SK_F10); - '3': if readkey = '~' then exit(SK_F11); - '4': if readkey = '~' then exit(SK_F12); - '~': exit(SK_INS); - end; - end; - end; -end; - (* Rein grafisches Zeug ***********************************************) procedure FillRectangle(x1, y1, x2, y2: integer); diff --git a/src/modules/pas/lib/tyndur/tyndur.pas b/src/modules/pas/lib/tyndur/tyndur.pas index cf29ef9..19ccf0e 100644 --- a/src/modules/pas/lib/tyndur/tyndur.pas +++ b/src/modules/pas/lib/tyndur/tyndur.pas @@ -2,7 +2,41 @@ unit tyndur; interface + const + SK_F1 = #59; + SK_F2 = #60; + SK_F3 = #61; + SK_F4 = #62; + SK_F5 = #63; + SK_F6 = #64; + SK_F7 = #65; + SK_F8 = #66; + SK_F9 = #67; + SK_F10 = #68; + SK_F11 = #133; + SK_F12 = #134; + + SK_INS = #82; + SK_DEL = #83; + SK_HOME = #71; + SK_END = #79; + SK_PGUP = #73; + SK_PGDN = #81; + + SK_UP = #72; + SK_DOWN = #80; + SK_LEFT = #75; + SK_RIGHT = #77; + + SK_CTRL_PGUP = #132; + SK_CTRL_PGDN = #118; + + SK_MIN = #59; + SK_MAX = #134; + + function ReadUnicodeChar: UnicodeChar; + function ReadEscapeSequence: char; implementation @@ -36,4 +70,51 @@ implementation exit(res[1]); end; + function ReadEscapeSequence: char; + begin + ReadEscapeSequence := #0; + + case readkey of + 'O': + case readkey of + 'P': exit(SK_F1); + 'Q': exit(SK_F2); + 'R': exit(SK_F3); + 'S': exit(SK_F4); + end; + + '[': + case readkey of + 'A': exit(SK_UP); + 'B': exit(SK_DOWN); + 'C': exit(SK_RIGHT); + 'D': exit(SK_LEFT); + 'F': exit(SK_END); + 'H': exit(SK_HOME); + + '3': if readkey = '~' then exit(SK_DEL); + '5': if readkey = '~' then exit(SK_PGUP); + '6': if readkey = '~' then exit(SK_PGDN); + + '1': + case readkey of + '5': if readkey = '~' then exit(SK_F5); + '7': if readkey = '~' then exit(SK_F6); + '8': if readkey = '~' then exit(SK_F7); + '9': if readkey = '~' then exit(SK_F8); + end; + + '2': + case readkey of + '0': if readkey = '~' then exit(SK_F9); + '1': if readkey = '~' then exit(SK_F10); + '3': if readkey = '~' then exit(SK_F11); + '4': if readkey = '~' then exit(SK_F12); + '~': exit(SK_INS); + end; + end; + end; + end; + + end. -- 1.6.0.2 From hartmut at tyndur.org Fri Sep 11 00:36:10 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 11 Sep 2009 00:36:10 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_kedit=3A_Syntax-Highlighting?= =?utf-8?q?_f=C3=BCr_Pascal?= Message-ID: <1252622170-10461-1-git-send-email-hartmut@tyndur.org> Syntax-Highlighting umgestrickt * kedit: Aufteilung in syntax.pas, syntax_*.pas für verschiedene Syntaxdateien * kedit: syntax.pas, Klasse TSyntax + kedit: syntax_c.pas, Klasse TSyntax_C Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/syntax.pas | 195 ++---------------------------------- src/modules/pas/kedit/syntax_c.pas | 197 ++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 186 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_c.pas diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas index b382265..0f9950e 100644 --- a/src/modules/pas/kedit/syntax.pas +++ b/src/modules/pas/kedit/syntax.pas @@ -29,30 +29,18 @@ type property GetState: integer read f_state; end; - TSyntax_C = class(TSyntax) - public - procedure StartLine(s: String; state: integer); override; - function Next: TSyntaxChange; override; - end; - function SyntaxColor(c: TSyntaxColor): byte; function SyntaxBgColor(c: TSyntaxColor): byte; +function Matches(s: String; pos: integer; pattern: String): boolean; +function MatchesNumber(s: string; pos: integer): integer; +function MatchesKeyword(s: string; pos: integer; p: Array of String): integer; +function MatchesLabel(s: string; pos: integer): integer; +function MatchesType(s: string; pos: integer): integer; +function MatchesTrailingSpace(s: string; pos: integer): boolean; implementation - -const - Keywords_C: Array [1..15] of String = ( - 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', - 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' - ); - Types_C: Array [1..17] of String = ( - 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', - 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' - ); - - function SyntaxColor(c: TSyntaxColor): byte; begin case c of @@ -70,6 +58,7 @@ begin exit(8); end; + function SyntaxBgColor(c: TSyntaxColor): byte; begin case c of @@ -79,11 +68,13 @@ begin exit(0); end; + function Matches(s: String; pos: integer; pattern: String): boolean; begin Matches := (Copy(s, pos, length(pattern)) = pattern); end; + function MatchesNumber(s: String; pos: integer): integer; var i: integer; @@ -261,172 +252,4 @@ begin color := c; end; -procedure TSyntax_C.StartLine(s: String; state: integer); -begin - line := s; - f_state := state; - pos := 1; - - case f_state of - 1: color := syn_comment; - 2: color := syn_comment; - 3: color := syn_number; - 4: color := syn_string; - 5: color := syn_string_special; - 6: color := syn_keyword; - 7: color := syn_type; - 8: color := syn_label; - else color := syn_other; - end; -end; - -function TSyntax_C.Next: TSyntaxChange; -var - c: char; - tmp: integer; -begin - Next.posY := 0; - Next.color := color; - - while pos <= length(line) do begin - c := line[pos]; - - case f_state of - - 0: { Normaler Text } - case c of - '/': - if Matches(line, pos, '//') then begin - f_state := 1; - exit(Highlight(syn_comment)); - end else if Matches(line, pos, '/*') then begin - f_state := 2; - exit(Highlight(syn_comment)); - end; - - '0' .. '9', '-', '+': - begin - tmp := MatchesNumber(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_number); - Inc(pos, tmp); - f_state := 3; - exit; - end; - end; - - '#': - begin - if Copy(line, 1, pos - 1) = Space(pos - 1) then begin - f_state := 1; - exit(Highlight(syn_compiler)); - end; - end; - - '"': - begin - Next := Highlight(syn_string); - Inc(pos); - f_state := 4; - exit; - end; - ' ': - begin - if MatchesTrailingSpace(line, pos) then begin - Next := Highlight(syn_trailing_space); - pos := length(line) + 1; - exit; - end; - end; - - else - begin - tmp := MatchesKeyword(line, pos, Keywords_C); - if tmp <> 0 then begin - Next := Highlight(syn_keyword); - Inc(pos, tmp); - f_state := 6; - exit; - end; - - tmp := MatchesKeyword(line, pos, Types_C); - if tmp <> 0 then begin - Next := Highlight(syn_type); - Inc(pos, tmp); - f_state := 7; - exit; - end; - - tmp := MatchesType(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_type); - Inc(pos, tmp); - f_state := 7; - exit; - end; - - tmp := MatchesLabel(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_label); - Inc(pos, tmp); - f_state := 8; - exit; - end; - end; - end; - - 1: { Kommentar bis Zeilenende } - begin - pos := length(line); - break; - end; - - 2: { C-Kommentar } - if Matches(line, pos, '*/') then begin - f_state := 0; - Inc(pos, 2); - exit(Highlight(syn_other)); - end; - - 3, 6, 7, 8: { Ende eines gefaerbten Worts } - begin - f_state := 0; - exit(Highlight(syn_other)); - end; - - 4: { String } - case c of - '\': - begin - f_state := 5; - Next := Highlight(syn_string_special); - Inc(pos); - exit; - end; - - '"': - begin - f_state := 0; - Inc(pos); - exit(Highlight(syn_other)); - end; - end; - - 5: { Escaptes Zeichen in einem String } - begin - f_state := 4; - Inc(pos); - exit(Highlight(syn_string)); - end; - - end; - - Inc(pos); - end; - - if f_state in [1, 3, 4, 5] then begin - f_state := 0; - end; -end; - end. diff --git a/src/modules/pas/kedit/syntax_c.pas b/src/modules/pas/kedit/syntax_c.pas new file mode 100644 index 0000000..f7662cc --- /dev/null +++ b/src/modules/pas/kedit/syntax_c.pas @@ -0,0 +1,197 @@ +unit syntax_c; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_C = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_C: Array [1..15] of String = ( + 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', + 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' + ); + + Types_C: Array [1..17] of String = ( + 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', + 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' + ); + +procedure TSyntax_C.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_C.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + + 0: { Normaler Text } + case c of + '/': + if Matches(line, pos, '//') then begin + f_state := 1; + exit(Highlight(syn_comment)); + end else if Matches(line, pos, '/*') then begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '#': + begin + if Copy(line, 1, pos - 1) = Space(pos - 1) then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end; + end; + + '"': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_C); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Types_C); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { C-Kommentar } + if Matches(line, pos, '*/') then begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + '\': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end; + + '"': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. -- 1.6.0.4 From hartmut at tyndur.org Fri Sep 11 00:40:16 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 11 Sep 2009 00:40:16 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_kedit=3A_Syntax-Highlighting?= =?utf-8?q?_f=C3=BCr_Pascal?= Message-ID: <1252622416-10814-1-git-send-email-hartmut@tyndur.org> 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 --- 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 From hartmut at tyndur.org Fri Sep 11 00:42:51 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 11 Sep 2009 00:42:51 +0200 Subject: [tyndur-devel] [PATCH] kedit: Syntax-Highlighting Message-ID: <1252622571-10875-1-git-send-email-hartmut@tyndur.org> + kedit: Pascal-Highlighting Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/syntax_pas.pas | 222 ++++++++++++++++++++++++++++++++++ 1 files changed, 222 insertions(+), 0 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_pas.pas diff --git a/src/modules/pas/kedit/syntax_pas.pas b/src/modules/pas/kedit/syntax_pas.pas new file mode 100644 index 0000000..314f9f5 --- /dev/null +++ b/src/modules/pas/kedit/syntax_pas.pas @@ -0,0 +1,222 @@ +unit syntax_pas; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_Pas = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_Pas: Array [1..81] of String = ( + 'absolute', 'abstract', 'and', 'array', 'assembler', 'asm', + 'automated', 'begin', 'case', 'cdecl', + 'class', 'compilerprog', 'const', 'constructor', + 'deconstructor', 'default', 'deprecated', 'div', 'do', 'downto', + 'dynamic', 'else', 'end', 'export', 'external', 'far', + 'forward', 'finalization', 'for', + 'function', 'generic', 'goto', 'inline', 'if', 'implementation', 'in', + 'interface', 'label', 'message', 'mod', 'near', 'nil', 'not', + 'object', 'overlay', 'overload', 'override', 'of', 'or', 'packed', + 'platform', 'private', 'procedure', + 'program', 'property', 'protected', 'public', 'published', 'raise', + 'record', 'reintroduce', 'resourcestring', + 'repeat', 'sealed', 'set', 'shl', 'shr', 'specialize', 'stdcall', + 'then', 'threadvar', 'to', + 'type', 'unit', 'until', 'uses', 'var', 'virtual', 'while', 'with', + 'xor' + ); + + Types_Pas: Array [1..8] of String = ( + 'integer', 'byte', 'real', 'char', 'string', 'boolean', 'string', + 'file' + ); + + +procedure TSyntax_Pas.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_Pas.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + 0: + case c of + '{': + if Matches(line, pos, '{$') then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end else begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '(': + if Matches(line, pos, '(*') then begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '/': + if (Matches(line, pos, '//')) then begin + f_state := 1; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '''': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_Pas); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Types_Pas); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { Pascal-Kommentar } + if Matches(line, pos, '}') then begin + f_state := 0; + Inc(pos, 1); + exit(Highlight(syn_other)); + end else if Matches(line, pos, '*)') then begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + {'''''': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end;} + + '''': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. + -- 1.6.0.4 From kevin at tyndur.org Fri Sep 11 20:37:46 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 11 Sep 2009 20:37:46 +0200 Subject: [tyndur-devel] [PATCH v2] libm: Rundungsfunktionen Message-ID: <1252694266-26546-1-git-send-email-kevin@tyndur.org> + libm: floor, ceil, round, trunc, nearbyint, fesetround, fegetround Signed-off-by: Kevin Wolf --- src/modules/include/fenv.h | 42 ++++++++ src/modules/include/math.h | 18 +++- src/modules/lib/stdlibc/math/round.c | 182 ++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 1 deletions(-) create mode 100644 src/modules/include/fenv.h create mode 100644 src/modules/lib/stdlibc/math/round.c diff --git a/src/modules/include/fenv.h b/src/modules/include/fenv.h new file mode 100644 index 0000000..10e9ded --- /dev/null +++ b/src/modules/include/fenv.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +enum { + FE_TONEAREST, + FE_UPWARD, + FE_DOWNWARD, + FE_TOWARDZERO, +}; + +int fegetround(void); +int fesetround(int rounding_mode); + +#endif diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 49083ab..1cbb54f 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -50,7 +50,6 @@ #define M_SQRT1_2 0.70710678118654752440 - double tan(double); float tanf(float); long double tanl(long double); @@ -94,5 +93,22 @@ double acos(double); float acosf(float); long double acosl(long double); + +double floor(double x); +float floorf(float x); +long double floorl(long double x); +double ceil(double x); +float ceilf(float x); +long double ceill(long double x); +double trunc(double x); +float truncf(float x); +long double truncl(long double x); +double round(double x); +float roundf(float x); +long double roundl(long double x); +double nearbyint(double x); +float nearbyintf(float x); +long double nearbyintl(long double x); + #endif diff --git a/src/modules/lib/stdlibc/math/round.c b/src/modules/lib/stdlibc/math/round.c new file mode 100644 index 0000000..b16a95a --- /dev/null +++ b/src/modules/lib/stdlibc/math/round.c @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#define ROUND_NEAR 0x000 +#define ROUND_DOWN 0x400 +#define ROUND_UP 0x800 +#define ROUND_TRUNC 0xc00 + +static int rounding_mode = FE_TONEAREST; + +/* + * Achtung: + * + * Die folgende Funktion basieren auf der Annahme, dass das RC-Feld im FPU + * Control Word normalerweise immer auf 0 gesetzt ist, also der neue Wert durch + * ein einfaches or eingetragen werden kann. + */ +static inline long double do_round(long double x, int mode) +{ + long double res; + uint16_t control_word; + + asm( + // Rundungsmodus setzen + "fnstcw %2;" + "mov %2, %%eax;" + "orl %3, %2;" + "fldcw %2;" + + // Zahl auf dem Stack runden + "frndint;" + + // Wieder den Standardrundungsmodus setzen + "mov %%eax, %2;" + "fldcw %2;" + : "=t" (res) : "0" (x), "m" (control_word), "r" (mode) : "eax"); + + return res; +} + + +long double floorl(long double x) +{ + return do_round(x, ROUND_DOWN); +} + +double floor(double x) +{ + return floorl(x); +} + +float floorf(float x) +{ + return floorl(x); +} + + +long double ceill(long double x) +{ + return do_round(x, ROUND_UP); +} + +double ceil(double x) +{ + return ceill(x); +} + +float ceilf(float x) +{ + return ceill(x); +} + +long double truncl(long double x) +{ + return do_round(x, ROUND_TRUNC); +} + +double trunc(double x) +{ + return truncl(x); +} + +float truncf(float x) +{ + return truncl(x); +} + +long double roundl(long double x) +{ + long double res; + + asm("frndint" : "=t" (res) : "0" (x)); + + return res; +} + +double round(double x) +{ + return roundl(x); +} + +float roundf(float x) +{ + return roundl(x); +} + +long double nearbyintl(long double x) +{ + switch (rounding_mode) { + case FE_TONEAREST: + return roundl(x); + case FE_TOWARDZERO: + return truncl(x); + case FE_DOWNWARD: + return floorl(x); + case FE_UPWARD: + return ceill(x); + } + + abort(); + return x; +} + +double nearbyint(double x) +{ + return nearbyintl(x); +} + +float nearbyintf(float x) +{ + return nearbyintl(x); +} + +int fegetround(void) +{ + return rounding_mode; +} + +int fesetround(int mode) +{ + switch(mode) { + case FE_TONEAREST: + case FE_TOWARDZERO: + case FE_DOWNWARD: + case FE_UPWARD: + rounding_mode = mode; + return 0; + + default: + return -1; + } +} -- 1.6.0.2 From kevin at tyndur.org Tue Sep 15 21:41:56 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 15 Sep 2009 21:41:56 +0200 Subject: [tyndur-devel] [PATCH] strto(u)l: 0x ist nur ein Praefix, wenn danach noch was kommt Message-ID: <1253043716-7092-1-git-send-email-kevin@tyndur.org> ! strtou(l): Wenn nach dem 0x keine gueltige Ziffer mehr kommt, ist es entweder keine Hexzahl (Basis 0) oder eine Null ohne 0x vorne dran (Basis 16). Signed-off-by: Kevin Wolf --- src/lib/stdlibc/strtol.c | 9 ++++++++- src/lib/string.c | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/lib/stdlibc/strtol.c b/src/lib/stdlibc/strtol.c index d605144..2387e98 100644 --- a/src/lib/stdlibc/strtol.c +++ b/src/lib/stdlibc/strtol.c @@ -31,6 +31,13 @@ #include "limits.h" #include "types.h" +static int is_hexdigit(char x) +{ + return (x >= '0' && x <= '9') + || (x >= 'a' && x <= 'f') + || (x >= 'A' && x <= 'F'); +} + long strtol(const char *str, char **endptr, int base) { long retval = 0; @@ -56,7 +63,7 @@ long strtol(const char *str, char **endptr, int base) base = 16; } - if (base == 16) { + if (base == 16 && is_hexdigit(str[2])) { str += 2; } } else if (base == 0) { diff --git a/src/lib/string.c b/src/lib/string.c index 3125c2c..ae809a6 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -65,6 +65,13 @@ void itoa(unsigned int n, char *s, unsigned int base) s[y] = '\0'; } +static int is_hexdigit(char x) +{ + return (x >= '0' && x <= '9') + || (x >= 'a' && x <= 'f') + || (x >= 'A' && x <= 'F'); +} + unsigned long long int strtoull(const char *nptr, char **endptr, int base) { unsigned long long int result = 0; @@ -94,8 +101,10 @@ unsigned long long int strtoull(const char *nptr, char **endptr, int base) base = 10; if (*nptr == '0') { if (*++nptr == 'x') { - base = 16; - nptr++; + if (is_hexdigit(nptr[1])) { + base = 16; + nptr++; + } } else { base = 8; } @@ -103,7 +112,7 @@ unsigned long long int strtoull(const char *nptr, char **endptr, int base) break; case 16: - if ((*nptr == '0') && (*(nptr+1) == 'x')) { + if ((*nptr == '0') && (nptr[1] == 'x') && is_hexdigit(nptr[2])) { nptr += 2; } break; -- 1.6.0.2 From kevin at tyndur.org Thu Sep 17 22:48:37 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 17 Sep 2009 22:48:37 +0200 Subject: [tyndur-devel] [RFC] libc: sscanf Message-ID: <1253220517-5304-1-git-send-email-kevin@tyndur.org> Im Folgenden also wie gewuenscht, kein Patch. Bisher nur unter Linux getestet, scheint in den paar Testfaellen in main() was vernuenftiges zu tun. Ein paar Sachen fehlen noch (float ueberlasse ich uebrigens gern einem Freiwilligen), aber die ueblichsten Sachen (Strings und Integer) sollten gehen. --- #include #include #include #include #include typedef int (*jscanf_getc)(void* state); typedef void (*jscanf_ungetc)(void* state, char c); /** * @param base Basis der einzulesenden Zahl (8, 10 oder 16) */ static int jscanf_read_number(char* buf, int size, jscanf_getc jgetc, jscanf_ungetc jungetc, void* state, int base) { int valid; int i; int c; int first_digit = 0; i = 0; while (i < size) { c = jgetc(state); if (c == EOF) { break; } valid = 0; switch (c) { case '+': case '-': if (i == 0) { valid = 1; first_digit++; } break; case '0': valid = 1; break; case '1' ... '7': if (base == 0) { base = buf[first_digit] == '0' ? 8 : 10; } valid = 1; break; case '8' ... '9': if (base == 0) { base = buf[first_digit] == '0' ? 8 : 10; } valid = (base != 8); break; case 'A' ... 'F': case 'a' ... 'f': valid = (base == 16); break; case 'x': if (base == 0) { base = 16; } if ((base == 16) && (i == first_digit + 1) && (buf[first_digit] == '0')) { valid = 1; } break; } if (!valid) { jungetc(state, c); break; } buf[i] = c; i++; } buf[i] = '\0'; return i; } static int assign_number(void* ptr, uint64_t value, int size) { if (size == 1) { uint8_t* tptr = ptr; *tptr = (uint8_t) value; } else if (size == 2) { uint16_t* tptr = ptr; *tptr = (uint16_t) value; } else if (size == 4) { uint32_t* tptr = ptr; *tptr = (uint32_t) value; } else if (size == 8) { uint64_t* tptr = ptr; *tptr = (uint64_t) value; } else { abort(); } } static int jscanf(const char* fmt, va_list ap, jscanf_getc jgetc, jscanf_ungetc jungetc, void* state) { int ret = 0; int assign; int len; int size; int c; char* endptr; uint64_t value; // 64 Bit oktal = 22 Zeichen, Vorzeichen und \0 char buf[24]; while (*fmt) { switch (*fmt) { case ' ': case '\t': case '\n': case '\f': case '\v': do { c = jgetc(state); } while (isspace(c)); break; case '%': fmt++; // Ein * bedeutet, dass der Wert nur eingelesen, aber keiner // Variablen zugewiesen wird if (*fmt == '*') { assign = 0; fmt++; } else { assign = 1; } // Optional kann jetzt die Feldlaenge kommen if (isdigit(*fmt)) { len = strtol(fmt, (char**) &fmt, 10); if (len == 0) { goto matching_error; } } else { len = 0; } // Und die Laenge der Variablen kann auch noch angegeben sein switch (*fmt) { case 'h': if (*++fmt == 'h') { fmt++; size = sizeof(char); } else { size = sizeof(short); } break; case 'l': if (*++fmt == 'l') { fmt++; size = sizeof(long long); } else { size = sizeof(long); } break; case 'j': size = sizeof(intmax_t); break; case 't': size = sizeof(ptrdiff_t); break; case 'z': size = sizeof(size_t); break; default: size = sizeof(int); break; } // Whitespace muss uebersprungen werden (ausser %[ %c %n) if ((*fmt != '[') && (*fmt != 'c') && (*fmt != 'n')) { while (isspace(c = jgetc(state))); if (c != EOF) { jungetc(state, c); } } // Eingabe parsen switch (*fmt) { int base; case 'i': base = 0; goto convert_number; case 'o': base = 8; goto convert_number; case 'x': case 'X': base = 16; goto convert_number; case 'p': base = 16; size = sizeof(void*); len = 0; goto convert_number; case 'd': case 'u': base = 10; convert_number: if (len == 0 || len >= sizeof(buf)) { len = sizeof(buf) - 1; } len = jscanf_read_number(buf, len, jgetc, jungetc, state, base); value = strtoull(buf, &endptr, base); if (endptr != buf + len) { goto matching_error; } if (assign) { void* ptr = va_arg(ap, void*); assign_number(ptr, value, size); ret++; } break; case 'n': { void* ptr = va_arg(ap, void*); assign_number(ptr, ret, size); break; } case 'c': { int i; char* ptr = va_arg(ap, char*); // TODO Multibyte-Zeichen if (len == 0) { len = 1; } for (i = 0; i < len; i++) { c = jgetc(state); if (c == EOF) { goto matching_error; } ptr[i] = c; } break; } case 's': { char* ptr = va_arg(ap, char*); if (len == 0) { len = -1; } while ((len == -1) || len--) { c = jgetc(state); if (isspace(c)) { jungetc(state, c); break; } else if (c == EOF) { break; } *ptr++ = c; } *ptr = '\0'; break; } case '%': goto parse_percent; default: abort(); } break; parse_percent: default: c = jgetc(state); if (c == EOF) { goto input_error; } if (c != *fmt) { goto matching_error; } break; } fmt++; } matching_error: return ret; input_error: if (ret == 0) { return EOF; } return ret; } struct sscanf_state { const char* input; int pos; }; int sscanf_getc(void* state) { struct sscanf_state* s = state; int ret = EOF; if (s->input[s->pos]) { ret = s->input[s->pos]; s->pos++; } return ret; } void sscanf_ungetc(void* state, char c) { struct sscanf_state* s = state; if (s->pos > 0) { s->pos--; if (s->input[s->pos] != c) { abort(); } } else { abort(); } } int vsscanf(const char* input, const char* fmt, va_list ap) { struct sscanf_state state = { .input = input, .pos = 0, }; return jscanf(fmt, ap, sscanf_getc, sscanf_ungetc, &state); } int sscanf(const char* input, const char* fmt, ...) { va_list ap; int ret; va_start(ap, fmt); ret = vsscanf(input, fmt, ap); va_end(ap); return ret; } int main(void) { int n; int ret; int cnt; char buf[10] = { 0 }; char bufx[] = "Vollgeschriebener Puffer"; ret = sscanf("42", "%d", &n); printf("sscanf(%%d -- '42') = %d; read %d\n", ret, n); ret = sscanf("42", "%1d", &n); printf("sscanf(%%1d -- '42') = %d; read %d\n", ret, n); ret = sscanf("42", "%2d", &n); printf("sscanf(%%2d -- '42') = %d; read %d\n", ret, n); ret = sscanf("42abc", "%d%n%2c", &n, &cnt, buf); printf("sscanf(%%d -- '42abc') = %d; read %d\n", ret, n); printf(" cnt = %d, buf = '%s'\n", cnt, buf); ret = sscanf("-42", "%d", &n); printf("sscanf(%%d -- '-42') = %d; read %d\n", ret, n); ret = sscanf("2a", "%x", &n); printf("sscanf(%%x -- '2a') = %d; read %d\n", ret, n); ret = sscanf("0x2a", "%x", &n); printf("sscanf(%%x -- '0x2a') = %d; read %d\n", ret, n); ret = sscanf("0xz", "%x", &n); printf("sscanf(%%x -- '0xz') = %d; read %d\n", ret, n); puts(""); ret = sscanf("020", "%i", &n); printf("sscanf(%%i -- '020') = %d; read %d\n", ret, n); ret = sscanf("0x20", "%i", &n); printf("sscanf(%%i -- '0x20') = %d; read %d\n", ret, n); ret = sscanf("20", "%i", &n); printf("sscanf(%%i -- '20') = %d; read %d\n", ret, n); puts(""); ret = sscanf("42abc", "%*1d%d%n%1s", &n, &cnt, bufx); printf("sscanf(%%d -- '42abc') = %d; read %d\n", ret, n); printf(" cnt = %d, buf = '%s'\n", cnt, bufx); ret = sscanf("42abc", "%d%n%s", &n, &cnt, bufx); printf("sscanf(%%d -- '42abc') = %d; read %d\n", ret, n); printf(" cnt = %d, buf = '%s'\n", cnt, bufx); ret = sscanf("42abc", "%d%n%42s", &n, &cnt, bufx); printf("sscanf(%%d -- '42abc') = %d; read %d\n", ret, n); printf(" cnt = %d, buf = '%s'\n", cnt, bufx); return 0; } From kevin at tyndur.org Fri Sep 18 19:30:25 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 18 Sep 2009 19:30:25 +0200 Subject: [tyndur-devel] [PATCH] libc: scanf-Familie Message-ID: <1253295025-22420-1-git-send-email-kevin@tyndur.org> + libc: scanf, sscanf, fscanf, vscanf, vsscanf, vfscanf Sollte bis auf Fliesskommazahlen und Multibyte-Supprt vollstaendig sein Signed-off-by: Kevin Wolf --- src/modules/include/stdio.h | 13 +- src/modules/lib/stdlibc/scanf.c | 609 ++++++++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/sscanf.c | 40 --- 3 files changed, 618 insertions(+), 44 deletions(-) create mode 100644 src/modules/lib/stdlibc/scanf.c delete mode 100644 src/modules/lib/stdlibc/sscanf.c diff --git a/src/modules/include/stdio.h b/src/modules/include/stdio.h index b3375f2..a4d3bb3 100644 --- a/src/modules/include/stdio.h +++ b/src/modules/include/stdio.h @@ -78,10 +78,15 @@ int vsnprintf(char * buffer, size_t size, const char * format, va_list); int vfprintf(FILE * fp, const char * format, va_list); int vasprintf(char ** buffer, const char * format, va_list); -#ifndef CONFIG_LIBC_NO_STUBS -int fscanf(FILE* fp, const char* format, ...); -int sscanf(const char* str, const char* format, ...); -#endif + +int scanf(const char* fmt, ...); +int sscanf(const char* input, const char* fmt, ...); +int fscanf(FILE* f, const char* fmt, ...); + +int vscanf(const char* fmt, va_list ap); +int vsscanf(const char* input, const char* fmt, va_list ap); +int vfscanf(FILE* f, const char* fmt, va_list ap); + //Dateihandling FILE* fopen(const char* filename, const char* mode); diff --git a/src/modules/lib/stdlibc/scanf.c b/src/modules/lib/stdlibc/scanf.c new file mode 100644 index 0000000..6f2e776 --- /dev/null +++ b/src/modules/lib/stdlibc/scanf.c @@ -0,0 +1,609 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef int (*jscanf_getc)(void* state); +typedef void (*jscanf_ungetc)(void* state, char c); + +/** + * Liest Zahlen passend fuer jscanf ein, d.h. es wird so lange gelesen, wie + * theoretisch noch eine gueltige Zahl herauskommen koennte. Das Parsen und + * Entscheiden, ob es tatsaechlich eine gueltige Zahl ist, bleibt dem Aufrufer + * ueberlassen. + * + * @param buf Puffer, in den die Zeichen eingelesen werden + * @param size Laenge des Puffers in einlesbaren Zeichen. Es muss mindestens + * Platz fuer size + 1 Zeichen vorhanden sein, da noch ein Nullbyte geschrieben + * wird. + * @param jgetc Funktion, um ein Zeichen auszulesen + * @param jungetc Funktion, um ein Zeichen zurueckzugeben, wenn es doch nicht + * passt + * @param state Zustand der Eingabe fuer jgetc/jungetc + * @param base Basis der einzulesenden Zahl (8, 10 oder 16) + */ +static int jscanf_read_number(char* buf, int size, jscanf_getc jgetc, + jscanf_ungetc jungetc, void* state, int base) +{ + int valid; + int i; + int c; + int first_digit = 0; + + i = 0; + while (i < size) { + c = jgetc(state); + + if (c == EOF) { + break; + } + + valid = 0; + switch (c) { + case '+': + case '-': + if (i == 0) { + valid = 1; + first_digit++; + } + break; + case '0': + valid = 1; + break; + case '1' ... '7': + if (base == 0) { + base = buf[first_digit] == '0' ? 8 : 10; + } + valid = 1; + break; + case '8' ... '9': + if (base == 0) { + base = buf[first_digit] == '0' ? 8 : 10; + } + valid = (base != 8); + break; + case 'A' ... 'F': + case 'a' ... 'f': + valid = (base == 16); + break; + case 'x': + if (base == 0) { + base = 16; + } + if ((base == 16) && (i == first_digit + 1) && + (buf[first_digit] == '0')) + { + valid = 1; + } + break; + } + + if (!valid) { + jungetc(state, c); + break; + } + + buf[i] = c; + i++; + } + + buf[i] = '\0'; + + return i; +} + +/** + * Weist eine Zahl einer Variablen zu. Die Groesse der Variablen wird dabei + * als Parameter uebergeben. + * + * @param ptr Variable, in die die Zahl geschrieben werden soll + * @param value Wert, der der Variablen zugewiesen werden soll + * @param size Groesse der Variablen in Bytes + */ +static void assign_number(void* ptr, uint64_t value, int size) +{ + if (size == 1) { + uint8_t* tptr = ptr; + *tptr = (uint8_t) value; + } else if (size == 2) { + uint16_t* tptr = ptr; + *tptr = (uint16_t) value; + } else if (size == 4) { + uint32_t* tptr = ptr; + *tptr = (uint32_t) value; + } else if (size == 8) { + uint64_t* tptr = ptr; + *tptr = (uint64_t) value; + } else { + abort(); + } +} + +/** + * Die eigentliche scanf-Engine, die den Formatstring verarbeitet und die + * eingelesenen Daten in die uebergebenen Parameter schreibt. Die + * Eingabezeichen werden mit den uebergebenen Funktionen geholt. + * + * @param fmt scanf-Formatstring + * @param ap Liste der Ausgabevariablen + * @param jgetc Funktion, um ein Zeichen auszulesen + * @param jungetc Funktion, um ein Zeichen zurueckzugeben, wenn es doch nicht + * passt + * @param state Zustand der Eingabe fuer jgetc/jungetc + * + * @return Anzahl der erfolgreich zugewiesenen Variablen; EOF, wenn ein + * Eingabefehler auftritt, bevor mindestens eine Variable erfolgreich + * eingelesen wurde. + */ +static int jscanf(const char* fmt, va_list ap, + jscanf_getc jgetc, jscanf_ungetc jungetc, void* state) +{ + int ret = 0; + int assign; + int len; + int size; + int c; + char* endptr; + uint64_t value; + + // 64 Bit oktal = 22 Zeichen, Vorzeichen und \0 + char buf[24]; + + while (*fmt) { + switch (*fmt) { + case ' ': + case '\t': + case '\n': + case '\f': + case '\v': + do { + c = jgetc(state); + } while (isspace(c)); + break; + + case '%': + fmt++; + + // Ein * bedeutet, dass der Wert nur eingelesen, aber keiner + // Variablen zugewiesen wird + if (*fmt == '*') { + assign = 0; + fmt++; + } else { + assign = 1; + } + + // Optional kann jetzt die Feldlaenge kommen + if (isdigit(*fmt)) { + len = strtol(fmt, (char**) &fmt, 10); + if (len == 0) { + goto matching_error; + } + } else { + len = 0; + } + + // Und die Laenge der Variablen kann auch noch angegeben sein + switch (*fmt) { + case 'h': + if (*++fmt == 'h') { + fmt++; + size = sizeof(char); + } else { + size = sizeof(short); + } + break; + case 'l': + if (*++fmt == 'l') { + fmt++; + size = sizeof(long long); + } else { + size = sizeof(long); + } + break; + case 'j': + size = sizeof(intmax_t); + break; + case 't': + size = sizeof(ptrdiff_t); + break; + case 'z': + size = sizeof(size_t); + break; + default: + size = sizeof(int); + break; + } + + // Whitespace muss uebersprungen werden (ausser %[ %c %n) + if ((*fmt != '[') && (*fmt != 'c') && (*fmt != 'n')) { + while (isspace(c = jgetc(state))); + if (c != EOF) { + jungetc(state, c); + } + } + + // Eingabe parsen + switch (*fmt) { + int base; + + // %i - Integer (strtol mit Basis 0) + // %d - Integer (strtol mit Basis 10) + // %o - Integer (strtoul mit Basis 8 + // %u - Integer (strtoul mit Basis 1) + // %x - Integer (strtoul mit Basis 16) + // %X - Integer (strtoul mit Basis 16) + // %p - Pointer (strtoul mit Basis 16) + case 'i': + base = 0; + goto convert_number; + case 'o': + base = 8; + goto convert_number; + case 'x': + case 'X': + base = 16; + goto convert_number; + case 'p': + base = 16; + size = sizeof(void*); + len = 0; + goto convert_number; + case 'd': + case 'u': + base = 10; + convert_number: + if (len == 0 || len >= sizeof(buf)) { + len = sizeof(buf) - 1; + } + len = jscanf_read_number(buf, len, jgetc, jungetc, + state, base); + + value = strtoull(buf, &endptr, base); + if (endptr != buf + len) { + goto matching_error; + } + + if (assign) { + void* ptr = va_arg(ap, void*); + assign_number(ptr, value, size); + ret++; + } + break; + + // %n - Anzahl der bisher zugewiesenen Variablen + case 'n': + if (assign) { + void* ptr = va_arg(ap, void*); + assign_number(ptr, ret, size); + ret++; + } + break; + + // %c - char-Array (feste Laenge, kein Nullbyte) + case 'c': + { + // TODO Multibyte-Zeichen + int i; + char* ptr = NULL; + + if (assign) { + ptr = va_arg(ap, char*); + } + + if (len == 0) { + len = 1; + } + + for (i = 0; i < len; i++) { + c = jgetc(state); + if (c == EOF) { + goto matching_error; + } + if (assign) { + ptr[i] = c; + } + } + + if (assign) { + ret++; + } + break; + } + + // %s - Whitespaceterminierter String + case 's': + { + // TODO MUltibyte-Zeichen + char* ptr = NULL; + + if (assign) { + ptr = va_arg(ap, char*); + } + + if (len == 0) { + len = -1; + } + + while ((len == -1) || len--) { + c = jgetc(state); + if (isspace(c)) { + jungetc(state, c); + break; + } else if (c == EOF) { + break; + } + if (assign) { + *ptr++ = c; + } + } + + if (assign) { + *ptr = '\0'; + ret++; + } + break; + } + + // %[ - String aus einer Zeicheklasse + case '[': + { + const char* p = fmt; + const char* end; + int negation = 0; + char* ptr = NULL; + + if (assign) { + ptr = va_arg(ap, char*); + } + + // Wenn das Scanset mit ^ anfaengt, duerfen die Zeichen + // des Scansets _nicht_ vorkommen + if (*++p == '^') { + negation = 1; + p++; + } + + // Scanset zusammenbasteln + if (*p == '\0') { + abort(); + } + + end = strchr(p + 1, ']'); + if (end == NULL) { + abort(); + } + + char scanset[end - p + 1]; + scanset[end - p] = '\0'; + strncpy(scanset, p, end - p); + + // Hier kommt das eigentliche Matching + if (len == 0) { + len = -1; + } + + while ((len == -1) || len--) { + c = jgetc(state); + if (!!strchr(scanset, c) == negation) { + jungetc(state, c); + break; + } else if (c == EOF) { + break; + } + if (assign) { + *ptr++ = c; + } + } + + if (assign) { + *ptr = '\0'; + ret++; + } + + fmt = end + 1; + + break; + } + + // %% - Prozentzeichen + case '%': + goto parse_percent; + + // Das Verhalten bei ungueltiger Conversion Specification + // ist undefiniert. + default: + abort(); + } + break; + + // Ein einzelnes Zeichen wird direkt gematcht + parse_percent: + default: + c = jgetc(state); + if (c == EOF) { + goto input_error; + } + if (c != *fmt) { + goto matching_error; + } + break; + } + + fmt++; + } + +matching_error: + return ret; + +input_error: + if (ret == 0) { + return EOF; + } + return ret; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// sscanf - Eingabe aus einem String + +struct sscanf_state { + const char* input; + int pos; +}; + +static int sscanf_getc(void* state) +{ + struct sscanf_state* s = state; + int ret = EOF; + + if (s->input[s->pos]) { + ret = s->input[s->pos]; + s->pos++; + } + + return ret; +} + +static void sscanf_ungetc(void* state, char c) +{ + struct sscanf_state* s = state; + + if (s->pos > 0) { + s->pos--; + if (s->input[s->pos] != c) { + abort(); + } + } else { + abort(); + } +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einem String aus + */ +int vsscanf(const char* input, const char* fmt, va_list ap) +{ + struct sscanf_state state = { + .input = input, + .pos = 0, + }; + + return jscanf(fmt, ap, sscanf_getc, sscanf_ungetc, &state); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einem String aus + */ +int sscanf(const char* input, const char* fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vsscanf(input, fmt, ap); + va_end(ap); + + return ret; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// fscanf - Eingabe aus einer Datei + +static int fscanf_getc(void* state) +{ + FILE* f = state; + + return fgetc(f); +} + +static void fscanf_ungetc(void* state, char c) +{ + FILE* f = state; + + ungetc(c, f); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einer Datei aus + */ +int vfscanf(FILE* f, const char* fmt, va_list ap) +{ + return jscanf(fmt, ap, fscanf_getc, fscanf_ungetc, f); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einer Datei aus + */ +int fscanf(FILE* f, const char* fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vfscanf(f, fmt, ap); + va_end(ap); + + return ret; +} + + +/////////////////////////////////////////////////////////////////////////////// +// scanf - Eingabe aus der Standardeingabe + +/** + * Fuehrt ein jscanf mit Eingabe aus der Standardeingabe aus + */ +int vscanf(const char* fmt, va_list ap) +{ + return vfscanf(stdin, fmt, ap); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus der Standardeingabe aus + */ +int scanf(const char* fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vscanf(fmt, ap); + va_end(ap); + + return ret; +} diff --git a/src/modules/lib/stdlibc/sscanf.c b/src/modules/lib/stdlibc/sscanf.c deleted file mode 100644 index 3082e3d..0000000 --- a/src/modules/lib/stdlibc/sscanf.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#ifndef CONFIG_LIBC_NO_STUBS -int sscanf(const char* str, const char* format, ...) -{ - // FIXME - puts("TODO in LOST-Libc: sscanf!"); - return 0; -} -#endif - -- 1.6.0.2 From kevin at tyndur.org Sun Sep 20 13:31:04 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 20 Sep 2009 13:31:04 +0200 Subject: [tyndur-devel] [PATCH] libc: ctype.h-Funktionen sollten keine Makros sein Message-ID: <1253446264-25058-1-git-send-email-kevin@tyndur.org> ! libc: Parameter mehrfach auswerten in isspace() usw. ist doof Signed-off-by: Kevin Wolf --- src/include/ctype.h | 153 ++++++++++++++++++++++++++++++++------------------- 1 files changed, 96 insertions(+), 57 deletions(-) diff --git a/src/include/ctype.h b/src/include/ctype.h index d43dcab..51cb2f4 100644 --- a/src/include/ctype.h +++ b/src/include/ctype.h @@ -1,57 +1,96 @@ -/* - * Copyright (c) 2006-2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Burkhard Weseloh. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _CTYPE_H_ -#define _CTYPE_H_ - -#define isprint(c) ((c) >= (char) 0x20) -#define iscntrl(c) ((c) < (char) 0x20) - -#define isspace(c) ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r') -#define isblank(c) ((c) == ' ' || (c) == '\t') -#define isdigit(c) ((c) >= '0' && (c) <= '9') -#define isalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) -#define isalnum(c) (isdigit(c) || isalpha(c)) -#define isxdigit(c) (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -#define isupper(c) ((c) >= 'A' && (c) <= 'Z') -#define islower(c) ((c) >= 'a' && (c) <= 'z') -#define ispunct(c) (isprint(c) && (!isspace(c)) && (!isalpha(c))) -#define isgraph(c) (isprint(c) && !isspace(c)) - - -static inline int tolower(int c) -{ - return isupper(c) ? c + ('a' - 'A') : c; -} - -static inline int toupper(int c) -{ - return islower(c) ? c - ('a' - 'A') : c; -} - -#endif /* ndef CTYPE_H */ +/* + * Copyright (c) 2006-2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Burkhard Weseloh. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#define isprint(c) ((c) >= (char) 0x20) +#define iscntrl(c) ((c) < (char) 0x20) + +static inline int isspace(int c) +{ + return (c == ' ' || c== '\n' || c == '\t' || c == '\r'); +} + +static inline int isblank(int c) +{ + return (c == ' ' ||c == '\t'); +} + +static inline int isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} + +static inline int isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} + +static inline int isalnum(int c) +{ + return (isdigit(c) || isalpha(c)); +} + +static inline int isxdigit(int c) +{ + return (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); +} + +static inline int isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static inline int islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} + +static inline int ispunct(int c) +{ + return (isprint(c) && !isspace(c) && !isalpha(c)); +} + +static inline int isgraph(int c) +{ + return (isprint(c) && !isspace(c)); +} + + +static inline int tolower(int c) +{ + return isupper(c) ? c + ('a' - 'A') : c; +} + +static inline int toupper(int c) +{ + return islower(c) ? c - ('a' - 'A') : c; +} + +#endif /* ndef CTYPE_H */ -- 1.6.0.2 From kevin at tyndur.org Sun Sep 20 14:49:01 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 20 Sep 2009 14:49:01 +0200 Subject: [tyndur-devel] [PATCH v2] libc: scanf-Familie Message-ID: <1253450941-1665-1-git-send-email-kevin@tyndur.org> + libc: scanf, sscanf, fscanf, vscanf, vsscanf, vfscanf Sollte bis auf Gleitkommazahlen und Multibyte-Supprt vollstaendig sein Signed-off-by: Kevin Wolf --- src/modules/include/stdio.h | 13 +- src/modules/lib/stdlibc/scanf.c | 671 ++++++++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/sscanf.c | 40 --- 3 files changed, 680 insertions(+), 44 deletions(-) create mode 100644 src/modules/lib/stdlibc/scanf.c delete mode 100644 src/modules/lib/stdlibc/sscanf.c diff --git a/src/modules/include/stdio.h b/src/modules/include/stdio.h index b3375f2..a4d3bb3 100644 --- a/src/modules/include/stdio.h +++ b/src/modules/include/stdio.h @@ -78,10 +78,15 @@ int vsnprintf(char * buffer, size_t size, const char * format, va_list); int vfprintf(FILE * fp, const char * format, va_list); int vasprintf(char ** buffer, const char * format, va_list); -#ifndef CONFIG_LIBC_NO_STUBS -int fscanf(FILE* fp, const char* format, ...); -int sscanf(const char* str, const char* format, ...); -#endif + +int scanf(const char* fmt, ...); +int sscanf(const char* input, const char* fmt, ...); +int fscanf(FILE* f, const char* fmt, ...); + +int vscanf(const char* fmt, va_list ap); +int vsscanf(const char* input, const char* fmt, va_list ap); +int vfscanf(FILE* f, const char* fmt, va_list ap); + //Dateihandling FILE* fopen(const char* filename, const char* mode); diff --git a/src/modules/lib/stdlibc/scanf.c b/src/modules/lib/stdlibc/scanf.c new file mode 100644 index 0000000..c181ff6 --- /dev/null +++ b/src/modules/lib/stdlibc/scanf.c @@ -0,0 +1,671 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef int (*jscanf_getc)(void* state); +typedef void (*jscanf_ungetc)(void* state, char c); +typedef int (*jscanf_tell)(void* state); + +/** + * Liest Zahlen passend fuer jscanf ein, d.h. es wird so lange gelesen, wie + * theoretisch noch eine gueltige Zahl herauskommen koennte. Das Parsen und + * Entscheiden, ob es tatsaechlich eine gueltige Zahl ist, bleibt dem Aufrufer + * ueberlassen. + * + * @param buf Puffer, in den die Zeichen eingelesen werden + * @param size Laenge des Puffers in einlesbaren Zeichen. Es muss mindestens + * Platz fuer size + 1 Zeichen vorhanden sein, da noch ein Nullbyte geschrieben + * wird. + * @param jgetc Funktion, um ein Zeichen auszulesen + * @param jungetc Funktion, um ein Zeichen zurueckzugeben, wenn es doch nicht + * passt + * @param state Zustand der Eingabe fuer jgetc/jungetc + * @param base Basis der einzulesenden Zahl (8, 10 oder 16) + * @param eof Wird auf 1 gesetzt, wenn die Eingabe wegen EOF beendet wurde, auf + * 0, wenn ein unpassendes Zeichen gekommen ist + * + * @return Anzahl der in den Puffer eingelesenen Zeichen + */ +static int jscanf_read_number(char* buf, int size, jscanf_getc jgetc, + jscanf_ungetc jungetc, void* state, int base, int* eof) +{ + int valid; + int i; + int c; + int first_digit = 0; + + *eof = 0; + i = 0; + while (i < size) { + c = jgetc(state); + + if (c == EOF) { + *eof = 1; + break; + } + + valid = 0; + switch (c) { + case '+': + case '-': + if (i == 0) { + valid = 1; + first_digit++; + } + break; + case '0': + valid = 1; + break; + case '1' ... '7': + if (base == 0) { + base = buf[first_digit] == '0' ? 8 : 10; + } + valid = 1; + break; + case '8' ... '9': + if (base == 0) { + base = buf[first_digit] == '0' ? 8 : 10; + } + valid = (base != 8); + break; + case 'A' ... 'F': + case 'a' ... 'f': + valid = (base == 16); + break; + case 'x': + if (base == 0) { + base = 16; + } + if ((base == 16) && (i == first_digit + 1) && + (buf[first_digit] == '0')) + { + valid = 1; + } + break; + } + + if (!valid) { + jungetc(state, c); + break; + } + + buf[i] = c; + i++; + } + + buf[i] = '\0'; + + return i; +} + +/** + * Weist eine Zahl einer Variablen zu. Die Groesse der Variablen wird dabei + * als Parameter uebergeben. + * + * @param ptr Variable, in die die Zahl geschrieben werden soll + * @param value Wert, der der Variablen zugewiesen werden soll + * @param size Groesse der Variablen in Bytes + */ +static void assign_number(void* ptr, uint64_t value, int size) +{ + if (size == 1) { + uint8_t* tptr = ptr; + *tptr = (uint8_t) value; + } else if (size == 2) { + uint16_t* tptr = ptr; + *tptr = (uint16_t) value; + } else if (size == 4) { + uint32_t* tptr = ptr; + *tptr = (uint32_t) value; + } else if (size == 8) { + uint64_t* tptr = ptr; + *tptr = (uint64_t) value; + } else { + abort(); + } +} + +/** + * Die eigentliche scanf-Engine, die den Formatstring verarbeitet und die + * eingelesenen Daten in die uebergebenen Parameter schreibt. Die + * Eingabezeichen werden mit den uebergebenen Funktionen geholt. + * + * @param fmt scanf-Formatstring + * @param ap Liste der Ausgabevariablen + * @param jgetc Funktion, um ein Zeichen auszulesen + * @param jungetc Funktion, um ein Zeichen zurueckzugeben, wenn es doch nicht + * passt + * @param jtell Funktion, die die Anzahl der bisher gelesenen Zeichen + * zurueckgibt + * @param state Zustand der Eingabe fuer jgetc/jungetc + * + * @return Anzahl der erfolgreich zugewiesenen Variablen; EOF, wenn ein + * Eingabefehler auftritt, bevor mindestens eine Variable erfolgreich + * eingelesen wurde. + */ +static int jscanf(const char* fmt, va_list ap, + jscanf_getc jgetc, jscanf_ungetc jungetc, jscanf_tell jtell, void* state) +{ + int ret = 0; + int assign; + int len; + int size; + int c; + char* endptr; + uint64_t value; + + // 64 Bit oktal = 22 Zeichen, Vorzeichen und \0 + char buf[24]; + + while (*fmt) { + switch (*fmt) { + case ' ': + case '\t': + case '\n': + case '\f': + case '\v': + do { + c = jgetc(state); + } while (isspace(c)); + break; + + case '%': + fmt++; + + // Ein * bedeutet, dass der Wert nur eingelesen, aber keiner + // Variablen zugewiesen wird + if (*fmt == '*') { + assign = 0; + fmt++; + } else { + assign = 1; + } + + // Optional kann jetzt die Feldlaenge kommen + if (isdigit(*fmt)) { + len = strtol(fmt, (char**) &fmt, 10); + if (len == 0) { + goto matching_error; + } + } else { + len = 0; + } + + // Und die Laenge der Variablen kann auch noch angegeben sein + switch (*fmt) { + case 'h': + if (*++fmt == 'h') { + fmt++; + size = sizeof(char); + } else { + size = sizeof(short); + } + break; + case 'l': + if (*++fmt == 'l') { + fmt++; + size = sizeof(long long); + } else { + size = sizeof(long); + } + break; + case 'j': + size = sizeof(intmax_t); + break; + case 't': + size = sizeof(ptrdiff_t); + break; + case 'z': + size = sizeof(size_t); + break; + default: + size = sizeof(int); + break; + } + + // Whitespace muss uebersprungen werden (ausser %[ %c %n) + if ((*fmt != '[') && (*fmt != 'c') && (*fmt != 'n')) { + while (isspace(c = jgetc(state))); + if (c != EOF) { + jungetc(state, c); + } + } + + // Eingabe parsen + switch (*fmt) { + int base; + int eof; + + // %i - Integer (strtol mit Basis 0) + // %d - Integer (strtol mit Basis 10) + // %o - Integer (strtoul mit Basis 8 + // %u - Integer (strtoul mit Basis 1) + // %x - Integer (strtoul mit Basis 16) + // %X - Integer (strtoul mit Basis 16) + // %p - Pointer (strtoul mit Basis 16) + case 'i': + base = 0; + goto convert_number; + case 'o': + base = 8; + goto convert_number; + case 'x': + case 'X': + base = 16; + goto convert_number; + case 'p': + base = 16; + size = sizeof(void*); + len = 0; + goto convert_number; + case 'd': + case 'u': + base = 10; + convert_number: + if (len == 0 || len >= sizeof(buf)) { + len = sizeof(buf) - 1; + } + len = jscanf_read_number(buf, len, jgetc, jungetc, + state, base, &eof); + + value = strtoull(buf, &endptr, base); + if ((endptr != buf + len) || (len == 0)) { + if ((len == 0) && eof) { + goto input_error; + } + goto matching_error; + } + + if (assign) { + void* ptr = va_arg(ap, void*); + assign_number(ptr, value, size); + ret++; + } + break; + + // %n - Anzahl der bisher gelesenen Zeichen + case 'n': + if (assign) { + void* ptr = va_arg(ap, void*); + assign_number(ptr, jtell(state), size); + } + break; + + // %c - char-Array (feste Laenge, kein Nullbyte) + case 'c': + { + // TODO Multibyte-Zeichen + int i; + char* ptr = NULL; + + if (assign) { + ptr = va_arg(ap, char*); + } + + if (len == 0) { + len = 1; + } + + for (i = 0; i < len; i++) { + c = jgetc(state); + if (c == EOF) { + goto input_error; + } + if (assign) { + ptr[i] = c; + } + } + + if (assign) { + ret++; + } + break; + } + + // %s - Whitespaceterminierter String + case 's': + { + // TODO MUltibyte-Zeichen + char* ptr = NULL; + int matched = 0; + + if (assign) { + ptr = va_arg(ap, char*); + } + + if (len == 0) { + len = -1; + } + + while ((len == -1) || len--) { + c = jgetc(state); + if (isspace(c)) { + jungetc(state, c); + break; + } else if (c == EOF) { + break; + } + matched = 1; + if (assign) { + *ptr++ = c; + } + } + + // Matching Error ist nicht moeglich, da alle + // Leerzeichen bereits vorher weggelesen werden und + // ansonsten alle Zeichen akzeptiert werden. + if (!matched) { + goto input_error; + } + + if (assign) { + *ptr = '\0'; + ret++; + } + break; + } + + // %[ - String aus einer Zeicheklasse + case '[': + { + const char* p = fmt; + const char* end; + int negation = 0; + int match = 0; + char* ptr = NULL; + + if (assign) { + ptr = va_arg(ap, char*); + } + + // Wenn das Scanset mit ^ anfaengt, duerfen die Zeichen + // des Scansets _nicht_ vorkommen + if (*++p == '^') { + negation = 1; + p++; + } + + // Scanset zusammenbasteln + if (*p == '\0') { + abort(); + } + + end = strchr(p + 1, ']'); + if (end == NULL) { + abort(); + } + + char scanset[end - p + 1]; + scanset[end - p] = '\0'; + strncpy(scanset, p, end - p); + + // Hier kommt das eigentliche Matching + if (len == 0) { + len = -1; + } + + c = EOF; + while ((len == -1) || len--) { + c = jgetc(state); + if (c == EOF) { + break; + } else if (!!strchr(scanset, c) == negation) { + jungetc(state, c); + break; + } + match = 1; + if (assign) { + *ptr++ = c; + } + } + + if (!match) { + if (c == EOF) { + goto input_error; + } else { + goto matching_error; + } + } + + if (assign) { + *ptr = '\0'; + ret++; + } + + fmt = end; + + break; + } + + // %% - Prozentzeichen + case '%': + goto parse_percent; + + // Das Verhalten bei ungueltiger Conversion Specification + // ist undefiniert. + default: + abort(); + } + break; + + // Ein einzelnes Zeichen wird direkt gematcht + parse_percent: + default: + c = jgetc(state); + if (c == EOF) { + goto input_error; + } + if (c != *fmt) { + goto matching_error; + } + break; + } + + fmt++; + } + +matching_error: + return ret; + +input_error: + if (ret == 0) { + return EOF; + } + return ret; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// sscanf - Eingabe aus einem String + +struct sscanf_state { + const char* input; + int pos; +}; + +static int sscanf_getc(void* state) +{ + struct sscanf_state* s = state; + int ret = EOF; + + if (s->input[s->pos]) { + ret = s->input[s->pos]; + s->pos++; + } + + return ret; +} + +static void sscanf_ungetc(void* state, char c) +{ + struct sscanf_state* s = state; + + if (s->pos > 0) { + s->pos--; + if (s->input[s->pos] != c) { + abort(); + } + } else { + abort(); + } +} + +static int sscanf_tell(void* state) +{ + struct sscanf_state* s = state; + return s->pos; +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einem String aus + */ +int vsscanf(const char* input, const char* fmt, va_list ap) +{ + struct sscanf_state state = { + .input = input, + .pos = 0, + }; + + return jscanf(fmt, ap, sscanf_getc, sscanf_ungetc, sscanf_tell, &state); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einem String aus + */ +int sscanf(const char* input, const char* fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vsscanf(input, fmt, ap); + va_end(ap); + + return ret; +} + + + +/////////////////////////////////////////////////////////////////////////////// +// fscanf - Eingabe aus einer Datei + +struct fscanf_state { + FILE* file; + int pos; +}; + +static int fscanf_getc(void* state) +{ + struct fscanf_state* s = state; + FILE* f = s->file; + int c; + + c = fgetc(f); + if (c != EOF) { + s->pos++; + } + + return c; +} + +static void fscanf_ungetc(void* state, char c) +{ + struct fscanf_state* s = state; + FILE* f = s->file; + + s->pos--; + ungetc(c, f); +} + +static int fscanf_tell(void* state) +{ + struct fscanf_state* s = state; + return s->pos; +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einer Datei aus + */ +int vfscanf(FILE* f, const char* fmt, va_list ap) +{ + struct fscanf_state state = { + .file = f, + .pos = 0, + }; + return jscanf(fmt, ap, fscanf_getc, fscanf_ungetc, fscanf_tell, &state); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus einer Datei aus + */ +int fscanf(FILE* f, const char* fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vfscanf(f, fmt, ap); + va_end(ap); + + return ret; +} + + +/////////////////////////////////////////////////////////////////////////////// +// scanf - Eingabe aus der Standardeingabe + +/** + * Fuehrt ein jscanf mit Eingabe aus der Standardeingabe aus + */ +int vscanf(const char* fmt, va_list ap) +{ + return vfscanf(stdin, fmt, ap); +} + +/** + * Fuehrt ein jscanf mit Eingabe aus der Standardeingabe aus + */ +int scanf(const char* fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vscanf(fmt, ap); + va_end(ap); + + return ret; +} diff --git a/src/modules/lib/stdlibc/sscanf.c b/src/modules/lib/stdlibc/sscanf.c deleted file mode 100644 index 3082e3d..0000000 --- a/src/modules/lib/stdlibc/sscanf.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Antoine Kaufmann. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#ifndef CONFIG_LIBC_NO_STUBS -int sscanf(const char* str, const char* format, ...) -{ - // FIXME - puts("TODO in LOST-Libc: sscanf!"); - return 0; -} -#endif - -- 1.6.0.2 From toni at tyndur.org Sun Sep 20 17:38:19 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 17:38:19 +0200 Subject: [tyndur-devel] [PATCH 1/3] vterm: include-Verzeichnis anlegen In-Reply-To: <1252149678-24099-2-git-send-email-kevin@tyndur.org> References: <1252149678-24099-1-git-send-email-kevin@tyndur.org> <1252149678-24099-2-git-send-email-kevin@tyndur.org> Message-ID: <20090920153818.GA23087@neo.geekcave.lan> On Sat, Sep 05 13:21, Kevin Wolf wrote: > * vterm: Header in einem include-Verzeichnis koennen auch von > Unterverzeichnissen benutzt werden; solche im Hauptverzeichnis nicht. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Sep 20 17:51:06 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 17:51:06 +0200 Subject: [tyndur-devel] [PATCH 2/3] vterm: Tastaturbelegung aenderbar machen In-Reply-To: <1252149678-24099-3-git-send-email-kevin@tyndur.org> References: <1252149678-24099-1-git-send-email-kevin@tyndur.org> <1252149678-24099-3-git-send-email-kevin@tyndur.org> Message-ID: <20090920155105.GB23087@neo.geekcave.lan> On Sat, Sep 05 13:21, Kevin Wolf wrote: > + vterm: Ueber die Datei vterm:/keymap kann die Tastaturbelegung > veraendert werden > > Signed-off-by: Kevin Wolf > --- > src/modules/vterm/include/keymap.h | 18 +++++++++++++ > src/modules/vterm/keymap.c | 50 ++++++++++++++++++++++++++++++++++++ > src/modules/vterm/lostio.c | 10 +++++++ > src/modules/vterm/vterm.c | 4 +++ > src/modules/vterm/vterm.h | 1 + > 5 files changed, 83 insertions(+), 0 deletions(-) > > diff --git a/src/modules/vterm/include/keymap.h b/src/modules/vterm/include/keymap.h > index 668067e..dcbc0ba 100644 > --- a/src/modules/vterm/include/keymap.h > +++ b/src/modules/vterm/include/keymap.h > @@ -37,6 +37,7 @@ > #define _KEYMAP_H_ > #include > #include > +#include > > /** > * Eintrag in der Keymap > @@ -55,5 +56,22 @@ typedef struct keymap_entry { > */ > keymap_entry_t* keymap_get(uint8_t keycode); > > +/** > + * Legt die vterm:/keymap im Verzeichnisbaum an > + */ > +void keymap_init(void); > + > +/** > + * LostIO-Handller um die Tastaturbelegung zu lesen > + */ > +size_t keymap_read(lostio_filehandle_t* file, void* buf, > + size_t blocksize, size_t blockcount); > + > +/** > + * LostIO-Handler um die Tastaturbelegung zu aendern > + */ > +size_t keymap_write(lostio_filehandle_t* file, size_t blocksize, > + size_t blockcount, void* data); > + > #endif // ifndef _KEYMAP_H_ > > diff --git a/src/modules/vterm/keymap.c b/src/modules/vterm/keymap.c > index 4b5846f..c1881bd 100644 > --- a/src/modules/vterm/keymap.c > +++ b/src/modules/vterm/keymap.c > @@ -33,6 +33,10 @@ > * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > */ > > +#include > +#include > + > +#include "vterm.h" > #include "keymap.h" > > keymap_entry_t keymap[] = { > @@ -176,3 +180,49 @@ keymap_entry_t* keymap_get(uint8_t keycode) > return &keymap[keycode]; > } > > +/** > + * Legt die vterm:/keymap im Verzeichnisbaum an > + */ > +void keymap_init(void) > +{ > + stdout = NULL; Hm, das musst du mir aber erklären. ;-) > + vfstree_create_node("/keymap", LOSTIO_TYPES_KEYMAP, 0, NULL, 0); > +} > + > +/** > + * LostIO-Handller um die Tastaturbelegung zu lesen > + */ > +size_t keymap_read(lostio_filehandle_t* file, void* buf, > + size_t blocksize, size_t blockcount) > +{ > + size_t size = blocksize * blockcount; > + > + if (file->pos + size >= sizeof(keymap)) { > + size = sizeof(keymap) - file->pos; > + file->flags |= LOSTIO_FLAG_EOF; > + } > + > + memcpy(buf, ((uint8_t*) keymap) + file->pos, size); > + file->pos += size; > + > + return size; > +} > + > +/** > + * LostIO-Handler um die Tastaturbelegung zu aendern > + */ > +size_t keymap_write(lostio_filehandle_t* file, size_t blocksize, > + size_t blockcount, void* buf) > +{ > + size_t size = blocksize * blockcount; > + > + if (file->pos + size >= sizeof(keymap)) { > + size = sizeof(keymap) - file->pos; > + file->flags |= LOSTIO_FLAG_EOF; > + } > + > + memcpy(((uint8_t*) keymap) + file->pos, buf, size); > + file->pos += size; > + > + return size; > +} > diff --git a/src/modules/vterm/lostio.c b/src/modules/vterm/lostio.c > index a835d6a..1470fa7 100644 > --- a/src/modules/vterm/lostio.c > +++ b/src/modules/vterm/lostio.c > @@ -35,8 +35,11 @@ > #include > #include > #include > + > #include "vterm.h" > #include "lostio.h" > +#include "keymap.h" > + > /// Handler fuer Lesen aus in > size_t terminal_read(lostio_filehandle_t* handle, void* buf, > size_t blocksize, size_t blockcount); > @@ -83,6 +86,13 @@ void init_lostio_interface() > typehandle->link = NULL; > typehandle->unlink = NULL; > lostio_register_typehandle(typehandle); > + > + // Typehandle fuer Keymaps > + typehandle = calloc(1, sizeof(typehandle_t)); > + typehandle->id = LOSTIO_TYPES_KEYMAP; > + typehandle->read = &keymap_read; > + typehandle->write = &keymap_write; > + lostio_register_typehandle(typehandle); > } > > /** > diff --git a/src/modules/vterm/vterm.c b/src/modules/vterm/vterm.c > index d3fcd7f..d27fbc6 100644 > --- a/src/modules/vterm/vterm.c > +++ b/src/modules/vterm/vterm.c > @@ -41,6 +41,7 @@ > #include "vterm.h" > #include "sleep.h" > #include "init.h" > +#include "keymap.h" > > > /// Hier kommen die Eingaben fuer all die virtuellen Terminals her > @@ -67,6 +68,9 @@ int main(int argc, char* argv[]) > return -1; > } > > + // Tastaturbelegung konfigurierbar machen > + keymap_init(); > + > // Auf Anfragen warten > while(TRUE) { > wait_for_rpc(); > diff --git a/src/modules/vterm/vterm.h b/src/modules/vterm/vterm.h > index d5149da..0871db9 100644 > --- a/src/modules/vterm/vterm.h > +++ b/src/modules/vterm/vterm.h > @@ -39,6 +39,7 @@ > > #define LOSTIO_TYPES_OUT 255 > #define LOSTIO_TYPES_IN 254 > +#define LOSTIO_TYPES_KEYMAP 253 > > #define SCREEN_WIDTH_MAX 80 > #define SCREEN_HEIGHT_MAX 25 Sonst sieht das glaub ich vernünftig aus. ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Sep 20 17:56:38 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 17:56:38 +0200 Subject: [tyndur-devel] [PATCH 3/3] vterm: Tastaturbelegungen de und us In-Reply-To: <1252149678-24099-4-git-send-email-kevin@tyndur.org> References: <1252149678-24099-1-git-send-email-kevin@tyndur.org> <1252149678-24099-4-git-send-email-kevin@tyndur.org> Message-ID: <20090920155638.GA23823@neo.geekcave.lan> On Sat, Sep 05 13:21, Kevin Wolf wrote: > * vterm: Deutsche Tastaturbelegung auslagern und in system/keymaps > verfuegbar machen, aber weiterhin als Default dazulinken. > + vterm: Amerikanische Tastaturbelegung. Nur kompilieren und nach > system/keymaps kopieren. Wenn ich jetzt du wäre, würde ich ja da beanstanden, dass man das in 2 Patches aufsplitten soltte... ;-) > > Signed-off-by: Kevin Wolf Aber von mir aus kann das so rein. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Sep 20 18:01:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 18:01:31 +0200 Subject: [tyndur-devel] [PATCH] Pascal-RTL: ReadEscapeSequence In-Reply-To: <1252260140-29629-1-git-send-email-kevin@tyndur.org> References: <1252260140-29629-1-git-send-email-kevin@tyndur.org> Message-ID: <20090920160130.GB23823@neo.geekcave.lan> On Sun, Sep 06 20:02, Kevin Wolf wrote: > * Pascal-RTL: kedit hat so eine schoene Funktion, um den vt100-Kram > einzulesen und in was vernuenftiges umzuwanden. Das kann so ziemlich > jedes interaktiven Programm brauchen, also ab in die RTL damit. > > Signed-off-by: Kevin Wolf Sieht so aus als ob du den Code vernünftig verschoben hättest, reviewt habe ich die Funktion jetzt nicht nochmal... ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Sep 20 18:25:00 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 18:25:00 +0200 Subject: [tyndur-devel] [PATCH v2] libm: Rundungsfunktionen In-Reply-To: <1252694266-26546-1-git-send-email-kevin@tyndur.org> References: <1252694266-26546-1-git-send-email-kevin@tyndur.org> Message-ID: <20090920162500.GA24220@neo.geekcave.lan> On Fri, Sep 11 20:37, Kevin Wolf wrote: > + libm: floor, ceil, round, trunc, nearbyint, fesetround, fegetround > > Signed-off-by: Kevin Wolf > --- > src/modules/include/fenv.h | 42 ++++++++ > src/modules/include/math.h | 18 +++- > src/modules/lib/stdlibc/math/round.c | 182 ++++++++++++++++++++++++++++++++++ > 3 files changed, 241 insertions(+), 1 deletions(-) > create mode 100644 src/modules/include/fenv.h > create mode 100644 src/modules/lib/stdlibc/math/round.c > > diff --git a/src/modules/include/fenv.h b/src/modules/include/fenv.h > new file mode 100644 > index 0000000..10e9ded > --- /dev/null > +++ b/src/modules/include/fenv.h > @@ -0,0 +1,42 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#ifndef _FENV_H_ > +#define _FENV_H_ > + > +enum { > + FE_TONEAREST, > + FE_UPWARD, > + FE_DOWNWARD, > + FE_TOWARDZERO, > +}; > + > +int fegetround(void); > +int fesetround(int rounding_mode); > + > +#endif > diff --git a/src/modules/include/math.h b/src/modules/include/math.h > index 49083ab..1cbb54f 100644 > --- a/src/modules/include/math.h > +++ b/src/modules/include/math.h > @@ -50,7 +50,6 @@ > #define M_SQRT1_2 0.70710678118654752440 > > > - > double tan(double); > float tanf(float); > long double tanl(long double); > @@ -94,5 +93,22 @@ double acos(double); > float acosf(float); > long double acosl(long double); > > + > +double floor(double x); > +float floorf(float x); > +long double floorl(long double x); > +double ceil(double x); > +float ceilf(float x); > +long double ceill(long double x); > +double trunc(double x); > +float truncf(float x); > +long double truncl(long double x); > +double round(double x); > +float roundf(float x); > +long double roundl(long double x); > +double nearbyint(double x); > +float nearbyintf(float x); > +long double nearbyintl(long double x); > + > #endif > > diff --git a/src/modules/lib/stdlibc/math/round.c b/src/modules/lib/stdlibc/math/round.c > new file mode 100644 > index 0000000..b16a95a > --- /dev/null > +++ b/src/modules/lib/stdlibc/math/round.c > @@ -0,0 +1,182 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > + > +#define ROUND_NEAR 0x000 > +#define ROUND_DOWN 0x400 > +#define ROUND_UP 0x800 > +#define ROUND_TRUNC 0xc00 > + > +static int rounding_mode = FE_TONEAREST; > + > +/* > + * Achtung: > + * > + * Die folgende Funktion basieren auf der Annahme, dass das RC-Feld im FPU > + * Control Word normalerweise immer auf 0 gesetzt ist, also der neue Wert durch > + * ein einfaches or eingetragen werden kann. > + */ > +static inline long double do_round(long double x, int mode) > +{ > + long double res; > + uint16_t control_word; > + > + asm( > + // Rundungsmodus setzen > + "fnstcw %2;" > + "mov %2, %%eax;" > + "orl %3, %2;" > + "fldcw %2;" > + > + // Zahl auf dem Stack runden > + "frndint;" > + > + // Wieder den Standardrundungsmodus setzen > + "mov %%eax, %2;" > + "fldcw %2;" > + : "=t" (res) : "0" (x), "m" (control_word), "r" (mode) : "eax"); > + > + return res; > +} > + > + > +long double floorl(long double x) > +{ > + return do_round(x, ROUND_DOWN); > +} > + > +double floor(double x) > +{ > + return floorl(x); > +} > + > +float floorf(float x) > +{ > + return floorl(x); > +} > + > + > +long double ceill(long double x) > +{ > + return do_round(x, ROUND_UP); > +} > + > +double ceil(double x) > +{ > + return ceill(x); > +} > + > +float ceilf(float x) > +{ > + return ceill(x); > +} > + > +long double truncl(long double x) > +{ > + return do_round(x, ROUND_TRUNC); > +} > + > +double trunc(double x) > +{ > + return truncl(x); > +} > + > +float truncf(float x) > +{ > + return truncl(x); > +} > + > +long double roundl(long double x) > +{ > + long double res; > + > + asm("frndint" : "=t" (res) : "0" (x)); Hat es einen speziellen Grund, dass du hier nicht do_round mit ROUND_NEAR nimmst? Dann wäre man doch, sobald man mal do_round richtig macht, so richtig schön unabhängig von den aktuell gesetzten Flags... ;-) > + > + return res; > +} > + > +double round(double x) > +{ > + return roundl(x); > +} > + > +float roundf(float x) > +{ > + return roundl(x); > +} > + > +long double nearbyintl(long double x) > +{ > + switch (rounding_mode) { > + case FE_TONEAREST: > + return roundl(x); > + case FE_TOWARDZERO: > + return truncl(x); > + case FE_DOWNWARD: > + return floorl(x); > + case FE_UPWARD: > + return ceill(x); > + } > + > + abort(); > + return x; > +} > + > +double nearbyint(double x) > +{ > + return nearbyintl(x); > +} > + > +float nearbyintf(float x) > +{ > + return nearbyintl(x); > +} > + > +int fegetround(void) > +{ > + return rounding_mode; > +} > + > +int fesetround(int mode) > +{ > + switch(mode) { > + case FE_TONEAREST: > + case FE_TOWARDZERO: > + case FE_DOWNWARD: > + case FE_UPWARD: > + rounding_mode = mode; > + return 0; > + > + default: > + return -1; > + } > +} Sonst sieht das einigermassen vernünftig aus. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Sep 20 18:35:44 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 18:35:44 +0200 Subject: [tyndur-devel] [PATCH] strto(u)l: 0x ist nur ein Praefix, wenn danach noch was kommt In-Reply-To: <1253043716-7092-1-git-send-email-kevin@tyndur.org> References: <1253043716-7092-1-git-send-email-kevin@tyndur.org> Message-ID: <20090920163544.GB24220@neo.geekcave.lan> On Tue, Sep 15 21:41, Kevin Wolf wrote: > ! strtou(l): Wenn nach dem 0x keine gueltige Ziffer mehr kommt, ist es > entweder keine Hexzahl (Basis 0) oder eine Null ohne 0x vorne dran > (Basis 16). > > Signed-off-by: Kevin Wolf > --- > src/lib/stdlibc/strtol.c | 9 ++++++++- > src/lib/string.c | 15 ++++++++++++--- > 2 files changed, 20 insertions(+), 4 deletions(-) > > diff --git a/src/lib/stdlibc/strtol.c b/src/lib/stdlibc/strtol.c > index d605144..2387e98 100644 > --- a/src/lib/stdlibc/strtol.c > +++ b/src/lib/stdlibc/strtol.c > @@ -31,6 +31,13 @@ > #include "limits.h" > #include "types.h" > > +static int is_hexdigit(char x) > +{ > + return (x >= '0' && x <= '9') > + || (x >= 'a' && x <= 'f') > + || (x >= 'A' && x <= 'F'); > +} Was hast du denn gegen unser isxdigit()? > + > long strtol(const char *str, char **endptr, int base) > { > long retval = 0; > @@ -56,7 +63,7 @@ long strtol(const char *str, char **endptr, int base) > base = 16; > } > > - if (base == 16) { > + if (base == 16 && is_hexdigit(str[2])) { > str += 2; > } > } else if (base == 0) { > diff --git a/src/lib/string.c b/src/lib/string.c > index 3125c2c..ae809a6 100644 > --- a/src/lib/string.c > +++ b/src/lib/string.c > @@ -65,6 +65,13 @@ void itoa(unsigned int n, char *s, unsigned int base) > s[y] = '\0'; > } > > +static int is_hexdigit(char x) > +{ > + return (x >= '0' && x <= '9') > + || (x >= 'a' && x <= 'f') > + || (x >= 'A' && x <= 'F'); > +} Hier nochmal ;-) > + > unsigned long long int strtoull(const char *nptr, char **endptr, int base) > { > unsigned long long int result = 0; > @@ -94,8 +101,10 @@ unsigned long long int strtoull(const char *nptr, char **endptr, int base) > base = 10; > if (*nptr == '0') { > if (*++nptr == 'x') { > - base = 16; > - nptr++; > + if (is_hexdigit(nptr[1])) { > + base = 16; > + nptr++; > + } > } else { > base = 8; > } > @@ -103,7 +112,7 @@ unsigned long long int strtoull(const char *nptr, char **endptr, int base) > break; > > case 16: > - if ((*nptr == '0') && (*(nptr+1) == 'x')) { > + if ((*nptr == '0') && (nptr[1] == 'x') && is_hexdigit(nptr[2])) { > nptr += 2; > } > break; Abgesehen davon sieht das gut aus. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sun Sep 20 18:39:11 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 20 Sep 2009 18:39:11 +0200 Subject: [tyndur-devel] [PATCH v2] libm: Rundungsfunktionen In-Reply-To: <20090920162500.GA24220@neo.geekcave.lan> References: <1252694266-26546-1-git-send-email-kevin@tyndur.org> <20090920162500.GA24220@neo.geekcave.lan> Message-ID: <20090920163911.GA29560@silvanus> On Sun, Sep 20, 2009 at 06:25:00PM +0200, Antoine Kaufmann wrote: > On Fri, Sep 11 20:37, Kevin Wolf wrote: > > + libm: floor, ceil, round, trunc, nearbyint, fesetround, fegetround > > > > Signed-off-by: Kevin Wolf > > --- > > src/modules/include/fenv.h | 42 ++++++++ > > src/modules/include/math.h | 18 +++- > > src/modules/lib/stdlibc/math/round.c | 182 ++++++++++++++++++++++++++++++++++ > > 3 files changed, 241 insertions(+), 1 deletions(-) > > create mode 100644 src/modules/include/fenv.h > > create mode 100644 src/modules/lib/stdlibc/math/round.c > > > > diff --git a/src/modules/include/fenv.h b/src/modules/include/fenv.h > > new file mode 100644 > > index 0000000..10e9ded > > --- /dev/null > > +++ b/src/modules/include/fenv.h > > @@ -0,0 +1,42 @@ > > +/* > > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > > + * > > + * This code is derived from software contributed to the tyndur Project > > + * by Kevin Wolf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + * notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + * notice, this list of conditions and the following disclaimer in the > > + * documentation and/or other materials provided with the distribution. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > + */ > > + > > +#ifndef _FENV_H_ > > +#define _FENV_H_ > > + > > +enum { > > + FE_TONEAREST, > > + FE_UPWARD, > > + FE_DOWNWARD, > > + FE_TOWARDZERO, > > +}; > > + > > +int fegetround(void); > > +int fesetround(int rounding_mode); > > + > > +#endif > > diff --git a/src/modules/include/math.h b/src/modules/include/math.h > > index 49083ab..1cbb54f 100644 > > --- a/src/modules/include/math.h > > +++ b/src/modules/include/math.h > > @@ -50,7 +50,6 @@ > > #define M_SQRT1_2 0.70710678118654752440 > > > > > > - > > double tan(double); > > float tanf(float); > > long double tanl(long double); > > @@ -94,5 +93,22 @@ double acos(double); > > float acosf(float); > > long double acosl(long double); > > > > + > > +double floor(double x); > > +float floorf(float x); > > +long double floorl(long double x); > > +double ceil(double x); > > +float ceilf(float x); > > +long double ceill(long double x); > > +double trunc(double x); > > +float truncf(float x); > > +long double truncl(long double x); > > +double round(double x); > > +float roundf(float x); > > +long double roundl(long double x); > > +double nearbyint(double x); > > +float nearbyintf(float x); > > +long double nearbyintl(long double x); > > + > > #endif > > > > diff --git a/src/modules/lib/stdlibc/math/round.c b/src/modules/lib/stdlibc/math/round.c > > new file mode 100644 > > index 0000000..b16a95a > > --- /dev/null > > +++ b/src/modules/lib/stdlibc/math/round.c > > @@ -0,0 +1,182 @@ > > +/* > > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > > + * > > + * This code is derived from software contributed to the tyndur Project > > + * by Kevin Wolf. > > + * > > + * Redistribution and use in source and binary forms, with or without > > + * modification, are permitted provided that the following conditions > > + * are met: > > + * 1. Redistributions of source code must retain the above copyright > > + * notice, this list of conditions and the following disclaimer. > > + * 2. Redistributions in binary form must reproduce the above copyright > > + * notice, this list of conditions and the following disclaimer in the > > + * documentation and/or other materials provided with the distribution. > > + * > > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > + > > +#define ROUND_NEAR 0x000 > > +#define ROUND_DOWN 0x400 > > +#define ROUND_UP 0x800 > > +#define ROUND_TRUNC 0xc00 > > + > > +static int rounding_mode = FE_TONEAREST; > > + > > +/* > > + * Achtung: > > + * > > + * Die folgende Funktion basieren auf der Annahme, dass das RC-Feld im FPU > > + * Control Word normalerweise immer auf 0 gesetzt ist, also der neue Wert durch > > + * ein einfaches or eingetragen werden kann. > > + */ > > +static inline long double do_round(long double x, int mode) > > +{ > > + long double res; > > + uint16_t control_word; > > + > > + asm( > > + // Rundungsmodus setzen > > + "fnstcw %2;" > > + "mov %2, %%eax;" > > + "orl %3, %2;" > > + "fldcw %2;" > > + > > + // Zahl auf dem Stack runden > > + "frndint;" > > + > > + // Wieder den Standardrundungsmodus setzen > > + "mov %%eax, %2;" > > + "fldcw %2;" > > + : "=t" (res) : "0" (x), "m" (control_word), "r" (mode) : "eax"); > > + > > + return res; > > +} > > + > > + > > +long double floorl(long double x) > > +{ > > + return do_round(x, ROUND_DOWN); > > +} > > + > > +double floor(double x) > > +{ > > + return floorl(x); > > +} > > + > > +float floorf(float x) > > +{ > > + return floorl(x); > > +} > > + > > + > > +long double ceill(long double x) > > +{ > > + return do_round(x, ROUND_UP); > > +} > > + > > +double ceil(double x) > > +{ > > + return ceill(x); > > +} > > + > > +float ceilf(float x) > > +{ > > + return ceill(x); > > +} > > + > > +long double truncl(long double x) > > +{ > > + return do_round(x, ROUND_TRUNC); > > +} > > + > > +double trunc(double x) > > +{ > > + return truncl(x); > > +} > > + > > +float truncf(float x) > > +{ > > + return truncl(x); > > +} > > + > > +long double roundl(long double x) > > +{ > > + long double res; > > + > > + asm("frndint" : "=t" (res) : "0" (x)); > > Hat es einen speziellen Grund, dass du hier nicht do_round mit > ROUND_NEAR nimmst? Dann wäre man doch, sobald man mal do_round richtig > macht, so richtig schön unabhängig von den aktuell gesetzten Flags... > ;-) Genuine Effizienzität! ;-) Momentan werde ja in do_round die Flags werden nur dazugeodert, das Feld wird vorher nicht gelöscht. Insofern ist das eh nicht generisch. Nicht, dass es schwer wäre, das zu ändern, aber das überlasse ich dir. From kevin at tyndur.org Sun Sep 20 18:40:57 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 20 Sep 2009 18:40:57 +0200 Subject: [tyndur-devel] [PATCH] strto(u)l: 0x ist nur ein Praefix, wenn danach noch was kommt In-Reply-To: <20090920163544.GB24220@neo.geekcave.lan> References: <1253043716-7092-1-git-send-email-kevin@tyndur.org> <20090920163544.GB24220@neo.geekcave.lan> Message-ID: <20090920164057.GB29560@silvanus> On Sun, Sep 20, 2009 at 06:35:44PM +0200, Antoine Kaufmann wrote: > On Tue, Sep 15 21:41, Kevin Wolf wrote: > > ! strtou(l): Wenn nach dem 0x keine gueltige Ziffer mehr kommt, ist es > > entweder keine Hexzahl (Basis 0) oder eine Null ohne 0x vorne dran > > (Basis 16). > > > > Signed-off-by: Kevin Wolf > > --- > > src/lib/stdlibc/strtol.c | 9 ++++++++- > > src/lib/string.c | 15 ++++++++++++--- > > 2 files changed, 20 insertions(+), 4 deletions(-) > > > > diff --git a/src/lib/stdlibc/strtol.c b/src/lib/stdlibc/strtol.c > > index d605144..2387e98 100644 > > --- a/src/lib/stdlibc/strtol.c > > +++ b/src/lib/stdlibc/strtol.c > > @@ -31,6 +31,13 @@ > > #include "limits.h" > > #include "types.h" > > > > +static int is_hexdigit(char x) > > +{ > > + return (x >= '0' && x <= '9') > > + || (x >= 'a' && x <= 'f') > > + || (x >= 'A' && x <= 'F'); > > +} > > Was hast du denn gegen unser isxdigit()? 1. Das wär ja viel zu einfach 2. Viel - siehe folgende Patches ;-) Ich änder's ab. From toni at tyndur.org Sun Sep 20 18:41:01 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 18:41:01 +0200 Subject: [tyndur-devel] [PATCH] libc: ctype.h-Funktionen sollten keine Makros sein In-Reply-To: <1253446264-25058-1-git-send-email-kevin@tyndur.org> References: <1253446264-25058-1-git-send-email-kevin@tyndur.org> Message-ID: <20090920164101.GC24220@neo.geekcave.lan> On Sun, Sep 20 13:31, Kevin Wolf wrote: > ! libc: Parameter mehrfach auswerten in isspace() usw. ist doof > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Sep 20 18:52:00 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 20 Sep 2009 18:52:00 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Konfigurationsdateien haben ein Nullbyte zuviel In-Reply-To: <1252141457-22050-1-git-send-email-kevin@tyndur.org> References: <1252141457-22050-1-git-send-email-kevin@tyndur.org> Message-ID: <20090920165159.GD24220@neo.geekcave.lan> On Sat, Sep 05 11:04, Kevin Wolf wrote: > ! tcpip: An Ende von IP und MAC gehoert kein Nullbyte. kedit zeigt das > naemlich sogar an. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From alex at tyndur.org Mon Sep 21 12:54:07 2009 From: alex at tyndur.org (Alexander Siol) Date: Mon, 21 Sep 2009 12:54:07 +0200 Subject: [PATCH 0/6] Grafik für tyndur Message-ID: Diese Patchreihe fügt Video zu CDI hinzu, enthält einen vesa/vbe-Treiber (der aber nur unter QEMU funktioniert), die Userspace-Lib für "lowlevel"-Grafik (d.h. Kommunikation mit Treiber, keine GUI-Dienste o.ä.), sowie ein einfaches Testprogramm. Zum Testen: * wie gewohnt kompilieren * in tyndur: start modules/vesa gfxtest ------------------------------------ Alexander Siol (6): + cdi: video-Header + libvideo: Header + cdi.video: tyndur-Bibliothek + cdi.video: vesa + videolib + gfxtest: Testprogramm für videolib und cdi.video src/modules/c/gfxtest/Makefile.all | 8 + src/modules/c/gfxtest/main.c | 110 +++++++ src/modules/cdi/include/cdi.h | 1 + src/modules/cdi/include/cdi/vesa.h | 92 ++++++ src/modules/cdi/include/cdi/video.h | 274 ++++++++++++++++ src/modules/cdi/lib/video/bitmap.c | 76 +++++ src/modules/cdi/lib/video/bitmap.h | 51 +++ src/modules/cdi/lib/video/context.c | 102 ++++++ src/modules/cdi/lib/video/context.h | 64 ++++ src/modules/cdi/lib/video/rpc.c | 576 ++++++++++++++++++++++++++++++++++ src/modules/cdi/lib/video/vesa.c | 190 +++++++++++ src/modules/cdi/lib/video/video.c | 236 ++++++++++++++ src/modules/cdi/lib/video/video.h | 26 ++ src/modules/cdi/vesa/Makefile.all | 6 + src/modules/cdi/vesa/bitmap.c | 79 +++++ src/modules/cdi/vesa/bitmap.h | 14 + src/modules/cdi/vesa/device.c | 180 +++++++++++ src/modules/cdi/vesa/device.h | 15 + src/modules/cdi/vesa/drawing.c | 341 ++++++++++++++++++++ src/modules/cdi/vesa/drawing.h | 59 ++++ src/modules/cdi/vesa/main.c | 124 ++++++++ src/modules/cdi/vesa/vesa.h | 47 +++ src/modules/include/video/commands.h | 63 ++++ src/modules/include/video/drawing.h | 187 +++++++++++ src/modules/include/video/rop.h | 41 +++ src/modules/include/video/video.h | 105 ++++++ src/modules/lib/video/bitmaps.c | 86 +++++ src/modules/lib/video/context.c | 110 +++++++ src/modules/lib/video/drawing.c | 101 ++++++ src/modules/lib/video/query.c | 61 ++++ src/modules/lib/video/video.c | 67 ++++ 31 files changed, 3492 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/gfxtest/Makefile.all create mode 100644 src/modules/c/gfxtest/main.c create mode 100644 src/modules/cdi/include/cdi/vesa.h create mode 100644 src/modules/cdi/include/cdi/video.h create mode 100644 src/modules/cdi/lib/video/bitmap.c create mode 100644 src/modules/cdi/lib/video/bitmap.h create mode 100644 src/modules/cdi/lib/video/context.c create mode 100644 src/modules/cdi/lib/video/context.h create mode 100644 src/modules/cdi/lib/video/rpc.c create mode 100644 src/modules/cdi/lib/video/vesa.c create mode 100644 src/modules/cdi/lib/video/video.c create mode 100644 src/modules/cdi/lib/video/video.h create mode 100644 src/modules/cdi/vesa/Makefile.all create mode 100644 src/modules/cdi/vesa/bitmap.c create mode 100644 src/modules/cdi/vesa/bitmap.h create mode 100644 src/modules/cdi/vesa/device.c create mode 100644 src/modules/cdi/vesa/device.h create mode 100644 src/modules/cdi/vesa/drawing.c create mode 100644 src/modules/cdi/vesa/drawing.h create mode 100644 src/modules/cdi/vesa/main.c create mode 100644 src/modules/cdi/vesa/vesa.h create mode 100644 src/modules/include/video/commands.h create mode 100644 src/modules/include/video/drawing.h create mode 100644 src/modules/include/video/rop.h create mode 100644 src/modules/include/video/video.h create mode 100644 src/modules/lib/video/bitmaps.c create mode 100644 src/modules/lib/video/context.c create mode 100644 src/modules/lib/video/drawing.c create mode 100644 src/modules/lib/video/query.c create mode 100644 src/modules/lib/video/video.c From alex at tyndur.org Mon Sep 21 12:54:08 2009 From: alex at tyndur.org (Alexander Siol) Date: Mon, 21 Sep 2009 12:54:08 +0200 Subject: [tyndur-devel] [PATCH 1/6] + cdi: video-Header In-Reply-To: References: Message-ID: <5e589d6aa650fe257ec43c3b3325bccc4ebcf279.1253530182.git.alex@tyndur.org> Signed-off-by: Alexander Siol --- src/modules/cdi/include/cdi.h | 1 + src/modules/cdi/include/cdi/vesa.h | 92 ++++++++++++ src/modules/cdi/include/cdi/video.h | 274 +++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/include/cdi/vesa.h create mode 100644 src/modules/cdi/include/cdi/video.h diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 7bcf9e4..fee8976 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -26,6 +26,7 @@ typedef enum { CDI_NETWORK = 1, CDI_STORAGE = 2, CDI_SCSI = 3, + CDI_VIDEO = 4, } cdi_device_type_t; struct cdi_driver; diff --git a/src/modules/cdi/include/cdi/vesa.h b/src/modules/cdi/include/cdi/vesa.h new file mode 100644 index 0000000..f8ff636 --- /dev/null +++ b/src/modules/cdi/include/cdi/vesa.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2008-2009 Mathias Gottschlag, Janosch Graef, Alexander Siol + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef _CDI_VESA_H_ +#define _CDI_VESA_H_ + +#include +#include +#include + +/** + * VESA information block, used to get information about the card like video + * modes + */ +struct cdi_video_vesa_info_block { + char signature[4]; + char version[2]; + uint32_t oemname; + uint32_t capabilities; + uint32_t modeptr; + uint16_t videomem; + // VBE 2.0 + uint16_t oemversion; + uint32_t vendornameptr; + uint32_t productnameptr; + uint32_t revisionptr; + uint16_t modes[111]; + uint8_t oem[256]; +} __attribute__ ((packed)); + +struct cdi_video_vesa_mode_info { + uint16_t modeattr; + uint8_t windowattra; + uint8_t windowattrb; + uint16_t windowgran; + uint16_t windowsize; + uint16_t startsega; + uint16_t startsegb; + uint32_t posfunc; + uint16_t scanline; + + uint16_t width; + uint16_t height; + uint8_t charwidth; + uint8_t charheight; + uint8_t planecount; + uint8_t depth; + uint8_t banks; + uint8_t type; + uint8_t banksize; + uint8_t imagepages; + uint8_t reserved; + // VBE v1.2+ + uint8_t redmasksize; + uint8_t redfieldpos; + uint8_t greenmasksize; + uint8_t greenfieldpos; + uint8_t bluemasksize; + uint8_t bluefieldpos; + uint8_t resmasksize; + uint8_t resfieldsize; + uint8_t dircolormode; + // VBE v2.0 + uint32_t linearfb; + uint32_t offscreenmem; + uint32_t offscreensize; + + char reserved2[206]; +} __attribute__ ((packed)); + +struct cdi_video_vesa_mode { + struct cdi_video_displaymode mode; + uint16_t vesamode; +}; + +struct cdi_video_vesa_info_block cdi_vesa_infoblock; + +int cdi_video_vesa_initialize + (struct cdi_video_vesa_info_block **vesainfo, + void (*mode_callback)(int modenum, struct cdi_video_vesa_mode_info *mode)); + +struct cdi_video_vesa_mode_info* cdi_video_vesa_get_mode(int modenum); +int cdi_video_vesa_change_mode(int modenum); + +#endif diff --git a/src/modules/cdi/include/cdi/video.h b/src/modules/cdi/include/cdi/video.h new file mode 100644 index 0000000..c42dbfe --- /dev/null +++ b/src/modules/cdi/include/cdi/video.h @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2007-2009 Mathias Gottschlag, Janosch Graef, Alexander Siol + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef _CDI_VIDEO_H_ +#define _CDI_VIDEO_H_ + +#include "cdi.h" +#include "cdi/lists.h" + +struct cdi_video_displaymode { + unsigned int width; + unsigned int height; + unsigned int depth; + int refreshrate; // 0 für Irrelevant +}; + +enum cdi_video_bitmap_usage_hint { + CDI_VIDEO_PRIO_HIGH, + CDI_VIDEO_PRIO_NORMAL, + CDI_VIDEO_PRIO_LOW, +}; + +struct cdi_video_pixel_format { + char bpp; + uint32_t red_bits, red_offset; + uint32_t green_bits, green_offset; + uint32_t blue_bits, blue_offset; + uint32_t alpha_bits, alpha_offset; +}; + +struct cdi_video_bitmap { + int width; + int height; + struct cdi_video_pixel_format format; + int pitch; + + struct cdi_video_device *device; + + /// 1 wenn im VRAM, 0 wenn im RAM + int in_vram; + + /// Addresse + int *pixeldata; +}; + +enum cdi_video_raster_op { + CDI_VIDEO_ROP_COPY, + CDI_VIDEO_ROP_OR, + CDI_VIDEO_ROP_AND, + CDI_VIDEO_ROP_XOR, + // TODO: Erweitern +}; + +struct cdi_video_device { + /// CDI-Geraet + struct cdi_device dev; + + /// Liste der Bildschirme + cdi_list_t displays; + + /// Aktuelle RasterOP (fuer Software-Helfer noetig) + enum cdi_video_raster_op raster_op; + + /// Daten zur Moduswiederherstellung + void* restore_data; + + /// Pointer zum Beginn des (gemappten) VRAM + void* vram; + + /// Groesse des VRAM + size_t vram_size; +}; + +struct cdi_video_display { + /// Videogeraet, dem dieser Bildschirm angehoert + struct cdi_video_device *device; + + /// Momentaner Modus + struct cdi_video_displaymode *mode; + + /// Liste mit verfuegbaren Modi + cdi_list_t modes; + + /// Zeichenbuffer fuer Display + struct cdi_video_bitmap *frontbuffer; +}; + +struct cdi_video_color { + uint8_t alpha; + uint8_t red; + uint8_t green; + uint8_t blue; +}; + +struct cdi_video_driver { + /// CDI-Treiber + struct cdi_driver drv; + + // Basis-Funktionen + /** + * Sichert die aktiven Modi der Displays zur spaeteren Wiederherstellung + * @param device Das zu sichernde Device + * @return 0 = Erfolg; -1 = Fehlschlag + */ + int (*driver_save)(struct cdi_video_device *device); + + /** + * Stellt den gesicherten Zustand wieder her. + * @param device Das Device das wiederherstellen soll + * @return 0 = Erfolg; -1 = Fehlschlag + */ + int (*driver_restore)(struct cdi_video_device *device); + + + + // Anzeigenkontrolle + + /** + * Setzt die Aufloesung eines Bildschirms + * @param display Bildschirm + * @param mode Modus + * @return 0 = Erfolg; -1 = Fehlschlag + */ + int (*display_set_mode) + (struct cdi_video_device *device, struct cdi_video_display *display, + struct cdi_video_displaymode *mode); + + + + // Bitmap-Funktionen + + /** + * Erstellt ein Bitmap + * @param width Breite des Bitmaps + * @param height Hoehe des Bitmaps + * @param data Pixeldaten, oder 0, wenn das Bitmap vom Treiber beschrieben wird + */ + struct cdi_video_bitmap* (*bitmap_create) + (struct cdi_video_device *device, unsigned int width, + unsigned int height, void *data); + + /** + * Loescht ein Bitmap + * @param bitmap Zu loeschendes Bitmap + */ + void (*bitmap_destroy) + (struct cdi_video_device *device, struct cdi_video_bitmap *bitmap); + + /** + * Setzt den Gebrauchsmodus eines Bitmaps (bestimmt zB, ob ein Bitmap gecacht wird) + * @param device Videogeraet + * @param bitmap Betroffenes Bitmap + * @param hint Hinweis auf die Priorität des Bitmaps + */ + void (*bitmap_set_usage_hint) + (struct cdi_video_device *device, struct cdi_video_bitmap *bitmap, + enum cdi_video_bitmap_usage_hint hint); + + + + // Zeichen-Funktionen + + /** + * Setzt den Raster-Op für die folgenden Zeichenfunktionen. + * Der Raster-Op bestimmt, auf welche Art Grafik gezeichnet wird. + * @param display Display, auf das gezeichnet wird + * @param rop Raster-Op + * @note Kann nur angewendet werden wenn der Bildschirm aktiviert ist + */ + void (*set_raster_op) + (struct cdi_video_device *device, enum cdi_video_raster_op rop); + + /** + * Zeichnet eine Linie + * @param display Display, auf das gezeichnet wird + * @param x1 X-Koordinate des Anfangs + * @param y1 Y-Koordinate des Anfangs + * @param x1 X-Koordinate des Endpunktes + * @param y1 Y-Koordinate des Endpunktes + * @param color Farbe der Linie + * @note Kann nur angewendet werden wenn der Bildschirm aktiviert ist + */ + + void (*draw_line) + (struct cdi_video_bitmap *target, unsigned int x1, unsigned int y1, + unsigned int x2, unsigned int y2, struct cdi_video_color color); + /** + * Zeichnet ein Rechteck + * @param display Display, auf das gezeichnet wird + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite + * @param height Hoehe + * @param color Farbe des Rechtecks + */ + void (*draw_rectangle) + (struct cdi_video_bitmap *target, unsigned int x, unsigned int y, + unsigned int width, unsigned int height, struct cdi_video_color color); + + /** + * Zeichnet eine Ellipse + * @param display Display, auf das gezeichnet wird + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite + * @param height Hoehe + * @param color Farbe der Ellipse + */ + void (*draw_ellipse) + (struct cdi_video_bitmap *target, unsigned int x, unsigned int y, + unsigned int width, unsigned int height, struct cdi_video_color color); + + /** + * Zeichnet ein Bitmap + * @param display Display, auf das gezeichnet wird + * @param bitmap Zu zeichnendes Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + * @note Es wird nur so viel kopiert wie das Zielbitmap aufnehmen kann + */ + void (*draw_bitmap) + (struct cdi_video_bitmap *target, struct cdi_video_bitmap *bitmap, + unsigned int x, unsigned int y); + + /** + * Zeichnet einen Teil einer Bitmap + * @param display Display, auf das gezeichnet wird + * @param bitmap Zu zeichnendes Bitmap + * @param x X-Koordinate (Ziel) + * @param y Y-Koordinate (Ziel) + * @param srcx X-Koordinate (Quelle) + * @param srcy Y-Koordinate (Quelle) + * @param width Breite + * @param height Hoehe + */ + void (*draw_bitmap_part) + (struct cdi_video_bitmap *target, struct cdi_video_bitmap *bitmap, + unsigned int x, unsigned int y, unsigned int srcx, unsigned int srcy, + unsigned int width, unsigned int height); + + /** + * Zeichnet einen Punkt + * @param display Display, auf dem gezeichnet wird + * @param x X-Koordinate (Ziel) + * @param y Y-Koordinate (Ziel) + * @note Kann nur angewendet werden wenn der Bildschirm aktiviert ist + */ + void (*draw_dot) + (struct cdi_video_bitmap *target, unsigned int x, unsigned int y, + struct cdi_video_color color); +}; + +/** + * Initialisiert die Datenstrukturen fuer einen Grafikkartentreiber + */ +void cdi_video_driver_init(struct cdi_video_driver* driver); +/** + * Deinitialisiert die Datenstrukturen fuer einen Grafikkartentreiber + */ +void cdi_video_driver_destroy(struct cdi_video_driver* driver); +/** + * Registiert einen Grafikkartentreiber + */ +void cdi_video_driver_register(struct cdi_video_driver* driver); + + +#endif -- 1.6.0.4 From alex at tyndur.org Mon Sep 21 12:54:09 2009 From: alex at tyndur.org (Alexander Siol) Date: Mon, 21 Sep 2009 12:54:09 +0200 Subject: [tyndur-devel] [PATCH 2/6] + libvideo: Header In-Reply-To: <5e589d6aa650fe257ec43c3b3325bccc4ebcf279.1253530182.git.alex@tyndur.org> References: <5e589d6aa650fe257ec43c3b3325bccc4ebcf279.1253530182.git.alex@tyndur.org> Message-ID: Signed-off-by: Alexander Siol --- src/modules/include/video/commands.h | 63 ++++++++++++ src/modules/include/video/drawing.h | 187 ++++++++++++++++++++++++++++++++++ src/modules/include/video/rop.h | 41 ++++++++ src/modules/include/video/video.h | 105 +++++++++++++++++++ 4 files changed, 396 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/video/commands.h create mode 100644 src/modules/include/video/drawing.h create mode 100644 src/modules/include/video/rop.h create mode 100644 src/modules/include/video/video.h diff --git a/src/modules/include/video/commands.h b/src/modules/include/video/commands.h new file mode 100644 index 0000000..70516f8 --- /dev/null +++ b/src/modules/include/video/commands.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +/// Kommandos + +enum video_commands { +VIDEO_CMD_NULL = 0, + +/// Kontextsteuerung +VIDEO_CMD_CREATE_CONTEXT, +VIDEO_CMD_USE_CONTEXT, +VIDEO_CMD_USE_DEVICE, +VIDEO_CMD_USE_TARGET, +VIDEO_CMD_USE_COLOR, +VIDEO_CMD_USE_ROP, +VIDEO_CMD_GET_CMD_BUFFER, +VIDEO_CMD_DO_CMD_BUFFER, + +/// Geräteabfrage +VIDEO_CMD_GET_NUM_DEVICES, +VIDEO_CMD_GET_NUM_DISPLAYS, +VIDEO_CMD_GET_DISPLAY_MODES, + +/// Anderes +VIDEO_CMD_SET_RESOLUTION, + +/// Bitmaps +VIDEO_CMD_CREATE_BITMAP, +VIDEO_CMD_DESTROY_BITMAP, +VIDEO_CMD_CREATE_FRONTBUFFER_BITMAP, + +/// Primitiven Zeichnen +VIDEO_CMD_DRAW_PIXEL, +VIDEO_CMD_DRAW_RECTANGLE, +VIDEO_CMD_DRAW_ELLIPSE, +VIDEO_CMD_DRAW_LINE, +VIDEO_CMD_DRAW_BITMAP, +VIDEO_CMD_DRAW_BITMAP_PART, +}; \ No newline at end of file diff --git a/src/modules/include/video/drawing.h b/src/modules/include/video/drawing.h new file mode 100644 index 0000000..440acf9 --- /dev/null +++ b/src/modules/include/video/drawing.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2008 The LOST Project. All rights reserved. + * + * This code is derived from software contributed to the LOST Project + * by Mathias Gottschlag. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the LOST Project + * and its contributors. + * 4. Neither the name of the LOST Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DRAWING_H +#define DRAWING_H + +/** + * Startet einen Videokommandostream. Kommandos werden gebuffert per Shared + * Memory uebertragen. + */ +void video_start_command(void); +/** + * Beendet einen Videokommandostream und sendet ihn an den Treiber. + */ +void video_end_command(void); + +/** + * Raster Ops kontrollieren, wie etwas gezeichnet wird + */ +typedef enum video_rop { + /// Normales Schreiben aufs Ziel, Untergrund wird ueberschrieben + ROP_COPY, + /// Zwischen Untergrund und zu schreibendem wird ein "or" durchgeführt + /// Beispiel: Malen von Teilen mittels einer weissen Maske + ROP_OR, + /// Zwischen Untergrund und zu schreibendem wird ein "and" durchgeführt + /// Beispiel: Loeschen von Teilen mittels einer schwarzen Maske + ROP_AND, + /// Zwischen Untergrund und zu schreibendem wird ein "xor" durchgeführt + /// Beispiel: Invertieren eines Bildes durch Uebermalen mit weissem Rechteck + ROP_XOR +} video_rop_t; + +/** + * Stellt den Raster Op ein, der zum Zeichnen benutzt wird + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + */ +void video_set_rop(video_rop_t rop); + +/** + * Stellt das Ziel ein, auf das geschrieben wird. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param bitmap Zielbitmap. Wenn gleich 0, dann wird auf den Bildschirm + * geschrieben. + */ +void video_set_target(int bitmap); // 0 = Screen + +/** + * Zeichnet einen farbigen Punkt + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe des Punktes + * @param x X-Koordinate + * @param y Y-Koordinate + */ +void video_draw_dot(int color, int x, int y); +/** + * Zeichnet ein farbiges Rechteck + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe des Rechtecks + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite des Rechtecks + * @param height Hoehe des Rechtecks + */ +void video_draw_solid_rect(int color, int x, int y, int width, int height); +/** + * Zeichnet eine farbige Linie + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe der Linie + * @param x1 X-Koordinate des Startpunkts + * @param y1 Y-Koordinate des Startpunkts + * @param x2 X-Koordinate des Endpunkts + * @param y2 Y-Koordinate des Endpunkts + */ +void video_draw_line(int color, int x1, int y1, int x2, int y2); +/** + * Zeichnet eine farbige Ellipse + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe der Ellipse + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite der Ellipse + * @param height Hoehe der Ellipse + */ +void video_draw_ellipse(int color, int x, int y, int width, int height); + +/** + * Zeichnet ein komplettes Bitmap aufs Ziel. Das Bitmap muss vorher via + * video_upload_bitmap geladen worden sein. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param bitmap Zu benutzendes Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + */ +void video_draw_bitmap(int bitmap, int x, int y); +/** + * Zeichnet einen Teil eines Bitmaps aufs Ziel. Das Bitmap muss vorher via + * video_upload_bitmap geladen worden sein. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param bitmap Zu benutzendes Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + * @param srcx X-Koordinate des zu zeichnenden Teils + * @param srcy Y-Koordinate des zu zeichnenden Teils + * @param srcwidth Breite des zu zeichnenden Teils + * @param srcheight Hoehe des zu zeichnenden Teils + */ +void video_draw_bitmap_part(int bitmap, int x, int y, int srcx, int srcy, int srcwidth, int srcheight); +/** + * Zeichnet einen Teil aus dem Bildschirm aufs Ziel. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param x X-Koordinate + * @param y Y-Koordinate + * @param srcx X-Koordinate des zu zeichnenden Teils + * @param srcy Y-Koordinate des zu zeichnenden Teils + * @param srcwidth Breite des zu zeichnenden Teils + * @param srcheight Hoehe des zu zeichnenden Teils + */ +void video_copy_screen(int x, int y, int srcx, int srcy, int srcwidth, int srcheight); + +// Bitmapformate +#define BITMAP_FORMAT_MONO_1 0 +#define BITMAP_FORMAT_MONO_8 1 +#define BITMAP_FORMAT_R8G8B8_24 2 +#define BITMAP_FORMAT_B8G8R8_24 3 +#define BITMAP_FORMAT_R8G8B8_32 4 +#define BITMAP_FORMAT_B8G8R8_32 5 +#define BITMAP_FORMAT_R5G6B5_16 6 +#define BITMAP_FORMAT_B5G6R5_16 7 +#define BITMAP_FORMAT_R5G5B5_16 8 +#define BITMAP_FORMAT_B5G5R5_16 9 +#define BITMAP_FORMAT_GREY_8 10 + +/** + * Laedt ein Bitmap in den Videotreiber. + * @param data Pixeldaten oder 0, wenn das Bitmap nicht initialisiert werden soll + * @param width Breite des Bitmaps + * @param height Hoehe des Bitmaps + * @param format Format der Pixeldaten + * @return ID des Bitmaps + */ +int video_upload_bitmap(void *data, int width, int height, int format); +/** + * Loescht das Bitmap mit der angegebenen ID + * @param bitmap Zu loeschendes Bitmap + */ +void video_delete_bitmap(int bitmap); +/** + * Loescht alle Bitmaps, die zuvor via video_upload_bitmap in den Videotreiber + * geladen wurden + */ +void video_delete_all_bitmaps(void); + +#endif + diff --git a/src/modules/include/video/rop.h b/src/modules/include/video/rop.h new file mode 100644 index 0000000..0e5724e --- /dev/null +++ b/src/modules/include/video/rop.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#ifndef __VIDEO_ROP_H__ +#define __VIDEO_ROP_H__ + +// FIXME: Muss immer mit CDI (cdi/video.h) abgeglichen werden! + +typedef enum { + VIDEO_ROP_COPY, + VIDEO_ROP_OR, + VIDEO_ROP_AND, + VIDEO_ROP_XOR, + // TODO: Erweitern +} rop_t; + +#endif /* __VIDEO_ROP_H__ */ \ No newline at end of file diff --git a/src/modules/include/video/video.h b/src/modules/include/video/video.h new file mode 100644 index 0000000..7b303e9 --- /dev/null +++ b/src/modules/include/video/video.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#ifndef __LIBVIDEO_VIDEO_H__ +#define __LIBVIDEO_VIDEO_H__ + +#include +#include +#include