Skip to content

Commit 40a2b0f

Browse files
committed
2 parents de17511 + e619215 commit 40a2b0f

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "src/openspin/OpenSpin"]
1+
[submodule "src/openspin/repo"]
22
path = src/openspin/repo
3-
url = https://github.com/bweir/OpenSpin
3+
url = https://github.com/bweir/OpenSpin.git

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ VERSION := $(shell echo $(shell grep -r VERSION= propelleride.pri \
2020
| sed -e 's/ /./g')
2121

2222
# if CPU (uname -m) equals...
23-
ifeq ($(shell uname -n),raspberrypi) # if Raspberry Pi
23+
ifeq ($(shell cat /etc/os-release | grep "ID=raspbian"),ID=raspbian) # if Raspberry Pi
2424
CPU := armhf
2525
else
2626
ifeq ($(shell uname -m),i686) # if i686

src/propelleride/SpinParser.cpp

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "SpinParser.h"
22

3-
#define KEY_ELEMENT_SEP ":"
3+
#define KEY_ELEMENT_SEP ':'
44

55
SpinParser::SpinParser()
66
{
@@ -71,17 +71,11 @@ QStringList SpinParser::spinFileTree(QString file, QString libpath)
7171
QStringList nodes;
7272
foreach(key, keys) {
7373
value = db[key];
74-
QStringList levels = key.split("/");
75-
int lcount = levels.count()-1;
76-
QStringList keyel = levels[lcount].split(KEY_ELEMENT_SEP);
77-
if(keyel.count() < 2)
78-
continue;
79-
if(QString(keyel[0]).compare(keyel[1]) == 0) {
80-
//qDebug() << key;
81-
objectInfo(value, subnode, subfile);
82-
//for(int n = 0; n < lcount; n++) subfile = " " + subfile;
83-
nodes.append(subfile);
84-
}
74+
QStringList tags = value.split("\t");
75+
if (tags.count() < 4 || !tags[3].startsWith(SpinKinds[K_OBJECT].letter))
76+
continue; // short list or not an object
77+
objectInfo(value, subnode, subfile);
78+
nodes.append(subfile);
8579
}
8680
// Indent later. Just sort for now.
8781
#ifdef QT5
@@ -93,7 +87,6 @@ QStringList SpinParser::spinFileTree(QString file, QString libpath)
9387
QString ns = nodes.at(n);
9488
spinFiles.append(ns.mid(ns.lastIndexOf(":")+1));
9589
}
96-
9790
return spinFiles;
9891
}
9992

@@ -421,9 +414,6 @@ void SpinParser::match_dat (QString p, int line)
421414

422415
void SpinParser::match_object (QString p, int line)
423416
{
424-
QString tag = "";
425-
QString subfile = "";
426-
QString subnode = "";
427417
int len = p.indexOf(":");
428418
if(p.indexOf(":=") > 0)
429419
len = 0;
@@ -440,15 +430,38 @@ void SpinParser::match_object (QString p, int line)
440430
if(s.contains("[",Qt::CaseInsensitive))
441431
p = p.mid(0,p.indexOf("[",0,Qt::CaseInsensitive));
442432
p = p.trimmed();
443-
tag = s+"\t"+currentFile+"\t"+p+"\t"+SpinKinds[K_OBJECT].letter;
444-
objectInfo(tag, subnode, subfile);
433+
434+
QString key = objectNode+KEY_ELEMENT_SEP+s;
435+
QString tag = s+"\t"+currentFile+"\t"+p+"\t"+SpinKinds[K_OBJECT].letter;
436+
QString dummy, subnode, subfile, parent, curr = key;
437+
438+
objectInfo(tag, subnode, subfile, parent);
445439
QString file = checkFile(subfile);
446-
if(QFile::exists(file) == false)
447-
return;
448-
QString key = objectNode+"/"+subnode+KEY_ELEMENT_SEP+s;
449-
if(db.contains(key) == false)
440+
441+
// file is missing, ignore object
442+
if(!QFile::exists(file)) return;
443+
444+
// avoid circular references, do this by scanning all existing
445+
// parents of this particular key (*/*/*:*)
446+
for (;;) {
447+
int index;
448+
// invalid match, ignore object
449+
if (parent == file) {
450+
qDebug() << "circular reference: " << s << currentFile;
451+
return;
452+
}
453+
// cut off key at KEY_ELEMENT_SEP
454+
if ((index = curr.lastIndexOf(KEY_ELEMENT_SEP)) == -1) break;
455+
curr.resize(index);
456+
// replace last / with KEY_ELEMENT_SEP
457+
if ((index = curr.lastIndexOf('/')) == -1) break;
458+
curr[index] = QChar(KEY_ELEMENT_SEP);
459+
// extract parent file
460+
objectInfo(db[curr], dummy, dummy, parent);
461+
}
462+
if(!db.contains(key))
450463
db.insert(key,tag+"\t"+QString("%1").arg(line));
451-
// qDebug() << objectNode+"/"+subnode << " :: " << tag;
464+
452465
findSpinTags(subfile,objectNode+"/"+subnode);
453466
}
454467
}
@@ -531,10 +544,16 @@ void SpinParser::match_var (QString p, int line)
531544
}
532545

533546
int SpinParser::objectInfo(QString tag, QString &name, QString &file)
547+
{
548+
return objectInfo(tag, name, file, file);
549+
}
550+
551+
int SpinParser::objectInfo(QString tag, QString &name, QString &file, QString &parent)
534552
{
535553
QStringList list = tag.split("\t",QString::KeepEmptyParts);
536554
if(list.length() == 0)
537555
return 0;
556+
538557
name = QString(list[0]).trimmed();
539558
file = QString(list[2]).trimmed();
540559
file = file.mid(file.indexOf("\"")+1);
@@ -544,6 +563,9 @@ int SpinParser::objectInfo(QString tag, QString &name, QString &file)
544563
if(file.contains(".spin",Qt::CaseInsensitive) == false)
545564
file += ".spin";
546565

566+
if (parent != file)
567+
parent = QString(list[1]).trimmed();
568+
547569
return list.length();
548570
}
549571

src/propelleride/SpinParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class SpinParser
7474

7575
typedef struct sKindOption {
7676
bool enabled; /* are tags for kind enabled? */
77-
int letter; /* kind letter */
77+
char letter; /* kind letter */
7878
QString name; /* kind name */
7979
QString description; /* displayed in --help output */
8080
} kindOption;
@@ -123,6 +123,7 @@ class SpinParser
123123
void match_pub (QString p, int line);
124124
void match_var (QString p, int line);
125125
int objectInfo(QString tag, QString &name, QString &file);
126+
int objectInfo(QString tag, QString &name, QString &file, QString &parent);
126127
QString checkFile(QString fileName);
127128
void findSpinTags (QString fileName, QString objnode);
128129

0 commit comments

Comments
 (0)