<commit_before>/*
 * Copyright (C) 2013 - 2014 Andrew Duggan
 * Copyright (C) 2013 - 2014 Synaptics Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <getopt.h>

#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <signal.h>
#include <stdlib.h>

#include "hiddevice.h"

#define RMI4UPDATE_GETOPTS      "hp:ir:w:foam"

 enum rmihidtool_cmd {
	RMIHIDTOOL_CMD_INTERACTIVE,
	RMIHIDTOOL_CMD_READ,
	RMIHIDTOOL_CMD_WRITE,
	RMIHIDTOOL_CMD_FW_ID,
	RMIHIDTOOL_CMD_PROPS,
	RMIHIDTOOL_CMD_ATTN,
	RMIHIDTOOL_CMD_PRINT_FUNCTIONS,
};

static int report_attn = 0;
static RMIDevice * g_device = NULL;

void print_help(const char *prog_name)
{
	fprintf(stdout, "Usage: %s [OPTIONS] DEVICEFILE\n", prog_name);
	fprintf(stdout, "\t-h, --help\t\t\t\tPrint this message\n");
	fprintf(stdout, "\t-p, --protocol [protocol]\t\tSet which transport prototocl to use.\n");
	fprintf(stdout, "\t-i, --interactive\t\t\tRun in interactive mode.\n");
	fprintf(stdout, "\t-r, --read [address] [length]\t\tRead registers starting at the address.\n");
	fprintf(stdout, "\t-r, --write [address] [length] [data]\tWrite registers starting at the address.\n");
	fprintf(stdout, "\t-f, --firmware-id\t\t\tPrint the firmware id\n");
	fprintf(stdout, "\t-o, --props\t\t\t\tPrint device properties\n");
	fprintf(stdout, "\t-a, --attention\t\t\t\tPrint attention reports until control + c\n");
	fprintf(stdout, "\t-m, --print-functions\t\t\tPrint RMI4 functions for the device.\n");
}

void print_cmd_usage()
{
	fprintf(stdout, "Commands:\n");
	fprintf(stdout, "s [0,1,2]: Set RMIMode\n");
	fprintf(stdout, "r address size: read size bytes from address\n");
	fprintf(stdout, "w address { values }: write bytes to address\n");
	fprintf(stdout, "a: Wait for attention\n");
	fprintf(stdout, "q: quit\n");
}

int find_token(char * input, char * result, char ** endpp)
{
	int i = 0;
	char * start = input;
	char * end;

	while (input[i] == ' ') {
		++start;
		++i;
	}

	while (input[i] != '\0') {
		if (input[++i] == ' ')
			break;
	}
	end = &input[i];

	if (start == end)
		return 0;

	*endpp = end;
	strncpy(result, start, end - start);
	result[end - start] = '\0';

	return 1;
}

void interactive(RMIDevice * device, unsigned char *report)
{
	char token[256];
	char * start;
	char * end;
	int rc;

	for (;;) {
		fprintf(stdout, "\n");
		print_cmd_usage();
		char input[256];

		if (fgets(input, 256, stdin)) {
			memset(token, 0, 256);

			if (input[0] == 's') {
				start = input + 2;
				find_token(start, token, &end);
				int mode = strtol(token, NULL, 0);
				if (mode >= 0 && mode <= 2) {
					if (device->SetMode(mode)) {
						fprintf(stderr, "Set RMI Mode to: %d\n", mode);
					} else {
						fprintf(stderr, "Set RMI Mode FAILED!\n");
						continue;
					}
				}
			} else if (input[0] == 'r') {
				start = input + 2;
				find_token(start, token, &end);
				start = end + 1;
				unsigned int addr = strtol(token, NULL, 0);
				find_token(start, token, &end);
				start = end + 1;
				unsigned int len = strtol(token, NULL, 0);
				fprintf(stdout, "Address = 0x%02x Length = %d\n", addr, len);

				memset(report, 0, 256);
				rc = device->Read(addr, report, len);
				if (rc < 0)
					fprintf(stderr, "Failed to read report: %d\n", rc);
				print_buffer(report, len);
			} else if (input[0] == 'w') {
				int index = 0;
				start = input + 2;
				find_token(start, token, &end);
				start = end + 1;
				unsigned int addr = strtol(token, NULL, 0);
				unsigned int len = 0;

				memset(report, 0, 256);
				while (find_token(start, token, &end)) {
					start = end;
					report[index++] = strtol(token, NULL, 0);
					++len;
				}

				if (device->Write(addr, report, len) < 0) {
					fprintf(stderr, "Failed to Write Report\n");
					continue;
				}
			} else if (input[0] == 'a') {
				unsigned int bytes = 256;
				device->GetAttentionReport(NULL,
						RMI_INTERUPT_SOURCES_ALL_MASK,
						report, &bytes);
				print_buffer(report, bytes);
			} else if (input[0] == 'q') {
				return;
			} else {
				print_cmd_usage();
			}
		}
	}
}

static void cleanup(int status)
{
	if (report_attn) {
		report_attn = 0;
		if (g_device)
			g_device->Cancel();
	} else {
		exit(0);
	}
}

int main(int argc, char ** argv)
{
	int rc;
	struct sigaction sig_cleanup_action;
	int opt;
	int index;
	RMIDevice *device;
	const char *protocol = "HID";
	unsigned char report[256];
	char token[256];
	static struct option long_options[] = {
		{"help", 0, NULL, 'h'},
		{"protocol", 1, NULL, 'p'},
		{"interactive", 0, NULL, 'i'},
		{"read", 1, NULL, 'r'},
		{"write", 1, NULL, 'w'},
		{"firmware-id", 0, NULL, 'f'},
		{"props", 0, NULL, 'o'},
		{"attention", 0, NULL, 'a'},
		{"print-functions", 0, NULL, 'm'},
		{0, 0, 0, 0},
	};
	enum rmihidtool_cmd cmd = RMIHIDTOOL_CMD_INTERACTIVE;
	unsigned int addr = 0;
	unsigned int len = 0;
	char * data = NULL;
	char * start;
	char * end;
	int i = 0;

	memset(&sig_cleanup_action, 0, sizeof(struct sigaction));
	sig_cleanup_action.sa_handler = cleanup;
	sig_cleanup_action.sa_flags = SA_RESTART;
	sigaction(SIGINT, &sig_cleanup_action, NULL);

	while ((opt = getopt_long(argc, argv, RMI4UPDATE_GETOPTS, long_options, &index)) != -1) {
		switch (opt) {
			case 'h':
				print_help(argv[0]);
				return 0;
			case 'p':
				protocol = optarg;
				break;
			case 'i':
				cmd = RMIHIDTOOL_CMD_INTERACTIVE;
				break;
			case 'r':
				cmd = RMIHIDTOOL_CMD_READ;
				addr = strtol(optarg, NULL, 0);
				len = strtol(argv[optind++], NULL, 0);
				break;
			case 'w':
				cmd = RMIHIDTOOL_CMD_WRITE;
				addr = strtol(optarg, NULL, 0);
				data = argv[optind++];
				break;
			case 'f':
				cmd = RMIHIDTOOL_CMD_FW_ID;
				break;
			case 'o':
				cmd = RMIHIDTOOL_CMD_PROPS;
				break;
			case 'a':
				cmd = RMIHIDTOOL_CMD_ATTN;
				break;
			case 'm':
				cmd = RMIHIDTOOL_CMD_PRINT_FUNCTIONS;
				break;
			default:
				print_help(argv[0]);
				return 0;
				break;

		}
	}

	if (!strncasecmp("hid", protocol, 3)) {
		device = new HIDDevice();
	} else {
		fprintf(stderr, "Invalid Protocol: %s\n", protocol);
		return -1;
	}

	if (optind >= argc) {
		print_help(argv[0]);
		return -1;
	}

	rc = device->Open(argv[optind++]);
	if (rc) {
		fprintf(stderr, "%s: failed to initialize rmi device (%d): %s\n", argv[0], errno,
			strerror(errno));
		return 1;
	}

	g_device = device;

	switch (cmd) {
		case RMIHIDTOOL_CMD_READ:
			memset(report, 0, sizeof(report));
			rc = device->Read(addr, report, len);
			if (rc < 0)
				fprintf(stderr, "Failed to read report: %d\n", rc);

			print_buffer(report, len);
			break;
		case RMIHIDTOOL_CMD_WRITE:
			i = 0;
			start = data;
			memset(report, 0, sizeof(report));
			while (find_token(start, token, &end)) {
				start = end;
				report[i++] = (unsigned char)strtol(token, NULL, 0);
				++len;
			}

			if (device->Write(addr, report, len) < 0) {
				fprintf(stderr, "Failed to Write Report\n");
				return -1;
			}
			break;
		case RMIHIDTOOL_CMD_FW_ID:
			device->ScanPDT();
			device->QueryBasicProperties();
			fprintf(stdout, "firmware id: %lu\n", device->GetFirmwareID());
			break;
		case RMIHIDTOOL_CMD_PROPS:
			device->ScanPDT();
			device->QueryBasicProperties();
			device->PrintProperties();
			break;
		case RMIHIDTOOL_CMD_ATTN:
			report_attn = 1;
			while(report_attn) {
				unsigned int bytes = 256;
				rc = device->GetAttentionReport(NULL,
						RMI_INTERUPT_SOURCES_ALL_MASK,
						report, &bytes);
				if (rc > 0) {
					print_buffer(report, bytes);
					fprintf(stdout, "\n");
				}
			}
			break;
		case RMIHIDTOOL_CMD_PRINT_FUNCTIONS:
			device->ScanPDT();
			device->PrintFunctions();
			break;
		case RMIHIDTOOL_CMD_INTERACTIVE:
		default:
			interactive(device, report);
			break;
	}

	device->Close();

	return 0;
}
<commit_msg>Add option to rebind the driver from rmihidtool.<commit_after>/*
 * Copyright (C) 2013 - 2014 Andrew Duggan
 * Copyright (C) 2013 - 2014 Synaptics Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <getopt.h>

#include <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <signal.h>
#include <stdlib.h>

#include "hiddevice.h"

#define RMI4UPDATE_GETOPTS      "hp:ir:w:foamb"

 enum rmihidtool_cmd {
	RMIHIDTOOL_CMD_INTERACTIVE,
	RMIHIDTOOL_CMD_READ,
	RMIHIDTOOL_CMD_WRITE,
	RMIHIDTOOL_CMD_FW_ID,
	RMIHIDTOOL_CMD_PROPS,
	RMIHIDTOOL_CMD_ATTN,
	RMIHIDTOOL_CMD_PRINT_FUNCTIONS,
	RMIHIDTOOL_CMD_REBIND_DRIVER,
};

static int report_attn = 0;
static RMIDevice * g_device = NULL;

void print_help(const char *prog_name)
{
	fprintf(stdout, "Usage: %s [OPTIONS] DEVICEFILE\n", prog_name);
	fprintf(stdout, "\t-h, --help\t\t\t\tPrint this message\n");
	fprintf(stdout, "\t-p, --protocol [protocol]\t\tSet which transport prototocl to use.\n");
	fprintf(stdout, "\t-i, --interactive\t\t\tRun in interactive mode.\n");
	fprintf(stdout, "\t-r, --read [address] [length]\t\tRead registers starting at the address.\n");
	fprintf(stdout, "\t-r, --write [address] [length] [data]\tWrite registers starting at the address.\n");
	fprintf(stdout, "\t-f, --firmware-id\t\t\tPrint the firmware id\n");
	fprintf(stdout, "\t-o, --props\t\t\t\tPrint device properties\n");
	fprintf(stdout, "\t-a, --attention\t\t\t\tPrint attention reports until control + c\n");
	fprintf(stdout, "\t-m, --print-functions\t\t\tPrint RMI4 functions for the device.\n");
	fprintf(stdout, "\t-b, --rebind-driver\t\t\tRebind the driver to force an update of device properties.\n");
}

void print_cmd_usage()
{
	fprintf(stdout, "Commands:\n");
	fprintf(stdout, "s [0,1,2]: Set RMIMode\n");
	fprintf(stdout, "r address size: read size bytes from address\n");
	fprintf(stdout, "w address { values }: write bytes to address\n");
	fprintf(stdout, "a: Wait for attention\n");
	fprintf(stdout, "q: quit\n");
}

int find_token(char * input, char * result, char ** endpp)
{
	int i = 0;
	char * start = input;
	char * end;

	while (input[i] == ' ') {
		++start;
		++i;
	}

	while (input[i] != '\0') {
		if (input[++i] == ' ')
			break;
	}
	end = &input[i];

	if (start == end)
		return 0;

	*endpp = end;
	strncpy(result, start, end - start);
	result[end - start] = '\0';

	return 1;
}

void interactive(RMIDevice * device, unsigned char *report)
{
	char token[256];
	char * start;
	char * end;
	int rc;

	for (;;) {
		fprintf(stdout, "\n");
		print_cmd_usage();
		char input[256];

		if (fgets(input, 256, stdin)) {
			memset(token, 0, 256);

			if (input[0] == 's') {
				start = input + 2;
				find_token(start, token, &end);
				int mode = strtol(token, NULL, 0);
				if (mode >= 0 && mode <= 2) {
					if (device->SetMode(mode)) {
						fprintf(stderr, "Set RMI Mode to: %d\n", mode);
					} else {
						fprintf(stderr, "Set RMI Mode FAILED!\n");
						continue;
					}
				}
			} else if (input[0] == 'r') {
				start = input + 2;
				find_token(start, token, &end);
				start = end + 1;
				unsigned int addr = strtol(token, NULL, 0);
				find_token(start, token, &end);
				start = end + 1;
				unsigned int len = strtol(token, NULL, 0);
				fprintf(stdout, "Address = 0x%02x Length = %d\n", addr, len);

				memset(report, 0, 256);
				rc = device->Read(addr, report, len);
				if (rc < 0)
					fprintf(stderr, "Failed to read report: %d\n", rc);
				print_buffer(report, len);
			} else if (input[0] == 'w') {
				int index = 0;
				start = input + 2;
				find_token(start, token, &end);
				start = end + 1;
				unsigned int addr = strtol(token, NULL, 0);
				unsigned int len = 0;

				memset(report, 0, 256);
				while (find_token(start, token, &end)) {
					start = end;
					report[index++] = strtol(token, NULL, 0);
					++len;
				}

				if (device->Write(addr, report, len) < 0) {
					fprintf(stderr, "Failed to Write Report\n");
					continue;
				}
			} else if (input[0] == 'a') {
				unsigned int bytes = 256;
				device->GetAttentionReport(NULL,
						RMI_INTERUPT_SOURCES_ALL_MASK,
						report, &bytes);
				print_buffer(report, bytes);
			} else if (input[0] == 'q') {
				return;
			} else {
				print_cmd_usage();
			}
		}
	}
}

static void cleanup(int status)
{
	if (report_attn) {
		report_attn = 0;
		if (g_device)
			g_device->Cancel();
	} else {
		exit(0);
	}
}

int main(int argc, char ** argv)
{
	int rc;
	struct sigaction sig_cleanup_action;
	int opt;
	int index;
	RMIDevice *device;
	const char *protocol = "HID";
	unsigned char report[256];
	char token[256];
	static struct option long_options[] = {
		{"help", 0, NULL, 'h'},
		{"protocol", 1, NULL, 'p'},
		{"interactive", 0, NULL, 'i'},
		{"read", 1, NULL, 'r'},
		{"write", 1, NULL, 'w'},
		{"firmware-id", 0, NULL, 'f'},
		{"props", 0, NULL, 'o'},
		{"attention", 0, NULL, 'a'},
		{"print-functions", 0, NULL, 'm'},
		{"rebind-driver", 0, NULL, 'b'},
		{0, 0, 0, 0},
	};
	enum rmihidtool_cmd cmd = RMIHIDTOOL_CMD_INTERACTIVE;
	unsigned int addr = 0;
	unsigned int len = 0;
	char * data = NULL;
	char * start;
	char * end;
	int i = 0;

	memset(&sig_cleanup_action, 0, sizeof(struct sigaction));
	sig_cleanup_action.sa_handler = cleanup;
	sig_cleanup_action.sa_flags = SA_RESTART;
	sigaction(SIGINT, &sig_cleanup_action, NULL);

	while ((opt = getopt_long(argc, argv, RMI4UPDATE_GETOPTS, long_options, &index)) != -1) {
		switch (opt) {
			case 'h':
				print_help(argv[0]);
				return 0;
			case 'p':
				protocol = optarg;
				break;
			case 'i':
				cmd = RMIHIDTOOL_CMD_INTERACTIVE;
				break;
			case 'r':
				cmd = RMIHIDTOOL_CMD_READ;
				addr = strtol(optarg, NULL, 0);
				len = strtol(argv[optind++], NULL, 0);
				break;
			case 'w':
				cmd = RMIHIDTOOL_CMD_WRITE;
				addr = strtol(optarg, NULL, 0);
				data = argv[optind++];
				break;
			case 'f':
				cmd = RMIHIDTOOL_CMD_FW_ID;
				break;
			case 'o':
				cmd = RMIHIDTOOL_CMD_PROPS;
				break;
			case 'a':
				cmd = RMIHIDTOOL_CMD_ATTN;
				break;
			case 'm':
				cmd = RMIHIDTOOL_CMD_PRINT_FUNCTIONS;
				break;
			case 'b':
				cmd = RMIHIDTOOL_CMD_REBIND_DRIVER;
				break;
			default:
				print_help(argv[0]);
				return 0;
				break;

		}
	}

	if (!strncasecmp("hid", protocol, 3)) {
		device = new HIDDevice();
	} else {
		fprintf(stderr, "Invalid Protocol: %s\n", protocol);
		return -1;
	}

	if (optind >= argc) {
		print_help(argv[0]);
		return -1;
	}

	rc = device->Open(argv[optind++]);
	if (rc) {
		fprintf(stderr, "%s: failed to initialize rmi device (%d): %s\n", argv[0], errno,
			strerror(errno));
		return 1;
	}

	g_device = device;

	switch (cmd) {
		case RMIHIDTOOL_CMD_READ:
			memset(report, 0, sizeof(report));
			rc = device->Read(addr, report, len);
			if (rc < 0)
				fprintf(stderr, "Failed to read report: %d\n", rc);

			print_buffer(report, len);
			break;
		case RMIHIDTOOL_CMD_WRITE:
			i = 0;
			start = data;
			memset(report, 0, sizeof(report));
			while (find_token(start, token, &end)) {
				start = end;
				report[i++] = (unsigned char)strtol(token, NULL, 0);
				++len;
			}

			if (device->Write(addr, report, len) < 0) {
				fprintf(stderr, "Failed to Write Report\n");
				return -1;
			}
			break;
		case RMIHIDTOOL_CMD_FW_ID:
			device->ScanPDT();
			device->QueryBasicProperties();
			fprintf(stdout, "firmware id: %lu\n", device->GetFirmwareID());
			break;
		case RMIHIDTOOL_CMD_PROPS:
			device->ScanPDT();
			device->QueryBasicProperties();
			device->PrintProperties();
			break;
		case RMIHIDTOOL_CMD_ATTN:
			report_attn = 1;
			while(report_attn) {
				unsigned int bytes = 256;
				rc = device->GetAttentionReport(NULL,
						RMI_INTERUPT_SOURCES_ALL_MASK,
						report, &bytes);
				if (rc > 0) {
					print_buffer(report, bytes);
					fprintf(stdout, "\n");
				}
			}
			break;
		case RMIHIDTOOL_CMD_PRINT_FUNCTIONS:
			device->ScanPDT();
			device->PrintFunctions();
			break;
		case RMIHIDTOOL_CMD_REBIND_DRIVER:
			device->RebindDriver();
			break;
		case RMIHIDTOOL_CMD_INTERACTIVE:
		default:
			interactive(device, report);
			break;
	}

	device->Close();

	return 0;
}
<|endoftext|>


<commit_before>#include "ModulusRemainder.h"
#include "IROperator.h"
#include "IRPrinter.h"
#include "IR.h"
#include "Simplify.h"

// This file is largely a port of parts of src/analysis.ml
namespace Halide {
namespace Internal {

class ComputeModulusRemainder : public IRVisitor {
public:
    ModulusRemainder analyze(Expr e);

    int modulus, remainder;
    Scope<ModulusRemainder> scope;

    ComputeModulusRemainder(const Scope<ModulusRemainder> *s) {
        scope.set_containing_scope(s);
    }

    void visit(const IntImm *);
    void visit(const UIntImm *);
    void visit(const FloatImm *);
    void visit(const StringImm *);
    void visit(const Cast *);
    void visit(const Variable *);
    void visit(const Add *);
    void visit(const Sub *);
    void visit(const Mul *);
    void visit(const Div *);
    void visit(const Mod *);
    void visit(const Min *);
    void visit(const Max *);
    void visit(const EQ *);
    void visit(const NE *);
    void visit(const LT *);
    void visit(const LE *);
    void visit(const GT *);
    void visit(const GE *);
    void visit(const And *);
    void visit(const Or *);
    void visit(const Not *);
    void visit(const Select *);
    void visit(const Load *);
    void visit(const Ramp *);
    void visit(const Broadcast *);
    void visit(const Call *);
    void visit(const Let *);
    void visit(const LetStmt *);
    void visit(const AssertStmt *);
    void visit(const ProducerConsumer *);
    void visit(const For *);
    void visit(const Store *);
    void visit(const Provide *);
    void visit(const Allocate *);
    void visit(const Realize *);
    void visit(const Block *);
    void visit(const IfThenElse *);
    void visit(const Free *);
    void visit(const Evaluate *);
};

ModulusRemainder modulus_remainder(Expr e) {
    ComputeModulusRemainder mr(NULL);
    return mr.analyze(e);
}

ModulusRemainder modulus_remainder(Expr e, const Scope<ModulusRemainder> &scope) {
    ComputeModulusRemainder mr(&scope);
    return mr.analyze(e);
}

bool reduce_expr_modulo(Expr expr, int modulus, int *remainder) {
    ModulusRemainder result = modulus_remainder(expr);

    /* As an example: If we asked for expr mod 8, and the analysis
     * said that expr = 16*k + 13, then because 16 % 8 == 0, the
     * result is 13 % 8 == 5. But if the analysis says that expr =
     * 6*k + 3, then expr mod 8 could be 1, 3, 5, or 7, so we just
     * return false.
     */

    if (result.modulus % modulus == 0) {
        *remainder = result.remainder % modulus;
        return true;
    } else {
        return false;
    }
}

