From ac430471a0af9cd9ba19b76495327be59c7cef58 Mon Sep 17 00:00:00 2001
From: marshmellow42 <marshmellowrf@gmail.com>
Date: Thu, 13 Apr 2017 17:14:40 -0400
Subject: [PATCH] fix compile errors in newer environment

---
 armsrc/crapto1.c        | 29 +++++++++++++++++---------
 armsrc/crypto1.c        |  5 ++++-
 client/Makefile         | 43 +++++++++++++++++++++++---------------
 client/proxgui.h        |  2 +-
 client/ui.c             |  2 +-
 client/ui/ui_overlays.h | 46 ++++++++++++++++++++---------------------
 6 files changed, 74 insertions(+), 53 deletions(-)

diff --git a/armsrc/crapto1.c b/armsrc/crapto1.c
index 9d491d12..74b4eea7 100644
--- a/armsrc/crapto1.c
+++ b/armsrc/crapto1.c
@@ -34,22 +34,29 @@ static void __attribute__((constructor)) fill_lut()
 static void quicksort(uint32_t* const start, uint32_t* const stop)
 {
 	uint32_t *it = start + 1, *rit = stop;
-
+	uint32_t tmp;
 	if(it > rit)
 		return;
 
-	while(it < rit)
-		if(*it <= *start)
+	while(it < rit) {
+		if(*it <= *start) {
 			++it;
-		else if(*rit > *start)
+		} else if(*rit > *start) {
 			--rit;
-		else
-			*it ^= (*it ^= *rit, *rit ^= *it);
+		} else {
+			tmp = *it;
+			*it = *rit;
+			*rit = tmp;
+		}
+	}
 
 	if(*rit >= *start)
 		--rit;
-	if(rit != start)
-		*rit ^= (*rit ^= *start, *start ^= *rit);
+	if(rit != start) {
+		tmp = *rit;
+		*rit = *start;
+		*start = tmp;
+	}
 
 	quicksort(start, rit - 1);
 	quicksort(rit + 1, stop);
@@ -319,9 +326,11 @@ uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb)
 {
 	int out;
 	uint8_t ret;
-
+	uint32_t tmp;
 	s->odd &= 0xffffff;
-	s->odd ^= (s->odd ^= s->even, s->even ^= s->odd);
+	tmp = s->odd;
+	s->odd = s->even;
+	s->even = tmp;
 
 	out = s->even & 1;
 	out ^= LF_POLY_EVEN & (s->even >>= 1);
diff --git a/armsrc/crypto1.c b/armsrc/crypto1.c
index 9d103c7f..3d56fab4 100644
--- a/armsrc/crypto1.c
+++ b/armsrc/crypto1.c
@@ -52,6 +52,7 @@ uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
 {
 	uint32_t feedin;
 	uint8_t ret = filter(s->odd);
+	uint32_t tmp;
 
 	feedin  = ret & !!is_encrypted;
 	feedin ^= !!in;
@@ -59,7 +60,9 @@ uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
 	feedin ^= LF_POLY_EVEN & s->even;
 	s->even = s->even << 1 | parity(feedin);
 
-	s->odd ^= (s->odd ^= s->even, s->even ^= s->odd);
+	tmp = s->odd;
+	s->odd = s->even;
+	s->even = tmp;
 
 	return ret;
 }
diff --git a/client/Makefile b/client/Makefile
index 621b5779..4d28216b 100644
--- a/client/Makefile
+++ b/client/Makefile
@@ -16,25 +16,34 @@ LDLIBS = -L/opt/local/lib -L/usr/local/lib ../liblua/liblua.a -lreadline -lpthre
 LDFLAGS = $(COMMON_FLAGS)
 CFLAGS = -std=c99 -I. -I../include -I../common -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4
 LUAPLATFORM = generic
+
+platform = $(shell uname)
 ifneq (,$(findstring MINGW,$(platform)))
-CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
-QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
-MOC = $(QTDIR)/bin/moc
-LUAPLATFORM = mingw
-else ifeq ($(platform),Darwin)
-CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
-QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
-MOC = $(shell pkg-config --variable=moc_location QtCore)
-LUAPLATFORM = macosx
+    CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
+    ifneq ($(wildcard $(QTDIR)/include/QtWidgets),)
+        CXXFLAGS += -I$(QTDIR)/include/QtWidgets
+        QTLDLIBS = -L$(QTDIR)/lib -lQt5Core -lQt5Gui -lQt5Widgets
+    else
+        QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
+    endif
+    MOC = $(QTDIR)/bin/moc
+    LUAPLATFORM = mingw
 else
-CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
-QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
-MOC = $(shell pkg-config --variable=moc_location QtCore)
-LDLIBS +=  -ldl
-
-# Below is a variant you can use if you have problems compiling with QT5 on ubuntu. see http://www.proxmark.org/forum/viewtopic.php?id=1661 for more info. 
-#MOC = /usr/lib/x86_64-linux-gnu/qt4/bin/moc
-LUAPLATFORM = linux
+	CXXFLAGS = $(shell pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null) -Wall -O4
+	QTLDLIBS = $(shell pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
+	MOC = $(shell pkg-config --variable=host_bins Qt5Core)/moc
+	ifeq ($(QTLDLIBS), )
+		CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
+		QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
+		MOC = $(shell pkg-config --variable=moc_location QtCore)
+	endif
+	ifeq ($(platform),Darwin)
+		LUAPLATFORM = macosx
+	else
+		LUALIB +=  -ldl
+		LDLIBS +=  -ltermcap -lncurses
+		LUAPLATFORM = linux
+	endif
 endif
 
 
diff --git a/client/proxgui.h b/client/proxgui.h
index 0d50a4f6..b8c4f6c4 100644
--- a/client/proxgui.h
+++ b/client/proxgui.h
@@ -8,7 +8,7 @@
 // GUI functions
 //-----------------------------------------------------------------------------
 #include <string.h>
-
+#include <stdint.h>
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/client/ui.c b/client/ui.c
index c0d01bc3..bdaaf60c 100644
--- a/client/ui.c
+++ b/client/ui.c
@@ -18,7 +18,7 @@
 
 #include "ui.h"
 
-double CursorScaleFactor;
+double CursorScaleFactor = 0;
 int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64;
 int offline;
 int flushAfterWrite = 0;  //buzzy
diff --git a/client/ui/ui_overlays.h b/client/ui/ui_overlays.h
index 6e652c12..83aa3e6c 100644
--- a/client/ui/ui_overlays.h
+++ b/client/ui/ui_overlays.h
@@ -10,19 +10,19 @@
 #define OVERLAYSTQ7020_H
 
 #include <QtCore/QVariant>
-#include <QtGui/QAction>
-#include <QtGui/QApplication>
-#include <QtGui/QButtonGroup>
-#include <QtGui/QFormLayout>
-#include <QtGui/QHBoxLayout>
-#include <QtGui/QHeaderView>
-#include <QtGui/QLabel>
-#include <QtGui/QPushButton>
-#include <QtGui/QSlider>
-#include <QtGui/QSpacerItem>
-#include <QtGui/QTabWidget>
-#include <QtGui/QVBoxLayout>
-#include <QtGui/QWidget>
+#include <QAction>
+#include <QApplication>
+#include <QButtonGroup>
+#include <QFormLayout>
+#include <QHBoxLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QPushButton>
+#include <QSlider>
+#include <QSpacerItem>
+#include <QTabWidget>
+#include <QVBoxLayout>
+#include <QWidget>
 
 QT_BEGIN_NAMESPACE
 
@@ -198,19 +198,19 @@ public:
 
     void retranslateUi(QWidget *Form)
     {
-        Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0, QApplication::UnicodeUTF8));
-        label->setText(QApplication::translate("Form", "Window size", 0, QApplication::UnicodeUTF8));
+        Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0));
+        label->setText(QApplication::translate("Form", "Window size", 0));
         label_5->setText(QString());
