]> git.8kb.co.uk Git - dataflex/df32func/blobdiff - src/df32/data.inc
Just pushing the latest copy of my development / staging DataFlex stuff into git...
[dataflex/df32func] / src / df32 / data.inc
index 2bd8fa10d486434f508e02d25bccbc6c5af6020b..14eafd7b52c8407507a73240f85bfac759601242 100644 (file)
@@ -5,7 +5,7 @@
 //\r
 // This file is to be included in df32func.mk\r
 //\r
-// Copyright (c) 2006-2009, glyn@8kb.co.uk\r
+// Copyright (c) 2006-2015, glyn@8kb.co.uk\r
 // \r
 // df32func/data.inc\r
 //-------------------------------------------------------------------------\r
@@ -799,6 +799,8 @@ end_class
 //    hash_is_unique                - Add a unique constraint on the hash\r
 //    remove_hash_is_unique         - Remove a unique constraint from the hash\r
 //    matrix_index_lookup_clear     - Clear the lookup buffer\r
+//    matrix_append_csv                                - Append some data in CSV format to the array E.g. ('My Name,"My,\"address\""')\r
+//    matrix_copy_csv                          - Copy csv data from sprecified file into matrix\r
 //\r
 // Set methods:\r
 //    matrix_value                  - Set a value at X, Y\r
@@ -815,19 +817,22 @@ end_class
 //    matrix_index_lookup_clear     - Clear the buffer for an indexed lookup\r
 //    matrix_index_count_from_value - Get a count of rows with a particular value\r
 //    matrix_index_from_value       - Get the next X pos (row) with indexed value. Returns -1 when nothing left to find.\r
+//    item_count                                       - Get count of rows in matrix\r
+//    item_width                                       - Get count of columns in matrix\r
 //    \r
 // Example usage:\r
 //\r
-//\r
 //    object test is a matrix\r
 //    end_object\r
 //\r
 //    set matrix_value of (test(current_object)) item 0 item 1 to "1"    - x then y pos to Value\r
 //    get matrix_value of (test(current_object)) item 0 item 1 to tmpStr - x then y pos to Value\r
+//    send matrix_append_csv to test ('My Name,"My,\"address\""')        - Append CSV data to the end of the matrix\r
+//       send matrix_copy_csv to (test(current_object)) "f:\data.csv"          - Copy data from csv file into matrix\r
 //    send matrix_sort to (test(current_object)) 1               - x then y pos to sort by\r
 //    send matrix_delete to (test(current_object)) 1 1           - x then y pos to delete \r
 //    send matrix_delete_row to (test(current_object)) 1             - x essentially blanks record out, no reshuffle\r
-//    send delete_item to (test1(current_object)) 1              - x pos (not v efficient), reshuffles\r
+//    send delete_item to (test(current_object)) 1              - x pos (not v efficient), reshuffles\r
 //\r
 // Hash indexed columns usage:\r
 //\r
@@ -841,12 +846,16 @@ end_class
 //    get matrix_index_from_value of (test(current_object)) item "1" to x_pos   \r
 //    get matrix_indextable_from_value of (test(current_object)) item "1" to tmpStr \r
 //    get matrix_hash_from_value of (test(current_object)) item "1" to tmpInt   \r
+//       get item_count of (test(current_object) to tmpInt\r
+//    get item_width of (test(current_object) to tmpInt\r
 \r
 class matrix is an array\r
     procedure construct_object integer argc\r
         object mTokens is a StringTokenizer\r
         end_object\r
-    \r
+        object mTokens2 is a StringTokenizer\r
+        end_object\r
+        \r
         forward send construct_object\r
         property integer c_iWidth public argc\r
         property integer c_iHashOn\r
@@ -1024,6 +1033,44 @@ class matrix is an array
         end\r
     end_procedure\r
     \r
