2022-09-22 20:57:46 -04:00
|
|
|
// This file is part of Motion Watch.
|
|
|
|
|
|
|
|
// Motion Watch is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Motion Watch is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QString getParam(const QString &key, const QStringList &args)
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
// this can be used by command objects to pick out parameters
|
|
|
|
// from a command line that are pointed by a name identifier
|
|
|
|
// example: -i /etc/some_file, this function should pick out
|
|
|
|
// "/etc/some_file" from args if "-i" is passed into key.
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QString ret;
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
int pos = args.indexOf(QRegularExpression(key, QRegularExpression::CaseInsensitiveOption));
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if (pos != -1)
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
// key found.
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if ((pos + 1) <= (args.size() - 1))
|
2023-03-05 16:07:07 -05:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
// check ahead to make sure pos + 1 will not go out
|
|
|
|
// of range.
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if (!args[pos + 1].startsWith("-"))
|
2022-12-11 12:33:56 -05:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
// the "-" used throughout this application
|
|
|
|
// indicates an argument so the above 'if'
|
|
|
|
// statement will check to make sure it does
|
|
|
|
// not return another argument as a parameter
|
|
|
|
// in case a back-to-back "-arg -arg" is
|
|
|
|
// present.
|
|
|
|
|
|
|
|
ret = args[pos + 1];
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
return ret;
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QStringList lsFilesInDir(const QString &path, const QString &ext)
|
2022-12-04 15:13:39 -05:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
QStringList filters;
|
2022-12-13 21:13:10 -05:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
filters << "*" + ext;
|
2023-03-26 10:32:56 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QDir dirObj(path);
|
2023-03-10 19:35:44 -05:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
dirObj.setFilter(QDir::Files);
|
|
|
|
dirObj.setNameFilters(filters);
|
|
|
|
dirObj.setSorting(QDir::Name);
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
return dirObj.entryList();
|
|
|
|
}
|
2023-03-05 16:07:07 -05:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QStringList lsDirsInDir(const QString &path)
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
QDir dirObj(path);
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
dirObj.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
dirObj.setSorting(QDir::Name);
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
return dirObj.entryList();
|
|
|
|
}
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-26 16:12:53 -04:00
|
|
|
QStringList listFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs, char dir)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
|
|
|
|
|
|
|
for (auto i = 0; i < secs; ++i)
|
|
|
|
{
|
|
|
|
QString filePath;
|
|
|
|
|
|
|
|
if (dir == '-') filePath = path + "/" + stamp.addSecs(-i).toString(DATETIME_FMT) + ext;
|
|
|
|
if (dir == '+') filePath = path + "/" + stamp.addSecs(i).toString(DATETIME_FMT) + ext;
|
|
|
|
|
|
|
|
if (QFile::exists(filePath))
|
|
|
|
{
|
|
|
|
if (dir == '-') ret.insert(0, filePath);
|
|
|
|
if (dir == '+') ret.append(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList backwardFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs)
|
|
|
|
{
|
|
|
|
return listFacingFiles(path, ext, stamp, secs, '-');
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList forwardFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs)
|
|
|
|
{
|
|
|
|
return listFacingFiles(path, ext, stamp, secs, '+');
|
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
void enforceMaxEvents(shared_t *share)
|
|
|
|
{
|
|
|
|
auto names = lsFilesInDir("events", ".mp4");
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
while (names.size() > share->maxEvents)
|
|
|
|
{
|
|
|
|
auto nameOnly = "events/" + names[0];
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
nameOnly.remove(".mp4");
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
auto mp4File = nameOnly + ".mp4";
|
|
|
|
auto imgFile = nameOnly + ".jpg";
|
|
|
|
auto webFile = nameOnly + ".html";
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QFile::remove(mp4File);
|
|
|
|
QFile::remove(imgFile);
|
|
|
|
QFile::remove(webFile);
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
names.removeFirst();
|
|
|
|
}
|
2023-04-20 14:52:59 -04:00
|
|
|
}
|
|
|
|
|
2023-05-26 16:12:53 -04:00
|
|
|
void enforceMaxImages()
|
|
|
|
{
|
|
|
|
auto names = lsFilesInDir("img", ".bmp");
|
|
|
|
|
|
|
|
while (names.size() > MAX_IMAGES)
|
|
|
|
{
|
|
|
|
QFile::remove("img/" + names[0]);
|
|
|
|
|
|
|
|
names.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:24:32 -04:00
|
|
|
void enforceMaxVids()
|
|
|
|
{
|
|
|
|
auto names = lsFilesInDir("live", ".ts");
|
|
|
|
|
|
|
|
while (names.size() > MAX_VIDEOS)
|
|
|
|
{
|
|
|
|
QFile::remove("live/" + names[0]);
|
|
|
|
|
|
|
|
names.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
void rdLine(const QString ¶m, const QString &line, QString *value)
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
if (line.startsWith(param))
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
*value = line.mid(param.size());
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
void rdLine(const QString ¶m, const QString &line, int *value)
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
if (line.startsWith(param))
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
*value = line.mid(param.size()).toInt();
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-18 18:47:14 -04:00
|
|
|
void touch(const QString &path)
|
|
|
|
{
|
|
|
|
if (!QFile::exists(path))
|
|
|
|
{
|
|
|
|
QFile file(path);
|
|
|
|
|
|
|
|
if (file.open(QFile::WriteOnly))
|
|
|
|
{
|
|
|
|
file.write("");
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
bool rdConf(const QString &filePath, shared_t *share)
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
QFile varFile(filePath);
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if (!varFile.open(QFile::ReadOnly))
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
|
|
|
share->retCode = ENOENT;
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QTextStream(stderr) << "err: config file: " << filePath << " does not exists or lack read permissions." << Qt::endl;
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
share->recordUrl.clear();
|
|
|
|
share->postCmd.clear();
|
|
|
|
share->camName.clear();
|
|
|
|
|
|
|
|
share->retCode = 0;
|
|
|
|
share->imgThresh = 8000;
|
|
|
|
share->maxEvents = 100;
|
|
|
|
share->maxLogSize = 100000;
|
|
|
|
share->skipCmd = false;
|
|
|
|
share->postSecs = 60;
|
|
|
|
share->evMaxSecs = 30;
|
|
|
|
share->conf = filePath;
|
|
|
|
share->buffPath = "/var/opt/" + QString(APP_BIN) + "/buf";
|
|
|
|
share->webRoot = "/var/opt/" + QString(APP_BIN) + "/web";
|
|
|
|
share->webBg = "#485564";
|
|
|
|
share->webTxt = "#dee5ee";
|
|
|
|
share->webFont = "courier";
|
2023-08-06 10:17:10 -04:00
|
|
|
share->outputType = "stderr";
|
|
|
|
share->compCmd = "magick compare -metric FUZZ " + QString(PREV_IMG) + " " + QString(NEXT_IMG) + " /dev/null";
|
2023-07-31 11:16:07 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
QString line;
|
2022-09-22 20:57:46 -04:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
line = QString::fromUtf8(varFile.readLine());
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if (!line.startsWith("#"))
|
2022-09-22 20:57:46 -04:00
|
|
|
{
|
2022-12-04 15:13:39 -05:00
|
|
|
rdLine("cam_name = ", line, &share->camName);
|
2022-09-22 20:57:46 -04:00
|
|
|
rdLine("recording_stream = ", line, &share->recordUrl);
|
2023-07-18 18:47:14 -04:00
|
|
|
rdLine("buffer_path = ", line, &share->buffPath);
|
2022-12-11 10:25:22 -05:00
|
|
|
rdLine("web_root = ", line, &share->webRoot);
|
|
|
|
rdLine("web_text = ", line, &share->webTxt);
|
|
|
|
rdLine("web_bg = ", line, &share->webBg);
|
|
|
|
rdLine("web_font = ", line, &share->webFont);
|
2023-04-20 14:52:59 -04:00
|
|
|
rdLine("max_event_secs = ", line, &share->evMaxSecs);
|
|
|
|
rdLine("post_secs = ", line, &share->postSecs);
|
2022-09-22 20:57:46 -04:00
|
|
|
rdLine("post_cmd = ", line, &share->postCmd);
|
2022-12-04 15:13:39 -05:00
|
|
|
rdLine("img_thresh = ", line, &share->imgThresh);
|
2023-03-05 16:07:07 -05:00
|
|
|
rdLine("max_events = ", line, &share->maxEvents);
|
2022-12-13 20:27:32 -05:00
|
|
|
rdLine("max_log_size = ", line, &share->maxLogSize);
|
2023-08-06 10:17:10 -04:00
|
|
|
rdLine("img_comp_out = ", line, &share->outputType);
|
|
|
|
rdLine("img_comp_cmd = ", line, &share->compCmd);
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
} while(!line.isEmpty());
|
2022-12-24 13:48:51 -05:00
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
if (share->camName.isEmpty())
|
2023-02-05 14:05:56 -05:00
|
|
|
{
|
2023-05-15 15:29:47 -04:00
|
|
|
share->camName = QFileInfo(share->conf).fileName();
|
2023-02-05 14:05:56 -05:00
|
|
|
}
|
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
share->outDir = QDir().cleanPath(share->webRoot) + "/" + share->camName;
|
2023-08-06 10:17:10 -04:00
|
|
|
share->tmpDir = share->buffPath + "/" + share->camName;
|
2023-07-31 11:16:07 -04:00
|
|
|
share->servPath = QString("/var/opt/") + APP_BIN + "/" + APP_BIN + "." + share->camName + ".service";
|
2022-09-22 20:57:46 -04:00
|
|
|
}
|
|
|
|
|
2023-05-15 15:29:47 -04:00
|
|
|
return share->retCode == 0;
|
2023-03-05 16:07:07 -05:00
|
|
|
}
|
2023-05-17 15:06:58 -04:00
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
void rmServices()
|
2023-05-17 15:06:58 -04:00
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
auto files = lsFilesInDir(QString("/var/opt/") + APP_BIN, ".service");
|
2023-05-17 15:06:58 -04:00
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
for (auto &&serv : files)
|
2023-05-17 15:06:58 -04:00
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
QProcess::execute("systemctl", {"stop", serv});
|
|
|
|
QProcess::execute("systemctl", {"disable", serv});
|
|
|
|
|
|
|
|
QFile::remove(QString("/lib/systemd/system/") + serv);
|
|
|
|
QFile::remove(QString("/var/opt/") + APP_BIN + "/" + serv);
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
2023-07-31 11:16:07 -04:00
|
|
|
|
|
|
|
QProcess::execute("systemctl", {"daemon-reload"});
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
void listServices()
|
2023-05-17 15:06:58 -04:00
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
auto files = lsFilesInDir(QString("/var/opt/") + APP_BIN, ".service");
|
2023-05-17 15:06:58 -04:00
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
for (auto &&serv : files)
|
2023-05-17 15:06:58 -04:00
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
QTextStream(stdout) << serv << ": "; QProcess::execute("systemctl", {"is-active", serv});
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
int loadServices(const QStringList &args)
|
2023-05-17 15:06:58 -04:00
|
|
|
{
|
|
|
|
auto ret = ENOENT;
|
2023-05-17 17:10:39 -04:00
|
|
|
auto path = QDir().cleanPath(getParam("-d", args));
|
2023-05-17 15:06:58 -04:00
|
|
|
auto files = lsFilesInDir(path);
|
|
|
|
|
|
|
|
if (!QDir(path).exists())
|
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
QTextStream(stderr) << "err: the supplied directory in -d '" << path << "' does not exists or is not a directory." << Qt::endl;
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
|
|
|
else if (files.isEmpty())
|
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
QTextStream(stderr) << "err: no config files found in '" << path << "'" << Qt::endl;
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-17 17:10:39 -04:00
|
|
|
ret = 0;
|
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
QTextStream(stdout) << "loading conf files from dir: " << path << Qt::endl;
|
|
|
|
|
2023-05-17 15:06:58 -04:00
|
|
|
for (auto &&conf : files)
|
|
|
|
{
|
2023-07-31 11:16:07 -04:00
|
|
|
shared_t shared;
|
2023-05-17 15:06:58 -04:00
|
|
|
|
2023-07-31 11:16:07 -04:00
|
|
|
if (!rdConf(path + "/" + conf, &shared))
|
|
|
|
{
|
|
|
|
ret = shared.retCode; break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QTextStream(stdout) << conf << " --" << Qt::endl;
|
|
|
|
|
|
|
|
QFile file(shared.servPath);
|
|
|
|
|
|
|
|
if (!file.open(QFile::ReadWrite | QFile::Truncate))
|
|
|
|
{
|
|
|
|
QTextStream(stderr) << "err: failed to open service file: " << shared.servPath << " for writing. reason: " << file.errorString();
|
|
|
|
|
|
|
|
ret = EACCES; file.close(); break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file.write("[Unit]\n");
|
|
|
|
file.write("Description=" + QByteArray(APP_NAME) + " Camera - " + shared.camName.toUtf8() + "\n");
|
|
|
|
file.write("After=network.target\n\n");
|
|
|
|
file.write("[Service]\n");
|
|
|
|
file.write("Type=simple\n");
|
|
|
|
file.write("User=" + QByteArray(APP_BIN) + "\n");
|
|
|
|
file.write("Restart=always\n");
|
|
|
|
file.write("RestartSec=5\n");
|
|
|
|
file.write("TimeoutStopSec=infinity\n");
|
|
|
|
file.write("ExecStart=/usr/bin/env " + QByteArray(APP_BIN) + " -c " + shared.conf.toUtf8() + "\n\n");
|
|
|
|
file.write("[Install]\n");
|
|
|
|
file.write("WantedBy=multi-user.target");
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
auto servName = QFileInfo(shared.servPath).fileName();
|
|
|
|
|
|
|
|
if (!QFile::link(shared.servPath, "/lib/systemd/system/" + servName))
|
|
|
|
{
|
|
|
|
ret = EACCES; break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ret == 0) ret = QProcess::execute("systemctl", {"daemon-reload"});
|
|
|
|
if (ret == 0) ret = QProcess::execute("systemctl", {"enable", servName});
|
|
|
|
if (ret == 0) ret = QProcess::execute("systemctl", {"start", servName});
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QTextStream(stdout) << "Successfully loaded camera service: " << servName << Qt::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 15:06:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2023-08-06 10:17:10 -04:00
|
|
|
|
|
|
|
QStringList parseArgs(const QByteArray &data, int maxArgs, int *pos)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
|
|
|
QString arg;
|
|
|
|
|
|
|
|
auto line = QString::fromUtf8(data);
|
|
|
|
auto inDQuotes = false;
|
|
|
|
auto inSQuotes = false;
|
|
|
|
auto escaped = false;
|
|
|
|
|
|
|
|
if (pos != nullptr) *pos = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < line.size(); ++i)
|
|
|
|
{
|
|
|
|
if (pos != nullptr) *pos += 1;
|
|
|
|
|
|
|
|
if ((line[i] == '\'') && !inDQuotes && !escaped)
|
|
|
|
{
|
|
|
|
// single quote '
|
|
|
|
|
|
|
|
inSQuotes = !inSQuotes;
|
|
|
|
}
|
|
|
|
else if ((line[i] == '\"') && !inSQuotes && !escaped)
|
|
|
|
{
|
|
|
|
// double quote "
|
|
|
|
|
|
|
|
inDQuotes = !inDQuotes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
escaped = false;
|
|
|
|
|
|
|
|
if (line[i].isSpace() && !inDQuotes && !inSQuotes)
|
|
|
|
{
|
|
|
|
// space
|
|
|
|
|
|
|
|
if (!arg.isEmpty())
|
|
|
|
{
|
|
|
|
ret.append(arg);
|
|
|
|
arg.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((line[i] == '\\') && ((i + 1) < line.size()))
|
|
|
|
{
|
|
|
|
if ((line[i + 1] == '\'') || (line[i + 1] == '\"'))
|
|
|
|
{
|
|
|
|
escaped = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arg.append(line[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arg.append(line[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret.size() >= maxArgs) && (maxArgs != -1))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg.isEmpty() && !inDQuotes && !inSQuotes)
|
|
|
|
{
|
|
|
|
ret.append(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|