<commit_before>#include "stdafx.h"

// OpenARK Libraries
#include "version.h"
#ifdef PMDSDK_ENABLED
    #include "PMDCamera.h"
#endif
#ifdef RSSDK_ENABLED
    #include "SR300Camera.h"
#endif

#include "Webcam.h"
#include "Visualizer.h"
#include "Hand.h"
#include "Plane.h"
#include "Calibration.h"
#include "Util.h"
#include "UDPSender.h"
#include "Object3D.h"
#include "StreamingAverager.h"

#include "HandFeatureExtractor.h"
#include "HandClassifier.h"

using namespace ark;

static inline void drawHand(cv::Mat & image, Object3D & obj, float confidence = 0.0) {
    if (obj.getContour().size() > 2) {
        cv::polylines(image, obj.getContour(), true, cv::Scalar(0, 255, 0), 1);
    }

    if (obj.hasHand) {
        image = Visualizer::visualizeHand(image, obj.getHand());
    }

    std::stringstream disp;
    disp << std::setprecision(3) << std::fixed << confidence;

    Point2i center = obj.getCenterIj();
    Point2i dispPt = Point2i(center.x - (int)disp.str().size() * 8, center.y);
    cv::putText(image, disp.str(), dispPt, 0, 0.8, cv::Scalar(255, 255, 255), 1);
}

int main() {
    printf("Welcome to OpenARK v %s\n", ark::VERSION);
    DepthCamera * camera;

#ifdef PMDSDK_ENABLED
    if (!strcmp(OPENARK_CAMERA_TYPE, "pmd")) {
        camera = new PMDCamera();
    }
    else {
        return -1;
    }
#endif
#ifdef RSSDK_ENABLED
    if (!strcmp(OPENARK_CAMERA_TYPE, "sr300")) {
        camera = new SR300Camera();
    }
    else {
        return -1;
    }
#endif

    //RGBCamera *cam = new Webcam(1);
    int frame = 0;

    //Calibration::XYZToUnity(*pmd, 4, 4, 3);

    cv::FileStorage fs;
    fs.open("RT_Transform.txt", cv::FileStorage::READ);

    cv::Mat r, t;
    fs["R"] >> r;
    fs["T"] >> t;

    fs.release();
    UDPSender u = UDPSender();

    StreamingAverager handAverager = StreamingAverager(4, 0.15), pAverager = StreamingAverager(6, 0.05);
    clock_t cycleStartTime = 0;

    // store FPS information
    const int FPS_FRAMES = 5;
    float currFps = 0;

    while (true)
    {
        camera->nextFrame();

        #ifdef DEMO
            if (camera->getXYZMap().rows > 0) {
                cv::imshow("OpenARK Depth Image", camera->getXYZMap());
                if (camera->hasRGBImage()) {
                    cv::imshow("OpenARK Color Image", camera->getRGBImage());
                }
                //if (camera->hasIRImage() && camera->getIRImage().rows > 0) {
                //    cv::Mat colorMat;
                //    camera->getIRImage().convertTo(colorMat, CV_8U);
                //    cv::imshow("OpenARK Infrared Image", colorMat);
                //}
            }
        #endif

        // Classifying objects in the scene
        std::vector<Object3D> objects = camera->queryObjects();

        // visualization of hand objects
        cv::Mat handVisual;

#ifdef DEMO
        if (camera->hasIRImage()) {
            camera->getIRImage().convertTo(handVisual, CV_8UC1);
            handVisual /= 2;
            cv::cvtColor(handVisual, handVisual, cv::COLOR_GRAY2BGR, 3);
        }
        else {
#endif
            handVisual = cv::Mat::zeros(camera->getHeight(), camera->getWidth(), CV_8UC3);
#ifdef DEMO
        }
#endif

        int handObjectIndex = -1, handCount = 0, planeObjectIndex = -1;

        // object is immediately considered to be hand if SVM confidence is above this
        static const double SVM_HIGH_CONFIDENCE_THRESH = 0.59;

        float bestHandDist = FLT_MAX, bestDistConf = 0;

        for (int i = 0; i < objects.size(); ++i) {
            Object3D & obj = objects[i];

            if (obj.hasPlane) {
                planeObjectIndex = i;
                //cv::polylines(handVisual, obj.getContour(), true,
                    //cv::Scalar(255, 0, 255));
            }

            if (obj.hasHand) {
                float distance = obj.getDepth();

                double conf = obj.getHand().svm_confidence;

                if (distance < bestHandDist){
                    handObjectIndex = i;
                    bestHandDist = distance;
                    bestDistConf = conf;
                }

                if (conf > SVM_HIGH_CONFIDENCE_THRESH) {
                    drawHand(handVisual, obj, conf);
                    ++handCount;

                    if (handObjectIndex == i) handObjectIndex = -1;
                }
            }
        }

        // Draw hands
        if (handObjectIndex != -1) {
            ++handCount;
            Object3D obj = objects[handObjectIndex];
            drawHand(handVisual, obj, bestDistConf);
        }

        if (handCount > 0) {
            cv::putText(handVisual,
                std::to_string(handCount) + " Hand" + (handCount == 1 ? "" : "s"),
                Point2i(10, 25), 0, 0.5, cv::Scalar(255, 255, 255));
        }

        if (cycleStartTime) {
            if (frame % FPS_FRAMES == 0) {
                currFps = (float)CLOCKS_PER_SEC  * (float)FPS_FRAMES / (clock() - cycleStartTime);
                cycleStartTime = clock();
            }

            if (frame > FPS_FRAMES) {
                std::stringstream fpsDisplay;
                double fpsDisp = currFps;
                fpsDisplay << "FPS: " << (fpsDisp < 10 ? "0" : "") << setprecision(3) << std::fixed << fpsDisp;
                cv::putText(handVisual, fpsDisplay.str(),
                    Point2i(handVisual.cols - 120, 25), 0, 0.5, cv::Scalar(255, 255, 255));

            }
        }
        else {
            cycleStartTime = clock();
        }

        if (camera->badInput()) {
            const int RECT_WID = 160, RECT_HI = 40;
            cv::Rect rect(handVisual.cols / 2 - RECT_WID / 2,
                handVisual.rows / 2 - RECT_HI / 2,
                RECT_WID, RECT_HI);
            cv::rectangle(handVisual, rect, cv::Scalar(0, 50, 255), -1);
            cv::putText(handVisual, "NO SIGNAL",
                cv::Point(handVisual.cols / 2 - 65, handVisual.rows / 2 + 7),
                0, 0.8, cv::Scalar(255, 255, 255), 1, cv::LINE_AA);
        }

        cv::namedWindow("OpenARK Hand Detection");
        cv::imshow("OpenARK Hand Detection", handVisual);

        // Interpret the relationship between the objects
        bool clicked = false, paletteFound = false;

        Object3D handObject, planeObject;
        Point paletteCenter(-1. - 1);
        cv::Mat mask = cv::Mat::zeros(camera->getXYZMap().rows, camera->getXYZMap().cols, CV_8UC1);

        if (planeObjectIndex != -1 && handObjectIndex != -1) {
            //planeObject = objects[planeObjectIndex];
            //handObject = objects[handObjectIndex];

            //clicked = handObject.getHand().touchObject(planeObject.getPlane().getPlaneEquation(), planeObject.getPlane().R_SQUARED_DISTANCE_THRESHOLD * 5);
            ////auto scene = Visualizer::visualizePlaneRegression(camera->getXYZMap(), planeObject.getPlane().getPlaneEquation(), planeObject.getPlane().R_SQUARED_DISTANCE_THRESHOLD, clicked);
            ////scene = Visualizer::visualizeHand(scene, handObject.getHand());
            //if (planeObject.leftEdgeConnected) {
            //    Visualizer::visualizePlanePoints(mask, planeObject.getPlane().getPlaneIndicies());
            //    auto m = moments(mask, false);
            //    paletteCenter = Point(m.m10 / m.m00, m.m01 / m.m00);
            //    //circle(scene, paletteCenter, 2, Scalar(0, 0, 255), 2);
            //    paletteFound = true;
            //}
            //namedWindow("Results", CV_WINDOW_AUTOSIZE);
            //imshow("Results", scene);
        }
        else if (handObjectIndex != -1) {
            handObject = objects[handObjectIndex];
            //cv::imshow("Results", Visualizer::visualizeHand(pmd->getXYZMap(), handObject.getHand()));
        }
        else if (planeObjectIndex != -1) {
            planeObject = objects[planeObjectIndex];
            //auto scene = Visualizer::visualizePlaneRegression(camera->getXYZMap(), planeObject.getPlane().getPlaneEquation(), planeObject.getPlane().R_SQUARED_DISTANCE_THRESHOLD, clicked);
            if (planeObject.leftEdgeConnected) {
                Visualizer::visualizePlanePoints(mask, planeObject.getPlane().getPlaneIndicies());
                auto m = moments(mask, false);
                paletteCenter = Point2i(m.m10 / m.m00, m.m01 / m.m00);
                //circle(scene, paletteCenter, 2, Scalar(0, 0, 255), 2);
                paletteFound = true;
            }
            //namedWindow("Results", CV_WINDOW_AUTOSIZE);
            //imshow("Results", scene);
        }

        // Organize the data and send to game engine
        std::string handX = "-", handY = "-", handZ = "-";
        std::string paletteX = "-", paletteY = "-", paletteZ = "-";
        std::string clickStatus = "2";
        std::string num_fingers = "0";
        if (handObjectIndex != -1 && !objects[handObjectIndex].getHand().fingers_xyz.empty()) {
            auto handPos = handAverager.addDataPoint(objects[handObjectIndex].getHand().fingers_xyz[0]);
            //float hand_pt[3] = { objects[handObjectIndex].getHand().pointer_finger_xyz[0], objects[handObjectIndex].getHand().pointer_finger_xyz[1], objects[handObjectIndex].getHand().pointer_finger_xyz[2]};
            double hand_pt[3] = { handPos[0], handPos[1], handPos[2] };
            auto hand_mat = cv::Mat(3, 1, CV_32FC1, &hand_pt);
            //hand_mat = r*hand_mat + t;
            handX = std::to_string(hand_mat.at<float>(0, 0));
            handY = std::to_string(hand_mat.at<float>(1, 0));
            handZ = std::to_string(hand_mat.at<float>(2, 0));
            num_fingers = std::to_string(objects[handObjectIndex].getHand().fingers_xyz.size());
        }
        else {
            handAverager.addEmptyPoint();
        }
        if (paletteFound) {
            auto pt = pAverager.addDataPoint(camera->getXYZMap().at<Vec3f>(paletteCenter.y, paletteCenter.x));
            float palette_pt[3] = { pt[0], pt[1], pt[2] };
            auto palette_mat = cv::Mat(3, 1, CV_32FC1, &palette_pt);
            //palette_mat = r*palette_mat + t;
            paletteX = std::to_string(palette_mat.at<float>(0, 0));
            paletteY = std::to_string(palette_mat.at<float>(1, 0));
            paletteZ = std::to_string(palette_mat.at<float>(2, 0));
        }
        else {
            pAverager.addEmptyPoint();
        }
        if (clicked) {
            clickStatus = "1";
        }

        std::string tempS = "";
        tempS = handX + "%" + handY + "%" + handZ + "%" + paletteX + "%" + paletteY + "%" + paletteZ + "%" + clickStatus + "%" + num_fingers;
        u.send(tempS);

        /**** Start: Write Frames to File ****/
        //std::string filename = "img" + std::to_string(frame) + ".yml";
        //pmd->writeImage(filename);
        //std::cout << filename << std::endl;
        /**** End: Write Frames to File ****/

        /**** Start: Loop Break Condition ****/
        int c = cv::waitKey(1);
        if (c == 'q' || c == 'Q' || c == 27) {
            break;
        }

        /**** End: Loop Break Condition ****/
        ++frame;
    }

    camera->destroyInstance();
    cv::destroyAllWindows();
    return 0;
}<commit_msg>Added srand to main<commit_after>#include "stdafx.h"

