{"id":224,"date":"2016-06-16T18:59:05","date_gmt":"2016-06-16T16:59:05","guid":{"rendered":"http:\/\/arnoldvanhofwegen.com\/blog\/?p=224"},"modified":"2016-06-16T19:00:01","modified_gmt":"2016-06-16T17:00:01","slug":"delineenline-community-effort-part-2","status":"publish","type":"post","link":"https:\/\/arnoldvanhofwegen.com\/blog\/delineenline-community-effort-part-2\/","title":{"rendered":"DELINE\/ENLINE (community effort) Part 2"},"content":{"rendered":"<p>Hi,<\/p>\n<p>This is Part 2 yes, the previous post was Part 1 but I did not call it that.<\/p>\n<p>So now we proceed and make a first version for trying out, we add to<br \/>\n<code>runtime\\macros.reds<\/code><br \/>\nin #enum natives! after last entry the line<\/p>\n<pre>NAT_DELINE<\/pre>\n<p>We also add the deline function to natives.red<\/p>\n<pre>deline: make native! [[\r\n\t\t\"Converts string terminators to standard format, e.g. CRLF to LF. (Modifies)\"\r\n\t\tvalue [string!] \"The string to convert\"\r\n\t\t\/lines \"return a block of lines\"\r\n\t\t\/with\r\n\t\t\tstr [char! string!] \"Character or string to represent new line terminator\"\r\n\t]\r\n\t#get-definition NAT_DELINE\r\n]<\/pre>\n<p>Then we add code in <code>natives.reds<\/code>. At this moment we are not interested in making everything correct and functioning. Red\/System code with all the added types and using pointers and fields within the declared struct!s can get pretty confusing resulting in many possible compile errors. For every compile error you need to adapt your code and open a new Rebol console, load the %red.r file and compile the console again. So I give a compiling version that does not do anything but as a starting point to work from.<\/p>\n<pre>\tdeline*: func [\r\n\t\tcheck?   [logic!]\r\n\t\t_with [integer!]\t\t\t\t\t\t\t\t\t;-- with is reserved \r\n\t\tlines [integer!]\r\n\t\treturn: [c-string!]\r\n\t\t\/local\r\n\t\t\tdata \t[red-string!]\r\n\t\t\tbuffer\t[red-string!]\r\n\t\t\tval  \t[red-value!]\r\n\t\t\twith-arg [red-value!]\t\t\t\t\t\t\t;-- with char! or string! value\r\n\t\t\tchar \t[red-char!]\r\n\t\t\ts\t \t[series!]\r\n\t\t\tp\t\t[byte-ptr!]\r\n\t\t\tlen  \t[integer!]\r\n\t\t\tunit \t[integer!]\r\n\t\t\tc1   \t[integer!]\r\n\t\t\tblk\t\t[red-block!]\r\n\t\t\ttail      [byte-ptr!]\r\n\t\t\tcnt       [integer!]\r\n\t\t\tsize      [integer!]\r\n\t][\r\n\t\t#typecheck [deline _with lines]\r\n\t\tdata: as red-string! stack\/arguments\r\n\t\tprint lines print _with\r\n\t\tif positive? lines [\r\n\t\t\tprint \"lines refinement found\"\r\n\t\t\tblk: as red-block! 0\r\n\r\n\t\t\t;return \"\"\r\n\t\t\t; To do: return a block of lines using some split functionality\r\n\t\t]\r\n\t\teither positive? _with [\r\n\t\t\tprint \"with refinement found\"\r\n\t\t\tval: as red-value! data + 1\r\n\t\t\teither TYPE_OF(val) = TYPE_CHAR [\r\n\t\t\t\tprint \"char type\"\r\n\t\t\t\t;char: as red-char! val\r\n\t\t\t\tprint val\r\n\t\t\t][  print \"string type\"\r\n\t\t\t\tprint val\r\n\t\t\t]\r\n\t\t][print \"char\" ]\r\n\r\n\t\ts:  GET_BUFFER(data)\r\n\t\tunit: GET_UNIT(s)\r\n\t\tp:\t  string\/rs-head data\r\n\t\tlen:  string\/rs-length? data\r\n\t\ttail: as byte-ptr! s\/tail\r\n\r\n\r\n\t\t;buffer: string\/rs-make-at stack\/push* ( len + ( cnt * ( size - 1 ) ) ) * unit\r\n\r\n\t\treturn \"\"\r\n\t]\r\n<\/pre>\n<p>In the init function we also add the deline* function.<\/p>\n<p>As you see, lot&#8217;s of commented code, too many unused variables, print statements are present. It is still a mess. But it compiles. And it gives some hints to how things work.<\/p>\n<p>These are some results:<\/p>\n<pre>red&gt;&gt; deline\/lines \"hello\"\r\n1-1lines refinement foundchar== \"hello\"\r\nred&gt;&gt; deline\/with \"hello\" \"a\"\r\n-11with refinement foundstring type02333EE8== \"hello\"\r\nred&gt;&gt; deline\/with \"hello\" #\"a\"\r\n-11with refinement foundchar type02333EE8== \"hello\"\r\nred&gt;&gt; \r\n<\/pre>\n<p>First thing to repair is that all native functions work without the RETURN. When a different type needs to be returned the type of the return variable is changed.<br \/>\nExamples are <code>bool\/header: TYPE_LOGIC<\/code> or <code>pair\/header: TYPE_PAIR<\/code> or <code>f\/header: TYPE_FLOAT<\/code>.<\/p>\n<p>So next is experimenting with returning a block! in case of the \/lines refinement and a string! in all other cases.<\/p>\n<p>But that I will post soon&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, This is Part 2 yes, the previous post was Part 1 but I did not call it that. So now we proceed and make a first version for trying out, we add to runtime\\macros.reds in #enum natives! after last &hellip; <a href=\"https:\/\/arnoldvanhofwegen.com\/blog\/delineenline-community-effort-part-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts\/224"}],"collection":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/comments?post=224"}],"version-history":[{"count":1,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/posts\/224\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arnoldvanhofwegen.com\/blog\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}