+    procedure matrix_append_csv string row        \r
+        local integer l_iMax l_iValues l_i\r
+        local string l_sBuf\r
+            \r
+        forward get item_count to l_iMax\r
+               \r
+               send delete_data to (mTokens2(current_object))\r
+               send set_string_csv to (mTokens2(current_object)) row\r
+               get token_count of (mTokens2(current_object)) to l_iValues\r
+               \r
+               for l_i from 0 to l_iValues                             \r
+                       get token_value of (mTokens2(current_object)) item l_i to l_sBuf\r
+                       indicate err false\r
+                       set matrix_value item l_iMax item l_i to l_sBuf                 \r
+                       if (err) forward send delete_item l_iMax\r
+                       if (err) break\r
+               loop\r
+\r
+    end_procedure\r
+    \r
+       procedure matrix_copy_csv string fname\r
+               local string l_sBuf\r
+               \r
+               if (does_exist(fname)) begin\r
+                       direct_input channel DEFAULT_FILE_CHANNEL fname\r
+                               while not (seqeof)\r
+                                       readln channel DEFAULT_FILE_CHANNEL l_sBuf\r
+                                       if (seqeof) break\r
+                                       if (trim(l_sBuf) <> "") begin\r
+                                               send matrix_append_csv l_sBuf\r
+                                       end\r
+                               loop\r
+                       close_input channel DEFAULT_FILE_CHANNEL\r
+               end\r
+               else;\r
+                       custom_error ERROR_CODE_FILE_NOT_FOUND$ ERROR_MSG_FILE_NOT_FOUND ERROR_DETAIL_FILE_NOT_FOUND fname                      \r
+       end_procedure    \r
+    \r
     function matrix_string integer itemx integer itemy returns string\r
         local string l_sBuf l_sTmp\r
 \r
@@ -1181,6 +1228,12 @@ class matrix is an array
     procedure set item_count integer newVal\r
         forward set item_count to newVal\r
     end_procedure\r
+    \r
+    function item_width returns integer\r
+           local integer l_iWidth\r
+           get c_iWidth to l_iWidth\r
+           function_return l_iWidth\r
+    end_function\r
         \r
     procedure matrix_delete integer itemx integer itemy\r
         local string l_sBuf l_sTmp l_sOldVal\r
@@ -1529,39 +1582,39 @@ class rss20 is a matrix
         get c_itemCount to l_itemCount\r
         get c_ttl to l_iTtl\r
     \r
-        direct_output channel default_file_channel rssFileName\r
-            writeln channel default_file_channel '<?xml version="1.0" ?>'\r
-            writeln channel default_file_channel '<?xml-stylesheet type="text/xsl" href="rss.xsl" media="screen"?>'\r
-            write channel default_file_channel '<rss version="2.0" xmlns:dc="http:/' '/purl.org/dc/elements/1.1/" xmlns:sy="http:/'\r
-            write channel default_file_channel '/purl.org/rss/1.0/modules/syndication/" xmlns:admin="http:/' '/webns.net/mvcb/" xmlns:rdf="http:/'\r
-            writeln channel default_file_channel '/www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http:/' '/purl.org/rss/1.0/modules/content/">'\r
+        direct_output channel DEFAULT_FILE_CHANNEL rssFileName\r
+            writeln channel DEFAULT_FILE_CHANNEL '<?xml version="1.0" ?>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '<?xml-stylesheet type="text/xsl" href="rss.xsl" media="screen"?>'\r
+            write channel DEFAULT_FILE_CHANNEL '<rss version="2.0" xmlns:dc="http:/' '/purl.org/dc/elements/1.1/" xmlns:sy="http:/'\r
+            write channel DEFAULT_FILE_CHANNEL '/purl.org/rss/1.0/modules/syndication/" xmlns:admin="http:/' '/webns.net/mvcb/" xmlns:rdf="http:/'\r
+            writeln channel DEFAULT_FILE_CHANNEL '/www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http:/' '/purl.org/rss/1.0/modules/content/">'\r
             \r
             // skipHours skipDays cloud - all currently not used\r
             // Write out Channel\r
