Subversion Repositories Kolibri OS

Rev

Rev 7504 | Rev 7517 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7504 Rev 7516
Line 586... Line 586...
586
	return r;
586
	return r;
587
}
587
}
588
 
588
 
589
int LoadCSV(char *fname)
589
char GetCsvSeparator(char *fname)
Line -... Line 590...
-
 
590
{
-
 
591
	char buffer[512];
-
 
592
	kosFileInfo fileInfo;
-
 
593
 
-
 
594
	rtlDebugOutString("hi");
-
 
595
	rtlDebugOutString(fname);
-
 
596
 
-
 
597
	strcpy(fileInfo.fileURL, fname);
-
 
598
	fileInfo.OffsetLow = 0;
-
 
599
	fileInfo.OffsetHigh = 0;
-
 
600
	fileInfo.dataCount = 512;
-
 
601
	fileInfo.rwMode = 0;
-
 
602
	fileInfo.bufferPtr = (Byte *)buffer;
-
 
603
	
-
 
604
	if (kos_FileSystemAccess(&fileInfo) == 0) {
-
 
605
		int separ_coma = chrnum(buffer, ',');
-
 
606
		int separ_semicolon = chrnum(buffer, ';');
-
 
607
		//kos_DebugValue(",", separ_coma);
-
 
608
		//kos_DebugValue(";", separ_semicolon);
-
 
609
		if (separ_semicolon>separ_coma) return ';';
-
 
610
	}
-
 
611
	return ',';
-
 
612
}
-
 
613
 
-
 
614
int LoadCSV(char *fname)
590
{
615
{
591
	// clear the table
616
	// clear the table
592
	reinit();
617
	reinit();
593
 
618
 
Line 594... Line 619...
594
	kosFileInfo fileInfo;
619
	kosFileInfo fileInfo;
595
	strcpy(fileInfo.fileURL,fname);
620
	strcpy(fileInfo.fileURL,fname);
596
	fileInfo.OffsetLow = 0;
621
	fileInfo.OffsetLow = 0;
597
	fileInfo.OffsetHigh = 0;
622
	fileInfo.OffsetHigh = 0;
Line -... Line 623...
-
 
623
 
-
 
624
	char separator = GetCsvSeparator(fileInfo.fileURL);
598
 
625
 
Line 599... Line 626...
599
	char *line;
626
	char *line;
600
 
627
 
601
	int col = 1, row = 1;
628
	int col = 1, row = 1;
Line 624... Line 651...
624
			{
651
			{
625
				char c = line[i];
652
				char c = line[i];
626
				if (!c)
653
				if (!c)
627
					c = ';'; 
654
					c = separator; 
628
				int yes_semicolon = 0;
655
				int yes_semicolon = 0;
629
 
656
 
630
				switch (inPar)
657
				switch (inPar)
Line 631... Line 658...
631
				{
658
				{
632
					case 0:
659
					case 0:
633
						if (c == '\"')
660
						if (c == '\"')
Line 636... Line 663...
636
						}
663
						}
637
						else
664
						else
638
						{
665
						{
639
							if (c == ';')
666
							if (c == separator)
640
								yes_semicolon = 1;
667
								yes_semicolon = 1;
641
						}
668
						}
642
						break;
669
						break;
643
					case 1:
670
					case 1:
644
						inPar = 2;
671
						inPar = 2;
645
						break;
672
						break;
646
					case 2:
673
					case 2:
Line 650... Line 677...
650
						}
677
						}
651
						/*else
678
						/*else
652
						{
679
						{
653
							if (c == ';')
680
							if (c == separator)
654
								yes_semicolon = 1;
681
								yes_semicolon = 1;
655
 
682
 
656
						}*/
683
						}*/
Line 657... Line 684...
657
						break;
684
						break;
658
				}
685
				}
659
				if (yes_semicolon)
686
				if (yes_semicolon)
660
				{
687
				{
661
					// èòàê, line[i] = ';'
688
					// èòàê, line[i] = separator
662
					int tmp = line[start] == '"' ? 1 : 0;
689
					int tmp = line[start] == '"' ? 1 : 0;
663
					int sz = i - start - tmp * 2;
690
					int sz = i - start - tmp * 2;
664
					if (sz > 0)
691
					if (sz > 0)
665
					{
692
					{
666
						cells[col][row] = (char *)allocmem(sz + 1);
693
						cells[col][row] = (char *)allocmem(sz + 1);
667
						memset((Byte*)cells[col][row], 0, sz + 1);
694
						memset((Byte*)cells[col][row], 0, sz + 1);