ModulusRemainder ComputeModulusRemainder::analyze(Expr e) {
    e.accept(this);
    return ModulusRemainder(modulus, remainder);
}

namespace {
void check(Expr e, int m, int r) {
    ModulusRemainder result = modulus_remainder(e);
    if (result.modulus != m || result.remainder != r) {
        std::cerr << "Test failed for modulus_remainder:\n";
        std::cerr << "Expression: " << e << "\n";
        std::cerr << "Correct modulus, remainder  = " << m << ", " << r << "\n";
        std::cerr << "Computed modulus, remainder = "
                  << result.modulus << ", "
                  << result.remainder << "\n";
        exit(-1);
    }
}
}

void modulus_remainder_test() {
    Expr x = Variable::make(Int(32), "x");
    Expr y = Variable::make(Int(32), "y");

    check((30*x + 3) + (40*y + 2), 10, 5);
    check((6*x + 3) * (4*y + 1), 2, 1);
    check(max(30*x - 24, 40*y + 31), 5, 1);
    check(10*x - 33*y, 1, 0);
    check(10*x - 35*y, 5, 0);
    check(123, 0, 123);
    check(Let::make("y", x*3 + 4, y*3 + 4), 9, 7);

    std::cout << "modulus_remainder test passed\n";
}

void ComputeModulusRemainder::visit(const IntImm *op) {
    // Equal to op->value modulo anything. We'll use zero as the
    // modulus to mark this special case. We'd better be able to
    // handle zero in the rest of the code...
    remainder = op->value;
    modulus = 0;
}