-            writeln channel default_file_channel '       <channel>'\r
-            writeln channel default_file_channel '               <title>' (trim(l_rssTitle)) '</title>'\r
-            writeln channel default_file_channel '               <link>' (trim(l_rssLink)) '</link>'\r
-            writeln channel default_file_channel '               <description>' (trim(l_rssDesc)) '</description>'\r
-            writeln channel default_file_channel '               <language>en-gb</language>'\r
-            writeln channel default_file_channel '               <generator>Df32func RSS Object Generator</generator>'\r
-            writeln channel default_file_channel '               <copyright>Copyright ' (trim(l_rssTitle)) ' (C) ' (now("date")) '</copyright>'\r
-            writeln channel default_file_channel '               <lastBuildDate>' (rssdate((now("date")),(now("longtime")))) '</lastBuildDate>'\r
-            writeln channel default_file_channel '               <pubDate>' (rssdate((now("date")),(now("longtime")))) '</pubDate>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '       <channel>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <title>' (trim(l_rssTitle)) '</title>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <link>' (trim(l_rssLink)) '</link>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <description>' (trim(l_rssDesc)) '</description>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <language>en-gb</language>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <generator>Df32func RSS Object Generator</generator>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <copyright>Copyright ' (trim(l_rssTitle)) ' (C) ' (now("date")) '</copyright>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <lastBuildDate>' (rssdate((now("date")),(now("longtime")))) '</lastBuildDate>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '               <pubDate>' (rssdate((now("date")),(now("longtime")))) '</pubDate>'\r
             \r
-            if (l_manEditor <> "") writeln channel default_file_channel '               <managingEditor>' l_manEditor '</managingEditor>'\r
-            if (l_webMaster <> "") writeln channel default_file_channel '               <webMaster>' l_webMaster '</webMaster>'\r
-            if (l_iTtl <> 0) writeln channel default_file_channel '               <ttl>' l_iTtl '</ttl>'           \r
+            if (l_manEditor <> "") writeln channel DEFAULT_FILE_CHANNEL '               <managingEditor>' l_manEditor '</managingEditor>'\r
+            if (l_webMaster <> "") writeln channel DEFAULT_FILE_CHANNEL '               <webMaster>' l_webMaster '</webMaster>'\r
+            if (l_iTtl <> 0) writeln channel DEFAULT_FILE_CHANNEL '               <ttl>' l_iTtl '</ttl>'           \r
             \r
             // Write out image\r
             if ((l_imgUrl <> "") and (l_imgx > 0) and (l_imgy > 0)) begin\r
-                writeln channel default_file_channel '               <image>'\r
-                writeln channel default_file_channel '                       <title>' (trim(l_imgTitle)) '</title>'\r
-                writeln channel default_file_channel '                       <url>' (trim(l_imgUrl)) '</url>'\r
-                writeln channel default_file_channel '                       <link>' (trim(l_imgLink)) '</link>'\r
-                writeln channel default_file_channel '                       <height>' l_imgx '</height>'\r
-                writeln channel default_file_channel '                       <width>' l_imgy '</width>'\r
-                writeln channel default_file_channel '                       <description>' (trim(l_rssDesc)) '</description>'\r
-                writeln channel default_file_channel '               </image>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '               <image>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                       <title>' (trim(l_imgTitle)) '</title>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                       <url>' (trim(l_imgUrl)) '</url>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                       <link>' (trim(l_imgLink)) '</link>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                       <height>' l_imgx '</height>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                       <width>' l_imgy '</width>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                       <description>' (trim(l_rssDesc)) '</description>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '               </image>'\r
             end\r
             \r
             // Write out items\r
@@ -1580,10 +1633,10 @@ class rss20 is a matrix
                 move (replaces('<',l_itemDesc,"&lt;")) to l_itemDesc\r
                 move (replaces('>',l_itemDesc,"&gt;")) to l_itemDesc\r
                 \r
