1 #include <Core/Core.h>
2 
3 using namespace Upp;
4 
5 #include "Spreadsheet.h"
6 
7 
SpreadsheetDemo(Spreadsheet & spreadsheet)8 void SpreadsheetDemo(Spreadsheet &spreadsheet) {
9 	spreadsheet.Open("myfile.xls");
10 	spreadsheet.SetData(4, 6, "Hello world");
11 }
12 
PluginDemo()13 void PluginDemo() {
14 	Spreadsheet spreadsheet;
15 
16 	if (!PluginInit(spreadsheet, "Open")) {
17 		UppLog() << "Impossible to init OpenOffice/LibreOffice";
18 		return;
19 	}
20 	SpreadsheetDemo(spreadsheet);
21 	if (!PluginInit(spreadsheet, "Excel")) {
22 		UppLog() << "Impossible to init Excel";
23 		return;
24 	}
25 	SpreadsheetDemo(spreadsheet);
26 }
27 
FilesDemo()28 void FilesDemo() {
29 	{
30 		String from = "/books/technology/computers";
31 		String path = "/books/biology/mammals";
32 		String ret;
33 		if (!GetRelativePath(from, path, ret))
34 			ret = "Null";
35 		Cout() << "\nGetRelativePath(\"" << from << "\", \"" << path << "\")\n= \"" << ret << "\" (should be: \"../../biology/mammals\")";
36 	}
37 	{
38 		String from = "/books/technology/computers";
39 		String path = "/books/technology/computers";
40 		String ret;
41 		if (!GetRelativePath(from, path, ret))
42 			ret = "Null";
43 		Cout() << "\nGetRelativePath(\"" << from << "\", \"" << path << "\")\n= \"" << ret << "\" (should be: \"\")";
44 	}
45 	{
46 		String from = "/books/technology/computers";
47 		String path = "/books2/biology/mammals";
48 		String ret;
49 		if (!GetRelativePath(from, path, ret))
50 			ret = "Null";
51 		Cout() << "\nGetRelativePath(\"" << from << "\", \"" << path << "\")\n= \"" << ret << "\" (should be: \"../../../books2/biology/mammals\")";
52 	}
53 	{
54 		String from = "c:/books/technology/computers";
55 		String path = "y:/books2/biology/mammals";
56 		String ret;
57 		if (!GetRelativePath(from, path, ret))
58 			ret = "Null";
59 		Cout() << "\nGetRelativePath(\"" << from << "\", \"" << path << "\")\n= \"" << ret << "\" (should be: Null)";
60 	}
61 
62 	String filename1 = AppendFileNameX(GetExeFolder(), "Demo", "file1.txt");
63 	RealizePath(filename1);
64 	String str1 = "This is the First string";
65 	SaveFile(filename1, str1);
66 	String filename2 = AppendFileNameX(GetExeFolder(), "Demo", "file2.txt");
67 	String str2 = "This is the Second string";
68 	SaveFile(filename2, str2);
69 
70 	FileCat(filename1, filename2);
71 	UppLog() << Format("\nFileCat(%s, %s)", filename1, filename2);
72 
73 //	LaunchFile(filename1);
74 //	UppLog() << Format("LaunchFile(%s)", filename1);
75 
76 	int intres = FileCompare(filename1, filename2);
77 	UppLog() << Format("\nFileCompare(%s, %s) = %d (has to be -1)", filename1, filename2, intres);
78 
79 	int64 pos = FindStringInFile(filename1, "Second");
80 	UppLog() << Format("\nFindStringInFile(%s, %s) = %d (has to be 35)", filename1, filename2, pos);
81 
82 	bool boolres = FileStrAppend(filename1, ". Text appended at the end.");
83 	UppLog() << Format("\nFileStrAppend(%s, \". Text appended at the end.\") = %s (has to be true)",
84 				filename1, boolres ? "true" : "false");
85 
86 	//boolres = UpperFolder(GetFileDirectory(filename1));
87 	//UppLog() << Format("\nUpperFolder(%s) = %s (has to be true)", filename1, boolres ? "true" : "false");
88 
89 	String upperFolder = GetUpperFolder(GetFileDirectory(filename1));
90 	UppLog() << Format("\nGetUpperFolder(%s) = %s (has to be %s)", filename1, upperFolder, GetExeFolder());
91 
92 	String stringres = GetNextFolder(GetUpperFolder(GetExeFolder()), GetFileDirectory(filename1));
93 	UppLog() << Format("\nGetNextFolder(%s, %s) = %s (has to be %s)", GetUpperFolder(GetExeFolder()),
94 										GetFileDirectory(filename1), stringres, GetExeFolder());
95 
96 	String lfilename1 = ToLower(filename1);
97 	filename1 = FileRealName(lfilename1);
98 	UppLog() << Format("\nFileRealName(%s) = %s", lfilename1, filename1);
99 }
100 
NonReentrantDemo()101 void NonReentrantDemo() {
102 	UppLog() << "\nTrying to enter Non reentrant. ";
103 	NON_REENTRANT_V;
104 
105 	UppLog() << "Entered in Non reentrant. It has to be once.";
106 	NonReentrantDemo();
107 	NonReentrantDemo();
108 }
109 
DistanceDemo()110 void DistanceDemo() {
111 	UppLog() << Format("Distance between 'hello' and 'hello'  is %d", DamerauLevenshteinDistance("hello", "hello"));
112 	UppLog() << Format("Distance between 'hello' and 'helo'   is %d", DamerauLevenshteinDistance("hello", "helo"));
113 	UppLog() << Format("Distance between 'hello' and 'heloo'  is %d", DamerauLevenshteinDistance("hello", "helloo"));
114 	UppLog() << Format("Distance between 'hello' and 'yellow' is %d", DamerauLevenshteinDistance("hello", "yellow"));
115 }
116 
MiscellaneousDemos()117 void MiscellaneousDemos() {
118 	SetConsoleColor(CONSOLE_COLOR::LTRED);
119 	UppLog() << "This message is in red\n";
120 	SetConsoleColor(CONSOLE_COLOR::LTYELLOW);
121 	UppLog() << "This message is in yellow\n";
122 	SetConsoleColor(CONSOLE_COLOR::RESET);
123 	UppLog() << "This message is in normal color\n";
124 
125 	UppLog() << "Next text messages (printf, Cout(), UppLog()) will be disabled\n";
126 	ConsoleOutputDisable(true);
127 	Cout() << "Text with Cout()\n";
128 	UppLog() << "Text with UppLog()\n";
129 	printf("Text with printf()\n");
130 	ConsoleOutputDisable(false);
131 	UppLog() << "Text messages are now enabled\n";
132 }
133 
134 CONSOLE_APP_MAIN
135 {
136 	StdLogSetup(LOG_COUT|LOG_FILE);
137 
138 	UppLog() << "Miscellaneous demos";
139 	MiscellaneousDemos();
140 
141 	UppLog() << "\n\nFiles demo";
142 	FilesDemo();
143 
144 	UppLog() << "\n\nPlugin demo";
145 	PluginDemo();
146 
147 	UppLog() << "\n\nNonReentrant demo";
148 	NonReentrantDemo();
149 
150 	UppLog() << "\n\nDistance demo";
151 	DistanceDemo();
152 
153 	#ifdef flagDEBUG
154 	UppLog() << "\n";
155 	Cout() << "\nPress enter key to end";
156 	ReadStdIn();
157 	#endif
158 }
159 
160