Skip to content

Commit 0e82f3e

Browse files
committed
Added support for Visual Studio 2019
1 parent 063b37e commit 0e82f3e

File tree

9 files changed

+1299
-1
lines changed

9 files changed

+1299
-1
lines changed

getopt.c

Lines changed: 973 additions & 0 deletions
Large diffs are not rendered by default.

getopt.h

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/* Getopt for Microsoft C
2+
This code is a modification of the Free Software Foundation, Inc.
3+
Getopt library for parsing command line argument the purpose was
4+
to provide a Microsoft Visual C friendly derivative. This code
5+
provides functionality for both Unicode and Multibyte builds.
6+
7+
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
8+
Version: 1.0
9+
Comment: Supports getopt, getopt_long, and getopt_long_only
10+
and POSIXLY_CORRECT environment flag
11+
License: LGPL
12+
13+
Revisions:
14+
15+
02/03/2011 - Ludvik Jerabek - Initial Release
16+
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
17+
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
18+
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
19+
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
20+
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
21+
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
22+
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
23+
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
24+
25+
**DISCLAIMER**
26+
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
27+
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
28+
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
29+
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
30+
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
31+
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
32+
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
33+
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
34+
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
35+
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
36+
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37+
*/
38+
#ifndef __GETOPT_H_
39+
#define __GETOPT_H_
40+
41+
#ifdef _GETOPT_API
42+
#undef _GETOPT_API
43+
#endif
44+
45+
#if defined(EXPORTS_GETOPT) && defined(STATIC_GETOPT)
46+
#error "The preprocessor definitions of EXPORTS_GETOPT and STATIC_GETOPT can only be used individually"
47+
#elif defined(STATIC_GETOPT)
48+
#pragma message("Warning static builds of getopt violate the Lesser GNU Public License")
49+
#define _GETOPT_API
50+
#elif defined(EXPORTS_GETOPT)
51+
#pragma message("Exporting getopt library")
52+
#define _GETOPT_API __declspec(dllexport)
53+
#else
54+
#pragma message("Importing getopt library")
55+
#define _GETOPT_API __declspec(dllimport)
56+
#endif
57+
58+
// Change behavior for C\C++
59+
#ifdef __cplusplus
60+
#define _BEGIN_EXTERN_C extern "C" {
61+
#define _END_EXTERN_C }
62+
#define _GETOPT_THROW throw()
63+
#else
64+
#define _BEGIN_EXTERN_C
65+
#define _END_EXTERN_C
66+
#define _GETOPT_THROW
67+
#endif
68+
69+
// Standard GNU options
70+
#define null_argument 0 /*Argument Null*/
71+
#define no_argument 0 /*Argument Switch Only*/
72+
#define required_argument 1 /*Argument Required*/
73+
#define optional_argument 2 /*Argument Optional*/
74+
75+
// Shorter Options
76+
#define ARG_NULL 0 /*Argument Null*/
77+
#define ARG_NONE 0 /*Argument Switch Only*/
78+
#define ARG_REQ 1 /*Argument Required*/
79+
#define ARG_OPT 2 /*Argument Optional*/
80+
81+
#include <string.h>
82+
#include <wchar.h>
83+
84+
_BEGIN_EXTERN_C
85+
86+
extern _GETOPT_API int optind;
87+
extern _GETOPT_API int opterr;
88+
extern _GETOPT_API int optopt;
89+
90+
// Ansi
91+
struct option_a
92+
{
93+
const char* name;
94+
int has_arg;
95+
int *flag;
96+
int val;
97+
};
98+
extern _GETOPT_API char *optarg_a;
99+
extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
100+
extern _GETOPT_API int getopt_long_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
101+
extern _GETOPT_API int getopt_long_only_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
102+
103+
// Unicode
104+
struct option_w
105+
{
106+
const wchar_t* name;
107+
int has_arg;
108+
int *flag;
109+
int val;
110+
};
111+
extern _GETOPT_API wchar_t *optarg_w;
112+
extern _GETOPT_API int getopt_w(int argc, wchar_t *const *argv, const wchar_t *optstring) _GETOPT_THROW;
113+
extern _GETOPT_API int getopt_long_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW;
114+
extern _GETOPT_API int getopt_long_only_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW;
115+
116+
_END_EXTERN_C
117+
118+
#undef _BEGIN_EXTERN_C
119+
#undef _END_EXTERN_C
120+
#undef _GETOPT_THROW
121+
#undef _GETOPT_API
122+
123+
#ifdef _UNICODE
124+
#define getopt getopt_w
125+
#define getopt_long getopt_long_w
126+
#define getopt_long_only getopt_long_only_w
127+
#define option option_w
128+
#define optarg optarg_w
129+
#else
130+
#define getopt getopt_a
131+
#define getopt_long getopt_long_a
132+
#define getopt_long_only getopt_long_only_a
133+
#define option option_a
134+
#define optarg optarg_a
135+
#endif
136+
#endif // __GETOPT_H_