-                writeln channel default_file_channel '               <item>'\r
-                writeln channel default_file_channel '                      <title>' l_itemTitle '</title>'\r
-                writeln channel default_file_channel '                      <link>' l_itemLink '</link>'\r
-                writeln channel default_file_channel '                      <description>' l_itemDesc '</description>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '               <item>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                      <title>' l_itemTitle '</title>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                      <link>' l_itemLink '</link>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                      <description>' l_itemDesc '</description>'\r
                 \r
                 if (l_itemGuID = "") begin\r
                 move 0 to l_iConflict\r
@@ -1595,17 +1648,17 @@ class rss20 is a matrix
                 end\r
                 if (l_itemGuID <> "") append l_itemLink "#" l_itemGuID\r
                 \r
-                writeln channel default_file_channel '                      <guid isPermaLink="false">' l_itemLink '</guid>'\r
-                if ((l_pubDate = "") or (l_pubDate = "NOW")) writeln channel default_file_channel '                      <pubDate>' (rssdate((now("date")),(now("longtime")))) '</pubDate>'\r
-                else writeln channel default_file_channel '                      <pubDate>' l_pubDate '</pubDate>'\r
-                writeln channel default_file_channel '                      <category>' l_itemCat '</category>'\r
-                writeln channel default_file_channel '               </item>'          \r
+                writeln channel DEFAULT_FILE_CHANNEL '                      <guid isPermaLink="false">' l_itemLink '</guid>'\r
+                if ((l_pubDate = "") or (l_pubDate = "NOW")) writeln channel DEFAULT_FILE_CHANNEL '                      <pubDate>' (rssdate((now("date")),(now("longtime")))) '</pubDate>'\r
+                else writeln channel DEFAULT_FILE_CHANNEL '                      <pubDate>' l_pubDate '</pubDate>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '                      <category>' l_itemCat '</category>'\r
+                writeln channel DEFAULT_FILE_CHANNEL '               </item>'          \r
             loop\r
             \r
             // Write out file/channel close\r
-            writeln channel default_file_channel '       </channel>'\r
-            writeln channel default_file_channel '</rss>'  \r
-        close_output channel default_file_channel\r
+            writeln channel DEFAULT_FILE_CHANNEL '       </channel>'\r
+            writeln channel DEFAULT_FILE_CHANNEL '</rss>'  \r
+        close_output channel DEFAULT_FILE_CHANNEL\r
         \r
     end_procedure        \r
     \r
@@ -1674,13 +1727,13 @@ class filelist is a matrix
         set c_filelistDirectory to filelistDirectory\r
         set c_filelistName to filelistName\r
         \r
-        direct_input channel default_file_channel (filelistDirectory+filelistName)\r
+        direct_input channel DEFAULT_FILE_CHANNEL (filelistDirectory+filelistName)\r
             read_block l_sHead 256          \r
             while not (seqeof)          \r
                 //Block of 128 split 41\33\54\r
-                read_block channel default_file_channel l_sRootName 41\r
-                read_block channel default_file_channel l_sUserDisplayName 33\r
-                read_block channel default_file_channel l_sFileName 54\r
+                read_block channel DEFAULT_FILE_CHANNEL l_sRootName 41\r
+                read_block channel DEFAULT_FILE_CHANNEL l_sUserDisplayName 33\r
+                read_block channel DEFAULT_FILE_CHANNEL l_sFileName 54\r
 \r
                 move filelistDirectory to l_sUrn\r
                 append l_sUrn (trim(cstring(l_sFileName))) ".FD"\r
@@ -1698,7 +1751,7 @@ class filelist is a matrix
                     increment l_iFileNumber\r
                 end\r
             loop        \r
-        close_input channel default_file_channel\r
+        close_input channel DEFAULT_FILE_CHANNEL\r
     \r
         set c_itemCount to l_iFileNumber\r
     end_procedure\r