Help me with colors? also... csv file reader.
- Posted by jshaman at PHREAK.ORG Jun 07, 1998
- 696 views
Is there any way of reading the current screen text mode color under dos or a console window into an object? Just wondering. Oh, here's a somewhat useful routine for reading data from a .csv (comma seperated value) file, commonly exported by several database programs. It could use a little work (like multiple end-of-line character support so mac .csv files will work too.) --- function csvdata(sequence filename) -- return a sequence containing the data of a .csv file in the format: -- { -- { -- {"header1.1","header1.2","header1.3",...}, -- {"data1.1.1","data1.1.2","data1.1.3",...}, -- {"data1.2.1","data1.2.2","data1.2.3",...}, -- {"data1.3.1","data1.3.2","data1.3.3",...},... -- }, -- { -- {"header2.1","header2.2","header2.3",...}, -- {"data2.1.1","data2.1.2","data2.1.3",...}, -- {"data2.2.1","data2.2.2","data2.2.3",...}, -- {"data2.3.1","data2.3.2","data2.3.3",...},... -- },... -- } -- return {} if file cannot be opened for read integer fn, quotemode atom character sequence element, line, block, database quotemode = 0 database = {} element = {} line = {} block = {} fn = open(filename, "rb") if fn = -1 then puts(1,"Cannot open file for read.\n") return {} end if character = getc(fn) while character > -1 do -- toggle quotemode if character = 34 then if quotemode = 0 and length(element) = 0 then quotemode = 1 character = getc(fn) elsif quotemode = 1 then character = getc(fn) if character = ',' then quotemode = 0 end if end if end if -- end of element? if (character=',' and quotemode=0)or(character=10 and length(line)> 0) then line = append(line, element) element = {} end if -- end of line? if character = 10 and length(line) > 0 then block = append(block, line) line = {} element = {} elsif --end of block? character = 10 then database = append(database, block) block = {} line = {} element = {} end if -- add character to element if (character != 13 and character != 10 and character != ',') or (character = ',' and quotemode = 1) then element = append(element, character) end if character = getc(fn) end while if length(element) > 0 then line = append(line, element) end if if length(line) > 0 then block = append(block, line) end if if length(block) > 0 then database = append(database, block) end if return database end function -- data = cvsdata("filename") ---