void ComputeModulusRemainder::visit(const UIntImm *op) {
    internal_error << "modulus_remainder of uint\n";
}

void ComputeModulusRemainder::visit(const FloatImm *) {
    internal_error << "modulus_remainder of float\n";
}

void ComputeModulusRemainder::visit(const StringImm *) {
    internal_error << "modulus_remainder of string\n";
}

void ComputeModulusRemainder::visit(const Cast *) {
    modulus = 1;
    remainder = 0;
}

void ComputeModulusRemainder::visit(const Variable *op) {
    if (scope.contains(op->name)) {
        ModulusRemainder mod_rem = scope.get(op->name);
        modulus = mod_rem.modulus;
        remainder = mod_rem.remainder;
    } else {
        modulus = 1;
        remainder = 0;
    }
}

int gcd(int a, int b) {
    if (a < b) std::swap(a, b);
    while (b != 0) {
        int tmp = b;
        b = a % b;
        a = tmp;
    }
    return a;
}

int lcm(int a, int b) {
    return (a*b)/gcd(a, b);
}

int mod(int a, int m) {
    if (m == 0) return a;
    return mod_imp(a, m);
}

void ComputeModulusRemainder::visit(const Add *op) {
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);
    modulus = gcd(a.modulus, b.modulus);
    remainder = mod(a.remainder + b.remainder, modulus);
}

void ComputeModulusRemainder::visit(const Sub *op) {
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);
    modulus = gcd(a.modulus, b.modulus);
    remainder = mod(a.remainder - b.remainder, modulus);
}

void ComputeModulusRemainder::visit(const Mul *op) {
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);

    if (a.modulus == 0) {
        // a is constant
        modulus = a.remainder * b.modulus;
        remainder = a.remainder * b.remainder;
    } else if (b.modulus == 0) {
        // b is constant
        modulus = b.remainder * a.modulus;
        remainder = a.remainder * b.remainder;
    } else if (a.remainder == 0 && b.remainder == 0) {
        // multiple times multiple
        modulus = a.modulus * b.modulus;
        remainder = 0;
    } else if (a.remainder == 0) {
        modulus = a.modulus * gcd(b.modulus, b.remainder);
        remainder = 0;
    } else if (b.remainder == 0) {
        modulus = b.modulus * gcd(a.modulus, a.remainder);
        remainder = 0;
    } else {
        // All our tricks failed. Convert them to the same modulus and multiply
        modulus = gcd(a.modulus, b.modulus);
        a.remainder = mod(a.remainder * b.remainder, modulus);
    }
}

void ComputeModulusRemainder::visit(const Div *) {
    // We might be able to say something about this if the numerator
    // modulus is provably a multiple of a constant denominator, but
    // in this case we should have simplified away the division.
    remainder = 0;
    modulus = 1;
}

namespace {
ModulusRemainder unify_alternatives(ModulusRemainder a, ModulusRemainder b) {
    // We don't know if we're going to get a or b, so we'd better find
    // a single modulus remainder that works for both.

    // For example:
    // max(30*_ + 13, 40*_ + 27) ->
    // max(10*_ + 3, 10*_ + 7) ->
    // max(2*_ + 1, 2*_ + 1) ->
    // 2*_ + 1

    // Reduce them to the same modulus and the same remainder
    int modulus = gcd(a.modulus, b.modulus);
    int diff = a.remainder - b.remainder;
    if (diff < 0) diff = -diff;
    modulus = gcd(diff, modulus);

    int ra = mod(a.remainder, modulus);

    internal_assert(ra == mod(b.remainder, modulus))
        << "There's a bug inside ModulusRemainder in unify_alternatives\n";

    return ModulusRemainder(modulus, ra);
}
}

void ComputeModulusRemainder::visit(const Mod *op) {
    // We can treat x mod y as x + z*y, where we know nothing about z.
    // (ax + b) + z (cx + d) ->
    // ax + b + zcx + dz ->
    // gcd(a, c, d) * w + b

    // E.g:
    // (8x + 5) mod (6x + 2) ->
    // (8x + 5) + z (6x + 2) ->
    // (8x + 6zx + 2x) + 5 ->
    // 2(4x + 3zx + x) + 5 ->
    // 2w + 1
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);
    modulus = gcd(a.modulus, b.modulus);
    modulus = gcd(modulus, b.remainder);
    remainder = mod(a.remainder, modulus);
}

void ComputeModulusRemainder::visit(const Min *op) {
    ModulusRemainder r = unify_alternatives(analyze(op->a), analyze(op->b));
    modulus = r.modulus;
    remainder = r.remainder;
}

void ComputeModulusRemainder::visit(const Max *op) {
    ModulusRemainder r = unify_alternatives(analyze(op->a), analyze(op->b));
    modulus = r.modulus;
    remainder = r.remainder;
}

void ComputeModulusRemainder::visit(const EQ *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const NE *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const LT *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const LE *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const GT *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const GE *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const And *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const Or *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const Not *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const Select *op) {
    ModulusRemainder r = unify_alternatives(analyze(op->true_value),
                                            analyze(op->false_value));
    modulus = r.modulus;
    remainder = r.remainder;
}

void ComputeModulusRemainder::visit(const Load *) {
    modulus = 1;
    remainder = 0;
}

void ComputeModulusRemainder::visit(const Ramp *) {
    internal_assert(false) << "modulus_remainder of vector\n";
}

void ComputeModulusRemainder::visit(const Broadcast *) {
    internal_assert(false) << "modulus_remainder of vector\n";
}

void ComputeModulusRemainder::visit(const Call *) {
    modulus = 1;
    remainder = 0;
}

void ComputeModulusRemainder::visit(const Let *op) {
    bool value_interesting = op->value.type().is_int();

    if (value_interesting) {
        ModulusRemainder val = analyze(op->value);
        scope.push(op->name, val);
    }
    ModulusRemainder val = analyze(op->body);
    if (value_interesting) {
        scope.pop(op->name);
    }
    modulus = val.modulus;
    remainder = val.remainder;
}

void ComputeModulusRemainder::visit(const LetStmt *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const AssertStmt *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const ProducerConsumer *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const For *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Store *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Provide *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Allocate *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Realize *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Block *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Free *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const IfThenElse *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Evaluate *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

}
}
<commit_msg>Fix subtle overflow bug in unify_alternatives<commit_after>#include "ModulusRemainder.h"
#include "IROperator.h"
#include "IRPrinter.h"
#include "IR.h"
#include "Simplify.h"

// This file is largely a port of parts of src/analysis.ml
namespace Halide {
namespace Internal {

class ComputeModulusRemainder : public IRVisitor {
public:
    ModulusRemainder analyze(Expr e);

    int modulus, remainder;
    Scope<ModulusRemainder> scope;

    ComputeModulusRemainder(const Scope<ModulusRemainder> *s) {
        scope.set_containing_scope(s);
    }

    void visit(const IntImm *);
    void visit(const UIntImm *);
    void visit(const FloatImm *);
    void visit(const StringImm *);
    void visit(const Cast *);
    void visit(const Variable *);
    void visit(const Add *);
    void visit(const Sub *);
    void visit(const Mul *);
    void visit(const Div *);
    void visit(const Mod *);
    void visit(const Min *);
    void visit(const Max *);
    void visit(const EQ *);
    void visit(const NE *);
    void visit(const LT *);
    void visit(const LE *);
    void visit(const GT *);
    void visit(const GE *);
    void visit(const And *);
    void visit(const Or *);
    void visit(const Not *);
    void visit(const Select *);
    void visit(const Load *);
    void visit(const Ramp *);
    void visit(const Broadcast *);
    void visit(const Call *);
    void visit(const Let *);
    void visit(const LetStmt *);
    void visit(const AssertStmt *);
    void visit(const ProducerConsumer *);
    void visit(const For *);
    void visit(const Store *);
    void visit(const Provide *);
    void visit(const Allocate *);
    void visit(const Realize *);
    void visit(const Block *);
    void visit(const IfThenElse *);
    void visit(const Free *);
    void visit(const Evaluate *);
};

ModulusRemainder modulus_remainder(Expr e) {
    ComputeModulusRemainder mr(NULL);
    return mr.analyze(e);
}

ModulusRemainder modulus_remainder(Expr e, const Scope<ModulusRemainder> &scope) {
    ComputeModulusRemainder mr(&scope);
    return mr.analyze(e);
}

bool reduce_expr_modulo(Expr expr, int modulus, int *remainder) {
    ModulusRemainder result = modulus_remainder(expr);

    /* As an example: If we asked for expr mod 8, and the analysis
     * said that expr = 16*k + 13, then because 16 % 8 == 0, the
     * result is 13 % 8 == 5. But if the analysis says that expr =
     * 6*k + 3, then expr mod 8 could be 1, 3, 5, or 7, so we just
     * return false.
     */

    if (result.modulus % modulus == 0) {
        *remainder = result.remainder % modulus;
        return true;
    } else {
        return false;
    }
}

ModulusRemainder ComputeModulusRemainder::analyze(Expr e) {
    e.accept(this);
    return ModulusRemainder(modulus, remainder);
}

namespace {
void check(Expr e, int m, int r) {
    ModulusRemainder result = modulus_remainder(e);
    if (result.modulus != m || result.remainder != r) {
        std::cerr << "Test failed for modulus_remainder:\n";
        std::cerr << "Expression: " << e << "\n";
        std::cerr << "Correct modulus, remainder  = " << m << ", " << r << "\n";
        std::cerr << "Computed modulus, remainder = "
                  << result.modulus << ", "
                  << result.remainder << "\n";
        exit(-1);
    }
}
}

void modulus_remainder_test() {
    Expr x = Variable::make(Int(32), "x");
    Expr y = Variable::make(Int(32), "y");

    check((30*x + 3) + (40*y + 2), 10, 5);
    check((6*x + 3) * (4*y + 1), 2, 1);
    check(max(30*x - 24, 40*y + 31), 5, 1);
    check(10*x - 33*y, 1, 0);
    check(10*x - 35*y, 5, 0);
    check(123, 0, 123);
    check(Let::make("y", x*3 + 4, y*3 + 4), 9, 7);

    std::cout << "modulus_remainder test passed\n";
}

void ComputeModulusRemainder::visit(const IntImm *op) {
    // Equal to op->value modulo anything. We'll use zero as the
    // modulus to mark this special case. We'd better be able to
    // handle zero in the rest of the code...
    remainder = op->value;
    modulus = 0;
}

void ComputeModulusRemainder::visit(const UIntImm *op) {
    internal_error << "modulus_remainder of uint\n";
}

void ComputeModulusRemainder::visit(const FloatImm *) {
    internal_error << "modulus_remainder of float\n";
}

void ComputeModulusRemainder::visit(const StringImm *) {
    internal_error << "modulus_remainder of string\n";
}

void ComputeModulusRemainder::visit(const Cast *) {
    modulus = 1;
    remainder = 0;
}

void ComputeModulusRemainder::visit(const Variable *op) {
    if (scope.contains(op->name)) {
        ModulusRemainder mod_rem = scope.get(op->name);
        modulus = mod_rem.modulus;
        remainder = mod_rem.remainder;
    } else {
        modulus = 1;
        remainder = 0;
    }
}

int gcd(int a, int b) {
    if (a < b) std::swap(a, b);
    while (b != 0) {
        int64_t tmp = b;
        b = a % b;
        a = tmp;
    }
    return a;
}

int lcm(int a, int b) {
    return (a*b)/gcd(a, b);
}

int mod(int a, int m) {
    if (m == 0) return a;
    return mod_imp(a, m);
}

void ComputeModulusRemainder::visit(const Add *op) {
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);
    modulus = gcd(a.modulus, b.modulus);
    remainder = mod(a.remainder + b.remainder, modulus);
}

void ComputeModulusRemainder::visit(const Sub *op) {
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);
    modulus = gcd(a.modulus, b.modulus);
    remainder = mod(a.remainder - b.remainder, modulus);
}

