table: fix the detection of separator in a small files (fix issue #61)

git-svn-id: svn://kolibrios.org@7897 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-05-08 12:20:36 +00:00
parent 4f7d0a63ed
commit 00f9e8a85f
2 changed files with 20 additions and 11 deletions

View File

@ -20,6 +20,7 @@ extern DWORD *cell_x, *cell_y;
extern char ***buffer; extern char ***buffer;
extern DWORD buf_col, buf_row; extern DWORD buf_col, buf_row;
extern DWORD buf_old_x, buf_old_y; extern DWORD buf_old_x, buf_old_y;
DWORD filesize;
extern bool sel_moved; extern bool sel_moved;
@ -576,15 +577,22 @@ char *Kos_FileRead(kosFileInfo &fileInfo, int &code)
char GetCsvSeparator(char *fname) char GetCsvSeparator(char *fname)
{ {
char buffer[512]; char buffer[4096];
kosFileInfo fileInfo; kosFileInfo fileInfo;
DWORD load_size;
if (filesize < 4096) {
load_size = filesize;
} else {
load_size = 4096;
}
rtlDebugOutString(fname); rtlDebugOutString(fname);
strcpy(fileInfo.fileURL, fname); strcpy(fileInfo.fileURL, fname);
fileInfo.OffsetLow = 0; fileInfo.OffsetLow = 0;
fileInfo.OffsetHigh = 0; fileInfo.OffsetHigh = 0;
fileInfo.dataCount = 512; fileInfo.dataCount = load_size;
fileInfo.rwMode = 0; fileInfo.rwMode = 0;
fileInfo.bufferPtr = (Byte *)buffer; fileInfo.bufferPtr = (Byte *)buffer;
@ -714,7 +722,7 @@ int LoadFile(char *fname)
kosFileInfo fileInfo; kosFileInfo fileInfo;
kosBDVK bdvk; kosBDVK bdvk;
int filePointer = 0, i, j; int filePointer = 0, i, j;
Dword res, filesize; Dword res;
char buffer[512 + 1]; char buffer[512 + 1];
char *d, *s, *k; char *d, *s, *k;
int step = 0, items; int step = 0, items;
@ -733,6 +741,8 @@ int LoadFile(char *fname)
return -1; return -1;
} }
filesize = bdvk.size_low;
if (str_is_csv(fname)) if (str_is_csv(fname))
return LoadCSV(fname); return LoadCSV(fname);
@ -740,8 +750,6 @@ int LoadFile(char *fname)
// clear the table // clear the table
reinit(); reinit();
filesize = bdvk.size_low;
fileInfo.rwMode = 0; fileInfo.rwMode = 0;
fileInfo.dataCount = strlen(sFileSign); fileInfo.dataCount = strlen(sFileSign);
fileInfo.bufferPtr = (Byte*)buffer; fileInfo.bufferPtr = (Byte*)buffer;

View File

@ -23,7 +23,7 @@ const char sNew[] = "New";
const char er_file_not_found[] = "'Cannot open file' -E"; const char er_file_not_found[] = "'Cannot open file' -E";
const char er_format[] = "'Error: bad format' -E"; const char er_format[] = "'Error: bad format' -E";
const char msg_save[] = "'File saved' -O"; const char msg_save[] = "'File saved' -O";
const char msg_load[] = "'File loaded' -O"; //const char msg_load[] = "'File loaded' -O";
const char msg_save_error[] = "'Error saving file' -E"; const char msg_save_error[] = "'Error saving file' -E";
const char msg_new[] = "'Memory cleared' -I"; const char msg_new[] = "'Memory cleared' -I";
@ -1058,16 +1058,17 @@ void EventLoadFile()
{ {
stop_edit(); stop_edit();
int r = LoadFile(fname); int r = LoadFile(fname);
char *result;
if (r > 0) { if (r > 0) {
calculate_values(); calculate_values();
sel_moved = 0; sel_moved = 0;
draw_grid(); draw_grid();
result = (char*)msg_load; //result = (char*)msg_load;
} } else {
else if (r == -1) result = (char*)er_file_not_found; char *result;
if (r == -1) result = (char*)er_file_not_found;
else if (r == -2) result = (char*)er_format; else if (r == -2) result = (char*)er_format;
kos_AppRun("/sys/@notify", result); kos_AppRun("/sys/@notify", result);
}
} }
void EventGridSelectAll() void EventGridSelectAll()