-        tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0, QApplication::UnicodeUTF8));
-        tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "Askdemod", 0, QApplication::UnicodeUTF8));
-        label_2->setText(QApplication::translate("Form", "Up", 0, QApplication::UnicodeUTF8));
+        tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0));
+        tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "Askdemod", 0));
+        label_2->setText(QApplication::translate("Form", "Up", 0));
         label_6->setText(QString());
-        label_3->setText(QApplication::translate("Form", "Down", 0, QApplication::UnicodeUTF8));
+        label_3->setText(QApplication::translate("Form", "Down", 0));
         label_7->setText(QString());
-        tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0, QApplication::UnicodeUTF8));
-        pushButton_apply->setText(QApplication::translate("Form", "Apply", 0, QApplication::UnicodeUTF8));
-        pushButton_sticky->setText(QApplication::translate("Form", "Sticky", 0, QApplication::UnicodeUTF8));
-        label_4->setText(QApplication::translate("Form", "TextLabel", 0, QApplication::UnicodeUTF8));
+        tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0));
+        pushButton_apply->setText(QApplication::translate("Form", "Apply", 0));
+        pushButton_sticky->setText(QApplication::translate("Form", "Sticky", 0));
+        label_4->setText(QApplication::translate("Form", "TextLabel", 0));
     } // retranslateUi
 
 };
-- 
2.39.5