// OpenARK Libraries
#include "version.h"
#ifdef PMDSDK_ENABLED
    #include "PMDCamera.h"
#endif
#ifdef RSSDK_ENABLED
    #include "SR300Camera.h"
#endif

#include "Webcam.h"
#include "Visualizer.h"
#include "Hand.h"
#include "Plane.h"
#include "Calibration.h"
#include "Util.h"
#include "UDPSender.h"
#include "Object3D.h"
#include "StreamingAverager.h"

#include "HandFeatureExtractor.h"
#include "HandClassifier.h"

using namespace ark;

static inline void drawHand(cv::Mat & image, Object3D & obj, float confidence = 0.0) {
    if (obj.getContour().size() > 2) {
        cv::polylines(image, obj.getContour(), true, cv::Scalar(0, 255, 0), 1);
    }

    if (obj.hasHand) {
        image = Visualizer::visualizeHand(image, obj.getHand());
    }

    std::stringstream disp;
    disp << std::setprecision(3) << std::fixed << confidence;

    Point2i center = obj.getCenterIj();
    Point2i dispPt = Point2i(center.x - (int)disp.str().size() * 8, center.y);
    cv::putText(image, disp.str(), dispPt, 0, 0.8, cv::Scalar(255, 255, 255), 1);
}

int main() {
    printf("Welcome to OpenARK v %s\n", ark::VERSION);
    DepthCamera * camera;

#ifdef PMDSDK_ENABLED
    if (!strcmp(OPENARK_CAMERA_TYPE, "pmd")) {
        camera = new PMDCamera();
    }
    else {
        return -1;
    }
#endif
#ifdef RSSDK_ENABLED
    if (!strcmp(OPENARK_CAMERA_TYPE, "sr300")) {
        camera = new SR300Camera();
    }
    else {
        return -1;
    }
#endif
    srand(time(NULL))

    //RGBCamera *cam = new Webcam(1);
    int frame = 0;

    //Calibration::XYZToUnity(*pmd, 4, 4, 3);

    cv::FileStorage fs;
    fs.open("RT_Transform.txt", cv::FileStorage::READ);

    cv::Mat r, t;
    fs["R"] >> r;
    fs["T"] >> t;

    fs.release();
    UDPSender u = UDPSender();

    StreamingAverager handAverager = StreamingAverager(4, 0.15), pAverager = StreamingAverager(6, 0.05);
    clock_t cycleStartTime = 0;

    // store FPS information
    const int FPS_FRAMES = 5;
    float currFps = 0;

    while (true)
    {
        camera->nextFrame();

        #ifdef DEMO
            if (camera->getXYZMap().rows > 0) {
                cv::imshow("OpenARK Depth Image", camera->getXYZMap());
                if (camera->hasRGBImage()) {
                    cv::imshow("OpenARK Color Image", camera->getRGBImage());
                }
                //if (camera->hasIRImage() && camera->getIRImage().rows > 0) {
                //    cv::Mat colorMat;
                //    camera->getIRImage().convertTo(colorMat, CV_8U);
                //    cv::imshow("OpenARK Infrared Image", colorMat);
                //}
            }
        #endif

        // Classifying objects in the scene
        std::vector<Object3D> objects = camera->queryObjects();

        // visualization of hand objects
        cv::Mat handVisual;

#ifdef DEMO
        if (camera->hasIRImage()) {
            camera->getIRImage().convertTo(handVisual, CV_8UC1);
            handVisual /= 2;
            cv::cvtColor(handVisual, handVisual, cv::COLOR_GRAY2BGR, 3);
        }
        else {
#endif
            handVisual = cv::Mat::zeros(camera->getHeight(), camera->getWidth(), CV_8UC3);
#ifdef DEMO
        }
#endif

        int handObjectIndex = -1, handCount = 0, planeObjectIndex = -1;

        // object is immediately considered to be hand if SVM confidence is above this
        static const double SVM_HIGH_CONFIDENCE_THRESH = 0.59;

        float bestHandDist = FLT_MAX, bestDistConf = 0;

        for (int i = 0; i < objects.size(); ++i) {
            Object3D & obj = objects[i];

            if (obj.hasPlane) {
                planeObjectIndex = i;
                //cv::polylines(handVisual, obj.getContour(), true,
                    //cv::Scalar(255, 0, 255));
            }

            if (obj.hasHand) {
                float distance = obj.getDepth();

                double conf = obj.getHand().svm_confidence;

                if (distance < bestHandDist){
                    handObjectIndex = i;
                    bestHandDist = distance;
                    bestDistConf = conf;
                }

                if (conf > SVM_HIGH_CONFIDENCE_THRESH) {
                    drawHand(handVisual, obj, conf);
                    ++handCount;

                    if (handObjectIndex == i) handObjectIndex = -1;
                }
            }
        }

        // Draw hands
        if (handObjectIndex != -1) {
            ++handCount;
            Object3D obj = objects[handObjectIndex];
            drawHand(handVisual, obj, bestDistConf);
        }

        if (handCount > 0) {
            cv::putText(handVisual,
                std::to_string(handCount) + " Hand" + (handCount == 1 ? "" : "s"),
                Point2i(10, 25), 0, 0.5, cv::Scalar(255, 255, 255));
        }

        if (cycleStartTime) {
            if (frame % FPS_FRAMES == 0) {
                currFps = (float)CLOCKS_PER_SEC  * (float)FPS_FRAMES / (clock() - cycleStartTime);
                cycleStartTime = clock();
            }

            if (frame > FPS_FRAMES) {
                std::stringstream fpsDisplay;
                double fpsDisp = currFps;
                fpsDisplay << "FPS: " << (fpsDisp < 10 ? "0" : "") << setprecision(3) << std::fixed << fpsDisp;
                cv::putText(handVisual, fpsDisplay.str(),
                    Point2i(handVisual.cols - 120, 25), 0, 0.5, cv::Scalar(255, 255, 255));

            }
        }
        else {
            cycleStartTime = clock();
        }

        if (camera->badInput()) {
            const int RECT_WID = 160, RECT_HI = 40;
            cv::Rect rect(handVisual.cols / 2 - RECT_WID / 2,
                handVisual.rows / 2 - RECT_HI / 2,
                RECT_WID, RECT_HI);
            cv::rectangle(handVisual, rect, cv::Scalar(0, 50, 255), -1);
            cv::putText(handVisual, "NO SIGNAL",
                cv::Point(handVisual.cols / 2 - 65, handVisual.rows / 2 + 7),
                0, 0.8, cv::Scalar(255, 255, 255), 1, cv::LINE_AA);
        }

        cv::namedWindow("OpenARK Hand Detection");
        cv::imshow("OpenARK Hand Detection", handVisual);

        // Interpret the relationship between the objects
        bool clicked = false, paletteFound = false;

        Object3D handObject, planeObject;
        Point paletteCenter(-1. - 1);
        cv::Mat mask = cv::Mat::zeros(camera->getXYZMap().rows, camera->getXYZMap().cols, CV_8UC1);

        if (planeObjectIndex != -1 && handObjectIndex != -1) {
            //planeObject = objects[planeObjectIndex];
            //handObject = objects[handObjectIndex];

            //clicked = handObject.getHand().touchObject(planeObject.getPlane().getPlaneEquation(), planeObject.getPlane().R_SQUARED_DISTANCE_THRESHOLD * 5);
            ////auto scene = Visualizer::visualizePlaneRegression(camera->getXYZMap(), planeObject.getPlane().getPlaneEquation(), planeObject.getPlane().R_SQUARED_DISTANCE_THRESHOLD, clicked);
            ////scene = Visualizer::visualizeHand(scene, handObject.getHand());
            //if (planeObject.leftEdgeConnected) {
            //    Visualizer::visualizePlanePoints(mask, planeObject.getPlane().getPlaneIndicies());
            //    auto m = moments(mask, false);
            //    paletteCenter = Point(m.m10 / m.m00, m.m01 / m.m00);
            //    //circle(scene, paletteCenter, 2, Scalar(0, 0, 255), 2);
            //    paletteFound = true;
            //}
            //namedWindow("Results", CV_WINDOW_AUTOSIZE);
            //imshow("Results", scene);
        }
        else if (handObjectIndex != -1) {
            handObject = objects[handObjectIndex];
            //cv::imshow("Results", Visualizer::visualizeHand(pmd->getXYZMap(), handObject.getHand()));
        }
        else if (planeObjectIndex != -1) {
            planeObject = objects[planeObjectIndex];
            //auto scene = Visualizer::visualizePlaneRegression(camera->getXYZMap(), planeObject.getPlane().getPlaneEquation(), planeObject.getPlane().R_SQUARED_DISTANCE_THRESHOLD, clicked);
            if (planeObject.leftEdgeConnected) {
                Visualizer::visualizePlanePoints(mask, planeObject.getPlane().getPlaneIndicies());
                auto m = moments(mask, false);
                paletteCenter = Point2i(m.m10 / m.m00, m.m01 / m.m00);
                //circle(scene, paletteCenter, 2, Scalar(0, 0, 255), 2);
                paletteFound = true;
            }
            //namedWindow("Results", CV_WINDOW_AUTOSIZE);
            //imshow("Results", scene);
        }

        // Organize the data and send to game engine
        std::string handX = "-", handY = "-", handZ = "-";
        std::string paletteX = "-", paletteY = "-", paletteZ = "-";
        std::string clickStatus = "2";
        std::string num_fingers = "0";
        if (handObjectIndex != -1 && !objects[handObjectIndex].getHand().fingers_xyz.empty()) {
            auto handPos = handAverager.addDataPoint(objects[handObjectIndex].getHand().fingers_xyz[0]);
            //float hand_pt[3] = { objects[handObjectIndex].getHand().pointer_finger_xyz[0], objects[handObjectIndex].getHand().pointer_finger_xyz[1], objects[handObjectIndex].getHand().pointer_finger_xyz[2]};
            double hand_pt[3] = { handPos[0], handPos[1], handPos[2] };
            auto hand_mat = cv::Mat(3, 1, CV_32FC1, &hand_pt);
            //hand_mat = r*hand_mat + t;
            handX = std::to_string(hand_mat.at<float>(0, 0));
            handY = std::to_string(hand_mat.at<float>(1, 0));
            handZ = std::to_string(hand_mat.at<float>(2, 0));
            num_fingers = std::to_string(objects[handObjectIndex].getHand().fingers_xyz.size());
        }
        else {
            handAverager.addEmptyPoint();
        }
        if (paletteFound) {
            auto pt = pAverager.addDataPoint(camera->getXYZMap().at<Vec3f>(paletteCenter.y, paletteCenter.x));
            float palette_pt[3] = { pt[0], pt[1], pt[2] };
            auto palette_mat = cv::Mat(3, 1, CV_32FC1, &palette_pt);
            //palette_mat = r*palette_mat + t;
            paletteX = std::to_string(palette_mat.at<float>(0, 0));
            paletteY = std::to_string(palette_mat.at<float>(1, 0));
            paletteZ = std::to_string(palette_mat.at<float>(2, 0));
        }
        else {
            pAverager.addEmptyPoint();
        }
        if (clicked) {
            clickStatus = "1";
        }

        std::string tempS = "";
        tempS = handX + "%" + handY + "%" + handZ + "%" + paletteX + "%" + paletteY + "%" + paletteZ + "%" + clickStatus + "%" + num_fingers;
        u.send(tempS);

        /**** Start: Write Frames to File ****/
        //std::string filename = "img" + std::to_string(frame) + ".yml";
        //pmd->writeImage(filename);
        //std::cout << filename << std::endl;
        /**** End: Write Frames to File ****/

        /**** Start: Loop Break Condition ****/
        int c = cv::waitKey(1);
        if (c == 'q' || c == 'Q' || c == 27) {
            break;
        }

        /**** End: Loop Break Condition ****/
        ++frame;
    }

    camera->destroyInstance();
    cv::destroyAllWindows();
    return 0;
}<|endoftext|>