void ComputeModulusRemainder::visit(const Mul *op) {
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);

    if (a.modulus == 0) {
        // a is constant
        modulus = a.remainder * b.modulus;
        remainder = a.remainder * b.remainder;
    } else if (b.modulus == 0) {
        // b is constant
        modulus = b.remainder * a.modulus;
        remainder = a.remainder * b.remainder;
    } else if (a.remainder == 0 && b.remainder == 0) {
        // multiple times multiple
        modulus = a.modulus * b.modulus;
        remainder = 0;
    } else if (a.remainder == 0) {
        modulus = a.modulus * gcd(b.modulus, b.remainder);
        remainder = 0;
    } else if (b.remainder == 0) {
        modulus = b.modulus * gcd(a.modulus, a.remainder);
        remainder = 0;
    } else {
        // All our tricks failed. Convert them to the same modulus and multiply
        modulus = gcd(a.modulus, b.modulus);
        a.remainder = mod(a.remainder * b.remainder, modulus);
    }
}

void ComputeModulusRemainder::visit(const Div *) {
    // We might be able to say something about this if the numerator
    // modulus is provably a multiple of a constant denominator, but
    // in this case we should have simplified away the division.
    remainder = 0;
    modulus = 1;
}

namespace {
ModulusRemainder unify_alternatives(ModulusRemainder a, ModulusRemainder b) {
    // We don't know if we're going to get a or b, so we'd better find
    // a single modulus remainder that works for both.

    // For example:
    // max(30*_ + 13, 40*_ + 27) ->
    // max(10*_ + 3, 10*_ + 7) ->
    // max(2*_ + 1, 2*_ + 1) ->
    // 2*_ + 1

    // Reduce them to the same modulus and the same remainder
    int modulus = gcd(a.modulus, b.modulus);
    int64_t diff = (int64_t)a.remainder - (int64_t)b.remainder;
    if (!Int(32).can_represent(diff)) {
        // The difference overflows.
        return ModulusRemainder(0, 1);
    }
    if (diff < 0) diff = -diff;
    modulus = gcd((int)diff, modulus);

    int ra = mod(a.remainder, modulus);

    internal_assert(ra == mod(b.remainder, modulus))
        << "There's a bug inside ModulusRemainder in unify_alternatives:\n"
        << "a.modulus         = " << a.modulus << "\n"
        << "a.remainder       = " << a.remainder << "\n"
        << "b.modulus         = " << b.modulus << "\n"
        << "b.remainder       = " << b.remainder << "\n"
        << "diff              = " << diff << "\n"
        << "unified modulus   = " << modulus << "\n"
        << "unified remainder = " << ra << "\n";

    return ModulusRemainder(modulus, ra);
}
}

void ComputeModulusRemainder::visit(const Mod *op) {
    // We can treat x mod y as x + z*y, where we know nothing about z.
    // (ax + b) + z (cx + d) ->
    // ax + b + zcx + dz ->
    // gcd(a, c, d) * w + b

    // E.g:
    // (8x + 5) mod (6x + 2) ->
    // (8x + 5) + z (6x + 2) ->
    // (8x + 6zx + 2x) + 5 ->
    // 2(4x + 3zx + x) + 5 ->
    // 2w + 1
    ModulusRemainder a = analyze(op->a);
    ModulusRemainder b = analyze(op->b);
    modulus = gcd(a.modulus, b.modulus);
    modulus = gcd(modulus, b.remainder);
    remainder = mod(a.remainder, modulus);
}

void ComputeModulusRemainder::visit(const Min *op) {
    ModulusRemainder r = unify_alternatives(analyze(op->a), analyze(op->b));
    modulus = r.modulus;
    remainder = r.remainder;
}

void ComputeModulusRemainder::visit(const Max *op) {
    ModulusRemainder r = unify_alternatives(analyze(op->a), analyze(op->b));
    modulus = r.modulus;
    remainder = r.remainder;
}

void ComputeModulusRemainder::visit(const EQ *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const NE *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const LT *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const LE *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const GT *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const GE *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const And *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const Or *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const Not *) {
    internal_assert(false) << "modulus_remainder of bool\n";
}

void ComputeModulusRemainder::visit(const Select *op) {
    ModulusRemainder r = unify_alternatives(analyze(op->true_value),
                                            analyze(op->false_value));
    modulus = r.modulus;
    remainder = r.remainder;
}

void ComputeModulusRemainder::visit(const Load *) {
    modulus = 1;
    remainder = 0;
}

void ComputeModulusRemainder::visit(const Ramp *) {
    internal_assert(false) << "modulus_remainder of vector\n";
}

void ComputeModulusRemainder::visit(const Broadcast *) {
    internal_assert(false) << "modulus_remainder of vector\n";
}

void ComputeModulusRemainder::visit(const Call *) {
    modulus = 1;
    remainder = 0;
}

void ComputeModulusRemainder::visit(const Let *op) {
    bool value_interesting = op->value.type().is_int();

    if (value_interesting) {
        ModulusRemainder val = analyze(op->value);
        scope.push(op->name, val);
    }
    ModulusRemainder val = analyze(op->body);
    if (value_interesting) {
        scope.pop(op->name);
    }
    modulus = val.modulus;
    remainder = val.remainder;
}

void ComputeModulusRemainder::visit(const LetStmt *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const AssertStmt *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const ProducerConsumer *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const For *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Store *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Provide *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Allocate *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Realize *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Block *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Free *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const IfThenElse *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

void ComputeModulusRemainder::visit(const Evaluate *) {
    internal_assert(false) << "modulus_remainder of statement\n";
}

}
}
<|endoftext|>


<commit_before>#include "StdAfx.h"
#include "SetControlValuesTask.h"

SetControlValuesTask::SetControlValuesTask(const htmlayout::dom::element& root, HANDLE evt, std::wstring * perror)
	: m_root(root)
	, m_event(evt)
	, m_perror(perror)
{

}

