added parseCmdLine module
git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@45 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
parent
94ea8c4aec
commit
cfb6dd739b
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
||||
|
||||
TARGET := pppc.exe
|
||||
OBJS := pppc.o session_notification.o resources.o pport.o
|
||||
OBJS := pppc.o session_notification.o resources.o pport.o parseCmdLine.o
|
||||
CXXFLAGS := -O2 -Wall
|
||||
LDFLAGS := -mwindows
|
||||
|
||||
|
111
parseCmdLine.cc
Normal file
111
parseCmdLine.cc
Normal file
@ -0,0 +1,111 @@
|
||||
|
||||
#include "parseCmdLine.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
static std::string trim(const std::string & orig)
|
||||
{
|
||||
const char ws[] = " \t\r\n\v\f";
|
||||
size_t first = orig.find_first_not_of(ws);
|
||||
size_t last = orig.find_last_not_of(ws);
|
||||
if (first == string::npos || last == string::npos)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return string(orig, first, last - first + 1);
|
||||
}
|
||||
|
||||
std::vector<std::string> parseCmdLine(char * cmdline)
|
||||
{
|
||||
enum { WSSKIP, GATHERING, SQUOTE, DQUOTE } state = WSSKIP;
|
||||
vector<string> args;
|
||||
string arg;
|
||||
|
||||
for (; *cmdline; cmdline++)
|
||||
{
|
||||
char c = *cmdline;
|
||||
switch (state)
|
||||
{
|
||||
case WSSKIP:
|
||||
if (!isspace(c))
|
||||
{
|
||||
if (c == '\'')
|
||||
{
|
||||
state = SQUOTE;
|
||||
arg = "";
|
||||
}
|
||||
else if (c == '"')
|
||||
{
|
||||
state = DQUOTE;
|
||||
arg = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
state = GATHERING;
|
||||
arg = c;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GATHERING:
|
||||
if (c == '\'')
|
||||
{
|
||||
state = SQUOTE;
|
||||
}
|
||||
else if (c == '"')
|
||||
{
|
||||
state = DQUOTE;
|
||||
}
|
||||
else if (isspace(c))
|
||||
{
|
||||
args.push_back(arg);
|
||||
state = WSSKIP;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg += c;
|
||||
}
|
||||
break;
|
||||
case SQUOTE:
|
||||
if (c == '\'')
|
||||
{
|
||||
state = GATHERING;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg += c;
|
||||
}
|
||||
break;
|
||||
case DQUOTE:
|
||||
if (c == '"')
|
||||
{
|
||||
state = GATHERING;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg += c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (state)
|
||||
{
|
||||
case WSSKIP:
|
||||
break;
|
||||
case GATHERING:
|
||||
args.push_back(arg);
|
||||
break;
|
||||
case SQUOTE:
|
||||
cerr << "Warning: unmatched '\\'' character!" << endl;
|
||||
break;
|
||||
case DQUOTE:
|
||||
cerr << "Warning: unmatched '\"' character!" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int args_len = args.size(), i = 0; i < args_len; i++)
|
||||
{
|
||||
args[i] = trim(args[i]);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
10
parseCmdLine.h
Normal file
10
parseCmdLine.h
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef PARSECMDLINE_H
|
||||
#define PARSECMDLINE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
std::vector<std::string> parseCmdLine(char * cmdline);
|
||||
|
||||
#endif
|
5
pppc.cc
5
pppc.cc
@ -2,9 +2,12 @@
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "session_notification.h"
|
||||
#include "pport.h"
|
||||
#include "resources.h"
|
||||
#include "parseCmdLine.h"
|
||||
using namespace std;
|
||||
|
||||
#define APP_NAME "Parallel Port Power Controller"
|
||||
@ -21,6 +24,8 @@ int WinMain(
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
vector<string> args = parseCmdLine(lpCmdLine);
|
||||
|
||||
m_hInstance = hInstance;
|
||||
|
||||
/* Load the application icon */
|
||||
|
Loading…
x
Reference in New Issue
Block a user