-
Notifications
You must be signed in to change notification settings - Fork 0
/
csvgraph.cpp
114 lines (108 loc) · 5.12 KB
/
csvgraph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//---------------------------------------------------------------------------
/*----------------------------------------------------------------------------
* MIT License:
*
* Copyright (c) 2020,2022 Peter Miller
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*--------------------------------------------------------------------------*/
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
USEFORM("About.cpp", AboutBox);
USEFORM("UScalesWindow.cpp", ScalesWindow);
USEFORM("Unit1.cpp", Form1);
USEFORM("UDataPlotWindow.cpp", PlotWindow);
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1)
USEFORM("UScalesWindow.cpp", ScalesWindow)
USEFORM("UDataPlotWindow.cpp", PlotWindow)
USEFORM("About.cpp", AboutBox)
//---------------------------------------------------------------------------
#define NoForm1
#include "rprintf.h"
#include "expr-code.h"
#include <float.h>
#if 1 /* my version that picks up command line */
extern volatile int xchange_running; // avoid running multiple instances of Edit_XoffsetChange() in parallel, but still do correct number of updates , set to -1 initially
extern volatile bool addtraceactive; // set to true when add trace active to avoid multiple clicks
/* next function used to support conversion to unicode vcl see https://blogs.embarcadero.com/migrating-legacy-c-builder-apps-to-c-builder-10-seattle/
*/
#define STR_CONV_BUF_SIZE 2000 // the largest string you may have to convert. depends on your project
static char* __fastcall Utf8Of(wchar_t* w) /* convert to utf-8 encoding */
{
static char c[STR_CONV_BUF_SIZE];
memset(c, 0, sizeof(c));
WideCharToMultiByte(CP_UTF8, 0, w, -1, c, STR_CONV_BUF_SIZE-1, nullptr, nullptr); /* size-1 ensure result is null terminated */
return(c);
}
void proces_open_filename(char *fn); // open filename - just to peek at header row
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{LPWSTR *szArglist;
int nArgs;
_controlfp( MCW_EM,MCW_EM ); // disable (bits set) all floating point exceptions see https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/control87-controlfp-control87-2?view=msvc-170
// command line handling based on the example at https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw
// It is therefore windows specific, but should be portable to other compilers
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
try
{
Application->Initialize();
Application->MainFormOnTaskBar = true;
Application->Title = "CSVgraph";
// Application->CreateForm(__classid(TAboutBox), &AboutBox);
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TScalesWindow), &ScalesWindow);
Application->CreateForm(__classid(TAboutBox), &AboutBox);
if(szArglist != nullptr && nArgs==2) // one argument, assume its a filename and load this file
{
proces_open_filename( Utf8Of(szArglist[1])); // open filename supplied on command line - just to peek at header row
}
Application->Run();
}
catch (Exception &exception)
{
xchange_running= -1; // avoid running multiple instances of Edit_XoffsetChange() in parallel, but still do correct number of updates, -1 is initial value
addtraceactive=false; // set to true when add trace active to avoid multiple clicks
rprintf("Exception1:\n");
#ifndef TRY_CATCH_DISABLED
Application->ShowException(&exception);
#endif
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
xchange_running= -1; // avoid running multiple instances of Edit_XoffsetChange() in parallel, but still do correct number of updates, -1 is initial value
addtraceactive=false; // set to true when add trace active to avoid multiple clicks
rprintf("Exception2:\n");
#ifndef TRY_CATCH_DISABLED
Application->ShowException(&exception);
#endif
}
}
return 0;
}
#endif
//---------------------------------------------------------------------------