<commit_before>/* main.cpp
 *
 * Copyright (c) 2011, 2012 Chantilly Robotics <chantilly612@gmail.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * Implement robot_class to provide functionality for robot.
 */

#include "612.h"
#include "main.h"
#include "ports.h"
#include "update.h"
#include "vision/vision_processing.h"
#include "state_tracker.h"
#include "visionalg.h"
#include "shifter.h"

//constructor - initialize drive
robot_class::robot_class() {
    //do nothing
    GetWatchdog().SetEnabled(false); //we don't want Watchdog
}

void robot_class::RobotInit() {
    //Run-Time INIT
    //set necessary inversions
    drive.SetInvertedMotor(left_front_motor.type,  left_front_motor.reverse);
    drive.SetInvertedMotor(left_rear_motor.type,   left_rear_motor.reverse);
    drive.SetInvertedMotor(right_front_motor.type, right_front_motor.reverse);
    drive.SetInvertedMotor(right_rear_motor.type,  right_rear_motor.reverse);
    global_state.set_state(STATE_DRIVING);
    init_camera();
}

void robot_class::DisabledInit() {
    //do nothing
}

void robot_class::AutonomousInit() {
    //do nothing
}

void robot_class::TeleopInit() {
    //do nothing
}

void robot_class::DisabledPeriodic() {
    //do nothing
}

void robot_class::AutonomousPeriodic() {
    update_sensors();
}

void robot_class::TeleopPeriodic() {
    update_sensors();
}

void robot_class::DisabledContinuous() {
    //do nothing
}

void robot_class::AutonomousContinuous() {
    //do nothing
}

void robot_class::TeleopContinuous() {
    if(global_state.get_state() == STATE_DRIVING) {
        if (left_joystick.GetRawButton(1)) {
            //arcade drive
            drive.ArcadeDrive(left_joystick); //arcade drive on left joystick
        }
        else {
            //tank drive
            float left = left_joystick.GetY();
            float right = right_joystick.GetY();
            //explicitly state drive power is based on Y axis of that side joy
            drive.TankDrive(left, right);
        }
        if (right_joystick.GetRawButton(11) || left_joystick.GetRawButton(11)) {
            servo_shifter.set(shifter::HIGH);
            // set servo to high gear
        }
        else if (left_joystick.GetRawButton(10) || right_joystick.GetRawButton(10)) {
            servo_shifter.set(shifter::LOW);
            //Sets servo to low gear
        }
        if(left_joystick.GetRawButton(3)) {
            global_state.set_state(STATE_SHOOTING);
        }
    }
    else if(global_state.get_state() == STATE_SHOOTING) {
        // disable motor safety check to stop wasting netconsole space
        drive.SetSafetyEnabled(false);
        vision_processing::update();
        vector<double> target_degrees = vision_processing::get_degrees();
        vector<double> target_distances = vision_processing::get_distance();
        if(target_degrees.size() >= 1) {
            printf("Angle (degrees) of camera: %f\n", target_degrees[0]);
        }
        else {
            printf("No target detected\n");
        }
        if(target_distances.size() >= 1) {
            printf("Distance of target:       %f\n", target_distances[0]);
        }
        if(!left_joystick.GetRawButton(3)) {
            global_state.set_state(STATE_DRIVING);
            drive.SetSafetyEnabled(true);
        }
    }
    //TEMPORARY: GUNNER LAUNCHER WHEEL CONTROLS
    if (gunner_joystick.GetRawButton(7)) {
        left_launcher_jag.Set(1.0);
        right_launcher_jag.Set(1.0);
    }
    else {
        left_launcher_jag.Set(0.0);
        right_launcher_jag.Set(0.0);
    }
    if(global_state.get_state() != STATE_SHOOTING) {
        //MANUAL ROLLER CONTROL
        if (gunner_joystick.GetRawButton(11)) {
            //rollers up
            rollers.set_direction(roller_t::UP);
        }
        else if (gunner_joystick.GetRawButton(10)) {
            //rollers down
            rollers.set_direction(roller_t::DOWN);
        }
        else {
            //auto belts
        }
        //
        Wait(0.005); //let the CPU rest a little - 5 ms isn't too long
    }
}

void robot_class::update_sensors() {
    //run functions in update registry
    registry().update();
}

//the following macro tells the library that we want to generate code
//for our class robot_class
START_ROBOT_CLASS(robot_class);
<commit_msg>Now prints number of targets detected. Gives gunner joystick control over turret (driving state only)<commit_after>/* main.cpp
 *
 * Copyright (c) 2011, 2012 Chantilly Robotics <chantilly612@gmail.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * Implement robot_class to provide functionality for robot.
 */

#include "612.h"
#include "main.h"
#include "ports.h"
#include "update.h"
#include "vision/vision_processing.h"
#include "state_tracker.h"
#include "visionalg.h"
#include "shifter.h"

//constructor - initialize drive
robot_class::robot_class() {
    //do nothing
    GetWatchdog().SetEnabled(false); //we don't want Watchdog
}

void robot_class::RobotInit() {
    //Run-Time INIT
    //set necessary inversions
    drive.SetInvertedMotor(left_front_motor.type,  left_front_motor.reverse);
    drive.SetInvertedMotor(left_rear_motor.type,   left_rear_motor.reverse);
    drive.SetInvertedMotor(right_front_motor.type, right_front_motor.reverse);
    drive.SetInvertedMotor(right_rear_motor.type,  right_rear_motor.reverse);
    global_state.set_state(STATE_DRIVING);
    init_camera();
}

void robot_class::DisabledInit() {
    //do nothing
}

void robot_class::AutonomousInit() {
    //do nothing
}

void robot_class::TeleopInit() {
    //do nothing
}

void robot_class::DisabledPeriodic() {
    //do nothing
}

void robot_class::AutonomousPeriodic() {
    update_sensors();
}

void robot_class::TeleopPeriodic() {
    update_sensors();
}

void robot_class::DisabledContinuous() {
    //do nothing
}

void robot_class::AutonomousContinuous() {
    //do nothing
}