void SetControlValuesTask::exec(htmlayout::dom::element elt)
{
	if (elt.is_valid())
	{
		const wchar_t * id = elt.get_attribute("id");
		const wchar_t * type = elt.get_attribute("type");
		const wchar_t * control_ptr = elt.get_attribute("control_ptr");
		const wchar_t * disabled_a = elt.get_attribute("disabled");
		bool disabled = (disabled_a != NULL && wcslen(disabled_a) > 0);
		const wchar_t * has_value_disabled_a = elt.get_attribute("has_value_disabled");
		bool has_value_disabled = (has_value_disabled_a != NULL && wcslen(has_value_disabled_a) > 0);

		if (id != NULL && type != NULL && (! disabled || has_value_disabled))
		{
			if (0 == wcscmp(type, L"checkbox") && elt.get_attribute("license") != NULL)
			{
				ControlLicense * p_license = reinterpret_cast<ControlLicense *>(DVLib::wstring2long(control_ptr, 16));
				if (! InstallUILevelSetting::Instance->IsSilent())
				{
					if (! elt.get_state(STATE_CHECKED))
					{
						THROW_EX(p_license->accept_message);
					}
				}

				std::wstring value = elt.get_state(STATE_CHECKED) ? L"1" : L"0";
				LOG(L"--- Setting user-defined license value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}
			else if (0 == wcscmp(type, L"checkbox"))
			{
				std::wstring value;
				if (control_ptr != NULL)
				{
					ControlCheckBox * p_checkbox = reinterpret_cast<ControlCheckBox *>(DVLib::wstring2long(control_ptr, 16));
					value = elt.get_state(STATE_CHECKED) ? p_checkbox->checked_value.GetValue() : p_checkbox->unchecked_value.GetValue();
				}
				else
				{
					value = elt.get_state(STATE_CHECKED) ? L"1" : L"0";
				}

				LOG(L"--- Setting user-defined checkbox value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}
			else if (0 == wcscmp(type, L"text"))
			{
				std::wstring value = elt.get_value().to_string();
				LOG(L"--- Setting user-defined edit value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}
			else if (0 == wcscmp(type, L"file-path") || 0 == wcscmp(type, L"folder-path"))
			{
				std::wstring value = elt.get_value().to_string();
				if (value.empty()) value = elt.get_attribute("novalue");
				value = DVLib::StripPathTerminator(value);
				LOG(L"--- Setting user-defined browse value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}

			// TODO: support widget types: select, dropdown-select, textarea, htmlarea
		}

		for(unsigned int child_index = 0; child_index < elt.children_count(); child_index++)
		{
			exec(elt.child(child_index));
		}
	}
}

void SetControlValuesTask::exec()
{
	try
	{
		exec(m_root);
	}
	catch(std::exception& ex)
	{
		TRYLOG(L"Error: " << DVLib::string2wstring(ex.what()));
		if (NULL != m_perror)
		{
			* m_perror = DVLib::string2wstring(ex.what());
		}
	}

	CHECK_WIN32_BOOL(SetEvent(m_event),
		L"SetEvent");
}
<commit_msg>Add HTML support for radio button user values<commit_after>#include "StdAfx.h"
#include "SetControlValuesTask.h"

SetControlValuesTask::SetControlValuesTask(const htmlayout::dom::element& root, HANDLE evt, std::wstring * perror)
	: m_root(root)
	, m_event(evt)
	, m_perror(perror)
{

}

void SetControlValuesTask::exec(htmlayout::dom::element elt)
{
	if (elt.is_valid())
	{
		const wchar_t * id = elt.get_attribute("id");
		const wchar_t * type = elt.get_attribute("type");
		const wchar_t * control_ptr = elt.get_attribute("control_ptr");
		const wchar_t * disabled_a = elt.get_attribute("disabled");
		bool disabled = (disabled_a != NULL && wcslen(disabled_a) > 0);
		const wchar_t * has_value_disabled_a = elt.get_attribute("has_value_disabled");
		bool has_value_disabled = (has_value_disabled_a != NULL && wcslen(has_value_disabled_a) > 0);

		if (id != NULL && type != NULL && (! disabled || has_value_disabled))
		{
			if (0 == wcscmp(type, L"checkbox") && elt.get_attribute("license") != NULL)
			{
				ControlLicense * p_license = reinterpret_cast<ControlLicense *>(DVLib::wstring2long(control_ptr, 16));
				if (! InstallUILevelSetting::Instance->IsSilent())
				{
					if (! elt.get_state(STATE_CHECKED))
					{
						THROW_EX(p_license->accept_message);
					}
				}

				std::wstring value = elt.get_state(STATE_CHECKED) ? L"1" : L"0";
				LOG(L"--- Setting user-defined license value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}
			else if (0 == wcscmp(type, L"checkbox"))
			{
				std::wstring value;
				if (control_ptr != NULL)
				{
					ControlCheckBox * p_checkbox = reinterpret_cast<ControlCheckBox *>(DVLib::wstring2long(control_ptr, 16));
					value = elt.get_state(STATE_CHECKED) ? p_checkbox->checked_value.GetValue() : p_checkbox->unchecked_value.GetValue();
				}
				else
				{
					value = elt.get_state(STATE_CHECKED) ? L"1" : L"0";
				}

				LOG(L"--- Setting user-defined checkbox value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}
			else if (0 == wcscmp(type, L"radio"))
			{
				std::wstring value;
				// Ignore this radio button if it's not checked.
				// Only one "checked" element for each ID should exist
				if (elt.get_state(STATE_CHECKED))
				{
					const wchar_t * elt_value = elt.get_attribute("value");
					value = elt_value != NULL ? elt_value : L"1";

					LOG(L"--- Setting user-defined radio button value '" << id << L"'=" << value);
					InstallerSession::Instance->AdditionalControlArgs[id] = value;
				}
			}
			else if (0 == wcscmp(type, L"text"))
			{
				std::wstring value = elt.get_value().to_string();
				LOG(L"--- Setting user-defined edit value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}
			else if (0 == wcscmp(type, L"file-path") || 0 == wcscmp(type, L"folder-path"))
			{
				std::wstring value = elt.get_value().to_string();
				if (value.empty()) value = elt.get_attribute("novalue");
				value = DVLib::StripPathTerminator(value);
				LOG(L"--- Setting user-defined browse value '" << id << L"'=" << value);
				InstallerSession::Instance->AdditionalControlArgs[id] = value;
			}

			// TODO: support widget types: select, dropdown-select, textarea, htmlarea
		}

		for(unsigned int child_index = 0; child_index < elt.children_count(); child_index++)
		{
			exec(elt.child(child_index));
		}
	}
}

void SetControlValuesTask::exec()
{
	try
	{
		exec(m_root);
	}
	catch(std::exception& ex)
	{
		TRYLOG(L"Error: " << DVLib::string2wstring(ex.what()));
		if (NULL != m_perror)
		{
			* m_perror = DVLib::string2wstring(ex.what());
		}
	}

	CHECK_WIN32_BOOL(SetEvent(m_event),
		L"SetEvent");
}
<|endoftext|>


<commit_before><commit_msg>debig<commit_after><|endoftext|>


<commit_before><commit_msg>Ajokki: print more messages with `std::cout`.<commit_after><|endoftext|>


<commit_before>#include "Utility/Random.h"

#include <random>
#include <string>
#include <limits>

namespace
{
    struct Seeder
    {
        using result_type = unsigned int;
        template<typename Iterator>
        void generate(Iterator begin, Iterator end)
        {
            std::random_device rd;
            std::generate(begin, end, [&rd]() { return rd(); });
        }
    };
}

Random::Random_Bits_Generator Random::get_new_seeded_random_bit_source() noexcept
{
    auto seeder = Seeder{};
    return Random_Bits_Generator(seeder);
}

double Random::random_laplace(double width) noexcept
{
    thread_local static auto generator = get_new_seeded_random_bit_source();
    using ed = std::exponential_distribution<double>;
    thread_local static auto dist = ed{};
    return (coin_flip() ? 1 : -1)*dist(generator, ed::param_type{1.0/width});
}

uint64_t Random::random_unsigned_int64() noexcept
{
    return random_integer(std::numeric_limits<uint64_t>::min(),
                          std::numeric_limits<uint64_t>::max());
}

bool Random::coin_flip() noexcept
{
    return success_probability(1, 2);
}

bool Random::success_probability(size_t successes, size_t attempts) noexcept
{
    assert(attempts > 0);
    return random_integer(size_t{1}, attempts) <= successes;
}

std::string Random::random_string(size_t size) noexcept
{
    std::string s;
    while(s.size() < size)
    {
        s.push_back('a' + char(random_integer(0, 25)));
    }
    return s;
}
<commit_msg>Replace while-loop with algorithm<commit_after>#include "Utility/Random.h"

#include <random>
#include <string>
#include <limits>

namespace
{
    struct Seeder
    {
        using result_type = unsigned int;
        template<typename Iterator>
        void generate(Iterator begin, Iterator end)
        {
            std::random_device rd;
            std::generate(begin, end, [&rd]() { return rd(); });
        }
    };
}

Random::Random_Bits_Generator Random::get_new_seeded_random_bit_source() noexcept
{
    auto seeder = Seeder{};
    return Random_Bits_Generator(seeder);
}

double Random::random_laplace(double width) noexcept
{
    thread_local static auto generator = get_new_seeded_random_bit_source();
    using ed = std::exponential_distribution<double>;
    thread_local static auto dist = ed{};
    return (coin_flip() ? 1 : -1)*dist(generator, ed::param_type{1.0/width});
}

uint64_t Random::random_unsigned_int64() noexcept
{
    return random_integer(std::numeric_limits<uint64_t>::min(),
                          std::numeric_limits<uint64_t>::max());
}

bool Random::coin_flip() noexcept
{
    return success_probability(1, 2);
}

bool Random::success_probability(size_t successes, size_t attempts) noexcept
{
    assert(attempts > 0);
    return random_integer(size_t{1}, attempts) <= successes;
}

std::string Random::random_string(const size_t size) noexcept
{
    std::string s(size, ' ');
    std::generate(s.begin(), s.end(), []() -> char { return 'a' + char(random_integer(0, 25)); });
    return s;
}
<|endoftext|>


<commit_before><commit_msg>Turn on cloud print in about:flags on the Mac.<commit_after><|endoftext|>


<commit_before>#define _BSD_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
#include "ptbox.h"

pt_process *pt_alloc_process(pt_debugger *debugger) {
    return new pt_process(debugger);
}

void pt_free_process(pt_process *process) {
    delete process;
}

pt_process::pt_process(pt_debugger *debugger) :
    pid(0), callback(NULL), context(NULL), debugger(debugger),
    event_proc(NULL), event_context(NULL), _trace_syscalls(true),
    _initialized(false)
{
    memset(&exec_time, 0, sizeof exec_time);
    memset(handler, 0, sizeof handler);
    debugger->set_process(this);
}

void pt_process::set_callback(pt_handler_callback callback, void *context) {
    this->callback = callback;
    this->context = context;
}

void pt_process::set_event_proc(pt_event_callback callback, void *context) {
    this->event_proc = callback;
    this->event_context = context;
}

int pt_process::set_handler(int syscall, int handler) {
    if (syscall >= MAX_SYSCALL || syscall < 0)
        return 1;
    this->handler[syscall] = handler;
    return 0;
}

int pt_process::dispatch(int event, unsigned long param) {
    if (event_proc != NULL)
        return event_proc(event_context, event, param);
    return -1;
}

int pt_process::spawn(pt_fork_handler child, void *context) {
    pid_t pid = fork();
    if (pid == -1)
        return 1;
    if (pid == 0)
        _exit(child(context));
    this->pid = pid;
    debugger->new_process();
    return 0;
}

int pt_process::protection_fault(int syscall) {
    dispatch(PTBOX_EVENT_PROTECTION, syscall);
    dispatch(PTBOX_EVENT_EXITING, PTBOX_EXIT_PROTECTION);
    kill(pid, SIGKILL);
    return PTBOX_EXIT_PROTECTION;
}

int pt_process::monitor() {
    bool in_syscall = false, first = true;
    struct timespec start, end, delta;
    int status, exit_reason = PTBOX_EXIT_NORMAL;
    siginfo_t si;

    while (true) {
        clock_gettime(CLOCK_MONOTONIC, &start);
        wait4(pid, &status, 0, &_rusage);
        clock_gettime(CLOCK_MONOTONIC, &end);
        timespec_sub(&end, &start, &delta);
        timespec_add(&exec_time, &delta, &exec_time);
        int signal = 0;

        if (WIFEXITED(status) || WIFSIGNALED(status))
            break;

        if (first) {
            dispatch(PTBOX_EVENT_ATTACH, 0);
            // This is right after SIGSTOP is received:
            ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT);
        }

        if (WIFSTOPPED(status)) {
            if (WSTOPSIG(status) == (0x80 | SIGTRAP)) {
                int syscall = debugger->syscall();
                in_syscall ^= true;
                //printf("%s syscall %d\n", in_syscall ? "Enter" : "Exit", syscall);

                if (!this->_initialized) {
                    if (!in_syscall && syscall == debugger->execve_syscall())
                        this->_initialized = true;
                } else if (in_syscall) {
                    if (syscall < MAX_SYSCALL) {
                        switch (handler[syscall]) {
                            case PTBOX_HANDLER_ALLOW:
                                break;
                            case PTBOX_HANDLER_STDOUTERR: {
                                int arg0 = debugger->arg0();
                                if (arg0 != 1 && arg0 != 2)
                                    exit_reason = protection_fault(syscall);
                                break;
                            }
                            case PTBOX_HANDLER_CALLBACK:
                                if (callback(context, syscall))
                                    break;
                                //printf("Killed by callback: %d\n", syscall);
                                exit_reason = protection_fault(syscall);
                                continue;
                            default:
                                // Default is to kill, safety first.
                                //printf("Killed by DISALLOW or None: %d\n", syscall);
                                exit_reason = protection_fault(syscall);
                                continue;
                        }
                    }
                } else if (debugger->on_return_callback) {
                    debugger->on_return_callback(debugger->on_return_context, syscall);
                    debugger->on_return_callback = NULL;
                    debugger->on_return_context = NULL;
                }
            } else {
                switch (WSTOPSIG(status)) {
                    case SIGTRAP:
                        switch (status >> 16) {
                            case PTRACE_EVENT_EXIT:
                                if (exit_reason != PTBOX_EXIT_NORMAL)
                                    dispatch(PTBOX_EVENT_EXITING, PTBOX_EXIT_NORMAL);
                        }
                        break;
                    default:
                        signal = WSTOPSIG(status);
                }
                if(!first) // *** Don't set _signal to SIGSTOP if this is the /first/ SIGSTOP
                    dispatch(PTBOX_EVENT_SIGNAL, WSTOPSIG(status));
            }
        }
        // Pass NULL as signal in case of our first SIGSTOP because the runtime tends to resend it, making all our
        // work for naught. Like abort(), it catches the signal, prints something (^Z?) and then resends it.
        // Doing this prevents a second SIGSTOP from being dispatched to our event handler above. ***
        ptrace(_trace_syscalls ? PTRACE_SYSCALL : PTRACE_CONT, pid, NULL, first ? NULL : (void*) signal);
        first = false;
    }
    dispatch(PTBOX_EVENT_EXITED, exit_reason);
    return WIFEXITED(status) ? WEXITSTATUS(status) : -WTERMSIG(status);
}
<commit_msg>Document iffy execve behaviour; #179<commit_after>#define _BSD_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
#include "ptbox.h"

pt_process *pt_alloc_process(pt_debugger *debugger) {
    return new pt_process(debugger);
}

void pt_free_process(pt_process *process) {
    delete process;
}

pt_process::pt_process(pt_debugger *debugger) :
    pid(0), callback(NULL), context(NULL), debugger(debugger),
    event_proc(NULL), event_context(NULL), _trace_syscalls(true),
    _initialized(false)
{
    memset(&exec_time, 0, sizeof exec_time);
    memset(handler, 0, sizeof handler);
    debugger->set_process(this);
}

void pt_process::set_callback(pt_handler_callback callback, void *context) {
    this->callback = callback;
    this->context = context;
}

void pt_process::set_event_proc(pt_event_callback callback, void *context) {
    this->event_proc = callback;
    this->event_context = context;
}

int pt_process::set_handler(int syscall, int handler) {
    if (syscall >= MAX_SYSCALL || syscall < 0)
        return 1;
    this->handler[syscall] = handler;
    return 0;
}

int pt_process::dispatch(int event, unsigned long param) {
    if (event_proc != NULL)
        return event_proc(event_context, event, param);
    return -1;
}

int pt_process::spawn(pt_fork_handler child, void *context) {
    pid_t pid = fork();
    if (pid == -1)
        return 1;
    if (pid == 0)
        _exit(child(context));
    this->pid = pid;
    debugger->new_process();
    return 0;
}

int pt_process::protection_fault(int syscall) {
    dispatch(PTBOX_EVENT_PROTECTION, syscall);
    dispatch(PTBOX_EVENT_EXITING, PTBOX_EXIT_PROTECTION);
    kill(pid, SIGKILL);
    return PTBOX_EXIT_PROTECTION;
}

int pt_process::monitor() {
    bool in_syscall = false, first = true;
    struct timespec start, end, delta;
    int status, exit_reason = PTBOX_EXIT_NORMAL;
    siginfo_t si;

    while (true) {
        clock_gettime(CLOCK_MONOTONIC, &start);
        wait4(pid, &status, 0, &_rusage);
        clock_gettime(CLOCK_MONOTONIC, &end);
        timespec_sub(&end, &start, &delta);
        timespec_add(&exec_time, &delta, &exec_time);
        int signal = 0;

        if (WIFEXITED(status) || WIFSIGNALED(status))
            break;

        if (first) {
            dispatch(PTBOX_EVENT_ATTACH, 0);
            // This is right after SIGSTOP is received:
            ptrace(PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT);
        }

        if (WIFSTOPPED(status)) {
            if (WSTOPSIG(status) == (0x80 | SIGTRAP)) {
                int syscall = debugger->syscall();
                in_syscall ^= true;
                //printf("%s syscall %d\n", in_syscall ? "Enter" : "Exit", syscall);

                if (!this->_initialized) {
                    // This might seem odd, and you may ask yourself: "does execve not return if the process hits an
                    // rlimit and gets SIGKILLed?"
                    //
                    // No, it doesn't. See the session below.
                    //      $ ulimit -Sv50000
                    //      $ strace ./a.out
                    //      execve("./a.out", ["./a.out"], [/* 17 vars */] <unfinished ...>
                    //      +++ killed by SIGKILL +++
                    //      Killed
                    //
                    // From this we can see that execve doesn't return (<unfinished ...>) if the process fails to
                    // initialize, so we don't need to wait until the next non-execve syscall to set
                    // _initialized to true - if it exited execve, it's good to go.
                    if (!in_syscall && syscall == debugger->execve_syscall())
                        this->_initialized = true;
                } else if (in_syscall) {
                    if (syscall < MAX_SYSCALL) {
                        switch (handler[syscall]) {
                            case PTBOX_HANDLER_ALLOW:
                                break;
                            case PTBOX_HANDLER_STDOUTERR: {
                                int arg0 = debugger->arg0();
                                if (arg0 != 1 && arg0 != 2)
                                    exit_reason = protection_fault(syscall);
                                break;
                            }
                            case PTBOX_HANDLER_CALLBACK:
                                if (callback(context, syscall))
                                    break;
                                //printf("Killed by callback: %d\n", syscall);
                                exit_reason = protection_fault(syscall);
                                continue;
                            default:
                                // Default is to kill, safety first.
                                //printf("Killed by DISALLOW or None: %d\n", syscall);
                                exit_reason = protection_fault(syscall);
                                continue;
                        }
                    }
                } else if (debugger->on_return_callback) {
                    debugger->on_return_callback(debugger->on_return_context, syscall);
                    debugger->on_return_callback = NULL;
                    debugger->on_return_context = NULL;
                }
            } else {
                switch (WSTOPSIG(status)) {
                    case SIGTRAP:
                        switch (status >> 16) {
                            case PTRACE_EVENT_EXIT:
                                if (exit_reason != PTBOX_EXIT_NORMAL)
                                    dispatch(PTBOX_EVENT_EXITING, PTBOX_EXIT_NORMAL);
                        }
                        break;
                    default:
                        signal = WSTOPSIG(status);
                }
                if(!first) // *** Don't set _signal to SIGSTOP if this is the /first/ SIGSTOP
                    dispatch(PTBOX_EVENT_SIGNAL, WSTOPSIG(status));
            }
        }
        // Pass NULL as signal in case of our first SIGSTOP because the runtime tends to resend it, making all our
        // work for naught. Like abort(), it catches the signal, prints something (^Z?) and then resends it.
        // Doing this prevents a second SIGSTOP from being dispatched to our event handler above. ***
        ptrace(_trace_syscalls ? PTRACE_SYSCALL : PTRACE_CONT, pid, NULL, first ? NULL : (void*) signal);
        first = false;
    }
    dispatch(PTBOX_EVENT_EXITED, exit_reason);
    return WIFEXITED(status) ? WEXITSTATUS(status) : -WTERMSIG(status);
}
<|endoftext|>


<commit_before>class Box
{
    type = CT_STATIC;
    idc = -1;
    style = ST_CENTER;
    shadow = 2;
    colorBackground[] = { 0.2,0.9,0.5, 0.9};
    colorText[] = {1,1,1,0.9};
    font = "PuristaLight";
    sizeEx = 0.03;
    text = "";
};

class AW_INTRO
{
	idd=-1;
	movingenable=false;

	class controls
	{
////////////////////////////////////////////////////////
// GUI EDITOR OUTPUT START (by BACONMOP, v1.063, #Murapy)
////////////////////////////////////////////////////////

class Rules_box: RscFrame
{
	idc = 1800;
	x = 1;
	y = 0;
	w = 0.725;
	h = 1;
};
class Rules_background: Box
{
    type = CT_STATIC;
    idc = -1;
    style = ST_CENTER;
    shadow = 2;
    colorBackground[] = { 0.1,0.1,0.1,0.9};
    font = "PuristaLight";
    sizeEx = 0.03;
	x = 1;
	y = 0;
	w = 0.725;
	h = 1;
};
class Rules_Header: RscText
{
	idc = 1000;
	text = "Rules"; //--- ToDo: Localize;
	x = 1.175;
	y = 0.02;
	w = 0.125;
	h = 0.08;
	SizeEx = 0.05400;
	colorText[] = {.9,.1,.1,.9};
};
class Rule_1: RscText
{
	idc = 1001;
	text = "1. Hacking and mission exploitation will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.1;
	w = 0.6875;
	h = 0.08;
	SizeEx = 0.03700;
};
class Rule_2: RscText
{
	idc = 1002;
	text = "2. Intentional team-killing will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.18;
	w = 0.6125;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_3: RscText
{
	idc = 1003;
	text = "3. Excessive, unintentional team-killing may result in a Kick/Ban.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.28;
	w = 0.6875;
	h = 0.08;
	SizeEx = 0.03700;
};
class Rule_4: RscText
{
	idc = 1004;
	text = "4. Unnecessary destruction of BLUFOR vehicles will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.36;
	w = 0.7;
	h = 0.08;
	SizeEx = 0.03700;
};
class Rule_5: RscText
{
	idc = 1005;
	text = "5. Verbal abuse and bullying will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.44;
	w = 0.6375;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_6: RscText
{
	idc = 1006;
	text = "6. Firing a weapon on base may result in a Kick/Ban.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.52;
	w = 0.5875;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_7: RscText
{
	idc = 1007;
	text = "7. Griefing and obstructive play will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.6;
	w = 0.7125;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_8: RscText
{
	idc = 1008;
	text = "8. Excessive mic spamming will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.68;
	w = 0.6;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_9: RscText
{
	idc = 1009;
	text = "9. A server moderator or admin's word is final."; //--- ToDo: Localize;
	x = 1;
	y = 0.78;
	w = 0.675;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_10: RscText
{
	idc = 1010;
	text = "10. Landing inside of the HQ may result in a warning or kick.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.88;
	w = 0.725;
	h = 0.08;
	SizeEx = 0.03700;
};
class AW_Intro_and_TS_picture: RscPicture
{
	idc = 1200;
	text = "media\images\Aw_Intro_Image.paa";
	x = 0;
	y = 0;
	w = 1;
	h = 1;
};
class Ok_button: RscButton
{
	idc = 1600;
	text = "Ok, Cool. Please make this box disappear"; //--- ToDo: Localize;
	x = 0;
	y = 1;
	w = 1;
	h = 0.1;
	action = "closedialog 0";
};
class General_hints: RscFrame
{
	idc = 1801;
	x = -0.713889;
	y = 0.00208756;
	w = 0.7125;
	h = 1;
	colorBackground[] = {1,1,1,1};
};
class hINTS_background: Box
{
    type = CT_STATIC;
    idc = -1;
    style = ST_CENTER;
    shadow = 2;
    colorBackground[] = { 0.1,0.1,0.1,0.9};
    font = "PuristaLight";
    sizeEx = 0.03;
	x = -0.713889;
	y = 0.00208756;
	w = 0.7125;
	h = 1;
};
class Genreal_hints_Header: RscText
{
	idc = 1011;
	text = "Some Hints and Tips"; //--- ToDo: Localize;
	x = -0.525;
	y = 0.02;
	w = 0.5;
	h = 0.08;
	SizeEx = 0.05400;
	colorText[] = {.9,.1,.1,.9};
};
class Hint_1: RscText
{
	idc = 1012;
	text = "Support elements should be on standby until called in."; //--- ToDo: Localize;
	x = -0.65;
	y = 0.1;
	w = 0.6375;
	h = 0.08;
	SizeEx = 0.03700;
};
class Hint_2: RscText
{
	idc = 1013;
	text = "Got a question? Look at our FAQ on the map."; //--- ToDo: Localize;
	x = -0.625;
	y = 0.18;
	w = 0.575;
	h = 0.08;
	SizeEx = 0.03700;
};
class Hint_3: RscText
{
	idc = 1014;
	text = "Zues players may be on but that doesn't mean they killed you."; //--- ToDo: Localize;
	x = -0.6875;
	y = 0.26;
	w = 0.6625;
	h = 0.06;
	SizeEx = 0.03700;
};
class Hint_5: RscText
{
	idc = 1015;
	text = "Found a bug? Post it on our forums. Ahoyworld.Co.uk"; //--- ToDo: Localize;
	x = -0.65;
	y = 0.34;
	w = 0.5625;
	h = 0.08;
	SizeEx = 0.03700;
};
class Hint_6: RscText
{
	idc = 1016;
	text = "Looking for a squad? Join us on Teamspeak."; //--- ToDo: Localize;
	x = -0.6125;
	y = 0.42;
	w = 0.4875;
	h = 0.06;
	SizeEx = 0.03700;
};
class Hint_7: RscText
{
	idc = 1016;
	text = "Pilots should be on Teamspeak."; //--- ToDo: Localize;
	x = -0.55;
	y = 0.50;
	w = 0.4875;
	h = 0.06;
	SizeEx = 0.03700;
};

////////////////////////////////////////////////////////
// GUI EDITOR OUTPUT END
////////////////////////////////////////////////////////

};
};

<commit_msg>Убрать бы этот диалог полностью<commit_after>class Box
{
    type = CT_STATIC;
    idc = -1;
    style = ST_CENTER;
    shadow = 2;
    colorBackground[] = { 0.2,0.9,0.5, 0.9};
    colorText[] = {1,1,1,0.9};
    font = "PuristaLight";
    sizeEx = 0.03;
    text = "";
};

class AW_INTRO
{
	idd=-1;
	movingenable=false;

	class controls
	{
////////////////////////////////////////////////////////
// GUI EDITOR OUTPUT START (by BACONMOP, v1.063, #Murapy)
////////////////////////////////////////////////////////

class Rules_box: RscFrame
{
	idc = 1800;
	x = 1;
	y = 0;
	w = 0.725;
	h = 1;
};
class Rules_background: Box
{
    type = CT_STATIC;
    idc = -1;
    style = ST_CENTER;
    shadow = 2;
    colorBackground[] = { 0.1,0.1,0.1,0.9};
    font = "PuristaLight";
    sizeEx = 0.03;
	x = 1;
	y = 0;
	w = 0.725;
	h = 1;
};
class Rules_Header: RscText
{
	idc = 1000;
	text = "Rules"; //--- ToDo: Localize;
	x = 1.175;
	y = 0.02;
	w = 0.125;
	h = 0.08;
	SizeEx = 0.05400;
	colorText[] = {.9,.1,.1,.9};
};
class Rule_1: RscText
{
	idc = 1001;
	text = "1. Hacking and mission exploitation will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.1;
	w = 0.6875;
	h = 0.08;
	SizeEx = 0.03700;
};
class Rule_2: RscText
{
	idc = 1002;
	text = "2. Intentional team-killing will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.18;
	w = 0.6125;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_3: RscText
{
	idc = 1003;
	text = "3. Excessive, unintentional team-killing may result in a Kick/Ban.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.28;
	w = 0.6875;
	h = 0.08;
	SizeEx = 0.03700;
};
class Rule_4: RscText
{
	idc = 1004;
	text = "4. Unnecessary destruction of BLUFOR vehicles will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.36;
	w = 0.7;
	h = 0.08;
	SizeEx = 0.03700;
};
class Rule_5: RscText
{
	idc = 1005;
	text = "5. Verbal abuse and bullying will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.44;
	w = 0.6375;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_6: RscText
{
	idc = 1006;
	text = "6. Firing a weapon on base may result in a Kick/Ban.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.52;
	w = 0.5875;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_7: RscText
{
	idc = 1007;
	text = "7. Griefing and obstructive play will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.6;
	w = 0.7125;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_8: RscText
{
	idc = 1008;
	text = "8. Excessive mic spamming will not be tolerated.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.68;
	w = 0.6;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_9: RscText
{
	idc = 1009;
	text = "9. A server moderator or admin's word is final."; //--- ToDo: Localize;
	x = 1;
	y = 0.78;
	w = 0.675;
	h = 0.1;
	SizeEx = 0.03700;
};
class Rule_10: RscText
{
	idc = 1010;
	text = "10. Landing inside of the HQ may result in a warning or kick.  "; //--- ToDo: Localize;
	x = 1;
	y = 0.88;
	w = 0.725;
	h = 0.08;
	SizeEx = 0.03700;
};
class AW_Intro_and_TS_picture: RscPicture
{
	idc = 1200;
	text = "media\images\Aw_Intro_Image.paa";
	x = 0;
	y = 0;
	w = 1;
	h = 1;
};
class Ok_button: RscButton
{
	idc = 1600;
	text = "Ok, Cool. Please make this box disappear"; //--- ToDo: Localize;
	x = 0;
	y = 1;
	w = 1;
	h = 0.1;
	action = "closedialog 0";
};
class General_hints: RscFrame
{
	idc = 1801;
	x = -0.713889;
	y = 0.00208756;
	w = 0.7125;
	h = 1;
	colorBackground[] = {1,1,1,1};
};
class hINTS_background: Box
{
    type = CT_STATIC;
    idc = -1;
    style = ST_CENTER;
    shadow = 2;
    colorBackground[] = { 0.1,0.1,0.1,0.9};
    font = "PuristaLight";
    sizeEx = 0.03;
	x = -0.713889;
	y = 0.00208756;
	w = 0.7125;
	h = 1;
};
class Genreal_hints_Header: RscText
{
	idc = 1011;
	text = "Some Hints and Tips"; //--- ToDo: Localize;
	x = -0.525;
	y = 0.02;
	w = 0.5;
	h = 0.08;
	SizeEx = 0.05400;
	colorText[] = {.9,.1,.1,.9};
};
class Hint_1: RscText
{
	idc = 1012;
	text = "Support elements should be on standby until called in."; //--- ToDo: Localize;
	x = -0.65;
	y = 0.1;
	w = 0.6375;
	h = 0.08;
	SizeEx = 0.03700;
};
class Hint_2: RscText
{
	idc = 1013;
	text = "Got a question? Look at our FAQ on the map."; //--- ToDo: Localize;
	x = -0.625;
	y = 0.18;
	w = 0.575;
	h = 0.08;
	SizeEx = 0.03700;
};
class Hint_3: RscText
{
	idc = 1014;
	text = "Zues players may be on but that doesn't mean they killed you."; //--- ToDo: Localize;
	x = -0.6875;
	y = 0.26;
	w = 0.6625;
	h = 0.06;
	SizeEx = 0.03700;
};
class Hint_5: RscText
{
	idc = 1015;
	text = "Found a bug? Post it on Ahoyworld.Co.uk (or TEHGAM.COM)"; //--- ToDo: Localize;
	x = -0.65;
	y = 0.34;
	w = 0.5625;
	h = 0.08;
	SizeEx = 0.03700;
};
class Hint_6: RscText
{
	idc = 1016;
	text = "Looking for a squad? Join us on Teamspeak."; //--- ToDo: Localize;
	x = -0.6125;
	y = 0.42;
	w = 0.4875;
	h = 0.06;
	SizeEx = 0.03700;
};
class Hint_7: RscText
{
	idc = 1016;
	text = "Pilots should be on Teamspeak."; //--- ToDo: Localize;
	x = -0.55;
	y = 0.50;
	w = 0.4875;
	h = 0.06;
	SizeEx = 0.03700;
};

////////////////////////////////////////////////////////
// GUI EDITOR OUTPUT END
////////////////////////////////////////////////////////

};
};

<|endoftext|>


<commit_before>#include "GHIElectronics_TinyCLR_Devices.h"
#include "GHIElectronics_TinyCLR_InteropUtil.h"

const int CummulativeDaysForMonth[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };

#define BASE_YEAR                   1601
#define BASE_YEAR_LEAPYEAR_ADJUST   388
#define DAYS_IN_NORMAL_YEAR         365
#define BASE_YEAR_DAYOFWEEK_SHIFT   1

#define IS_LEAP_YEAR(y)             (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
#define NUMBER_OF_LEAP_YEARS(y)     ((((y - 1) / 4) - ((y - 1) / 100) + ((y - 1) / 400)) - BASE_YEAR_LEAPYEAR_ADJUST) /// Number of leap years until base year, not including the target year itself.
#define NUMBER_OF_YEARS(y)          (y - BASE_YEAR)

#define YEARS_TO_DAYS(y)            ((NUMBER_OF_YEARS(y) * DAYS_IN_NORMAL_YEAR) + NUMBER_OF_LEAP_YEARS(y))
#define MONTH_TO_DAYS(y, m)         (CummulativeDaysForMonth[m - 1] + ((IS_LEAP_YEAR(y) && (m > 2)) ? 1 : 0))

#define TIMEUNIT_TO_MINUTES         600000000
#define TIMEUNIT_TO_MILLISECONDS    10000
#define MILLISECONDS_TO_SECONDS     1000
#define SECONDS_TO_MINUTES          60
#define MINUTES_TO_HOUR             60
#define HOURS_TO_DAY                24

static inline uint64_t Interop_Rtc_FromSystemTime(const TinyCLR_Rtc_DateTime* systemTime) {
    uint64_t r = YEARS_TO_DAYS(systemTime->Year) + MONTH_TO_DAYS(systemTime->Year, systemTime->Month) + systemTime->DayOfMonth - 1;
    r = (((((r * HOURS_TO_DAY) + systemTime->Hour) * MINUTES_TO_HOUR + systemTime->Minute) * SECONDS_TO_MINUTES + systemTime->Second) * MILLISECONDS_TO_SECONDS + systemTime->Millisecond) * TIMEUNIT_TO_MILLISECONDS;

    return r;
}

static inline void Interop_Rtc_ToSystemTime(uint64_t time, TinyCLR_Rtc_DateTime* systemTime) {
    int ytd = 0;
    int mtd = 0;

    time /= TIMEUNIT_TO_MILLISECONDS;
    systemTime->Millisecond = time % MILLISECONDS_TO_SECONDS;
    time /= MILLISECONDS_TO_SECONDS;
    systemTime->Second = time % SECONDS_TO_MINUTES;
    time /= SECONDS_TO_MINUTES;
    systemTime->Minute = time % MINUTES_TO_HOUR;
    time /= MINUTES_TO_HOUR;
    systemTime->Hour = time % HOURS_TO_DAY;
    time /= HOURS_TO_DAY;

    systemTime->DayOfWeek = (time + BASE_YEAR_DAYOFWEEK_SHIFT) % 7;
    systemTime->Year = (uint32_t)(time / DAYS_IN_NORMAL_YEAR + BASE_YEAR);
    ytd = YEARS_TO_DAYS(systemTime->Year);
    if (ytd > time) {
        systemTime->Year--;
        ytd = YEARS_TO_DAYS(systemTime->Year);
    }

    time -= ytd;

    systemTime->Month = (uint32_t)(time / 31 + 1);
    mtd = MONTH_TO_DAYS(systemTime->Year, systemTime->Month + 1);

    if (time >= mtd) {
        systemTime->Month++;
    }

    mtd = MONTH_TO_DAYS(systemTime->Year, systemTime->Month);

    systemTime->DayOfMonth = (uint32_t)(time - mtd + 1);
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::GetTime___GHIElectronicsTinyCLRDevicesRtcRtcDateTime(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    TinyCLR_Rtc_DateTime now;

    auto result = api->GetTime(api, now);

    TinyCLR_Interop_ClrValue obj, ret;
    TinyCLR_Interop_ClrTypeId type;

    md.InteropManager->FindType(md.InteropManager, "GHIElectronics.TinyCLR.Devices", "GHIElectronics.TinyCLR.Devices.Rtc", "RtcDateTime", type);

    md.InteropManager->CreateObject(md.InteropManager, md.Stack, type, obj);

    TinyCLR_Interop_ClrValue year, month, week, dayofweek, dayofmonth, dayofyear, hour, minute, second, milisecond, microsecond, nanosecond;

    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Year___I4, year);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Month___I4, month);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Week___I4, week);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfYear___I4, dayofweek);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfMonth___I4, dayofmonth);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfWeek___I4, dayofyear);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Hour___I4, hour);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Minute___I4, minute);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Second___I4, second);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Millisecond___I4, milisecond);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Microsecond___I4, microsecond);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Nanosecond___I4, nanosecond);

    year.Data.Numeric->I4 = now.Year;
    month.Data.Numeric->I4 = now.Month;
    week.Data.Numeric->I4 = now.Week;
    dayofweek.Data.Numeric->I4 = now.DayOfYear;
    dayofmonth.Data.Numeric->I4 = now.DayOfMonth;
    dayofyear.Data.Numeric->I4 = now.DayOfWeek;
    hour.Data.Numeric->I4 = now.Hour;
    minute.Data.Numeric->I4 = now.Minute;
    second.Data.Numeric->I4 = now.Second;
    milisecond.Data.Numeric->I4 = now.Millisecond;
    microsecond.Data.Numeric->I4 = now.Microsecond;
    nanosecond.Data.Numeric->I4 = now.Nanosecond;

    md.InteropManager->GetReturn(md.InteropManager, md.Stack, ret);

    md.InteropManager->AssignObjectReference(md.InteropManager, ret, obj.Object);

    return result;
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::SetTime___VOID__GHIElectronicsTinyCLRDevicesRtcRtcDateTime(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    TinyCLR_Interop_ClrValue arg0;

    md.InteropManager->GetArgument(md.InteropManager, md.Stack, 0, arg0);

    TinyCLR_Rtc_DateTime now;

    TinyCLR_Interop_ClrValue year, month, week, dayofweek, dayofmonth, dayofyear, hour, minute, second, milisecond, microsecond, nanosecond;

    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Year___I4, year);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Month___I4, month);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Week___I4, week);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfYear___I4, dayofweek);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfMonth___I4, dayofmonth);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfWeek___I4, dayofyear);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Hour___I4, hour);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Minute___I4, minute);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Second___I4, second);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Millisecond___I4, milisecond);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Microsecond___I4, microsecond);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Nanosecond___I4, nanosecond);

    now.Year = year.Data.Numeric->I4;
    now.Month = month.Data.Numeric->I4;
    now.Week = week.Data.Numeric->I4;
    now.DayOfYear = dayofweek.Data.Numeric->I4;
    now.DayOfMonth = dayofmonth.Data.Numeric->I4;
    now.DayOfWeek = dayofyear.Data.Numeric->I4;
    now.Hour = hour.Data.Numeric->I4;
    now.Minute = minute.Data.Numeric->I4;
    now.Second = second.Data.Numeric->I4;
    now.Millisecond = milisecond.Data.Numeric->I4;
    now.Microsecond = microsecond.Data.Numeric->I4;
    now.Nanosecond = nanosecond.Data.Numeric->I4;

    return api->SetTime(api, now);
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::Acquire___VOID(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    return api->Acquire(api);
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::Release___VOID(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    return api->Release(api);
}
<commit_msg>Remove old stuff that isn't used in RTC<commit_after>#include "GHIElectronics_TinyCLR_Devices.h"
#include "GHIElectronics_TinyCLR_InteropUtil.h"

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::GetTime___GHIElectronicsTinyCLRDevicesRtcRtcDateTime(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    TinyCLR_Rtc_DateTime now;

    auto result = api->GetTime(api, now);

    TinyCLR_Interop_ClrValue obj, ret;
    TinyCLR_Interop_ClrTypeId type;

    md.InteropManager->FindType(md.InteropManager, "GHIElectronics.TinyCLR.Devices", "GHIElectronics.TinyCLR.Devices.Rtc", "RtcDateTime", type);

    md.InteropManager->CreateObject(md.InteropManager, md.Stack, type, obj);

    TinyCLR_Interop_ClrValue year, month, week, dayofweek, dayofmonth, dayofyear, hour, minute, second, milisecond, microsecond, nanosecond;

    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Year___I4, year);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Month___I4, month);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Week___I4, week);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfYear___I4, dayofweek);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfMonth___I4, dayofmonth);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfWeek___I4, dayofyear);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Hour___I4, hour);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Minute___I4, minute);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Second___I4, second);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Millisecond___I4, milisecond);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Microsecond___I4, microsecond);
    md.InteropManager->GetField(md.InteropManager, obj.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Nanosecond___I4, nanosecond);

    year.Data.Numeric->I4 = now.Year;
    month.Data.Numeric->I4 = now.Month;
    week.Data.Numeric->I4 = now.Week;
    dayofweek.Data.Numeric->I4 = now.DayOfYear;
    dayofmonth.Data.Numeric->I4 = now.DayOfMonth;
    dayofyear.Data.Numeric->I4 = now.DayOfWeek;
    hour.Data.Numeric->I4 = now.Hour;
    minute.Data.Numeric->I4 = now.Minute;
    second.Data.Numeric->I4 = now.Second;
    milisecond.Data.Numeric->I4 = now.Millisecond;
    microsecond.Data.Numeric->I4 = now.Microsecond;
    nanosecond.Data.Numeric->I4 = now.Nanosecond;

    md.InteropManager->GetReturn(md.InteropManager, md.Stack, ret);

    md.InteropManager->AssignObjectReference(md.InteropManager, ret, obj.Object);

    return result;
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::SetTime___VOID__GHIElectronicsTinyCLRDevicesRtcRtcDateTime(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    TinyCLR_Interop_ClrValue arg0;

    md.InteropManager->GetArgument(md.InteropManager, md.Stack, 0, arg0);

    TinyCLR_Rtc_DateTime now;

    TinyCLR_Interop_ClrValue year, month, week, dayofweek, dayofmonth, dayofyear, hour, minute, second, milisecond, microsecond, nanosecond;

    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Year___I4, year);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Month___I4, month);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Week___I4, week);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfYear___I4, dayofweek);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfMonth___I4, dayofmonth);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___DayOfWeek___I4, dayofyear);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Hour___I4, hour);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Minute___I4, minute);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Second___I4, second);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Millisecond___I4, milisecond);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Microsecond___I4, microsecond);
    md.InteropManager->GetField(md.InteropManager, arg0.Object, Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_RtcDateTime::FIELD___Nanosecond___I4, nanosecond);

    now.Year = year.Data.Numeric->I4;
    now.Month = month.Data.Numeric->I4;
    now.Week = week.Data.Numeric->I4;
    now.DayOfYear = dayofweek.Data.Numeric->I4;
    now.DayOfMonth = dayofmonth.Data.Numeric->I4;
    now.DayOfWeek = dayofyear.Data.Numeric->I4;
    now.Hour = hour.Data.Numeric->I4;
    now.Minute = minute.Data.Numeric->I4;
    now.Second = second.Data.Numeric->I4;
    now.Millisecond = milisecond.Data.Numeric->I4;
    now.Microsecond = microsecond.Data.Numeric->I4;
    now.Nanosecond = nanosecond.Data.Numeric->I4;

    return api->SetTime(api, now);
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::Acquire___VOID(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    return api->Acquire(api);
}