mdloader.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30804.86
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mdloader", "mdloader.vcxproj", "{DCB8F5C8-7EDC-425D-854D-B8A2F8879F4C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x86 = Debug|x86
11+
Release|x86 = Release|x86
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{DCB8F5C8-7EDC-425D-854D-B8A2F8879F4C}.Debug|x86.ActiveCfg = Debug|Win32
15+
{DCB8F5C8-7EDC-425D-854D-B8A2F8879F4C}.Debug|x86.Build.0 = Debug|Win32
16+
{DCB8F5C8-7EDC-425D-854D-B8A2F8879F4C}.Release|x86.ActiveCfg = Release|Win32
17+
{DCB8F5C8-7EDC-425D-854D-B8A2F8879F4C}.Release|x86.Build.0 = Release|Win32
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {9DE6276C-A03E-407A-A98D-74B002CDB2A3}
24+
EndGlobalSection
25+
EndGlobal

mdloader.vcxproj

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<None Include="applet-mdflash.bin" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<ClCompile Include="getopt.c" />
18+
<ClCompile Include="mdloader_common.c" />
19+
<ClCompile Include="mdloader_parser.c" />
20+
<ClCompile Include="mdloader_win32.c" />
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="getopt.h" />
24+
<ClInclude Include="mdloader_common.h" />
25+
<ClInclude Include="mdloader_parser.h" />
26+
</ItemGroup>
27+
<PropertyGroup Label="Globals">
28+
<VCProjectVersion>16.0</VCProjectVersion>
29+
<Keyword>Win32Proj</Keyword>
30+
<ProjectGuid>{dcb8f5c8-7edc-425d-854d-b8a2f8879f4c}</ProjectGuid>
31+
<RootNamespace>mdloader</RootNamespace>
32+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>true</UseDebugLibraries>
38+
<PlatformToolset>v142</PlatformToolset>
39+
<CharacterSet>MultiByte</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>false</UseDebugLibraries>
44+
<PlatformToolset>v142</PlatformToolset>
45+
<WholeProgramOptimization>true</WholeProgramOptimization>
46+
<CharacterSet>MultiByte</CharacterSet>
47+
</PropertyGroup>
48+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
49+
<ImportGroup Label="ExtensionSettings">
50+
</ImportGroup>
51+
<ImportGroup Label="Shared">
52+
</ImportGroup>
53+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
54+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
55+
</ImportGroup>
56+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
57+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
58+
</ImportGroup>
59+
<PropertyGroup Label="UserMacros" />
60+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<LinkIncremental>true</LinkIncremental>
62+
</PropertyGroup>
63+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<LinkIncremental>false</LinkIncremental>
65+
</PropertyGroup>
66+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
67+
<ClCompile>
68+
<WarningLevel>Level3</WarningLevel>
69+
<SDLCheck>true</SDLCheck>
70+
<PreprocessorDefinitions>STATIC_GETOPT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
71+
<ConformanceMode>true</ConformanceMode>
72+
<LanguageStandard_C>Default</LanguageStandard_C>
73+
</ClCompile>
74+
<Link>
75+
<SubSystem>Console</SubSystem>
76+
<GenerateDebugInformation>true</GenerateDebugInformation>
77+
</Link>
78+
</ItemDefinitionGroup>
79+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<ClCompile>
81+
<WarningLevel>Level3</WarningLevel>
82+
<FunctionLevelLinking>true</FunctionLevelLinking>
83+
<IntrinsicFunctions>true</IntrinsicFunctions>
84+
<SDLCheck>true</SDLCheck>
85+
<PreprocessorDefinitions>STATIC_GETOPT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
86+
<ConformanceMode>true</ConformanceMode>
87+
<LanguageStandard_C>Default</LanguageStandard_C>
88+
</ClCompile>
89+
<Link>
90+
<SubSystem>Console</SubSystem>
91+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
92+
<OptimizeReferences>true</OptimizeReferences>
93+
<GenerateDebugInformation>true</GenerateDebugInformation>
94+
</Link>
95+
</ItemDefinitionGroup>
96+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
97+
<ImportGroup Label="ExtensionTargets">
98+
</ImportGroup>
99+
</Project>

mdloader.vcxproj.filters

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="mdloader_common.c">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="mdloader_parser.c">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
<ClCompile Include="mdloader_win32.c">
25+
<Filter>Source Files</Filter>
26+
</ClCompile>
27+
<ClCompile Include="getopt.c">
28+
<Filter>Source Files</Filter>
29+
</ClCompile>
30+
</ItemGroup>
31+
<ItemGroup>
32+
<ClInclude Include="mdloader_parser.h">
33+
<Filter>Header Files</Filter>
34+
</ClInclude>
35+
<ClInclude Include="mdloader_common.h">
36+
<Filter>Header Files</Filter>
37+
</ClInclude>
38+
<ClInclude Include="getopt.h">
39+
<Filter>Header Files</Filter>
40+
</ClInclude>
41+
</ItemGroup>
42+
<ItemGroup>
43+
<None Include="applet-mdflash.bin">
44+
<Filter>Resource Files</Filter>
45+
</None>
46+
</ItemGroup>
47+
</Project>

mdloader_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ INCBIN(applet, "applet-mdflash.bin");
2525
#include "mdloader_common.h"
2626
#include "mdloader_parser.h"
2727

28+
#ifdef _MSC_VER
29+
#pragma warning(disable:4996)
30+
#endif
31+
2832
char verbose;
2933
char testmode;
3034
char first_device;

mdloader_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
#include <stdlib.h>
4646
#include <string.h>
4747
#include <stdint.h>
48+
49+
#ifdef _MSC_VER
50+
#include "getopt.h"
51+
#else
4852
#include <getopt.h>
53+
#endif
4954

5055
//Atmel files
5156
#include "./atmel/applet.h"

mdloader_parser.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include "mdloader_common.h"
2121
#include "mdloader_parser.h"
2222

23+
#ifdef _MSC_VER
24+
#pragma warning(disable:4996)
25+
#endif
26+
2327
void free_data(data_t *data)
2428
{
2529
if (!data)

mdloader_win32.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#include "mdloader_common.h"
2121

22+
#ifdef _MSC_VER
23+
#pragma warning(disable:4996)
24+
#endif
25+
2226
#define EXAMPLE_PORT "COM23"
2327
#define PORT_SEARCH_STRING "COM"
2428

@@ -469,7 +473,8 @@ int close_port(char silent)
469473
//Return 1 on sucess, 0 on failure
470474
int config_port(void)
471475
{
472-
DCB dcb = {};
476+
DCB dcb;
477+
memset(&dcb, 0, sizeof(DCB));
473478

474479
if (verbose) printf("Configuring port... \n");
475480

0 commit comments

Comments
 (0)