void robot_class::TeleopContinuous() {
    if(global_state.get_state() == STATE_DRIVING) {
        //Turret rotation controlled by gunner joystick during drive state only. Must press button 1
        if(gunner_joystick.GetRawButton(1){
            turret_rotation_jag.Set(gunner_joystick.GetX());
        if (left_joystick.GetRawButton(1)) {
            //arcade drive
            drive.ArcadeDrive(left_joystick); //arcade drive on left joystick
        }
        else {
            //tank drive
            float left = left_joystick.GetY();
            float right = right_joystick.GetY();
            //explicitly state drive power is based on Y axis of that side joy
            drive.TankDrive(left, right);
        }
        if (right_joystick.GetRawButton(11) || left_joystick.GetRawButton(11)) {
            servo_shifter.set(shifter::HIGH);
            // set servo to high gear
        }
        else if (left_joystick.GetRawButton(10) || right_joystick.GetRawButton(10)) {
            servo_shifter.set(shifter::LOW);
            //Sets servo to low gear
        }
        if(left_joystick.GetRawButton(3)) {
            global_state.set_state(STATE_SHOOTING);
        }
    }
    else if(global_state.get_state() == STATE_SHOOTING) {
        // disable motor safety check to stop wasting netconsole space
        drive.SetSafetyEnabled(false);
        vision_processing::update();
        vector<double> target_degrees = vision_processing::get_degrees();
        vector<double> target_distances = vision_processing::get_distance();
        printf("Number of targets detected: %d\n", target_degrees.size());
        if(target_degrees.size() >= 1) {
            printf("Angle (degrees) of camera: %f\n", target_degrees[0]);
        }
        else {
            printf("No target detected\n");
        }
        if(target_distances.size() >= 1) {
            printf("Distance of target:       %f\n", target_distances[0]);
        }
        if(!left_joystick.GetRawButton(3)) {
            global_state.set_state(STATE_DRIVING);
            drive.SetSafetyEnabled(true);
        }
    }
    //TEMPORARY: GUNNER LAUNCHER WHEEL CONTROLS
    if (gunner_joystick.GetRawButton(7)) {
        left_launcher_jag.Set(1.0);
        right_launcher_jag.Set(1.0);
    }
    else {
        left_launcher_jag.Set(0.0);
        right_launcher_jag.Set(0.0);
    }
    if(global_state.get_state() != STATE_SHOOTING) {
        //MANUAL ROLLER CONTROL
        if (gunner_joystick.GetRawButton(11)) {
            //rollers up
            rollers.set_direction(roller_t::UP);
        }
        else if (gunner_joystick.GetRawButton(10)) {
            //rollers down
            rollers.set_direction(roller_t::DOWN);
        }
        else {
            //auto belts
        }
        //
        Wait(0.005); //let the CPU rest a little - 5 ms isn't too long
    }
}

void robot_class::update_sensors() {
    //run functions in update registry
    registry().update();
}

//the following macro tells the library that we want to generate code
//for our class robot_class
START_ROBOT_CLASS(robot_class);
<|endoftext|>


<commit_before>#include <iostream>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/stat.h>
#include <vector>

using namespace std;
int info_RF(char* dirName);
int info_D(char* dirName);
int info_CS(char* dirName);
int info_BS(char* dirName);
int info_S(char* dirName);
int info_SL(char* dirName);
int info_R(char* dirName);
int info_W(char* dirName);
int info_X(char* dirName);
int main()
{
	char *word[50];
    char buf[500] = "\0";
	while(word[0] != "exit"){
    int i, k=0;
	cin.getline(buf, 500);

    word[k] = strtok(buf, " ");

    while (word[k++] != NULL) {
        word[k] = strtok(NULL, " ");
    }
 	char checking_first = *word[0];
/*	pid_t pid;
	pid = fork();
	if(pid == 0)
	{
		if(k<=3  && word[0] != "exit"){
			string cmd("./src./single_command.sh ");
			cmd += word[0];
			cmd += " ";
			cmd += word[1];
			system(cmd.c_str());
			perror("invalid input");
		}								//run for single_command.sh
		else if(checking_first == '#'){
			string cmd("./src./comment_command.sh ");
			system(cmd.c_str());		//run for comment_command.sh
			perror("invalid input");
		}
		else if(word[0] == "exit"){
			string cmd("./src./exit.sh ");
			cmd += word[0];
			system(cmd.c_str());
			perror("invalid input");
		}								//run for exit.sh
		else	{
			int initial = 0;
			int hold_number = 0;
			int hold_other_number = 0;
			int ret[20];
			int v[20];

			while(initial <= k){
			string cmd("./src./multi_command.sh ");
				if(word[initial] == "|"|| word[initial] == "&" || word[initial][strlen(word[initial]-1)] == ';'){
					if(hold_number < initial){
						while(hold_number <initial){
						cmd += word[hold_number];
						hold_number++;
						}
						ret[hold_other_number] = system(cmd.c_str());
						v[hold_other_number] = WEXITSTATUS(ret[hold_other_number]);
					}
				}
				initial++;
			}
		}
		int status = 0;
		waitpid(pid, status, WNOHANG);
		if(status != 1){
			perror("fail to close child process");
		}

	}
	else if(pid == -1){
		cout<<"fork error!"<<endl;
	}
	else{
		cout<<"Should not be in parents"<<endl;
	}
*/
//top of part is for homework 01 which does not working so i made it as comment
		if(checking_first == '[' || word[0] =="test"){
			checking_first = *word[1];
			if(checking_first == '-'){
				//All functions need that file exist
					vector<char *> dirlist;
					dirlist.push_back(word[2]);
					if(word[1] == "-a" || word[1] == "-e"){ //True if <file> exist
						cout<<"file exist"<<endl;
					}
					else if(word[1] == "-f"){//True if <file> exist and is regular file
						if(info_RF(dirlist.front()) == 1){
						cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-d"){//True if <file> exist and is a directory
						if(info_D(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-c"){//True if <file> exist and is character special file
						if(info_CS(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-b"){//True if <file> exist and is block special file
						if(info_BS(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-p"){//True if <file> exist and is named pipe
						// need to
					}
					else if(word[1] == "-S"){//True if <file> exist and is socket file
						if(info_S(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-L" || word[1] =="-h"){//True if <file> exist and is symbolic link
						if(info_SL(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-g"){//True if <file> exist and is sgid bit set
						// need to
					}
					else if(word[1] == "-u"){//True if <file> exist and is suid bit set
						// need to
					}
					else if(word[1] == "-r"){//True if <file> exist and is readable
						if(info_R(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-w"){//True if <file> exist and is writeable
						if(info_W(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-x"){//True if <file> exist and is excutable
						if(info_X(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-s"){//True if <file> exist and size of file is bigger than 0 (not empty)
						//need to
					}
					else if(word[1] == "-t"){//True if file descriptor <fd> is open and refers to a terminal
						//need to
					}
			}
			checking_first = *word[2];
			if(checking_first == '-'){ // there is two files to compare
				if(word[2] == "-nt"){// True if <file1> is newer than <file2>

				}
				else if(word[2] == "-ot"){// True if <file1> is older than <file2>

				}
				else if(word[2] == "-ef"){// True if <file1> and <file2> refer to the same device and inode numbers.

				}
			}
		}
	}
	return 0;
}
int info_RF(char* dirName){//regular file
	struct stat sb;
	if((sb.st_mode & S_IFREG)){
		return 1;
	}
	return 0;
}
int info_D(char* dirName){
	struct stat sb;
	if((sb.st_mode & S_IFDIR)){
		return 1;
	}
	return 0;
}
int info_CS(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFCHR)){
		return 1;
	}
	return 0;
}
int info_BS(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFBLK)){
		return 1;
	}
	return 0;
}
int info_S(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFSOCK)){
		return 1;
	}
	return 0;
}
int info_SL(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFLNK)){
		return 1;
	}
	return 0;
}
 int info_R(char * dirName){//read
	 struct stat sb;
	 if((sb.st_mode & S_IRUSR)){
		return 1;
	 }
	 return 0;
 }
int info_W(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IWUSR)){
		return 1;
	}
	return 0;
}
int info_X(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IXUSR)){
		return 1;
	}
	return 0;
}<commit_msg>201511201808<commit_after>#include <iostream>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/stat.h>
#include <vector>

using namespace std;
int info_RF(char* dirName);
int info_D(char* dirName);
int info_CS(char* dirName);
int info_BS(char* dirName);
int info_S(char* dirName);
int info_SL(char* dirName);
int info_R(char* dirName);
int info_W(char* dirName);
int info_X(char* dirName);
int main()
{
	char *word[50];
    char buf[500] = "\0";
    int i, k=0;
	cin.getline(buf, 500);

    word[k] = strtok(buf, " ");

    while (word[k++] != NULL) {
        word[k] = strtok(NULL, " ");
    }
 	char checking_first = *word[0];
/*	pid_t pid;
	pid = fork();
	if(pid == 0)
	{
		if(k<=3  && word[0] != "exit"){
			string cmd("./src./single_command.sh ");
			cmd += word[0];
			cmd += " ";
			cmd += word[1];
			system(cmd.c_str());
			perror("invalid input");
		}								//run for single_command.sh
		else if(checking_first == '#'){
			string cmd("./src./comment_command.sh ");
			system(cmd.c_str());		//run for comment_command.sh
			perror("invalid input");
		}
		else if(word[0] == "exit"){
			string cmd("./src./exit.sh ");
			cmd += word[0];
			system(cmd.c_str());
			perror("invalid input");
		}								//run for exit.sh
		else	{
			int initial = 0;
			int hold_number = 0;
			int hold_other_number = 0;
			int ret[20];
			int v[20];

			while(initial <= k){
			string cmd("./src./multi_command.sh ");
				if(word[initial] == "|"|| word[initial] == "&" || word[initial][strlen(word[initial]-1)] == ';'){
					if(hold_number < initial){
						while(hold_number <initial){
						cmd += word[hold_number];
						hold_number++;
						}
						ret[hold_other_number] = system(cmd.c_str());
						v[hold_other_number] = WEXITSTATUS(ret[hold_other_number]);
					}
				}
				initial++;
			}
		}
		int status = 0;
		waitpid(pid, status, WNOHANG);
		if(status != 1){
			perror("fail to close child process");
		}

	}
	else if(pid == -1){
		cout<<"fork error!"<<endl;
	}
	else{
		cout<<"Should not be in parents"<<endl;
	}
*/
//top of part is for homework 01 which does not working so i made it as comment
		if(checking_first == '[' || word[0] =="test"){
			checking_first = *word[1];
			if(checking_first == '-'){
				//All functions need that file exist
					vector<char *> dirlist;
					dirlist.push_back(word[2]);
					if(word[1] == "-a" || word[1] == "-e"){ //True if <file> exist
						cout<<"file exist"<<endl;
					}
					else if(word[1] == "-f"){//True if <file> exist and is regular file
						if(info_RF(dirlist.front()) == 1){
						cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-d"){//True if <file> exist and is a directory
						if(info_D(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-c"){//True if <file> exist and is character special file
						if(info_CS(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-b"){//True if <file> exist and is block special file
						if(info_BS(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-p"){//True if <file> exist and is named pipe
						// need to
					}
					else if(word[1] == "-S"){//True if <file> exist and is socket file
						if(info_S(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-L" || word[1] =="-h"){//True if <file> exist and is symbolic link
						if(info_SL(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-g"){//True if <file> exist and is sgid bit set
						// need to
					}
					else if(word[1] == "-u"){//True if <file> exist and is suid bit set
						// need to
					}
					else if(word[1] == "-r"){//True if <file> exist and is readable
						if(info_R(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-w"){//True if <file> exist and is writeable
						if(info_W(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-x"){//True if <file> exist and is excutable
						if(info_X(dirlist.front()) == 1){
							cout<<"file exist"<<endl;
						}
						else
							cout<<"file does not exist"<<endl;
					}
					else if(word[1] == "-s"){//True if <file> exist and size of file is bigger than 0 (not empty)
						//need to
					}
					else if(word[1] == "-t"){//True if file descriptor <fd> is open and refers to a terminal
						//need to
					}
			}
			checking_first = *word[2];
			if(checking_first == '-'){ // there is two files to compare
				if(word[2] == "-nt"){// True if <file1> is newer than <file2>

				}
				else if(word[2] == "-ot"){// True if <file1> is older than <file2>

				}
				else if(word[2] == "-ef"){// True if <file1> and <file2> refer to the same device and inode numbers.

				}
			}
		}
	return 0;
}
int info_RF(char* dirName){//regular file
	struct stat sb;
	if((sb.st_mode & S_IFREG)){
		return 1;
	}
	return 0;
}
int info_D(char* dirName){
	struct stat sb;
	if((sb.st_mode & S_IFDIR)){
		return 1;
	}
	return 0;
}
int info_CS(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFCHR)){
		return 1;
	}
	return 0;
}
int info_BS(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFBLK)){
		return 1;
	}
	return 0;
}
int info_S(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFSOCK)){
		return 1;
	}
	return 0;
}
int info_SL(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IFLNK)){
		return 1;
	}
	return 0;
}
 int info_R(char * dirName){//read
	 struct stat sb;
	 if((sb.st_mode & S_IRUSR)){
		return 1;
	 }
	 return 0;
 }
int info_W(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IWUSR)){
		return 1;
	}
	return 0;
}
int info_X(char * dirName){
	struct stat sb;
	if((sb.st_mode & S_IXUSR)){
		return 1;
	}
	return 0;
}<|endoftext|>


<commit_before>//
//  main.cpp
//  make_spiffs
//
//  Created by Ivan Grokhotkov on 13/05/15.
//  Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
//
#define TCLAP_SETBASE_ZERO 1

#include <iostream>
#include "spiffs/spiffs.h"
#include <vector>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <string>
#include <memory>
#include <cstdlib>
#include "tclap/CmdLine.h"
#include "tclap/UnlabeledValueArg.h"

#define LOG_PAGE_SIZE       256

static std::vector<uint8_t> s_flashmem;
static std::string s_dirName;
static std::string s_imageName;
static int s_imageSize;

enum Action { ACTION_NONE, ACTION_PACK, ACTION_LIST };
static Action s_action = ACTION_NONE;

static spiffs _filesystemStorageHandle;
static u8_t spiffs_work_buf[LOG_PAGE_SIZE*2];
static u8_t spiffs_fds[32*4];
static u8_t spiffs_cache[(LOG_PAGE_SIZE+32)*4];

static s32_t api_spiffs_read(u32_t addr, u32_t size, u8_t *dst)
{
    memcpy(dst, &s_flashmem[0] + addr, size);
    return SPIFFS_OK;
}

static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src)
{
    memcpy(&s_flashmem[0] + addr, src, size);
    return SPIFFS_OK;
}

static s32_t api_spiffs_erase(u32_t addr, u32_t size)
{
    memset(&s_flashmem[0] + addr, 0xff, size);
    return SPIFFS_OK;
}

spiffs_config spiffs_get_storage_config()
{
    spiffs_config cfg = {0};

    cfg.phys_addr = 0x0000;
    cfg.phys_size = (u32_t) s_flashmem.size();

    const int flash_sector_size = 4096;
    const int log_page_size = 256;

    cfg.phys_erase_block = flash_sector_size; // according to datasheet
    cfg.log_block_size = flash_sector_size * 2; // Important to make large
    cfg.log_page_size = log_page_size; // as we said
    return cfg;
}

void check_callback(spiffs_check_type type, spiffs_check_report report,
                                   u32_t arg1, u32_t arg2)
{
}

void spiffs_mount(bool init)
{
    spiffs_config cfg = spiffs_get_storage_config();

//    debugf("fs.start:%x, size:%d Kb\n", cfg.phys_addr, cfg.phys_size / 1024);

    cfg.hal_read_f = api_spiffs_read;
    cfg.hal_write_f = api_spiffs_write;
    cfg.hal_erase_f = api_spiffs_erase;

    int res = SPIFFS_mount(&_filesystemStorageHandle,
                           &cfg,
                           spiffs_work_buf,
                           spiffs_fds,
                           sizeof(spiffs_fds),
                           spiffs_cache,
                           sizeof(spiffs_cache),
                           NULL);

//    debugf("mount res: %d\n", res);
    if (init) {
        spiffs_file fd = SPIFFS_open(&_filesystemStorageHandle, "tmp", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
        uint8_t tmp = 0xff;
        SPIFFS_write(&_filesystemStorageHandle, fd, &tmp, 1);
        SPIFFS_fremove(&_filesystemStorageHandle, fd);
        SPIFFS_close(&_filesystemStorageHandle, fd);
    } else {
        _filesystemStorageHandle.check_cb_f = &check_callback;
        //SPIFFS_check(&_filesystemStorageHandle);
    }
}

void spiffs_unmount()
{
    uint32_t total, used;
    SPIFFS_info(&_filesystemStorageHandle, &total, &used);
    SPIFFS_vis(&_filesystemStorageHandle);
    std::cerr << "total: " << total << ", used: " << used << std::endl;
    SPIFFS_unmount(&_filesystemStorageHandle);
}

int add_file(char* name, const char* path) {
    const size_t write_size = 512;
    uint8_t write_block[write_size];

    FILE* src = fopen(path, "rb");
    if (!src) {
        std::cerr << "error: failed to open " << path << " for reading" << std::endl;
        return 1;
    }

    spiffs_file dst = SPIFFS_open(&_filesystemStorageHandle, name, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);

    fseek(src, 0, SEEK_END);
    size_t size = ftell(src);
    fseek(src, 0, SEEK_SET);

    size_t left = size;
    while (left > 0)
    {
        size_t will_write = std::min(left, write_size);
        if (will_write != fread(write_block, 1, will_write, src)) {
            std::cerr << "error: failed to read from file";
            fclose(src);
            SPIFFS_close(&_filesystemStorageHandle, dst);
            return 1;
        }
        SPIFFS_write(&_filesystemStorageHandle, dst, write_block, write_size);
        left -= will_write;
    }

    SPIFFS_close(&_filesystemStorageHandle, dst);
    fclose(src);
    return 0;
}

int add_files(const char* dirname)
{
    DIR *dir;
    struct dirent *ent;
    if ((dir = opendir (dirname)) != NULL) {
        while ((ent = readdir (dir)) != NULL) {
            if (ent->d_name[0] == '.')
                continue;
            std::string fullpath = dirname;
            fullpath += '/';
            fullpath += ent->d_name;
            struct stat path_stat;
            stat (fullpath.c_str(), &path_stat);
            if (!S_ISREG(path_stat.st_mode)) {
                std::cerr << "skipping " << ent->d_name << std::endl;
                continue;
            }

            std::cerr << "adding " << ent->d_name << std::endl;
            if (add_file(ent->d_name, fullpath.c_str()) != 0) {
                break;
            }
        }
        closedir (dir);
    } else {
        std::cerr << "warning: can't read source directory" << std::endl;
        return 1;
    }
    return 0;
}

void listFiles() {
    spiffs_DIR dir;
    spiffs_dirent ent;

    spiffs_DIR* res = SPIFFS_opendir(&_filesystemStorageHandle, 0, &dir);
    spiffs_dirent* it;
    while (true) {
        it = SPIFFS_readdir(&dir, &ent);
        if (!it)
            break;

        std::cout << it->size << '\t' << it->name << std::endl;
    }
    SPIFFS_closedir(&dir);
}

int actionPack() {
    s_flashmem.resize(s_imageSize, 0xff);

    FILE* fdres = fopen(s_imageName.c_str(), "wb");
    if (!fdres) {
        std::cerr << "error: failed to open image file" << std::endl;
        return 1;
    }

    spiffs_mount(true);
    add_files(s_dirName.c_str());
    spiffs_unmount();

    fwrite(&s_flashmem[0], 4, s_flashmem.size()/4, fdres);

    fclose(fdres);

    return 0;
}

int actionList() {
    s_flashmem.resize(s_imageSize, 0xff);

    FILE* fdsrc = fopen(s_imageName.c_str(), "rb");
    if (!fdsrc) {
        std::cerr << "error: failed to open image file" << std::endl;
        return 1;
    }

    fread(&s_flashmem[0], 4, s_flashmem.size()/4, fdsrc);
    fclose(fdsrc);

    spiffs_mount(false);
    listFiles();
    spiffs_unmount();

    return 0;
}

int processArgs(int argc, const char** argv) {

    TCLAP::CmdLine cmd("", ' ', "0.1");
    TCLAP::ValueArg<std::string> packArg( "c", "create", "create spiffs image from a directory", true, "", "pack_dir");
    TCLAP::SwitchArg listArg( "l", "list", "list spiffs image to a directory", false);
    TCLAP::UnlabeledValueArg<std::string> outNameArg( "image_file", "spiffs image file", true, "", "image_file"  );
    TCLAP::ValueArg<int> sizeArg( "s", "fs_size", "fs image size, in bytes", false, 0xb000, "number" );

    cmd.add( sizeArg );
    cmd.xorAdd( packArg, listArg );
    cmd.add( outNameArg );
    cmd.parse( argc, argv );

    if (packArg.isSet()) {
        s_dirName = packArg.getValue();
        s_action = ACTION_PACK;
    }
    else if (listArg.isSet()) {
        s_action = ACTION_LIST;
    }

    s_imageName = outNameArg.getValue();
    s_imageSize = sizeArg.getValue();

    return 0;
}

int main(int argc, const char * argv[]) {

    try {
        processArgs(argc, argv);
    }
    catch(...) {
        std::cerr << "Invalid arguments" << std::endl;
        return 1;
    }

    switch (s_action) {
        case ACTION_PACK: return actionPack();
        case ACTION_LIST: return actionList();
        default: ;
    }

    return 1;
}
<commit_msg>Add page and block size arguments<commit_after>//
//  main.cpp
//  make_spiffs
//
//  Created by Ivan Grokhotkov on 13/05/15.
//  Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
//
#define TCLAP_SETBASE_ZERO 1

#include <iostream>
#include "spiffs/spiffs.h"
#include <vector>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <string>
#include <memory>
#include <cstdlib>
#include "tclap/CmdLine.h"
#include "tclap/UnlabeledValueArg.h"

static std::vector<uint8_t> s_flashmem;

static std::string s_dirName;
static std::string s_imageName;
static int s_imageSize;
static int s_pageSize;
static int s_blockSize;

enum Action { ACTION_NONE, ACTION_PACK, ACTION_LIST, ACTION_VISUALIZE };
static Action s_action = ACTION_NONE;

static spiffs s_fs;

static std::vector<uint8_t> s_spiffsWorkBuf;
static std::vector<uint8_t> s_spiffsFds;
static std::vector<uint8_t> s_spiffsCache;

static s32_t api_spiffs_read(u32_t addr, u32_t size, u8_t *dst)
{
    memcpy(dst, &s_flashmem[0] + addr, size);
    return SPIFFS_OK;
}

static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src)
{
    memcpy(&s_flashmem[0] + addr, src, size);
    return SPIFFS_OK;
}

static s32_t api_spiffs_erase(u32_t addr, u32_t size)
{
    memset(&s_flashmem[0] + addr, 0xff, size);
    return SPIFFS_OK;
}

void checkCallback(spiffs_check_type type, spiffs_check_report report,
                                   u32_t arg1, u32_t arg2)
{
}

void spiffsMount(bool init)
{
    spiffs_config cfg = {0};

    cfg.phys_addr = 0x0000;
    cfg.phys_size = (u32_t) s_flashmem.size();

    cfg.phys_erase_block = s_blockSize;
    cfg.log_block_size = s_blockSize;
    cfg.log_page_size = s_pageSize;

    cfg.hal_read_f = api_spiffs_read;
    cfg.hal_write_f = api_spiffs_write;
    cfg.hal_erase_f = api_spiffs_erase;

    const int maxOpenFiles = 4;
    s_spiffsWorkBuf.resize(s_pageSize * 2);
    s_spiffsFds.resize(32 * maxOpenFiles);
    s_spiffsCache.resize((32 + s_pageSize) * maxOpenFiles);

    int res = SPIFFS_mount(&s_fs,
                           &cfg,
                           &s_spiffsWorkBuf[0],
                           &s_spiffsFds[0],
                           s_spiffsFds.size(),
                           &s_spiffsCache[0],
                           s_spiffsCache.size(),
                           NULL);

//    debugf("mount res: %d\n", res);
    if (init) {
        spiffs_file fd = SPIFFS_open(&s_fs, "tmp", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
        uint8_t tmp = 0xff;
        SPIFFS_write(&s_fs, fd, &tmp, 1);
        SPIFFS_fremove(&s_fs, fd);
        SPIFFS_close(&s_fs, fd);
    } else {
        s_fs.check_cb_f = &checkCallback;
        //SPIFFS_check(&s_fs);
    }
}

void spiffsUnmount()
{
    uint32_t total, used;
    SPIFFS_info(&s_fs, &total, &used);
    std::cerr << "total: " << total << ", used: " << used << std::endl;
    SPIFFS_unmount(&s_fs);
}

int addFile(char* name, const char* path) {
    const size_t write_size = 512;
    uint8_t write_block[write_size];

    FILE* src = fopen(path, "rb");
    if (!src) {
        std::cerr << "error: failed to open " << path << " for reading" << std::endl;
        return 1;
    }

    spiffs_file dst = SPIFFS_open(&s_fs, name, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);

    fseek(src, 0, SEEK_END);
    size_t size = ftell(src);
    fseek(src, 0, SEEK_SET);

    size_t left = size;
    while (left > 0)
    {
        size_t will_write = std::min(left, write_size);
        if (will_write != fread(write_block, 1, will_write, src)) {
            fclose(src);
            SPIFFS_close(&s_fs, dst);
            return 1;
        }
        int res = SPIFFS_write(&s_fs, dst, write_block, write_size);
        if (res < 0) {
            fclose(src);
            SPIFFS_close(&s_fs, dst);
            return 1;
        }
        left -= will_write;
    }

    SPIFFS_close(&s_fs, dst);
    fclose(src);
    return 0;
}

int addFiles(const char* dirname)
{
    DIR *dir;
    struct dirent *ent;
    bool error = false;
    if ((dir = opendir (dirname)) != NULL) {
        while ((ent = readdir (dir)) != NULL) {
            if (ent->d_name[0] == '.')
                continue;
            std::string fullpath = dirname;
            fullpath += '/';
            fullpath += ent->d_name;
            struct stat path_stat;
            stat (fullpath.c_str(), &path_stat);
            if (!S_ISREG(path_stat.st_mode)) {
                std::cerr << "skipping " << ent->d_name << std::endl;
                continue;
            }

            std::cerr << "adding " << ent->d_name;
            if (addFile(ent->d_name, fullpath.c_str()) != 0) {
                std::cerr << " - error!" << std::endl;
                error = true;
                break;
            }
            std::cerr << std::endl;
        }
        closedir (dir);
    } else {
        std::cerr << "warning: can't read source directory" << std::endl;
        return 1;
    }
    return (error) ? 1 : 0;
}

void listFiles() {
    spiffs_DIR dir;
    spiffs_dirent ent;

    spiffs_DIR* res = SPIFFS_opendir(&s_fs, 0, &dir);
    spiffs_dirent* it;
    while (true) {
        it = SPIFFS_readdir(&dir, &ent);
        if (!it)
            break;

        std::cout << it->size << '\t' << it->name << std::endl;
    }
    SPIFFS_closedir(&dir);
}

int actionPack() {
    s_flashmem.resize(s_imageSize, 0xff);

    FILE* fdres = fopen(s_imageName.c_str(), "wb");
    if (!fdres) {
        std::cerr << "error: failed to open image file" << std::endl;
        return 1;
    }

    spiffsMount(true);
    int result = addFiles(s_dirName.c_str());
    spiffsUnmount();

    fwrite(&s_flashmem[0], 4, s_flashmem.size()/4, fdres);
    fclose(fdres);

    return result;
}

int actionList() {
    s_flashmem.resize(s_imageSize, 0xff);

    FILE* fdsrc = fopen(s_imageName.c_str(), "rb");
    if (!fdsrc) {
        std::cerr << "error: failed to open image file" << std::endl;
        return 1;
    }

    fread(&s_flashmem[0], 4, s_flashmem.size()/4, fdsrc);
    fclose(fdsrc);

    spiffsMount(false);
    listFiles();
    spiffsUnmount();

    return 0;
}

int actionVisualize() {
    s_flashmem.resize(s_imageSize, 0xff);

    FILE* fdsrc = fopen(s_imageName.c_str(), "rb");
    if (!fdsrc) {
        std::cerr << "error: failed to open image file" << std::endl;
        return 1;
    }

    fread(&s_flashmem[0], 4, s_flashmem.size()/4, fdsrc);
    fclose(fdsrc);

    spiffsMount(false);
    SPIFFS_vis(&s_fs);
    spiffsUnmount();

    return 0;
}

void processArgs(int argc, const char** argv) {

    TCLAP::CmdLine cmd("", ' ', "0.1");
    TCLAP::ValueArg<std::string> packArg( "c", "create", "create spiffs image from a directory", true, "", "pack_dir");
    TCLAP::SwitchArg listArg( "l", "list", "list files in spiffs image", false);
    TCLAP::SwitchArg visualizeArg( "i", "visualize", "visualize spiffs image", false);
    TCLAP::UnlabeledValueArg<std::string> outNameArg( "image_file", "spiffs image file", true, "", "image_file"  );
    TCLAP::ValueArg<int> imageSizeArg( "s", "size", "fs image size, in bytes", false, 0x10000, "number" );
    TCLAP::ValueArg<int> pageSizeArg( "p", "page", "fs page size, in bytes", false, 256, "number" );
    TCLAP::ValueArg<int> blockSizeArg( "b", "block", "fs block size, in bytes", false, 4096, "number" );

    cmd.add( imageSizeArg );
    cmd.add( pageSizeArg );
    cmd.add( blockSizeArg );
    std::vector<TCLAP::Arg*> args = {&packArg, &listArg, &visualizeArg};
    cmd.xorAdd( args );
    cmd.add( outNameArg );
    cmd.parse( argc, argv );

    if (packArg.isSet()) {
        s_dirName = packArg.getValue();
        s_action = ACTION_PACK;
    }
    else if (listArg.isSet()) {
        s_action = ACTION_LIST;
    }
    else if (visualizeArg.isSet()) {
        s_action = ACTION_VISUALIZE;
    }

    s_imageName = outNameArg.getValue();
    s_imageSize = imageSizeArg.getValue();
    s_pageSize  = pageSizeArg.getValue();
    s_blockSize = blockSizeArg.getValue();
}

int main(int argc, const char * argv[]) {

    try {
        processArgs(argc, argv);
    }
    catch(...) {
        std::cerr << "Invalid arguments" << std::endl;
        return 1;
    }

    switch (s_action) {
        case ACTION_PACK: return actionPack();
        case ACTION_LIST: return actionList();
        case ACTION_VISUALIZE: return actionVisualize();
        default: ;
    }

    return 1;
}
<|endoftext|>


<commit_before>#include <iostream>

//Returns the value of x multiplied by 2, except for 42, which is multiplied by one
int do_magic(const int x)
{
  if (x == 42)
  {
    return 42;
  }
  return x * 2;
}

int main()
{
  std::cout << do_magic(2) << '\n';
  //Forgot to test do_magic(42)
}
<commit_msg>hgjdthghfd<commit_after>#include <iostream>

//Returns the value of x multiplied by 2, except for 42, which is multiplied by one
int do_magic(const int x)
{
  if (x ==  42)
  {
    return 42;
  }
  return x * 2;
}

int main()
{
  std::cout << do_magic(2) << '\n';
  //Forgot to test do_magic(42)
}
<|endoftext|>


<commit_before>/*******************************************************************************

         Yuri V. Krugloff. 2013-2015. http://www.tver-soft.org

    This is free and unencumbered software released into the public domain.

    Anyone is free to copy, modify, publish, use, compile, sell, or
    distribute this software, either in source code form or as a compiled
    binary, for any purpose, commercial or non-commercial, and by any
    means.

    In jurisdictions that recognize copyright laws, the author or authors
    of this software dedicate any and all copyright interest in the
    software to the public domain. We make this dedication for the benefit
    of the public at large and to the detriment of our heirs and
    successors. We intend this dedication to be an overt act of
    relinquishment in perpetuity of all present and future rights to this
    software under copyright law.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.

    For more information, please refer to <http://unlicense.org/>

*******************************************************************************/

#include <string>

#include "Logger.hpp"
#include "Functions.hpp"
#include "CmdLineOptions.hpp"
#include "CmdLineParser.hpp"
#include "CmdLineChecker.hpp"
#include "QtBinPatcher.hpp"

//------------------------------------------------------------------------------

void howToUseMessage()
{
    printf(
        //.......|.........|.........|.........|.........|.........|.........|.........|
        "\n"
        "Usage: qtbinpatcher [options]\n"
        "Options:\n"
        "  --version      Show program version and exit.\n"
        "  --help         Show this help and exit.\n"
        "  --verbose      Print extended runtime information.\n"
        "  --logfile=name Duplicate messages into logfile with name \"name\".\n"
        "  --backup       Create and save backup for files that will be patched.\n"
        "                 This option incompatible with option \"--nobackup\".\n"
        "  --nobackup     Don't create backup files in patch process.\n"
        "                 This option incompatible with option \"--backup\".\n"
        "                 WARNING: If an error occurs during patching, Qt library can be\n"
        "                          permanently damaged!\n"
        "  --force        Force patching (without old path actuality checking).\n"
        "  --qt-dir=path  Directory, where Qt or qmake is now located (may be relative).\n"
        "                 If not specified, will be used current directory. Patcher will\n"
        "                 search qmake first in directory \"path\", and then in its subdir\n"
        "                 \"bin\". Patcher is NEVER looking qmake in other directories.\n"
        "                 WARNING: If nonstandard directory for binary files is used\n"
        "                          (not \"bin\"), select directory where located qmake.\n"
        "  --new-dir=path Directory where Qt will be located (may be relative).\n"
        "                 If not specified, will be used the current location.\n"
        "  --old-dir=path Directory where Qt was located. This option can be specified\n"
        "                 more then once. This path will be replaced only in text files.\n"
        "  --dry-run      Output the procedure only, do not really process the jobs.\n"
        "\n"
        "Remark.\n"
        "  If missing \"--backup\" and \"--nobackup\" options, the backup files will be\n"
        "  created before patching and deleted after successful completion of the\n"
        "  patching or restored if an error occurs.\n"
        "\n"
        //.......|.........|.........|.........|.........|.........|.........|.........|
    );
}

//------------------------------------------------------------------------------

int main(int argc, const char* argv[])
{
    LOG("\n"
        "QtBinPatcher v2.3.0Beta. Tool for patching paths in Qt binaries.\n"
        "Yuri V. Krugloff, 2013-2015. http://www.tver-soft.org\n"
        "Frank Su, 2016. http://mogara.org\n"
        "This is free software released into the public domain.\n"
#ifdef QTCROSS
        "This binary is built for cross compiled Qt.\n"
#endif
        "\n"
    );

    TCmdLineParser CmdLineParser(argc, argv);
    if (CmdLineParser.hasError()) {
        LOG("%s\n", CmdLineParser.errorString().c_str());
        howToUseMessage();
        return -1;
    }
    const TStringListMap& argsMap = CmdLineParser.argsMap();

    std::string ErrorString = TCmdLineChecker::check(argsMap);
    if (!ErrorString.empty()) {
        LOG("%s\n", ErrorString.c_str());
        howToUseMessage();
        return -1;
    }

    TLogger::setVerbose(argsMap.contains(OPT_VERBOSE));
    LOG_SET_FILENAME(argsMap.value(OPT_LOGFILE).c_str());
    LOG_V("%s\n", CmdLineParser.dump().c_str());
    LOG_V("Working directory: \"%s\".\n", Functions::currentDir().c_str());
    LOG_V("Binary file location: \"%s\".\n", argv[0]);

    if (argsMap.contains(OPT_HELP)) {
        howToUseMessage();
        return 0;
    }

    if (argsMap.contains(OPT_VERSION))
        return 0;

    return TQtBinPatcher::exec(argsMap) ? 0 : -1;
}

//------------------------------------------------------------------------------
<commit_msg>fix compile on Visual Studio (possibly caused by ub????)<commit_after>/*******************************************************************************

         Yuri V. Krugloff. 2013-2015. http://www.tver-soft.org

    This is free and unencumbered software released into the public domain.

    Anyone is free to copy, modify, publish, use, compile, sell, or
    distribute this software, either in source code form or as a compiled
    binary, for any purpose, commercial or non-commercial, and by any
    means.

    In jurisdictions that recognize copyright laws, the author or authors
    of this software dedicate any and all copyright interest in the
    software to the public domain. We make this dedication for the benefit
    of the public at large and to the detriment of our heirs and
    successors. We intend this dedication to be an overt act of
    relinquishment in perpetuity of all present and future rights to this
    software under copyright law.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.

    For more information, please refer to <http://unlicense.org/>

*******************************************************************************/

#include <string>

#include "Logger.hpp"
#include "Functions.hpp"
#include "CmdLineOptions.hpp"
#include "CmdLineParser.hpp"
#include "CmdLineChecker.hpp"
#include "QtBinPatcher.hpp"

//------------------------------------------------------------------------------

void howToUseMessage()
{
    printf(
        //.......|.........|.........|.........|.........|.........|.........|.........|
        "\n"
        "Usage: qtbinpatcher [options]\n"
        "Options:\n"
        "  --version      Show program version and exit.\n"
        "  --help         Show this help and exit.\n"
        "  --verbose      Print extended runtime information.\n"
        "  --logfile=name Duplicate messages into logfile with name \"name\".\n"
        "  --backup       Create and save backup for files that will be patched.\n"
        "                 This option incompatible with option \"--nobackup\".\n"
        "  --nobackup     Don't create backup files in patch process.\n"
        "                 This option incompatible with option \"--backup\".\n"
        "                 WARNING: If an error occurs during patching, Qt library can be\n"
        "                          permanently damaged!\n"
        "  --force        Force patching (without old path actuality checking).\n"
        "  --qt-dir=path  Directory, where Qt or qmake is now located (may be relative).\n"
        "                 If not specified, will be used current directory. Patcher will\n"
        "                 search qmake first in directory \"path\", and then in its subdir\n"
        "                 \"bin\". Patcher is NEVER looking qmake in other directories.\n"
        "                 WARNING: If nonstandard directory for binary files is used\n"
        "                          (not \"bin\"), select directory where located qmake.\n"
        "  --new-dir=path Directory where Qt will be located (may be relative).\n"
        "                 If not specified, will be used the current location.\n"
        "  --old-dir=path Directory where Qt was located. This option can be specified\n"
        "                 more then once. This path will be replaced only in text files.\n"
        "  --dry-run      Output the procedure only, do not really process the jobs.\n"
        "\n"
        "Remark.\n"
        "  If missing \"--backup\" and \"--nobackup\" options, the backup files will be\n"
        "  created before patching and deleted after successful completion of the\n"
        "  patching or restored if an error occurs.\n"
        "\n"
        //.......|.........|.........|.........|.........|.........|.........|.........|
    );
}

//------------------------------------------------------------------------------

int main(int argc, const char* argv[])
{
    const char *description = "\n"
        "QtBinPatcher v2.3.0Beta. Tool for patching paths in Qt binaries.\n"
        "Yuri V. Krugloff, 2013-2015. http://www.tver-soft.org\n"
        "Frank Su, 2016. http://mogara.org\n"
        "This is free software released into the public domain.\n"
#ifdef QTCROSS
        "This binary is built for cross compiled Qt.\n"
#endif
        "\n"
    ;

    LOG(description);

    TCmdLineParser CmdLineParser(argc, argv);
    if (CmdLineParser.hasError()) {
        LOG("%s\n", CmdLineParser.errorString().c_str());
        howToUseMessage();
        return -1;
    }
    const TStringListMap& argsMap = CmdLineParser.argsMap();

    std::string ErrorString = TCmdLineChecker::check(argsMap);
    if (!ErrorString.empty()) {
        LOG("%s\n", ErrorString.c_str());
        howToUseMessage();
        return -1;
    }

    TLogger::setVerbose(argsMap.contains(OPT_VERBOSE));
    LOG_SET_FILENAME(argsMap.value(OPT_LOGFILE).c_str());
    LOG_V("%s\n", CmdLineParser.dump().c_str());
    LOG_V("Working directory: \"%s\".\n", Functions::currentDir().c_str());
    LOG_V("Binary file location: \"%s\".\n", argv[0]);

    if (argsMap.contains(OPT_HELP)) {
        howToUseMessage();
        return 0;
    }

    if (argsMap.contains(OPT_VERSION))
        return 0;

    return TQtBinPatcher::exec(argsMap) ? 0 : -1;
}

//------------------------------------------------------------------------------
<|endoftext|>


<commit_before>#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <bits/stl_algo.h>
#include <bitset>
#include <fstream>
#include <chrono>

using namespace std;

typedef struct GraphTree {
    unsigned char symbol;
    unsigned char symbolExtended;
    unsigned long long int nrOfApp;
    GraphTree *parent;
    GraphTree *left;
    GraphTree *right;
} ShannonTree;

typedef std::map<int, std::pair<GraphTree *, std::string>> MappedSymbols;
typedef std::chrono::duration<int, std::milli> miliseconds_type;

typedef struct GraphSearch {
    std::string code;
    bool type;
    GraphTree *reference;
};

int ENCODE_BITS = 8;
int ESC_VALUE = 257;
int EOS_VALUE = 256;
MappedSymbols symbolMap;

auto
        cmp = [](std::pair<unsigned char, unsigned long int> const &a, std::pair<unsigned char, unsigned long int> const &b) {
    return a.second != b.second ? a.second > b.second : a.first < b.first;
};

GraphTree *initGraph() {

    GraphTree *parent, *left, *right;
    parent = new GraphTree;
    left = new GraphTree;
    right = new GraphTree;
    parent->symbol = 0;
    parent->symbolExtended = 0;
    parent->nrOfApp = 2;

    parent->parent = NULL;
    parent->left = left;
    parent->right = right;

    left->parent = parent;
    right->parent = parent;

    left->left = NULL;
    left->right = NULL;

    right->left = NULL;
    right->right = NULL;

    left->symbol = 255;
    left->symbolExtended = 1;

    right->symbol = 255;
    right->symbolExtended = 2;

    left->nrOfApp = 1;
    right->nrOfApp = 1;

    symbolMap[right->symbol + right->symbolExtended].first = right;
    symbolMap[right->symbol + right->symbolExtended].second = "1";

    symbolMap[left->symbol + left->symbolExtended].first = left;
    symbolMap[left->symbol + left->symbolExtended].second = "0";

    return parent;

}

/**
* find symbol in alphabet map, if it is first occurence for symbol return a reference for ESC symbol
*/
GraphSearch findSymbol(unsigned char symbol) {
    GraphSearch result;
    if (symbolMap.count(symbol) > 0) {
        result.code = symbolMap[symbol].second;
        result.type = true;
        result.reference = symbolMap[symbol].first;
    } else {
        result.code = symbolMap[ESC_VALUE].second;
        result.type = false;
        result.reference = symbolMap[ESC_VALUE].first;
    }
    return result;

}

void updateSymbol(GraphSearch result) {
    (result.reference)->nrOfApp = (result.reference)->nrOfApp + 1;
}

void addSymbol(GraphSearch result, unsigned char symbol) {
    GraphTree *left, *right;

    left = new GraphTree;
    left->nrOfApp = 1;
    left->right = NULL;
    left->left = NULL;
    left->symbol = symbol;
    left->symbolExtended = 0;
    left->parent = result.reference;

    right = new GraphTree;
    right->nrOfApp = 1;
    right->right = NULL;
    right->left = NULL;
    right->symbol = 255;
    right->symbolExtended = 2;
    right->parent = result.reference;

    (result.reference)->left = left;
    (result.reference)->right = right;
    (result.reference)->nrOfApp = 2;
    (result.reference)->symbol = 0;
    (result.reference)->symbolExtended = 0;

}

/**
* After a new symbol is added we need to update with one unit all parent nodes
*/
void updateNoOfApp(GraphTree *node) {
    GraphTree *iterator;
    iterator = node->parent;
    while (iterator != NULL) {
        node->nrOfApp++;
    }
}

void displayGraph(GraphTree *root) {
    if ((root->symbol + root->symbolExtended) == 0) {
        displayGraph(root->left);
        displayGraph(root->right);
    } else {
        std::cout << "Simbol: " << (root->symbol + root->symbolExtended) << "\n";
    }

}

void encodeSymbol(unsigned char symbol, GraphTree *parent) {
    GraphSearch result;

    result = findSymbol(symbol);
    if (result.type == true) {
        updateSymbol(result);
    } else {
        addSymbol(result, symbol);
    }

    //updateNoOfApp(result.reference);
}

void encodeFile() {

}

void compressFile(std::string fileName) {

    GraphTree *huffmanTree;
    huffmanTree = initGraph();
    displayGraph(huffmanTree);
    encodeSymbol('a', huffmanTree);
    std::cout << "\n\n";
    displayGraph(huffmanTree);
}

void uncompressFile(std::string fileName) {

}

void displayOptions() {
    std::cout << "Alege fisierul!" << "\n\n Audio:\n";
    std::cout << "\t1.)instr_01.wav\n";
    std::cout << "\t2.)sound_01.wav\n";
    std::cout << "\t3.)speech_01.wav\n";
    std::cout << "\nDocuments:\n";
    std::cout << "\t4.)Documentatie_UMAPID.doc\n";
    std::cout << "\t5.)Documentatie_UMAPID.pdf\n";
    std::cout << "\t6.)Prefata_Undine.txt\n";
    std::cout << "\t7.)show_audio.m\n";
    std::cout << "\t8.)Y04.M\n";
    std::cout << "\nExecutables:\n";
    std::cout << "\t9.)KARMA_DATA482#1_5_V7.mat\n";
    std::cout << "\t10.)quartz.dll\n";
    std::cout << "\t11.)WinRar.exe\n";
    std::cout << "\t12.)WINZIP32.EXE\n";

}

std::ifstream::pos_type filesize(std::string fileName) {
    std::ifstream in(fileName.c_str(), std::ifstream::ate | std::ifstream::binary);
    return in.tellg();
}

void displayInformations(std::string fileName) {
    std::ifstream::pos_type compressedFileSize, fileSize, uncompressedFileSize;
    std::string compressedFileName, uncompressedFileName;

    compressedFileName = fileName + ".psh";
    uncompressedFileName = fileName + ".pshu";

    compressedFileSize = filesize(compressedFileName);
    fileSize = filesize(fileName);
    uncompressedFileSize = filesize(uncompressedFileName);

    std::cout << "Norma: " << (fileSize - uncompressedFileSize) * (fileSize - uncompressedFileSize) << "\n";
    std::cout << "Rata compresie: " << (1 - ((float) compressedFileSize) / ((float) uncompressedFileSize)) * 100 << "%\n";
    std::cout << "Factor compresie:  " << (((float) compressedFileSize) / ((float) fileSize)) * 100 << "%\n";

}

int main() {

    std::vector<std::string> files = {
            ".\\audio\\instr_01.wav",
            ".\\audio\\sound_01.wav",
            ".\\audio\\speech_01.wav",
            ".\\documents\\Documentatie_UMAPID.doc",
            ".\\documents\\Documentatie_UMAPID.pdf",
            ".\\documents\\Prefata_Undine.txt",
            ".\\documents\\show_audio.m",
            ".\\documents\\Y04.M",
            ".\\executables\\KARMA_DATA482#1_5_V7.mat",
            ".\\executables\\quartz.dll",
            ".\\executables\\WinRar.exe",
            ".\\executables\\WINZIP32.EXE",
            ".\\documents\\input.txt",
            "D:\\input.txt",
    };

    int option;
    //displayOptions();
    //std::cout << "Select file!..\n";
    //std::cin >> option;
//    if (option < 1 && option > 14) {
//        std::cout << "Invalid option!";
//        return 0;
//    }
    auto startC = std::chrono::high_resolution_clock::now();

    compressFile(files[2]);
    auto endC = std::chrono::high_resolution_clock::now();
    auto timeC = endC - startC;
    std::cout << "Compressed time: " << std::chrono::duration_cast<miliseconds_type>(timeC).count() << " miliseconds.\n";

    auto startU = std::chrono::high_resolution_clock::now();
//    uncompressFile(files[option - 1]);

    auto endU = std::chrono::high_resolution_clock::now();
    auto timeU = endU - startU;
    std::cout << "Uncompressed time: " << std::chrono::duration_cast<miliseconds_type>(timeU).count() << " miliseconds.\n";
//    displayInformations(files[option - 1]);

    //std::cin >> option;

    return 0;
}<commit_msg>Update encode symbol function<commit_after>#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <bits/stl_algo.h>
#include <bitset>
#include <fstream>
#include <chrono>

using namespace std;

typedef struct GraphTree {
    unsigned char symbol;
    unsigned char symbolExtended;
    unsigned long long int nrOfApp;
    GraphTree *parent;
    GraphTree *left;
    GraphTree *right;
    unsigned long long int index;
} ShannonTree;

typedef std::vector<GraphTree *> GraphIndex;

typedef std::map<int, std::pair<GraphTree *, std::string>> MappedSymbols;
typedef std::chrono::duration<int, std::milli> miliseconds_type;

typedef struct GraphSearch {
    std::string code;
    bool type;
    GraphTree *reference;
};

int ENCODE_BITS = 8;
int ESC_VALUE = 257;
int EOS_VALUE = 256;
MappedSymbols symbolMap;
GraphIndex indexedGraph;

auto
        cmp = [](std::pair<unsigned char, unsigned long int> const &a, std::pair<unsigned char, unsigned long int> const &b) {
    return a.second != b.second ? a.second > b.second : a.first < b.first;
};

GraphTree *initGraph() {

    GraphTree *parent, *left, *right;
    parent = new GraphTree;
    left = new GraphTree;
    right = new GraphTree;
    parent->symbol = 0;
    parent->symbolExtended = 0;
    parent->nrOfApp = 2;

    parent->parent = NULL;
    parent->left = left;
    parent->right = right;
    parent->index = 1;

    indexedGraph.push_back(parent);

    left->parent = parent;
    right->parent = parent;

    left->left = NULL;
    left->right = NULL;

    right->left = NULL;
    right->right = NULL;

    left->symbol = 255;
    left->symbolExtended = 1;

    right->symbol = 255;
    right->symbolExtended = 2;

    left->nrOfApp = 1;
    right->nrOfApp = 1;

    left->index = 2;
    right->index = 3;

    indexedGraph.push_back(left);
    indexedGraph.push_back(right);

    symbolMap[right->symbol + right->symbolExtended].first = right;
    symbolMap[right->symbol + right->symbolExtended].second = "1";

    symbolMap[left->symbol + left->symbolExtended].first = left;
    symbolMap[left->symbol + left->symbolExtended].second = "0";

    return parent;

}

/**
* find symbol in alphabet map, if it is first occurence for symbol return a reference for ESC symbol
*/
GraphSearch findSymbol(unsigned char symbol) {
    GraphSearch result;
    if (symbolMap.count(symbol) > 0) {
        result.code = symbolMap[symbol].second;
        result.type = true;
        result.reference = symbolMap[symbol].first;
    } else {
        result.code = symbolMap[ESC_VALUE].second;
        result.type = false;
        result.reference = symbolMap[ESC_VALUE].first;
    }
    return result;

}

void updateSymbol(GraphSearch result) {
    (result.reference)->nrOfApp = (result.reference)->nrOfApp + 1;
}

void addSymbol(GraphSearch result, unsigned char symbol) {
    GraphTree *left, *right;

    left = new GraphTree;
    left->nrOfApp = 1;
    left->right = NULL;
    left->left = NULL;
    left->symbol = symbol;
    left->symbolExtended = 0;
    left->parent = result.reference;
    left->index = (result.reference)->index + 1;

    right = new GraphTree;
    right->nrOfApp = 1;
    right->right = NULL;
    right->left = NULL;
    right->symbol = 255;
    right->symbolExtended = 2;
    right->parent = result.reference;
    right->index = (result.reference)->index + 2;

    (result.reference)->left = left;
    (result.reference)->right = right;
    (result.reference)->nrOfApp = 2;
    (result.reference)->symbol = 0;
    (result.reference)->symbolExtended = 0;

    indexedGraph.push_back(left);
    indexedGraph.push_back(right);

    symbolMap[ESC_VALUE].first = right;

}

void displayIndexedGraph() {
    GraphIndex::size_type iterator;
    for (iterator = 0; iterator < indexedGraph.size(); ++iterator) {
        std::cout << (indexedGraph[iterator])->nrOfApp << " " << (indexedGraph[iterator])->index << " -> " << iterator + 1 << "\n";
    }
}

void displayGraph(GraphTree *root) {
    if ((root->symbol + root->symbolExtended) == 0) {
        std::cout << "Pondere: " << root->nrOfApp << "\n";
        displayGraph(root->left);
        displayGraph(root->right);
    } else {
        std::cout << "Simbol: " << (root->symbol + root->symbolExtended) << "\n";
    }

}

void balanceGraph(GraphTree *node) {
    GraphTree *aux, *changeAux;
    GraphIndex::size_type iterator, auxIndex;

    for (iterator = node->index - 1; iterator > 0; iterator--) {
        if ((indexedGraph[iterator - 1])->nrOfApp >= node->nrOfApp) {
            break;
        }
    }
    if (iterator == node->index - 1) {
        node->parent->nrOfApp++;
        if (node->parent->parent != NULL) {
            balanceGraph(node->parent);
        }

    }

    if (iterator == node->index - 2) {
        (indexedGraph[iterator - 1])->right = indexedGraph[iterator];
        (indexedGraph[iterator - 1])->left = node;
        indexedGraph[iterator]->index++;
        node->index--;
        indexedGraph[iterator] = node;
        indexedGraph[iterator + 1] = (indexedGraph[iterator - 1])->right;
        balanceGraph(node);
    }

    if (iterator > node->index - 2) {
        (indexedGraph[iterator - 1])->right = indexedGraph[iterator];
        (indexedGraph[iterator - 1])->left = node;
        indexedGraph[iterator]->index++;
        node->index--;
        indexedGraph[iterator] = node;
        indexedGraph[iterator + 1] = (indexedGraph[iterator - 1])->right;
        //balanceGraph(node);
    }
    std::cout << "\n\n";
}

void encodeSymbol(unsigned char symbol, GraphTree *parent) {
    GraphSearch result;

    result = findSymbol(symbol);
    if (result.type == true) {
        updateSymbol(result);
    } else {
        addSymbol(result, symbol);
    }

    balanceGraph(result.reference);

}

void swapChild(GraphTree *root) {
    GraphTree *aux;
    aux = root->left;
    root->left = root->right;
    root->right = aux;
}

void balanceTree(GraphTree *root) {

    if ((root->symbol + root->symbolExtended) == 0) {
        if (root->left->nrOfApp < root->right->nrOfApp) {
            swapChild(root);
        }
    }
}

void encodeFile() {

}

void compressFile(std::string fileName) {

    GraphTree *huffmanTree;
    huffmanTree = initGraph();
    encodeSymbol('a', huffmanTree);
    encodeSymbol('b', huffmanTree);
    displayIndexedGraph();
    std::cout << "\n\n";
    displayGraph(huffmanTree);
//    balanceTree(huffmanTree);
//    encodeSymbol('b', huffmanTree);
//    balanceTree(huffmanTree);
//    std::cout << "\n\n";
//    displayGraph(huffmanTree);
}

void uncompressFile(std::string fileName) {

}

void displayOptions() {
    std::cout << "Alege fisierul!" << "\n\n Audio:\n";
    std::cout << "\t1.)instr_01.wav\n";
    std::cout << "\t2.)sound_01.wav\n";
    std::cout << "\t3.)speech_01.wav\n";
    std::cout << "\nDocuments:\n";
    std::cout << "\t4.)Documentatie_UMAPID.doc\n";
    std::cout << "\t5.)Documentatie_UMAPID.pdf\n";
    std::cout << "\t6.)Prefata_Undine.txt\n";
    std::cout << "\t7.)show_audio.m\n";
    std::cout << "\t8.)Y04.M\n";
    std::cout << "\nExecutables:\n";
    std::cout << "\t9.)KARMA_DATA482#1_5_V7.mat\n";
    std::cout << "\t10.)quartz.dll\n";
    std::cout << "\t11.)WinRar.exe\n";
    std::cout << "\t12.)WINZIP32.EXE\n";

}

std::ifstream::pos_type filesize(std::string fileName) {
    std::ifstream in(fileName.c_str(), std::ifstream::ate | std::ifstream::binary);
    return in.tellg();
}

void displayInformations(std::string fileName) {
    std::ifstream::pos_type compressedFileSize, fileSize, uncompressedFileSize;
    std::string compressedFileName, uncompressedFileName;

    compressedFileName = fileName + ".psh";
    uncompressedFileName = fileName + ".pshu";

    compressedFileSize = filesize(compressedFileName);
    fileSize = filesize(fileName);
    uncompressedFileSize = filesize(uncompressedFileName);

    std::cout << "Norma: " << (fileSize - uncompressedFileSize) * (fileSize - uncompressedFileSize) << "\n";
    std::cout << "Rata compresie: " << (1 - ((float) compressedFileSize) / ((float) uncompressedFileSize)) * 100 << "%\n";
    std::cout << "Factor compresie:  " << (((float) compressedFileSize) / ((float) fileSize)) * 100 << "%\n";

}

int main() {

    std::vector<std::string> files = {
            ".\\audio\\instr_01.wav",
            ".\\audio\\sound_01.wav",
            ".\\audio\\speech_01.wav",
            ".\\documents\\Documentatie_UMAPID.doc",
            ".\\documents\\Documentatie_UMAPID.pdf",
            ".\\documents\\Prefata_Undine.txt",
            ".\\documents\\show_audio.m",
            ".\\documents\\Y04.M",
            ".\\executables\\KARMA_DATA482#1_5_V7.mat",
            ".\\executables\\quartz.dll",
            ".\\executables\\WinRar.exe",
            ".\\executables\\WINZIP32.EXE",
            ".\\documents\\input.txt",
            "D:\\input.txt",
    };

    int option;
    //displayOptions();
    //std::cout << "Select file!..\n";
    //std::cin >> option;
//    if (option < 1 && option > 14) {
//        std::cout << "Invalid option!";
//        return 0;
//    }
    auto startC = std::chrono::high_resolution_clock::now();

    compressFile(files[2]);
    auto endC = std::chrono::high_resolution_clock::now();
    auto timeC = endC - startC;
    std::cout << "Compressed time: " << std::chrono::duration_cast<miliseconds_type>(timeC).count() << " miliseconds.\n";

    auto startU = std::chrono::high_resolution_clock::now();
//    uncompressFile(files[option - 1]);

    auto endU = std::chrono::high_resolution_clock::now();
    auto timeU = endU - startU;
    std::cout << "Uncompressed time: " << std::chrono::duration_cast<miliseconds_type>(timeU).count() << " miliseconds.\n";
//    displayInformations(files[option - 1]);

    //std::cin >> option;

    return 0;
}<|endoftext|>


<commit_before>#include "cpuinforeader.h"
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    CPUInfoReader reader;

    qWarning(reader.readCPUInfo().toLatin1());

    qmlRegisterType<CPUInfoReader>("procinfo", 1, 0, "CPUInfoReader");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
<commit_msg>Improve debug string output<commit_after>#include "cpuinforeader.h"
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    CPUInfoReader reader;
    qDebug(reader.readCPUInfo().toUtf8());

    qmlRegisterType<CPUInfoReader>("procinfo", 1, 0, "CPUInfoReader");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
<|endoftext|>


<commit_before>3ff20e94-ad58-11e7-b422-ac87a332f658<commit_msg>Did ANOTHER thing<commit_after>404dd882-ad58-11e7-af0b-ac87a332f658<|endoftext|>


<commit_before>/******************************************************************************
shiftty (ShifTTY) - Shapeshift Cryptocurrency Exchange Terminal

ShifTTY is a command-line interface to the cryptocurrency exchange Shapeshift
using its API.

******************************************************************************/

/* C++ Standard Library */

#include <cstdlib>
#include <cinttypes>
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cassert>
#include <vector>
#include "http.h"
#include "json.h"
#include "logger.h"
#include "shapeshift-api.h"
#include "shapeshift-api-debug.h"

/* OS-specific Libraries */

#ifndef WIN32
#include <unistd.h>
#endif

/* CURL Libraries (from package "libcurl-devel" (Fedora Linux 24) */

#include <curl/curl.h>

using namespace std;

int main(int argc, const char* argv[])
{
	test_all(true);

	int breakpointHere = 0;
	log("Hello world!");

    return breakpointHere;
}
<commit_msg>Removed some of the include lines from main.cpp<commit_after>/******************************************************************************
shiftty (ShifTTY) - Shapeshift Cryptocurrency Exchange Terminal

ShifTTY is a command-line interface to the cryptocurrency exchange Shapeshift
using its API.

******************************************************************************/

#include <cstdlib>
#include <cinttypes>
#include <iostream>
#include <string>
#include <cassert>
#include <vector>
#include "logger.h"
#include "shapeshift-api.h"
#include "shapeshift-api-debug.h"

/* OS-specific Libraries */

#ifndef WIN32
#include <unistd.h>
#endif

/* CURL Libraries (from package "libcurl-devel" (Fedora Linux 24) */

#include <curl/curl.h>

using namespace std;

int main(int argc, const char* argv[])
{
	test_all(true);

	int breakpointHere = 0;
	log("Hello world!");

    return breakpointHere;
}
<|endoftext|>


<commit_before>3985d500-ad5c-11e7-b0f2-ac87a332f658<commit_msg>master branch<commit_after>39e4c023-ad5c-11e7-a7f0-ac87a332f658<|endoftext|>