TinyCLR_Result Interop_GHIElectronics_TinyCLR_Devices_GHIElectronics_TinyCLR_Devices_Rtc_Provider_RtcControllerApiWrapper::Release___VOID(const TinyCLR_Interop_MethodData md) {
    auto api = reinterpret_cast<const TinyCLR_Rtc_Controller*>(TinyCLR_Interop_GetApi(md, FIELD___impl___I));

    return api->Release(api);
}
<|endoftext|>


<commit_before>// Ylikuutio - A 3D game and simulation engine.
//
// Copyright (C) 2015-2019 Antti Nuortimo.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#ifndef __UNIVERSE_STRUCT_HPP_INCLUDED
#define __UNIVERSE_STRUCT_HPP_INCLUDED

#include "code/ylikuutio/callback_system/key_and_callback_struct.hpp"

// Include standard headers
#include <cstddef>  // std::size_t
#include <stdint.h> // uint32_t etc.
#include <string>   // std::string
#include <vector>   // std::vector

namespace yli
{
    namespace ontology
    {
        struct UniverseStruct
        {
            UniverseStruct()
                : window_title(""),
                window_width(1600),
                window_height(900),
                framebuffer_width(8000),
                framebuffer_height(4500),
                text_size(40),
                font_size(16),
                max_FPS(50000),         // default value max 50000 frames per second.
                speed(5.0f),            // default value 5.0 units / second.
                turbo_factor(5.0f),        // default value 5.0 x speed.
                twin_turbo_factor(100.0f), // default value 100.0 x speed.
                mouse_speed(0.005f),
                gravity(9.81f / 60.0f), // default Earth gravity (9.81 m/s^2).
                znear(1.0f),
                zfar(5000.0f),          // visibility: from 1 to 5000 units.
                is_headless(false)
            {
                // constructor.
            }

