X-Git-Url: https://git.8kb.co.uk/?p=dataflex%2Fdf32func;a=blobdiff_plain;f=src%2Fdf32%2Fdata.inc;fp=src%2Fdf32%2Fdata.inc;h=14eafd7b52c8407507a73240f85bfac759601242;hp=2bd8fa10d486434f508e02d25bccbc6c5af6020b;hb=0342737c4763de343d9d87c0cb25a8e31f0211e7;hpb=bcf238db90dafa502b8189b81769e4e0bfedc39c diff --git a/src/df32/data.inc b/src/df32/data.inc index 2bd8fa1..14eafd7 100644 --- a/src/df32/data.inc +++ b/src/df32/data.inc @@ -5,7 +5,7 @@ // // This file is to be included in df32func.mk // -// Copyright (c) 2006-2009, glyn@8kb.co.uk +// Copyright (c) 2006-2015, glyn@8kb.co.uk // // df32func/data.inc //------------------------------------------------------------------------- @@ -799,6 +799,8 @@ end_class // hash_is_unique - Add a unique constraint on the hash // remove_hash_is_unique - Remove a unique constraint from the hash // matrix_index_lookup_clear - Clear the lookup buffer +// matrix_append_csv - Append some data in CSV format to the array E.g. ('My Name,"My,\"address\""') +// matrix_copy_csv - Copy csv data from sprecified file into matrix // // Set methods: // matrix_value - Set a value at X, Y @@ -815,19 +817,22 @@ end_class // matrix_index_lookup_clear - Clear the buffer for an indexed lookup // matrix_index_count_from_value - Get a count of rows with a particular value // matrix_index_from_value - Get the next X pos (row) with indexed value. Returns -1 when nothing left to find. +// item_count - Get count of rows in matrix +// item_width - Get count of columns in matrix // // Example usage: // -// // object test is a matrix // end_object // // set matrix_value of (test(current_object)) item 0 item 1 to "1" - x then y pos to Value // get matrix_value of (test(current_object)) item 0 item 1 to tmpStr - x then y pos to Value +// send matrix_append_csv to test ('My Name,"My,\"address\""') - Append CSV data to the end of the matrix +// send matrix_copy_csv to (test(current_object)) "f:\data.csv" - Copy data from csv file into matrix // send matrix_sort to (test(current_object)) 1 - x then y pos to sort by // send matrix_delete to (test(current_object)) 1 1 - x then y pos to delete // send matrix_delete_row to (test(current_object)) 1 - x essentially blanks record out, no reshuffle -// send delete_item to (test1(current_object)) 1 - x pos (not v efficient), reshuffles +// send delete_item to (test(current_object)) 1 - x pos (not v efficient), reshuffles // // Hash indexed columns usage: // @@ -841,12 +846,16 @@ end_class // get matrix_index_from_value of (test(current_object)) item "1" to x_pos // get matrix_indextable_from_value of (test(current_object)) item "1" to tmpStr // get matrix_hash_from_value of (test(current_object)) item "1" to tmpInt +// get item_count of (test(current_object) to tmpInt +// get item_width of (test(current_object) to tmpInt class matrix is an array procedure construct_object integer argc object mTokens is a StringTokenizer end_object - + object mTokens2 is a StringTokenizer + end_object + forward send construct_object property integer c_iWidth public argc property integer c_iHashOn @@ -1024,6 +1033,44 @@ class matrix is an array end end_procedure + procedure matrix_append_csv string row + local integer l_iMax l_iValues l_i + local string l_sBuf + + forward get item_count to l_iMax + + send delete_data to (mTokens2(current_object)) + send set_string_csv to (mTokens2(current_object)) row + get token_count of (mTokens2(current_object)) to l_iValues + + for l_i from 0 to l_iValues + get token_value of (mTokens2(current_object)) item l_i to l_sBuf + indicate err false + set matrix_value item l_iMax item l_i to l_sBuf + if (err) forward send delete_item l_iMax + if (err) break + loop + + end_procedure + + procedure matrix_copy_csv string fname + local string l_sBuf + + if (does_exist(fname)) begin + direct_input channel DEFAULT_FILE_CHANNEL fname + while not (seqeof) + readln channel DEFAULT_FILE_CHANNEL l_sBuf + if (seqeof) break + if (trim(l_sBuf) <> "") begin + send matrix_append_csv l_sBuf + end + loop + close_input channel DEFAULT_FILE_CHANNEL + end + else; + custom_error ERROR_CODE_FILE_NOT_FOUND$ ERROR_MSG_FILE_NOT_FOUND ERROR_DETAIL_FILE_NOT_FOUND fname + end_procedure + function matrix_string integer itemx integer itemy returns string local string l_sBuf l_sTmp @@ -1181,6 +1228,12 @@ class matrix is an array procedure set item_count integer newVal forward set item_count to newVal end_procedure + + function item_width returns integer + local integer l_iWidth + get c_iWidth to l_iWidth + function_return l_iWidth + end_function procedure matrix_delete integer itemx integer itemy local string l_sBuf l_sTmp l_sOldVal @@ -1529,39 +1582,39 @@ class rss20 is a matrix get c_itemCount to l_itemCount get c_ttl to l_iTtl - direct_output channel default_file_channel rssFileName - writeln channel default_file_channel '' - writeln channel default_file_channel '' - write channel default_file_channel '' + direct_output channel DEFAULT_FILE_CHANNEL rssFileName + writeln channel DEFAULT_FILE_CHANNEL '' + writeln channel DEFAULT_FILE_CHANNEL '' + write channel DEFAULT_FILE_CHANNEL '' // skipHours skipDays cloud - all currently not used // Write out Channel - writeln channel default_file_channel ' ' - writeln channel default_file_channel ' ' (trim(l_rssTitle)) '' - writeln channel default_file_channel ' ' (trim(l_rssLink)) '' - writeln channel default_file_channel ' ' (trim(l_rssDesc)) '' - writeln channel default_file_channel ' en-gb' - writeln channel default_file_channel ' Df32func RSS Object Generator' - writeln channel default_file_channel ' Copyright ' (trim(l_rssTitle)) ' (C) ' (now("date")) '' - writeln channel default_file_channel ' ' (rssdate((now("date")),(now("longtime")))) '' - writeln channel default_file_channel ' ' (rssdate((now("date")),(now("longtime")))) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_rssTitle)) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_rssLink)) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_rssDesc)) '' + writeln channel DEFAULT_FILE_CHANNEL ' en-gb' + writeln channel DEFAULT_FILE_CHANNEL ' Df32func RSS Object Generator' + writeln channel DEFAULT_FILE_CHANNEL ' Copyright ' (trim(l_rssTitle)) ' (C) ' (now("date")) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (rssdate((now("date")),(now("longtime")))) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (rssdate((now("date")),(now("longtime")))) '' - if (l_manEditor <> "") writeln channel default_file_channel ' ' l_manEditor '' - if (l_webMaster <> "") writeln channel default_file_channel ' ' l_webMaster '' - if (l_iTtl <> 0) writeln channel default_file_channel ' ' l_iTtl '' + if (l_manEditor <> "") writeln channel DEFAULT_FILE_CHANNEL ' ' l_manEditor '' + if (l_webMaster <> "") writeln channel DEFAULT_FILE_CHANNEL ' ' l_webMaster '' + if (l_iTtl <> 0) writeln channel DEFAULT_FILE_CHANNEL ' ' l_iTtl '' // Write out image if ((l_imgUrl <> "") and (l_imgx > 0) and (l_imgy > 0)) begin - writeln channel default_file_channel ' ' - writeln channel default_file_channel ' ' (trim(l_imgTitle)) '' - writeln channel default_file_channel ' ' (trim(l_imgUrl)) '' - writeln channel default_file_channel ' ' (trim(l_imgLink)) '' - writeln channel default_file_channel ' ' l_imgx '' - writeln channel default_file_channel ' ' l_imgy '' - writeln channel default_file_channel ' ' (trim(l_rssDesc)) '' - writeln channel default_file_channel ' ' + writeln channel DEFAULT_FILE_CHANNEL ' ' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_imgTitle)) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_imgUrl)) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_imgLink)) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_imgx '' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_imgy '' + writeln channel DEFAULT_FILE_CHANNEL ' ' (trim(l_rssDesc)) '' + writeln channel DEFAULT_FILE_CHANNEL ' ' end // Write out items @@ -1580,10 +1633,10 @@ class rss20 is a matrix move (replaces('<',l_itemDesc,"<")) to l_itemDesc move (replaces('>',l_itemDesc,">")) to l_itemDesc - writeln channel default_file_channel ' ' - writeln channel default_file_channel ' ' l_itemTitle '' - writeln channel default_file_channel ' ' l_itemLink '' - writeln channel default_file_channel ' ' l_itemDesc '' + writeln channel DEFAULT_FILE_CHANNEL ' ' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_itemTitle '' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_itemLink '' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_itemDesc '' if (l_itemGuID = "") begin move 0 to l_iConflict @@ -1595,17 +1648,17 @@ class rss20 is a matrix end if (l_itemGuID <> "") append l_itemLink "#" l_itemGuID - writeln channel default_file_channel ' ' l_itemLink '' - if ((l_pubDate = "") or (l_pubDate = "NOW")) writeln channel default_file_channel ' ' (rssdate((now("date")),(now("longtime")))) '' - else writeln channel default_file_channel ' ' l_pubDate '' - writeln channel default_file_channel ' ' l_itemCat '' - writeln channel default_file_channel ' ' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_itemLink '' + if ((l_pubDate = "") or (l_pubDate = "NOW")) writeln channel DEFAULT_FILE_CHANNEL ' ' (rssdate((now("date")),(now("longtime")))) '' + else writeln channel DEFAULT_FILE_CHANNEL ' ' l_pubDate '' + writeln channel DEFAULT_FILE_CHANNEL ' ' l_itemCat '' + writeln channel DEFAULT_FILE_CHANNEL ' ' loop // Write out file/channel close - writeln channel default_file_channel ' ' - writeln channel default_file_channel '' - close_output channel default_file_channel + writeln channel DEFAULT_FILE_CHANNEL ' ' + writeln channel DEFAULT_FILE_CHANNEL '' + close_output channel DEFAULT_FILE_CHANNEL end_procedure @@ -1674,13 +1727,13 @@ class filelist is a matrix set c_filelistDirectory to filelistDirectory set c_filelistName to filelistName - direct_input channel default_file_channel (filelistDirectory+filelistName) + direct_input channel DEFAULT_FILE_CHANNEL (filelistDirectory+filelistName) read_block l_sHead 256 while not (seqeof) //Block of 128 split 41\33\54 - read_block channel default_file_channel l_sRootName 41 - read_block channel default_file_channel l_sUserDisplayName 33 - read_block channel default_file_channel l_sFileName 54 + read_block channel DEFAULT_FILE_CHANNEL l_sRootName 41 + read_block channel DEFAULT_FILE_CHANNEL l_sUserDisplayName 33 + read_block channel DEFAULT_FILE_CHANNEL l_sFileName 54 move filelistDirectory to l_sUrn append l_sUrn (trim(cstring(l_sFileName))) ".FD" @@ -1698,7 +1751,7 @@ class filelist is a matrix increment l_iFileNumber end loop - close_input channel default_file_channel + close_input channel DEFAULT_FILE_CHANNEL set c_itemCount to l_iFileNumber end_procedure