            std::string window_title;
            uint32_t window_width;
            uint32_t window_height;
            uint32_t framebuffer_width;
            uint32_t framebuffer_height;
            std::size_t text_size;
            std::size_t font_size;
            std::size_t max_FPS;
            float speed;
            float turbo_factor;
            float twin_turbo_factor;
            float mouse_speed;
            float gravity;
            float znear;
            float zfar;
            bool is_headless;
        };
    }
}

#endif
<commit_msg>Removed unnecessary `#include` line.<commit_after>// Ylikuutio - A 3D game and simulation engine.
//
// Copyright (C) 2015-2019 Antti Nuortimo.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#ifndef __UNIVERSE_STRUCT_HPP_INCLUDED
#define __UNIVERSE_STRUCT_HPP_INCLUDED

// Include standard headers
#include <cstddef>  // std::size_t
#include <stdint.h> // uint32_t etc.
#include <string>   // std::string
#include <vector>   // std::vector

namespace yli
{
    namespace ontology
    {
        struct UniverseStruct
        {
            UniverseStruct()
                : window_title(""),
                window_width(1600),
                window_height(900),
                framebuffer_width(8000),
                framebuffer_height(4500),
                text_size(40),
                font_size(16),
                max_FPS(50000),         // default value max 50000 frames per second.
                speed(5.0f),            // default value 5.0 units / second.
                turbo_factor(5.0f),        // default value 5.0 x speed.
                twin_turbo_factor(100.0f), // default value 100.0 x speed.
                mouse_speed(0.005f),
                gravity(9.81f / 60.0f), // default Earth gravity (9.81 m/s^2).
                znear(1.0f),
                zfar(5000.0f),          // visibility: from 1 to 5000 units.
                is_headless(false)
            {
                // constructor.
            }

            std::string window_title;
            uint32_t window_width;
            uint32_t window_height;
            uint32_t framebuffer_width;
            uint32_t framebuffer_height;
            std::size_t text_size;
            std::size_t font_size;
            std::size_t max_FPS;
            float speed;
            float turbo_factor;
            float twin_turbo_factor;
            float mouse_speed;
            float gravity;
            float znear;
            float zfar;
            bool is_headless;
        };
    }
}

#endif
<|endoftext|>